1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, 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 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
473 -- Save the Ghost-related attributes to restore on exit
476 Restore_Scope
: Boolean := False;
478 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
481 -- Do not analyze the pragma multiple times
483 if Is_Analyzed_Pragma
(N
) then
487 -- Set the Ghost mode in effect from the pragma. Due to the delayed
488 -- analysis of the pragma, the Ghost mode at point of declaration and
489 -- point of analysis may not necessarily be the same. Use the mode in
490 -- effect at the point of declaration.
494 -- Single and multiple contract cases must appear in aggregate form. If
495 -- this is not the case, then either the parser of the analysis of the
496 -- pragma failed to produce an aggregate.
498 pragma Assert
(Nkind
(CCases
) = N_Aggregate
);
500 if Present
(Component_Associations
(CCases
)) then
502 -- Ensure that the formal parameters are visible when analyzing all
503 -- clauses. This falls out of the general rule of aspects pertaining
504 -- to subprogram declarations.
506 if not In_Open_Scopes
(Spec_Id
) then
507 Restore_Scope
:= True;
508 Push_Scope
(Spec_Id
);
510 if Is_Generic_Subprogram
(Spec_Id
) then
511 Install_Generic_Formals
(Spec_Id
);
513 Install_Formals
(Spec_Id
);
517 CCase
:= First
(Component_Associations
(CCases
));
518 while Present
(CCase
) loop
519 Analyze_Contract_Case
(CCase
);
523 if Restore_Scope
then
527 -- Currently it is not possible to inline pre/postconditions on a
528 -- subprogram subject to pragma Inline_Always.
530 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
532 -- Otherwise the pragma is illegal
535 Error_Msg_N
("wrong syntax for constract cases", N
);
538 Set_Is_Analyzed_Pragma
(N
);
540 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
541 end Analyze_Contract_Cases_In_Decl_Part
;
543 ----------------------------------
544 -- Analyze_Depends_In_Decl_Part --
545 ----------------------------------
547 procedure Analyze_Depends_In_Decl_Part
(N
: Node_Id
) is
548 Loc
: constant Source_Ptr
:= Sloc
(N
);
549 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
550 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
552 All_Inputs_Seen
: Elist_Id
:= No_Elist
;
553 -- A list containing the entities of all the inputs processed so far.
554 -- The list is populated with unique entities because the same input
555 -- may appear in multiple input lists.
557 All_Outputs_Seen
: Elist_Id
:= No_Elist
;
558 -- A list containing the entities of all the outputs processed so far.
559 -- The list is populated with unique entities because output items are
560 -- unique in a dependence relation.
562 Constits_Seen
: Elist_Id
:= No_Elist
;
563 -- A list containing the entities of all constituents processed so far.
564 -- It aids in detecting illegal usage of a state and a corresponding
565 -- constituent in pragma [Refinde_]Depends.
567 Global_Seen
: Boolean := False;
568 -- A flag set when pragma Global has been processed
570 Null_Output_Seen
: Boolean := False;
571 -- A flag used to track the legality of a null output
573 Result_Seen
: Boolean := False;
574 -- A flag set when Spec_Id'Result is processed
576 States_Seen
: Elist_Id
:= No_Elist
;
577 -- A list containing the entities of all states processed so far. It
578 -- helps in detecting illegal usage of a state and a corresponding
579 -- constituent in pragma [Refined_]Depends.
581 Subp_Inputs
: Elist_Id
:= No_Elist
;
582 Subp_Outputs
: Elist_Id
:= No_Elist
;
583 -- Two lists containing the full set of inputs and output of the related
584 -- subprograms. Note that these lists contain both nodes and entities.
586 Task_Input_Seen
: Boolean := False;
587 Task_Output_Seen
: Boolean := False;
588 -- Flags used to track the implicit dependence of a task unit on itself
590 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
);
591 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
592 -- to the name buffer. The individual kinds are as follows:
593 -- E_Abstract_State - "state"
594 -- E_Constant - "constant"
595 -- E_Generic_In_Out_Parameter - "generic parameter"
596 -- E_Generic_In_Parameter - "generic parameter"
597 -- E_In_Parameter - "parameter"
598 -- E_In_Out_Parameter - "parameter"
599 -- E_Loop_Parameter - "loop parameter"
600 -- E_Out_Parameter - "parameter"
601 -- E_Protected_Type - "current instance of protected type"
602 -- E_Task_Type - "current instance of task type"
603 -- E_Variable - "global"
605 procedure Analyze_Dependency_Clause
608 -- Verify the legality of a single dependency clause. Flag Is_Last
609 -- denotes whether Clause is the last clause in the relation.
611 procedure Check_Function_Return
;
612 -- Verify that Funtion'Result appears as one of the outputs
613 -- (SPARK RM 6.1.5(10)).
620 -- Ensure that an item fulfills its designated input and/or output role
621 -- as specified by pragma Global (if any) or the enclosing context. If
622 -- this is not the case, emit an error. Item and Item_Id denote the
623 -- attributes of an item. Flag Is_Input should be set when item comes
624 -- from an input list. Flag Self_Ref should be set when the item is an
625 -- output and the dependency clause has operator "+".
627 procedure Check_Usage
628 (Subp_Items
: Elist_Id
;
629 Used_Items
: Elist_Id
;
631 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
632 -- error if this is not the case.
634 procedure Normalize_Clause
(Clause
: Node_Id
);
635 -- Remove a self-dependency "+" from the input list of a clause
637 -----------------------------
638 -- Add_Item_To_Name_Buffer --
639 -----------------------------
641 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
) is
643 if Ekind
(Item_Id
) = E_Abstract_State
then
644 Add_Str_To_Name_Buffer
("state");
646 elsif Ekind
(Item_Id
) = E_Constant
then
647 Add_Str_To_Name_Buffer
("constant");
649 elsif Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
650 E_Generic_In_Parameter
)
652 Add_Str_To_Name_Buffer
("generic parameter");
654 elsif Is_Formal
(Item_Id
) then
655 Add_Str_To_Name_Buffer
("parameter");
657 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
658 Add_Str_To_Name_Buffer
("loop parameter");
660 elsif Ekind
(Item_Id
) = E_Protected_Type
661 or else Is_Single_Protected_Object
(Item_Id
)
663 Add_Str_To_Name_Buffer
("current instance of protected type");
665 elsif Ekind
(Item_Id
) = E_Task_Type
666 or else Is_Single_Task_Object
(Item_Id
)
668 Add_Str_To_Name_Buffer
("current instance of task type");
670 elsif Ekind
(Item_Id
) = E_Variable
then
671 Add_Str_To_Name_Buffer
("global");
673 -- The routine should not be called with non-SPARK items
678 end Add_Item_To_Name_Buffer
;
680 -------------------------------
681 -- Analyze_Dependency_Clause --
682 -------------------------------
684 procedure Analyze_Dependency_Clause
688 procedure Analyze_Input_List
(Inputs
: Node_Id
);
689 -- Verify the legality of a single input list
691 procedure Analyze_Input_Output
696 Seen
: in out Elist_Id
;
697 Null_Seen
: in out Boolean;
698 Non_Null_Seen
: in out Boolean);
699 -- Verify the legality of a single input or output item. Flag
700 -- Is_Input should be set whenever Item is an input, False when it
701 -- denotes an output. Flag Self_Ref should be set when the item is an
702 -- output and the dependency clause has a "+". Flag Top_Level should
703 -- be set whenever Item appears immediately within an input or output
704 -- list. Seen is a collection of all abstract states, objects and
705 -- formals processed so far. Flag Null_Seen denotes whether a null
706 -- input or output has been encountered. Flag Non_Null_Seen denotes
707 -- whether a non-null input or output has been encountered.
709 ------------------------
710 -- Analyze_Input_List --
711 ------------------------
713 procedure Analyze_Input_List
(Inputs
: Node_Id
) is
714 Inputs_Seen
: Elist_Id
:= No_Elist
;
715 -- A list containing the entities of all inputs that appear in the
716 -- current input list.
718 Non_Null_Input_Seen
: Boolean := False;
719 Null_Input_Seen
: Boolean := False;
720 -- Flags used to check the legality of an input list
725 -- Multiple inputs appear as an aggregate
727 if Nkind
(Inputs
) = N_Aggregate
then
728 if Present
(Component_Associations
(Inputs
)) then
730 ("nested dependency relations not allowed", Inputs
);
732 elsif Present
(Expressions
(Inputs
)) then
733 Input
:= First
(Expressions
(Inputs
));
734 while Present
(Input
) loop
741 Null_Seen
=> Null_Input_Seen
,
742 Non_Null_Seen
=> Non_Null_Input_Seen
);
747 -- Syntax error, always report
750 Error_Msg_N
("malformed input dependency list", Inputs
);
753 -- Process a solitary input
762 Null_Seen
=> Null_Input_Seen
,
763 Non_Null_Seen
=> Non_Null_Input_Seen
);
766 -- Detect an illegal dependency clause of the form
770 if Null_Output_Seen
and then Null_Input_Seen
then
772 ("null dependency clause cannot have a null input list",
775 end Analyze_Input_List
;
777 --------------------------
778 -- Analyze_Input_Output --
779 --------------------------
781 procedure Analyze_Input_Output
786 Seen
: in out Elist_Id
;
787 Null_Seen
: in out Boolean;
788 Non_Null_Seen
: in out Boolean)
790 procedure Current_Task_Instance_Seen
;
791 -- Set the appropriate global flag when the current instance of a
792 -- task unit is encountered.
794 --------------------------------
795 -- Current_Task_Instance_Seen --
796 --------------------------------
798 procedure Current_Task_Instance_Seen
is
801 Task_Input_Seen
:= True;
803 Task_Output_Seen
:= True;
805 end Current_Task_Instance_Seen
;
809 Is_Output
: constant Boolean := not Is_Input
;
813 -- Start of processing for Analyze_Input_Output
816 -- Multiple input or output items appear as an aggregate
818 if Nkind
(Item
) = N_Aggregate
then
819 if not Top_Level
then
820 SPARK_Msg_N
("nested grouping of items not allowed", Item
);
822 elsif Present
(Component_Associations
(Item
)) then
824 ("nested dependency relations not allowed", Item
);
826 -- Recursively analyze the grouped items
828 elsif Present
(Expressions
(Item
)) then
829 Grouped
:= First
(Expressions
(Item
));
830 while Present
(Grouped
) loop
833 Is_Input
=> Is_Input
,
834 Self_Ref
=> Self_Ref
,
837 Null_Seen
=> Null_Seen
,
838 Non_Null_Seen
=> Non_Null_Seen
);
843 -- Syntax error, always report
846 Error_Msg_N
("malformed dependency list", Item
);
849 -- Process attribute 'Result in the context of a dependency clause
851 elsif Is_Attribute_Result
(Item
) then
852 Non_Null_Seen
:= True;
856 -- Attribute 'Result is allowed to appear on the output side of
857 -- a dependency clause (SPARK RM 6.1.5(6)).
860 SPARK_Msg_N
("function result cannot act as input", Item
);
864 ("cannot mix null and non-null dependency items", Item
);
870 -- Detect multiple uses of null in a single dependency list or
871 -- throughout the whole relation. Verify the placement of a null
872 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
874 elsif Nkind
(Item
) = N_Null
then
877 ("multiple null dependency relations not allowed", Item
);
879 elsif Non_Null_Seen
then
881 ("cannot mix null and non-null dependency items", Item
);
889 ("null output list must be the last clause in a "
890 & "dependency relation", Item
);
892 -- Catch a useless dependence of the form:
897 ("useless dependence, null depends on itself", Item
);
905 Non_Null_Seen
:= True;
908 SPARK_Msg_N
("cannot mix null and non-null items", Item
);
912 Resolve_State
(Item
);
914 -- Find the entity of the item. If this is a renaming, climb
915 -- the renaming chain to reach the root object. Renamings of
916 -- non-entire objects do not yield an entity (Empty).
918 Item_Id
:= Entity_Of
(Item
);
920 if Present
(Item_Id
) then
924 if Ekind_In
(Item_Id
, E_Constant
, E_Loop_Parameter
)
927 -- Current instances of concurrent types
929 Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
)
934 Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
935 E_Generic_In_Parameter
,
943 Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
)
945 -- A [generic] function is not allowed to have Output
946 -- items in its dependency relations. Note that "null"
947 -- and attribute 'Result are still valid items.
949 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
950 and then not Is_Input
953 ("output item is not applicable to function", Item
);
956 -- The item denotes a concurrent type. Note that single
957 -- protected/task types are not considered here because
958 -- they behave as objects in the context of pragma
959 -- [Refined_]Depends.
961 if Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
963 -- This use is legal as long as the concurrent type is
964 -- the current instance of an enclosing type.
966 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
968 -- The dependence of a task unit on itself is
969 -- implicit and may or may not be explicitly
970 -- specified (SPARK RM 6.1.4).
972 if Ekind
(Item_Id
) = E_Task_Type
then
973 Current_Task_Instance_Seen
;
976 -- Otherwise this is not the current instance
980 ("invalid use of subtype mark in dependency "
984 -- The dependency of a task unit on itself is implicit
985 -- and may or may not be explicitly specified
988 elsif Is_Single_Task_Object
(Item_Id
)
989 and then Is_CCT_Instance
(Etype
(Item_Id
), Spec_Id
)
991 Current_Task_Instance_Seen
;
994 -- Ensure that the item fulfills its role as input and/or
995 -- output as specified by pragma Global or the enclosing
998 Check_Role
(Item
, Item_Id
, Is_Input
, Self_Ref
);
1000 -- Detect multiple uses of the same state, variable or
1001 -- formal parameter. If this is not the case, add the
1002 -- item to the list of processed relations.
1004 if Contains
(Seen
, Item_Id
) then
1006 ("duplicate use of item &", Item
, Item_Id
);
1008 Append_New_Elmt
(Item_Id
, Seen
);
1011 -- Detect illegal use of an input related to a null
1012 -- output. Such input items cannot appear in other
1013 -- input lists (SPARK RM 6.1.5(13)).
1016 and then Null_Output_Seen
1017 and then Contains
(All_Inputs_Seen
, Item_Id
)
1020 ("input of a null output list cannot appear in "
1021 & "multiple input lists", Item
);
1024 -- Add an input or a self-referential output to the list
1025 -- of all processed inputs.
1027 if Is_Input
or else Self_Ref
then
1028 Append_New_Elmt
(Item_Id
, All_Inputs_Seen
);
1031 -- State related checks (SPARK RM 6.1.5(3))
1033 if Ekind
(Item_Id
) = E_Abstract_State
then
1035 -- Package and subprogram bodies are instantiated
1036 -- individually in a separate compiler pass. Due to
1037 -- this mode of instantiation, the refinement of a
1038 -- state may no longer be visible when a subprogram
1039 -- body contract is instantiated. Since the generic
1040 -- template is legal, do not perform this check in
1041 -- the instance to circumvent this oddity.
1043 if Is_Generic_Instance
(Spec_Id
) then
1046 -- An abstract state with visible refinement cannot
1047 -- appear in pragma [Refined_]Depends as its place
1048 -- must be taken by some of its constituents
1049 -- (SPARK RM 6.1.4(7)).
1051 elsif Has_Visible_Refinement
(Item_Id
) then
1053 ("cannot mention state & in dependence relation",
1055 SPARK_Msg_N
("\use its constituents instead", Item
);
1058 -- If the reference to the abstract state appears in
1059 -- an enclosing package body that will eventually
1060 -- refine the state, record the reference for future
1064 Record_Possible_Body_Reference
1065 (State_Id
=> Item_Id
,
1070 -- When the item renames an entire object, replace the
1071 -- item with a reference to the object.
1073 if Entity
(Item
) /= Item_Id
then
1075 New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
1079 -- Add the entity of the current item to the list of
1082 if Ekind
(Item_Id
) = E_Abstract_State
then
1083 Append_New_Elmt
(Item_Id
, States_Seen
);
1085 -- The variable may eventually become a constituent of a
1086 -- single protected/task type. Record the reference now
1087 -- and verify its legality when analyzing the contract of
1088 -- the variable (SPARK RM 9.3).
1090 elsif Ekind
(Item_Id
) = E_Variable
then
1091 Record_Possible_Part_Of_Reference
1096 if Ekind_In
(Item_Id
, E_Abstract_State
,
1099 and then Present
(Encapsulating_State
(Item_Id
))
1101 Append_New_Elmt
(Item_Id
, Constits_Seen
);
1104 -- All other input/output items are illegal
1105 -- (SPARK RM 6.1.5(1)).
1109 ("item must denote parameter, variable, state or "
1110 & "current instance of concurrent type", Item
);
1113 -- All other input/output items are illegal
1114 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1118 ("item must denote parameter, variable, state or current "
1119 & "instance of concurrent type", Item
);
1122 end Analyze_Input_Output
;
1130 Non_Null_Output_Seen
: Boolean := False;
1131 -- Flag used to check the legality of an output list
1133 -- Start of processing for Analyze_Dependency_Clause
1136 Inputs
:= Expression
(Clause
);
1139 -- An input list with a self-dependency appears as operator "+" where
1140 -- the actuals inputs are the right operand.
1142 if Nkind
(Inputs
) = N_Op_Plus
then
1143 Inputs
:= Right_Opnd
(Inputs
);
1147 -- Process the output_list of a dependency_clause
1149 Output
:= First
(Choices
(Clause
));
1150 while Present
(Output
) loop
1151 Analyze_Input_Output
1154 Self_Ref
=> Self_Ref
,
1156 Seen
=> All_Outputs_Seen
,
1157 Null_Seen
=> Null_Output_Seen
,
1158 Non_Null_Seen
=> Non_Null_Output_Seen
);
1163 -- Process the input_list of a dependency_clause
1165 Analyze_Input_List
(Inputs
);
1166 end Analyze_Dependency_Clause
;
1168 ---------------------------
1169 -- Check_Function_Return --
1170 ---------------------------
1172 procedure Check_Function_Return
is
1174 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
1175 and then not Result_Seen
1178 ("result of & must appear in exactly one output list",
1181 end Check_Function_Return
;
1187 procedure Check_Role
1189 Item_Id
: Entity_Id
;
1194 (Item_Is_Input
: out Boolean;
1195 Item_Is_Output
: out Boolean);
1196 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1197 -- Item_Is_Output are set depending on the role.
1199 procedure Role_Error
1200 (Item_Is_Input
: Boolean;
1201 Item_Is_Output
: Boolean);
1202 -- Emit an error message concerning the incorrect use of Item in
1203 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1204 -- denote whether the item is an input and/or an output.
1211 (Item_Is_Input
: out Boolean;
1212 Item_Is_Output
: out Boolean)
1215 case Ekind
(Item_Id
) is
1219 when E_Abstract_State
=>
1221 -- When pragma Global is present it determines the mode of
1222 -- the abstract state.
1225 Item_Is_Input
:= Appears_In
(Subp_Inputs
, Item_Id
);
1226 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1228 -- Otherwise the state has a default IN OUT mode, because it
1229 -- behaves as a variable.
1232 Item_Is_Input
:= True;
1233 Item_Is_Output
:= True;
1236 -- Constants and IN parameters
1239 | E_Generic_In_Parameter
1243 -- When pragma Global is present it determines the mode
1244 -- of constant objects as inputs (and such objects cannot
1245 -- appear as outputs in the Global contract).
1248 Item_Is_Input
:= Appears_In
(Subp_Inputs
, Item_Id
);
1250 Item_Is_Input
:= True;
1253 Item_Is_Output
:= False;
1255 -- Variables and IN OUT parameters
1257 when E_Generic_In_Out_Parameter
1258 | E_In_Out_Parameter
1261 -- When pragma Global is present it determines the mode of
1266 -- A variable has mode IN when its type is unconstrained
1267 -- or tagged because array bounds, discriminants or tags
1271 Appears_In
(Subp_Inputs
, Item_Id
)
1272 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1274 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1276 -- Otherwise the variable has a default IN OUT mode
1279 Item_Is_Input
:= True;
1280 Item_Is_Output
:= True;
1283 when E_Out_Parameter
=>
1285 -- An OUT parameter of the related subprogram; it cannot
1286 -- appear in Global.
1288 if Scope
(Item_Id
) = Spec_Id
then
1290 -- The parameter has mode IN if its type is unconstrained
1291 -- or tagged because array bounds, discriminants or tags
1295 Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1297 Item_Is_Output
:= True;
1299 -- An OUT parameter of an enclosing subprogram; it can
1300 -- appear in Global and behaves as a read-write variable.
1303 -- When pragma Global is present it determines the mode
1308 -- A variable has mode IN when its type is
1309 -- unconstrained or tagged because array
1310 -- bounds, discriminants or tags can be read.
1313 Appears_In
(Subp_Inputs
, Item_Id
)
1314 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1316 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1318 -- Otherwise the variable has a default IN OUT mode
1321 Item_Is_Input
:= True;
1322 Item_Is_Output
:= True;
1328 when E_Protected_Type
=>
1331 -- A variable has mode IN when its type is unconstrained
1332 -- or tagged because array bounds, discriminants or tags
1336 Appears_In
(Subp_Inputs
, Item_Id
)
1337 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1339 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1342 -- A protected type acts as a formal parameter of mode IN
1343 -- when it applies to a protected function.
1345 if Ekind
(Spec_Id
) = E_Function
then
1346 Item_Is_Input
:= True;
1347 Item_Is_Output
:= False;
1349 -- Otherwise the protected type acts as a formal of mode
1353 Item_Is_Input
:= True;
1354 Item_Is_Output
:= True;
1362 -- When pragma Global is present it determines the mode of
1367 Appears_In
(Subp_Inputs
, Item_Id
)
1368 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1370 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1372 -- Otherwise task types act as IN OUT parameters
1375 Item_Is_Input
:= True;
1376 Item_Is_Output
:= True;
1380 raise Program_Error
;
1388 procedure Role_Error
1389 (Item_Is_Input
: Boolean;
1390 Item_Is_Output
: Boolean)
1392 Error_Msg
: Name_Id
;
1397 -- When the item is not part of the input and the output set of
1398 -- the related subprogram, then it appears as extra in pragma
1399 -- [Refined_]Depends.
1401 if not Item_Is_Input
and then not Item_Is_Output
then
1402 Add_Item_To_Name_Buffer
(Item_Id
);
1403 Add_Str_To_Name_Buffer
1404 (" & cannot appear in dependence relation");
1406 Error_Msg
:= Name_Find
;
1407 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1409 Error_Msg_Name_1
:= Chars
(Spec_Id
);
1411 (Fix_Msg
(Spec_Id
, "\& is not part of the input or output "
1412 & "set of subprogram %"), Item
, Item_Id
);
1414 -- The mode of the item and its role in pragma [Refined_]Depends
1415 -- are in conflict. Construct a detailed message explaining the
1416 -- illegality (SPARK RM 6.1.5(5-6)).
1419 if Item_Is_Input
then
1420 Add_Str_To_Name_Buffer
("read-only");
1422 Add_Str_To_Name_Buffer
("write-only");
1425 Add_Char_To_Name_Buffer
(' ');
1426 Add_Item_To_Name_Buffer
(Item_Id
);
1427 Add_Str_To_Name_Buffer
(" & cannot appear as ");
1429 if Item_Is_Input
then
1430 Add_Str_To_Name_Buffer
("output");
1432 Add_Str_To_Name_Buffer
("input");
1435 Add_Str_To_Name_Buffer
(" in dependence relation");
1436 Error_Msg
:= Name_Find
;
1437 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1443 Item_Is_Input
: Boolean;
1444 Item_Is_Output
: Boolean;
1446 -- Start of processing for Check_Role
1449 Find_Role
(Item_Is_Input
, Item_Is_Output
);
1454 if not Item_Is_Input
then
1455 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1458 -- Self-referential item
1461 if not Item_Is_Input
or else not Item_Is_Output
then
1462 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1467 elsif not Item_Is_Output
then
1468 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1476 procedure Check_Usage
1477 (Subp_Items
: Elist_Id
;
1478 Used_Items
: Elist_Id
;
1481 procedure Usage_Error
(Item_Id
: Entity_Id
);
1482 -- Emit an error concerning the illegal usage of an item
1488 procedure Usage_Error
(Item_Id
: Entity_Id
) is
1489 Error_Msg
: Name_Id
;
1496 -- Unconstrained and tagged items are not part of the explicit
1497 -- input set of the related subprogram, they do not have to be
1498 -- present in a dependence relation and should not be flagged
1499 -- (SPARK RM 6.1.5(5)).
1501 if not Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1504 Add_Item_To_Name_Buffer
(Item_Id
);
1505 Add_Str_To_Name_Buffer
1506 (" & is missing from input dependence list");
1508 Error_Msg
:= Name_Find
;
1509 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1511 ("\add `null ='> &` dependency to ignore this input",
1515 -- Output case (SPARK RM 6.1.5(10))
1520 Add_Item_To_Name_Buffer
(Item_Id
);
1521 Add_Str_To_Name_Buffer
1522 (" & is missing from output dependence list");
1524 Error_Msg
:= Name_Find
;
1525 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1533 Item_Id
: Entity_Id
;
1535 -- Start of processing for Check_Usage
1538 if No
(Subp_Items
) then
1542 -- Each input or output of the subprogram must appear in a dependency
1545 Elmt
:= First_Elmt
(Subp_Items
);
1546 while Present
(Elmt
) loop
1547 Item
:= Node
(Elmt
);
1549 if Nkind
(Item
) = N_Defining_Identifier
then
1552 Item_Id
:= Entity_Of
(Item
);
1555 -- The item does not appear in a dependency
1557 if Present
(Item_Id
)
1558 and then not Contains
(Used_Items
, Item_Id
)
1560 if Is_Formal
(Item_Id
) then
1561 Usage_Error
(Item_Id
);
1563 -- The current instance of a protected type behaves as a formal
1564 -- parameter (SPARK RM 6.1.4).
1566 elsif Ekind
(Item_Id
) = E_Protected_Type
1567 or else Is_Single_Protected_Object
(Item_Id
)
1569 Usage_Error
(Item_Id
);
1571 -- The current instance of a task type behaves as a formal
1572 -- parameter (SPARK RM 6.1.4).
1574 elsif Ekind
(Item_Id
) = E_Task_Type
1575 or else Is_Single_Task_Object
(Item_Id
)
1577 -- The dependence of a task unit on itself is implicit and
1578 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1579 -- Emit an error if only one input/output is present.
1581 if Task_Input_Seen
/= Task_Output_Seen
then
1582 Usage_Error
(Item_Id
);
1585 -- States and global objects are not used properly only when
1586 -- the subprogram is subject to pragma Global.
1588 elsif Global_Seen
then
1589 Usage_Error
(Item_Id
);
1597 ----------------------
1598 -- Normalize_Clause --
1599 ----------------------
1601 procedure Normalize_Clause
(Clause
: Node_Id
) is
1602 procedure Create_Or_Modify_Clause
1608 Multiple
: Boolean);
1609 -- Create a brand new clause to represent the self-reference or
1610 -- modify the input and/or output lists of an existing clause. Output
1611 -- denotes a self-referencial output. Outputs is the output list of a
1612 -- clause. Inputs is the input list of a clause. After denotes the
1613 -- clause after which the new clause is to be inserted. Flag In_Place
1614 -- should be set when normalizing the last output of an output list.
1615 -- Flag Multiple should be set when Output comes from a list with
1618 -----------------------------
1619 -- Create_Or_Modify_Clause --
1620 -----------------------------
1622 procedure Create_Or_Modify_Clause
1630 procedure Propagate_Output
1633 -- Handle the various cases of output propagation to the input
1634 -- list. Output denotes a self-referencial output item. Inputs
1635 -- is the input list of a clause.
1637 ----------------------
1638 -- Propagate_Output --
1639 ----------------------
1641 procedure Propagate_Output
1645 function In_Input_List
1647 Inputs
: List_Id
) return Boolean;
1648 -- Determine whether a particulat item appears in the input
1649 -- list of a clause.
1655 function In_Input_List
1657 Inputs
: List_Id
) return Boolean
1662 Elmt
:= First
(Inputs
);
1663 while Present
(Elmt
) loop
1664 if Entity_Of
(Elmt
) = Item
then
1676 Output_Id
: constant Entity_Id
:= Entity_Of
(Output
);
1679 -- Start of processing for Propagate_Output
1682 -- The clause is of the form:
1684 -- (Output =>+ null)
1686 -- Remove null input and replace it with a copy of the output:
1688 -- (Output => Output)
1690 if Nkind
(Inputs
) = N_Null
then
1691 Rewrite
(Inputs
, New_Copy_Tree
(Output
));
1693 -- The clause is of the form:
1695 -- (Output =>+ (Input1, ..., InputN))
1697 -- Determine whether the output is not already mentioned in the
1698 -- input list and if not, add it to the list of inputs:
1700 -- (Output => (Output, Input1, ..., InputN))
1702 elsif Nkind
(Inputs
) = N_Aggregate
then
1703 Grouped
:= Expressions
(Inputs
);
1705 if not In_Input_List
1709 Prepend_To
(Grouped
, New_Copy_Tree
(Output
));
1712 -- The clause is of the form:
1714 -- (Output =>+ Input)
1716 -- If the input does not mention the output, group the two
1719 -- (Output => (Output, Input))
1721 elsif Entity_Of
(Inputs
) /= Output_Id
then
1723 Make_Aggregate
(Loc
,
1724 Expressions
=> New_List
(
1725 New_Copy_Tree
(Output
),
1726 New_Copy_Tree
(Inputs
))));
1728 end Propagate_Output
;
1732 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
1733 New_Clause
: Node_Id
;
1735 -- Start of processing for Create_Or_Modify_Clause
1738 -- A null output depending on itself does not require any
1741 if Nkind
(Output
) = N_Null
then
1744 -- A function result cannot depend on itself because it cannot
1745 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1747 elsif Is_Attribute_Result
(Output
) then
1748 SPARK_Msg_N
("function result cannot depend on itself", Output
);
1752 -- When performing the transformation in place, simply add the
1753 -- output to the list of inputs (if not already there). This
1754 -- case arises when dealing with the last output of an output
1755 -- list. Perform the normalization in place to avoid generating
1756 -- a malformed tree.
1759 Propagate_Output
(Output
, Inputs
);
1761 -- A list with multiple outputs is slowly trimmed until only
1762 -- one element remains. When this happens, replace aggregate
1763 -- with the element itself.
1767 Rewrite
(Outputs
, Output
);
1773 -- Unchain the output from its output list as it will appear in
1774 -- a new clause. Note that we cannot simply rewrite the output
1775 -- as null because this will violate the semantics of pragma
1780 -- Generate a new clause of the form:
1781 -- (Output => Inputs)
1784 Make_Component_Association
(Loc
,
1785 Choices
=> New_List
(Output
),
1786 Expression
=> New_Copy_Tree
(Inputs
));
1788 -- The new clause contains replicated content that has already
1789 -- been analyzed. There is not need to reanalyze or renormalize
1792 Set_Analyzed
(New_Clause
);
1795 (Output
=> First
(Choices
(New_Clause
)),
1796 Inputs
=> Expression
(New_Clause
));
1798 Insert_After
(After
, New_Clause
);
1800 end Create_Or_Modify_Clause
;
1804 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
1806 Last_Output
: Node_Id
;
1807 Next_Output
: Node_Id
;
1810 -- Start of processing for Normalize_Clause
1813 -- A self-dependency appears as operator "+". Remove the "+" from the
1814 -- tree by moving the real inputs to their proper place.
1816 if Nkind
(Expression
(Clause
)) = N_Op_Plus
then
1817 Rewrite
(Expression
(Clause
), Right_Opnd
(Expression
(Clause
)));
1818 Inputs
:= Expression
(Clause
);
1820 -- Multiple outputs appear as an aggregate
1822 if Nkind
(Outputs
) = N_Aggregate
then
1823 Last_Output
:= Last
(Expressions
(Outputs
));
1825 Output
:= First
(Expressions
(Outputs
));
1826 while Present
(Output
) loop
1828 -- Normalization may remove an output from its list,
1829 -- preserve the subsequent output now.
1831 Next_Output
:= Next
(Output
);
1833 Create_Or_Modify_Clause
1838 In_Place
=> Output
= Last_Output
,
1841 Output
:= Next_Output
;
1847 Create_Or_Modify_Clause
1856 end Normalize_Clause
;
1860 Deps
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
1861 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
1865 Last_Clause
: Node_Id
;
1866 Restore_Scope
: Boolean := False;
1868 -- Start of processing for Analyze_Depends_In_Decl_Part
1871 -- Do not analyze the pragma multiple times
1873 if Is_Analyzed_Pragma
(N
) then
1877 -- Empty dependency list
1879 if Nkind
(Deps
) = N_Null
then
1881 -- Gather all states, objects and formal parameters that the
1882 -- subprogram may depend on. These items are obtained from the
1883 -- parameter profile or pragma [Refined_]Global (if available).
1885 Collect_Subprogram_Inputs_Outputs
1886 (Subp_Id
=> Subp_Id
,
1887 Subp_Inputs
=> Subp_Inputs
,
1888 Subp_Outputs
=> Subp_Outputs
,
1889 Global_Seen
=> Global_Seen
);
1891 -- Verify that every input or output of the subprogram appear in a
1894 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1895 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1896 Check_Function_Return
;
1898 -- Dependency clauses appear as component associations of an aggregate
1900 elsif Nkind
(Deps
) = N_Aggregate
then
1902 -- Do not attempt to perform analysis of a syntactically illegal
1903 -- clause as this will lead to misleading errors.
1905 if Has_Extra_Parentheses
(Deps
) then
1909 if Present
(Component_Associations
(Deps
)) then
1910 Last_Clause
:= Last
(Component_Associations
(Deps
));
1912 -- Gather all states, objects and formal parameters that the
1913 -- subprogram may depend on. These items are obtained from the
1914 -- parameter profile or pragma [Refined_]Global (if available).
1916 Collect_Subprogram_Inputs_Outputs
1917 (Subp_Id
=> Subp_Id
,
1918 Subp_Inputs
=> Subp_Inputs
,
1919 Subp_Outputs
=> Subp_Outputs
,
1920 Global_Seen
=> Global_Seen
);
1922 -- When pragma [Refined_]Depends appears on a single concurrent
1923 -- type, it is relocated to the anonymous object.
1925 if Is_Single_Concurrent_Object
(Spec_Id
) then
1928 -- Ensure that the formal parameters are visible when analyzing
1929 -- all clauses. This falls out of the general rule of aspects
1930 -- pertaining to subprogram declarations.
1932 elsif not In_Open_Scopes
(Spec_Id
) then
1933 Restore_Scope
:= True;
1934 Push_Scope
(Spec_Id
);
1936 if Ekind
(Spec_Id
) = E_Task_Type
then
1937 if Has_Discriminants
(Spec_Id
) then
1938 Install_Discriminants
(Spec_Id
);
1941 elsif Is_Generic_Subprogram
(Spec_Id
) then
1942 Install_Generic_Formals
(Spec_Id
);
1945 Install_Formals
(Spec_Id
);
1949 Clause
:= First
(Component_Associations
(Deps
));
1950 while Present
(Clause
) loop
1951 Errors
:= Serious_Errors_Detected
;
1953 -- The normalization mechanism may create extra clauses that
1954 -- contain replicated input and output names. There is no need
1955 -- to reanalyze them.
1957 if not Analyzed
(Clause
) then
1958 Set_Analyzed
(Clause
);
1960 Analyze_Dependency_Clause
1962 Is_Last
=> Clause
= Last_Clause
);
1965 -- Do not normalize a clause if errors were detected (count
1966 -- of Serious_Errors has increased) because the inputs and/or
1967 -- outputs may denote illegal items. Normalization is disabled
1968 -- in ASIS mode as it alters the tree by introducing new nodes
1969 -- similar to expansion.
1971 if Serious_Errors_Detected
= Errors
and then not ASIS_Mode
then
1972 Normalize_Clause
(Clause
);
1978 if Restore_Scope
then
1982 -- Verify that every input or output of the subprogram appear in a
1985 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1986 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1987 Check_Function_Return
;
1989 -- The dependency list is malformed. This is a syntax error, always
1993 Error_Msg_N
("malformed dependency relation", Deps
);
1997 -- The top level dependency relation is malformed. This is a syntax
1998 -- error, always report.
2001 Error_Msg_N
("malformed dependency relation", Deps
);
2005 -- Ensure that a state and a corresponding constituent do not appear
2006 -- together in pragma [Refined_]Depends.
2008 Check_State_And_Constituent_Use
2009 (States
=> States_Seen
,
2010 Constits
=> Constits_Seen
,
2014 Set_Is_Analyzed_Pragma
(N
);
2015 end Analyze_Depends_In_Decl_Part
;
2017 --------------------------------------------
2018 -- Analyze_External_Property_In_Decl_Part --
2019 --------------------------------------------
2021 procedure Analyze_External_Property_In_Decl_Part
2023 Expr_Val
: out Boolean)
2025 Arg1
: constant Node_Id
:=
2026 First
(Pragma_Argument_Associations
(N
));
2027 Obj_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
2028 Obj_Id
: constant Entity_Id
:= Defining_Entity
(Obj_Decl
);
2034 -- Do not analyze the pragma multiple times
2036 if Is_Analyzed_Pragma
(N
) then
2040 Error_Msg_Name_1
:= Pragma_Name
(N
);
2042 -- An external property pragma must apply to an effectively volatile
2043 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2044 -- The check is performed at the end of the declarative region due to a
2045 -- possible out-of-order arrangement of pragmas:
2048 -- pragma Async_Readers (Obj);
2049 -- pragma Volatile (Obj);
2051 if not Is_Effectively_Volatile
(Obj_Id
) then
2053 ("external property % must apply to a volatile object", N
);
2056 -- Ensure that the Boolean expression (if present) is static. A missing
2057 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2061 if Present
(Arg1
) then
2062 Expr
:= Get_Pragma_Arg
(Arg1
);
2064 if Is_OK_Static_Expression
(Expr
) then
2065 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
2069 Set_Is_Analyzed_Pragma
(N
);
2070 end Analyze_External_Property_In_Decl_Part
;
2072 ---------------------------------
2073 -- Analyze_Global_In_Decl_Part --
2074 ---------------------------------
2076 procedure Analyze_Global_In_Decl_Part
(N
: Node_Id
) is
2077 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
2078 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
2079 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
2081 Constits_Seen
: Elist_Id
:= No_Elist
;
2082 -- A list containing the entities of all constituents processed so far.
2083 -- It aids in detecting illegal usage of a state and a corresponding
2084 -- constituent in pragma [Refinde_]Global.
2086 Seen
: Elist_Id
:= No_Elist
;
2087 -- A list containing the entities of all the items processed so far. It
2088 -- plays a role in detecting distinct entities.
2090 States_Seen
: Elist_Id
:= No_Elist
;
2091 -- A list containing the entities of all states processed so far. It
2092 -- helps in detecting illegal usage of a state and a corresponding
2093 -- constituent in pragma [Refined_]Global.
2095 In_Out_Seen
: Boolean := False;
2096 Input_Seen
: Boolean := False;
2097 Output_Seen
: Boolean := False;
2098 Proof_Seen
: Boolean := False;
2099 -- Flags used to verify the consistency of modes
2101 procedure Analyze_Global_List
2103 Global_Mode
: Name_Id
:= Name_Input
);
2104 -- Verify the legality of a single global list declaration. Global_Mode
2105 -- denotes the current mode in effect.
2107 -------------------------
2108 -- Analyze_Global_List --
2109 -------------------------
2111 procedure Analyze_Global_List
2113 Global_Mode
: Name_Id
:= Name_Input
)
2115 procedure Analyze_Global_Item
2117 Global_Mode
: Name_Id
);
2118 -- Verify the legality of a single global item declaration denoted by
2119 -- Item. Global_Mode denotes the current mode in effect.
2121 procedure Check_Duplicate_Mode
2123 Status
: in out Boolean);
2124 -- Flag Status denotes whether a particular mode has been seen while
2125 -- processing a global list. This routine verifies that Mode is not a
2126 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2128 procedure Check_Mode_Restriction_In_Enclosing_Context
2130 Item_Id
: Entity_Id
);
2131 -- Verify that an item of mode In_Out or Output does not appear as
2132 -- an input in the Global aspect of an enclosing subprogram or task
2133 -- unit. If this is the case, emit an error. Item and Item_Id are
2134 -- respectively the item and its entity.
2136 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
);
2137 -- Mode denotes either In_Out or Output. Depending on the kind of the
2138 -- related subprogram, emit an error if those two modes apply to a
2139 -- function (SPARK RM 6.1.4(10)).
2141 -------------------------
2142 -- Analyze_Global_Item --
2143 -------------------------
2145 procedure Analyze_Global_Item
2147 Global_Mode
: Name_Id
)
2149 Item_Id
: Entity_Id
;
2152 -- Detect one of the following cases
2154 -- with Global => (null, Name)
2155 -- with Global => (Name_1, null, Name_2)
2156 -- with Global => (Name, null)
2158 if Nkind
(Item
) = N_Null
then
2159 SPARK_Msg_N
("cannot mix null and non-null global items", Item
);
2164 Resolve_State
(Item
);
2166 -- Find the entity of the item. If this is a renaming, climb the
2167 -- renaming chain to reach the root object. Renamings of non-
2168 -- entire objects do not yield an entity (Empty).
2170 Item_Id
:= Entity_Of
(Item
);
2172 if Present
(Item_Id
) then
2174 -- A global item may denote a formal parameter of an enclosing
2175 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2176 -- provide a better error diagnostic.
2178 if Is_Formal
(Item_Id
) then
2179 if Scope
(Item_Id
) = Spec_Id
then
2181 (Fix_Msg
(Spec_Id
, "global item cannot reference "
2182 & "parameter of subprogram &"), Item
, Spec_Id
);
2186 -- A global item may denote a concurrent type as long as it is
2187 -- the current instance of an enclosing protected or task type
2188 -- (SPARK RM 6.1.4).
2190 elsif Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
2191 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
2193 -- Pragma [Refined_]Global associated with a protected
2194 -- subprogram cannot mention the current instance of a
2195 -- protected type because the instance behaves as a
2196 -- formal parameter.
2198 if Ekind
(Item_Id
) = E_Protected_Type
then
2199 if Scope
(Spec_Id
) = Item_Id
then
2200 Error_Msg_Name_1
:= Chars
(Item_Id
);
2202 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2203 & "cannot reference current instance of "
2204 & "protected type %"), Item
, Spec_Id
);
2208 -- Pragma [Refined_]Global associated with a task type
2209 -- cannot mention the current instance of a task type
2210 -- because the instance behaves as a formal parameter.
2212 else pragma Assert
(Ekind
(Item_Id
) = E_Task_Type
);
2213 if Spec_Id
= Item_Id
then
2214 Error_Msg_Name_1
:= Chars
(Item_Id
);
2216 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2217 & "cannot reference current instance of task "
2218 & "type %"), Item
, Spec_Id
);
2223 -- Otherwise the global item denotes a subtype mark that is
2224 -- not a current instance.
2228 ("invalid use of subtype mark in global list", Item
);
2232 -- A global item may denote the anonymous object created for a
2233 -- single protected/task type as long as the current instance
2234 -- is the same single type (SPARK RM 6.1.4).
2236 elsif Is_Single_Concurrent_Object
(Item_Id
)
2237 and then Is_CCT_Instance
(Etype
(Item_Id
), Spec_Id
)
2239 -- Pragma [Refined_]Global associated with a protected
2240 -- subprogram cannot mention the current instance of a
2241 -- protected type because the instance behaves as a formal
2244 if Is_Single_Protected_Object
(Item_Id
) then
2245 if Scope
(Spec_Id
) = Etype
(Item_Id
) then
2246 Error_Msg_Name_1
:= Chars
(Item_Id
);
2248 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2249 & "cannot reference current instance of protected "
2250 & "type %"), Item
, Spec_Id
);
2254 -- Pragma [Refined_]Global associated with a task type
2255 -- cannot mention the current instance of a task type
2256 -- because the instance behaves as a formal parameter.
2258 else pragma Assert
(Is_Single_Task_Object
(Item_Id
));
2259 if Spec_Id
= Item_Id
then
2260 Error_Msg_Name_1
:= Chars
(Item_Id
);
2262 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2263 & "cannot reference current instance of task "
2264 & "type %"), Item
, Spec_Id
);
2269 -- A formal object may act as a global item inside a generic
2271 elsif Is_Formal_Object
(Item_Id
) then
2274 -- The only legal references are those to abstract states,
2275 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2277 elsif not Ekind_In
(Item_Id
, E_Abstract_State
,
2283 ("global item must denote object, state or current "
2284 & "instance of concurrent type", Item
);
2288 -- State related checks
2290 if Ekind
(Item_Id
) = E_Abstract_State
then
2292 -- Package and subprogram bodies are instantiated
2293 -- individually in a separate compiler pass. Due to this
2294 -- mode of instantiation, the refinement of a state may
2295 -- no longer be visible when a subprogram body contract
2296 -- is instantiated. Since the generic template is legal,
2297 -- do not perform this check in the instance to circumvent
2300 if Is_Generic_Instance
(Spec_Id
) then
2303 -- An abstract state with visible refinement cannot appear
2304 -- in pragma [Refined_]Global as its place must be taken by
2305 -- some of its constituents (SPARK RM 6.1.4(7)).
2307 elsif Has_Visible_Refinement
(Item_Id
) then
2309 ("cannot mention state & in global refinement",
2311 SPARK_Msg_N
("\use its constituents instead", Item
);
2314 -- An external state cannot appear as a global item of a
2315 -- nonvolatile function (SPARK RM 7.1.3(8)).
2317 elsif Is_External_State
(Item_Id
)
2318 and then Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2319 and then not Is_Volatile_Function
(Spec_Id
)
2322 ("external state & cannot act as global item of "
2323 & "nonvolatile function", Item
, Item_Id
);
2326 -- If the reference to the abstract state appears in an
2327 -- enclosing package body that will eventually refine the
2328 -- state, record the reference for future checks.
2331 Record_Possible_Body_Reference
2332 (State_Id
=> Item_Id
,
2336 -- Constant related checks
2338 elsif Ekind
(Item_Id
) = E_Constant
then
2340 -- A constant is a read-only item, therefore it cannot act
2343 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2345 ("constant & cannot act as output", Item
, Item_Id
);
2349 -- Loop parameter related checks
2351 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
2353 -- A loop parameter is a read-only item, therefore it cannot
2354 -- act as an output.
2356 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2358 ("loop parameter & cannot act as output",
2363 -- Variable related checks. These are only relevant when
2364 -- SPARK_Mode is on as they are not standard Ada legality
2367 elsif SPARK_Mode
= On
2368 and then Ekind
(Item_Id
) = E_Variable
2369 and then Is_Effectively_Volatile
(Item_Id
)
2371 -- An effectively volatile object cannot appear as a global
2372 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2374 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2375 and then not Is_Volatile_Function
(Spec_Id
)
2378 ("volatile object & cannot act as global item of a "
2379 & "function", Item
, Item_Id
);
2382 -- An effectively volatile object with external property
2383 -- Effective_Reads set to True must have mode Output or
2384 -- In_Out (SPARK RM 7.1.3(10)).
2386 elsif Effective_Reads_Enabled
(Item_Id
)
2387 and then Global_Mode
= Name_Input
2390 ("volatile object & with property Effective_Reads must "
2391 & "have mode In_Out or Output", Item
, Item_Id
);
2396 -- When the item renames an entire object, replace the item
2397 -- with a reference to the object.
2399 if Entity
(Item
) /= Item_Id
then
2400 Rewrite
(Item
, New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
2404 -- Some form of illegal construct masquerading as a name
2405 -- (SPARK RM 6.1.4(4)).
2409 ("global item must denote object, state or current instance "
2410 & "of concurrent type", Item
);
2414 -- Verify that an output does not appear as an input in an
2415 -- enclosing subprogram.
2417 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2418 Check_Mode_Restriction_In_Enclosing_Context
(Item
, Item_Id
);
2421 -- The same entity might be referenced through various way.
2422 -- Check the entity of the item rather than the item itself
2423 -- (SPARK RM 6.1.4(10)).
2425 if Contains
(Seen
, Item_Id
) then
2426 SPARK_Msg_N
("duplicate global item", Item
);
2428 -- Add the entity of the current item to the list of processed
2432 Append_New_Elmt
(Item_Id
, Seen
);
2434 if Ekind
(Item_Id
) = E_Abstract_State
then
2435 Append_New_Elmt
(Item_Id
, States_Seen
);
2437 -- The variable may eventually become a constituent of a single
2438 -- protected/task type. Record the reference now and verify its
2439 -- legality when analyzing the contract of the variable
2442 elsif Ekind
(Item_Id
) = E_Variable
then
2443 Record_Possible_Part_Of_Reference
2448 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
2449 and then Present
(Encapsulating_State
(Item_Id
))
2451 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2454 end Analyze_Global_Item
;
2456 --------------------------
2457 -- Check_Duplicate_Mode --
2458 --------------------------
2460 procedure Check_Duplicate_Mode
2462 Status
: in out Boolean)
2466 SPARK_Msg_N
("duplicate global mode", Mode
);
2470 end Check_Duplicate_Mode
;
2472 -------------------------------------------------
2473 -- Check_Mode_Restriction_In_Enclosing_Context --
2474 -------------------------------------------------
2476 procedure Check_Mode_Restriction_In_Enclosing_Context
2478 Item_Id
: Entity_Id
)
2480 Context
: Entity_Id
;
2482 Inputs
: Elist_Id
:= No_Elist
;
2483 Outputs
: Elist_Id
:= No_Elist
;
2486 -- Traverse the scope stack looking for enclosing subprograms or
2487 -- tasks subject to pragma [Refined_]Global.
2489 Context
:= Scope
(Subp_Id
);
2490 while Present
(Context
) and then Context
/= Standard_Standard
loop
2492 -- For a single task type, retrieve the corresponding object to
2493 -- which pragma [Refined_]Global is attached.
2495 if Ekind
(Context
) = E_Task_Type
2496 and then Is_Single_Concurrent_Type
(Context
)
2498 Context
:= Anonymous_Object
(Context
);
2501 if (Is_Subprogram
(Context
)
2502 or else Ekind
(Context
) = E_Task_Type
2503 or else Is_Single_Task_Object
(Context
))
2505 (Present
(Get_Pragma
(Context
, Pragma_Global
))
2507 Present
(Get_Pragma
(Context
, Pragma_Refined_Global
)))
2509 Collect_Subprogram_Inputs_Outputs
2510 (Subp_Id
=> Context
,
2511 Subp_Inputs
=> Inputs
,
2512 Subp_Outputs
=> Outputs
,
2513 Global_Seen
=> Dummy
);
2515 -- The item is classified as In_Out or Output but appears as
2516 -- an Input in an enclosing subprogram or task unit (SPARK
2519 if Appears_In
(Inputs
, Item_Id
)
2520 and then not Appears_In
(Outputs
, Item_Id
)
2523 ("global item & cannot have mode In_Out or Output",
2526 if Is_Subprogram
(Context
) then
2528 (Fix_Msg
(Subp_Id
, "\item already appears as input "
2529 & "of subprogram &"), Item
, Context
);
2532 (Fix_Msg
(Subp_Id
, "\item already appears as input "
2533 & "of task &"), Item
, Context
);
2536 -- Stop the traversal once an error has been detected
2542 Context
:= Scope
(Context
);
2544 end Check_Mode_Restriction_In_Enclosing_Context
;
2546 ----------------------------------------
2547 -- Check_Mode_Restriction_In_Function --
2548 ----------------------------------------
2550 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
) is
2552 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
2554 ("global mode & is not applicable to functions", Mode
);
2556 end Check_Mode_Restriction_In_Function
;
2564 -- Start of processing for Analyze_Global_List
2567 if Nkind
(List
) = N_Null
then
2568 Set_Analyzed
(List
);
2570 -- Single global item declaration
2572 elsif Nkind_In
(List
, N_Expanded_Name
,
2574 N_Selected_Component
)
2576 Analyze_Global_Item
(List
, Global_Mode
);
2578 -- Simple global list or moded global list declaration
2580 elsif Nkind
(List
) = N_Aggregate
then
2581 Set_Analyzed
(List
);
2583 -- The declaration of a simple global list appear as a collection
2586 if Present
(Expressions
(List
)) then
2587 if Present
(Component_Associations
(List
)) then
2589 ("cannot mix moded and non-moded global lists", List
);
2592 Item
:= First
(Expressions
(List
));
2593 while Present
(Item
) loop
2594 Analyze_Global_Item
(Item
, Global_Mode
);
2598 -- The declaration of a moded global list appears as a collection
2599 -- of component associations where individual choices denote
2602 elsif Present
(Component_Associations
(List
)) then
2603 if Present
(Expressions
(List
)) then
2605 ("cannot mix moded and non-moded global lists", List
);
2608 Assoc
:= First
(Component_Associations
(List
));
2609 while Present
(Assoc
) loop
2610 Mode
:= First
(Choices
(Assoc
));
2612 if Nkind
(Mode
) = N_Identifier
then
2613 if Chars
(Mode
) = Name_In_Out
then
2614 Check_Duplicate_Mode
(Mode
, In_Out_Seen
);
2615 Check_Mode_Restriction_In_Function
(Mode
);
2617 elsif Chars
(Mode
) = Name_Input
then
2618 Check_Duplicate_Mode
(Mode
, Input_Seen
);
2620 elsif Chars
(Mode
) = Name_Output
then
2621 Check_Duplicate_Mode
(Mode
, Output_Seen
);
2622 Check_Mode_Restriction_In_Function
(Mode
);
2624 elsif Chars
(Mode
) = Name_Proof_In
then
2625 Check_Duplicate_Mode
(Mode
, Proof_Seen
);
2628 SPARK_Msg_N
("invalid mode selector", Mode
);
2632 SPARK_Msg_N
("invalid mode selector", Mode
);
2635 -- Items in a moded list appear as a collection of
2636 -- expressions. Reuse the existing machinery to analyze
2640 (List
=> Expression
(Assoc
),
2641 Global_Mode
=> Chars
(Mode
));
2649 raise Program_Error
;
2652 -- Any other attempt to declare a global item is illegal. This is a
2653 -- syntax error, always report.
2656 Error_Msg_N
("malformed global list", List
);
2658 end Analyze_Global_List
;
2662 Items
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
2664 Restore_Scope
: Boolean := False;
2666 -- Start of processing for Analyze_Global_In_Decl_Part
2669 -- Do not analyze the pragma multiple times
2671 if Is_Analyzed_Pragma
(N
) then
2675 -- There is nothing to be done for a null global list
2677 if Nkind
(Items
) = N_Null
then
2678 Set_Analyzed
(Items
);
2680 -- Analyze the various forms of global lists and items. Note that some
2681 -- of these may be malformed in which case the analysis emits error
2685 -- When pragma [Refined_]Global appears on a single concurrent type,
2686 -- it is relocated to the anonymous object.
2688 if Is_Single_Concurrent_Object
(Spec_Id
) then
2691 -- Ensure that the formal parameters are visible when processing an
2692 -- item. This falls out of the general rule of aspects pertaining to
2693 -- subprogram declarations.
2695 elsif not In_Open_Scopes
(Spec_Id
) then
2696 Restore_Scope
:= True;
2697 Push_Scope
(Spec_Id
);
2699 if Ekind
(Spec_Id
) = E_Task_Type
then
2700 if Has_Discriminants
(Spec_Id
) then
2701 Install_Discriminants
(Spec_Id
);
2704 elsif Is_Generic_Subprogram
(Spec_Id
) then
2705 Install_Generic_Formals
(Spec_Id
);
2708 Install_Formals
(Spec_Id
);
2712 Analyze_Global_List
(Items
);
2714 if Restore_Scope
then
2719 -- Ensure that a state and a corresponding constituent do not appear
2720 -- together in pragma [Refined_]Global.
2722 Check_State_And_Constituent_Use
2723 (States
=> States_Seen
,
2724 Constits
=> Constits_Seen
,
2727 Set_Is_Analyzed_Pragma
(N
);
2728 end Analyze_Global_In_Decl_Part
;
2730 --------------------------------------------
2731 -- Analyze_Initial_Condition_In_Decl_Part --
2732 --------------------------------------------
2734 -- WARNING: This routine manages Ghost regions. Return statements must be
2735 -- replaced by gotos which jump to the end of the routine and restore the
2738 procedure Analyze_Initial_Condition_In_Decl_Part
(N
: Node_Id
) is
2739 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2740 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2741 Expr
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
2743 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2744 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
2745 -- Save the Ghost-related attributes to restore on exit
2748 -- Do not analyze the pragma multiple times
2750 if Is_Analyzed_Pragma
(N
) then
2754 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2755 -- analysis of the pragma, the Ghost mode at point of declaration and
2756 -- point of analysis may not necessarily be the same. Use the mode in
2757 -- effect at the point of declaration.
2761 -- The expression is preanalyzed because it has not been moved to its
2762 -- final place yet. A direct analysis may generate side effects and this
2763 -- is not desired at this point.
2765 Preanalyze_Assert_Expression
(Expr
, Standard_Boolean
);
2766 Set_Is_Analyzed_Pragma
(N
);
2768 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
2769 end Analyze_Initial_Condition_In_Decl_Part
;
2771 --------------------------------------
2772 -- Analyze_Initializes_In_Decl_Part --
2773 --------------------------------------
2775 procedure Analyze_Initializes_In_Decl_Part
(N
: Node_Id
) is
2776 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2777 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2779 Constits_Seen
: Elist_Id
:= No_Elist
;
2780 -- A list containing the entities of all constituents processed so far.
2781 -- It aids in detecting illegal usage of a state and a corresponding
2782 -- constituent in pragma Initializes.
2784 Items_Seen
: Elist_Id
:= No_Elist
;
2785 -- A list of all initialization items processed so far. This list is
2786 -- used to detect duplicate items.
2788 States_And_Objs
: Elist_Id
:= No_Elist
;
2789 -- A list of all abstract states and objects declared in the visible
2790 -- declarations of the related package. This list is used to detect the
2791 -- legality of initialization items.
2793 States_Seen
: Elist_Id
:= No_Elist
;
2794 -- A list containing the entities of all states processed so far. It
2795 -- helps in detecting illegal usage of a state and a corresponding
2796 -- constituent in pragma Initializes.
2798 procedure Analyze_Initialization_Item
(Item
: Node_Id
);
2799 -- Verify the legality of a single initialization item
2801 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
);
2802 -- Verify the legality of a single initialization item followed by a
2803 -- list of input items.
2805 procedure Collect_States_And_Objects
;
2806 -- Inspect the visible declarations of the related package and gather
2807 -- the entities of all abstract states and objects in States_And_Objs.
2809 ---------------------------------
2810 -- Analyze_Initialization_Item --
2811 ---------------------------------
2813 procedure Analyze_Initialization_Item
(Item
: Node_Id
) is
2814 Item_Id
: Entity_Id
;
2818 Resolve_State
(Item
);
2820 if Is_Entity_Name
(Item
) then
2821 Item_Id
:= Entity_Of
(Item
);
2823 if Present
(Item_Id
)
2824 and then Ekind_In
(Item_Id
, E_Abstract_State
,
2828 -- When the initialization item is undefined, it appears as
2829 -- Any_Id. Do not continue with the analysis of the item.
2831 if Item_Id
= Any_Id
then
2834 -- The state or variable must be declared in the visible
2835 -- declarations of the package (SPARK RM 7.1.5(7)).
2837 elsif not Contains
(States_And_Objs
, Item_Id
) then
2838 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2840 ("initialization item & must appear in the visible "
2841 & "declarations of package %", Item
, Item_Id
);
2843 -- Detect a duplicate use of the same initialization item
2844 -- (SPARK RM 7.1.5(5)).
2846 elsif Contains
(Items_Seen
, Item_Id
) then
2847 SPARK_Msg_N
("duplicate initialization item", Item
);
2849 -- The item is legal, add it to the list of processed states
2853 Append_New_Elmt
(Item_Id
, Items_Seen
);
2855 if Ekind
(Item_Id
) = E_Abstract_State
then
2856 Append_New_Elmt
(Item_Id
, States_Seen
);
2859 if Present
(Encapsulating_State
(Item_Id
)) then
2860 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2864 -- The item references something that is not a state or object
2865 -- (SPARK RM 7.1.5(3)).
2869 ("initialization item must denote object or state", Item
);
2872 -- Some form of illegal construct masquerading as a name
2873 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2877 ("initialization item must denote object or state", Item
);
2879 end Analyze_Initialization_Item
;
2881 ---------------------------------------------
2882 -- Analyze_Initialization_Item_With_Inputs --
2883 ---------------------------------------------
2885 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
) is
2886 Inputs_Seen
: Elist_Id
:= No_Elist
;
2887 -- A list of all inputs processed so far. This list is used to detect
2888 -- duplicate uses of an input.
2890 Non_Null_Seen
: Boolean := False;
2891 Null_Seen
: Boolean := False;
2892 -- Flags used to check the legality of an input list
2894 procedure Analyze_Input_Item
(Input
: Node_Id
);
2895 -- Verify the legality of a single input item
2897 ------------------------
2898 -- Analyze_Input_Item --
2899 ------------------------
2901 procedure Analyze_Input_Item
(Input
: Node_Id
) is
2902 Input_Id
: Entity_Id
;
2907 if Nkind
(Input
) = N_Null
then
2910 ("multiple null initializations not allowed", Item
);
2912 elsif Non_Null_Seen
then
2914 ("cannot mix null and non-null initialization item", Item
);
2922 Non_Null_Seen
:= True;
2926 ("cannot mix null and non-null initialization item", Item
);
2930 Resolve_State
(Input
);
2932 if Is_Entity_Name
(Input
) then
2933 Input_Id
:= Entity_Of
(Input
);
2935 if Present
(Input_Id
)
2936 and then Ekind_In
(Input_Id
, E_Abstract_State
,
2938 E_Generic_In_Out_Parameter
,
2939 E_Generic_In_Parameter
,
2947 -- The input cannot denote states or objects declared
2948 -- within the related package (SPARK RM 7.1.5(4)).
2950 if Within_Scope
(Input_Id
, Current_Scope
) then
2952 -- Do not consider generic formal parameters or their
2953 -- respective mappings to generic formals. Even though
2954 -- the formals appear within the scope of the package,
2955 -- it is allowed for an initialization item to depend
2956 -- on an input item.
2958 if Ekind_In
(Input_Id
, E_Generic_In_Out_Parameter
,
2959 E_Generic_In_Parameter
)
2963 elsif Ekind_In
(Input_Id
, E_Constant
, E_Variable
)
2964 and then Present
(Corresponding_Generic_Association
2965 (Declaration_Node
(Input_Id
)))
2970 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2972 ("input item & cannot denote a visible object or "
2973 & "state of package %", Input
, Input_Id
);
2978 -- Detect a duplicate use of the same input item
2979 -- (SPARK RM 7.1.5(5)).
2981 if Contains
(Inputs_Seen
, Input_Id
) then
2982 SPARK_Msg_N
("duplicate input item", Input
);
2986 -- At this point it is known that the input is legal. Add
2987 -- it to the list of processed inputs.
2989 Append_New_Elmt
(Input_Id
, Inputs_Seen
);
2991 if Ekind
(Input_Id
) = E_Abstract_State
then
2992 Append_New_Elmt
(Input_Id
, States_Seen
);
2995 if Ekind_In
(Input_Id
, E_Abstract_State
,
2998 and then Present
(Encapsulating_State
(Input_Id
))
3000 Append_New_Elmt
(Input_Id
, Constits_Seen
);
3003 -- The input references something that is not a state or an
3004 -- object (SPARK RM 7.1.5(3)).
3008 ("input item must denote object or state", Input
);
3011 -- Some form of illegal construct masquerading as a name
3012 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
3016 ("input item must denote object or state", Input
);
3019 end Analyze_Input_Item
;
3023 Inputs
: constant Node_Id
:= Expression
(Item
);
3027 Name_Seen
: Boolean := False;
3028 -- A flag used to detect multiple item names
3030 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3033 -- Inspect the name of an item with inputs
3035 Elmt
:= First
(Choices
(Item
));
3036 while Present
(Elmt
) loop
3038 SPARK_Msg_N
("only one item allowed in initialization", Elmt
);
3041 Analyze_Initialization_Item
(Elmt
);
3047 -- Multiple input items appear as an aggregate
3049 if Nkind
(Inputs
) = N_Aggregate
then
3050 if Present
(Expressions
(Inputs
)) then
3051 Input
:= First
(Expressions
(Inputs
));
3052 while Present
(Input
) loop
3053 Analyze_Input_Item
(Input
);
3058 if Present
(Component_Associations
(Inputs
)) then
3060 ("inputs must appear in named association form", Inputs
);
3063 -- Single input item
3066 Analyze_Input_Item
(Inputs
);
3068 end Analyze_Initialization_Item_With_Inputs
;
3070 --------------------------------
3071 -- Collect_States_And_Objects --
3072 --------------------------------
3074 procedure Collect_States_And_Objects
is
3075 Pack_Spec
: constant Node_Id
:= Specification
(Pack_Decl
);
3079 -- Collect the abstract states defined in the package (if any)
3081 if Present
(Abstract_States
(Pack_Id
)) then
3082 States_And_Objs
:= New_Copy_Elist
(Abstract_States
(Pack_Id
));
3085 -- Collect all objects that appear in the visible declarations of the
3088 if Present
(Visible_Declarations
(Pack_Spec
)) then
3089 Decl
:= First
(Visible_Declarations
(Pack_Spec
));
3090 while Present
(Decl
) loop
3091 if Comes_From_Source
(Decl
)
3092 and then Nkind_In
(Decl
, N_Object_Declaration
,
3093 N_Object_Renaming_Declaration
)
3095 Append_New_Elmt
(Defining_Entity
(Decl
), States_And_Objs
);
3097 elsif Is_Single_Concurrent_Type_Declaration
(Decl
) then
3099 (Anonymous_Object
(Defining_Entity
(Decl
)),
3106 end Collect_States_And_Objects
;
3110 Inits
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
3113 -- Start of processing for Analyze_Initializes_In_Decl_Part
3116 -- Do not analyze the pragma multiple times
3118 if Is_Analyzed_Pragma
(N
) then
3122 -- Nothing to do when the initialization list is empty
3124 if Nkind
(Inits
) = N_Null
then
3128 -- Single and multiple initialization clauses appear as an aggregate. If
3129 -- this is not the case, then either the parser or the analysis of the
3130 -- pragma failed to produce an aggregate.
3132 pragma Assert
(Nkind
(Inits
) = N_Aggregate
);
3134 -- Initialize the various lists used during analysis
3136 Collect_States_And_Objects
;
3138 if Present
(Expressions
(Inits
)) then
3139 Init
:= First
(Expressions
(Inits
));
3140 while Present
(Init
) loop
3141 Analyze_Initialization_Item
(Init
);
3146 if Present
(Component_Associations
(Inits
)) then
3147 Init
:= First
(Component_Associations
(Inits
));
3148 while Present
(Init
) loop
3149 Analyze_Initialization_Item_With_Inputs
(Init
);
3154 -- Ensure that a state and a corresponding constituent do not appear
3155 -- together in pragma Initializes.
3157 Check_State_And_Constituent_Use
3158 (States
=> States_Seen
,
3159 Constits
=> Constits_Seen
,
3162 Set_Is_Analyzed_Pragma
(N
);
3163 end Analyze_Initializes_In_Decl_Part
;
3165 ---------------------
3166 -- Analyze_Part_Of --
3167 ---------------------
3169 procedure Analyze_Part_Of
3171 Item_Id
: Entity_Id
;
3173 Encap_Id
: out Entity_Id
;
3174 Legal
: out Boolean)
3176 procedure Check_Part_Of_Abstract_State
;
3177 pragma Inline
(Check_Part_Of_Abstract_State
);
3178 -- Verify the legality of indicator Part_Of when the encapsulator is an
3181 procedure Check_Part_Of_Concurrent_Type
;
3182 pragma Inline
(Check_Part_Of_Concurrent_Type
);
3183 -- Verify the legality of indicator Part_Of when the encapsulator is a
3184 -- single concurrent type.
3186 ----------------------------------
3187 -- Check_Part_Of_Abstract_State --
3188 ----------------------------------
3190 procedure Check_Part_Of_Abstract_State
is
3191 Pack_Id
: Entity_Id
;
3192 Placement
: State_Space_Kind
;
3193 Parent_Unit
: Entity_Id
;
3196 -- Determine where the object, package instantiation or state lives
3197 -- with respect to the enclosing packages or package bodies.
3199 Find_Placement_In_State_Space
3200 (Item_Id
=> Item_Id
,
3201 Placement
=> Placement
,
3202 Pack_Id
=> Pack_Id
);
3204 -- The item appears in a non-package construct with a declarative
3205 -- part (subprogram, block, etc). As such, the item is not allowed
3206 -- to be a part of an encapsulating state because the item is not
3209 if Placement
= Not_In_Package
then
3211 ("indicator Part_Of cannot appear in this context "
3212 & "(SPARK RM 7.2.6(5))", Indic
);
3214 Error_Msg_Name_1
:= Chars
(Scope
(Encap_Id
));
3216 ("\& is not part of the hidden state of package %",
3220 -- The item appears in the visible state space of some package. In
3221 -- general this scenario does not warrant Part_Of except when the
3222 -- package is a nongeneric private child unit and the encapsulating
3223 -- state is declared in a parent unit or a public descendant of that
3226 elsif Placement
= Visible_State_Space
then
3227 if Is_Child_Unit
(Pack_Id
)
3228 and then not Is_Generic_Unit
(Pack_Id
)
3229 and then Is_Private_Descendant
(Pack_Id
)
3231 -- A variable or state abstraction which is part of the visible
3232 -- state of a nongeneric private child unit or its public
3233 -- descendants must have its Part_Of indicator specified. The
3234 -- Part_Of indicator must denote a state declared by either the
3235 -- parent unit of the private unit or by a public descendant of
3236 -- that parent unit.
3238 -- Find the nearest private ancestor (which can be the current
3241 Parent_Unit
:= Pack_Id
;
3242 while Present
(Parent_Unit
) loop
3245 (Parent
(Unit_Declaration_Node
(Parent_Unit
)));
3246 Parent_Unit
:= Scope
(Parent_Unit
);
3249 Parent_Unit
:= Scope
(Parent_Unit
);
3251 if not Is_Child_Or_Sibling
(Pack_Id
, Scope
(Encap_Id
)) then
3253 ("indicator Part_Of must denote abstract state of & or of "
3254 & "its public descendant (SPARK RM 7.2.6(3))",
3255 Indic
, Parent_Unit
);
3258 elsif Scope
(Encap_Id
) = Parent_Unit
3260 (Is_Ancestor_Package
(Parent_Unit
, Scope
(Encap_Id
))
3261 and then not Is_Private_Descendant
(Scope
(Encap_Id
)))
3267 ("indicator Part_Of must denote abstract state of & or of "
3268 & "its public descendant (SPARK RM 7.2.6(3))",
3269 Indic
, Parent_Unit
);
3273 -- Indicator Part_Of is not needed when the related package is
3274 -- not a nongeneric private child unit or a public descendant
3279 ("indicator Part_Of cannot appear in this context "
3280 & "(SPARK RM 7.2.6(5))", Indic
);
3282 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3284 ("\& is declared in the visible part of package %",
3289 -- When the item appears in the private state space of a package, the
3290 -- encapsulating state must be declared in the same package.
3292 elsif Placement
= Private_State_Space
then
3293 if Scope
(Encap_Id
) /= Pack_Id
then
3295 ("indicator Part_Of must denote an abstract state of "
3296 & "package & (SPARK RM 7.2.6(2))", Indic
, Pack_Id
);
3298 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3300 ("\& is declared in the private part of package %",
3305 -- Items declared in the body state space of a package do not need
3306 -- Part_Of indicators as the refinement has already been seen.
3310 ("indicator Part_Of cannot appear in this context "
3311 & "(SPARK RM 7.2.6(5))", Indic
);
3313 if Scope
(Encap_Id
) = Pack_Id
then
3314 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3316 ("\& is declared in the body of package %", Indic
, Item_Id
);
3322 -- At this point it is known that the Part_Of indicator is legal
3325 end Check_Part_Of_Abstract_State
;
3327 -----------------------------------
3328 -- Check_Part_Of_Concurrent_Type --
3329 -----------------------------------
3331 procedure Check_Part_Of_Concurrent_Type
is
3332 function In_Proper_Order
3334 Second
: Node_Id
) return Boolean;
3335 pragma Inline
(In_Proper_Order
);
3336 -- Determine whether node First precedes node Second
3338 procedure Placement_Error
;
3339 pragma Inline
(Placement_Error
);
3340 -- Emit an error concerning the illegal placement of the item with
3341 -- respect to the single concurrent type.
3343 ---------------------
3344 -- In_Proper_Order --
3345 ---------------------
3347 function In_Proper_Order
3349 Second
: Node_Id
) return Boolean
3354 if List_Containing
(First
) = List_Containing
(Second
) then
3356 while Present
(N
) loop
3366 end In_Proper_Order
;
3368 ---------------------
3369 -- Placement_Error --
3370 ---------------------
3372 procedure Placement_Error
is
3375 ("indicator Part_Of must denote a previously declared single "
3376 & "protected type or single task type", Encap
);
3377 end Placement_Error
;
3381 Conc_Typ
: constant Entity_Id
:= Etype
(Encap_Id
);
3382 Encap_Decl
: constant Node_Id
:= Declaration_Node
(Encap_Id
);
3383 Encap_Context
: constant Node_Id
:= Parent
(Encap_Decl
);
3385 Item_Context
: Node_Id
;
3386 Item_Decl
: Node_Id
;
3387 Prv_Decls
: List_Id
;
3388 Vis_Decls
: List_Id
;
3390 -- Start of processing for Check_Part_Of_Concurrent_Type
3393 -- Only abstract states and variables can act as constituents of an
3394 -- encapsulating single concurrent type.
3396 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
3399 -- The constituent is a constant
3401 elsif Ekind
(Item_Id
) = E_Constant
then
3402 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3404 (Fix_Msg
(Conc_Typ
, "constant & cannot act as constituent of "
3405 & "single protected type %"), Indic
, Item_Id
);
3408 -- The constituent is a package instantiation
3411 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3413 (Fix_Msg
(Conc_Typ
, "package instantiation & cannot act as "
3414 & "constituent of single protected type %"), Indic
, Item_Id
);
3418 -- When the item denotes an abstract state of a nested package, use
3419 -- the declaration of the package to detect proper placement.
3424 -- with Abstract_State => (State with Part_Of => T)
3426 if Ekind
(Item_Id
) = E_Abstract_State
then
3427 Item_Decl
:= Unit_Declaration_Node
(Scope
(Item_Id
));
3429 Item_Decl
:= Declaration_Node
(Item_Id
);
3432 Item_Context
:= Parent
(Item_Decl
);
3434 -- The item and the single concurrent type must appear in the same
3435 -- declarative region, with the item following the declaration of
3436 -- the single concurrent type (SPARK RM 9(3)).
3438 if Item_Context
= Encap_Context
then
3439 if Nkind_In
(Item_Context
, N_Package_Specification
,
3440 N_Protected_Definition
,
3443 Prv_Decls
:= Private_Declarations
(Item_Context
);
3444 Vis_Decls
:= Visible_Declarations
(Item_Context
);
3446 -- The placement is OK when the single concurrent type appears
3447 -- within the visible declarations and the item in the private
3453 -- Constit : ... with Part_Of => PO;
3456 if List_Containing
(Encap_Decl
) = Vis_Decls
3457 and then List_Containing
(Item_Decl
) = Prv_Decls
3461 -- The placement is illegal when the item appears within the
3462 -- visible declarations and the single concurrent type is in
3463 -- the private declarations.
3466 -- Constit : ... with Part_Of => PO;
3471 elsif List_Containing
(Item_Decl
) = Vis_Decls
3472 and then List_Containing
(Encap_Decl
) = Prv_Decls
3477 -- Otherwise both the item and the single concurrent type are
3478 -- in the same list. Ensure that the declaration of the single
3479 -- concurrent type precedes that of the item.
3481 elsif not In_Proper_Order
3482 (First
=> Encap_Decl
,
3483 Second
=> Item_Decl
)
3489 -- Otherwise both the item and the single concurrent type are
3490 -- in the same list. Ensure that the declaration of the single
3491 -- concurrent type precedes that of the item.
3493 elsif not In_Proper_Order
3494 (First
=> Encap_Decl
,
3495 Second
=> Item_Decl
)
3501 -- Otherwise the item and the single concurrent type reside within
3502 -- unrelated regions.
3505 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3507 (Fix_Msg
(Conc_Typ
, "constituent & must be declared "
3508 & "immediately within the same region as single protected "
3509 & "type %"), Indic
, Item_Id
);
3513 -- At this point it is known that the Part_Of indicator is legal
3516 end Check_Part_Of_Concurrent_Type
;
3518 -- Start of processing for Analyze_Part_Of
3521 -- Assume that the indicator is illegal
3526 if Nkind_In
(Encap
, N_Expanded_Name
,
3528 N_Selected_Component
)
3531 Resolve_State
(Encap
);
3533 Encap_Id
:= Entity
(Encap
);
3535 -- The encapsulator is an abstract state
3537 if Ekind
(Encap_Id
) = E_Abstract_State
then
3540 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3542 elsif Is_Single_Concurrent_Object
(Encap_Id
) then
3545 -- Otherwise the encapsulator is not a legal choice
3549 ("indicator Part_Of must denote abstract state, single "
3550 & "protected type or single task type", Encap
);
3554 -- This is a syntax error, always report
3558 ("indicator Part_Of must denote abstract state, single protected "
3559 & "type or single task type", Encap
);
3563 -- Catch a case where indicator Part_Of denotes the abstract view of a
3564 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3566 if From_Limited_With
(Encap_Id
)
3567 and then Present
(Non_Limited_View
(Encap_Id
))
3568 and then Ekind
(Non_Limited_View
(Encap_Id
)) = E_Variable
3570 SPARK_Msg_N
("indicator Part_Of must denote abstract state", Encap
);
3571 SPARK_Msg_N
("\& denotes abstract view of object", Encap
);
3575 -- The encapsulator is an abstract state
3577 if Ekind
(Encap_Id
) = E_Abstract_State
then
3578 Check_Part_Of_Abstract_State
;
3580 -- The encapsulator is a single concurrent type
3583 Check_Part_Of_Concurrent_Type
;
3585 end Analyze_Part_Of
;
3587 ----------------------------------
3588 -- Analyze_Part_Of_In_Decl_Part --
3589 ----------------------------------
3591 procedure Analyze_Part_Of_In_Decl_Part
3593 Freeze_Id
: Entity_Id
:= Empty
)
3595 Encap
: constant Node_Id
:=
3596 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
3597 Errors
: constant Nat
:= Serious_Errors_Detected
;
3598 Var_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
3599 Var_Id
: constant Entity_Id
:= Defining_Entity
(Var_Decl
);
3600 Constits
: Elist_Id
;
3601 Encap_Id
: Entity_Id
;
3605 -- Detect any discrepancies between the placement of the variable with
3606 -- respect to general state space and the encapsulating state or single
3613 Encap_Id
=> Encap_Id
,
3616 -- The Part_Of indicator turns the variable into a constituent of the
3617 -- encapsulating state or single concurrent type.
3620 pragma Assert
(Present
(Encap_Id
));
3621 Constits
:= Part_Of_Constituents
(Encap_Id
);
3623 if No
(Constits
) then
3624 Constits
:= New_Elmt_List
;
3625 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
3628 Append_Elmt
(Var_Id
, Constits
);
3629 Set_Encapsulating_State
(Var_Id
, Encap_Id
);
3631 -- A Part_Of constituent partially refines an abstract state. This
3632 -- property does not apply to protected or task units.
3634 if Ekind
(Encap_Id
) = E_Abstract_State
then
3635 Set_Has_Partial_Visible_Refinement
(Encap_Id
);
3639 -- Emit a clarification message when the encapsulator is undefined,
3640 -- possibly due to contract freezing.
3642 if Errors
/= Serious_Errors_Detected
3643 and then Present
(Freeze_Id
)
3644 and then Has_Undefined_Reference
(Encap
)
3646 Contract_Freeze_Error
(Var_Id
, Freeze_Id
);
3648 end Analyze_Part_Of_In_Decl_Part
;
3650 --------------------
3651 -- Analyze_Pragma --
3652 --------------------
3654 procedure Analyze_Pragma
(N
: Node_Id
) is
3655 Loc
: constant Source_Ptr
:= Sloc
(N
);
3657 Pname
: Name_Id
:= Pragma_Name
(N
);
3658 -- Name of the source pragma, or name of the corresponding aspect for
3659 -- pragmas which originate in a source aspect. In the latter case, the
3660 -- name may be different from the pragma name.
3662 Prag_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Pname
);
3664 Pragma_Exit
: exception;
3665 -- This exception is used to exit pragma processing completely. It
3666 -- is used when an error is detected, and no further processing is
3667 -- required. It is also used if an earlier error has left the tree in
3668 -- a state where the pragma should not be processed.
3671 -- Number of pragma argument associations
3677 -- First four pragma arguments (pragma argument association nodes, or
3678 -- Empty if the corresponding argument does not exist).
3680 type Name_List
is array (Natural range <>) of Name_Id
;
3681 type Args_List
is array (Natural range <>) of Node_Id
;
3682 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3684 -----------------------
3685 -- Local Subprograms --
3686 -----------------------
3688 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
);
3689 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3690 -- get the given string argument, and place it in Name_Buffer, adding
3691 -- leading and trailing asterisks if they are not already present. The
3692 -- caller has already checked that Arg is a static string expression.
3694 procedure Ada_2005_Pragma
;
3695 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3696 -- Ada 95 mode, these are implementation defined pragmas, so should be
3697 -- caught by the No_Implementation_Pragmas restriction.
3699 procedure Ada_2012_Pragma
;
3700 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3701 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3702 -- should be caught by the No_Implementation_Pragmas restriction.
3704 procedure Analyze_Depends_Global
3705 (Spec_Id
: out Entity_Id
;
3706 Subp_Decl
: out Node_Id
;
3707 Legal
: out Boolean);
3708 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3709 -- legality of the placement and related context of the pragma. Spec_Id
3710 -- is the entity of the related subprogram. Subp_Decl is the declaration
3711 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3713 procedure Analyze_If_Present
(Id
: Pragma_Id
);
3714 -- Inspect the remainder of the list containing pragma N and look for
3715 -- a pragma that matches Id. If found, analyze the pragma.
3717 procedure Analyze_Pre_Post_Condition
;
3718 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3720 procedure Analyze_Refined_Depends_Global_Post
3721 (Spec_Id
: out Entity_Id
;
3722 Body_Id
: out Entity_Id
;
3723 Legal
: out Boolean);
3724 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3725 -- Refined_Global and Refined_Post. Verify the legality of the placement
3726 -- and related context of the pragma. Spec_Id is the entity of the
3727 -- related subprogram. Body_Id is the entity of the subprogram body.
3728 -- Flag Legal is set when the pragma is legal.
3730 procedure Analyze_Unmodified_Or_Unused
(Is_Unused
: Boolean := False);
3731 -- Perform full analysis of pragma Unmodified and the write aspect of
3732 -- pragma Unused. Flag Is_Unused should be set when verifying the
3733 -- semantics of pragma Unused.
3735 procedure Analyze_Unreferenced_Or_Unused
(Is_Unused
: Boolean := False);
3736 -- Perform full analysis of pragma Unreferenced and the read aspect of
3737 -- pragma Unused. Flag Is_Unused should be set when verifying the
3738 -- semantics of pragma Unused.
3740 procedure Check_Ada_83_Warning
;
3741 -- Issues a warning message for the current pragma if operating in Ada
3742 -- 83 mode (used for language pragmas that are not a standard part of
3743 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3746 procedure Check_Arg_Count
(Required
: Nat
);
3747 -- Check argument count for pragma is equal to given parameter. If not,
3748 -- then issue an error message and raise Pragma_Exit.
3750 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3751 -- Arg which can either be a pragma argument association, in which case
3752 -- the check is applied to the expression of the association or an
3753 -- expression directly.
3755 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
);
3756 -- Check that an argument has the right form for an EXTERNAL_NAME
3757 -- parameter of an extended import/export pragma. The rule is that the
3758 -- name must be an identifier or string literal (in Ada 83 mode) or a
3759 -- static string expression (in Ada 95 mode).
3761 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
);
3762 -- Check the specified argument Arg to make sure that it is an
3763 -- identifier. If not give error and raise Pragma_Exit.
3765 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
);
3766 -- Check the specified argument Arg to make sure that it is an integer
3767 -- literal. If not give error and raise Pragma_Exit.
3769 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
);
3770 -- Check the specified argument Arg to make sure that it has the proper
3771 -- syntactic form for a local name and meets the semantic requirements
3772 -- for a local name. The local name is analyzed as part of the
3773 -- processing for this call. In addition, the local name is required
3774 -- to represent an entity at the library level.
3776 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
);
3777 -- Check the specified argument Arg to make sure that it has the proper
3778 -- syntactic form for a local name and meets the semantic requirements
3779 -- for a local name. The local name is analyzed as part of the
3780 -- processing for this call.
3782 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
);
3783 -- Check the specified argument Arg to make sure that it is a valid
3784 -- locking policy name. If not give error and raise Pragma_Exit.
3786 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
);
3787 -- Check the specified argument Arg to make sure that it is a valid
3788 -- elaboration policy name. If not give error and raise Pragma_Exit.
3790 procedure Check_Arg_Is_One_Of
3793 procedure Check_Arg_Is_One_Of
3795 N1
, N2
, N3
: Name_Id
);
3796 procedure Check_Arg_Is_One_Of
3798 N1
, N2
, N3
, N4
: Name_Id
);
3799 procedure Check_Arg_Is_One_Of
3801 N1
, N2
, N3
, N4
, N5
: Name_Id
);
3802 -- Check the specified argument Arg to make sure that it is an
3803 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3804 -- present). If not then give error and raise Pragma_Exit.
3806 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
);
3807 -- Check the specified argument Arg to make sure that it is a valid
3808 -- queuing policy name. If not give error and raise Pragma_Exit.
3810 procedure Check_Arg_Is_OK_Static_Expression
3812 Typ
: Entity_Id
:= Empty
);
3813 -- Check the specified argument Arg to make sure that it is a static
3814 -- expression of the given type (i.e. it will be analyzed and resolved
3815 -- using this type, which can be any valid argument to Resolve, e.g.
3816 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3817 -- Typ is left Empty, then any static expression is allowed. Includes
3818 -- checking that the argument does not raise Constraint_Error.
3820 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
);
3821 -- Check the specified argument Arg to make sure that it is a valid task
3822 -- dispatching policy name. If not give error and raise Pragma_Exit.
3824 procedure Check_Arg_Order
(Names
: Name_List
);
3825 -- Checks for an instance of two arguments with identifiers for the
3826 -- current pragma which are not in the sequence indicated by Names,
3827 -- and if so, generates a fatal message about bad order of arguments.
3829 procedure Check_At_Least_N_Arguments
(N
: Nat
);
3830 -- Check there are at least N arguments present
3832 procedure Check_At_Most_N_Arguments
(N
: Nat
);
3833 -- Check there are no more than N arguments present
3835 procedure Check_Component
3838 In_Variant_Part
: Boolean := False);
3839 -- Examine an Unchecked_Union component for correct use of per-object
3840 -- constrained subtypes, and for restrictions on finalizable components.
3841 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3842 -- should be set when Comp comes from a record variant.
3844 procedure Check_Duplicate_Pragma
(E
: Entity_Id
);
3845 -- Check if a rep item of the same name as the current pragma is already
3846 -- chained as a rep pragma to the given entity. If so give a message
3847 -- about the duplicate, and then raise Pragma_Exit so does not return.
3848 -- Note that if E is a type, then this routine avoids flagging a pragma
3849 -- which applies to a parent type from which E is derived.
3851 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
);
3852 -- Nam is an N_String_Literal node containing the external name set by
3853 -- an Import or Export pragma (or extended Import or Export pragma).
3854 -- This procedure checks for possible duplications if this is the export
3855 -- case, and if found, issues an appropriate error message.
3857 procedure Check_Expr_Is_OK_Static_Expression
3859 Typ
: Entity_Id
:= Empty
);
3860 -- Check the specified expression Expr to make sure that it is a static
3861 -- expression of the given type (i.e. it will be analyzed and resolved
3862 -- using this type, which can be any valid argument to Resolve, e.g.
3863 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3864 -- Typ is left Empty, then any static expression is allowed. Includes
3865 -- checking that the expression does not raise Constraint_Error.
3867 procedure Check_First_Subtype
(Arg
: Node_Id
);
3868 -- Checks that Arg, whose expression is an entity name, references a
3871 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3872 -- Checks that the given argument has an identifier, and if so, requires
3873 -- it to match the given identifier name. If there is no identifier, or
3874 -- a non-matching identifier, then an error message is given and
3875 -- Pragma_Exit is raised.
3877 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
);
3878 -- Checks that the given argument has an identifier, and if so, requires
3879 -- it to match one of the given identifier names. If there is no
3880 -- identifier, or a non-matching identifier, then an error message is
3881 -- given and Pragma_Exit is raised.
3883 procedure Check_In_Main_Program
;
3884 -- Common checks for pragmas that appear within a main program
3885 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3887 procedure Check_Interrupt_Or_Attach_Handler
;
3888 -- Common processing for first argument of pragma Interrupt_Handler or
3889 -- pragma Attach_Handler.
3891 procedure Check_Loop_Pragma_Placement
;
3892 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3893 -- appear immediately within a construct restricted to loops, and that
3894 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3896 procedure Check_Is_In_Decl_Part_Or_Package_Spec
;
3897 -- Check that pragma appears in a declarative part, or in a package
3898 -- specification, i.e. that it does not occur in a statement sequence
3901 procedure Check_No_Identifier
(Arg
: Node_Id
);
3902 -- Checks that the given argument does not have an identifier. If
3903 -- an identifier is present, then an error message is issued, and
3904 -- Pragma_Exit is raised.
3906 procedure Check_No_Identifiers
;
3907 -- Checks that none of the arguments to the pragma has an identifier.
3908 -- If any argument has an identifier, then an error message is issued,
3909 -- and Pragma_Exit is raised.
3911 procedure Check_No_Link_Name
;
3912 -- Checks that no link name is specified
3914 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3915 -- Checks if the given argument has an identifier, and if so, requires
3916 -- it to match the given identifier name. If there is a non-matching
3917 -- identifier, then an error message is given and Pragma_Exit is raised.
3919 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String);
3920 -- Checks if the given argument has an identifier, and if so, requires
3921 -- it to match the given identifier name. If there is a non-matching
3922 -- identifier, then an error message is given and Pragma_Exit is raised.
3923 -- In this version of the procedure, the identifier name is given as
3924 -- a string with lower case letters.
3926 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
);
3927 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3928 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3929 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3930 -- is an OK static boolean expression. Emit an error if this is not the
3933 procedure Check_Static_Constraint
(Constr
: Node_Id
);
3934 -- Constr is a constraint from an N_Subtype_Indication node from a
3935 -- component constraint in an Unchecked_Union type. This routine checks
3936 -- that the constraint is static as required by the restrictions for
3939 procedure Check_Valid_Configuration_Pragma
;
3940 -- Legality checks for placement of a configuration pragma
3942 procedure Check_Valid_Library_Unit_Pragma
;
3943 -- Legality checks for library unit pragmas. A special case arises for
3944 -- pragmas in generic instances that come from copies of the original
3945 -- library unit pragmas in the generic templates. In the case of other
3946 -- than library level instantiations these can appear in contexts which
3947 -- would normally be invalid (they only apply to the original template
3948 -- and to library level instantiations), and they are simply ignored,
3949 -- which is implemented by rewriting them as null statements.
3951 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
);
3952 -- Check an Unchecked_Union variant for lack of nested variants and
3953 -- presence of at least one component. UU_Typ is the related Unchecked_
3956 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
);
3957 -- Subsidiary routine to the processing of pragmas Abstract_State,
3958 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3959 -- Refined_Global and Refined_State. Transform argument Arg into
3960 -- an aggregate if not one already. N_Null is never transformed.
3961 -- Arg may denote an aspect specification or a pragma argument
3964 procedure Error_Pragma
(Msg
: String);
3965 pragma No_Return
(Error_Pragma
);
3966 -- Outputs error message for current pragma. The message contains a %
3967 -- that will be replaced with the pragma name, and the flag is placed
3968 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3969 -- calls Fix_Error (see spec of that procedure for details).
3971 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
);
3972 pragma No_Return
(Error_Pragma_Arg
);
3973 -- Outputs error message for current pragma. The message may contain
3974 -- a % that will be replaced with the pragma name. The parameter Arg
3975 -- may either be a pragma argument association, in which case the flag
3976 -- is placed on the expression of this association, or an expression,
3977 -- in which case the flag is placed directly on the expression. The
3978 -- message is placed using Error_Msg_N, so the message may also contain
3979 -- an & insertion character which will reference the given Arg value.
3980 -- After placing the message, Pragma_Exit is raised. Note: this routine
3981 -- calls Fix_Error (see spec of that procedure for details).
3983 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
);
3984 pragma No_Return
(Error_Pragma_Arg
);
3985 -- Similar to above form of Error_Pragma_Arg except that two messages
3986 -- are provided, the second is a continuation comment starting with \.
3988 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
);
3989 pragma No_Return
(Error_Pragma_Arg_Ident
);
3990 -- Outputs error message for current pragma. The message may contain a %
3991 -- that will be replaced with the pragma name. The parameter Arg must be
3992 -- a pragma argument association with a non-empty identifier (i.e. its
3993 -- Chars field must be set), and the error message is placed on the
3994 -- identifier. The message is placed using Error_Msg_N so the message
3995 -- may also contain an & insertion character which will reference
3996 -- the identifier. After placing the message, Pragma_Exit is raised.
3997 -- Note: this routine calls Fix_Error (see spec of that procedure for
4000 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
);
4001 pragma No_Return
(Error_Pragma_Ref
);
4002 -- Outputs error message for current pragma. The message may contain
4003 -- a % that will be replaced with the pragma name. The parameter Ref
4004 -- must be an entity whose name can be referenced by & and sloc by #.
4005 -- After placing the message, Pragma_Exit is raised. Note: this routine
4006 -- calls Fix_Error (see spec of that procedure for details).
4008 function Find_Lib_Unit_Name
return Entity_Id
;
4009 -- Used for a library unit pragma to find the entity to which the
4010 -- library unit pragma applies, returns the entity found.
4012 procedure Find_Program_Unit_Name
(Id
: Node_Id
);
4013 -- If the pragma is a compilation unit pragma, the id must denote the
4014 -- compilation unit in the same compilation, and the pragma must appear
4015 -- in the list of preceding or trailing pragmas. If it is a program
4016 -- unit pragma that is not a compilation unit pragma, then the
4017 -- identifier must be visible.
4019 function Find_Unique_Parameterless_Procedure
4021 Arg
: Node_Id
) return Entity_Id
;
4022 -- Used for a procedure pragma to find the unique parameterless
4023 -- procedure identified by Name, returns it if it exists, otherwise
4024 -- errors out and uses Arg as the pragma argument for the message.
4026 function Fix_Error
(Msg
: String) return String;
4027 -- This is called prior to issuing an error message. Msg is the normal
4028 -- error message issued in the pragma case. This routine checks for the
4029 -- case of a pragma coming from an aspect in the source, and returns a
4030 -- message suitable for the aspect case as follows:
4032 -- Each substring "pragma" is replaced by "aspect"
4034 -- If "argument of" is at the start of the error message text, it is
4035 -- replaced by "entity for".
4037 -- If "argument" is at the start of the error message text, it is
4038 -- replaced by "entity".
4040 -- So for example, "argument of pragma X must be discrete type"
4041 -- returns "entity for aspect X must be a discrete type".
4043 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4044 -- be different from the pragma name). If the current pragma results
4045 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4046 -- original pragma name.
4048 procedure Gather_Associations
4050 Args
: out Args_List
);
4051 -- This procedure is used to gather the arguments for a pragma that
4052 -- permits arbitrary ordering of parameters using the normal rules
4053 -- for named and positional parameters. The Names argument is a list
4054 -- of Name_Id values that corresponds to the allowed pragma argument
4055 -- association identifiers in order. The result returned in Args is
4056 -- a list of corresponding expressions that are the pragma arguments.
4057 -- Note that this is a list of expressions, not of pragma argument
4058 -- associations (Gather_Associations has completely checked all the
4059 -- optional identifiers when it returns). An entry in Args is Empty
4060 -- on return if the corresponding argument is not present.
4062 procedure GNAT_Pragma
;
4063 -- Called for all GNAT defined pragmas to check the relevant restriction
4064 -- (No_Implementation_Pragmas).
4066 function Is_Before_First_Decl
4067 (Pragma_Node
: Node_Id
;
4068 Decls
: List_Id
) return Boolean;
4069 -- Return True if Pragma_Node is before the first declarative item in
4070 -- Decls where Decls is the list of declarative items.
4072 function Is_Configuration_Pragma
return Boolean;
4073 -- Determines if the placement of the current pragma is appropriate
4074 -- for a configuration pragma.
4076 function Is_In_Context_Clause
return Boolean;
4077 -- Returns True if pragma appears within the context clause of a unit,
4078 -- and False for any other placement (does not generate any messages).
4080 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean;
4081 -- Analyzes the argument, and determines if it is a static string
4082 -- expression, returns True if so, False if non-static or not String.
4083 -- A special case is that a string literal returns True in Ada 83 mode
4084 -- (which has no such thing as static string expressions). Note that
4085 -- the call analyzes its argument, so this cannot be used for the case
4086 -- where an identifier might not be declared.
4088 procedure Pragma_Misplaced
;
4089 pragma No_Return
(Pragma_Misplaced
);
4090 -- Issue fatal error message for misplaced pragma
4092 procedure Process_Atomic_Independent_Shared_Volatile
;
4093 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4094 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4095 -- and treated as being identical in effect to pragma Atomic.
4097 procedure Process_Compile_Time_Warning_Or_Error
;
4098 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4100 procedure Process_Convention
4101 (C
: out Convention_Id
;
4102 Ent
: out Entity_Id
);
4103 -- Common processing for Convention, Interface, Import and Export.
4104 -- Checks first two arguments of pragma, and sets the appropriate
4105 -- convention value in the specified entity or entities. On return
4106 -- C is the convention, Ent is the referenced entity.
4108 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
);
4109 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4110 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4112 procedure Process_Extended_Import_Export_Object_Pragma
4113 (Arg_Internal
: Node_Id
;
4114 Arg_External
: Node_Id
;
4115 Arg_Size
: Node_Id
);
4116 -- Common processing for the pragmas Import/Export_Object. The three
4117 -- arguments correspond to the three named parameters of the pragmas. An
4118 -- argument is empty if the corresponding parameter is not present in
4121 procedure Process_Extended_Import_Export_Internal_Arg
4122 (Arg_Internal
: Node_Id
:= Empty
);
4123 -- Common processing for all extended Import and Export pragmas. The
4124 -- argument is the pragma parameter for the Internal argument. If
4125 -- Arg_Internal is empty or inappropriate, an error message is posted.
4126 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4127 -- set to identify the referenced entity.
4129 procedure Process_Extended_Import_Export_Subprogram_Pragma
4130 (Arg_Internal
: Node_Id
;
4131 Arg_External
: Node_Id
;
4132 Arg_Parameter_Types
: Node_Id
;
4133 Arg_Result_Type
: Node_Id
:= Empty
;
4134 Arg_Mechanism
: Node_Id
;
4135 Arg_Result_Mechanism
: Node_Id
:= Empty
);
4136 -- Common processing for all extended Import and Export pragmas applying
4137 -- to subprograms. The caller omits any arguments that do not apply to
4138 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4139 -- only in the Import_Function and Export_Function cases). The argument
4140 -- names correspond to the allowed pragma association identifiers.
4142 procedure Process_Generic_List
;
4143 -- Common processing for Share_Generic and Inline_Generic
4145 procedure Process_Import_Or_Interface
;
4146 -- Common processing for Import or Interface
4148 procedure Process_Import_Predefined_Type
;
4149 -- Processing for completing a type with pragma Import. This is used
4150 -- to declare types that match predefined C types, especially for cases
4151 -- without corresponding Ada predefined type.
4153 type Inline_Status
is (Suppressed
, Disabled
, Enabled
);
4154 -- Inline status of a subprogram, indicated as follows:
4155 -- Suppressed: inlining is suppressed for the subprogram
4156 -- Disabled: no inlining is requested for the subprogram
4157 -- Enabled: inlining is requested/required for the subprogram
4159 procedure Process_Inline
(Status
: Inline_Status
);
4160 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4161 -- indicates the inline status specified by the pragma.
4163 procedure Process_Interface_Name
4164 (Subprogram_Def
: Entity_Id
;
4168 -- Given the last two arguments of pragma Import, pragma Export, or
4169 -- pragma Interface_Name, performs validity checks and sets the
4170 -- Interface_Name field of the given subprogram entity to the
4171 -- appropriate external or link name, depending on the arguments given.
4172 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4173 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4174 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4175 -- nor Link_Arg is present, the interface name is set to the default
4176 -- from the subprogram name. In addition, the pragma itself is passed
4177 -- to analyze any expressions in the case the pragma came from an aspect
4180 procedure Process_Interrupt_Or_Attach_Handler
;
4181 -- Common processing for Interrupt and Attach_Handler pragmas
4183 procedure Process_Restrictions_Or_Restriction_Warnings
(Warn
: Boolean);
4184 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4185 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4186 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4187 -- is not set in the Restrictions case.
4189 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean);
4190 -- Common processing for Suppress and Unsuppress. The boolean parameter
4191 -- Suppress_Case is True for the Suppress case, and False for the
4194 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
);
4195 -- Subsidiary to the analysis of pragmas Independent[_Components].
4196 -- Record such a pragma N applied to entity E for future checks.
4198 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
);
4199 -- This procedure sets the Is_Exported flag for the given entity,
4200 -- checking that the entity was not previously imported. Arg is
4201 -- the argument that specified the entity. A check is also made
4202 -- for exporting inappropriate entities.
4204 procedure Set_Extended_Import_Export_External_Name
4205 (Internal_Ent
: Entity_Id
;
4206 Arg_External
: Node_Id
);
4207 -- Common processing for all extended import export pragmas. The first
4208 -- argument, Internal_Ent, is the internal entity, which has already
4209 -- been checked for validity by the caller. Arg_External is from the
4210 -- Import or Export pragma, and may be null if no External parameter
4211 -- was present. If Arg_External is present and is a non-null string
4212 -- (a null string is treated as the default), then the Interface_Name
4213 -- field of Internal_Ent is set appropriately.
4215 procedure Set_Imported
(E
: Entity_Id
);
4216 -- This procedure sets the Is_Imported flag for the given entity,
4217 -- checking that it is not previously exported or imported.
4219 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
);
4220 -- Mech is a parameter passing mechanism (see Import_Function syntax
4221 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4222 -- has the right form, and if not issues an error message. If the
4223 -- argument has the right form then the Mechanism field of Ent is
4224 -- set appropriately.
4226 procedure Set_Rational_Profile
;
4227 -- Activate the set of configuration pragmas and permissions that make
4228 -- up the Rational profile.
4230 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
);
4231 -- Activate the set of configuration pragmas and restrictions that make
4232 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4233 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
4234 -- which is used for error messages on any constructs violating the
4237 ----------------------------------
4238 -- Acquire_Warning_Match_String --
4239 ----------------------------------
4241 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
) is
4243 String_To_Name_Buffer
4244 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
4246 -- Add asterisk at start if not already there
4248 if Name_Len
> 0 and then Name_Buffer
(1) /= '*' then
4249 Name_Buffer
(2 .. Name_Len
+ 1) :=
4250 Name_Buffer
(1 .. Name_Len
);
4251 Name_Buffer
(1) := '*';
4252 Name_Len
:= Name_Len
+ 1;
4255 -- Add asterisk at end if not already there
4257 if Name_Buffer
(Name_Len
) /= '*' then
4258 Name_Len
:= Name_Len
+ 1;
4259 Name_Buffer
(Name_Len
) := '*';
4261 end Acquire_Warning_Match_String
;
4263 ---------------------
4264 -- Ada_2005_Pragma --
4265 ---------------------
4267 procedure Ada_2005_Pragma
is
4269 if Ada_Version
<= Ada_95
then
4270 Check_Restriction
(No_Implementation_Pragmas
, N
);
4272 end Ada_2005_Pragma
;
4274 ---------------------
4275 -- Ada_2012_Pragma --
4276 ---------------------
4278 procedure Ada_2012_Pragma
is
4280 if Ada_Version
<= Ada_2005
then
4281 Check_Restriction
(No_Implementation_Pragmas
, N
);
4283 end Ada_2012_Pragma
;
4285 ----------------------------
4286 -- Analyze_Depends_Global --
4287 ----------------------------
4289 procedure Analyze_Depends_Global
4290 (Spec_Id
: out Entity_Id
;
4291 Subp_Decl
: out Node_Id
;
4292 Legal
: out Boolean)
4295 -- Assume that the pragma is illegal
4302 Check_Arg_Count
(1);
4304 -- Ensure the proper placement of the pragma. Depends/Global must be
4305 -- associated with a subprogram declaration or a body that acts as a
4308 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4312 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4315 -- Generic subprogram
4317 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4320 -- Object declaration of a single concurrent type
4322 elsif Nkind
(Subp_Decl
) = N_Object_Declaration
4323 and then Is_Single_Concurrent_Object
4324 (Unique_Defining_Entity
(Subp_Decl
))
4330 elsif Nkind
(Subp_Decl
) = N_Single_Task_Declaration
then
4333 -- Subprogram body acts as spec
4335 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4336 and then No
(Corresponding_Spec
(Subp_Decl
))
4340 -- Subprogram body stub acts as spec
4342 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4343 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
4347 -- Subprogram declaration
4349 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4354 elsif Nkind
(Subp_Decl
) = N_Task_Type_Declaration
then
4362 -- If we get here, then the pragma is legal
4365 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
4367 -- When the related context is an entry, the entry must belong to a
4368 -- protected unit (SPARK RM 6.1.4(6)).
4370 if Is_Entry_Declaration
(Spec_Id
)
4371 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
4376 -- When the related context is an anonymous object created for a
4377 -- simple concurrent type, the type must be a task
4378 -- (SPARK RM 6.1.4(6)).
4380 elsif Is_Single_Concurrent_Object
(Spec_Id
)
4381 and then Ekind
(Etype
(Spec_Id
)) /= E_Task_Type
4387 -- A pragma that applies to a Ghost entity becomes Ghost for the
4388 -- purposes of legality checks and removal of ignored Ghost code.
4390 Mark_Ghost_Pragma
(N
, Spec_Id
);
4391 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4392 end Analyze_Depends_Global
;
4394 ------------------------
4395 -- Analyze_If_Present --
4396 ------------------------
4398 procedure Analyze_If_Present
(Id
: Pragma_Id
) is
4402 pragma Assert
(Is_List_Member
(N
));
4404 -- Inspect the declarations or statements following pragma N looking
4405 -- for another pragma whose Id matches the caller's request. If it is
4406 -- available, analyze it.
4409 while Present
(Stmt
) loop
4410 if Nkind
(Stmt
) = N_Pragma
and then Get_Pragma_Id
(Stmt
) = Id
then
4411 Analyze_Pragma
(Stmt
);
4414 -- The first source declaration or statement immediately following
4415 -- N ends the region where a pragma may appear.
4417 elsif Comes_From_Source
(Stmt
) then
4423 end Analyze_If_Present
;
4425 --------------------------------
4426 -- Analyze_Pre_Post_Condition --
4427 --------------------------------
4429 procedure Analyze_Pre_Post_Condition
is
4430 Prag_Iden
: constant Node_Id
:= Pragma_Identifier
(N
);
4431 Subp_Decl
: Node_Id
;
4432 Subp_Id
: Entity_Id
;
4434 Duplicates_OK
: Boolean := False;
4435 -- Flag set when a pre/postcondition allows multiple pragmas of the
4438 In_Body_OK
: Boolean := False;
4439 -- Flag set when a pre/postcondition is allowed to appear on a body
4440 -- even though the subprogram may have a spec.
4442 Is_Pre_Post
: Boolean := False;
4443 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4446 function Inherits_Class_Wide_Pre
(E
: Entity_Id
) return Boolean;
4447 -- Implement rules in AI12-0131: an overriding operation can have
4448 -- a class-wide precondition only if one of its ancestors has an
4449 -- explicit class-wide precondition.
4451 -----------------------------
4452 -- Inherits_Class_Wide_Pre --
4453 -----------------------------
4455 function Inherits_Class_Wide_Pre
(E
: Entity_Id
) return Boolean is
4456 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(E
);
4459 Prev
: Entity_Id
:= Overridden_Operation
(E
);
4462 -- Check ancestors on the overriding operation to examine the
4463 -- preconditions that may apply to them.
4465 while Present
(Prev
) loop
4466 Cont
:= Contract
(Prev
);
4467 if Present
(Cont
) then
4468 Prag
:= Pre_Post_Conditions
(Cont
);
4469 while Present
(Prag
) loop
4470 if Pragma_Name
(Prag
) = Name_Precondition
4471 and then Class_Present
(Prag
)
4476 Prag
:= Next_Pragma
(Prag
);
4480 -- For a type derived from a generic formal type, the operation
4481 -- inheriting the condition is a renaming, not an overriding of
4482 -- the operation of the formal. Ditto for an inherited
4483 -- operation which has no explicit contracts.
4485 if Is_Generic_Type
(Find_Dispatching_Type
(Prev
))
4486 or else not Comes_From_Source
(Prev
)
4488 Prev
:= Alias
(Prev
);
4490 Prev
:= Overridden_Operation
(Prev
);
4494 -- If the controlling type of the subprogram has progenitors, an
4495 -- interface operation implemented by the current operation may
4496 -- have a class-wide precondition.
4498 if Has_Interfaces
(Typ
) then
4503 Prim_Elmt
: Elmt_Id
;
4504 Prim_List
: Elist_Id
;
4507 Collect_Interfaces
(Typ
, Ints
);
4508 Elmt
:= First_Elmt
(Ints
);
4510 -- Iterate over the primitive operations of each interface
4512 while Present
(Elmt
) loop
4513 Prim_List
:= Direct_Primitive_Operations
(Node
(Elmt
));
4514 Prim_Elmt
:= First_Elmt
(Prim_List
);
4515 while Present
(Prim_Elmt
) loop
4516 Prim
:= Node
(Prim_Elmt
);
4517 if Chars
(Prim
) = Chars
(E
)
4518 and then Present
(Contract
(Prim
))
4519 and then Class_Present
4520 (Pre_Post_Conditions
(Contract
(Prim
)))
4525 Next_Elmt
(Prim_Elmt
);
4534 end Inherits_Class_Wide_Pre
;
4536 -- Start of processing for Analyze_Pre_Post_Condition
4539 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4540 -- offer uniformity among the various kinds of pre/postconditions by
4541 -- rewriting the pragma identifier. This allows the retrieval of the
4542 -- original pragma name by routine Original_Aspect_Pragma_Name.
4544 if Comes_From_Source
(N
) then
4545 if Nam_In
(Pname
, Name_Pre
, Name_Pre_Class
) then
4546 Is_Pre_Post
:= True;
4547 Set_Class_Present
(N
, Pname
= Name_Pre_Class
);
4548 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Precondition
));
4550 elsif Nam_In
(Pname
, Name_Post
, Name_Post_Class
) then
4551 Is_Pre_Post
:= True;
4552 Set_Class_Present
(N
, Pname
= Name_Post_Class
);
4553 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Postcondition
));
4557 -- Determine the semantics with respect to duplicates and placement
4558 -- in a body. Pragmas Precondition and Postcondition were introduced
4559 -- before aspects and are not subject to the same aspect-like rules.
4561 if Nam_In
(Pname
, Name_Precondition
, Name_Postcondition
) then
4562 Duplicates_OK
:= True;
4568 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4569 -- argument without an identifier.
4572 Check_Arg_Count
(1);
4573 Check_No_Identifiers
;
4575 -- Pragmas Precondition and Postcondition have complex argument
4579 Check_At_Least_N_Arguments
(1);
4580 Check_At_Most_N_Arguments
(2);
4581 Check_Optional_Identifier
(Arg1
, Name_Check
);
4583 if Present
(Arg2
) then
4584 Check_Optional_Identifier
(Arg2
, Name_Message
);
4585 Preanalyze_Spec_Expression
4586 (Get_Pragma_Arg
(Arg2
), Standard_String
);
4590 -- For a pragma PPC in the extended main source unit, record enabled
4592 -- ??? nothing checks that the pragma is in the main source unit
4594 if Is_Checked
(N
) and then not Split_PPC
(N
) then
4595 Set_SCO_Pragma_Enabled
(Loc
);
4598 -- Ensure the proper placement of the pragma
4601 Find_Related_Declaration_Or_Body
4602 (N
, Do_Checks
=> not Duplicates_OK
);
4604 -- When a pre/postcondition pragma applies to an abstract subprogram,
4605 -- its original form must be an aspect with 'Class.
4607 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
4608 if not From_Aspect_Specification
(N
) then
4610 ("pragma % cannot be applied to abstract subprogram");
4612 elsif not Class_Present
(N
) then
4614 ("aspect % requires ''Class for abstract subprogram");
4617 -- Entry declaration
4619 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4622 -- Generic subprogram declaration
4624 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4629 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4630 and then (No
(Corresponding_Spec
(Subp_Decl
)) or In_Body_OK
)
4634 -- Subprogram body stub
4636 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4637 and then (No
(Corresponding_Spec_Of_Stub
(Subp_Decl
)) or In_Body_OK
)
4641 -- Subprogram declaration
4643 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4645 -- AI05-0230: When a pre/postcondition pragma applies to a null
4646 -- procedure, its original form must be an aspect with 'Class.
4648 if Nkind
(Specification
(Subp_Decl
)) = N_Procedure_Specification
4649 and then Null_Present
(Specification
(Subp_Decl
))
4650 and then From_Aspect_Specification
(N
)
4651 and then not Class_Present
(N
)
4653 Error_Pragma
("aspect % requires ''Class for null procedure");
4656 -- Implement the legality checks mandated by AI12-0131:
4657 -- Pre'Class shall not be specified for an overriding primitive
4658 -- subprogram of a tagged type T unless the Pre'Class aspect is
4659 -- specified for the corresponding primitive subprogram of some
4663 E
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
4666 if Class_Present
(N
)
4667 and then Pragma_Name
(N
) = Name_Precondition
4668 and then Present
(Overridden_Operation
(E
))
4669 and then not Inherits_Class_Wide_Pre
(E
)
4672 ("illegal class-wide precondition on overriding operation",
4673 Corresponding_Aspect
(N
));
4677 -- A renaming declaration may inherit a generated pragma, its
4678 -- placement comes from expansion, not from source.
4680 elsif Nkind
(Subp_Decl
) = N_Subprogram_Renaming_Declaration
4681 and then not Comes_From_Source
(N
)
4685 -- Otherwise the placement is illegal
4692 Subp_Id
:= Defining_Entity
(Subp_Decl
);
4694 -- A pragma that applies to a Ghost entity becomes Ghost for the
4695 -- purposes of legality checks and removal of ignored Ghost code.
4697 Mark_Ghost_Pragma
(N
, Subp_Id
);
4699 -- Chain the pragma on the contract for further processing by
4700 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4702 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
4704 -- Fully analyze the pragma when it appears inside an entry or
4705 -- subprogram body because it cannot benefit from forward references.
4707 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
4709 N_Subprogram_Body_Stub
)
4711 -- The legality checks of pragmas Precondition and Postcondition
4712 -- are affected by the SPARK mode in effect and the volatility of
4713 -- the context. Analyze all pragmas in a specific order.
4715 Analyze_If_Present
(Pragma_SPARK_Mode
);
4716 Analyze_If_Present
(Pragma_Volatile_Function
);
4717 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
4719 end Analyze_Pre_Post_Condition
;
4721 -----------------------------------------
4722 -- Analyze_Refined_Depends_Global_Post --
4723 -----------------------------------------
4725 procedure Analyze_Refined_Depends_Global_Post
4726 (Spec_Id
: out Entity_Id
;
4727 Body_Id
: out Entity_Id
;
4728 Legal
: out Boolean)
4730 Body_Decl
: Node_Id
;
4731 Spec_Decl
: Node_Id
;
4734 -- Assume that the pragma is illegal
4741 Check_Arg_Count
(1);
4742 Check_No_Identifiers
;
4744 -- Verify the placement of the pragma and check for duplicates. The
4745 -- pragma must apply to a subprogram body [stub].
4747 Body_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4749 if not Nkind_In
(Body_Decl
, N_Entry_Body
,
4751 N_Subprogram_Body_Stub
,
4759 Body_Id
:= Defining_Entity
(Body_Decl
);
4760 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
4762 -- The pragma must apply to the second declaration of a subprogram.
4763 -- In other words, the body [stub] cannot acts as a spec.
4765 if No
(Spec_Id
) then
4766 Error_Pragma
("pragma % cannot apply to a stand alone body");
4769 -- Catch the case where the subprogram body is a subunit and acts as
4770 -- the third declaration of the subprogram.
4772 elsif Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
4773 Error_Pragma
("pragma % cannot apply to a subunit");
4777 -- A refined pragma can only apply to the body [stub] of a subprogram
4778 -- declared in the visible part of a package. Retrieve the context of
4779 -- the subprogram declaration.
4781 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
4783 -- When dealing with protected entries or protected subprograms, use
4784 -- the enclosing protected type as the proper context.
4786 if Ekind_In
(Spec_Id
, E_Entry
,
4790 and then Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
4792 Spec_Decl
:= Declaration_Node
(Scope
(Spec_Id
));
4795 if Nkind
(Parent
(Spec_Decl
)) /= N_Package_Specification
then
4797 (Fix_Msg
(Spec_Id
, "pragma % must apply to the body of "
4798 & "subprogram declared in a package specification"));
4802 -- If we get here, then the pragma is legal
4806 -- A pragma that applies to a Ghost entity becomes Ghost for the
4807 -- purposes of legality checks and removal of ignored Ghost code.
4809 Mark_Ghost_Pragma
(N
, Spec_Id
);
4811 if Nam_In
(Pname
, Name_Refined_Depends
, Name_Refined_Global
) then
4812 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4814 end Analyze_Refined_Depends_Global_Post
;
4816 ----------------------------------
4817 -- Analyze_Unmodified_Or_Unused --
4818 ----------------------------------
4820 procedure Analyze_Unmodified_Or_Unused
(Is_Unused
: Boolean := False) is
4825 Ghost_Error_Posted
: Boolean := False;
4826 -- Flag set when an error concerning the illegal mix of Ghost and
4827 -- non-Ghost variables is emitted.
4829 Ghost_Id
: Entity_Id
:= Empty
;
4830 -- The entity of the first Ghost variable encountered while
4831 -- processing the arguments of the pragma.
4835 Check_At_Least_N_Arguments
(1);
4837 -- Loop through arguments
4840 while Present
(Arg
) loop
4841 Check_No_Identifier
(Arg
);
4843 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4844 -- in fact generate reference, so that the entity will have a
4845 -- reference, which will inhibit any warnings about it not
4846 -- being referenced, and also properly show up in the ali file
4847 -- as a reference. But this reference is recorded before the
4848 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4849 -- generated for this reference.
4851 Check_Arg_Is_Local_Name
(Arg
);
4852 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4854 if Is_Entity_Name
(Arg_Expr
) then
4855 Arg_Id
:= Entity
(Arg_Expr
);
4857 -- Skip processing the argument if already flagged
4859 if Is_Assignable
(Arg_Id
)
4860 and then not Has_Pragma_Unmodified
(Arg_Id
)
4861 and then not Has_Pragma_Unused
(Arg_Id
)
4863 Set_Has_Pragma_Unmodified
(Arg_Id
);
4866 Set_Has_Pragma_Unused
(Arg_Id
);
4869 -- A pragma that applies to a Ghost entity becomes Ghost for
4870 -- the purposes of legality checks and removal of ignored
4873 Mark_Ghost_Pragma
(N
, Arg_Id
);
4875 -- Capture the entity of the first Ghost variable being
4876 -- processed for error detection purposes.
4878 if Is_Ghost_Entity
(Arg_Id
) then
4879 if No
(Ghost_Id
) then
4883 -- Otherwise the variable is non-Ghost. It is illegal to mix
4884 -- references to Ghost and non-Ghost entities
4887 elsif Present
(Ghost_Id
)
4888 and then not Ghost_Error_Posted
4890 Ghost_Error_Posted
:= True;
4892 Error_Msg_Name_1
:= Pname
;
4894 ("pragma % cannot mention ghost and non-ghost "
4897 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
4898 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
4900 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
4901 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
4904 -- Warn if already flagged as Unused or Unmodified
4906 elsif Has_Pragma_Unmodified
(Arg_Id
) then
4907 if Has_Pragma_Unused
(Arg_Id
) then
4909 ("??pragma Unused already given for &!", Arg_Expr
,
4913 ("??pragma Unmodified already given for &!", Arg_Expr
,
4917 -- Otherwise the pragma referenced an illegal entity
4921 ("pragma% can only be applied to a variable", Arg_Expr
);
4927 end Analyze_Unmodified_Or_Unused
;
4929 ------------------------------------
4930 -- Analyze_Unreferenced_Or_Unused --
4931 ------------------------------------
4933 procedure Analyze_Unreferenced_Or_Unused
4934 (Is_Unused
: Boolean := False)
4941 Ghost_Error_Posted
: Boolean := False;
4942 -- Flag set when an error concerning the illegal mix of Ghost and
4943 -- non-Ghost names is emitted.
4945 Ghost_Id
: Entity_Id
:= Empty
;
4946 -- The entity of the first Ghost name encountered while processing
4947 -- the arguments of the pragma.
4951 Check_At_Least_N_Arguments
(1);
4953 -- Check case of appearing within context clause
4955 if not Is_Unused
and then Is_In_Context_Clause
then
4957 -- The arguments must all be units mentioned in a with clause in
4958 -- the same context clause. Note that Par.Prag already checked
4959 -- that the arguments are either identifiers or selected
4963 while Present
(Arg
) loop
4964 Citem
:= First
(List_Containing
(N
));
4965 while Citem
/= N
loop
4966 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4968 if Nkind
(Citem
) = N_With_Clause
4969 and then Same_Name
(Name
(Citem
), Arg_Expr
)
4971 Set_Has_Pragma_Unreferenced
4974 (Library_Unit
(Citem
))));
4975 Set_Elab_Unit_Name
(Arg_Expr
, Name
(Citem
));
4984 ("argument of pragma% is not withed unit", Arg
);
4990 -- Case of not in list of context items
4994 while Present
(Arg
) loop
4995 Check_No_Identifier
(Arg
);
4997 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4998 -- in fact generate reference, so that the entity will have a
4999 -- reference, which will inhibit any warnings about it not
5000 -- being referenced, and also properly show up in the ali file
5001 -- as a reference. But this reference is recorded before the
5002 -- Has_Pragma_Unreferenced flag is set, so that no warning is
5003 -- generated for this reference.
5005 Check_Arg_Is_Local_Name
(Arg
);
5006 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
5008 if Is_Entity_Name
(Arg_Expr
) then
5009 Arg_Id
:= Entity
(Arg_Expr
);
5011 -- Warn if already flagged as Unused or Unreferenced and
5012 -- skip processing the argument.
5014 if Has_Pragma_Unreferenced
(Arg_Id
) then
5015 if Has_Pragma_Unused
(Arg_Id
) then
5017 ("??pragma Unused already given for &!", Arg_Expr
,
5021 ("??pragma Unreferenced already given for &!",
5025 -- Apply Unreferenced to the entity
5028 -- If the entity is overloaded, the pragma applies to the
5029 -- most recent overloading, as documented. In this case,
5030 -- name resolution does not generate a reference, so it
5031 -- must be done here explicitly.
5033 if Is_Overloaded
(Arg_Expr
) then
5034 Generate_Reference
(Arg_Id
, N
);
5037 Set_Has_Pragma_Unreferenced
(Arg_Id
);
5040 Set_Has_Pragma_Unused
(Arg_Id
);
5043 -- A pragma that applies to a Ghost entity becomes Ghost
5044 -- for the purposes of legality checks and removal of
5045 -- ignored Ghost code.
5047 Mark_Ghost_Pragma
(N
, Arg_Id
);
5049 -- Capture the entity of the first Ghost name being
5050 -- processed for error detection purposes.
5052 if Is_Ghost_Entity
(Arg_Id
) then
5053 if No
(Ghost_Id
) then
5057 -- Otherwise the name is non-Ghost. It is illegal to mix
5058 -- references to Ghost and non-Ghost entities
5061 elsif Present
(Ghost_Id
)
5062 and then not Ghost_Error_Posted
5064 Ghost_Error_Posted
:= True;
5066 Error_Msg_Name_1
:= Pname
;
5068 ("pragma % cannot mention ghost and non-ghost "
5071 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
5073 ("\& # declared as ghost", N
, Ghost_Id
);
5075 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
5077 ("\& # declared as non-ghost", N
, Arg_Id
);
5085 end Analyze_Unreferenced_Or_Unused
;
5087 --------------------------
5088 -- Check_Ada_83_Warning --
5089 --------------------------
5091 procedure Check_Ada_83_Warning
is
5093 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
5094 Error_Msg_N
("(Ada 83) pragma& is non-standard??", N
);
5096 end Check_Ada_83_Warning
;
5098 ---------------------
5099 -- Check_Arg_Count --
5100 ---------------------
5102 procedure Check_Arg_Count
(Required
: Nat
) is
5104 if Arg_Count
/= Required
then
5105 Error_Pragma
("wrong number of arguments for pragma%");
5107 end Check_Arg_Count
;
5109 --------------------------------
5110 -- Check_Arg_Is_External_Name --
5111 --------------------------------
5113 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
) is
5114 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5117 if Nkind
(Argx
) = N_Identifier
then
5121 Analyze_And_Resolve
(Argx
, Standard_String
);
5123 if Is_OK_Static_Expression
(Argx
) then
5126 elsif Etype
(Argx
) = Any_Type
then
5129 -- An interesting special case, if we have a string literal and
5130 -- we are in Ada 83 mode, then we allow it even though it will
5131 -- not be flagged as static. This allows expected Ada 83 mode
5132 -- use of external names which are string literals, even though
5133 -- technically these are not static in Ada 83.
5135 elsif Ada_Version
= Ada_83
5136 and then Nkind
(Argx
) = N_String_Literal
5140 -- Here we have a real error (non-static expression)
5143 Error_Msg_Name_1
:= Pname
;
5144 Flag_Non_Static_Expr
5145 (Fix_Error
("argument for pragma% must be a identifier or "
5146 & "static string expression!"), Argx
);
5151 end Check_Arg_Is_External_Name
;
5153 -----------------------------
5154 -- Check_Arg_Is_Identifier --
5155 -----------------------------
5157 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
) is
5158 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5160 if Nkind
(Argx
) /= N_Identifier
then
5161 Error_Pragma_Arg
("argument for pragma% must be identifier", Argx
);
5163 end Check_Arg_Is_Identifier
;
5165 ----------------------------------
5166 -- Check_Arg_Is_Integer_Literal --
5167 ----------------------------------
5169 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
) is
5170 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5172 if Nkind
(Argx
) /= N_Integer_Literal
then
5174 ("argument for pragma% must be integer literal", Argx
);
5176 end Check_Arg_Is_Integer_Literal
;
5178 -------------------------------------------
5179 -- Check_Arg_Is_Library_Level_Local_Name --
5180 -------------------------------------------
5184 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5185 -- | library_unit_NAME
5187 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
) is
5189 Check_Arg_Is_Local_Name
(Arg
);
5191 -- If it came from an aspect, we want to give the error just as if it
5192 -- came from source.
5194 if not Is_Library_Level_Entity
(Entity
(Get_Pragma_Arg
(Arg
)))
5195 and then (Comes_From_Source
(N
)
5196 or else Present
(Corresponding_Aspect
(Parent
(Arg
))))
5199 ("argument for pragma% must be library level entity", Arg
);
5201 end Check_Arg_Is_Library_Level_Local_Name
;
5203 -----------------------------
5204 -- Check_Arg_Is_Local_Name --
5205 -----------------------------
5209 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5210 -- | library_unit_NAME
5212 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
) is
5213 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5216 -- If this pragma came from an aspect specification, we don't want to
5217 -- check for this error, because that would cause spurious errors, in
5218 -- case a type is frozen in a scope more nested than the type. The
5219 -- aspect itself of course can't be anywhere but on the declaration
5222 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
5223 if From_Aspect_Specification
(Parent
(Arg
)) then
5227 -- Arg is the Expression of an N_Pragma_Argument_Association
5230 if From_Aspect_Specification
(Parent
(Parent
(Arg
))) then
5237 if Nkind
(Argx
) not in N_Direct_Name
5238 and then (Nkind
(Argx
) /= N_Attribute_Reference
5239 or else Present
(Expressions
(Argx
))
5240 or else Nkind
(Prefix
(Argx
)) /= N_Identifier
)
5241 and then (not Is_Entity_Name
(Argx
)
5242 or else not Is_Compilation_Unit
(Entity
(Argx
)))
5244 Error_Pragma_Arg
("argument for pragma% must be local name", Argx
);
5247 -- No further check required if not an entity name
5249 if not Is_Entity_Name
(Argx
) then
5255 Ent
: constant Entity_Id
:= Entity
(Argx
);
5256 Scop
: constant Entity_Id
:= Scope
(Ent
);
5259 -- Case of a pragma applied to a compilation unit: pragma must
5260 -- occur immediately after the program unit in the compilation.
5262 if Is_Compilation_Unit
(Ent
) then
5264 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
5267 -- Case of pragma placed immediately after spec
5269 if Parent
(N
) = Aux_Decls_Node
(Parent
(Decl
)) then
5272 -- Case of pragma placed immediately after body
5274 elsif Nkind
(Decl
) = N_Subprogram_Declaration
5275 and then Present
(Corresponding_Body
(Decl
))
5279 (Parent
(Unit_Declaration_Node
5280 (Corresponding_Body
(Decl
))));
5282 -- All other cases are illegal
5289 -- Special restricted placement rule from 10.2.1(11.8/2)
5291 elsif Is_Generic_Formal
(Ent
)
5292 and then Prag_Id
= Pragma_Preelaborable_Initialization
5294 OK
:= List_Containing
(N
) =
5295 Generic_Formal_Declarations
5296 (Unit_Declaration_Node
(Scop
));
5298 -- If this is an aspect applied to a subprogram body, the
5299 -- pragma is inserted in its declarative part.
5301 elsif From_Aspect_Specification
(N
)
5302 and then Ent
= Current_Scope
5304 Nkind
(Unit_Declaration_Node
(Ent
)) = N_Subprogram_Body
5308 -- If the aspect is a predicate (possibly others ???) and the
5309 -- context is a record type, this is a discriminant expression
5310 -- within a type declaration, that freezes the predicated
5313 elsif From_Aspect_Specification
(N
)
5314 and then Prag_Id
= Pragma_Predicate
5315 and then Ekind
(Current_Scope
) = E_Record_Type
5316 and then Scop
= Scope
(Current_Scope
)
5320 -- Default case, just check that the pragma occurs in the scope
5321 -- of the entity denoted by the name.
5324 OK
:= Current_Scope
= Scop
;
5329 ("pragma% argument must be in same declarative part", Arg
);
5333 end Check_Arg_Is_Local_Name
;
5335 ---------------------------------
5336 -- Check_Arg_Is_Locking_Policy --
5337 ---------------------------------
5339 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
) is
5340 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5343 Check_Arg_Is_Identifier
(Argx
);
5345 if not Is_Locking_Policy_Name
(Chars
(Argx
)) then
5346 Error_Pragma_Arg
("& is not a valid locking policy name", Argx
);
5348 end Check_Arg_Is_Locking_Policy
;
5350 -----------------------------------------------
5351 -- Check_Arg_Is_Partition_Elaboration_Policy --
5352 -----------------------------------------------
5354 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
) is
5355 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5358 Check_Arg_Is_Identifier
(Argx
);
5360 if not Is_Partition_Elaboration_Policy_Name
(Chars
(Argx
)) then
5362 ("& is not a valid partition elaboration policy name", Argx
);
5364 end Check_Arg_Is_Partition_Elaboration_Policy
;
5366 -------------------------
5367 -- Check_Arg_Is_One_Of --
5368 -------------------------
5370 procedure Check_Arg_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
5371 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5374 Check_Arg_Is_Identifier
(Argx
);
5376 if not Nam_In
(Chars
(Argx
), N1
, N2
) then
5377 Error_Msg_Name_2
:= N1
;
5378 Error_Msg_Name_3
:= N2
;
5379 Error_Pragma_Arg
("argument for pragma% must be% or%", Argx
);
5381 end Check_Arg_Is_One_Of
;
5383 procedure Check_Arg_Is_One_Of
5385 N1
, N2
, N3
: Name_Id
)
5387 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5390 Check_Arg_Is_Identifier
(Argx
);
5392 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
) then
5393 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5395 end Check_Arg_Is_One_Of
;
5397 procedure Check_Arg_Is_One_Of
5399 N1
, N2
, N3
, N4
: Name_Id
)
5401 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5404 Check_Arg_Is_Identifier
(Argx
);
5406 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
) then
5407 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5409 end Check_Arg_Is_One_Of
;
5411 procedure Check_Arg_Is_One_Of
5413 N1
, N2
, N3
, N4
, N5
: Name_Id
)
5415 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5418 Check_Arg_Is_Identifier
(Argx
);
5420 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
, N5
) then
5421 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5423 end Check_Arg_Is_One_Of
;
5425 ---------------------------------
5426 -- Check_Arg_Is_Queuing_Policy --
5427 ---------------------------------
5429 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
) is
5430 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5433 Check_Arg_Is_Identifier
(Argx
);
5435 if not Is_Queuing_Policy_Name
(Chars
(Argx
)) then
5436 Error_Pragma_Arg
("& is not a valid queuing policy name", Argx
);
5438 end Check_Arg_Is_Queuing_Policy
;
5440 ---------------------------------------
5441 -- Check_Arg_Is_OK_Static_Expression --
5442 ---------------------------------------
5444 procedure Check_Arg_Is_OK_Static_Expression
5446 Typ
: Entity_Id
:= Empty
)
5449 Check_Expr_Is_OK_Static_Expression
(Get_Pragma_Arg
(Arg
), Typ
);
5450 end Check_Arg_Is_OK_Static_Expression
;
5452 ------------------------------------------
5453 -- Check_Arg_Is_Task_Dispatching_Policy --
5454 ------------------------------------------
5456 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
) is
5457 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5460 Check_Arg_Is_Identifier
(Argx
);
5462 if not Is_Task_Dispatching_Policy_Name
(Chars
(Argx
)) then
5464 ("& is not an allowed task dispatching policy name", Argx
);
5466 end Check_Arg_Is_Task_Dispatching_Policy
;
5468 ---------------------
5469 -- Check_Arg_Order --
5470 ---------------------
5472 procedure Check_Arg_Order
(Names
: Name_List
) is
5475 Highest_So_Far
: Natural := 0;
5476 -- Highest index in Names seen do far
5480 for J
in 1 .. Arg_Count
loop
5481 if Chars
(Arg
) /= No_Name
then
5482 for K
in Names
'Range loop
5483 if Chars
(Arg
) = Names
(K
) then
5484 if K
< Highest_So_Far
then
5485 Error_Msg_Name_1
:= Pname
;
5487 ("parameters out of order for pragma%", Arg
);
5488 Error_Msg_Name_1
:= Names
(K
);
5489 Error_Msg_Name_2
:= Names
(Highest_So_Far
);
5490 Error_Msg_N
("\% must appear before %", Arg
);
5494 Highest_So_Far
:= K
;
5502 end Check_Arg_Order
;
5504 --------------------------------
5505 -- Check_At_Least_N_Arguments --
5506 --------------------------------
5508 procedure Check_At_Least_N_Arguments
(N
: Nat
) is
5510 if Arg_Count
< N
then
5511 Error_Pragma
("too few arguments for pragma%");
5513 end Check_At_Least_N_Arguments
;
5515 -------------------------------
5516 -- Check_At_Most_N_Arguments --
5517 -------------------------------
5519 procedure Check_At_Most_N_Arguments
(N
: Nat
) is
5522 if Arg_Count
> N
then
5524 for J
in 1 .. N
loop
5526 Error_Pragma_Arg
("too many arguments for pragma%", Arg
);
5529 end Check_At_Most_N_Arguments
;
5531 ---------------------
5532 -- Check_Component --
5533 ---------------------
5535 procedure Check_Component
5538 In_Variant_Part
: Boolean := False)
5540 Comp_Id
: constant Entity_Id
:= Defining_Identifier
(Comp
);
5541 Sindic
: constant Node_Id
:=
5542 Subtype_Indication
(Component_Definition
(Comp
));
5543 Typ
: constant Entity_Id
:= Etype
(Comp_Id
);
5546 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5547 -- object constraint, then the component type shall be an Unchecked_
5550 if Nkind
(Sindic
) = N_Subtype_Indication
5551 and then Has_Per_Object_Constraint
(Comp_Id
)
5552 and then not Is_Unchecked_Union
(Etype
(Subtype_Mark
(Sindic
)))
5555 ("component subtype subject to per-object constraint "
5556 & "must be an Unchecked_Union", Comp
);
5558 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5559 -- the body of a generic unit, or within the body of any of its
5560 -- descendant library units, no part of the type of a component
5561 -- declared in a variant_part of the unchecked union type shall be of
5562 -- a formal private type or formal private extension declared within
5563 -- the formal part of the generic unit.
5565 elsif Ada_Version
>= Ada_2012
5566 and then In_Generic_Body
(UU_Typ
)
5567 and then In_Variant_Part
5568 and then Is_Private_Type
(Typ
)
5569 and then Is_Generic_Type
(Typ
)
5572 ("component of unchecked union cannot be of generic type", Comp
);
5574 elsif Needs_Finalization
(Typ
) then
5576 ("component of unchecked union cannot be controlled", Comp
);
5578 elsif Has_Task
(Typ
) then
5580 ("component of unchecked union cannot have tasks", Comp
);
5582 end Check_Component
;
5584 ----------------------------
5585 -- Check_Duplicate_Pragma --
5586 ----------------------------
5588 procedure Check_Duplicate_Pragma
(E
: Entity_Id
) is
5589 Id
: Entity_Id
:= E
;
5593 -- Nothing to do if this pragma comes from an aspect specification,
5594 -- since we could not be duplicating a pragma, and we dealt with the
5595 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5597 if From_Aspect_Specification
(N
) then
5601 -- Otherwise current pragma may duplicate previous pragma or a
5602 -- previously given aspect specification or attribute definition
5603 -- clause for the same pragma.
5605 P
:= Get_Rep_Item
(E
, Pragma_Name
(N
), Check_Parents
=> False);
5609 -- If the entity is a type, then we have to make sure that the
5610 -- ostensible duplicate is not for a parent type from which this
5614 if Nkind
(P
) = N_Pragma
then
5616 Args
: constant List_Id
:=
5617 Pragma_Argument_Associations
(P
);
5620 and then Is_Entity_Name
(Expression
(First
(Args
)))
5621 and then Is_Type
(Entity
(Expression
(First
(Args
))))
5622 and then Entity
(Expression
(First
(Args
))) /= E
5628 elsif Nkind
(P
) = N_Aspect_Specification
5629 and then Is_Type
(Entity
(P
))
5630 and then Entity
(P
) /= E
5636 -- Here we have a definite duplicate
5638 Error_Msg_Name_1
:= Pragma_Name
(N
);
5639 Error_Msg_Sloc
:= Sloc
(P
);
5641 -- For a single protected or a single task object, the error is
5642 -- issued on the original entity.
5644 if Ekind_In
(Id
, E_Task_Type
, E_Protected_Type
) then
5645 Id
:= Defining_Identifier
(Original_Node
(Parent
(Id
)));
5648 if Nkind
(P
) = N_Aspect_Specification
5649 or else From_Aspect_Specification
(P
)
5651 Error_Msg_NE
("aspect% for & previously given#", N
, Id
);
5653 Error_Msg_NE
("pragma% for & duplicates pragma#", N
, Id
);
5658 end Check_Duplicate_Pragma
;
5660 ----------------------------------
5661 -- Check_Duplicated_Export_Name --
5662 ----------------------------------
5664 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
) is
5665 String_Val
: constant String_Id
:= Strval
(Nam
);
5668 -- We are only interested in the export case, and in the case of
5669 -- generics, it is the instance, not the template, that is the
5670 -- problem (the template will generate a warning in any case).
5672 if not Inside_A_Generic
5673 and then (Prag_Id
= Pragma_Export
5675 Prag_Id
= Pragma_Export_Procedure
5677 Prag_Id
= Pragma_Export_Valued_Procedure
5679 Prag_Id
= Pragma_Export_Function
)
5681 for J
in Externals
.First
.. Externals
.Last
loop
5682 if String_Equal
(String_Val
, Strval
(Externals
.Table
(J
))) then
5683 Error_Msg_Sloc
:= Sloc
(Externals
.Table
(J
));
5684 Error_Msg_N
("external name duplicates name given#", Nam
);
5689 Externals
.Append
(Nam
);
5691 end Check_Duplicated_Export_Name
;
5693 ----------------------------------------
5694 -- Check_Expr_Is_OK_Static_Expression --
5695 ----------------------------------------
5697 procedure Check_Expr_Is_OK_Static_Expression
5699 Typ
: Entity_Id
:= Empty
)
5702 if Present
(Typ
) then
5703 Analyze_And_Resolve
(Expr
, Typ
);
5705 Analyze_And_Resolve
(Expr
);
5708 -- An expression cannot be considered static if its resolution failed
5709 -- or if it's erroneous. Stop the analysis of the related pragma.
5711 if Etype
(Expr
) = Any_Type
or else Error_Posted
(Expr
) then
5714 elsif Is_OK_Static_Expression
(Expr
) then
5717 -- An interesting special case, if we have a string literal and we
5718 -- are in Ada 83 mode, then we allow it even though it will not be
5719 -- flagged as static. This allows the use of Ada 95 pragmas like
5720 -- Import in Ada 83 mode. They will of course be flagged with
5721 -- warnings as usual, but will not cause errors.
5723 elsif Ada_Version
= Ada_83
5724 and then Nkind
(Expr
) = N_String_Literal
5728 -- Finally, we have a real error
5731 Error_Msg_Name_1
:= Pname
;
5732 Flag_Non_Static_Expr
5733 (Fix_Error
("argument for pragma% must be a static expression!"),
5737 end Check_Expr_Is_OK_Static_Expression
;
5739 -------------------------
5740 -- Check_First_Subtype --
5741 -------------------------
5743 procedure Check_First_Subtype
(Arg
: Node_Id
) is
5744 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5745 Ent
: constant Entity_Id
:= Entity
(Argx
);
5748 if Is_First_Subtype
(Ent
) then
5751 elsif Is_Type
(Ent
) then
5753 ("pragma% cannot apply to subtype", Argx
);
5755 elsif Is_Object
(Ent
) then
5757 ("pragma% cannot apply to object, requires a type", Argx
);
5761 ("pragma% cannot apply to&, requires a type", Argx
);
5763 end Check_First_Subtype
;
5765 ----------------------
5766 -- Check_Identifier --
5767 ----------------------
5769 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
5772 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5774 if Chars
(Arg
) = No_Name
or else Chars
(Arg
) /= Id
then
5775 Error_Msg_Name_1
:= Pname
;
5776 Error_Msg_Name_2
:= Id
;
5777 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
5781 end Check_Identifier
;
5783 --------------------------------
5784 -- Check_Identifier_Is_One_Of --
5785 --------------------------------
5787 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
5790 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5792 if Chars
(Arg
) = No_Name
then
5793 Error_Msg_Name_1
:= Pname
;
5794 Error_Msg_N
("pragma% argument expects an identifier", Arg
);
5797 elsif Chars
(Arg
) /= N1
5798 and then Chars
(Arg
) /= N2
5800 Error_Msg_Name_1
:= Pname
;
5801 Error_Msg_N
("invalid identifier for pragma% argument", Arg
);
5805 end Check_Identifier_Is_One_Of
;
5807 ---------------------------
5808 -- Check_In_Main_Program --
5809 ---------------------------
5811 procedure Check_In_Main_Program
is
5812 P
: constant Node_Id
:= Parent
(N
);
5815 -- Must be in subprogram body
5817 if Nkind
(P
) /= N_Subprogram_Body
then
5818 Error_Pragma
("% pragma allowed only in subprogram");
5820 -- Otherwise warn if obviously not main program
5822 elsif Present
(Parameter_Specifications
(Specification
(P
)))
5823 or else not Is_Compilation_Unit
(Defining_Entity
(P
))
5825 Error_Msg_Name_1
:= Pname
;
5827 ("??pragma% is only effective in main program", N
);
5829 end Check_In_Main_Program
;
5831 ---------------------------------------
5832 -- Check_Interrupt_Or_Attach_Handler --
5833 ---------------------------------------
5835 procedure Check_Interrupt_Or_Attach_Handler
is
5836 Arg1_X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
5837 Handler_Proc
, Proc_Scope
: Entity_Id
;
5842 if Prag_Id
= Pragma_Interrupt_Handler
then
5843 Check_Restriction
(No_Dynamic_Attachment
, N
);
5846 Handler_Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
5847 Proc_Scope
:= Scope
(Handler_Proc
);
5849 if Ekind
(Proc_Scope
) /= E_Protected_Type
then
5851 ("argument of pragma% must be protected procedure", Arg1
);
5854 -- For pragma case (as opposed to access case), check placement.
5855 -- We don't need to do that for aspects, because we have the
5856 -- check that they aspect applies an appropriate procedure.
5858 if not From_Aspect_Specification
(N
)
5859 and then Parent
(N
) /= Protected_Definition
(Parent
(Proc_Scope
))
5861 Error_Pragma
("pragma% must be in protected definition");
5864 if not Is_Library_Level_Entity
(Proc_Scope
) then
5866 ("argument for pragma% must be library level entity", Arg1
);
5869 -- AI05-0033: A pragma cannot appear within a generic body, because
5870 -- instance can be in a nested scope. The check that protected type
5871 -- is itself a library-level declaration is done elsewhere.
5873 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5874 -- handle code prior to AI-0033. Analysis tools typically are not
5875 -- interested in this pragma in any case, so no need to worry too
5876 -- much about its placement.
5878 if Inside_A_Generic
then
5879 if Ekind
(Scope
(Current_Scope
)) = E_Generic_Package
5880 and then In_Package_Body
(Scope
(Current_Scope
))
5881 and then not Relaxed_RM_Semantics
5883 Error_Pragma
("pragma% cannot be used inside a generic");
5886 end Check_Interrupt_Or_Attach_Handler
;
5888 ---------------------------------
5889 -- Check_Loop_Pragma_Placement --
5890 ---------------------------------
5892 procedure Check_Loop_Pragma_Placement
is
5893 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
);
5894 -- Verify whether the current pragma is properly grouped with other
5895 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5896 -- related loop where the pragma appears.
5898 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean;
5899 -- Determine whether an arbitrary statement Stmt denotes pragma
5900 -- Loop_Invariant or Loop_Variant.
5902 procedure Placement_Error
(Constr
: Node_Id
);
5903 pragma No_Return
(Placement_Error
);
5904 -- Node Constr denotes the last loop restricted construct before we
5905 -- encountered an illegal relation between enclosing constructs. Emit
5906 -- an error depending on what Constr was.
5908 --------------------------------
5909 -- Check_Loop_Pragma_Grouping --
5910 --------------------------------
5912 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
) is
5913 Stop_Search
: exception;
5914 -- This exception is used to terminate the recursive descent of
5915 -- routine Check_Grouping.
5917 procedure Check_Grouping
(L
: List_Id
);
5918 -- Find the first group of pragmas in list L and if successful,
5919 -- ensure that the current pragma is part of that group. The
5920 -- routine raises Stop_Search once such a check is performed to
5921 -- halt the recursive descent.
5923 procedure Grouping_Error
(Prag
: Node_Id
);
5924 pragma No_Return
(Grouping_Error
);
5925 -- Emit an error concerning the current pragma indicating that it
5926 -- should be placed after pragma Prag.
5928 --------------------
5929 -- Check_Grouping --
5930 --------------------
5932 procedure Check_Grouping
(L
: List_Id
) is
5935 Prag
: Node_Id
:= Empty
; -- init to avoid warning
5938 -- Inspect the list of declarations or statements looking for
5939 -- the first grouping of pragmas:
5942 -- pragma Loop_Invariant ...;
5943 -- pragma Loop_Variant ...;
5945 -- pragma Loop_Variant ...; -- current pragma
5947 -- If the current pragma is not in the grouping, then it must
5948 -- either appear in a different declarative or statement list
5949 -- or the construct at (1) is separating the pragma from the
5953 while Present
(Stmt
) loop
5955 -- First pragma of the first topmost grouping has been found
5957 if Is_Loop_Pragma
(Stmt
) then
5959 -- The group and the current pragma are not in the same
5960 -- declarative or statement list.
5962 if List_Containing
(Stmt
) /= List_Containing
(N
) then
5963 Grouping_Error
(Stmt
);
5965 -- Try to reach the current pragma from the first pragma
5966 -- of the grouping while skipping other members:
5968 -- pragma Loop_Invariant ...; -- first pragma
5969 -- pragma Loop_Variant ...; -- member
5971 -- pragma Loop_Variant ...; -- current pragma
5974 while Present
(Stmt
) loop
5975 -- The current pragma is either the first pragma
5976 -- of the group or is a member of the group.
5977 -- Stop the search as the placement is legal.
5982 -- Skip group members, but keep track of the
5983 -- last pragma in the group.
5985 elsif Is_Loop_Pragma
(Stmt
) then
5988 -- Skip declarations and statements generated by
5989 -- the compiler during expansion. Note that some
5990 -- source statements (e.g. pragma Assert) may have
5991 -- been transformed so that they do not appear as
5992 -- coming from source anymore, so we instead look
5993 -- at their Original_Node.
5995 elsif not Comes_From_Source
(Original_Node
(Stmt
))
5999 -- A non-pragma is separating the group from the
6000 -- current pragma, the placement is illegal.
6003 Grouping_Error
(Prag
);
6009 -- If the traversal did not reach the current pragma,
6010 -- then the list must be malformed.
6012 raise Program_Error
;
6015 -- Pragmas Loop_Invariant and Loop_Variant may only appear
6016 -- inside a loop or a block housed inside a loop. Inspect
6017 -- the declarations and statements of the block as they may
6018 -- contain the first grouping. This case follows the one for
6019 -- loop pragmas, as block statements which originate in a
6020 -- loop pragma (and so Is_Loop_Pragma will return True on
6021 -- that block statement) should be treated in the previous
6024 elsif Nkind
(Stmt
) = N_Block_Statement
then
6025 HSS
:= Handled_Statement_Sequence
(Stmt
);
6027 Check_Grouping
(Declarations
(Stmt
));
6029 if Present
(HSS
) then
6030 Check_Grouping
(Statements
(HSS
));
6038 --------------------
6039 -- Grouping_Error --
6040 --------------------
6042 procedure Grouping_Error
(Prag
: Node_Id
) is
6044 Error_Msg_Sloc
:= Sloc
(Prag
);
6045 Error_Pragma
("pragma% must appear next to pragma#");
6048 -- Start of processing for Check_Loop_Pragma_Grouping
6051 -- Inspect the statements of the loop or nested blocks housed
6052 -- within to determine whether the current pragma is part of the
6053 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6055 Check_Grouping
(Statements
(Loop_Stmt
));
6058 when Stop_Search
=> null;
6059 end Check_Loop_Pragma_Grouping
;
6061 --------------------
6062 -- Is_Loop_Pragma --
6063 --------------------
6065 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean is
6067 -- Inspect the original node as Loop_Invariant and Loop_Variant
6068 -- pragmas are rewritten to null when assertions are disabled.
6070 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
then
6072 Nam_In
(Pragma_Name_Unmapped
(Original_Node
(Stmt
)),
6073 Name_Loop_Invariant
,
6080 ---------------------
6081 -- Placement_Error --
6082 ---------------------
6084 procedure Placement_Error
(Constr
: Node_Id
) is
6085 LA
: constant String := " with Loop_Entry";
6088 if Prag_Id
= Pragma_Assert
then
6089 Error_Msg_String
(1 .. LA
'Length) := LA
;
6090 Error_Msg_Strlen
:= LA
'Length;
6092 Error_Msg_Strlen
:= 0;
6095 if Nkind
(Constr
) = N_Pragma
then
6097 ("pragma %~ must appear immediately within the statements "
6101 ("block containing pragma %~ must appear immediately within "
6102 & "the statements of a loop", Constr
);
6104 end Placement_Error
;
6106 -- Local declarations
6111 -- Start of processing for Check_Loop_Pragma_Placement
6114 -- Check that pragma appears immediately within a loop statement,
6115 -- ignoring intervening block statements.
6119 while Present
(Stmt
) loop
6121 -- The pragma or previous block must appear immediately within the
6122 -- current block's declarative or statement part.
6124 if Nkind
(Stmt
) = N_Block_Statement
then
6125 if (No
(Declarations
(Stmt
))
6126 or else List_Containing
(Prev
) /= Declarations
(Stmt
))
6128 List_Containing
(Prev
) /=
6129 Statements
(Handled_Statement_Sequence
(Stmt
))
6131 Placement_Error
(Prev
);
6134 -- Keep inspecting the parents because we are now within a
6135 -- chain of nested blocks.
6139 Stmt
:= Parent
(Stmt
);
6142 -- The pragma or previous block must appear immediately within the
6143 -- statements of the loop.
6145 elsif Nkind
(Stmt
) = N_Loop_Statement
then
6146 if List_Containing
(Prev
) /= Statements
(Stmt
) then
6147 Placement_Error
(Prev
);
6150 -- Stop the traversal because we reached the innermost loop
6151 -- regardless of whether we encountered an error or not.
6155 -- Ignore a handled statement sequence. Note that this node may
6156 -- be related to a subprogram body in which case we will emit an
6157 -- error on the next iteration of the search.
6159 elsif Nkind
(Stmt
) = N_Handled_Sequence_Of_Statements
then
6160 Stmt
:= Parent
(Stmt
);
6162 -- Any other statement breaks the chain from the pragma to the
6166 Placement_Error
(Prev
);
6171 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6172 -- grouped together with other such pragmas.
6174 if Is_Loop_Pragma
(N
) then
6176 -- The previous check should have located the related loop
6178 pragma Assert
(Nkind
(Stmt
) = N_Loop_Statement
);
6179 Check_Loop_Pragma_Grouping
(Stmt
);
6181 end Check_Loop_Pragma_Placement
;
6183 -------------------------------------------
6184 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6185 -------------------------------------------
6187 procedure Check_Is_In_Decl_Part_Or_Package_Spec
is
6196 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
then
6199 elsif Nkind_In
(P
, N_Package_Specification
,
6204 -- Note: the following tests seem a little peculiar, because
6205 -- they test for bodies, but if we were in the statement part
6206 -- of the body, we would already have hit the handled statement
6207 -- sequence, so the only way we get here is by being in the
6208 -- declarative part of the body.
6210 elsif Nkind_In
(P
, N_Subprogram_Body
,
6221 Error_Pragma
("pragma% is not in declarative part or package spec");
6222 end Check_Is_In_Decl_Part_Or_Package_Spec
;
6224 -------------------------
6225 -- Check_No_Identifier --
6226 -------------------------
6228 procedure Check_No_Identifier
(Arg
: Node_Id
) is
6230 if Nkind
(Arg
) = N_Pragma_Argument_Association
6231 and then Chars
(Arg
) /= No_Name
6233 Error_Pragma_Arg_Ident
6234 ("pragma% does not permit identifier& here", Arg
);
6236 end Check_No_Identifier
;
6238 --------------------------
6239 -- Check_No_Identifiers --
6240 --------------------------
6242 procedure Check_No_Identifiers
is
6246 for J
in 1 .. Arg_Count
loop
6247 Check_No_Identifier
(Arg_Node
);
6250 end Check_No_Identifiers
;
6252 ------------------------
6253 -- Check_No_Link_Name --
6254 ------------------------
6256 procedure Check_No_Link_Name
is
6258 if Present
(Arg3
) and then Chars
(Arg3
) = Name_Link_Name
then
6262 if Present
(Arg4
) then
6264 ("Link_Name argument not allowed for Import Intrinsic", Arg4
);
6266 end Check_No_Link_Name
;
6268 -------------------------------
6269 -- Check_Optional_Identifier --
6270 -------------------------------
6272 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
6275 and then Nkind
(Arg
) = N_Pragma_Argument_Association
6276 and then Chars
(Arg
) /= No_Name
6278 if Chars
(Arg
) /= Id
then
6279 Error_Msg_Name_1
:= Pname
;
6280 Error_Msg_Name_2
:= Id
;
6281 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
6285 end Check_Optional_Identifier
;
6287 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String) is
6289 Check_Optional_Identifier
(Arg
, Name_Find
(Id
));
6290 end Check_Optional_Identifier
;
6292 -------------------------------------
6293 -- Check_Static_Boolean_Expression --
6294 -------------------------------------
6296 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
) is
6298 if Present
(Expr
) then
6299 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
6301 if not Is_OK_Static_Expression
(Expr
) then
6303 ("expression of pragma % must be static", Expr
);
6306 end Check_Static_Boolean_Expression
;
6308 -----------------------------
6309 -- Check_Static_Constraint --
6310 -----------------------------
6312 -- Note: for convenience in writing this procedure, in addition to
6313 -- the officially (i.e. by spec) allowed argument which is always a
6314 -- constraint, it also allows ranges and discriminant associations.
6315 -- Above is not clear ???
6317 procedure Check_Static_Constraint
(Constr
: Node_Id
) is
6319 procedure Require_Static
(E
: Node_Id
);
6320 -- Require given expression to be static expression
6322 --------------------
6323 -- Require_Static --
6324 --------------------
6326 procedure Require_Static
(E
: Node_Id
) is
6328 if not Is_OK_Static_Expression
(E
) then
6329 Flag_Non_Static_Expr
6330 ("non-static constraint not allowed in Unchecked_Union!", E
);
6335 -- Start of processing for Check_Static_Constraint
6338 case Nkind
(Constr
) is
6339 when N_Discriminant_Association
=>
6340 Require_Static
(Expression
(Constr
));
6343 Require_Static
(Low_Bound
(Constr
));
6344 Require_Static
(High_Bound
(Constr
));
6346 when N_Attribute_Reference
=>
6347 Require_Static
(Type_Low_Bound
(Etype
(Prefix
(Constr
))));
6348 Require_Static
(Type_High_Bound
(Etype
(Prefix
(Constr
))));
6350 when N_Range_Constraint
=>
6351 Check_Static_Constraint
(Range_Expression
(Constr
));
6353 when N_Index_Or_Discriminant_Constraint
=>
6357 IDC
:= First
(Constraints
(Constr
));
6358 while Present
(IDC
) loop
6359 Check_Static_Constraint
(IDC
);
6367 end Check_Static_Constraint
;
6369 --------------------------------------
6370 -- Check_Valid_Configuration_Pragma --
6371 --------------------------------------
6373 -- A configuration pragma must appear in the context clause of a
6374 -- compilation unit, and only other pragmas may precede it. Note that
6375 -- the test also allows use in a configuration pragma file.
6377 procedure Check_Valid_Configuration_Pragma
is
6379 if not Is_Configuration_Pragma
then
6380 Error_Pragma
("incorrect placement for configuration pragma%");
6382 end Check_Valid_Configuration_Pragma
;
6384 -------------------------------------
6385 -- Check_Valid_Library_Unit_Pragma --
6386 -------------------------------------
6388 procedure Check_Valid_Library_Unit_Pragma
is
6390 Parent_Node
: Node_Id
;
6391 Unit_Name
: Entity_Id
;
6392 Unit_Kind
: Node_Kind
;
6393 Unit_Node
: Node_Id
;
6394 Sindex
: Source_File_Index
;
6397 if not Is_List_Member
(N
) then
6401 Plist
:= List_Containing
(N
);
6402 Parent_Node
:= Parent
(Plist
);
6404 if Parent_Node
= Empty
then
6407 -- Case of pragma appearing after a compilation unit. In this case
6408 -- it must have an argument with the corresponding name and must
6409 -- be part of the following pragmas of its parent.
6411 elsif Nkind
(Parent_Node
) = N_Compilation_Unit_Aux
then
6412 if Plist
/= Pragmas_After
(Parent_Node
) then
6415 elsif Arg_Count
= 0 then
6417 ("argument required if outside compilation unit");
6420 Check_No_Identifiers
;
6421 Check_Arg_Count
(1);
6422 Unit_Node
:= Unit
(Parent
(Parent_Node
));
6423 Unit_Kind
:= Nkind
(Unit_Node
);
6425 Analyze
(Get_Pragma_Arg
(Arg1
));
6427 if Unit_Kind
= N_Generic_Subprogram_Declaration
6428 or else Unit_Kind
= N_Subprogram_Declaration
6430 Unit_Name
:= Defining_Entity
(Unit_Node
);
6432 elsif Unit_Kind
in N_Generic_Instantiation
then
6433 Unit_Name
:= Defining_Entity
(Unit_Node
);
6436 Unit_Name
:= Cunit_Entity
(Current_Sem_Unit
);
6439 if Chars
(Unit_Name
) /=
6440 Chars
(Entity
(Get_Pragma_Arg
(Arg1
)))
6443 ("pragma% argument is not current unit name", Arg1
);
6446 if Ekind
(Unit_Name
) = E_Package
6447 and then Present
(Renamed_Entity
(Unit_Name
))
6449 Error_Pragma
("pragma% not allowed for renamed package");
6453 -- Pragma appears other than after a compilation unit
6456 -- Here we check for the generic instantiation case and also
6457 -- for the case of processing a generic formal package. We
6458 -- detect these cases by noting that the Sloc on the node
6459 -- does not belong to the current compilation unit.
6461 Sindex
:= Source_Index
(Current_Sem_Unit
);
6463 if Loc
not in Source_First
(Sindex
) .. Source_Last
(Sindex
) then
6464 Rewrite
(N
, Make_Null_Statement
(Loc
));
6467 -- If before first declaration, the pragma applies to the
6468 -- enclosing unit, and the name if present must be this name.
6470 elsif Is_Before_First_Decl
(N
, Plist
) then
6471 Unit_Node
:= Unit_Declaration_Node
(Current_Scope
);
6472 Unit_Kind
:= Nkind
(Unit_Node
);
6474 if Nkind
(Parent
(Unit_Node
)) /= N_Compilation_Unit
then
6477 elsif Unit_Kind
= N_Subprogram_Body
6478 and then not Acts_As_Spec
(Unit_Node
)
6482 elsif Nkind
(Parent_Node
) = N_Package_Body
then
6485 elsif Nkind
(Parent_Node
) = N_Package_Specification
6486 and then Plist
= Private_Declarations
(Parent_Node
)
6490 elsif (Nkind
(Parent_Node
) = N_Generic_Package_Declaration
6491 or else Nkind
(Parent_Node
) =
6492 N_Generic_Subprogram_Declaration
)
6493 and then Plist
= Generic_Formal_Declarations
(Parent_Node
)
6497 elsif Arg_Count
> 0 then
6498 Analyze
(Get_Pragma_Arg
(Arg1
));
6500 if Entity
(Get_Pragma_Arg
(Arg1
)) /= Current_Scope
then
6502 ("name in pragma% must be enclosing unit", Arg1
);
6505 -- It is legal to have no argument in this context
6511 -- Error if not before first declaration. This is because a
6512 -- library unit pragma argument must be the name of a library
6513 -- unit (RM 10.1.5(7)), but the only names permitted in this
6514 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6515 -- generic subprogram declarations or generic instantiations.
6519 ("pragma% misplaced, must be before first declaration");
6523 end Check_Valid_Library_Unit_Pragma
;
6529 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
) is
6530 Clist
: constant Node_Id
:= Component_List
(Variant
);
6534 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
6535 while Present
(Comp
) loop
6536 Check_Component
(Comp
, UU_Typ
, In_Variant_Part
=> True);
6537 Next_Non_Pragma
(Comp
);
6541 ---------------------------
6542 -- Ensure_Aggregate_Form --
6543 ---------------------------
6545 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
) is
6546 CFSD
: constant Boolean := Get_Comes_From_Source_Default
;
6547 Expr
: constant Node_Id
:= Expression
(Arg
);
6548 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6549 Comps
: List_Id
:= No_List
;
6550 Exprs
: List_Id
:= No_List
;
6551 Nam
: Name_Id
:= No_Name
;
6552 Nam_Loc
: Source_Ptr
;
6555 -- The pragma argument is in positional form:
6557 -- pragma Depends (Nam => ...)
6561 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6562 -- argument association.
6564 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
6566 Nam_Loc
:= Sloc
(Arg
);
6568 -- Remove the pragma argument name as this will be captured in the
6571 Set_Chars
(Arg
, No_Name
);
6574 -- The argument is already in aggregate form, but the presence of a
6575 -- name causes this to be interpreted as named association which in
6576 -- turn must be converted into an aggregate.
6578 -- pragma Global (In_Out => (A, B, C))
6582 -- pragma Global ((In_Out => (A, B, C)))
6584 -- aggregate aggregate
6586 if Nkind
(Expr
) = N_Aggregate
then
6587 if Nam
= No_Name
then
6591 -- Do not transform a null argument into an aggregate as N_Null has
6592 -- special meaning in formal verification pragmas.
6594 elsif Nkind
(Expr
) = N_Null
then
6598 -- Everything comes from source if the original comes from source
6600 Set_Comes_From_Source_Default
(Comes_From_Source
(Arg
));
6602 -- Positional argument is transformed into an aggregate with an
6603 -- Expressions list.
6605 if Nam
= No_Name
then
6606 Exprs
:= New_List
(Relocate_Node
(Expr
));
6608 -- An associative argument is transformed into an aggregate with
6609 -- Component_Associations.
6613 Make_Component_Association
(Loc
,
6614 Choices
=> New_List
(Make_Identifier
(Nam_Loc
, Nam
)),
6615 Expression
=> Relocate_Node
(Expr
)));
6618 Set_Expression
(Arg
,
6619 Make_Aggregate
(Loc
,
6620 Component_Associations
=> Comps
,
6621 Expressions
=> Exprs
));
6623 -- Restore Comes_From_Source default
6625 Set_Comes_From_Source_Default
(CFSD
);
6626 end Ensure_Aggregate_Form
;
6632 procedure Error_Pragma
(Msg
: String) is
6634 Error_Msg_Name_1
:= Pname
;
6635 Error_Msg_N
(Fix_Error
(Msg
), N
);
6639 ----------------------
6640 -- Error_Pragma_Arg --
6641 ----------------------
6643 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
) is
6645 Error_Msg_Name_1
:= Pname
;
6646 Error_Msg_N
(Fix_Error
(Msg
), Get_Pragma_Arg
(Arg
));
6648 end Error_Pragma_Arg
;
6650 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
) is
6652 Error_Msg_Name_1
:= Pname
;
6653 Error_Msg_N
(Fix_Error
(Msg1
), Get_Pragma_Arg
(Arg
));
6654 Error_Pragma_Arg
(Msg2
, Arg
);
6655 end Error_Pragma_Arg
;
6657 ----------------------------
6658 -- Error_Pragma_Arg_Ident --
6659 ----------------------------
6661 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
) is
6663 Error_Msg_Name_1
:= Pname
;
6664 Error_Msg_N
(Fix_Error
(Msg
), Arg
);
6666 end Error_Pragma_Arg_Ident
;
6668 ----------------------
6669 -- Error_Pragma_Ref --
6670 ----------------------
6672 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
) is
6674 Error_Msg_Name_1
:= Pname
;
6675 Error_Msg_Sloc
:= Sloc
(Ref
);
6676 Error_Msg_NE
(Fix_Error
(Msg
), N
, Ref
);
6678 end Error_Pragma_Ref
;
6680 ------------------------
6681 -- Find_Lib_Unit_Name --
6682 ------------------------
6684 function Find_Lib_Unit_Name
return Entity_Id
is
6686 -- Return inner compilation unit entity, for case of nested
6687 -- categorization pragmas. This happens in generic unit.
6689 if Nkind
(Parent
(N
)) = N_Package_Specification
6690 and then Defining_Entity
(Parent
(N
)) /= Current_Scope
6692 return Defining_Entity
(Parent
(N
));
6694 return Current_Scope
;
6696 end Find_Lib_Unit_Name
;
6698 ----------------------------
6699 -- Find_Program_Unit_Name --
6700 ----------------------------
6702 procedure Find_Program_Unit_Name
(Id
: Node_Id
) is
6703 Unit_Name
: Entity_Id
;
6704 Unit_Kind
: Node_Kind
;
6705 P
: constant Node_Id
:= Parent
(N
);
6708 if Nkind
(P
) = N_Compilation_Unit
then
6709 Unit_Kind
:= Nkind
(Unit
(P
));
6711 if Nkind_In
(Unit_Kind
, N_Subprogram_Declaration
,
6712 N_Package_Declaration
)
6713 or else Unit_Kind
in N_Generic_Declaration
6715 Unit_Name
:= Defining_Entity
(Unit
(P
));
6717 if Chars
(Id
) = Chars
(Unit_Name
) then
6718 Set_Entity
(Id
, Unit_Name
);
6719 Set_Etype
(Id
, Etype
(Unit_Name
));
6721 Set_Etype
(Id
, Any_Type
);
6723 ("cannot find program unit referenced by pragma%");
6727 Set_Etype
(Id
, Any_Type
);
6728 Error_Pragma
("pragma% inapplicable to this unit");
6734 end Find_Program_Unit_Name
;
6736 -----------------------------------------
6737 -- Find_Unique_Parameterless_Procedure --
6738 -----------------------------------------
6740 function Find_Unique_Parameterless_Procedure
6742 Arg
: Node_Id
) return Entity_Id
6744 Proc
: Entity_Id
:= Empty
;
6747 -- The body of this procedure needs some comments ???
6749 if not Is_Entity_Name
(Name
) then
6751 ("argument of pragma% must be entity name", Arg
);
6753 elsif not Is_Overloaded
(Name
) then
6754 Proc
:= Entity
(Name
);
6756 if Ekind
(Proc
) /= E_Procedure
6757 or else Present
(First_Formal
(Proc
))
6760 ("argument of pragma% must be parameterless procedure", Arg
);
6765 Found
: Boolean := False;
6767 Index
: Interp_Index
;
6770 Get_First_Interp
(Name
, Index
, It
);
6771 while Present
(It
.Nam
) loop
6774 if Ekind
(Proc
) = E_Procedure
6775 and then No
(First_Formal
(Proc
))
6779 Set_Entity
(Name
, Proc
);
6780 Set_Is_Overloaded
(Name
, False);
6783 ("ambiguous handler name for pragma% ", Arg
);
6787 Get_Next_Interp
(Index
, It
);
6792 ("argument of pragma% must be parameterless procedure",
6795 Proc
:= Entity
(Name
);
6801 end Find_Unique_Parameterless_Procedure
;
6807 function Fix_Error
(Msg
: String) return String is
6808 Res
: String (Msg
'Range) := Msg
;
6809 Res_Last
: Natural := Msg
'Last;
6813 -- If we have a rewriting of another pragma, go to that pragma
6815 if Is_Rewrite_Substitution
(N
)
6816 and then Nkind
(Original_Node
(N
)) = N_Pragma
6818 Error_Msg_Name_1
:= Pragma_Name
(Original_Node
(N
));
6821 -- Case where pragma comes from an aspect specification
6823 if From_Aspect_Specification
(N
) then
6825 -- Change appearence of "pragma" in message to "aspect"
6828 while J
<= Res_Last
- 5 loop
6829 if Res
(J
.. J
+ 5) = "pragma" then
6830 Res
(J
.. J
+ 5) := "aspect";
6838 -- Change "argument of" at start of message to "entity for"
6841 and then Res
(Res
'First .. Res
'First + 10) = "argument of"
6843 Res
(Res
'First .. Res
'First + 9) := "entity for";
6844 Res
(Res
'First + 10 .. Res_Last
- 1) :=
6845 Res
(Res
'First + 11 .. Res_Last
);
6846 Res_Last
:= Res_Last
- 1;
6849 -- Change "argument" at start of message to "entity"
6852 and then Res
(Res
'First .. Res
'First + 7) = "argument"
6854 Res
(Res
'First .. Res
'First + 5) := "entity";
6855 Res
(Res
'First + 6 .. Res_Last
- 2) :=
6856 Res
(Res
'First + 8 .. Res_Last
);
6857 Res_Last
:= Res_Last
- 2;
6860 -- Get name from corresponding aspect
6862 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(N
);
6865 -- Return possibly modified message
6867 return Res
(Res
'First .. Res_Last
);
6870 -------------------------
6871 -- Gather_Associations --
6872 -------------------------
6874 procedure Gather_Associations
6876 Args
: out Args_List
)
6881 -- Initialize all parameters to Empty
6883 for J
in Args
'Range loop
6887 -- That's all we have to do if there are no argument associations
6889 if No
(Pragma_Argument_Associations
(N
)) then
6893 -- Otherwise first deal with any positional parameters present
6895 Arg
:= First
(Pragma_Argument_Associations
(N
));
6896 for Index
in Args
'Range loop
6897 exit when No
(Arg
) or else Chars
(Arg
) /= No_Name
;
6898 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6902 -- Positional parameters all processed, if any left, then we
6903 -- have too many positional parameters.
6905 if Present
(Arg
) and then Chars
(Arg
) = No_Name
then
6907 ("too many positional associations for pragma%", Arg
);
6910 -- Process named parameters if any are present
6912 while Present
(Arg
) loop
6913 if Chars
(Arg
) = No_Name
then
6915 ("positional association cannot follow named association",
6919 for Index
in Names
'Range loop
6920 if Names
(Index
) = Chars
(Arg
) then
6921 if Present
(Args
(Index
)) then
6923 ("duplicate argument association for pragma%", Arg
);
6925 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6930 if Index
= Names
'Last then
6931 Error_Msg_Name_1
:= Pname
;
6932 Error_Msg_N
("pragma% does not allow & argument", Arg
);
6934 -- Check for possible misspelling
6936 for Index1
in Names
'Range loop
6937 if Is_Bad_Spelling_Of
6938 (Chars
(Arg
), Names
(Index1
))
6940 Error_Msg_Name_1
:= Names
(Index1
);
6941 Error_Msg_N
-- CODEFIX
6942 ("\possible misspelling of%", Arg
);
6954 end Gather_Associations
;
6960 procedure GNAT_Pragma
is
6962 -- We need to check the No_Implementation_Pragmas restriction for
6963 -- the case of a pragma from source. Note that the case of aspects
6964 -- generating corresponding pragmas marks these pragmas as not being
6965 -- from source, so this test also catches that case.
6967 if Comes_From_Source
(N
) then
6968 Check_Restriction
(No_Implementation_Pragmas
, N
);
6972 --------------------------
6973 -- Is_Before_First_Decl --
6974 --------------------------
6976 function Is_Before_First_Decl
6977 (Pragma_Node
: Node_Id
;
6978 Decls
: List_Id
) return Boolean
6980 Item
: Node_Id
:= First
(Decls
);
6983 -- Only other pragmas can come before this pragma
6986 if No
(Item
) or else Nkind
(Item
) /= N_Pragma
then
6989 elsif Item
= Pragma_Node
then
6995 end Is_Before_First_Decl
;
6997 -----------------------------
6998 -- Is_Configuration_Pragma --
6999 -----------------------------
7001 -- A configuration pragma must appear in the context clause of a
7002 -- compilation unit, and only other pragmas may precede it. Note that
7003 -- the test below also permits use in a configuration pragma file.
7005 function Is_Configuration_Pragma
return Boolean is
7006 Lis
: constant List_Id
:= List_Containing
(N
);
7007 Par
: constant Node_Id
:= Parent
(N
);
7011 -- If no parent, then we are in the configuration pragma file,
7012 -- so the placement is definitely appropriate.
7017 -- Otherwise we must be in the context clause of a compilation unit
7018 -- and the only thing allowed before us in the context list is more
7019 -- configuration pragmas.
7021 elsif Nkind
(Par
) = N_Compilation_Unit
7022 and then Context_Items
(Par
) = Lis
7029 elsif Nkind
(Prg
) /= N_Pragma
then
7039 end Is_Configuration_Pragma
;
7041 --------------------------
7042 -- Is_In_Context_Clause --
7043 --------------------------
7045 function Is_In_Context_Clause
return Boolean is
7047 Parent_Node
: Node_Id
;
7050 if not Is_List_Member
(N
) then
7054 Plist
:= List_Containing
(N
);
7055 Parent_Node
:= Parent
(Plist
);
7057 if Parent_Node
= Empty
7058 or else Nkind
(Parent_Node
) /= N_Compilation_Unit
7059 or else Context_Items
(Parent_Node
) /= Plist
7066 end Is_In_Context_Clause
;
7068 ---------------------------------
7069 -- Is_Static_String_Expression --
7070 ---------------------------------
7072 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean is
7073 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
7074 Lit
: constant Boolean := Nkind
(Argx
) = N_String_Literal
;
7077 Analyze_And_Resolve
(Argx
);
7079 -- Special case Ada 83, where the expression will never be static,
7080 -- but we will return true if we had a string literal to start with.
7082 if Ada_Version
= Ada_83
then
7085 -- Normal case, true only if we end up with a string literal that
7086 -- is marked as being the result of evaluating a static expression.
7089 return Is_OK_Static_Expression
(Argx
)
7090 and then Nkind
(Argx
) = N_String_Literal
;
7093 end Is_Static_String_Expression
;
7095 ----------------------
7096 -- Pragma_Misplaced --
7097 ----------------------
7099 procedure Pragma_Misplaced
is
7101 Error_Pragma
("incorrect placement of pragma%");
7102 end Pragma_Misplaced
;
7104 ------------------------------------------------
7105 -- Process_Atomic_Independent_Shared_Volatile --
7106 ------------------------------------------------
7108 procedure Process_Atomic_Independent_Shared_Volatile
is
7109 procedure Check_VFA_Conflicts
(Ent
: Entity_Id
);
7110 -- Apply additional checks for the GNAT pragma Volatile_Full_Access
7112 procedure Mark_Component_Or_Object
(Ent
: Entity_Id
);
7113 -- Appropriately set flags on the given entity (either an array or
7114 -- record component, or an object declaration) according to the
7117 procedure Set_Atomic_VFA
(Ent
: Entity_Id
);
7118 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7119 -- no explicit alignment was given, set alignment to unknown, since
7120 -- back end knows what the alignment requirements are for atomic and
7121 -- full access arrays. Note: this is necessary for derived types.
7123 -------------------------
7124 -- Check_VFA_Conflicts --
7125 -------------------------
7127 procedure Check_VFA_Conflicts
(Ent
: Entity_Id
) is
7131 VFA_And_Atomic
: Boolean := False;
7132 -- Set True if atomic component present
7134 VFA_And_Aliased
: Boolean := False;
7135 -- Set True if aliased component present
7138 -- Fetch the type in case we are dealing with an object or
7141 if Is_Type
(Ent
) then
7144 pragma Assert
(Is_Object
(Ent
)
7146 Nkind
(Declaration_Node
(Ent
)) = N_Component_Declaration
);
7151 -- Check Atomic and VFA used together
7153 if Prag_Id
= Pragma_Volatile_Full_Access
7154 or else Is_Volatile_Full_Access
(Ent
)
7156 if Prag_Id
= Pragma_Atomic
7157 or else Prag_Id
= Pragma_Shared
7158 or else Is_Atomic
(Ent
)
7160 VFA_And_Atomic
:= True;
7162 elsif Is_Array_Type
(Typ
) then
7163 VFA_And_Atomic
:= Has_Atomic_Components
(Typ
);
7165 -- Note: Has_Atomic_Components is not used below, as this flag
7166 -- represents the pragma of the same name, Atomic_Components,
7167 -- which only applies to arrays.
7169 elsif Is_Record_Type
(Typ
) then
7170 -- Attributes cannot be applied to discriminants, only
7171 -- regular record components.
7173 Comp
:= First_Component
(Typ
);
7174 while Present
(Comp
) loop
7176 or else Is_Atomic
(Typ
)
7178 VFA_And_Atomic
:= True;
7183 Next_Component
(Comp
);
7187 if VFA_And_Atomic
then
7189 ("cannot have Volatile_Full_Access and Atomic for same "
7194 -- Check for the application of VFA to an entity that has aliased
7197 if Prag_Id
= Pragma_Volatile_Full_Access
then
7198 if Is_Array_Type
(Typ
)
7199 and then Has_Aliased_Components
(Typ
)
7201 VFA_And_Aliased
:= True;
7203 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
7204 -- and Has_Independent_Components, applies only to arrays.
7205 -- However, this flag does not have a corresponding pragma, so
7206 -- perhaps it should be possible to apply it to record types as
7207 -- well. Should this be done ???
7209 elsif Is_Record_Type
(Typ
) then
7210 -- It is possible to have an aliased discriminant, so they
7211 -- must be checked along with normal components.
7213 Comp
:= First_Component_Or_Discriminant
(Typ
);
7214 while Present
(Comp
) loop
7215 if Is_Aliased
(Comp
)
7216 or else Is_Aliased
(Etype
(Comp
))
7218 VFA_And_Aliased
:= True;
7219 Check_SPARK_05_Restriction
7220 ("aliased is not allowed", Comp
);
7225 Next_Component_Or_Discriminant
(Comp
);
7229 if VFA_And_Aliased
then
7231 ("cannot apply Volatile_Full_Access (aliased component "
7235 end Check_VFA_Conflicts
;
7237 ------------------------------
7238 -- Mark_Component_Or_Object --
7239 ------------------------------
7241 procedure Mark_Component_Or_Object
(Ent
: Entity_Id
) is
7243 if Prag_Id
= Pragma_Atomic
7244 or else Prag_Id
= Pragma_Shared
7245 or else Prag_Id
= Pragma_Volatile_Full_Access
7247 if Prag_Id
= Pragma_Volatile_Full_Access
then
7248 Set_Is_Volatile_Full_Access
(Ent
);
7250 Set_Is_Atomic
(Ent
);
7253 -- If the object declaration has an explicit initialization, a
7254 -- temporary may have to be created to hold the expression, to
7255 -- ensure that access to the object remains atomic.
7257 if Nkind
(Parent
(Ent
)) = N_Object_Declaration
7258 and then Present
(Expression
(Parent
(Ent
)))
7260 Set_Has_Delayed_Freeze
(Ent
);
7264 -- Atomic/Shared/Volatile_Full_Access imply Independent
7266 if Prag_Id
/= Pragma_Volatile
then
7267 Set_Is_Independent
(Ent
);
7269 if Prag_Id
= Pragma_Independent
then
7270 Record_Independence_Check
(N
, Ent
);
7274 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7276 if Prag_Id
/= Pragma_Independent
then
7277 Set_Is_Volatile
(Ent
);
7278 Set_Treat_As_Volatile
(Ent
);
7280 end Mark_Component_Or_Object
;
7282 --------------------
7283 -- Set_Atomic_VFA --
7284 --------------------
7286 procedure Set_Atomic_VFA
(Ent
: Entity_Id
) is
7288 if Prag_Id
= Pragma_Volatile_Full_Access
then
7289 Set_Is_Volatile_Full_Access
(Ent
);
7291 Set_Is_Atomic
(Ent
);
7294 if not Has_Alignment_Clause
(Ent
) then
7295 Set_Alignment
(Ent
, Uint_0
);
7305 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7308 Check_Ada_83_Warning
;
7309 Check_No_Identifiers
;
7310 Check_Arg_Count
(1);
7311 Check_Arg_Is_Local_Name
(Arg1
);
7312 E_Arg
:= Get_Pragma_Arg
(Arg1
);
7314 if Etype
(E_Arg
) = Any_Type
then
7318 E
:= Entity
(E_Arg
);
7320 -- A pragma that applies to a Ghost entity becomes Ghost for the
7321 -- purposes of legality checks and removal of ignored Ghost code.
7323 Mark_Ghost_Pragma
(N
, E
);
7325 -- Check duplicate before we chain ourselves
7327 Check_Duplicate_Pragma
(E
);
7329 -- Check appropriateness of the entity
7331 Decl
:= Declaration_Node
(E
);
7333 -- Deal with the case where the pragma/attribute is applied to a type
7336 if Rep_Item_Too_Early
(E
, N
)
7337 or else Rep_Item_Too_Late
(E
, N
)
7341 Check_First_Subtype
(Arg1
);
7344 -- Attribute belongs on the base type. If the view of the type is
7345 -- currently private, it also belongs on the underlying type.
7347 if Prag_Id
= Pragma_Atomic
7348 or else Prag_Id
= Pragma_Shared
7349 or else Prag_Id
= Pragma_Volatile_Full_Access
7352 Set_Atomic_VFA
(Base_Type
(E
));
7353 Set_Atomic_VFA
(Underlying_Type
(E
));
7356 -- Atomic/Shared/Volatile_Full_Access imply Independent
7358 if Prag_Id
/= Pragma_Volatile
then
7359 Set_Is_Independent
(E
);
7360 Set_Is_Independent
(Base_Type
(E
));
7361 Set_Is_Independent
(Underlying_Type
(E
));
7363 if Prag_Id
= Pragma_Independent
then
7364 Record_Independence_Check
(N
, Base_Type
(E
));
7368 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7370 if Prag_Id
/= Pragma_Independent
then
7371 Set_Is_Volatile
(E
);
7372 Set_Is_Volatile
(Base_Type
(E
));
7373 Set_Is_Volatile
(Underlying_Type
(E
));
7375 Set_Treat_As_Volatile
(E
);
7376 Set_Treat_As_Volatile
(Underlying_Type
(E
));
7379 -- Apply Volatile to the composite type's individual components,
7382 if Prag_Id
= Pragma_Volatile
7383 and then Is_Record_Type
(Etype
(E
))
7388 Comp
:= First_Component
(E
);
7389 while Present
(Comp
) loop
7390 Mark_Component_Or_Object
(Comp
);
7392 Next_Component
(Comp
);
7397 -- Deal with the case where the pragma/attribute applies to a
7398 -- component or object declaration.
7400 elsif Nkind
(Decl
) = N_Object_Declaration
7401 or else (Nkind
(Decl
) = N_Component_Declaration
7402 and then Original_Record_Component
(E
) = E
)
7404 if Rep_Item_Too_Late
(E
, N
) then
7408 Mark_Component_Or_Object
(E
);
7410 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
7413 -- Perform the checks needed to assure the proper use of the GNAT
7414 -- pragma Volatile_Full_Access.
7416 Check_VFA_Conflicts
(E
);
7418 -- The following check is only relevant when SPARK_Mode is on as
7419 -- this is not a standard Ada legality rule. Pragma Volatile can
7420 -- only apply to a full type declaration or an object declaration
7421 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7422 -- untagged derived types that are rewritten as subtypes of their
7423 -- respective root types.
7426 and then Prag_Id
= Pragma_Volatile
7427 and then not Nkind_In
(Original_Node
(Decl
),
7428 N_Full_Type_Declaration
,
7429 N_Object_Declaration
,
7430 N_Single_Protected_Declaration
,
7431 N_Single_Task_Declaration
)
7434 ("argument of pragma % must denote a full type or object "
7435 & "declaration", Arg1
);
7437 end Process_Atomic_Independent_Shared_Volatile
;
7439 -------------------------------------------
7440 -- Process_Compile_Time_Warning_Or_Error --
7441 -------------------------------------------
7443 procedure Process_Compile_Time_Warning_Or_Error
is
7444 Validation_Needed
: Boolean := False;
7446 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
7447 -- Tree visitor that checks if N is an attribute reference that can
7448 -- be statically computed by the back end. Validation_Needed is set
7449 -- to True if found.
7455 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
7457 if Nkind
(N
) = N_Attribute_Reference
7458 and then Is_Entity_Name
(Prefix
(N
))
7461 Attr_Id
: constant Attribute_Id
:=
7462 Get_Attribute_Id
(Attribute_Name
(N
));
7464 if Attr_Id
= Attribute_Alignment
7465 or else Attr_Id
= Attribute_Size
7467 Validation_Needed
:= True;
7475 procedure Check_Expression
is new Traverse_Proc
(Check_Node
);
7479 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
7481 -- Start of processing for Process_Compile_Time_Warning_Or_Error
7484 Check_Arg_Count
(2);
7485 Check_No_Identifiers
;
7486 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
7487 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
7489 if Compile_Time_Known_Value
(Arg1x
) then
7490 Process_Compile_Time_Warning_Or_Error
(N
, Sloc
(Arg1
));
7492 -- Register the expression for its validation after the back end has
7493 -- been called if it has occurrences of attributes Size or Alignment
7494 -- (because they may be statically computed by the back end and hence
7495 -- the whole expression needs to be reevaluated).
7498 Check_Expression
(Arg1x
);
7500 if Validation_Needed
then
7501 Sem_Ch13
.Validate_Compile_Time_Warning_Error
(N
);
7504 end Process_Compile_Time_Warning_Or_Error
;
7506 ------------------------
7507 -- Process_Convention --
7508 ------------------------
7510 procedure Process_Convention
7511 (C
: out Convention_Id
;
7512 Ent
: out Entity_Id
)
7516 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
);
7517 -- Called if we have more than one Export/Import/Convention pragma.
7518 -- This is generally illegal, but we have a special case of allowing
7519 -- Import and Interface to coexist if they specify the convention in
7520 -- a consistent manner. We are allowed to do this, since Interface is
7521 -- an implementation defined pragma, and we choose to do it since we
7522 -- know Rational allows this combination. S is the entity id of the
7523 -- subprogram in question. This procedure also sets the special flag
7524 -- Import_Interface_Present in both pragmas in the case where we do
7525 -- have matching Import and Interface pragmas.
7527 procedure Set_Convention_From_Pragma
(E
: Entity_Id
);
7528 -- Set convention in entity E, and also flag that the entity has a
7529 -- convention pragma. If entity is for a private or incomplete type,
7530 -- also set convention and flag on underlying type. This procedure
7531 -- also deals with the special case of C_Pass_By_Copy convention,
7532 -- and error checks for inappropriate convention specification.
7534 -------------------------------
7535 -- Diagnose_Multiple_Pragmas --
7536 -------------------------------
7538 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
) is
7539 Pdec
: constant Node_Id
:= Declaration_Node
(S
);
7543 function Same_Convention
(Decl
: Node_Id
) return Boolean;
7544 -- Decl is a pragma node. This function returns True if this
7545 -- pragma has a first argument that is an identifier with a
7546 -- Chars field corresponding to the Convention_Id C.
7548 function Same_Name
(Decl
: Node_Id
) return Boolean;
7549 -- Decl is a pragma node. This function returns True if this
7550 -- pragma has a second argument that is an identifier with a
7551 -- Chars field that matches the Chars of the current subprogram.
7553 ---------------------
7554 -- Same_Convention --
7555 ---------------------
7557 function Same_Convention
(Decl
: Node_Id
) return Boolean is
7558 Arg1
: constant Node_Id
:=
7559 First
(Pragma_Argument_Associations
(Decl
));
7562 if Present
(Arg1
) then
7564 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
7566 if Nkind
(Arg
) = N_Identifier
7567 and then Is_Convention_Name
(Chars
(Arg
))
7568 and then Get_Convention_Id
(Chars
(Arg
)) = C
7576 end Same_Convention
;
7582 function Same_Name
(Decl
: Node_Id
) return Boolean is
7583 Arg1
: constant Node_Id
:=
7584 First
(Pragma_Argument_Associations
(Decl
));
7592 Arg2
:= Next
(Arg1
);
7599 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
7601 if Nkind
(Arg
) = N_Identifier
7602 and then Chars
(Arg
) = Chars
(S
)
7611 -- Start of processing for Diagnose_Multiple_Pragmas
7616 -- Definitely give message if we have Convention/Export here
7618 if Prag_Id
= Pragma_Convention
or else Prag_Id
= Pragma_Export
then
7621 -- If we have an Import or Export, scan back from pragma to
7622 -- find any previous pragma applying to the same procedure.
7623 -- The scan will be terminated by the start of the list, or
7624 -- hitting the subprogram declaration. This won't allow one
7625 -- pragma to appear in the public part and one in the private
7626 -- part, but that seems very unlikely in practice.
7630 while Present
(Decl
) and then Decl
/= Pdec
loop
7632 -- Look for pragma with same name as us
7634 if Nkind
(Decl
) = N_Pragma
7635 and then Same_Name
(Decl
)
7637 -- Give error if same as our pragma or Export/Convention
7639 if Nam_In
(Pragma_Name_Unmapped
(Decl
),
7642 Pragma_Name_Unmapped
(N
))
7646 -- Case of Import/Interface or the other way round
7648 elsif Nam_In
(Pragma_Name_Unmapped
(Decl
),
7649 Name_Interface
, Name_Import
)
7651 -- Here we know that we have Import and Interface. It
7652 -- doesn't matter which way round they are. See if
7653 -- they specify the same convention. If so, all OK,
7654 -- and set special flags to stop other messages
7656 if Same_Convention
(Decl
) then
7657 Set_Import_Interface_Present
(N
);
7658 Set_Import_Interface_Present
(Decl
);
7661 -- If different conventions, special message
7664 Error_Msg_Sloc
:= Sloc
(Decl
);
7666 ("convention differs from that given#", Arg1
);
7676 -- Give message if needed if we fall through those tests
7677 -- except on Relaxed_RM_Semantics where we let go: either this
7678 -- is a case accepted/ignored by other Ada compilers (e.g.
7679 -- a mix of Convention and Import), or another error will be
7680 -- generated later (e.g. using both Import and Export).
7682 if Err
and not Relaxed_RM_Semantics
then
7684 ("at most one Convention/Export/Import pragma is allowed",
7687 end Diagnose_Multiple_Pragmas
;
7689 --------------------------------
7690 -- Set_Convention_From_Pragma --
7691 --------------------------------
7693 procedure Set_Convention_From_Pragma
(E
: Entity_Id
) is
7695 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7696 -- for an overridden dispatching operation. Technically this is
7697 -- an amendment and should only be done in Ada 2005 mode. However,
7698 -- this is clearly a mistake, since the problem that is addressed
7699 -- by this AI is that there is a clear gap in the RM.
7701 if Is_Dispatching_Operation
(E
)
7702 and then Present
(Overridden_Operation
(E
))
7703 and then C
/= Convention
(Overridden_Operation
(E
))
7706 ("cannot change convention for overridden dispatching "
7707 & "operation", Arg1
);
7710 -- Special checks for Convention_Stdcall
7712 if C
= Convention_Stdcall
then
7714 -- A dispatching call is not allowed. A dispatching subprogram
7715 -- cannot be used to interface to the Win32 API, so in fact
7716 -- this check does not impose any effective restriction.
7718 if Is_Dispatching_Operation
(E
) then
7719 Error_Msg_Sloc
:= Sloc
(E
);
7721 -- Note: make this unconditional so that if there is more
7722 -- than one call to which the pragma applies, we get a
7723 -- message for each call. Also don't use Error_Pragma,
7724 -- so that we get multiple messages.
7727 ("dispatching subprogram# cannot use Stdcall convention!",
7730 -- Several allowed cases
7732 elsif Is_Subprogram_Or_Generic_Subprogram
(E
)
7736 or else Ekind
(E
) = E_Variable
7738 -- A component as well. The entity does not have its Ekind
7739 -- set until the enclosing record declaration is fully
7742 or else Nkind
(Parent
(E
)) = N_Component_Declaration
7744 -- An access to subprogram is also allowed
7748 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
)
7750 -- Allow internal call to set convention of subprogram type
7752 or else Ekind
(E
) = E_Subprogram_Type
7758 ("second argument of pragma% must be subprogram (type)",
7763 -- Set the convention
7765 Set_Convention
(E
, C
);
7766 Set_Has_Convention_Pragma
(E
);
7768 -- For the case of a record base type, also set the convention of
7769 -- any anonymous access types declared in the record which do not
7770 -- currently have a specified convention.
7772 if Is_Record_Type
(E
) and then Is_Base_Type
(E
) then
7777 Comp
:= First_Component
(E
);
7778 while Present
(Comp
) loop
7779 if Present
(Etype
(Comp
))
7780 and then Ekind_In
(Etype
(Comp
),
7781 E_Anonymous_Access_Type
,
7782 E_Anonymous_Access_Subprogram_Type
)
7783 and then not Has_Convention_Pragma
(Comp
)
7785 Set_Convention
(Comp
, C
);
7788 Next_Component
(Comp
);
7793 -- Deal with incomplete/private type case, where underlying type
7794 -- is available, so set convention of that underlying type.
7796 if Is_Incomplete_Or_Private_Type
(E
)
7797 and then Present
(Underlying_Type
(E
))
7799 Set_Convention
(Underlying_Type
(E
), C
);
7800 Set_Has_Convention_Pragma
(Underlying_Type
(E
), True);
7803 -- A class-wide type should inherit the convention of the specific
7804 -- root type (although this isn't specified clearly by the RM).
7806 if Is_Type
(E
) and then Present
(Class_Wide_Type
(E
)) then
7807 Set_Convention
(Class_Wide_Type
(E
), C
);
7810 -- If the entity is a record type, then check for special case of
7811 -- C_Pass_By_Copy, which is treated the same as C except that the
7812 -- special record flag is set. This convention is only permitted
7813 -- on record types (see AI95-00131).
7815 if Cname
= Name_C_Pass_By_Copy
then
7816 if Is_Record_Type
(E
) then
7817 Set_C_Pass_By_Copy
(Base_Type
(E
));
7818 elsif Is_Incomplete_Or_Private_Type
(E
)
7819 and then Is_Record_Type
(Underlying_Type
(E
))
7821 Set_C_Pass_By_Copy
(Base_Type
(Underlying_Type
(E
)));
7824 ("C_Pass_By_Copy convention allowed only for record type",
7829 -- If the entity is a derived boolean type, check for the special
7830 -- case of convention C, C++, or Fortran, where we consider any
7831 -- nonzero value to represent true.
7833 if Is_Discrete_Type
(E
)
7834 and then Root_Type
(Etype
(E
)) = Standard_Boolean
7840 C
= Convention_Fortran
)
7842 Set_Nonzero_Is_True
(Base_Type
(E
));
7844 end Set_Convention_From_Pragma
;
7848 Comp_Unit
: Unit_Number_Type
;
7853 -- Start of processing for Process_Convention
7856 Check_At_Least_N_Arguments
(2);
7857 Check_Optional_Identifier
(Arg1
, Name_Convention
);
7858 Check_Arg_Is_Identifier
(Arg1
);
7859 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
7861 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7862 -- tested again below to set the critical flag).
7864 if Cname
= Name_C_Pass_By_Copy
then
7867 -- Otherwise we must have something in the standard convention list
7869 elsif Is_Convention_Name
(Cname
) then
7870 C
:= Get_Convention_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
7872 -- Otherwise warn on unrecognized convention
7875 if Warn_On_Export_Import
then
7877 ("??unrecognized convention name, C assumed",
7878 Get_Pragma_Arg
(Arg1
));
7884 Check_Optional_Identifier
(Arg2
, Name_Entity
);
7885 Check_Arg_Is_Local_Name
(Arg2
);
7887 Id
:= Get_Pragma_Arg
(Arg2
);
7890 if not Is_Entity_Name
(Id
) then
7891 Error_Pragma_Arg
("entity name required", Arg2
);
7896 -- Set entity to return
7900 -- Ada_Pass_By_Copy special checking
7902 if C
= Convention_Ada_Pass_By_Copy
then
7903 if not Is_First_Subtype
(E
) then
7905 ("convention `Ada_Pass_By_Copy` only allowed for types",
7909 if Is_By_Reference_Type
(E
) then
7911 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7915 -- Ada_Pass_By_Reference special checking
7917 elsif C
= Convention_Ada_Pass_By_Reference
then
7918 if not Is_First_Subtype
(E
) then
7920 ("convention `Ada_Pass_By_Reference` only allowed for types",
7924 if Is_By_Copy_Type
(E
) then
7926 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7931 -- Go to renamed subprogram if present, since convention applies to
7932 -- the actual renamed entity, not to the renaming entity. If the
7933 -- subprogram is inherited, go to parent subprogram.
7935 if Is_Subprogram
(E
)
7936 and then Present
(Alias
(E
))
7938 if Nkind
(Parent
(Declaration_Node
(E
))) =
7939 N_Subprogram_Renaming_Declaration
7941 if Scope
(E
) /= Scope
(Alias
(E
)) then
7943 ("cannot apply pragma% to non-local entity&#", E
);
7948 elsif Nkind_In
(Parent
(E
), N_Full_Type_Declaration
,
7949 N_Private_Extension_Declaration
)
7950 and then Scope
(E
) = Scope
(Alias
(E
))
7954 -- Return the parent subprogram the entity was inherited from
7960 -- Check that we are not applying this to a specless body. Relax this
7961 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
7963 if Is_Subprogram
(E
)
7964 and then Nkind
(Parent
(Declaration_Node
(E
))) = N_Subprogram_Body
7965 and then not Relaxed_RM_Semantics
7968 ("pragma% requires separate spec and must come before body");
7971 -- Check that we are not applying this to a named constant
7973 if Ekind_In
(E
, E_Named_Integer
, E_Named_Real
) then
7974 Error_Msg_Name_1
:= Pname
;
7976 ("cannot apply pragma% to named constant!",
7977 Get_Pragma_Arg
(Arg2
));
7979 ("\supply appropriate type for&!", Arg2
);
7982 if Ekind
(E
) = E_Enumeration_Literal
then
7983 Error_Pragma
("enumeration literal not allowed for pragma%");
7986 -- Check for rep item appearing too early or too late
7988 if Etype
(E
) = Any_Type
7989 or else Rep_Item_Too_Early
(E
, N
)
7993 elsif Present
(Underlying_Type
(E
)) then
7994 E
:= Underlying_Type
(E
);
7997 if Rep_Item_Too_Late
(E
, N
) then
8001 if Has_Convention_Pragma
(E
) then
8002 Diagnose_Multiple_Pragmas
(E
);
8004 elsif Convention
(E
) = Convention_Protected
8005 or else Ekind
(Scope
(E
)) = E_Protected_Type
8008 ("a protected operation cannot be given a different convention",
8012 -- For Intrinsic, a subprogram is required
8014 if C
= Convention_Intrinsic
8015 and then not Is_Subprogram_Or_Generic_Subprogram
(E
)
8017 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
8019 if not (Is_Type
(E
) and then Relaxed_RM_Semantics
) then
8021 ("second argument of pragma% must be a subprogram", Arg2
);
8025 -- Deal with non-subprogram cases
8027 if not Is_Subprogram_Or_Generic_Subprogram
(E
) then
8028 Set_Convention_From_Pragma
(E
);
8032 -- The pragma must apply to a first subtype, but it can also
8033 -- apply to a generic type in a generic formal part, in which
8034 -- case it will also appear in the corresponding instance.
8036 if Is_Generic_Type
(E
) or else In_Instance
then
8039 Check_First_Subtype
(Arg2
);
8042 Set_Convention_From_Pragma
(Base_Type
(E
));
8044 -- For access subprograms, we must set the convention on the
8045 -- internally generated directly designated type as well.
8047 if Ekind
(E
) = E_Access_Subprogram_Type
then
8048 Set_Convention_From_Pragma
(Directly_Designated_Type
(E
));
8052 -- For the subprogram case, set proper convention for all homonyms
8053 -- in same scope and the same declarative part, i.e. the same
8054 -- compilation unit.
8057 Comp_Unit
:= Get_Source_Unit
(E
);
8058 Set_Convention_From_Pragma
(E
);
8060 -- Treat a pragma Import as an implicit body, and pragma import
8061 -- as implicit reference (for navigation in GPS).
8063 if Prag_Id
= Pragma_Import
then
8064 Generate_Reference
(E
, Id
, 'b');
8066 -- For exported entities we restrict the generation of references
8067 -- to entities exported to foreign languages since entities
8068 -- exported to Ada do not provide further information to GPS and
8069 -- add undesired references to the output of the gnatxref tool.
8071 elsif Prag_Id
= Pragma_Export
8072 and then Convention
(E
) /= Convention_Ada
8074 Generate_Reference
(E
, Id
, 'i');
8077 -- If the pragma comes from an aspect, it only applies to the
8078 -- given entity, not its homonyms.
8080 if From_Aspect_Specification
(N
) then
8081 if C
= Convention_Intrinsic
8082 and then Nkind
(Ent
) = N_Defining_Operator_Symbol
8084 if Is_Fixed_Point_Type
(Etype
(Ent
))
8085 or else Is_Fixed_Point_Type
(Etype
(First_Entity
(Ent
)))
8086 or else Is_Fixed_Point_Type
(Etype
(Last_Entity
(Ent
)))
8089 ("no intrinsic operator available for this fixed-point "
8092 ("\use expression functions with the desired "
8093 & "conversions made explicit", N
);
8100 -- Otherwise Loop through the homonyms of the pragma argument's
8101 -- entity, an apply convention to those in the current scope.
8107 exit when No
(E1
) or else Scope
(E1
) /= Current_Scope
;
8109 -- Ignore entry for which convention is already set
8111 if Has_Convention_Pragma
(E1
) then
8115 if Is_Subprogram
(E1
)
8116 and then Nkind
(Parent
(Declaration_Node
(E1
))) =
8118 and then not Relaxed_RM_Semantics
8120 Set_Has_Completion
(E
); -- to prevent cascaded error
8122 ("pragma% requires separate spec and must come before "
8126 -- Do not set the pragma on inherited operations or on formal
8129 if Comes_From_Source
(E1
)
8130 and then Comp_Unit
= Get_Source_Unit
(E1
)
8131 and then not Is_Formal_Subprogram
(E1
)
8132 and then Nkind
(Original_Node
(Parent
(E1
))) /=
8133 N_Full_Type_Declaration
8135 if Present
(Alias
(E1
))
8136 and then Scope
(E1
) /= Scope
(Alias
(E1
))
8139 ("cannot apply pragma% to non-local entity& declared#",
8143 Set_Convention_From_Pragma
(E1
);
8145 if Prag_Id
= Pragma_Import
then
8146 Generate_Reference
(E1
, Id
, 'b');
8154 end Process_Convention
;
8156 ----------------------------------------
8157 -- Process_Disable_Enable_Atomic_Sync --
8158 ----------------------------------------
8160 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
) is
8162 Check_No_Identifiers
;
8163 Check_At_Most_N_Arguments
(1);
8165 -- Modeled internally as
8166 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8171 Pragma_Argument_Associations
=> New_List
(
8172 Make_Pragma_Argument_Association
(Loc
,
8174 Make_Identifier
(Loc
, Name_Atomic_Synchronization
)))));
8176 if Present
(Arg1
) then
8177 Append_To
(Pragma_Argument_Associations
(N
), New_Copy
(Arg1
));
8181 end Process_Disable_Enable_Atomic_Sync
;
8183 -------------------------------------------------
8184 -- Process_Extended_Import_Export_Internal_Arg --
8185 -------------------------------------------------
8187 procedure Process_Extended_Import_Export_Internal_Arg
8188 (Arg_Internal
: Node_Id
:= Empty
)
8191 if No
(Arg_Internal
) then
8192 Error_Pragma
("Internal parameter required for pragma%");
8195 if Nkind
(Arg_Internal
) = N_Identifier
then
8198 elsif Nkind
(Arg_Internal
) = N_Operator_Symbol
8199 and then (Prag_Id
= Pragma_Import_Function
8201 Prag_Id
= Pragma_Export_Function
)
8207 ("wrong form for Internal parameter for pragma%", Arg_Internal
);
8210 Check_Arg_Is_Local_Name
(Arg_Internal
);
8211 end Process_Extended_Import_Export_Internal_Arg
;
8213 --------------------------------------------------
8214 -- Process_Extended_Import_Export_Object_Pragma --
8215 --------------------------------------------------
8217 procedure Process_Extended_Import_Export_Object_Pragma
8218 (Arg_Internal
: Node_Id
;
8219 Arg_External
: Node_Id
;
8225 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
8226 Def_Id
:= Entity
(Arg_Internal
);
8228 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
8230 ("pragma% must designate an object", Arg_Internal
);
8233 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
8235 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
8238 ("previous Common/Psect_Object applies, pragma % not permitted",
8242 if Rep_Item_Too_Late
(Def_Id
, N
) then
8246 Set_Extended_Import_Export_External_Name
(Def_Id
, Arg_External
);
8248 if Present
(Arg_Size
) then
8249 Check_Arg_Is_External_Name
(Arg_Size
);
8252 -- Export_Object case
8254 if Prag_Id
= Pragma_Export_Object
then
8255 if not Is_Library_Level_Entity
(Def_Id
) then
8257 ("argument for pragma% must be library level entity",
8261 if Ekind
(Current_Scope
) = E_Generic_Package
then
8262 Error_Pragma
("pragma& cannot appear in a generic unit");
8265 if not Size_Known_At_Compile_Time
(Etype
(Def_Id
)) then
8267 ("exported object must have compile time known size",
8271 if Warn_On_Export_Import
and then Is_Exported
(Def_Id
) then
8272 Error_Msg_N
("??duplicate Export_Object pragma", N
);
8274 Set_Exported
(Def_Id
, Arg_Internal
);
8277 -- Import_Object case
8280 if Is_Concurrent_Type
(Etype
(Def_Id
)) then
8282 ("cannot use pragma% for task/protected object",
8286 if Ekind
(Def_Id
) = E_Constant
then
8288 ("cannot import a constant", Arg_Internal
);
8291 if Warn_On_Export_Import
8292 and then Has_Discriminants
(Etype
(Def_Id
))
8295 ("imported value must be initialized??", Arg_Internal
);
8298 if Warn_On_Export_Import
8299 and then Is_Access_Type
(Etype
(Def_Id
))
8302 ("cannot import object of an access type??", Arg_Internal
);
8305 if Warn_On_Export_Import
8306 and then Is_Imported
(Def_Id
)
8308 Error_Msg_N
("??duplicate Import_Object pragma", N
);
8310 -- Check for explicit initialization present. Note that an
8311 -- initialization generated by the code generator, e.g. for an
8312 -- access type, does not count here.
8314 elsif Present
(Expression
(Parent
(Def_Id
)))
8317 (Original_Node
(Expression
(Parent
(Def_Id
))))
8319 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8321 ("imported entities cannot be initialized (RM B.1(24))",
8322 "\no initialization allowed for & declared#", Arg1
);
8324 Set_Imported
(Def_Id
);
8325 Note_Possible_Modification
(Arg_Internal
, Sure
=> False);
8328 end Process_Extended_Import_Export_Object_Pragma
;
8330 ------------------------------------------------------
8331 -- Process_Extended_Import_Export_Subprogram_Pragma --
8332 ------------------------------------------------------
8334 procedure Process_Extended_Import_Export_Subprogram_Pragma
8335 (Arg_Internal
: Node_Id
;
8336 Arg_External
: Node_Id
;
8337 Arg_Parameter_Types
: Node_Id
;
8338 Arg_Result_Type
: Node_Id
:= Empty
;
8339 Arg_Mechanism
: Node_Id
;
8340 Arg_Result_Mechanism
: Node_Id
:= Empty
)
8346 Ambiguous
: Boolean;
8349 function Same_Base_Type
8351 Formal
: Entity_Id
) return Boolean;
8352 -- Determines if Ptype references the type of Formal. Note that only
8353 -- the base types need to match according to the spec. Ptype here is
8354 -- the argument from the pragma, which is either a type name, or an
8355 -- access attribute.
8357 --------------------
8358 -- Same_Base_Type --
8359 --------------------
8361 function Same_Base_Type
8363 Formal
: Entity_Id
) return Boolean
8365 Ftyp
: constant Entity_Id
:= Base_Type
(Etype
(Formal
));
8369 -- Case where pragma argument is typ'Access
8371 if Nkind
(Ptype
) = N_Attribute_Reference
8372 and then Attribute_Name
(Ptype
) = Name_Access
8374 Pref
:= Prefix
(Ptype
);
8377 if not Is_Entity_Name
(Pref
)
8378 or else Entity
(Pref
) = Any_Type
8383 -- We have a match if the corresponding argument is of an
8384 -- anonymous access type, and its designated type matches the
8385 -- type of the prefix of the access attribute
8387 return Ekind
(Ftyp
) = E_Anonymous_Access_Type
8388 and then Base_Type
(Entity
(Pref
)) =
8389 Base_Type
(Etype
(Designated_Type
(Ftyp
)));
8391 -- Case where pragma argument is a type name
8396 if not Is_Entity_Name
(Ptype
)
8397 or else Entity
(Ptype
) = Any_Type
8402 -- We have a match if the corresponding argument is of the type
8403 -- given in the pragma (comparing base types)
8405 return Base_Type
(Entity
(Ptype
)) = Ftyp
;
8409 -- Start of processing for
8410 -- Process_Extended_Import_Export_Subprogram_Pragma
8413 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
8417 -- Loop through homonyms (overloadings) of the entity
8419 Hom_Id
:= Entity
(Arg_Internal
);
8420 while Present
(Hom_Id
) loop
8421 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8423 -- We need a subprogram in the current scope
8425 if not Is_Subprogram
(Def_Id
)
8426 or else Scope
(Def_Id
) /= Current_Scope
8433 -- Pragma cannot apply to subprogram body
8435 if Is_Subprogram
(Def_Id
)
8436 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
8440 ("pragma% requires separate spec and must come before "
8444 -- Test result type if given, note that the result type
8445 -- parameter can only be present for the function cases.
8447 if Present
(Arg_Result_Type
)
8448 and then not Same_Base_Type
(Arg_Result_Type
, Def_Id
)
8452 elsif Etype
(Def_Id
) /= Standard_Void_Type
8453 and then Nam_In
(Pname
, Name_Export_Procedure
,
8454 Name_Import_Procedure
)
8458 -- Test parameter types if given. Note that this parameter has
8459 -- not been analyzed (and must not be, since it is semantic
8460 -- nonsense), so we get it as the parser left it.
8462 elsif Present
(Arg_Parameter_Types
) then
8463 Check_Matching_Types
: declare
8468 Formal
:= First_Formal
(Def_Id
);
8470 if Nkind
(Arg_Parameter_Types
) = N_Null
then
8471 if Present
(Formal
) then
8475 -- A list of one type, e.g. (List) is parsed as a
8476 -- parenthesized expression.
8478 elsif Nkind
(Arg_Parameter_Types
) /= N_Aggregate
8479 and then Paren_Count
(Arg_Parameter_Types
) = 1
8482 or else Present
(Next_Formal
(Formal
))
8487 Same_Base_Type
(Arg_Parameter_Types
, Formal
);
8490 -- A list of more than one type is parsed as a aggregate
8492 elsif Nkind
(Arg_Parameter_Types
) = N_Aggregate
8493 and then Paren_Count
(Arg_Parameter_Types
) = 0
8495 Ptype
:= First
(Expressions
(Arg_Parameter_Types
));
8496 while Present
(Ptype
) or else Present
(Formal
) loop
8499 or else not Same_Base_Type
(Ptype
, Formal
)
8504 Next_Formal
(Formal
);
8509 -- Anything else is of the wrong form
8513 ("wrong form for Parameter_Types parameter",
8514 Arg_Parameter_Types
);
8516 end Check_Matching_Types
;
8519 -- Match is now False if the entry we found did not match
8520 -- either a supplied Parameter_Types or Result_Types argument
8526 -- Ambiguous case, the flag Ambiguous shows if we already
8527 -- detected this and output the initial messages.
8530 if not Ambiguous
then
8532 Error_Msg_Name_1
:= Pname
;
8534 ("pragma% does not uniquely identify subprogram!",
8536 Error_Msg_Sloc
:= Sloc
(Ent
);
8537 Error_Msg_N
("matching subprogram #!", N
);
8541 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8542 Error_Msg_N
("matching subprogram #!", N
);
8547 Hom_Id
:= Homonym
(Hom_Id
);
8550 -- See if we found an entry
8553 if not Ambiguous
then
8554 if Is_Generic_Subprogram
(Entity
(Arg_Internal
)) then
8556 ("pragma% cannot be given for generic subprogram");
8559 ("pragma% does not identify local subprogram");
8566 -- Import pragmas must be for imported entities
8568 if Prag_Id
= Pragma_Import_Function
8570 Prag_Id
= Pragma_Import_Procedure
8572 Prag_Id
= Pragma_Import_Valued_Procedure
8574 if not Is_Imported
(Ent
) then
8576 ("pragma Import or Interface must precede pragma%");
8579 -- Here we have the Export case which can set the entity as exported
8581 -- But does not do so if the specified external name is null, since
8582 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8583 -- compatible) to request no external name.
8585 elsif Nkind
(Arg_External
) = N_String_Literal
8586 and then String_Length
(Strval
(Arg_External
)) = 0
8590 -- In all other cases, set entity as exported
8593 Set_Exported
(Ent
, Arg_Internal
);
8596 -- Special processing for Valued_Procedure cases
8598 if Prag_Id
= Pragma_Import_Valued_Procedure
8600 Prag_Id
= Pragma_Export_Valued_Procedure
8602 Formal
:= First_Formal
(Ent
);
8605 Error_Pragma
("at least one parameter required for pragma%");
8607 elsif Ekind
(Formal
) /= E_Out_Parameter
then
8608 Error_Pragma
("first parameter must have mode out for pragma%");
8611 Set_Is_Valued_Procedure
(Ent
);
8615 Set_Extended_Import_Export_External_Name
(Ent
, Arg_External
);
8617 -- Process Result_Mechanism argument if present. We have already
8618 -- checked that this is only allowed for the function case.
8620 if Present
(Arg_Result_Mechanism
) then
8621 Set_Mechanism_Value
(Ent
, Arg_Result_Mechanism
);
8624 -- Process Mechanism parameter if present. Note that this parameter
8625 -- is not analyzed, and must not be analyzed since it is semantic
8626 -- nonsense, so we get it in exactly as the parser left it.
8628 if Present
(Arg_Mechanism
) then
8636 -- A single mechanism association without a formal parameter
8637 -- name is parsed as a parenthesized expression. All other
8638 -- cases are parsed as aggregates, so we rewrite the single
8639 -- parameter case as an aggregate for consistency.
8641 if Nkind
(Arg_Mechanism
) /= N_Aggregate
8642 and then Paren_Count
(Arg_Mechanism
) = 1
8644 Rewrite
(Arg_Mechanism
,
8645 Make_Aggregate
(Sloc
(Arg_Mechanism
),
8646 Expressions
=> New_List
(
8647 Relocate_Node
(Arg_Mechanism
))));
8650 -- Case of only mechanism name given, applies to all formals
8652 if Nkind
(Arg_Mechanism
) /= N_Aggregate
then
8653 Formal
:= First_Formal
(Ent
);
8654 while Present
(Formal
) loop
8655 Set_Mechanism_Value
(Formal
, Arg_Mechanism
);
8656 Next_Formal
(Formal
);
8659 -- Case of list of mechanism associations given
8662 if Null_Record_Present
(Arg_Mechanism
) then
8664 ("inappropriate form for Mechanism parameter",
8668 -- Deal with positional ones first
8670 Formal
:= First_Formal
(Ent
);
8672 if Present
(Expressions
(Arg_Mechanism
)) then
8673 Mname
:= First
(Expressions
(Arg_Mechanism
));
8674 while Present
(Mname
) loop
8677 ("too many mechanism associations", Mname
);
8680 Set_Mechanism_Value
(Formal
, Mname
);
8681 Next_Formal
(Formal
);
8686 -- Deal with named entries
8688 if Present
(Component_Associations
(Arg_Mechanism
)) then
8689 Massoc
:= First
(Component_Associations
(Arg_Mechanism
));
8690 while Present
(Massoc
) loop
8691 Choice
:= First
(Choices
(Massoc
));
8693 if Nkind
(Choice
) /= N_Identifier
8694 or else Present
(Next
(Choice
))
8697 ("incorrect form for mechanism association",
8701 Formal
:= First_Formal
(Ent
);
8705 ("parameter name & not present", Choice
);
8708 if Chars
(Choice
) = Chars
(Formal
) then
8710 (Formal
, Expression
(Massoc
));
8712 -- Set entity on identifier (needed by ASIS)
8714 Set_Entity
(Choice
, Formal
);
8719 Next_Formal
(Formal
);
8728 end Process_Extended_Import_Export_Subprogram_Pragma
;
8730 --------------------------
8731 -- Process_Generic_List --
8732 --------------------------
8734 procedure Process_Generic_List
is
8739 Check_No_Identifiers
;
8740 Check_At_Least_N_Arguments
(1);
8742 -- Check all arguments are names of generic units or instances
8745 while Present
(Arg
) loop
8746 Exp
:= Get_Pragma_Arg
(Arg
);
8749 if not Is_Entity_Name
(Exp
)
8751 (not Is_Generic_Instance
(Entity
(Exp
))
8753 not Is_Generic_Unit
(Entity
(Exp
)))
8756 ("pragma% argument must be name of generic unit/instance",
8762 end Process_Generic_List
;
8764 ------------------------------------
8765 -- Process_Import_Predefined_Type --
8766 ------------------------------------
8768 procedure Process_Import_Predefined_Type
is
8769 Loc
: constant Source_Ptr
:= Sloc
(N
);
8771 Ftyp
: Node_Id
:= Empty
;
8777 Nam
:= String_To_Name
(Strval
(Expression
(Arg3
)));
8779 Elmt
:= First_Elmt
(Predefined_Float_Types
);
8780 while Present
(Elmt
) and then Chars
(Node
(Elmt
)) /= Nam
loop
8784 Ftyp
:= Node
(Elmt
);
8786 if Present
(Ftyp
) then
8788 -- Don't build a derived type declaration, because predefined C
8789 -- types have no declaration anywhere, so cannot really be named.
8790 -- Instead build a full type declaration, starting with an
8791 -- appropriate type definition is built
8793 if Is_Floating_Point_Type
(Ftyp
) then
8794 Def
:= Make_Floating_Point_Definition
(Loc
,
8795 Make_Integer_Literal
(Loc
, Digits_Value
(Ftyp
)),
8796 Make_Real_Range_Specification
(Loc
,
8797 Make_Real_Literal
(Loc
, Realval
(Type_Low_Bound
(Ftyp
))),
8798 Make_Real_Literal
(Loc
, Realval
(Type_High_Bound
(Ftyp
)))));
8800 -- Should never have a predefined type we cannot handle
8803 raise Program_Error
;
8806 -- Build and insert a Full_Type_Declaration, which will be
8807 -- analyzed as soon as this list entry has been analyzed.
8809 Decl
:= Make_Full_Type_Declaration
(Loc
,
8810 Make_Defining_Identifier
(Loc
, Chars
(Expression
(Arg2
))),
8811 Type_Definition
=> Def
);
8813 Insert_After
(N
, Decl
);
8814 Mark_Rewrite_Insertion
(Decl
);
8817 Error_Pragma_Arg
("no matching type found for pragma%",
8820 end Process_Import_Predefined_Type
;
8822 ---------------------------------
8823 -- Process_Import_Or_Interface --
8824 ---------------------------------
8826 procedure Process_Import_Or_Interface
is
8832 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8833 -- pragma Import (Entity, "external name");
8835 if Relaxed_RM_Semantics
8836 and then Arg_Count
= 2
8837 and then Prag_Id
= Pragma_Import
8838 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
8841 Def_Id
:= Get_Pragma_Arg
(Arg1
);
8844 if not Is_Entity_Name
(Def_Id
) then
8845 Error_Pragma_Arg
("entity name required", Arg1
);
8848 Def_Id
:= Entity
(Def_Id
);
8849 Kill_Size_Check_Code
(Def_Id
);
8850 Note_Possible_Modification
(Get_Pragma_Arg
(Arg1
), Sure
=> False);
8853 Process_Convention
(C
, Def_Id
);
8855 -- A pragma that applies to a Ghost entity becomes Ghost for the
8856 -- purposes of legality checks and removal of ignored Ghost code.
8858 Mark_Ghost_Pragma
(N
, Def_Id
);
8859 Kill_Size_Check_Code
(Def_Id
);
8860 Note_Possible_Modification
(Get_Pragma_Arg
(Arg2
), Sure
=> False);
8863 -- Various error checks
8865 if Ekind_In
(Def_Id
, E_Variable
, E_Constant
) then
8867 -- We do not permit Import to apply to a renaming declaration
8869 if Present
(Renamed_Object
(Def_Id
)) then
8871 ("pragma% not allowed for object renaming", Arg2
);
8873 -- User initialization is not allowed for imported object, but
8874 -- the object declaration may contain a default initialization,
8875 -- that will be discarded. Note that an explicit initialization
8876 -- only counts if it comes from source, otherwise it is simply
8877 -- the code generator making an implicit initialization explicit.
8879 elsif Present
(Expression
(Parent
(Def_Id
)))
8880 and then Comes_From_Source
8881 (Original_Node
(Expression
(Parent
(Def_Id
))))
8883 -- Set imported flag to prevent cascaded errors
8885 Set_Is_Imported
(Def_Id
);
8887 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8889 ("no initialization allowed for declaration of& #",
8890 "\imported entities cannot be initialized (RM B.1(24))",
8894 -- If the pragma comes from an aspect specification the
8895 -- Is_Imported flag has already been set.
8897 if not From_Aspect_Specification
(N
) then
8898 Set_Imported
(Def_Id
);
8901 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
8903 -- Note that we do not set Is_Public here. That's because we
8904 -- only want to set it if there is no address clause, and we
8905 -- don't know that yet, so we delay that processing till
8908 -- pragma Import completes deferred constants
8910 if Ekind
(Def_Id
) = E_Constant
then
8911 Set_Has_Completion
(Def_Id
);
8914 -- It is not possible to import a constant of an unconstrained
8915 -- array type (e.g. string) because there is no simple way to
8916 -- write a meaningful subtype for it.
8918 if Is_Array_Type
(Etype
(Def_Id
))
8919 and then not Is_Constrained
(Etype
(Def_Id
))
8922 ("imported constant& must have a constrained subtype",
8927 elsif Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8929 -- If the name is overloaded, pragma applies to all of the denoted
8930 -- entities in the same declarative part, unless the pragma comes
8931 -- from an aspect specification or was generated by the compiler
8932 -- (such as for pragma Provide_Shift_Operators).
8935 while Present
(Hom_Id
) loop
8937 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8939 -- Ignore inherited subprograms because the pragma will apply
8940 -- to the parent operation, which is the one called.
8942 if Is_Overloadable
(Def_Id
)
8943 and then Present
(Alias
(Def_Id
))
8947 -- If it is not a subprogram, it must be in an outer scope and
8948 -- pragma does not apply.
8950 elsif not Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8953 -- The pragma does not apply to primitives of interfaces
8955 elsif Is_Dispatching_Operation
(Def_Id
)
8956 and then Present
(Find_Dispatching_Type
(Def_Id
))
8957 and then Is_Interface
(Find_Dispatching_Type
(Def_Id
))
8961 -- Verify that the homonym is in the same declarative part (not
8962 -- just the same scope). If the pragma comes from an aspect
8963 -- specification we know that it is part of the declaration.
8965 elsif Parent
(Unit_Declaration_Node
(Def_Id
)) /= Parent
(N
)
8966 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit_Aux
8967 and then not From_Aspect_Specification
(N
)
8972 -- If the pragma comes from an aspect specification the
8973 -- Is_Imported flag has already been set.
8975 if not From_Aspect_Specification
(N
) then
8976 Set_Imported
(Def_Id
);
8979 -- Reject an Import applied to an abstract subprogram
8981 if Is_Subprogram
(Def_Id
)
8982 and then Is_Abstract_Subprogram
(Def_Id
)
8984 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8986 ("cannot import abstract subprogram& declared#",
8990 -- Special processing for Convention_Intrinsic
8992 if C
= Convention_Intrinsic
then
8994 -- Link_Name argument not allowed for intrinsic
8998 Set_Is_Intrinsic_Subprogram
(Def_Id
);
9000 -- If no external name is present, then check that this
9001 -- is a valid intrinsic subprogram. If an external name
9002 -- is present, then this is handled by the back end.
9005 Check_Intrinsic_Subprogram
9006 (Def_Id
, Get_Pragma_Arg
(Arg2
));
9010 -- Verify that the subprogram does not have a completion
9011 -- through a renaming declaration. For other completions the
9012 -- pragma appears as a too late representation.
9015 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Def_Id
);
9019 and then Nkind
(Decl
) = N_Subprogram_Declaration
9020 and then Present
(Corresponding_Body
(Decl
))
9021 and then Nkind
(Unit_Declaration_Node
9022 (Corresponding_Body
(Decl
))) =
9023 N_Subprogram_Renaming_Declaration
9025 Error_Msg_Sloc
:= Sloc
(Def_Id
);
9027 ("cannot import&, renaming already provided for "
9028 & "declaration #", N
, Def_Id
);
9032 -- If the pragma comes from an aspect specification, there
9033 -- must be an Import aspect specified as well. In the rare
9034 -- case where Import is set to False, the suprogram needs to
9035 -- have a local completion.
9038 Imp_Aspect
: constant Node_Id
:=
9039 Find_Aspect
(Def_Id
, Aspect_Import
);
9043 if Present
(Imp_Aspect
)
9044 and then Present
(Expression
(Imp_Aspect
))
9046 Expr
:= Expression
(Imp_Aspect
);
9047 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
9049 if Is_Entity_Name
(Expr
)
9050 and then Entity
(Expr
) = Standard_True
9052 Set_Has_Completion
(Def_Id
);
9055 -- If there is no expression, the default is True, as for
9056 -- all boolean aspects. Same for the older pragma.
9059 Set_Has_Completion
(Def_Id
);
9063 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
9066 if Is_Compilation_Unit
(Hom_Id
) then
9068 -- Its possible homonyms are not affected by the pragma.
9069 -- Such homonyms might be present in the context of other
9070 -- units being compiled.
9074 elsif From_Aspect_Specification
(N
) then
9077 -- If the pragma was created by the compiler, then we don't
9078 -- want it to apply to other homonyms. This kind of case can
9079 -- occur when using pragma Provide_Shift_Operators, which
9080 -- generates implicit shift and rotate operators with Import
9081 -- pragmas that might apply to earlier explicit or implicit
9082 -- declarations marked with Import (for example, coming from
9083 -- an earlier pragma Provide_Shift_Operators for another type),
9084 -- and we don't generally want other homonyms being treated
9085 -- as imported or the pragma flagged as an illegal duplicate.
9087 elsif not Comes_From_Source
(N
) then
9091 Hom_Id
:= Homonym
(Hom_Id
);
9095 -- Import a CPP class
9097 elsif C
= Convention_CPP
9098 and then (Is_Record_Type
(Def_Id
)
9099 or else Ekind
(Def_Id
) = E_Incomplete_Type
)
9101 if Ekind
(Def_Id
) = E_Incomplete_Type
then
9102 if Present
(Full_View
(Def_Id
)) then
9103 Def_Id
:= Full_View
(Def_Id
);
9107 ("cannot import 'C'P'P type before full declaration seen",
9108 Get_Pragma_Arg
(Arg2
));
9110 -- Although we have reported the error we decorate it as
9111 -- CPP_Class to avoid reporting spurious errors
9113 Set_Is_CPP_Class
(Def_Id
);
9118 -- Types treated as CPP classes must be declared limited (note:
9119 -- this used to be a warning but there is no real benefit to it
9120 -- since we did effectively intend to treat the type as limited
9123 if not Is_Limited_Type
(Def_Id
) then
9125 ("imported 'C'P'P type must be limited",
9126 Get_Pragma_Arg
(Arg2
));
9129 if Etype
(Def_Id
) /= Def_Id
9130 and then not Is_CPP_Class
(Root_Type
(Def_Id
))
9132 Error_Msg_N
("root type must be a 'C'P'P type", Arg1
);
9135 Set_Is_CPP_Class
(Def_Id
);
9137 -- Imported CPP types must not have discriminants (because C++
9138 -- classes do not have discriminants).
9140 if Has_Discriminants
(Def_Id
) then
9142 ("imported 'C'P'P type cannot have discriminants",
9143 First
(Discriminant_Specifications
9144 (Declaration_Node
(Def_Id
))));
9147 -- Check that components of imported CPP types do not have default
9148 -- expressions. For private types this check is performed when the
9149 -- full view is analyzed (see Process_Full_View).
9151 if not Is_Private_Type
(Def_Id
) then
9152 Check_CPP_Type_Has_No_Defaults
(Def_Id
);
9155 -- Import a CPP exception
9157 elsif C
= Convention_CPP
9158 and then Ekind
(Def_Id
) = E_Exception
9162 ("'External_'Name arguments is required for 'Cpp exception",
9165 -- As only a string is allowed, Check_Arg_Is_External_Name
9168 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
9171 if Present
(Arg4
) then
9173 ("Link_Name argument not allowed for imported Cpp exception",
9177 -- Do not call Set_Interface_Name as the name of the exception
9178 -- shouldn't be modified (and in particular it shouldn't be
9179 -- the External_Name). For exceptions, the External_Name is the
9180 -- name of the RTTI structure.
9182 -- ??? Emit an error if pragma Import/Export_Exception is present
9184 elsif Nkind
(Parent
(Def_Id
)) = N_Incomplete_Type_Declaration
then
9186 Check_Arg_Count
(3);
9187 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
9189 Process_Import_Predefined_Type
;
9193 ("second argument of pragma% must be object, subprogram "
9194 & "or incomplete type",
9198 -- If this pragma applies to a compilation unit, then the unit, which
9199 -- is a subprogram, does not require (or allow) a body. We also do
9200 -- not need to elaborate imported procedures.
9202 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
9204 Cunit
: constant Node_Id
:= Parent
(Parent
(N
));
9206 Set_Body_Required
(Cunit
, False);
9209 end Process_Import_Or_Interface
;
9211 --------------------
9212 -- Process_Inline --
9213 --------------------
9215 procedure Process_Inline
(Status
: Inline_Status
) is
9222 Ghost_Error_Posted
: Boolean := False;
9223 -- Flag set when an error concerning the illegal mix of Ghost and
9224 -- non-Ghost subprograms is emitted.
9226 Ghost_Id
: Entity_Id
:= Empty
;
9227 -- The entity of the first Ghost subprogram encountered while
9228 -- processing the arguments of the pragma.
9230 procedure Check_Inline_Always_Placement
(Spec_Id
: Entity_Id
);
9231 -- Verify the placement of pragma Inline_Always with respect to the
9232 -- initial declaration of subprogram Spec_Id.
9234 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean;
9235 -- Returns True if it can be determined at this stage that inlining
9236 -- is not possible, for example if the body is available and contains
9237 -- exception handlers, we prevent inlining, since otherwise we can
9238 -- get undefined symbols at link time. This function also emits a
9239 -- warning if the pragma appears too late.
9241 -- ??? is business with link symbols still valid, or does it relate
9242 -- to front end ZCX which is being phased out ???
9244 procedure Make_Inline
(Subp
: Entity_Id
);
9245 -- Subp is the defining unit name of the subprogram declaration. If
9246 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9247 -- the corresponding body, if there is one present.
9249 procedure Set_Inline_Flags
(Subp
: Entity_Id
);
9250 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9251 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9253 -----------------------------------
9254 -- Check_Inline_Always_Placement --
9255 -----------------------------------
9257 procedure Check_Inline_Always_Placement
(Spec_Id
: Entity_Id
) is
9258 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Spec_Id
);
9260 function Compilation_Unit_OK
return Boolean;
9261 pragma Inline
(Compilation_Unit_OK
);
9262 -- Determine whether pragma Inline_Always applies to a compatible
9263 -- compilation unit denoted by Spec_Id.
9265 function Declarative_List_OK
return Boolean;
9266 pragma Inline
(Declarative_List_OK
);
9267 -- Determine whether the initial declaration of subprogram Spec_Id
9268 -- and the pragma appear in compatible declarative lists.
9270 function Subprogram_Body_OK
return Boolean;
9271 pragma Inline
(Subprogram_Body_OK
);
9272 -- Determine whether pragma Inline_Always applies to a compatible
9273 -- subprogram body denoted by Spec_Id.
9275 -------------------------
9276 -- Compilation_Unit_OK --
9277 -------------------------
9279 function Compilation_Unit_OK
return Boolean is
9280 Comp_Unit
: constant Node_Id
:= Parent
(Spec_Decl
);
9283 -- The pragma appears after the initial declaration of a
9284 -- compilation unit.
9286 -- procedure Comp_Unit;
9287 -- pragma Inline_Always (Comp_Unit);
9289 -- Note that for compatibility reasons, the following case is
9292 -- procedure Stand_Alone_Body_Comp_Unit is
9294 -- end Stand_Alone_Body_Comp_Unit;
9295 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9298 Nkind
(Comp_Unit
) = N_Compilation_Unit
9299 and then Present
(Aux_Decls_Node
(Comp_Unit
))
9300 and then Is_List_Member
(N
)
9301 and then List_Containing
(N
) =
9302 Pragmas_After
(Aux_Decls_Node
(Comp_Unit
));
9303 end Compilation_Unit_OK
;
9305 -------------------------
9306 -- Declarative_List_OK --
9307 -------------------------
9309 function Declarative_List_OK
return Boolean is
9310 Context
: constant Node_Id
:= Parent
(Spec_Decl
);
9312 Init_Decl
: Node_Id
;
9313 Init_List
: List_Id
;
9314 Prag_List
: List_Id
;
9317 -- Determine the proper initial declaration. In general this is
9318 -- the declaration node of the subprogram except when the input
9319 -- denotes a generic instantiation.
9321 -- procedure Inst is new Gen;
9322 -- pragma Inline_Always (Inst);
9324 -- In this case the original subprogram is moved inside an
9325 -- anonymous package while pragma Inline_Always remains at the
9326 -- level of the anonymous package. Use the declaration of the
9327 -- package because it reflects the placement of the original
9330 -- package Anon_Pack is
9331 -- procedure Inst is ... end Inst; -- original
9334 -- procedure Inst renames Anon_Pack.Inst;
9335 -- pragma Inline_Always (Inst);
9337 if Is_Generic_Instance
(Spec_Id
) then
9338 Init_Decl
:= Parent
(Parent
(Spec_Decl
));
9339 pragma Assert
(Nkind
(Init_Decl
) = N_Package_Declaration
);
9341 Init_Decl
:= Spec_Decl
;
9344 if Is_List_Member
(Init_Decl
) and then Is_List_Member
(N
) then
9345 Init_List
:= List_Containing
(Init_Decl
);
9346 Prag_List
:= List_Containing
(N
);
9348 -- The pragma and then initial declaration appear within the
9349 -- same declarative list.
9351 if Init_List
= Prag_List
then
9354 -- A special case of the above is when both the pragma and
9355 -- the initial declaration appear in different lists of a
9356 -- package spec, protected definition, or a task definition.
9361 -- pragma Inline_Always (Proc);
9364 elsif Nkind_In
(Context
, N_Package_Specification
,
9365 N_Protected_Definition
,
9367 and then Init_List
= Visible_Declarations
(Context
)
9368 and then Prag_List
= Private_Declarations
(Context
)
9375 end Declarative_List_OK
;
9377 ------------------------
9378 -- Subprogram_Body_OK --
9379 ------------------------
9381 function Subprogram_Body_OK
return Boolean is
9382 Body_Decl
: Node_Id
;
9385 -- The pragma appears within the declarative list of a stand-
9386 -- alone subprogram body.
9388 -- procedure Stand_Alone_Body is
9389 -- pragma Inline_Always (Stand_Alone_Body);
9392 -- end Stand_Alone_Body;
9394 -- The compiler creates a dummy spec in this case, however the
9395 -- pragma remains within the declarative list of the body.
9397 if Nkind
(Spec_Decl
) = N_Subprogram_Declaration
9398 and then not Comes_From_Source
(Spec_Decl
)
9399 and then Present
(Corresponding_Body
(Spec_Decl
))
9402 Unit_Declaration_Node
(Corresponding_Body
(Spec_Decl
));
9404 if Present
(Declarations
(Body_Decl
))
9405 and then Is_List_Member
(N
)
9406 and then List_Containing
(N
) = Declarations
(Body_Decl
)
9413 end Subprogram_Body_OK
;
9415 -- Start of processing for Check_Inline_Always_Placement
9418 -- This check is relevant only for pragma Inline_Always
9420 if Pname
/= Name_Inline_Always
then
9423 -- Nothing to do when the pragma is internally generated on the
9424 -- assumption that it is properly placed.
9426 elsif not Comes_From_Source
(N
) then
9429 -- Nothing to do for internally generated subprograms that act
9430 -- as accidental homonyms of a source subprogram being inlined.
9432 elsif not Comes_From_Source
(Spec_Id
) then
9435 -- Nothing to do for generic formal subprograms that act as
9436 -- homonyms of another source subprogram being inlined.
9438 elsif Is_Formal_Subprogram
(Spec_Id
) then
9441 elsif Compilation_Unit_OK
9442 or else Declarative_List_OK
9443 or else Subprogram_Body_OK
9448 -- At this point it is known that the pragma applies to or appears
9449 -- within a completing body, a completing stub, or a subunit.
9451 Error_Msg_Name_1
:= Pname
;
9452 Error_Msg_Name_2
:= Chars
(Spec_Id
);
9453 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
9456 ("pragma % must appear on initial declaration of subprogram "
9457 & "% defined #", N
);
9458 end Check_Inline_Always_Placement
;
9460 ---------------------------
9461 -- Inlining_Not_Possible --
9462 ---------------------------
9464 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean is
9465 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
9469 if Nkind
(Decl
) = N_Subprogram_Body
then
9470 Stats
:= Handled_Statement_Sequence
(Decl
);
9471 return Present
(Exception_Handlers
(Stats
))
9472 or else Present
(At_End_Proc
(Stats
));
9474 elsif Nkind
(Decl
) = N_Subprogram_Declaration
9475 and then Present
(Corresponding_Body
(Decl
))
9477 if Analyzed
(Corresponding_Body
(Decl
)) then
9478 Error_Msg_N
("pragma appears too late, ignored??", N
);
9481 -- If the subprogram is a renaming as body, the body is just a
9482 -- call to the renamed subprogram, and inlining is trivially
9486 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
9487 N_Subprogram_Renaming_Declaration
9493 Handled_Statement_Sequence
9494 (Unit_Declaration_Node
(Corresponding_Body
(Decl
)));
9497 Present
(Exception_Handlers
(Stats
))
9498 or else Present
(At_End_Proc
(Stats
));
9502 -- If body is not available, assume the best, the check is
9503 -- performed again when compiling enclosing package bodies.
9507 end Inlining_Not_Possible
;
9513 procedure Make_Inline
(Subp
: Entity_Id
) is
9514 Kind
: constant Entity_Kind
:= Ekind
(Subp
);
9515 Inner_Subp
: Entity_Id
:= Subp
;
9518 -- Ignore if bad type, avoid cascaded error
9520 if Etype
(Subp
) = Any_Type
then
9524 -- If inlining is not possible, for now do not treat as an error
9526 elsif Status
/= Suppressed
9527 and then Front_End_Inlining
9528 and then Inlining_Not_Possible
(Subp
)
9533 -- Here we have a candidate for inlining, but we must exclude
9534 -- derived operations. Otherwise we would end up trying to inline
9535 -- a phantom declaration, and the result would be to drag in a
9536 -- body which has no direct inlining associated with it. That
9537 -- would not only be inefficient but would also result in the
9538 -- backend doing cross-unit inlining in cases where it was
9539 -- definitely inappropriate to do so.
9541 -- However, a simple Comes_From_Source test is insufficient, since
9542 -- we do want to allow inlining of generic instances which also do
9543 -- not come from source. We also need to recognize specs generated
9544 -- by the front-end for bodies that carry the pragma. Finally,
9545 -- predefined operators do not come from source but are not
9546 -- inlineable either.
9548 elsif Is_Generic_Instance
(Subp
)
9549 or else Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Declaration
9553 elsif not Comes_From_Source
(Subp
)
9554 and then Scope
(Subp
) /= Standard_Standard
9560 -- The referenced entity must either be the enclosing entity, or
9561 -- an entity declared within the current open scope.
9563 if Present
(Scope
(Subp
))
9564 and then Scope
(Subp
) /= Current_Scope
9565 and then Subp
/= Current_Scope
9568 ("argument of% must be entity in current scope", Assoc
);
9572 -- Processing for procedure, operator or function. If subprogram
9573 -- is aliased (as for an instance) indicate that the renamed
9574 -- entity (if declared in the same unit) is inlined.
9575 -- If this is the anonymous subprogram created for a subprogram
9576 -- instance, the inlining applies to it directly. Otherwise we
9577 -- retrieve it as the alias of the visible subprogram instance.
9579 if Is_Subprogram
(Subp
) then
9581 -- Ensure that pragma Inline_Always is associated with the
9582 -- initial declaration of the subprogram.
9584 Check_Inline_Always_Placement
(Subp
);
9586 if Is_Wrapper_Package
(Scope
(Subp
)) then
9589 Inner_Subp
:= Ultimate_Alias
(Inner_Subp
);
9592 if In_Same_Source_Unit
(Subp
, Inner_Subp
) then
9593 Set_Inline_Flags
(Inner_Subp
);
9595 Decl
:= Parent
(Parent
(Inner_Subp
));
9597 if Nkind
(Decl
) = N_Subprogram_Declaration
9598 and then Present
(Corresponding_Body
(Decl
))
9600 Set_Inline_Flags
(Corresponding_Body
(Decl
));
9602 elsif Is_Generic_Instance
(Subp
)
9603 and then Comes_From_Source
(Subp
)
9605 -- Indicate that the body needs to be created for
9606 -- inlining subsequent calls. The instantiation node
9607 -- follows the declaration of the wrapper package
9608 -- created for it. The subprogram that requires the
9609 -- body is the anonymous one in the wrapper package.
9611 if Scope
(Subp
) /= Standard_Standard
9613 Need_Subprogram_Instance_Body
9614 (Next
(Unit_Declaration_Node
9615 (Scope
(Alias
(Subp
)))), Subp
)
9620 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9621 -- appear in a formal part to apply to a formal subprogram.
9622 -- Do not apply check within an instance or a formal package
9623 -- the test will have been applied to the original generic.
9625 elsif Nkind
(Decl
) in N_Formal_Subprogram_Declaration
9626 and then List_Containing
(Decl
) = List_Containing
(N
)
9627 and then not In_Instance
9630 ("Inline cannot apply to a formal subprogram", N
);
9632 -- If Subp is a renaming, it is the renamed entity that
9633 -- will appear in any call, and be inlined. However, for
9634 -- ASIS uses it is convenient to indicate that the renaming
9635 -- itself is an inlined subprogram, so that some gnatcheck
9636 -- rules can be applied in the absence of expansion.
9638 elsif Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
9639 Set_Inline_Flags
(Subp
);
9645 -- For a generic subprogram set flag as well, for use at the point
9646 -- of instantiation, to determine whether the body should be
9649 elsif Is_Generic_Subprogram
(Subp
) then
9650 Set_Inline_Flags
(Subp
);
9653 -- Literals are by definition inlined
9655 elsif Kind
= E_Enumeration_Literal
then
9658 -- Anything else is an error
9662 ("expect subprogram name for pragma%", Assoc
);
9666 ----------------------
9667 -- Set_Inline_Flags --
9668 ----------------------
9670 procedure Set_Inline_Flags
(Subp
: Entity_Id
) is
9672 -- First set the Has_Pragma_XXX flags and issue the appropriate
9673 -- errors and warnings for suspicious combinations.
9675 if Prag_Id
= Pragma_No_Inline
then
9676 if Has_Pragma_Inline_Always
(Subp
) then
9678 ("Inline_Always and No_Inline are mutually exclusive", N
);
9679 elsif Has_Pragma_Inline
(Subp
) then
9681 ("Inline and No_Inline both specified for& ??",
9682 N
, Entity
(Subp_Id
));
9685 Set_Has_Pragma_No_Inline
(Subp
);
9687 if Prag_Id
= Pragma_Inline_Always
then
9688 if Has_Pragma_No_Inline
(Subp
) then
9690 ("Inline_Always and No_Inline are mutually exclusive",
9694 Set_Has_Pragma_Inline_Always
(Subp
);
9696 if Has_Pragma_No_Inline
(Subp
) then
9698 ("Inline and No_Inline both specified for& ??",
9699 N
, Entity
(Subp_Id
));
9703 Set_Has_Pragma_Inline
(Subp
);
9706 -- Then adjust the Is_Inlined flag. It can never be set if the
9707 -- subprogram is subject to pragma No_Inline.
9711 Set_Is_Inlined
(Subp
, False);
9717 if not Has_Pragma_No_Inline
(Subp
) then
9718 Set_Is_Inlined
(Subp
, True);
9722 -- A pragma that applies to a Ghost entity becomes Ghost for the
9723 -- purposes of legality checks and removal of ignored Ghost code.
9725 Mark_Ghost_Pragma
(N
, Subp
);
9727 -- Capture the entity of the first Ghost subprogram being
9728 -- processed for error detection purposes.
9730 if Is_Ghost_Entity
(Subp
) then
9731 if No
(Ghost_Id
) then
9735 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9736 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9738 elsif Present
(Ghost_Id
) and then not Ghost_Error_Posted
then
9739 Ghost_Error_Posted
:= True;
9741 Error_Msg_Name_1
:= Pname
;
9743 ("pragma % cannot mention ghost and non-ghost subprograms",
9746 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
9747 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
9749 Error_Msg_Sloc
:= Sloc
(Subp
);
9750 Error_Msg_NE
("\& # declared as non-ghost", N
, Subp
);
9752 end Set_Inline_Flags
;
9754 -- Start of processing for Process_Inline
9757 Check_No_Identifiers
;
9758 Check_At_Least_N_Arguments
(1);
9760 if Status
= Enabled
then
9761 Inline_Processing_Required
:= True;
9765 while Present
(Assoc
) loop
9766 Subp_Id
:= Get_Pragma_Arg
(Assoc
);
9770 if Is_Entity_Name
(Subp_Id
) then
9771 Subp
:= Entity
(Subp_Id
);
9773 if Subp
= Any_Id
then
9775 -- If previous error, avoid cascaded errors
9777 Check_Error_Detected
;
9783 -- For the pragma case, climb homonym chain. This is
9784 -- what implements allowing the pragma in the renaming
9785 -- case, with the result applying to the ancestors, and
9786 -- also allows Inline to apply to all previous homonyms.
9788 if not From_Aspect_Specification
(N
) then
9789 while Present
(Homonym
(Subp
))
9790 and then Scope
(Homonym
(Subp
)) = Current_Scope
9792 Make_Inline
(Homonym
(Subp
));
9793 Subp
:= Homonym
(Subp
);
9800 Error_Pragma_Arg
("inappropriate argument for pragma%", Assoc
);
9806 -- If the context is a package declaration, the pragma indicates
9807 -- that inlining will require the presence of the corresponding
9808 -- body. (this may be further refined).
9811 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
9812 N_Package_Declaration
9814 Set_Body_Needed_For_Inlining
(Cunit_Entity
(Current_Sem_Unit
));
9818 ----------------------------
9819 -- Process_Interface_Name --
9820 ----------------------------
9822 procedure Process_Interface_Name
9823 (Subprogram_Def
: Entity_Id
;
9830 String_Val
: String_Id
;
9832 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
);
9833 -- SN is a string literal node for an interface name. This routine
9834 -- performs some minimal checks that the name is reasonable. In
9835 -- particular that no spaces or other obviously incorrect characters
9836 -- appear. This is only a warning, since any characters are allowed.
9838 ----------------------------------
9839 -- Check_Form_Of_Interface_Name --
9840 ----------------------------------
9842 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
) is
9843 S
: constant String_Id
:= Strval
(Expr_Value_S
(SN
));
9844 SL
: constant Nat
:= String_Length
(S
);
9849 Error_Msg_N
("interface name cannot be null string", SN
);
9852 for J
in 1 .. SL
loop
9853 C
:= Get_String_Char
(S
, J
);
9855 -- Look for dubious character and issue unconditional warning.
9856 -- Definitely dubious if not in character range.
9858 if not In_Character_Range
(C
)
9860 -- Commas, spaces and (back)slashes are dubious
9862 or else Get_Character
(C
) = ','
9863 or else Get_Character
(C
) = '\'
9864 or else Get_Character
(C
) = ' '
9865 or else Get_Character
(C
) = '/'
9868 ("??interface name contains illegal character",
9869 Sloc
(SN
) + Source_Ptr
(J
));
9872 end Check_Form_Of_Interface_Name
;
9874 -- Start of processing for Process_Interface_Name
9877 -- If we are looking at a pragma that comes from an aspect then it
9878 -- needs to have its corresponding aspect argument expressions
9879 -- analyzed in addition to the generated pragma so that aspects
9880 -- within generic units get properly resolved.
9882 if Present
(Prag
) and then From_Aspect_Specification
(Prag
) then
9884 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
9892 -- Obtain all interfacing aspects used to construct the pragma
9894 Get_Interfacing_Aspects
9895 (Asp
, Dummy_1
, EN
, Dummy_2
, Dummy_3
, LN
);
9897 -- Analyze the expression of aspect External_Name
9899 if Present
(EN
) then
9900 Analyze
(Expression
(EN
));
9903 -- Analyze the expressio of aspect Link_Name
9905 if Present
(LN
) then
9906 Analyze
(Expression
(LN
));
9911 if No
(Link_Arg
) then
9912 if No
(Ext_Arg
) then
9915 elsif Chars
(Ext_Arg
) = Name_Link_Name
then
9917 Link_Nam
:= Expression
(Ext_Arg
);
9920 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
9921 Ext_Nam
:= Expression
(Ext_Arg
);
9926 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
9927 Check_Optional_Identifier
(Link_Arg
, Name_Link_Name
);
9928 Ext_Nam
:= Expression
(Ext_Arg
);
9929 Link_Nam
:= Expression
(Link_Arg
);
9932 -- Check expressions for external name and link name are static
9934 if Present
(Ext_Nam
) then
9935 Check_Arg_Is_OK_Static_Expression
(Ext_Nam
, Standard_String
);
9936 Check_Form_Of_Interface_Name
(Ext_Nam
);
9938 -- Verify that external name is not the name of a local entity,
9939 -- which would hide the imported one and could lead to run-time
9940 -- surprises. The problem can only arise for entities declared in
9941 -- a package body (otherwise the external name is fully qualified
9942 -- and will not conflict).
9950 if Prag_Id
= Pragma_Import
then
9951 Nam
:= String_To_Name
(Strval
(Expr_Value_S
(Ext_Nam
)));
9952 E
:= Entity_Id
(Get_Name_Table_Int
(Nam
));
9954 if Nam
/= Chars
(Subprogram_Def
)
9955 and then Present
(E
)
9956 and then not Is_Overloadable
(E
)
9957 and then Is_Immediately_Visible
(E
)
9958 and then not Is_Imported
(E
)
9959 and then Ekind
(Scope
(E
)) = E_Package
9962 while Present
(Par
) loop
9963 if Nkind
(Par
) = N_Package_Body
then
9964 Error_Msg_Sloc
:= Sloc
(E
);
9966 ("imported entity is hidden by & declared#",
9971 Par
:= Parent
(Par
);
9978 if Present
(Link_Nam
) then
9979 Check_Arg_Is_OK_Static_Expression
(Link_Nam
, Standard_String
);
9980 Check_Form_Of_Interface_Name
(Link_Nam
);
9983 -- If there is no link name, just set the external name
9985 if No
(Link_Nam
) then
9986 Link_Nam
:= Adjust_External_Name_Case
(Expr_Value_S
(Ext_Nam
));
9988 -- For the Link_Name case, the given literal is preceded by an
9989 -- asterisk, which indicates to GCC that the given name should be
9990 -- taken literally, and in particular that no prepending of
9991 -- underlines should occur, even in systems where this is the
9996 Store_String_Char
(Get_Char_Code
('*'));
9997 String_Val
:= Strval
(Expr_Value_S
(Link_Nam
));
9998 Store_String_Chars
(String_Val
);
10000 Make_String_Literal
(Sloc
(Link_Nam
),
10001 Strval
=> End_String
);
10004 -- Set the interface name. If the entity is a generic instance, use
10005 -- its alias, which is the callable entity.
10007 if Is_Generic_Instance
(Subprogram_Def
) then
10008 Set_Encoded_Interface_Name
10009 (Alias
(Get_Base_Subprogram
(Subprogram_Def
)), Link_Nam
);
10011 Set_Encoded_Interface_Name
10012 (Get_Base_Subprogram
(Subprogram_Def
), Link_Nam
);
10015 Check_Duplicated_Export_Name
(Link_Nam
);
10016 end Process_Interface_Name
;
10018 -----------------------------------------
10019 -- Process_Interrupt_Or_Attach_Handler --
10020 -----------------------------------------
10022 procedure Process_Interrupt_Or_Attach_Handler
is
10023 Handler
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
10024 Prot_Typ
: constant Entity_Id
:= Scope
(Handler
);
10027 -- A pragma that applies to a Ghost entity becomes Ghost for the
10028 -- purposes of legality checks and removal of ignored Ghost code.
10030 Mark_Ghost_Pragma
(N
, Handler
);
10031 Set_Is_Interrupt_Handler
(Handler
);
10033 pragma Assert
(Ekind
(Prot_Typ
) = E_Protected_Type
);
10035 Record_Rep_Item
(Prot_Typ
, N
);
10037 -- Chain the pragma on the contract for completeness
10039 Add_Contract_Item
(N
, Handler
);
10040 end Process_Interrupt_Or_Attach_Handler
;
10042 --------------------------------------------------
10043 -- Process_Restrictions_Or_Restriction_Warnings --
10044 --------------------------------------------------
10046 -- Note: some of the simple identifier cases were handled in par-prag,
10047 -- but it is harmless (and more straightforward) to simply handle all
10048 -- cases here, even if it means we repeat a bit of work in some cases.
10050 procedure Process_Restrictions_Or_Restriction_Warnings
10054 R_Id
: Restriction_Id
;
10060 -- Ignore all Restrictions pragmas in CodePeer mode
10062 if CodePeer_Mode
then
10066 Check_Ada_83_Warning
;
10067 Check_At_Least_N_Arguments
(1);
10068 Check_Valid_Configuration_Pragma
;
10071 while Present
(Arg
) loop
10073 Expr
:= Get_Pragma_Arg
(Arg
);
10075 -- Case of no restriction identifier present
10077 if Id
= No_Name
then
10078 if Nkind
(Expr
) /= N_Identifier
then
10080 ("invalid form for restriction", Arg
);
10085 (Process_Restriction_Synonyms
(Expr
));
10087 if R_Id
not in All_Boolean_Restrictions
then
10088 Error_Msg_Name_1
:= Pname
;
10090 ("invalid restriction identifier&", Get_Pragma_Arg
(Arg
));
10092 -- Check for possible misspelling
10094 for J
in Restriction_Id
loop
10096 Rnm
: constant String := Restriction_Id
'Image (J
);
10099 Name_Buffer
(1 .. Rnm
'Length) := Rnm
;
10100 Name_Len
:= Rnm
'Length;
10101 Set_Casing
(All_Lower_Case
);
10103 if Is_Bad_Spelling_Of
(Chars
(Expr
), Name_Enter
) then
10106 (Source_Index
(Current_Sem_Unit
)));
10107 Error_Msg_String
(1 .. Rnm
'Length) :=
10108 Name_Buffer
(1 .. Name_Len
);
10109 Error_Msg_Strlen
:= Rnm
'Length;
10110 Error_Msg_N
-- CODEFIX
10111 ("\possible misspelling of ""~""",
10112 Get_Pragma_Arg
(Arg
));
10121 if Implementation_Restriction
(R_Id
) then
10122 Check_Restriction
(No_Implementation_Restrictions
, Arg
);
10125 -- Special processing for No_Elaboration_Code restriction
10127 if R_Id
= No_Elaboration_Code
then
10129 -- Restriction is only recognized within a configuration
10130 -- pragma file, or within a unit of the main extended
10131 -- program. Note: the test for Main_Unit is needed to
10132 -- properly include the case of configuration pragma files.
10134 if not (Current_Sem_Unit
= Main_Unit
10135 or else In_Extended_Main_Source_Unit
(N
))
10139 -- Don't allow in a subunit unless already specified in
10142 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
10143 and then Nkind
(Unit
(Parent
(N
))) = N_Subunit
10144 and then not Restriction_Active
(No_Elaboration_Code
)
10147 ("invalid specification of ""No_Elaboration_Code""",
10150 ("\restriction cannot be specified in a subunit", N
);
10152 ("\unless also specified in body or spec", N
);
10155 -- If we accept a No_Elaboration_Code restriction, then it
10156 -- needs to be added to the configuration restriction set so
10157 -- that we get proper application to other units in the main
10158 -- extended source as required.
10161 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
10165 -- If this is a warning, then set the warning unless we already
10166 -- have a real restriction active (we never want a warning to
10167 -- override a real restriction).
10170 if not Restriction_Active
(R_Id
) then
10171 Set_Restriction
(R_Id
, N
);
10172 Restriction_Warnings
(R_Id
) := True;
10175 -- If real restriction case, then set it and make sure that the
10176 -- restriction warning flag is off, since a real restriction
10177 -- always overrides a warning.
10180 Set_Restriction
(R_Id
, N
);
10181 Restriction_Warnings
(R_Id
) := False;
10184 -- Check for obsolescent restrictions in Ada 2005 mode
10187 and then Ada_Version
>= Ada_2005
10188 and then (R_Id
= No_Asynchronous_Control
10190 R_Id
= No_Unchecked_Deallocation
10192 R_Id
= No_Unchecked_Conversion
)
10194 Check_Restriction
(No_Obsolescent_Features
, N
);
10197 -- A very special case that must be processed here: pragma
10198 -- Restrictions (No_Exceptions) turns off all run-time
10199 -- checking. This is a bit dubious in terms of the formal
10200 -- language definition, but it is what is intended by RM
10201 -- H.4(12). Restriction_Warnings never affects generated code
10202 -- so this is done only in the real restriction case.
10204 -- Atomic_Synchronization is not a real check, so it is not
10205 -- affected by this processing).
10207 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10208 -- run-time checks in CodePeer and GNATprove modes: we want to
10209 -- generate checks for analysis purposes, as set respectively
10210 -- by -gnatC and -gnatd.F
10213 and then not (CodePeer_Mode
or GNATprove_Mode
)
10214 and then R_Id
= No_Exceptions
10216 for J
in Scope_Suppress
.Suppress
'Range loop
10217 if J
/= Atomic_Synchronization
then
10218 Scope_Suppress
.Suppress
(J
) := True;
10223 -- Case of No_Dependence => unit-name. Note that the parser
10224 -- already made the necessary entry in the No_Dependence table.
10226 elsif Id
= Name_No_Dependence
then
10227 if not OK_No_Dependence_Unit_Name
(Expr
) then
10231 -- Case of No_Specification_Of_Aspect => aspect-identifier
10233 elsif Id
= Name_No_Specification_Of_Aspect
then
10238 if Nkind
(Expr
) /= N_Identifier
then
10241 A_Id
:= Get_Aspect_Id
(Chars
(Expr
));
10244 if A_Id
= No_Aspect
then
10245 Error_Pragma_Arg
("invalid restriction name", Arg
);
10247 Set_Restriction_No_Specification_Of_Aspect
(Expr
, Warn
);
10251 -- Case of No_Use_Of_Attribute => attribute-identifier
10253 elsif Id
= Name_No_Use_Of_Attribute
then
10254 if Nkind
(Expr
) /= N_Identifier
10255 or else not Is_Attribute_Name
(Chars
(Expr
))
10257 Error_Msg_N
("unknown attribute name??", Expr
);
10260 Set_Restriction_No_Use_Of_Attribute
(Expr
, Warn
);
10263 -- Case of No_Use_Of_Entity => fully-qualified-name
10265 elsif Id
= Name_No_Use_Of_Entity
then
10267 -- Restriction is only recognized within a configuration
10268 -- pragma file, or within a unit of the main extended
10269 -- program. Note: the test for Main_Unit is needed to
10270 -- properly include the case of configuration pragma files.
10272 if Current_Sem_Unit
= Main_Unit
10273 or else In_Extended_Main_Source_Unit
(N
)
10275 if not OK_No_Dependence_Unit_Name
(Expr
) then
10276 Error_Msg_N
("wrong form for entity name", Expr
);
10278 Set_Restriction_No_Use_Of_Entity
10279 (Expr
, Warn
, No_Profile
);
10283 -- Case of No_Use_Of_Pragma => pragma-identifier
10285 elsif Id
= Name_No_Use_Of_Pragma
then
10286 if Nkind
(Expr
) /= N_Identifier
10287 or else not Is_Pragma_Name
(Chars
(Expr
))
10289 Error_Msg_N
("unknown pragma name??", Expr
);
10291 Set_Restriction_No_Use_Of_Pragma
(Expr
, Warn
);
10294 -- All other cases of restriction identifier present
10297 R_Id
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(Arg
));
10298 Analyze_And_Resolve
(Expr
, Any_Integer
);
10300 if R_Id
not in All_Parameter_Restrictions
then
10302 ("invalid restriction parameter identifier", Arg
);
10304 elsif not Is_OK_Static_Expression
(Expr
) then
10305 Flag_Non_Static_Expr
10306 ("value must be static expression!", Expr
);
10309 elsif not Is_Integer_Type
(Etype
(Expr
))
10310 or else Expr_Value
(Expr
) < 0
10313 ("value must be non-negative integer", Arg
);
10316 -- Restriction pragma is active
10318 Val
:= Expr_Value
(Expr
);
10320 if not UI_Is_In_Int_Range
(Val
) then
10322 ("pragma ignored, value too large??", Arg
);
10325 -- Warning case. If the real restriction is active, then we
10326 -- ignore the request, since warning never overrides a real
10327 -- restriction. Otherwise we set the proper warning. Note that
10328 -- this circuit sets the warning again if it is already set,
10329 -- which is what we want, since the constant may have changed.
10332 if not Restriction_Active
(R_Id
) then
10334 (R_Id
, N
, Integer (UI_To_Int
(Val
)));
10335 Restriction_Warnings
(R_Id
) := True;
10338 -- Real restriction case, set restriction and make sure warning
10339 -- flag is off since real restriction always overrides warning.
10342 Set_Restriction
(R_Id
, N
, Integer (UI_To_Int
(Val
)));
10343 Restriction_Warnings
(R_Id
) := False;
10349 end Process_Restrictions_Or_Restriction_Warnings
;
10351 ---------------------------------
10352 -- Process_Suppress_Unsuppress --
10353 ---------------------------------
10355 -- Note: this procedure makes entries in the check suppress data
10356 -- structures managed by Sem. See spec of package Sem for full
10357 -- details on how we handle recording of check suppression.
10359 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean) is
10364 In_Package_Spec
: constant Boolean :=
10365 Is_Package_Or_Generic_Package
(Current_Scope
)
10366 and then not In_Package_Body
(Current_Scope
);
10368 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
);
10369 -- Used to suppress a single check on the given entity
10371 --------------------------------
10372 -- Suppress_Unsuppress_Echeck --
10373 --------------------------------
10375 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
) is
10377 -- Check for error of trying to set atomic synchronization for
10378 -- a non-atomic variable.
10380 if C
= Atomic_Synchronization
10381 and then not (Is_Atomic
(E
) or else Has_Atomic_Components
(E
))
10384 ("pragma & requires atomic type or variable",
10385 Pragma_Identifier
(Original_Node
(N
)));
10388 Set_Checks_May_Be_Suppressed
(E
);
10390 if In_Package_Spec
then
10391 Push_Global_Suppress_Stack_Entry
10394 Suppress
=> Suppress_Case
);
10396 Push_Local_Suppress_Stack_Entry
10399 Suppress
=> Suppress_Case
);
10402 -- If this is a first subtype, and the base type is distinct,
10403 -- then also set the suppress flags on the base type.
10405 if Is_First_Subtype
(E
) and then Etype
(E
) /= E
then
10406 Suppress_Unsuppress_Echeck
(Etype
(E
), C
);
10408 end Suppress_Unsuppress_Echeck
;
10410 -- Start of processing for Process_Suppress_Unsuppress
10413 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10414 -- on user code: we want to generate checks for analysis purposes, as
10415 -- set respectively by -gnatC and -gnatd.F
10417 if Comes_From_Source
(N
)
10418 and then (CodePeer_Mode
or GNATprove_Mode
)
10423 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10424 -- declarative part or a package spec (RM 11.5(5)).
10426 if not Is_Configuration_Pragma
then
10427 Check_Is_In_Decl_Part_Or_Package_Spec
;
10430 Check_At_Least_N_Arguments
(1);
10431 Check_At_Most_N_Arguments
(2);
10432 Check_No_Identifier
(Arg1
);
10433 Check_Arg_Is_Identifier
(Arg1
);
10435 C
:= Get_Check_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
10437 if C
= No_Check_Id
then
10439 ("argument of pragma% is not valid check name", Arg1
);
10442 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10444 if C
= Elaboration_Check
and then SPARK_Mode
= On
then
10446 ("Suppress of Elaboration_Check ignored in SPARK??",
10447 "\elaboration checking rules are statically enforced "
10448 & "(SPARK RM 7.7)", Arg1
);
10451 -- One-argument case
10453 if Arg_Count
= 1 then
10455 -- Make an entry in the local scope suppress table. This is the
10456 -- table that directly shows the current value of the scope
10457 -- suppress check for any check id value.
10459 if C
= All_Checks
then
10461 -- For All_Checks, we set all specific predefined checks with
10462 -- the exception of Elaboration_Check, which is handled
10463 -- specially because of not wanting All_Checks to have the
10464 -- effect of deactivating static elaboration order processing.
10465 -- Atomic_Synchronization is also not affected, since this is
10466 -- not a real check.
10468 for J
in Scope_Suppress
.Suppress
'Range loop
10469 if J
/= Elaboration_Check
10471 J
/= Atomic_Synchronization
10473 Scope_Suppress
.Suppress
(J
) := Suppress_Case
;
10477 -- If not All_Checks, and predefined check, then set appropriate
10478 -- scope entry. Note that we will set Elaboration_Check if this
10479 -- is explicitly specified. Atomic_Synchronization is allowed
10480 -- only if internally generated and entity is atomic.
10482 elsif C
in Predefined_Check_Id
10483 and then (not Comes_From_Source
(N
)
10484 or else C
/= Atomic_Synchronization
)
10486 Scope_Suppress
.Suppress
(C
) := Suppress_Case
;
10489 -- Also make an entry in the Local_Entity_Suppress table
10491 Push_Local_Suppress_Stack_Entry
10494 Suppress
=> Suppress_Case
);
10496 -- Case of two arguments present, where the check is suppressed for
10497 -- a specified entity (given as the second argument of the pragma)
10500 -- This is obsolescent in Ada 2005 mode
10502 if Ada_Version
>= Ada_2005
then
10503 Check_Restriction
(No_Obsolescent_Features
, Arg2
);
10506 Check_Optional_Identifier
(Arg2
, Name_On
);
10507 E_Id
:= Get_Pragma_Arg
(Arg2
);
10510 if not Is_Entity_Name
(E_Id
) then
10512 ("second argument of pragma% must be entity name", Arg2
);
10515 E
:= Entity
(E_Id
);
10521 -- A pragma that applies to a Ghost entity becomes Ghost for the
10522 -- purposes of legality checks and removal of ignored Ghost code.
10524 Mark_Ghost_Pragma
(N
, E
);
10526 -- Enforce RM 11.5(7) which requires that for a pragma that
10527 -- appears within a package spec, the named entity must be
10528 -- within the package spec. We allow the package name itself
10529 -- to be mentioned since that makes sense, although it is not
10530 -- strictly allowed by 11.5(7).
10533 and then E
/= Current_Scope
10534 and then Scope
(E
) /= Current_Scope
10537 ("entity in pragma% is not in package spec (RM 11.5(7))",
10541 -- Loop through homonyms. As noted below, in the case of a package
10542 -- spec, only homonyms within the package spec are considered.
10545 Suppress_Unsuppress_Echeck
(E
, C
);
10547 if Is_Generic_Instance
(E
)
10548 and then Is_Subprogram
(E
)
10549 and then Present
(Alias
(E
))
10551 Suppress_Unsuppress_Echeck
(Alias
(E
), C
);
10554 -- Move to next homonym if not aspect spec case
10556 exit when From_Aspect_Specification
(N
);
10560 -- If we are within a package specification, the pragma only
10561 -- applies to homonyms in the same scope.
10563 exit when In_Package_Spec
10564 and then Scope
(E
) /= Current_Scope
;
10567 end Process_Suppress_Unsuppress
;
10569 -------------------------------
10570 -- Record_Independence_Check --
10571 -------------------------------
10573 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
) is
10574 pragma Unreferenced
(N
, E
);
10576 -- For GCC back ends the validation is done a priori
10577 -- ??? This code is dead, might be useful in the future
10579 -- if not AAMP_On_Target then
10583 -- Independence_Checks.Append ((N, E));
10586 end Record_Independence_Check
;
10592 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
) is
10594 if Is_Imported
(E
) then
10596 ("cannot export entity& that was previously imported", Arg
);
10598 elsif Present
(Address_Clause
(E
))
10599 and then not Relaxed_RM_Semantics
10602 ("cannot export entity& that has an address clause", Arg
);
10605 Set_Is_Exported
(E
);
10607 -- Generate a reference for entity explicitly, because the
10608 -- identifier may be overloaded and name resolution will not
10611 Generate_Reference
(E
, Arg
);
10613 -- Deal with exporting non-library level entity
10615 if not Is_Library_Level_Entity
(E
) then
10617 -- Not allowed at all for subprograms
10619 if Is_Subprogram
(E
) then
10620 Error_Pragma_Arg
("local subprogram& cannot be exported", Arg
);
10622 -- Otherwise set public and statically allocated
10626 Set_Is_Statically_Allocated
(E
);
10628 -- Warn if the corresponding W flag is set
10630 if Warn_On_Export_Import
10632 -- Only do this for something that was in the source. Not
10633 -- clear if this can be False now (there used for sure to be
10634 -- cases on some systems where it was False), but anyway the
10635 -- test is harmless if not needed, so it is retained.
10637 and then Comes_From_Source
(Arg
)
10640 ("?x?& has been made static as a result of Export",
10643 ("\?x?this usage is non-standard and non-portable",
10649 if Warn_On_Export_Import
and then Is_Type
(E
) then
10650 Error_Msg_NE
("exporting a type has no effect?x?", Arg
, E
);
10653 if Warn_On_Export_Import
and Inside_A_Generic
then
10655 ("all instances of& will have the same external name?x?",
10660 ----------------------------------------------
10661 -- Set_Extended_Import_Export_External_Name --
10662 ----------------------------------------------
10664 procedure Set_Extended_Import_Export_External_Name
10665 (Internal_Ent
: Entity_Id
;
10666 Arg_External
: Node_Id
)
10668 Old_Name
: constant Node_Id
:= Interface_Name
(Internal_Ent
);
10669 New_Name
: Node_Id
;
10672 if No
(Arg_External
) then
10676 Check_Arg_Is_External_Name
(Arg_External
);
10678 if Nkind
(Arg_External
) = N_String_Literal
then
10679 if String_Length
(Strval
(Arg_External
)) = 0 then
10682 New_Name
:= Adjust_External_Name_Case
(Arg_External
);
10685 elsif Nkind
(Arg_External
) = N_Identifier
then
10686 New_Name
:= Get_Default_External_Name
(Arg_External
);
10688 -- Check_Arg_Is_External_Name should let through only identifiers and
10689 -- string literals or static string expressions (which are folded to
10690 -- string literals).
10693 raise Program_Error
;
10696 -- If we already have an external name set (by a prior normal Import
10697 -- or Export pragma), then the external names must match
10699 if Present
(Interface_Name
(Internal_Ent
)) then
10701 -- Ignore mismatching names in CodePeer mode, to support some
10702 -- old compilers which would export the same procedure under
10703 -- different names, e.g:
10705 -- pragma Export_Procedure (P, "a");
10706 -- pragma Export_Procedure (P, "b");
10708 if CodePeer_Mode
then
10712 Check_Matching_Internal_Names
: declare
10713 S1
: constant String_Id
:= Strval
(Old_Name
);
10714 S2
: constant String_Id
:= Strval
(New_Name
);
10716 procedure Mismatch
;
10717 pragma No_Return
(Mismatch
);
10718 -- Called if names do not match
10724 procedure Mismatch
is
10726 Error_Msg_Sloc
:= Sloc
(Old_Name
);
10728 ("external name does not match that given #",
10732 -- Start of processing for Check_Matching_Internal_Names
10735 if String_Length
(S1
) /= String_Length
(S2
) then
10739 for J
in 1 .. String_Length
(S1
) loop
10740 if Get_String_Char
(S1
, J
) /= Get_String_Char
(S2
, J
) then
10745 end Check_Matching_Internal_Names
;
10747 -- Otherwise set the given name
10750 Set_Encoded_Interface_Name
(Internal_Ent
, New_Name
);
10751 Check_Duplicated_Export_Name
(New_Name
);
10753 end Set_Extended_Import_Export_External_Name
;
10759 procedure Set_Imported
(E
: Entity_Id
) is
10761 -- Error message if already imported or exported
10763 if Is_Exported
(E
) or else Is_Imported
(E
) then
10765 -- Error if being set Exported twice
10767 if Is_Exported
(E
) then
10768 Error_Msg_NE
("entity& was previously exported", N
, E
);
10770 -- Ignore error in CodePeer mode where we treat all imported
10771 -- subprograms as unknown.
10773 elsif CodePeer_Mode
then
10776 -- OK if Import/Interface case
10778 elsif Import_Interface_Present
(N
) then
10781 -- Error if being set Imported twice
10784 Error_Msg_NE
("entity& was previously imported", N
, E
);
10787 Error_Msg_Name_1
:= Pname
;
10789 ("\(pragma% applies to all previous entities)", N
);
10791 Error_Msg_Sloc
:= Sloc
(E
);
10792 Error_Msg_NE
("\import not allowed for& declared#", N
, E
);
10794 -- Here if not previously imported or exported, OK to import
10797 Set_Is_Imported
(E
);
10799 -- For subprogram, set Import_Pragma field
10801 if Is_Subprogram
(E
) then
10802 Set_Import_Pragma
(E
, N
);
10805 -- If the entity is an object that is not at the library level,
10806 -- then it is statically allocated. We do not worry about objects
10807 -- with address clauses in this context since they are not really
10808 -- imported in the linker sense.
10811 and then not Is_Library_Level_Entity
(E
)
10812 and then No
(Address_Clause
(E
))
10814 Set_Is_Statically_Allocated
(E
);
10821 -------------------------
10822 -- Set_Mechanism_Value --
10823 -------------------------
10825 -- Note: the mechanism name has not been analyzed (and cannot indeed be
10826 -- analyzed, since it is semantic nonsense), so we get it in the exact
10827 -- form created by the parser.
10829 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
) is
10830 procedure Bad_Mechanism
;
10831 pragma No_Return
(Bad_Mechanism
);
10832 -- Signal bad mechanism name
10834 -------------------
10835 -- Bad_Mechanism --
10836 -------------------
10838 procedure Bad_Mechanism
is
10840 Error_Pragma_Arg
("unrecognized mechanism name", Mech_Name
);
10843 -- Start of processing for Set_Mechanism_Value
10846 if Mechanism
(Ent
) /= Default_Mechanism
then
10848 ("mechanism for & has already been set", Mech_Name
, Ent
);
10851 -- MECHANISM_NAME ::= value | reference
10853 if Nkind
(Mech_Name
) = N_Identifier
then
10854 if Chars
(Mech_Name
) = Name_Value
then
10855 Set_Mechanism
(Ent
, By_Copy
);
10858 elsif Chars
(Mech_Name
) = Name_Reference
then
10859 Set_Mechanism
(Ent
, By_Reference
);
10862 elsif Chars
(Mech_Name
) = Name_Copy
then
10864 ("bad mechanism name, Value assumed", Mech_Name
);
10873 end Set_Mechanism_Value
;
10875 --------------------------
10876 -- Set_Rational_Profile --
10877 --------------------------
10879 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
10880 -- extension to the semantics of renaming declarations.
10882 procedure Set_Rational_Profile
is
10884 Implicit_Packing
:= True;
10885 Overriding_Renamings
:= True;
10886 Use_VADS_Size
:= True;
10887 end Set_Rational_Profile
;
10889 ---------------------------
10890 -- Set_Ravenscar_Profile --
10891 ---------------------------
10893 -- The tasks to be done here are
10895 -- Set required policies
10897 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10898 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
10899 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10900 -- (For GNAT_Ravenscar_EDF profile)
10901 -- pragma Locking_Policy (Ceiling_Locking)
10903 -- Set Detect_Blocking mode
10905 -- Set required restrictions (see System.Rident for detailed list)
10907 -- Set the No_Dependence rules
10908 -- No_Dependence => Ada.Asynchronous_Task_Control
10909 -- No_Dependence => Ada.Calendar
10910 -- No_Dependence => Ada.Execution_Time.Group_Budget
10911 -- No_Dependence => Ada.Execution_Time.Timers
10912 -- No_Dependence => Ada.Task_Attributes
10913 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10915 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
) is
10916 procedure Set_Error_Msg_To_Profile_Name
;
10917 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
10920 -----------------------------------
10921 -- Set_Error_Msg_To_Profile_Name --
10922 -----------------------------------
10924 procedure Set_Error_Msg_To_Profile_Name
is
10925 Prof_Nam
: constant Node_Id
:=
10927 (First
(Pragma_Argument_Associations
(N
)));
10930 Get_Name_String
(Chars
(Prof_Nam
));
10931 Adjust_Name_Case
(Global_Name_Buffer
, Sloc
(Prof_Nam
));
10932 Error_Msg_Strlen
:= Name_Len
;
10933 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
10934 end Set_Error_Msg_To_Profile_Name
;
10943 Profile_Dispatching_Policy
: Character;
10945 -- Start of processing for Set_Ravenscar_Profile
10948 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10950 if Profile
= GNAT_Ravenscar_EDF
then
10951 Profile_Dispatching_Policy
:= 'E';
10953 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10956 Profile_Dispatching_Policy
:= 'F';
10959 if Task_Dispatching_Policy
/= ' '
10960 and then Task_Dispatching_Policy
/= Profile_Dispatching_Policy
10962 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
10963 Set_Error_Msg_To_Profile_Name
;
10964 Error_Pragma
("Profile (~) incompatible with policy#");
10966 -- Set the FIFO_Within_Priorities policy, but always preserve
10967 -- System_Location since we like the error message with the run time
10971 Task_Dispatching_Policy
:= Profile_Dispatching_Policy
;
10973 if Task_Dispatching_Policy_Sloc
/= System_Location
then
10974 Task_Dispatching_Policy_Sloc
:= Loc
;
10978 -- pragma Locking_Policy (Ceiling_Locking)
10980 if Locking_Policy
/= ' '
10981 and then Locking_Policy
/= 'C'
10983 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
10984 Set_Error_Msg_To_Profile_Name
;
10985 Error_Pragma
("Profile (~) incompatible with policy#");
10987 -- Set the Ceiling_Locking policy, but preserve System_Location since
10988 -- we like the error message with the run time name.
10991 Locking_Policy
:= 'C';
10993 if Locking_Policy_Sloc
/= System_Location
then
10994 Locking_Policy_Sloc
:= Loc
;
10998 -- pragma Detect_Blocking
11000 Detect_Blocking
:= True;
11002 -- Set the corresponding restrictions
11004 Set_Profile_Restrictions
11005 (Profile
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
11007 -- Set the No_Dependence restrictions
11009 -- The following No_Dependence restrictions:
11010 -- No_Dependence => Ada.Asynchronous_Task_Control
11011 -- No_Dependence => Ada.Calendar
11012 -- No_Dependence => Ada.Task_Attributes
11013 -- are already set by previous call to Set_Profile_Restrictions.
11015 -- Set the following restrictions which were added to Ada 2005:
11016 -- No_Dependence => Ada.Execution_Time.Group_Budget
11017 -- No_Dependence => Ada.Execution_Time.Timers
11019 if Ada_Version
>= Ada_2005
then
11020 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
("ada"));
11021 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("execution_time"));
11024 Make_Selected_Component
11027 Selector_Name
=> Sel_Id
);
11029 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("group_budgets"));
11032 Make_Selected_Component
11035 Selector_Name
=> Sel_Id
);
11037 Set_Restriction_No_Dependence
11039 Warn
=> Treat_Restrictions_As_Warnings
,
11040 Profile
=> Ravenscar
);
11042 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("timers"));
11045 Make_Selected_Component
11048 Selector_Name
=> Sel_Id
);
11050 Set_Restriction_No_Dependence
11052 Warn
=> Treat_Restrictions_As_Warnings
,
11053 Profile
=> Ravenscar
);
11056 -- Set the following restriction which was added to Ada 2012 (see
11058 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11060 if Ada_Version
>= Ada_2012
then
11061 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
("system"));
11062 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("multiprocessors"));
11065 Make_Selected_Component
11068 Selector_Name
=> Sel_Id
);
11070 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("dispatching_domains"));
11073 Make_Selected_Component
11076 Selector_Name
=> Sel_Id
);
11078 Set_Restriction_No_Dependence
11080 Warn
=> Treat_Restrictions_As_Warnings
,
11081 Profile
=> Ravenscar
);
11083 end Set_Ravenscar_Profile
;
11085 -- Start of processing for Analyze_Pragma
11088 -- The following code is a defense against recursion. Not clear that
11089 -- this can happen legitimately, but perhaps some error situations can
11090 -- cause it, and we did see this recursion during testing.
11092 if Analyzed
(N
) then
11098 Check_Restriction_No_Use_Of_Pragma
(N
);
11100 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11101 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11103 if Should_Ignore_Pragma_Sem
(N
)
11104 or else (Prag_Id
= Pragma_Default_Scalar_Storage_Order
11105 and then Ignore_Rep_Clauses
)
11110 -- Deal with unrecognized pragma
11112 if not Is_Pragma_Name
(Pname
) then
11113 if Warn_On_Unrecognized_Pragma
then
11114 Error_Msg_Name_1
:= Pname
;
11115 Error_Msg_N
("?g?unrecognized pragma%!", Pragma_Identifier
(N
));
11117 for PN
in First_Pragma_Name
.. Last_Pragma_Name
loop
11118 if Is_Bad_Spelling_Of
(Pname
, PN
) then
11119 Error_Msg_Name_1
:= PN
;
11120 Error_Msg_N
-- CODEFIX
11121 ("\?g?possible misspelling of %!", Pragma_Identifier
(N
));
11130 -- Here to start processing for recognized pragma
11132 Pname
:= Original_Aspect_Pragma_Name
(N
);
11134 -- Capture setting of Opt.Uneval_Old
11136 case Opt
.Uneval_Old
is
11138 Set_Uneval_Old_Accept
(N
);
11144 Set_Uneval_Old_Warn
(N
);
11147 raise Program_Error
;
11150 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11151 -- is already set, indicating that we have already checked the policy
11152 -- at the right point. This happens for example in the case of a pragma
11153 -- that is derived from an Aspect.
11155 if Is_Ignored
(N
) or else Is_Checked
(N
) then
11158 -- For a pragma that is a rewriting of another pragma, copy the
11159 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11161 elsif Is_Rewrite_Substitution
(N
)
11162 and then Nkind
(Original_Node
(N
)) = N_Pragma
11164 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
11165 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
11167 -- Otherwise query the applicable policy at this point
11170 Check_Applicable_Policy
(N
);
11172 -- If pragma is disabled, rewrite as NULL and skip analysis
11174 if Is_Disabled
(N
) then
11175 Rewrite
(N
, Make_Null_Statement
(Loc
));
11181 -- Preset arguments
11189 if Present
(Pragma_Argument_Associations
(N
)) then
11190 Arg_Count
:= List_Length
(Pragma_Argument_Associations
(N
));
11191 Arg1
:= First
(Pragma_Argument_Associations
(N
));
11193 if Present
(Arg1
) then
11194 Arg2
:= Next
(Arg1
);
11196 if Present
(Arg2
) then
11197 Arg3
:= Next
(Arg2
);
11199 if Present
(Arg3
) then
11200 Arg4
:= Next
(Arg3
);
11206 -- An enumeration type defines the pragmas that are supported by the
11207 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11208 -- into the corresponding enumeration value for the following case.
11216 -- pragma Abort_Defer;
11218 when Pragma_Abort_Defer
=>
11220 Check_Arg_Count
(0);
11222 -- The only required semantic processing is to check the
11223 -- placement. This pragma must appear at the start of the
11224 -- statement sequence of a handled sequence of statements.
11226 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
11227 or else N
/= First
(Statements
(Parent
(N
)))
11232 --------------------
11233 -- Abstract_State --
11234 --------------------
11236 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11238 -- ABSTRACT_STATE_LIST ::=
11240 -- | STATE_NAME_WITH_OPTIONS
11241 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11243 -- STATE_NAME_WITH_OPTIONS ::=
11245 -- | (STATE_NAME with OPTION_LIST)
11247 -- OPTION_LIST ::= OPTION {, OPTION}
11251 -- | NAME_VALUE_OPTION
11253 -- SIMPLE_OPTION ::= Ghost | Synchronous
11255 -- NAME_VALUE_OPTION ::=
11256 -- Part_Of => ABSTRACT_STATE
11257 -- | External [=> EXTERNAL_PROPERTY_LIST]
11259 -- EXTERNAL_PROPERTY_LIST ::=
11260 -- EXTERNAL_PROPERTY
11261 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11263 -- EXTERNAL_PROPERTY ::=
11264 -- Async_Readers [=> boolean_EXPRESSION]
11265 -- | Async_Writers [=> boolean_EXPRESSION]
11266 -- | Effective_Reads [=> boolean_EXPRESSION]
11267 -- | Effective_Writes [=> boolean_EXPRESSION]
11268 -- others => boolean_EXPRESSION
11270 -- STATE_NAME ::= defining_identifier
11272 -- ABSTRACT_STATE ::= name
11274 -- Characteristics:
11276 -- * Analysis - The annotation is fully analyzed immediately upon
11277 -- elaboration as it cannot forward reference entities.
11279 -- * Expansion - None.
11281 -- * Template - The annotation utilizes the generic template of the
11282 -- related package declaration.
11284 -- * Globals - The annotation cannot reference global entities.
11286 -- * Instance - The annotation is instantiated automatically when
11287 -- the related generic package is instantiated.
11289 when Pragma_Abstract_State
=> Abstract_State
: declare
11290 Missing_Parentheses
: Boolean := False;
11291 -- Flag set when a state declaration with options is not properly
11294 -- Flags used to verify the consistency of states
11296 Non_Null_Seen
: Boolean := False;
11297 Null_Seen
: Boolean := False;
11299 procedure Analyze_Abstract_State
11301 Pack_Id
: Entity_Id
);
11302 -- Verify the legality of a single state declaration. Create and
11303 -- decorate a state abstraction entity and introduce it into the
11304 -- visibility chain. Pack_Id denotes the entity or the related
11305 -- package where pragma Abstract_State appears.
11307 procedure Malformed_State_Error
(State
: Node_Id
);
11308 -- Emit an error concerning the illegal declaration of abstract
11309 -- state State. This routine diagnoses syntax errors that lead to
11310 -- a different parse tree. The error is issued regardless of the
11311 -- SPARK mode in effect.
11313 ----------------------------
11314 -- Analyze_Abstract_State --
11315 ----------------------------
11317 procedure Analyze_Abstract_State
11319 Pack_Id
: Entity_Id
)
11321 -- Flags used to verify the consistency of options
11323 AR_Seen
: Boolean := False;
11324 AW_Seen
: Boolean := False;
11325 ER_Seen
: Boolean := False;
11326 EW_Seen
: Boolean := False;
11327 External_Seen
: Boolean := False;
11328 Ghost_Seen
: Boolean := False;
11329 Others_Seen
: Boolean := False;
11330 Part_Of_Seen
: Boolean := False;
11331 Synchronous_Seen
: Boolean := False;
11333 -- Flags used to store the static value of all external states'
11336 AR_Val
: Boolean := False;
11337 AW_Val
: Boolean := False;
11338 ER_Val
: Boolean := False;
11339 EW_Val
: Boolean := False;
11341 State_Id
: Entity_Id
:= Empty
;
11342 -- The entity to be generated for the current state declaration
11344 procedure Analyze_External_Option
(Opt
: Node_Id
);
11345 -- Verify the legality of option External
11347 procedure Analyze_External_Property
11349 Expr
: Node_Id
:= Empty
);
11350 -- Verify the legailty of a single external property. Prop
11351 -- denotes the external property. Expr is the expression used
11352 -- to set the property.
11354 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
);
11355 -- Verify the legality of option Part_Of
11357 procedure Check_Duplicate_Option
11359 Status
: in out Boolean);
11360 -- Flag Status denotes whether a particular option has been
11361 -- seen while processing a state. This routine verifies that
11362 -- Opt is not a duplicate option and sets the flag Status
11363 -- (SPARK RM 7.1.4(1)).
11365 procedure Check_Duplicate_Property
11367 Status
: in out Boolean);
11368 -- Flag Status denotes whether a particular property has been
11369 -- seen while processing option External. This routine verifies
11370 -- that Prop is not a duplicate property and sets flag Status.
11371 -- Opt is not a duplicate property and sets the flag Status.
11372 -- (SPARK RM 7.1.4(2))
11374 procedure Check_Ghost_Synchronous
;
11375 -- Ensure that the abstract state is not subject to both Ghost
11376 -- and Synchronous simple options. Emit an error if this is the
11379 procedure Create_Abstract_State
11383 Is_Null
: Boolean);
11384 -- Generate an abstract state entity with name Nam and enter it
11385 -- into visibility. Decl is the "declaration" of the state as
11386 -- it appears in pragma Abstract_State. Loc is the location of
11387 -- the related state "declaration". Flag Is_Null should be set
11388 -- when the associated Abstract_State pragma defines a null
11391 -----------------------------
11392 -- Analyze_External_Option --
11393 -----------------------------
11395 procedure Analyze_External_Option
(Opt
: Node_Id
) is
11396 Errors
: constant Nat
:= Serious_Errors_Detected
;
11398 Props
: Node_Id
:= Empty
;
11401 if Nkind
(Opt
) = N_Component_Association
then
11402 Props
:= Expression
(Opt
);
11405 -- External state with properties
11407 if Present
(Props
) then
11409 -- Multiple properties appear as an aggregate
11411 if Nkind
(Props
) = N_Aggregate
then
11413 -- Simple property form
11415 Prop
:= First
(Expressions
(Props
));
11416 while Present
(Prop
) loop
11417 Analyze_External_Property
(Prop
);
11421 -- Property with expression form
11423 Prop
:= First
(Component_Associations
(Props
));
11424 while Present
(Prop
) loop
11425 Analyze_External_Property
11426 (Prop
=> First
(Choices
(Prop
)),
11427 Expr
=> Expression
(Prop
));
11435 Analyze_External_Property
(Props
);
11438 -- An external state defined without any properties defaults
11439 -- all properties to True.
11448 -- Once all external properties have been processed, verify
11449 -- their mutual interaction. Do not perform the check when
11450 -- at least one of the properties is illegal as this will
11451 -- produce a bogus error.
11453 if Errors
= Serious_Errors_Detected
then
11454 Check_External_Properties
11455 (State
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
11457 end Analyze_External_Option
;
11459 -------------------------------
11460 -- Analyze_External_Property --
11461 -------------------------------
11463 procedure Analyze_External_Property
11465 Expr
: Node_Id
:= Empty
)
11467 Expr_Val
: Boolean;
11470 -- Check the placement of "others" (if available)
11472 if Nkind
(Prop
) = N_Others_Choice
then
11473 if Others_Seen
then
11475 ("only one others choice allowed in option External",
11478 Others_Seen
:= True;
11481 elsif Others_Seen
then
11483 ("others must be the last property in option External",
11486 -- The only remaining legal options are the four predefined
11487 -- external properties.
11489 elsif Nkind
(Prop
) = N_Identifier
11490 and then Nam_In
(Chars
(Prop
), Name_Async_Readers
,
11491 Name_Async_Writers
,
11492 Name_Effective_Reads
,
11493 Name_Effective_Writes
)
11497 -- Otherwise the construct is not a valid property
11500 SPARK_Msg_N
("invalid external state property", Prop
);
11504 -- Ensure that the expression of the external state property
11505 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11507 if Present
(Expr
) then
11508 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
11510 if Is_OK_Static_Expression
(Expr
) then
11511 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
11514 ("expression of external state property must be "
11519 -- The lack of expression defaults the property to True
11525 -- Named properties
11527 if Nkind
(Prop
) = N_Identifier
then
11528 if Chars
(Prop
) = Name_Async_Readers
then
11529 Check_Duplicate_Property
(Prop
, AR_Seen
);
11530 AR_Val
:= Expr_Val
;
11532 elsif Chars
(Prop
) = Name_Async_Writers
then
11533 Check_Duplicate_Property
(Prop
, AW_Seen
);
11534 AW_Val
:= Expr_Val
;
11536 elsif Chars
(Prop
) = Name_Effective_Reads
then
11537 Check_Duplicate_Property
(Prop
, ER_Seen
);
11538 ER_Val
:= Expr_Val
;
11541 Check_Duplicate_Property
(Prop
, EW_Seen
);
11542 EW_Val
:= Expr_Val
;
11545 -- The handling of property "others" must take into account
11546 -- all other named properties that have been encountered so
11547 -- far. Only those that have not been seen are affected by
11551 if not AR_Seen
then
11552 AR_Val
:= Expr_Val
;
11555 if not AW_Seen
then
11556 AW_Val
:= Expr_Val
;
11559 if not ER_Seen
then
11560 ER_Val
:= Expr_Val
;
11563 if not EW_Seen
then
11564 EW_Val
:= Expr_Val
;
11567 end Analyze_External_Property
;
11569 ----------------------------
11570 -- Analyze_Part_Of_Option --
11571 ----------------------------
11573 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
) is
11574 Encap
: constant Node_Id
:= Expression
(Opt
);
11575 Constits
: Elist_Id
;
11576 Encap_Id
: Entity_Id
;
11580 Check_Duplicate_Option
(Opt
, Part_Of_Seen
);
11583 (Indic
=> First
(Choices
(Opt
)),
11584 Item_Id
=> State_Id
,
11586 Encap_Id
=> Encap_Id
,
11589 -- The Part_Of indicator transforms the abstract state into
11590 -- a constituent of the encapsulating state or single
11591 -- concurrent type.
11594 pragma Assert
(Present
(Encap_Id
));
11595 Constits
:= Part_Of_Constituents
(Encap_Id
);
11597 if No
(Constits
) then
11598 Constits
:= New_Elmt_List
;
11599 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
11602 Append_Elmt
(State_Id
, Constits
);
11603 Set_Encapsulating_State
(State_Id
, Encap_Id
);
11605 end Analyze_Part_Of_Option
;
11607 ----------------------------
11608 -- Check_Duplicate_Option --
11609 ----------------------------
11611 procedure Check_Duplicate_Option
11613 Status
: in out Boolean)
11617 SPARK_Msg_N
("duplicate state option", Opt
);
11621 end Check_Duplicate_Option
;
11623 ------------------------------
11624 -- Check_Duplicate_Property --
11625 ------------------------------
11627 procedure Check_Duplicate_Property
11629 Status
: in out Boolean)
11633 SPARK_Msg_N
("duplicate external property", Prop
);
11637 end Check_Duplicate_Property
;
11639 -----------------------------
11640 -- Check_Ghost_Synchronous --
11641 -----------------------------
11643 procedure Check_Ghost_Synchronous
is
11645 -- A synchronized abstract state cannot be Ghost and vice
11646 -- versa (SPARK RM 6.9(19)).
11648 if Ghost_Seen
and Synchronous_Seen
then
11649 SPARK_Msg_N
("synchronized state cannot be ghost", State
);
11651 end Check_Ghost_Synchronous
;
11653 ---------------------------
11654 -- Create_Abstract_State --
11655 ---------------------------
11657 procedure Create_Abstract_State
11664 -- The abstract state may be semi-declared when the related
11665 -- package was withed through a limited with clause. In that
11666 -- case reuse the entity to fully declare the state.
11668 if Present
(Decl
) and then Present
(Entity
(Decl
)) then
11669 State_Id
:= Entity
(Decl
);
11671 -- Otherwise the elaboration of pragma Abstract_State
11672 -- declares the state.
11675 State_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
11677 if Present
(Decl
) then
11678 Set_Entity
(Decl
, State_Id
);
11682 -- Null states never come from source
11684 Set_Comes_From_Source
(State_Id
, not Is_Null
);
11685 Set_Parent
(State_Id
, State
);
11686 Set_Ekind
(State_Id
, E_Abstract_State
);
11687 Set_Etype
(State_Id
, Standard_Void_Type
);
11688 Set_Encapsulating_State
(State_Id
, Empty
);
11690 -- Set the SPARK mode from the current context
11692 Set_SPARK_Pragma
(State_Id
, SPARK_Mode_Pragma
);
11693 Set_SPARK_Pragma_Inherited
(State_Id
);
11695 -- An abstract state declared within a Ghost region becomes
11696 -- Ghost (SPARK RM 6.9(2)).
11698 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Pack_Id
) then
11699 Set_Is_Ghost_Entity
(State_Id
);
11702 -- Establish a link between the state declaration and the
11703 -- abstract state entity. Note that a null state remains as
11704 -- N_Null and does not carry any linkages.
11706 if not Is_Null
then
11707 if Present
(Decl
) then
11708 Set_Entity
(Decl
, State_Id
);
11709 Set_Etype
(Decl
, Standard_Void_Type
);
11712 -- Every non-null state must be defined, nameable and
11715 Push_Scope
(Pack_Id
);
11716 Generate_Definition
(State_Id
);
11717 Enter_Name
(State_Id
);
11720 end Create_Abstract_State
;
11727 -- Start of processing for Analyze_Abstract_State
11730 -- A package with a null abstract state is not allowed to
11731 -- declare additional states.
11735 ("package & has null abstract state", State
, Pack_Id
);
11737 -- Null states appear as internally generated entities
11739 elsif Nkind
(State
) = N_Null
then
11740 Create_Abstract_State
11741 (Nam
=> New_Internal_Name
('S'),
11743 Loc
=> Sloc
(State
),
11747 -- Catch a case where a null state appears in a list of
11748 -- non-null states.
11750 if Non_Null_Seen
then
11752 ("package & has non-null abstract state",
11756 -- Simple state declaration
11758 elsif Nkind
(State
) = N_Identifier
then
11759 Create_Abstract_State
11760 (Nam
=> Chars
(State
),
11762 Loc
=> Sloc
(State
),
11764 Non_Null_Seen
:= True;
11766 -- State declaration with various options. This construct
11767 -- appears as an extension aggregate in the tree.
11769 elsif Nkind
(State
) = N_Extension_Aggregate
then
11770 if Nkind
(Ancestor_Part
(State
)) = N_Identifier
then
11771 Create_Abstract_State
11772 (Nam
=> Chars
(Ancestor_Part
(State
)),
11773 Decl
=> Ancestor_Part
(State
),
11774 Loc
=> Sloc
(Ancestor_Part
(State
)),
11776 Non_Null_Seen
:= True;
11779 ("state name must be an identifier",
11780 Ancestor_Part
(State
));
11783 -- Options External, Ghost and Synchronous appear as
11786 Opt
:= First
(Expressions
(State
));
11787 while Present
(Opt
) loop
11788 if Nkind
(Opt
) = N_Identifier
then
11792 if Chars
(Opt
) = Name_External
then
11793 Check_Duplicate_Option
(Opt
, External_Seen
);
11794 Analyze_External_Option
(Opt
);
11798 elsif Chars
(Opt
) = Name_Ghost
then
11799 Check_Duplicate_Option
(Opt
, Ghost_Seen
);
11800 Check_Ghost_Synchronous
;
11802 if Present
(State_Id
) then
11803 Set_Is_Ghost_Entity
(State_Id
);
11808 elsif Chars
(Opt
) = Name_Synchronous
then
11809 Check_Duplicate_Option
(Opt
, Synchronous_Seen
);
11810 Check_Ghost_Synchronous
;
11812 -- Option Part_Of without an encapsulating state is
11813 -- illegal (SPARK RM 7.1.4(9)).
11815 elsif Chars
(Opt
) = Name_Part_Of
then
11817 ("indicator Part_Of must denote abstract state, "
11818 & "single protected type or single task type",
11821 -- Do not emit an error message when a previous state
11822 -- declaration with options was not parenthesized as
11823 -- the option is actually another state declaration.
11825 -- with Abstract_State
11826 -- (State_1 with ..., -- missing parentheses
11827 -- (State_2 with ...),
11828 -- State_3) -- ok state declaration
11830 elsif Missing_Parentheses
then
11833 -- Otherwise the option is not allowed. Note that it
11834 -- is not possible to distinguish between an option
11835 -- and a state declaration when a previous state with
11836 -- options not properly parentheses.
11838 -- with Abstract_State
11839 -- (State_1 with ..., -- missing parentheses
11840 -- State_2); -- could be an option
11844 ("simple option not allowed in state declaration",
11848 -- Catch a case where missing parentheses around a state
11849 -- declaration with options cause a subsequent state
11850 -- declaration with options to be treated as an option.
11852 -- with Abstract_State
11853 -- (State_1 with ..., -- missing parentheses
11854 -- (State_2 with ...))
11856 elsif Nkind
(Opt
) = N_Extension_Aggregate
then
11857 Missing_Parentheses
:= True;
11859 ("state declaration must be parenthesized",
11860 Ancestor_Part
(State
));
11862 -- Otherwise the option is malformed
11865 SPARK_Msg_N
("malformed option", Opt
);
11871 -- Options External and Part_Of appear as component
11874 Opt
:= First
(Component_Associations
(State
));
11875 while Present
(Opt
) loop
11876 Opt_Nam
:= First
(Choices
(Opt
));
11878 if Nkind
(Opt_Nam
) = N_Identifier
then
11879 if Chars
(Opt_Nam
) = Name_External
then
11880 Analyze_External_Option
(Opt
);
11882 elsif Chars
(Opt_Nam
) = Name_Part_Of
then
11883 Analyze_Part_Of_Option
(Opt
);
11886 SPARK_Msg_N
("invalid state option", Opt
);
11889 SPARK_Msg_N
("invalid state option", Opt
);
11895 -- Any other attempt to declare a state is illegal
11898 Malformed_State_Error
(State
);
11902 -- Guard against a junk state. In such cases no entity is
11903 -- generated and the subsequent checks cannot be applied.
11905 if Present
(State_Id
) then
11907 -- Verify whether the state does not introduce an illegal
11908 -- hidden state within a package subject to a null abstract
11911 Check_No_Hidden_State
(State_Id
);
11913 -- Check whether the lack of option Part_Of agrees with the
11914 -- placement of the abstract state with respect to the state
11917 if not Part_Of_Seen
then
11918 Check_Missing_Part_Of
(State_Id
);
11921 -- Associate the state with its related package
11923 if No
(Abstract_States
(Pack_Id
)) then
11924 Set_Abstract_States
(Pack_Id
, New_Elmt_List
);
11927 Append_Elmt
(State_Id
, Abstract_States
(Pack_Id
));
11929 end Analyze_Abstract_State
;
11931 ---------------------------
11932 -- Malformed_State_Error --
11933 ---------------------------
11935 procedure Malformed_State_Error
(State
: Node_Id
) is
11937 Error_Msg_N
("malformed abstract state declaration", State
);
11939 -- An abstract state with a simple option is being declared
11940 -- with "=>" rather than the legal "with". The state appears
11941 -- as a component association.
11943 if Nkind
(State
) = N_Component_Association
then
11944 Error_Msg_N
("\use WITH to specify simple option", State
);
11946 end Malformed_State_Error
;
11950 Pack_Decl
: Node_Id
;
11951 Pack_Id
: Entity_Id
;
11955 -- Start of processing for Abstract_State
11959 Check_No_Identifiers
;
11960 Check_Arg_Count
(1);
11962 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
11964 if not Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
11965 N_Package_Declaration
)
11971 Pack_Id
:= Defining_Entity
(Pack_Decl
);
11973 -- A pragma that applies to a Ghost entity becomes Ghost for the
11974 -- purposes of legality checks and removal of ignored Ghost code.
11976 Mark_Ghost_Pragma
(N
, Pack_Id
);
11977 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
11979 -- Chain the pragma on the contract for completeness
11981 Add_Contract_Item
(N
, Pack_Id
);
11983 -- The legality checks of pragmas Abstract_State, Initializes, and
11984 -- Initial_Condition are affected by the SPARK mode in effect. In
11985 -- addition, these three pragmas are subject to an inherent order:
11987 -- 1) Abstract_State
11989 -- 3) Initial_Condition
11991 -- Analyze all these pragmas in the order outlined above
11993 Analyze_If_Present
(Pragma_SPARK_Mode
);
11994 States
:= Expression
(Get_Argument
(N
, Pack_Id
));
11996 -- Multiple non-null abstract states appear as an aggregate
11998 if Nkind
(States
) = N_Aggregate
then
11999 State
:= First
(Expressions
(States
));
12000 while Present
(State
) loop
12001 Analyze_Abstract_State
(State
, Pack_Id
);
12005 -- An abstract state with a simple option is being illegaly
12006 -- declared with "=>" rather than "with". In this case the
12007 -- state declaration appears as a component association.
12009 if Present
(Component_Associations
(States
)) then
12010 State
:= First
(Component_Associations
(States
));
12011 while Present
(State
) loop
12012 Malformed_State_Error
(State
);
12017 -- Various forms of a single abstract state. Note that these may
12018 -- include malformed state declarations.
12021 Analyze_Abstract_State
(States
, Pack_Id
);
12024 Analyze_If_Present
(Pragma_Initializes
);
12025 Analyze_If_Present
(Pragma_Initial_Condition
);
12026 end Abstract_State
;
12034 -- Note: this pragma also has some specific processing in Par.Prag
12035 -- because we want to set the Ada version mode during parsing.
12037 when Pragma_Ada_83
=>
12039 Check_Arg_Count
(0);
12041 -- We really should check unconditionally for proper configuration
12042 -- pragma placement, since we really don't want mixed Ada modes
12043 -- within a single unit, and the GNAT reference manual has always
12044 -- said this was a configuration pragma, but we did not check and
12045 -- are hesitant to add the check now.
12047 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12048 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12049 -- or Ada 2012 mode.
12051 if Ada_Version
>= Ada_2005
then
12052 Check_Valid_Configuration_Pragma
;
12055 -- Now set Ada 83 mode
12057 if Latest_Ada_Only
then
12058 Error_Pragma
("??pragma% ignored");
12060 Ada_Version
:= Ada_83
;
12061 Ada_Version_Explicit
:= Ada_83
;
12062 Ada_Version_Pragma
:= N
;
12071 -- Note: this pragma also has some specific processing in Par.Prag
12072 -- because we want to set the Ada 83 version mode during parsing.
12074 when Pragma_Ada_95
=>
12076 Check_Arg_Count
(0);
12078 -- We really should check unconditionally for proper configuration
12079 -- pragma placement, since we really don't want mixed Ada modes
12080 -- within a single unit, and the GNAT reference manual has always
12081 -- said this was a configuration pragma, but we did not check and
12082 -- are hesitant to add the check now.
12084 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12085 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12087 if Ada_Version
>= Ada_2005
then
12088 Check_Valid_Configuration_Pragma
;
12091 -- Now set Ada 95 mode
12093 if Latest_Ada_Only
then
12094 Error_Pragma
("??pragma% ignored");
12096 Ada_Version
:= Ada_95
;
12097 Ada_Version_Explicit
:= Ada_95
;
12098 Ada_Version_Pragma
:= N
;
12101 ---------------------
12102 -- Ada_05/Ada_2005 --
12103 ---------------------
12106 -- pragma Ada_05 (LOCAL_NAME);
12108 -- pragma Ada_2005;
12109 -- pragma Ada_2005 (LOCAL_NAME):
12111 -- Note: these pragmas also have some specific processing in Par.Prag
12112 -- because we want to set the Ada 2005 version mode during parsing.
12114 -- The one argument form is used for managing the transition from
12115 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12116 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12117 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12118 -- mode, a preference rule is established which does not choose
12119 -- such an entity unless it is unambiguously specified. This avoids
12120 -- extra subprograms marked this way from generating ambiguities in
12121 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12122 -- intended for exclusive use in the GNAT run-time library.
12133 if Arg_Count
= 1 then
12134 Check_Arg_Is_Local_Name
(Arg1
);
12135 E_Id
:= Get_Pragma_Arg
(Arg1
);
12137 if Etype
(E_Id
) = Any_Type
then
12141 Set_Is_Ada_2005_Only
(Entity
(E_Id
));
12142 Record_Rep_Item
(Entity
(E_Id
), N
);
12145 Check_Arg_Count
(0);
12147 -- For Ada_2005 we unconditionally enforce the documented
12148 -- configuration pragma placement, since we do not want to
12149 -- tolerate mixed modes in a unit involving Ada 2005. That
12150 -- would cause real difficulties for those cases where there
12151 -- are incompatibilities between Ada 95 and Ada 2005.
12153 Check_Valid_Configuration_Pragma
;
12155 -- Now set appropriate Ada mode
12157 if Latest_Ada_Only
then
12158 Error_Pragma
("??pragma% ignored");
12160 Ada_Version
:= Ada_2005
;
12161 Ada_Version_Explicit
:= Ada_2005
;
12162 Ada_Version_Pragma
:= N
;
12167 ---------------------
12168 -- Ada_12/Ada_2012 --
12169 ---------------------
12172 -- pragma Ada_12 (LOCAL_NAME);
12174 -- pragma Ada_2012;
12175 -- pragma Ada_2012 (LOCAL_NAME):
12177 -- Note: these pragmas also have some specific processing in Par.Prag
12178 -- because we want to set the Ada 2012 version mode during parsing.
12180 -- The one argument form is used for managing the transition from Ada
12181 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12182 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12183 -- mode will generate a warning. In addition, in any pre-Ada_2012
12184 -- mode, a preference rule is established which does not choose
12185 -- such an entity unless it is unambiguously specified. This avoids
12186 -- extra subprograms marked this way from generating ambiguities in
12187 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12188 -- intended for exclusive use in the GNAT run-time library.
12199 if Arg_Count
= 1 then
12200 Check_Arg_Is_Local_Name
(Arg1
);
12201 E_Id
:= Get_Pragma_Arg
(Arg1
);
12203 if Etype
(E_Id
) = Any_Type
then
12207 Set_Is_Ada_2012_Only
(Entity
(E_Id
));
12208 Record_Rep_Item
(Entity
(E_Id
), N
);
12211 Check_Arg_Count
(0);
12213 -- For Ada_2012 we unconditionally enforce the documented
12214 -- configuration pragma placement, since we do not want to
12215 -- tolerate mixed modes in a unit involving Ada 2012. That
12216 -- would cause real difficulties for those cases where there
12217 -- are incompatibilities between Ada 95 and Ada 2012. We could
12218 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12220 Check_Valid_Configuration_Pragma
;
12222 -- Now set appropriate Ada mode
12224 Ada_Version
:= Ada_2012
;
12225 Ada_Version_Explicit
:= Ada_2012
;
12226 Ada_Version_Pragma
:= N
;
12234 -- pragma Ada_2020;
12236 -- Note: this pragma also has some specific processing in Par.Prag
12237 -- because we want to set the Ada 2020 version mode during parsing.
12239 when Pragma_Ada_2020
=>
12242 Check_Arg_Count
(0);
12244 Check_Valid_Configuration_Pragma
;
12246 -- Now set appropriate Ada mode
12248 Ada_Version
:= Ada_2020
;
12249 Ada_Version_Explicit
:= Ada_2020
;
12250 Ada_Version_Pragma
:= N
;
12252 ----------------------
12253 -- All_Calls_Remote --
12254 ----------------------
12256 -- pragma All_Calls_Remote [(library_package_NAME)];
12258 when Pragma_All_Calls_Remote
=> All_Calls_Remote
: declare
12259 Lib_Entity
: Entity_Id
;
12262 Check_Ada_83_Warning
;
12263 Check_Valid_Library_Unit_Pragma
;
12265 if Nkind
(N
) = N_Null_Statement
then
12269 Lib_Entity
:= Find_Lib_Unit_Name
;
12271 -- A pragma that applies to a Ghost entity becomes Ghost for the
12272 -- purposes of legality checks and removal of ignored Ghost code.
12274 Mark_Ghost_Pragma
(N
, Lib_Entity
);
12276 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12278 if Present
(Lib_Entity
) and then not Debug_Flag_U
then
12279 if not Is_Remote_Call_Interface
(Lib_Entity
) then
12280 Error_Pragma
("pragma% only apply to rci unit");
12282 -- Set flag for entity of the library unit
12285 Set_Has_All_Calls_Remote
(Lib_Entity
);
12288 end All_Calls_Remote
;
12290 ---------------------------
12291 -- Allow_Integer_Address --
12292 ---------------------------
12294 -- pragma Allow_Integer_Address;
12296 when Pragma_Allow_Integer_Address
=>
12298 Check_Valid_Configuration_Pragma
;
12299 Check_Arg_Count
(0);
12301 -- If Address is a private type, then set the flag to allow
12302 -- integer address values. If Address is not private, then this
12303 -- pragma has no purpose, so it is simply ignored. Not clear if
12304 -- there are any such targets now.
12306 if Opt
.Address_Is_Private
then
12307 Opt
.Allow_Integer_Address
:= True;
12315 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12316 -- ARG ::= NAME | EXPRESSION
12318 -- The first two arguments are by convention intended to refer to an
12319 -- external tool and a tool-specific function. These arguments are
12322 when Pragma_Annotate
=> Annotate
: declare
12329 Check_At_Least_N_Arguments
(1);
12331 Nam_Arg
:= Last
(Pragma_Argument_Associations
(N
));
12333 -- Determine whether the last argument is "Entity => local_NAME"
12334 -- and if it is, perform the required semantic checks. Remove the
12335 -- argument from further processing.
12337 if Nkind
(Nam_Arg
) = N_Pragma_Argument_Association
12338 and then Chars
(Nam_Arg
) = Name_Entity
12340 Check_Arg_Is_Local_Name
(Nam_Arg
);
12341 Arg_Count
:= Arg_Count
- 1;
12343 -- A pragma that applies to a Ghost entity becomes Ghost for
12344 -- the purposes of legality checks and removal of ignored Ghost
12347 if Is_Entity_Name
(Get_Pragma_Arg
(Nam_Arg
))
12348 and then Present
(Entity
(Get_Pragma_Arg
(Nam_Arg
)))
12350 Mark_Ghost_Pragma
(N
, Entity
(Get_Pragma_Arg
(Nam_Arg
)));
12353 -- Not allowed in compiler units (bootstrap issues)
12355 Check_Compiler_Unit
("Entity for pragma Annotate", N
);
12358 -- Continue the processing with last argument removed for now
12360 Check_Arg_Is_Identifier
(Arg1
);
12361 Check_No_Identifiers
;
12364 -- The second parameter is optional, it is never analyzed
12369 -- Otherwise there is a second parameter
12372 -- The second parameter must be an identifier
12374 Check_Arg_Is_Identifier
(Arg2
);
12376 -- Process the remaining parameters (if any)
12378 Arg
:= Next
(Arg2
);
12379 while Present
(Arg
) loop
12380 Expr
:= Get_Pragma_Arg
(Arg
);
12383 if Is_Entity_Name
(Expr
) then
12386 -- For string literals, we assume Standard_String as the
12387 -- type, unless the string contains wide or wide_wide
12390 elsif Nkind
(Expr
) = N_String_Literal
then
12391 if Has_Wide_Wide_Character
(Expr
) then
12392 Resolve
(Expr
, Standard_Wide_Wide_String
);
12393 elsif Has_Wide_Character
(Expr
) then
12394 Resolve
(Expr
, Standard_Wide_String
);
12396 Resolve
(Expr
, Standard_String
);
12399 elsif Is_Overloaded
(Expr
) then
12400 Error_Pragma_Arg
("ambiguous argument for pragma%", Expr
);
12411 -------------------------------------------------
12412 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12413 -------------------------------------------------
12416 -- ( [Check => ] Boolean_EXPRESSION
12417 -- [, [Message =>] Static_String_EXPRESSION]);
12419 -- pragma Assert_And_Cut
12420 -- ( [Check => ] Boolean_EXPRESSION
12421 -- [, [Message =>] Static_String_EXPRESSION]);
12424 -- ( [Check => ] Boolean_EXPRESSION
12425 -- [, [Message =>] Static_String_EXPRESSION]);
12427 -- pragma Loop_Invariant
12428 -- ( [Check => ] Boolean_EXPRESSION
12429 -- [, [Message =>] Static_String_EXPRESSION]);
12432 | Pragma_Assert_And_Cut
12434 | Pragma_Loop_Invariant
12437 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean;
12438 -- Determine whether expression Expr contains a Loop_Entry
12439 -- attribute reference.
12441 -------------------------
12442 -- Contains_Loop_Entry --
12443 -------------------------
12445 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean is
12446 Has_Loop_Entry
: Boolean := False;
12448 function Process
(N
: Node_Id
) return Traverse_Result
;
12449 -- Process function for traversal to look for Loop_Entry
12455 function Process
(N
: Node_Id
) return Traverse_Result
is
12457 if Nkind
(N
) = N_Attribute_Reference
12458 and then Attribute_Name
(N
) = Name_Loop_Entry
12460 Has_Loop_Entry
:= True;
12467 procedure Traverse
is new Traverse_Proc
(Process
);
12469 -- Start of processing for Contains_Loop_Entry
12473 return Has_Loop_Entry
;
12474 end Contains_Loop_Entry
;
12479 New_Args
: List_Id
;
12481 -- Start of processing for Assert
12484 -- Assert is an Ada 2005 RM-defined pragma
12486 if Prag_Id
= Pragma_Assert
then
12489 -- The remaining ones are GNAT pragmas
12495 Check_At_Least_N_Arguments
(1);
12496 Check_At_Most_N_Arguments
(2);
12497 Check_Arg_Order
((Name_Check
, Name_Message
));
12498 Check_Optional_Identifier
(Arg1
, Name_Check
);
12499 Expr
:= Get_Pragma_Arg
(Arg1
);
12501 -- Special processing for Loop_Invariant, Loop_Variant or for
12502 -- other cases where a Loop_Entry attribute is present. If the
12503 -- assertion pragma contains attribute Loop_Entry, ensure that
12504 -- the related pragma is within a loop.
12506 if Prag_Id
= Pragma_Loop_Invariant
12507 or else Prag_Id
= Pragma_Loop_Variant
12508 or else Contains_Loop_Entry
(Expr
)
12510 Check_Loop_Pragma_Placement
;
12512 -- Perform preanalysis to deal with embedded Loop_Entry
12515 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
12518 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12519 -- a corresponding Check pragma:
12521 -- pragma Check (name, condition [, msg]);
12523 -- Where name is the identifier matching the pragma name. So
12524 -- rewrite pragma in this manner, transfer the message argument
12525 -- if present, and analyze the result
12527 -- Note: When dealing with a semantically analyzed tree, the
12528 -- information that a Check node N corresponds to a source Assert,
12529 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12530 -- pragma kind of Original_Node(N).
12532 New_Args
:= New_List
(
12533 Make_Pragma_Argument_Association
(Loc
,
12534 Expression
=> Make_Identifier
(Loc
, Pname
)),
12535 Make_Pragma_Argument_Association
(Sloc
(Expr
),
12536 Expression
=> Expr
));
12538 if Arg_Count
> 1 then
12539 Check_Optional_Identifier
(Arg2
, Name_Message
);
12541 -- Provide semantic annnotations for optional argument, for
12542 -- ASIS use, before rewriting.
12544 Preanalyze_And_Resolve
(Expression
(Arg2
), Standard_String
);
12545 Append_To
(New_Args
, New_Copy_Tree
(Arg2
));
12548 -- Rewrite as Check pragma
12552 Chars
=> Name_Check
,
12553 Pragma_Argument_Associations
=> New_Args
));
12558 ----------------------
12559 -- Assertion_Policy --
12560 ----------------------
12562 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12564 -- The following form is Ada 2012 only, but we allow it in all modes
12566 -- Pragma Assertion_Policy (
12567 -- ASSERTION_KIND => POLICY_IDENTIFIER
12568 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12570 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12572 -- RM_ASSERTION_KIND ::= Assert |
12573 -- Static_Predicate |
12574 -- Dynamic_Predicate |
12579 -- Type_Invariant |
12580 -- Type_Invariant'Class
12582 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12584 -- Contract_Cases |
12586 -- Default_Initial_Condition |
12588 -- Initial_Condition |
12589 -- Loop_Invariant |
12595 -- Statement_Assertions
12597 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
12598 -- ID_ASSERTION_KIND list contains implementation-defined additions
12599 -- recognized by GNAT. The effect is to control the behavior of
12600 -- identically named aspects and pragmas, depending on the specified
12601 -- policy identifier:
12603 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12605 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12606 -- implementation-defined addition that results in totally ignoring
12607 -- the corresponding assertion. If Disable is specified, then the
12608 -- argument of the assertion is not even analyzed. This is useful
12609 -- when the aspect/pragma argument references entities in a with'ed
12610 -- package that is replaced by a dummy package in the final build.
12612 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12613 -- and Type_Invariant'Class were recognized by the parser and
12614 -- transformed into references to the special internal identifiers
12615 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12616 -- processing is required here.
12618 when Pragma_Assertion_Policy
=> Assertion_Policy
: declare
12619 procedure Resolve_Suppressible
(Policy
: Node_Id
);
12620 -- Converts the assertion policy 'Suppressible' to either Check or
12621 -- Ignore based on whether checks are suppressed via -gnatp.
12623 --------------------------
12624 -- Resolve_Suppressible --
12625 --------------------------
12627 procedure Resolve_Suppressible
(Policy
: Node_Id
) is
12628 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Policy
);
12632 -- Transform policy argument Suppressible into either Ignore or
12633 -- Check depending on whether checks are enabled or suppressed.
12635 if Chars
(Arg
) = Name_Suppressible
then
12636 if Suppress_Checks
then
12637 Nam
:= Name_Ignore
;
12642 Rewrite
(Arg
, Make_Identifier
(Sloc
(Arg
), Nam
));
12644 end Resolve_Suppressible
;
12656 -- This can always appear as a configuration pragma
12658 if Is_Configuration_Pragma
then
12661 -- It can also appear in a declarative part or package spec in Ada
12662 -- 2012 mode. We allow this in other modes, but in that case we
12663 -- consider that we have an Ada 2012 pragma on our hands.
12666 Check_Is_In_Decl_Part_Or_Package_Spec
;
12670 -- One argument case with no identifier (first form above)
12673 and then (Nkind
(Arg1
) /= N_Pragma_Argument_Association
12674 or else Chars
(Arg1
) = No_Name
)
12676 Check_Arg_Is_One_Of
(Arg1
,
12677 Name_Check
, Name_Disable
, Name_Ignore
, Name_Suppressible
);
12679 Resolve_Suppressible
(Arg1
);
12681 -- Treat one argument Assertion_Policy as equivalent to:
12683 -- pragma Check_Policy (Assertion, policy)
12685 -- So rewrite pragma in that manner and link on to the chain
12686 -- of Check_Policy pragmas, marking the pragma as analyzed.
12688 Policy
:= Get_Pragma_Arg
(Arg1
);
12692 Chars
=> Name_Check_Policy
,
12693 Pragma_Argument_Associations
=> New_List
(
12694 Make_Pragma_Argument_Association
(Loc
,
12695 Expression
=> Make_Identifier
(Loc
, Name_Assertion
)),
12697 Make_Pragma_Argument_Association
(Loc
,
12699 Make_Identifier
(Sloc
(Policy
), Chars
(Policy
))))));
12702 -- Here if we have two or more arguments
12705 Check_At_Least_N_Arguments
(1);
12708 -- Loop through arguments
12711 while Present
(Arg
) loop
12712 LocP
:= Sloc
(Arg
);
12714 -- Kind must be specified
12716 if Nkind
(Arg
) /= N_Pragma_Argument_Association
12717 or else Chars
(Arg
) = No_Name
12720 ("missing assertion kind for pragma%", Arg
);
12723 -- Check Kind and Policy have allowed forms
12725 Kind
:= Chars
(Arg
);
12726 Policy
:= Get_Pragma_Arg
(Arg
);
12728 if not Is_Valid_Assertion_Kind
(Kind
) then
12730 ("invalid assertion kind for pragma%", Arg
);
12733 Check_Arg_Is_One_Of
(Arg
,
12734 Name_Check
, Name_Disable
, Name_Ignore
, Name_Suppressible
);
12736 Resolve_Suppressible
(Arg
);
12738 if Kind
= Name_Ghost
then
12740 -- The Ghost policy must be either Check or Ignore
12741 -- (SPARK RM 6.9(6)).
12743 if not Nam_In
(Chars
(Policy
), Name_Check
,
12747 ("argument of pragma % Ghost must be Check or "
12748 & "Ignore", Policy
);
12751 -- Pragma Assertion_Policy specifying a Ghost policy
12752 -- cannot occur within a Ghost subprogram or package
12753 -- (SPARK RM 6.9(14)).
12755 if Ghost_Mode
> None
then
12757 ("pragma % cannot appear within ghost subprogram or "
12762 -- Rewrite the Assertion_Policy pragma as a series of
12763 -- Check_Policy pragmas of the form:
12765 -- Check_Policy (Kind, Policy);
12767 -- Note: the insertion of the pragmas cannot be done with
12768 -- Insert_Action because in the configuration case, there
12769 -- are no scopes on the scope stack and the mechanism will
12772 Insert_Before_And_Analyze
(N
,
12774 Chars
=> Name_Check_Policy
,
12775 Pragma_Argument_Associations
=> New_List
(
12776 Make_Pragma_Argument_Association
(LocP
,
12777 Expression
=> Make_Identifier
(LocP
, Kind
)),
12778 Make_Pragma_Argument_Association
(LocP
,
12779 Expression
=> Policy
))));
12784 -- Rewrite the Assertion_Policy pragma as null since we have
12785 -- now inserted all the equivalent Check pragmas.
12787 Rewrite
(N
, Make_Null_Statement
(Loc
));
12790 end Assertion_Policy
;
12792 ------------------------------
12793 -- Assume_No_Invalid_Values --
12794 ------------------------------
12796 -- pragma Assume_No_Invalid_Values (On | Off);
12798 when Pragma_Assume_No_Invalid_Values
=>
12800 Check_Valid_Configuration_Pragma
;
12801 Check_Arg_Count
(1);
12802 Check_No_Identifiers
;
12803 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
12805 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
12806 Assume_No_Invalid_Values
:= True;
12808 Assume_No_Invalid_Values
:= False;
12811 --------------------------
12812 -- Attribute_Definition --
12813 --------------------------
12815 -- pragma Attribute_Definition
12816 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
12817 -- [Entity =>] LOCAL_NAME,
12818 -- [Expression =>] EXPRESSION | NAME);
12820 when Pragma_Attribute_Definition
=> Attribute_Definition
: declare
12821 Attribute_Designator
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
12826 Check_Arg_Count
(3);
12827 Check_Optional_Identifier
(Arg1
, "attribute");
12828 Check_Optional_Identifier
(Arg2
, "entity");
12829 Check_Optional_Identifier
(Arg3
, "expression");
12831 if Nkind
(Attribute_Designator
) /= N_Identifier
then
12832 Error_Msg_N
("attribute name expected", Attribute_Designator
);
12836 Check_Arg_Is_Local_Name
(Arg2
);
12838 -- If the attribute is not recognized, then issue a warning (not
12839 -- an error), and ignore the pragma.
12841 Aname
:= Chars
(Attribute_Designator
);
12843 if not Is_Attribute_Name
(Aname
) then
12844 Bad_Attribute
(Attribute_Designator
, Aname
, Warn
=> True);
12848 -- Otherwise, rewrite the pragma as an attribute definition clause
12851 Make_Attribute_Definition_Clause
(Loc
,
12852 Name
=> Get_Pragma_Arg
(Arg2
),
12854 Expression
=> Get_Pragma_Arg
(Arg3
)));
12856 end Attribute_Definition
;
12858 ------------------------------------------------------------------
12859 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
12860 ------------------------------------------------------------------
12862 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
12863 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
12864 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
12865 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
12867 when Pragma_Async_Readers
12868 | Pragma_Async_Writers
12869 | Pragma_Effective_Reads
12870 | Pragma_Effective_Writes
12872 Async_Effective
: declare
12873 Obj_Decl
: Node_Id
;
12874 Obj_Id
: Entity_Id
;
12878 Check_No_Identifiers
;
12879 Check_At_Most_N_Arguments
(1);
12881 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
12883 -- Object declaration
12885 if Nkind
(Obj_Decl
) /= N_Object_Declaration
then
12890 Obj_Id
:= Defining_Entity
(Obj_Decl
);
12892 -- Perform minimal verification to ensure that the argument is at
12893 -- least a variable. Subsequent finer grained checks will be done
12894 -- at the end of the declarative region the contains the pragma.
12896 if Ekind
(Obj_Id
) = E_Variable
then
12898 -- A pragma that applies to a Ghost entity becomes Ghost for
12899 -- the purposes of legality checks and removal of ignored Ghost
12902 Mark_Ghost_Pragma
(N
, Obj_Id
);
12904 -- Chain the pragma on the contract for further processing by
12905 -- Analyze_External_Property_In_Decl_Part.
12907 Add_Contract_Item
(N
, Obj_Id
);
12909 -- Analyze the Boolean expression (if any)
12911 if Present
(Arg1
) then
12912 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
12915 -- Otherwise the external property applies to a constant
12918 Error_Pragma
("pragma % must apply to a volatile object");
12920 end Async_Effective
;
12926 -- pragma Asynchronous (LOCAL_NAME);
12928 when Pragma_Asynchronous
=> Asynchronous
: declare
12931 Formal
: Entity_Id
;
12936 procedure Process_Async_Pragma
;
12937 -- Common processing for procedure and access-to-procedure case
12939 --------------------------
12940 -- Process_Async_Pragma --
12941 --------------------------
12943 procedure Process_Async_Pragma
is
12946 Set_Is_Asynchronous
(Nm
);
12950 -- The formals should be of mode IN (RM E.4.1(6))
12953 while Present
(S
) loop
12954 Formal
:= Defining_Identifier
(S
);
12956 if Nkind
(Formal
) = N_Defining_Identifier
12957 and then Ekind
(Formal
) /= E_In_Parameter
12960 ("pragma% procedure can only have IN parameter",
12967 Set_Is_Asynchronous
(Nm
);
12968 end Process_Async_Pragma
;
12970 -- Start of processing for pragma Asynchronous
12973 Check_Ada_83_Warning
;
12974 Check_No_Identifiers
;
12975 Check_Arg_Count
(1);
12976 Check_Arg_Is_Local_Name
(Arg1
);
12978 if Debug_Flag_U
then
12982 C_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
12983 Analyze
(Get_Pragma_Arg
(Arg1
));
12984 Nm
:= Entity
(Get_Pragma_Arg
(Arg1
));
12986 -- A pragma that applies to a Ghost entity becomes Ghost for the
12987 -- purposes of legality checks and removal of ignored Ghost code.
12989 Mark_Ghost_Pragma
(N
, Nm
);
12991 if not Is_Remote_Call_Interface
(C_Ent
)
12992 and then not Is_Remote_Types
(C_Ent
)
12994 -- This pragma should only appear in an RCI or Remote Types
12995 -- unit (RM E.4.1(4)).
12998 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
13001 if Ekind
(Nm
) = E_Procedure
13002 and then Nkind
(Parent
(Nm
)) = N_Procedure_Specification
13004 if not Is_Remote_Call_Interface
(Nm
) then
13006 ("pragma% cannot be applied on non-remote procedure",
13010 L
:= Parameter_Specifications
(Parent
(Nm
));
13011 Process_Async_Pragma
;
13014 elsif Ekind
(Nm
) = E_Function
then
13016 ("pragma% cannot be applied to function", Arg1
);
13018 elsif Is_Remote_Access_To_Subprogram_Type
(Nm
) then
13019 if Is_Record_Type
(Nm
) then
13021 -- A record type that is the Equivalent_Type for a remote
13022 -- access-to-subprogram type.
13024 Decl
:= Declaration_Node
(Corresponding_Remote_Type
(Nm
));
13027 -- A non-expanded RAS type (distribution is not enabled)
13029 Decl
:= Declaration_Node
(Nm
);
13032 if Nkind
(Decl
) = N_Full_Type_Declaration
13033 and then Nkind
(Type_Definition
(Decl
)) =
13034 N_Access_Procedure_Definition
13036 L
:= Parameter_Specifications
(Type_Definition
(Decl
));
13037 Process_Async_Pragma
;
13039 if Is_Asynchronous
(Nm
)
13040 and then Expander_Active
13041 and then Get_PCS_Name
/= Name_No_DSA
13043 RACW_Type_Is_Asynchronous
(Underlying_RACW_Type
(Nm
));
13048 ("pragma% cannot reference access-to-function type",
13052 -- Only other possibility is Access-to-class-wide type
13054 elsif Is_Access_Type
(Nm
)
13055 and then Is_Class_Wide_Type
(Designated_Type
(Nm
))
13057 Check_First_Subtype
(Arg1
);
13058 Set_Is_Asynchronous
(Nm
);
13059 if Expander_Active
then
13060 RACW_Type_Is_Asynchronous
(Nm
);
13064 Error_Pragma_Arg
("inappropriate argument for pragma%", Arg1
);
13072 -- pragma Atomic (LOCAL_NAME);
13074 when Pragma_Atomic
=>
13075 Process_Atomic_Independent_Shared_Volatile
;
13077 -----------------------
13078 -- Atomic_Components --
13079 -----------------------
13081 -- pragma Atomic_Components (array_LOCAL_NAME);
13083 -- This processing is shared by Volatile_Components
13085 when Pragma_Atomic_Components
13086 | Pragma_Volatile_Components
13088 Atomic_Components
: declare
13095 Check_Ada_83_Warning
;
13096 Check_No_Identifiers
;
13097 Check_Arg_Count
(1);
13098 Check_Arg_Is_Local_Name
(Arg1
);
13099 E_Id
:= Get_Pragma_Arg
(Arg1
);
13101 if Etype
(E_Id
) = Any_Type
then
13105 E
:= Entity
(E_Id
);
13107 -- A pragma that applies to a Ghost entity becomes Ghost for the
13108 -- purposes of legality checks and removal of ignored Ghost code.
13110 Mark_Ghost_Pragma
(N
, E
);
13111 Check_Duplicate_Pragma
(E
);
13113 if Rep_Item_Too_Early
(E
, N
)
13115 Rep_Item_Too_Late
(E
, N
)
13120 D
:= Declaration_Node
(E
);
13123 if (K
= N_Full_Type_Declaration
and then Is_Array_Type
(E
))
13125 ((Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
13126 and then Nkind
(D
) = N_Object_Declaration
13127 and then Nkind
(Object_Definition
(D
)) =
13128 N_Constrained_Array_Definition
)
13130 -- The flag is set on the object, or on the base type
13132 if Nkind
(D
) /= N_Object_Declaration
then
13133 E
:= Base_Type
(E
);
13136 -- Atomic implies both Independent and Volatile
13138 if Prag_Id
= Pragma_Atomic_Components
then
13139 Set_Has_Atomic_Components
(E
);
13140 Set_Has_Independent_Components
(E
);
13143 Set_Has_Volatile_Components
(E
);
13146 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
13148 end Atomic_Components
;
13150 --------------------
13151 -- Attach_Handler --
13152 --------------------
13154 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13156 when Pragma_Attach_Handler
=>
13157 Check_Ada_83_Warning
;
13158 Check_No_Identifiers
;
13159 Check_Arg_Count
(2);
13161 if No_Run_Time_Mode
then
13162 Error_Msg_CRT
("Attach_Handler pragma", N
);
13164 Check_Interrupt_Or_Attach_Handler
;
13166 -- The expression that designates the attribute may depend on a
13167 -- discriminant, and is therefore a per-object expression, to
13168 -- be expanded in the init proc. If expansion is enabled, then
13169 -- perform semantic checks on a copy only.
13174 Parg2
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
13177 -- In Relaxed_RM_Semantics mode, we allow any static
13178 -- integer value, for compatibility with other compilers.
13180 if Relaxed_RM_Semantics
13181 and then Nkind
(Parg2
) = N_Integer_Literal
13183 Typ
:= Standard_Integer
;
13185 Typ
:= RTE
(RE_Interrupt_ID
);
13188 if Expander_Active
then
13189 Temp
:= New_Copy_Tree
(Parg2
);
13190 Set_Parent
(Temp
, N
);
13191 Preanalyze_And_Resolve
(Temp
, Typ
);
13194 Resolve
(Parg2
, Typ
);
13198 Process_Interrupt_Or_Attach_Handler
;
13201 --------------------
13202 -- C_Pass_By_Copy --
13203 --------------------
13205 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13207 when Pragma_C_Pass_By_Copy
=> C_Pass_By_Copy
: declare
13213 Check_Valid_Configuration_Pragma
;
13214 Check_Arg_Count
(1);
13215 Check_Optional_Identifier
(Arg1
, "max_size");
13217 Arg
:= Get_Pragma_Arg
(Arg1
);
13218 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
13220 Val
:= Expr_Value
(Arg
);
13224 ("maximum size for pragma% must be positive", Arg1
);
13226 elsif UI_Is_In_Int_Range
(Val
) then
13227 Default_C_Record_Mechanism
:= UI_To_Int
(Val
);
13229 -- If a giant value is given, Int'Last will do well enough.
13230 -- If sometime someone complains that a record larger than
13231 -- two gigabytes is not copied, we will worry about it then.
13234 Default_C_Record_Mechanism
:= Mechanism_Type
'Last;
13236 end C_Pass_By_Copy
;
13242 -- pragma Check ([Name =>] CHECK_KIND,
13243 -- [Check =>] Boolean_EXPRESSION
13244 -- [,[Message =>] String_EXPRESSION]);
13246 -- CHECK_KIND ::= IDENTIFIER |
13249 -- Invariant'Class |
13250 -- Type_Invariant'Class
13252 -- The identifiers Assertions and Statement_Assertions are not
13253 -- allowed, since they have special meaning for Check_Policy.
13255 -- WARNING: The code below manages Ghost regions. Return statements
13256 -- must be replaced by gotos which jump to the end of the code and
13257 -- restore the Ghost mode.
13259 when Pragma_Check
=> Check
: declare
13260 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
13261 Saved_IGR
: constant Node_Id
:= Ignored_Ghost_Region
;
13262 -- Save the Ghost-related attributes to restore on exit
13268 pragma Warnings
(Off
, Str
);
13271 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13272 -- the mode now to ensure that any nodes generated during analysis
13273 -- and expansion are marked as Ghost.
13275 Set_Ghost_Mode
(N
);
13278 Check_At_Least_N_Arguments
(2);
13279 Check_At_Most_N_Arguments
(3);
13280 Check_Optional_Identifier
(Arg1
, Name_Name
);
13281 Check_Optional_Identifier
(Arg2
, Name_Check
);
13283 if Arg_Count
= 3 then
13284 Check_Optional_Identifier
(Arg3
, Name_Message
);
13285 Str
:= Get_Pragma_Arg
(Arg3
);
13288 Rewrite_Assertion_Kind
(Get_Pragma_Arg
(Arg1
));
13289 Check_Arg_Is_Identifier
(Arg1
);
13290 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
13292 -- Check forbidden name Assertions or Statement_Assertions
13295 when Name_Assertions
=>
13297 ("""Assertions"" is not allowed as a check kind for "
13298 & "pragma%", Arg1
);
13300 when Name_Statement_Assertions
=>
13302 ("""Statement_Assertions"" is not allowed as a check kind "
13303 & "for pragma%", Arg1
);
13309 -- Check applicable policy. We skip this if Checked/Ignored status
13310 -- is already set (e.g. in the case of a pragma from an aspect).
13312 if Is_Checked
(N
) or else Is_Ignored
(N
) then
13315 -- For a non-source pragma that is a rewriting of another pragma,
13316 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13318 elsif Is_Rewrite_Substitution
(N
)
13319 and then Nkind
(Original_Node
(N
)) = N_Pragma
13321 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
13322 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
13324 -- Otherwise query the applicable policy at this point
13327 case Check_Kind
(Cname
) is
13328 when Name_Ignore
=>
13329 Set_Is_Ignored
(N
, True);
13330 Set_Is_Checked
(N
, False);
13333 Set_Is_Ignored
(N
, False);
13334 Set_Is_Checked
(N
, True);
13336 -- For disable, rewrite pragma as null statement and skip
13337 -- rest of the analysis of the pragma.
13339 when Name_Disable
=>
13340 Rewrite
(N
, Make_Null_Statement
(Loc
));
13344 -- No other possibilities
13347 raise Program_Error
;
13351 -- If check kind was not Disable, then continue pragma analysis
13353 Expr
:= Get_Pragma_Arg
(Arg2
);
13355 -- Deal with SCO generation
13357 if Is_Checked
(N
) and then not Split_PPC
(N
) then
13358 Set_SCO_Pragma_Enabled
(Loc
);
13361 -- Deal with analyzing the string argument. If checks are not
13362 -- on we don't want any expansion (since such expansion would
13363 -- not get properly deleted) but we do want to analyze (to get
13364 -- proper references). The Preanalyze_And_Resolve routine does
13365 -- just what we want. Ditto if pragma is active, because it will
13366 -- be rewritten as an if-statement whose analysis will complete
13367 -- analysis and expansion of the string message. This makes a
13368 -- difference in the unusual case where the expression for the
13369 -- string may have a side effect, such as raising an exception.
13370 -- This is mandated by RM 11.4.2, which specifies that the string
13371 -- expression is only evaluated if the check fails and
13372 -- Assertion_Error is to be raised.
13374 if Arg_Count
= 3 then
13375 Preanalyze_And_Resolve
(Str
, Standard_String
);
13378 -- Now you might think we could just do the same with the Boolean
13379 -- expression if checks are off (and expansion is on) and then
13380 -- rewrite the check as a null statement. This would work but we
13381 -- would lose the useful warnings about an assertion being bound
13382 -- to fail even if assertions are turned off.
13384 -- So instead we wrap the boolean expression in an if statement
13385 -- that looks like:
13387 -- if False and then condition then
13391 -- The reason we do this rewriting during semantic analysis rather
13392 -- than as part of normal expansion is that we cannot analyze and
13393 -- expand the code for the boolean expression directly, or it may
13394 -- cause insertion of actions that would escape the attempt to
13395 -- suppress the check code.
13397 -- Note that the Sloc for the if statement corresponds to the
13398 -- argument condition, not the pragma itself. The reason for
13399 -- this is that we may generate a warning if the condition is
13400 -- False at compile time, and we do not want to delete this
13401 -- warning when we delete the if statement.
13403 if Expander_Active
and Is_Ignored
(N
) then
13404 Eloc
:= Sloc
(Expr
);
13407 Make_If_Statement
(Eloc
,
13409 Make_And_Then
(Eloc
,
13410 Left_Opnd
=> Make_Identifier
(Eloc
, Name_False
),
13411 Right_Opnd
=> Expr
),
13412 Then_Statements
=> New_List
(
13413 Make_Null_Statement
(Eloc
))));
13415 -- Now go ahead and analyze the if statement
13417 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
13419 -- One rather special treatment. If we are now in Eliminated
13420 -- overflow mode, then suppress overflow checking since we do
13421 -- not want to drag in the bignum stuff if we are in Ignore
13422 -- mode anyway. This is particularly important if we are using
13423 -- a configurable run time that does not support bignum ops.
13425 if Scope_Suppress
.Overflow_Mode_Assertions
= Eliminated
then
13427 Svo
: constant Boolean :=
13428 Scope_Suppress
.Suppress
(Overflow_Check
);
13430 Scope_Suppress
.Overflow_Mode_Assertions
:= Strict
;
13431 Scope_Suppress
.Suppress
(Overflow_Check
) := True;
13433 Scope_Suppress
.Suppress
(Overflow_Check
) := Svo
;
13434 Scope_Suppress
.Overflow_Mode_Assertions
:= Eliminated
;
13437 -- Not that special case
13443 -- All done with this check
13445 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
13447 -- Check is active or expansion not active. In these cases we can
13448 -- just go ahead and analyze the boolean with no worries.
13451 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
13452 Analyze_And_Resolve
(Expr
, Any_Boolean
);
13453 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
13456 Restore_Ghost_Region
(Saved_GM
, Saved_IGR
);
13459 --------------------------
13460 -- Check_Float_Overflow --
13461 --------------------------
13463 -- pragma Check_Float_Overflow;
13465 when Pragma_Check_Float_Overflow
=>
13467 Check_Valid_Configuration_Pragma
;
13468 Check_Arg_Count
(0);
13469 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
13475 -- pragma Check_Name (check_IDENTIFIER);
13477 when Pragma_Check_Name
=>
13479 Check_No_Identifiers
;
13480 Check_Valid_Configuration_Pragma
;
13481 Check_Arg_Count
(1);
13482 Check_Arg_Is_Identifier
(Arg1
);
13485 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
13488 for J
in Check_Names
.First
.. Check_Names
.Last
loop
13489 if Check_Names
.Table
(J
) = Nam
then
13494 Check_Names
.Append
(Nam
);
13501 -- This is the old style syntax, which is still allowed in all modes:
13503 -- pragma Check_Policy ([Name =>] CHECK_KIND
13504 -- [Policy =>] POLICY_IDENTIFIER);
13506 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13508 -- CHECK_KIND ::= IDENTIFIER |
13511 -- Type_Invariant'Class |
13514 -- This is the new style syntax, compatible with Assertion_Policy
13515 -- and also allowed in all modes.
13517 -- Pragma Check_Policy (
13518 -- CHECK_KIND => POLICY_IDENTIFIER
13519 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13521 -- Note: the identifiers Name and Policy are not allowed as
13522 -- Check_Kind values. This avoids ambiguities between the old and
13523 -- new form syntax.
13525 when Pragma_Check_Policy
=> Check_Policy
: declare
13530 Check_At_Least_N_Arguments
(1);
13532 -- A Check_Policy pragma can appear either as a configuration
13533 -- pragma, or in a declarative part or a package spec (see RM
13534 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13535 -- followed for Check_Policy).
13537 if not Is_Configuration_Pragma
then
13538 Check_Is_In_Decl_Part_Or_Package_Spec
;
13541 -- Figure out if we have the old or new syntax. We have the
13542 -- old syntax if the first argument has no identifier, or the
13543 -- identifier is Name.
13545 if Nkind
(Arg1
) /= N_Pragma_Argument_Association
13546 or else Nam_In
(Chars
(Arg1
), No_Name
, Name_Name
)
13550 Check_Arg_Count
(2);
13551 Check_Optional_Identifier
(Arg1
, Name_Name
);
13552 Kind
:= Get_Pragma_Arg
(Arg1
);
13553 Rewrite_Assertion_Kind
(Kind
,
13554 From_Policy
=> Comes_From_Source
(N
));
13555 Check_Arg_Is_Identifier
(Arg1
);
13557 -- Check forbidden check kind
13559 if Nam_In
(Chars
(Kind
), Name_Name
, Name_Policy
) then
13560 Error_Msg_Name_2
:= Chars
(Kind
);
13562 ("pragma% does not allow% as check name", Arg1
);
13567 Check_Optional_Identifier
(Arg2
, Name_Policy
);
13568 Check_Arg_Is_One_Of
13570 Name_On
, Name_Off
, Name_Check
, Name_Disable
, Name_Ignore
);
13572 -- And chain pragma on the Check_Policy_List for search
13574 Set_Next_Pragma
(N
, Opt
.Check_Policy_List
);
13575 Opt
.Check_Policy_List
:= N
;
13577 -- For the new syntax, what we do is to convert each argument to
13578 -- an old syntax equivalent. We do that because we want to chain
13579 -- old style Check_Policy pragmas for the search (we don't want
13580 -- to have to deal with multiple arguments in the search).
13591 while Present
(Arg
) loop
13592 LocP
:= Sloc
(Arg
);
13593 Argx
:= Get_Pragma_Arg
(Arg
);
13595 -- Kind must be specified
13597 if Nkind
(Arg
) /= N_Pragma_Argument_Association
13598 or else Chars
(Arg
) = No_Name
13601 ("missing assertion kind for pragma%", Arg
);
13604 -- Construct equivalent old form syntax Check_Policy
13605 -- pragma and insert it to get remaining checks.
13609 Chars
=> Name_Check_Policy
,
13610 Pragma_Argument_Associations
=> New_List
(
13611 Make_Pragma_Argument_Association
(LocP
,
13613 Make_Identifier
(LocP
, Chars
(Arg
))),
13614 Make_Pragma_Argument_Association
(Sloc
(Argx
),
13615 Expression
=> Argx
)));
13619 -- For a configuration pragma, insert old form in
13620 -- the corresponding file.
13622 if Is_Configuration_Pragma
then
13623 Insert_After
(N
, New_P
);
13627 Insert_Action
(N
, New_P
);
13631 -- Rewrite original Check_Policy pragma to null, since we
13632 -- have converted it into a series of old syntax pragmas.
13634 Rewrite
(N
, Make_Null_Statement
(Loc
));
13644 -- pragma Comment (static_string_EXPRESSION)
13646 -- Processing for pragma Comment shares the circuitry for pragma
13647 -- Ident. The only differences are that Ident enforces a limit of 31
13648 -- characters on its argument, and also enforces limitations on
13649 -- placement for DEC compatibility. Pragma Comment shares neither of
13650 -- these restrictions.
13652 -------------------
13653 -- Common_Object --
13654 -------------------
13656 -- pragma Common_Object (
13657 -- [Internal =>] LOCAL_NAME
13658 -- [, [External =>] EXTERNAL_SYMBOL]
13659 -- [, [Size =>] EXTERNAL_SYMBOL]);
13661 -- Processing for this pragma is shared with Psect_Object
13663 ------------------------
13664 -- Compile_Time_Error --
13665 ------------------------
13667 -- pragma Compile_Time_Error
13668 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13670 when Pragma_Compile_Time_Error
=>
13672 Process_Compile_Time_Warning_Or_Error
;
13674 --------------------------
13675 -- Compile_Time_Warning --
13676 --------------------------
13678 -- pragma Compile_Time_Warning
13679 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13681 when Pragma_Compile_Time_Warning
=>
13683 Process_Compile_Time_Warning_Or_Error
;
13685 ---------------------------
13686 -- Compiler_Unit_Warning --
13687 ---------------------------
13689 -- pragma Compiler_Unit_Warning;
13693 -- Originally, we had only pragma Compiler_Unit, and it resulted in
13694 -- errors not warnings. This means that we had introduced a big extra
13695 -- inertia to compiler changes, since even if we implemented a new
13696 -- feature, and even if all versions to be used for bootstrapping
13697 -- implemented this new feature, we could not use it, since old
13698 -- compilers would give errors for using this feature in units
13699 -- having Compiler_Unit pragmas.
13701 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
13702 -- problem. We no longer have any units mentioning Compiler_Unit,
13703 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
13704 -- and thus generates a warning which can be ignored. So that deals
13705 -- with the problem of old compilers not implementing the newer form
13708 -- Newer compilers recognize the new pragma, but generate warning
13709 -- messages instead of errors, which again can be ignored in the
13710 -- case of an old compiler which implements a wanted new feature
13711 -- but at the time felt like warning about it for older compilers.
13713 -- We retain Compiler_Unit so that new compilers can be used to build
13714 -- older run-times that use this pragma. That's an unusual case, but
13715 -- it's easy enough to handle, so why not?
13717 when Pragma_Compiler_Unit
13718 | Pragma_Compiler_Unit_Warning
13721 Check_Arg_Count
(0);
13723 -- Only recognized in main unit
13725 if Current_Sem_Unit
= Main_Unit
then
13726 Compiler_Unit
:= True;
13729 -----------------------------
13730 -- Complete_Representation --
13731 -----------------------------
13733 -- pragma Complete_Representation;
13735 when Pragma_Complete_Representation
=>
13737 Check_Arg_Count
(0);
13739 if Nkind
(Parent
(N
)) /= N_Record_Representation_Clause
then
13741 ("pragma & must appear within record representation clause");
13744 ----------------------------
13745 -- Complex_Representation --
13746 ----------------------------
13748 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
13750 when Pragma_Complex_Representation
=> Complex_Representation
: declare
13757 Check_Arg_Count
(1);
13758 Check_Optional_Identifier
(Arg1
, Name_Entity
);
13759 Check_Arg_Is_Local_Name
(Arg1
);
13760 E_Id
:= Get_Pragma_Arg
(Arg1
);
13762 if Etype
(E_Id
) = Any_Type
then
13766 E
:= Entity
(E_Id
);
13768 if not Is_Record_Type
(E
) then
13770 ("argument for pragma% must be record type", Arg1
);
13773 Ent
:= First_Entity
(E
);
13776 or else No
(Next_Entity
(Ent
))
13777 or else Present
(Next_Entity
(Next_Entity
(Ent
)))
13778 or else not Is_Floating_Point_Type
(Etype
(Ent
))
13779 or else Etype
(Ent
) /= Etype
(Next_Entity
(Ent
))
13782 ("record for pragma% must have two fields of the same "
13783 & "floating-point type", Arg1
);
13786 Set_Has_Complex_Representation
(Base_Type
(E
));
13788 -- We need to treat the type has having a non-standard
13789 -- representation, for back-end purposes, even though in
13790 -- general a complex will have the default representation
13791 -- of a record with two real components.
13793 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
13795 end Complex_Representation
;
13797 -------------------------
13798 -- Component_Alignment --
13799 -------------------------
13801 -- pragma Component_Alignment (
13802 -- [Form =>] ALIGNMENT_CHOICE
13803 -- [, [Name =>] type_LOCAL_NAME]);
13805 -- ALIGNMENT_CHOICE ::=
13807 -- | Component_Size_4
13811 when Pragma_Component_Alignment
=> Component_AlignmentP
: declare
13812 Args
: Args_List
(1 .. 2);
13813 Names
: constant Name_List
(1 .. 2) := (
13817 Form
: Node_Id
renames Args
(1);
13818 Name
: Node_Id
renames Args
(2);
13820 Atype
: Component_Alignment_Kind
;
13825 Gather_Associations
(Names
, Args
);
13828 Error_Pragma
("missing Form argument for pragma%");
13831 Check_Arg_Is_Identifier
(Form
);
13833 -- Get proper alignment, note that Default = Component_Size on all
13834 -- machines we have so far, and we want to set this value rather
13835 -- than the default value to indicate that it has been explicitly
13836 -- set (and thus will not get overridden by the default component
13837 -- alignment for the current scope)
13839 if Chars
(Form
) = Name_Component_Size
then
13840 Atype
:= Calign_Component_Size
;
13842 elsif Chars
(Form
) = Name_Component_Size_4
then
13843 Atype
:= Calign_Component_Size_4
;
13845 elsif Chars
(Form
) = Name_Default
then
13846 Atype
:= Calign_Component_Size
;
13848 elsif Chars
(Form
) = Name_Storage_Unit
then
13849 Atype
:= Calign_Storage_Unit
;
13853 ("invalid Form parameter for pragma%", Form
);
13856 -- The pragma appears in a configuration file
13858 if No
(Parent
(N
)) then
13859 Check_Valid_Configuration_Pragma
;
13861 -- Capture the component alignment in a global variable when
13862 -- the pragma appears in a configuration file. Note that the
13863 -- scope stack is empty at this point and cannot be used to
13864 -- store the alignment value.
13866 Configuration_Component_Alignment
:= Atype
;
13868 -- Case with no name, supplied, affects scope table entry
13870 elsif No
(Name
) then
13872 (Scope_Stack
.Last
).Component_Alignment_Default
:= Atype
;
13874 -- Case of name supplied
13877 Check_Arg_Is_Local_Name
(Name
);
13879 Typ
:= Entity
(Name
);
13882 or else Rep_Item_Too_Early
(Typ
, N
)
13886 Typ
:= Underlying_Type
(Typ
);
13889 if not Is_Record_Type
(Typ
)
13890 and then not Is_Array_Type
(Typ
)
13893 ("Name parameter of pragma% must identify record or "
13894 & "array type", Name
);
13897 -- An explicit Component_Alignment pragma overrides an
13898 -- implicit pragma Pack, but not an explicit one.
13900 if not Has_Pragma_Pack
(Base_Type
(Typ
)) then
13901 Set_Is_Packed
(Base_Type
(Typ
), False);
13902 Set_Component_Alignment
(Base_Type
(Typ
), Atype
);
13905 end Component_AlignmentP
;
13907 --------------------------------
13908 -- Constant_After_Elaboration --
13909 --------------------------------
13911 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
13913 when Pragma_Constant_After_Elaboration
=> Constant_After_Elaboration
:
13915 Obj_Decl
: Node_Id
;
13916 Obj_Id
: Entity_Id
;
13920 Check_No_Identifiers
;
13921 Check_At_Most_N_Arguments
(1);
13923 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
13925 if Nkind
(Obj_Decl
) /= N_Object_Declaration
then
13930 Obj_Id
:= Defining_Entity
(Obj_Decl
);
13932 -- The object declaration must be a library-level variable which
13933 -- is either explicitly initialized or obtains a value during the
13934 -- elaboration of a package body (SPARK RM 3.3.1).
13936 if Ekind
(Obj_Id
) = E_Variable
then
13937 if not Is_Library_Level_Entity
(Obj_Id
) then
13939 ("pragma % must apply to a library level variable");
13943 -- Otherwise the pragma applies to a constant, which is illegal
13946 Error_Pragma
("pragma % must apply to a variable declaration");
13950 -- A pragma that applies to a Ghost entity becomes Ghost for the
13951 -- purposes of legality checks and removal of ignored Ghost code.
13953 Mark_Ghost_Pragma
(N
, Obj_Id
);
13955 -- Chain the pragma on the contract for completeness
13957 Add_Contract_Item
(N
, Obj_Id
);
13959 -- Analyze the Boolean expression (if any)
13961 if Present
(Arg1
) then
13962 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
13964 end Constant_After_Elaboration
;
13966 --------------------
13967 -- Contract_Cases --
13968 --------------------
13970 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
13972 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
13974 -- CASE_GUARD ::= boolean_EXPRESSION | others
13976 -- CONSEQUENCE ::= boolean_EXPRESSION
13978 -- Characteristics:
13980 -- * Analysis - The annotation undergoes initial checks to verify
13981 -- the legal placement and context. Secondary checks preanalyze the
13984 -- Analyze_Contract_Cases_In_Decl_Part
13986 -- * Expansion - The annotation is expanded during the expansion of
13987 -- the related subprogram [body] contract as performed in:
13989 -- Expand_Subprogram_Contract
13991 -- * Template - The annotation utilizes the generic template of the
13992 -- related subprogram [body] when it is:
13994 -- aspect on subprogram declaration
13995 -- aspect on stand-alone subprogram body
13996 -- pragma on stand-alone subprogram body
13998 -- The annotation must prepare its own template when it is:
14000 -- pragma on subprogram declaration
14002 -- * Globals - Capture of global references must occur after full
14005 -- * Instance - The annotation is instantiated automatically when
14006 -- the related generic subprogram [body] is instantiated except for
14007 -- the "pragma on subprogram declaration" case. In that scenario
14008 -- the annotation must instantiate itself.
14010 when Pragma_Contract_Cases
=> Contract_Cases
: declare
14011 Spec_Id
: Entity_Id
;
14012 Subp_Decl
: Node_Id
;
14013 Subp_Spec
: Node_Id
;
14017 Check_No_Identifiers
;
14018 Check_Arg_Count
(1);
14020 -- Ensure the proper placement of the pragma. Contract_Cases must
14021 -- be associated with a subprogram declaration or a body that acts
14025 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
14029 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
14032 -- Generic subprogram
14034 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
14037 -- Body acts as spec
14039 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
14040 and then No
(Corresponding_Spec
(Subp_Decl
))
14044 -- Body stub acts as spec
14046 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
14047 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
14053 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
14054 Subp_Spec
:= Specification
(Subp_Decl
);
14056 -- Pragma Contract_Cases is forbidden on null procedures, as
14057 -- this may lead to potential ambiguities in behavior when
14058 -- interface null procedures are involved.
14060 if Nkind
(Subp_Spec
) = N_Procedure_Specification
14061 and then Null_Present
(Subp_Spec
)
14063 Error_Msg_N
(Fix_Error
14064 ("pragma % cannot apply to null procedure"), N
);
14073 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
14075 -- A pragma that applies to a Ghost entity becomes Ghost for the
14076 -- purposes of legality checks and removal of ignored Ghost code.
14078 Mark_Ghost_Pragma
(N
, Spec_Id
);
14079 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
14081 -- Chain the pragma on the contract for further processing by
14082 -- Analyze_Contract_Cases_In_Decl_Part.
14084 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
14086 -- Fully analyze the pragma when it appears inside an entry
14087 -- or subprogram body because it cannot benefit from forward
14090 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
14092 N_Subprogram_Body_Stub
)
14094 -- The legality checks of pragma Contract_Cases are affected by
14095 -- the SPARK mode in effect and the volatility of the context.
14096 -- Analyze all pragmas in a specific order.
14098 Analyze_If_Present
(Pragma_SPARK_Mode
);
14099 Analyze_If_Present
(Pragma_Volatile_Function
);
14100 Analyze_Contract_Cases_In_Decl_Part
(N
);
14102 end Contract_Cases
;
14108 -- pragma Controlled (first_subtype_LOCAL_NAME);
14110 when Pragma_Controlled
=> Controlled
: declare
14114 Check_No_Identifiers
;
14115 Check_Arg_Count
(1);
14116 Check_Arg_Is_Local_Name
(Arg1
);
14117 Arg
:= Get_Pragma_Arg
(Arg1
);
14119 if not Is_Entity_Name
(Arg
)
14120 or else not Is_Access_Type
(Entity
(Arg
))
14122 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
14124 Set_Has_Pragma_Controlled
(Base_Type
(Entity
(Arg
)));
14132 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14133 -- [Entity =>] LOCAL_NAME);
14135 when Pragma_Convention
=> Convention
: declare
14138 pragma Warnings
(Off
, C
);
14139 pragma Warnings
(Off
, E
);
14142 Check_Arg_Order
((Name_Convention
, Name_Entity
));
14143 Check_Ada_83_Warning
;
14144 Check_Arg_Count
(2);
14145 Process_Convention
(C
, E
);
14147 -- A pragma that applies to a Ghost entity becomes Ghost for the
14148 -- purposes of legality checks and removal of ignored Ghost code.
14150 Mark_Ghost_Pragma
(N
, E
);
14153 ---------------------------
14154 -- Convention_Identifier --
14155 ---------------------------
14157 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14158 -- [Convention =>] convention_IDENTIFIER);
14160 when Pragma_Convention_Identifier
=> Convention_Identifier
: declare
14166 Check_Arg_Order
((Name_Name
, Name_Convention
));
14167 Check_Arg_Count
(2);
14168 Check_Optional_Identifier
(Arg1
, Name_Name
);
14169 Check_Optional_Identifier
(Arg2
, Name_Convention
);
14170 Check_Arg_Is_Identifier
(Arg1
);
14171 Check_Arg_Is_Identifier
(Arg2
);
14172 Idnam
:= Chars
(Get_Pragma_Arg
(Arg1
));
14173 Cname
:= Chars
(Get_Pragma_Arg
(Arg2
));
14175 if Is_Convention_Name
(Cname
) then
14176 Record_Convention_Identifier
14177 (Idnam
, Get_Convention_Id
(Cname
));
14180 ("second arg for % pragma must be convention", Arg2
);
14182 end Convention_Identifier
;
14188 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14190 when Pragma_CPP_Class
=>
14193 if Warn_On_Obsolescent_Feature
then
14195 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14196 & "effect; replace it by pragma import?j?", N
);
14199 Check_Arg_Count
(1);
14203 Chars
=> Name_Import
,
14204 Pragma_Argument_Associations
=> New_List
(
14205 Make_Pragma_Argument_Association
(Loc
,
14206 Expression
=> Make_Identifier
(Loc
, Name_CPP
)),
14207 New_Copy
(First
(Pragma_Argument_Associations
(N
))))));
14210 ---------------------
14211 -- CPP_Constructor --
14212 ---------------------
14214 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14215 -- [, [External_Name =>] static_string_EXPRESSION ]
14216 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14218 when Pragma_CPP_Constructor
=> CPP_Constructor
: declare
14221 Def_Id
: Entity_Id
;
14222 Tag_Typ
: Entity_Id
;
14226 Check_At_Least_N_Arguments
(1);
14227 Check_At_Most_N_Arguments
(3);
14228 Check_Optional_Identifier
(Arg1
, Name_Entity
);
14229 Check_Arg_Is_Local_Name
(Arg1
);
14231 Id
:= Get_Pragma_Arg
(Arg1
);
14232 Find_Program_Unit_Name
(Id
);
14234 -- If we did not find the name, we are done
14236 if Etype
(Id
) = Any_Type
then
14240 Def_Id
:= Entity
(Id
);
14242 -- Check if already defined as constructor
14244 if Is_Constructor
(Def_Id
) then
14246 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1
);
14250 if Ekind
(Def_Id
) = E_Function
14251 and then (Is_CPP_Class
(Etype
(Def_Id
))
14252 or else (Is_Class_Wide_Type
(Etype
(Def_Id
))
14254 Is_CPP_Class
(Root_Type
(Etype
(Def_Id
)))))
14256 if Scope
(Def_Id
) /= Scope
(Etype
(Def_Id
)) then
14258 ("'C'P'P constructor must be defined in the scope of "
14259 & "its returned type", Arg1
);
14262 if Arg_Count
>= 2 then
14263 Set_Imported
(Def_Id
);
14264 Set_Is_Public
(Def_Id
);
14265 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
14268 Set_Has_Completion
(Def_Id
);
14269 Set_Is_Constructor
(Def_Id
);
14270 Set_Convention
(Def_Id
, Convention_CPP
);
14272 -- Imported C++ constructors are not dispatching primitives
14273 -- because in C++ they don't have a dispatch table slot.
14274 -- However, in Ada the constructor has the profile of a
14275 -- function that returns a tagged type and therefore it has
14276 -- been treated as a primitive operation during semantic
14277 -- analysis. We now remove it from the list of primitive
14278 -- operations of the type.
14280 if Is_Tagged_Type
(Etype
(Def_Id
))
14281 and then not Is_Class_Wide_Type
(Etype
(Def_Id
))
14282 and then Is_Dispatching_Operation
(Def_Id
)
14284 Tag_Typ
:= Etype
(Def_Id
);
14286 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
14287 while Present
(Elmt
) and then Node
(Elmt
) /= Def_Id
loop
14291 Remove_Elmt
(Primitive_Operations
(Tag_Typ
), Elmt
);
14292 Set_Is_Dispatching_Operation
(Def_Id
, False);
14295 -- For backward compatibility, if the constructor returns a
14296 -- class wide type, and we internally change the return type to
14297 -- the corresponding root type.
14299 if Is_Class_Wide_Type
(Etype
(Def_Id
)) then
14300 Set_Etype
(Def_Id
, Root_Type
(Etype
(Def_Id
)));
14304 ("pragma% requires function returning a 'C'P'P_Class type",
14307 end CPP_Constructor
;
14313 when Pragma_CPP_Virtual
=>
14316 if Warn_On_Obsolescent_Feature
then
14318 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14326 when Pragma_CPP_Vtable
=>
14329 if Warn_On_Obsolescent_Feature
then
14331 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14339 -- pragma CPU (EXPRESSION);
14341 when Pragma_CPU
=> CPU
: declare
14342 P
: constant Node_Id
:= Parent
(N
);
14348 Check_No_Identifiers
;
14349 Check_Arg_Count
(1);
14353 if Nkind
(P
) = N_Subprogram_Body
then
14354 Check_In_Main_Program
;
14356 Arg
:= Get_Pragma_Arg
(Arg1
);
14357 Analyze_And_Resolve
(Arg
, Any_Integer
);
14359 Ent
:= Defining_Unit_Name
(Specification
(P
));
14361 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
14362 Ent
:= Defining_Identifier
(Ent
);
14367 if not Is_OK_Static_Expression
(Arg
) then
14368 Flag_Non_Static_Expr
14369 ("main subprogram affinity is not static!", Arg
);
14372 -- If constraint error, then we already signalled an error
14374 elsif Raises_Constraint_Error
(Arg
) then
14377 -- Otherwise check in range
14381 CPU_Id
: constant Entity_Id
:= RTE
(RE_CPU_Range
);
14382 -- This is the entity System.Multiprocessors.CPU_Range;
14384 Val
: constant Uint
:= Expr_Value
(Arg
);
14387 if Val
< Expr_Value
(Type_Low_Bound
(CPU_Id
))
14389 Val
> Expr_Value
(Type_High_Bound
(CPU_Id
))
14392 ("main subprogram CPU is out of range", Arg1
);
14398 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
14402 elsif Nkind
(P
) = N_Task_Definition
then
14403 Arg
:= Get_Pragma_Arg
(Arg1
);
14404 Ent
:= Defining_Identifier
(Parent
(P
));
14406 -- The expression must be analyzed in the special manner
14407 -- described in "Handling of Default and Per-Object
14408 -- Expressions" in sem.ads.
14410 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_CPU_Range
));
14412 -- Anything else is incorrect
14418 -- Check duplicate pragma before we chain the pragma in the Rep
14419 -- Item chain of Ent.
14421 Check_Duplicate_Pragma
(Ent
);
14422 Record_Rep_Item
(Ent
, N
);
14425 --------------------
14426 -- Deadline_Floor --
14427 --------------------
14429 -- pragma Deadline_Floor (time_span_EXPRESSION);
14431 when Pragma_Deadline_Floor
=> Deadline_Floor
: declare
14432 P
: constant Node_Id
:= Parent
(N
);
14438 Check_No_Identifiers
;
14439 Check_Arg_Count
(1);
14441 Arg
:= Get_Pragma_Arg
(Arg1
);
14443 -- The expression must be analyzed in the special manner described
14444 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14446 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
14448 -- Only protected types allowed
14450 if Nkind
(P
) /= N_Protected_Definition
then
14454 Ent
:= Defining_Identifier
(Parent
(P
));
14456 -- Check duplicate pragma before we chain the pragma in the Rep
14457 -- Item chain of Ent.
14459 Check_Duplicate_Pragma
(Ent
);
14460 Record_Rep_Item
(Ent
, N
);
14462 end Deadline_Floor
;
14468 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
14470 when Pragma_Debug
=> Debug
: declare
14477 -- The condition for executing the call is that the expander
14478 -- is active and that we are not ignoring this debug pragma.
14483 (Expander_Active
and then not Is_Ignored
(N
)),
14486 if not Is_Ignored
(N
) then
14487 Set_SCO_Pragma_Enabled
(Loc
);
14490 if Arg_Count
= 2 then
14492 Make_And_Then
(Loc
,
14493 Left_Opnd
=> Relocate_Node
(Cond
),
14494 Right_Opnd
=> Get_Pragma_Arg
(Arg1
));
14495 Call
:= Get_Pragma_Arg
(Arg2
);
14497 Call
:= Get_Pragma_Arg
(Arg1
);
14500 if Nkind_In
(Call
, N_Expanded_Name
,
14503 N_Indexed_Component
,
14504 N_Selected_Component
)
14506 -- If this pragma Debug comes from source, its argument was
14507 -- parsed as a name form (which is syntactically identical).
14508 -- In a generic context a parameterless call will be left as
14509 -- an expanded name (if global) or selected_component if local.
14510 -- Change it to a procedure call statement now.
14512 Change_Name_To_Procedure_Call_Statement
(Call
);
14514 elsif Nkind
(Call
) = N_Procedure_Call_Statement
then
14516 -- Already in the form of a procedure call statement: nothing
14517 -- to do (could happen in case of an internally generated
14523 -- All other cases: diagnose error
14526 ("argument of pragma ""Debug"" is not procedure call",
14531 -- Rewrite into a conditional with an appropriate condition. We
14532 -- wrap the procedure call in a block so that overhead from e.g.
14533 -- use of the secondary stack does not generate execution overhead
14534 -- for suppressed conditions.
14536 -- Normally the analysis that follows will freeze the subprogram
14537 -- being called. However, if the call is to a null procedure,
14538 -- we want to freeze it before creating the block, because the
14539 -- analysis that follows may be done with expansion disabled, in
14540 -- which case the body will not be generated, leading to spurious
14543 if Nkind
(Call
) = N_Procedure_Call_Statement
14544 and then Is_Entity_Name
(Name
(Call
))
14546 Analyze
(Name
(Call
));
14547 Freeze_Before
(N
, Entity
(Name
(Call
)));
14551 Make_Implicit_If_Statement
(N
,
14553 Then_Statements
=> New_List
(
14554 Make_Block_Statement
(Loc
,
14555 Handled_Statement_Sequence
=>
14556 Make_Handled_Sequence_Of_Statements
(Loc
,
14557 Statements
=> New_List
(Relocate_Node
(Call
)))))));
14560 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
14561 -- after analysis of the normally rewritten node, to capture all
14562 -- references to entities, which avoids issuing wrong warnings
14563 -- about unused entities.
14565 if GNATprove_Mode
then
14566 Rewrite
(N
, Make_Null_Statement
(Loc
));
14574 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
14576 when Pragma_Debug_Policy
=>
14578 Check_Arg_Count
(1);
14579 Check_No_Identifiers
;
14580 Check_Arg_Is_Identifier
(Arg1
);
14582 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
14583 -- rewrite it that way, and let the rest of the checking come
14584 -- from analyzing the rewritten pragma.
14588 Chars
=> Name_Check_Policy
,
14589 Pragma_Argument_Associations
=> New_List
(
14590 Make_Pragma_Argument_Association
(Loc
,
14591 Expression
=> Make_Identifier
(Loc
, Name_Debug
)),
14593 Make_Pragma_Argument_Association
(Loc
,
14594 Expression
=> Get_Pragma_Arg
(Arg1
)))));
14597 -------------------------------
14598 -- Default_Initial_Condition --
14599 -------------------------------
14601 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
14603 when Pragma_Default_Initial_Condition
=> DIC
: declare
14610 Check_No_Identifiers
;
14611 Check_At_Most_N_Arguments
(1);
14615 while Present
(Stmt
) loop
14617 -- Skip prior pragmas, but check for duplicates
14619 if Nkind
(Stmt
) = N_Pragma
then
14620 if Pragma_Name
(Stmt
) = Pname
then
14627 -- Skip internally generated code. Note that derived type
14628 -- declarations of untagged types with discriminants are
14629 -- rewritten as private type declarations.
14631 elsif not Comes_From_Source
(Stmt
)
14632 and then Nkind
(Stmt
) /= N_Private_Type_Declaration
14636 -- The associated private type [extension] has been found, stop
14639 elsif Nkind_In
(Stmt
, N_Private_Extension_Declaration
,
14640 N_Private_Type_Declaration
)
14642 Typ
:= Defining_Entity
(Stmt
);
14645 -- The pragma does not apply to a legal construct, issue an
14646 -- error and stop the analysis.
14653 Stmt
:= Prev
(Stmt
);
14656 -- The pragma does not apply to a legal construct, issue an error
14657 -- and stop the analysis.
14664 -- A pragma that applies to a Ghost entity becomes Ghost for the
14665 -- purposes of legality checks and removal of ignored Ghost code.
14667 Mark_Ghost_Pragma
(N
, Typ
);
14669 -- The pragma signals that the type defines its own DIC assertion
14672 Set_Has_Own_DIC
(Typ
);
14674 -- Chain the pragma on the rep item chain for further processing
14676 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
14678 -- Create the declaration of the procedure which verifies the
14679 -- assertion expression of pragma DIC at runtime.
14681 Build_DIC_Procedure_Declaration
(Typ
);
14684 ----------------------------------
14685 -- Default_Scalar_Storage_Order --
14686 ----------------------------------
14688 -- pragma Default_Scalar_Storage_Order
14689 -- (High_Order_First | Low_Order_First);
14691 when Pragma_Default_Scalar_Storage_Order
=> DSSO
: declare
14692 Default
: Character;
14696 Check_Arg_Count
(1);
14698 -- Default_Scalar_Storage_Order can appear as a configuration
14699 -- pragma, or in a declarative part of a package spec.
14701 if not Is_Configuration_Pragma
then
14702 Check_Is_In_Decl_Part_Or_Package_Spec
;
14705 Check_No_Identifiers
;
14706 Check_Arg_Is_One_Of
14707 (Arg1
, Name_High_Order_First
, Name_Low_Order_First
);
14708 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
14709 Default
:= Fold_Upper
(Name_Buffer
(1));
14711 if not Support_Nondefault_SSO_On_Target
14712 and then (Ttypes
.Bytes_Big_Endian
/= (Default
= 'H'))
14714 if Warn_On_Unrecognized_Pragma
then
14716 ("non-default Scalar_Storage_Order not supported "
14717 & "on target?g?", N
);
14719 ("\pragma Default_Scalar_Storage_Order ignored?g?", N
);
14722 -- Here set the specified default
14725 Opt
.Default_SSO
:= Default
;
14729 --------------------------
14730 -- Default_Storage_Pool --
14731 --------------------------
14733 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
14735 when Pragma_Default_Storage_Pool
=> Default_Storage_Pool
: declare
14740 Check_Arg_Count
(1);
14742 -- Default_Storage_Pool can appear as a configuration pragma, or
14743 -- in a declarative part of a package spec.
14745 if not Is_Configuration_Pragma
then
14746 Check_Is_In_Decl_Part_Or_Package_Spec
;
14749 if From_Aspect_Specification
(N
) then
14751 E
: constant Entity_Id
:= Entity
(Corresponding_Aspect
(N
));
14753 if not In_Open_Scopes
(E
) then
14755 ("aspect must apply to package or subprogram", N
);
14760 if Present
(Arg1
) then
14761 Pool
:= Get_Pragma_Arg
(Arg1
);
14763 -- Case of Default_Storage_Pool (null);
14765 if Nkind
(Pool
) = N_Null
then
14768 -- This is an odd case, this is not really an expression,
14769 -- so we don't have a type for it. So just set the type to
14772 Set_Etype
(Pool
, Empty
);
14774 -- Case of Default_Storage_Pool (storage_pool_NAME);
14777 -- If it's a configuration pragma, then the only allowed
14778 -- argument is "null".
14780 if Is_Configuration_Pragma
then
14781 Error_Pragma_Arg
("NULL expected", Arg1
);
14784 -- The expected type for a non-"null" argument is
14785 -- Root_Storage_Pool'Class, and the pool must be a variable.
14787 Analyze_And_Resolve
14788 (Pool
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
14790 if Is_Variable
(Pool
) then
14792 -- A pragma that applies to a Ghost entity becomes Ghost
14793 -- for the purposes of legality checks and removal of
14794 -- ignored Ghost code.
14796 Mark_Ghost_Pragma
(N
, Entity
(Pool
));
14800 ("default storage pool must be a variable", Arg1
);
14804 -- Record the pool name (or null). Freeze.Freeze_Entity for an
14805 -- access type will use this information to set the appropriate
14806 -- attributes of the access type. If the pragma appears in a
14807 -- generic unit it is ignored, given that it may refer to a
14810 if not Inside_A_Generic
then
14811 Default_Pool
:= Pool
;
14814 end Default_Storage_Pool
;
14820 -- pragma Depends (DEPENDENCY_RELATION);
14822 -- DEPENDENCY_RELATION ::=
14824 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
14826 -- DEPENDENCY_CLAUSE ::=
14827 -- OUTPUT_LIST =>[+] INPUT_LIST
14828 -- | NULL_DEPENDENCY_CLAUSE
14830 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
14832 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
14834 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
14836 -- OUTPUT ::= NAME | FUNCTION_RESULT
14839 -- where FUNCTION_RESULT is a function Result attribute_reference
14841 -- Characteristics:
14843 -- * Analysis - The annotation undergoes initial checks to verify
14844 -- the legal placement and context. Secondary checks fully analyze
14845 -- the dependency clauses in:
14847 -- Analyze_Depends_In_Decl_Part
14849 -- * Expansion - None.
14851 -- * Template - The annotation utilizes the generic template of the
14852 -- related subprogram [body] when it is:
14854 -- aspect on subprogram declaration
14855 -- aspect on stand-alone subprogram body
14856 -- pragma on stand-alone subprogram body
14858 -- The annotation must prepare its own template when it is:
14860 -- pragma on subprogram declaration
14862 -- * Globals - Capture of global references must occur after full
14865 -- * Instance - The annotation is instantiated automatically when
14866 -- the related generic subprogram [body] is instantiated except for
14867 -- the "pragma on subprogram declaration" case. In that scenario
14868 -- the annotation must instantiate itself.
14870 when Pragma_Depends
=> Depends
: declare
14872 Spec_Id
: Entity_Id
;
14873 Subp_Decl
: Node_Id
;
14876 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
14880 -- Chain the pragma on the contract for further processing by
14881 -- Analyze_Depends_In_Decl_Part.
14883 Add_Contract_Item
(N
, Spec_Id
);
14885 -- Fully analyze the pragma when it appears inside an entry
14886 -- or subprogram body because it cannot benefit from forward
14889 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
14891 N_Subprogram_Body_Stub
)
14893 -- The legality checks of pragmas Depends and Global are
14894 -- affected by the SPARK mode in effect and the volatility
14895 -- of the context. In addition these two pragmas are subject
14896 -- to an inherent order:
14901 -- Analyze all these pragmas in the order outlined above
14903 Analyze_If_Present
(Pragma_SPARK_Mode
);
14904 Analyze_If_Present
(Pragma_Volatile_Function
);
14905 Analyze_If_Present
(Pragma_Global
);
14906 Analyze_Depends_In_Decl_Part
(N
);
14911 ---------------------
14912 -- Detect_Blocking --
14913 ---------------------
14915 -- pragma Detect_Blocking;
14917 when Pragma_Detect_Blocking
=>
14919 Check_Arg_Count
(0);
14920 Check_Valid_Configuration_Pragma
;
14921 Detect_Blocking
:= True;
14923 ------------------------------------
14924 -- Disable_Atomic_Synchronization --
14925 ------------------------------------
14927 -- pragma Disable_Atomic_Synchronization [(Entity)];
14929 when Pragma_Disable_Atomic_Synchronization
=>
14931 Process_Disable_Enable_Atomic_Sync
(Name_Suppress
);
14933 -------------------
14934 -- Discard_Names --
14935 -------------------
14937 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
14939 when Pragma_Discard_Names
=> Discard_Names
: declare
14944 Check_Ada_83_Warning
;
14946 -- Deal with configuration pragma case
14948 if Arg_Count
= 0 and then Is_Configuration_Pragma
then
14949 Global_Discard_Names
:= True;
14952 -- Otherwise, check correct appropriate context
14955 Check_Is_In_Decl_Part_Or_Package_Spec
;
14957 if Arg_Count
= 0 then
14959 -- If there is no parameter, then from now on this pragma
14960 -- applies to any enumeration, exception or tagged type
14961 -- defined in the current declarative part, and recursively
14962 -- to any nested scope.
14964 Set_Discard_Names
(Current_Scope
);
14968 Check_Arg_Count
(1);
14969 Check_Optional_Identifier
(Arg1
, Name_On
);
14970 Check_Arg_Is_Local_Name
(Arg1
);
14972 E_Id
:= Get_Pragma_Arg
(Arg1
);
14974 if Etype
(E_Id
) = Any_Type
then
14978 E
:= Entity
(E_Id
);
14980 -- A pragma that applies to a Ghost entity becomes Ghost for
14981 -- the purposes of legality checks and removal of ignored
14984 Mark_Ghost_Pragma
(N
, E
);
14986 if (Is_First_Subtype
(E
)
14988 (Is_Enumeration_Type
(E
) or else Is_Tagged_Type
(E
)))
14989 or else Ekind
(E
) = E_Exception
14991 Set_Discard_Names
(E
);
14992 Record_Rep_Item
(E
, N
);
14996 ("inappropriate entity for pragma%", Arg1
);
15002 ------------------------
15003 -- Dispatching_Domain --
15004 ------------------------
15006 -- pragma Dispatching_Domain (EXPRESSION);
15008 when Pragma_Dispatching_Domain
=> Dispatching_Domain
: declare
15009 P
: constant Node_Id
:= Parent
(N
);
15015 Check_No_Identifiers
;
15016 Check_Arg_Count
(1);
15018 -- This pragma is born obsolete, but not the aspect
15020 if not From_Aspect_Specification
(N
) then
15022 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
15025 if Nkind
(P
) = N_Task_Definition
then
15026 Arg
:= Get_Pragma_Arg
(Arg1
);
15027 Ent
:= Defining_Identifier
(Parent
(P
));
15029 -- A pragma that applies to a Ghost entity becomes Ghost for
15030 -- the purposes of legality checks and removal of ignored Ghost
15033 Mark_Ghost_Pragma
(N
, Ent
);
15035 -- The expression must be analyzed in the special manner
15036 -- described in "Handling of Default and Per-Object
15037 -- Expressions" in sem.ads.
15039 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Dispatching_Domain
));
15041 -- Check duplicate pragma before we chain the pragma in the Rep
15042 -- Item chain of Ent.
15044 Check_Duplicate_Pragma
(Ent
);
15045 Record_Rep_Item
(Ent
, N
);
15047 -- Anything else is incorrect
15052 end Dispatching_Domain
;
15058 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15060 when Pragma_Elaborate
=> Elaborate
: declare
15065 -- Pragma must be in context items list of a compilation unit
15067 if not Is_In_Context_Clause
then
15071 -- Must be at least one argument
15073 if Arg_Count
= 0 then
15074 Error_Pragma
("pragma% requires at least one argument");
15077 -- In Ada 83 mode, there can be no items following it in the
15078 -- context list except other pragmas and implicit with clauses
15079 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15080 -- placement rule does not apply.
15082 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
15084 while Present
(Citem
) loop
15085 if Nkind
(Citem
) = N_Pragma
15086 or else (Nkind
(Citem
) = N_With_Clause
15087 and then Implicit_With
(Citem
))
15092 ("(Ada 83) pragma% must be at end of context clause");
15099 -- Finally, the arguments must all be units mentioned in a with
15100 -- clause in the same context clause. Note we already checked (in
15101 -- Par.Prag) that the arguments are all identifiers or selected
15105 Outer
: while Present
(Arg
) loop
15106 Citem
:= First
(List_Containing
(N
));
15107 Inner
: while Citem
/= N
loop
15108 if Nkind
(Citem
) = N_With_Clause
15109 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
15111 Set_Elaborate_Present
(Citem
, True);
15112 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
15114 -- With the pragma present, elaboration calls on
15115 -- subprograms from the named unit need no further
15116 -- checks, as long as the pragma appears in the current
15117 -- compilation unit. If the pragma appears in some unit
15118 -- in the context, there might still be a need for an
15119 -- Elaborate_All_Desirable from the current compilation
15120 -- to the named unit, so we keep the check enabled. This
15121 -- does not apply in SPARK mode, where we allow pragma
15122 -- Elaborate, but we don't trust it to be right so we
15123 -- will still insist on the Elaborate_All.
15125 if Legacy_Elaboration_Checks
15126 and then In_Extended_Main_Source_Unit
(N
)
15127 and then SPARK_Mode
/= On
15129 Set_Suppress_Elaboration_Warnings
15130 (Entity
(Name
(Citem
)));
15141 ("argument of pragma% is not withed unit", Arg
);
15148 -------------------
15149 -- Elaborate_All --
15150 -------------------
15152 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15154 when Pragma_Elaborate_All
=> Elaborate_All
: declare
15159 Check_Ada_83_Warning
;
15161 -- Pragma must be in context items list of a compilation unit
15163 if not Is_In_Context_Clause
then
15167 -- Must be at least one argument
15169 if Arg_Count
= 0 then
15170 Error_Pragma
("pragma% requires at least one argument");
15173 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15174 -- have to appear at the end of the context clause, but may
15175 -- appear mixed in with other items, even in Ada 83 mode.
15177 -- Final check: the arguments must all be units mentioned in
15178 -- a with clause in the same context clause. Note that we
15179 -- already checked (in Par.Prag) that all the arguments are
15180 -- either identifiers or selected components.
15183 Outr
: while Present
(Arg
) loop
15184 Citem
:= First
(List_Containing
(N
));
15185 Innr
: while Citem
/= N
loop
15186 if Nkind
(Citem
) = N_With_Clause
15187 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
15189 Set_Elaborate_All_Present
(Citem
, True);
15190 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
15192 -- Suppress warnings and elaboration checks on the named
15193 -- unit if the pragma is in the current compilation, as
15194 -- for pragma Elaborate.
15196 if Legacy_Elaboration_Checks
15197 and then In_Extended_Main_Source_Unit
(N
)
15199 Set_Suppress_Elaboration_Warnings
15200 (Entity
(Name
(Citem
)));
15210 Set_Error_Posted
(N
);
15212 ("argument of pragma% is not withed unit", Arg
);
15219 --------------------
15220 -- Elaborate_Body --
15221 --------------------
15223 -- pragma Elaborate_Body [( library_unit_NAME )];
15225 when Pragma_Elaborate_Body
=> Elaborate_Body
: declare
15226 Cunit_Node
: Node_Id
;
15227 Cunit_Ent
: Entity_Id
;
15230 Check_Ada_83_Warning
;
15231 Check_Valid_Library_Unit_Pragma
;
15233 if Nkind
(N
) = N_Null_Statement
then
15237 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
15238 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
15240 -- A pragma that applies to a Ghost entity becomes Ghost for the
15241 -- purposes of legality checks and removal of ignored Ghost code.
15243 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
15245 if Nkind_In
(Unit
(Cunit_Node
), N_Package_Body
,
15248 Error_Pragma
("pragma% must refer to a spec, not a body");
15250 Set_Body_Required
(Cunit_Node
);
15251 Set_Has_Pragma_Elaborate_Body
(Cunit_Ent
);
15253 -- If we are in dynamic elaboration mode, then we suppress
15254 -- elaboration warnings for the unit, since it is definitely
15255 -- fine NOT to do dynamic checks at the first level (and such
15256 -- checks will be suppressed because no elaboration boolean
15257 -- is created for Elaborate_Body packages).
15259 -- But in the static model of elaboration, Elaborate_Body is
15260 -- definitely NOT good enough to ensure elaboration safety on
15261 -- its own, since the body may WITH other units that are not
15262 -- safe from an elaboration point of view, so a client must
15263 -- still do an Elaborate_All on such units.
15265 -- Debug flag -gnatdD restores the old behavior of 3.13, where
15266 -- Elaborate_Body always suppressed elab warnings.
15268 if Legacy_Elaboration_Checks
15269 and then (Dynamic_Elaboration_Checks
or Debug_Flag_DD
)
15271 Set_Suppress_Elaboration_Warnings
(Cunit_Ent
);
15274 end Elaborate_Body
;
15276 ------------------------
15277 -- Elaboration_Checks --
15278 ------------------------
15280 -- pragma Elaboration_Checks (Static | Dynamic);
15282 when Pragma_Elaboration_Checks
=> Elaboration_Checks
: declare
15283 procedure Check_Duplicate_Elaboration_Checks_Pragma
;
15284 -- Emit an error if the current context list already contains
15285 -- a previous Elaboration_Checks pragma. This routine raises
15286 -- Pragma_Exit if a duplicate is found.
15288 procedure Ignore_Elaboration_Checks_Pragma
;
15289 -- Warn that the effects of the pragma are ignored. This routine
15290 -- raises Pragma_Exit.
15292 -----------------------------------------------
15293 -- Check_Duplicate_Elaboration_Checks_Pragma --
15294 -----------------------------------------------
15296 procedure Check_Duplicate_Elaboration_Checks_Pragma
is
15301 while Present
(Item
) loop
15302 if Nkind
(Item
) = N_Pragma
15303 and then Pragma_Name
(Item
) = Name_Elaboration_Checks
15313 end Check_Duplicate_Elaboration_Checks_Pragma
;
15315 --------------------------------------
15316 -- Ignore_Elaboration_Checks_Pragma --
15317 --------------------------------------
15319 procedure Ignore_Elaboration_Checks_Pragma
is
15321 Error_Msg_Name_1
:= Pname
;
15322 Error_Msg_N
("??effects of pragma % are ignored", N
);
15324 ("\place pragma on initial declaration of library unit", N
);
15327 end Ignore_Elaboration_Checks_Pragma
;
15331 Context
: constant Node_Id
:= Parent
(N
);
15334 -- Start of processing for Elaboration_Checks
15338 Check_Arg_Count
(1);
15339 Check_Arg_Is_One_Of
(Arg1
, Name_Static
, Name_Dynamic
);
15341 -- The pragma appears in a configuration file
15343 if No
(Context
) then
15344 Check_Valid_Configuration_Pragma
;
15345 Check_Duplicate_Elaboration_Checks_Pragma
;
15347 -- The pragma acts as a configuration pragma in a compilation unit
15349 -- pragma Elaboration_Checks (...);
15350 -- package Pack is ...;
15352 elsif Nkind
(Context
) = N_Compilation_Unit
15353 and then List_Containing
(N
) = Context_Items
(Context
)
15355 Check_Valid_Configuration_Pragma
;
15356 Check_Duplicate_Elaboration_Checks_Pragma
;
15358 Unt
:= Unit
(Context
);
15360 -- The pragma must appear on the initial declaration of a unit.
15361 -- If this is not the case, warn that the effects of the pragma
15364 if Nkind
(Unt
) = N_Package_Body
then
15365 Ignore_Elaboration_Checks_Pragma
;
15367 -- Check the Acts_As_Spec flag of the compilation units itself
15368 -- to determine whether the subprogram body completes since it
15369 -- has not been analyzed yet. This is safe because compilation
15370 -- units are not overloadable.
15372 elsif Nkind
(Unt
) = N_Subprogram_Body
15373 and then not Acts_As_Spec
(Context
)
15375 Ignore_Elaboration_Checks_Pragma
;
15377 elsif Nkind
(Unt
) = N_Subunit
then
15378 Ignore_Elaboration_Checks_Pragma
;
15381 -- Otherwise the pragma does not appear at the configuration level
15388 -- At this point the pragma is not a duplicate, and appears in the
15389 -- proper context. Set the elaboration model in effect.
15391 Dynamic_Elaboration_Checks
:=
15392 Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Dynamic
;
15393 end Elaboration_Checks
;
15399 -- pragma Eliminate (
15400 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
15401 -- [Entity =>] IDENTIFIER |
15402 -- SELECTED_COMPONENT |
15404 -- [, Source_Location => SOURCE_TRACE]);
15406 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
15407 -- SOURCE_TRACE ::= STRING_LITERAL
15409 when Pragma_Eliminate
=> Eliminate
: declare
15410 Args
: Args_List
(1 .. 5);
15411 Names
: constant Name_List
(1 .. 5) := (
15414 Name_Parameter_Types
,
15416 Name_Source_Location
);
15418 -- Note : Parameter_Types and Result_Type are leftovers from
15419 -- prior implementations of the pragma. They are not generated
15420 -- by the gnatelim tool, and play no role in selecting which
15421 -- of a set of overloaded names is chosen for elimination.
15423 Unit_Name
: Node_Id
renames Args
(1);
15424 Entity
: Node_Id
renames Args
(2);
15425 Parameter_Types
: Node_Id
renames Args
(3);
15426 Result_Type
: Node_Id
renames Args
(4);
15427 Source_Location
: Node_Id
renames Args
(5);
15431 Check_Valid_Configuration_Pragma
;
15432 Gather_Associations
(Names
, Args
);
15434 if No
(Unit_Name
) then
15435 Error_Pragma
("missing Unit_Name argument for pragma%");
15439 and then (Present
(Parameter_Types
)
15441 Present
(Result_Type
)
15443 Present
(Source_Location
))
15445 Error_Pragma
("missing Entity argument for pragma%");
15448 if (Present
(Parameter_Types
)
15450 Present
(Result_Type
))
15452 Present
(Source_Location
)
15455 ("parameter profile and source location cannot be used "
15456 & "together in pragma%");
15459 Process_Eliminate_Pragma
15468 -----------------------------------
15469 -- Enable_Atomic_Synchronization --
15470 -----------------------------------
15472 -- pragma Enable_Atomic_Synchronization [(Entity)];
15474 when Pragma_Enable_Atomic_Synchronization
=>
15476 Process_Disable_Enable_Atomic_Sync
(Name_Unsuppress
);
15483 -- [ Convention =>] convention_IDENTIFIER,
15484 -- [ Entity =>] LOCAL_NAME
15485 -- [, [External_Name =>] static_string_EXPRESSION ]
15486 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15488 when Pragma_Export
=> Export
: declare
15490 Def_Id
: Entity_Id
;
15492 pragma Warnings
(Off
, C
);
15495 Check_Ada_83_Warning
;
15499 Name_External_Name
,
15502 Check_At_Least_N_Arguments
(2);
15503 Check_At_Most_N_Arguments
(4);
15505 -- In Relaxed_RM_Semantics, support old Ada 83 style:
15506 -- pragma Export (Entity, "external name");
15508 if Relaxed_RM_Semantics
15509 and then Arg_Count
= 2
15510 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
15513 Def_Id
:= Get_Pragma_Arg
(Arg1
);
15516 if not Is_Entity_Name
(Def_Id
) then
15517 Error_Pragma_Arg
("entity name required", Arg1
);
15520 Def_Id
:= Entity
(Def_Id
);
15521 Set_Exported
(Def_Id
, Arg1
);
15524 Process_Convention
(C
, Def_Id
);
15526 -- A pragma that applies to a Ghost entity becomes Ghost for
15527 -- the purposes of legality checks and removal of ignored Ghost
15530 Mark_Ghost_Pragma
(N
, Def_Id
);
15532 if Ekind
(Def_Id
) /= E_Constant
then
15533 Note_Possible_Modification
15534 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
15537 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
15538 Set_Exported
(Def_Id
, Arg2
);
15541 -- If the entity is a deferred constant, propagate the information
15542 -- to the full view, because gigi elaborates the full view only.
15544 if Ekind
(Def_Id
) = E_Constant
15545 and then Present
(Full_View
(Def_Id
))
15548 Id2
: constant Entity_Id
:= Full_View
(Def_Id
);
15550 Set_Is_Exported
(Id2
, Is_Exported
(Def_Id
));
15551 Set_First_Rep_Item
(Id2
, First_Rep_Item
(Def_Id
));
15552 Set_Interface_Name
(Id2
, Einfo
.Interface_Name
(Def_Id
));
15557 ---------------------
15558 -- Export_Function --
15559 ---------------------
15561 -- pragma Export_Function (
15562 -- [Internal =>] LOCAL_NAME
15563 -- [, [External =>] EXTERNAL_SYMBOL]
15564 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15565 -- [, [Result_Type =>] TYPE_DESIGNATOR]
15566 -- [, [Mechanism =>] MECHANISM]
15567 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15569 -- EXTERNAL_SYMBOL ::=
15571 -- | static_string_EXPRESSION
15573 -- PARAMETER_TYPES ::=
15575 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15577 -- TYPE_DESIGNATOR ::=
15579 -- | subtype_Name ' Access
15583 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15585 -- MECHANISM_ASSOCIATION ::=
15586 -- [formal_parameter_NAME =>] MECHANISM_NAME
15588 -- MECHANISM_NAME ::=
15592 when Pragma_Export_Function
=> Export_Function
: declare
15593 Args
: Args_List
(1 .. 6);
15594 Names
: constant Name_List
(1 .. 6) := (
15597 Name_Parameter_Types
,
15600 Name_Result_Mechanism
);
15602 Internal
: Node_Id
renames Args
(1);
15603 External
: Node_Id
renames Args
(2);
15604 Parameter_Types
: Node_Id
renames Args
(3);
15605 Result_Type
: Node_Id
renames Args
(4);
15606 Mechanism
: Node_Id
renames Args
(5);
15607 Result_Mechanism
: Node_Id
renames Args
(6);
15611 Gather_Associations
(Names
, Args
);
15612 Process_Extended_Import_Export_Subprogram_Pragma
(
15613 Arg_Internal
=> Internal
,
15614 Arg_External
=> External
,
15615 Arg_Parameter_Types
=> Parameter_Types
,
15616 Arg_Result_Type
=> Result_Type
,
15617 Arg_Mechanism
=> Mechanism
,
15618 Arg_Result_Mechanism
=> Result_Mechanism
);
15619 end Export_Function
;
15621 -------------------
15622 -- Export_Object --
15623 -------------------
15625 -- pragma Export_Object (
15626 -- [Internal =>] LOCAL_NAME
15627 -- [, [External =>] EXTERNAL_SYMBOL]
15628 -- [, [Size =>] EXTERNAL_SYMBOL]);
15630 -- EXTERNAL_SYMBOL ::=
15632 -- | static_string_EXPRESSION
15634 -- PARAMETER_TYPES ::=
15636 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15638 -- TYPE_DESIGNATOR ::=
15640 -- | subtype_Name ' Access
15644 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15646 -- MECHANISM_ASSOCIATION ::=
15647 -- [formal_parameter_NAME =>] MECHANISM_NAME
15649 -- MECHANISM_NAME ::=
15653 when Pragma_Export_Object
=> Export_Object
: declare
15654 Args
: Args_List
(1 .. 3);
15655 Names
: constant Name_List
(1 .. 3) := (
15660 Internal
: Node_Id
renames Args
(1);
15661 External
: Node_Id
renames Args
(2);
15662 Size
: Node_Id
renames Args
(3);
15666 Gather_Associations
(Names
, Args
);
15667 Process_Extended_Import_Export_Object_Pragma
(
15668 Arg_Internal
=> Internal
,
15669 Arg_External
=> External
,
15673 ----------------------
15674 -- Export_Procedure --
15675 ----------------------
15677 -- pragma Export_Procedure (
15678 -- [Internal =>] LOCAL_NAME
15679 -- [, [External =>] EXTERNAL_SYMBOL]
15680 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15681 -- [, [Mechanism =>] MECHANISM]);
15683 -- EXTERNAL_SYMBOL ::=
15685 -- | static_string_EXPRESSION
15687 -- PARAMETER_TYPES ::=
15689 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15691 -- TYPE_DESIGNATOR ::=
15693 -- | subtype_Name ' Access
15697 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15699 -- MECHANISM_ASSOCIATION ::=
15700 -- [formal_parameter_NAME =>] MECHANISM_NAME
15702 -- MECHANISM_NAME ::=
15706 when Pragma_Export_Procedure
=> Export_Procedure
: declare
15707 Args
: Args_List
(1 .. 4);
15708 Names
: constant Name_List
(1 .. 4) := (
15711 Name_Parameter_Types
,
15714 Internal
: Node_Id
renames Args
(1);
15715 External
: Node_Id
renames Args
(2);
15716 Parameter_Types
: Node_Id
renames Args
(3);
15717 Mechanism
: Node_Id
renames Args
(4);
15721 Gather_Associations
(Names
, Args
);
15722 Process_Extended_Import_Export_Subprogram_Pragma
(
15723 Arg_Internal
=> Internal
,
15724 Arg_External
=> External
,
15725 Arg_Parameter_Types
=> Parameter_Types
,
15726 Arg_Mechanism
=> Mechanism
);
15727 end Export_Procedure
;
15733 -- pragma Export_Value (
15734 -- [Value =>] static_integer_EXPRESSION,
15735 -- [Link_Name =>] static_string_EXPRESSION);
15737 when Pragma_Export_Value
=>
15739 Check_Arg_Order
((Name_Value
, Name_Link_Name
));
15740 Check_Arg_Count
(2);
15742 Check_Optional_Identifier
(Arg1
, Name_Value
);
15743 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
15745 Check_Optional_Identifier
(Arg2
, Name_Link_Name
);
15746 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
15748 -----------------------------
15749 -- Export_Valued_Procedure --
15750 -----------------------------
15752 -- pragma Export_Valued_Procedure (
15753 -- [Internal =>] LOCAL_NAME
15754 -- [, [External =>] EXTERNAL_SYMBOL,]
15755 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15756 -- [, [Mechanism =>] MECHANISM]);
15758 -- EXTERNAL_SYMBOL ::=
15760 -- | static_string_EXPRESSION
15762 -- PARAMETER_TYPES ::=
15764 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15766 -- TYPE_DESIGNATOR ::=
15768 -- | subtype_Name ' Access
15772 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15774 -- MECHANISM_ASSOCIATION ::=
15775 -- [formal_parameter_NAME =>] MECHANISM_NAME
15777 -- MECHANISM_NAME ::=
15781 when Pragma_Export_Valued_Procedure
=>
15782 Export_Valued_Procedure
: declare
15783 Args
: Args_List
(1 .. 4);
15784 Names
: constant Name_List
(1 .. 4) := (
15787 Name_Parameter_Types
,
15790 Internal
: Node_Id
renames Args
(1);
15791 External
: Node_Id
renames Args
(2);
15792 Parameter_Types
: Node_Id
renames Args
(3);
15793 Mechanism
: Node_Id
renames Args
(4);
15797 Gather_Associations
(Names
, Args
);
15798 Process_Extended_Import_Export_Subprogram_Pragma
(
15799 Arg_Internal
=> Internal
,
15800 Arg_External
=> External
,
15801 Arg_Parameter_Types
=> Parameter_Types
,
15802 Arg_Mechanism
=> Mechanism
);
15803 end Export_Valued_Procedure
;
15805 -------------------
15806 -- Extend_System --
15807 -------------------
15809 -- pragma Extend_System ([Name =>] Identifier);
15811 when Pragma_Extend_System
=>
15813 Check_Valid_Configuration_Pragma
;
15814 Check_Arg_Count
(1);
15815 Check_Optional_Identifier
(Arg1
, Name_Name
);
15816 Check_Arg_Is_Identifier
(Arg1
);
15818 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
15821 and then Name_Buffer
(1 .. 4) = "aux_"
15823 if Present
(System_Extend_Pragma_Arg
) then
15824 if Chars
(Get_Pragma_Arg
(Arg1
)) =
15825 Chars
(Expression
(System_Extend_Pragma_Arg
))
15829 Error_Msg_Sloc
:= Sloc
(System_Extend_Pragma_Arg
);
15830 Error_Pragma
("pragma% conflicts with that #");
15834 System_Extend_Pragma_Arg
:= Arg1
;
15836 if not GNAT_Mode
then
15837 System_Extend_Unit
:= Arg1
;
15841 Error_Pragma
("incorrect name for pragma%, must be Aux_xxx");
15844 ------------------------
15845 -- Extensions_Allowed --
15846 ------------------------
15848 -- pragma Extensions_Allowed (ON | OFF);
15850 when Pragma_Extensions_Allowed
=>
15852 Check_Arg_Count
(1);
15853 Check_No_Identifiers
;
15854 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
15856 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
15857 Extensions_Allowed
:= True;
15858 Ada_Version
:= Ada_Version_Type
'Last;
15861 Extensions_Allowed
:= False;
15862 Ada_Version
:= Ada_Version_Explicit
;
15863 Ada_Version_Pragma
:= Empty
;
15866 ------------------------
15867 -- Extensions_Visible --
15868 ------------------------
15870 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
15872 -- Characteristics:
15874 -- * Analysis - The annotation is fully analyzed immediately upon
15875 -- elaboration as its expression must be static.
15877 -- * Expansion - None.
15879 -- * Template - The annotation utilizes the generic template of the
15880 -- related subprogram [body] when it is:
15882 -- aspect on subprogram declaration
15883 -- aspect on stand-alone subprogram body
15884 -- pragma on stand-alone subprogram body
15886 -- The annotation must prepare its own template when it is:
15888 -- pragma on subprogram declaration
15890 -- * Globals - Capture of global references must occur after full
15893 -- * Instance - The annotation is instantiated automatically when
15894 -- the related generic subprogram [body] is instantiated except for
15895 -- the "pragma on subprogram declaration" case. In that scenario
15896 -- the annotation must instantiate itself.
15898 when Pragma_Extensions_Visible
=> Extensions_Visible
: declare
15899 Formal
: Entity_Id
;
15900 Has_OK_Formal
: Boolean := False;
15901 Spec_Id
: Entity_Id
;
15902 Subp_Decl
: Node_Id
;
15906 Check_No_Identifiers
;
15907 Check_At_Most_N_Arguments
(1);
15910 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
15912 -- Abstract subprogram declaration
15914 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
15917 -- Generic subprogram declaration
15919 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
15922 -- Body acts as spec
15924 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
15925 and then No
(Corresponding_Spec
(Subp_Decl
))
15929 -- Body stub acts as spec
15931 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
15932 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
15936 -- Subprogram declaration
15938 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
15941 -- Otherwise the pragma is associated with an illegal construct
15944 Error_Pragma
("pragma % must apply to a subprogram");
15948 -- Mark the pragma as Ghost if the related subprogram is also
15949 -- Ghost. This also ensures that any expansion performed further
15950 -- below will produce Ghost nodes.
15952 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
15953 Mark_Ghost_Pragma
(N
, Spec_Id
);
15955 -- Chain the pragma on the contract for completeness
15957 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
15959 -- The legality checks of pragma Extension_Visible are affected
15960 -- by the SPARK mode in effect. Analyze all pragmas in specific
15963 Analyze_If_Present
(Pragma_SPARK_Mode
);
15965 -- Examine the formals of the related subprogram
15967 Formal
:= First_Formal
(Spec_Id
);
15968 while Present
(Formal
) loop
15970 -- At least one of the formals is of a specific tagged type,
15971 -- the pragma is legal.
15973 if Is_Specific_Tagged_Type
(Etype
(Formal
)) then
15974 Has_OK_Formal
:= True;
15977 -- A generic subprogram with at least one formal of a private
15978 -- type ensures the legality of the pragma because the actual
15979 -- may be specifically tagged. Note that this is verified by
15980 -- the check above at instantiation time.
15982 elsif Is_Private_Type
(Etype
(Formal
))
15983 and then Is_Generic_Type
(Etype
(Formal
))
15985 Has_OK_Formal
:= True;
15989 Next_Formal
(Formal
);
15992 if not Has_OK_Formal
then
15993 Error_Msg_Name_1
:= Pname
;
15994 Error_Msg_N
(Fix_Error
("incorrect placement of pragma %"), N
);
15996 ("\subprogram & lacks parameter of specific tagged or "
15997 & "generic private type", N
, Spec_Id
);
16002 -- Analyze the Boolean expression (if any)
16004 if Present
(Arg1
) then
16005 Check_Static_Boolean_Expression
16006 (Expression
(Get_Argument
(N
, Spec_Id
)));
16008 end Extensions_Visible
;
16014 -- pragma External (
16015 -- [ Convention =>] convention_IDENTIFIER,
16016 -- [ Entity =>] LOCAL_NAME
16017 -- [, [External_Name =>] static_string_EXPRESSION ]
16018 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16020 when Pragma_External
=> External
: declare
16023 pragma Warnings
(Off
, C
);
16030 Name_External_Name
,
16032 Check_At_Least_N_Arguments
(2);
16033 Check_At_Most_N_Arguments
(4);
16034 Process_Convention
(C
, E
);
16036 -- A pragma that applies to a Ghost entity becomes Ghost for the
16037 -- purposes of legality checks and removal of ignored Ghost code.
16039 Mark_Ghost_Pragma
(N
, E
);
16041 Note_Possible_Modification
16042 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
16043 Process_Interface_Name
(E
, Arg3
, Arg4
, N
);
16044 Set_Exported
(E
, Arg2
);
16047 --------------------------
16048 -- External_Name_Casing --
16049 --------------------------
16051 -- pragma External_Name_Casing (
16052 -- UPPERCASE | LOWERCASE
16053 -- [, AS_IS | UPPERCASE | LOWERCASE]);
16055 when Pragma_External_Name_Casing
=>
16057 Check_No_Identifiers
;
16059 if Arg_Count
= 2 then
16060 Check_Arg_Is_One_Of
16061 (Arg2
, Name_As_Is
, Name_Uppercase
, Name_Lowercase
);
16063 case Chars
(Get_Pragma_Arg
(Arg2
)) is
16065 Opt
.External_Name_Exp_Casing
:= As_Is
;
16067 when Name_Uppercase
=>
16068 Opt
.External_Name_Exp_Casing
:= Uppercase
;
16070 when Name_Lowercase
=>
16071 Opt
.External_Name_Exp_Casing
:= Lowercase
;
16078 Check_Arg_Count
(1);
16081 Check_Arg_Is_One_Of
(Arg1
, Name_Uppercase
, Name_Lowercase
);
16083 case Chars
(Get_Pragma_Arg
(Arg1
)) is
16084 when Name_Uppercase
=>
16085 Opt
.External_Name_Imp_Casing
:= Uppercase
;
16087 when Name_Lowercase
=>
16088 Opt
.External_Name_Imp_Casing
:= Lowercase
;
16098 -- pragma Fast_Math;
16100 when Pragma_Fast_Math
=>
16102 Check_No_Identifiers
;
16103 Check_Valid_Configuration_Pragma
;
16106 --------------------------
16107 -- Favor_Top_Level --
16108 --------------------------
16110 -- pragma Favor_Top_Level (type_NAME);
16112 when Pragma_Favor_Top_Level
=> Favor_Top_Level
: declare
16117 Check_No_Identifiers
;
16118 Check_Arg_Count
(1);
16119 Check_Arg_Is_Local_Name
(Arg1
);
16120 Typ
:= Entity
(Get_Pragma_Arg
(Arg1
));
16122 -- A pragma that applies to a Ghost entity becomes Ghost for the
16123 -- purposes of legality checks and removal of ignored Ghost code.
16125 Mark_Ghost_Pragma
(N
, Typ
);
16127 -- If it's an access-to-subprogram type (in particular, not a
16128 -- subtype), set the flag on that type.
16130 if Is_Access_Subprogram_Type
(Typ
) then
16131 Set_Can_Use_Internal_Rep
(Typ
, False);
16133 -- Otherwise it's an error (name denotes the wrong sort of entity)
16137 ("access-to-subprogram type expected",
16138 Get_Pragma_Arg
(Arg1
));
16140 end Favor_Top_Level
;
16142 ---------------------------
16143 -- Finalize_Storage_Only --
16144 ---------------------------
16146 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16148 when Pragma_Finalize_Storage_Only
=> Finalize_Storage
: declare
16149 Assoc
: constant Node_Id
:= Arg1
;
16150 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
16155 Check_No_Identifiers
;
16156 Check_Arg_Count
(1);
16157 Check_Arg_Is_Local_Name
(Arg1
);
16159 Find_Type
(Type_Id
);
16160 Typ
:= Entity
(Type_Id
);
16163 or else Rep_Item_Too_Early
(Typ
, N
)
16167 Typ
:= Underlying_Type
(Typ
);
16170 if not Is_Controlled
(Typ
) then
16171 Error_Pragma
("pragma% must specify controlled type");
16174 Check_First_Subtype
(Arg1
);
16176 if Finalize_Storage_Only
(Typ
) then
16177 Error_Pragma
("duplicate pragma%, only one allowed");
16179 elsif not Rep_Item_Too_Late
(Typ
, N
) then
16180 Set_Finalize_Storage_Only
(Base_Type
(Typ
), True);
16182 end Finalize_Storage
;
16188 -- pragma Ghost [ (boolean_EXPRESSION) ];
16190 when Pragma_Ghost
=> Ghost
: declare
16194 Orig_Stmt
: Node_Id
;
16195 Prev_Id
: Entity_Id
;
16200 Check_No_Identifiers
;
16201 Check_At_Most_N_Arguments
(1);
16205 while Present
(Stmt
) loop
16207 -- Skip prior pragmas, but check for duplicates
16209 if Nkind
(Stmt
) = N_Pragma
then
16210 if Pragma_Name
(Stmt
) = Pname
then
16217 -- Task unit declared without a definition cannot be subject to
16218 -- pragma Ghost (SPARK RM 6.9(19)).
16220 elsif Nkind_In
(Stmt
, N_Single_Task_Declaration
,
16221 N_Task_Type_Declaration
)
16223 Error_Pragma
("pragma % cannot apply to a task type");
16226 -- Skip internally generated code
16228 elsif not Comes_From_Source
(Stmt
) then
16229 Orig_Stmt
:= Original_Node
(Stmt
);
16231 -- When pragma Ghost applies to an untagged derivation, the
16232 -- derivation is transformed into a [sub]type declaration.
16234 if Nkind_In
(Stmt
, N_Full_Type_Declaration
,
16235 N_Subtype_Declaration
)
16236 and then Comes_From_Source
(Orig_Stmt
)
16237 and then Nkind
(Orig_Stmt
) = N_Full_Type_Declaration
16238 and then Nkind
(Type_Definition
(Orig_Stmt
)) =
16239 N_Derived_Type_Definition
16241 Id
:= Defining_Entity
(Stmt
);
16244 -- When pragma Ghost applies to an object declaration which
16245 -- is initialized by means of a function call that returns
16246 -- on the secondary stack, the object declaration becomes a
16249 elsif Nkind
(Stmt
) = N_Object_Renaming_Declaration
16250 and then Comes_From_Source
(Orig_Stmt
)
16251 and then Nkind
(Orig_Stmt
) = N_Object_Declaration
16253 Id
:= Defining_Entity
(Stmt
);
16256 -- When pragma Ghost applies to an expression function, the
16257 -- expression function is transformed into a subprogram.
16259 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
16260 and then Comes_From_Source
(Orig_Stmt
)
16261 and then Nkind
(Orig_Stmt
) = N_Expression_Function
16263 Id
:= Defining_Entity
(Stmt
);
16267 -- The pragma applies to a legal construct, stop the traversal
16269 elsif Nkind_In
(Stmt
, N_Abstract_Subprogram_Declaration
,
16270 N_Full_Type_Declaration
,
16271 N_Generic_Subprogram_Declaration
,
16272 N_Object_Declaration
,
16273 N_Private_Extension_Declaration
,
16274 N_Private_Type_Declaration
,
16275 N_Subprogram_Declaration
,
16276 N_Subtype_Declaration
)
16278 Id
:= Defining_Entity
(Stmt
);
16281 -- The pragma does not apply to a legal construct, issue an
16282 -- error and stop the analysis.
16286 ("pragma % must apply to an object, package, subprogram "
16291 Stmt
:= Prev
(Stmt
);
16294 Context
:= Parent
(N
);
16296 -- Handle compilation units
16298 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
16299 Context
:= Unit
(Parent
(Context
));
16302 -- Protected and task types cannot be subject to pragma Ghost
16303 -- (SPARK RM 6.9(19)).
16305 if Nkind_In
(Context
, N_Protected_Body
, N_Protected_Definition
)
16307 Error_Pragma
("pragma % cannot apply to a protected type");
16310 elsif Nkind_In
(Context
, N_Task_Body
, N_Task_Definition
) then
16311 Error_Pragma
("pragma % cannot apply to a task type");
16317 -- When pragma Ghost is associated with a [generic] package, it
16318 -- appears in the visible declarations.
16320 if Nkind
(Context
) = N_Package_Specification
16321 and then Present
(Visible_Declarations
(Context
))
16322 and then List_Containing
(N
) = Visible_Declarations
(Context
)
16324 Id
:= Defining_Entity
(Context
);
16326 -- Pragma Ghost applies to a stand-alone subprogram body
16328 elsif Nkind
(Context
) = N_Subprogram_Body
16329 and then No
(Corresponding_Spec
(Context
))
16331 Id
:= Defining_Entity
(Context
);
16333 -- Pragma Ghost applies to a subprogram declaration that acts
16334 -- as a compilation unit.
16336 elsif Nkind
(Context
) = N_Subprogram_Declaration
then
16337 Id
:= Defining_Entity
(Context
);
16339 -- Pragma Ghost applies to a generic subprogram
16341 elsif Nkind
(Context
) = N_Generic_Subprogram_Declaration
then
16342 Id
:= Defining_Entity
(Specification
(Context
));
16348 ("pragma % must apply to an object, package, subprogram or "
16353 -- Handle completions of types and constants that are subject to
16356 if Is_Record_Type
(Id
) or else Ekind
(Id
) = E_Constant
then
16357 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
16359 if Present
(Prev_Id
) and then not Is_Ghost_Entity
(Prev_Id
) then
16360 Error_Msg_Name_1
:= Pname
;
16362 -- The full declaration of a deferred constant cannot be
16363 -- subject to pragma Ghost unless the deferred declaration
16364 -- is also Ghost (SPARK RM 6.9(9)).
16366 if Ekind
(Prev_Id
) = E_Constant
then
16367 Error_Msg_Name_1
:= Pname
;
16368 Error_Msg_NE
(Fix_Error
16369 ("pragma % must apply to declaration of deferred "
16370 & "constant &"), N
, Id
);
16373 -- Pragma Ghost may appear on the full view of an incomplete
16374 -- type because the incomplete declaration lacks aspects and
16375 -- cannot be subject to pragma Ghost.
16377 elsif Ekind
(Prev_Id
) = E_Incomplete_Type
then
16380 -- The full declaration of a type cannot be subject to
16381 -- pragma Ghost unless the partial view is also Ghost
16382 -- (SPARK RM 6.9(9)).
16385 Error_Msg_NE
(Fix_Error
16386 ("pragma % must apply to partial view of type &"),
16392 -- A synchronized object cannot be subject to pragma Ghost
16393 -- (SPARK RM 6.9(19)).
16395 elsif Ekind
(Id
) = E_Variable
then
16396 if Is_Protected_Type
(Etype
(Id
)) then
16397 Error_Pragma
("pragma % cannot apply to a protected object");
16400 elsif Is_Task_Type
(Etype
(Id
)) then
16401 Error_Pragma
("pragma % cannot apply to a task object");
16406 -- Analyze the Boolean expression (if any)
16408 if Present
(Arg1
) then
16409 Expr
:= Get_Pragma_Arg
(Arg1
);
16411 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
16413 if Is_OK_Static_Expression
(Expr
) then
16415 -- "Ghostness" cannot be turned off once enabled within a
16416 -- region (SPARK RM 6.9(6)).
16418 if Is_False
(Expr_Value
(Expr
))
16419 and then Ghost_Mode
> None
16422 ("pragma % with value False cannot appear in enabled "
16427 -- Otherwie the expression is not static
16431 ("expression of pragma % must be static", Expr
);
16436 Set_Is_Ghost_Entity
(Id
);
16443 -- pragma Global (GLOBAL_SPECIFICATION);
16445 -- GLOBAL_SPECIFICATION ::=
16448 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
16450 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
16452 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
16453 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
16454 -- GLOBAL_ITEM ::= NAME
16456 -- Characteristics:
16458 -- * Analysis - The annotation undergoes initial checks to verify
16459 -- the legal placement and context. Secondary checks fully analyze
16460 -- the dependency clauses in:
16462 -- Analyze_Global_In_Decl_Part
16464 -- * Expansion - None.
16466 -- * Template - The annotation utilizes the generic template of the
16467 -- related subprogram [body] when it is:
16469 -- aspect on subprogram declaration
16470 -- aspect on stand-alone subprogram body
16471 -- pragma on stand-alone subprogram body
16473 -- The annotation must prepare its own template when it is:
16475 -- pragma on subprogram declaration
16477 -- * Globals - Capture of global references must occur after full
16480 -- * Instance - The annotation is instantiated automatically when
16481 -- the related generic subprogram [body] is instantiated except for
16482 -- the "pragma on subprogram declaration" case. In that scenario
16483 -- the annotation must instantiate itself.
16485 when Pragma_Global
=> Global
: declare
16487 Spec_Id
: Entity_Id
;
16488 Subp_Decl
: Node_Id
;
16491 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
16495 -- Chain the pragma on the contract for further processing by
16496 -- Analyze_Global_In_Decl_Part.
16498 Add_Contract_Item
(N
, Spec_Id
);
16500 -- Fully analyze the pragma when it appears inside an entry
16501 -- or subprogram body because it cannot benefit from forward
16504 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
16506 N_Subprogram_Body_Stub
)
16508 -- The legality checks of pragmas Depends and Global are
16509 -- affected by the SPARK mode in effect and the volatility
16510 -- of the context. In addition these two pragmas are subject
16511 -- to an inherent order:
16516 -- Analyze all these pragmas in the order outlined above
16518 Analyze_If_Present
(Pragma_SPARK_Mode
);
16519 Analyze_If_Present
(Pragma_Volatile_Function
);
16520 Analyze_Global_In_Decl_Part
(N
);
16521 Analyze_If_Present
(Pragma_Depends
);
16530 -- pragma Ident (static_string_EXPRESSION)
16532 -- Note: pragma Comment shares this processing. Pragma Ident is
16533 -- identical in effect to pragma Commment.
16535 when Pragma_Comment
16543 Check_Arg_Count
(1);
16544 Check_No_Identifiers
;
16545 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16548 Str
:= Expr_Value_S
(Get_Pragma_Arg
(Arg1
));
16555 GP
:= Parent
(Parent
(N
));
16557 if Nkind_In
(GP
, N_Package_Declaration
,
16558 N_Generic_Package_Declaration
)
16563 -- If we have a compilation unit, then record the ident value,
16564 -- checking for improper duplication.
16566 if Nkind
(GP
) = N_Compilation_Unit
then
16567 CS
:= Ident_String
(Current_Sem_Unit
);
16569 if Present
(CS
) then
16571 -- If we have multiple instances, concatenate them, but
16572 -- not in ASIS, where we want the original tree.
16574 if not ASIS_Mode
then
16575 Start_String
(Strval
(CS
));
16576 Store_String_Char
(' ');
16577 Store_String_Chars
(Strval
(Str
));
16578 Set_Strval
(CS
, End_String
);
16582 Set_Ident_String
(Current_Sem_Unit
, Str
);
16585 -- For subunits, we just ignore the Ident, since in GNAT these
16586 -- are not separate object files, and hence not separate units
16587 -- in the unit table.
16589 elsif Nkind
(GP
) = N_Subunit
then
16595 -------------------
16596 -- Ignore_Pragma --
16597 -------------------
16599 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
16601 -- Entirely handled in the parser, nothing to do here
16603 when Pragma_Ignore_Pragma
=>
16606 ----------------------------
16607 -- Implementation_Defined --
16608 ----------------------------
16610 -- pragma Implementation_Defined (LOCAL_NAME);
16612 -- Marks previously declared entity as implementation defined. For
16613 -- an overloaded entity, applies to the most recent homonym.
16615 -- pragma Implementation_Defined;
16617 -- The form with no arguments appears anywhere within a scope, most
16618 -- typically a package spec, and indicates that all entities that are
16619 -- defined within the package spec are Implementation_Defined.
16621 when Pragma_Implementation_Defined
=> Implementation_Defined
: declare
16626 Check_No_Identifiers
;
16628 -- Form with no arguments
16630 if Arg_Count
= 0 then
16631 Set_Is_Implementation_Defined
(Current_Scope
);
16633 -- Form with one argument
16636 Check_Arg_Count
(1);
16637 Check_Arg_Is_Local_Name
(Arg1
);
16638 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
16639 Set_Is_Implementation_Defined
(Ent
);
16641 end Implementation_Defined
;
16647 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
16649 -- IMPLEMENTATION_KIND ::=
16650 -- By_Entry | By_Protected_Procedure | By_Any | Optional
16652 -- "By_Any" and "Optional" are treated as synonyms in order to
16653 -- support Ada 2012 aspect Synchronization.
16655 when Pragma_Implemented
=> Implemented
: declare
16656 Proc_Id
: Entity_Id
;
16661 Check_Arg_Count
(2);
16662 Check_No_Identifiers
;
16663 Check_Arg_Is_Identifier
(Arg1
);
16664 Check_Arg_Is_Local_Name
(Arg1
);
16665 Check_Arg_Is_One_Of
(Arg2
,
16668 Name_By_Protected_Procedure
,
16671 -- Extract the name of the local procedure
16673 Proc_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
16675 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
16676 -- primitive procedure of a synchronized tagged type.
16678 if Ekind
(Proc_Id
) = E_Procedure
16679 and then Is_Primitive
(Proc_Id
)
16680 and then Present
(First_Formal
(Proc_Id
))
16682 Typ
:= Etype
(First_Formal
(Proc_Id
));
16684 if Is_Tagged_Type
(Typ
)
16687 -- Check for a protected, a synchronized or a task interface
16689 ((Is_Interface
(Typ
)
16690 and then Is_Synchronized_Interface
(Typ
))
16692 -- Check for a protected type or a task type that implements
16696 (Is_Concurrent_Record_Type
(Typ
)
16697 and then Present
(Interfaces
(Typ
)))
16699 -- In analysis-only mode, examine original protected type
16702 (Nkind
(Parent
(Typ
)) = N_Protected_Type_Declaration
16703 and then Present
(Interface_List
(Parent
(Typ
))))
16705 -- Check for a private record extension with keyword
16709 (Ekind_In
(Typ
, E_Record_Type_With_Private
,
16710 E_Record_Subtype_With_Private
)
16711 and then Synchronized_Present
(Parent
(Typ
))))
16716 ("controlling formal must be of synchronized tagged type",
16721 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
16722 -- By_Protected_Procedure to the primitive procedure of a task
16725 if Chars
(Arg2
) = Name_By_Protected_Procedure
16726 and then Is_Interface
(Typ
)
16727 and then Is_Task_Interface
(Typ
)
16730 ("implementation kind By_Protected_Procedure cannot be "
16731 & "applied to a task interface primitive", Arg2
);
16735 -- Procedures declared inside a protected type must be accepted
16737 elsif Ekind
(Proc_Id
) = E_Procedure
16738 and then Is_Protected_Type
(Scope
(Proc_Id
))
16742 -- The first argument is not a primitive procedure
16746 ("pragma % must be applied to a primitive procedure", Arg1
);
16750 Record_Rep_Item
(Proc_Id
, N
);
16753 ----------------------
16754 -- Implicit_Packing --
16755 ----------------------
16757 -- pragma Implicit_Packing;
16759 when Pragma_Implicit_Packing
=>
16761 Check_Arg_Count
(0);
16762 Implicit_Packing
:= True;
16769 -- [Convention =>] convention_IDENTIFIER,
16770 -- [Entity =>] LOCAL_NAME
16771 -- [, [External_Name =>] static_string_EXPRESSION ]
16772 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16774 when Pragma_Import
=>
16775 Check_Ada_83_Warning
;
16779 Name_External_Name
,
16782 Check_At_Least_N_Arguments
(2);
16783 Check_At_Most_N_Arguments
(4);
16784 Process_Import_Or_Interface
;
16786 ---------------------
16787 -- Import_Function --
16788 ---------------------
16790 -- pragma Import_Function (
16791 -- [Internal =>] LOCAL_NAME,
16792 -- [, [External =>] EXTERNAL_SYMBOL]
16793 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16794 -- [, [Result_Type =>] SUBTYPE_MARK]
16795 -- [, [Mechanism =>] MECHANISM]
16796 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16798 -- EXTERNAL_SYMBOL ::=
16800 -- | static_string_EXPRESSION
16802 -- PARAMETER_TYPES ::=
16804 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16806 -- TYPE_DESIGNATOR ::=
16808 -- | subtype_Name ' Access
16812 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16814 -- MECHANISM_ASSOCIATION ::=
16815 -- [formal_parameter_NAME =>] MECHANISM_NAME
16817 -- MECHANISM_NAME ::=
16821 when Pragma_Import_Function
=> Import_Function
: declare
16822 Args
: Args_List
(1 .. 6);
16823 Names
: constant Name_List
(1 .. 6) := (
16826 Name_Parameter_Types
,
16829 Name_Result_Mechanism
);
16831 Internal
: Node_Id
renames Args
(1);
16832 External
: Node_Id
renames Args
(2);
16833 Parameter_Types
: Node_Id
renames Args
(3);
16834 Result_Type
: Node_Id
renames Args
(4);
16835 Mechanism
: Node_Id
renames Args
(5);
16836 Result_Mechanism
: Node_Id
renames Args
(6);
16840 Gather_Associations
(Names
, Args
);
16841 Process_Extended_Import_Export_Subprogram_Pragma
(
16842 Arg_Internal
=> Internal
,
16843 Arg_External
=> External
,
16844 Arg_Parameter_Types
=> Parameter_Types
,
16845 Arg_Result_Type
=> Result_Type
,
16846 Arg_Mechanism
=> Mechanism
,
16847 Arg_Result_Mechanism
=> Result_Mechanism
);
16848 end Import_Function
;
16850 -------------------
16851 -- Import_Object --
16852 -------------------
16854 -- pragma Import_Object (
16855 -- [Internal =>] LOCAL_NAME
16856 -- [, [External =>] EXTERNAL_SYMBOL]
16857 -- [, [Size =>] EXTERNAL_SYMBOL]);
16859 -- EXTERNAL_SYMBOL ::=
16861 -- | static_string_EXPRESSION
16863 when Pragma_Import_Object
=> Import_Object
: declare
16864 Args
: Args_List
(1 .. 3);
16865 Names
: constant Name_List
(1 .. 3) := (
16870 Internal
: Node_Id
renames Args
(1);
16871 External
: Node_Id
renames Args
(2);
16872 Size
: Node_Id
renames Args
(3);
16876 Gather_Associations
(Names
, Args
);
16877 Process_Extended_Import_Export_Object_Pragma
(
16878 Arg_Internal
=> Internal
,
16879 Arg_External
=> External
,
16883 ----------------------
16884 -- Import_Procedure --
16885 ----------------------
16887 -- pragma Import_Procedure (
16888 -- [Internal =>] LOCAL_NAME
16889 -- [, [External =>] EXTERNAL_SYMBOL]
16890 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16891 -- [, [Mechanism =>] MECHANISM]);
16893 -- EXTERNAL_SYMBOL ::=
16895 -- | static_string_EXPRESSION
16897 -- PARAMETER_TYPES ::=
16899 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16901 -- TYPE_DESIGNATOR ::=
16903 -- | subtype_Name ' Access
16907 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16909 -- MECHANISM_ASSOCIATION ::=
16910 -- [formal_parameter_NAME =>] MECHANISM_NAME
16912 -- MECHANISM_NAME ::=
16916 when Pragma_Import_Procedure
=> Import_Procedure
: declare
16917 Args
: Args_List
(1 .. 4);
16918 Names
: constant Name_List
(1 .. 4) := (
16921 Name_Parameter_Types
,
16924 Internal
: Node_Id
renames Args
(1);
16925 External
: Node_Id
renames Args
(2);
16926 Parameter_Types
: Node_Id
renames Args
(3);
16927 Mechanism
: Node_Id
renames Args
(4);
16931 Gather_Associations
(Names
, Args
);
16932 Process_Extended_Import_Export_Subprogram_Pragma
(
16933 Arg_Internal
=> Internal
,
16934 Arg_External
=> External
,
16935 Arg_Parameter_Types
=> Parameter_Types
,
16936 Arg_Mechanism
=> Mechanism
);
16937 end Import_Procedure
;
16939 -----------------------------
16940 -- Import_Valued_Procedure --
16941 -----------------------------
16943 -- pragma Import_Valued_Procedure (
16944 -- [Internal =>] LOCAL_NAME
16945 -- [, [External =>] EXTERNAL_SYMBOL]
16946 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16947 -- [, [Mechanism =>] MECHANISM]);
16949 -- EXTERNAL_SYMBOL ::=
16951 -- | static_string_EXPRESSION
16953 -- PARAMETER_TYPES ::=
16955 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16957 -- TYPE_DESIGNATOR ::=
16959 -- | subtype_Name ' Access
16963 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16965 -- MECHANISM_ASSOCIATION ::=
16966 -- [formal_parameter_NAME =>] MECHANISM_NAME
16968 -- MECHANISM_NAME ::=
16972 when Pragma_Import_Valued_Procedure
=>
16973 Import_Valued_Procedure
: declare
16974 Args
: Args_List
(1 .. 4);
16975 Names
: constant Name_List
(1 .. 4) := (
16978 Name_Parameter_Types
,
16981 Internal
: Node_Id
renames Args
(1);
16982 External
: Node_Id
renames Args
(2);
16983 Parameter_Types
: Node_Id
renames Args
(3);
16984 Mechanism
: Node_Id
renames Args
(4);
16988 Gather_Associations
(Names
, Args
);
16989 Process_Extended_Import_Export_Subprogram_Pragma
(
16990 Arg_Internal
=> Internal
,
16991 Arg_External
=> External
,
16992 Arg_Parameter_Types
=> Parameter_Types
,
16993 Arg_Mechanism
=> Mechanism
);
16994 end Import_Valued_Procedure
;
17000 -- pragma Independent (LOCAL_NAME);
17002 when Pragma_Independent
=>
17003 Process_Atomic_Independent_Shared_Volatile
;
17005 ----------------------------
17006 -- Independent_Components --
17007 ----------------------------
17009 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
17011 when Pragma_Independent_Components
=> Independent_Components
: declare
17019 Check_Ada_83_Warning
;
17021 Check_No_Identifiers
;
17022 Check_Arg_Count
(1);
17023 Check_Arg_Is_Local_Name
(Arg1
);
17024 E_Id
:= Get_Pragma_Arg
(Arg1
);
17026 if Etype
(E_Id
) = Any_Type
then
17030 E
:= Entity
(E_Id
);
17032 -- A record type with a self-referential component of anonymous
17033 -- access type is given an incomplete view in order to handle the
17036 -- type Rec is record
17037 -- Self : access Rec;
17043 -- type Ptr is access Rec;
17044 -- type Rec is record
17048 -- Since the incomplete view is now the initial view of the type,
17049 -- the argument of the pragma will reference the incomplete view,
17050 -- but this view is illegal according to the semantics of the
17053 -- Obtain the full view of an internally-generated incomplete type
17054 -- only. This way an attempt to associate the pragma with a source
17055 -- incomplete type is still caught.
17057 if Ekind
(E
) = E_Incomplete_Type
17058 and then not Comes_From_Source
(E
)
17059 and then Present
(Full_View
(E
))
17061 E
:= Full_View
(E
);
17064 -- A pragma that applies to a Ghost entity becomes Ghost for the
17065 -- purposes of legality checks and removal of ignored Ghost code.
17067 Mark_Ghost_Pragma
(N
, E
);
17069 -- Check duplicate before we chain ourselves
17071 Check_Duplicate_Pragma
(E
);
17073 -- Check appropriate entity
17075 if Rep_Item_Too_Early
(E
, N
)
17077 Rep_Item_Too_Late
(E
, N
)
17082 D
:= Declaration_Node
(E
);
17085 -- The flag is set on the base type, or on the object
17087 if K
= N_Full_Type_Declaration
17088 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
17090 Set_Has_Independent_Components
(Base_Type
(E
));
17091 Record_Independence_Check
(N
, Base_Type
(E
));
17093 -- For record type, set all components independent
17095 if Is_Record_Type
(E
) then
17096 C
:= First_Component
(E
);
17097 while Present
(C
) loop
17098 Set_Is_Independent
(C
);
17099 Next_Component
(C
);
17103 elsif (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
17104 and then Nkind
(D
) = N_Object_Declaration
17105 and then Nkind
(Object_Definition
(D
)) =
17106 N_Constrained_Array_Definition
17108 Set_Has_Independent_Components
(E
);
17109 Record_Independence_Check
(N
, E
);
17112 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
17114 end Independent_Components
;
17116 -----------------------
17117 -- Initial_Condition --
17118 -----------------------
17120 -- pragma Initial_Condition (boolean_EXPRESSION);
17122 -- Characteristics:
17124 -- * Analysis - The annotation undergoes initial checks to verify
17125 -- the legal placement and context. Secondary checks preanalyze the
17128 -- Analyze_Initial_Condition_In_Decl_Part
17130 -- * Expansion - The annotation is expanded during the expansion of
17131 -- the package body whose declaration is subject to the annotation
17134 -- Expand_Pragma_Initial_Condition
17136 -- * Template - The annotation utilizes the generic template of the
17137 -- related package declaration.
17139 -- * Globals - Capture of global references must occur after full
17142 -- * Instance - The annotation is instantiated automatically when
17143 -- the related generic package is instantiated.
17145 when Pragma_Initial_Condition
=> Initial_Condition
: declare
17146 Pack_Decl
: Node_Id
;
17147 Pack_Id
: Entity_Id
;
17151 Check_No_Identifiers
;
17152 Check_Arg_Count
(1);
17154 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
17156 if not Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
17157 N_Package_Declaration
)
17163 Pack_Id
:= Defining_Entity
(Pack_Decl
);
17165 -- A pragma that applies to a Ghost entity becomes Ghost for the
17166 -- purposes of legality checks and removal of ignored Ghost code.
17168 Mark_Ghost_Pragma
(N
, Pack_Id
);
17170 -- Chain the pragma on the contract for further processing by
17171 -- Analyze_Initial_Condition_In_Decl_Part.
17173 Add_Contract_Item
(N
, Pack_Id
);
17175 -- The legality checks of pragmas Abstract_State, Initializes, and
17176 -- Initial_Condition are affected by the SPARK mode in effect. In
17177 -- addition, these three pragmas are subject to an inherent order:
17179 -- 1) Abstract_State
17181 -- 3) Initial_Condition
17183 -- Analyze all these pragmas in the order outlined above
17185 Analyze_If_Present
(Pragma_SPARK_Mode
);
17186 Analyze_If_Present
(Pragma_Abstract_State
);
17187 Analyze_If_Present
(Pragma_Initializes
);
17188 end Initial_Condition
;
17190 ------------------------
17191 -- Initialize_Scalars --
17192 ------------------------
17194 -- pragma Initialize_Scalars
17195 -- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ];
17197 -- TYPE_VALUE_PAIR ::=
17198 -- SCALAR_TYPE => static_EXPRESSION
17204 -- | Long_Long_Flat
17214 when Pragma_Initialize_Scalars
=> Do_Initialize_Scalars
: declare
17215 Seen
: array (Scalar_Id
) of Node_Id
:= (others => Empty
);
17216 -- This collection holds the individual pairs which specify the
17217 -- invalid values of their respective scalar types.
17219 procedure Analyze_Float_Value
17220 (Scal_Typ
: Float_Scalar_Id
;
17221 Val_Expr
: Node_Id
);
17222 -- Analyze a type value pair associated with float type Scal_Typ
17223 -- and expression Val_Expr.
17225 procedure Analyze_Integer_Value
17226 (Scal_Typ
: Integer_Scalar_Id
;
17227 Val_Expr
: Node_Id
);
17228 -- Analyze a type value pair associated with integer type Scal_Typ
17229 -- and expression Val_Expr.
17231 procedure Analyze_Type_Value_Pair
(Pair
: Node_Id
);
17232 -- Analyze type value pair Pair
17234 -------------------------
17235 -- Analyze_Float_Value --
17236 -------------------------
17238 procedure Analyze_Float_Value
17239 (Scal_Typ
: Float_Scalar_Id
;
17240 Val_Expr
: Node_Id
)
17243 Analyze_And_Resolve
(Val_Expr
, Any_Real
);
17245 if Is_OK_Static_Expression
(Val_Expr
) then
17246 Set_Invalid_Scalar_Value
(Scal_Typ
, Expr_Value_R
(Val_Expr
));
17249 Error_Msg_Name_1
:= Scal_Typ
;
17250 Error_Msg_N
("value for type % must be static", Val_Expr
);
17252 end Analyze_Float_Value
;
17254 ---------------------------
17255 -- Analyze_Integer_Value --
17256 ---------------------------
17258 procedure Analyze_Integer_Value
17259 (Scal_Typ
: Integer_Scalar_Id
;
17260 Val_Expr
: Node_Id
)
17263 Analyze_And_Resolve
(Val_Expr
, Any_Integer
);
17265 if Is_OK_Static_Expression
(Val_Expr
) then
17266 Set_Invalid_Scalar_Value
(Scal_Typ
, Expr_Value
(Val_Expr
));
17269 Error_Msg_Name_1
:= Scal_Typ
;
17270 Error_Msg_N
("value for type % must be static", Val_Expr
);
17272 end Analyze_Integer_Value
;
17274 -----------------------------
17275 -- Analyze_Type_Value_Pair --
17276 -----------------------------
17278 procedure Analyze_Type_Value_Pair
(Pair
: Node_Id
) is
17279 Scal_Typ
: constant Name_Id
:= Chars
(Pair
);
17280 Val_Expr
: constant Node_Id
:= Expression
(Pair
);
17281 Prev_Pair
: Node_Id
;
17284 if Scal_Typ
in Scalar_Id
then
17285 Prev_Pair
:= Seen
(Scal_Typ
);
17287 -- Prevent multiple attempts to set a value for a scalar
17290 if Present
(Prev_Pair
) then
17291 Error_Msg_Name_1
:= Scal_Typ
;
17293 ("cannot specify multiple invalid values for type %",
17296 Error_Msg_Sloc
:= Sloc
(Prev_Pair
);
17297 Error_Msg_N
("previous value set #", Pair
);
17299 -- Ignore the effects of the pair, but do not halt the
17300 -- analysis of the pragma altogether.
17304 -- Otherwise capture the first pair for this scalar type
17307 Seen
(Scal_Typ
) := Pair
;
17310 if Scal_Typ
in Float_Scalar_Id
then
17311 Analyze_Float_Value
(Scal_Typ
, Val_Expr
);
17313 else pragma Assert
(Scal_Typ
in Integer_Scalar_Id
);
17314 Analyze_Integer_Value
(Scal_Typ
, Val_Expr
);
17317 -- Otherwise the scalar family is illegal
17320 Error_Msg_Name_1
:= Pname
;
17322 ("argument of pragma % must denote valid scalar family",
17325 end Analyze_Type_Value_Pair
;
17329 Pairs
: constant List_Id
:= Pragma_Argument_Associations
(N
);
17332 -- Start of processing for Do_Initialize_Scalars
17336 Check_Valid_Configuration_Pragma
;
17337 Check_Restriction
(No_Initialize_Scalars
, N
);
17339 -- Ignore the effects of the pragma when No_Initialize_Scalars is
17342 if Restriction_Active
(No_Initialize_Scalars
) then
17345 -- Initialize_Scalars creates false positives in CodePeer, and
17346 -- incorrect negative results in GNATprove mode, so ignore this
17347 -- pragma in these modes.
17349 elsif CodePeer_Mode
or GNATprove_Mode
then
17352 -- Otherwise analyze the pragma
17355 if Present
(Pairs
) then
17357 -- Install Standard in order to provide access to primitive
17358 -- types in case the expressions contain attributes such as
17361 Push_Scope
(Standard_Standard
);
17363 Pair
:= First
(Pairs
);
17364 while Present
(Pair
) loop
17365 Analyze_Type_Value_Pair
(Pair
);
17374 Init_Or_Norm_Scalars
:= True;
17375 Initialize_Scalars
:= True;
17377 end Do_Initialize_Scalars
;
17383 -- pragma Initializes (INITIALIZATION_LIST);
17385 -- INITIALIZATION_LIST ::=
17387 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
17389 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
17394 -- | (INPUT {, INPUT})
17398 -- Characteristics:
17400 -- * Analysis - The annotation undergoes initial checks to verify
17401 -- the legal placement and context. Secondary checks preanalyze the
17404 -- Analyze_Initializes_In_Decl_Part
17406 -- * Expansion - None.
17408 -- * Template - The annotation utilizes the generic template of the
17409 -- related package declaration.
17411 -- * Globals - Capture of global references must occur after full
17414 -- * Instance - The annotation is instantiated automatically when
17415 -- the related generic package is instantiated.
17417 when Pragma_Initializes
=> Initializes
: declare
17418 Pack_Decl
: Node_Id
;
17419 Pack_Id
: Entity_Id
;
17423 Check_No_Identifiers
;
17424 Check_Arg_Count
(1);
17426 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
17428 if not Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
17429 N_Package_Declaration
)
17435 Pack_Id
:= Defining_Entity
(Pack_Decl
);
17437 -- A pragma that applies to a Ghost entity becomes Ghost for the
17438 -- purposes of legality checks and removal of ignored Ghost code.
17440 Mark_Ghost_Pragma
(N
, Pack_Id
);
17441 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
17443 -- Chain the pragma on the contract for further processing by
17444 -- Analyze_Initializes_In_Decl_Part.
17446 Add_Contract_Item
(N
, Pack_Id
);
17448 -- The legality checks of pragmas Abstract_State, Initializes, and
17449 -- Initial_Condition are affected by the SPARK mode in effect. In
17450 -- addition, these three pragmas are subject to an inherent order:
17452 -- 1) Abstract_State
17454 -- 3) Initial_Condition
17456 -- Analyze all these pragmas in the order outlined above
17458 Analyze_If_Present
(Pragma_SPARK_Mode
);
17459 Analyze_If_Present
(Pragma_Abstract_State
);
17460 Analyze_If_Present
(Pragma_Initial_Condition
);
17467 -- pragma Inline ( NAME {, NAME} );
17469 when Pragma_Inline
=>
17471 -- Pragma always active unless in GNATprove mode. It is disabled
17472 -- in GNATprove mode because frontend inlining is applied
17473 -- independently of pragmas Inline and Inline_Always for
17474 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
17477 if not GNATprove_Mode
then
17479 -- Inline status is Enabled if option -gnatn is specified.
17480 -- However this status determines only the value of the
17481 -- Is_Inlined flag on the subprogram and does not prevent
17482 -- the pragma itself from being recorded for later use,
17483 -- in particular for a later modification of Is_Inlined
17484 -- independently of the -gnatn option.
17486 -- In other words, if -gnatn is specified for a unit, then
17487 -- all Inline pragmas processed for the compilation of this
17488 -- unit, including those in the spec of other units, are
17489 -- activated, so subprograms will be inlined across units.
17491 -- If -gnatn is not specified, no Inline pragma is activated
17492 -- here, which means that subprograms will not be inlined
17493 -- across units. The Is_Inlined flag will nevertheless be
17494 -- set later when bodies are analyzed, so subprograms will
17495 -- be inlined within the unit.
17497 if Inline_Active
then
17498 Process_Inline
(Enabled
);
17500 Process_Inline
(Disabled
);
17504 -------------------
17505 -- Inline_Always --
17506 -------------------
17508 -- pragma Inline_Always ( NAME {, NAME} );
17510 when Pragma_Inline_Always
=>
17513 -- Pragma always active unless in CodePeer mode or GNATprove
17514 -- mode. It is disabled in CodePeer mode because inlining is
17515 -- not helpful, and enabling it caused walk order issues. It
17516 -- is disabled in GNATprove mode because frontend inlining is
17517 -- applied independently of pragmas Inline and Inline_Always for
17518 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
17521 if not CodePeer_Mode
and not GNATprove_Mode
then
17522 Process_Inline
(Enabled
);
17525 --------------------
17526 -- Inline_Generic --
17527 --------------------
17529 -- pragma Inline_Generic (NAME {, NAME});
17531 when Pragma_Inline_Generic
=>
17533 Process_Generic_List
;
17535 ----------------------
17536 -- Inspection_Point --
17537 ----------------------
17539 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
17541 when Pragma_Inspection_Point
=> Inspection_Point
: declare
17548 if Arg_Count
> 0 then
17551 Exp
:= Get_Pragma_Arg
(Arg
);
17554 if not Is_Entity_Name
(Exp
)
17555 or else not Is_Object
(Entity
(Exp
))
17557 Error_Pragma_Arg
("object name required", Arg
);
17561 exit when No
(Arg
);
17564 end Inspection_Point
;
17570 -- pragma Interface (
17571 -- [ Convention =>] convention_IDENTIFIER,
17572 -- [ Entity =>] LOCAL_NAME
17573 -- [, [External_Name =>] static_string_EXPRESSION ]
17574 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17576 when Pragma_Interface
=>
17581 Name_External_Name
,
17583 Check_At_Least_N_Arguments
(2);
17584 Check_At_Most_N_Arguments
(4);
17585 Process_Import_Or_Interface
;
17587 -- In Ada 2005, the permission to use Interface (a reserved word)
17588 -- as a pragma name is considered an obsolescent feature, and this
17589 -- pragma was already obsolescent in Ada 95.
17591 if Ada_Version
>= Ada_95
then
17593 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
17595 if Warn_On_Obsolescent_Feature
then
17597 ("pragma Interface is an obsolescent feature?j?", N
);
17599 ("|use pragma Import instead?j?", N
);
17603 --------------------
17604 -- Interface_Name --
17605 --------------------
17607 -- pragma Interface_Name (
17608 -- [ Entity =>] LOCAL_NAME
17609 -- [,[External_Name =>] static_string_EXPRESSION ]
17610 -- [,[Link_Name =>] static_string_EXPRESSION ]);
17612 when Pragma_Interface_Name
=> Interface_Name
: declare
17614 Def_Id
: Entity_Id
;
17615 Hom_Id
: Entity_Id
;
17621 ((Name_Entity
, Name_External_Name
, Name_Link_Name
));
17622 Check_At_Least_N_Arguments
(2);
17623 Check_At_Most_N_Arguments
(3);
17624 Id
:= Get_Pragma_Arg
(Arg1
);
17627 -- This is obsolete from Ada 95 on, but it is an implementation
17628 -- defined pragma, so we do not consider that it violates the
17629 -- restriction (No_Obsolescent_Features).
17631 if Ada_Version
>= Ada_95
then
17632 if Warn_On_Obsolescent_Feature
then
17634 ("pragma Interface_Name is an obsolescent feature?j?", N
);
17636 ("|use pragma Import instead?j?", N
);
17640 if not Is_Entity_Name
(Id
) then
17642 ("first argument for pragma% must be entity name", Arg1
);
17643 elsif Etype
(Id
) = Any_Type
then
17646 Def_Id
:= Entity
(Id
);
17649 -- Special DEC-compatible processing for the object case, forces
17650 -- object to be imported.
17652 if Ekind
(Def_Id
) = E_Variable
then
17653 Kill_Size_Check_Code
(Def_Id
);
17654 Note_Possible_Modification
(Id
, Sure
=> False);
17656 -- Initialization is not allowed for imported variable
17658 if Present
(Expression
(Parent
(Def_Id
)))
17659 and then Comes_From_Source
(Expression
(Parent
(Def_Id
)))
17661 Error_Msg_Sloc
:= Sloc
(Def_Id
);
17663 ("no initialization allowed for declaration of& #",
17667 -- For compatibility, support VADS usage of providing both
17668 -- pragmas Interface and Interface_Name to obtain the effect
17669 -- of a single Import pragma.
17671 if Is_Imported
(Def_Id
)
17672 and then Present
(First_Rep_Item
(Def_Id
))
17673 and then Nkind
(First_Rep_Item
(Def_Id
)) = N_Pragma
17674 and then Pragma_Name
(First_Rep_Item
(Def_Id
)) =
17679 Set_Imported
(Def_Id
);
17682 Set_Is_Public
(Def_Id
);
17683 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
17686 -- Otherwise must be subprogram
17688 elsif not Is_Subprogram
(Def_Id
) then
17690 ("argument of pragma% is not subprogram", Arg1
);
17693 Check_At_Most_N_Arguments
(3);
17697 -- Loop through homonyms
17700 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
17702 if Is_Imported
(Def_Id
) then
17703 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
17707 exit when From_Aspect_Specification
(N
);
17708 Hom_Id
:= Homonym
(Hom_Id
);
17710 exit when No
(Hom_Id
)
17711 or else Scope
(Hom_Id
) /= Current_Scope
;
17716 ("argument of pragma% is not imported subprogram",
17720 end Interface_Name
;
17722 -----------------------
17723 -- Interrupt_Handler --
17724 -----------------------
17726 -- pragma Interrupt_Handler (handler_NAME);
17728 when Pragma_Interrupt_Handler
=>
17729 Check_Ada_83_Warning
;
17730 Check_Arg_Count
(1);
17731 Check_No_Identifiers
;
17733 if No_Run_Time_Mode
then
17734 Error_Msg_CRT
("Interrupt_Handler pragma", N
);
17736 Check_Interrupt_Or_Attach_Handler
;
17737 Process_Interrupt_Or_Attach_Handler
;
17740 ------------------------
17741 -- Interrupt_Priority --
17742 ------------------------
17744 -- pragma Interrupt_Priority [(EXPRESSION)];
17746 when Pragma_Interrupt_Priority
=> Interrupt_Priority
: declare
17747 P
: constant Node_Id
:= Parent
(N
);
17752 Check_Ada_83_Warning
;
17754 if Arg_Count
/= 0 then
17755 Arg
:= Get_Pragma_Arg
(Arg1
);
17756 Check_Arg_Count
(1);
17757 Check_No_Identifiers
;
17759 -- The expression must be analyzed in the special manner
17760 -- described in "Handling of Default and Per-Object
17761 -- Expressions" in sem.ads.
17763 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Interrupt_Priority
));
17766 if not Nkind_In
(P
, N_Task_Definition
, N_Protected_Definition
) then
17771 Ent
:= Defining_Identifier
(Parent
(P
));
17773 -- Check duplicate pragma before we chain the pragma in the Rep
17774 -- Item chain of Ent.
17776 Check_Duplicate_Pragma
(Ent
);
17777 Record_Rep_Item
(Ent
, N
);
17779 -- Check the No_Task_At_Interrupt_Priority restriction
17781 if Nkind
(P
) = N_Task_Definition
then
17782 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
17785 end Interrupt_Priority
;
17787 ---------------------
17788 -- Interrupt_State --
17789 ---------------------
17791 -- pragma Interrupt_State (
17792 -- [Name =>] INTERRUPT_ID,
17793 -- [State =>] INTERRUPT_STATE);
17795 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
17796 -- INTERRUPT_STATE => System | Runtime | User
17798 -- Note: if the interrupt id is given as an identifier, then it must
17799 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
17800 -- given as a static integer expression which must be in the range of
17801 -- Ada.Interrupts.Interrupt_ID.
17803 when Pragma_Interrupt_State
=> Interrupt_State
: declare
17804 Int_Id
: constant Entity_Id
:= RTE
(RE_Interrupt_ID
);
17805 -- This is the entity Ada.Interrupts.Interrupt_ID;
17807 State_Type
: Character;
17808 -- Set to 's'/'r'/'u' for System/Runtime/User
17811 -- Index to entry in Interrupt_States table
17814 -- Value of interrupt
17816 Arg1X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
17817 -- The first argument to the pragma
17819 Int_Ent
: Entity_Id
;
17820 -- Interrupt entity in Ada.Interrupts.Names
17824 Check_Arg_Order
((Name_Name
, Name_State
));
17825 Check_Arg_Count
(2);
17827 Check_Optional_Identifier
(Arg1
, Name_Name
);
17828 Check_Optional_Identifier
(Arg2
, Name_State
);
17829 Check_Arg_Is_Identifier
(Arg2
);
17831 -- First argument is identifier
17833 if Nkind
(Arg1X
) = N_Identifier
then
17835 -- Search list of names in Ada.Interrupts.Names
17837 Int_Ent
:= First_Entity
(RTE
(RE_Names
));
17839 if No
(Int_Ent
) then
17840 Error_Pragma_Arg
("invalid interrupt name", Arg1
);
17842 elsif Chars
(Int_Ent
) = Chars
(Arg1X
) then
17843 Int_Val
:= Expr_Value
(Constant_Value
(Int_Ent
));
17847 Next_Entity
(Int_Ent
);
17850 -- First argument is not an identifier, so it must be a static
17851 -- expression of type Ada.Interrupts.Interrupt_ID.
17854 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
17855 Int_Val
:= Expr_Value
(Arg1X
);
17857 if Int_Val
< Expr_Value
(Type_Low_Bound
(Int_Id
))
17859 Int_Val
> Expr_Value
(Type_High_Bound
(Int_Id
))
17862 ("value not in range of type "
17863 & """Ada.Interrupts.Interrupt_'I'D""", Arg1
);
17869 case Chars
(Get_Pragma_Arg
(Arg2
)) is
17870 when Name_Runtime
=> State_Type
:= 'r';
17871 when Name_System
=> State_Type
:= 's';
17872 when Name_User
=> State_Type
:= 'u';
17875 Error_Pragma_Arg
("invalid interrupt state", Arg2
);
17878 -- Check if entry is already stored
17880 IST_Num
:= Interrupt_States
.First
;
17882 -- If entry not found, add it
17884 if IST_Num
> Interrupt_States
.Last
then
17885 Interrupt_States
.Append
17886 ((Interrupt_Number
=> UI_To_Int
(Int_Val
),
17887 Interrupt_State
=> State_Type
,
17888 Pragma_Loc
=> Loc
));
17891 -- Case of entry for the same entry
17893 elsif Int_Val
= Interrupt_States
.Table
(IST_Num
).
17896 -- If state matches, done, no need to make redundant entry
17899 State_Type
= Interrupt_States
.Table
(IST_Num
).
17902 -- Otherwise if state does not match, error
17905 Interrupt_States
.Table
(IST_Num
).Pragma_Loc
;
17907 ("state conflicts with that given #", Arg2
);
17911 IST_Num
:= IST_Num
+ 1;
17913 end Interrupt_State
;
17919 -- pragma Invariant
17920 -- ([Entity =>] type_LOCAL_NAME,
17921 -- [Check =>] EXPRESSION
17922 -- [,[Message =>] String_Expression]);
17924 when Pragma_Invariant
=> Invariant
: declare
17931 Check_At_Least_N_Arguments
(2);
17932 Check_At_Most_N_Arguments
(3);
17933 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17934 Check_Optional_Identifier
(Arg2
, Name_Check
);
17936 if Arg_Count
= 3 then
17937 Check_Optional_Identifier
(Arg3
, Name_Message
);
17938 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
17941 Check_Arg_Is_Local_Name
(Arg1
);
17943 Typ_Arg
:= Get_Pragma_Arg
(Arg1
);
17944 Find_Type
(Typ_Arg
);
17945 Typ
:= Entity
(Typ_Arg
);
17947 -- Nothing to do of the related type is erroneous in some way
17949 if Typ
= Any_Type
then
17952 -- AI12-0041: Invariants are allowed in interface types
17954 elsif Is_Interface
(Typ
) then
17957 -- An invariant must apply to a private type, or appear in the
17958 -- private part of a package spec and apply to a completion.
17959 -- a class-wide invariant can only appear on a private declaration
17960 -- or private extension, not a completion.
17962 -- A [class-wide] invariant may be associated a [limited] private
17963 -- type or a private extension.
17965 elsif Ekind_In
(Typ
, E_Limited_Private_Type
,
17967 E_Record_Type_With_Private
)
17971 -- A non-class-wide invariant may be associated with the full view
17972 -- of a [limited] private type or a private extension.
17974 elsif Has_Private_Declaration
(Typ
)
17975 and then not Class_Present
(N
)
17979 -- A class-wide invariant may appear on the partial view only
17981 elsif Class_Present
(N
) then
17983 ("pragma % only allowed for private type", Arg1
);
17986 -- A regular invariant may appear on both views
17990 ("pragma % only allowed for private type or corresponding "
17991 & "full view", Arg1
);
17995 -- An invariant associated with an abstract type (this includes
17996 -- interfaces) must be class-wide.
17998 if Is_Abstract_Type
(Typ
) and then not Class_Present
(N
) then
18000 ("pragma % not allowed for abstract type", Arg1
);
18004 -- A pragma that applies to a Ghost entity becomes Ghost for the
18005 -- purposes of legality checks and removal of ignored Ghost code.
18007 Mark_Ghost_Pragma
(N
, Typ
);
18009 -- The pragma defines a type-specific invariant, the type is said
18010 -- to have invariants of its "own".
18012 Set_Has_Own_Invariants
(Typ
);
18014 -- If the invariant is class-wide, then it can be inherited by
18015 -- derived or interface implementing types. The type is said to
18016 -- have "inheritable" invariants.
18018 if Class_Present
(N
) then
18019 Set_Has_Inheritable_Invariants
(Typ
);
18022 -- Chain the pragma on to the rep item chain, for processing when
18023 -- the type is frozen.
18025 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
18027 -- Create the declaration of the invariant procedure that will
18028 -- verify the invariant at run time. Interfaces are treated as the
18029 -- partial view of a private type in order to achieve uniformity
18030 -- with the general case. As a result, an interface receives only
18031 -- a "partial" invariant procedure, which is never called.
18033 Build_Invariant_Procedure_Declaration
18035 Partial_Invariant
=> Is_Interface
(Typ
));
18042 -- pragma Keep_Names ([On => ] LOCAL_NAME);
18044 when Pragma_Keep_Names
=> Keep_Names
: declare
18049 Check_Arg_Count
(1);
18050 Check_Optional_Identifier
(Arg1
, Name_On
);
18051 Check_Arg_Is_Local_Name
(Arg1
);
18053 Arg
:= Get_Pragma_Arg
(Arg1
);
18056 if Etype
(Arg
) = Any_Type
then
18060 if not Is_Entity_Name
(Arg
)
18061 or else Ekind
(Entity
(Arg
)) /= E_Enumeration_Type
18064 ("pragma% requires a local enumeration type", Arg1
);
18067 Set_Discard_Names
(Entity
(Arg
), False);
18074 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
18076 when Pragma_License
=>
18079 -- Do not analyze pragma any further in CodePeer mode, to avoid
18080 -- extraneous errors in this implementation-dependent pragma,
18081 -- which has a different profile on other compilers.
18083 if CodePeer_Mode
then
18087 Check_Arg_Count
(1);
18088 Check_No_Identifiers
;
18089 Check_Valid_Configuration_Pragma
;
18090 Check_Arg_Is_Identifier
(Arg1
);
18093 Sind
: constant Source_File_Index
:=
18094 Source_Index
(Current_Sem_Unit
);
18097 case Chars
(Get_Pragma_Arg
(Arg1
)) is
18099 Set_License
(Sind
, GPL
);
18101 when Name_Modified_GPL
=>
18102 Set_License
(Sind
, Modified_GPL
);
18104 when Name_Restricted
=>
18105 Set_License
(Sind
, Restricted
);
18107 when Name_Unrestricted
=>
18108 Set_License
(Sind
, Unrestricted
);
18111 Error_Pragma_Arg
("invalid license name", Arg1
);
18119 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
18121 when Pragma_Link_With
=> Link_With
: declare
18127 if Operating_Mode
= Generate_Code
18128 and then In_Extended_Main_Source_Unit
(N
)
18130 Check_At_Least_N_Arguments
(1);
18131 Check_No_Identifiers
;
18132 Check_Is_In_Decl_Part_Or_Package_Spec
;
18133 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
18137 while Present
(Arg
) loop
18138 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
18140 -- Store argument, converting sequences of spaces to a
18141 -- single null character (this is one of the differences
18142 -- in processing between Link_With and Linker_Options).
18144 Arg_Store
: declare
18145 C
: constant Char_Code
:= Get_Char_Code
(' ');
18146 S
: constant String_Id
:=
18147 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
)));
18148 L
: constant Nat
:= String_Length
(S
);
18151 procedure Skip_Spaces
;
18152 -- Advance F past any spaces
18158 procedure Skip_Spaces
is
18160 while F
<= L
and then Get_String_Char
(S
, F
) = C
loop
18165 -- Start of processing for Arg_Store
18168 Skip_Spaces
; -- skip leading spaces
18170 -- Loop through characters, changing any embedded
18171 -- sequence of spaces to a single null character (this
18172 -- is how Link_With/Linker_Options differ)
18175 if Get_String_Char
(S
, F
) = C
then
18178 Store_String_Char
(ASCII
.NUL
);
18181 Store_String_Char
(Get_String_Char
(S
, F
));
18189 if Present
(Arg
) then
18190 Store_String_Char
(ASCII
.NUL
);
18194 Store_Linker_Option_String
(End_String
);
18202 -- pragma Linker_Alias (
18203 -- [Entity =>] LOCAL_NAME
18204 -- [Target =>] static_string_EXPRESSION);
18206 when Pragma_Linker_Alias
=>
18208 Check_Arg_Order
((Name_Entity
, Name_Target
));
18209 Check_Arg_Count
(2);
18210 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18211 Check_Optional_Identifier
(Arg2
, Name_Target
);
18212 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
18213 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
18215 -- The only processing required is to link this item on to the
18216 -- list of rep items for the given entity. This is accomplished
18217 -- by the call to Rep_Item_Too_Late (when no error is detected
18218 -- and False is returned).
18220 if Rep_Item_Too_Late
(Entity
(Get_Pragma_Arg
(Arg1
)), N
) then
18223 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
18226 ------------------------
18227 -- Linker_Constructor --
18228 ------------------------
18230 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
18232 -- Code is shared with Linker_Destructor
18234 -----------------------
18235 -- Linker_Destructor --
18236 -----------------------
18238 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
18240 when Pragma_Linker_Constructor
18241 | Pragma_Linker_Destructor
18243 Linker_Constructor
: declare
18249 Check_Arg_Count
(1);
18250 Check_No_Identifiers
;
18251 Check_Arg_Is_Local_Name
(Arg1
);
18252 Arg1_X
:= Get_Pragma_Arg
(Arg1
);
18254 Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
18256 if not Is_Library_Level_Entity
(Proc
) then
18258 ("argument for pragma% must be library level entity", Arg1
);
18261 -- The only processing required is to link this item on to the
18262 -- list of rep items for the given entity. This is accomplished
18263 -- by the call to Rep_Item_Too_Late (when no error is detected
18264 -- and False is returned).
18266 if Rep_Item_Too_Late
(Proc
, N
) then
18269 Set_Has_Gigi_Rep_Item
(Proc
);
18271 end Linker_Constructor
;
18273 --------------------
18274 -- Linker_Options --
18275 --------------------
18277 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
18279 when Pragma_Linker_Options
=> Linker_Options
: declare
18283 Check_Ada_83_Warning
;
18284 Check_No_Identifiers
;
18285 Check_Arg_Count
(1);
18286 Check_Is_In_Decl_Part_Or_Package_Spec
;
18287 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
18288 Start_String
(Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg1
))));
18291 while Present
(Arg
) loop
18292 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
18293 Store_String_Char
(ASCII
.NUL
);
18295 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
18299 if Operating_Mode
= Generate_Code
18300 and then In_Extended_Main_Source_Unit
(N
)
18302 Store_Linker_Option_String
(End_String
);
18304 end Linker_Options
;
18306 --------------------
18307 -- Linker_Section --
18308 --------------------
18310 -- pragma Linker_Section (
18311 -- [Entity =>] LOCAL_NAME
18312 -- [Section =>] static_string_EXPRESSION);
18314 when Pragma_Linker_Section
=> Linker_Section
: declare
18319 Ghost_Error_Posted
: Boolean := False;
18320 -- Flag set when an error concerning the illegal mix of Ghost and
18321 -- non-Ghost subprograms is emitted.
18323 Ghost_Id
: Entity_Id
:= Empty
;
18324 -- The entity of the first Ghost subprogram encountered while
18325 -- processing the arguments of the pragma.
18329 Check_Arg_Order
((Name_Entity
, Name_Section
));
18330 Check_Arg_Count
(2);
18331 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18332 Check_Optional_Identifier
(Arg2
, Name_Section
);
18333 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
18334 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
18336 -- Check kind of entity
18338 Arg
:= Get_Pragma_Arg
(Arg1
);
18339 Ent
:= Entity
(Arg
);
18341 case Ekind
(Ent
) is
18343 -- Objects (constants and variables) and types. For these cases
18344 -- all we need to do is to set the Linker_Section_pragma field,
18345 -- checking that we do not have a duplicate.
18351 LPE
:= Linker_Section_Pragma
(Ent
);
18353 if Present
(LPE
) then
18354 Error_Msg_Sloc
:= Sloc
(LPE
);
18356 ("Linker_Section already specified for &#", Arg1
, Ent
);
18359 Set_Linker_Section_Pragma
(Ent
, N
);
18361 -- A pragma that applies to a Ghost entity becomes Ghost for
18362 -- the purposes of legality checks and removal of ignored
18365 Mark_Ghost_Pragma
(N
, Ent
);
18369 when Subprogram_Kind
=>
18371 -- Aspect case, entity already set
18373 if From_Aspect_Specification
(N
) then
18374 Set_Linker_Section_Pragma
18375 (Entity
(Corresponding_Aspect
(N
)), N
);
18377 -- Pragma case, we must climb the homonym chain, but skip
18378 -- any for which the linker section is already set.
18382 if No
(Linker_Section_Pragma
(Ent
)) then
18383 Set_Linker_Section_Pragma
(Ent
, N
);
18385 -- A pragma that applies to a Ghost entity becomes
18386 -- Ghost for the purposes of legality checks and
18387 -- removal of ignored Ghost code.
18389 Mark_Ghost_Pragma
(N
, Ent
);
18391 -- Capture the entity of the first Ghost subprogram
18392 -- being processed for error detection purposes.
18394 if Is_Ghost_Entity
(Ent
) then
18395 if No
(Ghost_Id
) then
18399 -- Otherwise the subprogram is non-Ghost. It is
18400 -- illegal to mix references to Ghost and non-Ghost
18401 -- entities (SPARK RM 6.9).
18403 elsif Present
(Ghost_Id
)
18404 and then not Ghost_Error_Posted
18406 Ghost_Error_Posted
:= True;
18408 Error_Msg_Name_1
:= Pname
;
18410 ("pragma % cannot mention ghost and "
18411 & "non-ghost subprograms", N
);
18413 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
18415 ("\& # declared as ghost", N
, Ghost_Id
);
18417 Error_Msg_Sloc
:= Sloc
(Ent
);
18419 ("\& # declared as non-ghost", N
, Ent
);
18423 Ent
:= Homonym
(Ent
);
18425 or else Scope
(Ent
) /= Current_Scope
;
18429 -- All other cases are illegal
18433 ("pragma% applies only to objects, subprograms, and types",
18436 end Linker_Section
;
18442 -- pragma List (On | Off)
18444 -- There is nothing to do here, since we did all the processing for
18445 -- this pragma in Par.Prag (so that it works properly even in syntax
18448 when Pragma_List
=>
18455 -- pragma Lock_Free [(Boolean_EXPRESSION)];
18457 when Pragma_Lock_Free
=> Lock_Free
: declare
18458 P
: constant Node_Id
:= Parent
(N
);
18464 Check_No_Identifiers
;
18465 Check_At_Most_N_Arguments
(1);
18467 -- Protected definition case
18469 if Nkind
(P
) = N_Protected_Definition
then
18470 Ent
:= Defining_Identifier
(Parent
(P
));
18474 if Arg_Count
= 1 then
18475 Arg
:= Get_Pragma_Arg
(Arg1
);
18476 Val
:= Is_True
(Static_Boolean
(Arg
));
18478 -- No arguments (expression is considered to be True)
18484 -- Check duplicate pragma before we chain the pragma in the Rep
18485 -- Item chain of Ent.
18487 Check_Duplicate_Pragma
(Ent
);
18488 Record_Rep_Item
(Ent
, N
);
18489 Set_Uses_Lock_Free
(Ent
, Val
);
18491 -- Anything else is incorrect placement
18498 --------------------
18499 -- Locking_Policy --
18500 --------------------
18502 -- pragma Locking_Policy (policy_IDENTIFIER);
18504 when Pragma_Locking_Policy
=> declare
18505 subtype LP_Range
is Name_Id
18506 range First_Locking_Policy_Name
.. Last_Locking_Policy_Name
;
18511 Check_Ada_83_Warning
;
18512 Check_Arg_Count
(1);
18513 Check_No_Identifiers
;
18514 Check_Arg_Is_Locking_Policy
(Arg1
);
18515 Check_Valid_Configuration_Pragma
;
18516 LP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
18519 when Name_Ceiling_Locking
=> LP
:= 'C';
18520 when Name_Concurrent_Readers_Locking
=> LP
:= 'R';
18521 when Name_Inheritance_Locking
=> LP
:= 'I';
18524 if Locking_Policy
/= ' '
18525 and then Locking_Policy
/= LP
18527 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
18528 Error_Pragma
("locking policy incompatible with policy#");
18530 -- Set new policy, but always preserve System_Location since we
18531 -- like the error message with the run time name.
18534 Locking_Policy
:= LP
;
18536 if Locking_Policy_Sloc
/= System_Location
then
18537 Locking_Policy_Sloc
:= Loc
;
18542 -------------------
18543 -- Loop_Optimize --
18544 -------------------
18546 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
18548 -- OPTIMIZATION_HINT ::=
18549 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
18551 when Pragma_Loop_Optimize
=> Loop_Optimize
: declare
18556 Check_At_Least_N_Arguments
(1);
18557 Check_No_Identifiers
;
18559 Hint
:= First
(Pragma_Argument_Associations
(N
));
18560 while Present
(Hint
) loop
18561 Check_Arg_Is_One_Of
(Hint
, Name_Ivdep
,
18569 Check_Loop_Pragma_Placement
;
18576 -- pragma Loop_Variant
18577 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
18579 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
18581 -- CHANGE_DIRECTION ::= Increases | Decreases
18583 when Pragma_Loop_Variant
=> Loop_Variant
: declare
18588 Check_At_Least_N_Arguments
(1);
18589 Check_Loop_Pragma_Placement
;
18591 -- Process all increasing / decreasing expressions
18593 Variant
:= First
(Pragma_Argument_Associations
(N
));
18594 while Present
(Variant
) loop
18595 if Chars
(Variant
) = No_Name
then
18596 Error_Pragma_Arg_Ident
("expect name `Increases`", Variant
);
18598 elsif not Nam_In
(Chars
(Variant
), Name_Decreases
,
18602 Name
: String := Get_Name_String
(Chars
(Variant
));
18605 -- It is a common mistake to write "Increasing" for
18606 -- "Increases" or "Decreasing" for "Decreases". Recognize
18607 -- specially names starting with "incr" or "decr" to
18608 -- suggest the corresponding name.
18610 System
.Case_Util
.To_Lower
(Name
);
18612 if Name
'Length >= 4
18613 and then Name
(1 .. 4) = "incr"
18615 Error_Pragma_Arg_Ident
18616 ("expect name `Increases`", Variant
);
18618 elsif Name
'Length >= 4
18619 and then Name
(1 .. 4) = "decr"
18621 Error_Pragma_Arg_Ident
18622 ("expect name `Decreases`", Variant
);
18625 Error_Pragma_Arg_Ident
18626 ("expect name `Increases` or `Decreases`", Variant
);
18631 Preanalyze_Assert_Expression
18632 (Expression
(Variant
), Any_Discrete
);
18638 -----------------------
18639 -- Machine_Attribute --
18640 -----------------------
18642 -- pragma Machine_Attribute (
18643 -- [Entity =>] LOCAL_NAME,
18644 -- [Attribute_Name =>] static_string_EXPRESSION
18645 -- [, [Info =>] static_EXPRESSION] );
18647 when Pragma_Machine_Attribute
=> Machine_Attribute
: declare
18648 Def_Id
: Entity_Id
;
18652 Check_Arg_Order
((Name_Entity
, Name_Attribute_Name
, Name_Info
));
18654 if Arg_Count
= 3 then
18655 Check_Optional_Identifier
(Arg3
, Name_Info
);
18656 Check_Arg_Is_OK_Static_Expression
(Arg3
);
18658 Check_Arg_Count
(2);
18661 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18662 Check_Optional_Identifier
(Arg2
, Name_Attribute_Name
);
18663 Check_Arg_Is_Local_Name
(Arg1
);
18664 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
18665 Def_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
18667 if Is_Access_Type
(Def_Id
) then
18668 Def_Id
:= Designated_Type
(Def_Id
);
18671 if Rep_Item_Too_Early
(Def_Id
, N
) then
18675 Def_Id
:= Underlying_Type
(Def_Id
);
18677 -- The only processing required is to link this item on to the
18678 -- list of rep items for the given entity. This is accomplished
18679 -- by the call to Rep_Item_Too_Late (when no error is detected
18680 -- and False is returned).
18682 if Rep_Item_Too_Late
(Def_Id
, N
) then
18685 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
18687 end Machine_Attribute
;
18694 -- (MAIN_OPTION [, MAIN_OPTION]);
18697 -- [STACK_SIZE =>] static_integer_EXPRESSION
18698 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
18699 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
18701 when Pragma_Main
=> Main
: declare
18702 Args
: Args_List
(1 .. 3);
18703 Names
: constant Name_List
(1 .. 3) := (
18705 Name_Task_Stack_Size_Default
,
18706 Name_Time_Slicing_Enabled
);
18712 Gather_Associations
(Names
, Args
);
18714 for J
in 1 .. 2 loop
18715 if Present
(Args
(J
)) then
18716 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
18720 if Present
(Args
(3)) then
18721 Check_Arg_Is_OK_Static_Expression
(Args
(3), Standard_Boolean
);
18725 while Present
(Nod
) loop
18726 if Nkind
(Nod
) = N_Pragma
18727 and then Pragma_Name
(Nod
) = Name_Main
18729 Error_Msg_Name_1
:= Pname
;
18730 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
18741 -- pragma Main_Storage
18742 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
18744 -- MAIN_STORAGE_OPTION ::=
18745 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
18746 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
18748 when Pragma_Main_Storage
=> Main_Storage
: declare
18749 Args
: Args_List
(1 .. 2);
18750 Names
: constant Name_List
(1 .. 2) := (
18751 Name_Working_Storage
,
18758 Gather_Associations
(Names
, Args
);
18760 for J
in 1 .. 2 loop
18761 if Present
(Args
(J
)) then
18762 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
18766 Check_In_Main_Program
;
18769 while Present
(Nod
) loop
18770 if Nkind
(Nod
) = N_Pragma
18771 and then Pragma_Name
(Nod
) = Name_Main_Storage
18773 Error_Msg_Name_1
:= Pname
;
18774 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
18781 ----------------------
18782 -- Max_Queue_Length --
18783 ----------------------
18785 -- pragma Max_Queue_Length (static_integer_EXPRESSION);
18787 -- This processing is shared by Pragma_Max_Entry_Queue_Depth
18789 when Pragma_Max_Queue_Length
18790 | Pragma_Max_Entry_Queue_Depth
18792 Max_Queue_Length
: declare
18794 Entry_Decl
: Node_Id
;
18795 Entry_Id
: Entity_Id
;
18799 if Prag_Id
= Pragma_Max_Queue_Length
then
18803 Check_Arg_Count
(1);
18806 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
18808 -- Entry declaration
18810 if Nkind
(Entry_Decl
) = N_Entry_Declaration
then
18812 -- Entry illegally within a task
18814 if Nkind
(Parent
(N
)) = N_Task_Definition
then
18815 Error_Pragma
("pragma % cannot apply to task entries");
18819 Entry_Id
:= Defining_Entity
(Entry_Decl
);
18821 -- Otherwise the pragma is associated with an illegal construct
18824 Error_Pragma
("pragma % must apply to a protected entry");
18828 -- Mark the pragma as Ghost if the related subprogram is also
18829 -- Ghost. This also ensures that any expansion performed further
18830 -- below will produce Ghost nodes.
18832 Mark_Ghost_Pragma
(N
, Entry_Id
);
18834 -- Analyze the Integer expression
18836 Arg
:= Get_Pragma_Arg
(Arg1
);
18837 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
18839 Val
:= Expr_Value
(Arg
);
18843 ("argument for pragma% must be positive", Arg1
);
18845 elsif not UI_Is_In_Int_Range
(Val
) then
18847 ("argument for pragma% out of range of Integer", Arg1
);
18851 -- Manually substitute the expression value of the pragma argument
18852 -- if it's not an integer literal because this is not taken care
18853 -- of automatically elsewhere.
18855 if Nkind
(Arg
) /= N_Integer_Literal
then
18856 Rewrite
(Arg
, Make_Integer_Literal
(Sloc
(Arg
), Val
));
18857 Set_Etype
(Arg
, Etype
(Original_Node
(Arg
)));
18860 Record_Rep_Item
(Entry_Id
, N
);
18861 end Max_Queue_Length
;
18867 -- pragma Memory_Size (NUMERIC_LITERAL)
18869 when Pragma_Memory_Size
=>
18872 -- Memory size is simply ignored
18874 Check_No_Identifiers
;
18875 Check_Arg_Count
(1);
18876 Check_Arg_Is_Integer_Literal
(Arg1
);
18884 -- The only correct use of this pragma is on its own in a file, in
18885 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
18886 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
18887 -- check for a file containing nothing but a No_Body pragma). If we
18888 -- attempt to process it during normal semantics processing, it means
18889 -- it was misplaced.
18891 when Pragma_No_Body
=>
18895 -----------------------------
18896 -- No_Elaboration_Code_All --
18897 -----------------------------
18899 -- pragma No_Elaboration_Code_All;
18901 when Pragma_No_Elaboration_Code_All
=>
18903 Check_Valid_Library_Unit_Pragma
;
18905 if Nkind
(N
) = N_Null_Statement
then
18909 -- Must appear for a spec or generic spec
18911 if not Nkind_In
(Unit
(Cunit
(Current_Sem_Unit
)),
18912 N_Generic_Package_Declaration
,
18913 N_Generic_Subprogram_Declaration
,
18914 N_Package_Declaration
,
18915 N_Subprogram_Declaration
)
18919 ("pragma% can only occur for package "
18920 & "or subprogram spec"));
18923 -- Set flag in unit table
18925 Set_No_Elab_Code_All
(Current_Sem_Unit
);
18927 -- Set restriction No_Elaboration_Code if this is the main unit
18929 if Current_Sem_Unit
= Main_Unit
then
18930 Set_Restriction
(No_Elaboration_Code
, N
);
18933 -- If we are in the main unit or in an extended main source unit,
18934 -- then we also add it to the configuration restrictions so that
18935 -- it will apply to all units in the extended main source.
18937 if Current_Sem_Unit
= Main_Unit
18938 or else In_Extended_Main_Source_Unit
(N
)
18940 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
18943 -- If in main extended unit, activate transitive with test
18945 if In_Extended_Main_Source_Unit
(N
) then
18946 Opt
.No_Elab_Code_All_Pragma
:= N
;
18949 -----------------------------
18950 -- No_Component_Reordering --
18951 -----------------------------
18953 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
18955 when Pragma_No_Component_Reordering
=> No_Comp_Reordering
: declare
18961 Check_At_Most_N_Arguments
(1);
18963 if Arg_Count
= 0 then
18964 Check_Valid_Configuration_Pragma
;
18965 Opt
.No_Component_Reordering
:= True;
18968 Check_Optional_Identifier
(Arg2
, Name_Entity
);
18969 Check_Arg_Is_Local_Name
(Arg1
);
18970 E_Id
:= Get_Pragma_Arg
(Arg1
);
18972 if Etype
(E_Id
) = Any_Type
then
18976 E
:= Entity
(E_Id
);
18978 if not Is_Record_Type
(E
) then
18979 Error_Pragma_Arg
("pragma% requires record type", Arg1
);
18982 Set_No_Reordering
(Base_Type
(E
));
18984 end No_Comp_Reordering
;
18986 --------------------------
18987 -- No_Heap_Finalization --
18988 --------------------------
18990 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
18992 when Pragma_No_Heap_Finalization
=> No_Heap_Finalization
: declare
18993 Context
: constant Node_Id
:= Parent
(N
);
18994 Typ_Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
19000 Check_No_Identifiers
;
19002 -- The pragma appears in a configuration file
19004 if No
(Context
) then
19005 Check_Arg_Count
(0);
19006 Check_Valid_Configuration_Pragma
;
19008 -- Detect a duplicate pragma
19010 if Present
(No_Heap_Finalization_Pragma
) then
19013 Prev
=> No_Heap_Finalization_Pragma
);
19017 No_Heap_Finalization_Pragma
:= N
;
19019 -- Otherwise the pragma should be associated with a library-level
19020 -- named access-to-object type.
19023 Check_Arg_Count
(1);
19024 Check_Arg_Is_Local_Name
(Arg1
);
19026 Find_Type
(Typ_Arg
);
19027 Typ
:= Entity
(Typ_Arg
);
19029 -- The type being subjected to the pragma is erroneous
19031 if Typ
= Any_Type
then
19032 Error_Pragma
("cannot find type referenced by pragma %");
19034 -- The pragma is applied to an incomplete or generic formal
19035 -- type way too early.
19037 elsif Rep_Item_Too_Early
(Typ
, N
) then
19041 Typ
:= Underlying_Type
(Typ
);
19044 -- The pragma must apply to an access-to-object type
19046 if Ekind_In
(Typ
, E_Access_Type
, E_General_Access_Type
) then
19049 -- Give a detailed error message on all other access type kinds
19051 elsif Ekind
(Typ
) = E_Access_Protected_Subprogram_Type
then
19053 ("pragma % cannot apply to access protected subprogram "
19056 elsif Ekind
(Typ
) = E_Access_Subprogram_Type
then
19058 ("pragma % cannot apply to access subprogram type");
19060 elsif Is_Anonymous_Access_Type
(Typ
) then
19062 ("pragma % cannot apply to anonymous access type");
19064 -- Give a general error message in case the pragma applies to a
19065 -- non-access type.
19069 ("pragma % must apply to library level access type");
19072 -- At this point the argument denotes an access-to-object type.
19073 -- Ensure that the type is declared at the library level.
19075 if Is_Library_Level_Entity
(Typ
) then
19078 -- Quietly ignore an access-to-object type originally declared
19079 -- at the library level within a generic, but instantiated at
19080 -- a non-library level. As a result the access-to-object type
19081 -- "loses" its No_Heap_Finalization property.
19083 elsif In_Instance
then
19088 ("pragma % must apply to library level access type");
19091 -- Detect a duplicate pragma
19093 if Present
(No_Heap_Finalization_Pragma
) then
19096 Prev
=> No_Heap_Finalization_Pragma
);
19100 Prev
:= Get_Pragma
(Typ
, Pragma_No_Heap_Finalization
);
19102 if Present
(Prev
) then
19110 Record_Rep_Item
(Typ
, N
);
19112 end No_Heap_Finalization
;
19118 -- pragma No_Inline ( NAME {, NAME} );
19120 when Pragma_No_Inline
=>
19122 Process_Inline
(Suppressed
);
19128 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
19130 when Pragma_No_Return
=> No_Return
: declare
19136 Ghost_Error_Posted
: Boolean := False;
19137 -- Flag set when an error concerning the illegal mix of Ghost and
19138 -- non-Ghost subprograms is emitted.
19140 Ghost_Id
: Entity_Id
:= Empty
;
19141 -- The entity of the first Ghost procedure encountered while
19142 -- processing the arguments of the pragma.
19146 Check_At_Least_N_Arguments
(1);
19148 -- Loop through arguments of pragma
19151 while Present
(Arg
) loop
19152 Check_Arg_Is_Local_Name
(Arg
);
19153 Id
:= Get_Pragma_Arg
(Arg
);
19156 if not Is_Entity_Name
(Id
) then
19157 Error_Pragma_Arg
("entity name required", Arg
);
19160 if Etype
(Id
) = Any_Type
then
19164 -- Loop to find matching procedures
19170 and then Scope
(E
) = Current_Scope
19172 if Ekind_In
(E
, E_Generic_Procedure
, E_Procedure
) then
19174 -- Check that the pragma is not applied to a body.
19175 -- First check the specless body case, to give a
19176 -- different error message. These checks do not apply
19177 -- if Relaxed_RM_Semantics, to accommodate other Ada
19178 -- compilers. Disable these checks under -gnatd.J.
19180 if not Debug_Flag_Dot_JJ
then
19181 if Nkind
(Parent
(Declaration_Node
(E
))) =
19183 and then not Relaxed_RM_Semantics
19186 ("pragma% requires separate spec and must come "
19190 -- Now the "specful" body case
19192 if Rep_Item_Too_Late
(E
, N
) then
19199 -- A pragma that applies to a Ghost entity becomes Ghost
19200 -- for the purposes of legality checks and removal of
19201 -- ignored Ghost code.
19203 Mark_Ghost_Pragma
(N
, E
);
19205 -- Capture the entity of the first Ghost procedure being
19206 -- processed for error detection purposes.
19208 if Is_Ghost_Entity
(E
) then
19209 if No
(Ghost_Id
) then
19213 -- Otherwise the subprogram is non-Ghost. It is illegal
19214 -- to mix references to Ghost and non-Ghost entities
19217 elsif Present
(Ghost_Id
)
19218 and then not Ghost_Error_Posted
19220 Ghost_Error_Posted
:= True;
19222 Error_Msg_Name_1
:= Pname
;
19224 ("pragma % cannot mention ghost and non-ghost "
19225 & "procedures", N
);
19227 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
19228 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
19230 Error_Msg_Sloc
:= Sloc
(E
);
19231 Error_Msg_NE
("\& # declared as non-ghost", N
, E
);
19234 -- Set flag on any alias as well
19236 if Is_Overloadable
(E
) and then Present
(Alias
(E
)) then
19237 Set_No_Return
(Alias
(E
));
19243 exit when From_Aspect_Specification
(N
);
19247 -- If entity in not in current scope it may be the enclosing
19248 -- suprogram body to which the aspect applies.
19251 if Entity
(Id
) = Current_Scope
19252 and then From_Aspect_Specification
(N
)
19254 Set_No_Return
(Entity
(Id
));
19256 Error_Pragma_Arg
("no procedure& found for pragma%", Arg
);
19268 -- pragma No_Run_Time;
19270 -- Note: this pragma is retained for backwards compatibility. See
19271 -- body of Rtsfind for full details on its handling.
19273 when Pragma_No_Run_Time
=>
19275 Check_Valid_Configuration_Pragma
;
19276 Check_Arg_Count
(0);
19278 -- Remove backward compatibility if Build_Type is FSF or GPL and
19279 -- generate a warning.
19282 Ignore
: constant Boolean := Build_Type
in FSF
.. GPL
;
19285 Error_Pragma
("pragma% is ignored, has no effect??");
19287 No_Run_Time_Mode
:= True;
19288 Configurable_Run_Time_Mode
:= True;
19290 -- Set Duration to 32 bits if word size is 32
19292 if Ttypes
.System_Word_Size
= 32 then
19293 Duration_32_Bits_On_Target
:= True;
19296 -- Set appropriate restrictions
19298 Set_Restriction
(No_Finalization
, N
);
19299 Set_Restriction
(No_Exception_Handlers
, N
);
19300 Set_Restriction
(Max_Tasks
, N
, 0);
19301 Set_Restriction
(No_Tasking
, N
);
19305 -----------------------
19306 -- No_Tagged_Streams --
19307 -----------------------
19309 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
19311 when Pragma_No_Tagged_Streams
=> No_Tagged_Strms
: declare
19317 Check_At_Most_N_Arguments
(1);
19319 -- One argument case
19321 if Arg_Count
= 1 then
19322 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19323 Check_Arg_Is_Local_Name
(Arg1
);
19324 E_Id
:= Get_Pragma_Arg
(Arg1
);
19326 if Etype
(E_Id
) = Any_Type
then
19330 E
:= Entity
(E_Id
);
19332 Check_Duplicate_Pragma
(E
);
19334 if not Is_Tagged_Type
(E
) or else Is_Derived_Type
(E
) then
19336 ("argument for pragma% must be root tagged type", Arg1
);
19339 if Rep_Item_Too_Early
(E
, N
)
19341 Rep_Item_Too_Late
(E
, N
)
19345 Set_No_Tagged_Streams_Pragma
(E
, N
);
19348 -- Zero argument case
19351 Check_Is_In_Decl_Part_Or_Package_Spec
;
19352 No_Tagged_Streams
:= N
;
19354 end No_Tagged_Strms
;
19356 ------------------------
19357 -- No_Strict_Aliasing --
19358 ------------------------
19360 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
19362 when Pragma_No_Strict_Aliasing
=> No_Strict_Aliasing
: declare
19368 Check_At_Most_N_Arguments
(1);
19370 if Arg_Count
= 0 then
19371 Check_Valid_Configuration_Pragma
;
19372 Opt
.No_Strict_Aliasing
:= True;
19375 Check_Optional_Identifier
(Arg2
, Name_Entity
);
19376 Check_Arg_Is_Local_Name
(Arg1
);
19377 E_Id
:= Get_Pragma_Arg
(Arg1
);
19379 if Etype
(E_Id
) = Any_Type
then
19383 E
:= Entity
(E_Id
);
19385 if not Is_Access_Type
(E
) then
19386 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
19389 Set_No_Strict_Aliasing
(Base_Type
(E
));
19391 end No_Strict_Aliasing
;
19393 -----------------------
19394 -- Normalize_Scalars --
19395 -----------------------
19397 -- pragma Normalize_Scalars;
19399 when Pragma_Normalize_Scalars
=>
19400 Check_Ada_83_Warning
;
19401 Check_Arg_Count
(0);
19402 Check_Valid_Configuration_Pragma
;
19404 -- Normalize_Scalars creates false positives in CodePeer, and
19405 -- incorrect negative results in GNATprove mode, so ignore this
19406 -- pragma in these modes.
19408 if not (CodePeer_Mode
or GNATprove_Mode
) then
19409 Normalize_Scalars
:= True;
19410 Init_Or_Norm_Scalars
:= True;
19417 -- pragma Obsolescent;
19419 -- pragma Obsolescent (
19420 -- [Message =>] static_string_EXPRESSION
19421 -- [,[Version =>] Ada_05]]);
19423 -- pragma Obsolescent (
19424 -- [Entity =>] NAME
19425 -- [,[Message =>] static_string_EXPRESSION
19426 -- [,[Version =>] Ada_05]] );
19428 when Pragma_Obsolescent
=> Obsolescent
: declare
19432 procedure Set_Obsolescent
(E
: Entity_Id
);
19433 -- Given an entity Ent, mark it as obsolescent if appropriate
19435 ---------------------
19436 -- Set_Obsolescent --
19437 ---------------------
19439 procedure Set_Obsolescent
(E
: Entity_Id
) is
19448 -- A pragma that applies to a Ghost entity becomes Ghost for
19449 -- the purposes of legality checks and removal of ignored Ghost
19452 Mark_Ghost_Pragma
(N
, E
);
19454 -- Entity name was given
19456 if Present
(Ename
) then
19458 -- If entity name matches, we are fine. Save entity in
19459 -- pragma argument, for ASIS use.
19461 if Chars
(Ename
) = Chars
(Ent
) then
19462 Set_Entity
(Ename
, Ent
);
19463 Generate_Reference
(Ent
, Ename
);
19465 -- If entity name does not match, only possibility is an
19466 -- enumeration literal from an enumeration type declaration.
19468 elsif Ekind
(Ent
) /= E_Enumeration_Type
then
19470 ("pragma % entity name does not match declaration");
19473 Ent
:= First_Literal
(E
);
19477 ("pragma % entity name does not match any "
19478 & "enumeration literal");
19480 elsif Chars
(Ent
) = Chars
(Ename
) then
19481 Set_Entity
(Ename
, Ent
);
19482 Generate_Reference
(Ent
, Ename
);
19486 Ent
:= Next_Literal
(Ent
);
19492 -- Ent points to entity to be marked
19494 if Arg_Count
>= 1 then
19496 -- Deal with static string argument
19498 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
19499 S
:= Strval
(Get_Pragma_Arg
(Arg1
));
19501 for J
in 1 .. String_Length
(S
) loop
19502 if not In_Character_Range
(Get_String_Char
(S
, J
)) then
19504 ("pragma% argument does not allow wide characters",
19509 Obsolescent_Warnings
.Append
19510 ((Ent
=> Ent
, Msg
=> Strval
(Get_Pragma_Arg
(Arg1
))));
19512 -- Check for Ada_05 parameter
19514 if Arg_Count
/= 1 then
19515 Check_Arg_Count
(2);
19518 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
19521 Check_Arg_Is_Identifier
(Argx
);
19523 if Chars
(Argx
) /= Name_Ada_05
then
19524 Error_Msg_Name_2
:= Name_Ada_05
;
19526 ("only allowed argument for pragma% is %", Argx
);
19529 if Ada_Version_Explicit
< Ada_2005
19530 or else not Warn_On_Ada_2005_Compatibility
19538 -- Set flag if pragma active
19541 Set_Is_Obsolescent
(Ent
);
19545 end Set_Obsolescent
;
19547 -- Start of processing for pragma Obsolescent
19552 Check_At_Most_N_Arguments
(3);
19554 -- See if first argument specifies an entity name
19558 (Chars
(Arg1
) = Name_Entity
19560 Nkind_In
(Get_Pragma_Arg
(Arg1
), N_Character_Literal
,
19562 N_Operator_Symbol
))
19564 Ename
:= Get_Pragma_Arg
(Arg1
);
19566 -- Eliminate first argument, so we can share processing
19570 Arg_Count
:= Arg_Count
- 1;
19572 -- No Entity name argument given
19578 if Arg_Count
>= 1 then
19579 Check_Optional_Identifier
(Arg1
, Name_Message
);
19581 if Arg_Count
= 2 then
19582 Check_Optional_Identifier
(Arg2
, Name_Version
);
19586 -- Get immediately preceding declaration
19589 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
19593 -- Cases where we do not follow anything other than another pragma
19597 -- First case: library level compilation unit declaration with
19598 -- the pragma immediately following the declaration.
19600 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
19602 (Defining_Entity
(Unit
(Parent
(Parent
(N
)))));
19605 -- Case 2: library unit placement for package
19609 Ent
: constant Entity_Id
:= Find_Lib_Unit_Name
;
19611 if Is_Package_Or_Generic_Package
(Ent
) then
19612 Set_Obsolescent
(Ent
);
19618 -- Cases where we must follow a declaration, including an
19619 -- abstract subprogram declaration, which is not in the
19620 -- other node subtypes.
19623 if Nkind
(Decl
) not in N_Declaration
19624 and then Nkind
(Decl
) not in N_Later_Decl_Item
19625 and then Nkind
(Decl
) not in N_Generic_Declaration
19626 and then Nkind
(Decl
) not in N_Renaming_Declaration
19627 and then Nkind
(Decl
) /= N_Abstract_Subprogram_Declaration
19630 ("pragma% misplaced, "
19631 & "must immediately follow a declaration");
19634 Set_Obsolescent
(Defining_Entity
(Decl
));
19644 -- pragma Optimize (Time | Space | Off);
19646 -- The actual check for optimize is done in Gigi. Note that this
19647 -- pragma does not actually change the optimization setting, it
19648 -- simply checks that it is consistent with the pragma.
19650 when Pragma_Optimize
=>
19651 Check_No_Identifiers
;
19652 Check_Arg_Count
(1);
19653 Check_Arg_Is_One_Of
(Arg1
, Name_Time
, Name_Space
, Name_Off
);
19655 ------------------------
19656 -- Optimize_Alignment --
19657 ------------------------
19659 -- pragma Optimize_Alignment (Time | Space | Off);
19661 when Pragma_Optimize_Alignment
=> Optimize_Alignment
: begin
19663 Check_No_Identifiers
;
19664 Check_Arg_Count
(1);
19665 Check_Valid_Configuration_Pragma
;
19668 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
19671 when Name_Off
=> Opt
.Optimize_Alignment
:= 'O';
19672 when Name_Space
=> Opt
.Optimize_Alignment
:= 'S';
19673 when Name_Time
=> Opt
.Optimize_Alignment
:= 'T';
19676 Error_Pragma_Arg
("invalid argument for pragma%", Arg1
);
19680 -- Set indication that mode is set locally. If we are in fact in a
19681 -- configuration pragma file, this setting is harmless since the
19682 -- switch will get reset anyway at the start of each unit.
19684 Optimize_Alignment_Local
:= True;
19685 end Optimize_Alignment
;
19691 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
19693 when Pragma_Ordered
=> Ordered
: declare
19694 Assoc
: constant Node_Id
:= Arg1
;
19700 Check_No_Identifiers
;
19701 Check_Arg_Count
(1);
19702 Check_Arg_Is_Local_Name
(Arg1
);
19704 Type_Id
:= Get_Pragma_Arg
(Assoc
);
19705 Find_Type
(Type_Id
);
19706 Typ
:= Entity
(Type_Id
);
19708 if Typ
= Any_Type
then
19711 Typ
:= Underlying_Type
(Typ
);
19714 if not Is_Enumeration_Type
(Typ
) then
19715 Error_Pragma
("pragma% must specify enumeration type");
19718 Check_First_Subtype
(Arg1
);
19719 Set_Has_Pragma_Ordered
(Base_Type
(Typ
));
19722 -------------------
19723 -- Overflow_Mode --
19724 -------------------
19726 -- pragma Overflow_Mode
19727 -- ([General => ] MODE [, [Assertions => ] MODE]);
19729 -- MODE := STRICT | MINIMIZED | ELIMINATED
19731 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
19732 -- since System.Bignums makes this assumption. This is true of nearly
19733 -- all (all?) targets.
19735 when Pragma_Overflow_Mode
=> Overflow_Mode
: declare
19736 function Get_Overflow_Mode
19738 Arg
: Node_Id
) return Overflow_Mode_Type
;
19739 -- Function to process one pragma argument, Arg. If an identifier
19740 -- is present, it must be Name. Mode type is returned if a valid
19741 -- argument exists, otherwise an error is signalled.
19743 -----------------------
19744 -- Get_Overflow_Mode --
19745 -----------------------
19747 function Get_Overflow_Mode
19749 Arg
: Node_Id
) return Overflow_Mode_Type
19751 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
19754 Check_Optional_Identifier
(Arg
, Name
);
19755 Check_Arg_Is_Identifier
(Argx
);
19757 if Chars
(Argx
) = Name_Strict
then
19760 elsif Chars
(Argx
) = Name_Minimized
then
19763 elsif Chars
(Argx
) = Name_Eliminated
then
19764 if Ttypes
.Standard_Long_Long_Integer_Size
/= 64 then
19766 ("Eliminated not implemented on this target", Argx
);
19772 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
19774 end Get_Overflow_Mode
;
19776 -- Start of processing for Overflow_Mode
19780 Check_At_Least_N_Arguments
(1);
19781 Check_At_Most_N_Arguments
(2);
19783 -- Process first argument
19785 Scope_Suppress
.Overflow_Mode_General
:=
19786 Get_Overflow_Mode
(Name_General
, Arg1
);
19788 -- Case of only one argument
19790 if Arg_Count
= 1 then
19791 Scope_Suppress
.Overflow_Mode_Assertions
:=
19792 Scope_Suppress
.Overflow_Mode_General
;
19794 -- Case of two arguments present
19797 Scope_Suppress
.Overflow_Mode_Assertions
:=
19798 Get_Overflow_Mode
(Name_Assertions
, Arg2
);
19802 --------------------------
19803 -- Overriding Renamings --
19804 --------------------------
19806 -- pragma Overriding_Renamings;
19808 when Pragma_Overriding_Renamings
=>
19810 Check_Arg_Count
(0);
19811 Check_Valid_Configuration_Pragma
;
19812 Overriding_Renamings
:= True;
19818 -- pragma Pack (first_subtype_LOCAL_NAME);
19820 when Pragma_Pack
=> Pack
: declare
19821 Assoc
: constant Node_Id
:= Arg1
;
19823 Ignore
: Boolean := False;
19828 Check_No_Identifiers
;
19829 Check_Arg_Count
(1);
19830 Check_Arg_Is_Local_Name
(Arg1
);
19831 Type_Id
:= Get_Pragma_Arg
(Assoc
);
19833 if not Is_Entity_Name
(Type_Id
)
19834 or else not Is_Type
(Entity
(Type_Id
))
19837 ("argument for pragma% must be type or subtype", Arg1
);
19840 Find_Type
(Type_Id
);
19841 Typ
:= Entity
(Type_Id
);
19844 or else Rep_Item_Too_Early
(Typ
, N
)
19848 Typ
:= Underlying_Type
(Typ
);
19851 -- A pragma that applies to a Ghost entity becomes Ghost for the
19852 -- purposes of legality checks and removal of ignored Ghost code.
19854 Mark_Ghost_Pragma
(N
, Typ
);
19856 if not Is_Array_Type
(Typ
) and then not Is_Record_Type
(Typ
) then
19857 Error_Pragma
("pragma% must specify array or record type");
19860 Check_First_Subtype
(Arg1
);
19861 Check_Duplicate_Pragma
(Typ
);
19865 if Is_Array_Type
(Typ
) then
19866 Ctyp
:= Component_Type
(Typ
);
19868 -- Ignore pack that does nothing
19870 if Known_Static_Esize
(Ctyp
)
19871 and then Known_Static_RM_Size
(Ctyp
)
19872 and then Esize
(Ctyp
) = RM_Size
(Ctyp
)
19873 and then Addressable
(Esize
(Ctyp
))
19878 -- Process OK pragma Pack. Note that if there is a separate
19879 -- component clause present, the Pack will be cancelled. This
19880 -- processing is in Freeze.
19882 if not Rep_Item_Too_Late
(Typ
, N
) then
19884 -- In CodePeer mode, we do not need complex front-end
19885 -- expansions related to pragma Pack, so disable handling
19888 if CodePeer_Mode
then
19891 -- Normal case where we do the pack action
19895 Set_Is_Packed
(Base_Type
(Typ
));
19896 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
19899 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
19903 -- For record types, the pack is always effective
19905 else pragma Assert
(Is_Record_Type
(Typ
));
19906 if not Rep_Item_Too_Late
(Typ
, N
) then
19907 Set_Is_Packed
(Base_Type
(Typ
));
19908 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
19909 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
19920 -- There is nothing to do here, since we did all the processing for
19921 -- this pragma in Par.Prag (so that it works properly even in syntax
19924 when Pragma_Page
=>
19931 -- pragma Part_Of (ABSTRACT_STATE);
19933 -- ABSTRACT_STATE ::= NAME
19935 when Pragma_Part_Of
=> Part_Of
: declare
19936 procedure Propagate_Part_Of
19937 (Pack_Id
: Entity_Id
;
19938 State_Id
: Entity_Id
;
19939 Instance
: Node_Id
);
19940 -- Propagate the Part_Of indicator to all abstract states and
19941 -- objects declared in the visible state space of a package
19942 -- denoted by Pack_Id. State_Id is the encapsulating state.
19943 -- Instance is the package instantiation node.
19945 -----------------------
19946 -- Propagate_Part_Of --
19947 -----------------------
19949 procedure Propagate_Part_Of
19950 (Pack_Id
: Entity_Id
;
19951 State_Id
: Entity_Id
;
19952 Instance
: Node_Id
)
19954 Has_Item
: Boolean := False;
19955 -- Flag set when the visible state space contains at least one
19956 -- abstract state or variable.
19958 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
);
19959 -- Propagate the Part_Of indicator to all abstract states and
19960 -- objects declared in the visible state space of a package
19961 -- denoted by Pack_Id.
19963 -----------------------
19964 -- Propagate_Part_Of --
19965 -----------------------
19967 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
) is
19968 Constits
: Elist_Id
;
19969 Item_Id
: Entity_Id
;
19972 -- Traverse the entity chain of the package and set relevant
19973 -- attributes of abstract states and objects declared in the
19974 -- visible state space of the package.
19976 Item_Id
:= First_Entity
(Pack_Id
);
19977 while Present
(Item_Id
)
19978 and then not In_Private_Part
(Item_Id
)
19980 -- Do not consider internally generated items
19982 if not Comes_From_Source
(Item_Id
) then
19985 -- Do not consider generic formals or their corresponding
19986 -- actuals because they are not part of a visible state.
19987 -- Note that both entities are marked as hidden.
19989 elsif Is_Hidden
(Item_Id
) then
19992 -- The Part_Of indicator turns an abstract state or an
19993 -- object into a constituent of the encapsulating state.
19994 -- Note that constants are considered here even though
19995 -- they may not depend on variable input. This check is
19996 -- left to the SPARK prover.
19998 elsif Ekind_In
(Item_Id
, E_Abstract_State
,
20003 Constits
:= Part_Of_Constituents
(State_Id
);
20005 if No
(Constits
) then
20006 Constits
:= New_Elmt_List
;
20007 Set_Part_Of_Constituents
(State_Id
, Constits
);
20010 Append_Elmt
(Item_Id
, Constits
);
20011 Set_Encapsulating_State
(Item_Id
, State_Id
);
20013 -- Recursively handle nested packages and instantiations
20015 elsif Ekind
(Item_Id
) = E_Package
then
20016 Propagate_Part_Of
(Item_Id
);
20019 Next_Entity
(Item_Id
);
20021 end Propagate_Part_Of
;
20023 -- Start of processing for Propagate_Part_Of
20026 Propagate_Part_Of
(Pack_Id
);
20028 -- Detect a package instantiation that is subject to a Part_Of
20029 -- indicator, but has no visible state.
20031 if not Has_Item
then
20033 ("package instantiation & has Part_Of indicator but "
20034 & "lacks visible state", Instance
, Pack_Id
);
20036 end Propagate_Part_Of
;
20040 Constits
: Elist_Id
;
20042 Encap_Id
: Entity_Id
;
20043 Item_Id
: Entity_Id
;
20047 -- Start of processing for Part_Of
20051 Check_No_Identifiers
;
20052 Check_Arg_Count
(1);
20054 Stmt
:= Find_Related_Context
(N
, Do_Checks
=> True);
20056 -- Object declaration
20058 if Nkind
(Stmt
) = N_Object_Declaration
then
20061 -- Package instantiation
20063 elsif Nkind
(Stmt
) = N_Package_Instantiation
then
20066 -- Single concurrent type declaration
20068 elsif Is_Single_Concurrent_Type_Declaration
(Stmt
) then
20071 -- Otherwise the pragma is associated with an illegal construct
20078 -- Extract the entity of the related object declaration or package
20079 -- instantiation. In the case of the instantiation, use the entity
20080 -- of the instance spec.
20082 if Nkind
(Stmt
) = N_Package_Instantiation
then
20083 Stmt
:= Instance_Spec
(Stmt
);
20086 Item_Id
:= Defining_Entity
(Stmt
);
20088 -- A pragma that applies to a Ghost entity becomes Ghost for the
20089 -- purposes of legality checks and removal of ignored Ghost code.
20091 Mark_Ghost_Pragma
(N
, Item_Id
);
20093 -- Chain the pragma on the contract for further processing by
20094 -- Analyze_Part_Of_In_Decl_Part or for completeness.
20096 Add_Contract_Item
(N
, Item_Id
);
20098 -- A variable may act as constituent of a single concurrent type
20099 -- which in turn could be declared after the variable. Due to this
20100 -- discrepancy, the full analysis of indicator Part_Of is delayed
20101 -- until the end of the enclosing declarative region (see routine
20102 -- Analyze_Part_Of_In_Decl_Part).
20104 if Ekind
(Item_Id
) = E_Variable
then
20107 -- Otherwise indicator Part_Of applies to a constant or a package
20111 Encap
:= Get_Pragma_Arg
(Arg1
);
20113 -- Detect any discrepancies between the placement of the
20114 -- constant or package instantiation with respect to state
20115 -- space and the encapsulating state.
20119 Item_Id
=> Item_Id
,
20121 Encap_Id
=> Encap_Id
,
20125 pragma Assert
(Present
(Encap_Id
));
20127 if Ekind
(Item_Id
) = E_Constant
then
20128 Constits
:= Part_Of_Constituents
(Encap_Id
);
20130 if No
(Constits
) then
20131 Constits
:= New_Elmt_List
;
20132 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
20135 Append_Elmt
(Item_Id
, Constits
);
20136 Set_Encapsulating_State
(Item_Id
, Encap_Id
);
20138 -- Propagate the Part_Of indicator to the visible state
20139 -- space of the package instantiation.
20143 (Pack_Id
=> Item_Id
,
20144 State_Id
=> Encap_Id
,
20151 ----------------------------------
20152 -- Partition_Elaboration_Policy --
20153 ----------------------------------
20155 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
20157 when Pragma_Partition_Elaboration_Policy
=> PEP
: declare
20158 subtype PEP_Range
is Name_Id
20159 range First_Partition_Elaboration_Policy_Name
20160 .. Last_Partition_Elaboration_Policy_Name
;
20161 PEP_Val
: PEP_Range
;
20166 Check_Arg_Count
(1);
20167 Check_No_Identifiers
;
20168 Check_Arg_Is_Partition_Elaboration_Policy
(Arg1
);
20169 Check_Valid_Configuration_Pragma
;
20170 PEP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
20173 when Name_Concurrent
=> PEP
:= 'C';
20174 when Name_Sequential
=> PEP
:= 'S';
20177 if Partition_Elaboration_Policy
/= ' '
20178 and then Partition_Elaboration_Policy
/= PEP
20180 Error_Msg_Sloc
:= Partition_Elaboration_Policy_Sloc
;
20182 ("partition elaboration policy incompatible with policy#");
20184 -- Set new policy, but always preserve System_Location since we
20185 -- like the error message with the run time name.
20188 Partition_Elaboration_Policy
:= PEP
;
20190 if Partition_Elaboration_Policy_Sloc
/= System_Location
then
20191 Partition_Elaboration_Policy_Sloc
:= Loc
;
20200 -- pragma Passive [(PASSIVE_FORM)];
20202 -- PASSIVE_FORM ::= Semaphore | No
20204 when Pragma_Passive
=>
20207 if Nkind
(Parent
(N
)) /= N_Task_Definition
then
20208 Error_Pragma
("pragma% must be within task definition");
20211 if Arg_Count
/= 0 then
20212 Check_Arg_Count
(1);
20213 Check_Arg_Is_One_Of
(Arg1
, Name_Semaphore
, Name_No
);
20216 ----------------------------------
20217 -- Preelaborable_Initialization --
20218 ----------------------------------
20220 -- pragma Preelaborable_Initialization (DIRECT_NAME);
20222 when Pragma_Preelaborable_Initialization
=> Preelab_Init
: declare
20227 Check_Arg_Count
(1);
20228 Check_No_Identifiers
;
20229 Check_Arg_Is_Identifier
(Arg1
);
20230 Check_Arg_Is_Local_Name
(Arg1
);
20231 Check_First_Subtype
(Arg1
);
20232 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
20234 -- A pragma that applies to a Ghost entity becomes Ghost for the
20235 -- purposes of legality checks and removal of ignored Ghost code.
20237 Mark_Ghost_Pragma
(N
, Ent
);
20239 -- The pragma may come from an aspect on a private declaration,
20240 -- even if the freeze point at which this is analyzed in the
20241 -- private part after the full view.
20243 if Has_Private_Declaration
(Ent
)
20244 and then From_Aspect_Specification
(N
)
20248 -- Check appropriate type argument
20250 elsif Is_Private_Type
(Ent
)
20251 or else Is_Protected_Type
(Ent
)
20252 or else (Is_Generic_Type
(Ent
) and then Is_Derived_Type
(Ent
))
20254 -- AI05-0028: The pragma applies to all composite types. Note
20255 -- that we apply this binding interpretation to earlier versions
20256 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
20257 -- choice since there are other compilers that do the same.
20259 or else Is_Composite_Type
(Ent
)
20265 ("pragma % can only be applied to private, formal derived, "
20266 & "protected, or composite type", Arg1
);
20269 -- Give an error if the pragma is applied to a protected type that
20270 -- does not qualify (due to having entries, or due to components
20271 -- that do not qualify).
20273 if Is_Protected_Type
(Ent
)
20274 and then not Has_Preelaborable_Initialization
(Ent
)
20277 ("protected type & does not have preelaborable "
20278 & "initialization", Ent
);
20280 -- Otherwise mark the type as definitely having preelaborable
20284 Set_Known_To_Have_Preelab_Init
(Ent
);
20287 if Has_Pragma_Preelab_Init
(Ent
)
20288 and then Warn_On_Redundant_Constructs
20290 Error_Pragma
("?r?duplicate pragma%!");
20292 Set_Has_Pragma_Preelab_Init
(Ent
);
20296 --------------------
20297 -- Persistent_BSS --
20298 --------------------
20300 -- pragma Persistent_BSS [(object_NAME)];
20302 when Pragma_Persistent_BSS
=> Persistent_BSS
: declare
20309 Check_At_Most_N_Arguments
(1);
20311 -- Case of application to specific object (one argument)
20313 if Arg_Count
= 1 then
20314 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
20316 if not Is_Entity_Name
(Get_Pragma_Arg
(Arg1
))
20318 Ekind_In
(Entity
(Get_Pragma_Arg
(Arg1
)), E_Variable
,
20321 Error_Pragma_Arg
("pragma% only applies to objects", Arg1
);
20324 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
20326 -- A pragma that applies to a Ghost entity becomes Ghost for
20327 -- the purposes of legality checks and removal of ignored Ghost
20330 Mark_Ghost_Pragma
(N
, Ent
);
20332 -- Check for duplication before inserting in list of
20333 -- representation items.
20335 Check_Duplicate_Pragma
(Ent
);
20337 if Rep_Item_Too_Late
(Ent
, N
) then
20341 Decl
:= Parent
(Ent
);
20343 if Present
(Expression
(Decl
)) then
20345 ("object for pragma% cannot have initialization", Arg1
);
20348 if not Is_Potentially_Persistent_Type
(Etype
(Ent
)) then
20350 ("object type for pragma% is not potentially persistent",
20355 Make_Linker_Section_Pragma
20356 (Ent
, Sloc
(N
), ".persistent.bss");
20357 Insert_After
(N
, Prag
);
20360 -- Case of use as configuration pragma with no arguments
20363 Check_Valid_Configuration_Pragma
;
20364 Persistent_BSS_Mode
:= True;
20366 end Persistent_BSS
;
20368 --------------------
20369 -- Rename_Pragma --
20370 --------------------
20372 -- pragma Rename_Pragma (
20373 -- [New_Name =>] IDENTIFIER,
20374 -- [Renamed =>] pragma_IDENTIFIER);
20376 when Pragma_Rename_Pragma
=> Rename_Pragma
: declare
20377 New_Name
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20378 Old_Name
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
20382 Check_Valid_Configuration_Pragma
;
20383 Check_Arg_Count
(2);
20384 Check_Optional_Identifier
(Arg1
, Name_New_Name
);
20385 Check_Optional_Identifier
(Arg2
, Name_Renamed
);
20387 if Nkind
(New_Name
) /= N_Identifier
then
20388 Error_Pragma_Arg
("identifier expected", Arg1
);
20391 if Nkind
(Old_Name
) /= N_Identifier
then
20392 Error_Pragma_Arg
("identifier expected", Arg2
);
20395 -- The New_Name arg should not be an existing pragma (but we allow
20396 -- it; it's just a warning). The Old_Name arg must be an existing
20399 if Is_Pragma_Name
(Chars
(New_Name
)) then
20400 Error_Pragma_Arg
("??pragma is already defined", Arg1
);
20403 if not Is_Pragma_Name
(Chars
(Old_Name
)) then
20404 Error_Pragma_Arg
("existing pragma name expected", Arg1
);
20407 Map_Pragma_Name
(From
=> Chars
(New_Name
), To
=> Chars
(Old_Name
));
20414 -- pragma Polling (ON | OFF);
20416 when Pragma_Polling
=>
20418 Check_Arg_Count
(1);
20419 Check_No_Identifiers
;
20420 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
20421 Polling_Required
:= (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
);
20423 -----------------------------------
20424 -- Post/Post_Class/Postcondition --
20425 -----------------------------------
20427 -- pragma Post (Boolean_EXPRESSION);
20428 -- pragma Post_Class (Boolean_EXPRESSION);
20429 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
20430 -- [,[Message =>] String_EXPRESSION]);
20432 -- Characteristics:
20434 -- * Analysis - The annotation undergoes initial checks to verify
20435 -- the legal placement and context. Secondary checks preanalyze the
20438 -- Analyze_Pre_Post_Condition_In_Decl_Part
20440 -- * Expansion - The annotation is expanded during the expansion of
20441 -- the related subprogram [body] contract as performed in:
20443 -- Expand_Subprogram_Contract
20445 -- * Template - The annotation utilizes the generic template of the
20446 -- related subprogram [body] when it is:
20448 -- aspect on subprogram declaration
20449 -- aspect on stand-alone subprogram body
20450 -- pragma on stand-alone subprogram body
20452 -- The annotation must prepare its own template when it is:
20454 -- pragma on subprogram declaration
20456 -- * Globals - Capture of global references must occur after full
20459 -- * Instance - The annotation is instantiated automatically when
20460 -- the related generic subprogram [body] is instantiated except for
20461 -- the "pragma on subprogram declaration" case. In that scenario
20462 -- the annotation must instantiate itself.
20465 | Pragma_Post_Class
20466 | Pragma_Postcondition
20468 Analyze_Pre_Post_Condition
;
20470 --------------------------------
20471 -- Pre/Pre_Class/Precondition --
20472 --------------------------------
20474 -- pragma Pre (Boolean_EXPRESSION);
20475 -- pragma Pre_Class (Boolean_EXPRESSION);
20476 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
20477 -- [,[Message =>] String_EXPRESSION]);
20479 -- Characteristics:
20481 -- * Analysis - The annotation undergoes initial checks to verify
20482 -- the legal placement and context. Secondary checks preanalyze the
20485 -- Analyze_Pre_Post_Condition_In_Decl_Part
20487 -- * Expansion - The annotation is expanded during the expansion of
20488 -- the related subprogram [body] contract as performed in:
20490 -- Expand_Subprogram_Contract
20492 -- * Template - The annotation utilizes the generic template of the
20493 -- related subprogram [body] when it is:
20495 -- aspect on subprogram declaration
20496 -- aspect on stand-alone subprogram body
20497 -- pragma on stand-alone subprogram body
20499 -- The annotation must prepare its own template when it is:
20501 -- pragma on subprogram declaration
20503 -- * Globals - Capture of global references must occur after full
20506 -- * Instance - The annotation is instantiated automatically when
20507 -- the related generic subprogram [body] is instantiated except for
20508 -- the "pragma on subprogram declaration" case. In that scenario
20509 -- the annotation must instantiate itself.
20513 | Pragma_Precondition
20515 Analyze_Pre_Post_Condition
;
20521 -- pragma Predicate
20522 -- ([Entity =>] type_LOCAL_NAME,
20523 -- [Check =>] boolean_EXPRESSION);
20525 when Pragma_Predicate
=> Predicate
: declare
20532 Check_Arg_Count
(2);
20533 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20534 Check_Optional_Identifier
(Arg2
, Name_Check
);
20536 Check_Arg_Is_Local_Name
(Arg1
);
20538 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20539 Find_Type
(Type_Id
);
20540 Typ
:= Entity
(Type_Id
);
20542 if Typ
= Any_Type
then
20546 -- A pragma that applies to a Ghost entity becomes Ghost for the
20547 -- purposes of legality checks and removal of ignored Ghost code.
20549 Mark_Ghost_Pragma
(N
, Typ
);
20551 -- The remaining processing is simply to link the pragma on to
20552 -- the rep item chain, for processing when the type is frozen.
20553 -- This is accomplished by a call to Rep_Item_Too_Late. We also
20554 -- mark the type as having predicates.
20556 -- If the current policy for predicate checking is Ignore mark the
20557 -- subtype accordingly. In the case of predicates we consider them
20558 -- enabled unless Ignore is specified (either directly or with a
20559 -- general Assertion_Policy pragma) to preserve existing warnings.
20561 Set_Has_Predicates
(Typ
);
20563 -- Indicate that the pragma must be processed at the point the
20564 -- type is frozen, as is done for the corresponding aspect.
20566 Set_Has_Delayed_Aspects
(Typ
);
20567 Set_Has_Delayed_Freeze
(Typ
);
20569 Set_Predicates_Ignored
(Typ
,
20570 Present
(Check_Policy_List
)
20572 Policy_In_Effect
(Name_Dynamic_Predicate
) = Name_Ignore
);
20573 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
20576 -----------------------
20577 -- Predicate_Failure --
20578 -----------------------
20580 -- pragma Predicate_Failure
20581 -- ([Entity =>] type_LOCAL_NAME,
20582 -- [Message =>] string_EXPRESSION);
20584 when Pragma_Predicate_Failure
=> Predicate_Failure
: declare
20591 Check_Arg_Count
(2);
20592 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20593 Check_Optional_Identifier
(Arg2
, Name_Message
);
20595 Check_Arg_Is_Local_Name
(Arg1
);
20597 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20598 Find_Type
(Type_Id
);
20599 Typ
:= Entity
(Type_Id
);
20601 if Typ
= Any_Type
then
20605 -- A pragma that applies to a Ghost entity becomes Ghost for the
20606 -- purposes of legality checks and removal of ignored Ghost code.
20608 Mark_Ghost_Pragma
(N
, Typ
);
20610 -- The remaining processing is simply to link the pragma on to
20611 -- the rep item chain, for processing when the type is frozen.
20612 -- This is accomplished by a call to Rep_Item_Too_Late.
20614 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
20615 end Predicate_Failure
;
20621 -- pragma Preelaborate [(library_unit_NAME)];
20623 -- Set the flag Is_Preelaborated of program unit name entity
20625 when Pragma_Preelaborate
=> Preelaborate
: declare
20626 Pa
: constant Node_Id
:= Parent
(N
);
20627 Pk
: constant Node_Kind
:= Nkind
(Pa
);
20631 Check_Ada_83_Warning
;
20632 Check_Valid_Library_Unit_Pragma
;
20634 if Nkind
(N
) = N_Null_Statement
then
20638 Ent
:= Find_Lib_Unit_Name
;
20640 -- A pragma that applies to a Ghost entity becomes Ghost for the
20641 -- purposes of legality checks and removal of ignored Ghost code.
20643 Mark_Ghost_Pragma
(N
, Ent
);
20644 Check_Duplicate_Pragma
(Ent
);
20646 -- This filters out pragmas inside generic parents that show up
20647 -- inside instantiations. Pragmas that come from aspects in the
20648 -- unit are not ignored.
20650 if Present
(Ent
) then
20651 if Pk
= N_Package_Specification
20652 and then Present
(Generic_Parent
(Pa
))
20653 and then not From_Aspect_Specification
(N
)
20658 if not Debug_Flag_U
then
20659 Set_Is_Preelaborated
(Ent
);
20661 if Legacy_Elaboration_Checks
then
20662 Set_Suppress_Elaboration_Warnings
(Ent
);
20669 -------------------------------
20670 -- Prefix_Exception_Messages --
20671 -------------------------------
20673 -- pragma Prefix_Exception_Messages;
20675 when Pragma_Prefix_Exception_Messages
=>
20677 Check_Valid_Configuration_Pragma
;
20678 Check_Arg_Count
(0);
20679 Prefix_Exception_Messages
:= True;
20685 -- pragma Priority (EXPRESSION);
20687 when Pragma_Priority
=> Priority
: declare
20688 P
: constant Node_Id
:= Parent
(N
);
20693 Check_No_Identifiers
;
20694 Check_Arg_Count
(1);
20698 if Nkind
(P
) = N_Subprogram_Body
then
20699 Check_In_Main_Program
;
20701 Ent
:= Defining_Unit_Name
(Specification
(P
));
20703 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
20704 Ent
:= Defining_Identifier
(Ent
);
20707 Arg
:= Get_Pragma_Arg
(Arg1
);
20708 Analyze_And_Resolve
(Arg
, Standard_Integer
);
20712 if not Is_OK_Static_Expression
(Arg
) then
20713 Flag_Non_Static_Expr
20714 ("main subprogram priority is not static!", Arg
);
20717 -- If constraint error, then we already signalled an error
20719 elsif Raises_Constraint_Error
(Arg
) then
20722 -- Otherwise check in range except if Relaxed_RM_Semantics
20723 -- where we ignore the value if out of range.
20726 if not Relaxed_RM_Semantics
20727 and then not Is_In_Range
(Arg
, RTE
(RE_Priority
))
20730 ("main subprogram priority is out of range", Arg1
);
20733 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
20737 -- Load an arbitrary entity from System.Tasking.Stages or
20738 -- System.Tasking.Restricted.Stages (depending on the
20739 -- supported profile) to make sure that one of these packages
20740 -- is implicitly with'ed, since we need to have the tasking
20741 -- run time active for the pragma Priority to have any effect.
20742 -- Previously we with'ed the package System.Tasking, but this
20743 -- package does not trigger the required initialization of the
20744 -- run-time library.
20747 Discard
: Entity_Id
;
20748 pragma Warnings
(Off
, Discard
);
20750 if Restricted_Profile
then
20751 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
20753 Discard
:= RTE
(RE_Activate_Tasks
);
20757 -- Task or Protected, must be of type Integer
20759 elsif Nkind_In
(P
, N_Protected_Definition
, N_Task_Definition
) then
20760 Arg
:= Get_Pragma_Arg
(Arg1
);
20761 Ent
:= Defining_Identifier
(Parent
(P
));
20763 -- The expression must be analyzed in the special manner
20764 -- described in "Handling of Default and Per-Object
20765 -- Expressions" in sem.ads.
20767 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Any_Priority
));
20769 if not Is_OK_Static_Expression
(Arg
) then
20770 Check_Restriction
(Static_Priorities
, Arg
);
20773 -- Anything else is incorrect
20779 -- Check duplicate pragma before we chain the pragma in the Rep
20780 -- Item chain of Ent.
20782 Check_Duplicate_Pragma
(Ent
);
20783 Record_Rep_Item
(Ent
, N
);
20786 -----------------------------------
20787 -- Priority_Specific_Dispatching --
20788 -----------------------------------
20790 -- pragma Priority_Specific_Dispatching (
20791 -- policy_IDENTIFIER,
20792 -- first_priority_EXPRESSION,
20793 -- last_priority_EXPRESSION);
20795 when Pragma_Priority_Specific_Dispatching
=>
20796 Priority_Specific_Dispatching
: declare
20797 Prio_Id
: constant Entity_Id
:= RTE
(RE_Any_Priority
);
20798 -- This is the entity System.Any_Priority;
20801 Lower_Bound
: Node_Id
;
20802 Upper_Bound
: Node_Id
;
20808 Check_Arg_Count
(3);
20809 Check_No_Identifiers
;
20810 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
20811 Check_Valid_Configuration_Pragma
;
20812 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
20813 DP
:= Fold_Upper
(Name_Buffer
(1));
20815 Lower_Bound
:= Get_Pragma_Arg
(Arg2
);
20816 Check_Arg_Is_OK_Static_Expression
(Lower_Bound
, Standard_Integer
);
20817 Lower_Val
:= Expr_Value
(Lower_Bound
);
20819 Upper_Bound
:= Get_Pragma_Arg
(Arg3
);
20820 Check_Arg_Is_OK_Static_Expression
(Upper_Bound
, Standard_Integer
);
20821 Upper_Val
:= Expr_Value
(Upper_Bound
);
20823 -- It is not allowed to use Task_Dispatching_Policy and
20824 -- Priority_Specific_Dispatching in the same partition.
20826 if Task_Dispatching_Policy
/= ' ' then
20827 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
20829 ("pragma% incompatible with Task_Dispatching_Policy#");
20831 -- Check lower bound in range
20833 elsif Lower_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
20835 Lower_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
20838 ("first_priority is out of range", Arg2
);
20840 -- Check upper bound in range
20842 elsif Upper_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
20844 Upper_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
20847 ("last_priority is out of range", Arg3
);
20849 -- Check that the priority range is valid
20851 elsif Lower_Val
> Upper_Val
then
20853 ("last_priority_expression must be greater than or equal to "
20854 & "first_priority_expression");
20856 -- Store the new policy, but always preserve System_Location since
20857 -- we like the error message with the run-time name.
20860 -- Check overlapping in the priority ranges specified in other
20861 -- Priority_Specific_Dispatching pragmas within the same
20862 -- partition. We can only check those we know about.
20865 Specific_Dispatching
.First
.. Specific_Dispatching
.Last
20867 if Specific_Dispatching
.Table
(J
).First_Priority
in
20868 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
20869 or else Specific_Dispatching
.Table
(J
).Last_Priority
in
20870 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
20873 Specific_Dispatching
.Table
(J
).Pragma_Loc
;
20875 ("priority range overlaps with "
20876 & "Priority_Specific_Dispatching#");
20880 -- The use of Priority_Specific_Dispatching is incompatible
20881 -- with Task_Dispatching_Policy.
20883 if Task_Dispatching_Policy
/= ' ' then
20884 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
20886 ("Priority_Specific_Dispatching incompatible "
20887 & "with Task_Dispatching_Policy#");
20890 -- The use of Priority_Specific_Dispatching forces ceiling
20893 if Locking_Policy
/= ' ' and then Locking_Policy
/= 'C' then
20894 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
20896 ("Priority_Specific_Dispatching incompatible "
20897 & "with Locking_Policy#");
20899 -- Set the Ceiling_Locking policy, but preserve System_Location
20900 -- since we like the error message with the run time name.
20903 Locking_Policy
:= 'C';
20905 if Locking_Policy_Sloc
/= System_Location
then
20906 Locking_Policy_Sloc
:= Loc
;
20910 -- Add entry in the table
20912 Specific_Dispatching
.Append
20913 ((Dispatching_Policy
=> DP
,
20914 First_Priority
=> UI_To_Int
(Lower_Val
),
20915 Last_Priority
=> UI_To_Int
(Upper_Val
),
20916 Pragma_Loc
=> Loc
));
20918 end Priority_Specific_Dispatching
;
20924 -- pragma Profile (profile_IDENTIFIER);
20926 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
20928 when Pragma_Profile
=>
20930 Check_Arg_Count
(1);
20931 Check_Valid_Configuration_Pragma
;
20932 Check_No_Identifiers
;
20935 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20938 if Chars
(Argx
) = Name_Ravenscar
then
20939 Set_Ravenscar_Profile
(Ravenscar
, N
);
20941 elsif Chars
(Argx
) = Name_Gnat_Extended_Ravenscar
then
20942 Set_Ravenscar_Profile
(GNAT_Extended_Ravenscar
, N
);
20944 elsif Chars
(Argx
) = Name_Gnat_Ravenscar_EDF
then
20945 Set_Ravenscar_Profile
(GNAT_Ravenscar_EDF
, N
);
20947 elsif Chars
(Argx
) = Name_Restricted
then
20948 Set_Profile_Restrictions
20950 N
, Warn
=> Treat_Restrictions_As_Warnings
);
20952 elsif Chars
(Argx
) = Name_Rational
then
20953 Set_Rational_Profile
;
20955 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
20956 Set_Profile_Restrictions
20957 (No_Implementation_Extensions
,
20958 N
, Warn
=> Treat_Restrictions_As_Warnings
);
20961 Error_Pragma_Arg
("& is not a valid profile", Argx
);
20965 ----------------------
20966 -- Profile_Warnings --
20967 ----------------------
20969 -- pragma Profile_Warnings (profile_IDENTIFIER);
20971 -- profile_IDENTIFIER => Restricted | Ravenscar
20973 when Pragma_Profile_Warnings
=>
20975 Check_Arg_Count
(1);
20976 Check_Valid_Configuration_Pragma
;
20977 Check_No_Identifiers
;
20980 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20983 if Chars
(Argx
) = Name_Ravenscar
then
20984 Set_Profile_Restrictions
(Ravenscar
, N
, Warn
=> True);
20986 elsif Chars
(Argx
) = Name_Restricted
then
20987 Set_Profile_Restrictions
(Restricted
, N
, Warn
=> True);
20989 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
20990 Set_Profile_Restrictions
20991 (No_Implementation_Extensions
, N
, Warn
=> True);
20994 Error_Pragma_Arg
("& is not a valid profile", Argx
);
20998 --------------------------
20999 -- Propagate_Exceptions --
21000 --------------------------
21002 -- pragma Propagate_Exceptions;
21004 -- Note: this pragma is obsolete and has no effect
21006 when Pragma_Propagate_Exceptions
=>
21008 Check_Arg_Count
(0);
21010 if Warn_On_Obsolescent_Feature
then
21012 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
21013 "and has no effect?j?", N
);
21016 -----------------------------
21017 -- Provide_Shift_Operators --
21018 -----------------------------
21020 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
21022 when Pragma_Provide_Shift_Operators
=>
21023 Provide_Shift_Operators
: declare
21026 procedure Declare_Shift_Operator
(Nam
: Name_Id
);
21027 -- Insert declaration and pragma Instrinsic for named shift op
21029 ----------------------------
21030 -- Declare_Shift_Operator --
21031 ----------------------------
21033 procedure Declare_Shift_Operator
(Nam
: Name_Id
) is
21039 Make_Subprogram_Declaration
(Loc
,
21040 Make_Function_Specification
(Loc
,
21041 Defining_Unit_Name
=>
21042 Make_Defining_Identifier
(Loc
, Chars
=> Nam
),
21044 Result_Definition
=>
21045 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
)),
21047 Parameter_Specifications
=> New_List
(
21048 Make_Parameter_Specification
(Loc
,
21049 Defining_Identifier
=>
21050 Make_Defining_Identifier
(Loc
, Name_Value
),
21052 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
))),
21054 Make_Parameter_Specification
(Loc
,
21055 Defining_Identifier
=>
21056 Make_Defining_Identifier
(Loc
, Name_Amount
),
21058 New_Occurrence_Of
(Standard_Natural
, Loc
)))));
21062 Chars
=> Name_Import
,
21063 Pragma_Argument_Associations
=> New_List
(
21064 Make_Pragma_Argument_Association
(Loc
,
21065 Expression
=> Make_Identifier
(Loc
, Name_Intrinsic
)),
21066 Make_Pragma_Argument_Association
(Loc
,
21067 Expression
=> Make_Identifier
(Loc
, Nam
))));
21069 Insert_After
(N
, Import
);
21070 Insert_After
(N
, Func
);
21071 end Declare_Shift_Operator
;
21073 -- Start of processing for Provide_Shift_Operators
21077 Check_Arg_Count
(1);
21078 Check_Arg_Is_Local_Name
(Arg1
);
21080 Arg1
:= Get_Pragma_Arg
(Arg1
);
21082 -- We must have an entity name
21084 if not Is_Entity_Name
(Arg1
) then
21086 ("pragma % must apply to integer first subtype", Arg1
);
21089 -- If no Entity, means there was a prior error so ignore
21091 if Present
(Entity
(Arg1
)) then
21092 Ent
:= Entity
(Arg1
);
21094 -- Apply error checks
21096 if not Is_First_Subtype
(Ent
) then
21098 ("cannot apply pragma %",
21099 "\& is not a first subtype",
21102 elsif not Is_Integer_Type
(Ent
) then
21104 ("cannot apply pragma %",
21105 "\& is not an integer type",
21108 elsif Has_Shift_Operator
(Ent
) then
21110 ("cannot apply pragma %",
21111 "\& already has declared shift operators",
21114 elsif Is_Frozen
(Ent
) then
21116 ("pragma % appears too late",
21117 "\& is already frozen",
21121 -- Now declare the operators. We do this during analysis rather
21122 -- than expansion, since we want the operators available if we
21123 -- are operating in -gnatc or ASIS mode.
21125 Declare_Shift_Operator
(Name_Rotate_Left
);
21126 Declare_Shift_Operator
(Name_Rotate_Right
);
21127 Declare_Shift_Operator
(Name_Shift_Left
);
21128 Declare_Shift_Operator
(Name_Shift_Right
);
21129 Declare_Shift_Operator
(Name_Shift_Right_Arithmetic
);
21131 end Provide_Shift_Operators
;
21137 -- pragma Psect_Object (
21138 -- [Internal =>] LOCAL_NAME,
21139 -- [, [External =>] EXTERNAL_SYMBOL]
21140 -- [, [Size =>] EXTERNAL_SYMBOL]);
21142 when Pragma_Common_Object
21143 | Pragma_Psect_Object
21145 Psect_Object
: declare
21146 Args
: Args_List
(1 .. 3);
21147 Names
: constant Name_List
(1 .. 3) := (
21152 Internal
: Node_Id
renames Args
(1);
21153 External
: Node_Id
renames Args
(2);
21154 Size
: Node_Id
renames Args
(3);
21156 Def_Id
: Entity_Id
;
21158 procedure Check_Arg
(Arg
: Node_Id
);
21159 -- Checks that argument is either a string literal or an
21160 -- identifier, and posts error message if not.
21166 procedure Check_Arg
(Arg
: Node_Id
) is
21168 if not Nkind_In
(Original_Node
(Arg
),
21173 ("inappropriate argument for pragma %", Arg
);
21177 -- Start of processing for Common_Object/Psect_Object
21181 Gather_Associations
(Names
, Args
);
21182 Process_Extended_Import_Export_Internal_Arg
(Internal
);
21184 Def_Id
:= Entity
(Internal
);
21186 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
21188 ("pragma% must designate an object", Internal
);
21191 Check_Arg
(Internal
);
21193 if Is_Imported
(Def_Id
) or else Is_Exported
(Def_Id
) then
21195 ("cannot use pragma% for imported/exported object",
21199 if Is_Concurrent_Type
(Etype
(Internal
)) then
21201 ("cannot specify pragma % for task/protected object",
21205 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
21207 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
21209 Error_Msg_N
("??duplicate Common/Psect_Object pragma", N
);
21212 if Ekind
(Def_Id
) = E_Constant
then
21214 ("cannot specify pragma % for a constant", Internal
);
21217 if Is_Record_Type
(Etype
(Internal
)) then
21223 Ent
:= First_Entity
(Etype
(Internal
));
21224 while Present
(Ent
) loop
21225 Decl
:= Declaration_Node
(Ent
);
21227 if Ekind
(Ent
) = E_Component
21228 and then Nkind
(Decl
) = N_Component_Declaration
21229 and then Present
(Expression
(Decl
))
21230 and then Warn_On_Export_Import
21233 ("?x?object for pragma % has defaults", Internal
);
21243 if Present
(Size
) then
21247 if Present
(External
) then
21248 Check_Arg_Is_External_Name
(External
);
21251 -- If all error tests pass, link pragma on to the rep item chain
21253 Record_Rep_Item
(Def_Id
, N
);
21260 -- pragma Pure [(library_unit_NAME)];
21262 when Pragma_Pure
=> Pure
: declare
21266 Check_Ada_83_Warning
;
21268 -- If the pragma comes from a subprogram instantiation, nothing to
21269 -- check, this can happen at any level of nesting.
21271 if Is_Wrapper_Package
(Current_Scope
) then
21274 Check_Valid_Library_Unit_Pragma
;
21277 if Nkind
(N
) = N_Null_Statement
then
21281 Ent
:= Find_Lib_Unit_Name
;
21283 -- A pragma that applies to a Ghost entity becomes Ghost for the
21284 -- purposes of legality checks and removal of ignored Ghost code.
21286 Mark_Ghost_Pragma
(N
, Ent
);
21288 if not Debug_Flag_U
then
21290 Set_Has_Pragma_Pure
(Ent
);
21292 if Legacy_Elaboration_Checks
then
21293 Set_Suppress_Elaboration_Warnings
(Ent
);
21298 -------------------
21299 -- Pure_Function --
21300 -------------------
21302 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
21304 when Pragma_Pure_Function
=> Pure_Function
: declare
21305 Def_Id
: Entity_Id
;
21308 Effective
: Boolean := False;
21309 Orig_Def
: Entity_Id
;
21310 Same_Decl
: Boolean := False;
21314 Check_Arg_Count
(1);
21315 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21316 Check_Arg_Is_Local_Name
(Arg1
);
21317 E_Id
:= Get_Pragma_Arg
(Arg1
);
21319 if Etype
(E_Id
) = Any_Type
then
21323 -- Loop through homonyms (overloadings) of referenced entity
21325 E
:= Entity
(E_Id
);
21327 -- A pragma that applies to a Ghost entity becomes Ghost for the
21328 -- purposes of legality checks and removal of ignored Ghost code.
21330 Mark_Ghost_Pragma
(N
, E
);
21332 if Present
(E
) then
21334 Def_Id
:= Get_Base_Subprogram
(E
);
21336 if not Ekind_In
(Def_Id
, E_Function
,
21337 E_Generic_Function
,
21341 ("pragma% requires a function name", Arg1
);
21344 -- When we have a generic function we must jump up a level
21345 -- to the declaration of the wrapper package itself.
21347 Orig_Def
:= Def_Id
;
21349 if Is_Generic_Instance
(Def_Id
) then
21350 while Nkind
(Orig_Def
) /= N_Package_Declaration
loop
21351 Orig_Def
:= Parent
(Orig_Def
);
21355 if In_Same_Declarative_Part
(Parent
(N
), Orig_Def
) then
21357 Set_Is_Pure
(Def_Id
);
21359 if not Has_Pragma_Pure_Function
(Def_Id
) then
21360 Set_Has_Pragma_Pure_Function
(Def_Id
);
21365 exit when From_Aspect_Specification
(N
);
21367 exit when No
(E
) or else Scope
(E
) /= Current_Scope
;
21371 and then Warn_On_Redundant_Constructs
21374 ("pragma Pure_Function on& is redundant?r?",
21377 elsif not Same_Decl
then
21379 ("pragma% argument must be in same declarative part",
21385 --------------------
21386 -- Queuing_Policy --
21387 --------------------
21389 -- pragma Queuing_Policy (policy_IDENTIFIER);
21391 when Pragma_Queuing_Policy
=> declare
21395 Check_Ada_83_Warning
;
21396 Check_Arg_Count
(1);
21397 Check_No_Identifiers
;
21398 Check_Arg_Is_Queuing_Policy
(Arg1
);
21399 Check_Valid_Configuration_Pragma
;
21400 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
21401 QP
:= Fold_Upper
(Name_Buffer
(1));
21403 if Queuing_Policy
/= ' '
21404 and then Queuing_Policy
/= QP
21406 Error_Msg_Sloc
:= Queuing_Policy_Sloc
;
21407 Error_Pragma
("queuing policy incompatible with policy#");
21409 -- Set new policy, but always preserve System_Location since we
21410 -- like the error message with the run time name.
21413 Queuing_Policy
:= QP
;
21415 if Queuing_Policy_Sloc
/= System_Location
then
21416 Queuing_Policy_Sloc
:= Loc
;
21425 -- pragma Rational, for compatibility with foreign compiler
21427 when Pragma_Rational
=>
21428 Set_Rational_Profile
;
21430 ---------------------
21431 -- Refined_Depends --
21432 ---------------------
21434 -- pragma Refined_Depends (DEPENDENCY_RELATION);
21436 -- DEPENDENCY_RELATION ::=
21438 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
21440 -- DEPENDENCY_CLAUSE ::=
21441 -- OUTPUT_LIST =>[+] INPUT_LIST
21442 -- | NULL_DEPENDENCY_CLAUSE
21444 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
21446 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
21448 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
21450 -- OUTPUT ::= NAME | FUNCTION_RESULT
21453 -- where FUNCTION_RESULT is a function Result attribute_reference
21455 -- Characteristics:
21457 -- * Analysis - The annotation undergoes initial checks to verify
21458 -- the legal placement and context. Secondary checks fully analyze
21459 -- the dependency clauses/global list in:
21461 -- Analyze_Refined_Depends_In_Decl_Part
21463 -- * Expansion - None.
21465 -- * Template - The annotation utilizes the generic template of the
21466 -- related subprogram body.
21468 -- * Globals - Capture of global references must occur after full
21471 -- * Instance - The annotation is instantiated automatically when
21472 -- the related generic subprogram body is instantiated.
21474 when Pragma_Refined_Depends
=> Refined_Depends
: declare
21475 Body_Id
: Entity_Id
;
21477 Spec_Id
: Entity_Id
;
21480 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21484 -- Chain the pragma on the contract for further processing by
21485 -- Analyze_Refined_Depends_In_Decl_Part.
21487 Add_Contract_Item
(N
, Body_Id
);
21489 -- The legality checks of pragmas Refined_Depends and
21490 -- Refined_Global are affected by the SPARK mode in effect and
21491 -- the volatility of the context. In addition these two pragmas
21492 -- are subject to an inherent order:
21494 -- 1) Refined_Global
21495 -- 2) Refined_Depends
21497 -- Analyze all these pragmas in the order outlined above
21499 Analyze_If_Present
(Pragma_SPARK_Mode
);
21500 Analyze_If_Present
(Pragma_Volatile_Function
);
21501 Analyze_If_Present
(Pragma_Refined_Global
);
21502 Analyze_Refined_Depends_In_Decl_Part
(N
);
21504 end Refined_Depends
;
21506 --------------------
21507 -- Refined_Global --
21508 --------------------
21510 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
21512 -- GLOBAL_SPECIFICATION ::=
21515 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
21517 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
21519 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
21520 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
21521 -- GLOBAL_ITEM ::= NAME
21523 -- Characteristics:
21525 -- * Analysis - The annotation undergoes initial checks to verify
21526 -- the legal placement and context. Secondary checks fully analyze
21527 -- the dependency clauses/global list in:
21529 -- Analyze_Refined_Global_In_Decl_Part
21531 -- * Expansion - None.
21533 -- * Template - The annotation utilizes the generic template of the
21534 -- related subprogram body.
21536 -- * Globals - Capture of global references must occur after full
21539 -- * Instance - The annotation is instantiated automatically when
21540 -- the related generic subprogram body is instantiated.
21542 when Pragma_Refined_Global
=> Refined_Global
: declare
21543 Body_Id
: Entity_Id
;
21545 Spec_Id
: Entity_Id
;
21548 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21552 -- Chain the pragma on the contract for further processing by
21553 -- Analyze_Refined_Global_In_Decl_Part.
21555 Add_Contract_Item
(N
, Body_Id
);
21557 -- The legality checks of pragmas Refined_Depends and
21558 -- Refined_Global are affected by the SPARK mode in effect and
21559 -- the volatility of the context. In addition these two pragmas
21560 -- are subject to an inherent order:
21562 -- 1) Refined_Global
21563 -- 2) Refined_Depends
21565 -- Analyze all these pragmas in the order outlined above
21567 Analyze_If_Present
(Pragma_SPARK_Mode
);
21568 Analyze_If_Present
(Pragma_Volatile_Function
);
21569 Analyze_Refined_Global_In_Decl_Part
(N
);
21570 Analyze_If_Present
(Pragma_Refined_Depends
);
21572 end Refined_Global
;
21578 -- pragma Refined_Post (boolean_EXPRESSION);
21580 -- Characteristics:
21582 -- * Analysis - The annotation is fully analyzed immediately upon
21583 -- elaboration as it cannot forward reference entities.
21585 -- * Expansion - The annotation is expanded during the expansion of
21586 -- the related subprogram body contract as performed in:
21588 -- Expand_Subprogram_Contract
21590 -- * Template - The annotation utilizes the generic template of the
21591 -- related subprogram body.
21593 -- * Globals - Capture of global references must occur after full
21596 -- * Instance - The annotation is instantiated automatically when
21597 -- the related generic subprogram body is instantiated.
21599 when Pragma_Refined_Post
=> Refined_Post
: declare
21600 Body_Id
: Entity_Id
;
21602 Spec_Id
: Entity_Id
;
21605 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21607 -- Fully analyze the pragma when it appears inside a subprogram
21608 -- body because it cannot benefit from forward references.
21612 -- Chain the pragma on the contract for completeness
21614 Add_Contract_Item
(N
, Body_Id
);
21616 -- The legality checks of pragma Refined_Post are affected by
21617 -- the SPARK mode in effect and the volatility of the context.
21618 -- Analyze all pragmas in a specific order.
21620 Analyze_If_Present
(Pragma_SPARK_Mode
);
21621 Analyze_If_Present
(Pragma_Volatile_Function
);
21622 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
21624 -- Currently it is not possible to inline pre/postconditions on
21625 -- a subprogram subject to pragma Inline_Always.
21627 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
21631 -------------------
21632 -- Refined_State --
21633 -------------------
21635 -- pragma Refined_State (REFINEMENT_LIST);
21637 -- REFINEMENT_LIST ::=
21638 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
21640 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
21642 -- CONSTITUENT_LIST ::=
21645 -- | (CONSTITUENT {, CONSTITUENT})
21647 -- CONSTITUENT ::= object_NAME | state_NAME
21649 -- Characteristics:
21651 -- * Analysis - The annotation undergoes initial checks to verify
21652 -- the legal placement and context. Secondary checks preanalyze the
21653 -- refinement clauses in:
21655 -- Analyze_Refined_State_In_Decl_Part
21657 -- * Expansion - None.
21659 -- * Template - The annotation utilizes the template of the related
21662 -- * Globals - Capture of global references must occur after full
21665 -- * Instance - The annotation is instantiated automatically when
21666 -- the related generic package body is instantiated.
21668 when Pragma_Refined_State
=> Refined_State
: declare
21669 Pack_Decl
: Node_Id
;
21670 Spec_Id
: Entity_Id
;
21674 Check_No_Identifiers
;
21675 Check_Arg_Count
(1);
21677 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
21679 if Nkind
(Pack_Decl
) /= N_Package_Body
then
21684 Spec_Id
:= Corresponding_Spec
(Pack_Decl
);
21686 -- A pragma that applies to a Ghost entity becomes Ghost for the
21687 -- purposes of legality checks and removal of ignored Ghost code.
21689 Mark_Ghost_Pragma
(N
, Spec_Id
);
21691 -- Chain the pragma on the contract for further processing by
21692 -- Analyze_Refined_State_In_Decl_Part.
21694 Add_Contract_Item
(N
, Defining_Entity
(Pack_Decl
));
21696 -- The legality checks of pragma Refined_State are affected by the
21697 -- SPARK mode in effect. Analyze all pragmas in a specific order.
21699 Analyze_If_Present
(Pragma_SPARK_Mode
);
21701 -- State refinement is allowed only when the corresponding package
21702 -- declaration has non-null pragma Abstract_State. Refinement not
21703 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
21705 if SPARK_Mode
/= Off
21707 (No
(Abstract_States
(Spec_Id
))
21708 or else Has_Null_Abstract_State
(Spec_Id
))
21711 ("useless refinement, package & does not define abstract "
21712 & "states", N
, Spec_Id
);
21717 -----------------------
21718 -- Relative_Deadline --
21719 -----------------------
21721 -- pragma Relative_Deadline (time_span_EXPRESSION);
21723 when Pragma_Relative_Deadline
=> Relative_Deadline
: declare
21724 P
: constant Node_Id
:= Parent
(N
);
21729 Check_No_Identifiers
;
21730 Check_Arg_Count
(1);
21732 Arg
:= Get_Pragma_Arg
(Arg1
);
21734 -- The expression must be analyzed in the special manner described
21735 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
21737 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
21741 if Nkind
(P
) = N_Subprogram_Body
then
21742 Check_In_Main_Program
;
21744 -- Only Task and subprogram cases allowed
21746 elsif Nkind
(P
) /= N_Task_Definition
then
21750 -- Check duplicate pragma before we set the corresponding flag
21752 if Has_Relative_Deadline_Pragma
(P
) then
21753 Error_Pragma
("duplicate pragma% not allowed");
21756 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
21757 -- Relative_Deadline pragma node cannot be inserted in the Rep
21758 -- Item chain of Ent since it is rewritten by the expander as a
21759 -- procedure call statement that will break the chain.
21761 Set_Has_Relative_Deadline_Pragma
(P
);
21762 end Relative_Deadline
;
21764 ------------------------
21765 -- Remote_Access_Type --
21766 ------------------------
21768 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
21770 when Pragma_Remote_Access_Type
=> Remote_Access_Type
: declare
21775 Check_Arg_Count
(1);
21776 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21777 Check_Arg_Is_Local_Name
(Arg1
);
21779 E
:= Entity
(Get_Pragma_Arg
(Arg1
));
21781 -- A pragma that applies to a Ghost entity becomes Ghost for the
21782 -- purposes of legality checks and removal of ignored Ghost code.
21784 Mark_Ghost_Pragma
(N
, E
);
21786 if Nkind
(Parent
(E
)) = N_Formal_Type_Declaration
21787 and then Ekind
(E
) = E_General_Access_Type
21788 and then Is_Class_Wide_Type
(Directly_Designated_Type
(E
))
21789 and then Scope
(Root_Type
(Directly_Designated_Type
(E
)))
21791 and then Is_Valid_Remote_Object_Type
21792 (Root_Type
(Directly_Designated_Type
(E
)))
21794 Set_Is_Remote_Types
(E
);
21798 ("pragma% applies only to formal access-to-class-wide types",
21801 end Remote_Access_Type
;
21803 ---------------------------
21804 -- Remote_Call_Interface --
21805 ---------------------------
21807 -- pragma Remote_Call_Interface [(library_unit_NAME)];
21809 when Pragma_Remote_Call_Interface
=> Remote_Call_Interface
: declare
21810 Cunit_Node
: Node_Id
;
21811 Cunit_Ent
: Entity_Id
;
21815 Check_Ada_83_Warning
;
21816 Check_Valid_Library_Unit_Pragma
;
21818 if Nkind
(N
) = N_Null_Statement
then
21822 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21823 K
:= Nkind
(Unit
(Cunit_Node
));
21824 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21826 -- A pragma that applies to a Ghost entity becomes Ghost for the
21827 -- purposes of legality checks and removal of ignored Ghost code.
21829 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21831 if K
= N_Package_Declaration
21832 or else K
= N_Generic_Package_Declaration
21833 or else K
= N_Subprogram_Declaration
21834 or else K
= N_Generic_Subprogram_Declaration
21835 or else (K
= N_Subprogram_Body
21836 and then Acts_As_Spec
(Unit
(Cunit_Node
)))
21841 "pragma% must apply to package or subprogram declaration");
21844 Set_Is_Remote_Call_Interface
(Cunit_Ent
);
21845 end Remote_Call_Interface
;
21851 -- pragma Remote_Types [(library_unit_NAME)];
21853 when Pragma_Remote_Types
=> Remote_Types
: declare
21854 Cunit_Node
: Node_Id
;
21855 Cunit_Ent
: Entity_Id
;
21858 Check_Ada_83_Warning
;
21859 Check_Valid_Library_Unit_Pragma
;
21861 if Nkind
(N
) = N_Null_Statement
then
21865 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21866 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21868 -- A pragma that applies to a Ghost entity becomes Ghost for the
21869 -- purposes of legality checks and removal of ignored Ghost code.
21871 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21873 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
21874 N_Generic_Package_Declaration
)
21877 ("pragma% can only apply to a package declaration");
21880 Set_Is_Remote_Types
(Cunit_Ent
);
21887 -- pragma Ravenscar;
21889 when Pragma_Ravenscar
=>
21891 Check_Arg_Count
(0);
21892 Check_Valid_Configuration_Pragma
;
21893 Set_Ravenscar_Profile
(Ravenscar
, N
);
21895 if Warn_On_Obsolescent_Feature
then
21897 ("pragma Ravenscar is an obsolescent feature?j?", N
);
21899 ("|use pragma Profile (Ravenscar) instead?j?", N
);
21902 -------------------------
21903 -- Restricted_Run_Time --
21904 -------------------------
21906 -- pragma Restricted_Run_Time;
21908 when Pragma_Restricted_Run_Time
=>
21910 Check_Arg_Count
(0);
21911 Check_Valid_Configuration_Pragma
;
21912 Set_Profile_Restrictions
21913 (Restricted
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
21915 if Warn_On_Obsolescent_Feature
then
21917 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
21920 ("|use pragma Profile (Restricted) instead?j?", N
);
21927 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
21930 -- restriction_IDENTIFIER
21931 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21933 when Pragma_Restrictions
=>
21934 Process_Restrictions_Or_Restriction_Warnings
21935 (Warn
=> Treat_Restrictions_As_Warnings
);
21937 --------------------------
21938 -- Restriction_Warnings --
21939 --------------------------
21941 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
21944 -- restriction_IDENTIFIER
21945 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21947 when Pragma_Restriction_Warnings
=>
21949 Process_Restrictions_Or_Restriction_Warnings
(Warn
=> True);
21955 -- pragma Reviewable;
21957 when Pragma_Reviewable
=>
21958 Check_Ada_83_Warning
;
21959 Check_Arg_Count
(0);
21961 -- Call dummy debugging function rv. This is done to assist front
21962 -- end debugging. By placing a Reviewable pragma in the source
21963 -- program, a breakpoint on rv catches this place in the source,
21964 -- allowing convenient stepping to the point of interest.
21968 --------------------------
21969 -- Secondary_Stack_Size --
21970 --------------------------
21972 -- pragma Secondary_Stack_Size (EXPRESSION);
21974 when Pragma_Secondary_Stack_Size
=> Secondary_Stack_Size
: declare
21975 P
: constant Node_Id
:= Parent
(N
);
21981 Check_No_Identifiers
;
21982 Check_Arg_Count
(1);
21984 if Nkind
(P
) = N_Task_Definition
then
21985 Arg
:= Get_Pragma_Arg
(Arg1
);
21986 Ent
:= Defining_Identifier
(Parent
(P
));
21988 -- The expression must be analyzed in the special manner
21989 -- described in "Handling of Default Expressions" in sem.ads.
21991 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
21993 -- The pragma cannot appear if the No_Secondary_Stack
21994 -- restriction is in effect.
21996 Check_Restriction
(No_Secondary_Stack
, Arg
);
21998 -- Anything else is incorrect
22004 -- Check duplicate pragma before we chain the pragma in the Rep
22005 -- Item chain of Ent.
22007 Check_Duplicate_Pragma
(Ent
);
22008 Record_Rep_Item
(Ent
, N
);
22009 end Secondary_Stack_Size
;
22011 --------------------------
22012 -- Short_Circuit_And_Or --
22013 --------------------------
22015 -- pragma Short_Circuit_And_Or;
22017 when Pragma_Short_Circuit_And_Or
=>
22019 Check_Arg_Count
(0);
22020 Check_Valid_Configuration_Pragma
;
22021 Short_Circuit_And_Or
:= True;
22023 -------------------
22024 -- Share_Generic --
22025 -------------------
22027 -- pragma Share_Generic (GNAME {, GNAME});
22029 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
22031 when Pragma_Share_Generic
=>
22033 Process_Generic_List
;
22039 -- pragma Shared (LOCAL_NAME);
22041 when Pragma_Shared
=>
22043 Process_Atomic_Independent_Shared_Volatile
;
22045 --------------------
22046 -- Shared_Passive --
22047 --------------------
22049 -- pragma Shared_Passive [(library_unit_NAME)];
22051 -- Set the flag Is_Shared_Passive of program unit name entity
22053 when Pragma_Shared_Passive
=> Shared_Passive
: declare
22054 Cunit_Node
: Node_Id
;
22055 Cunit_Ent
: Entity_Id
;
22058 Check_Ada_83_Warning
;
22059 Check_Valid_Library_Unit_Pragma
;
22061 if Nkind
(N
) = N_Null_Statement
then
22065 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
22066 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
22068 -- A pragma that applies to a Ghost entity becomes Ghost for the
22069 -- purposes of legality checks and removal of ignored Ghost code.
22071 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
22073 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
22074 N_Generic_Package_Declaration
)
22077 ("pragma% can only apply to a package declaration");
22080 Set_Is_Shared_Passive
(Cunit_Ent
);
22081 end Shared_Passive
;
22083 -----------------------
22084 -- Short_Descriptors --
22085 -----------------------
22087 -- pragma Short_Descriptors;
22089 -- Recognize and validate, but otherwise ignore
22091 when Pragma_Short_Descriptors
=>
22093 Check_Arg_Count
(0);
22094 Check_Valid_Configuration_Pragma
;
22096 ------------------------------
22097 -- Simple_Storage_Pool_Type --
22098 ------------------------------
22100 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
22102 when Pragma_Simple_Storage_Pool_Type
=>
22103 Simple_Storage_Pool_Type
: declare
22109 Check_Arg_Count
(1);
22110 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
22112 Type_Id
:= Get_Pragma_Arg
(Arg1
);
22113 Find_Type
(Type_Id
);
22114 Typ
:= Entity
(Type_Id
);
22116 if Typ
= Any_Type
then
22120 -- A pragma that applies to a Ghost entity becomes Ghost for the
22121 -- purposes of legality checks and removal of ignored Ghost code.
22123 Mark_Ghost_Pragma
(N
, Typ
);
22125 -- We require the pragma to apply to a type declared in a package
22126 -- declaration, but not (immediately) within a package body.
22128 if Ekind
(Current_Scope
) /= E_Package
22129 or else In_Package_Body
(Current_Scope
)
22132 ("pragma% can only apply to type declared immediately "
22133 & "within a package declaration");
22136 -- A simple storage pool type must be an immutably limited record
22137 -- or private type. If the pragma is given for a private type,
22138 -- the full type is similarly restricted (which is checked later
22139 -- in Freeze_Entity).
22141 if Is_Record_Type
(Typ
)
22142 and then not Is_Limited_View
(Typ
)
22145 ("pragma% can only apply to explicitly limited record type");
22147 elsif Is_Private_Type
(Typ
) and then not Is_Limited_Type
(Typ
) then
22149 ("pragma% can only apply to a private type that is limited");
22151 elsif not Is_Record_Type
(Typ
)
22152 and then not Is_Private_Type
(Typ
)
22155 ("pragma% can only apply to limited record or private type");
22158 Record_Rep_Item
(Typ
, N
);
22159 end Simple_Storage_Pool_Type
;
22161 ----------------------
22162 -- Source_File_Name --
22163 ----------------------
22165 -- There are five forms for this pragma:
22167 -- pragma Source_File_Name (
22168 -- [UNIT_NAME =>] unit_NAME,
22169 -- BODY_FILE_NAME => STRING_LITERAL
22170 -- [, [INDEX =>] INTEGER_LITERAL]);
22172 -- pragma Source_File_Name (
22173 -- [UNIT_NAME =>] unit_NAME,
22174 -- SPEC_FILE_NAME => STRING_LITERAL
22175 -- [, [INDEX =>] INTEGER_LITERAL]);
22177 -- pragma Source_File_Name (
22178 -- BODY_FILE_NAME => STRING_LITERAL
22179 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22180 -- [, CASING => CASING_SPEC]);
22182 -- pragma Source_File_Name (
22183 -- SPEC_FILE_NAME => STRING_LITERAL
22184 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22185 -- [, CASING => CASING_SPEC]);
22187 -- pragma Source_File_Name (
22188 -- SUBUNIT_FILE_NAME => STRING_LITERAL
22189 -- [, DOT_REPLACEMENT => STRING_LITERAL]
22190 -- [, CASING => CASING_SPEC]);
22192 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
22194 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
22195 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
22196 -- only be used when no project file is used, while SFNP can only be
22197 -- used when a project file is used.
22199 -- No processing here. Processing was completed during parsing, since
22200 -- we need to have file names set as early as possible. Units are
22201 -- loaded well before semantic processing starts.
22203 -- The only processing we defer to this point is the check for
22204 -- correct placement.
22206 when Pragma_Source_File_Name
=>
22208 Check_Valid_Configuration_Pragma
;
22210 ------------------------------
22211 -- Source_File_Name_Project --
22212 ------------------------------
22214 -- See Source_File_Name for syntax
22216 -- No processing here. Processing was completed during parsing, since
22217 -- we need to have file names set as early as possible. Units are
22218 -- loaded well before semantic processing starts.
22220 -- The only processing we defer to this point is the check for
22221 -- correct placement.
22223 when Pragma_Source_File_Name_Project
=>
22225 Check_Valid_Configuration_Pragma
;
22227 -- Check that a pragma Source_File_Name_Project is used only in a
22228 -- configuration pragmas file.
22230 -- Pragmas Source_File_Name_Project should only be generated by
22231 -- the Project Manager in configuration pragmas files.
22233 -- This is really an ugly test. It seems to depend on some
22234 -- accidental and undocumented property. At the very least it
22235 -- needs to be documented, but it would be better to have a
22236 -- clean way of testing if we are in a configuration file???
22238 if Present
(Parent
(N
)) then
22240 ("pragma% can only appear in a configuration pragmas file");
22243 ----------------------
22244 -- Source_Reference --
22245 ----------------------
22247 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
22249 -- Nothing to do, all processing completed in Par.Prag, since we need
22250 -- the information for possible parser messages that are output.
22252 when Pragma_Source_Reference
=>
22259 -- pragma SPARK_Mode [(On | Off)];
22261 when Pragma_SPARK_Mode
=> Do_SPARK_Mode
: declare
22262 Mode_Id
: SPARK_Mode_Type
;
22264 procedure Check_Pragma_Conformance
22265 (Context_Pragma
: Node_Id
;
22266 Entity
: Entity_Id
;
22267 Entity_Pragma
: Node_Id
);
22268 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
22269 -- conformance of pragma N depending the following scenarios:
22271 -- If pragma Context_Pragma is not Empty, verify that pragma N is
22272 -- compatible with the pragma Context_Pragma that was inherited
22273 -- from the context:
22274 -- * If the mode of Context_Pragma is ON, then the new mode can
22276 -- * If the mode of Context_Pragma is OFF, then the only allowed
22277 -- new mode is also OFF. Emit error if this is not the case.
22279 -- If Entity is not Empty, verify that pragma N is compatible with
22280 -- pragma Entity_Pragma that belongs to Entity.
22281 -- * If Entity_Pragma is Empty, always issue an error as this
22282 -- corresponds to the case where a previous section of Entity
22283 -- has no SPARK_Mode set.
22284 -- * If the mode of Entity_Pragma is ON, then the new mode can
22286 -- * If the mode of Entity_Pragma is OFF, then the only allowed
22287 -- new mode is also OFF. Emit error if this is not the case.
22289 procedure Check_Library_Level_Entity
(E
: Entity_Id
);
22290 -- Subsidiary to routines Process_xxx. Verify that the related
22291 -- entity E subject to pragma SPARK_Mode is library-level.
22293 procedure Process_Body
(Decl
: Node_Id
);
22294 -- Verify the legality of pragma SPARK_Mode when it appears as the
22295 -- top of the body declarations of entry, package, protected unit,
22296 -- subprogram or task unit body denoted by Decl.
22298 procedure Process_Overloadable
(Decl
: Node_Id
);
22299 -- Verify the legality of pragma SPARK_Mode when it applies to an
22300 -- entry or [generic] subprogram declaration denoted by Decl.
22302 procedure Process_Private_Part
(Decl
: Node_Id
);
22303 -- Verify the legality of pragma SPARK_Mode when it appears at the
22304 -- top of the private declarations of a package spec, protected or
22305 -- task unit declaration denoted by Decl.
22307 procedure Process_Statement_Part
(Decl
: Node_Id
);
22308 -- Verify the legality of pragma SPARK_Mode when it appears at the
22309 -- top of the statement sequence of a package body denoted by node
22312 procedure Process_Visible_Part
(Decl
: Node_Id
);
22313 -- Verify the legality of pragma SPARK_Mode when it appears at the
22314 -- top of the visible declarations of a package spec, protected or
22315 -- task unit declaration denoted by Decl. The routine is also used
22316 -- on protected or task units declared without a definition.
22318 procedure Set_SPARK_Context
;
22319 -- Subsidiary to routines Process_xxx. Set the global variables
22320 -- which represent the mode of the context from pragma N. Ensure
22321 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
22323 ------------------------------
22324 -- Check_Pragma_Conformance --
22325 ------------------------------
22327 procedure Check_Pragma_Conformance
22328 (Context_Pragma
: Node_Id
;
22329 Entity
: Entity_Id
;
22330 Entity_Pragma
: Node_Id
)
22332 Err_Id
: Entity_Id
;
22336 -- The current pragma may appear without an argument. If this
22337 -- is the case, associate all error messages with the pragma
22340 if Present
(Arg1
) then
22346 -- The mode of the current pragma is compared against that of
22347 -- an enclosing context.
22349 if Present
(Context_Pragma
) then
22350 pragma Assert
(Nkind
(Context_Pragma
) = N_Pragma
);
22352 -- Issue an error if the new mode is less restrictive than
22353 -- that of the context.
22355 if Get_SPARK_Mode_From_Annotation
(Context_Pragma
) = Off
22356 and then Get_SPARK_Mode_From_Annotation
(N
) = On
22359 ("cannot change SPARK_Mode from Off to On", Err_N
);
22360 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
22361 Error_Msg_N
("\SPARK_Mode was set to Off#", Err_N
);
22366 -- The mode of the current pragma is compared against that of
22367 -- an initial package, protected type, subprogram or task type
22370 if Present
(Entity
) then
22372 -- A simple protected or task type is transformed into an
22373 -- anonymous type whose name cannot be used to issue error
22374 -- messages. Recover the original entity of the type.
22376 if Ekind_In
(Entity
, E_Protected_Type
, E_Task_Type
) then
22379 (Original_Node
(Unit_Declaration_Node
(Entity
)));
22384 -- Both the initial declaration and the completion carry
22385 -- SPARK_Mode pragmas.
22387 if Present
(Entity_Pragma
) then
22388 pragma Assert
(Nkind
(Entity_Pragma
) = N_Pragma
);
22390 -- Issue an error if the new mode is less restrictive
22391 -- than that of the initial declaration.
22393 if Get_SPARK_Mode_From_Annotation
(Entity_Pragma
) = Off
22394 and then Get_SPARK_Mode_From_Annotation
(N
) = On
22396 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
22397 Error_Msg_Sloc
:= Sloc
(Entity_Pragma
);
22399 ("\value Off was set for SPARK_Mode on&#",
22404 -- Otherwise the initial declaration lacks a SPARK_Mode
22405 -- pragma in which case the current pragma is illegal as
22406 -- it cannot "complete".
22409 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
22410 Error_Msg_Sloc
:= Sloc
(Err_Id
);
22412 ("\no value was set for SPARK_Mode on&#",
22417 end Check_Pragma_Conformance
;
22419 --------------------------------
22420 -- Check_Library_Level_Entity --
22421 --------------------------------
22423 procedure Check_Library_Level_Entity
(E
: Entity_Id
) is
22424 procedure Add_Entity_To_Name_Buffer
;
22425 -- Add the E_Kind of entity E to the name buffer
22427 -------------------------------
22428 -- Add_Entity_To_Name_Buffer --
22429 -------------------------------
22431 procedure Add_Entity_To_Name_Buffer
is
22433 if Ekind_In
(E
, E_Entry
, E_Entry_Family
) then
22434 Add_Str_To_Name_Buffer
("entry");
22436 elsif Ekind_In
(E
, E_Generic_Package
,
22440 Add_Str_To_Name_Buffer
("package");
22442 elsif Ekind_In
(E
, E_Protected_Body
, E_Protected_Type
) then
22443 Add_Str_To_Name_Buffer
("protected type");
22445 elsif Ekind_In
(E
, E_Function
,
22446 E_Generic_Function
,
22447 E_Generic_Procedure
,
22451 Add_Str_To_Name_Buffer
("subprogram");
22454 pragma Assert
(Ekind_In
(E
, E_Task_Body
, E_Task_Type
));
22455 Add_Str_To_Name_Buffer
("task type");
22457 end Add_Entity_To_Name_Buffer
;
22461 Msg_1
: constant String := "incorrect placement of pragma%";
22464 -- Start of processing for Check_Library_Level_Entity
22467 if not Is_Library_Level_Entity
(E
) then
22468 Error_Msg_Name_1
:= Pname
;
22469 Error_Msg_N
(Fix_Error
(Msg_1
), N
);
22472 Add_Str_To_Name_Buffer
("\& is not a library-level ");
22473 Add_Entity_To_Name_Buffer
;
22475 Msg_2
:= Name_Find
;
22476 Error_Msg_NE
(Get_Name_String
(Msg_2
), N
, E
);
22480 end Check_Library_Level_Entity
;
22486 procedure Process_Body
(Decl
: Node_Id
) is
22487 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22488 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
22491 -- Ignore pragma when applied to the special body created for
22492 -- inlining, recognized by its internal name _Parent.
22494 if Chars
(Body_Id
) = Name_uParent
then
22498 Check_Library_Level_Entity
(Body_Id
);
22500 -- For entry bodies, verify the legality against:
22501 -- * The mode of the context
22502 -- * The mode of the spec (if any)
22504 if Nkind_In
(Decl
, N_Entry_Body
, N_Subprogram_Body
) then
22506 -- A stand-alone subprogram body
22508 if Body_Id
= Spec_Id
then
22509 Check_Pragma_Conformance
22510 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22512 Entity_Pragma
=> Empty
);
22514 -- An entry or subprogram body that completes a previous
22518 Check_Pragma_Conformance
22519 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22521 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
22525 Set_SPARK_Pragma
(Body_Id
, N
);
22526 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22528 -- For package bodies, verify the legality against:
22529 -- * The mode of the context
22530 -- * The mode of the private part
22532 -- This case is separated from protected and task bodies
22533 -- because the statement part of the package body inherits
22534 -- the mode of the body declarations.
22536 elsif Nkind
(Decl
) = N_Package_Body
then
22537 Check_Pragma_Conformance
22538 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22540 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
22543 Set_SPARK_Pragma
(Body_Id
, N
);
22544 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22545 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
22546 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
22548 -- For protected and task bodies, verify the legality against:
22549 -- * The mode of the context
22550 -- * The mode of the private part
22554 (Nkind_In
(Decl
, N_Protected_Body
, N_Task_Body
));
22556 Check_Pragma_Conformance
22557 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22559 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
22562 Set_SPARK_Pragma
(Body_Id
, N
);
22563 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22567 --------------------------
22568 -- Process_Overloadable --
22569 --------------------------
22571 procedure Process_Overloadable
(Decl
: Node_Id
) is
22572 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22573 Spec_Typ
: constant Entity_Id
:= Etype
(Spec_Id
);
22576 Check_Library_Level_Entity
(Spec_Id
);
22578 -- Verify the legality against:
22579 -- * The mode of the context
22581 Check_Pragma_Conformance
22582 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
22584 Entity_Pragma
=> Empty
);
22586 Set_SPARK_Pragma
(Spec_Id
, N
);
22587 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
22589 -- When the pragma applies to the anonymous object created for
22590 -- a single task type, decorate the type as well. This scenario
22591 -- arises when the single task type lacks a task definition,
22592 -- therefore there is no issue with respect to a potential
22593 -- pragma SPARK_Mode in the private part.
22595 -- task type Anon_Task_Typ;
22596 -- Obj : Anon_Task_Typ;
22597 -- pragma SPARK_Mode ...;
22599 if Is_Single_Task_Object
(Spec_Id
) then
22600 Set_SPARK_Pragma
(Spec_Typ
, N
);
22601 Set_SPARK_Pragma_Inherited
(Spec_Typ
, False);
22602 Set_SPARK_Aux_Pragma
(Spec_Typ
, N
);
22603 Set_SPARK_Aux_Pragma_Inherited
(Spec_Typ
, True);
22605 end Process_Overloadable
;
22607 --------------------------
22608 -- Process_Private_Part --
22609 --------------------------
22611 procedure Process_Private_Part
(Decl
: Node_Id
) is
22612 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22615 Check_Library_Level_Entity
(Spec_Id
);
22617 -- Verify the legality against:
22618 -- * The mode of the visible declarations
22620 Check_Pragma_Conformance
22621 (Context_Pragma
=> Empty
,
22623 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
22626 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
22627 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, False);
22628 end Process_Private_Part
;
22630 ----------------------------
22631 -- Process_Statement_Part --
22632 ----------------------------
22634 procedure Process_Statement_Part
(Decl
: Node_Id
) is
22635 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22638 Check_Library_Level_Entity
(Body_Id
);
22640 -- Verify the legality against:
22641 -- * The mode of the body declarations
22643 Check_Pragma_Conformance
22644 (Context_Pragma
=> Empty
,
22646 Entity_Pragma
=> SPARK_Pragma
(Body_Id
));
22649 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
22650 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, False);
22651 end Process_Statement_Part
;
22653 --------------------------
22654 -- Process_Visible_Part --
22655 --------------------------
22657 procedure Process_Visible_Part
(Decl
: Node_Id
) is
22658 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22659 Obj_Id
: Entity_Id
;
22662 Check_Library_Level_Entity
(Spec_Id
);
22664 -- Verify the legality against:
22665 -- * The mode of the context
22667 Check_Pragma_Conformance
22668 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
22670 Entity_Pragma
=> Empty
);
22672 -- A task unit declared without a definition does not set the
22673 -- SPARK_Mode of the context because the task does not have any
22674 -- entries that could inherit the mode.
22676 if not Nkind_In
(Decl
, N_Single_Task_Declaration
,
22677 N_Task_Type_Declaration
)
22682 Set_SPARK_Pragma
(Spec_Id
, N
);
22683 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
22684 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
22685 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, True);
22687 -- When the pragma applies to a single protected or task type,
22688 -- decorate the corresponding anonymous object as well.
22690 -- protected Anon_Prot_Typ is
22691 -- pragma SPARK_Mode ...;
22693 -- end Anon_Prot_Typ;
22695 -- Obj : Anon_Prot_Typ;
22697 if Is_Single_Concurrent_Type
(Spec_Id
) then
22698 Obj_Id
:= Anonymous_Object
(Spec_Id
);
22700 Set_SPARK_Pragma
(Obj_Id
, N
);
22701 Set_SPARK_Pragma_Inherited
(Obj_Id
, False);
22703 end Process_Visible_Part
;
22705 -----------------------
22706 -- Set_SPARK_Context --
22707 -----------------------
22709 procedure Set_SPARK_Context
is
22711 SPARK_Mode
:= Mode_Id
;
22712 SPARK_Mode_Pragma
:= N
;
22713 end Set_SPARK_Context
;
22721 -- Start of processing for Do_SPARK_Mode
22724 -- When a SPARK_Mode pragma appears inside an instantiation whose
22725 -- enclosing context has SPARK_Mode set to "off", the pragma has
22726 -- no semantic effect.
22728 if Ignore_SPARK_Mode_Pragmas_In_Instance
then
22729 Rewrite
(N
, Make_Null_Statement
(Loc
));
22735 Check_No_Identifiers
;
22736 Check_At_Most_N_Arguments
(1);
22738 -- Check the legality of the mode (no argument = ON)
22740 if Arg_Count
= 1 then
22741 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
22742 Mode
:= Chars
(Get_Pragma_Arg
(Arg1
));
22747 Mode_Id
:= Get_SPARK_Mode_Type
(Mode
);
22748 Context
:= Parent
(N
);
22750 -- The pragma appears in a configuration file
22752 if No
(Context
) then
22753 Check_Valid_Configuration_Pragma
;
22755 if Present
(SPARK_Mode_Pragma
) then
22758 Prev
=> SPARK_Mode_Pragma
);
22764 -- The pragma acts as a configuration pragma in a compilation unit
22766 -- pragma SPARK_Mode ...;
22767 -- package Pack is ...;
22769 elsif Nkind
(Context
) = N_Compilation_Unit
22770 and then List_Containing
(N
) = Context_Items
(Context
)
22772 Check_Valid_Configuration_Pragma
;
22775 -- Otherwise the placement of the pragma within the tree dictates
22776 -- its associated construct. Inspect the declarative list where
22777 -- the pragma resides to find a potential construct.
22781 while Present
(Stmt
) loop
22783 -- Skip prior pragmas, but check for duplicates. Note that
22784 -- this also takes care of pragmas generated for aspects.
22786 if Nkind
(Stmt
) = N_Pragma
then
22787 if Pragma_Name
(Stmt
) = Pname
then
22794 -- The pragma applies to an expression function that has
22795 -- already been rewritten into a subprogram declaration.
22797 -- function Expr_Func return ... is (...);
22798 -- pragma SPARK_Mode ...;
22800 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
22801 and then Nkind
(Original_Node
(Stmt
)) =
22802 N_Expression_Function
22804 Process_Overloadable
(Stmt
);
22807 -- The pragma applies to the anonymous object created for a
22808 -- single concurrent type.
22810 -- protected type Anon_Prot_Typ ...;
22811 -- Obj : Anon_Prot_Typ;
22812 -- pragma SPARK_Mode ...;
22814 elsif Nkind
(Stmt
) = N_Object_Declaration
22815 and then Is_Single_Concurrent_Object
22816 (Defining_Entity
(Stmt
))
22818 Process_Overloadable
(Stmt
);
22821 -- Skip internally generated code
22823 elsif not Comes_From_Source
(Stmt
) then
22826 -- The pragma applies to an entry or [generic] subprogram
22830 -- pragma SPARK_Mode ...;
22833 -- procedure Proc ...;
22834 -- pragma SPARK_Mode ...;
22836 elsif Nkind_In
(Stmt
, N_Generic_Subprogram_Declaration
,
22837 N_Subprogram_Declaration
)
22838 or else (Nkind
(Stmt
) = N_Entry_Declaration
22839 and then Is_Protected_Type
22840 (Scope
(Defining_Entity
(Stmt
))))
22842 Process_Overloadable
(Stmt
);
22845 -- Otherwise the pragma does not apply to a legal construct
22846 -- or it does not appear at the top of a declarative or a
22847 -- statement list. Issue an error and stop the analysis.
22857 -- The pragma applies to a package or a subprogram that acts as
22858 -- a compilation unit.
22860 -- procedure Proc ...;
22861 -- pragma SPARK_Mode ...;
22863 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
22864 Context
:= Unit
(Parent
(Context
));
22867 -- The pragma appears at the top of entry, package, protected
22868 -- unit, subprogram or task unit body declarations.
22870 -- entry Ent when ... is
22871 -- pragma SPARK_Mode ...;
22873 -- package body Pack is
22874 -- pragma SPARK_Mode ...;
22876 -- procedure Proc ... is
22877 -- pragma SPARK_Mode;
22879 -- protected body Prot is
22880 -- pragma SPARK_Mode ...;
22882 if Nkind_In
(Context
, N_Entry_Body
,
22888 Process_Body
(Context
);
22890 -- The pragma appears at the top of the visible or private
22891 -- declaration of a package spec, protected or task unit.
22894 -- pragma SPARK_Mode ...;
22896 -- pragma SPARK_Mode ...;
22898 -- protected [type] Prot is
22899 -- pragma SPARK_Mode ...;
22901 -- pragma SPARK_Mode ...;
22903 elsif Nkind_In
(Context
, N_Package_Specification
,
22904 N_Protected_Definition
,
22907 if List_Containing
(N
) = Visible_Declarations
(Context
) then
22908 Process_Visible_Part
(Parent
(Context
));
22910 Process_Private_Part
(Parent
(Context
));
22913 -- The pragma appears at the top of package body statements
22915 -- package body Pack is
22917 -- pragma SPARK_Mode;
22919 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
22920 and then Nkind
(Parent
(Context
)) = N_Package_Body
22922 Process_Statement_Part
(Parent
(Context
));
22924 -- The pragma appeared as an aspect of a [generic] subprogram
22925 -- declaration that acts as a compilation unit.
22928 -- procedure Proc ...;
22929 -- pragma SPARK_Mode ...;
22931 elsif Nkind_In
(Context
, N_Generic_Subprogram_Declaration
,
22932 N_Subprogram_Declaration
)
22934 Process_Overloadable
(Context
);
22936 -- The pragma does not apply to a legal construct, issue error
22944 --------------------------------
22945 -- Static_Elaboration_Desired --
22946 --------------------------------
22948 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
22950 when Pragma_Static_Elaboration_Desired
=>
22952 Check_At_Most_N_Arguments
(1);
22954 if Is_Compilation_Unit
(Current_Scope
)
22955 and then Ekind
(Current_Scope
) = E_Package
22957 Set_Static_Elaboration_Desired
(Current_Scope
, True);
22959 Error_Pragma
("pragma% must apply to a library-level package");
22966 -- pragma Storage_Size (EXPRESSION);
22968 when Pragma_Storage_Size
=> Storage_Size
: declare
22969 P
: constant Node_Id
:= Parent
(N
);
22973 Check_No_Identifiers
;
22974 Check_Arg_Count
(1);
22976 -- The expression must be analyzed in the special manner described
22977 -- in "Handling of Default Expressions" in sem.ads.
22979 Arg
:= Get_Pragma_Arg
(Arg1
);
22980 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
22982 if not Is_OK_Static_Expression
(Arg
) then
22983 Check_Restriction
(Static_Storage_Size
, Arg
);
22986 if Nkind
(P
) /= N_Task_Definition
then
22991 if Has_Storage_Size_Pragma
(P
) then
22992 Error_Pragma
("duplicate pragma% not allowed");
22994 Set_Has_Storage_Size_Pragma
(P
, True);
22997 Record_Rep_Item
(Defining_Identifier
(Parent
(P
)), N
);
23005 -- pragma Storage_Unit (NUMERIC_LITERAL);
23007 -- Only permitted argument is System'Storage_Unit value
23009 when Pragma_Storage_Unit
=>
23010 Check_No_Identifiers
;
23011 Check_Arg_Count
(1);
23012 Check_Arg_Is_Integer_Literal
(Arg1
);
23014 if Intval
(Get_Pragma_Arg
(Arg1
)) /=
23015 UI_From_Int
(Ttypes
.System_Storage_Unit
)
23017 Error_Msg_Uint_1
:= UI_From_Int
(Ttypes
.System_Storage_Unit
);
23019 ("the only allowed argument for pragma% is ^", Arg1
);
23022 --------------------
23023 -- Stream_Convert --
23024 --------------------
23026 -- pragma Stream_Convert (
23027 -- [Entity =>] type_LOCAL_NAME,
23028 -- [Read =>] function_NAME,
23029 -- [Write =>] function NAME);
23031 when Pragma_Stream_Convert
=> Stream_Convert
: declare
23032 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
);
23033 -- Check that the given argument is the name of a local function
23034 -- of one argument that is not overloaded earlier in the current
23035 -- local scope. A check is also made that the argument is a
23036 -- function with one parameter.
23038 --------------------------------------
23039 -- Check_OK_Stream_Convert_Function --
23040 --------------------------------------
23042 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
) is
23046 Check_Arg_Is_Local_Name
(Arg
);
23047 Ent
:= Entity
(Get_Pragma_Arg
(Arg
));
23049 if Has_Homonym
(Ent
) then
23051 ("argument for pragma% may not be overloaded", Arg
);
23054 if Ekind
(Ent
) /= E_Function
23055 or else No
(First_Formal
(Ent
))
23056 or else Present
(Next_Formal
(First_Formal
(Ent
)))
23059 ("argument for pragma% must be function of one argument",
23062 end Check_OK_Stream_Convert_Function
;
23064 -- Start of processing for Stream_Convert
23068 Check_Arg_Order
((Name_Entity
, Name_Read
, Name_Write
));
23069 Check_Arg_Count
(3);
23070 Check_Optional_Identifier
(Arg1
, Name_Entity
);
23071 Check_Optional_Identifier
(Arg2
, Name_Read
);
23072 Check_Optional_Identifier
(Arg3
, Name_Write
);
23073 Check_Arg_Is_Local_Name
(Arg1
);
23074 Check_OK_Stream_Convert_Function
(Arg2
);
23075 Check_OK_Stream_Convert_Function
(Arg3
);
23078 Typ
: constant Entity_Id
:=
23079 Underlying_Type
(Entity
(Get_Pragma_Arg
(Arg1
)));
23080 Read
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg2
));
23081 Write
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg3
));
23084 Check_First_Subtype
(Arg1
);
23086 -- Check for too early or too late. Note that we don't enforce
23087 -- the rule about primitive operations in this case, since, as
23088 -- is the case for explicit stream attributes themselves, these
23089 -- restrictions are not appropriate. Note that the chaining of
23090 -- the pragma by Rep_Item_Too_Late is actually the critical
23091 -- processing done for this pragma.
23093 if Rep_Item_Too_Early
(Typ
, N
)
23095 Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True)
23100 -- Return if previous error
23102 if Etype
(Typ
) = Any_Type
23104 Etype
(Read
) = Any_Type
23106 Etype
(Write
) = Any_Type
23113 if Underlying_Type
(Etype
(Read
)) /= Typ
then
23115 ("incorrect return type for function&", Arg2
);
23118 if Underlying_Type
(Etype
(First_Formal
(Write
))) /= Typ
then
23120 ("incorrect parameter type for function&", Arg3
);
23123 if Underlying_Type
(Etype
(First_Formal
(Read
))) /=
23124 Underlying_Type
(Etype
(Write
))
23127 ("result type of & does not match Read parameter type",
23131 end Stream_Convert
;
23137 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23139 -- This is processed by the parser since some of the style checks
23140 -- take place during source scanning and parsing. This means that
23141 -- we don't need to issue error messages here.
23143 when Pragma_Style_Checks
=> Style_Checks
: declare
23144 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
23150 Check_No_Identifiers
;
23152 -- Two argument form
23154 if Arg_Count
= 2 then
23155 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
23162 E_Id
:= Get_Pragma_Arg
(Arg2
);
23165 if not Is_Entity_Name
(E_Id
) then
23167 ("second argument of pragma% must be entity name",
23171 E
:= Entity
(E_Id
);
23173 if not Ignore_Style_Checks_Pragmas
then
23178 Set_Suppress_Style_Checks
23179 (E
, Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Off
);
23180 exit when No
(Homonym
(E
));
23187 -- One argument form
23190 Check_Arg_Count
(1);
23192 if Nkind
(A
) = N_String_Literal
then
23196 Slen
: constant Natural := Natural (String_Length
(S
));
23197 Options
: String (1 .. Slen
);
23203 C
:= Get_String_Char
(S
, Pos
(J
));
23204 exit when not In_Character_Range
(C
);
23205 Options
(J
) := Get_Character
(C
);
23207 -- If at end of string, set options. As per discussion
23208 -- above, no need to check for errors, since we issued
23209 -- them in the parser.
23212 if not Ignore_Style_Checks_Pragmas
then
23213 Set_Style_Check_Options
(Options
);
23223 elsif Nkind
(A
) = N_Identifier
then
23224 if Chars
(A
) = Name_All_Checks
then
23225 if not Ignore_Style_Checks_Pragmas
then
23227 Set_GNAT_Style_Check_Options
;
23229 Set_Default_Style_Check_Options
;
23233 elsif Chars
(A
) = Name_On
then
23234 if not Ignore_Style_Checks_Pragmas
then
23235 Style_Check
:= True;
23238 elsif Chars
(A
) = Name_Off
then
23239 if not Ignore_Style_Checks_Pragmas
then
23240 Style_Check
:= False;
23251 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
23253 when Pragma_Subtitle
=>
23255 Check_Arg_Count
(1);
23256 Check_Optional_Identifier
(Arg1
, Name_Subtitle
);
23257 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
23264 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
23266 when Pragma_Suppress
=>
23267 Process_Suppress_Unsuppress
(Suppress_Case
=> True);
23273 -- pragma Suppress_All;
23275 -- The only check made here is that the pragma has no arguments.
23276 -- There are no placement rules, and the processing required (setting
23277 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
23278 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
23279 -- then creates and inserts a pragma Suppress (All_Checks).
23281 when Pragma_Suppress_All
=>
23283 Check_Arg_Count
(0);
23285 -------------------------
23286 -- Suppress_Debug_Info --
23287 -------------------------
23289 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
23291 when Pragma_Suppress_Debug_Info
=> Suppress_Debug_Info
: declare
23292 Nam_Id
: Entity_Id
;
23296 Check_Arg_Count
(1);
23297 Check_Optional_Identifier
(Arg1
, Name_Entity
);
23298 Check_Arg_Is_Local_Name
(Arg1
);
23300 Nam_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
23302 -- A pragma that applies to a Ghost entity becomes Ghost for the
23303 -- purposes of legality checks and removal of ignored Ghost code.
23305 Mark_Ghost_Pragma
(N
, Nam_Id
);
23306 Set_Debug_Info_Off
(Nam_Id
);
23307 end Suppress_Debug_Info
;
23309 ----------------------------------
23310 -- Suppress_Exception_Locations --
23311 ----------------------------------
23313 -- pragma Suppress_Exception_Locations;
23315 when Pragma_Suppress_Exception_Locations
=>
23317 Check_Arg_Count
(0);
23318 Check_Valid_Configuration_Pragma
;
23319 Exception_Locations_Suppressed
:= True;
23321 -----------------------------
23322 -- Suppress_Initialization --
23323 -----------------------------
23325 -- pragma Suppress_Initialization ([Entity =>] type_Name);
23327 when Pragma_Suppress_Initialization
=> Suppress_Init
: declare
23333 Check_Arg_Count
(1);
23334 Check_Optional_Identifier
(Arg1
, Name_Entity
);
23335 Check_Arg_Is_Local_Name
(Arg1
);
23337 E_Id
:= Get_Pragma_Arg
(Arg1
);
23339 if Etype
(E_Id
) = Any_Type
then
23343 E
:= Entity
(E_Id
);
23345 -- A pragma that applies to a Ghost entity becomes Ghost for the
23346 -- purposes of legality checks and removal of ignored Ghost code.
23348 Mark_Ghost_Pragma
(N
, E
);
23350 if not Is_Type
(E
) and then Ekind
(E
) /= E_Variable
then
23352 ("pragma% requires variable, type or subtype", Arg1
);
23355 if Rep_Item_Too_Early
(E
, N
)
23357 Rep_Item_Too_Late
(E
, N
, FOnly
=> True)
23362 -- For incomplete/private type, set flag on full view
23364 if Is_Incomplete_Or_Private_Type
(E
) then
23365 if No
(Full_View
(Base_Type
(E
))) then
23367 ("argument of pragma% cannot be an incomplete type", Arg1
);
23369 Set_Suppress_Initialization
(Full_View
(Base_Type
(E
)));
23372 -- For first subtype, set flag on base type
23374 elsif Is_First_Subtype
(E
) then
23375 Set_Suppress_Initialization
(Base_Type
(E
));
23377 -- For other than first subtype, set flag on subtype or variable
23380 Set_Suppress_Initialization
(E
);
23388 -- pragma System_Name (DIRECT_NAME);
23390 -- Syntax check: one argument, which must be the identifier GNAT or
23391 -- the identifier GCC, no other identifiers are acceptable.
23393 when Pragma_System_Name
=>
23395 Check_No_Identifiers
;
23396 Check_Arg_Count
(1);
23397 Check_Arg_Is_One_Of
(Arg1
, Name_Gcc
, Name_Gnat
);
23399 -----------------------------
23400 -- Task_Dispatching_Policy --
23401 -----------------------------
23403 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
23405 when Pragma_Task_Dispatching_Policy
=> declare
23409 Check_Ada_83_Warning
;
23410 Check_Arg_Count
(1);
23411 Check_No_Identifiers
;
23412 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
23413 Check_Valid_Configuration_Pragma
;
23414 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
23415 DP
:= Fold_Upper
(Name_Buffer
(1));
23417 if Task_Dispatching_Policy
/= ' '
23418 and then Task_Dispatching_Policy
/= DP
23420 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
23422 ("task dispatching policy incompatible with policy#");
23424 -- Set new policy, but always preserve System_Location since we
23425 -- like the error message with the run time name.
23428 Task_Dispatching_Policy
:= DP
;
23430 if Task_Dispatching_Policy_Sloc
/= System_Location
then
23431 Task_Dispatching_Policy_Sloc
:= Loc
;
23440 -- pragma Task_Info (EXPRESSION);
23442 when Pragma_Task_Info
=> Task_Info
: declare
23443 P
: constant Node_Id
:= Parent
(N
);
23449 if Warn_On_Obsolescent_Feature
then
23451 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
23452 & "instead?j?", N
);
23455 if Nkind
(P
) /= N_Task_Definition
then
23456 Error_Pragma
("pragma% must appear in task definition");
23459 Check_No_Identifiers
;
23460 Check_Arg_Count
(1);
23462 Analyze_And_Resolve
23463 (Get_Pragma_Arg
(Arg1
), RTE
(RE_Task_Info_Type
));
23465 if Etype
(Get_Pragma_Arg
(Arg1
)) = Any_Type
then
23469 Ent
:= Defining_Identifier
(Parent
(P
));
23471 -- Check duplicate pragma before we chain the pragma in the Rep
23472 -- Item chain of Ent.
23475 (Ent
, Name_Task_Info
, Check_Parents
=> False)
23477 Error_Pragma
("duplicate pragma% not allowed");
23480 Record_Rep_Item
(Ent
, N
);
23487 -- pragma Task_Name (string_EXPRESSION);
23489 when Pragma_Task_Name
=> Task_Name
: declare
23490 P
: constant Node_Id
:= Parent
(N
);
23495 Check_No_Identifiers
;
23496 Check_Arg_Count
(1);
23498 Arg
:= Get_Pragma_Arg
(Arg1
);
23500 -- The expression is used in the call to Create_Task, and must be
23501 -- expanded there, not in the context of the current spec. It must
23502 -- however be analyzed to capture global references, in case it
23503 -- appears in a generic context.
23505 Preanalyze_And_Resolve
(Arg
, Standard_String
);
23507 if Nkind
(P
) /= N_Task_Definition
then
23511 Ent
:= Defining_Identifier
(Parent
(P
));
23513 -- Check duplicate pragma before we chain the pragma in the Rep
23514 -- Item chain of Ent.
23517 (Ent
, Name_Task_Name
, Check_Parents
=> False)
23519 Error_Pragma
("duplicate pragma% not allowed");
23522 Record_Rep_Item
(Ent
, N
);
23529 -- pragma Task_Storage (
23530 -- [Task_Type =>] LOCAL_NAME,
23531 -- [Top_Guard =>] static_integer_EXPRESSION);
23533 when Pragma_Task_Storage
=> Task_Storage
: declare
23534 Args
: Args_List
(1 .. 2);
23535 Names
: constant Name_List
(1 .. 2) := (
23539 Task_Type
: Node_Id
renames Args
(1);
23540 Top_Guard
: Node_Id
renames Args
(2);
23546 Gather_Associations
(Names
, Args
);
23548 if No
(Task_Type
) then
23550 ("missing task_type argument for pragma%");
23553 Check_Arg_Is_Local_Name
(Task_Type
);
23555 Ent
:= Entity
(Task_Type
);
23557 if not Is_Task_Type
(Ent
) then
23559 ("argument for pragma% must be task type", Task_Type
);
23562 if No
(Top_Guard
) then
23564 ("pragma% takes two arguments", Task_Type
);
23566 Check_Arg_Is_OK_Static_Expression
(Top_Guard
, Any_Integer
);
23569 Check_First_Subtype
(Task_Type
);
23571 if Rep_Item_Too_Late
(Ent
, N
) then
23580 -- pragma Test_Case
23581 -- ([Name =>] Static_String_EXPRESSION
23582 -- ,[Mode =>] MODE_TYPE
23583 -- [, Requires => Boolean_EXPRESSION]
23584 -- [, Ensures => Boolean_EXPRESSION]);
23586 -- MODE_TYPE ::= Nominal | Robustness
23588 -- Characteristics:
23590 -- * Analysis - The annotation undergoes initial checks to verify
23591 -- the legal placement and context. Secondary checks preanalyze the
23594 -- Analyze_Test_Case_In_Decl_Part
23596 -- * Expansion - None.
23598 -- * Template - The annotation utilizes the generic template of the
23599 -- related subprogram when it is:
23601 -- aspect on subprogram declaration
23603 -- The annotation must prepare its own template when it is:
23605 -- pragma on subprogram declaration
23607 -- * Globals - Capture of global references must occur after full
23610 -- * Instance - The annotation is instantiated automatically when
23611 -- the related generic subprogram is instantiated except for the
23612 -- "pragma on subprogram declaration" case. In that scenario the
23613 -- annotation must instantiate itself.
23615 when Pragma_Test_Case
=> Test_Case
: declare
23616 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
);
23617 -- Ensure that the contract of subprogram Subp_Id does not contain
23618 -- another Test_Case pragma with the same Name as the current one.
23620 -------------------------
23621 -- Check_Distinct_Name --
23622 -------------------------
23624 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
) is
23625 Items
: constant Node_Id
:= Contract
(Subp_Id
);
23626 Name
: constant String_Id
:= Get_Name_From_CTC_Pragma
(N
);
23630 -- Inspect all Test_Case pragma of the related subprogram
23631 -- looking for one with a duplicate "Name" argument.
23633 if Present
(Items
) then
23634 Prag
:= Contract_Test_Cases
(Items
);
23635 while Present
(Prag
) loop
23636 if Pragma_Name
(Prag
) = Name_Test_Case
23638 and then String_Equal
23639 (Name
, Get_Name_From_CTC_Pragma
(Prag
))
23641 Error_Msg_Sloc
:= Sloc
(Prag
);
23642 Error_Pragma
("name for pragma % is already used #");
23645 Prag
:= Next_Pragma
(Prag
);
23648 end Check_Distinct_Name
;
23652 Pack_Decl
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
23655 Subp_Decl
: Node_Id
;
23656 Subp_Id
: Entity_Id
;
23658 -- Start of processing for Test_Case
23662 Check_At_Least_N_Arguments
(2);
23663 Check_At_Most_N_Arguments
(4);
23665 ((Name_Name
, Name_Mode
, Name_Requires
, Name_Ensures
));
23669 Check_Optional_Identifier
(Arg1
, Name_Name
);
23670 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
23674 Check_Optional_Identifier
(Arg2
, Name_Mode
);
23675 Check_Arg_Is_One_Of
(Arg2
, Name_Nominal
, Name_Robustness
);
23677 -- Arguments "Requires" and "Ensures"
23679 if Present
(Arg3
) then
23680 if Present
(Arg4
) then
23681 Check_Identifier
(Arg3
, Name_Requires
);
23682 Check_Identifier
(Arg4
, Name_Ensures
);
23684 Check_Identifier_Is_One_Of
23685 (Arg3
, Name_Requires
, Name_Ensures
);
23689 -- Pragma Test_Case must be associated with a subprogram declared
23690 -- in a library-level package. First determine whether the current
23691 -- compilation unit is a legal context.
23693 if Nkind_In
(Pack_Decl
, N_Package_Declaration
,
23694 N_Generic_Package_Declaration
)
23698 -- Otherwise the placement is illegal
23702 ("pragma % must be specified within a package declaration");
23706 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
);
23708 -- Find the enclosing context
23710 Context
:= Parent
(Subp_Decl
);
23712 if Present
(Context
) then
23713 Context
:= Parent
(Context
);
23716 -- Verify the placement of the pragma
23718 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
23720 ("pragma % cannot be applied to abstract subprogram");
23723 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
23724 Error_Pragma
("pragma % cannot be applied to entry");
23727 -- The context is a [generic] subprogram declared at the top level
23728 -- of the [generic] package unit.
23730 elsif Nkind_In
(Subp_Decl
, N_Generic_Subprogram_Declaration
,
23731 N_Subprogram_Declaration
)
23732 and then Present
(Context
)
23733 and then Nkind_In
(Context
, N_Generic_Package_Declaration
,
23734 N_Package_Declaration
)
23738 -- Otherwise the placement is illegal
23742 ("pragma % must be applied to a library-level subprogram "
23747 Subp_Id
:= Defining_Entity
(Subp_Decl
);
23749 -- A pragma that applies to a Ghost entity becomes Ghost for the
23750 -- purposes of legality checks and removal of ignored Ghost code.
23752 Mark_Ghost_Pragma
(N
, Subp_Id
);
23754 -- Chain the pragma on the contract for further processing by
23755 -- Analyze_Test_Case_In_Decl_Part.
23757 Add_Contract_Item
(N
, Subp_Id
);
23759 -- Preanalyze the original aspect argument "Name" for ASIS or for
23760 -- a generic subprogram to properly capture global references.
23762 if ASIS_Mode
or else Is_Generic_Subprogram
(Subp_Id
) then
23763 Asp_Arg
:= Test_Case_Arg
(N
, Name_Name
, From_Aspect
=> True);
23765 if Present
(Asp_Arg
) then
23767 -- The argument appears with an identifier in association
23770 if Nkind
(Asp_Arg
) = N_Component_Association
then
23771 Asp_Arg
:= Expression
(Asp_Arg
);
23774 Check_Expr_Is_OK_Static_Expression
23775 (Asp_Arg
, Standard_String
);
23779 -- Ensure that the all Test_Case pragmas of the related subprogram
23780 -- have distinct names.
23782 Check_Distinct_Name
(Subp_Id
);
23784 -- Fully analyze the pragma when it appears inside an entry
23785 -- or subprogram body because it cannot benefit from forward
23788 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
23790 N_Subprogram_Body_Stub
)
23792 -- The legality checks of pragma Test_Case are affected by the
23793 -- SPARK mode in effect and the volatility of the context.
23794 -- Analyze all pragmas in a specific order.
23796 Analyze_If_Present
(Pragma_SPARK_Mode
);
23797 Analyze_If_Present
(Pragma_Volatile_Function
);
23798 Analyze_Test_Case_In_Decl_Part
(N
);
23802 --------------------------
23803 -- Thread_Local_Storage --
23804 --------------------------
23806 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
23808 when Pragma_Thread_Local_Storage
=> Thread_Local_Storage
: declare
23814 Check_Arg_Count
(1);
23815 Check_Optional_Identifier
(Arg1
, Name_Entity
);
23816 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
23818 Id
:= Get_Pragma_Arg
(Arg1
);
23821 if not Is_Entity_Name
(Id
)
23822 or else Ekind
(Entity
(Id
)) /= E_Variable
23824 Error_Pragma_Arg
("local variable name required", Arg1
);
23829 -- A pragma that applies to a Ghost entity becomes Ghost for the
23830 -- purposes of legality checks and removal of ignored Ghost code.
23832 Mark_Ghost_Pragma
(N
, E
);
23834 if Rep_Item_Too_Early
(E
, N
)
23836 Rep_Item_Too_Late
(E
, N
)
23841 Set_Has_Pragma_Thread_Local_Storage
(E
);
23842 Set_Has_Gigi_Rep_Item
(E
);
23843 end Thread_Local_Storage
;
23849 -- pragma Time_Slice (static_duration_EXPRESSION);
23851 when Pragma_Time_Slice
=> Time_Slice
: declare
23857 Check_Arg_Count
(1);
23858 Check_No_Identifiers
;
23859 Check_In_Main_Program
;
23860 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_Duration
);
23862 if not Error_Posted
(Arg1
) then
23864 while Present
(Nod
) loop
23865 if Nkind
(Nod
) = N_Pragma
23866 and then Pragma_Name
(Nod
) = Name_Time_Slice
23868 Error_Msg_Name_1
:= Pname
;
23869 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
23876 -- Process only if in main unit
23878 if Get_Source_Unit
(Loc
) = Main_Unit
then
23879 Opt
.Time_Slice_Set
:= True;
23880 Val
:= Expr_Value_R
(Get_Pragma_Arg
(Arg1
));
23882 if Val
<= Ureal_0
then
23883 Opt
.Time_Slice_Value
:= 0;
23885 elsif Val
> UR_From_Uint
(UI_From_Int
(1000)) then
23886 Opt
.Time_Slice_Value
:= 1_000_000_000
;
23889 Opt
.Time_Slice_Value
:=
23890 UI_To_Int
(UR_To_Uint
(Val
* UI_From_Int
(1_000_000
)));
23899 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
23901 -- TITLING_OPTION ::=
23902 -- [Title =>] STRING_LITERAL
23903 -- | [Subtitle =>] STRING_LITERAL
23905 when Pragma_Title
=> Title
: declare
23906 Args
: Args_List
(1 .. 2);
23907 Names
: constant Name_List
(1 .. 2) := (
23913 Gather_Associations
(Names
, Args
);
23916 for J
in 1 .. 2 loop
23917 if Present
(Args
(J
)) then
23918 Check_Arg_Is_OK_Static_Expression
23919 (Args
(J
), Standard_String
);
23924 ----------------------------
23925 -- Type_Invariant[_Class] --
23926 ----------------------------
23928 -- pragma Type_Invariant[_Class]
23929 -- ([Entity =>] type_LOCAL_NAME,
23930 -- [Check =>] EXPRESSION);
23932 when Pragma_Type_Invariant
23933 | Pragma_Type_Invariant_Class
23935 Type_Invariant
: declare
23936 I_Pragma
: Node_Id
;
23939 Check_Arg_Count
(2);
23941 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
23942 -- setting Class_Present for the Type_Invariant_Class case.
23944 Set_Class_Present
(N
, Prag_Id
= Pragma_Type_Invariant_Class
);
23945 I_Pragma
:= New_Copy
(N
);
23946 Set_Pragma_Identifier
23947 (I_Pragma
, Make_Identifier
(Loc
, Name_Invariant
));
23948 Rewrite
(N
, I_Pragma
);
23949 Set_Analyzed
(N
, False);
23951 end Type_Invariant
;
23953 ---------------------
23954 -- Unchecked_Union --
23955 ---------------------
23957 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
23959 when Pragma_Unchecked_Union
=> Unchecked_Union
: declare
23960 Assoc
: constant Node_Id
:= Arg1
;
23961 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
23971 Check_No_Identifiers
;
23972 Check_Arg_Count
(1);
23973 Check_Arg_Is_Local_Name
(Arg1
);
23975 Find_Type
(Type_Id
);
23977 Typ
:= Entity
(Type_Id
);
23979 -- A pragma that applies to a Ghost entity becomes Ghost for the
23980 -- purposes of legality checks and removal of ignored Ghost code.
23982 Mark_Ghost_Pragma
(N
, Typ
);
23985 or else Rep_Item_Too_Early
(Typ
, N
)
23989 Typ
:= Underlying_Type
(Typ
);
23992 if Rep_Item_Too_Late
(Typ
, N
) then
23996 Check_First_Subtype
(Arg1
);
23998 -- Note remaining cases are references to a type in the current
23999 -- declarative part. If we find an error, we post the error on
24000 -- the relevant type declaration at an appropriate point.
24002 if not Is_Record_Type
(Typ
) then
24003 Error_Msg_N
("unchecked union must be record type", Typ
);
24006 elsif Is_Tagged_Type
(Typ
) then
24007 Error_Msg_N
("unchecked union must not be tagged", Typ
);
24010 elsif not Has_Discriminants
(Typ
) then
24012 ("unchecked union must have one discriminant", Typ
);
24015 -- Note: in previous versions of GNAT we used to check for limited
24016 -- types and give an error, but in fact the standard does allow
24017 -- Unchecked_Union on limited types, so this check was removed.
24019 -- Similarly, GNAT used to require that all discriminants have
24020 -- default values, but this is not mandated by the RM.
24022 -- Proceed with basic error checks completed
24025 Tdef
:= Type_Definition
(Declaration_Node
(Typ
));
24026 Clist
:= Component_List
(Tdef
);
24028 -- Check presence of component list and variant part
24030 if No
(Clist
) or else No
(Variant_Part
(Clist
)) then
24032 ("unchecked union must have variant part", Tdef
);
24036 -- Check components
24038 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
24039 while Present
(Comp
) loop
24040 Check_Component
(Comp
, Typ
);
24041 Next_Non_Pragma
(Comp
);
24044 -- Check variant part
24046 Vpart
:= Variant_Part
(Clist
);
24048 Variant
:= First_Non_Pragma
(Variants
(Vpart
));
24049 while Present
(Variant
) loop
24050 Check_Variant
(Variant
, Typ
);
24051 Next_Non_Pragma
(Variant
);
24055 Set_Is_Unchecked_Union
(Typ
);
24056 Set_Convention
(Typ
, Convention_C
);
24057 Set_Has_Unchecked_Union
(Base_Type
(Typ
));
24058 Set_Is_Unchecked_Union
(Base_Type
(Typ
));
24059 end Unchecked_Union
;
24061 ----------------------------
24062 -- Unevaluated_Use_Of_Old --
24063 ----------------------------
24065 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
24067 when Pragma_Unevaluated_Use_Of_Old
=>
24069 Check_Arg_Count
(1);
24070 Check_No_Identifiers
;
24071 Check_Arg_Is_One_Of
(Arg1
, Name_Error
, Name_Warn
, Name_Allow
);
24073 -- Suppress/Unsuppress can appear as a configuration pragma, or in
24074 -- a declarative part or a package spec.
24076 if not Is_Configuration_Pragma
then
24077 Check_Is_In_Decl_Part_Or_Package_Spec
;
24080 -- Store proper setting of Uneval_Old
24082 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
24083 Uneval_Old
:= Fold_Upper
(Name_Buffer
(1));
24085 ------------------------
24086 -- Unimplemented_Unit --
24087 ------------------------
24089 -- pragma Unimplemented_Unit;
24091 -- Note: this only gives an error if we are generating code, or if
24092 -- we are in a generic library unit (where the pragma appears in the
24093 -- body, not in the spec).
24095 when Pragma_Unimplemented_Unit
=> Unimplemented_Unit
: declare
24096 Cunitent
: constant Entity_Id
:=
24097 Cunit_Entity
(Get_Source_Unit
(Loc
));
24098 Ent_Kind
: constant Entity_Kind
:= Ekind
(Cunitent
);
24102 Check_Arg_Count
(0);
24104 if Operating_Mode
= Generate_Code
24105 or else Ent_Kind
= E_Generic_Function
24106 or else Ent_Kind
= E_Generic_Procedure
24107 or else Ent_Kind
= E_Generic_Package
24109 Get_Name_String
(Chars
(Cunitent
));
24110 Set_Casing
(Mixed_Case
);
24111 Write_Str
(Name_Buffer
(1 .. Name_Len
));
24112 Write_Str
(" is not supported in this configuration");
24114 raise Unrecoverable_Error
;
24116 end Unimplemented_Unit
;
24118 ------------------------
24119 -- Universal_Aliasing --
24120 ------------------------
24122 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
24124 when Pragma_Universal_Aliasing
=> Universal_Alias
: declare
24130 Check_Arg_Count
(1);
24131 Check_Optional_Identifier
(Arg2
, Name_Entity
);
24132 Check_Arg_Is_Local_Name
(Arg1
);
24133 E_Id
:= Get_Pragma_Arg
(Arg1
);
24135 if Etype
(E_Id
) = Any_Type
then
24139 E
:= Entity
(E_Id
);
24141 if not Is_Type
(E
) then
24142 Error_Pragma_Arg
("pragma% requires type", Arg1
);
24145 -- A pragma that applies to a Ghost entity becomes Ghost for the
24146 -- purposes of legality checks and removal of ignored Ghost code.
24148 Mark_Ghost_Pragma
(N
, E
);
24149 Set_Universal_Aliasing
(Base_Type
(E
));
24150 Record_Rep_Item
(E
, N
);
24151 end Universal_Alias
;
24153 --------------------
24154 -- Universal_Data --
24155 --------------------
24157 -- pragma Universal_Data [(library_unit_NAME)];
24159 when Pragma_Universal_Data
=>
24161 Error_Pragma
("??pragma% ignored (applies only to AAMP)");
24167 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
24169 when Pragma_Unmodified
=>
24170 Analyze_Unmodified_Or_Unused
;
24176 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
24178 -- or when used in a context clause:
24180 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
24182 when Pragma_Unreferenced
=>
24183 Analyze_Unreferenced_Or_Unused
;
24185 --------------------------
24186 -- Unreferenced_Objects --
24187 --------------------------
24189 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
24191 when Pragma_Unreferenced_Objects
=> Unreferenced_Objects
: declare
24193 Arg_Expr
: Node_Id
;
24194 Arg_Id
: Entity_Id
;
24196 Ghost_Error_Posted
: Boolean := False;
24197 -- Flag set when an error concerning the illegal mix of Ghost and
24198 -- non-Ghost types is emitted.
24200 Ghost_Id
: Entity_Id
:= Empty
;
24201 -- The entity of the first Ghost type encountered while processing
24202 -- the arguments of the pragma.
24206 Check_At_Least_N_Arguments
(1);
24209 while Present
(Arg
) loop
24210 Check_No_Identifier
(Arg
);
24211 Check_Arg_Is_Local_Name
(Arg
);
24212 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
24214 if Is_Entity_Name
(Arg_Expr
) then
24215 Arg_Id
:= Entity
(Arg_Expr
);
24217 if Is_Type
(Arg_Id
) then
24218 Set_Has_Pragma_Unreferenced_Objects
(Arg_Id
);
24220 -- A pragma that applies to a Ghost entity becomes Ghost
24221 -- for the purposes of legality checks and removal of
24222 -- ignored Ghost code.
24224 Mark_Ghost_Pragma
(N
, Arg_Id
);
24226 -- Capture the entity of the first Ghost type being
24227 -- processed for error detection purposes.
24229 if Is_Ghost_Entity
(Arg_Id
) then
24230 if No
(Ghost_Id
) then
24231 Ghost_Id
:= Arg_Id
;
24234 -- Otherwise the type is non-Ghost. It is illegal to mix
24235 -- references to Ghost and non-Ghost entities
24238 elsif Present
(Ghost_Id
)
24239 and then not Ghost_Error_Posted
24241 Ghost_Error_Posted
:= True;
24243 Error_Msg_Name_1
:= Pname
;
24245 ("pragma % cannot mention ghost and non-ghost types",
24248 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
24249 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
24251 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
24252 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
24256 ("argument for pragma% must be type or subtype", Arg
);
24260 ("argument for pragma% must be type or subtype", Arg
);
24265 end Unreferenced_Objects
;
24267 ------------------------------
24268 -- Unreserve_All_Interrupts --
24269 ------------------------------
24271 -- pragma Unreserve_All_Interrupts;
24273 when Pragma_Unreserve_All_Interrupts
=>
24275 Check_Arg_Count
(0);
24277 if In_Extended_Main_Code_Unit
(Main_Unit_Entity
) then
24278 Unreserve_All_Interrupts
:= True;
24285 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
24287 when Pragma_Unsuppress
=>
24289 Process_Suppress_Unsuppress
(Suppress_Case
=> False);
24295 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
24297 when Pragma_Unused
=>
24298 Analyze_Unmodified_Or_Unused
(Is_Unused
=> True);
24299 Analyze_Unreferenced_Or_Unused
(Is_Unused
=> True);
24301 -------------------
24302 -- Use_VADS_Size --
24303 -------------------
24305 -- pragma Use_VADS_Size;
24307 when Pragma_Use_VADS_Size
=>
24309 Check_Arg_Count
(0);
24310 Check_Valid_Configuration_Pragma
;
24311 Use_VADS_Size
:= True;
24313 ---------------------
24314 -- Validity_Checks --
24315 ---------------------
24317 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
24319 when Pragma_Validity_Checks
=> Validity_Checks
: declare
24320 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
24326 Check_Arg_Count
(1);
24327 Check_No_Identifiers
;
24329 -- Pragma always active unless in CodePeer or GNATprove modes,
24330 -- which use a fixed configuration of validity checks.
24332 if not (CodePeer_Mode
or GNATprove_Mode
) then
24333 if Nkind
(A
) = N_String_Literal
then
24337 Slen
: constant Natural := Natural (String_Length
(S
));
24338 Options
: String (1 .. Slen
);
24342 -- Couldn't we use a for loop here over Options'Range???
24346 C
:= Get_String_Char
(S
, Pos
(J
));
24348 -- This is a weird test, it skips setting validity
24349 -- checks entirely if any element of S is out of
24350 -- range of Character, what is that about ???
24352 exit when not In_Character_Range
(C
);
24353 Options
(J
) := Get_Character
(C
);
24356 Set_Validity_Check_Options
(Options
);
24364 elsif Nkind
(A
) = N_Identifier
then
24365 if Chars
(A
) = Name_All_Checks
then
24366 Set_Validity_Check_Options
("a");
24367 elsif Chars
(A
) = Name_On
then
24368 Validity_Checks_On
:= True;
24369 elsif Chars
(A
) = Name_Off
then
24370 Validity_Checks_On
:= False;
24374 end Validity_Checks
;
24380 -- pragma Volatile (LOCAL_NAME);
24382 when Pragma_Volatile
=>
24383 Process_Atomic_Independent_Shared_Volatile
;
24385 -------------------------
24386 -- Volatile_Components --
24387 -------------------------
24389 -- pragma Volatile_Components (array_LOCAL_NAME);
24391 -- Volatile is handled by the same circuit as Atomic_Components
24393 --------------------------
24394 -- Volatile_Full_Access --
24395 --------------------------
24397 -- pragma Volatile_Full_Access (LOCAL_NAME);
24399 when Pragma_Volatile_Full_Access
=>
24401 Process_Atomic_Independent_Shared_Volatile
;
24403 -----------------------
24404 -- Volatile_Function --
24405 -----------------------
24407 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
24409 when Pragma_Volatile_Function
=> Volatile_Function
: declare
24410 Over_Id
: Entity_Id
;
24411 Spec_Id
: Entity_Id
;
24412 Subp_Decl
: Node_Id
;
24416 Check_No_Identifiers
;
24417 Check_At_Most_N_Arguments
(1);
24420 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
24422 -- Generic subprogram
24424 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
24427 -- Body acts as spec
24429 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
24430 and then No
(Corresponding_Spec
(Subp_Decl
))
24434 -- Body stub acts as spec
24436 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
24437 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
24443 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
24451 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
24453 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
24458 -- A pragma that applies to a Ghost entity becomes Ghost for the
24459 -- purposes of legality checks and removal of ignored Ghost code.
24461 Mark_Ghost_Pragma
(N
, Spec_Id
);
24463 -- Chain the pragma on the contract for completeness
24465 Add_Contract_Item
(N
, Spec_Id
);
24467 -- The legality checks of pragma Volatile_Function are affected by
24468 -- the SPARK mode in effect. Analyze all pragmas in a specific
24471 Analyze_If_Present
(Pragma_SPARK_Mode
);
24473 -- A volatile function cannot override a non-volatile function
24474 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
24475 -- in New_Overloaded_Entity, however at that point the pragma has
24476 -- not been processed yet.
24478 Over_Id
:= Overridden_Operation
(Spec_Id
);
24480 if Present
(Over_Id
)
24481 and then not Is_Volatile_Function
(Over_Id
)
24484 ("incompatible volatile function values in effect", Spec_Id
);
24486 Error_Msg_Sloc
:= Sloc
(Over_Id
);
24488 ("\& declared # with Volatile_Function value False",
24491 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
24493 ("\overridden # with Volatile_Function value True",
24497 -- Analyze the Boolean expression (if any)
24499 if Present
(Arg1
) then
24500 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
24502 end Volatile_Function
;
24504 ----------------------
24505 -- Warning_As_Error --
24506 ----------------------
24508 -- pragma Warning_As_Error (static_string_EXPRESSION);
24510 when Pragma_Warning_As_Error
=>
24512 Check_Arg_Count
(1);
24513 Check_No_Identifiers
;
24514 Check_Valid_Configuration_Pragma
;
24516 if not Is_Static_String_Expression
(Arg1
) then
24518 ("argument of pragma% must be static string expression",
24521 -- OK static string expression
24524 Acquire_Warning_Match_String
(Arg1
);
24525 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
24526 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
24527 new String'(Name_Buffer (1 .. Name_Len));
24534 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
24536 -- DETAILS ::= On | Off
24537 -- DETAILS ::= On | Off, local_NAME
24538 -- DETAILS ::= static_string_EXPRESSION
24539 -- DETAILS ::= On | Off, static_string_EXPRESSION
24541 -- TOOL_NAME ::= GNAT | GNATProve
24543 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
24545 -- Note: If the first argument matches an allowed tool name, it is
24546 -- always considered to be a tool name, even if there is a string
24547 -- variable of that name.
24549 -- Note if the second argument of DETAILS is a local_NAME then the
24550 -- second form is always understood. If the intention is to use
24551 -- the fourth form, then you can write NAME & "" to force the
24552 -- intepretation as a static_string_EXPRESSION.
24554 when Pragma_Warnings => Warnings : declare
24555 Reason : String_Id;
24559 Check_At_Least_N_Arguments (1);
24561 -- See if last argument is labeled Reason. If so, make sure we
24562 -- have a string literal or a concatenation of string literals,
24563 -- and acquire the REASON string. Then remove the REASON argument
24564 -- by decreasing Num_Args by one; Remaining processing looks only
24565 -- at first Num_Args arguments).
24568 Last_Arg : constant Node_Id :=
24569 Last (Pragma_Argument_Associations (N));
24572 if Nkind (Last_Arg) = N_Pragma_Argument_Association
24573 and then Chars (Last_Arg) = Name_Reason
24576 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
24577 Reason := End_String;
24578 Arg_Count := Arg_Count - 1;
24580 -- Not allowed in compiler units (bootstrap issues)
24582 Check_Compiler_Unit ("Reason for pragma Warnings", N);
24584 -- No REASON string, set null string as reason
24587 Reason := Null_String_Id;
24591 -- Now proceed with REASON taken care of and eliminated
24593 Check_No_Identifiers;
24595 -- If debug flag -gnatd.i is set, pragma is ignored
24597 if Debug_Flag_Dot_I then
24601 -- Process various forms of the pragma
24604 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
24605 Shifted_Args : List_Id;
24608 -- See if first argument is a tool name, currently either
24609 -- GNAT or GNATprove. If so, either ignore the pragma if the
24610 -- tool used does not match, or continue as if no tool name
24611 -- was given otherwise, by shifting the arguments.
24613 if Nkind (Argx) = N_Identifier
24614 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
24616 if Chars (Argx) = Name_Gnat then
24617 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
24618 Rewrite (N, Make_Null_Statement (Loc));
24623 elsif Chars (Argx) = Name_Gnatprove then
24624 if not GNATprove_Mode then
24625 Rewrite (N, Make_Null_Statement (Loc));
24631 raise Program_Error;
24634 -- At this point, the pragma Warnings applies to the tool,
24635 -- so continue with shifted arguments.
24637 Arg_Count := Arg_Count - 1;
24639 if Arg_Count = 1 then
24640 Shifted_Args := New_List (New_Copy (Arg2));
24641 elsif Arg_Count = 2 then
24642 Shifted_Args := New_List (New_Copy (Arg2),
24644 elsif Arg_Count = 3 then
24645 Shifted_Args := New_List (New_Copy (Arg2),
24649 raise Program_Error;
24654 Chars => Name_Warnings,
24655 Pragma_Argument_Associations => Shifted_Args));
24660 -- One argument case
24662 if Arg_Count = 1 then
24664 -- On/Off one argument case was processed by parser
24666 if Nkind (Argx) = N_Identifier
24667 and then Nam_In (Chars (Argx), Name_On, Name_Off)
24671 -- One argument case must be ON/OFF or static string expr
24673 elsif not Is_Static_String_Expression (Arg1) then
24675 ("argument of pragma% must be On/Off or static string "
24676 & "expression", Arg1);
24678 -- One argument string expression case
24682 Lit : constant Node_Id := Expr_Value_S (Argx);
24683 Str : constant String_Id := Strval (Lit);
24684 Len : constant Nat := String_Length (Str);
24692 while J <= Len loop
24693 C := Get_String_Char (Str, J);
24694 OK := In_Character_Range (C);
24697 Chr := Get_Character (C);
24699 -- Dash case: only -Wxxx is accepted
24706 C := Get_String_Char (Str, J);
24707 Chr := Get_Character (C);
24708 exit when Chr = 'W
';
24713 elsif J < Len and then Chr = '.' then
24715 C := Get_String_Char (Str, J);
24716 Chr := Get_Character (C);
24718 if not Set_Dot_Warning_Switch (Chr) then
24720 ("invalid warning switch character "
24721 & '.' & Chr, Arg1);
24727 OK := Set_Warning_Switch (Chr);
24732 ("invalid warning switch character " & Chr,
24738 ("invalid wide character in warning switch ",
24747 -- Two or more arguments (must be two)
24750 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24751 Check_Arg_Count (2);
24759 E_Id := Get_Pragma_Arg (Arg2);
24762 -- In the expansion of an inlined body, a reference to
24763 -- the formal may be wrapped in a conversion if the
24764 -- actual is a conversion. Retrieve the real entity name.
24766 if (In_Instance_Body or In_Inlined_Body)
24767 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
24769 E_Id := Expression (E_Id);
24772 -- Entity name case
24774 if Is_Entity_Name (E_Id) then
24775 E := Entity (E_Id);
24782 (E, (Chars (Get_Pragma_Arg (Arg1)) =
24785 -- Suppress elaboration warnings if the entity
24786 -- denotes an elaboration target.
24788 if Is_Elaboration_Target (E) then
24789 Set_Is_Elaboration_Warnings_OK_Id (E, False);
24792 -- For OFF case, make entry in warnings off
24793 -- pragma table for later processing. But we do
24794 -- not do that within an instance, since these
24795 -- warnings are about what is needed in the
24796 -- template, not an instance of it.
24798 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
24799 and then Warn_On_Warnings_Off
24800 and then not In_Instance
24802 Warnings_Off_Pragmas.Append ((N, E, Reason));
24805 if Is_Enumeration_Type (E) then
24809 Lit := First_Literal (E);
24810 while Present (Lit) loop
24811 Set_Warnings_Off (Lit);
24812 Next_Literal (Lit);
24817 exit when No (Homonym (E));
24822 -- Error if not entity or static string expression case
24824 elsif not Is_Static_String_Expression (Arg2) then
24826 ("second argument of pragma% must be entity name "
24827 & "or static string expression", Arg2);
24829 -- Static string expression case
24832 Acquire_Warning_Match_String (Arg2);
24834 -- Note on configuration pragma case: If this is a
24835 -- configuration pragma, then for an OFF pragma, we
24836 -- just set Config True in the call, which is all
24837 -- that needs to be done. For the case of ON, this
24838 -- is normally an error, unless it is canceling the
24839 -- effect of a previous OFF pragma in the same file.
24840 -- In any other case, an error will be signalled (ON
24841 -- with no matching OFF).
24843 -- Note: We set Used if we are inside a generic to
24844 -- disable the test that the non-config case actually
24845 -- cancels a warning. That's because we can't be sure
24846 -- there isn't an instantiation in some other unit
24847 -- where a warning is suppressed.
24849 -- We could do a little better here by checking if the
24850 -- generic unit we are inside is public, but for now
24851 -- we don't bother with that refinement.
24853 if Chars (Argx) = Name_Off then
24854 Set_Specific_Warning_Off
24855 (Loc, Name_Buffer (1 .. Name_Len), Reason,
24856 Config => Is_Configuration_Pragma,
24857 Used => Inside_A_Generic or else In_Instance);
24859 elsif Chars (Argx) = Name_On then
24860 Set_Specific_Warning_On
24861 (Loc, Name_Buffer (1 .. Name_Len), Err);
24865 ("??pragma Warnings On with no matching "
24866 & "Warnings Off", Loc);
24875 -------------------
24876 -- Weak_External --
24877 -------------------
24879 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
24881 when Pragma_Weak_External => Weak_External : declare
24886 Check_Arg_Count (1);
24887 Check_Optional_Identifier (Arg1, Name_Entity);
24888 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24889 Ent := Entity (Get_Pragma_Arg (Arg1));
24891 if Rep_Item_Too_Early (Ent, N) then
24894 Ent := Underlying_Type (Ent);
24897 -- The only processing required is to link this item on to the
24898 -- list of rep items for the given entity. This is accomplished
24899 -- by the call to Rep_Item_Too_Late (when no error is detected
24900 -- and False is returned).
24902 if Rep_Item_Too_Late (Ent, N) then
24905 Set_Has_Gigi_Rep_Item (Ent);
24909 -----------------------------
24910 -- Wide_Character_Encoding --
24911 -----------------------------
24913 -- pragma Wide_Character_Encoding (IDENTIFIER);
24915 when Pragma_Wide_Character_Encoding =>
24918 -- Nothing to do, handled in parser. Note that we do not enforce
24919 -- configuration pragma placement, this pragma can appear at any
24920 -- place in the source, allowing mixed encodings within a single
24925 --------------------
24926 -- Unknown_Pragma --
24927 --------------------
24929 -- Should be impossible, since the case of an unknown pragma is
24930 -- separately processed before the case statement is entered.
24932 when Unknown_Pragma =>
24933 raise Program_Error;
24936 -- AI05-0144: detect dangerous order dependence. Disabled for now,
24937 -- until AI is formally approved.
24939 -- Check_Order_Dependence;
24942 when Pragma_Exit => null;
24943 end Analyze_Pragma;
24945 ---------------------------------------------
24946 -- Analyze_Pre_Post_Condition_In_Decl_Part --
24947 ---------------------------------------------
24949 -- WARNING: This routine manages Ghost regions. Return statements must be
24950 -- replaced by gotos which jump to the end of the routine and restore the
24953 procedure Analyze_Pre_Post_Condition_In_Decl_Part
24955 Freeze_Id : Entity_Id := Empty)
24957 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24958 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
24960 Disp_Typ : Entity_Id;
24961 -- The dispatching type of the subprogram subject to the pre- or
24964 function Check_References (Nod : Node_Id) return Traverse_Result;
24965 -- Check that expression Nod does not mention non-primitives of the
24966 -- type, global objects of the type, or other illegalities described
24967 -- and implied by AI12-0113.
24969 ----------------------
24970 -- Check_References --
24971 ----------------------
24973 function Check_References (Nod : Node_Id) return Traverse_Result is
24975 if Nkind (Nod) = N_Function_Call
24976 and then Is_Entity_Name (Name (Nod))
24979 Func : constant Entity_Id := Entity (Name (Nod));
24983 -- An operation of the type must be a primitive
24985 if No (Find_Dispatching_Type (Func)) then
24986 Form := First_Formal (Func);
24987 while Present (Form) loop
24988 if Etype (Form) = Disp_Typ then
24990 ("operation in class-wide condition must be "
24991 & "primitive of &", Nod, Disp_Typ);
24994 Next_Formal (Form);
24997 -- A return object of the type is illegal as well
24999 if Etype (Func) = Disp_Typ
25000 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
25003 ("operation in class-wide condition must be primitive "
25004 & "of &", Nod, Disp_Typ);
25007 -- Otherwise we have a call to an overridden primitive, and we
25008 -- will create a common class-wide clone for the body of
25009 -- original operation and its eventual inherited versions. If
25010 -- the original operation dispatches on result it is never
25011 -- inherited and there is no need for a clone. There is not
25012 -- need for a clone either in GNATprove mode, as cases that
25013 -- would require it are rejected (when an inherited primitive
25014 -- calls an overridden operation in a class-wide contract), and
25015 -- the clone would make proof impossible in some cases.
25017 elsif not Is_Abstract_Subprogram (Spec_Id)
25018 and then No (Class_Wide_Clone (Spec_Id))
25019 and then not Has_Controlling_Result (Spec_Id)
25020 and then not GNATprove_Mode
25022 Build_Class_Wide_Clone_Decl (Spec_Id);
25026 elsif Is_Entity_Name (Nod)
25028 (Etype (Nod) = Disp_Typ
25029 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25030 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
25033 ("object in class-wide condition must be formal of type &",
25036 elsif Nkind (Nod) = N_Explicit_Dereference
25037 and then (Etype (Nod) = Disp_Typ
25038 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
25039 and then (not Is_Entity_Name (Prefix (Nod))
25040 or else not Is_Formal (Entity (Prefix (Nod))))
25043 ("operation in class-wide condition must be primitive of &",
25048 end Check_References;
25050 procedure Check_Class_Wide_Condition is
25051 new Traverse_Proc (Check_References);
25055 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
25057 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
25058 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
25059 -- Save the Ghost-related attributes to restore on exit
25062 Restore_Scope : Boolean := False;
25064 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
25067 -- Do not analyze the pragma multiple times
25069 if Is_Analyzed_Pragma (N) then
25073 -- Set the Ghost mode in effect from the pragma. Due to the delayed
25074 -- analysis of the pragma, the Ghost mode at point of declaration and
25075 -- point of analysis may not necessarily be the same. Use the mode in
25076 -- effect at the point of declaration.
25078 Set_Ghost_Mode (N);
25080 -- Ensure that the subprogram and its formals are visible when analyzing
25081 -- the expression of the pragma.
25083 if not In_Open_Scopes (Spec_Id) then
25084 Restore_Scope := True;
25085 Push_Scope (Spec_Id);
25087 if Is_Generic_Subprogram (Spec_Id) then
25088 Install_Generic_Formals (Spec_Id);
25090 Install_Formals (Spec_Id);
25094 Errors := Serious_Errors_Detected;
25095 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
25097 -- Emit a clarification message when the expression contains at least
25098 -- one undefined reference, possibly due to contract freezing.
25100 if Errors /= Serious_Errors_Detected
25101 and then Present (Freeze_Id)
25102 and then Has_Undefined_Reference (Expr)
25104 Contract_Freeze_Error (Spec_Id, Freeze_Id);
25107 if Class_Present (N) then
25109 -- Verify that a class-wide condition is legal, i.e. the operation is
25110 -- a primitive of a tagged type. Note that a generic subprogram is
25111 -- not a primitive operation.
25113 Disp_Typ := Find_Dispatching_Type (Spec_Id);
25115 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
25116 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
25118 if From_Aspect_Specification (N) then
25120 ("aspect % can only be specified for a primitive operation "
25121 & "of a tagged type", Corresponding_Aspect (N));
25123 -- The pragma is a source construct
25127 ("pragma % can only be specified for a primitive operation "
25128 & "of a tagged type", N);
25131 -- Remaining semantic checks require a full tree traversal
25134 Check_Class_Wide_Condition (Expr);
25139 if Restore_Scope then
25143 -- If analysis of the condition indicates that a class-wide clone
25144 -- has been created, build and analyze its declaration.
25146 if Is_Subprogram (Spec_Id)
25147 and then Present (Class_Wide_Clone (Spec_Id))
25149 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
25152 -- Currently it is not possible to inline pre/postconditions on a
25153 -- subprogram subject to pragma Inline_Always.
25155 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
25156 Set_Is_Analyzed_Pragma (N);
25158 Restore_Ghost_Region (Saved_GM, Saved_IGR);
25159 end Analyze_Pre_Post_Condition_In_Decl_Part;
25161 ------------------------------------------
25162 -- Analyze_Refined_Depends_In_Decl_Part --
25163 ------------------------------------------
25165 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
25166 procedure Check_Dependency_Clause
25167 (Spec_Id : Entity_Id;
25168 Dep_Clause : Node_Id;
25169 Dep_States : Elist_Id;
25170 Refinements : List_Id;
25171 Matched_Items : in out Elist_Id);
25172 -- Try to match a single dependency clause Dep_Clause against one or
25173 -- more refinement clauses found in list Refinements. Each successful
25174 -- match eliminates at least one refinement clause from Refinements.
25175 -- Spec_Id denotes the entity of the related subprogram. Dep_States
25176 -- denotes the entities of all abstract states which appear in pragma
25177 -- Depends. Matched_Items contains the entities of all successfully
25178 -- matched items found in pragma Depends.
25180 procedure Check_Output_States
25181 (Spec_Id : Entity_Id;
25182 Spec_Inputs : Elist_Id;
25183 Spec_Outputs : Elist_Id;
25184 Body_Inputs : Elist_Id;
25185 Body_Outputs : Elist_Id);
25186 -- Determine whether pragma Depends contains an output state with a
25187 -- visible refinement and if so, ensure that pragma Refined_Depends
25188 -- mentions all its constituents as outputs. Spec_Id is the entity of
25189 -- the related subprograms. Spec_Inputs and Spec_Outputs denote the
25190 -- inputs and outputs of the subprogram spec synthesized from pragma
25191 -- Depends. Body_Inputs and Body_Outputs denote the inputs and outputs
25192 -- of the subprogram body synthesized from pragma Refined_Depends.
25194 function Collect_States (Clauses : List_Id) return Elist_Id;
25195 -- Given a normalized list of dependencies obtained from calling
25196 -- Normalize_Clauses, return a list containing the entities of all
25197 -- states appearing in dependencies. It helps in checking refinements
25198 -- involving a state and a corresponding constituent which is not a
25199 -- direct constituent of the state.
25201 procedure Normalize_Clauses (Clauses : List_Id);
25202 -- Given a list of dependence or refinement clauses Clauses, normalize
25203 -- each clause by creating multiple dependencies with exactly one input
25206 procedure Remove_Extra_Clauses
25207 (Clauses : List_Id;
25208 Matched_Items : Elist_Id);
25209 -- Given a list of refinement clauses Clauses, remove all clauses whose
25210 -- inputs and/or outputs have been previously matched. See the body for
25211 -- all special cases. Matched_Items contains the entities of all matched
25212 -- items found in pragma Depends.
25214 procedure Report_Extra_Clauses
25215 (Spec_Id : Entity_Id;
25216 Clauses : List_Id);
25217 -- Emit an error for each extra clause found in list Clauses. Spec_Id
25218 -- denotes the entity of the related subprogram.
25220 -----------------------------
25221 -- Check_Dependency_Clause --
25222 -----------------------------
25224 procedure Check_Dependency_Clause
25225 (Spec_Id : Entity_Id;
25226 Dep_Clause : Node_Id;
25227 Dep_States : Elist_Id;
25228 Refinements : List_Id;
25229 Matched_Items : in out Elist_Id)
25231 Dep_Input : constant Node_Id := Expression (Dep_Clause);
25232 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
25234 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
25235 -- Determine whether dependency item Dep_Item has been matched in a
25236 -- previous clause.
25238 function Is_In_Out_State_Clause return Boolean;
25239 -- Determine whether dependence clause Dep_Clause denotes an abstract
25240 -- state that depends on itself (State => State).
25242 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
25243 -- Determine whether item Item denotes an abstract state with visible
25244 -- null refinement.
25246 procedure Match_Items
25247 (Dep_Item : Node_Id;
25248 Ref_Item : Node_Id;
25249 Matched : out Boolean);
25250 -- Try to match dependence item Dep_Item against refinement item
25251 -- Ref_Item. To match against a possible null refinement (see 2, 9),
25252 -- set Ref_Item to Empty. Flag Matched is set to True when one of
25253 -- the following conformance scenarios is in effect:
25254 -- 1) Both items denote null
25255 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
25256 -- 3) Both items denote attribute 'Result
25257 -- 4) Both items denote the same object
25258 -- 5) Both items denote the same formal parameter
25259 -- 6) Both items denote the same current instance of a type
25260 -- 7) Both items denote the same discriminant
25261 -- 8) Dep_Item is an abstract state with visible null refinement
25262 -- and Ref_Item denotes null.
25263 -- 9) Dep_Item is an abstract state with visible null refinement
25264 -- and Ref_Item is Empty (special case).
25265 -- 10) Dep_Item is an abstract state with full or partial visible
25266 -- non-null refinement and Ref_Item denotes one of its
25268 -- 11) Dep_Item is an abstract state without a full visible
25269 -- refinement and Ref_Item denotes the same state.
25270 -- When scenario 10 is in effect, the entity of the abstract state
25271 -- denoted by Dep_Item is added to list Refined_States.
25273 procedure Record_Item
(Item_Id
: Entity_Id
);
25274 -- Store the entity of an item denoted by Item_Id in Matched_Items
25276 ------------------------
25277 -- Is_Already_Matched --
25278 ------------------------
25280 function Is_Already_Matched
(Dep_Item
: Node_Id
) return Boolean is
25281 Item_Id
: Entity_Id
:= Empty
;
25284 -- When the dependency item denotes attribute 'Result, check for
25285 -- the entity of the related subprogram.
25287 if Is_Attribute_Result
(Dep_Item
) then
25288 Item_Id
:= Spec_Id
;
25290 elsif Is_Entity_Name
(Dep_Item
) then
25291 Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
25295 Present
(Item_Id
) and then Contains
(Matched_Items
, Item_Id
);
25296 end Is_Already_Matched
;
25298 ----------------------------
25299 -- Is_In_Out_State_Clause --
25300 ----------------------------
25302 function Is_In_Out_State_Clause
return Boolean is
25303 Dep_Input_Id
: Entity_Id
;
25304 Dep_Output_Id
: Entity_Id
;
25307 -- Detect the following clause:
25310 if Is_Entity_Name
(Dep_Input
)
25311 and then Is_Entity_Name
(Dep_Output
)
25313 -- Handle abstract views generated for limited with clauses
25315 Dep_Input_Id
:= Available_View
(Entity_Of
(Dep_Input
));
25316 Dep_Output_Id
:= Available_View
(Entity_Of
(Dep_Output
));
25319 Ekind
(Dep_Input_Id
) = E_Abstract_State
25320 and then Dep_Input_Id
= Dep_Output_Id
;
25324 end Is_In_Out_State_Clause
;
25326 ---------------------------
25327 -- Is_Null_Refined_State --
25328 ---------------------------
25330 function Is_Null_Refined_State
(Item
: Node_Id
) return Boolean is
25331 Item_Id
: Entity_Id
;
25334 if Is_Entity_Name
(Item
) then
25336 -- Handle abstract views generated for limited with clauses
25338 Item_Id
:= Available_View
(Entity_Of
(Item
));
25341 Ekind
(Item_Id
) = E_Abstract_State
25342 and then Has_Null_Visible_Refinement
(Item_Id
);
25346 end Is_Null_Refined_State
;
25352 procedure Match_Items
25353 (Dep_Item
: Node_Id
;
25354 Ref_Item
: Node_Id
;
25355 Matched
: out Boolean)
25357 Dep_Item_Id
: Entity_Id
;
25358 Ref_Item_Id
: Entity_Id
;
25361 -- Assume that the two items do not match
25365 -- A null matches null or Empty (special case)
25367 if Nkind
(Dep_Item
) = N_Null
25368 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
25372 -- Attribute 'Result matches attribute 'Result
25374 elsif Is_Attribute_Result
(Dep_Item
)
25375 and then Is_Attribute_Result
(Ref_Item
)
25377 -- Put the entity of the related function on the list of
25378 -- matched items because attribute 'Result does not carry
25379 -- an entity similar to states and constituents.
25381 Record_Item
(Spec_Id
);
25384 -- Abstract states, current instances of concurrent types,
25385 -- discriminants, formal parameters and objects.
25387 elsif Is_Entity_Name
(Dep_Item
) then
25389 -- Handle abstract views generated for limited with clauses
25391 Dep_Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
25393 if Ekind
(Dep_Item_Id
) = E_Abstract_State
then
25395 -- An abstract state with visible null refinement matches
25396 -- null or Empty (special case).
25398 if Has_Null_Visible_Refinement
(Dep_Item_Id
)
25399 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
25401 Record_Item
(Dep_Item_Id
);
25404 -- An abstract state with visible non-null refinement
25405 -- matches one of its constituents, or itself for an
25406 -- abstract state with partial visible refinement.
25408 elsif Has_Non_Null_Visible_Refinement
(Dep_Item_Id
) then
25409 if Is_Entity_Name
(Ref_Item
) then
25410 Ref_Item_Id
:= Entity_Of
(Ref_Item
);
25412 if Ekind_In
(Ref_Item_Id
, E_Abstract_State
,
25415 and then Present
(Encapsulating_State
(Ref_Item_Id
))
25416 and then Find_Encapsulating_State
25417 (Dep_States
, Ref_Item_Id
) = Dep_Item_Id
25419 Record_Item
(Dep_Item_Id
);
25422 elsif not Has_Visible_Refinement
(Dep_Item_Id
)
25423 and then Ref_Item_Id
= Dep_Item_Id
25425 Record_Item
(Dep_Item_Id
);
25430 -- An abstract state without a visible refinement matches
25433 elsif Is_Entity_Name
(Ref_Item
)
25434 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
25436 Record_Item
(Dep_Item_Id
);
25440 -- A current instance of a concurrent type, discriminant,
25441 -- formal parameter or an object matches itself.
25443 elsif Is_Entity_Name
(Ref_Item
)
25444 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
25446 Record_Item
(Dep_Item_Id
);
25456 procedure Record_Item
(Item_Id
: Entity_Id
) is
25458 if No
(Matched_Items
) then
25459 Matched_Items
:= New_Elmt_List
;
25462 Append_Unique_Elmt
(Item_Id
, Matched_Items
);
25467 Clause_Matched
: Boolean := False;
25468 Dummy
: Boolean := False;
25469 Inputs_Match
: Boolean;
25470 Next_Ref_Clause
: Node_Id
;
25471 Outputs_Match
: Boolean;
25472 Ref_Clause
: Node_Id
;
25473 Ref_Input
: Node_Id
;
25474 Ref_Output
: Node_Id
;
25476 -- Start of processing for Check_Dependency_Clause
25479 -- Do not perform this check in an instance because it was already
25480 -- performed successfully in the generic template.
25482 if Is_Generic_Instance
(Spec_Id
) then
25486 -- Examine all refinement clauses and compare them against the
25487 -- dependence clause.
25489 Ref_Clause
:= First
(Refinements
);
25490 while Present
(Ref_Clause
) loop
25491 Next_Ref_Clause
:= Next
(Ref_Clause
);
25493 -- Obtain the attributes of the current refinement clause
25495 Ref_Input
:= Expression
(Ref_Clause
);
25496 Ref_Output
:= First
(Choices
(Ref_Clause
));
25498 -- The current refinement clause matches the dependence clause
25499 -- when both outputs match and both inputs match. See routine
25500 -- Match_Items for all possible conformance scenarios.
25502 -- Depends Dep_Output => Dep_Input
25506 -- Refined_Depends Ref_Output => Ref_Input
25509 (Dep_Item
=> Dep_Input
,
25510 Ref_Item
=> Ref_Input
,
25511 Matched
=> Inputs_Match
);
25514 (Dep_Item
=> Dep_Output
,
25515 Ref_Item
=> Ref_Output
,
25516 Matched
=> Outputs_Match
);
25518 -- An In_Out state clause may be matched against a refinement with
25519 -- a null input or null output as long as the non-null side of the
25520 -- relation contains a valid constituent of the In_Out_State.
25522 if Is_In_Out_State_Clause
then
25524 -- Depends => (State => State)
25525 -- Refined_Depends => (null => Constit) -- OK
25528 and then not Outputs_Match
25529 and then Nkind
(Ref_Output
) = N_Null
25531 Outputs_Match
:= True;
25534 -- Depends => (State => State)
25535 -- Refined_Depends => (Constit => null) -- OK
25537 if not Inputs_Match
25538 and then Outputs_Match
25539 and then Nkind
(Ref_Input
) = N_Null
25541 Inputs_Match
:= True;
25545 -- The current refinement clause is legally constructed following
25546 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
25547 -- the pool of candidates. The seach continues because a single
25548 -- dependence clause may have multiple matching refinements.
25550 if Inputs_Match
and Outputs_Match
then
25551 Clause_Matched
:= True;
25552 Remove
(Ref_Clause
);
25555 Ref_Clause
:= Next_Ref_Clause
;
25558 -- Depending on the order or composition of refinement clauses, an
25559 -- In_Out state clause may not be directly refinable.
25561 -- Refined_State => (State => (Constit_1, Constit_2))
25562 -- Depends => ((Output, State) => (Input, State))
25563 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
25565 -- Matching normalized clause (State => State) fails because there is
25566 -- no direct refinement capable of satisfying this relation. Another
25567 -- similar case arises when clauses (Constit_1 => Input) and (Output
25568 -- => Constit_2) are matched first, leaving no candidates for clause
25569 -- (State => State). Both scenarios are legal as long as one of the
25570 -- previous clauses mentioned a valid constituent of State.
25572 if not Clause_Matched
25573 and then Is_In_Out_State_Clause
25574 and then Is_Already_Matched
(Dep_Input
)
25576 Clause_Matched
:= True;
25579 -- A clause where the input is an abstract state with visible null
25580 -- refinement or a 'Result attribute is implicitly matched when the
25581 -- output has already been matched in a previous clause.
25583 -- Refined_State => (State => null)
25584 -- Depends => (Output => State) -- implicitly OK
25585 -- Refined_Depends => (Output => ...)
25586 -- Depends => (...'Result => State) -- implicitly OK
25587 -- Refined_Depends => (...'Result => ...)
25589 if not Clause_Matched
25590 and then Is_Null_Refined_State
(Dep_Input
)
25591 and then Is_Already_Matched
(Dep_Output
)
25593 Clause_Matched
:= True;
25596 -- A clause where the output is an abstract state with visible null
25597 -- refinement is implicitly matched when the input has already been
25598 -- matched in a previous clause.
25600 -- Refined_State => (State => null)
25601 -- Depends => (State => Input) -- implicitly OK
25602 -- Refined_Depends => (... => Input)
25604 if not Clause_Matched
25605 and then Is_Null_Refined_State
(Dep_Output
)
25606 and then Is_Already_Matched
(Dep_Input
)
25608 Clause_Matched
:= True;
25611 -- At this point either all refinement clauses have been examined or
25612 -- pragma Refined_Depends contains a solitary null. Only an abstract
25613 -- state with null refinement can possibly match these cases.
25615 -- Refined_State => (State => null)
25616 -- Depends => (State => null)
25617 -- Refined_Depends => null -- OK
25619 if not Clause_Matched
then
25621 (Dep_Item
=> Dep_Input
,
25623 Matched
=> Inputs_Match
);
25626 (Dep_Item
=> Dep_Output
,
25628 Matched
=> Outputs_Match
);
25630 Clause_Matched
:= Inputs_Match
and Outputs_Match
;
25633 -- If the contents of Refined_Depends are legal, then the current
25634 -- dependence clause should be satisfied either by an explicit match
25635 -- or by one of the special cases.
25637 if not Clause_Matched
then
25639 (Fix_Msg
(Spec_Id
, "dependence clause of subprogram & has no "
25640 & "matching refinement in body"), Dep_Clause
, Spec_Id
);
25642 end Check_Dependency_Clause
;
25644 -------------------------
25645 -- Check_Output_States --
25646 -------------------------
25648 procedure Check_Output_States
25649 (Spec_Id
: Entity_Id
;
25650 Spec_Inputs
: Elist_Id
;
25651 Spec_Outputs
: Elist_Id
;
25652 Body_Inputs
: Elist_Id
;
25653 Body_Outputs
: Elist_Id
)
25655 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
25656 -- Determine whether all constituents of state State_Id with full
25657 -- visible refinement are used as outputs in pragma Refined_Depends.
25658 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
25660 -----------------------------
25661 -- Check_Constituent_Usage --
25662 -----------------------------
25664 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
25665 Constits
: constant Elist_Id
:=
25666 Partial_Refinement_Constituents
(State_Id
);
25667 Constit_Elmt
: Elmt_Id
;
25668 Constit_Id
: Entity_Id
;
25669 Only_Partial
: constant Boolean :=
25670 not Has_Visible_Refinement
(State_Id
);
25671 Posted
: Boolean := False;
25674 if Present
(Constits
) then
25675 Constit_Elmt
:= First_Elmt
(Constits
);
25676 while Present
(Constit_Elmt
) loop
25677 Constit_Id
:= Node
(Constit_Elmt
);
25679 -- Issue an error when a constituent of State_Id is used,
25680 -- and State_Id has only partial visible refinement
25681 -- (SPARK RM 7.2.4(3d)).
25683 if Only_Partial
then
25684 if (Present
(Body_Inputs
)
25685 and then Appears_In
(Body_Inputs
, Constit_Id
))
25687 (Present
(Body_Outputs
)
25688 and then Appears_In
(Body_Outputs
, Constit_Id
))
25690 Error_Msg_Name_1
:= Chars
(State_Id
);
25692 ("constituent & of state % cannot be used in "
25693 & "dependence refinement", N
, Constit_Id
);
25694 Error_Msg_Name_1
:= Chars
(State_Id
);
25695 SPARK_Msg_N
("\use state % instead", N
);
25698 -- The constituent acts as an input (SPARK RM 7.2.5(3))
25700 elsif Present
(Body_Inputs
)
25701 and then Appears_In
(Body_Inputs
, Constit_Id
)
25703 Error_Msg_Name_1
:= Chars
(State_Id
);
25705 ("constituent & of state % must act as output in "
25706 & "dependence refinement", N
, Constit_Id
);
25708 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
25710 elsif No
(Body_Outputs
)
25711 or else not Appears_In
(Body_Outputs
, Constit_Id
)
25716 ("output state & must be replaced by all its "
25717 & "constituents in dependence refinement",
25722 ("\constituent & is missing in output list",
25726 Next_Elmt
(Constit_Elmt
);
25729 end Check_Constituent_Usage
;
25734 Item_Elmt
: Elmt_Id
;
25735 Item_Id
: Entity_Id
;
25737 -- Start of processing for Check_Output_States
25740 -- Do not perform this check in an instance because it was already
25741 -- performed successfully in the generic template.
25743 if Is_Generic_Instance
(Spec_Id
) then
25746 -- Inspect the outputs of pragma Depends looking for a state with a
25747 -- visible refinement.
25749 elsif Present
(Spec_Outputs
) then
25750 Item_Elmt
:= First_Elmt
(Spec_Outputs
);
25751 while Present
(Item_Elmt
) loop
25752 Item
:= Node
(Item_Elmt
);
25754 -- Deal with the mixed nature of the input and output lists
25756 if Nkind
(Item
) = N_Defining_Identifier
then
25759 Item_Id
:= Available_View
(Entity_Of
(Item
));
25762 if Ekind
(Item_Id
) = E_Abstract_State
then
25764 -- The state acts as an input-output, skip it
25766 if Present
(Spec_Inputs
)
25767 and then Appears_In
(Spec_Inputs
, Item_Id
)
25771 -- Ensure that all of the constituents are utilized as
25772 -- outputs in pragma Refined_Depends.
25774 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
25775 Check_Constituent_Usage
(Item_Id
);
25779 Next_Elmt
(Item_Elmt
);
25782 end Check_Output_States
;
25784 --------------------
25785 -- Collect_States --
25786 --------------------
25788 function Collect_States
(Clauses
: List_Id
) return Elist_Id
is
25789 procedure Collect_State
25791 States
: in out Elist_Id
);
25792 -- Add the entity of Item to list States when it denotes to a state
25794 -------------------
25795 -- Collect_State --
25796 -------------------
25798 procedure Collect_State
25800 States
: in out Elist_Id
)
25805 if Is_Entity_Name
(Item
) then
25806 Id
:= Entity_Of
(Item
);
25808 if Ekind
(Id
) = E_Abstract_State
then
25809 if No
(States
) then
25810 States
:= New_Elmt_List
;
25813 Append_Unique_Elmt
(Id
, States
);
25823 States
: Elist_Id
:= No_Elist
;
25825 -- Start of processing for Collect_States
25828 Clause
:= First
(Clauses
);
25829 while Present
(Clause
) loop
25830 Input
:= Expression
(Clause
);
25831 Output
:= First
(Choices
(Clause
));
25833 Collect_State
(Input
, States
);
25834 Collect_State
(Output
, States
);
25840 end Collect_States
;
25842 -----------------------
25843 -- Normalize_Clauses --
25844 -----------------------
25846 procedure Normalize_Clauses
(Clauses
: List_Id
) is
25847 procedure Normalize_Inputs
(Clause
: Node_Id
);
25848 -- Normalize clause Clause by creating multiple clauses for each
25849 -- input item of Clause. It is assumed that Clause has exactly one
25850 -- output. The transformation is as follows:
25852 -- Output => (Input_1, Input_2) -- original
25854 -- Output => Input_1 -- normalizations
25855 -- Output => Input_2
25857 procedure Normalize_Outputs
(Clause
: Node_Id
);
25858 -- Normalize clause Clause by creating multiple clause for each
25859 -- output item of Clause. The transformation is as follows:
25861 -- (Output_1, Output_2) => Input -- original
25863 -- Output_1 => Input -- normalization
25864 -- Output_2 => Input
25866 ----------------------
25867 -- Normalize_Inputs --
25868 ----------------------
25870 procedure Normalize_Inputs
(Clause
: Node_Id
) is
25871 Inputs
: constant Node_Id
:= Expression
(Clause
);
25872 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
25873 Output
: constant List_Id
:= Choices
(Clause
);
25874 Last_Input
: Node_Id
;
25876 New_Clause
: Node_Id
;
25877 Next_Input
: Node_Id
;
25880 -- Normalization is performed only when the original clause has
25881 -- more than one input. Multiple inputs appear as an aggregate.
25883 if Nkind
(Inputs
) = N_Aggregate
then
25884 Last_Input
:= Last
(Expressions
(Inputs
));
25886 -- Create a new clause for each input
25888 Input
:= First
(Expressions
(Inputs
));
25889 while Present
(Input
) loop
25890 Next_Input
:= Next
(Input
);
25892 -- Unhook the current input from the original input list
25893 -- because it will be relocated to a new clause.
25897 -- Special processing for the last input. At this point the
25898 -- original aggregate has been stripped down to one element.
25899 -- Replace the aggregate by the element itself.
25901 if Input
= Last_Input
then
25902 Rewrite
(Inputs
, Input
);
25904 -- Generate a clause of the form:
25909 Make_Component_Association
(Loc
,
25910 Choices
=> New_Copy_List_Tree
(Output
),
25911 Expression
=> Input
);
25913 -- The new clause contains replicated content that has
25914 -- already been analyzed, mark the clause as analyzed.
25916 Set_Analyzed
(New_Clause
);
25917 Insert_After
(Clause
, New_Clause
);
25920 Input
:= Next_Input
;
25923 end Normalize_Inputs
;
25925 -----------------------
25926 -- Normalize_Outputs --
25927 -----------------------
25929 procedure Normalize_Outputs
(Clause
: Node_Id
) is
25930 Inputs
: constant Node_Id
:= Expression
(Clause
);
25931 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
25932 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
25933 Last_Output
: Node_Id
;
25934 New_Clause
: Node_Id
;
25935 Next_Output
: Node_Id
;
25939 -- Multiple outputs appear as an aggregate. Nothing to do when
25940 -- the clause has exactly one output.
25942 if Nkind
(Outputs
) = N_Aggregate
then
25943 Last_Output
:= Last
(Expressions
(Outputs
));
25945 -- Create a clause for each output. Note that each time a new
25946 -- clause is created, the original output list slowly shrinks
25947 -- until there is one item left.
25949 Output
:= First
(Expressions
(Outputs
));
25950 while Present
(Output
) loop
25951 Next_Output
:= Next
(Output
);
25953 -- Unhook the output from the original output list as it
25954 -- will be relocated to a new clause.
25958 -- Special processing for the last output. At this point
25959 -- the original aggregate has been stripped down to one
25960 -- element. Replace the aggregate by the element itself.
25962 if Output
= Last_Output
then
25963 Rewrite
(Outputs
, Output
);
25966 -- Generate a clause of the form:
25967 -- (Output => Inputs)
25970 Make_Component_Association
(Loc
,
25971 Choices
=> New_List
(Output
),
25972 Expression
=> New_Copy_Tree
(Inputs
));
25974 -- The new clause contains replicated content that has
25975 -- already been analyzed. There is not need to reanalyze
25978 Set_Analyzed
(New_Clause
);
25979 Insert_After
(Clause
, New_Clause
);
25982 Output
:= Next_Output
;
25985 end Normalize_Outputs
;
25991 -- Start of processing for Normalize_Clauses
25994 Clause
:= First
(Clauses
);
25995 while Present
(Clause
) loop
25996 Normalize_Outputs
(Clause
);
26000 Clause
:= First
(Clauses
);
26001 while Present
(Clause
) loop
26002 Normalize_Inputs
(Clause
);
26005 end Normalize_Clauses
;
26007 --------------------------
26008 -- Remove_Extra_Clauses --
26009 --------------------------
26011 procedure Remove_Extra_Clauses
26012 (Clauses
: List_Id
;
26013 Matched_Items
: Elist_Id
)
26017 Input_Id
: Entity_Id
;
26018 Next_Clause
: Node_Id
;
26020 State_Id
: Entity_Id
;
26023 Clause
:= First
(Clauses
);
26024 while Present
(Clause
) loop
26025 Next_Clause
:= Next
(Clause
);
26027 Input
:= Expression
(Clause
);
26028 Output
:= First
(Choices
(Clause
));
26030 -- Recognize a clause of the form
26034 -- where Input is a constituent of a state which was already
26035 -- successfully matched. This clause must be removed because it
26036 -- simply indicates that some of the constituents of the state
26039 -- Refined_State => (State => (Constit_1, Constit_2))
26040 -- Depends => (Output => State)
26041 -- Refined_Depends => ((Output => Constit_1), -- State matched
26042 -- (null => Constit_2)) -- OK
26044 if Nkind
(Output
) = N_Null
and then Is_Entity_Name
(Input
) then
26046 -- Handle abstract views generated for limited with clauses
26048 Input_Id
:= Available_View
(Entity_Of
(Input
));
26050 -- The input must be a constituent of a state
26052 if Ekind_In
(Input_Id
, E_Abstract_State
,
26055 and then Present
(Encapsulating_State
(Input_Id
))
26057 State_Id
:= Encapsulating_State
(Input_Id
);
26059 -- The state must have a non-null visible refinement and be
26060 -- matched in a previous clause.
26062 if Has_Non_Null_Visible_Refinement
(State_Id
)
26063 and then Contains
(Matched_Items
, State_Id
)
26069 -- Recognize a clause of the form
26073 -- where Output is an arbitrary item. This clause must be removed
26074 -- because a null input legitimately matches anything.
26076 elsif Nkind
(Input
) = N_Null
then
26080 Clause
:= Next_Clause
;
26082 end Remove_Extra_Clauses
;
26084 --------------------------
26085 -- Report_Extra_Clauses --
26086 --------------------------
26088 procedure Report_Extra_Clauses
26089 (Spec_Id
: Entity_Id
;
26095 -- Do not perform this check in an instance because it was already
26096 -- performed successfully in the generic template.
26098 if Is_Generic_Instance
(Spec_Id
) then
26101 elsif Present
(Clauses
) then
26102 Clause
:= First
(Clauses
);
26103 while Present
(Clause
) loop
26105 ("unmatched or extra clause in dependence refinement",
26111 end Report_Extra_Clauses
;
26115 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
26116 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
26117 Errors
: constant Nat
:= Serious_Errors_Detected
;
26124 Body_Inputs
: Elist_Id
:= No_Elist
;
26125 Body_Outputs
: Elist_Id
:= No_Elist
;
26126 -- The inputs and outputs of the subprogram body synthesized from pragma
26127 -- Refined_Depends.
26129 Dependencies
: List_Id
:= No_List
;
26131 -- The corresponding Depends pragma along with its clauses
26133 Matched_Items
: Elist_Id
:= No_Elist
;
26134 -- A list containing the entities of all successfully matched items
26135 -- found in pragma Depends.
26137 Refinements
: List_Id
:= No_List
;
26138 -- The clauses of pragma Refined_Depends
26140 Spec_Id
: Entity_Id
;
26141 -- The entity of the subprogram subject to pragma Refined_Depends
26143 Spec_Inputs
: Elist_Id
:= No_Elist
;
26144 Spec_Outputs
: Elist_Id
:= No_Elist
;
26145 -- The inputs and outputs of the subprogram spec synthesized from pragma
26148 States
: Elist_Id
:= No_Elist
;
26149 -- A list containing the entities of all states whose constituents
26150 -- appear in pragma Depends.
26152 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
26155 -- Do not analyze the pragma multiple times
26157 if Is_Analyzed_Pragma
(N
) then
26161 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
26163 -- Use the anonymous object as the proper spec when Refined_Depends
26164 -- applies to the body of a single task type. The object carries the
26165 -- proper Chars as well as all non-refined versions of pragmas.
26167 if Is_Single_Concurrent_Type
(Spec_Id
) then
26168 Spec_Id
:= Anonymous_Object
(Spec_Id
);
26171 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
26173 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
26174 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
26176 if No
(Depends
) then
26178 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
26179 & "& lacks aspect or pragma Depends"), N
, Spec_Id
);
26183 Deps
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
26185 -- A null dependency relation renders the refinement useless because it
26186 -- cannot possibly mention abstract states with visible refinement. Note
26187 -- that the inverse is not true as states may be refined to null
26188 -- (SPARK RM 7.2.5(2)).
26190 if Nkind
(Deps
) = N_Null
then
26192 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
26193 & "depend on abstract state with visible refinement"), N
, Spec_Id
);
26197 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
26198 -- This ensures that the categorization of all refined dependency items
26199 -- is consistent with their role.
26201 Analyze_Depends_In_Decl_Part
(N
);
26203 -- Do not match dependencies against refinements if Refined_Depends is
26204 -- illegal to avoid emitting misleading error.
26206 if Serious_Errors_Detected
= Errors
then
26208 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
26209 -- the inputs and outputs of the subprogram spec and body to verify
26210 -- the use of states with visible refinement and their constituents.
26212 if No
(Get_Pragma
(Spec_Id
, Pragma_Global
))
26213 or else No
(Get_Pragma
(Body_Id
, Pragma_Refined_Global
))
26215 Collect_Subprogram_Inputs_Outputs
26216 (Subp_Id
=> Spec_Id
,
26217 Synthesize
=> True,
26218 Subp_Inputs
=> Spec_Inputs
,
26219 Subp_Outputs
=> Spec_Outputs
,
26220 Global_Seen
=> Dummy
);
26222 Collect_Subprogram_Inputs_Outputs
26223 (Subp_Id
=> Body_Id
,
26224 Synthesize
=> True,
26225 Subp_Inputs
=> Body_Inputs
,
26226 Subp_Outputs
=> Body_Outputs
,
26227 Global_Seen
=> Dummy
);
26229 -- For an output state with a visible refinement, ensure that all
26230 -- constituents appear as outputs in the dependency refinement.
26232 Check_Output_States
26233 (Spec_Id
=> Spec_Id
,
26234 Spec_Inputs
=> Spec_Inputs
,
26235 Spec_Outputs
=> Spec_Outputs
,
26236 Body_Inputs
=> Body_Inputs
,
26237 Body_Outputs
=> Body_Outputs
);
26240 -- Matching is disabled in ASIS because clauses are not normalized as
26241 -- this is a tree altering activity similar to expansion.
26247 -- Multiple dependency clauses appear as component associations of an
26248 -- aggregate. Note that the clauses are copied because the algorithm
26249 -- modifies them and this should not be visible in Depends.
26251 pragma Assert
(Nkind
(Deps
) = N_Aggregate
);
26252 Dependencies
:= New_Copy_List_Tree
(Component_Associations
(Deps
));
26253 Normalize_Clauses
(Dependencies
);
26255 -- Gather all states which appear in Depends
26257 States
:= Collect_States
(Dependencies
);
26259 Refs
:= Expression
(Get_Argument
(N
, Spec_Id
));
26261 if Nkind
(Refs
) = N_Null
then
26262 Refinements
:= No_List
;
26264 -- Multiple dependency clauses appear as component associations of an
26265 -- aggregate. Note that the clauses are copied because the algorithm
26266 -- modifies them and this should not be visible in Refined_Depends.
26268 else pragma Assert
(Nkind
(Refs
) = N_Aggregate
);
26269 Refinements
:= New_Copy_List_Tree
(Component_Associations
(Refs
));
26270 Normalize_Clauses
(Refinements
);
26273 -- At this point the clauses of pragmas Depends and Refined_Depends
26274 -- have been normalized into simple dependencies between one output
26275 -- and one input. Examine all clauses of pragma Depends looking for
26276 -- matching clauses in pragma Refined_Depends.
26278 Clause
:= First
(Dependencies
);
26279 while Present
(Clause
) loop
26280 Check_Dependency_Clause
26281 (Spec_Id
=> Spec_Id
,
26282 Dep_Clause
=> Clause
,
26283 Dep_States
=> States
,
26284 Refinements
=> Refinements
,
26285 Matched_Items
=> Matched_Items
);
26290 -- Pragma Refined_Depends may contain multiple clarification clauses
26291 -- which indicate that certain constituents do not influence the data
26292 -- flow in any way. Such clauses must be removed as long as the state
26293 -- has been matched, otherwise they will be incorrectly flagged as
26296 -- Refined_State => (State => (Constit_1, Constit_2))
26297 -- Depends => (Output => State)
26298 -- Refined_Depends => ((Output => Constit_1), -- State matched
26299 -- (null => Constit_2)) -- must be removed
26301 Remove_Extra_Clauses
(Refinements
, Matched_Items
);
26303 if Serious_Errors_Detected
= Errors
then
26304 Report_Extra_Clauses
(Spec_Id
, Refinements
);
26309 Set_Is_Analyzed_Pragma
(N
);
26310 end Analyze_Refined_Depends_In_Decl_Part
;
26312 -----------------------------------------
26313 -- Analyze_Refined_Global_In_Decl_Part --
26314 -----------------------------------------
26316 procedure Analyze_Refined_Global_In_Decl_Part
(N
: Node_Id
) is
26318 -- The corresponding Global pragma
26320 Has_In_State
: Boolean := False;
26321 Has_In_Out_State
: Boolean := False;
26322 Has_Out_State
: Boolean := False;
26323 Has_Proof_In_State
: Boolean := False;
26324 -- These flags are set when the corresponding Global pragma has a state
26325 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
26328 Has_Null_State
: Boolean := False;
26329 -- This flag is set when the corresponding Global pragma has at least
26330 -- one state with a null refinement.
26332 In_Constits
: Elist_Id
:= No_Elist
;
26333 In_Out_Constits
: Elist_Id
:= No_Elist
;
26334 Out_Constits
: Elist_Id
:= No_Elist
;
26335 Proof_In_Constits
: Elist_Id
:= No_Elist
;
26336 -- These lists contain the entities of all Input, In_Out, Output and
26337 -- Proof_In constituents that appear in Refined_Global and participate
26338 -- in state refinement.
26340 In_Items
: Elist_Id
:= No_Elist
;
26341 In_Out_Items
: Elist_Id
:= No_Elist
;
26342 Out_Items
: Elist_Id
:= No_Elist
;
26343 Proof_In_Items
: Elist_Id
:= No_Elist
;
26344 -- These lists contain the entities of all Input, In_Out, Output and
26345 -- Proof_In items defined in the corresponding Global pragma.
26347 Repeat_Items
: Elist_Id
:= No_Elist
;
26348 -- A list of all global items without full visible refinement found
26349 -- in pragma Global. These states should be repeated in the global
26350 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
26351 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
26353 Spec_Id
: Entity_Id
;
26354 -- The entity of the subprogram subject to pragma Refined_Global
26356 States
: Elist_Id
:= No_Elist
;
26357 -- A list of all states with full or partial visible refinement found in
26360 procedure Check_In_Out_States
;
26361 -- Determine whether the corresponding Global pragma mentions In_Out
26362 -- states with visible refinement and if so, ensure that one of the
26363 -- following completions apply to the constituents of the state:
26364 -- 1) there is at least one constituent of mode In_Out
26365 -- 2) there is at least one Input and one Output constituent
26366 -- 3) not all constituents are present and one of them is of mode
26368 -- This routine may remove elements from In_Constits, In_Out_Constits,
26369 -- Out_Constits and Proof_In_Constits.
26371 procedure Check_Input_States
;
26372 -- Determine whether the corresponding Global pragma mentions Input
26373 -- states with visible refinement and if so, ensure that at least one of
26374 -- its constituents appears as an Input item in Refined_Global.
26375 -- This routine may remove elements from In_Constits, In_Out_Constits,
26376 -- Out_Constits and Proof_In_Constits.
26378 procedure Check_Output_States
;
26379 -- Determine whether the corresponding Global pragma mentions Output
26380 -- states with visible refinement and if so, ensure that all of its
26381 -- constituents appear as Output items in Refined_Global.
26382 -- This routine may remove elements from In_Constits, In_Out_Constits,
26383 -- Out_Constits and Proof_In_Constits.
26385 procedure Check_Proof_In_States
;
26386 -- Determine whether the corresponding Global pragma mentions Proof_In
26387 -- states with visible refinement and if so, ensure that at least one of
26388 -- its constituents appears as a Proof_In item in Refined_Global.
26389 -- This routine may remove elements from In_Constits, In_Out_Constits,
26390 -- Out_Constits and Proof_In_Constits.
26392 procedure Check_Refined_Global_List
26394 Global_Mode
: Name_Id
:= Name_Input
);
26395 -- Verify the legality of a single global list declaration. Global_Mode
26396 -- denotes the current mode in effect.
26398 procedure Collect_Global_Items
26400 Mode
: Name_Id
:= Name_Input
);
26401 -- Gather all Input, In_Out, Output and Proof_In items from node List
26402 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
26403 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
26404 -- and Has_Proof_In_State are set when there is at least one abstract
26405 -- state with full or partial visible refinement available in the
26406 -- corresponding mode. Flag Has_Null_State is set when at least state
26407 -- has a null refinement. Mode denotes the current global mode in
26410 function Present_Then_Remove
26412 Item
: Entity_Id
) return Boolean;
26413 -- Search List for a particular entity Item. If Item has been found,
26414 -- remove it from List. This routine is used to strip lists In_Constits,
26415 -- In_Out_Constits and Out_Constits of valid constituents.
26417 procedure Present_Then_Remove
(List
: Elist_Id
; Item
: Entity_Id
);
26418 -- Same as function Present_Then_Remove, but do not report the presence
26419 -- of Item in List.
26421 procedure Report_Extra_Constituents
;
26422 -- Emit an error for each constituent found in lists In_Constits,
26423 -- In_Out_Constits and Out_Constits.
26425 procedure Report_Missing_Items
;
26426 -- Emit an error for each global item not repeated found in list
26429 -------------------------
26430 -- Check_In_Out_States --
26431 -------------------------
26433 procedure Check_In_Out_States
is
26434 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26435 -- Determine whether one of the following coverage scenarios is in
26437 -- 1) there is at least one constituent of mode In_Out or Output
26438 -- 2) there is at least one pair of constituents with modes Input
26439 -- and Output, or Proof_In and Output.
26440 -- 3) there is at least one constituent of mode Output and not all
26441 -- constituents are present.
26442 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
26444 -----------------------------
26445 -- Check_Constituent_Usage --
26446 -----------------------------
26448 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26449 Constits
: constant Elist_Id
:=
26450 Partial_Refinement_Constituents
(State_Id
);
26451 Constit_Elmt
: Elmt_Id
;
26452 Constit_Id
: Entity_Id
;
26453 Has_Missing
: Boolean := False;
26454 In_Out_Seen
: Boolean := False;
26455 Input_Seen
: Boolean := False;
26456 Output_Seen
: Boolean := False;
26457 Proof_In_Seen
: Boolean := False;
26460 -- Process all the constituents of the state and note their modes
26461 -- within the global refinement.
26463 if Present
(Constits
) then
26464 Constit_Elmt
:= First_Elmt
(Constits
);
26465 while Present
(Constit_Elmt
) loop
26466 Constit_Id
:= Node
(Constit_Elmt
);
26468 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
26469 Input_Seen
:= True;
26471 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
) then
26472 In_Out_Seen
:= True;
26474 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
26475 Output_Seen
:= True;
26477 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26479 Proof_In_Seen
:= True;
26482 Has_Missing
:= True;
26485 Next_Elmt
(Constit_Elmt
);
26489 -- An In_Out constituent is a valid completion
26491 if In_Out_Seen
then
26494 -- A pair of one Input/Proof_In and one Output constituent is a
26495 -- valid completion.
26497 elsif (Input_Seen
or Proof_In_Seen
) and Output_Seen
then
26500 elsif Output_Seen
then
26502 -- A single Output constituent is a valid completion only when
26503 -- some of the other constituents are missing.
26505 if Has_Missing
then
26508 -- Otherwise all constituents are of mode Output
26512 ("global refinement of state & must include at least one "
26513 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
26517 -- The state lacks a completion. When full refinement is visible,
26518 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
26519 -- refinement is visible, emit an error if the abstract state
26520 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
26521 -- both are utilized, Check_State_And_Constituent_Use. will issue
26524 elsif not Input_Seen
26525 and then not In_Out_Seen
26526 and then not Output_Seen
26527 and then not Proof_In_Seen
26529 if Has_Visible_Refinement
(State_Id
)
26530 or else Contains
(Repeat_Items
, State_Id
)
26533 ("missing global refinement of state &", N
, State_Id
);
26536 -- Otherwise the state has a malformed completion where at least
26537 -- one of the constituents has a different mode.
26541 ("global refinement of state & redefines the mode of its "
26542 & "constituents", N
, State_Id
);
26544 end Check_Constituent_Usage
;
26548 Item_Elmt
: Elmt_Id
;
26549 Item_Id
: Entity_Id
;
26551 -- Start of processing for Check_In_Out_States
26554 -- Do not perform this check in an instance because it was already
26555 -- performed successfully in the generic template.
26557 if Is_Generic_Instance
(Spec_Id
) then
26560 -- Inspect the In_Out items of the corresponding Global pragma
26561 -- looking for a state with a visible refinement.
26563 elsif Has_In_Out_State
and then Present
(In_Out_Items
) then
26564 Item_Elmt
:= First_Elmt
(In_Out_Items
);
26565 while Present
(Item_Elmt
) loop
26566 Item_Id
:= Node
(Item_Elmt
);
26568 -- Ensure that one of the three coverage variants is satisfied
26570 if Ekind
(Item_Id
) = E_Abstract_State
26571 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26573 Check_Constituent_Usage
(Item_Id
);
26576 Next_Elmt
(Item_Elmt
);
26579 end Check_In_Out_States
;
26581 ------------------------
26582 -- Check_Input_States --
26583 ------------------------
26585 procedure Check_Input_States
is
26586 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26587 -- Determine whether at least one constituent of state State_Id with
26588 -- full or partial visible refinement is used and has mode Input.
26589 -- Ensure that the remaining constituents do not have In_Out or
26590 -- Output modes. Emit an error if this is not the case
26591 -- (SPARK RM 7.2.4(5)).
26593 -----------------------------
26594 -- Check_Constituent_Usage --
26595 -----------------------------
26597 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26598 Constits
: constant Elist_Id
:=
26599 Partial_Refinement_Constituents
(State_Id
);
26600 Constit_Elmt
: Elmt_Id
;
26601 Constit_Id
: Entity_Id
;
26602 In_Seen
: Boolean := False;
26605 if Present
(Constits
) then
26606 Constit_Elmt
:= First_Elmt
(Constits
);
26607 while Present
(Constit_Elmt
) loop
26608 Constit_Id
:= Node
(Constit_Elmt
);
26610 -- At least one of the constituents appears as an Input
26612 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
26615 -- A Proof_In constituent can refine an Input state as long
26616 -- as there is at least one Input constituent present.
26618 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26622 -- The constituent appears in the global refinement, but has
26623 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
26625 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26626 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
26628 Error_Msg_Name_1
:= Chars
(State_Id
);
26630 ("constituent & of state % must have mode `Input` in "
26631 & "global refinement", N
, Constit_Id
);
26634 Next_Elmt
(Constit_Elmt
);
26638 -- Not one of the constituents appeared as Input. Always emit an
26639 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
26640 -- When only partial refinement is visible, emit an error if the
26641 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26642 -- the case where both are utilized, an error will be issued in
26643 -- Check_State_And_Constituent_Use.
26646 and then (Has_Visible_Refinement
(State_Id
)
26647 or else Contains
(Repeat_Items
, State_Id
))
26650 ("global refinement of state & must include at least one "
26651 & "constituent of mode `Input`", N
, State_Id
);
26653 end Check_Constituent_Usage
;
26657 Item_Elmt
: Elmt_Id
;
26658 Item_Id
: Entity_Id
;
26660 -- Start of processing for Check_Input_States
26663 -- Do not perform this check in an instance because it was already
26664 -- performed successfully in the generic template.
26666 if Is_Generic_Instance
(Spec_Id
) then
26669 -- Inspect the Input items of the corresponding Global pragma looking
26670 -- for a state with a visible refinement.
26672 elsif Has_In_State
and then Present
(In_Items
) then
26673 Item_Elmt
:= First_Elmt
(In_Items
);
26674 while Present
(Item_Elmt
) loop
26675 Item_Id
:= Node
(Item_Elmt
);
26677 -- When full refinement is visible, ensure that at least one of
26678 -- the constituents is utilized and is of mode Input. When only
26679 -- partial refinement is visible, ensure that either one of
26680 -- the constituents is utilized and is of mode Input, or the
26681 -- abstract state is repeated and no constituent is utilized.
26683 if Ekind
(Item_Id
) = E_Abstract_State
26684 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26686 Check_Constituent_Usage
(Item_Id
);
26689 Next_Elmt
(Item_Elmt
);
26692 end Check_Input_States
;
26694 -------------------------
26695 -- Check_Output_States --
26696 -------------------------
26698 procedure Check_Output_States
is
26699 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26700 -- Determine whether all constituents of state State_Id with full
26701 -- visible refinement are used and have mode Output. Emit an error
26702 -- if this is not the case (SPARK RM 7.2.4(5)).
26704 -----------------------------
26705 -- Check_Constituent_Usage --
26706 -----------------------------
26708 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26709 Constits
: constant Elist_Id
:=
26710 Partial_Refinement_Constituents
(State_Id
);
26711 Only_Partial
: constant Boolean :=
26712 not Has_Visible_Refinement
(State_Id
);
26713 Constit_Elmt
: Elmt_Id
;
26714 Constit_Id
: Entity_Id
;
26715 Posted
: Boolean := False;
26718 if Present
(Constits
) then
26719 Constit_Elmt
:= First_Elmt
(Constits
);
26720 while Present
(Constit_Elmt
) loop
26721 Constit_Id
:= Node
(Constit_Elmt
);
26723 -- Issue an error when a constituent of State_Id is utilized
26724 -- and State_Id has only partial visible refinement
26725 -- (SPARK RM 7.2.4(3d)).
26727 if Only_Partial
then
26728 if Present_Then_Remove
(Out_Constits
, Constit_Id
)
26729 or else Present_Then_Remove
(In_Constits
, Constit_Id
)
26731 Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26733 Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26735 Error_Msg_Name_1
:= Chars
(State_Id
);
26737 ("constituent & of state % cannot be used in global "
26738 & "refinement", N
, Constit_Id
);
26739 Error_Msg_Name_1
:= Chars
(State_Id
);
26740 SPARK_Msg_N
("\use state % instead", N
);
26743 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
26746 -- The constituent appears in the global refinement, but has
26747 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
26749 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
26750 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26751 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26753 Error_Msg_Name_1
:= Chars
(State_Id
);
26755 ("constituent & of state % must have mode `Output` in "
26756 & "global refinement", N
, Constit_Id
);
26758 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26764 ("`Output` state & must be replaced by all its "
26765 & "constituents in global refinement", N
, State_Id
);
26769 ("\constituent & is missing in output list",
26773 Next_Elmt
(Constit_Elmt
);
26776 end Check_Constituent_Usage
;
26780 Item_Elmt
: Elmt_Id
;
26781 Item_Id
: Entity_Id
;
26783 -- Start of processing for Check_Output_States
26786 -- Do not perform this check in an instance because it was already
26787 -- performed successfully in the generic template.
26789 if Is_Generic_Instance
(Spec_Id
) then
26792 -- Inspect the Output items of the corresponding Global pragma
26793 -- looking for a state with a visible refinement.
26795 elsif Has_Out_State
and then Present
(Out_Items
) then
26796 Item_Elmt
:= First_Elmt
(Out_Items
);
26797 while Present
(Item_Elmt
) loop
26798 Item_Id
:= Node
(Item_Elmt
);
26800 -- When full refinement is visible, ensure that all of the
26801 -- constituents are utilized and they have mode Output. When
26802 -- only partial refinement is visible, ensure that no
26803 -- constituent is utilized.
26805 if Ekind
(Item_Id
) = E_Abstract_State
26806 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26808 Check_Constituent_Usage
(Item_Id
);
26811 Next_Elmt
(Item_Elmt
);
26814 end Check_Output_States
;
26816 ---------------------------
26817 -- Check_Proof_In_States --
26818 ---------------------------
26820 procedure Check_Proof_In_States
is
26821 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26822 -- Determine whether at least one constituent of state State_Id with
26823 -- full or partial visible refinement is used and has mode Proof_In.
26824 -- Ensure that the remaining constituents do not have Input, In_Out,
26825 -- or Output modes. Emit an error if this is not the case
26826 -- (SPARK RM 7.2.4(5)).
26828 -----------------------------
26829 -- Check_Constituent_Usage --
26830 -----------------------------
26832 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26833 Constits
: constant Elist_Id
:=
26834 Partial_Refinement_Constituents
(State_Id
);
26835 Constit_Elmt
: Elmt_Id
;
26836 Constit_Id
: Entity_Id
;
26837 Proof_In_Seen
: Boolean := False;
26840 if Present
(Constits
) then
26841 Constit_Elmt
:= First_Elmt
(Constits
);
26842 while Present
(Constit_Elmt
) loop
26843 Constit_Id
:= Node
(Constit_Elmt
);
26845 -- At least one of the constituents appears as Proof_In
26847 if Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
26848 Proof_In_Seen
:= True;
26850 -- The constituent appears in the global refinement, but has
26851 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
26853 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
26854 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26855 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
26857 Error_Msg_Name_1
:= Chars
(State_Id
);
26859 ("constituent & of state % must have mode `Proof_In` "
26860 & "in global refinement", N
, Constit_Id
);
26863 Next_Elmt
(Constit_Elmt
);
26867 -- Not one of the constituents appeared as Proof_In. Always emit
26868 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
26869 -- When only partial refinement is visible, emit an error if the
26870 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26871 -- the case where both are utilized, an error will be issued by
26872 -- Check_State_And_Constituent_Use.
26874 if not Proof_In_Seen
26875 and then (Has_Visible_Refinement
(State_Id
)
26876 or else Contains
(Repeat_Items
, State_Id
))
26879 ("global refinement of state & must include at least one "
26880 & "constituent of mode `Proof_In`", N
, State_Id
);
26882 end Check_Constituent_Usage
;
26886 Item_Elmt
: Elmt_Id
;
26887 Item_Id
: Entity_Id
;
26889 -- Start of processing for Check_Proof_In_States
26892 -- Do not perform this check in an instance because it was already
26893 -- performed successfully in the generic template.
26895 if Is_Generic_Instance
(Spec_Id
) then
26898 -- Inspect the Proof_In items of the corresponding Global pragma
26899 -- looking for a state with a visible refinement.
26901 elsif Has_Proof_In_State
and then Present
(Proof_In_Items
) then
26902 Item_Elmt
:= First_Elmt
(Proof_In_Items
);
26903 while Present
(Item_Elmt
) loop
26904 Item_Id
:= Node
(Item_Elmt
);
26906 -- Ensure that at least one of the constituents is utilized
26907 -- and is of mode Proof_In. When only partial refinement is
26908 -- visible, ensure that either one of the constituents is
26909 -- utilized and is of mode Proof_In, or the abstract state
26910 -- is repeated and no constituent is utilized.
26912 if Ekind
(Item_Id
) = E_Abstract_State
26913 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26915 Check_Constituent_Usage
(Item_Id
);
26918 Next_Elmt
(Item_Elmt
);
26921 end Check_Proof_In_States
;
26923 -------------------------------
26924 -- Check_Refined_Global_List --
26925 -------------------------------
26927 procedure Check_Refined_Global_List
26929 Global_Mode
: Name_Id
:= Name_Input
)
26931 procedure Check_Refined_Global_Item
26933 Global_Mode
: Name_Id
);
26934 -- Verify the legality of a single global item declaration. Parameter
26935 -- Global_Mode denotes the current mode in effect.
26937 -------------------------------
26938 -- Check_Refined_Global_Item --
26939 -------------------------------
26941 procedure Check_Refined_Global_Item
26943 Global_Mode
: Name_Id
)
26945 Item_Id
: constant Entity_Id
:= Entity_Of
(Item
);
26947 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
);
26948 -- Issue a common error message for all mode mismatches. Expect
26949 -- denotes the expected mode.
26951 -----------------------------
26952 -- Inconsistent_Mode_Error --
26953 -----------------------------
26955 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
) is
26958 ("global item & has inconsistent modes", Item
, Item_Id
);
26960 Error_Msg_Name_1
:= Global_Mode
;
26961 Error_Msg_Name_2
:= Expect
;
26962 SPARK_Msg_N
("\expected mode %, found mode %", Item
);
26963 end Inconsistent_Mode_Error
;
26967 Enc_State
: Entity_Id
:= Empty
;
26968 -- Encapsulating state for constituent, Empty otherwise
26970 -- Start of processing for Check_Refined_Global_Item
26973 if Ekind_In
(Item_Id
, E_Abstract_State
,
26977 Enc_State
:= Find_Encapsulating_State
(States
, Item_Id
);
26980 -- When the state or object acts as a constituent of another
26981 -- state with a visible refinement, collect it for the state
26982 -- completeness checks performed later on. Note that the item
26983 -- acts as a constituent only when the encapsulating state is
26984 -- present in pragma Global.
26986 if Present
(Enc_State
)
26987 and then (Has_Visible_Refinement
(Enc_State
)
26988 or else Has_Partial_Visible_Refinement
(Enc_State
))
26989 and then Contains
(States
, Enc_State
)
26991 -- If the state has only partial visible refinement, remove it
26992 -- from the list of items that should be repeated from pragma
26995 if not Has_Visible_Refinement
(Enc_State
) then
26996 Present_Then_Remove
(Repeat_Items
, Enc_State
);
26999 if Global_Mode
= Name_Input
then
27000 Append_New_Elmt
(Item_Id
, In_Constits
);
27002 elsif Global_Mode
= Name_In_Out
then
27003 Append_New_Elmt
(Item_Id
, In_Out_Constits
);
27005 elsif Global_Mode
= Name_Output
then
27006 Append_New_Elmt
(Item_Id
, Out_Constits
);
27008 elsif Global_Mode
= Name_Proof_In
then
27009 Append_New_Elmt
(Item_Id
, Proof_In_Constits
);
27012 -- When not a constituent, ensure that both occurrences of the
27013 -- item in pragmas Global and Refined_Global match. Also remove
27014 -- it when present from the list of items that should be repeated
27015 -- from pragma Global.
27018 Present_Then_Remove
(Repeat_Items
, Item_Id
);
27020 if Contains
(In_Items
, Item_Id
) then
27021 if Global_Mode
/= Name_Input
then
27022 Inconsistent_Mode_Error
(Name_Input
);
27025 elsif Contains
(In_Out_Items
, Item_Id
) then
27026 if Global_Mode
/= Name_In_Out
then
27027 Inconsistent_Mode_Error
(Name_In_Out
);
27030 elsif Contains
(Out_Items
, Item_Id
) then
27031 if Global_Mode
/= Name_Output
then
27032 Inconsistent_Mode_Error
(Name_Output
);
27035 elsif Contains
(Proof_In_Items
, Item_Id
) then
27038 -- The item does not appear in the corresponding Global pragma,
27039 -- it must be an extra (SPARK RM 7.2.4(3)).
27042 SPARK_Msg_NE
("extra global item &", Item
, Item_Id
);
27045 end Check_Refined_Global_Item
;
27051 -- Start of processing for Check_Refined_Global_List
27054 -- Do not perform this check in an instance because it was already
27055 -- performed successfully in the generic template.
27057 if Is_Generic_Instance
(Spec_Id
) then
27060 elsif Nkind
(List
) = N_Null
then
27063 -- Single global item declaration
27065 elsif Nkind_In
(List
, N_Expanded_Name
,
27067 N_Selected_Component
)
27069 Check_Refined_Global_Item
(List
, Global_Mode
);
27071 -- Simple global list or moded global list declaration
27073 elsif Nkind
(List
) = N_Aggregate
then
27075 -- The declaration of a simple global list appear as a collection
27078 if Present
(Expressions
(List
)) then
27079 Item
:= First
(Expressions
(List
));
27080 while Present
(Item
) loop
27081 Check_Refined_Global_Item
(Item
, Global_Mode
);
27085 -- The declaration of a moded global list appears as a collection
27086 -- of component associations where individual choices denote
27089 elsif Present
(Component_Associations
(List
)) then
27090 Item
:= First
(Component_Associations
(List
));
27091 while Present
(Item
) loop
27092 Check_Refined_Global_List
27093 (List
=> Expression
(Item
),
27094 Global_Mode
=> Chars
(First
(Choices
(Item
))));
27102 raise Program_Error
;
27108 raise Program_Error
;
27110 end Check_Refined_Global_List
;
27112 --------------------------
27113 -- Collect_Global_Items --
27114 --------------------------
27116 procedure Collect_Global_Items
27118 Mode
: Name_Id
:= Name_Input
)
27120 procedure Collect_Global_Item
27122 Item_Mode
: Name_Id
);
27123 -- Add a single item to the appropriate list. Item_Mode denotes the
27124 -- current mode in effect.
27126 -------------------------
27127 -- Collect_Global_Item --
27128 -------------------------
27130 procedure Collect_Global_Item
27132 Item_Mode
: Name_Id
)
27134 Item_Id
: constant Entity_Id
:= Available_View
(Entity_Of
(Item
));
27135 -- The above handles abstract views of variables and states built
27136 -- for limited with clauses.
27139 -- Signal that the global list contains at least one abstract
27140 -- state with a visible refinement. Note that the refinement may
27141 -- be null in which case there are no constituents.
27143 if Ekind
(Item_Id
) = E_Abstract_State
then
27144 if Has_Null_Visible_Refinement
(Item_Id
) then
27145 Has_Null_State
:= True;
27147 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
27148 Append_New_Elmt
(Item_Id
, States
);
27150 if Item_Mode
= Name_Input
then
27151 Has_In_State
:= True;
27152 elsif Item_Mode
= Name_In_Out
then
27153 Has_In_Out_State
:= True;
27154 elsif Item_Mode
= Name_Output
then
27155 Has_Out_State
:= True;
27156 elsif Item_Mode
= Name_Proof_In
then
27157 Has_Proof_In_State
:= True;
27162 -- Record global items without full visible refinement found in
27163 -- pragma Global which should be repeated in the global refinement
27164 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
27166 if Ekind
(Item_Id
) /= E_Abstract_State
27167 or else not Has_Visible_Refinement
(Item_Id
)
27169 Append_New_Elmt
(Item_Id
, Repeat_Items
);
27172 -- Add the item to the proper list
27174 if Item_Mode
= Name_Input
then
27175 Append_New_Elmt
(Item_Id
, In_Items
);
27176 elsif Item_Mode
= Name_In_Out
then
27177 Append_New_Elmt
(Item_Id
, In_Out_Items
);
27178 elsif Item_Mode
= Name_Output
then
27179 Append_New_Elmt
(Item_Id
, Out_Items
);
27180 elsif Item_Mode
= Name_Proof_In
then
27181 Append_New_Elmt
(Item_Id
, Proof_In_Items
);
27183 end Collect_Global_Item
;
27189 -- Start of processing for Collect_Global_Items
27192 if Nkind
(List
) = N_Null
then
27195 -- Single global item declaration
27197 elsif Nkind_In
(List
, N_Expanded_Name
,
27199 N_Selected_Component
)
27201 Collect_Global_Item
(List
, Mode
);
27203 -- Single global list or moded global list declaration
27205 elsif Nkind
(List
) = N_Aggregate
then
27207 -- The declaration of a simple global list appear as a collection
27210 if Present
(Expressions
(List
)) then
27211 Item
:= First
(Expressions
(List
));
27212 while Present
(Item
) loop
27213 Collect_Global_Item
(Item
, Mode
);
27217 -- The declaration of a moded global list appears as a collection
27218 -- of component associations where individual choices denote mode.
27220 elsif Present
(Component_Associations
(List
)) then
27221 Item
:= First
(Component_Associations
(List
));
27222 while Present
(Item
) loop
27223 Collect_Global_Items
27224 (List
=> Expression
(Item
),
27225 Mode
=> Chars
(First
(Choices
(Item
))));
27233 raise Program_Error
;
27236 -- To accommodate partial decoration of disabled SPARK features, this
27237 -- routine may be called with illegal input. If this is the case, do
27238 -- not raise Program_Error.
27243 end Collect_Global_Items
;
27245 -------------------------
27246 -- Present_Then_Remove --
27247 -------------------------
27249 function Present_Then_Remove
27251 Item
: Entity_Id
) return Boolean
27256 if Present
(List
) then
27257 Elmt
:= First_Elmt
(List
);
27258 while Present
(Elmt
) loop
27259 if Node
(Elmt
) = Item
then
27260 Remove_Elmt
(List
, Elmt
);
27269 end Present_Then_Remove
;
27271 procedure Present_Then_Remove
(List
: Elist_Id
; Item
: Entity_Id
) is
27274 Ignore
:= Present_Then_Remove
(List
, Item
);
27275 end Present_Then_Remove
;
27277 -------------------------------
27278 -- Report_Extra_Constituents --
27279 -------------------------------
27281 procedure Report_Extra_Constituents
is
27282 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
);
27283 -- Emit an error for every element of List
27285 ---------------------------------------
27286 -- Report_Extra_Constituents_In_List --
27287 ---------------------------------------
27289 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
) is
27290 Constit_Elmt
: Elmt_Id
;
27293 if Present
(List
) then
27294 Constit_Elmt
:= First_Elmt
(List
);
27295 while Present
(Constit_Elmt
) loop
27296 SPARK_Msg_NE
("extra constituent &", N
, Node
(Constit_Elmt
));
27297 Next_Elmt
(Constit_Elmt
);
27300 end Report_Extra_Constituents_In_List
;
27302 -- Start of processing for Report_Extra_Constituents
27305 -- Do not perform this check in an instance because it was already
27306 -- performed successfully in the generic template.
27308 if Is_Generic_Instance
(Spec_Id
) then
27312 Report_Extra_Constituents_In_List
(In_Constits
);
27313 Report_Extra_Constituents_In_List
(In_Out_Constits
);
27314 Report_Extra_Constituents_In_List
(Out_Constits
);
27315 Report_Extra_Constituents_In_List
(Proof_In_Constits
);
27317 end Report_Extra_Constituents
;
27319 --------------------------
27320 -- Report_Missing_Items --
27321 --------------------------
27323 procedure Report_Missing_Items
is
27324 Item_Elmt
: Elmt_Id
;
27325 Item_Id
: Entity_Id
;
27328 -- Do not perform this check in an instance because it was already
27329 -- performed successfully in the generic template.
27331 if Is_Generic_Instance
(Spec_Id
) then
27335 if Present
(Repeat_Items
) then
27336 Item_Elmt
:= First_Elmt
(Repeat_Items
);
27337 while Present
(Item_Elmt
) loop
27338 Item_Id
:= Node
(Item_Elmt
);
27339 SPARK_Msg_NE
("missing global item &", N
, Item_Id
);
27340 Next_Elmt
(Item_Elmt
);
27344 end Report_Missing_Items
;
27348 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
27349 Errors
: constant Nat
:= Serious_Errors_Detected
;
27351 No_Constit
: Boolean;
27353 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
27356 -- Do not analyze the pragma multiple times
27358 if Is_Analyzed_Pragma
(N
) then
27362 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
27364 -- Use the anonymous object as the proper spec when Refined_Global
27365 -- applies to the body of a single task type. The object carries the
27366 -- proper Chars as well as all non-refined versions of pragmas.
27368 if Is_Single_Concurrent_Type
(Spec_Id
) then
27369 Spec_Id
:= Anonymous_Object
(Spec_Id
);
27372 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
27373 Items
:= Expression
(Get_Argument
(N
, Spec_Id
));
27375 -- The subprogram declaration lacks pragma Global. This renders
27376 -- Refined_Global useless as there is nothing to refine.
27378 if No
(Global
) then
27380 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
27381 & "& lacks aspect or pragma Global"), N
, Spec_Id
);
27385 -- Extract all relevant items from the corresponding Global pragma
27387 Collect_Global_Items
(Expression
(Get_Argument
(Global
, Spec_Id
)));
27389 -- Package and subprogram bodies are instantiated individually in
27390 -- a separate compiler pass. Due to this mode of instantiation, the
27391 -- refinement of a state may no longer be visible when a subprogram
27392 -- body contract is instantiated. Since the generic template is legal,
27393 -- do not perform this check in the instance to circumvent this oddity.
27395 if Is_Generic_Instance
(Spec_Id
) then
27398 -- Non-instance case
27401 -- The corresponding Global pragma must mention at least one
27402 -- state with a visible refinement at the point Refined_Global
27403 -- is processed. States with null refinements need Refined_Global
27404 -- pragma (SPARK RM 7.2.4(2)).
27406 if not Has_In_State
27407 and then not Has_In_Out_State
27408 and then not Has_Out_State
27409 and then not Has_Proof_In_State
27410 and then not Has_Null_State
27413 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
27414 & "depend on abstract state with visible refinement"),
27418 -- The global refinement of inputs and outputs cannot be null when
27419 -- the corresponding Global pragma contains at least one item except
27420 -- in the case where we have states with null refinements.
27422 elsif Nkind
(Items
) = N_Null
27424 (Present
(In_Items
)
27425 or else Present
(In_Out_Items
)
27426 or else Present
(Out_Items
)
27427 or else Present
(Proof_In_Items
))
27428 and then not Has_Null_State
27431 (Fix_Msg
(Spec_Id
, "refinement cannot be null, subprogram & has "
27432 & "global items"), N
, Spec_Id
);
27437 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
27438 -- This ensures that the categorization of all refined global items is
27439 -- consistent with their role.
27441 Analyze_Global_In_Decl_Part
(N
);
27443 -- Perform all refinement checks with respect to completeness and mode
27446 if Serious_Errors_Detected
= Errors
then
27447 Check_Refined_Global_List
(Items
);
27450 -- Store the information that no constituent is used in the global
27451 -- refinement, prior to calling checking procedures which remove items
27452 -- from the list of constituents.
27456 and then No
(In_Out_Constits
)
27457 and then No
(Out_Constits
)
27458 and then No
(Proof_In_Constits
);
27460 -- For Input states with visible refinement, at least one constituent
27461 -- must be used as an Input in the global refinement.
27463 if Serious_Errors_Detected
= Errors
then
27464 Check_Input_States
;
27467 -- Verify all possible completion variants for In_Out states with
27468 -- visible refinement.
27470 if Serious_Errors_Detected
= Errors
then
27471 Check_In_Out_States
;
27474 -- For Output states with visible refinement, all constituents must be
27475 -- used as Outputs in the global refinement.
27477 if Serious_Errors_Detected
= Errors
then
27478 Check_Output_States
;
27481 -- For Proof_In states with visible refinement, at least one constituent
27482 -- must be used as Proof_In in the global refinement.
27484 if Serious_Errors_Detected
= Errors
then
27485 Check_Proof_In_States
;
27488 -- Emit errors for all constituents that belong to other states with
27489 -- visible refinement that do not appear in Global.
27491 if Serious_Errors_Detected
= Errors
then
27492 Report_Extra_Constituents
;
27495 -- Emit errors for all items in Global that are not repeated in the
27496 -- global refinement and for which there is no full visible refinement
27497 -- and, in the case of states with partial visible refinement, no
27498 -- constituent is mentioned in the global refinement.
27500 if Serious_Errors_Detected
= Errors
then
27501 Report_Missing_Items
;
27504 -- Emit an error if no constituent is used in the global refinement
27505 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
27506 -- one may be issued by the checking procedures. Do not perform this
27507 -- check in an instance because it was already performed successfully
27508 -- in the generic template.
27510 if Serious_Errors_Detected
= Errors
27511 and then not Is_Generic_Instance
(Spec_Id
)
27512 and then not Has_Null_State
27513 and then No_Constit
27515 SPARK_Msg_N
("missing refinement", N
);
27519 Set_Is_Analyzed_Pragma
(N
);
27520 end Analyze_Refined_Global_In_Decl_Part
;
27522 ----------------------------------------
27523 -- Analyze_Refined_State_In_Decl_Part --
27524 ----------------------------------------
27526 procedure Analyze_Refined_State_In_Decl_Part
27528 Freeze_Id
: Entity_Id
:= Empty
)
27530 Body_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
27531 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
27532 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(Body_Decl
);
27534 Available_States
: Elist_Id
:= No_Elist
;
27535 -- A list of all abstract states defined in the package declaration that
27536 -- are available for refinement. The list is used to report unrefined
27539 Body_States
: Elist_Id
:= No_Elist
;
27540 -- A list of all hidden states that appear in the body of the related
27541 -- package. The list is used to report unused hidden states.
27543 Constituents_Seen
: Elist_Id
:= No_Elist
;
27544 -- A list that contains all constituents processed so far. The list is
27545 -- used to detect multiple uses of the same constituent.
27547 Freeze_Posted
: Boolean := False;
27548 -- A flag that controls the output of a freezing-related error (see use
27551 Refined_States_Seen
: Elist_Id
:= No_Elist
;
27552 -- A list that contains all refined states processed so far. The list is
27553 -- used to detect duplicate refinements.
27555 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
);
27556 -- Perform full analysis of a single refinement clause
27558 procedure Report_Unrefined_States
(States
: Elist_Id
);
27559 -- Emit errors for all unrefined abstract states found in list States
27561 -------------------------------
27562 -- Analyze_Refinement_Clause --
27563 -------------------------------
27565 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
) is
27566 AR_Constit
: Entity_Id
:= Empty
;
27567 AW_Constit
: Entity_Id
:= Empty
;
27568 ER_Constit
: Entity_Id
:= Empty
;
27569 EW_Constit
: Entity_Id
:= Empty
;
27570 -- The entities of external constituents that contain one of the
27571 -- following enabled properties: Async_Readers, Async_Writers,
27572 -- Effective_Reads and Effective_Writes.
27574 External_Constit_Seen
: Boolean := False;
27575 -- Flag used to mark when at least one external constituent is part
27576 -- of the state refinement.
27578 Non_Null_Seen
: Boolean := False;
27579 Null_Seen
: Boolean := False;
27580 -- Flags used to detect multiple uses of null in a single clause or a
27581 -- mixture of null and non-null constituents.
27583 Part_Of_Constits
: Elist_Id
:= No_Elist
;
27584 -- A list of all candidate constituents subject to indicator Part_Of
27585 -- where the encapsulating state is the current state.
27588 State_Id
: Entity_Id
;
27589 -- The current state being refined
27591 procedure Analyze_Constituent
(Constit
: Node_Id
);
27592 -- Perform full analysis of a single constituent
27594 procedure Check_External_Property
27595 (Prop_Nam
: Name_Id
;
27597 Constit
: Entity_Id
);
27598 -- Determine whether a property denoted by name Prop_Nam is present
27599 -- in the refined state. Emit an error if this is not the case. Flag
27600 -- Enabled should be set when the property applies to the refined
27601 -- state. Constit denotes the constituent (if any) which introduces
27602 -- the property in the refinement.
27604 procedure Match_State
;
27605 -- Determine whether the state being refined appears in list
27606 -- Available_States. Emit an error when attempting to re-refine the
27607 -- state or when the state is not defined in the package declaration,
27608 -- otherwise remove the state from Available_States.
27610 procedure Report_Unused_Constituents
(Constits
: Elist_Id
);
27611 -- Emit errors for all unused Part_Of constituents in list Constits
27613 -------------------------
27614 -- Analyze_Constituent --
27615 -------------------------
27617 procedure Analyze_Constituent
(Constit
: Node_Id
) is
27618 procedure Match_Constituent
(Constit_Id
: Entity_Id
);
27619 -- Determine whether constituent Constit denoted by its entity
27620 -- Constit_Id appears in Body_States. Emit an error when the
27621 -- constituent is not a valid hidden state of the related package
27622 -- or when it is used more than once. Otherwise remove the
27623 -- constituent from Body_States.
27625 -----------------------
27626 -- Match_Constituent --
27627 -----------------------
27629 procedure Match_Constituent
(Constit_Id
: Entity_Id
) is
27630 procedure Collect_Constituent
;
27631 -- Verify the legality of constituent Constit_Id and add it to
27632 -- the refinements of State_Id.
27634 -------------------------
27635 -- Collect_Constituent --
27636 -------------------------
27638 procedure Collect_Constituent
is
27639 Constits
: Elist_Id
;
27642 -- The Ghost policy in effect at the point of abstract state
27643 -- declaration and constituent must match (SPARK RM 6.9(15))
27645 Check_Ghost_Refinement
27646 (State
, State_Id
, Constit
, Constit_Id
);
27648 -- A synchronized state must be refined by a synchronized
27649 -- object or another synchronized state (SPARK RM 9.6).
27651 if Is_Synchronized_State
(State_Id
)
27652 and then not Is_Synchronized_Object
(Constit_Id
)
27653 and then not Is_Synchronized_State
(Constit_Id
)
27656 ("constituent of synchronized state & must be "
27657 & "synchronized", Constit
, State_Id
);
27660 -- Add the constituent to the list of processed items to aid
27661 -- with the detection of duplicates.
27663 Append_New_Elmt
(Constit_Id
, Constituents_Seen
);
27665 -- Collect the constituent in the list of refinement items
27666 -- and establish a relation between the refined state and
27669 Constits
:= Refinement_Constituents
(State_Id
);
27671 if No
(Constits
) then
27672 Constits
:= New_Elmt_List
;
27673 Set_Refinement_Constituents
(State_Id
, Constits
);
27676 Append_Elmt
(Constit_Id
, Constits
);
27677 Set_Encapsulating_State
(Constit_Id
, State_Id
);
27679 -- The state has at least one legal constituent, mark the
27680 -- start of the refinement region. The region ends when the
27681 -- body declarations end (see routine Analyze_Declarations).
27683 Set_Has_Visible_Refinement
(State_Id
);
27685 -- When the constituent is external, save its relevant
27686 -- property for further checks.
27688 if Async_Readers_Enabled
(Constit_Id
) then
27689 AR_Constit
:= Constit_Id
;
27690 External_Constit_Seen
:= True;
27693 if Async_Writers_Enabled
(Constit_Id
) then
27694 AW_Constit
:= Constit_Id
;
27695 External_Constit_Seen
:= True;
27698 if Effective_Reads_Enabled
(Constit_Id
) then
27699 ER_Constit
:= Constit_Id
;
27700 External_Constit_Seen
:= True;
27703 if Effective_Writes_Enabled
(Constit_Id
) then
27704 EW_Constit
:= Constit_Id
;
27705 External_Constit_Seen
:= True;
27707 end Collect_Constituent
;
27711 State_Elmt
: Elmt_Id
;
27713 -- Start of processing for Match_Constituent
27716 -- Detect a duplicate use of a constituent
27718 if Contains
(Constituents_Seen
, Constit_Id
) then
27720 ("duplicate use of constituent &", Constit
, Constit_Id
);
27724 -- The constituent is subject to a Part_Of indicator
27726 if Present
(Encapsulating_State
(Constit_Id
)) then
27727 if Encapsulating_State
(Constit_Id
) = State_Id
then
27728 Remove
(Part_Of_Constits
, Constit_Id
);
27729 Collect_Constituent
;
27731 -- The constituent is part of another state and is used
27732 -- incorrectly in the refinement of the current state.
27735 Error_Msg_Name_1
:= Chars
(State_Id
);
27737 ("& cannot act as constituent of state %",
27738 Constit
, Constit_Id
);
27740 ("\Part_Of indicator specifies encapsulator &",
27741 Constit
, Encapsulating_State
(Constit_Id
));
27744 -- The only other source of legal constituents is the body
27745 -- state space of the related package.
27748 if Present
(Body_States
) then
27749 State_Elmt
:= First_Elmt
(Body_States
);
27750 while Present
(State_Elmt
) loop
27752 -- Consume a valid constituent to signal that it has
27753 -- been encountered.
27755 if Node
(State_Elmt
) = Constit_Id
then
27756 Remove_Elmt
(Body_States
, State_Elmt
);
27757 Collect_Constituent
;
27761 Next_Elmt
(State_Elmt
);
27765 -- At this point it is known that the constituent is not
27766 -- part of the package hidden state and cannot be used in
27767 -- a refinement (SPARK RM 7.2.2(9)).
27769 Error_Msg_Name_1
:= Chars
(Spec_Id
);
27771 ("cannot use & in refinement, constituent is not a hidden "
27772 & "state of package %", Constit
, Constit_Id
);
27774 end Match_Constituent
;
27778 Constit_Id
: Entity_Id
;
27779 Constits
: Elist_Id
;
27781 -- Start of processing for Analyze_Constituent
27784 -- Detect multiple uses of null in a single refinement clause or a
27785 -- mixture of null and non-null constituents.
27787 if Nkind
(Constit
) = N_Null
then
27790 ("multiple null constituents not allowed", Constit
);
27792 elsif Non_Null_Seen
then
27794 ("cannot mix null and non-null constituents", Constit
);
27799 -- Collect the constituent in the list of refinement items
27801 Constits
:= Refinement_Constituents
(State_Id
);
27803 if No
(Constits
) then
27804 Constits
:= New_Elmt_List
;
27805 Set_Refinement_Constituents
(State_Id
, Constits
);
27808 Append_Elmt
(Constit
, Constits
);
27810 -- The state has at least one legal constituent, mark the
27811 -- start of the refinement region. The region ends when the
27812 -- body declarations end (see Analyze_Declarations).
27814 Set_Has_Visible_Refinement
(State_Id
);
27817 -- Non-null constituents
27820 Non_Null_Seen
:= True;
27824 ("cannot mix null and non-null constituents", Constit
);
27828 Resolve_State
(Constit
);
27830 -- Ensure that the constituent denotes a valid state or a
27831 -- whole object (SPARK RM 7.2.2(5)).
27833 if Is_Entity_Name
(Constit
) then
27834 Constit_Id
:= Entity_Of
(Constit
);
27836 -- When a constituent is declared after a subprogram body
27837 -- that caused freezing of the related contract where
27838 -- pragma Refined_State resides, the constituent appears
27839 -- undefined and carries Any_Id as its entity.
27841 -- package body Pack
27842 -- with Refined_State => (State => Constit)
27845 -- with Refined_Global => (Input => Constit)
27853 if Constit_Id
= Any_Id
then
27854 SPARK_Msg_NE
("& is undefined", Constit
, Constit_Id
);
27856 -- Emit a specialized info message when the contract of
27857 -- the related package body was "frozen" by another body.
27858 -- Note that it is not possible to precisely identify why
27859 -- the constituent is undefined because it is not visible
27860 -- when pragma Refined_State is analyzed. This message is
27861 -- a reasonable approximation.
27863 if Present
(Freeze_Id
) and then not Freeze_Posted
then
27864 Freeze_Posted
:= True;
27866 Error_Msg_Name_1
:= Chars
(Body_Id
);
27867 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
27869 ("body & declared # freezes the contract of %",
27872 ("\all constituents must be declared before body #",
27875 -- A misplaced constituent is a critical error because
27876 -- pragma Refined_Depends or Refined_Global depends on
27877 -- the proper link between a state and a constituent.
27878 -- Stop the compilation, as this leads to a multitude
27879 -- of misleading cascaded errors.
27881 raise Unrecoverable_Error
;
27884 -- The constituent is a valid state or object
27886 elsif Ekind_In
(Constit_Id
, E_Abstract_State
,
27890 Match_Constituent
(Constit_Id
);
27892 -- The variable may eventually become a constituent of a
27893 -- single protected/task type. Record the reference now
27894 -- and verify its legality when analyzing the contract of
27895 -- the variable (SPARK RM 9.3).
27897 if Ekind
(Constit_Id
) = E_Variable
then
27898 Record_Possible_Part_Of_Reference
27899 (Var_Id
=> Constit_Id
,
27903 -- Otherwise the constituent is illegal
27907 ("constituent & must denote object or state",
27908 Constit
, Constit_Id
);
27911 -- The constituent is illegal
27914 SPARK_Msg_N
("malformed constituent", Constit
);
27917 end Analyze_Constituent
;
27919 -----------------------------
27920 -- Check_External_Property --
27921 -----------------------------
27923 procedure Check_External_Property
27924 (Prop_Nam
: Name_Id
;
27926 Constit
: Entity_Id
)
27929 -- The property is missing in the declaration of the state, but
27930 -- a constituent is introducing it in the state refinement
27931 -- (SPARK RM 7.2.8(2)).
27933 if not Enabled
and then Present
(Constit
) then
27934 Error_Msg_Name_1
:= Prop_Nam
;
27935 Error_Msg_Name_2
:= Chars
(State_Id
);
27937 ("constituent & introduces external property % in refinement "
27938 & "of state %", State
, Constit
);
27940 Error_Msg_Sloc
:= Sloc
(State_Id
);
27942 ("\property is missing in abstract state declaration #",
27945 end Check_External_Property
;
27951 procedure Match_State
is
27952 State_Elmt
: Elmt_Id
;
27955 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
27957 if Contains
(Refined_States_Seen
, State_Id
) then
27959 ("duplicate refinement of state &", State
, State_Id
);
27963 -- Inspect the abstract states defined in the package declaration
27964 -- looking for a match.
27966 State_Elmt
:= First_Elmt
(Available_States
);
27967 while Present
(State_Elmt
) loop
27969 -- A valid abstract state is being refined in the body. Add
27970 -- the state to the list of processed refined states to aid
27971 -- with the detection of duplicate refinements. Remove the
27972 -- state from Available_States to signal that it has already
27975 if Node
(State_Elmt
) = State_Id
then
27976 Append_New_Elmt
(State_Id
, Refined_States_Seen
);
27977 Remove_Elmt
(Available_States
, State_Elmt
);
27981 Next_Elmt
(State_Elmt
);
27984 -- If we get here, we are refining a state that is not defined in
27985 -- the package declaration.
27987 Error_Msg_Name_1
:= Chars
(Spec_Id
);
27989 ("cannot refine state, & is not defined in package %",
27993 --------------------------------
27994 -- Report_Unused_Constituents --
27995 --------------------------------
27997 procedure Report_Unused_Constituents
(Constits
: Elist_Id
) is
27998 Constit_Elmt
: Elmt_Id
;
27999 Constit_Id
: Entity_Id
;
28000 Posted
: Boolean := False;
28003 if Present
(Constits
) then
28004 Constit_Elmt
:= First_Elmt
(Constits
);
28005 while Present
(Constit_Elmt
) loop
28006 Constit_Id
:= Node
(Constit_Elmt
);
28008 -- Generate an error message of the form:
28010 -- state ... has unused Part_Of constituents
28011 -- abstract state ... defined at ...
28012 -- constant ... defined at ...
28013 -- variable ... defined at ...
28018 ("state & has unused Part_Of constituents",
28022 Error_Msg_Sloc
:= Sloc
(Constit_Id
);
28024 if Ekind
(Constit_Id
) = E_Abstract_State
then
28026 ("\abstract state & defined #", State
, Constit_Id
);
28028 elsif Ekind
(Constit_Id
) = E_Constant
then
28030 ("\constant & defined #", State
, Constit_Id
);
28033 pragma Assert
(Ekind
(Constit_Id
) = E_Variable
);
28034 SPARK_Msg_NE
("\variable & defined #", State
, Constit_Id
);
28037 Next_Elmt
(Constit_Elmt
);
28040 end Report_Unused_Constituents
;
28042 -- Local declarations
28044 Body_Ref
: Node_Id
;
28045 Body_Ref_Elmt
: Elmt_Id
;
28047 Extra_State
: Node_Id
;
28049 -- Start of processing for Analyze_Refinement_Clause
28052 -- A refinement clause appears as a component association where the
28053 -- sole choice is the state and the expressions are the constituents.
28054 -- This is a syntax error, always report.
28056 if Nkind
(Clause
) /= N_Component_Association
then
28057 Error_Msg_N
("malformed state refinement clause", Clause
);
28061 -- Analyze the state name of a refinement clause
28063 State
:= First
(Choices
(Clause
));
28066 Resolve_State
(State
);
28068 -- Ensure that the state name denotes a valid abstract state that is
28069 -- defined in the spec of the related package.
28071 if Is_Entity_Name
(State
) then
28072 State_Id
:= Entity_Of
(State
);
28074 -- When the abstract state is undefined, it appears as Any_Id. Do
28075 -- not continue with the analysis of the clause.
28077 if State_Id
= Any_Id
then
28080 -- Catch any attempts to re-refine a state or refine a state that
28081 -- is not defined in the package declaration.
28083 elsif Ekind
(State_Id
) = E_Abstract_State
then
28087 SPARK_Msg_NE
("& must denote abstract state", State
, State_Id
);
28091 -- References to a state with visible refinement are illegal.
28092 -- When nested packages are involved, detecting such references is
28093 -- tricky because pragma Refined_State is analyzed later than the
28094 -- offending pragma Depends or Global. References that occur in
28095 -- such nested context are stored in a list. Emit errors for all
28096 -- references found in Body_References (SPARK RM 6.1.4(8)).
28098 if Present
(Body_References
(State_Id
)) then
28099 Body_Ref_Elmt
:= First_Elmt
(Body_References
(State_Id
));
28100 while Present
(Body_Ref_Elmt
) loop
28101 Body_Ref
:= Node
(Body_Ref_Elmt
);
28103 SPARK_Msg_N
("reference to & not allowed", Body_Ref
);
28104 Error_Msg_Sloc
:= Sloc
(State
);
28105 SPARK_Msg_N
("\refinement of & is visible#", Body_Ref
);
28107 Next_Elmt
(Body_Ref_Elmt
);
28111 -- The state name is illegal. This is a syntax error, always report.
28114 Error_Msg_N
("malformed state name in refinement clause", State
);
28118 -- A refinement clause may only refine one state at a time
28120 Extra_State
:= Next
(State
);
28122 if Present
(Extra_State
) then
28124 ("refinement clause cannot cover multiple states", Extra_State
);
28127 -- Replicate the Part_Of constituents of the refined state because
28128 -- the algorithm will consume items.
28130 Part_Of_Constits
:= New_Copy_Elist
(Part_Of_Constituents
(State_Id
));
28132 -- Analyze all constituents of the refinement. Multiple constituents
28133 -- appear as an aggregate.
28135 Constit
:= Expression
(Clause
);
28137 if Nkind
(Constit
) = N_Aggregate
then
28138 if Present
(Component_Associations
(Constit
)) then
28140 ("constituents of refinement clause must appear in "
28141 & "positional form", Constit
);
28143 else pragma Assert
(Present
(Expressions
(Constit
)));
28144 Constit
:= First
(Expressions
(Constit
));
28145 while Present
(Constit
) loop
28146 Analyze_Constituent
(Constit
);
28151 -- Various forms of a single constituent. Note that these may include
28152 -- malformed constituents.
28155 Analyze_Constituent
(Constit
);
28158 -- Verify that external constituents do not introduce new external
28159 -- property in the state refinement (SPARK RM 7.2.8(2)).
28161 if Is_External_State
(State_Id
) then
28162 Check_External_Property
28163 (Prop_Nam
=> Name_Async_Readers
,
28164 Enabled
=> Async_Readers_Enabled
(State_Id
),
28165 Constit
=> AR_Constit
);
28167 Check_External_Property
28168 (Prop_Nam
=> Name_Async_Writers
,
28169 Enabled
=> Async_Writers_Enabled
(State_Id
),
28170 Constit
=> AW_Constit
);
28172 Check_External_Property
28173 (Prop_Nam
=> Name_Effective_Reads
,
28174 Enabled
=> Effective_Reads_Enabled
(State_Id
),
28175 Constit
=> ER_Constit
);
28177 Check_External_Property
28178 (Prop_Nam
=> Name_Effective_Writes
,
28179 Enabled
=> Effective_Writes_Enabled
(State_Id
),
28180 Constit
=> EW_Constit
);
28182 -- When a refined state is not external, it should not have external
28183 -- constituents (SPARK RM 7.2.8(1)).
28185 elsif External_Constit_Seen
then
28187 ("non-external state & cannot contain external constituents in "
28188 & "refinement", State
, State_Id
);
28191 -- Ensure that all Part_Of candidate constituents have been mentioned
28192 -- in the refinement clause.
28194 Report_Unused_Constituents
(Part_Of_Constits
);
28195 end Analyze_Refinement_Clause
;
28197 -----------------------------
28198 -- Report_Unrefined_States --
28199 -----------------------------
28201 procedure Report_Unrefined_States
(States
: Elist_Id
) is
28202 State_Elmt
: Elmt_Id
;
28205 if Present
(States
) then
28206 State_Elmt
:= First_Elmt
(States
);
28207 while Present
(State_Elmt
) loop
28209 ("abstract state & must be refined", Node
(State_Elmt
));
28211 Next_Elmt
(State_Elmt
);
28214 end Report_Unrefined_States
;
28216 -- Local declarations
28218 Clauses
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
28221 -- Start of processing for Analyze_Refined_State_In_Decl_Part
28224 -- Do not analyze the pragma multiple times
28226 if Is_Analyzed_Pragma
(N
) then
28230 -- Save the scenario for examination by the ABE Processing phase
28232 Record_Elaboration_Scenario
(N
);
28234 -- Replicate the abstract states declared by the package because the
28235 -- matching algorithm will consume states.
28237 Available_States
:= New_Copy_Elist
(Abstract_States
(Spec_Id
));
28239 -- Gather all abstract states and objects declared in the visible
28240 -- state space of the package body. These items must be utilized as
28241 -- constituents in a state refinement.
28243 Body_States
:= Collect_Body_States
(Body_Id
);
28245 -- Multiple non-null state refinements appear as an aggregate
28247 if Nkind
(Clauses
) = N_Aggregate
then
28248 if Present
(Expressions
(Clauses
)) then
28250 ("state refinements must appear as component associations",
28253 else pragma Assert
(Present
(Component_Associations
(Clauses
)));
28254 Clause
:= First
(Component_Associations
(Clauses
));
28255 while Present
(Clause
) loop
28256 Analyze_Refinement_Clause
(Clause
);
28261 -- Various forms of a single state refinement. Note that these may
28262 -- include malformed refinements.
28265 Analyze_Refinement_Clause
(Clauses
);
28268 -- List all abstract states that were left unrefined
28270 Report_Unrefined_States
(Available_States
);
28272 Set_Is_Analyzed_Pragma
(N
);
28273 end Analyze_Refined_State_In_Decl_Part
;
28275 ------------------------------------
28276 -- Analyze_Test_Case_In_Decl_Part --
28277 ------------------------------------
28279 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
) is
28280 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
28281 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
28283 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
);
28284 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
28285 -- denoted by Arg_Nam.
28287 ------------------------------
28288 -- Preanalyze_Test_Case_Arg --
28289 ------------------------------
28291 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
) is
28295 -- Preanalyze the original aspect argument for ASIS or for a generic
28296 -- subprogram to properly capture global references.
28298 if ASIS_Mode
or else Is_Generic_Subprogram
(Spec_Id
) then
28302 Arg_Nam
=> Arg_Nam
,
28303 From_Aspect
=> True);
28305 if Present
(Arg
) then
28306 Preanalyze_Assert_Expression
28307 (Expression
(Arg
), Standard_Boolean
);
28311 Arg
:= Test_Case_Arg
(N
, Arg_Nam
);
28313 if Present
(Arg
) then
28314 Preanalyze_Assert_Expression
(Expression
(Arg
), Standard_Boolean
);
28316 end Preanalyze_Test_Case_Arg
;
28320 Restore_Scope
: Boolean := False;
28322 -- Start of processing for Analyze_Test_Case_In_Decl_Part
28325 -- Do not analyze the pragma multiple times
28327 if Is_Analyzed_Pragma
(N
) then
28331 -- Ensure that the formal parameters are visible when analyzing all
28332 -- clauses. This falls out of the general rule of aspects pertaining
28333 -- to subprogram declarations.
28335 if not In_Open_Scopes
(Spec_Id
) then
28336 Restore_Scope
:= True;
28337 Push_Scope
(Spec_Id
);
28339 if Is_Generic_Subprogram
(Spec_Id
) then
28340 Install_Generic_Formals
(Spec_Id
);
28342 Install_Formals
(Spec_Id
);
28346 Preanalyze_Test_Case_Arg
(Name_Requires
);
28347 Preanalyze_Test_Case_Arg
(Name_Ensures
);
28349 if Restore_Scope
then
28353 -- Currently it is not possible to inline pre/postconditions on a
28354 -- subprogram subject to pragma Inline_Always.
28356 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
28358 Set_Is_Analyzed_Pragma
(N
);
28359 end Analyze_Test_Case_In_Decl_Part
;
28365 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean is
28370 if Present
(List
) then
28371 Elmt
:= First_Elmt
(List
);
28372 while Present
(Elmt
) loop
28373 if Nkind
(Node
(Elmt
)) = N_Defining_Identifier
then
28376 Id
:= Entity_Of
(Node
(Elmt
));
28379 if Id
= Item_Id
then
28390 -----------------------------------
28391 -- Build_Pragma_Check_Equivalent --
28392 -----------------------------------
28394 function Build_Pragma_Check_Equivalent
28396 Subp_Id
: Entity_Id
:= Empty
;
28397 Inher_Id
: Entity_Id
:= Empty
;
28398 Keep_Pragma_Id
: Boolean := False) return Node_Id
28400 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
;
28401 -- Detect whether node N references a formal parameter subject to
28402 -- pragma Unreferenced. If this is the case, set Comes_From_Source
28403 -- to False to suppress the generation of a reference when analyzing
28406 ------------------------
28407 -- Suppress_Reference --
28408 ------------------------
28410 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
is
28411 Formal
: Entity_Id
;
28414 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
28415 Formal
:= Entity
(N
);
28417 -- The formal parameter is subject to pragma Unreferenced. Prevent
28418 -- the generation of references by resetting the Comes_From_Source
28421 if Is_Formal
(Formal
)
28422 and then Has_Pragma_Unreferenced
(Formal
)
28424 Set_Comes_From_Source
(N
, False);
28429 end Suppress_Reference
;
28431 procedure Suppress_References
is
28432 new Traverse_Proc
(Suppress_Reference
);
28436 Loc
: constant Source_Ptr
:= Sloc
(Prag
);
28437 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
28438 Check_Prag
: Node_Id
;
28442 Needs_Wrapper
: Boolean;
28443 pragma Unreferenced
(Needs_Wrapper
);
28445 -- Start of processing for Build_Pragma_Check_Equivalent
28448 -- When the pre- or postcondition is inherited, map the formals of the
28449 -- inherited subprogram to those of the current subprogram. In addition,
28450 -- map primitive operations of the parent type into the corresponding
28451 -- primitive operations of the descendant.
28453 if Present
(Inher_Id
) then
28454 pragma Assert
(Present
(Subp_Id
));
28456 Update_Primitives_Mapping
(Inher_Id
, Subp_Id
);
28458 -- Use generic machinery to copy inherited pragma, as if it were an
28459 -- instantiation, resetting source locations appropriately, so that
28460 -- expressions inside the inherited pragma use chained locations.
28461 -- This is used in particular in GNATprove to locate precisely
28462 -- messages on a given inherited pragma.
28464 Set_Copied_Sloc_For_Inherited_Pragma
28465 (Unit_Declaration_Node
(Subp_Id
), Inher_Id
);
28466 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
28468 -- Build the inherited class-wide condition
28470 Build_Class_Wide_Expression
28471 (Prag
=> Check_Prag
,
28473 Par_Subp
=> Inher_Id
,
28474 Adjust_Sloc
=> True,
28475 Needs_Wrapper
=> Needs_Wrapper
);
28477 -- If not an inherited condition simply copy the original pragma
28480 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
28483 -- Mark the pragma as being internally generated and reset the Analyzed
28486 Set_Analyzed
(Check_Prag
, False);
28487 Set_Comes_From_Source
(Check_Prag
, False);
28489 -- The tree of the original pragma may contain references to the
28490 -- formal parameters of the related subprogram. At the same time
28491 -- the corresponding body may mark the formals as unreferenced:
28493 -- procedure Proc (Formal : ...)
28494 -- with Pre => Formal ...;
28496 -- procedure Proc (Formal : ...) is
28497 -- pragma Unreferenced (Formal);
28500 -- This creates problems because all pragma Check equivalents are
28501 -- analyzed at the end of the body declarations. Since all source
28502 -- references have already been accounted for, reset any references
28503 -- to such formals in the generated pragma Check equivalent.
28505 Suppress_References
(Check_Prag
);
28507 if Present
(Corresponding_Aspect
(Prag
)) then
28508 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Prag
)));
28513 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
28514 -- the copied pragma in the newly created pragma, convert the copy into
28515 -- pragma Check by correcting the name and adding a check_kind argument.
28517 if not Keep_Pragma_Id
then
28518 Set_Class_Present
(Check_Prag
, False);
28520 Set_Pragma_Identifier
28521 (Check_Prag
, Make_Identifier
(Loc
, Name_Check
));
28523 Prepend_To
(Pragma_Argument_Associations
(Check_Prag
),
28524 Make_Pragma_Argument_Association
(Loc
,
28525 Expression
=> Make_Identifier
(Loc
, Nam
)));
28528 -- Update the error message when the pragma is inherited
28530 if Present
(Inher_Id
) then
28531 Msg_Arg
:= Last
(Pragma_Argument_Associations
(Check_Prag
));
28533 if Chars
(Msg_Arg
) = Name_Message
then
28534 String_To_Name_Buffer
(Strval
(Expression
(Msg_Arg
)));
28536 -- Insert "inherited" to improve the error message
28538 if Name_Buffer
(1 .. 8) = "failed p" then
28539 Insert_Str_In_Name_Buffer
("inherited ", 8);
28540 Set_Strval
(Expression
(Msg_Arg
), String_From_Name_Buffer
);
28546 end Build_Pragma_Check_Equivalent
;
28548 -----------------------------
28549 -- Check_Applicable_Policy --
28550 -----------------------------
28552 procedure Check_Applicable_Policy
(N
: Node_Id
) is
28556 Ename
: constant Name_Id
:= Original_Aspect_Pragma_Name
(N
);
28559 -- No effect if not valid assertion kind name
28561 if not Is_Valid_Assertion_Kind
(Ename
) then
28565 -- Loop through entries in check policy list
28567 PP
:= Opt
.Check_Policy_List
;
28568 while Present
(PP
) loop
28570 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
28571 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
28575 or else Pnm
= Name_Assertion
28576 or else (Pnm
= Name_Statement_Assertions
28577 and then Nam_In
(Ename
, Name_Assert
,
28578 Name_Assert_And_Cut
,
28580 Name_Loop_Invariant
,
28581 Name_Loop_Variant
))
28583 Policy
:= Chars
(Get_Pragma_Arg
(Last
(PPA
)));
28589 -- In CodePeer mode and GNATprove mode, we need to
28590 -- consider all assertions, unless they are disabled.
28591 -- Force Is_Checked on ignored assertions, in particular
28592 -- because transformations of the AST may depend on
28593 -- assertions being checked (e.g. the translation of
28594 -- attribute 'Loop_Entry).
28596 if CodePeer_Mode
or GNATprove_Mode
then
28597 Set_Is_Checked
(N
, True);
28598 Set_Is_Ignored
(N
, False);
28600 Set_Is_Checked
(N
, False);
28601 Set_Is_Ignored
(N
, True);
28607 Set_Is_Checked
(N
, True);
28608 Set_Is_Ignored
(N
, False);
28610 when Name_Disable
=>
28611 Set_Is_Ignored
(N
, True);
28612 Set_Is_Checked
(N
, False);
28613 Set_Is_Disabled
(N
, True);
28615 -- That should be exhaustive, the null here is a defence
28616 -- against a malformed tree from previous errors.
28625 PP
:= Next_Pragma
(PP
);
28629 -- If there are no specific entries that matched, then we let the
28630 -- setting of assertions govern. Note that this provides the needed
28631 -- compatibility with the RM for the cases of assertion, invariant,
28632 -- precondition, predicate, and postcondition. Note also that
28633 -- Assertions_Enabled is forced in CodePeer mode and GNATprove mode.
28635 if Assertions_Enabled
then
28636 Set_Is_Checked
(N
, True);
28637 Set_Is_Ignored
(N
, False);
28639 Set_Is_Checked
(N
, False);
28640 Set_Is_Ignored
(N
, True);
28642 end Check_Applicable_Policy
;
28644 -------------------------------
28645 -- Check_External_Properties --
28646 -------------------------------
28648 procedure Check_External_Properties
28656 -- All properties enabled
28658 if AR
and AW
and ER
and EW
then
28661 -- Async_Readers + Effective_Writes
28662 -- Async_Readers + Async_Writers + Effective_Writes
28664 elsif AR
and EW
and not ER
then
28667 -- Async_Writers + Effective_Reads
28668 -- Async_Readers + Async_Writers + Effective_Reads
28670 elsif AW
and ER
and not EW
then
28673 -- Async_Readers + Async_Writers
28675 elsif AR
and AW
and not ER
and not EW
then
28680 elsif AR
and not AW
and not ER
and not EW
then
28685 elsif AW
and not AR
and not ER
and not EW
then
28690 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
28693 end Check_External_Properties
;
28699 function Check_Kind
(Nam
: Name_Id
) return Name_Id
is
28703 -- Loop through entries in check policy list
28705 PP
:= Opt
.Check_Policy_List
;
28706 while Present
(PP
) loop
28708 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
28709 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
28713 or else (Pnm
= Name_Assertion
28714 and then Is_Valid_Assertion_Kind
(Nam
))
28715 or else (Pnm
= Name_Statement_Assertions
28716 and then Nam_In
(Nam
, Name_Assert
,
28717 Name_Assert_And_Cut
,
28719 Name_Loop_Invariant
,
28720 Name_Loop_Variant
))
28722 case (Chars
(Get_Pragma_Arg
(Last
(PPA
)))) is
28731 return Name_Ignore
;
28733 when Name_Disable
=>
28734 return Name_Disable
;
28737 raise Program_Error
;
28741 PP
:= Next_Pragma
(PP
);
28746 -- If there are no specific entries that matched, then we let the
28747 -- setting of assertions govern. Note that this provides the needed
28748 -- compatibility with the RM for the cases of assertion, invariant,
28749 -- precondition, predicate, and postcondition.
28751 if Assertions_Enabled
then
28754 return Name_Ignore
;
28758 ---------------------------
28759 -- Check_Missing_Part_Of --
28760 ---------------------------
28762 procedure Check_Missing_Part_Of
(Item_Id
: Entity_Id
) is
28763 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean;
28764 -- Determine whether a package denoted by Pack_Id declares at least one
28767 -----------------------
28768 -- Has_Visible_State --
28769 -----------------------
28771 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean is
28772 Item_Id
: Entity_Id
;
28775 -- Traverse the entity chain of the package trying to find at least
28776 -- one visible abstract state, variable or a package [instantiation]
28777 -- that declares a visible state.
28779 Item_Id
:= First_Entity
(Pack_Id
);
28780 while Present
(Item_Id
)
28781 and then not In_Private_Part
(Item_Id
)
28783 -- Do not consider internally generated items
28785 if not Comes_From_Source
(Item_Id
) then
28788 -- Do not consider generic formals or their corresponding actuals
28789 -- because they are not part of a visible state. Note that both
28790 -- entities are marked as hidden.
28792 elsif Is_Hidden
(Item_Id
) then
28795 -- A visible state has been found. Note that constants are not
28796 -- considered here because it is not possible to determine whether
28797 -- they depend on variable input. This check is left to the SPARK
28800 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
28803 -- Recursively peek into nested packages and instantiations
28805 elsif Ekind
(Item_Id
) = E_Package
28806 and then Has_Visible_State
(Item_Id
)
28811 Next_Entity
(Item_Id
);
28815 end Has_Visible_State
;
28819 Pack_Id
: Entity_Id
;
28820 Placement
: State_Space_Kind
;
28822 -- Start of processing for Check_Missing_Part_Of
28825 -- Do not consider abstract states, variables or package instantiations
28826 -- coming from an instance as those always inherit the Part_Of indicator
28827 -- of the instance itself.
28829 if In_Instance
then
28832 -- Do not consider internally generated entities as these can never
28833 -- have a Part_Of indicator.
28835 elsif not Comes_From_Source
(Item_Id
) then
28838 -- Perform these checks only when SPARK_Mode is enabled as they will
28839 -- interfere with standard Ada rules and produce false positives.
28841 elsif SPARK_Mode
/= On
then
28844 -- Do not consider constants, because the compiler cannot accurately
28845 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
28846 -- act as a hidden state of a package.
28848 elsif Ekind
(Item_Id
) = E_Constant
then
28852 -- Find where the abstract state, variable or package instantiation
28853 -- lives with respect to the state space.
28855 Find_Placement_In_State_Space
28856 (Item_Id
=> Item_Id
,
28857 Placement
=> Placement
,
28858 Pack_Id
=> Pack_Id
);
28860 -- Items that appear in a non-package construct (subprogram, block, etc)
28861 -- do not require a Part_Of indicator because they can never act as a
28864 if Placement
= Not_In_Package
then
28867 -- An item declared in the body state space of a package always act as a
28868 -- constituent and does not need explicit Part_Of indicator.
28870 elsif Placement
= Body_State_Space
then
28873 -- In general an item declared in the visible state space of a package
28874 -- does not require a Part_Of indicator. The only exception is when the
28875 -- related package is a nongeneric private child unit, in which case
28876 -- Part_Of must denote a state in the parent unit or in one of its
28879 elsif Placement
= Visible_State_Space
then
28880 if Is_Child_Unit
(Pack_Id
)
28881 and then not Is_Generic_Unit
(Pack_Id
)
28882 and then Is_Private_Descendant
(Pack_Id
)
28884 -- A package instantiation does not need a Part_Of indicator when
28885 -- the related generic template has no visible state.
28887 if Ekind
(Item_Id
) = E_Package
28888 and then Is_Generic_Instance
(Item_Id
)
28889 and then not Has_Visible_State
(Item_Id
)
28893 -- All other cases require Part_Of
28897 ("indicator Part_Of is required in this context "
28898 & "(SPARK RM 7.2.6(3))", Item_Id
);
28899 Error_Msg_Name_1
:= Chars
(Pack_Id
);
28901 ("\& is declared in the visible part of private child "
28902 & "unit %", Item_Id
);
28906 -- When the item appears in the private state space of a package, it
28907 -- must be a part of some state declared by the said package.
28909 else pragma Assert
(Placement
= Private_State_Space
);
28911 -- The related package does not declare a state, the item cannot act
28912 -- as a Part_Of constituent.
28914 if No
(Get_Pragma
(Pack_Id
, Pragma_Abstract_State
)) then
28917 -- A package instantiation does not need a Part_Of indicator when the
28918 -- related generic template has no visible state.
28920 elsif Ekind
(Item_Id
) = E_Package
28921 and then Is_Generic_Instance
(Item_Id
)
28922 and then not Has_Visible_State
(Item_Id
)
28926 -- All other cases require Part_Of
28930 ("indicator Part_Of is required in this context "
28931 & "(SPARK RM 7.2.6(2))", Item_Id
);
28932 Error_Msg_Name_1
:= Chars
(Pack_Id
);
28934 ("\& is declared in the private part of package %", Item_Id
);
28937 end Check_Missing_Part_Of
;
28939 ---------------------------------------------------
28940 -- Check_Postcondition_Use_In_Inlined_Subprogram --
28941 ---------------------------------------------------
28943 procedure Check_Postcondition_Use_In_Inlined_Subprogram
28945 Spec_Id
: Entity_Id
)
28948 if Warn_On_Redundant_Constructs
28949 and then Has_Pragma_Inline_Always
(Spec_Id
)
28950 and then Assertions_Enabled
28952 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
28954 if From_Aspect_Specification
(Prag
) then
28956 ("aspect % not enforced on inlined subprogram &?r?",
28957 Corresponding_Aspect
(Prag
), Spec_Id
);
28960 ("pragma % not enforced on inlined subprogram &?r?",
28964 end Check_Postcondition_Use_In_Inlined_Subprogram
;
28966 -------------------------------------
28967 -- Check_State_And_Constituent_Use --
28968 -------------------------------------
28970 procedure Check_State_And_Constituent_Use
28971 (States
: Elist_Id
;
28972 Constits
: Elist_Id
;
28975 Constit_Elmt
: Elmt_Id
;
28976 Constit_Id
: Entity_Id
;
28977 State_Id
: Entity_Id
;
28980 -- Nothing to do if there are no states or constituents
28982 if No
(States
) or else No
(Constits
) then
28986 -- Inspect the list of constituents and try to determine whether its
28987 -- encapsulating state is in list States.
28989 Constit_Elmt
:= First_Elmt
(Constits
);
28990 while Present
(Constit_Elmt
) loop
28991 Constit_Id
:= Node
(Constit_Elmt
);
28993 -- Determine whether the constituent is part of an encapsulating
28994 -- state that appears in the same context and if this is the case,
28995 -- emit an error (SPARK RM 7.2.6(7)).
28997 State_Id
:= Find_Encapsulating_State
(States
, Constit_Id
);
28999 if Present
(State_Id
) then
29000 Error_Msg_Name_1
:= Chars
(Constit_Id
);
29002 ("cannot mention state & and its constituent % in the same "
29003 & "context", Context
, State_Id
);
29007 Next_Elmt
(Constit_Elmt
);
29009 end Check_State_And_Constituent_Use
;
29011 ---------------------------------------------
29012 -- Collect_Inherited_Class_Wide_Conditions --
29013 ---------------------------------------------
29015 procedure Collect_Inherited_Class_Wide_Conditions
(Subp
: Entity_Id
) is
29016 Parent_Subp
: constant Entity_Id
:=
29017 Ultimate_Alias
(Overridden_Operation
(Subp
));
29018 -- The Overridden_Operation may itself be inherited and as such have no
29019 -- explicit contract.
29021 Prags
: constant Node_Id
:= Contract
(Parent_Subp
);
29022 In_Spec_Expr
: Boolean;
29023 Installed
: Boolean;
29025 New_Prag
: Node_Id
;
29028 Installed
:= False;
29030 -- Iterate over the contract of the overridden subprogram to find all
29031 -- inherited class-wide pre- and postconditions.
29033 if Present
(Prags
) then
29034 Prag
:= Pre_Post_Conditions
(Prags
);
29036 while Present
(Prag
) loop
29037 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
29038 Name_Precondition
, Name_Postcondition
)
29039 and then Class_Present
(Prag
)
29041 -- The generated pragma must be analyzed in the context of
29042 -- the subprogram, to make its formals visible. In addition,
29043 -- we must inhibit freezing and full analysis because the
29044 -- controlling type of the subprogram is not frozen yet, and
29045 -- may have further primitives.
29047 if not Installed
then
29050 Install_Formals
(Subp
);
29051 In_Spec_Expr
:= In_Spec_Expression
;
29052 In_Spec_Expression
:= True;
29056 Build_Pragma_Check_Equivalent
29057 (Prag
, Subp
, Parent_Subp
, Keep_Pragma_Id
=> True);
29059 Insert_After
(Unit_Declaration_Node
(Subp
), New_Prag
);
29060 Preanalyze
(New_Prag
);
29062 -- Prevent further analysis in subsequent processing of the
29063 -- current list of declarations
29065 Set_Analyzed
(New_Prag
);
29068 Prag
:= Next_Pragma
(Prag
);
29072 In_Spec_Expression
:= In_Spec_Expr
;
29076 end Collect_Inherited_Class_Wide_Conditions
;
29078 ---------------------------------------
29079 -- Collect_Subprogram_Inputs_Outputs --
29080 ---------------------------------------
29082 procedure Collect_Subprogram_Inputs_Outputs
29083 (Subp_Id
: Entity_Id
;
29084 Synthesize
: Boolean := False;
29085 Subp_Inputs
: in out Elist_Id
;
29086 Subp_Outputs
: in out Elist_Id
;
29087 Global_Seen
: out Boolean)
29089 procedure Collect_Dependency_Clause
(Clause
: Node_Id
);
29090 -- Collect all relevant items from a dependency clause
29092 procedure Collect_Global_List
29094 Mode
: Name_Id
:= Name_Input
);
29095 -- Collect all relevant items from a global list
29097 -------------------------------
29098 -- Collect_Dependency_Clause --
29099 -------------------------------
29101 procedure Collect_Dependency_Clause
(Clause
: Node_Id
) is
29102 procedure Collect_Dependency_Item
29104 Is_Input
: Boolean);
29105 -- Add an item to the proper subprogram input or output collection
29107 -----------------------------
29108 -- Collect_Dependency_Item --
29109 -----------------------------
29111 procedure Collect_Dependency_Item
29113 Is_Input
: Boolean)
29118 -- Nothing to collect when the item is null
29120 if Nkind
(Item
) = N_Null
then
29123 -- Ditto for attribute 'Result
29125 elsif Is_Attribute_Result
(Item
) then
29128 -- Multiple items appear as an aggregate
29130 elsif Nkind
(Item
) = N_Aggregate
then
29131 Extra
:= First
(Expressions
(Item
));
29132 while Present
(Extra
) loop
29133 Collect_Dependency_Item
(Extra
, Is_Input
);
29137 -- Otherwise this is a solitary item
29141 Append_New_Elmt
(Item
, Subp_Inputs
);
29143 Append_New_Elmt
(Item
, Subp_Outputs
);
29146 end Collect_Dependency_Item
;
29148 -- Start of processing for Collect_Dependency_Clause
29151 if Nkind
(Clause
) = N_Null
then
29154 -- A dependency clause appears as component association
29156 elsif Nkind
(Clause
) = N_Component_Association
then
29157 Collect_Dependency_Item
29158 (Item
=> Expression
(Clause
),
29161 Collect_Dependency_Item
29162 (Item
=> First
(Choices
(Clause
)),
29163 Is_Input
=> False);
29165 -- To accommodate partial decoration of disabled SPARK features, this
29166 -- routine may be called with illegal input. If this is the case, do
29167 -- not raise Program_Error.
29172 end Collect_Dependency_Clause
;
29174 -------------------------
29175 -- Collect_Global_List --
29176 -------------------------
29178 procedure Collect_Global_List
29180 Mode
: Name_Id
:= Name_Input
)
29182 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
29183 -- Add an item to the proper subprogram input or output collection
29185 -------------------------
29186 -- Collect_Global_Item --
29187 -------------------------
29189 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
29191 if Nam_In
(Mode
, Name_In_Out
, Name_Input
) then
29192 Append_New_Elmt
(Item
, Subp_Inputs
);
29195 if Nam_In
(Mode
, Name_In_Out
, Name_Output
) then
29196 Append_New_Elmt
(Item
, Subp_Outputs
);
29198 end Collect_Global_Item
;
29205 -- Start of processing for Collect_Global_List
29208 if Nkind
(List
) = N_Null
then
29211 -- Single global item declaration
29213 elsif Nkind_In
(List
, N_Expanded_Name
,
29215 N_Selected_Component
)
29217 Collect_Global_Item
(List
, Mode
);
29219 -- Simple global list or moded global list declaration
29221 elsif Nkind
(List
) = N_Aggregate
then
29222 if Present
(Expressions
(List
)) then
29223 Item
:= First
(Expressions
(List
));
29224 while Present
(Item
) loop
29225 Collect_Global_Item
(Item
, Mode
);
29230 Assoc
:= First
(Component_Associations
(List
));
29231 while Present
(Assoc
) loop
29232 Collect_Global_List
29233 (List
=> Expression
(Assoc
),
29234 Mode
=> Chars
(First
(Choices
(Assoc
))));
29239 -- To accommodate partial decoration of disabled SPARK features, this
29240 -- routine may be called with illegal input. If this is the case, do
29241 -- not raise Program_Error.
29246 end Collect_Global_List
;
29253 Formal
: Entity_Id
;
29255 Spec_Id
: Entity_Id
:= Empty
;
29256 Subp_Decl
: Node_Id
;
29259 -- Start of processing for Collect_Subprogram_Inputs_Outputs
29262 Global_Seen
:= False;
29264 -- Process all formal parameters of entries, [generic] subprograms, and
29267 if Ekind_In
(Subp_Id
, E_Entry
,
29270 E_Generic_Function
,
29271 E_Generic_Procedure
,
29275 Subp_Decl
:= Unit_Declaration_Node
(Subp_Id
);
29276 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
29278 -- Process all formal parameters
29280 Formal
:= First_Entity
(Spec_Id
);
29281 while Present
(Formal
) loop
29282 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_In_Parameter
) then
29283 Append_New_Elmt
(Formal
, Subp_Inputs
);
29286 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
29287 Append_New_Elmt
(Formal
, Subp_Outputs
);
29289 -- Out parameters can act as inputs when the related type is
29290 -- tagged, unconstrained array, unconstrained record, or record
29291 -- with unconstrained components.
29293 if Ekind
(Formal
) = E_Out_Parameter
29294 and then Is_Unconstrained_Or_Tagged_Item
(Formal
)
29296 Append_New_Elmt
(Formal
, Subp_Inputs
);
29300 Next_Entity
(Formal
);
29303 -- Otherwise the input denotes a task type, a task body, or the
29304 -- anonymous object created for a single task type.
29306 elsif Ekind_In
(Subp_Id
, E_Task_Type
, E_Task_Body
)
29307 or else Is_Single_Task_Object
(Subp_Id
)
29309 Subp_Decl
:= Declaration_Node
(Subp_Id
);
29310 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
29313 -- When processing an entry, subprogram or task body, look for pragmas
29314 -- Refined_Depends and Refined_Global as they specify the inputs and
29317 if Is_Entry_Body
(Subp_Id
)
29318 or else Ekind_In
(Subp_Id
, E_Subprogram_Body
, E_Task_Body
)
29320 Depends
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Depends
);
29321 Global
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Global
);
29323 -- Subprogram declaration or stand-alone body case, look for pragmas
29324 -- Depends and Global
29327 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
29328 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
29331 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
29332 -- because it provides finer granularity of inputs and outputs.
29334 if Present
(Global
) then
29335 Global_Seen
:= True;
29336 Collect_Global_List
(Expression
(Get_Argument
(Global
, Spec_Id
)));
29338 -- When the related subprogram lacks pragma [Refined_]Global, fall back
29339 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
29340 -- the inputs and outputs from [Refined_]Depends.
29342 elsif Synthesize
and then Present
(Depends
) then
29343 Clauses
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
29345 -- Multiple dependency clauses appear as an aggregate
29347 if Nkind
(Clauses
) = N_Aggregate
then
29348 Clause
:= First
(Component_Associations
(Clauses
));
29349 while Present
(Clause
) loop
29350 Collect_Dependency_Clause
(Clause
);
29354 -- Otherwise this is a single dependency clause
29357 Collect_Dependency_Clause
(Clauses
);
29361 -- The current instance of a protected type acts as a formal parameter
29362 -- of mode IN for functions and IN OUT for entries and procedures
29363 -- (SPARK RM 6.1.4).
29365 if Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
29366 Typ
:= Scope
(Spec_Id
);
29368 -- Use the anonymous object when the type is single protected
29370 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
29371 Typ
:= Anonymous_Object
(Typ
);
29374 Append_New_Elmt
(Typ
, Subp_Inputs
);
29376 if Ekind_In
(Spec_Id
, E_Entry
, E_Entry_Family
, E_Procedure
) then
29377 Append_New_Elmt
(Typ
, Subp_Outputs
);
29380 -- The current instance of a task type acts as a formal parameter of
29381 -- mode IN OUT (SPARK RM 6.1.4).
29383 elsif Ekind
(Spec_Id
) = E_Task_Type
then
29386 -- Use the anonymous object when the type is single task
29388 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
29389 Typ
:= Anonymous_Object
(Typ
);
29392 Append_New_Elmt
(Typ
, Subp_Inputs
);
29393 Append_New_Elmt
(Typ
, Subp_Outputs
);
29395 elsif Is_Single_Task_Object
(Spec_Id
) then
29396 Append_New_Elmt
(Spec_Id
, Subp_Inputs
);
29397 Append_New_Elmt
(Spec_Id
, Subp_Outputs
);
29399 end Collect_Subprogram_Inputs_Outputs
;
29401 ---------------------------
29402 -- Contract_Freeze_Error --
29403 ---------------------------
29405 procedure Contract_Freeze_Error
29406 (Contract_Id
: Entity_Id
;
29407 Freeze_Id
: Entity_Id
)
29410 Error_Msg_Name_1
:= Chars
(Contract_Id
);
29411 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
29414 ("body & declared # freezes the contract of%", Contract_Id
, Freeze_Id
);
29416 ("\all contractual items must be declared before body #", Contract_Id
);
29417 end Contract_Freeze_Error
;
29419 ---------------------------------
29420 -- Delay_Config_Pragma_Analyze --
29421 ---------------------------------
29423 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean is
29425 return Nam_In
(Pragma_Name_Unmapped
(N
),
29426 Name_Interrupt_State
, Name_Priority_Specific_Dispatching
);
29427 end Delay_Config_Pragma_Analyze
;
29429 -----------------------
29430 -- Duplication_Error --
29431 -----------------------
29433 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
) is
29434 Prag_From_Asp
: constant Boolean := From_Aspect_Specification
(Prag
);
29435 Prev_From_Asp
: constant Boolean := From_Aspect_Specification
(Prev
);
29438 Error_Msg_Sloc
:= Sloc
(Prev
);
29439 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
29441 -- Emit a precise message to distinguish between source pragmas and
29442 -- pragmas generated from aspects. The ordering of the two pragmas is
29446 -- Prag -- duplicate
29448 -- No error is emitted when both pragmas come from aspects because this
29449 -- is already detected by the general aspect analysis mechanism.
29451 if Prag_From_Asp
and Prev_From_Asp
then
29453 elsif Prag_From_Asp
then
29454 Error_Msg_N
("aspect % duplicates pragma declared #", Prag
);
29455 elsif Prev_From_Asp
then
29456 Error_Msg_N
("pragma % duplicates aspect declared #", Prag
);
29458 Error_Msg_N
("pragma % duplicates pragma declared #", Prag
);
29460 end Duplication_Error
;
29462 ------------------------------
29463 -- Find_Encapsulating_State --
29464 ------------------------------
29466 function Find_Encapsulating_State
29467 (States
: Elist_Id
;
29468 Constit_Id
: Entity_Id
) return Entity_Id
29470 State_Id
: Entity_Id
;
29473 -- Since a constituent may be part of a larger constituent set, climb
29474 -- the encapsulating state chain looking for a state that appears in
29477 State_Id
:= Encapsulating_State
(Constit_Id
);
29478 while Present
(State_Id
) loop
29479 if Contains
(States
, State_Id
) then
29483 State_Id
:= Encapsulating_State
(State_Id
);
29487 end Find_Encapsulating_State
;
29489 --------------------------
29490 -- Find_Related_Context --
29491 --------------------------
29493 function Find_Related_Context
29495 Do_Checks
: Boolean := False) return Node_Id
29500 Stmt
:= Prev
(Prag
);
29501 while Present
(Stmt
) loop
29503 -- Skip prior pragmas, but check for duplicates
29505 if Nkind
(Stmt
) = N_Pragma
then
29507 and then Pragma_Name
(Stmt
) = Pragma_Name
(Prag
)
29514 -- Skip internally generated code
29516 elsif not Comes_From_Source
(Stmt
) then
29518 -- The anonymous object created for a single concurrent type is a
29519 -- suitable context.
29521 if Nkind
(Stmt
) = N_Object_Declaration
29522 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
29527 -- Return the current source construct
29537 end Find_Related_Context
;
29539 --------------------------------------
29540 -- Find_Related_Declaration_Or_Body --
29541 --------------------------------------
29543 function Find_Related_Declaration_Or_Body
29545 Do_Checks
: Boolean := False) return Node_Id
29547 Prag_Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
29549 procedure Expression_Function_Error
;
29550 -- Emit an error concerning pragma Prag that illegaly applies to an
29551 -- expression function.
29553 -------------------------------
29554 -- Expression_Function_Error --
29555 -------------------------------
29557 procedure Expression_Function_Error
is
29559 Error_Msg_Name_1
:= Prag_Nam
;
29561 -- Emit a precise message to distinguish between source pragmas and
29562 -- pragmas generated from aspects.
29564 if From_Aspect_Specification
(Prag
) then
29566 ("aspect % cannot apply to a stand alone expression function",
29570 ("pragma % cannot apply to a stand alone expression function",
29573 end Expression_Function_Error
;
29577 Context
: constant Node_Id
:= Parent
(Prag
);
29580 Look_For_Body
: constant Boolean :=
29581 Nam_In
(Prag_Nam
, Name_Refined_Depends
,
29582 Name_Refined_Global
,
29584 Name_Refined_State
);
29585 -- Refinement pragmas must be associated with a subprogram body [stub]
29587 -- Start of processing for Find_Related_Declaration_Or_Body
29590 Stmt
:= Prev
(Prag
);
29591 while Present
(Stmt
) loop
29593 -- Skip prior pragmas, but check for duplicates. Pragmas produced
29594 -- by splitting a complex pre/postcondition are not considered to
29597 if Nkind
(Stmt
) = N_Pragma
then
29599 and then not Split_PPC
(Stmt
)
29600 and then Original_Aspect_Pragma_Name
(Stmt
) = Prag_Nam
29607 -- Emit an error when a refinement pragma appears on an expression
29608 -- function without a completion.
29611 and then Look_For_Body
29612 and then Nkind
(Stmt
) = N_Subprogram_Declaration
29613 and then Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
29614 and then not Has_Completion
(Defining_Entity
(Stmt
))
29616 Expression_Function_Error
;
29619 -- The refinement pragma applies to a subprogram body stub
29621 elsif Look_For_Body
29622 and then Nkind
(Stmt
) = N_Subprogram_Body_Stub
29626 -- Skip internally generated code
29628 elsif not Comes_From_Source
(Stmt
) then
29630 -- The anonymous object created for a single concurrent type is a
29631 -- suitable context.
29633 if Nkind
(Stmt
) = N_Object_Declaration
29634 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
29638 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
then
29640 -- The subprogram declaration is an internally generated spec
29641 -- for an expression function.
29643 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
29646 -- The subprogram declaration is an internally generated spec
29647 -- for a stand-alone subrogram body declared inside a protected
29650 elsif Present
(Corresponding_Body
(Stmt
))
29651 and then Comes_From_Source
(Corresponding_Body
(Stmt
))
29652 and then Is_Protected_Type
(Current_Scope
)
29656 -- The subprogram is actually an instance housed within an
29657 -- anonymous wrapper package.
29659 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
29664 -- Return the current construct which is either a subprogram body,
29665 -- a subprogram declaration or is illegal.
29674 -- If we fall through, then the pragma was either the first declaration
29675 -- or it was preceded by other pragmas and no source constructs.
29677 -- The pragma is associated with a library-level subprogram
29679 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
29680 return Unit
(Parent
(Context
));
29682 -- The pragma appears inside the declarations of an entry body
29684 elsif Nkind
(Context
) = N_Entry_Body
then
29687 -- The pragma appears inside the statements of a subprogram body. This
29688 -- placement is the result of subprogram contract expansion.
29690 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
then
29691 return Parent
(Context
);
29693 -- The pragma appears inside the declarative part of a package body
29695 elsif Nkind
(Context
) = N_Package_Body
then
29698 -- The pragma appears inside the declarative part of a subprogram body
29700 elsif Nkind
(Context
) = N_Subprogram_Body
then
29703 -- The pragma appears inside the declarative part of a task body
29705 elsif Nkind
(Context
) = N_Task_Body
then
29708 -- The pragma appears inside the visible part of a package specification
29710 elsif Nkind
(Context
) = N_Package_Specification
then
29711 return Parent
(Context
);
29713 -- The pragma is a byproduct of aspect expansion, return the related
29714 -- context of the original aspect. This case has a lower priority as
29715 -- the above circuitry pinpoints precisely the related context.
29717 elsif Present
(Corresponding_Aspect
(Prag
)) then
29718 return Parent
(Corresponding_Aspect
(Prag
));
29720 -- No candidate subprogram [body] found
29725 end Find_Related_Declaration_Or_Body
;
29727 ----------------------------------
29728 -- Find_Related_Package_Or_Body --
29729 ----------------------------------
29731 function Find_Related_Package_Or_Body
29733 Do_Checks
: Boolean := False) return Node_Id
29735 Context
: constant Node_Id
:= Parent
(Prag
);
29736 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
29740 Stmt
:= Prev
(Prag
);
29741 while Present
(Stmt
) loop
29743 -- Skip prior pragmas, but check for duplicates
29745 if Nkind
(Stmt
) = N_Pragma
then
29746 if Do_Checks
and then Pragma_Name
(Stmt
) = Prag_Nam
then
29752 -- Skip internally generated code
29754 elsif not Comes_From_Source
(Stmt
) then
29755 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
29757 -- The subprogram declaration is an internally generated spec
29758 -- for an expression function.
29760 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
29763 -- The subprogram is actually an instance housed within an
29764 -- anonymous wrapper package.
29766 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
29771 -- Return the current source construct which is illegal
29780 -- If we fall through, then the pragma was either the first declaration
29781 -- or it was preceded by other pragmas and no source constructs.
29783 -- The pragma is associated with a package. The immediate context in
29784 -- this case is the specification of the package.
29786 if Nkind
(Context
) = N_Package_Specification
then
29787 return Parent
(Context
);
29789 -- The pragma appears in the declarations of a package body
29791 elsif Nkind
(Context
) = N_Package_Body
then
29794 -- The pragma appears in the statements of a package body
29796 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
29797 and then Nkind
(Parent
(Context
)) = N_Package_Body
29799 return Parent
(Context
);
29801 -- The pragma is a byproduct of aspect expansion, return the related
29802 -- context of the original aspect. This case has a lower priority as
29803 -- the above circuitry pinpoints precisely the related context.
29805 elsif Present
(Corresponding_Aspect
(Prag
)) then
29806 return Parent
(Corresponding_Aspect
(Prag
));
29808 -- No candidate package [body] found
29813 end Find_Related_Package_Or_Body
;
29819 function Get_Argument
29821 Context_Id
: Entity_Id
:= Empty
) return Node_Id
29823 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
29826 -- Use the expression of the original aspect when compiling for ASIS or
29827 -- when analyzing the template of a generic unit. In both cases the
29828 -- aspect's tree must be decorated to allow for ASIS queries or to save
29829 -- the global references in the generic context.
29831 if From_Aspect_Specification
(Prag
)
29832 and then (ASIS_Mode
or else (Present
(Context_Id
)
29833 and then Is_Generic_Unit
(Context_Id
)))
29835 return Corresponding_Aspect
(Prag
);
29837 -- Otherwise use the expression of the pragma
29839 elsif Present
(Args
) then
29840 return First
(Args
);
29847 -------------------------
29848 -- Get_Base_Subprogram --
29849 -------------------------
29851 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
is
29853 -- Follow subprogram renaming chain
29855 if Is_Subprogram
(Def_Id
)
29856 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
29857 N_Subprogram_Renaming_Declaration
29858 and then Present
(Alias
(Def_Id
))
29860 return Alias
(Def_Id
);
29864 end Get_Base_Subprogram
;
29866 -----------------------
29867 -- Get_SPARK_Mode_Type --
29868 -----------------------
29870 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
is
29872 if N
= Name_On
then
29874 elsif N
= Name_Off
then
29877 -- Any other argument is illegal. Assume that no SPARK mode applies to
29878 -- avoid potential cascaded errors.
29883 end Get_SPARK_Mode_Type
;
29885 ------------------------------------
29886 -- Get_SPARK_Mode_From_Annotation --
29887 ------------------------------------
29889 function Get_SPARK_Mode_From_Annotation
29890 (N
: Node_Id
) return SPARK_Mode_Type
29895 if Nkind
(N
) = N_Aspect_Specification
then
29896 Mode
:= Expression
(N
);
29898 else pragma Assert
(Nkind
(N
) = N_Pragma
);
29899 Mode
:= First
(Pragma_Argument_Associations
(N
));
29901 if Present
(Mode
) then
29902 Mode
:= Get_Pragma_Arg
(Mode
);
29906 -- Aspect or pragma SPARK_Mode specifies an explicit mode
29908 if Present
(Mode
) then
29909 if Nkind
(Mode
) = N_Identifier
then
29910 return Get_SPARK_Mode_Type
(Chars
(Mode
));
29912 -- In case of a malformed aspect or pragma, return the default None
29918 -- Otherwise the lack of an expression defaults SPARK_Mode to On
29923 end Get_SPARK_Mode_From_Annotation
;
29925 ---------------------------
29926 -- Has_Extra_Parentheses --
29927 ---------------------------
29929 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean is
29933 -- The aggregate should not have an expression list because a clause
29934 -- is always interpreted as a component association. The only way an
29935 -- expression list can sneak in is by adding extra parentheses around
29936 -- the individual clauses:
29938 -- Depends (Output => Input) -- proper form
29939 -- Depends ((Output => Input)) -- extra parentheses
29941 -- Since the extra parentheses are not allowed by the syntax of the
29942 -- pragma, flag them now to avoid emitting misleading errors down the
29945 if Nkind
(Clause
) = N_Aggregate
29946 and then Present
(Expressions
(Clause
))
29948 Expr
:= First
(Expressions
(Clause
));
29949 while Present
(Expr
) loop
29951 -- A dependency clause surrounded by extra parentheses appears
29952 -- as an aggregate of component associations with an optional
29953 -- Paren_Count set.
29955 if Nkind
(Expr
) = N_Aggregate
29956 and then Present
(Component_Associations
(Expr
))
29959 ("dependency clause contains extra parentheses", Expr
);
29961 -- Otherwise the expression is a malformed construct
29964 SPARK_Msg_N
("malformed dependency clause", Expr
);
29974 end Has_Extra_Parentheses
;
29980 procedure Initialize
is
29991 Dummy
:= Dummy
+ 1;
29994 -----------------------------
29995 -- Is_Config_Static_String --
29996 -----------------------------
29998 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean is
30000 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean;
30001 -- This is an internal recursive function that is just like the outer
30002 -- function except that it adds the string to the name buffer rather
30003 -- than placing the string in the name buffer.
30005 ------------------------------
30006 -- Add_Config_Static_String --
30007 ------------------------------
30009 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean is
30016 if Nkind
(N
) = N_Op_Concat
then
30017 if Add_Config_Static_String
(Left_Opnd
(N
)) then
30018 N
:= Right_Opnd
(N
);
30024 if Nkind
(N
) /= N_String_Literal
then
30025 Error_Msg_N
("string literal expected for pragma argument", N
);
30029 for J
in 1 .. String_Length
(Strval
(N
)) loop
30030 C
:= Get_String_Char
(Strval
(N
), J
);
30032 if not In_Character_Range
(C
) then
30034 ("string literal contains invalid wide character",
30035 Sloc
(N
) + 1 + Source_Ptr
(J
));
30039 Add_Char_To_Name_Buffer
(Get_Character
(C
));
30044 end Add_Config_Static_String
;
30046 -- Start of processing for Is_Config_Static_String
30051 return Add_Config_Static_String
(Arg
);
30052 end Is_Config_Static_String
;
30054 -------------------------------
30055 -- Is_Elaboration_SPARK_Mode --
30056 -------------------------------
30058 function Is_Elaboration_SPARK_Mode
(N
: Node_Id
) return Boolean is
30061 (Nkind
(N
) = N_Pragma
30062 and then Pragma_Name
(N
) = Name_SPARK_Mode
30063 and then Is_List_Member
(N
));
30065 -- Pragma SPARK_Mode affects the elaboration of a package body when it
30066 -- appears in the statement part of the body.
30069 Present
(Parent
(N
))
30070 and then Nkind
(Parent
(N
)) = N_Handled_Sequence_Of_Statements
30071 and then List_Containing
(N
) = Statements
(Parent
(N
))
30072 and then Present
(Parent
(Parent
(N
)))
30073 and then Nkind
(Parent
(Parent
(N
))) = N_Package_Body
;
30074 end Is_Elaboration_SPARK_Mode
;
30076 -----------------------
30077 -- Is_Enabled_Pragma --
30078 -----------------------
30080 function Is_Enabled_Pragma
(Prag
: Node_Id
) return Boolean is
30084 if Present
(Prag
) then
30085 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
30087 if Present
(Arg
) then
30088 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg
)));
30090 -- The lack of a Boolean argument automatically enables the pragma
30096 -- The pragma is missing, therefore it is not enabled
30101 end Is_Enabled_Pragma
;
30103 -----------------------------------------
30104 -- Is_Non_Significant_Pragma_Reference --
30105 -----------------------------------------
30107 -- This function makes use of the following static table which indicates
30108 -- whether appearance of some name in a given pragma is to be considered
30109 -- as a reference for the purposes of warnings about unreferenced objects.
30111 -- -1 indicates that appearence in any argument is significant
30112 -- 0 indicates that appearance in any argument is not significant
30113 -- +n indicates that appearance as argument n is significant, but all
30114 -- other arguments are not significant
30115 -- 9n arguments from n on are significant, before n insignificant
30117 Sig_Flags
: constant array (Pragma_Id
) of Int
:=
30118 (Pragma_Abort_Defer
=> -1,
30119 Pragma_Abstract_State
=> -1,
30120 Pragma_Ada_83
=> -1,
30121 Pragma_Ada_95
=> -1,
30122 Pragma_Ada_05
=> -1,
30123 Pragma_Ada_2005
=> -1,
30124 Pragma_Ada_12
=> -1,
30125 Pragma_Ada_2012
=> -1,
30126 Pragma_Ada_2020
=> -1,
30127 Pragma_All_Calls_Remote
=> -1,
30128 Pragma_Allow_Integer_Address
=> -1,
30129 Pragma_Annotate
=> 93,
30130 Pragma_Assert
=> -1,
30131 Pragma_Assert_And_Cut
=> -1,
30132 Pragma_Assertion_Policy
=> 0,
30133 Pragma_Assume
=> -1,
30134 Pragma_Assume_No_Invalid_Values
=> 0,
30135 Pragma_Async_Readers
=> 0,
30136 Pragma_Async_Writers
=> 0,
30137 Pragma_Asynchronous
=> 0,
30138 Pragma_Atomic
=> 0,
30139 Pragma_Atomic_Components
=> 0,
30140 Pragma_Attach_Handler
=> -1,
30141 Pragma_Attribute_Definition
=> 92,
30142 Pragma_Check
=> -1,
30143 Pragma_Check_Float_Overflow
=> 0,
30144 Pragma_Check_Name
=> 0,
30145 Pragma_Check_Policy
=> 0,
30146 Pragma_CPP_Class
=> 0,
30147 Pragma_CPP_Constructor
=> 0,
30148 Pragma_CPP_Virtual
=> 0,
30149 Pragma_CPP_Vtable
=> 0,
30151 Pragma_C_Pass_By_Copy
=> 0,
30152 Pragma_Comment
=> -1,
30153 Pragma_Common_Object
=> 0,
30154 Pragma_Compile_Time_Error
=> -1,
30155 Pragma_Compile_Time_Warning
=> -1,
30156 Pragma_Compiler_Unit
=> -1,
30157 Pragma_Compiler_Unit_Warning
=> -1,
30158 Pragma_Complete_Representation
=> 0,
30159 Pragma_Complex_Representation
=> 0,
30160 Pragma_Component_Alignment
=> 0,
30161 Pragma_Constant_After_Elaboration
=> 0,
30162 Pragma_Contract_Cases
=> -1,
30163 Pragma_Controlled
=> 0,
30164 Pragma_Convention
=> 0,
30165 Pragma_Convention_Identifier
=> 0,
30166 Pragma_Deadline_Floor
=> -1,
30167 Pragma_Debug
=> -1,
30168 Pragma_Debug_Policy
=> 0,
30169 Pragma_Detect_Blocking
=> 0,
30170 Pragma_Default_Initial_Condition
=> -1,
30171 Pragma_Default_Scalar_Storage_Order
=> 0,
30172 Pragma_Default_Storage_Pool
=> 0,
30173 Pragma_Depends
=> -1,
30174 Pragma_Disable_Atomic_Synchronization
=> 0,
30175 Pragma_Discard_Names
=> 0,
30176 Pragma_Dispatching_Domain
=> -1,
30177 Pragma_Effective_Reads
=> 0,
30178 Pragma_Effective_Writes
=> 0,
30179 Pragma_Elaborate
=> 0,
30180 Pragma_Elaborate_All
=> 0,
30181 Pragma_Elaborate_Body
=> 0,
30182 Pragma_Elaboration_Checks
=> 0,
30183 Pragma_Eliminate
=> 0,
30184 Pragma_Enable_Atomic_Synchronization
=> 0,
30185 Pragma_Export
=> -1,
30186 Pragma_Export_Function
=> -1,
30187 Pragma_Export_Object
=> -1,
30188 Pragma_Export_Procedure
=> -1,
30189 Pragma_Export_Value
=> -1,
30190 Pragma_Export_Valued_Procedure
=> -1,
30191 Pragma_Extend_System
=> -1,
30192 Pragma_Extensions_Allowed
=> 0,
30193 Pragma_Extensions_Visible
=> 0,
30194 Pragma_External
=> -1,
30195 Pragma_Favor_Top_Level
=> 0,
30196 Pragma_External_Name_Casing
=> 0,
30197 Pragma_Fast_Math
=> 0,
30198 Pragma_Finalize_Storage_Only
=> 0,
30200 Pragma_Global
=> -1,
30201 Pragma_Ident
=> -1,
30202 Pragma_Ignore_Pragma
=> 0,
30203 Pragma_Implementation_Defined
=> -1,
30204 Pragma_Implemented
=> -1,
30205 Pragma_Implicit_Packing
=> 0,
30206 Pragma_Import
=> 93,
30207 Pragma_Import_Function
=> 0,
30208 Pragma_Import_Object
=> 0,
30209 Pragma_Import_Procedure
=> 0,
30210 Pragma_Import_Valued_Procedure
=> 0,
30211 Pragma_Independent
=> 0,
30212 Pragma_Independent_Components
=> 0,
30213 Pragma_Initial_Condition
=> -1,
30214 Pragma_Initialize_Scalars
=> 0,
30215 Pragma_Initializes
=> -1,
30216 Pragma_Inline
=> 0,
30217 Pragma_Inline_Always
=> 0,
30218 Pragma_Inline_Generic
=> 0,
30219 Pragma_Inspection_Point
=> -1,
30220 Pragma_Interface
=> 92,
30221 Pragma_Interface_Name
=> 0,
30222 Pragma_Interrupt_Handler
=> -1,
30223 Pragma_Interrupt_Priority
=> -1,
30224 Pragma_Interrupt_State
=> -1,
30225 Pragma_Invariant
=> -1,
30226 Pragma_Keep_Names
=> 0,
30227 Pragma_License
=> 0,
30228 Pragma_Link_With
=> -1,
30229 Pragma_Linker_Alias
=> -1,
30230 Pragma_Linker_Constructor
=> -1,
30231 Pragma_Linker_Destructor
=> -1,
30232 Pragma_Linker_Options
=> -1,
30233 Pragma_Linker_Section
=> -1,
30235 Pragma_Lock_Free
=> 0,
30236 Pragma_Locking_Policy
=> 0,
30237 Pragma_Loop_Invariant
=> -1,
30238 Pragma_Loop_Optimize
=> 0,
30239 Pragma_Loop_Variant
=> -1,
30240 Pragma_Machine_Attribute
=> -1,
30242 Pragma_Main_Storage
=> -1,
30243 Pragma_Max_Entry_Queue_Depth
=> 0,
30244 Pragma_Max_Queue_Length
=> 0,
30245 Pragma_Memory_Size
=> 0,
30246 Pragma_No_Return
=> 0,
30247 Pragma_No_Body
=> 0,
30248 Pragma_No_Component_Reordering
=> -1,
30249 Pragma_No_Elaboration_Code_All
=> 0,
30250 Pragma_No_Heap_Finalization
=> 0,
30251 Pragma_No_Inline
=> 0,
30252 Pragma_No_Run_Time
=> -1,
30253 Pragma_No_Strict_Aliasing
=> -1,
30254 Pragma_No_Tagged_Streams
=> 0,
30255 Pragma_Normalize_Scalars
=> 0,
30256 Pragma_Obsolescent
=> 0,
30257 Pragma_Optimize
=> 0,
30258 Pragma_Optimize_Alignment
=> 0,
30259 Pragma_Overflow_Mode
=> 0,
30260 Pragma_Overriding_Renamings
=> 0,
30261 Pragma_Ordered
=> 0,
30264 Pragma_Part_Of
=> 0,
30265 Pragma_Partition_Elaboration_Policy
=> 0,
30266 Pragma_Passive
=> 0,
30267 Pragma_Persistent_BSS
=> 0,
30268 Pragma_Polling
=> 0,
30269 Pragma_Prefix_Exception_Messages
=> 0,
30271 Pragma_Postcondition
=> -1,
30272 Pragma_Post_Class
=> -1,
30274 Pragma_Precondition
=> -1,
30275 Pragma_Predicate
=> -1,
30276 Pragma_Predicate_Failure
=> -1,
30277 Pragma_Preelaborable_Initialization
=> -1,
30278 Pragma_Preelaborate
=> 0,
30279 Pragma_Pre_Class
=> -1,
30280 Pragma_Priority
=> -1,
30281 Pragma_Priority_Specific_Dispatching
=> 0,
30282 Pragma_Profile
=> 0,
30283 Pragma_Profile_Warnings
=> 0,
30284 Pragma_Propagate_Exceptions
=> 0,
30285 Pragma_Provide_Shift_Operators
=> 0,
30286 Pragma_Psect_Object
=> 0,
30288 Pragma_Pure_Function
=> 0,
30289 Pragma_Queuing_Policy
=> 0,
30290 Pragma_Rational
=> 0,
30291 Pragma_Ravenscar
=> 0,
30292 Pragma_Refined_Depends
=> -1,
30293 Pragma_Refined_Global
=> -1,
30294 Pragma_Refined_Post
=> -1,
30295 Pragma_Refined_State
=> -1,
30296 Pragma_Relative_Deadline
=> 0,
30297 Pragma_Rename_Pragma
=> 0,
30298 Pragma_Remote_Access_Type
=> -1,
30299 Pragma_Remote_Call_Interface
=> -1,
30300 Pragma_Remote_Types
=> -1,
30301 Pragma_Restricted_Run_Time
=> 0,
30302 Pragma_Restriction_Warnings
=> 0,
30303 Pragma_Restrictions
=> 0,
30304 Pragma_Reviewable
=> -1,
30305 Pragma_Secondary_Stack_Size
=> -1,
30306 Pragma_Short_Circuit_And_Or
=> 0,
30307 Pragma_Share_Generic
=> 0,
30308 Pragma_Shared
=> 0,
30309 Pragma_Shared_Passive
=> 0,
30310 Pragma_Short_Descriptors
=> 0,
30311 Pragma_Simple_Storage_Pool_Type
=> 0,
30312 Pragma_Source_File_Name
=> 0,
30313 Pragma_Source_File_Name_Project
=> 0,
30314 Pragma_Source_Reference
=> 0,
30315 Pragma_SPARK_Mode
=> 0,
30316 Pragma_Storage_Size
=> -1,
30317 Pragma_Storage_Unit
=> 0,
30318 Pragma_Static_Elaboration_Desired
=> 0,
30319 Pragma_Stream_Convert
=> 0,
30320 Pragma_Style_Checks
=> 0,
30321 Pragma_Subtitle
=> 0,
30322 Pragma_Suppress
=> 0,
30323 Pragma_Suppress_Exception_Locations
=> 0,
30324 Pragma_Suppress_All
=> 0,
30325 Pragma_Suppress_Debug_Info
=> 0,
30326 Pragma_Suppress_Initialization
=> 0,
30327 Pragma_System_Name
=> 0,
30328 Pragma_Task_Dispatching_Policy
=> 0,
30329 Pragma_Task_Info
=> -1,
30330 Pragma_Task_Name
=> -1,
30331 Pragma_Task_Storage
=> -1,
30332 Pragma_Test_Case
=> -1,
30333 Pragma_Thread_Local_Storage
=> -1,
30334 Pragma_Time_Slice
=> -1,
30336 Pragma_Type_Invariant
=> -1,
30337 Pragma_Type_Invariant_Class
=> -1,
30338 Pragma_Unchecked_Union
=> 0,
30339 Pragma_Unevaluated_Use_Of_Old
=> 0,
30340 Pragma_Unimplemented_Unit
=> 0,
30341 Pragma_Universal_Aliasing
=> 0,
30342 Pragma_Universal_Data
=> 0,
30343 Pragma_Unmodified
=> 0,
30344 Pragma_Unreferenced
=> 0,
30345 Pragma_Unreferenced_Objects
=> 0,
30346 Pragma_Unreserve_All_Interrupts
=> 0,
30347 Pragma_Unsuppress
=> 0,
30348 Pragma_Unused
=> 0,
30349 Pragma_Use_VADS_Size
=> 0,
30350 Pragma_Validity_Checks
=> 0,
30351 Pragma_Volatile
=> 0,
30352 Pragma_Volatile_Components
=> 0,
30353 Pragma_Volatile_Full_Access
=> 0,
30354 Pragma_Volatile_Function
=> 0,
30355 Pragma_Warning_As_Error
=> 0,
30356 Pragma_Warnings
=> 0,
30357 Pragma_Weak_External
=> 0,
30358 Pragma_Wide_Character_Encoding
=> 0,
30359 Unknown_Pragma
=> 0);
30361 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean is
30367 function Arg_No
return Nat
;
30368 -- Returns an integer showing what argument we are in. A value of
30369 -- zero means we are not in any of the arguments.
30375 function Arg_No
return Nat
is
30380 A
:= First
(Pragma_Argument_Associations
(Parent
(P
)));
30394 -- Start of processing for Non_Significant_Pragma_Reference
30399 if Nkind
(P
) /= N_Pragma_Argument_Association
then
30403 Id
:= Get_Pragma_Id
(Parent
(P
));
30404 C
:= Sig_Flags
(Id
);
30419 return AN
< (C
- 90);
30425 end Is_Non_Significant_Pragma_Reference
;
30427 ------------------------------
30428 -- Is_Pragma_String_Literal --
30429 ------------------------------
30431 -- This function returns true if the corresponding pragma argument is a
30432 -- static string expression. These are the only cases in which string
30433 -- literals can appear as pragma arguments. We also allow a string literal
30434 -- as the first argument to pragma Assert (although it will of course
30435 -- always generate a type error).
30437 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean is
30438 Pragn
: constant Node_Id
:= Parent
(Par
);
30439 Assoc
: constant List_Id
:= Pragma_Argument_Associations
(Pragn
);
30440 Pname
: constant Name_Id
:= Pragma_Name
(Pragn
);
30446 N
:= First
(Assoc
);
30453 if Pname
= Name_Assert
then
30456 elsif Pname
= Name_Export
then
30459 elsif Pname
= Name_Ident
then
30462 elsif Pname
= Name_Import
then
30465 elsif Pname
= Name_Interface_Name
then
30468 elsif Pname
= Name_Linker_Alias
then
30471 elsif Pname
= Name_Linker_Section
then
30474 elsif Pname
= Name_Machine_Attribute
then
30477 elsif Pname
= Name_Source_File_Name
then
30480 elsif Pname
= Name_Source_Reference
then
30483 elsif Pname
= Name_Title
then
30486 elsif Pname
= Name_Subtitle
then
30492 end Is_Pragma_String_Literal
;
30494 ---------------------------
30495 -- Is_Private_SPARK_Mode --
30496 ---------------------------
30498 function Is_Private_SPARK_Mode
(N
: Node_Id
) return Boolean is
30501 (Nkind
(N
) = N_Pragma
30502 and then Pragma_Name
(N
) = Name_SPARK_Mode
30503 and then Is_List_Member
(N
));
30505 -- For pragma SPARK_Mode to be private, it has to appear in the private
30506 -- declarations of a package.
30509 Present
(Parent
(N
))
30510 and then Nkind
(Parent
(N
)) = N_Package_Specification
30511 and then List_Containing
(N
) = Private_Declarations
(Parent
(N
));
30512 end Is_Private_SPARK_Mode
;
30514 -------------------------------------
30515 -- Is_Unconstrained_Or_Tagged_Item --
30516 -------------------------------------
30518 function Is_Unconstrained_Or_Tagged_Item
30519 (Item
: Entity_Id
) return Boolean
30521 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean;
30522 -- Determine whether record type Typ has at least one unconstrained
30525 ---------------------------------
30526 -- Has_Unconstrained_Component --
30527 ---------------------------------
30529 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean is
30533 Comp
:= First_Component
(Typ
);
30534 while Present
(Comp
) loop
30535 if Is_Unconstrained_Or_Tagged_Item
(Comp
) then
30539 Next_Component
(Comp
);
30543 end Has_Unconstrained_Component
;
30547 Typ
: constant Entity_Id
:= Etype
(Item
);
30549 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
30552 if Is_Tagged_Type
(Typ
) then
30555 elsif Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
30558 elsif Is_Record_Type
(Typ
) then
30559 if Has_Discriminants
(Typ
) and then not Is_Constrained
(Typ
) then
30562 return Has_Unconstrained_Component
(Typ
);
30565 elsif Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
) then
30571 end Is_Unconstrained_Or_Tagged_Item
;
30573 -----------------------------
30574 -- Is_Valid_Assertion_Kind --
30575 -----------------------------
30577 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean is
30584 | Name_Assertion_Policy
30585 | Name_Static_Predicate
30586 | Name_Dynamic_Predicate
30591 | Name_Type_Invariant
30592 | Name_uType_Invariant
30596 | Name_Assert_And_Cut
30598 | Name_Contract_Cases
30600 | Name_Default_Initial_Condition
30602 | Name_Initial_Condition
30605 | Name_Loop_Invariant
30606 | Name_Loop_Variant
30607 | Name_Postcondition
30608 | Name_Precondition
30610 | Name_Refined_Post
30611 | Name_Statement_Assertions
30618 end Is_Valid_Assertion_Kind
;
30620 --------------------------------------
30621 -- Process_Compilation_Unit_Pragmas --
30622 --------------------------------------
30624 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
) is
30626 -- A special check for pragma Suppress_All, a very strange DEC pragma,
30627 -- strange because it comes at the end of the unit. Rational has the
30628 -- same name for a pragma, but treats it as a program unit pragma, In
30629 -- GNAT we just decide to allow it anywhere at all. If it appeared then
30630 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
30631 -- node, and we insert a pragma Suppress (All_Checks) at the start of
30632 -- the context clause to ensure the correct processing.
30634 if Has_Pragma_Suppress_All
(N
) then
30635 Prepend_To
(Context_Items
(N
),
30636 Make_Pragma
(Sloc
(N
),
30637 Chars
=> Name_Suppress
,
30638 Pragma_Argument_Associations
=> New_List
(
30639 Make_Pragma_Argument_Association
(Sloc
(N
),
30640 Expression
=> Make_Identifier
(Sloc
(N
), Name_All_Checks
)))));
30643 -- Nothing else to do at the current time
30645 end Process_Compilation_Unit_Pragmas
;
30647 -------------------------------------------
30648 -- Process_Compile_Time_Warning_Or_Error --
30649 -------------------------------------------
30651 procedure Process_Compile_Time_Warning_Or_Error
30655 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
30656 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
30657 Arg2
: constant Node_Id
:= Next
(Arg1
);
30660 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
30662 if Compile_Time_Known_Value
(Arg1x
) then
30663 if Is_True
(Expr_Value
(Arg1x
)) then
30665 -- We have already verified that the second argument is a static
30666 -- string expression. Its string value must be retrieved
30667 -- explicitly if it is a declared constant, otherwise it has
30668 -- been constant-folded previously.
30671 Cent
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
30672 Pname
: constant Name_Id
:= Pragma_Name_Unmapped
(N
);
30673 Prag_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Pname
);
30674 Str
: constant String_Id
:=
30675 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg2
)));
30676 Str_Len
: constant Nat
:= String_Length
(Str
);
30678 Force
: constant Boolean :=
30679 Prag_Id
= Pragma_Compile_Time_Warning
30680 and then Is_Spec_Name
(Unit_Name
(Current_Sem_Unit
))
30681 and then (Ekind
(Cent
) /= E_Package
30682 or else not In_Private_Part
(Cent
));
30683 -- Set True if this is the warning case, and we are in the
30684 -- visible part of a package spec, or in a subprogram spec,
30685 -- in which case we want to force the client to see the
30686 -- warning, even though it is not in the main unit.
30694 -- Loop through segments of message separated by line feeds.
30695 -- We output these segments as separate messages with
30696 -- continuation marks for all but the first.
30701 Error_Msg_Strlen
:= 0;
30703 -- Loop to copy characters from argument to error message
30707 exit when Ptr
> Str_Len
;
30708 CC
:= Get_String_Char
(Str
, Ptr
);
30711 -- Ignore wide chars ??? else store character
30713 if In_Character_Range
(CC
) then
30714 C
:= Get_Character
(CC
);
30715 exit when C
= ASCII
.LF
;
30716 Error_Msg_Strlen
:= Error_Msg_Strlen
+ 1;
30717 Error_Msg_String
(Error_Msg_Strlen
) := C
;
30721 -- Here with one line ready to go
30723 Error_Msg_Warn
:= Prag_Id
= Pragma_Compile_Time_Warning
;
30725 -- If this is a warning in a spec, then we want clients
30726 -- to see the warning, so mark the message with the
30727 -- special sequence !! to force the warning. In the case
30728 -- of a package spec, we do not force this if we are in
30729 -- the private part of the spec.
30732 if Cont
= False then
30733 Error_Msg
("<<~!!", Eloc
);
30736 Error_Msg
("\<<~!!", Eloc
);
30739 -- Error, rather than warning, or in a body, so we do not
30740 -- need to force visibility for client (error will be
30741 -- output in any case, and this is the situation in which
30742 -- we do not want a client to get a warning, since the
30743 -- warning is in the body or the spec private part).
30746 if Cont
= False then
30747 Error_Msg
("<<~", Eloc
);
30750 Error_Msg
("\<<~", Eloc
);
30754 exit when Ptr
> Str_Len
;
30759 end Process_Compile_Time_Warning_Or_Error
;
30761 ------------------------------------
30762 -- Record_Possible_Body_Reference --
30763 ------------------------------------
30765 procedure Record_Possible_Body_Reference
30766 (State_Id
: Entity_Id
;
30770 Spec_Id
: Entity_Id
;
30773 -- Ensure that we are dealing with a reference to a state
30775 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
30777 -- Climb the tree starting from the reference looking for a package body
30778 -- whose spec declares the referenced state. This criteria automatically
30779 -- excludes references in package specs which are legal. Note that it is
30780 -- not wise to emit an error now as the package body may lack pragma
30781 -- Refined_State or the referenced state may not be mentioned in the
30782 -- refinement. This approach avoids the generation of misleading errors.
30785 while Present
(Context
) loop
30786 if Nkind
(Context
) = N_Package_Body
then
30787 Spec_Id
:= Corresponding_Spec
(Context
);
30789 if Present
(Abstract_States
(Spec_Id
))
30790 and then Contains
(Abstract_States
(Spec_Id
), State_Id
)
30792 if No
(Body_References
(State_Id
)) then
30793 Set_Body_References
(State_Id
, New_Elmt_List
);
30796 Append_Elmt
(Ref
, To
=> Body_References
(State_Id
));
30801 Context
:= Parent
(Context
);
30803 end Record_Possible_Body_Reference
;
30805 ------------------------------------------
30806 -- Relocate_Pragmas_To_Anonymous_Object --
30807 ------------------------------------------
30809 procedure Relocate_Pragmas_To_Anonymous_Object
30810 (Typ_Decl
: Node_Id
;
30811 Obj_Decl
: Node_Id
)
30815 Next_Decl
: Node_Id
;
30818 if Nkind
(Typ_Decl
) = N_Protected_Type_Declaration
then
30819 Def
:= Protected_Definition
(Typ_Decl
);
30821 pragma Assert
(Nkind
(Typ_Decl
) = N_Task_Type_Declaration
);
30822 Def
:= Task_Definition
(Typ_Decl
);
30825 -- The concurrent definition has a visible declaration list. Inspect it
30826 -- and relocate all canidate pragmas.
30828 if Present
(Def
) and then Present
(Visible_Declarations
(Def
)) then
30829 Decl
:= First
(Visible_Declarations
(Def
));
30830 while Present
(Decl
) loop
30832 -- Preserve the following declaration for iteration purposes due
30833 -- to possible relocation of a pragma.
30835 Next_Decl
:= Next
(Decl
);
30837 if Nkind
(Decl
) = N_Pragma
30838 and then Pragma_On_Anonymous_Object_OK
(Get_Pragma_Id
(Decl
))
30841 Insert_After
(Obj_Decl
, Decl
);
30843 -- Skip internally generated code
30845 elsif not Comes_From_Source
(Decl
) then
30848 -- No candidate pragmas are available for relocation
30857 end Relocate_Pragmas_To_Anonymous_Object
;
30859 ------------------------------
30860 -- Relocate_Pragmas_To_Body --
30861 ------------------------------
30863 procedure Relocate_Pragmas_To_Body
30864 (Subp_Body
: Node_Id
;
30865 Target_Body
: Node_Id
:= Empty
)
30867 procedure Relocate_Pragma
(Prag
: Node_Id
);
30868 -- Remove a single pragma from its current list and add it to the
30869 -- declarations of the proper body (either Subp_Body or Target_Body).
30871 ---------------------
30872 -- Relocate_Pragma --
30873 ---------------------
30875 procedure Relocate_Pragma
(Prag
: Node_Id
) is
30880 -- When subprogram stubs or expression functions are involves, the
30881 -- destination declaration list belongs to the proper body.
30883 if Present
(Target_Body
) then
30884 Target
:= Target_Body
;
30886 Target
:= Subp_Body
;
30889 Decls
:= Declarations
(Target
);
30893 Set_Declarations
(Target
, Decls
);
30896 -- Unhook the pragma from its current list
30899 Prepend
(Prag
, Decls
);
30900 end Relocate_Pragma
;
30904 Body_Id
: constant Entity_Id
:=
30905 Defining_Unit_Name
(Specification
(Subp_Body
));
30906 Next_Stmt
: Node_Id
;
30909 -- Start of processing for Relocate_Pragmas_To_Body
30912 -- Do not process a body that comes from a separate unit as no construct
30913 -- can possibly follow it.
30915 if not Is_List_Member
(Subp_Body
) then
30918 -- Do not relocate pragmas that follow a stub if the stub does not have
30921 elsif Nkind
(Subp_Body
) = N_Subprogram_Body_Stub
30922 and then No
(Target_Body
)
30926 -- Do not process internally generated routine _Postconditions
30928 elsif Ekind
(Body_Id
) = E_Procedure
30929 and then Chars
(Body_Id
) = Name_uPostconditions
30934 -- Look at what is following the body. We are interested in certain kind
30935 -- of pragmas (either from source or byproducts of expansion) that can
30936 -- apply to a body [stub].
30938 Stmt
:= Next
(Subp_Body
);
30939 while Present
(Stmt
) loop
30941 -- Preserve the following statement for iteration purposes due to a
30942 -- possible relocation of a pragma.
30944 Next_Stmt
:= Next
(Stmt
);
30946 -- Move a candidate pragma following the body to the declarations of
30949 if Nkind
(Stmt
) = N_Pragma
30950 and then Pragma_On_Body_Or_Stub_OK
(Get_Pragma_Id
(Stmt
))
30953 -- If a source pragma Warnings follows the body, it applies to
30954 -- following statements and does not belong in the body.
30956 if Get_Pragma_Id
(Stmt
) = Pragma_Warnings
30957 and then Comes_From_Source
(Stmt
)
30961 Relocate_Pragma
(Stmt
);
30964 -- Skip internally generated code
30966 elsif not Comes_From_Source
(Stmt
) then
30969 -- No candidate pragmas are available for relocation
30977 end Relocate_Pragmas_To_Body
;
30979 -------------------
30980 -- Resolve_State --
30981 -------------------
30983 procedure Resolve_State
(N
: Node_Id
) is
30988 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
30989 Func
:= Entity
(N
);
30991 -- Handle overloading of state names by functions. Traverse the
30992 -- homonym chain looking for an abstract state.
30994 if Ekind
(Func
) = E_Function
and then Has_Homonym
(Func
) then
30995 pragma Assert
(Is_Overloaded
(N
));
30997 State
:= Homonym
(Func
);
30998 while Present
(State
) loop
30999 if Ekind
(State
) = E_Abstract_State
then
31001 -- Resolve the overloading by setting the proper entity of
31002 -- the reference to that of the state.
31004 Set_Etype
(N
, Standard_Void_Type
);
31005 Set_Entity
(N
, State
);
31006 Set_Is_Overloaded
(N
, False);
31008 Generate_Reference
(State
, N
);
31012 State
:= Homonym
(State
);
31015 -- A function can never act as a state. If the homonym chain does
31016 -- not contain a corresponding state, then something went wrong in
31017 -- the overloading mechanism.
31019 raise Program_Error
;
31024 ----------------------------
31025 -- Rewrite_Assertion_Kind --
31026 ----------------------------
31028 procedure Rewrite_Assertion_Kind
31030 From_Policy
: Boolean := False)
31036 if Nkind
(N
) = N_Attribute_Reference
31037 and then Attribute_Name
(N
) = Name_Class
31038 and then Nkind
(Prefix
(N
)) = N_Identifier
31040 case Chars
(Prefix
(N
)) is
31047 when Name_Type_Invariant
=>
31048 Nam
:= Name_uType_Invariant
;
31050 when Name_Invariant
=>
31051 Nam
:= Name_uInvariant
;
31057 -- Recommend standard use of aspect names Pre/Post
31059 elsif Nkind
(N
) = N_Identifier
31060 and then From_Policy
31061 and then Serious_Errors_Detected
= 0
31062 and then not ASIS_Mode
31064 if Chars
(N
) = Name_Precondition
31065 or else Chars
(N
) = Name_Postcondition
31067 Error_Msg_N
("Check_Policy is a non-standard pragma??", N
);
31069 ("\use Assertion_Policy and aspect names Pre/Post for "
31070 & "Ada2012 conformance?", N
);
31076 if Nam
/= No_Name
then
31077 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
=> Nam
));
31079 end Rewrite_Assertion_Kind
;
31087 Dummy
:= Dummy
+ 1;
31090 --------------------------------
31091 -- Set_Encoded_Interface_Name --
31092 --------------------------------
31094 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
) is
31095 Str
: constant String_Id
:= Strval
(S
);
31096 Len
: constant Nat
:= String_Length
(Str
);
31101 Hex
: constant array (0 .. 15) of Character := "0123456789abcdef";
31104 -- Stores encoded value of character code CC. The encoding we use an
31105 -- underscore followed by four lower case hex digits.
31111 procedure Encode
is
31113 Store_String_Char
(Get_Char_Code
('_'));
31115 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 12))));
31117 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 8 and 16#
0F#
))));
31119 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 4 and 16#
0F#
))));
31121 (Get_Char_Code
(Hex
(Integer (CC
and 16#
0F#
))));
31124 -- Start of processing for Set_Encoded_Interface_Name
31127 -- If first character is asterisk, this is a link name, and we leave it
31128 -- completely unmodified. We also ignore null strings (the latter case
31129 -- happens only in error cases).
31132 or else Get_String_Char
(Str
, 1) = Get_Char_Code
('*')
31134 Set_Interface_Name
(E
, S
);
31139 CC
:= Get_String_Char
(Str
, J
);
31141 exit when not In_Character_Range
(CC
);
31143 C
:= Get_Character
(CC
);
31145 exit when C
/= '_' and then C
/= '$'
31146 and then C
not in '0' .. '9'
31147 and then C
not in 'a' .. 'z'
31148 and then C
not in 'A' .. 'Z';
31151 Set_Interface_Name
(E
, S
);
31159 -- Here we need to encode. The encoding we use as follows:
31160 -- three underscores + four hex digits (lower case)
31164 for J
in 1 .. String_Length
(Str
) loop
31165 CC
:= Get_String_Char
(Str
, J
);
31167 if not In_Character_Range
(CC
) then
31170 C
:= Get_Character
(CC
);
31172 if C
= '_' or else C
= '$'
31173 or else C
in '0' .. '9'
31174 or else C
in 'a' .. 'z'
31175 or else C
in 'A' .. 'Z'
31177 Store_String_Char
(CC
);
31184 Set_Interface_Name
(E
,
31185 Make_String_Literal
(Sloc
(S
),
31186 Strval
=> End_String
));
31188 end Set_Encoded_Interface_Name
;
31190 ------------------------
31191 -- Set_Elab_Unit_Name --
31192 ------------------------
31194 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
) is
31199 if Nkind
(N
) = N_Identifier
31200 and then Nkind
(With_Item
) = N_Identifier
31202 Set_Entity
(N
, Entity
(With_Item
));
31204 elsif Nkind
(N
) = N_Selected_Component
then
31205 Change_Selected_Component_To_Expanded_Name
(N
);
31206 Set_Entity
(N
, Entity
(With_Item
));
31207 Set_Entity
(Selector_Name
(N
), Entity
(N
));
31209 Pref
:= Prefix
(N
);
31210 Scop
:= Scope
(Entity
(N
));
31211 while Nkind
(Pref
) = N_Selected_Component
loop
31212 Change_Selected_Component_To_Expanded_Name
(Pref
);
31213 Set_Entity
(Selector_Name
(Pref
), Scop
);
31214 Set_Entity
(Pref
, Scop
);
31215 Pref
:= Prefix
(Pref
);
31216 Scop
:= Scope
(Scop
);
31219 Set_Entity
(Pref
, Scop
);
31222 Generate_Reference
(Entity
(With_Item
), N
, Set_Ref
=> False);
31223 end Set_Elab_Unit_Name
;
31225 -------------------
31226 -- Test_Case_Arg --
31227 -------------------
31229 function Test_Case_Arg
31232 From_Aspect
: Boolean := False) return Node_Id
31234 Aspect
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
31239 pragma Assert
(Nam_In
(Arg_Nam
, Name_Ensures
,
31244 -- The caller requests the aspect argument
31246 if From_Aspect
then
31247 if Present
(Aspect
)
31248 and then Nkind
(Expression
(Aspect
)) = N_Aggregate
31250 Args
:= Expression
(Aspect
);
31252 -- "Name" and "Mode" may appear without an identifier as a
31253 -- positional association.
31255 if Present
(Expressions
(Args
)) then
31256 Arg
:= First
(Expressions
(Args
));
31258 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
31266 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
31271 -- Some or all arguments may appear as component associatons
31273 if Present
(Component_Associations
(Args
)) then
31274 Arg
:= First
(Component_Associations
(Args
));
31275 while Present
(Arg
) loop
31276 if Chars
(First
(Choices
(Arg
))) = Arg_Nam
then
31285 -- Otherwise retrieve the argument directly from the pragma
31288 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
31290 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
31294 -- Skip argument "Name"
31298 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
31302 -- Skip argument "Mode"
31306 -- Arguments "Requires" and "Ensures" are optional and may not be
31309 while Present
(Arg
) loop
31310 if Chars
(Arg
) = Arg_Nam
then