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 -- Save the Ghost mode to restore on exit
475 Restore_Scope
: Boolean := False;
477 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
480 -- Do not analyze the pragma multiple times
482 if Is_Analyzed_Pragma
(N
) then
486 -- Set the Ghost mode in effect from the pragma. Due to the delayed
487 -- analysis of the pragma, the Ghost mode at point of declaration and
488 -- point of analysis may not necessarily be the same. Use the mode in
489 -- effect at the point of declaration.
493 -- Single and multiple contract cases must appear in aggregate form. If
494 -- this is not the case, then either the parser of the analysis of the
495 -- pragma failed to produce an aggregate.
497 pragma Assert
(Nkind
(CCases
) = N_Aggregate
);
499 if Present
(Component_Associations
(CCases
)) then
501 -- Ensure that the formal parameters are visible when analyzing all
502 -- clauses. This falls out of the general rule of aspects pertaining
503 -- to subprogram declarations.
505 if not In_Open_Scopes
(Spec_Id
) then
506 Restore_Scope
:= True;
507 Push_Scope
(Spec_Id
);
509 if Is_Generic_Subprogram
(Spec_Id
) then
510 Install_Generic_Formals
(Spec_Id
);
512 Install_Formals
(Spec_Id
);
516 CCase
:= First
(Component_Associations
(CCases
));
517 while Present
(CCase
) loop
518 Analyze_Contract_Case
(CCase
);
522 if Restore_Scope
then
526 -- Currently it is not possible to inline pre/postconditions on a
527 -- subprogram subject to pragma Inline_Always.
529 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
531 -- Otherwise the pragma is illegal
534 Error_Msg_N
("wrong syntax for constract cases", N
);
537 Set_Is_Analyzed_Pragma
(N
);
539 Restore_Ghost_Mode
(Saved_GM
);
540 end Analyze_Contract_Cases_In_Decl_Part
;
542 ----------------------------------
543 -- Analyze_Depends_In_Decl_Part --
544 ----------------------------------
546 procedure Analyze_Depends_In_Decl_Part
(N
: Node_Id
) is
547 Loc
: constant Source_Ptr
:= Sloc
(N
);
548 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
549 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
551 All_Inputs_Seen
: Elist_Id
:= No_Elist
;
552 -- A list containing the entities of all the inputs processed so far.
553 -- The list is populated with unique entities because the same input
554 -- may appear in multiple input lists.
556 All_Outputs_Seen
: Elist_Id
:= No_Elist
;
557 -- A list containing the entities of all the outputs processed so far.
558 -- The list is populated with unique entities because output items are
559 -- unique in a dependence relation.
561 Constits_Seen
: Elist_Id
:= No_Elist
;
562 -- A list containing the entities of all constituents processed so far.
563 -- It aids in detecting illegal usage of a state and a corresponding
564 -- constituent in pragma [Refinde_]Depends.
566 Global_Seen
: Boolean := False;
567 -- A flag set when pragma Global has been processed
569 Null_Output_Seen
: Boolean := False;
570 -- A flag used to track the legality of a null output
572 Result_Seen
: Boolean := False;
573 -- A flag set when Spec_Id'Result is processed
575 States_Seen
: Elist_Id
:= No_Elist
;
576 -- A list containing the entities of all states processed so far. It
577 -- helps in detecting illegal usage of a state and a corresponding
578 -- constituent in pragma [Refined_]Depends.
580 Subp_Inputs
: Elist_Id
:= No_Elist
;
581 Subp_Outputs
: Elist_Id
:= No_Elist
;
582 -- Two lists containing the full set of inputs and output of the related
583 -- subprograms. Note that these lists contain both nodes and entities.
585 Task_Input_Seen
: Boolean := False;
586 Task_Output_Seen
: Boolean := False;
587 -- Flags used to track the implicit dependence of a task unit on itself
589 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
);
590 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
591 -- to the name buffer. The individual kinds are as follows:
592 -- E_Abstract_State - "state"
593 -- E_Constant - "constant"
594 -- E_Generic_In_Out_Parameter - "generic parameter"
595 -- E_Generic_In_Parameter - "generic parameter"
596 -- E_In_Parameter - "parameter"
597 -- E_In_Out_Parameter - "parameter"
598 -- E_Loop_Parameter - "loop parameter"
599 -- E_Out_Parameter - "parameter"
600 -- E_Protected_Type - "current instance of protected type"
601 -- E_Task_Type - "current instance of task type"
602 -- E_Variable - "global"
604 procedure Analyze_Dependency_Clause
607 -- Verify the legality of a single dependency clause. Flag Is_Last
608 -- denotes whether Clause is the last clause in the relation.
610 procedure Check_Function_Return
;
611 -- Verify that Funtion'Result appears as one of the outputs
612 -- (SPARK RM 6.1.5(10)).
619 -- Ensure that an item fulfills its designated input and/or output role
620 -- as specified by pragma Global (if any) or the enclosing context. If
621 -- this is not the case, emit an error. Item and Item_Id denote the
622 -- attributes of an item. Flag Is_Input should be set when item comes
623 -- from an input list. Flag Self_Ref should be set when the item is an
624 -- output and the dependency clause has operator "+".
626 procedure Check_Usage
627 (Subp_Items
: Elist_Id
;
628 Used_Items
: Elist_Id
;
630 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
631 -- error if this is not the case.
633 procedure Normalize_Clause
(Clause
: Node_Id
);
634 -- Remove a self-dependency "+" from the input list of a clause
636 -----------------------------
637 -- Add_Item_To_Name_Buffer --
638 -----------------------------
640 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
) is
642 if Ekind
(Item_Id
) = E_Abstract_State
then
643 Add_Str_To_Name_Buffer
("state");
645 elsif Ekind
(Item_Id
) = E_Constant
then
646 Add_Str_To_Name_Buffer
("constant");
648 elsif Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
649 E_Generic_In_Parameter
)
651 Add_Str_To_Name_Buffer
("generic parameter");
653 elsif Is_Formal
(Item_Id
) then
654 Add_Str_To_Name_Buffer
("parameter");
656 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
657 Add_Str_To_Name_Buffer
("loop parameter");
659 elsif Ekind
(Item_Id
) = E_Protected_Type
660 or else Is_Single_Protected_Object
(Item_Id
)
662 Add_Str_To_Name_Buffer
("current instance of protected type");
664 elsif Ekind
(Item_Id
) = E_Task_Type
665 or else Is_Single_Task_Object
(Item_Id
)
667 Add_Str_To_Name_Buffer
("current instance of task type");
669 elsif Ekind
(Item_Id
) = E_Variable
then
670 Add_Str_To_Name_Buffer
("global");
672 -- The routine should not be called with non-SPARK items
677 end Add_Item_To_Name_Buffer
;
679 -------------------------------
680 -- Analyze_Dependency_Clause --
681 -------------------------------
683 procedure Analyze_Dependency_Clause
687 procedure Analyze_Input_List
(Inputs
: Node_Id
);
688 -- Verify the legality of a single input list
690 procedure Analyze_Input_Output
695 Seen
: in out Elist_Id
;
696 Null_Seen
: in out Boolean;
697 Non_Null_Seen
: in out Boolean);
698 -- Verify the legality of a single input or output item. Flag
699 -- Is_Input should be set whenever Item is an input, False when it
700 -- denotes an output. Flag Self_Ref should be set when the item is an
701 -- output and the dependency clause has a "+". Flag Top_Level should
702 -- be set whenever Item appears immediately within an input or output
703 -- list. Seen is a collection of all abstract states, objects and
704 -- formals processed so far. Flag Null_Seen denotes whether a null
705 -- input or output has been encountered. Flag Non_Null_Seen denotes
706 -- whether a non-null input or output has been encountered.
708 ------------------------
709 -- Analyze_Input_List --
710 ------------------------
712 procedure Analyze_Input_List
(Inputs
: Node_Id
) is
713 Inputs_Seen
: Elist_Id
:= No_Elist
;
714 -- A list containing the entities of all inputs that appear in the
715 -- current input list.
717 Non_Null_Input_Seen
: Boolean := False;
718 Null_Input_Seen
: Boolean := False;
719 -- Flags used to check the legality of an input list
724 -- Multiple inputs appear as an aggregate
726 if Nkind
(Inputs
) = N_Aggregate
then
727 if Present
(Component_Associations
(Inputs
)) then
729 ("nested dependency relations not allowed", Inputs
);
731 elsif Present
(Expressions
(Inputs
)) then
732 Input
:= First
(Expressions
(Inputs
));
733 while Present
(Input
) loop
740 Null_Seen
=> Null_Input_Seen
,
741 Non_Null_Seen
=> Non_Null_Input_Seen
);
746 -- Syntax error, always report
749 Error_Msg_N
("malformed input dependency list", Inputs
);
752 -- Process a solitary input
761 Null_Seen
=> Null_Input_Seen
,
762 Non_Null_Seen
=> Non_Null_Input_Seen
);
765 -- Detect an illegal dependency clause of the form
769 if Null_Output_Seen
and then Null_Input_Seen
then
771 ("null dependency clause cannot have a null input list",
774 end Analyze_Input_List
;
776 --------------------------
777 -- Analyze_Input_Output --
778 --------------------------
780 procedure Analyze_Input_Output
785 Seen
: in out Elist_Id
;
786 Null_Seen
: in out Boolean;
787 Non_Null_Seen
: in out Boolean)
789 procedure Current_Task_Instance_Seen
;
790 -- Set the appropriate global flag when the current instance of a
791 -- task unit is encountered.
793 --------------------------------
794 -- Current_Task_Instance_Seen --
795 --------------------------------
797 procedure Current_Task_Instance_Seen
is
800 Task_Input_Seen
:= True;
802 Task_Output_Seen
:= True;
804 end Current_Task_Instance_Seen
;
808 Is_Output
: constant Boolean := not Is_Input
;
812 -- Start of processing for Analyze_Input_Output
815 -- Multiple input or output items appear as an aggregate
817 if Nkind
(Item
) = N_Aggregate
then
818 if not Top_Level
then
819 SPARK_Msg_N
("nested grouping of items not allowed", Item
);
821 elsif Present
(Component_Associations
(Item
)) then
823 ("nested dependency relations not allowed", Item
);
825 -- Recursively analyze the grouped items
827 elsif Present
(Expressions
(Item
)) then
828 Grouped
:= First
(Expressions
(Item
));
829 while Present
(Grouped
) loop
832 Is_Input
=> Is_Input
,
833 Self_Ref
=> Self_Ref
,
836 Null_Seen
=> Null_Seen
,
837 Non_Null_Seen
=> Non_Null_Seen
);
842 -- Syntax error, always report
845 Error_Msg_N
("malformed dependency list", Item
);
848 -- Process attribute 'Result in the context of a dependency clause
850 elsif Is_Attribute_Result
(Item
) then
851 Non_Null_Seen
:= True;
855 -- Attribute 'Result is allowed to appear on the output side of
856 -- a dependency clause (SPARK RM 6.1.5(6)).
859 SPARK_Msg_N
("function result cannot act as input", Item
);
863 ("cannot mix null and non-null dependency items", Item
);
869 -- Detect multiple uses of null in a single dependency list or
870 -- throughout the whole relation. Verify the placement of a null
871 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
873 elsif Nkind
(Item
) = N_Null
then
876 ("multiple null dependency relations not allowed", Item
);
878 elsif Non_Null_Seen
then
880 ("cannot mix null and non-null dependency items", Item
);
888 ("null output list must be the last clause in a "
889 & "dependency relation", Item
);
891 -- Catch a useless dependence of the form:
896 ("useless dependence, null depends on itself", Item
);
904 Non_Null_Seen
:= True;
907 SPARK_Msg_N
("cannot mix null and non-null items", Item
);
911 Resolve_State
(Item
);
913 -- Find the entity of the item. If this is a renaming, climb
914 -- the renaming chain to reach the root object. Renamings of
915 -- non-entire objects do not yield an entity (Empty).
917 Item_Id
:= Entity_Of
(Item
);
919 if Present
(Item_Id
) then
923 if Ekind_In
(Item_Id
, E_Constant
, E_Loop_Parameter
)
926 -- Current instances of concurrent types
928 Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
)
933 Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
934 E_Generic_In_Parameter
,
942 Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
)
944 -- The item denotes a concurrent type. Note that single
945 -- protected/task types are not considered here because
946 -- they behave as objects in the context of pragma
947 -- [Refined_]Depends.
949 if Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
951 -- This use is legal as long as the concurrent type is
952 -- the current instance of an enclosing type.
954 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
956 -- The dependence of a task unit on itself is
957 -- implicit and may or may not be explicitly
958 -- specified (SPARK RM 6.1.4).
960 if Ekind
(Item_Id
) = E_Task_Type
then
961 Current_Task_Instance_Seen
;
964 -- Otherwise this is not the current instance
968 ("invalid use of subtype mark in dependency "
972 -- The dependency of a task unit on itself is implicit
973 -- and may or may not be explicitly specified
976 elsif Is_Single_Task_Object
(Item_Id
)
977 and then Is_CCT_Instance
(Etype
(Item_Id
), Spec_Id
)
979 Current_Task_Instance_Seen
;
982 -- Ensure that the item fulfills its role as input and/or
983 -- output as specified by pragma Global or the enclosing
986 Check_Role
(Item
, Item_Id
, Is_Input
, Self_Ref
);
988 -- Detect multiple uses of the same state, variable or
989 -- formal parameter. If this is not the case, add the
990 -- item to the list of processed relations.
992 if Contains
(Seen
, Item_Id
) then
994 ("duplicate use of item &", Item
, Item_Id
);
996 Append_New_Elmt
(Item_Id
, Seen
);
999 -- Detect illegal use of an input related to a null
1000 -- output. Such input items cannot appear in other
1001 -- input lists (SPARK RM 6.1.5(13)).
1004 and then Null_Output_Seen
1005 and then Contains
(All_Inputs_Seen
, Item_Id
)
1008 ("input of a null output list cannot appear in "
1009 & "multiple input lists", Item
);
1012 -- Add an input or a self-referential output to the list
1013 -- of all processed inputs.
1015 if Is_Input
or else Self_Ref
then
1016 Append_New_Elmt
(Item_Id
, All_Inputs_Seen
);
1019 -- State related checks (SPARK RM 6.1.5(3))
1021 if Ekind
(Item_Id
) = E_Abstract_State
then
1023 -- Package and subprogram bodies are instantiated
1024 -- individually in a separate compiler pass. Due to
1025 -- this mode of instantiation, the refinement of a
1026 -- state may no longer be visible when a subprogram
1027 -- body contract is instantiated. Since the generic
1028 -- template is legal, do not perform this check in
1029 -- the instance to circumvent this oddity.
1031 if Is_Generic_Instance
(Spec_Id
) then
1034 -- An abstract state with visible refinement cannot
1035 -- appear in pragma [Refined_]Depends as its place
1036 -- must be taken by some of its constituents
1037 -- (SPARK RM 6.1.4(7)).
1039 elsif Has_Visible_Refinement
(Item_Id
) then
1041 ("cannot mention state & in dependence relation",
1043 SPARK_Msg_N
("\use its constituents instead", Item
);
1046 -- If the reference to the abstract state appears in
1047 -- an enclosing package body that will eventually
1048 -- refine the state, record the reference for future
1052 Record_Possible_Body_Reference
1053 (State_Id
=> Item_Id
,
1058 -- When the item renames an entire object, replace the
1059 -- item with a reference to the object.
1061 if Entity
(Item
) /= Item_Id
then
1063 New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
1067 -- Add the entity of the current item to the list of
1070 if Ekind
(Item_Id
) = E_Abstract_State
then
1071 Append_New_Elmt
(Item_Id
, States_Seen
);
1073 -- The variable may eventually become a constituent of a
1074 -- single protected/task type. Record the reference now
1075 -- and verify its legality when analyzing the contract of
1076 -- the variable (SPARK RM 9.3).
1078 elsif Ekind
(Item_Id
) = E_Variable
then
1079 Record_Possible_Part_Of_Reference
1084 if Ekind_In
(Item_Id
, E_Abstract_State
,
1087 and then Present
(Encapsulating_State
(Item_Id
))
1089 Append_New_Elmt
(Item_Id
, Constits_Seen
);
1092 -- All other input/output items are illegal
1093 -- (SPARK RM 6.1.5(1)).
1097 ("item must denote parameter, variable, state or "
1098 & "current instance of concurrent type", Item
);
1101 -- All other input/output items are illegal
1102 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1106 ("item must denote parameter, variable, state or current "
1107 & "instance of concurrent type", Item
);
1110 end Analyze_Input_Output
;
1118 Non_Null_Output_Seen
: Boolean := False;
1119 -- Flag used to check the legality of an output list
1121 -- Start of processing for Analyze_Dependency_Clause
1124 Inputs
:= Expression
(Clause
);
1127 -- An input list with a self-dependency appears as operator "+" where
1128 -- the actuals inputs are the right operand.
1130 if Nkind
(Inputs
) = N_Op_Plus
then
1131 Inputs
:= Right_Opnd
(Inputs
);
1135 -- Process the output_list of a dependency_clause
1137 Output
:= First
(Choices
(Clause
));
1138 while Present
(Output
) loop
1139 Analyze_Input_Output
1142 Self_Ref
=> Self_Ref
,
1144 Seen
=> All_Outputs_Seen
,
1145 Null_Seen
=> Null_Output_Seen
,
1146 Non_Null_Seen
=> Non_Null_Output_Seen
);
1151 -- Process the input_list of a dependency_clause
1153 Analyze_Input_List
(Inputs
);
1154 end Analyze_Dependency_Clause
;
1156 ---------------------------
1157 -- Check_Function_Return --
1158 ---------------------------
1160 procedure Check_Function_Return
is
1162 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
1163 and then not Result_Seen
1166 ("result of & must appear in exactly one output list",
1169 end Check_Function_Return
;
1175 procedure Check_Role
1177 Item_Id
: Entity_Id
;
1182 (Item_Is_Input
: out Boolean;
1183 Item_Is_Output
: out Boolean);
1184 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1185 -- Item_Is_Output are set depending on the role.
1187 procedure Role_Error
1188 (Item_Is_Input
: Boolean;
1189 Item_Is_Output
: Boolean);
1190 -- Emit an error message concerning the incorrect use of Item in
1191 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1192 -- denote whether the item is an input and/or an output.
1199 (Item_Is_Input
: out Boolean;
1200 Item_Is_Output
: out Boolean)
1203 case Ekind
(Item_Id
) is
1207 when E_Abstract_State
=>
1209 -- When pragma Global is present it determines the mode of
1210 -- the abstract state.
1213 Item_Is_Input
:= Appears_In
(Subp_Inputs
, Item_Id
);
1214 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1216 -- Otherwise the state has a default IN OUT mode, because it
1217 -- behaves as a variable.
1220 Item_Is_Input
:= True;
1221 Item_Is_Output
:= True;
1224 -- Constants and IN parameters
1227 | E_Generic_In_Parameter
1231 -- When pragma Global is present it determines the mode
1232 -- of constant objects as inputs (and such objects cannot
1233 -- appear as outputs in the Global contract).
1236 Item_Is_Input
:= Appears_In
(Subp_Inputs
, Item_Id
);
1238 Item_Is_Input
:= True;
1241 Item_Is_Output
:= False;
1243 -- Variables and IN OUT parameters
1245 when E_Generic_In_Out_Parameter
1246 | E_In_Out_Parameter
1249 -- When pragma Global is present it determines the mode of
1254 -- A variable has mode IN when its type is unconstrained
1255 -- or tagged because array bounds, discriminants or tags
1259 Appears_In
(Subp_Inputs
, Item_Id
)
1260 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1262 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1264 -- Otherwise the variable has a default IN OUT mode
1267 Item_Is_Input
:= True;
1268 Item_Is_Output
:= True;
1271 when E_Out_Parameter
=>
1273 -- An OUT parameter of the related subprogram; it cannot
1274 -- appear in Global.
1276 if Scope
(Item_Id
) = Spec_Id
then
1278 -- The parameter has mode IN if its type is unconstrained
1279 -- or tagged because array bounds, discriminants or tags
1283 Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1285 Item_Is_Output
:= True;
1287 -- An OUT parameter of an enclosing subprogram; it can
1288 -- appear in Global and behaves as a read-write variable.
1291 -- When pragma Global is present it determines the mode
1296 -- A variable has mode IN when its type is
1297 -- unconstrained or tagged because array
1298 -- bounds, discriminants or tags can be read.
1301 Appears_In
(Subp_Inputs
, Item_Id
)
1302 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1304 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1306 -- Otherwise the variable has a default IN OUT mode
1309 Item_Is_Input
:= True;
1310 Item_Is_Output
:= True;
1316 when E_Protected_Type
=>
1319 -- A variable has mode IN when its type is unconstrained
1320 -- or tagged because array bounds, discriminants or tags
1324 Appears_In
(Subp_Inputs
, Item_Id
)
1325 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1327 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1330 -- A protected type acts as a formal parameter of mode IN
1331 -- when it applies to a protected function.
1333 if Ekind
(Spec_Id
) = E_Function
then
1334 Item_Is_Input
:= True;
1335 Item_Is_Output
:= False;
1337 -- Otherwise the protected type acts as a formal of mode
1341 Item_Is_Input
:= True;
1342 Item_Is_Output
:= True;
1350 -- When pragma Global is present it determines the mode of
1355 Appears_In
(Subp_Inputs
, Item_Id
)
1356 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
);
1358 Item_Is_Output
:= Appears_In
(Subp_Outputs
, Item_Id
);
1360 -- Otherwise task types act as IN OUT parameters
1363 Item_Is_Input
:= True;
1364 Item_Is_Output
:= True;
1368 raise Program_Error
;
1376 procedure Role_Error
1377 (Item_Is_Input
: Boolean;
1378 Item_Is_Output
: Boolean)
1380 Error_Msg
: Name_Id
;
1385 -- When the item is not part of the input and the output set of
1386 -- the related subprogram, then it appears as extra in pragma
1387 -- [Refined_]Depends.
1389 if not Item_Is_Input
and then not Item_Is_Output
then
1390 Add_Item_To_Name_Buffer
(Item_Id
);
1391 Add_Str_To_Name_Buffer
1392 (" & cannot appear in dependence relation");
1394 Error_Msg
:= Name_Find
;
1395 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1397 Error_Msg_Name_1
:= Chars
(Spec_Id
);
1399 (Fix_Msg
(Spec_Id
, "\& is not part of the input or output "
1400 & "set of subprogram %"), Item
, Item_Id
);
1402 -- The mode of the item and its role in pragma [Refined_]Depends
1403 -- are in conflict. Construct a detailed message explaining the
1404 -- illegality (SPARK RM 6.1.5(5-6)).
1407 if Item_Is_Input
then
1408 Add_Str_To_Name_Buffer
("read-only");
1410 Add_Str_To_Name_Buffer
("write-only");
1413 Add_Char_To_Name_Buffer
(' ');
1414 Add_Item_To_Name_Buffer
(Item_Id
);
1415 Add_Str_To_Name_Buffer
(" & cannot appear as ");
1417 if Item_Is_Input
then
1418 Add_Str_To_Name_Buffer
("output");
1420 Add_Str_To_Name_Buffer
("input");
1423 Add_Str_To_Name_Buffer
(" in dependence relation");
1424 Error_Msg
:= Name_Find
;
1425 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1431 Item_Is_Input
: Boolean;
1432 Item_Is_Output
: Boolean;
1434 -- Start of processing for Check_Role
1437 Find_Role
(Item_Is_Input
, Item_Is_Output
);
1442 if not Item_Is_Input
then
1443 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1446 -- Self-referential item
1449 if not Item_Is_Input
or else not Item_Is_Output
then
1450 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1455 elsif not Item_Is_Output
then
1456 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1464 procedure Check_Usage
1465 (Subp_Items
: Elist_Id
;
1466 Used_Items
: Elist_Id
;
1469 procedure Usage_Error
(Item_Id
: Entity_Id
);
1470 -- Emit an error concerning the illegal usage of an item
1476 procedure Usage_Error
(Item_Id
: Entity_Id
) is
1477 Error_Msg
: Name_Id
;
1484 -- Unconstrained and tagged items are not part of the explicit
1485 -- input set of the related subprogram, they do not have to be
1486 -- present in a dependence relation and should not be flagged
1487 -- (SPARK RM 6.1.5(5)).
1489 if not Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1492 Add_Item_To_Name_Buffer
(Item_Id
);
1493 Add_Str_To_Name_Buffer
1494 (" & is missing from input dependence list");
1496 Error_Msg
:= Name_Find
;
1497 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1499 ("\add `null ='> &` dependency to ignore this input",
1503 -- Output case (SPARK RM 6.1.5(10))
1508 Add_Item_To_Name_Buffer
(Item_Id
);
1509 Add_Str_To_Name_Buffer
1510 (" & is missing from output dependence list");
1512 Error_Msg
:= Name_Find
;
1513 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1521 Item_Id
: Entity_Id
;
1523 -- Start of processing for Check_Usage
1526 if No
(Subp_Items
) then
1530 -- Each input or output of the subprogram must appear in a dependency
1533 Elmt
:= First_Elmt
(Subp_Items
);
1534 while Present
(Elmt
) loop
1535 Item
:= Node
(Elmt
);
1537 if Nkind
(Item
) = N_Defining_Identifier
then
1540 Item_Id
:= Entity_Of
(Item
);
1543 -- The item does not appear in a dependency
1545 if Present
(Item_Id
)
1546 and then not Contains
(Used_Items
, Item_Id
)
1548 if Is_Formal
(Item_Id
) then
1549 Usage_Error
(Item_Id
);
1551 -- The current instance of a protected type behaves as a formal
1552 -- parameter (SPARK RM 6.1.4).
1554 elsif Ekind
(Item_Id
) = E_Protected_Type
1555 or else Is_Single_Protected_Object
(Item_Id
)
1557 Usage_Error
(Item_Id
);
1559 -- The current instance of a task type behaves as a formal
1560 -- parameter (SPARK RM 6.1.4).
1562 elsif Ekind
(Item_Id
) = E_Task_Type
1563 or else Is_Single_Task_Object
(Item_Id
)
1565 -- The dependence of a task unit on itself is implicit and
1566 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1567 -- Emit an error if only one input/output is present.
1569 if Task_Input_Seen
/= Task_Output_Seen
then
1570 Usage_Error
(Item_Id
);
1573 -- States and global objects are not used properly only when
1574 -- the subprogram is subject to pragma Global.
1576 elsif Global_Seen
then
1577 Usage_Error
(Item_Id
);
1585 ----------------------
1586 -- Normalize_Clause --
1587 ----------------------
1589 procedure Normalize_Clause
(Clause
: Node_Id
) is
1590 procedure Create_Or_Modify_Clause
1596 Multiple
: Boolean);
1597 -- Create a brand new clause to represent the self-reference or
1598 -- modify the input and/or output lists of an existing clause. Output
1599 -- denotes a self-referencial output. Outputs is the output list of a
1600 -- clause. Inputs is the input list of a clause. After denotes the
1601 -- clause after which the new clause is to be inserted. Flag In_Place
1602 -- should be set when normalizing the last output of an output list.
1603 -- Flag Multiple should be set when Output comes from a list with
1606 -----------------------------
1607 -- Create_Or_Modify_Clause --
1608 -----------------------------
1610 procedure Create_Or_Modify_Clause
1618 procedure Propagate_Output
1621 -- Handle the various cases of output propagation to the input
1622 -- list. Output denotes a self-referencial output item. Inputs
1623 -- is the input list of a clause.
1625 ----------------------
1626 -- Propagate_Output --
1627 ----------------------
1629 procedure Propagate_Output
1633 function In_Input_List
1635 Inputs
: List_Id
) return Boolean;
1636 -- Determine whether a particulat item appears in the input
1637 -- list of a clause.
1643 function In_Input_List
1645 Inputs
: List_Id
) return Boolean
1650 Elmt
:= First
(Inputs
);
1651 while Present
(Elmt
) loop
1652 if Entity_Of
(Elmt
) = Item
then
1664 Output_Id
: constant Entity_Id
:= Entity_Of
(Output
);
1667 -- Start of processing for Propagate_Output
1670 -- The clause is of the form:
1672 -- (Output =>+ null)
1674 -- Remove null input and replace it with a copy of the output:
1676 -- (Output => Output)
1678 if Nkind
(Inputs
) = N_Null
then
1679 Rewrite
(Inputs
, New_Copy_Tree
(Output
));
1681 -- The clause is of the form:
1683 -- (Output =>+ (Input1, ..., InputN))
1685 -- Determine whether the output is not already mentioned in the
1686 -- input list and if not, add it to the list of inputs:
1688 -- (Output => (Output, Input1, ..., InputN))
1690 elsif Nkind
(Inputs
) = N_Aggregate
then
1691 Grouped
:= Expressions
(Inputs
);
1693 if not In_Input_List
1697 Prepend_To
(Grouped
, New_Copy_Tree
(Output
));
1700 -- The clause is of the form:
1702 -- (Output =>+ Input)
1704 -- If the input does not mention the output, group the two
1707 -- (Output => (Output, Input))
1709 elsif Entity_Of
(Inputs
) /= Output_Id
then
1711 Make_Aggregate
(Loc
,
1712 Expressions
=> New_List
(
1713 New_Copy_Tree
(Output
),
1714 New_Copy_Tree
(Inputs
))));
1716 end Propagate_Output
;
1720 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
1721 New_Clause
: Node_Id
;
1723 -- Start of processing for Create_Or_Modify_Clause
1726 -- A null output depending on itself does not require any
1729 if Nkind
(Output
) = N_Null
then
1732 -- A function result cannot depend on itself because it cannot
1733 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1735 elsif Is_Attribute_Result
(Output
) then
1736 SPARK_Msg_N
("function result cannot depend on itself", Output
);
1740 -- When performing the transformation in place, simply add the
1741 -- output to the list of inputs (if not already there). This
1742 -- case arises when dealing with the last output of an output
1743 -- list. Perform the normalization in place to avoid generating
1744 -- a malformed tree.
1747 Propagate_Output
(Output
, Inputs
);
1749 -- A list with multiple outputs is slowly trimmed until only
1750 -- one element remains. When this happens, replace aggregate
1751 -- with the element itself.
1755 Rewrite
(Outputs
, Output
);
1761 -- Unchain the output from its output list as it will appear in
1762 -- a new clause. Note that we cannot simply rewrite the output
1763 -- as null because this will violate the semantics of pragma
1768 -- Generate a new clause of the form:
1769 -- (Output => Inputs)
1772 Make_Component_Association
(Loc
,
1773 Choices
=> New_List
(Output
),
1774 Expression
=> New_Copy_Tree
(Inputs
));
1776 -- The new clause contains replicated content that has already
1777 -- been analyzed. There is not need to reanalyze or renormalize
1780 Set_Analyzed
(New_Clause
);
1783 (Output
=> First
(Choices
(New_Clause
)),
1784 Inputs
=> Expression
(New_Clause
));
1786 Insert_After
(After
, New_Clause
);
1788 end Create_Or_Modify_Clause
;
1792 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
1794 Last_Output
: Node_Id
;
1795 Next_Output
: Node_Id
;
1798 -- Start of processing for Normalize_Clause
1801 -- A self-dependency appears as operator "+". Remove the "+" from the
1802 -- tree by moving the real inputs to their proper place.
1804 if Nkind
(Expression
(Clause
)) = N_Op_Plus
then
1805 Rewrite
(Expression
(Clause
), Right_Opnd
(Expression
(Clause
)));
1806 Inputs
:= Expression
(Clause
);
1808 -- Multiple outputs appear as an aggregate
1810 if Nkind
(Outputs
) = N_Aggregate
then
1811 Last_Output
:= Last
(Expressions
(Outputs
));
1813 Output
:= First
(Expressions
(Outputs
));
1814 while Present
(Output
) loop
1816 -- Normalization may remove an output from its list,
1817 -- preserve the subsequent output now.
1819 Next_Output
:= Next
(Output
);
1821 Create_Or_Modify_Clause
1826 In_Place
=> Output
= Last_Output
,
1829 Output
:= Next_Output
;
1835 Create_Or_Modify_Clause
1844 end Normalize_Clause
;
1848 Deps
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
1849 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
1853 Last_Clause
: Node_Id
;
1854 Restore_Scope
: Boolean := False;
1856 -- Start of processing for Analyze_Depends_In_Decl_Part
1859 -- Do not analyze the pragma multiple times
1861 if Is_Analyzed_Pragma
(N
) then
1865 -- Empty dependency list
1867 if Nkind
(Deps
) = N_Null
then
1869 -- Gather all states, objects and formal parameters that the
1870 -- subprogram may depend on. These items are obtained from the
1871 -- parameter profile or pragma [Refined_]Global (if available).
1873 Collect_Subprogram_Inputs_Outputs
1874 (Subp_Id
=> Subp_Id
,
1875 Subp_Inputs
=> Subp_Inputs
,
1876 Subp_Outputs
=> Subp_Outputs
,
1877 Global_Seen
=> Global_Seen
);
1879 -- Verify that every input or output of the subprogram appear in a
1882 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1883 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1884 Check_Function_Return
;
1886 -- Dependency clauses appear as component associations of an aggregate
1888 elsif Nkind
(Deps
) = N_Aggregate
then
1890 -- Do not attempt to perform analysis of a syntactically illegal
1891 -- clause as this will lead to misleading errors.
1893 if Has_Extra_Parentheses
(Deps
) then
1897 if Present
(Component_Associations
(Deps
)) then
1898 Last_Clause
:= Last
(Component_Associations
(Deps
));
1900 -- Gather all states, objects and formal parameters that the
1901 -- subprogram may depend on. These items are obtained from the
1902 -- parameter profile or pragma [Refined_]Global (if available).
1904 Collect_Subprogram_Inputs_Outputs
1905 (Subp_Id
=> Subp_Id
,
1906 Subp_Inputs
=> Subp_Inputs
,
1907 Subp_Outputs
=> Subp_Outputs
,
1908 Global_Seen
=> Global_Seen
);
1910 -- When pragma [Refined_]Depends appears on a single concurrent
1911 -- type, it is relocated to the anonymous object.
1913 if Is_Single_Concurrent_Object
(Spec_Id
) then
1916 -- Ensure that the formal parameters are visible when analyzing
1917 -- all clauses. This falls out of the general rule of aspects
1918 -- pertaining to subprogram declarations.
1920 elsif not In_Open_Scopes
(Spec_Id
) then
1921 Restore_Scope
:= True;
1922 Push_Scope
(Spec_Id
);
1924 if Ekind
(Spec_Id
) = E_Task_Type
then
1925 if Has_Discriminants
(Spec_Id
) then
1926 Install_Discriminants
(Spec_Id
);
1929 elsif Is_Generic_Subprogram
(Spec_Id
) then
1930 Install_Generic_Formals
(Spec_Id
);
1933 Install_Formals
(Spec_Id
);
1937 Clause
:= First
(Component_Associations
(Deps
));
1938 while Present
(Clause
) loop
1939 Errors
:= Serious_Errors_Detected
;
1941 -- The normalization mechanism may create extra clauses that
1942 -- contain replicated input and output names. There is no need
1943 -- to reanalyze them.
1945 if not Analyzed
(Clause
) then
1946 Set_Analyzed
(Clause
);
1948 Analyze_Dependency_Clause
1950 Is_Last
=> Clause
= Last_Clause
);
1953 -- Do not normalize a clause if errors were detected (count
1954 -- of Serious_Errors has increased) because the inputs and/or
1955 -- outputs may denote illegal items. Normalization is disabled
1956 -- in ASIS mode as it alters the tree by introducing new nodes
1957 -- similar to expansion.
1959 if Serious_Errors_Detected
= Errors
and then not ASIS_Mode
then
1960 Normalize_Clause
(Clause
);
1966 if Restore_Scope
then
1970 -- Verify that every input or output of the subprogram appear in a
1973 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1974 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1975 Check_Function_Return
;
1977 -- The dependency list is malformed. This is a syntax error, always
1981 Error_Msg_N
("malformed dependency relation", Deps
);
1985 -- The top level dependency relation is malformed. This is a syntax
1986 -- error, always report.
1989 Error_Msg_N
("malformed dependency relation", Deps
);
1993 -- Ensure that a state and a corresponding constituent do not appear
1994 -- together in pragma [Refined_]Depends.
1996 Check_State_And_Constituent_Use
1997 (States
=> States_Seen
,
1998 Constits
=> Constits_Seen
,
2002 Set_Is_Analyzed_Pragma
(N
);
2003 end Analyze_Depends_In_Decl_Part
;
2005 --------------------------------------------
2006 -- Analyze_External_Property_In_Decl_Part --
2007 --------------------------------------------
2009 procedure Analyze_External_Property_In_Decl_Part
2011 Expr_Val
: out Boolean)
2013 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
2014 Obj_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
2015 Obj_Id
: constant Entity_Id
:= Defining_Entity
(Obj_Decl
);
2021 -- Do not analyze the pragma multiple times
2023 if Is_Analyzed_Pragma
(N
) then
2027 Error_Msg_Name_1
:= Pragma_Name
(N
);
2029 -- An external property pragma must apply to an effectively volatile
2030 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
2031 -- The check is performed at the end of the declarative region due to a
2032 -- possible out-of-order arrangement of pragmas:
2035 -- pragma Async_Readers (Obj);
2036 -- pragma Volatile (Obj);
2038 if not Is_Effectively_Volatile
(Obj_Id
) then
2040 ("external property % must apply to a volatile object", N
);
2043 -- Ensure that the Boolean expression (if present) is static. A missing
2044 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
2048 if Present
(Arg1
) then
2049 Expr
:= Get_Pragma_Arg
(Arg1
);
2051 if Is_OK_Static_Expression
(Expr
) then
2052 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
2056 Set_Is_Analyzed_Pragma
(N
);
2057 end Analyze_External_Property_In_Decl_Part
;
2059 ---------------------------------
2060 -- Analyze_Global_In_Decl_Part --
2061 ---------------------------------
2063 procedure Analyze_Global_In_Decl_Part
(N
: Node_Id
) is
2064 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
2065 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
2066 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
2068 Constits_Seen
: Elist_Id
:= No_Elist
;
2069 -- A list containing the entities of all constituents processed so far.
2070 -- It aids in detecting illegal usage of a state and a corresponding
2071 -- constituent in pragma [Refinde_]Global.
2073 Seen
: Elist_Id
:= No_Elist
;
2074 -- A list containing the entities of all the items processed so far. It
2075 -- plays a role in detecting distinct entities.
2077 States_Seen
: Elist_Id
:= No_Elist
;
2078 -- A list containing the entities of all states processed so far. It
2079 -- helps in detecting illegal usage of a state and a corresponding
2080 -- constituent in pragma [Refined_]Global.
2082 In_Out_Seen
: Boolean := False;
2083 Input_Seen
: Boolean := False;
2084 Output_Seen
: Boolean := False;
2085 Proof_Seen
: Boolean := False;
2086 -- Flags used to verify the consistency of modes
2088 procedure Analyze_Global_List
2090 Global_Mode
: Name_Id
:= Name_Input
);
2091 -- Verify the legality of a single global list declaration. Global_Mode
2092 -- denotes the current mode in effect.
2094 -------------------------
2095 -- Analyze_Global_List --
2096 -------------------------
2098 procedure Analyze_Global_List
2100 Global_Mode
: Name_Id
:= Name_Input
)
2102 procedure Analyze_Global_Item
2104 Global_Mode
: Name_Id
);
2105 -- Verify the legality of a single global item declaration denoted by
2106 -- Item. Global_Mode denotes the current mode in effect.
2108 procedure Check_Duplicate_Mode
2110 Status
: in out Boolean);
2111 -- Flag Status denotes whether a particular mode has been seen while
2112 -- processing a global list. This routine verifies that Mode is not a
2113 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2115 procedure Check_Mode_Restriction_In_Enclosing_Context
2117 Item_Id
: Entity_Id
);
2118 -- Verify that an item of mode In_Out or Output does not appear as an
2119 -- input in the Global aspect of an enclosing subprogram. If this is
2120 -- the case, emit an error. Item and Item_Id are respectively the
2121 -- item and its entity.
2123 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
);
2124 -- Mode denotes either In_Out or Output. Depending on the kind of the
2125 -- related subprogram, emit an error if those two modes apply to a
2126 -- function (SPARK RM 6.1.4(10)).
2128 -------------------------
2129 -- Analyze_Global_Item --
2130 -------------------------
2132 procedure Analyze_Global_Item
2134 Global_Mode
: Name_Id
)
2136 Item_Id
: Entity_Id
;
2139 -- Detect one of the following cases
2141 -- with Global => (null, Name)
2142 -- with Global => (Name_1, null, Name_2)
2143 -- with Global => (Name, null)
2145 if Nkind
(Item
) = N_Null
then
2146 SPARK_Msg_N
("cannot mix null and non-null global items", Item
);
2151 Resolve_State
(Item
);
2153 -- Find the entity of the item. If this is a renaming, climb the
2154 -- renaming chain to reach the root object. Renamings of non-
2155 -- entire objects do not yield an entity (Empty).
2157 Item_Id
:= Entity_Of
(Item
);
2159 if Present
(Item_Id
) then
2161 -- A global item may denote a formal parameter of an enclosing
2162 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2163 -- provide a better error diagnostic.
2165 if Is_Formal
(Item_Id
) then
2166 if Scope
(Item_Id
) = Spec_Id
then
2168 (Fix_Msg
(Spec_Id
, "global item cannot reference "
2169 & "parameter of subprogram &"), Item
, Spec_Id
);
2173 -- A global item may denote a concurrent type as long as it is
2174 -- the current instance of an enclosing protected or task type
2175 -- (SPARK RM 6.1.4).
2177 elsif Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
2178 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
2180 -- Pragma [Refined_]Global associated with a protected
2181 -- subprogram cannot mention the current instance of a
2182 -- protected type because the instance behaves as a
2183 -- formal parameter.
2185 if Ekind
(Item_Id
) = E_Protected_Type
then
2186 if Scope
(Spec_Id
) = Item_Id
then
2187 Error_Msg_Name_1
:= Chars
(Item_Id
);
2189 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2190 & "cannot reference current instance of "
2191 & "protected type %"), Item
, Spec_Id
);
2195 -- Pragma [Refined_]Global associated with a task type
2196 -- cannot mention the current instance of a task type
2197 -- because the instance behaves as a formal parameter.
2199 else pragma Assert
(Ekind
(Item_Id
) = E_Task_Type
);
2200 if Spec_Id
= Item_Id
then
2201 Error_Msg_Name_1
:= Chars
(Item_Id
);
2203 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2204 & "cannot reference current instance of task "
2205 & "type %"), Item
, Spec_Id
);
2210 -- Otherwise the global item denotes a subtype mark that is
2211 -- not a current instance.
2215 ("invalid use of subtype mark in global list", Item
);
2219 -- A global item may denote the anonymous object created for a
2220 -- single protected/task type as long as the current instance
2221 -- is the same single type (SPARK RM 6.1.4).
2223 elsif Is_Single_Concurrent_Object
(Item_Id
)
2224 and then Is_CCT_Instance
(Etype
(Item_Id
), Spec_Id
)
2226 -- Pragma [Refined_]Global associated with a protected
2227 -- subprogram cannot mention the current instance of a
2228 -- protected type because the instance behaves as a formal
2231 if Is_Single_Protected_Object
(Item_Id
) then
2232 if Scope
(Spec_Id
) = Etype
(Item_Id
) then
2233 Error_Msg_Name_1
:= Chars
(Item_Id
);
2235 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2236 & "cannot reference current instance of protected "
2237 & "type %"), Item
, Spec_Id
);
2241 -- Pragma [Refined_]Global associated with a task type
2242 -- cannot mention the current instance of a task type
2243 -- because the instance behaves as a formal parameter.
2245 else pragma Assert
(Is_Single_Task_Object
(Item_Id
));
2246 if Spec_Id
= Item_Id
then
2247 Error_Msg_Name_1
:= Chars
(Item_Id
);
2249 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2250 & "cannot reference current instance of task "
2251 & "type %"), Item
, Spec_Id
);
2256 -- A formal object may act as a global item inside a generic
2258 elsif Is_Formal_Object
(Item_Id
) then
2261 -- The only legal references are those to abstract states,
2262 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2264 elsif not Ekind_In
(Item_Id
, E_Abstract_State
,
2270 ("global item must denote object, state or current "
2271 & "instance of concurrent type", Item
);
2275 -- State related checks
2277 if Ekind
(Item_Id
) = E_Abstract_State
then
2279 -- Package and subprogram bodies are instantiated
2280 -- individually in a separate compiler pass. Due to this
2281 -- mode of instantiation, the refinement of a state may
2282 -- no longer be visible when a subprogram body contract
2283 -- is instantiated. Since the generic template is legal,
2284 -- do not perform this check in the instance to circumvent
2287 if Is_Generic_Instance
(Spec_Id
) then
2290 -- An abstract state with visible refinement cannot appear
2291 -- in pragma [Refined_]Global as its place must be taken by
2292 -- some of its constituents (SPARK RM 6.1.4(7)).
2294 elsif Has_Visible_Refinement
(Item_Id
) then
2296 ("cannot mention state & in global refinement",
2298 SPARK_Msg_N
("\use its constituents instead", Item
);
2301 -- An external state cannot appear as a global item of a
2302 -- nonvolatile function (SPARK RM 7.1.3(8)).
2304 elsif Is_External_State
(Item_Id
)
2305 and then Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2306 and then not Is_Volatile_Function
(Spec_Id
)
2309 ("external state & cannot act as global item of "
2310 & "nonvolatile function", Item
, Item_Id
);
2313 -- If the reference to the abstract state appears in an
2314 -- enclosing package body that will eventually refine the
2315 -- state, record the reference for future checks.
2318 Record_Possible_Body_Reference
2319 (State_Id
=> Item_Id
,
2323 -- Constant related checks
2325 elsif Ekind
(Item_Id
) = E_Constant
then
2327 -- A constant is a read-only item, therefore it cannot act
2330 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2332 ("constant & cannot act as output", Item
, Item_Id
);
2336 -- Loop parameter related checks
2338 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
2340 -- A loop parameter is a read-only item, therefore it cannot
2341 -- act as an output.
2343 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2345 ("loop parameter & cannot act as output",
2350 -- Variable related checks. These are only relevant when
2351 -- SPARK_Mode is on as they are not standard Ada legality
2354 elsif SPARK_Mode
= On
2355 and then Ekind
(Item_Id
) = E_Variable
2356 and then Is_Effectively_Volatile
(Item_Id
)
2358 -- An effectively volatile object cannot appear as a global
2359 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2361 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2362 and then not Is_Volatile_Function
(Spec_Id
)
2365 ("volatile object & cannot act as global item of a "
2366 & "function", Item
, Item_Id
);
2369 -- An effectively volatile object with external property
2370 -- Effective_Reads set to True must have mode Output or
2371 -- In_Out (SPARK RM 7.1.3(10)).
2373 elsif Effective_Reads_Enabled
(Item_Id
)
2374 and then Global_Mode
= Name_Input
2377 ("volatile object & with property Effective_Reads must "
2378 & "have mode In_Out or Output", Item
, Item_Id
);
2383 -- When the item renames an entire object, replace the item
2384 -- with a reference to the object.
2386 if Entity
(Item
) /= Item_Id
then
2387 Rewrite
(Item
, New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
2391 -- Some form of illegal construct masquerading as a name
2392 -- (SPARK RM 6.1.4(4)).
2396 ("global item must denote object, state or current instance "
2397 & "of concurrent type", Item
);
2401 -- Verify that an output does not appear as an input in an
2402 -- enclosing subprogram.
2404 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2405 Check_Mode_Restriction_In_Enclosing_Context
(Item
, Item_Id
);
2408 -- The same entity might be referenced through various way.
2409 -- Check the entity of the item rather than the item itself
2410 -- (SPARK RM 6.1.4(10)).
2412 if Contains
(Seen
, Item_Id
) then
2413 SPARK_Msg_N
("duplicate global item", Item
);
2415 -- Add the entity of the current item to the list of processed
2419 Append_New_Elmt
(Item_Id
, Seen
);
2421 if Ekind
(Item_Id
) = E_Abstract_State
then
2422 Append_New_Elmt
(Item_Id
, States_Seen
);
2424 -- The variable may eventually become a constituent of a single
2425 -- protected/task type. Record the reference now and verify its
2426 -- legality when analyzing the contract of the variable
2429 elsif Ekind
(Item_Id
) = E_Variable
then
2430 Record_Possible_Part_Of_Reference
2435 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
2436 and then Present
(Encapsulating_State
(Item_Id
))
2438 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2441 end Analyze_Global_Item
;
2443 --------------------------
2444 -- Check_Duplicate_Mode --
2445 --------------------------
2447 procedure Check_Duplicate_Mode
2449 Status
: in out Boolean)
2453 SPARK_Msg_N
("duplicate global mode", Mode
);
2457 end Check_Duplicate_Mode
;
2459 -------------------------------------------------
2460 -- Check_Mode_Restriction_In_Enclosing_Context --
2461 -------------------------------------------------
2463 procedure Check_Mode_Restriction_In_Enclosing_Context
2465 Item_Id
: Entity_Id
)
2467 Context
: Entity_Id
;
2469 Inputs
: Elist_Id
:= No_Elist
;
2470 Outputs
: Elist_Id
:= No_Elist
;
2473 -- Traverse the scope stack looking for enclosing subprograms
2474 -- subject to pragma [Refined_]Global.
2476 Context
:= Scope
(Subp_Id
);
2477 while Present
(Context
) and then Context
/= Standard_Standard
loop
2478 if Is_Subprogram
(Context
)
2480 (Present
(Get_Pragma
(Context
, Pragma_Global
))
2482 Present
(Get_Pragma
(Context
, Pragma_Refined_Global
)))
2484 Collect_Subprogram_Inputs_Outputs
2485 (Subp_Id
=> Context
,
2486 Subp_Inputs
=> Inputs
,
2487 Subp_Outputs
=> Outputs
,
2488 Global_Seen
=> Dummy
);
2490 -- The item is classified as In_Out or Output but appears as
2491 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)).
2493 if Appears_In
(Inputs
, Item_Id
)
2494 and then not Appears_In
(Outputs
, Item_Id
)
2497 ("global item & cannot have mode In_Out or Output",
2501 (Fix_Msg
(Subp_Id
, "\item already appears as input of "
2502 & "subprogram &"), Item
, Context
);
2504 -- Stop the traversal once an error has been detected
2510 Context
:= Scope
(Context
);
2512 end Check_Mode_Restriction_In_Enclosing_Context
;
2514 ----------------------------------------
2515 -- Check_Mode_Restriction_In_Function --
2516 ----------------------------------------
2518 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
) is
2520 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
2522 ("global mode & is not applicable to functions", Mode
);
2524 end Check_Mode_Restriction_In_Function
;
2532 -- Start of processing for Analyze_Global_List
2535 if Nkind
(List
) = N_Null
then
2536 Set_Analyzed
(List
);
2538 -- Single global item declaration
2540 elsif Nkind_In
(List
, N_Expanded_Name
,
2542 N_Selected_Component
)
2544 Analyze_Global_Item
(List
, Global_Mode
);
2546 -- Simple global list or moded global list declaration
2548 elsif Nkind
(List
) = N_Aggregate
then
2549 Set_Analyzed
(List
);
2551 -- The declaration of a simple global list appear as a collection
2554 if Present
(Expressions
(List
)) then
2555 if Present
(Component_Associations
(List
)) then
2557 ("cannot mix moded and non-moded global lists", List
);
2560 Item
:= First
(Expressions
(List
));
2561 while Present
(Item
) loop
2562 Analyze_Global_Item
(Item
, Global_Mode
);
2566 -- The declaration of a moded global list appears as a collection
2567 -- of component associations where individual choices denote
2570 elsif Present
(Component_Associations
(List
)) then
2571 if Present
(Expressions
(List
)) then
2573 ("cannot mix moded and non-moded global lists", List
);
2576 Assoc
:= First
(Component_Associations
(List
));
2577 while Present
(Assoc
) loop
2578 Mode
:= First
(Choices
(Assoc
));
2580 if Nkind
(Mode
) = N_Identifier
then
2581 if Chars
(Mode
) = Name_In_Out
then
2582 Check_Duplicate_Mode
(Mode
, In_Out_Seen
);
2583 Check_Mode_Restriction_In_Function
(Mode
);
2585 elsif Chars
(Mode
) = Name_Input
then
2586 Check_Duplicate_Mode
(Mode
, Input_Seen
);
2588 elsif Chars
(Mode
) = Name_Output
then
2589 Check_Duplicate_Mode
(Mode
, Output_Seen
);
2590 Check_Mode_Restriction_In_Function
(Mode
);
2592 elsif Chars
(Mode
) = Name_Proof_In
then
2593 Check_Duplicate_Mode
(Mode
, Proof_Seen
);
2596 SPARK_Msg_N
("invalid mode selector", Mode
);
2600 SPARK_Msg_N
("invalid mode selector", Mode
);
2603 -- Items in a moded list appear as a collection of
2604 -- expressions. Reuse the existing machinery to analyze
2608 (List
=> Expression
(Assoc
),
2609 Global_Mode
=> Chars
(Mode
));
2617 raise Program_Error
;
2620 -- Any other attempt to declare a global item is illegal. This is a
2621 -- syntax error, always report.
2624 Error_Msg_N
("malformed global list", List
);
2626 end Analyze_Global_List
;
2630 Items
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
2632 Restore_Scope
: Boolean := False;
2634 -- Start of processing for Analyze_Global_In_Decl_Part
2637 -- Do not analyze the pragma multiple times
2639 if Is_Analyzed_Pragma
(N
) then
2643 -- There is nothing to be done for a null global list
2645 if Nkind
(Items
) = N_Null
then
2646 Set_Analyzed
(Items
);
2648 -- Analyze the various forms of global lists and items. Note that some
2649 -- of these may be malformed in which case the analysis emits error
2653 -- When pragma [Refined_]Global appears on a single concurrent type,
2654 -- it is relocated to the anonymous object.
2656 if Is_Single_Concurrent_Object
(Spec_Id
) then
2659 -- Ensure that the formal parameters are visible when processing an
2660 -- item. This falls out of the general rule of aspects pertaining to
2661 -- subprogram declarations.
2663 elsif not In_Open_Scopes
(Spec_Id
) then
2664 Restore_Scope
:= True;
2665 Push_Scope
(Spec_Id
);
2667 if Ekind
(Spec_Id
) = E_Task_Type
then
2668 if Has_Discriminants
(Spec_Id
) then
2669 Install_Discriminants
(Spec_Id
);
2672 elsif Is_Generic_Subprogram
(Spec_Id
) then
2673 Install_Generic_Formals
(Spec_Id
);
2676 Install_Formals
(Spec_Id
);
2680 Analyze_Global_List
(Items
);
2682 if Restore_Scope
then
2687 -- Ensure that a state and a corresponding constituent do not appear
2688 -- together in pragma [Refined_]Global.
2690 Check_State_And_Constituent_Use
2691 (States
=> States_Seen
,
2692 Constits
=> Constits_Seen
,
2695 Set_Is_Analyzed_Pragma
(N
);
2696 end Analyze_Global_In_Decl_Part
;
2698 --------------------------------------------
2699 -- Analyze_Initial_Condition_In_Decl_Part --
2700 --------------------------------------------
2702 -- WARNING: This routine manages Ghost regions. Return statements must be
2703 -- replaced by gotos which jump to the end of the routine and restore the
2706 procedure Analyze_Initial_Condition_In_Decl_Part
(N
: Node_Id
) is
2707 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2708 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2709 Expr
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
2711 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2712 -- Save the Ghost mode to restore on exit
2715 -- Do not analyze the pragma multiple times
2717 if Is_Analyzed_Pragma
(N
) then
2721 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2722 -- analysis of the pragma, the Ghost mode at point of declaration and
2723 -- point of analysis may not necessarily be the same. Use the mode in
2724 -- effect at the point of declaration.
2728 -- The expression is preanalyzed because it has not been moved to its
2729 -- final place yet. A direct analysis may generate side effects and this
2730 -- is not desired at this point.
2732 Preanalyze_Assert_Expression
(Expr
, Standard_Boolean
);
2733 Set_Is_Analyzed_Pragma
(N
);
2735 Restore_Ghost_Mode
(Saved_GM
);
2736 end Analyze_Initial_Condition_In_Decl_Part
;
2738 --------------------------------------
2739 -- Analyze_Initializes_In_Decl_Part --
2740 --------------------------------------
2742 procedure Analyze_Initializes_In_Decl_Part
(N
: Node_Id
) is
2743 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2744 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2746 Constits_Seen
: Elist_Id
:= No_Elist
;
2747 -- A list containing the entities of all constituents processed so far.
2748 -- It aids in detecting illegal usage of a state and a corresponding
2749 -- constituent in pragma Initializes.
2751 Items_Seen
: Elist_Id
:= No_Elist
;
2752 -- A list of all initialization items processed so far. This list is
2753 -- used to detect duplicate items.
2755 States_And_Objs
: Elist_Id
:= No_Elist
;
2756 -- A list of all abstract states and objects declared in the visible
2757 -- declarations of the related package. This list is used to detect the
2758 -- legality of initialization items.
2760 States_Seen
: Elist_Id
:= No_Elist
;
2761 -- A list containing the entities of all states processed so far. It
2762 -- helps in detecting illegal usage of a state and a corresponding
2763 -- constituent in pragma Initializes.
2765 procedure Analyze_Initialization_Item
(Item
: Node_Id
);
2766 -- Verify the legality of a single initialization item
2768 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
);
2769 -- Verify the legality of a single initialization item followed by a
2770 -- list of input items.
2772 procedure Collect_States_And_Objects
;
2773 -- Inspect the visible declarations of the related package and gather
2774 -- the entities of all abstract states and objects in States_And_Objs.
2776 ---------------------------------
2777 -- Analyze_Initialization_Item --
2778 ---------------------------------
2780 procedure Analyze_Initialization_Item
(Item
: Node_Id
) is
2781 Item_Id
: Entity_Id
;
2785 Resolve_State
(Item
);
2787 if Is_Entity_Name
(Item
) then
2788 Item_Id
:= Entity_Of
(Item
);
2790 if Present
(Item_Id
)
2791 and then Ekind_In
(Item_Id
, E_Abstract_State
,
2795 -- When the initialization item is undefined, it appears as
2796 -- Any_Id. Do not continue with the analysis of the item.
2798 if Item_Id
= Any_Id
then
2801 -- The state or variable must be declared in the visible
2802 -- declarations of the package (SPARK RM 7.1.5(7)).
2804 elsif not Contains
(States_And_Objs
, Item_Id
) then
2805 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2807 ("initialization item & must appear in the visible "
2808 & "declarations of package %", Item
, Item_Id
);
2810 -- Detect a duplicate use of the same initialization item
2811 -- (SPARK RM 7.1.5(5)).
2813 elsif Contains
(Items_Seen
, Item_Id
) then
2814 SPARK_Msg_N
("duplicate initialization item", Item
);
2816 -- The item is legal, add it to the list of processed states
2820 Append_New_Elmt
(Item_Id
, Items_Seen
);
2822 if Ekind
(Item_Id
) = E_Abstract_State
then
2823 Append_New_Elmt
(Item_Id
, States_Seen
);
2826 if Present
(Encapsulating_State
(Item_Id
)) then
2827 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2831 -- The item references something that is not a state or object
2832 -- (SPARK RM 7.1.5(3)).
2836 ("initialization item must denote object or state", Item
);
2839 -- Some form of illegal construct masquerading as a name
2840 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2844 ("initialization item must denote object or state", Item
);
2846 end Analyze_Initialization_Item
;
2848 ---------------------------------------------
2849 -- Analyze_Initialization_Item_With_Inputs --
2850 ---------------------------------------------
2852 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
) is
2853 Inputs_Seen
: Elist_Id
:= No_Elist
;
2854 -- A list of all inputs processed so far. This list is used to detect
2855 -- duplicate uses of an input.
2857 Non_Null_Seen
: Boolean := False;
2858 Null_Seen
: Boolean := False;
2859 -- Flags used to check the legality of an input list
2861 procedure Analyze_Input_Item
(Input
: Node_Id
);
2862 -- Verify the legality of a single input item
2864 ------------------------
2865 -- Analyze_Input_Item --
2866 ------------------------
2868 procedure Analyze_Input_Item
(Input
: Node_Id
) is
2869 Input_Id
: Entity_Id
;
2874 if Nkind
(Input
) = N_Null
then
2877 ("multiple null initializations not allowed", Item
);
2879 elsif Non_Null_Seen
then
2881 ("cannot mix null and non-null initialization item", Item
);
2889 Non_Null_Seen
:= True;
2893 ("cannot mix null and non-null initialization item", Item
);
2897 Resolve_State
(Input
);
2899 if Is_Entity_Name
(Input
) then
2900 Input_Id
:= Entity_Of
(Input
);
2902 if Present
(Input_Id
)
2903 and then Ekind_In
(Input_Id
, E_Abstract_State
,
2905 E_Generic_In_Out_Parameter
,
2906 E_Generic_In_Parameter
,
2914 -- The input cannot denote states or objects declared
2915 -- within the related package (SPARK RM 7.1.5(4)).
2917 if Within_Scope
(Input_Id
, Current_Scope
) then
2919 -- Do not consider generic formal parameters or their
2920 -- respective mappings to generic formals. Even though
2921 -- the formals appear within the scope of the package,
2922 -- it is allowed for an initialization item to depend
2923 -- on an input item.
2925 if Ekind_In
(Input_Id
, E_Generic_In_Out_Parameter
,
2926 E_Generic_In_Parameter
)
2930 elsif Ekind_In
(Input_Id
, E_Constant
, E_Variable
)
2931 and then Present
(Corresponding_Generic_Association
2932 (Declaration_Node
(Input_Id
)))
2937 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2939 ("input item & cannot denote a visible object or "
2940 & "state of package %", Input
, Input_Id
);
2945 -- Detect a duplicate use of the same input item
2946 -- (SPARK RM 7.1.5(5)).
2948 if Contains
(Inputs_Seen
, Input_Id
) then
2949 SPARK_Msg_N
("duplicate input item", Input
);
2953 -- At this point it is known that the input is legal. Add
2954 -- it to the list of processed inputs.
2956 Append_New_Elmt
(Input_Id
, Inputs_Seen
);
2958 if Ekind
(Input_Id
) = E_Abstract_State
then
2959 Append_New_Elmt
(Input_Id
, States_Seen
);
2962 if Ekind_In
(Input_Id
, E_Abstract_State
,
2965 and then Present
(Encapsulating_State
(Input_Id
))
2967 Append_New_Elmt
(Input_Id
, Constits_Seen
);
2970 -- The input references something that is not a state or an
2971 -- object (SPARK RM 7.1.5(3)).
2975 ("input item must denote object or state", Input
);
2978 -- Some form of illegal construct masquerading as a name
2979 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2983 ("input item must denote object or state", Input
);
2986 end Analyze_Input_Item
;
2990 Inputs
: constant Node_Id
:= Expression
(Item
);
2994 Name_Seen
: Boolean := False;
2995 -- A flag used to detect multiple item names
2997 -- Start of processing for Analyze_Initialization_Item_With_Inputs
3000 -- Inspect the name of an item with inputs
3002 Elmt
:= First
(Choices
(Item
));
3003 while Present
(Elmt
) loop
3005 SPARK_Msg_N
("only one item allowed in initialization", Elmt
);
3008 Analyze_Initialization_Item
(Elmt
);
3014 -- Multiple input items appear as an aggregate
3016 if Nkind
(Inputs
) = N_Aggregate
then
3017 if Present
(Expressions
(Inputs
)) then
3018 Input
:= First
(Expressions
(Inputs
));
3019 while Present
(Input
) loop
3020 Analyze_Input_Item
(Input
);
3025 if Present
(Component_Associations
(Inputs
)) then
3027 ("inputs must appear in named association form", Inputs
);
3030 -- Single input item
3033 Analyze_Input_Item
(Inputs
);
3035 end Analyze_Initialization_Item_With_Inputs
;
3037 --------------------------------
3038 -- Collect_States_And_Objects --
3039 --------------------------------
3041 procedure Collect_States_And_Objects
is
3042 Pack_Spec
: constant Node_Id
:= Specification
(Pack_Decl
);
3046 -- Collect the abstract states defined in the package (if any)
3048 if Present
(Abstract_States
(Pack_Id
)) then
3049 States_And_Objs
:= New_Copy_Elist
(Abstract_States
(Pack_Id
));
3052 -- Collect all objects that appear in the visible declarations of the
3055 if Present
(Visible_Declarations
(Pack_Spec
)) then
3056 Decl
:= First
(Visible_Declarations
(Pack_Spec
));
3057 while Present
(Decl
) loop
3058 if Comes_From_Source
(Decl
)
3059 and then Nkind_In
(Decl
, N_Object_Declaration
,
3060 N_Object_Renaming_Declaration
)
3062 Append_New_Elmt
(Defining_Entity
(Decl
), States_And_Objs
);
3064 elsif Is_Single_Concurrent_Type_Declaration
(Decl
) then
3066 (Anonymous_Object
(Defining_Entity
(Decl
)),
3073 end Collect_States_And_Objects
;
3077 Inits
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
3080 -- Start of processing for Analyze_Initializes_In_Decl_Part
3083 -- Do not analyze the pragma multiple times
3085 if Is_Analyzed_Pragma
(N
) then
3089 -- Nothing to do when the initialization list is empty
3091 if Nkind
(Inits
) = N_Null
then
3095 -- Single and multiple initialization clauses appear as an aggregate. If
3096 -- this is not the case, then either the parser or the analysis of the
3097 -- pragma failed to produce an aggregate.
3099 pragma Assert
(Nkind
(Inits
) = N_Aggregate
);
3101 -- Initialize the various lists used during analysis
3103 Collect_States_And_Objects
;
3105 if Present
(Expressions
(Inits
)) then
3106 Init
:= First
(Expressions
(Inits
));
3107 while Present
(Init
) loop
3108 Analyze_Initialization_Item
(Init
);
3113 if Present
(Component_Associations
(Inits
)) then
3114 Init
:= First
(Component_Associations
(Inits
));
3115 while Present
(Init
) loop
3116 Analyze_Initialization_Item_With_Inputs
(Init
);
3121 -- Ensure that a state and a corresponding constituent do not appear
3122 -- together in pragma Initializes.
3124 Check_State_And_Constituent_Use
3125 (States
=> States_Seen
,
3126 Constits
=> Constits_Seen
,
3129 Set_Is_Analyzed_Pragma
(N
);
3130 end Analyze_Initializes_In_Decl_Part
;
3132 ---------------------
3133 -- Analyze_Part_Of --
3134 ---------------------
3136 procedure Analyze_Part_Of
3138 Item_Id
: Entity_Id
;
3140 Encap_Id
: out Entity_Id
;
3141 Legal
: out Boolean)
3143 procedure Check_Part_Of_Abstract_State
;
3144 pragma Inline
(Check_Part_Of_Abstract_State
);
3145 -- Verify the legality of indicator Part_Of when the encapsulator is an
3148 procedure Check_Part_Of_Concurrent_Type
;
3149 pragma Inline
(Check_Part_Of_Concurrent_Type
);
3150 -- Verify the legality of indicator Part_Of when the encapsulator is a
3151 -- single concurrent type.
3153 ----------------------------------
3154 -- Check_Part_Of_Abstract_State --
3155 ----------------------------------
3157 procedure Check_Part_Of_Abstract_State
is
3158 Pack_Id
: Entity_Id
;
3159 Placement
: State_Space_Kind
;
3160 Parent_Unit
: Entity_Id
;
3163 -- Determine where the object, package instantiation or state lives
3164 -- with respect to the enclosing packages or package bodies.
3166 Find_Placement_In_State_Space
3167 (Item_Id
=> Item_Id
,
3168 Placement
=> Placement
,
3169 Pack_Id
=> Pack_Id
);
3171 -- The item appears in a non-package construct with a declarative
3172 -- part (subprogram, block, etc). As such, the item is not allowed
3173 -- to be a part of an encapsulating state because the item is not
3176 if Placement
= Not_In_Package
then
3178 ("indicator Part_Of cannot appear in this context "
3179 & "(SPARK RM 7.2.6(5))", Indic
);
3181 Error_Msg_Name_1
:= Chars
(Scope
(Encap_Id
));
3183 ("\& is not part of the hidden state of package %",
3187 -- The item appears in the visible state space of some package. In
3188 -- general this scenario does not warrant Part_Of except when the
3189 -- package is a private child unit and the encapsulating state is
3190 -- declared in a parent unit or a public descendant of that parent
3193 elsif Placement
= Visible_State_Space
then
3194 if Is_Child_Unit
(Pack_Id
)
3195 and then Is_Private_Descendant
(Pack_Id
)
3197 -- A variable or state abstraction which is part of the visible
3198 -- state of a private child unit or its public descendants must
3199 -- have its Part_Of indicator specified. The Part_Of indicator
3200 -- must denote a state declared by either the parent unit of
3201 -- the private unit or by a public descendant of that parent
3204 -- Find the nearest private ancestor (which can be the current
3207 Parent_Unit
:= Pack_Id
;
3208 while Present
(Parent_Unit
) loop
3211 (Parent
(Unit_Declaration_Node
(Parent_Unit
)));
3212 Parent_Unit
:= Scope
(Parent_Unit
);
3215 Parent_Unit
:= Scope
(Parent_Unit
);
3217 if not Is_Child_Or_Sibling
(Pack_Id
, Scope
(Encap_Id
)) then
3219 ("indicator Part_Of must denote abstract state of & or of "
3220 & "its public descendant (SPARK RM 7.2.6(3))",
3221 Indic
, Parent_Unit
);
3224 elsif Scope
(Encap_Id
) = Parent_Unit
3226 (Is_Ancestor_Package
(Parent_Unit
, Scope
(Encap_Id
))
3227 and then not Is_Private_Descendant
(Scope
(Encap_Id
)))
3233 ("indicator Part_Of must denote abstract state of & or of "
3234 & "its public descendant (SPARK RM 7.2.6(3))",
3235 Indic
, Parent_Unit
);
3239 -- Indicator Part_Of is not needed when the related package is not
3240 -- a private child unit or a public descendant thereof.
3244 ("indicator Part_Of cannot appear in this context "
3245 & "(SPARK RM 7.2.6(5))", Indic
);
3247 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3249 ("\& is declared in the visible part of package %",
3254 -- When the item appears in the private state space of a package, the
3255 -- encapsulating state must be declared in the same package.
3257 elsif Placement
= Private_State_Space
then
3258 if Scope
(Encap_Id
) /= Pack_Id
then
3260 ("indicator Part_Of must denote an abstract state of "
3261 & "package & (SPARK RM 7.2.6(2))", Indic
, Pack_Id
);
3263 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3265 ("\& is declared in the private part of package %",
3270 -- Items declared in the body state space of a package do not need
3271 -- Part_Of indicators as the refinement has already been seen.
3275 ("indicator Part_Of cannot appear in this context "
3276 & "(SPARK RM 7.2.6(5))", Indic
);
3278 if Scope
(Encap_Id
) = Pack_Id
then
3279 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3281 ("\& is declared in the body of package %", Indic
, Item_Id
);
3287 -- At this point it is known that the Part_Of indicator is legal
3290 end Check_Part_Of_Abstract_State
;
3292 -----------------------------------
3293 -- Check_Part_Of_Concurrent_Type --
3294 -----------------------------------
3296 procedure Check_Part_Of_Concurrent_Type
is
3297 function In_Proper_Order
3299 Second
: Node_Id
) return Boolean;
3300 pragma Inline
(In_Proper_Order
);
3301 -- Determine whether node First precedes node Second
3303 procedure Placement_Error
;
3304 pragma Inline
(Placement_Error
);
3305 -- Emit an error concerning the illegal placement of the item with
3306 -- respect to the single concurrent type.
3308 ---------------------
3309 -- In_Proper_Order --
3310 ---------------------
3312 function In_Proper_Order
3314 Second
: Node_Id
) return Boolean
3319 if List_Containing
(First
) = List_Containing
(Second
) then
3321 while Present
(N
) loop
3331 end In_Proper_Order
;
3333 ---------------------
3334 -- Placement_Error --
3335 ---------------------
3337 procedure Placement_Error
is
3340 ("indicator Part_Of must denote a previously declared single "
3341 & "protected type or single task type", Encap
);
3342 end Placement_Error
;
3346 Conc_Typ
: constant Entity_Id
:= Etype
(Encap_Id
);
3347 Encap_Decl
: constant Node_Id
:= Declaration_Node
(Encap_Id
);
3348 Encap_Context
: constant Node_Id
:= Parent
(Encap_Decl
);
3350 Item_Context
: Node_Id
;
3351 Item_Decl
: Node_Id
;
3352 Prv_Decls
: List_Id
;
3353 Vis_Decls
: List_Id
;
3355 -- Start of processing for Check_Part_Of_Concurrent_Type
3358 -- Only abstract states and variables can act as constituents of an
3359 -- encapsulating single concurrent type.
3361 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
3364 -- The constituent is a constant
3366 elsif Ekind
(Item_Id
) = E_Constant
then
3367 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3369 (Fix_Msg
(Conc_Typ
, "constant & cannot act as constituent of "
3370 & "single protected type %"), Indic
, Item_Id
);
3373 -- The constituent is a package instantiation
3376 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3378 (Fix_Msg
(Conc_Typ
, "package instantiation & cannot act as "
3379 & "constituent of single protected type %"), Indic
, Item_Id
);
3383 -- When the item denotes an abstract state of a nested package, use
3384 -- the declaration of the package to detect proper placement.
3389 -- with Abstract_State => (State with Part_Of => T)
3391 if Ekind
(Item_Id
) = E_Abstract_State
then
3392 Item_Decl
:= Unit_Declaration_Node
(Scope
(Item_Id
));
3394 Item_Decl
:= Declaration_Node
(Item_Id
);
3397 Item_Context
:= Parent
(Item_Decl
);
3399 -- The item and the single concurrent type must appear in the same
3400 -- declarative region, with the item following the declaration of
3401 -- the single concurrent type (SPARK RM 9(3)).
3403 if Item_Context
= Encap_Context
then
3404 if Nkind_In
(Item_Context
, N_Package_Specification
,
3405 N_Protected_Definition
,
3408 Prv_Decls
:= Private_Declarations
(Item_Context
);
3409 Vis_Decls
:= Visible_Declarations
(Item_Context
);
3411 -- The placement is OK when the single concurrent type appears
3412 -- within the visible declarations and the item in the private
3418 -- Constit : ... with Part_Of => PO;
3421 if List_Containing
(Encap_Decl
) = Vis_Decls
3422 and then List_Containing
(Item_Decl
) = Prv_Decls
3426 -- The placement is illegal when the item appears within the
3427 -- visible declarations and the single concurrent type is in
3428 -- the private declarations.
3431 -- Constit : ... with Part_Of => PO;
3436 elsif List_Containing
(Item_Decl
) = Vis_Decls
3437 and then List_Containing
(Encap_Decl
) = Prv_Decls
3442 -- Otherwise both the item and the single concurrent type are
3443 -- in the same list. Ensure that the declaration of the single
3444 -- concurrent type precedes that of the item.
3446 elsif not In_Proper_Order
3447 (First
=> Encap_Decl
,
3448 Second
=> Item_Decl
)
3454 -- Otherwise both the item and the single concurrent type are
3455 -- in the same list. Ensure that the declaration of the single
3456 -- concurrent type precedes that of the item.
3458 elsif not In_Proper_Order
3459 (First
=> Encap_Decl
,
3460 Second
=> Item_Decl
)
3466 -- Otherwise the item and the single concurrent type reside within
3467 -- unrelated regions.
3470 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3472 (Fix_Msg
(Conc_Typ
, "constituent & must be declared "
3473 & "immediately within the same region as single protected "
3474 & "type %"), Indic
, Item_Id
);
3478 -- At this point it is known that the Part_Of indicator is legal
3481 end Check_Part_Of_Concurrent_Type
;
3483 -- Start of processing for Analyze_Part_Of
3486 -- Assume that the indicator is illegal
3491 if Nkind_In
(Encap
, N_Expanded_Name
,
3493 N_Selected_Component
)
3496 Resolve_State
(Encap
);
3498 Encap_Id
:= Entity
(Encap
);
3500 -- The encapsulator is an abstract state
3502 if Ekind
(Encap_Id
) = E_Abstract_State
then
3505 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3507 elsif Is_Single_Concurrent_Object
(Encap_Id
) then
3510 -- Otherwise the encapsulator is not a legal choice
3514 ("indicator Part_Of must denote abstract state, single "
3515 & "protected type or single task type", Encap
);
3519 -- This is a syntax error, always report
3523 ("indicator Part_Of must denote abstract state, single protected "
3524 & "type or single task type", Encap
);
3528 -- Catch a case where indicator Part_Of denotes the abstract view of a
3529 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3531 if From_Limited_With
(Encap_Id
)
3532 and then Present
(Non_Limited_View
(Encap_Id
))
3533 and then Ekind
(Non_Limited_View
(Encap_Id
)) = E_Variable
3535 SPARK_Msg_N
("indicator Part_Of must denote abstract state", Encap
);
3536 SPARK_Msg_N
("\& denotes abstract view of object", Encap
);
3540 -- The encapsulator is an abstract state
3542 if Ekind
(Encap_Id
) = E_Abstract_State
then
3543 Check_Part_Of_Abstract_State
;
3545 -- The encapsulator is a single concurrent type
3548 Check_Part_Of_Concurrent_Type
;
3550 end Analyze_Part_Of
;
3552 ----------------------------------
3553 -- Analyze_Part_Of_In_Decl_Part --
3554 ----------------------------------
3556 procedure Analyze_Part_Of_In_Decl_Part
3558 Freeze_Id
: Entity_Id
:= Empty
)
3560 Encap
: constant Node_Id
:=
3561 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
3562 Errors
: constant Nat
:= Serious_Errors_Detected
;
3563 Var_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
3564 Var_Id
: constant Entity_Id
:= Defining_Entity
(Var_Decl
);
3565 Constits
: Elist_Id
;
3566 Encap_Id
: Entity_Id
;
3570 -- Detect any discrepancies between the placement of the variable with
3571 -- respect to general state space and the encapsulating state or single
3578 Encap_Id
=> Encap_Id
,
3581 -- The Part_Of indicator turns the variable into a constituent of the
3582 -- encapsulating state or single concurrent type.
3585 pragma Assert
(Present
(Encap_Id
));
3586 Constits
:= Part_Of_Constituents
(Encap_Id
);
3588 if No
(Constits
) then
3589 Constits
:= New_Elmt_List
;
3590 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
3593 Append_Elmt
(Var_Id
, Constits
);
3594 Set_Encapsulating_State
(Var_Id
, Encap_Id
);
3596 -- A Part_Of constituent partially refines an abstract state. This
3597 -- property does not apply to protected or task units.
3599 if Ekind
(Encap_Id
) = E_Abstract_State
then
3600 Set_Has_Partial_Visible_Refinement
(Encap_Id
);
3604 -- Emit a clarification message when the encapsulator is undefined,
3605 -- possibly due to contract freezing.
3607 if Errors
/= Serious_Errors_Detected
3608 and then Present
(Freeze_Id
)
3609 and then Has_Undefined_Reference
(Encap
)
3611 Contract_Freeze_Error
(Var_Id
, Freeze_Id
);
3613 end Analyze_Part_Of_In_Decl_Part
;
3615 --------------------
3616 -- Analyze_Pragma --
3617 --------------------
3619 procedure Analyze_Pragma
(N
: Node_Id
) is
3620 Loc
: constant Source_Ptr
:= Sloc
(N
);
3622 Pname
: Name_Id
:= Pragma_Name
(N
);
3623 -- Name of the source pragma, or name of the corresponding aspect for
3624 -- pragmas which originate in a source aspect. In the latter case, the
3625 -- name may be different from the pragma name.
3627 Prag_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Pname
);
3629 Pragma_Exit
: exception;
3630 -- This exception is used to exit pragma processing completely. It
3631 -- is used when an error is detected, and no further processing is
3632 -- required. It is also used if an earlier error has left the tree in
3633 -- a state where the pragma should not be processed.
3636 -- Number of pragma argument associations
3642 -- First four pragma arguments (pragma argument association nodes, or
3643 -- Empty if the corresponding argument does not exist).
3645 type Name_List
is array (Natural range <>) of Name_Id
;
3646 type Args_List
is array (Natural range <>) of Node_Id
;
3647 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3649 -----------------------
3650 -- Local Subprograms --
3651 -----------------------
3653 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
);
3654 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3655 -- get the given string argument, and place it in Name_Buffer, adding
3656 -- leading and trailing asterisks if they are not already present. The
3657 -- caller has already checked that Arg is a static string expression.
3659 procedure Ada_2005_Pragma
;
3660 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3661 -- Ada 95 mode, these are implementation defined pragmas, so should be
3662 -- caught by the No_Implementation_Pragmas restriction.
3664 procedure Ada_2012_Pragma
;
3665 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3666 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3667 -- should be caught by the No_Implementation_Pragmas restriction.
3669 procedure Analyze_Depends_Global
3670 (Spec_Id
: out Entity_Id
;
3671 Subp_Decl
: out Node_Id
;
3672 Legal
: out Boolean);
3673 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3674 -- legality of the placement and related context of the pragma. Spec_Id
3675 -- is the entity of the related subprogram. Subp_Decl is the declaration
3676 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3678 procedure Analyze_If_Present
(Id
: Pragma_Id
);
3679 -- Inspect the remainder of the list containing pragma N and look for
3680 -- a pragma that matches Id. If found, analyze the pragma.
3682 procedure Analyze_Pre_Post_Condition
;
3683 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3685 procedure Analyze_Refined_Depends_Global_Post
3686 (Spec_Id
: out Entity_Id
;
3687 Body_Id
: out Entity_Id
;
3688 Legal
: out Boolean);
3689 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3690 -- Refined_Global and Refined_Post. Verify the legality of the placement
3691 -- and related context of the pragma. Spec_Id is the entity of the
3692 -- related subprogram. Body_Id is the entity of the subprogram body.
3693 -- Flag Legal is set when the pragma is legal.
3695 procedure Analyze_Unmodified_Or_Unused
(Is_Unused
: Boolean := False);
3696 -- Perform full analysis of pragma Unmodified and the write aspect of
3697 -- pragma Unused. Flag Is_Unused should be set when verifying the
3698 -- semantics of pragma Unused.
3700 procedure Analyze_Unreferenced_Or_Unused
(Is_Unused
: Boolean := False);
3701 -- Perform full analysis of pragma Unreferenced and the read aspect of
3702 -- pragma Unused. Flag Is_Unused should be set when verifying the
3703 -- semantics of pragma Unused.
3705 procedure Check_Ada_83_Warning
;
3706 -- Issues a warning message for the current pragma if operating in Ada
3707 -- 83 mode (used for language pragmas that are not a standard part of
3708 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3711 procedure Check_Arg_Count
(Required
: Nat
);
3712 -- Check argument count for pragma is equal to given parameter. If not,
3713 -- then issue an error message and raise Pragma_Exit.
3715 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3716 -- Arg which can either be a pragma argument association, in which case
3717 -- the check is applied to the expression of the association or an
3718 -- expression directly.
3720 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
);
3721 -- Check that an argument has the right form for an EXTERNAL_NAME
3722 -- parameter of an extended import/export pragma. The rule is that the
3723 -- name must be an identifier or string literal (in Ada 83 mode) or a
3724 -- static string expression (in Ada 95 mode).
3726 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
);
3727 -- Check the specified argument Arg to make sure that it is an
3728 -- identifier. If not give error and raise Pragma_Exit.
3730 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
);
3731 -- Check the specified argument Arg to make sure that it is an integer
3732 -- literal. If not give error and raise Pragma_Exit.
3734 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
);
3735 -- Check the specified argument Arg to make sure that it has the proper
3736 -- syntactic form for a local name and meets the semantic requirements
3737 -- for a local name. The local name is analyzed as part of the
3738 -- processing for this call. In addition, the local name is required
3739 -- to represent an entity at the library level.
3741 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
);
3742 -- Check the specified argument Arg to make sure that it has the proper
3743 -- syntactic form for a local name and meets the semantic requirements
3744 -- for a local name. The local name is analyzed as part of the
3745 -- processing for this call.
3747 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
);
3748 -- Check the specified argument Arg to make sure that it is a valid
3749 -- locking policy name. If not give error and raise Pragma_Exit.
3751 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
);
3752 -- Check the specified argument Arg to make sure that it is a valid
3753 -- elaboration policy name. If not give error and raise Pragma_Exit.
3755 procedure Check_Arg_Is_One_Of
3758 procedure Check_Arg_Is_One_Of
3760 N1
, N2
, N3
: Name_Id
);
3761 procedure Check_Arg_Is_One_Of
3763 N1
, N2
, N3
, N4
: Name_Id
);
3764 procedure Check_Arg_Is_One_Of
3766 N1
, N2
, N3
, N4
, N5
: Name_Id
);
3767 -- Check the specified argument Arg to make sure that it is an
3768 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3769 -- present). If not then give error and raise Pragma_Exit.
3771 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
);
3772 -- Check the specified argument Arg to make sure that it is a valid
3773 -- queuing policy name. If not give error and raise Pragma_Exit.
3775 procedure Check_Arg_Is_OK_Static_Expression
3777 Typ
: Entity_Id
:= Empty
);
3778 -- Check the specified argument Arg to make sure that it is a static
3779 -- expression of the given type (i.e. it will be analyzed and resolved
3780 -- using this type, which can be any valid argument to Resolve, e.g.
3781 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3782 -- Typ is left Empty, then any static expression is allowed. Includes
3783 -- checking that the argument does not raise Constraint_Error.
3785 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
);
3786 -- Check the specified argument Arg to make sure that it is a valid task
3787 -- dispatching policy name. If not give error and raise Pragma_Exit.
3789 procedure Check_Arg_Order
(Names
: Name_List
);
3790 -- Checks for an instance of two arguments with identifiers for the
3791 -- current pragma which are not in the sequence indicated by Names,
3792 -- and if so, generates a fatal message about bad order of arguments.
3794 procedure Check_At_Least_N_Arguments
(N
: Nat
);
3795 -- Check there are at least N arguments present
3797 procedure Check_At_Most_N_Arguments
(N
: Nat
);
3798 -- Check there are no more than N arguments present
3800 procedure Check_Component
3803 In_Variant_Part
: Boolean := False);
3804 -- Examine an Unchecked_Union component for correct use of per-object
3805 -- constrained subtypes, and for restrictions on finalizable components.
3806 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3807 -- should be set when Comp comes from a record variant.
3809 procedure Check_Duplicate_Pragma
(E
: Entity_Id
);
3810 -- Check if a rep item of the same name as the current pragma is already
3811 -- chained as a rep pragma to the given entity. If so give a message
3812 -- about the duplicate, and then raise Pragma_Exit so does not return.
3813 -- Note that if E is a type, then this routine avoids flagging a pragma
3814 -- which applies to a parent type from which E is derived.
3816 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
);
3817 -- Nam is an N_String_Literal node containing the external name set by
3818 -- an Import or Export pragma (or extended Import or Export pragma).
3819 -- This procedure checks for possible duplications if this is the export
3820 -- case, and if found, issues an appropriate error message.
3822 procedure Check_Expr_Is_OK_Static_Expression
3824 Typ
: Entity_Id
:= Empty
);
3825 -- Check the specified expression Expr to make sure that it is a static
3826 -- expression of the given type (i.e. it will be analyzed and resolved
3827 -- using this type, which can be any valid argument to Resolve, e.g.
3828 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3829 -- Typ is left Empty, then any static expression is allowed. Includes
3830 -- checking that the expression does not raise Constraint_Error.
3832 procedure Check_First_Subtype
(Arg
: Node_Id
);
3833 -- Checks that Arg, whose expression is an entity name, references a
3836 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3837 -- Checks that the given argument has an identifier, and if so, requires
3838 -- it to match the given identifier name. If there is no identifier, or
3839 -- a non-matching identifier, then an error message is given and
3840 -- Pragma_Exit is raised.
3842 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
);
3843 -- Checks that the given argument has an identifier, and if so, requires
3844 -- it to match one of the given identifier names. If there is no
3845 -- identifier, or a non-matching identifier, then an error message is
3846 -- given and Pragma_Exit is raised.
3848 procedure Check_In_Main_Program
;
3849 -- Common checks for pragmas that appear within a main program
3850 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3852 procedure Check_Interrupt_Or_Attach_Handler
;
3853 -- Common processing for first argument of pragma Interrupt_Handler or
3854 -- pragma Attach_Handler.
3856 procedure Check_Loop_Pragma_Placement
;
3857 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3858 -- appear immediately within a construct restricted to loops, and that
3859 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3861 procedure Check_Is_In_Decl_Part_Or_Package_Spec
;
3862 -- Check that pragma appears in a declarative part, or in a package
3863 -- specification, i.e. that it does not occur in a statement sequence
3866 procedure Check_No_Identifier
(Arg
: Node_Id
);
3867 -- Checks that the given argument does not have an identifier. If
3868 -- an identifier is present, then an error message is issued, and
3869 -- Pragma_Exit is raised.
3871 procedure Check_No_Identifiers
;
3872 -- Checks that none of the arguments to the pragma has an identifier.
3873 -- If any argument has an identifier, then an error message is issued,
3874 -- and Pragma_Exit is raised.
3876 procedure Check_No_Link_Name
;
3877 -- Checks that no link name is specified
3879 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3880 -- Checks if the given argument has an identifier, and if so, requires
3881 -- it to match the given identifier name. If there is a non-matching
3882 -- identifier, then an error message is given and Pragma_Exit is raised.
3884 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String);
3885 -- Checks if the given argument has an identifier, and if so, requires
3886 -- it to match the given identifier name. If there is a non-matching
3887 -- identifier, then an error message is given and Pragma_Exit is raised.
3888 -- In this version of the procedure, the identifier name is given as
3889 -- a string with lower case letters.
3891 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
);
3892 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3893 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3894 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3895 -- is an OK static boolean expression. Emit an error if this is not the
3898 procedure Check_Static_Constraint
(Constr
: Node_Id
);
3899 -- Constr is a constraint from an N_Subtype_Indication node from a
3900 -- component constraint in an Unchecked_Union type. This routine checks
3901 -- that the constraint is static as required by the restrictions for
3904 procedure Check_Valid_Configuration_Pragma
;
3905 -- Legality checks for placement of a configuration pragma
3907 procedure Check_Valid_Library_Unit_Pragma
;
3908 -- Legality checks for library unit pragmas. A special case arises for
3909 -- pragmas in generic instances that come from copies of the original
3910 -- library unit pragmas in the generic templates. In the case of other
3911 -- than library level instantiations these can appear in contexts which
3912 -- would normally be invalid (they only apply to the original template
3913 -- and to library level instantiations), and they are simply ignored,
3914 -- which is implemented by rewriting them as null statements.
3916 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
);
3917 -- Check an Unchecked_Union variant for lack of nested variants and
3918 -- presence of at least one component. UU_Typ is the related Unchecked_
3921 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
);
3922 -- Subsidiary routine to the processing of pragmas Abstract_State,
3923 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3924 -- Refined_Global and Refined_State. Transform argument Arg into
3925 -- an aggregate if not one already. N_Null is never transformed.
3926 -- Arg may denote an aspect specification or a pragma argument
3929 procedure Error_Pragma
(Msg
: String);
3930 pragma No_Return
(Error_Pragma
);
3931 -- Outputs error message for current pragma. The message contains a %
3932 -- that will be replaced with the pragma name, and the flag is placed
3933 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3934 -- calls Fix_Error (see spec of that procedure for details).
3936 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
);
3937 pragma No_Return
(Error_Pragma_Arg
);
3938 -- Outputs error message for current pragma. The message may contain
3939 -- a % that will be replaced with the pragma name. The parameter Arg
3940 -- may either be a pragma argument association, in which case the flag
3941 -- is placed on the expression of this association, or an expression,
3942 -- in which case the flag is placed directly on the expression. The
3943 -- message is placed using Error_Msg_N, so the message may also contain
3944 -- an & insertion character which will reference the given Arg value.
3945 -- After placing the message, Pragma_Exit is raised. Note: this routine
3946 -- calls Fix_Error (see spec of that procedure for details).
3948 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
);
3949 pragma No_Return
(Error_Pragma_Arg
);
3950 -- Similar to above form of Error_Pragma_Arg except that two messages
3951 -- are provided, the second is a continuation comment starting with \.
3953 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
);
3954 pragma No_Return
(Error_Pragma_Arg_Ident
);
3955 -- Outputs error message for current pragma. The message may contain a %
3956 -- that will be replaced with the pragma name. The parameter Arg must be
3957 -- a pragma argument association with a non-empty identifier (i.e. its
3958 -- Chars field must be set), and the error message is placed on the
3959 -- identifier. The message is placed using Error_Msg_N so the message
3960 -- may also contain an & insertion character which will reference
3961 -- the identifier. After placing the message, Pragma_Exit is raised.
3962 -- Note: this routine calls Fix_Error (see spec of that procedure for
3965 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
);
3966 pragma No_Return
(Error_Pragma_Ref
);
3967 -- Outputs error message for current pragma. The message may contain
3968 -- a % that will be replaced with the pragma name. The parameter Ref
3969 -- must be an entity whose name can be referenced by & and sloc by #.
3970 -- After placing the message, Pragma_Exit is raised. Note: this routine
3971 -- calls Fix_Error (see spec of that procedure for details).
3973 function Find_Lib_Unit_Name
return Entity_Id
;
3974 -- Used for a library unit pragma to find the entity to which the
3975 -- library unit pragma applies, returns the entity found.
3977 procedure Find_Program_Unit_Name
(Id
: Node_Id
);
3978 -- If the pragma is a compilation unit pragma, the id must denote the
3979 -- compilation unit in the same compilation, and the pragma must appear
3980 -- in the list of preceding or trailing pragmas. If it is a program
3981 -- unit pragma that is not a compilation unit pragma, then the
3982 -- identifier must be visible.
3984 function Find_Unique_Parameterless_Procedure
3986 Arg
: Node_Id
) return Entity_Id
;
3987 -- Used for a procedure pragma to find the unique parameterless
3988 -- procedure identified by Name, returns it if it exists, otherwise
3989 -- errors out and uses Arg as the pragma argument for the message.
3991 function Fix_Error
(Msg
: String) return String;
3992 -- This is called prior to issuing an error message. Msg is the normal
3993 -- error message issued in the pragma case. This routine checks for the
3994 -- case of a pragma coming from an aspect in the source, and returns a
3995 -- message suitable for the aspect case as follows:
3997 -- Each substring "pragma" is replaced by "aspect"
3999 -- If "argument of" is at the start of the error message text, it is
4000 -- replaced by "entity for".
4002 -- If "argument" is at the start of the error message text, it is
4003 -- replaced by "entity".
4005 -- So for example, "argument of pragma X must be discrete type"
4006 -- returns "entity for aspect X must be a discrete type".
4008 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
4009 -- be different from the pragma name). If the current pragma results
4010 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
4011 -- original pragma name.
4013 procedure Gather_Associations
4015 Args
: out Args_List
);
4016 -- This procedure is used to gather the arguments for a pragma that
4017 -- permits arbitrary ordering of parameters using the normal rules
4018 -- for named and positional parameters. The Names argument is a list
4019 -- of Name_Id values that corresponds to the allowed pragma argument
4020 -- association identifiers in order. The result returned in Args is
4021 -- a list of corresponding expressions that are the pragma arguments.
4022 -- Note that this is a list of expressions, not of pragma argument
4023 -- associations (Gather_Associations has completely checked all the
4024 -- optional identifiers when it returns). An entry in Args is Empty
4025 -- on return if the corresponding argument is not present.
4027 procedure GNAT_Pragma
;
4028 -- Called for all GNAT defined pragmas to check the relevant restriction
4029 -- (No_Implementation_Pragmas).
4031 function Is_Before_First_Decl
4032 (Pragma_Node
: Node_Id
;
4033 Decls
: List_Id
) return Boolean;
4034 -- Return True if Pragma_Node is before the first declarative item in
4035 -- Decls where Decls is the list of declarative items.
4037 function Is_Configuration_Pragma
return Boolean;
4038 -- Determines if the placement of the current pragma is appropriate
4039 -- for a configuration pragma.
4041 function Is_In_Context_Clause
return Boolean;
4042 -- Returns True if pragma appears within the context clause of a unit,
4043 -- and False for any other placement (does not generate any messages).
4045 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean;
4046 -- Analyzes the argument, and determines if it is a static string
4047 -- expression, returns True if so, False if non-static or not String.
4048 -- A special case is that a string literal returns True in Ada 83 mode
4049 -- (which has no such thing as static string expressions). Note that
4050 -- the call analyzes its argument, so this cannot be used for the case
4051 -- where an identifier might not be declared.
4053 procedure Pragma_Misplaced
;
4054 pragma No_Return
(Pragma_Misplaced
);
4055 -- Issue fatal error message for misplaced pragma
4057 procedure Process_Atomic_Independent_Shared_Volatile
;
4058 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
4059 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
4060 -- and treated as being identical in effect to pragma Atomic.
4062 procedure Process_Compile_Time_Warning_Or_Error
;
4063 -- Common processing for Compile_Time_Error and Compile_Time_Warning
4065 procedure Process_Convention
4066 (C
: out Convention_Id
;
4067 Ent
: out Entity_Id
);
4068 -- Common processing for Convention, Interface, Import and Export.
4069 -- Checks first two arguments of pragma, and sets the appropriate
4070 -- convention value in the specified entity or entities. On return
4071 -- C is the convention, Ent is the referenced entity.
4073 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
);
4074 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
4075 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
4077 procedure Process_Extended_Import_Export_Object_Pragma
4078 (Arg_Internal
: Node_Id
;
4079 Arg_External
: Node_Id
;
4080 Arg_Size
: Node_Id
);
4081 -- Common processing for the pragmas Import/Export_Object. The three
4082 -- arguments correspond to the three named parameters of the pragmas. An
4083 -- argument is empty if the corresponding parameter is not present in
4086 procedure Process_Extended_Import_Export_Internal_Arg
4087 (Arg_Internal
: Node_Id
:= Empty
);
4088 -- Common processing for all extended Import and Export pragmas. The
4089 -- argument is the pragma parameter for the Internal argument. If
4090 -- Arg_Internal is empty or inappropriate, an error message is posted.
4091 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
4092 -- set to identify the referenced entity.
4094 procedure Process_Extended_Import_Export_Subprogram_Pragma
4095 (Arg_Internal
: Node_Id
;
4096 Arg_External
: Node_Id
;
4097 Arg_Parameter_Types
: Node_Id
;
4098 Arg_Result_Type
: Node_Id
:= Empty
;
4099 Arg_Mechanism
: Node_Id
;
4100 Arg_Result_Mechanism
: Node_Id
:= Empty
);
4101 -- Common processing for all extended Import and Export pragmas applying
4102 -- to subprograms. The caller omits any arguments that do not apply to
4103 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
4104 -- only in the Import_Function and Export_Function cases). The argument
4105 -- names correspond to the allowed pragma association identifiers.
4107 procedure Process_Generic_List
;
4108 -- Common processing for Share_Generic and Inline_Generic
4110 procedure Process_Import_Or_Interface
;
4111 -- Common processing for Import or Interface
4113 procedure Process_Import_Predefined_Type
;
4114 -- Processing for completing a type with pragma Import. This is used
4115 -- to declare types that match predefined C types, especially for cases
4116 -- without corresponding Ada predefined type.
4118 type Inline_Status
is (Suppressed
, Disabled
, Enabled
);
4119 -- Inline status of a subprogram, indicated as follows:
4120 -- Suppressed: inlining is suppressed for the subprogram
4121 -- Disabled: no inlining is requested for the subprogram
4122 -- Enabled: inlining is requested/required for the subprogram
4124 procedure Process_Inline
(Status
: Inline_Status
);
4125 -- Common processing for No_Inline, Inline and Inline_Always. Parameter
4126 -- indicates the inline status specified by the pragma.
4128 procedure Process_Interface_Name
4129 (Subprogram_Def
: Entity_Id
;
4133 -- Given the last two arguments of pragma Import, pragma Export, or
4134 -- pragma Interface_Name, performs validity checks and sets the
4135 -- Interface_Name field of the given subprogram entity to the
4136 -- appropriate external or link name, depending on the arguments given.
4137 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
4138 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
4139 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
4140 -- nor Link_Arg is present, the interface name is set to the default
4141 -- from the subprogram name. In addition, the pragma itself is passed
4142 -- to analyze any expressions in the case the pragma came from an aspect
4145 procedure Process_Interrupt_Or_Attach_Handler
;
4146 -- Common processing for Interrupt and Attach_Handler pragmas
4148 procedure Process_Restrictions_Or_Restriction_Warnings
(Warn
: Boolean);
4149 -- Common processing for Restrictions and Restriction_Warnings pragmas.
4150 -- Warn is True for Restriction_Warnings, or for Restrictions if the
4151 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
4152 -- is not set in the Restrictions case.
4154 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean);
4155 -- Common processing for Suppress and Unsuppress. The boolean parameter
4156 -- Suppress_Case is True for the Suppress case, and False for the
4159 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
);
4160 -- Subsidiary to the analysis of pragmas Independent[_Components].
4161 -- Record such a pragma N applied to entity E for future checks.
4163 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
);
4164 -- This procedure sets the Is_Exported flag for the given entity,
4165 -- checking that the entity was not previously imported. Arg is
4166 -- the argument that specified the entity. A check is also made
4167 -- for exporting inappropriate entities.
4169 procedure Set_Extended_Import_Export_External_Name
4170 (Internal_Ent
: Entity_Id
;
4171 Arg_External
: Node_Id
);
4172 -- Common processing for all extended import export pragmas. The first
4173 -- argument, Internal_Ent, is the internal entity, which has already
4174 -- been checked for validity by the caller. Arg_External is from the
4175 -- Import or Export pragma, and may be null if no External parameter
4176 -- was present. If Arg_External is present and is a non-null string
4177 -- (a null string is treated as the default), then the Interface_Name
4178 -- field of Internal_Ent is set appropriately.
4180 procedure Set_Imported
(E
: Entity_Id
);
4181 -- This procedure sets the Is_Imported flag for the given entity,
4182 -- checking that it is not previously exported or imported.
4184 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
);
4185 -- Mech is a parameter passing mechanism (see Import_Function syntax
4186 -- for MECHANISM_NAME). This routine checks that the mechanism argument
4187 -- has the right form, and if not issues an error message. If the
4188 -- argument has the right form then the Mechanism field of Ent is
4189 -- set appropriately.
4191 procedure Set_Rational_Profile
;
4192 -- Activate the set of configuration pragmas and permissions that make
4193 -- up the Rational profile.
4195 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
);
4196 -- Activate the set of configuration pragmas and restrictions that make
4197 -- up the Profile. Profile must be either GNAT_Extended_Ravenscar,
4198 -- GNAT_Ravenscar_EDF, or Ravenscar. N is the corresponding pragma node,
4199 -- which is used for error messages on any constructs violating the
4202 ----------------------------------
4203 -- Acquire_Warning_Match_String --
4204 ----------------------------------
4206 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
) is
4208 String_To_Name_Buffer
4209 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
4211 -- Add asterisk at start if not already there
4213 if Name_Len
> 0 and then Name_Buffer
(1) /= '*' then
4214 Name_Buffer
(2 .. Name_Len
+ 1) :=
4215 Name_Buffer
(1 .. Name_Len
);
4216 Name_Buffer
(1) := '*';
4217 Name_Len
:= Name_Len
+ 1;
4220 -- Add asterisk at end if not already there
4222 if Name_Buffer
(Name_Len
) /= '*' then
4223 Name_Len
:= Name_Len
+ 1;
4224 Name_Buffer
(Name_Len
) := '*';
4226 end Acquire_Warning_Match_String
;
4228 ---------------------
4229 -- Ada_2005_Pragma --
4230 ---------------------
4232 procedure Ada_2005_Pragma
is
4234 if Ada_Version
<= Ada_95
then
4235 Check_Restriction
(No_Implementation_Pragmas
, N
);
4237 end Ada_2005_Pragma
;
4239 ---------------------
4240 -- Ada_2012_Pragma --
4241 ---------------------
4243 procedure Ada_2012_Pragma
is
4245 if Ada_Version
<= Ada_2005
then
4246 Check_Restriction
(No_Implementation_Pragmas
, N
);
4248 end Ada_2012_Pragma
;
4250 ----------------------------
4251 -- Analyze_Depends_Global --
4252 ----------------------------
4254 procedure Analyze_Depends_Global
4255 (Spec_Id
: out Entity_Id
;
4256 Subp_Decl
: out Node_Id
;
4257 Legal
: out Boolean)
4260 -- Assume that the pragma is illegal
4267 Check_Arg_Count
(1);
4269 -- Ensure the proper placement of the pragma. Depends/Global must be
4270 -- associated with a subprogram declaration or a body that acts as a
4273 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4277 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4280 -- Generic subprogram
4282 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4285 -- Object declaration of a single concurrent type
4287 elsif Nkind
(Subp_Decl
) = N_Object_Declaration
4288 and then Is_Single_Concurrent_Object
4289 (Unique_Defining_Entity
(Subp_Decl
))
4295 elsif Nkind
(Subp_Decl
) = N_Single_Task_Declaration
then
4298 -- Subprogram body acts as spec
4300 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4301 and then No
(Corresponding_Spec
(Subp_Decl
))
4305 -- Subprogram body stub acts as spec
4307 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4308 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
4312 -- Subprogram declaration
4314 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4319 elsif Nkind
(Subp_Decl
) = N_Task_Type_Declaration
then
4327 -- If we get here, then the pragma is legal
4330 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
4332 -- When the related context is an entry, the entry must belong to a
4333 -- protected unit (SPARK RM 6.1.4(6)).
4335 if Is_Entry_Declaration
(Spec_Id
)
4336 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
4341 -- When the related context is an anonymous object created for a
4342 -- simple concurrent type, the type must be a task
4343 -- (SPARK RM 6.1.4(6)).
4345 elsif Is_Single_Concurrent_Object
(Spec_Id
)
4346 and then Ekind
(Etype
(Spec_Id
)) /= E_Task_Type
4352 -- A pragma that applies to a Ghost entity becomes Ghost for the
4353 -- purposes of legality checks and removal of ignored Ghost code.
4355 Mark_Ghost_Pragma
(N
, Spec_Id
);
4356 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4357 end Analyze_Depends_Global
;
4359 ------------------------
4360 -- Analyze_If_Present --
4361 ------------------------
4363 procedure Analyze_If_Present
(Id
: Pragma_Id
) is
4367 pragma Assert
(Is_List_Member
(N
));
4369 -- Inspect the declarations or statements following pragma N looking
4370 -- for another pragma whose Id matches the caller's request. If it is
4371 -- available, analyze it.
4374 while Present
(Stmt
) loop
4375 if Nkind
(Stmt
) = N_Pragma
and then Get_Pragma_Id
(Stmt
) = Id
then
4376 Analyze_Pragma
(Stmt
);
4379 -- The first source declaration or statement immediately following
4380 -- N ends the region where a pragma may appear.
4382 elsif Comes_From_Source
(Stmt
) then
4388 end Analyze_If_Present
;
4390 --------------------------------
4391 -- Analyze_Pre_Post_Condition --
4392 --------------------------------
4394 procedure Analyze_Pre_Post_Condition
is
4395 Prag_Iden
: constant Node_Id
:= Pragma_Identifier
(N
);
4396 Subp_Decl
: Node_Id
;
4397 Subp_Id
: Entity_Id
;
4399 Duplicates_OK
: Boolean := False;
4400 -- Flag set when a pre/postcondition allows multiple pragmas of the
4403 In_Body_OK
: Boolean := False;
4404 -- Flag set when a pre/postcondition is allowed to appear on a body
4405 -- even though the subprogram may have a spec.
4407 Is_Pre_Post
: Boolean := False;
4408 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4411 function Inherits_Class_Wide_Pre
(E
: Entity_Id
) return Boolean;
4412 -- Implement rules in AI12-0131: an overriding operation can have
4413 -- a class-wide precondition only if one of its ancestors has an
4414 -- explicit class-wide precondition.
4416 -----------------------------
4417 -- Inherits_Class_Wide_Pre --
4418 -----------------------------
4420 function Inherits_Class_Wide_Pre
(E
: Entity_Id
) return Boolean is
4421 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(E
);
4424 Prev
: Entity_Id
:= Overridden_Operation
(E
);
4427 -- Check ancestors on the overriding operation to examine the
4428 -- preconditions that may apply to them.
4430 while Present
(Prev
) loop
4431 Cont
:= Contract
(Prev
);
4432 if Present
(Cont
) then
4433 Prag
:= Pre_Post_Conditions
(Cont
);
4434 while Present
(Prag
) loop
4435 if Class_Present
(Prag
) then
4439 Prag
:= Next_Pragma
(Prag
);
4443 -- For a type derived from a generic formal type, the operation
4444 -- inheriting the condition is a renaming, not an overriding of
4445 -- the operation of the formal. Ditto for an inherited
4446 -- operation which has no explicit contracts.
4448 if Is_Generic_Type
(Find_Dispatching_Type
(Prev
))
4449 or else not Comes_From_Source
(Prev
)
4451 Prev
:= Alias
(Prev
);
4453 Prev
:= Overridden_Operation
(Prev
);
4457 -- If the controlling type of the subprogram has progenitors, an
4458 -- interface operation implemented by the current operation may
4459 -- have a class-wide precondition.
4461 if Has_Interfaces
(Typ
) then
4466 Prim_Elmt
: Elmt_Id
;
4467 Prim_List
: Elist_Id
;
4470 Collect_Interfaces
(Typ
, Ints
);
4471 Elmt
:= First_Elmt
(Ints
);
4473 -- Iterate over the primitive operations of each interface
4475 while Present
(Elmt
) loop
4476 Prim_List
:= Direct_Primitive_Operations
(Node
(Elmt
));
4477 Prim_Elmt
:= First_Elmt
(Prim_List
);
4478 while Present
(Prim_Elmt
) loop
4479 Prim
:= Node
(Prim_Elmt
);
4480 if Chars
(Prim
) = Chars
(E
)
4481 and then Present
(Contract
(Prim
))
4482 and then Class_Present
4483 (Pre_Post_Conditions
(Contract
(Prim
)))
4488 Next_Elmt
(Prim_Elmt
);
4497 end Inherits_Class_Wide_Pre
;
4499 -- Start of processing for Analyze_Pre_Post_Condition
4502 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4503 -- offer uniformity among the various kinds of pre/postconditions by
4504 -- rewriting the pragma identifier. This allows the retrieval of the
4505 -- original pragma name by routine Original_Aspect_Pragma_Name.
4507 if Comes_From_Source
(N
) then
4508 if Nam_In
(Pname
, Name_Pre
, Name_Pre_Class
) then
4509 Is_Pre_Post
:= True;
4510 Set_Class_Present
(N
, Pname
= Name_Pre_Class
);
4511 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Precondition
));
4513 elsif Nam_In
(Pname
, Name_Post
, Name_Post_Class
) then
4514 Is_Pre_Post
:= True;
4515 Set_Class_Present
(N
, Pname
= Name_Post_Class
);
4516 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Postcondition
));
4520 -- Determine the semantics with respect to duplicates and placement
4521 -- in a body. Pragmas Precondition and Postcondition were introduced
4522 -- before aspects and are not subject to the same aspect-like rules.
4524 if Nam_In
(Pname
, Name_Precondition
, Name_Postcondition
) then
4525 Duplicates_OK
:= True;
4531 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4532 -- argument without an identifier.
4535 Check_Arg_Count
(1);
4536 Check_No_Identifiers
;
4538 -- Pragmas Precondition and Postcondition have complex argument
4542 Check_At_Least_N_Arguments
(1);
4543 Check_At_Most_N_Arguments
(2);
4544 Check_Optional_Identifier
(Arg1
, Name_Check
);
4546 if Present
(Arg2
) then
4547 Check_Optional_Identifier
(Arg2
, Name_Message
);
4548 Preanalyze_Spec_Expression
4549 (Get_Pragma_Arg
(Arg2
), Standard_String
);
4553 -- For a pragma PPC in the extended main source unit, record enabled
4555 -- ??? nothing checks that the pragma is in the main source unit
4557 if Is_Checked
(N
) and then not Split_PPC
(N
) then
4558 Set_SCO_Pragma_Enabled
(Loc
);
4561 -- Ensure the proper placement of the pragma
4564 Find_Related_Declaration_Or_Body
4565 (N
, Do_Checks
=> not Duplicates_OK
);
4567 -- When a pre/postcondition pragma applies to an abstract subprogram,
4568 -- its original form must be an aspect with 'Class.
4570 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
4571 if not From_Aspect_Specification
(N
) then
4573 ("pragma % cannot be applied to abstract subprogram");
4575 elsif not Class_Present
(N
) then
4577 ("aspect % requires ''Class for abstract subprogram");
4580 -- Entry declaration
4582 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4585 -- Generic subprogram declaration
4587 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4592 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4593 and then (No
(Corresponding_Spec
(Subp_Decl
)) or In_Body_OK
)
4597 -- Subprogram body stub
4599 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4600 and then (No
(Corresponding_Spec_Of_Stub
(Subp_Decl
)) or In_Body_OK
)
4604 -- Subprogram declaration
4606 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4608 -- AI05-0230: When a pre/postcondition pragma applies to a null
4609 -- procedure, its original form must be an aspect with 'Class.
4611 if Nkind
(Specification
(Subp_Decl
)) = N_Procedure_Specification
4612 and then Null_Present
(Specification
(Subp_Decl
))
4613 and then From_Aspect_Specification
(N
)
4614 and then not Class_Present
(N
)
4616 Error_Pragma
("aspect % requires ''Class for null procedure");
4619 -- Implement the legality checks mandated by AI12-0131:
4620 -- Pre'Class shall not be specified for an overriding primitive
4621 -- subprogram of a tagged type T unless the Pre'Class aspect is
4622 -- specified for the corresponding primitive subprogram of some
4626 E
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
4629 if Class_Present
(N
)
4630 and then Pragma_Name
(N
) = Name_Precondition
4631 and then Present
(Overridden_Operation
(E
))
4632 and then not Inherits_Class_Wide_Pre
(E
)
4635 ("illegal class-wide precondition on overriding operation",
4636 Corresponding_Aspect
(N
));
4640 -- A renaming declaration may inherit a generated pragma, its
4641 -- placement comes from expansion, not from source.
4643 elsif Nkind
(Subp_Decl
) = N_Subprogram_Renaming_Declaration
4644 and then not Comes_From_Source
(N
)
4648 -- Otherwise the placement is illegal
4655 Subp_Id
:= Defining_Entity
(Subp_Decl
);
4657 -- A pragma that applies to a Ghost entity becomes Ghost for the
4658 -- purposes of legality checks and removal of ignored Ghost code.
4660 Mark_Ghost_Pragma
(N
, Subp_Id
);
4662 -- Chain the pragma on the contract for further processing by
4663 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4665 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
4667 -- Fully analyze the pragma when it appears inside an entry or
4668 -- subprogram body because it cannot benefit from forward references.
4670 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
4672 N_Subprogram_Body_Stub
)
4674 -- The legality checks of pragmas Precondition and Postcondition
4675 -- are affected by the SPARK mode in effect and the volatility of
4676 -- the context. Analyze all pragmas in a specific order.
4678 Analyze_If_Present
(Pragma_SPARK_Mode
);
4679 Analyze_If_Present
(Pragma_Volatile_Function
);
4680 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
4682 end Analyze_Pre_Post_Condition
;
4684 -----------------------------------------
4685 -- Analyze_Refined_Depends_Global_Post --
4686 -----------------------------------------
4688 procedure Analyze_Refined_Depends_Global_Post
4689 (Spec_Id
: out Entity_Id
;
4690 Body_Id
: out Entity_Id
;
4691 Legal
: out Boolean)
4693 Body_Decl
: Node_Id
;
4694 Spec_Decl
: Node_Id
;
4697 -- Assume that the pragma is illegal
4704 Check_Arg_Count
(1);
4705 Check_No_Identifiers
;
4707 -- Verify the placement of the pragma and check for duplicates. The
4708 -- pragma must apply to a subprogram body [stub].
4710 Body_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4714 if Nkind
(Body_Decl
) = N_Entry_Body
then
4719 elsif Nkind
(Body_Decl
) = N_Subprogram_Body
then
4722 -- Subprogram body stub
4724 elsif Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
4729 elsif Nkind
(Body_Decl
) = N_Task_Body
then
4737 Body_Id
:= Defining_Entity
(Body_Decl
);
4738 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
4740 -- The pragma must apply to the second declaration of a subprogram.
4741 -- In other words, the body [stub] cannot acts as a spec.
4743 if No
(Spec_Id
) then
4744 Error_Pragma
("pragma % cannot apply to a stand alone body");
4747 -- Catch the case where the subprogram body is a subunit and acts as
4748 -- the third declaration of the subprogram.
4750 elsif Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
4751 Error_Pragma
("pragma % cannot apply to a subunit");
4755 -- A refined pragma can only apply to the body [stub] of a subprogram
4756 -- declared in the visible part of a package. Retrieve the context of
4757 -- the subprogram declaration.
4759 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
4761 -- When dealing with protected entries or protected subprograms, use
4762 -- the enclosing protected type as the proper context.
4764 if Ekind_In
(Spec_Id
, E_Entry
,
4768 and then Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
4770 Spec_Decl
:= Declaration_Node
(Scope
(Spec_Id
));
4773 if Nkind
(Parent
(Spec_Decl
)) /= N_Package_Specification
then
4775 (Fix_Msg
(Spec_Id
, "pragma % must apply to the body of "
4776 & "subprogram declared in a package specification"));
4780 -- If we get here, then the pragma is legal
4784 -- A pragma that applies to a Ghost entity becomes Ghost for the
4785 -- purposes of legality checks and removal of ignored Ghost code.
4787 Mark_Ghost_Pragma
(N
, Spec_Id
);
4789 if Nam_In
(Pname
, Name_Refined_Depends
, Name_Refined_Global
) then
4790 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4792 end Analyze_Refined_Depends_Global_Post
;
4794 ----------------------------------
4795 -- Analyze_Unmodified_Or_Unused --
4796 ----------------------------------
4798 procedure Analyze_Unmodified_Or_Unused
(Is_Unused
: Boolean := False) is
4803 Ghost_Error_Posted
: Boolean := False;
4804 -- Flag set when an error concerning the illegal mix of Ghost and
4805 -- non-Ghost variables is emitted.
4807 Ghost_Id
: Entity_Id
:= Empty
;
4808 -- The entity of the first Ghost variable encountered while
4809 -- processing the arguments of the pragma.
4813 Check_At_Least_N_Arguments
(1);
4815 -- Loop through arguments
4818 while Present
(Arg
) loop
4819 Check_No_Identifier
(Arg
);
4821 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4822 -- in fact generate reference, so that the entity will have a
4823 -- reference, which will inhibit any warnings about it not
4824 -- being referenced, and also properly show up in the ali file
4825 -- as a reference. But this reference is recorded before the
4826 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4827 -- generated for this reference.
4829 Check_Arg_Is_Local_Name
(Arg
);
4830 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4832 if Is_Entity_Name
(Arg_Expr
) then
4833 Arg_Id
:= Entity
(Arg_Expr
);
4835 -- Skip processing the argument if already flagged
4837 if Is_Assignable
(Arg_Id
)
4838 and then not Has_Pragma_Unmodified
(Arg_Id
)
4839 and then not Has_Pragma_Unused
(Arg_Id
)
4841 Set_Has_Pragma_Unmodified
(Arg_Id
);
4844 Set_Has_Pragma_Unused
(Arg_Id
);
4847 -- A pragma that applies to a Ghost entity becomes Ghost for
4848 -- the purposes of legality checks and removal of ignored
4851 Mark_Ghost_Pragma
(N
, Arg_Id
);
4853 -- Capture the entity of the first Ghost variable being
4854 -- processed for error detection purposes.
4856 if Is_Ghost_Entity
(Arg_Id
) then
4857 if No
(Ghost_Id
) then
4861 -- Otherwise the variable is non-Ghost. It is illegal to mix
4862 -- references to Ghost and non-Ghost entities
4865 elsif Present
(Ghost_Id
)
4866 and then not Ghost_Error_Posted
4868 Ghost_Error_Posted
:= True;
4870 Error_Msg_Name_1
:= Pname
;
4872 ("pragma % cannot mention ghost and non-ghost "
4875 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
4876 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
4878 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
4879 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
4882 -- Warn if already flagged as Unused or Unmodified
4884 elsif Has_Pragma_Unmodified
(Arg_Id
) then
4885 if Has_Pragma_Unused
(Arg_Id
) then
4887 ("??pragma Unused already given for &!", Arg_Expr
,
4891 ("??pragma Unmodified already given for &!", Arg_Expr
,
4895 -- Otherwise the pragma referenced an illegal entity
4899 ("pragma% can only be applied to a variable", Arg_Expr
);
4905 end Analyze_Unmodified_Or_Unused
;
4907 -----------------------------------
4908 -- Analyze_Unreference_Or_Unused --
4909 -----------------------------------
4911 procedure Analyze_Unreferenced_Or_Unused
4912 (Is_Unused
: Boolean := False)
4919 Ghost_Error_Posted
: Boolean := False;
4920 -- Flag set when an error concerning the illegal mix of Ghost and
4921 -- non-Ghost names is emitted.
4923 Ghost_Id
: Entity_Id
:= Empty
;
4924 -- The entity of the first Ghost name encountered while processing
4925 -- the arguments of the pragma.
4929 Check_At_Least_N_Arguments
(1);
4931 -- Check case of appearing within context clause
4933 if not Is_Unused
and then Is_In_Context_Clause
then
4935 -- The arguments must all be units mentioned in a with clause in
4936 -- the same context clause. Note that Par.Prag already checked
4937 -- that the arguments are either identifiers or selected
4941 while Present
(Arg
) loop
4942 Citem
:= First
(List_Containing
(N
));
4943 while Citem
/= N
loop
4944 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4946 if Nkind
(Citem
) = N_With_Clause
4947 and then Same_Name
(Name
(Citem
), Arg_Expr
)
4949 Set_Has_Pragma_Unreferenced
4952 (Library_Unit
(Citem
))));
4953 Set_Elab_Unit_Name
(Arg_Expr
, Name
(Citem
));
4962 ("argument of pragma% is not withed unit", Arg
);
4968 -- Case of not in list of context items
4972 while Present
(Arg
) loop
4973 Check_No_Identifier
(Arg
);
4975 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
4976 -- in fact generate reference, so that the entity will have a
4977 -- reference, which will inhibit any warnings about it not
4978 -- being referenced, and also properly show up in the ali file
4979 -- as a reference. But this reference is recorded before the
4980 -- Has_Pragma_Unreferenced flag is set, so that no warning is
4981 -- generated for this reference.
4983 Check_Arg_Is_Local_Name
(Arg
);
4984 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
4986 if Is_Entity_Name
(Arg_Expr
) then
4987 Arg_Id
:= Entity
(Arg_Expr
);
4989 -- Warn if already flagged as Unused or Unreferenced and
4990 -- skip processing the argument.
4992 if Has_Pragma_Unreferenced
(Arg_Id
) then
4993 if Has_Pragma_Unused
(Arg_Id
) then
4995 ("??pragma Unused already given for &!", Arg_Expr
,
4999 ("??pragma Unreferenced already given for &!",
5003 -- Apply Unreferenced to the entity
5006 -- If the entity is overloaded, the pragma applies to the
5007 -- most recent overloading, as documented. In this case,
5008 -- name resolution does not generate a reference, so it
5009 -- must be done here explicitly.
5011 if Is_Overloaded
(Arg_Expr
) then
5012 Generate_Reference
(Arg_Id
, N
);
5015 Set_Has_Pragma_Unreferenced
(Arg_Id
);
5018 Set_Has_Pragma_Unused
(Arg_Id
);
5021 -- A pragma that applies to a Ghost entity becomes Ghost
5022 -- for the purposes of legality checks and removal of
5023 -- ignored Ghost code.
5025 Mark_Ghost_Pragma
(N
, Arg_Id
);
5027 -- Capture the entity of the first Ghost name being
5028 -- processed for error detection purposes.
5030 if Is_Ghost_Entity
(Arg_Id
) then
5031 if No
(Ghost_Id
) then
5035 -- Otherwise the name is non-Ghost. It is illegal to mix
5036 -- references to Ghost and non-Ghost entities
5039 elsif Present
(Ghost_Id
)
5040 and then not Ghost_Error_Posted
5042 Ghost_Error_Posted
:= True;
5044 Error_Msg_Name_1
:= Pname
;
5046 ("pragma % cannot mention ghost and non-ghost "
5049 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
5051 ("\& # declared as ghost", N
, Ghost_Id
);
5053 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
5055 ("\& # declared as non-ghost", N
, Arg_Id
);
5063 end Analyze_Unreferenced_Or_Unused
;
5065 --------------------------
5066 -- Check_Ada_83_Warning --
5067 --------------------------
5069 procedure Check_Ada_83_Warning
is
5071 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
5072 Error_Msg_N
("(Ada 83) pragma& is non-standard??", N
);
5074 end Check_Ada_83_Warning
;
5076 ---------------------
5077 -- Check_Arg_Count --
5078 ---------------------
5080 procedure Check_Arg_Count
(Required
: Nat
) is
5082 if Arg_Count
/= Required
then
5083 Error_Pragma
("wrong number of arguments for pragma%");
5085 end Check_Arg_Count
;
5087 --------------------------------
5088 -- Check_Arg_Is_External_Name --
5089 --------------------------------
5091 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
) is
5092 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5095 if Nkind
(Argx
) = N_Identifier
then
5099 Analyze_And_Resolve
(Argx
, Standard_String
);
5101 if Is_OK_Static_Expression
(Argx
) then
5104 elsif Etype
(Argx
) = Any_Type
then
5107 -- An interesting special case, if we have a string literal and
5108 -- we are in Ada 83 mode, then we allow it even though it will
5109 -- not be flagged as static. This allows expected Ada 83 mode
5110 -- use of external names which are string literals, even though
5111 -- technically these are not static in Ada 83.
5113 elsif Ada_Version
= Ada_83
5114 and then Nkind
(Argx
) = N_String_Literal
5118 -- Here we have a real error (non-static expression)
5121 Error_Msg_Name_1
:= Pname
;
5122 Flag_Non_Static_Expr
5123 (Fix_Error
("argument for pragma% must be a identifier or "
5124 & "static string expression!"), Argx
);
5129 end Check_Arg_Is_External_Name
;
5131 -----------------------------
5132 -- Check_Arg_Is_Identifier --
5133 -----------------------------
5135 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
) is
5136 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5138 if Nkind
(Argx
) /= N_Identifier
then
5139 Error_Pragma_Arg
("argument for pragma% must be identifier", Argx
);
5141 end Check_Arg_Is_Identifier
;
5143 ----------------------------------
5144 -- Check_Arg_Is_Integer_Literal --
5145 ----------------------------------
5147 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
) is
5148 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5150 if Nkind
(Argx
) /= N_Integer_Literal
then
5152 ("argument for pragma% must be integer literal", Argx
);
5154 end Check_Arg_Is_Integer_Literal
;
5156 -------------------------------------------
5157 -- Check_Arg_Is_Library_Level_Local_Name --
5158 -------------------------------------------
5162 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5163 -- | library_unit_NAME
5165 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
) is
5167 Check_Arg_Is_Local_Name
(Arg
);
5169 -- If it came from an aspect, we want to give the error just as if it
5170 -- came from source.
5172 if not Is_Library_Level_Entity
(Entity
(Get_Pragma_Arg
(Arg
)))
5173 and then (Comes_From_Source
(N
)
5174 or else Present
(Corresponding_Aspect
(Parent
(Arg
))))
5177 ("argument for pragma% must be library level entity", Arg
);
5179 end Check_Arg_Is_Library_Level_Local_Name
;
5181 -----------------------------
5182 -- Check_Arg_Is_Local_Name --
5183 -----------------------------
5187 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
5188 -- | library_unit_NAME
5190 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
) is
5191 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5194 -- If this pragma came from an aspect specification, we don't want to
5195 -- check for this error, because that would cause spurious errors, in
5196 -- case a type is frozen in a scope more nested than the type. The
5197 -- aspect itself of course can't be anywhere but on the declaration
5200 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
5201 if From_Aspect_Specification
(Parent
(Arg
)) then
5205 -- Arg is the Expression of an N_Pragma_Argument_Association
5208 if From_Aspect_Specification
(Parent
(Parent
(Arg
))) then
5215 if Nkind
(Argx
) not in N_Direct_Name
5216 and then (Nkind
(Argx
) /= N_Attribute_Reference
5217 or else Present
(Expressions
(Argx
))
5218 or else Nkind
(Prefix
(Argx
)) /= N_Identifier
)
5219 and then (not Is_Entity_Name
(Argx
)
5220 or else not Is_Compilation_Unit
(Entity
(Argx
)))
5222 Error_Pragma_Arg
("argument for pragma% must be local name", Argx
);
5225 -- No further check required if not an entity name
5227 if not Is_Entity_Name
(Argx
) then
5233 Ent
: constant Entity_Id
:= Entity
(Argx
);
5234 Scop
: constant Entity_Id
:= Scope
(Ent
);
5237 -- Case of a pragma applied to a compilation unit: pragma must
5238 -- occur immediately after the program unit in the compilation.
5240 if Is_Compilation_Unit
(Ent
) then
5242 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
5245 -- Case of pragma placed immediately after spec
5247 if Parent
(N
) = Aux_Decls_Node
(Parent
(Decl
)) then
5250 -- Case of pragma placed immediately after body
5252 elsif Nkind
(Decl
) = N_Subprogram_Declaration
5253 and then Present
(Corresponding_Body
(Decl
))
5257 (Parent
(Unit_Declaration_Node
5258 (Corresponding_Body
(Decl
))));
5260 -- All other cases are illegal
5267 -- Special restricted placement rule from 10.2.1(11.8/2)
5269 elsif Is_Generic_Formal
(Ent
)
5270 and then Prag_Id
= Pragma_Preelaborable_Initialization
5272 OK
:= List_Containing
(N
) =
5273 Generic_Formal_Declarations
5274 (Unit_Declaration_Node
(Scop
));
5276 -- If this is an aspect applied to a subprogram body, the
5277 -- pragma is inserted in its declarative part.
5279 elsif From_Aspect_Specification
(N
)
5280 and then Ent
= Current_Scope
5282 Nkind
(Unit_Declaration_Node
(Ent
)) = N_Subprogram_Body
5286 -- If the aspect is a predicate (possibly others ???) and the
5287 -- context is a record type, this is a discriminant expression
5288 -- within a type declaration, that freezes the predicated
5291 elsif From_Aspect_Specification
(N
)
5292 and then Prag_Id
= Pragma_Predicate
5293 and then Ekind
(Current_Scope
) = E_Record_Type
5294 and then Scop
= Scope
(Current_Scope
)
5298 -- Default case, just check that the pragma occurs in the scope
5299 -- of the entity denoted by the name.
5302 OK
:= Current_Scope
= Scop
;
5307 ("pragma% argument must be in same declarative part", Arg
);
5311 end Check_Arg_Is_Local_Name
;
5313 ---------------------------------
5314 -- Check_Arg_Is_Locking_Policy --
5315 ---------------------------------
5317 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
) is
5318 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5321 Check_Arg_Is_Identifier
(Argx
);
5323 if not Is_Locking_Policy_Name
(Chars
(Argx
)) then
5324 Error_Pragma_Arg
("& is not a valid locking policy name", Argx
);
5326 end Check_Arg_Is_Locking_Policy
;
5328 -----------------------------------------------
5329 -- Check_Arg_Is_Partition_Elaboration_Policy --
5330 -----------------------------------------------
5332 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
) is
5333 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5336 Check_Arg_Is_Identifier
(Argx
);
5338 if not Is_Partition_Elaboration_Policy_Name
(Chars
(Argx
)) then
5340 ("& is not a valid partition elaboration policy name", Argx
);
5342 end Check_Arg_Is_Partition_Elaboration_Policy
;
5344 -------------------------
5345 -- Check_Arg_Is_One_Of --
5346 -------------------------
5348 procedure Check_Arg_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
5349 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5352 Check_Arg_Is_Identifier
(Argx
);
5354 if not Nam_In
(Chars
(Argx
), N1
, N2
) then
5355 Error_Msg_Name_2
:= N1
;
5356 Error_Msg_Name_3
:= N2
;
5357 Error_Pragma_Arg
("argument for pragma% must be% or%", Argx
);
5359 end Check_Arg_Is_One_Of
;
5361 procedure Check_Arg_Is_One_Of
5363 N1
, N2
, N3
: Name_Id
)
5365 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5368 Check_Arg_Is_Identifier
(Argx
);
5370 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
) then
5371 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5373 end Check_Arg_Is_One_Of
;
5375 procedure Check_Arg_Is_One_Of
5377 N1
, N2
, N3
, N4
: Name_Id
)
5379 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5382 Check_Arg_Is_Identifier
(Argx
);
5384 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
) then
5385 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5387 end Check_Arg_Is_One_Of
;
5389 procedure Check_Arg_Is_One_Of
5391 N1
, N2
, N3
, N4
, N5
: Name_Id
)
5393 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5396 Check_Arg_Is_Identifier
(Argx
);
5398 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
, N5
) then
5399 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
5401 end Check_Arg_Is_One_Of
;
5403 ---------------------------------
5404 -- Check_Arg_Is_Queuing_Policy --
5405 ---------------------------------
5407 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
) is
5408 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5411 Check_Arg_Is_Identifier
(Argx
);
5413 if not Is_Queuing_Policy_Name
(Chars
(Argx
)) then
5414 Error_Pragma_Arg
("& is not a valid queuing policy name", Argx
);
5416 end Check_Arg_Is_Queuing_Policy
;
5418 ---------------------------------------
5419 -- Check_Arg_Is_OK_Static_Expression --
5420 ---------------------------------------
5422 procedure Check_Arg_Is_OK_Static_Expression
5424 Typ
: Entity_Id
:= Empty
)
5427 Check_Expr_Is_OK_Static_Expression
(Get_Pragma_Arg
(Arg
), Typ
);
5428 end Check_Arg_Is_OK_Static_Expression
;
5430 ------------------------------------------
5431 -- Check_Arg_Is_Task_Dispatching_Policy --
5432 ------------------------------------------
5434 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
) is
5435 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5438 Check_Arg_Is_Identifier
(Argx
);
5440 if not Is_Task_Dispatching_Policy_Name
(Chars
(Argx
)) then
5442 ("& is not an allowed task dispatching policy name", Argx
);
5444 end Check_Arg_Is_Task_Dispatching_Policy
;
5446 ---------------------
5447 -- Check_Arg_Order --
5448 ---------------------
5450 procedure Check_Arg_Order
(Names
: Name_List
) is
5453 Highest_So_Far
: Natural := 0;
5454 -- Highest index in Names seen do far
5458 for J
in 1 .. Arg_Count
loop
5459 if Chars
(Arg
) /= No_Name
then
5460 for K
in Names
'Range loop
5461 if Chars
(Arg
) = Names
(K
) then
5462 if K
< Highest_So_Far
then
5463 Error_Msg_Name_1
:= Pname
;
5465 ("parameters out of order for pragma%", Arg
);
5466 Error_Msg_Name_1
:= Names
(K
);
5467 Error_Msg_Name_2
:= Names
(Highest_So_Far
);
5468 Error_Msg_N
("\% must appear before %", Arg
);
5472 Highest_So_Far
:= K
;
5480 end Check_Arg_Order
;
5482 --------------------------------
5483 -- Check_At_Least_N_Arguments --
5484 --------------------------------
5486 procedure Check_At_Least_N_Arguments
(N
: Nat
) is
5488 if Arg_Count
< N
then
5489 Error_Pragma
("too few arguments for pragma%");
5491 end Check_At_Least_N_Arguments
;
5493 -------------------------------
5494 -- Check_At_Most_N_Arguments --
5495 -------------------------------
5497 procedure Check_At_Most_N_Arguments
(N
: Nat
) is
5500 if Arg_Count
> N
then
5502 for J
in 1 .. N
loop
5504 Error_Pragma_Arg
("too many arguments for pragma%", Arg
);
5507 end Check_At_Most_N_Arguments
;
5509 ---------------------
5510 -- Check_Component --
5511 ---------------------
5513 procedure Check_Component
5516 In_Variant_Part
: Boolean := False)
5518 Comp_Id
: constant Entity_Id
:= Defining_Identifier
(Comp
);
5519 Sindic
: constant Node_Id
:=
5520 Subtype_Indication
(Component_Definition
(Comp
));
5521 Typ
: constant Entity_Id
:= Etype
(Comp_Id
);
5524 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
5525 -- object constraint, then the component type shall be an Unchecked_
5528 if Nkind
(Sindic
) = N_Subtype_Indication
5529 and then Has_Per_Object_Constraint
(Comp_Id
)
5530 and then not Is_Unchecked_Union
(Etype
(Subtype_Mark
(Sindic
)))
5533 ("component subtype subject to per-object constraint "
5534 & "must be an Unchecked_Union", Comp
);
5536 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
5537 -- the body of a generic unit, or within the body of any of its
5538 -- descendant library units, no part of the type of a component
5539 -- declared in a variant_part of the unchecked union type shall be of
5540 -- a formal private type or formal private extension declared within
5541 -- the formal part of the generic unit.
5543 elsif Ada_Version
>= Ada_2012
5544 and then In_Generic_Body
(UU_Typ
)
5545 and then In_Variant_Part
5546 and then Is_Private_Type
(Typ
)
5547 and then Is_Generic_Type
(Typ
)
5550 ("component of unchecked union cannot be of generic type", Comp
);
5552 elsif Needs_Finalization
(Typ
) then
5554 ("component of unchecked union cannot be controlled", Comp
);
5556 elsif Has_Task
(Typ
) then
5558 ("component of unchecked union cannot have tasks", Comp
);
5560 end Check_Component
;
5562 ----------------------------
5563 -- Check_Duplicate_Pragma --
5564 ----------------------------
5566 procedure Check_Duplicate_Pragma
(E
: Entity_Id
) is
5567 Id
: Entity_Id
:= E
;
5571 -- Nothing to do if this pragma comes from an aspect specification,
5572 -- since we could not be duplicating a pragma, and we dealt with the
5573 -- case of duplicated aspects in Analyze_Aspect_Specifications.
5575 if From_Aspect_Specification
(N
) then
5579 -- Otherwise current pragma may duplicate previous pragma or a
5580 -- previously given aspect specification or attribute definition
5581 -- clause for the same pragma.
5583 P
:= Get_Rep_Item
(E
, Pragma_Name
(N
), Check_Parents
=> False);
5587 -- If the entity is a type, then we have to make sure that the
5588 -- ostensible duplicate is not for a parent type from which this
5592 if Nkind
(P
) = N_Pragma
then
5594 Args
: constant List_Id
:=
5595 Pragma_Argument_Associations
(P
);
5598 and then Is_Entity_Name
(Expression
(First
(Args
)))
5599 and then Is_Type
(Entity
(Expression
(First
(Args
))))
5600 and then Entity
(Expression
(First
(Args
))) /= E
5606 elsif Nkind
(P
) = N_Aspect_Specification
5607 and then Is_Type
(Entity
(P
))
5608 and then Entity
(P
) /= E
5614 -- Here we have a definite duplicate
5616 Error_Msg_Name_1
:= Pragma_Name
(N
);
5617 Error_Msg_Sloc
:= Sloc
(P
);
5619 -- For a single protected or a single task object, the error is
5620 -- issued on the original entity.
5622 if Ekind_In
(Id
, E_Task_Type
, E_Protected_Type
) then
5623 Id
:= Defining_Identifier
(Original_Node
(Parent
(Id
)));
5626 if Nkind
(P
) = N_Aspect_Specification
5627 or else From_Aspect_Specification
(P
)
5629 Error_Msg_NE
("aspect% for & previously given#", N
, Id
);
5631 Error_Msg_NE
("pragma% for & duplicates pragma#", N
, Id
);
5636 end Check_Duplicate_Pragma
;
5638 ----------------------------------
5639 -- Check_Duplicated_Export_Name --
5640 ----------------------------------
5642 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
) is
5643 String_Val
: constant String_Id
:= Strval
(Nam
);
5646 -- We are only interested in the export case, and in the case of
5647 -- generics, it is the instance, not the template, that is the
5648 -- problem (the template will generate a warning in any case).
5650 if not Inside_A_Generic
5651 and then (Prag_Id
= Pragma_Export
5653 Prag_Id
= Pragma_Export_Procedure
5655 Prag_Id
= Pragma_Export_Valued_Procedure
5657 Prag_Id
= Pragma_Export_Function
)
5659 for J
in Externals
.First
.. Externals
.Last
loop
5660 if String_Equal
(String_Val
, Strval
(Externals
.Table
(J
))) then
5661 Error_Msg_Sloc
:= Sloc
(Externals
.Table
(J
));
5662 Error_Msg_N
("external name duplicates name given#", Nam
);
5667 Externals
.Append
(Nam
);
5669 end Check_Duplicated_Export_Name
;
5671 ----------------------------------------
5672 -- Check_Expr_Is_OK_Static_Expression --
5673 ----------------------------------------
5675 procedure Check_Expr_Is_OK_Static_Expression
5677 Typ
: Entity_Id
:= Empty
)
5680 if Present
(Typ
) then
5681 Analyze_And_Resolve
(Expr
, Typ
);
5683 Analyze_And_Resolve
(Expr
);
5686 -- An expression cannot be considered static if its resolution failed
5687 -- or if it's erroneous. Stop the analysis of the related pragma.
5689 if Etype
(Expr
) = Any_Type
or else Error_Posted
(Expr
) then
5692 elsif Is_OK_Static_Expression
(Expr
) then
5695 -- An interesting special case, if we have a string literal and we
5696 -- are in Ada 83 mode, then we allow it even though it will not be
5697 -- flagged as static. This allows the use of Ada 95 pragmas like
5698 -- Import in Ada 83 mode. They will of course be flagged with
5699 -- warnings as usual, but will not cause errors.
5701 elsif Ada_Version
= Ada_83
5702 and then Nkind
(Expr
) = N_String_Literal
5706 -- Finally, we have a real error
5709 Error_Msg_Name_1
:= Pname
;
5710 Flag_Non_Static_Expr
5711 (Fix_Error
("argument for pragma% must be a static expression!"),
5715 end Check_Expr_Is_OK_Static_Expression
;
5717 -------------------------
5718 -- Check_First_Subtype --
5719 -------------------------
5721 procedure Check_First_Subtype
(Arg
: Node_Id
) is
5722 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5723 Ent
: constant Entity_Id
:= Entity
(Argx
);
5726 if Is_First_Subtype
(Ent
) then
5729 elsif Is_Type
(Ent
) then
5731 ("pragma% cannot apply to subtype", Argx
);
5733 elsif Is_Object
(Ent
) then
5735 ("pragma% cannot apply to object, requires a type", Argx
);
5739 ("pragma% cannot apply to&, requires a type", Argx
);
5741 end Check_First_Subtype
;
5743 ----------------------
5744 -- Check_Identifier --
5745 ----------------------
5747 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
5750 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5752 if Chars
(Arg
) = No_Name
or else Chars
(Arg
) /= Id
then
5753 Error_Msg_Name_1
:= Pname
;
5754 Error_Msg_Name_2
:= Id
;
5755 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
5759 end Check_Identifier
;
5761 --------------------------------
5762 -- Check_Identifier_Is_One_Of --
5763 --------------------------------
5765 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
5768 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5770 if Chars
(Arg
) = No_Name
then
5771 Error_Msg_Name_1
:= Pname
;
5772 Error_Msg_N
("pragma% argument expects an identifier", Arg
);
5775 elsif Chars
(Arg
) /= N1
5776 and then Chars
(Arg
) /= N2
5778 Error_Msg_Name_1
:= Pname
;
5779 Error_Msg_N
("invalid identifier for pragma% argument", Arg
);
5783 end Check_Identifier_Is_One_Of
;
5785 ---------------------------
5786 -- Check_In_Main_Program --
5787 ---------------------------
5789 procedure Check_In_Main_Program
is
5790 P
: constant Node_Id
:= Parent
(N
);
5793 -- Must be in subprogram body
5795 if Nkind
(P
) /= N_Subprogram_Body
then
5796 Error_Pragma
("% pragma allowed only in subprogram");
5798 -- Otherwise warn if obviously not main program
5800 elsif Present
(Parameter_Specifications
(Specification
(P
)))
5801 or else not Is_Compilation_Unit
(Defining_Entity
(P
))
5803 Error_Msg_Name_1
:= Pname
;
5805 ("??pragma% is only effective in main program", N
);
5807 end Check_In_Main_Program
;
5809 ---------------------------------------
5810 -- Check_Interrupt_Or_Attach_Handler --
5811 ---------------------------------------
5813 procedure Check_Interrupt_Or_Attach_Handler
is
5814 Arg1_X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
5815 Handler_Proc
, Proc_Scope
: Entity_Id
;
5820 if Prag_Id
= Pragma_Interrupt_Handler
then
5821 Check_Restriction
(No_Dynamic_Attachment
, N
);
5824 Handler_Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
5825 Proc_Scope
:= Scope
(Handler_Proc
);
5827 if Ekind
(Proc_Scope
) /= E_Protected_Type
then
5829 ("argument of pragma% must be protected procedure", Arg1
);
5832 -- For pragma case (as opposed to access case), check placement.
5833 -- We don't need to do that for aspects, because we have the
5834 -- check that they aspect applies an appropriate procedure.
5836 if not From_Aspect_Specification
(N
)
5837 and then Parent
(N
) /= Protected_Definition
(Parent
(Proc_Scope
))
5839 Error_Pragma
("pragma% must be in protected definition");
5842 if not Is_Library_Level_Entity
(Proc_Scope
) then
5844 ("argument for pragma% must be library level entity", Arg1
);
5847 -- AI05-0033: A pragma cannot appear within a generic body, because
5848 -- instance can be in a nested scope. The check that protected type
5849 -- is itself a library-level declaration is done elsewhere.
5851 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5852 -- handle code prior to AI-0033. Analysis tools typically are not
5853 -- interested in this pragma in any case, so no need to worry too
5854 -- much about its placement.
5856 if Inside_A_Generic
then
5857 if Ekind
(Scope
(Current_Scope
)) = E_Generic_Package
5858 and then In_Package_Body
(Scope
(Current_Scope
))
5859 and then not Relaxed_RM_Semantics
5861 Error_Pragma
("pragma% cannot be used inside a generic");
5864 end Check_Interrupt_Or_Attach_Handler
;
5866 ---------------------------------
5867 -- Check_Loop_Pragma_Placement --
5868 ---------------------------------
5870 procedure Check_Loop_Pragma_Placement
is
5871 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
);
5872 -- Verify whether the current pragma is properly grouped with other
5873 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5874 -- related loop where the pragma appears.
5876 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean;
5877 -- Determine whether an arbitrary statement Stmt denotes pragma
5878 -- Loop_Invariant or Loop_Variant.
5880 procedure Placement_Error
(Constr
: Node_Id
);
5881 pragma No_Return
(Placement_Error
);
5882 -- Node Constr denotes the last loop restricted construct before we
5883 -- encountered an illegal relation between enclosing constructs. Emit
5884 -- an error depending on what Constr was.
5886 --------------------------------
5887 -- Check_Loop_Pragma_Grouping --
5888 --------------------------------
5890 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
) is
5891 Stop_Search
: exception;
5892 -- This exception is used to terminate the recursive descent of
5893 -- routine Check_Grouping.
5895 procedure Check_Grouping
(L
: List_Id
);
5896 -- Find the first group of pragmas in list L and if successful,
5897 -- ensure that the current pragma is part of that group. The
5898 -- routine raises Stop_Search once such a check is performed to
5899 -- halt the recursive descent.
5901 procedure Grouping_Error
(Prag
: Node_Id
);
5902 pragma No_Return
(Grouping_Error
);
5903 -- Emit an error concerning the current pragma indicating that it
5904 -- should be placed after pragma Prag.
5906 --------------------
5907 -- Check_Grouping --
5908 --------------------
5910 procedure Check_Grouping
(L
: List_Id
) is
5913 Prag
: Node_Id
:= Empty
; -- init to avoid warning
5916 -- Inspect the list of declarations or statements looking for
5917 -- the first grouping of pragmas:
5920 -- pragma Loop_Invariant ...;
5921 -- pragma Loop_Variant ...;
5923 -- pragma Loop_Variant ...; -- current pragma
5925 -- If the current pragma is not in the grouping, then it must
5926 -- either appear in a different declarative or statement list
5927 -- or the construct at (1) is separating the pragma from the
5931 while Present
(Stmt
) loop
5933 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5934 -- inside a loop or a block housed inside a loop. Inspect
5935 -- the declarations and statements of the block as they may
5936 -- contain the first grouping.
5938 if Nkind
(Stmt
) = N_Block_Statement
then
5939 HSS
:= Handled_Statement_Sequence
(Stmt
);
5941 Check_Grouping
(Declarations
(Stmt
));
5943 if Present
(HSS
) then
5944 Check_Grouping
(Statements
(HSS
));
5947 -- First pragma of the first topmost grouping has been found
5949 elsif Is_Loop_Pragma
(Stmt
) then
5951 -- The group and the current pragma are not in the same
5952 -- declarative or statement list.
5954 if List_Containing
(Stmt
) /= List_Containing
(N
) then
5955 Grouping_Error
(Stmt
);
5957 -- Try to reach the current pragma from the first pragma
5958 -- of the grouping while skipping other members:
5960 -- pragma Loop_Invariant ...; -- first pragma
5961 -- pragma Loop_Variant ...; -- member
5963 -- pragma Loop_Variant ...; -- current pragma
5966 while Present
(Stmt
) loop
5967 -- The current pragma is either the first pragma
5968 -- of the group or is a member of the group.
5969 -- Stop the search as the placement is legal.
5974 -- Skip group members, but keep track of the
5975 -- last pragma in the group.
5977 elsif Is_Loop_Pragma
(Stmt
) then
5980 -- Skip declarations and statements generated by
5981 -- the compiler during expansion.
5983 elsif not Comes_From_Source
(Stmt
) then
5986 -- A non-pragma is separating the group from the
5987 -- current pragma, the placement is illegal.
5990 Grouping_Error
(Prag
);
5996 -- If the traversal did not reach the current pragma,
5997 -- then the list must be malformed.
5999 raise Program_Error
;
6007 --------------------
6008 -- Grouping_Error --
6009 --------------------
6011 procedure Grouping_Error
(Prag
: Node_Id
) is
6013 Error_Msg_Sloc
:= Sloc
(Prag
);
6014 Error_Pragma
("pragma% must appear next to pragma#");
6017 -- Start of processing for Check_Loop_Pragma_Grouping
6020 -- Inspect the statements of the loop or nested blocks housed
6021 -- within to determine whether the current pragma is part of the
6022 -- first topmost grouping of Loop_Invariant and Loop_Variant.
6024 Check_Grouping
(Statements
(Loop_Stmt
));
6027 when Stop_Search
=> null;
6028 end Check_Loop_Pragma_Grouping
;
6030 --------------------
6031 -- Is_Loop_Pragma --
6032 --------------------
6034 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean is
6036 -- Inspect the original node as Loop_Invariant and Loop_Variant
6037 -- pragmas are rewritten to null when assertions are disabled.
6039 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
then
6041 Nam_In
(Pragma_Name_Unmapped
(Original_Node
(Stmt
)),
6042 Name_Loop_Invariant
,
6049 ---------------------
6050 -- Placement_Error --
6051 ---------------------
6053 procedure Placement_Error
(Constr
: Node_Id
) is
6054 LA
: constant String := " with Loop_Entry";
6057 if Prag_Id
= Pragma_Assert
then
6058 Error_Msg_String
(1 .. LA
'Length) := LA
;
6059 Error_Msg_Strlen
:= LA
'Length;
6061 Error_Msg_Strlen
:= 0;
6064 if Nkind
(Constr
) = N_Pragma
then
6066 ("pragma %~ must appear immediately within the statements "
6070 ("block containing pragma %~ must appear immediately within "
6071 & "the statements of a loop", Constr
);
6073 end Placement_Error
;
6075 -- Local declarations
6080 -- Start of processing for Check_Loop_Pragma_Placement
6083 -- Check that pragma appears immediately within a loop statement,
6084 -- ignoring intervening block statements.
6088 while Present
(Stmt
) loop
6090 -- The pragma or previous block must appear immediately within the
6091 -- current block's declarative or statement part.
6093 if Nkind
(Stmt
) = N_Block_Statement
then
6094 if (No
(Declarations
(Stmt
))
6095 or else List_Containing
(Prev
) /= Declarations
(Stmt
))
6097 List_Containing
(Prev
) /=
6098 Statements
(Handled_Statement_Sequence
(Stmt
))
6100 Placement_Error
(Prev
);
6103 -- Keep inspecting the parents because we are now within a
6104 -- chain of nested blocks.
6108 Stmt
:= Parent
(Stmt
);
6111 -- The pragma or previous block must appear immediately within the
6112 -- statements of the loop.
6114 elsif Nkind
(Stmt
) = N_Loop_Statement
then
6115 if List_Containing
(Prev
) /= Statements
(Stmt
) then
6116 Placement_Error
(Prev
);
6119 -- Stop the traversal because we reached the innermost loop
6120 -- regardless of whether we encountered an error or not.
6124 -- Ignore a handled statement sequence. Note that this node may
6125 -- be related to a subprogram body in which case we will emit an
6126 -- error on the next iteration of the search.
6128 elsif Nkind
(Stmt
) = N_Handled_Sequence_Of_Statements
then
6129 Stmt
:= Parent
(Stmt
);
6131 -- Any other statement breaks the chain from the pragma to the
6135 Placement_Error
(Prev
);
6140 -- Check that the current pragma Loop_Invariant or Loop_Variant is
6141 -- grouped together with other such pragmas.
6143 if Is_Loop_Pragma
(N
) then
6145 -- The previous check should have located the related loop
6147 pragma Assert
(Nkind
(Stmt
) = N_Loop_Statement
);
6148 Check_Loop_Pragma_Grouping
(Stmt
);
6150 end Check_Loop_Pragma_Placement
;
6152 -------------------------------------------
6153 -- Check_Is_In_Decl_Part_Or_Package_Spec --
6154 -------------------------------------------
6156 procedure Check_Is_In_Decl_Part_Or_Package_Spec
is
6165 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
then
6168 elsif Nkind_In
(P
, N_Package_Specification
,
6173 -- Note: the following tests seem a little peculiar, because
6174 -- they test for bodies, but if we were in the statement part
6175 -- of the body, we would already have hit the handled statement
6176 -- sequence, so the only way we get here is by being in the
6177 -- declarative part of the body.
6179 elsif Nkind_In
(P
, N_Subprogram_Body
,
6190 Error_Pragma
("pragma% is not in declarative part or package spec");
6191 end Check_Is_In_Decl_Part_Or_Package_Spec
;
6193 -------------------------
6194 -- Check_No_Identifier --
6195 -------------------------
6197 procedure Check_No_Identifier
(Arg
: Node_Id
) is
6199 if Nkind
(Arg
) = N_Pragma_Argument_Association
6200 and then Chars
(Arg
) /= No_Name
6202 Error_Pragma_Arg_Ident
6203 ("pragma% does not permit identifier& here", Arg
);
6205 end Check_No_Identifier
;
6207 --------------------------
6208 -- Check_No_Identifiers --
6209 --------------------------
6211 procedure Check_No_Identifiers
is
6215 for J
in 1 .. Arg_Count
loop
6216 Check_No_Identifier
(Arg_Node
);
6219 end Check_No_Identifiers
;
6221 ------------------------
6222 -- Check_No_Link_Name --
6223 ------------------------
6225 procedure Check_No_Link_Name
is
6227 if Present
(Arg3
) and then Chars
(Arg3
) = Name_Link_Name
then
6231 if Present
(Arg4
) then
6233 ("Link_Name argument not allowed for Import Intrinsic", Arg4
);
6235 end Check_No_Link_Name
;
6237 -------------------------------
6238 -- Check_Optional_Identifier --
6239 -------------------------------
6241 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
6244 and then Nkind
(Arg
) = N_Pragma_Argument_Association
6245 and then Chars
(Arg
) /= No_Name
6247 if Chars
(Arg
) /= Id
then
6248 Error_Msg_Name_1
:= Pname
;
6249 Error_Msg_Name_2
:= Id
;
6250 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
6254 end Check_Optional_Identifier
;
6256 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String) is
6258 Check_Optional_Identifier
(Arg
, Name_Find
(Id
));
6259 end Check_Optional_Identifier
;
6261 -------------------------------------
6262 -- Check_Static_Boolean_Expression --
6263 -------------------------------------
6265 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
) is
6267 if Present
(Expr
) then
6268 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
6270 if not Is_OK_Static_Expression
(Expr
) then
6272 ("expression of pragma % must be static", Expr
);
6275 end Check_Static_Boolean_Expression
;
6277 -----------------------------
6278 -- Check_Static_Constraint --
6279 -----------------------------
6281 -- Note: for convenience in writing this procedure, in addition to
6282 -- the officially (i.e. by spec) allowed argument which is always a
6283 -- constraint, it also allows ranges and discriminant associations.
6284 -- Above is not clear ???
6286 procedure Check_Static_Constraint
(Constr
: Node_Id
) is
6288 procedure Require_Static
(E
: Node_Id
);
6289 -- Require given expression to be static expression
6291 --------------------
6292 -- Require_Static --
6293 --------------------
6295 procedure Require_Static
(E
: Node_Id
) is
6297 if not Is_OK_Static_Expression
(E
) then
6298 Flag_Non_Static_Expr
6299 ("non-static constraint not allowed in Unchecked_Union!", E
);
6304 -- Start of processing for Check_Static_Constraint
6307 case Nkind
(Constr
) is
6308 when N_Discriminant_Association
=>
6309 Require_Static
(Expression
(Constr
));
6312 Require_Static
(Low_Bound
(Constr
));
6313 Require_Static
(High_Bound
(Constr
));
6315 when N_Attribute_Reference
=>
6316 Require_Static
(Type_Low_Bound
(Etype
(Prefix
(Constr
))));
6317 Require_Static
(Type_High_Bound
(Etype
(Prefix
(Constr
))));
6319 when N_Range_Constraint
=>
6320 Check_Static_Constraint
(Range_Expression
(Constr
));
6322 when N_Index_Or_Discriminant_Constraint
=>
6326 IDC
:= First
(Constraints
(Constr
));
6327 while Present
(IDC
) loop
6328 Check_Static_Constraint
(IDC
);
6336 end Check_Static_Constraint
;
6338 --------------------------------------
6339 -- Check_Valid_Configuration_Pragma --
6340 --------------------------------------
6342 -- A configuration pragma must appear in the context clause of a
6343 -- compilation unit, and only other pragmas may precede it. Note that
6344 -- the test also allows use in a configuration pragma file.
6346 procedure Check_Valid_Configuration_Pragma
is
6348 if not Is_Configuration_Pragma
then
6349 Error_Pragma
("incorrect placement for configuration pragma%");
6351 end Check_Valid_Configuration_Pragma
;
6353 -------------------------------------
6354 -- Check_Valid_Library_Unit_Pragma --
6355 -------------------------------------
6357 procedure Check_Valid_Library_Unit_Pragma
is
6359 Parent_Node
: Node_Id
;
6360 Unit_Name
: Entity_Id
;
6361 Unit_Kind
: Node_Kind
;
6362 Unit_Node
: Node_Id
;
6363 Sindex
: Source_File_Index
;
6366 if not Is_List_Member
(N
) then
6370 Plist
:= List_Containing
(N
);
6371 Parent_Node
:= Parent
(Plist
);
6373 if Parent_Node
= Empty
then
6376 -- Case of pragma appearing after a compilation unit. In this case
6377 -- it must have an argument with the corresponding name and must
6378 -- be part of the following pragmas of its parent.
6380 elsif Nkind
(Parent_Node
) = N_Compilation_Unit_Aux
then
6381 if Plist
/= Pragmas_After
(Parent_Node
) then
6384 elsif Arg_Count
= 0 then
6386 ("argument required if outside compilation unit");
6389 Check_No_Identifiers
;
6390 Check_Arg_Count
(1);
6391 Unit_Node
:= Unit
(Parent
(Parent_Node
));
6392 Unit_Kind
:= Nkind
(Unit_Node
);
6394 Analyze
(Get_Pragma_Arg
(Arg1
));
6396 if Unit_Kind
= N_Generic_Subprogram_Declaration
6397 or else Unit_Kind
= N_Subprogram_Declaration
6399 Unit_Name
:= Defining_Entity
(Unit_Node
);
6401 elsif Unit_Kind
in N_Generic_Instantiation
then
6402 Unit_Name
:= Defining_Entity
(Unit_Node
);
6405 Unit_Name
:= Cunit_Entity
(Current_Sem_Unit
);
6408 if Chars
(Unit_Name
) /=
6409 Chars
(Entity
(Get_Pragma_Arg
(Arg1
)))
6412 ("pragma% argument is not current unit name", Arg1
);
6415 if Ekind
(Unit_Name
) = E_Package
6416 and then Present
(Renamed_Entity
(Unit_Name
))
6418 Error_Pragma
("pragma% not allowed for renamed package");
6422 -- Pragma appears other than after a compilation unit
6425 -- Here we check for the generic instantiation case and also
6426 -- for the case of processing a generic formal package. We
6427 -- detect these cases by noting that the Sloc on the node
6428 -- does not belong to the current compilation unit.
6430 Sindex
:= Source_Index
(Current_Sem_Unit
);
6432 if Loc
not in Source_First
(Sindex
) .. Source_Last
(Sindex
) then
6433 Rewrite
(N
, Make_Null_Statement
(Loc
));
6436 -- If before first declaration, the pragma applies to the
6437 -- enclosing unit, and the name if present must be this name.
6439 elsif Is_Before_First_Decl
(N
, Plist
) then
6440 Unit_Node
:= Unit_Declaration_Node
(Current_Scope
);
6441 Unit_Kind
:= Nkind
(Unit_Node
);
6443 if Nkind
(Parent
(Unit_Node
)) /= N_Compilation_Unit
then
6446 elsif Unit_Kind
= N_Subprogram_Body
6447 and then not Acts_As_Spec
(Unit_Node
)
6451 elsif Nkind
(Parent_Node
) = N_Package_Body
then
6454 elsif Nkind
(Parent_Node
) = N_Package_Specification
6455 and then Plist
= Private_Declarations
(Parent_Node
)
6459 elsif (Nkind
(Parent_Node
) = N_Generic_Package_Declaration
6460 or else Nkind
(Parent_Node
) =
6461 N_Generic_Subprogram_Declaration
)
6462 and then Plist
= Generic_Formal_Declarations
(Parent_Node
)
6466 elsif Arg_Count
> 0 then
6467 Analyze
(Get_Pragma_Arg
(Arg1
));
6469 if Entity
(Get_Pragma_Arg
(Arg1
)) /= Current_Scope
then
6471 ("name in pragma% must be enclosing unit", Arg1
);
6474 -- It is legal to have no argument in this context
6480 -- Error if not before first declaration. This is because a
6481 -- library unit pragma argument must be the name of a library
6482 -- unit (RM 10.1.5(7)), but the only names permitted in this
6483 -- context are (RM 10.1.5(6)) names of subprogram declarations,
6484 -- generic subprogram declarations or generic instantiations.
6488 ("pragma% misplaced, must be before first declaration");
6492 end Check_Valid_Library_Unit_Pragma
;
6498 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
) is
6499 Clist
: constant Node_Id
:= Component_List
(Variant
);
6503 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
6504 while Present
(Comp
) loop
6505 Check_Component
(Comp
, UU_Typ
, In_Variant_Part
=> True);
6506 Next_Non_Pragma
(Comp
);
6510 ---------------------------
6511 -- Ensure_Aggregate_Form --
6512 ---------------------------
6514 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
) is
6515 CFSD
: constant Boolean := Get_Comes_From_Source_Default
;
6516 Expr
: constant Node_Id
:= Expression
(Arg
);
6517 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6518 Comps
: List_Id
:= No_List
;
6519 Exprs
: List_Id
:= No_List
;
6520 Nam
: Name_Id
:= No_Name
;
6521 Nam_Loc
: Source_Ptr
;
6524 -- The pragma argument is in positional form:
6526 -- pragma Depends (Nam => ...)
6530 -- Note that the Sloc of the Chars field is the Sloc of the pragma
6531 -- argument association.
6533 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
6535 Nam_Loc
:= Sloc
(Arg
);
6537 -- Remove the pragma argument name as this will be captured in the
6540 Set_Chars
(Arg
, No_Name
);
6543 -- The argument is already in aggregate form, but the presence of a
6544 -- name causes this to be interpreted as named association which in
6545 -- turn must be converted into an aggregate.
6547 -- pragma Global (In_Out => (A, B, C))
6551 -- pragma Global ((In_Out => (A, B, C)))
6553 -- aggregate aggregate
6555 if Nkind
(Expr
) = N_Aggregate
then
6556 if Nam
= No_Name
then
6560 -- Do not transform a null argument into an aggregate as N_Null has
6561 -- special meaning in formal verification pragmas.
6563 elsif Nkind
(Expr
) = N_Null
then
6567 -- Everything comes from source if the original comes from source
6569 Set_Comes_From_Source_Default
(Comes_From_Source
(Arg
));
6571 -- Positional argument is transformed into an aggregate with an
6572 -- Expressions list.
6574 if Nam
= No_Name
then
6575 Exprs
:= New_List
(Relocate_Node
(Expr
));
6577 -- An associative argument is transformed into an aggregate with
6578 -- Component_Associations.
6582 Make_Component_Association
(Loc
,
6583 Choices
=> New_List
(Make_Identifier
(Nam_Loc
, Nam
)),
6584 Expression
=> Relocate_Node
(Expr
)));
6587 Set_Expression
(Arg
,
6588 Make_Aggregate
(Loc
,
6589 Component_Associations
=> Comps
,
6590 Expressions
=> Exprs
));
6592 -- Restore Comes_From_Source default
6594 Set_Comes_From_Source_Default
(CFSD
);
6595 end Ensure_Aggregate_Form
;
6601 procedure Error_Pragma
(Msg
: String) is
6603 Error_Msg_Name_1
:= Pname
;
6604 Error_Msg_N
(Fix_Error
(Msg
), N
);
6608 ----------------------
6609 -- Error_Pragma_Arg --
6610 ----------------------
6612 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
) is
6614 Error_Msg_Name_1
:= Pname
;
6615 Error_Msg_N
(Fix_Error
(Msg
), Get_Pragma_Arg
(Arg
));
6617 end Error_Pragma_Arg
;
6619 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
) is
6621 Error_Msg_Name_1
:= Pname
;
6622 Error_Msg_N
(Fix_Error
(Msg1
), Get_Pragma_Arg
(Arg
));
6623 Error_Pragma_Arg
(Msg2
, Arg
);
6624 end Error_Pragma_Arg
;
6626 ----------------------------
6627 -- Error_Pragma_Arg_Ident --
6628 ----------------------------
6630 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
) is
6632 Error_Msg_Name_1
:= Pname
;
6633 Error_Msg_N
(Fix_Error
(Msg
), Arg
);
6635 end Error_Pragma_Arg_Ident
;
6637 ----------------------
6638 -- Error_Pragma_Ref --
6639 ----------------------
6641 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
) is
6643 Error_Msg_Name_1
:= Pname
;
6644 Error_Msg_Sloc
:= Sloc
(Ref
);
6645 Error_Msg_NE
(Fix_Error
(Msg
), N
, Ref
);
6647 end Error_Pragma_Ref
;
6649 ------------------------
6650 -- Find_Lib_Unit_Name --
6651 ------------------------
6653 function Find_Lib_Unit_Name
return Entity_Id
is
6655 -- Return inner compilation unit entity, for case of nested
6656 -- categorization pragmas. This happens in generic unit.
6658 if Nkind
(Parent
(N
)) = N_Package_Specification
6659 and then Defining_Entity
(Parent
(N
)) /= Current_Scope
6661 return Defining_Entity
(Parent
(N
));
6663 return Current_Scope
;
6665 end Find_Lib_Unit_Name
;
6667 ----------------------------
6668 -- Find_Program_Unit_Name --
6669 ----------------------------
6671 procedure Find_Program_Unit_Name
(Id
: Node_Id
) is
6672 Unit_Name
: Entity_Id
;
6673 Unit_Kind
: Node_Kind
;
6674 P
: constant Node_Id
:= Parent
(N
);
6677 if Nkind
(P
) = N_Compilation_Unit
then
6678 Unit_Kind
:= Nkind
(Unit
(P
));
6680 if Nkind_In
(Unit_Kind
, N_Subprogram_Declaration
,
6681 N_Package_Declaration
)
6682 or else Unit_Kind
in N_Generic_Declaration
6684 Unit_Name
:= Defining_Entity
(Unit
(P
));
6686 if Chars
(Id
) = Chars
(Unit_Name
) then
6687 Set_Entity
(Id
, Unit_Name
);
6688 Set_Etype
(Id
, Etype
(Unit_Name
));
6690 Set_Etype
(Id
, Any_Type
);
6692 ("cannot find program unit referenced by pragma%");
6696 Set_Etype
(Id
, Any_Type
);
6697 Error_Pragma
("pragma% inapplicable to this unit");
6703 end Find_Program_Unit_Name
;
6705 -----------------------------------------
6706 -- Find_Unique_Parameterless_Procedure --
6707 -----------------------------------------
6709 function Find_Unique_Parameterless_Procedure
6711 Arg
: Node_Id
) return Entity_Id
6713 Proc
: Entity_Id
:= Empty
;
6716 -- The body of this procedure needs some comments ???
6718 if not Is_Entity_Name
(Name
) then
6720 ("argument of pragma% must be entity name", Arg
);
6722 elsif not Is_Overloaded
(Name
) then
6723 Proc
:= Entity
(Name
);
6725 if Ekind
(Proc
) /= E_Procedure
6726 or else Present
(First_Formal
(Proc
))
6729 ("argument of pragma% must be parameterless procedure", Arg
);
6734 Found
: Boolean := False;
6736 Index
: Interp_Index
;
6739 Get_First_Interp
(Name
, Index
, It
);
6740 while Present
(It
.Nam
) loop
6743 if Ekind
(Proc
) = E_Procedure
6744 and then No
(First_Formal
(Proc
))
6748 Set_Entity
(Name
, Proc
);
6749 Set_Is_Overloaded
(Name
, False);
6752 ("ambiguous handler name for pragma% ", Arg
);
6756 Get_Next_Interp
(Index
, It
);
6761 ("argument of pragma% must be parameterless procedure",
6764 Proc
:= Entity
(Name
);
6770 end Find_Unique_Parameterless_Procedure
;
6776 function Fix_Error
(Msg
: String) return String is
6777 Res
: String (Msg
'Range) := Msg
;
6778 Res_Last
: Natural := Msg
'Last;
6782 -- If we have a rewriting of another pragma, go to that pragma
6784 if Is_Rewrite_Substitution
(N
)
6785 and then Nkind
(Original_Node
(N
)) = N_Pragma
6787 Error_Msg_Name_1
:= Pragma_Name
(Original_Node
(N
));
6790 -- Case where pragma comes from an aspect specification
6792 if From_Aspect_Specification
(N
) then
6794 -- Change appearence of "pragma" in message to "aspect"
6797 while J
<= Res_Last
- 5 loop
6798 if Res
(J
.. J
+ 5) = "pragma" then
6799 Res
(J
.. J
+ 5) := "aspect";
6807 -- Change "argument of" at start of message to "entity for"
6810 and then Res
(Res
'First .. Res
'First + 10) = "argument of"
6812 Res
(Res
'First .. Res
'First + 9) := "entity for";
6813 Res
(Res
'First + 10 .. Res_Last
- 1) :=
6814 Res
(Res
'First + 11 .. Res_Last
);
6815 Res_Last
:= Res_Last
- 1;
6818 -- Change "argument" at start of message to "entity"
6821 and then Res
(Res
'First .. Res
'First + 7) = "argument"
6823 Res
(Res
'First .. Res
'First + 5) := "entity";
6824 Res
(Res
'First + 6 .. Res_Last
- 2) :=
6825 Res
(Res
'First + 8 .. Res_Last
);
6826 Res_Last
:= Res_Last
- 2;
6829 -- Get name from corresponding aspect
6831 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(N
);
6834 -- Return possibly modified message
6836 return Res
(Res
'First .. Res_Last
);
6839 -------------------------
6840 -- Gather_Associations --
6841 -------------------------
6843 procedure Gather_Associations
6845 Args
: out Args_List
)
6850 -- Initialize all parameters to Empty
6852 for J
in Args
'Range loop
6856 -- That's all we have to do if there are no argument associations
6858 if No
(Pragma_Argument_Associations
(N
)) then
6862 -- Otherwise first deal with any positional parameters present
6864 Arg
:= First
(Pragma_Argument_Associations
(N
));
6865 for Index
in Args
'Range loop
6866 exit when No
(Arg
) or else Chars
(Arg
) /= No_Name
;
6867 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6871 -- Positional parameters all processed, if any left, then we
6872 -- have too many positional parameters.
6874 if Present
(Arg
) and then Chars
(Arg
) = No_Name
then
6876 ("too many positional associations for pragma%", Arg
);
6879 -- Process named parameters if any are present
6881 while Present
(Arg
) loop
6882 if Chars
(Arg
) = No_Name
then
6884 ("positional association cannot follow named association",
6888 for Index
in Names
'Range loop
6889 if Names
(Index
) = Chars
(Arg
) then
6890 if Present
(Args
(Index
)) then
6892 ("duplicate argument association for pragma%", Arg
);
6894 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6899 if Index
= Names
'Last then
6900 Error_Msg_Name_1
:= Pname
;
6901 Error_Msg_N
("pragma% does not allow & argument", Arg
);
6903 -- Check for possible misspelling
6905 for Index1
in Names
'Range loop
6906 if Is_Bad_Spelling_Of
6907 (Chars
(Arg
), Names
(Index1
))
6909 Error_Msg_Name_1
:= Names
(Index1
);
6910 Error_Msg_N
-- CODEFIX
6911 ("\possible misspelling of%", Arg
);
6923 end Gather_Associations
;
6929 procedure GNAT_Pragma
is
6931 -- We need to check the No_Implementation_Pragmas restriction for
6932 -- the case of a pragma from source. Note that the case of aspects
6933 -- generating corresponding pragmas marks these pragmas as not being
6934 -- from source, so this test also catches that case.
6936 if Comes_From_Source
(N
) then
6937 Check_Restriction
(No_Implementation_Pragmas
, N
);
6941 --------------------------
6942 -- Is_Before_First_Decl --
6943 --------------------------
6945 function Is_Before_First_Decl
6946 (Pragma_Node
: Node_Id
;
6947 Decls
: List_Id
) return Boolean
6949 Item
: Node_Id
:= First
(Decls
);
6952 -- Only other pragmas can come before this pragma
6955 if No
(Item
) or else Nkind
(Item
) /= N_Pragma
then
6958 elsif Item
= Pragma_Node
then
6964 end Is_Before_First_Decl
;
6966 -----------------------------
6967 -- Is_Configuration_Pragma --
6968 -----------------------------
6970 -- A configuration pragma must appear in the context clause of a
6971 -- compilation unit, and only other pragmas may precede it. Note that
6972 -- the test below also permits use in a configuration pragma file.
6974 function Is_Configuration_Pragma
return Boolean is
6975 Lis
: constant List_Id
:= List_Containing
(N
);
6976 Par
: constant Node_Id
:= Parent
(N
);
6980 -- If no parent, then we are in the configuration pragma file,
6981 -- so the placement is definitely appropriate.
6986 -- Otherwise we must be in the context clause of a compilation unit
6987 -- and the only thing allowed before us in the context list is more
6988 -- configuration pragmas.
6990 elsif Nkind
(Par
) = N_Compilation_Unit
6991 and then Context_Items
(Par
) = Lis
6998 elsif Nkind
(Prg
) /= N_Pragma
then
7008 end Is_Configuration_Pragma
;
7010 --------------------------
7011 -- Is_In_Context_Clause --
7012 --------------------------
7014 function Is_In_Context_Clause
return Boolean is
7016 Parent_Node
: Node_Id
;
7019 if not Is_List_Member
(N
) then
7023 Plist
:= List_Containing
(N
);
7024 Parent_Node
:= Parent
(Plist
);
7026 if Parent_Node
= Empty
7027 or else Nkind
(Parent_Node
) /= N_Compilation_Unit
7028 or else Context_Items
(Parent_Node
) /= Plist
7035 end Is_In_Context_Clause
;
7037 ---------------------------------
7038 -- Is_Static_String_Expression --
7039 ---------------------------------
7041 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean is
7042 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
7043 Lit
: constant Boolean := Nkind
(Argx
) = N_String_Literal
;
7046 Analyze_And_Resolve
(Argx
);
7048 -- Special case Ada 83, where the expression will never be static,
7049 -- but we will return true if we had a string literal to start with.
7051 if Ada_Version
= Ada_83
then
7054 -- Normal case, true only if we end up with a string literal that
7055 -- is marked as being the result of evaluating a static expression.
7058 return Is_OK_Static_Expression
(Argx
)
7059 and then Nkind
(Argx
) = N_String_Literal
;
7062 end Is_Static_String_Expression
;
7064 ----------------------
7065 -- Pragma_Misplaced --
7066 ----------------------
7068 procedure Pragma_Misplaced
is
7070 Error_Pragma
("incorrect placement of pragma%");
7071 end Pragma_Misplaced
;
7073 ------------------------------------------------
7074 -- Process_Atomic_Independent_Shared_Volatile --
7075 ------------------------------------------------
7077 procedure Process_Atomic_Independent_Shared_Volatile
is
7078 procedure Check_VFA_Conflicts
(Ent
: Entity_Id
);
7079 -- Apply additional checks for the GNAT pragma Volatile_Full_Access
7081 procedure Mark_Component_Or_Object
(Ent
: Entity_Id
);
7082 -- Appropriately set flags on the given entity (either an array or
7083 -- record component, or an object declaration) according to the
7086 procedure Set_Atomic_VFA
(Ent
: Entity_Id
);
7087 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
7088 -- no explicit alignment was given, set alignment to unknown, since
7089 -- back end knows what the alignment requirements are for atomic and
7090 -- full access arrays. Note: this is necessary for derived types.
7092 -------------------------
7093 -- Check_VFA_Conflicts --
7094 -------------------------
7096 procedure Check_VFA_Conflicts
(Ent
: Entity_Id
) is
7100 VFA_And_Atomic
: Boolean := False;
7101 -- Set True if atomic component present
7103 VFA_And_Aliased
: Boolean := False;
7104 -- Set True if aliased component present
7107 -- Fetch the type in case we are dealing with an object or
7110 if Is_Type
(Ent
) then
7113 pragma Assert
(Is_Object
(Ent
)
7115 Nkind
(Declaration_Node
(Ent
)) = N_Component_Declaration
);
7120 -- Check Atomic and VFA used together
7122 if Prag_Id
= Pragma_Volatile_Full_Access
7123 or else Is_Volatile_Full_Access
(Ent
)
7125 if Prag_Id
= Pragma_Atomic
7126 or else Prag_Id
= Pragma_Shared
7127 or else Is_Atomic
(Ent
)
7129 VFA_And_Atomic
:= True;
7131 elsif Is_Array_Type
(Typ
) then
7132 VFA_And_Atomic
:= Has_Atomic_Components
(Typ
);
7134 -- Note: Has_Atomic_Components is not used below, as this flag
7135 -- represents the pragma of the same name, Atomic_Components,
7136 -- which only applies to arrays.
7138 elsif Is_Record_Type
(Typ
) then
7139 -- Attributes cannot be applied to discriminants, only
7140 -- regular record components.
7142 Comp
:= First_Component
(Typ
);
7143 while Present
(Comp
) loop
7145 or else Is_Atomic
(Typ
)
7147 VFA_And_Atomic
:= True;
7152 Next_Component
(Comp
);
7156 if VFA_And_Atomic
then
7158 ("cannot have Volatile_Full_Access and Atomic for same "
7163 -- Check for the application of VFA to an entity that has aliased
7166 if Prag_Id
= Pragma_Volatile_Full_Access
then
7167 if Is_Array_Type
(Typ
)
7168 and then Has_Aliased_Components
(Typ
)
7170 VFA_And_Aliased
:= True;
7172 -- Note: Has_Aliased_Components, like Has_Atomic_Components,
7173 -- and Has_Independent_Components, applies only to arrays.
7174 -- However, this flag does not have a corresponding pragma, so
7175 -- perhaps it should be possible to apply it to record types as
7176 -- well. Should this be done ???
7178 elsif Is_Record_Type
(Typ
) then
7179 -- It is possible to have an aliased discriminant, so they
7180 -- must be checked along with normal components.
7182 Comp
:= First_Component_Or_Discriminant
(Typ
);
7183 while Present
(Comp
) loop
7184 if Is_Aliased
(Comp
)
7185 or else Is_Aliased
(Etype
(Comp
))
7187 VFA_And_Aliased
:= True;
7188 Check_SPARK_05_Restriction
7189 ("aliased is not allowed", Comp
);
7194 Next_Component_Or_Discriminant
(Comp
);
7198 if VFA_And_Aliased
then
7200 ("cannot apply Volatile_Full_Access (aliased component "
7204 end Check_VFA_Conflicts
;
7206 ------------------------------
7207 -- Mark_Component_Or_Object --
7208 ------------------------------
7210 procedure Mark_Component_Or_Object
(Ent
: Entity_Id
) is
7212 if Prag_Id
= Pragma_Atomic
7213 or else Prag_Id
= Pragma_Shared
7214 or else Prag_Id
= Pragma_Volatile_Full_Access
7216 if Prag_Id
= Pragma_Volatile_Full_Access
then
7217 Set_Is_Volatile_Full_Access
(Ent
);
7219 Set_Is_Atomic
(Ent
);
7222 -- If the object declaration has an explicit initialization, a
7223 -- temporary may have to be created to hold the expression, to
7224 -- ensure that access to the object remains atomic.
7226 if Nkind
(Parent
(Ent
)) = N_Object_Declaration
7227 and then Present
(Expression
(Parent
(Ent
)))
7229 Set_Has_Delayed_Freeze
(Ent
);
7233 -- Atomic/Shared/Volatile_Full_Access imply Independent
7235 if Prag_Id
/= Pragma_Volatile
then
7236 Set_Is_Independent
(Ent
);
7238 if Prag_Id
= Pragma_Independent
then
7239 Record_Independence_Check
(N
, Ent
);
7243 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7245 if Prag_Id
/= Pragma_Independent
then
7246 Set_Is_Volatile
(Ent
);
7247 Set_Treat_As_Volatile
(Ent
);
7249 end Mark_Component_Or_Object
;
7251 --------------------
7252 -- Set_Atomic_VFA --
7253 --------------------
7255 procedure Set_Atomic_VFA
(Ent
: Entity_Id
) is
7257 if Prag_Id
= Pragma_Volatile_Full_Access
then
7258 Set_Is_Volatile_Full_Access
(Ent
);
7260 Set_Is_Atomic
(Ent
);
7263 if not Has_Alignment_Clause
(Ent
) then
7264 Set_Alignment
(Ent
, Uint_0
);
7274 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
7277 Check_Ada_83_Warning
;
7278 Check_No_Identifiers
;
7279 Check_Arg_Count
(1);
7280 Check_Arg_Is_Local_Name
(Arg1
);
7281 E_Arg
:= Get_Pragma_Arg
(Arg1
);
7283 if Etype
(E_Arg
) = Any_Type
then
7287 E
:= Entity
(E_Arg
);
7289 -- A pragma that applies to a Ghost entity becomes Ghost for the
7290 -- purposes of legality checks and removal of ignored Ghost code.
7292 Mark_Ghost_Pragma
(N
, E
);
7294 -- Check duplicate before we chain ourselves
7296 Check_Duplicate_Pragma
(E
);
7298 -- Check appropriateness of the entity
7300 Decl
:= Declaration_Node
(E
);
7302 -- Deal with the case where the pragma/attribute is applied to a type
7305 if Rep_Item_Too_Early
(E
, N
)
7306 or else Rep_Item_Too_Late
(E
, N
)
7310 Check_First_Subtype
(Arg1
);
7313 -- Attribute belongs on the base type. If the view of the type is
7314 -- currently private, it also belongs on the underlying type.
7316 if Prag_Id
= Pragma_Atomic
7317 or else Prag_Id
= Pragma_Shared
7318 or else Prag_Id
= Pragma_Volatile_Full_Access
7321 Set_Atomic_VFA
(Base_Type
(E
));
7322 Set_Atomic_VFA
(Underlying_Type
(E
));
7325 -- Atomic/Shared/Volatile_Full_Access imply Independent
7327 if Prag_Id
/= Pragma_Volatile
then
7328 Set_Is_Independent
(E
);
7329 Set_Is_Independent
(Base_Type
(E
));
7330 Set_Is_Independent
(Underlying_Type
(E
));
7332 if Prag_Id
= Pragma_Independent
then
7333 Record_Independence_Check
(N
, Base_Type
(E
));
7337 -- Atomic/Shared/Volatile_Full_Access imply Volatile
7339 if Prag_Id
/= Pragma_Independent
then
7340 Set_Is_Volatile
(E
);
7341 Set_Is_Volatile
(Base_Type
(E
));
7342 Set_Is_Volatile
(Underlying_Type
(E
));
7344 Set_Treat_As_Volatile
(E
);
7345 Set_Treat_As_Volatile
(Underlying_Type
(E
));
7348 -- Apply Volatile to the composite type's individual components,
7351 if Prag_Id
= Pragma_Volatile
7352 and then Is_Record_Type
(Etype
(E
))
7357 Comp
:= First_Component
(E
);
7358 while Present
(Comp
) loop
7359 Mark_Component_Or_Object
(Comp
);
7361 Next_Component
(Comp
);
7366 -- Deal with the case where the pragma/attribute applies to a
7367 -- component or object declaration.
7369 elsif Nkind
(Decl
) = N_Object_Declaration
7370 or else (Nkind
(Decl
) = N_Component_Declaration
7371 and then Original_Record_Component
(E
) = E
)
7373 if Rep_Item_Too_Late
(E
, N
) then
7377 Mark_Component_Or_Object
(E
);
7379 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
7382 -- Perform the checks needed to assure the proper use of the GNAT
7383 -- pragma Volatile_Full_Access.
7385 Check_VFA_Conflicts
(E
);
7387 -- The following check is only relevant when SPARK_Mode is on as
7388 -- this is not a standard Ada legality rule. Pragma Volatile can
7389 -- only apply to a full type declaration or an object declaration
7390 -- (SPARK RM 7.1.3(2)). Original_Node is necessary to account for
7391 -- untagged derived types that are rewritten as subtypes of their
7392 -- respective root types.
7395 and then Prag_Id
= Pragma_Volatile
7397 not Nkind_In
(Original_Node
(Decl
), N_Full_Type_Declaration
,
7398 N_Object_Declaration
)
7401 ("argument of pragma % must denote a full type or object "
7402 & "declaration", Arg1
);
7404 end Process_Atomic_Independent_Shared_Volatile
;
7406 -------------------------------------------
7407 -- Process_Compile_Time_Warning_Or_Error --
7408 -------------------------------------------
7410 procedure Process_Compile_Time_Warning_Or_Error
is
7411 Validation_Needed
: Boolean := False;
7413 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
7414 -- Tree visitor that checks if N is an attribute reference that can
7415 -- be statically computed by the back end. Validation_Needed is set
7416 -- to True if found.
7422 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
7424 if Nkind
(N
) = N_Attribute_Reference
7425 and then Is_Entity_Name
(Prefix
(N
))
7428 Attr_Id
: constant Attribute_Id
:=
7429 Get_Attribute_Id
(Attribute_Name
(N
));
7431 if Attr_Id
= Attribute_Alignment
7432 or else Attr_Id
= Attribute_Size
7434 Validation_Needed
:= True;
7442 procedure Check_Expression
is new Traverse_Proc
(Check_Node
);
7446 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
7448 -- Start of processing for Process_Compile_Time_Warning_Or_Error
7451 Check_Arg_Count
(2);
7452 Check_No_Identifiers
;
7453 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
7454 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
7456 if Compile_Time_Known_Value
(Arg1x
) then
7457 Process_Compile_Time_Warning_Or_Error
(N
, Sloc
(Arg1
));
7459 -- Register the expression for its validation after the back end has
7460 -- been called if it has occurrences of attributes Size or Alignment
7461 -- (because they may be statically computed by the back end and hence
7462 -- the whole expression needs to be reevaluated).
7465 Check_Expression
(Arg1x
);
7467 if Validation_Needed
then
7468 Sem_Ch13
.Validate_Compile_Time_Warning_Error
(N
);
7471 end Process_Compile_Time_Warning_Or_Error
;
7473 ------------------------
7474 -- Process_Convention --
7475 ------------------------
7477 procedure Process_Convention
7478 (C
: out Convention_Id
;
7479 Ent
: out Entity_Id
)
7483 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
);
7484 -- Called if we have more than one Export/Import/Convention pragma.
7485 -- This is generally illegal, but we have a special case of allowing
7486 -- Import and Interface to coexist if they specify the convention in
7487 -- a consistent manner. We are allowed to do this, since Interface is
7488 -- an implementation defined pragma, and we choose to do it since we
7489 -- know Rational allows this combination. S is the entity id of the
7490 -- subprogram in question. This procedure also sets the special flag
7491 -- Import_Interface_Present in both pragmas in the case where we do
7492 -- have matching Import and Interface pragmas.
7494 procedure Set_Convention_From_Pragma
(E
: Entity_Id
);
7495 -- Set convention in entity E, and also flag that the entity has a
7496 -- convention pragma. If entity is for a private or incomplete type,
7497 -- also set convention and flag on underlying type. This procedure
7498 -- also deals with the special case of C_Pass_By_Copy convention,
7499 -- and error checks for inappropriate convention specification.
7501 -------------------------------
7502 -- Diagnose_Multiple_Pragmas --
7503 -------------------------------
7505 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
) is
7506 Pdec
: constant Node_Id
:= Declaration_Node
(S
);
7510 function Same_Convention
(Decl
: Node_Id
) return Boolean;
7511 -- Decl is a pragma node. This function returns True if this
7512 -- pragma has a first argument that is an identifier with a
7513 -- Chars field corresponding to the Convention_Id C.
7515 function Same_Name
(Decl
: Node_Id
) return Boolean;
7516 -- Decl is a pragma node. This function returns True if this
7517 -- pragma has a second argument that is an identifier with a
7518 -- Chars field that matches the Chars of the current subprogram.
7520 ---------------------
7521 -- Same_Convention --
7522 ---------------------
7524 function Same_Convention
(Decl
: Node_Id
) return Boolean is
7525 Arg1
: constant Node_Id
:=
7526 First
(Pragma_Argument_Associations
(Decl
));
7529 if Present
(Arg1
) then
7531 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
7533 if Nkind
(Arg
) = N_Identifier
7534 and then Is_Convention_Name
(Chars
(Arg
))
7535 and then Get_Convention_Id
(Chars
(Arg
)) = C
7543 end Same_Convention
;
7549 function Same_Name
(Decl
: Node_Id
) return Boolean is
7550 Arg1
: constant Node_Id
:=
7551 First
(Pragma_Argument_Associations
(Decl
));
7559 Arg2
:= Next
(Arg1
);
7566 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
7568 if Nkind
(Arg
) = N_Identifier
7569 and then Chars
(Arg
) = Chars
(S
)
7578 -- Start of processing for Diagnose_Multiple_Pragmas
7583 -- Definitely give message if we have Convention/Export here
7585 if Prag_Id
= Pragma_Convention
or else Prag_Id
= Pragma_Export
then
7588 -- If we have an Import or Export, scan back from pragma to
7589 -- find any previous pragma applying to the same procedure.
7590 -- The scan will be terminated by the start of the list, or
7591 -- hitting the subprogram declaration. This won't allow one
7592 -- pragma to appear in the public part and one in the private
7593 -- part, but that seems very unlikely in practice.
7597 while Present
(Decl
) and then Decl
/= Pdec
loop
7599 -- Look for pragma with same name as us
7601 if Nkind
(Decl
) = N_Pragma
7602 and then Same_Name
(Decl
)
7604 -- Give error if same as our pragma or Export/Convention
7606 if Nam_In
(Pragma_Name_Unmapped
(Decl
),
7609 Pragma_Name_Unmapped
(N
))
7613 -- Case of Import/Interface or the other way round
7615 elsif Nam_In
(Pragma_Name_Unmapped
(Decl
),
7616 Name_Interface
, Name_Import
)
7618 -- Here we know that we have Import and Interface. It
7619 -- doesn't matter which way round they are. See if
7620 -- they specify the same convention. If so, all OK,
7621 -- and set special flags to stop other messages
7623 if Same_Convention
(Decl
) then
7624 Set_Import_Interface_Present
(N
);
7625 Set_Import_Interface_Present
(Decl
);
7628 -- If different conventions, special message
7631 Error_Msg_Sloc
:= Sloc
(Decl
);
7633 ("convention differs from that given#", Arg1
);
7643 -- Give message if needed if we fall through those tests
7644 -- except on Relaxed_RM_Semantics where we let go: either this
7645 -- is a case accepted/ignored by other Ada compilers (e.g.
7646 -- a mix of Convention and Import), or another error will be
7647 -- generated later (e.g. using both Import and Export).
7649 if Err
and not Relaxed_RM_Semantics
then
7651 ("at most one Convention/Export/Import pragma is allowed",
7654 end Diagnose_Multiple_Pragmas
;
7656 --------------------------------
7657 -- Set_Convention_From_Pragma --
7658 --------------------------------
7660 procedure Set_Convention_From_Pragma
(E
: Entity_Id
) is
7662 -- Ada 2005 (AI-430): Check invalid attempt to change convention
7663 -- for an overridden dispatching operation. Technically this is
7664 -- an amendment and should only be done in Ada 2005 mode. However,
7665 -- this is clearly a mistake, since the problem that is addressed
7666 -- by this AI is that there is a clear gap in the RM.
7668 if Is_Dispatching_Operation
(E
)
7669 and then Present
(Overridden_Operation
(E
))
7670 and then C
/= Convention
(Overridden_Operation
(E
))
7673 ("cannot change convention for overridden dispatching "
7674 & "operation", Arg1
);
7677 -- Special checks for Convention_Stdcall
7679 if C
= Convention_Stdcall
then
7681 -- A dispatching call is not allowed. A dispatching subprogram
7682 -- cannot be used to interface to the Win32 API, so in fact
7683 -- this check does not impose any effective restriction.
7685 if Is_Dispatching_Operation
(E
) then
7686 Error_Msg_Sloc
:= Sloc
(E
);
7688 -- Note: make this unconditional so that if there is more
7689 -- than one call to which the pragma applies, we get a
7690 -- message for each call. Also don't use Error_Pragma,
7691 -- so that we get multiple messages.
7694 ("dispatching subprogram# cannot use Stdcall convention!",
7697 -- Several allowed cases
7699 elsif Is_Subprogram_Or_Generic_Subprogram
(E
)
7703 or else Ekind
(E
) = E_Variable
7705 -- A component as well. The entity does not have its Ekind
7706 -- set until the enclosing record declaration is fully
7709 or else Nkind
(Parent
(E
)) = N_Component_Declaration
7711 -- An access to subprogram is also allowed
7715 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
)
7717 -- Allow internal call to set convention of subprogram type
7719 or else Ekind
(E
) = E_Subprogram_Type
7725 ("second argument of pragma% must be subprogram (type)",
7730 -- Set the convention
7732 Set_Convention
(E
, C
);
7733 Set_Has_Convention_Pragma
(E
);
7735 -- For the case of a record base type, also set the convention of
7736 -- any anonymous access types declared in the record which do not
7737 -- currently have a specified convention.
7739 if Is_Record_Type
(E
) and then Is_Base_Type
(E
) then
7744 Comp
:= First_Component
(E
);
7745 while Present
(Comp
) loop
7746 if Present
(Etype
(Comp
))
7747 and then Ekind_In
(Etype
(Comp
),
7748 E_Anonymous_Access_Type
,
7749 E_Anonymous_Access_Subprogram_Type
)
7750 and then not Has_Convention_Pragma
(Comp
)
7752 Set_Convention
(Comp
, C
);
7755 Next_Component
(Comp
);
7760 -- Deal with incomplete/private type case, where underlying type
7761 -- is available, so set convention of that underlying type.
7763 if Is_Incomplete_Or_Private_Type
(E
)
7764 and then Present
(Underlying_Type
(E
))
7766 Set_Convention
(Underlying_Type
(E
), C
);
7767 Set_Has_Convention_Pragma
(Underlying_Type
(E
), True);
7770 -- A class-wide type should inherit the convention of the specific
7771 -- root type (although this isn't specified clearly by the RM).
7773 if Is_Type
(E
) and then Present
(Class_Wide_Type
(E
)) then
7774 Set_Convention
(Class_Wide_Type
(E
), C
);
7777 -- If the entity is a record type, then check for special case of
7778 -- C_Pass_By_Copy, which is treated the same as C except that the
7779 -- special record flag is set. This convention is only permitted
7780 -- on record types (see AI95-00131).
7782 if Cname
= Name_C_Pass_By_Copy
then
7783 if Is_Record_Type
(E
) then
7784 Set_C_Pass_By_Copy
(Base_Type
(E
));
7785 elsif Is_Incomplete_Or_Private_Type
(E
)
7786 and then Is_Record_Type
(Underlying_Type
(E
))
7788 Set_C_Pass_By_Copy
(Base_Type
(Underlying_Type
(E
)));
7791 ("C_Pass_By_Copy convention allowed only for record type",
7796 -- If the entity is a derived boolean type, check for the special
7797 -- case of convention C, C++, or Fortran, where we consider any
7798 -- nonzero value to represent true.
7800 if Is_Discrete_Type
(E
)
7801 and then Root_Type
(Etype
(E
)) = Standard_Boolean
7807 C
= Convention_Fortran
)
7809 Set_Nonzero_Is_True
(Base_Type
(E
));
7811 end Set_Convention_From_Pragma
;
7815 Comp_Unit
: Unit_Number_Type
;
7820 -- Start of processing for Process_Convention
7823 Check_At_Least_N_Arguments
(2);
7824 Check_Optional_Identifier
(Arg1
, Name_Convention
);
7825 Check_Arg_Is_Identifier
(Arg1
);
7826 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
7828 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7829 -- tested again below to set the critical flag).
7831 if Cname
= Name_C_Pass_By_Copy
then
7834 -- Otherwise we must have something in the standard convention list
7836 elsif Is_Convention_Name
(Cname
) then
7837 C
:= Get_Convention_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
7839 -- Otherwise warn on unrecognized convention
7842 if Warn_On_Export_Import
then
7844 ("??unrecognized convention name, C assumed",
7845 Get_Pragma_Arg
(Arg1
));
7851 Check_Optional_Identifier
(Arg2
, Name_Entity
);
7852 Check_Arg_Is_Local_Name
(Arg2
);
7854 Id
:= Get_Pragma_Arg
(Arg2
);
7857 if not Is_Entity_Name
(Id
) then
7858 Error_Pragma_Arg
("entity name required", Arg2
);
7863 -- Set entity to return
7867 -- Ada_Pass_By_Copy special checking
7869 if C
= Convention_Ada_Pass_By_Copy
then
7870 if not Is_First_Subtype
(E
) then
7872 ("convention `Ada_Pass_By_Copy` only allowed for types",
7876 if Is_By_Reference_Type
(E
) then
7878 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7882 -- Ada_Pass_By_Reference special checking
7884 elsif C
= Convention_Ada_Pass_By_Reference
then
7885 if not Is_First_Subtype
(E
) then
7887 ("convention `Ada_Pass_By_Reference` only allowed for types",
7891 if Is_By_Copy_Type
(E
) then
7893 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7898 -- Go to renamed subprogram if present, since convention applies to
7899 -- the actual renamed entity, not to the renaming entity. If the
7900 -- subprogram is inherited, go to parent subprogram.
7902 if Is_Subprogram
(E
)
7903 and then Present
(Alias
(E
))
7905 if Nkind
(Parent
(Declaration_Node
(E
))) =
7906 N_Subprogram_Renaming_Declaration
7908 if Scope
(E
) /= Scope
(Alias
(E
)) then
7910 ("cannot apply pragma% to non-local entity&#", E
);
7915 elsif Nkind_In
(Parent
(E
), N_Full_Type_Declaration
,
7916 N_Private_Extension_Declaration
)
7917 and then Scope
(E
) = Scope
(Alias
(E
))
7921 -- Return the parent subprogram the entity was inherited from
7927 -- Check that we are not applying this to a specless body. Relax this
7928 -- check if Relaxed_RM_Semantics to accommodate other Ada compilers.
7930 if Is_Subprogram
(E
)
7931 and then Nkind
(Parent
(Declaration_Node
(E
))) = N_Subprogram_Body
7932 and then not Relaxed_RM_Semantics
7935 ("pragma% requires separate spec and must come before body");
7938 -- Check that we are not applying this to a named constant
7940 if Ekind_In
(E
, E_Named_Integer
, E_Named_Real
) then
7941 Error_Msg_Name_1
:= Pname
;
7943 ("cannot apply pragma% to named constant!",
7944 Get_Pragma_Arg
(Arg2
));
7946 ("\supply appropriate type for&!", Arg2
);
7949 if Ekind
(E
) = E_Enumeration_Literal
then
7950 Error_Pragma
("enumeration literal not allowed for pragma%");
7953 -- Check for rep item appearing too early or too late
7955 if Etype
(E
) = Any_Type
7956 or else Rep_Item_Too_Early
(E
, N
)
7960 elsif Present
(Underlying_Type
(E
)) then
7961 E
:= Underlying_Type
(E
);
7964 if Rep_Item_Too_Late
(E
, N
) then
7968 if Has_Convention_Pragma
(E
) then
7969 Diagnose_Multiple_Pragmas
(E
);
7971 elsif Convention
(E
) = Convention_Protected
7972 or else Ekind
(Scope
(E
)) = E_Protected_Type
7975 ("a protected operation cannot be given a different convention",
7979 -- For Intrinsic, a subprogram is required
7981 if C
= Convention_Intrinsic
7982 and then not Is_Subprogram_Or_Generic_Subprogram
(E
)
7984 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7986 if not (Is_Type
(E
) and then Relaxed_RM_Semantics
) then
7988 ("second argument of pragma% must be a subprogram", Arg2
);
7992 -- Deal with non-subprogram cases
7994 if not Is_Subprogram_Or_Generic_Subprogram
(E
) then
7995 Set_Convention_From_Pragma
(E
);
7999 -- The pragma must apply to a first subtype, but it can also
8000 -- apply to a generic type in a generic formal part, in which
8001 -- case it will also appear in the corresponding instance.
8003 if Is_Generic_Type
(E
) or else In_Instance
then
8006 Check_First_Subtype
(Arg2
);
8009 Set_Convention_From_Pragma
(Base_Type
(E
));
8011 -- For access subprograms, we must set the convention on the
8012 -- internally generated directly designated type as well.
8014 if Ekind
(E
) = E_Access_Subprogram_Type
then
8015 Set_Convention_From_Pragma
(Directly_Designated_Type
(E
));
8019 -- For the subprogram case, set proper convention for all homonyms
8020 -- in same scope and the same declarative part, i.e. the same
8021 -- compilation unit.
8024 Comp_Unit
:= Get_Source_Unit
(E
);
8025 Set_Convention_From_Pragma
(E
);
8027 -- Treat a pragma Import as an implicit body, and pragma import
8028 -- as implicit reference (for navigation in GPS).
8030 if Prag_Id
= Pragma_Import
then
8031 Generate_Reference
(E
, Id
, 'b');
8033 -- For exported entities we restrict the generation of references
8034 -- to entities exported to foreign languages since entities
8035 -- exported to Ada do not provide further information to GPS and
8036 -- add undesired references to the output of the gnatxref tool.
8038 elsif Prag_Id
= Pragma_Export
8039 and then Convention
(E
) /= Convention_Ada
8041 Generate_Reference
(E
, Id
, 'i');
8044 -- If the pragma comes from an aspect, it only applies to the
8045 -- given entity, not its homonyms.
8047 if From_Aspect_Specification
(N
) then
8048 if C
= Convention_Intrinsic
8049 and then Nkind
(Ent
) = N_Defining_Operator_Symbol
8051 if Is_Fixed_Point_Type
(Etype
(Ent
))
8052 or else Is_Fixed_Point_Type
(Etype
(First_Entity
(Ent
)))
8053 or else Is_Fixed_Point_Type
(Etype
(Last_Entity
(Ent
)))
8056 ("no intrinsic operator available for this fixed-point "
8059 ("\use expression functions with the desired "
8060 & "conversions made explicit", N
);
8067 -- Otherwise Loop through the homonyms of the pragma argument's
8068 -- entity, an apply convention to those in the current scope.
8074 exit when No
(E1
) or else Scope
(E1
) /= Current_Scope
;
8076 -- Ignore entry for which convention is already set
8078 if Has_Convention_Pragma
(E1
) then
8082 if Is_Subprogram
(E1
)
8083 and then Nkind
(Parent
(Declaration_Node
(E1
))) =
8085 and then not Relaxed_RM_Semantics
8087 Set_Has_Completion
(E
); -- to prevent cascaded error
8089 ("pragma% requires separate spec and must come before "
8093 -- Do not set the pragma on inherited operations or on formal
8096 if Comes_From_Source
(E1
)
8097 and then Comp_Unit
= Get_Source_Unit
(E1
)
8098 and then not Is_Formal_Subprogram
(E1
)
8099 and then Nkind
(Original_Node
(Parent
(E1
))) /=
8100 N_Full_Type_Declaration
8102 if Present
(Alias
(E1
))
8103 and then Scope
(E1
) /= Scope
(Alias
(E1
))
8106 ("cannot apply pragma% to non-local entity& declared#",
8110 Set_Convention_From_Pragma
(E1
);
8112 if Prag_Id
= Pragma_Import
then
8113 Generate_Reference
(E1
, Id
, 'b');
8121 end Process_Convention
;
8123 ----------------------------------------
8124 -- Process_Disable_Enable_Atomic_Sync --
8125 ----------------------------------------
8127 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
) is
8129 Check_No_Identifiers
;
8130 Check_At_Most_N_Arguments
(1);
8132 -- Modeled internally as
8133 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
8138 Pragma_Argument_Associations
=> New_List
(
8139 Make_Pragma_Argument_Association
(Loc
,
8141 Make_Identifier
(Loc
, Name_Atomic_Synchronization
)))));
8143 if Present
(Arg1
) then
8144 Append_To
(Pragma_Argument_Associations
(N
), New_Copy
(Arg1
));
8148 end Process_Disable_Enable_Atomic_Sync
;
8150 -------------------------------------------------
8151 -- Process_Extended_Import_Export_Internal_Arg --
8152 -------------------------------------------------
8154 procedure Process_Extended_Import_Export_Internal_Arg
8155 (Arg_Internal
: Node_Id
:= Empty
)
8158 if No
(Arg_Internal
) then
8159 Error_Pragma
("Internal parameter required for pragma%");
8162 if Nkind
(Arg_Internal
) = N_Identifier
then
8165 elsif Nkind
(Arg_Internal
) = N_Operator_Symbol
8166 and then (Prag_Id
= Pragma_Import_Function
8168 Prag_Id
= Pragma_Export_Function
)
8174 ("wrong form for Internal parameter for pragma%", Arg_Internal
);
8177 Check_Arg_Is_Local_Name
(Arg_Internal
);
8178 end Process_Extended_Import_Export_Internal_Arg
;
8180 --------------------------------------------------
8181 -- Process_Extended_Import_Export_Object_Pragma --
8182 --------------------------------------------------
8184 procedure Process_Extended_Import_Export_Object_Pragma
8185 (Arg_Internal
: Node_Id
;
8186 Arg_External
: Node_Id
;
8192 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
8193 Def_Id
:= Entity
(Arg_Internal
);
8195 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
8197 ("pragma% must designate an object", Arg_Internal
);
8200 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
8202 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
8205 ("previous Common/Psect_Object applies, pragma % not permitted",
8209 if Rep_Item_Too_Late
(Def_Id
, N
) then
8213 Set_Extended_Import_Export_External_Name
(Def_Id
, Arg_External
);
8215 if Present
(Arg_Size
) then
8216 Check_Arg_Is_External_Name
(Arg_Size
);
8219 -- Export_Object case
8221 if Prag_Id
= Pragma_Export_Object
then
8222 if not Is_Library_Level_Entity
(Def_Id
) then
8224 ("argument for pragma% must be library level entity",
8228 if Ekind
(Current_Scope
) = E_Generic_Package
then
8229 Error_Pragma
("pragma& cannot appear in a generic unit");
8232 if not Size_Known_At_Compile_Time
(Etype
(Def_Id
)) then
8234 ("exported object must have compile time known size",
8238 if Warn_On_Export_Import
and then Is_Exported
(Def_Id
) then
8239 Error_Msg_N
("??duplicate Export_Object pragma", N
);
8241 Set_Exported
(Def_Id
, Arg_Internal
);
8244 -- Import_Object case
8247 if Is_Concurrent_Type
(Etype
(Def_Id
)) then
8249 ("cannot use pragma% for task/protected object",
8253 if Ekind
(Def_Id
) = E_Constant
then
8255 ("cannot import a constant", Arg_Internal
);
8258 if Warn_On_Export_Import
8259 and then Has_Discriminants
(Etype
(Def_Id
))
8262 ("imported value must be initialized??", Arg_Internal
);
8265 if Warn_On_Export_Import
8266 and then Is_Access_Type
(Etype
(Def_Id
))
8269 ("cannot import object of an access type??", Arg_Internal
);
8272 if Warn_On_Export_Import
8273 and then Is_Imported
(Def_Id
)
8275 Error_Msg_N
("??duplicate Import_Object pragma", N
);
8277 -- Check for explicit initialization present. Note that an
8278 -- initialization generated by the code generator, e.g. for an
8279 -- access type, does not count here.
8281 elsif Present
(Expression
(Parent
(Def_Id
)))
8284 (Original_Node
(Expression
(Parent
(Def_Id
))))
8286 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8288 ("imported entities cannot be initialized (RM B.1(24))",
8289 "\no initialization allowed for & declared#", Arg1
);
8291 Set_Imported
(Def_Id
);
8292 Note_Possible_Modification
(Arg_Internal
, Sure
=> False);
8295 end Process_Extended_Import_Export_Object_Pragma
;
8297 ------------------------------------------------------
8298 -- Process_Extended_Import_Export_Subprogram_Pragma --
8299 ------------------------------------------------------
8301 procedure Process_Extended_Import_Export_Subprogram_Pragma
8302 (Arg_Internal
: Node_Id
;
8303 Arg_External
: Node_Id
;
8304 Arg_Parameter_Types
: Node_Id
;
8305 Arg_Result_Type
: Node_Id
:= Empty
;
8306 Arg_Mechanism
: Node_Id
;
8307 Arg_Result_Mechanism
: Node_Id
:= Empty
)
8313 Ambiguous
: Boolean;
8316 function Same_Base_Type
8318 Formal
: Entity_Id
) return Boolean;
8319 -- Determines if Ptype references the type of Formal. Note that only
8320 -- the base types need to match according to the spec. Ptype here is
8321 -- the argument from the pragma, which is either a type name, or an
8322 -- access attribute.
8324 --------------------
8325 -- Same_Base_Type --
8326 --------------------
8328 function Same_Base_Type
8330 Formal
: Entity_Id
) return Boolean
8332 Ftyp
: constant Entity_Id
:= Base_Type
(Etype
(Formal
));
8336 -- Case where pragma argument is typ'Access
8338 if Nkind
(Ptype
) = N_Attribute_Reference
8339 and then Attribute_Name
(Ptype
) = Name_Access
8341 Pref
:= Prefix
(Ptype
);
8344 if not Is_Entity_Name
(Pref
)
8345 or else Entity
(Pref
) = Any_Type
8350 -- We have a match if the corresponding argument is of an
8351 -- anonymous access type, and its designated type matches the
8352 -- type of the prefix of the access attribute
8354 return Ekind
(Ftyp
) = E_Anonymous_Access_Type
8355 and then Base_Type
(Entity
(Pref
)) =
8356 Base_Type
(Etype
(Designated_Type
(Ftyp
)));
8358 -- Case where pragma argument is a type name
8363 if not Is_Entity_Name
(Ptype
)
8364 or else Entity
(Ptype
) = Any_Type
8369 -- We have a match if the corresponding argument is of the type
8370 -- given in the pragma (comparing base types)
8372 return Base_Type
(Entity
(Ptype
)) = Ftyp
;
8376 -- Start of processing for
8377 -- Process_Extended_Import_Export_Subprogram_Pragma
8380 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
8384 -- Loop through homonyms (overloadings) of the entity
8386 Hom_Id
:= Entity
(Arg_Internal
);
8387 while Present
(Hom_Id
) loop
8388 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8390 -- We need a subprogram in the current scope
8392 if not Is_Subprogram
(Def_Id
)
8393 or else Scope
(Def_Id
) /= Current_Scope
8400 -- Pragma cannot apply to subprogram body
8402 if Is_Subprogram
(Def_Id
)
8403 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
8407 ("pragma% requires separate spec and must come before "
8411 -- Test result type if given, note that the result type
8412 -- parameter can only be present for the function cases.
8414 if Present
(Arg_Result_Type
)
8415 and then not Same_Base_Type
(Arg_Result_Type
, Def_Id
)
8419 elsif Etype
(Def_Id
) /= Standard_Void_Type
8420 and then Nam_In
(Pname
, Name_Export_Procedure
,
8421 Name_Import_Procedure
)
8425 -- Test parameter types if given. Note that this parameter has
8426 -- not been analyzed (and must not be, since it is semantic
8427 -- nonsense), so we get it as the parser left it.
8429 elsif Present
(Arg_Parameter_Types
) then
8430 Check_Matching_Types
: declare
8435 Formal
:= First_Formal
(Def_Id
);
8437 if Nkind
(Arg_Parameter_Types
) = N_Null
then
8438 if Present
(Formal
) then
8442 -- A list of one type, e.g. (List) is parsed as a
8443 -- parenthesized expression.
8445 elsif Nkind
(Arg_Parameter_Types
) /= N_Aggregate
8446 and then Paren_Count
(Arg_Parameter_Types
) = 1
8449 or else Present
(Next_Formal
(Formal
))
8454 Same_Base_Type
(Arg_Parameter_Types
, Formal
);
8457 -- A list of more than one type is parsed as a aggregate
8459 elsif Nkind
(Arg_Parameter_Types
) = N_Aggregate
8460 and then Paren_Count
(Arg_Parameter_Types
) = 0
8462 Ptype
:= First
(Expressions
(Arg_Parameter_Types
));
8463 while Present
(Ptype
) or else Present
(Formal
) loop
8466 or else not Same_Base_Type
(Ptype
, Formal
)
8471 Next_Formal
(Formal
);
8476 -- Anything else is of the wrong form
8480 ("wrong form for Parameter_Types parameter",
8481 Arg_Parameter_Types
);
8483 end Check_Matching_Types
;
8486 -- Match is now False if the entry we found did not match
8487 -- either a supplied Parameter_Types or Result_Types argument
8493 -- Ambiguous case, the flag Ambiguous shows if we already
8494 -- detected this and output the initial messages.
8497 if not Ambiguous
then
8499 Error_Msg_Name_1
:= Pname
;
8501 ("pragma% does not uniquely identify subprogram!",
8503 Error_Msg_Sloc
:= Sloc
(Ent
);
8504 Error_Msg_N
("matching subprogram #!", N
);
8508 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8509 Error_Msg_N
("matching subprogram #!", N
);
8514 Hom_Id
:= Homonym
(Hom_Id
);
8517 -- See if we found an entry
8520 if not Ambiguous
then
8521 if Is_Generic_Subprogram
(Entity
(Arg_Internal
)) then
8523 ("pragma% cannot be given for generic subprogram");
8526 ("pragma% does not identify local subprogram");
8533 -- Import pragmas must be for imported entities
8535 if Prag_Id
= Pragma_Import_Function
8537 Prag_Id
= Pragma_Import_Procedure
8539 Prag_Id
= Pragma_Import_Valued_Procedure
8541 if not Is_Imported
(Ent
) then
8543 ("pragma Import or Interface must precede pragma%");
8546 -- Here we have the Export case which can set the entity as exported
8548 -- But does not do so if the specified external name is null, since
8549 -- that is taken as a signal in DEC Ada 83 (with which we want to be
8550 -- compatible) to request no external name.
8552 elsif Nkind
(Arg_External
) = N_String_Literal
8553 and then String_Length
(Strval
(Arg_External
)) = 0
8557 -- In all other cases, set entity as exported
8560 Set_Exported
(Ent
, Arg_Internal
);
8563 -- Special processing for Valued_Procedure cases
8565 if Prag_Id
= Pragma_Import_Valued_Procedure
8567 Prag_Id
= Pragma_Export_Valued_Procedure
8569 Formal
:= First_Formal
(Ent
);
8572 Error_Pragma
("at least one parameter required for pragma%");
8574 elsif Ekind
(Formal
) /= E_Out_Parameter
then
8575 Error_Pragma
("first parameter must have mode out for pragma%");
8578 Set_Is_Valued_Procedure
(Ent
);
8582 Set_Extended_Import_Export_External_Name
(Ent
, Arg_External
);
8584 -- Process Result_Mechanism argument if present. We have already
8585 -- checked that this is only allowed for the function case.
8587 if Present
(Arg_Result_Mechanism
) then
8588 Set_Mechanism_Value
(Ent
, Arg_Result_Mechanism
);
8591 -- Process Mechanism parameter if present. Note that this parameter
8592 -- is not analyzed, and must not be analyzed since it is semantic
8593 -- nonsense, so we get it in exactly as the parser left it.
8595 if Present
(Arg_Mechanism
) then
8603 -- A single mechanism association without a formal parameter
8604 -- name is parsed as a parenthesized expression. All other
8605 -- cases are parsed as aggregates, so we rewrite the single
8606 -- parameter case as an aggregate for consistency.
8608 if Nkind
(Arg_Mechanism
) /= N_Aggregate
8609 and then Paren_Count
(Arg_Mechanism
) = 1
8611 Rewrite
(Arg_Mechanism
,
8612 Make_Aggregate
(Sloc
(Arg_Mechanism
),
8613 Expressions
=> New_List
(
8614 Relocate_Node
(Arg_Mechanism
))));
8617 -- Case of only mechanism name given, applies to all formals
8619 if Nkind
(Arg_Mechanism
) /= N_Aggregate
then
8620 Formal
:= First_Formal
(Ent
);
8621 while Present
(Formal
) loop
8622 Set_Mechanism_Value
(Formal
, Arg_Mechanism
);
8623 Next_Formal
(Formal
);
8626 -- Case of list of mechanism associations given
8629 if Null_Record_Present
(Arg_Mechanism
) then
8631 ("inappropriate form for Mechanism parameter",
8635 -- Deal with positional ones first
8637 Formal
:= First_Formal
(Ent
);
8639 if Present
(Expressions
(Arg_Mechanism
)) then
8640 Mname
:= First
(Expressions
(Arg_Mechanism
));
8641 while Present
(Mname
) loop
8644 ("too many mechanism associations", Mname
);
8647 Set_Mechanism_Value
(Formal
, Mname
);
8648 Next_Formal
(Formal
);
8653 -- Deal with named entries
8655 if Present
(Component_Associations
(Arg_Mechanism
)) then
8656 Massoc
:= First
(Component_Associations
(Arg_Mechanism
));
8657 while Present
(Massoc
) loop
8658 Choice
:= First
(Choices
(Massoc
));
8660 if Nkind
(Choice
) /= N_Identifier
8661 or else Present
(Next
(Choice
))
8664 ("incorrect form for mechanism association",
8668 Formal
:= First_Formal
(Ent
);
8672 ("parameter name & not present", Choice
);
8675 if Chars
(Choice
) = Chars
(Formal
) then
8677 (Formal
, Expression
(Massoc
));
8679 -- Set entity on identifier (needed by ASIS)
8681 Set_Entity
(Choice
, Formal
);
8686 Next_Formal
(Formal
);
8695 end Process_Extended_Import_Export_Subprogram_Pragma
;
8697 --------------------------
8698 -- Process_Generic_List --
8699 --------------------------
8701 procedure Process_Generic_List
is
8706 Check_No_Identifiers
;
8707 Check_At_Least_N_Arguments
(1);
8709 -- Check all arguments are names of generic units or instances
8712 while Present
(Arg
) loop
8713 Exp
:= Get_Pragma_Arg
(Arg
);
8716 if not Is_Entity_Name
(Exp
)
8718 (not Is_Generic_Instance
(Entity
(Exp
))
8720 not Is_Generic_Unit
(Entity
(Exp
)))
8723 ("pragma% argument must be name of generic unit/instance",
8729 end Process_Generic_List
;
8731 ------------------------------------
8732 -- Process_Import_Predefined_Type --
8733 ------------------------------------
8735 procedure Process_Import_Predefined_Type
is
8736 Loc
: constant Source_Ptr
:= Sloc
(N
);
8738 Ftyp
: Node_Id
:= Empty
;
8744 Nam
:= String_To_Name
(Strval
(Expression
(Arg3
)));
8746 Elmt
:= First_Elmt
(Predefined_Float_Types
);
8747 while Present
(Elmt
) and then Chars
(Node
(Elmt
)) /= Nam
loop
8751 Ftyp
:= Node
(Elmt
);
8753 if Present
(Ftyp
) then
8755 -- Don't build a derived type declaration, because predefined C
8756 -- types have no declaration anywhere, so cannot really be named.
8757 -- Instead build a full type declaration, starting with an
8758 -- appropriate type definition is built
8760 if Is_Floating_Point_Type
(Ftyp
) then
8761 Def
:= Make_Floating_Point_Definition
(Loc
,
8762 Make_Integer_Literal
(Loc
, Digits_Value
(Ftyp
)),
8763 Make_Real_Range_Specification
(Loc
,
8764 Make_Real_Literal
(Loc
, Realval
(Type_Low_Bound
(Ftyp
))),
8765 Make_Real_Literal
(Loc
, Realval
(Type_High_Bound
(Ftyp
)))));
8767 -- Should never have a predefined type we cannot handle
8770 raise Program_Error
;
8773 -- Build and insert a Full_Type_Declaration, which will be
8774 -- analyzed as soon as this list entry has been analyzed.
8776 Decl
:= Make_Full_Type_Declaration
(Loc
,
8777 Make_Defining_Identifier
(Loc
, Chars
(Expression
(Arg2
))),
8778 Type_Definition
=> Def
);
8780 Insert_After
(N
, Decl
);
8781 Mark_Rewrite_Insertion
(Decl
);
8784 Error_Pragma_Arg
("no matching type found for pragma%",
8787 end Process_Import_Predefined_Type
;
8789 ---------------------------------
8790 -- Process_Import_Or_Interface --
8791 ---------------------------------
8793 procedure Process_Import_Or_Interface
is
8799 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8800 -- pragma Import (Entity, "external name");
8802 if Relaxed_RM_Semantics
8803 and then Arg_Count
= 2
8804 and then Prag_Id
= Pragma_Import
8805 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
8808 Def_Id
:= Get_Pragma_Arg
(Arg1
);
8811 if not Is_Entity_Name
(Def_Id
) then
8812 Error_Pragma_Arg
("entity name required", Arg1
);
8815 Def_Id
:= Entity
(Def_Id
);
8816 Kill_Size_Check_Code
(Def_Id
);
8817 Note_Possible_Modification
(Get_Pragma_Arg
(Arg1
), Sure
=> False);
8820 Process_Convention
(C
, Def_Id
);
8822 -- A pragma that applies to a Ghost entity becomes Ghost for the
8823 -- purposes of legality checks and removal of ignored Ghost code.
8825 Mark_Ghost_Pragma
(N
, Def_Id
);
8826 Kill_Size_Check_Code
(Def_Id
);
8827 Note_Possible_Modification
(Get_Pragma_Arg
(Arg2
), Sure
=> False);
8830 -- Various error checks
8832 if Ekind_In
(Def_Id
, E_Variable
, E_Constant
) then
8834 -- We do not permit Import to apply to a renaming declaration
8836 if Present
(Renamed_Object
(Def_Id
)) then
8838 ("pragma% not allowed for object renaming", Arg2
);
8840 -- User initialization is not allowed for imported object, but
8841 -- the object declaration may contain a default initialization,
8842 -- that will be discarded. Note that an explicit initialization
8843 -- only counts if it comes from source, otherwise it is simply
8844 -- the code generator making an implicit initialization explicit.
8846 elsif Present
(Expression
(Parent
(Def_Id
)))
8847 and then Comes_From_Source
8848 (Original_Node
(Expression
(Parent
(Def_Id
))))
8850 -- Set imported flag to prevent cascaded errors
8852 Set_Is_Imported
(Def_Id
);
8854 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8856 ("no initialization allowed for declaration of& #",
8857 "\imported entities cannot be initialized (RM B.1(24))",
8861 -- If the pragma comes from an aspect specification the
8862 -- Is_Imported flag has already been set.
8864 if not From_Aspect_Specification
(N
) then
8865 Set_Imported
(Def_Id
);
8868 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
8870 -- Note that we do not set Is_Public here. That's because we
8871 -- only want to set it if there is no address clause, and we
8872 -- don't know that yet, so we delay that processing till
8875 -- pragma Import completes deferred constants
8877 if Ekind
(Def_Id
) = E_Constant
then
8878 Set_Has_Completion
(Def_Id
);
8881 -- It is not possible to import a constant of an unconstrained
8882 -- array type (e.g. string) because there is no simple way to
8883 -- write a meaningful subtype for it.
8885 if Is_Array_Type
(Etype
(Def_Id
))
8886 and then not Is_Constrained
(Etype
(Def_Id
))
8889 ("imported constant& must have a constrained subtype",
8894 elsif Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8896 -- If the name is overloaded, pragma applies to all of the denoted
8897 -- entities in the same declarative part, unless the pragma comes
8898 -- from an aspect specification or was generated by the compiler
8899 -- (such as for pragma Provide_Shift_Operators).
8902 while Present
(Hom_Id
) loop
8904 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8906 -- Ignore inherited subprograms because the pragma will apply
8907 -- to the parent operation, which is the one called.
8909 if Is_Overloadable
(Def_Id
)
8910 and then Present
(Alias
(Def_Id
))
8914 -- If it is not a subprogram, it must be in an outer scope and
8915 -- pragma does not apply.
8917 elsif not Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8920 -- The pragma does not apply to primitives of interfaces
8922 elsif Is_Dispatching_Operation
(Def_Id
)
8923 and then Present
(Find_Dispatching_Type
(Def_Id
))
8924 and then Is_Interface
(Find_Dispatching_Type
(Def_Id
))
8928 -- Verify that the homonym is in the same declarative part (not
8929 -- just the same scope). If the pragma comes from an aspect
8930 -- specification we know that it is part of the declaration.
8932 elsif Parent
(Unit_Declaration_Node
(Def_Id
)) /= Parent
(N
)
8933 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit_Aux
8934 and then not From_Aspect_Specification
(N
)
8939 -- If the pragma comes from an aspect specification the
8940 -- Is_Imported flag has already been set.
8942 if not From_Aspect_Specification
(N
) then
8943 Set_Imported
(Def_Id
);
8946 -- Reject an Import applied to an abstract subprogram
8948 if Is_Subprogram
(Def_Id
)
8949 and then Is_Abstract_Subprogram
(Def_Id
)
8951 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8953 ("cannot import abstract subprogram& declared#",
8957 -- Special processing for Convention_Intrinsic
8959 if C
= Convention_Intrinsic
then
8961 -- Link_Name argument not allowed for intrinsic
8965 Set_Is_Intrinsic_Subprogram
(Def_Id
);
8967 -- If no external name is present, then check that this
8968 -- is a valid intrinsic subprogram. If an external name
8969 -- is present, then this is handled by the back end.
8972 Check_Intrinsic_Subprogram
8973 (Def_Id
, Get_Pragma_Arg
(Arg2
));
8977 -- Verify that the subprogram does not have a completion
8978 -- through a renaming declaration. For other completions the
8979 -- pragma appears as a too late representation.
8982 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Def_Id
);
8986 and then Nkind
(Decl
) = N_Subprogram_Declaration
8987 and then Present
(Corresponding_Body
(Decl
))
8988 and then Nkind
(Unit_Declaration_Node
8989 (Corresponding_Body
(Decl
))) =
8990 N_Subprogram_Renaming_Declaration
8992 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8994 ("cannot import&, renaming already provided for "
8995 & "declaration #", N
, Def_Id
);
8999 -- If the pragma comes from an aspect specification, there
9000 -- must be an Import aspect specified as well. In the rare
9001 -- case where Import is set to False, the suprogram needs to
9002 -- have a local completion.
9005 Imp_Aspect
: constant Node_Id
:=
9006 Find_Aspect
(Def_Id
, Aspect_Import
);
9010 if Present
(Imp_Aspect
)
9011 and then Present
(Expression
(Imp_Aspect
))
9013 Expr
:= Expression
(Imp_Aspect
);
9014 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
9016 if Is_Entity_Name
(Expr
)
9017 and then Entity
(Expr
) = Standard_True
9019 Set_Has_Completion
(Def_Id
);
9022 -- If there is no expression, the default is True, as for
9023 -- all boolean aspects. Same for the older pragma.
9026 Set_Has_Completion
(Def_Id
);
9030 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
9033 if Is_Compilation_Unit
(Hom_Id
) then
9035 -- Its possible homonyms are not affected by the pragma.
9036 -- Such homonyms might be present in the context of other
9037 -- units being compiled.
9041 elsif From_Aspect_Specification
(N
) then
9044 -- If the pragma was created by the compiler, then we don't
9045 -- want it to apply to other homonyms. This kind of case can
9046 -- occur when using pragma Provide_Shift_Operators, which
9047 -- generates implicit shift and rotate operators with Import
9048 -- pragmas that might apply to earlier explicit or implicit
9049 -- declarations marked with Import (for example, coming from
9050 -- an earlier pragma Provide_Shift_Operators for another type),
9051 -- and we don't generally want other homonyms being treated
9052 -- as imported or the pragma flagged as an illegal duplicate.
9054 elsif not Comes_From_Source
(N
) then
9058 Hom_Id
:= Homonym
(Hom_Id
);
9062 -- Import a CPP class
9064 elsif C
= Convention_CPP
9065 and then (Is_Record_Type
(Def_Id
)
9066 or else Ekind
(Def_Id
) = E_Incomplete_Type
)
9068 if Ekind
(Def_Id
) = E_Incomplete_Type
then
9069 if Present
(Full_View
(Def_Id
)) then
9070 Def_Id
:= Full_View
(Def_Id
);
9074 ("cannot import 'C'P'P type before full declaration seen",
9075 Get_Pragma_Arg
(Arg2
));
9077 -- Although we have reported the error we decorate it as
9078 -- CPP_Class to avoid reporting spurious errors
9080 Set_Is_CPP_Class
(Def_Id
);
9085 -- Types treated as CPP classes must be declared limited (note:
9086 -- this used to be a warning but there is no real benefit to it
9087 -- since we did effectively intend to treat the type as limited
9090 if not Is_Limited_Type
(Def_Id
) then
9092 ("imported 'C'P'P type must be limited",
9093 Get_Pragma_Arg
(Arg2
));
9096 if Etype
(Def_Id
) /= Def_Id
9097 and then not Is_CPP_Class
(Root_Type
(Def_Id
))
9099 Error_Msg_N
("root type must be a 'C'P'P type", Arg1
);
9102 Set_Is_CPP_Class
(Def_Id
);
9104 -- Imported CPP types must not have discriminants (because C++
9105 -- classes do not have discriminants).
9107 if Has_Discriminants
(Def_Id
) then
9109 ("imported 'C'P'P type cannot have discriminants",
9110 First
(Discriminant_Specifications
9111 (Declaration_Node
(Def_Id
))));
9114 -- Check that components of imported CPP types do not have default
9115 -- expressions. For private types this check is performed when the
9116 -- full view is analyzed (see Process_Full_View).
9118 if not Is_Private_Type
(Def_Id
) then
9119 Check_CPP_Type_Has_No_Defaults
(Def_Id
);
9122 -- Import a CPP exception
9124 elsif C
= Convention_CPP
9125 and then Ekind
(Def_Id
) = E_Exception
9129 ("'External_'Name arguments is required for 'Cpp exception",
9132 -- As only a string is allowed, Check_Arg_Is_External_Name
9135 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
9138 if Present
(Arg4
) then
9140 ("Link_Name argument not allowed for imported Cpp exception",
9144 -- Do not call Set_Interface_Name as the name of the exception
9145 -- shouldn't be modified (and in particular it shouldn't be
9146 -- the External_Name). For exceptions, the External_Name is the
9147 -- name of the RTTI structure.
9149 -- ??? Emit an error if pragma Import/Export_Exception is present
9151 elsif Nkind
(Parent
(Def_Id
)) = N_Incomplete_Type_Declaration
then
9153 Check_Arg_Count
(3);
9154 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
9156 Process_Import_Predefined_Type
;
9160 ("second argument of pragma% must be object, subprogram "
9161 & "or incomplete type",
9165 -- If this pragma applies to a compilation unit, then the unit, which
9166 -- is a subprogram, does not require (or allow) a body. We also do
9167 -- not need to elaborate imported procedures.
9169 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
9171 Cunit
: constant Node_Id
:= Parent
(Parent
(N
));
9173 Set_Body_Required
(Cunit
, False);
9176 end Process_Import_Or_Interface
;
9178 --------------------
9179 -- Process_Inline --
9180 --------------------
9182 procedure Process_Inline
(Status
: Inline_Status
) is
9189 Ghost_Error_Posted
: Boolean := False;
9190 -- Flag set when an error concerning the illegal mix of Ghost and
9191 -- non-Ghost subprograms is emitted.
9193 Ghost_Id
: Entity_Id
:= Empty
;
9194 -- The entity of the first Ghost subprogram encountered while
9195 -- processing the arguments of the pragma.
9197 procedure Check_Inline_Always_Placement
(Spec_Id
: Entity_Id
);
9198 -- Verify the placement of pragma Inline_Always with respect to the
9199 -- initial declaration of subprogram Spec_Id.
9201 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean;
9202 -- Returns True if it can be determined at this stage that inlining
9203 -- is not possible, for example if the body is available and contains
9204 -- exception handlers, we prevent inlining, since otherwise we can
9205 -- get undefined symbols at link time. This function also emits a
9206 -- warning if the pragma appears too late.
9208 -- ??? is business with link symbols still valid, or does it relate
9209 -- to front end ZCX which is being phased out ???
9211 procedure Make_Inline
(Subp
: Entity_Id
);
9212 -- Subp is the defining unit name of the subprogram declaration. If
9213 -- the pragma is valid, call Set_Inline_Flags on Subp, as well as on
9214 -- the corresponding body, if there is one present.
9216 procedure Set_Inline_Flags
(Subp
: Entity_Id
);
9217 -- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp.
9218 -- Also set or clear Is_Inlined flag on Subp depending on Status.
9220 -----------------------------------
9221 -- Check_Inline_Always_Placement --
9222 -----------------------------------
9224 procedure Check_Inline_Always_Placement
(Spec_Id
: Entity_Id
) is
9225 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Spec_Id
);
9227 function Compilation_Unit_OK
return Boolean;
9228 pragma Inline
(Compilation_Unit_OK
);
9229 -- Determine whether pragma Inline_Always applies to a compatible
9230 -- compilation unit denoted by Spec_Id.
9232 function Declarative_List_OK
return Boolean;
9233 pragma Inline
(Declarative_List_OK
);
9234 -- Determine whether the initial declaration of subprogram Spec_Id
9235 -- and the pragma appear in compatible declarative lists.
9237 function Subprogram_Body_OK
return Boolean;
9238 pragma Inline
(Subprogram_Body_OK
);
9239 -- Determine whether pragma Inline_Always applies to a compatible
9240 -- subprogram body denoted by Spec_Id.
9242 -------------------------
9243 -- Compilation_Unit_OK --
9244 -------------------------
9246 function Compilation_Unit_OK
return Boolean is
9247 Comp_Unit
: constant Node_Id
:= Parent
(Spec_Decl
);
9250 -- The pragma appears after the initial declaration of a
9251 -- compilation unit.
9253 -- procedure Comp_Unit;
9254 -- pragma Inline_Always (Comp_Unit);
9256 -- Note that for compatibility reasons, the following case is
9259 -- procedure Stand_Alone_Body_Comp_Unit is
9261 -- end Stand_Alone_Body_Comp_Unit;
9262 -- pragma Inline_Always (Stand_Alone_Body_Comp_Unit);
9265 Nkind
(Comp_Unit
) = N_Compilation_Unit
9266 and then Present
(Aux_Decls_Node
(Comp_Unit
))
9267 and then Is_List_Member
(N
)
9268 and then List_Containing
(N
) =
9269 Pragmas_After
(Aux_Decls_Node
(Comp_Unit
));
9270 end Compilation_Unit_OK
;
9272 -------------------------
9273 -- Declarative_List_OK --
9274 -------------------------
9276 function Declarative_List_OK
return Boolean is
9277 Context
: constant Node_Id
:= Parent
(Spec_Decl
);
9279 Init_Decl
: Node_Id
;
9280 Init_List
: List_Id
;
9281 Prag_List
: List_Id
;
9284 -- Determine the proper initial declaration. In general this is
9285 -- the declaration node of the subprogram except when the input
9286 -- denotes a generic instantiation.
9288 -- procedure Inst is new Gen;
9289 -- pragma Inline_Always (Inst);
9291 -- In this case the original subprogram is moved inside an
9292 -- anonymous package while pragma Inline_Always remains at the
9293 -- level of the anonymous package. Use the declaration of the
9294 -- package because it reflects the placement of the original
9297 -- package Anon_Pack is
9298 -- procedure Inst is ... end Inst; -- original
9301 -- procedure Inst renames Anon_Pack.Inst;
9302 -- pragma Inline_Always (Inst);
9304 if Is_Generic_Instance
(Spec_Id
) then
9305 Init_Decl
:= Parent
(Parent
(Spec_Decl
));
9306 pragma Assert
(Nkind
(Init_Decl
) = N_Package_Declaration
);
9308 Init_Decl
:= Spec_Decl
;
9311 if Is_List_Member
(Init_Decl
) and then Is_List_Member
(N
) then
9312 Init_List
:= List_Containing
(Init_Decl
);
9313 Prag_List
:= List_Containing
(N
);
9315 -- The pragma and then initial declaration appear within the
9316 -- same declarative list.
9318 if Init_List
= Prag_List
then
9321 -- A special case of the above is when both the pragma and
9322 -- the initial declaration appear in different lists of a
9323 -- package spec, protected definition, or a task definition.
9328 -- pragma Inline_Always (Proc);
9331 elsif Nkind_In
(Context
, N_Package_Specification
,
9332 N_Protected_Definition
,
9334 and then Init_List
= Visible_Declarations
(Context
)
9335 and then Prag_List
= Private_Declarations
(Context
)
9342 end Declarative_List_OK
;
9344 ------------------------
9345 -- Subprogram_Body_OK --
9346 ------------------------
9348 function Subprogram_Body_OK
return Boolean is
9349 Body_Decl
: Node_Id
;
9352 -- The pragma appears within the declarative list of a stand-
9353 -- alone subprogram body.
9355 -- procedure Stand_Alone_Body is
9356 -- pragma Inline_Always (Stand_Alone_Body);
9359 -- end Stand_Alone_Body;
9361 -- The compiler creates a dummy spec in this case, however the
9362 -- pragma remains within the declarative list of the body.
9364 if Nkind
(Spec_Decl
) = N_Subprogram_Declaration
9365 and then not Comes_From_Source
(Spec_Decl
)
9366 and then Present
(Corresponding_Body
(Spec_Decl
))
9369 Unit_Declaration_Node
(Corresponding_Body
(Spec_Decl
));
9371 if Present
(Declarations
(Body_Decl
))
9372 and then Is_List_Member
(N
)
9373 and then List_Containing
(N
) = Declarations
(Body_Decl
)
9380 end Subprogram_Body_OK
;
9382 -- Start of processing for Check_Inline_Always_Placement
9385 -- This check is relevant only for pragma Inline_Always
9387 if Pname
/= Name_Inline_Always
then
9390 -- Nothing to do when the pragma is internally generated on the
9391 -- assumption that it is properly placed.
9393 elsif not Comes_From_Source
(N
) then
9396 -- Nothing to do for internally generated subprograms that act
9397 -- as accidental homonyms of a source subprogram being inlined.
9399 elsif not Comes_From_Source
(Spec_Id
) then
9402 -- Nothing to do for generic formal subprograms that act as
9403 -- homonyms of another source subprogram being inlined.
9405 elsif Is_Formal_Subprogram
(Spec_Id
) then
9408 elsif Compilation_Unit_OK
9409 or else Declarative_List_OK
9410 or else Subprogram_Body_OK
9415 -- At this point it is known that the pragma applies to or appears
9416 -- within a completing body, a completing stub, or a subunit.
9418 Error_Msg_Name_1
:= Pname
;
9419 Error_Msg_Name_2
:= Chars
(Spec_Id
);
9420 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
9423 ("pragma % must appear on initial declaration of subprogram "
9424 & "% defined #", N
);
9425 end Check_Inline_Always_Placement
;
9427 ---------------------------
9428 -- Inlining_Not_Possible --
9429 ---------------------------
9431 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean is
9432 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
9436 if Nkind
(Decl
) = N_Subprogram_Body
then
9437 Stats
:= Handled_Statement_Sequence
(Decl
);
9438 return Present
(Exception_Handlers
(Stats
))
9439 or else Present
(At_End_Proc
(Stats
));
9441 elsif Nkind
(Decl
) = N_Subprogram_Declaration
9442 and then Present
(Corresponding_Body
(Decl
))
9444 if Analyzed
(Corresponding_Body
(Decl
)) then
9445 Error_Msg_N
("pragma appears too late, ignored??", N
);
9448 -- If the subprogram is a renaming as body, the body is just a
9449 -- call to the renamed subprogram, and inlining is trivially
9453 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
9454 N_Subprogram_Renaming_Declaration
9460 Handled_Statement_Sequence
9461 (Unit_Declaration_Node
(Corresponding_Body
(Decl
)));
9464 Present
(Exception_Handlers
(Stats
))
9465 or else Present
(At_End_Proc
(Stats
));
9469 -- If body is not available, assume the best, the check is
9470 -- performed again when compiling enclosing package bodies.
9474 end Inlining_Not_Possible
;
9480 procedure Make_Inline
(Subp
: Entity_Id
) is
9481 Kind
: constant Entity_Kind
:= Ekind
(Subp
);
9482 Inner_Subp
: Entity_Id
:= Subp
;
9485 -- Ignore if bad type, avoid cascaded error
9487 if Etype
(Subp
) = Any_Type
then
9491 -- If inlining is not possible, for now do not treat as an error
9493 elsif Status
/= Suppressed
9494 and then Front_End_Inlining
9495 and then Inlining_Not_Possible
(Subp
)
9500 -- Here we have a candidate for inlining, but we must exclude
9501 -- derived operations. Otherwise we would end up trying to inline
9502 -- a phantom declaration, and the result would be to drag in a
9503 -- body which has no direct inlining associated with it. That
9504 -- would not only be inefficient but would also result in the
9505 -- backend doing cross-unit inlining in cases where it was
9506 -- definitely inappropriate to do so.
9508 -- However, a simple Comes_From_Source test is insufficient, since
9509 -- we do want to allow inlining of generic instances which also do
9510 -- not come from source. We also need to recognize specs generated
9511 -- by the front-end for bodies that carry the pragma. Finally,
9512 -- predefined operators do not come from source but are not
9513 -- inlineable either.
9515 elsif Is_Generic_Instance
(Subp
)
9516 or else Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Declaration
9520 elsif not Comes_From_Source
(Subp
)
9521 and then Scope
(Subp
) /= Standard_Standard
9527 -- The referenced entity must either be the enclosing entity, or
9528 -- an entity declared within the current open scope.
9530 if Present
(Scope
(Subp
))
9531 and then Scope
(Subp
) /= Current_Scope
9532 and then Subp
/= Current_Scope
9535 ("argument of% must be entity in current scope", Assoc
);
9539 -- Processing for procedure, operator or function. If subprogram
9540 -- is aliased (as for an instance) indicate that the renamed
9541 -- entity (if declared in the same unit) is inlined.
9542 -- If this is the anonymous subprogram created for a subprogram
9543 -- instance, the inlining applies to it directly. Otherwise we
9544 -- retrieve it as the alias of the visible subprogram instance.
9546 if Is_Subprogram
(Subp
) then
9548 -- Ensure that pragma Inline_Always is associated with the
9549 -- initial declaration of the subprogram.
9551 Check_Inline_Always_Placement
(Subp
);
9553 if Is_Wrapper_Package
(Scope
(Subp
)) then
9556 Inner_Subp
:= Ultimate_Alias
(Inner_Subp
);
9559 if In_Same_Source_Unit
(Subp
, Inner_Subp
) then
9560 Set_Inline_Flags
(Inner_Subp
);
9562 Decl
:= Parent
(Parent
(Inner_Subp
));
9564 if Nkind
(Decl
) = N_Subprogram_Declaration
9565 and then Present
(Corresponding_Body
(Decl
))
9567 Set_Inline_Flags
(Corresponding_Body
(Decl
));
9569 elsif Is_Generic_Instance
(Subp
)
9570 and then Comes_From_Source
(Subp
)
9572 -- Indicate that the body needs to be created for
9573 -- inlining subsequent calls. The instantiation node
9574 -- follows the declaration of the wrapper package
9575 -- created for it. The subprogram that requires the
9576 -- body is the anonymous one in the wrapper package.
9578 if Scope
(Subp
) /= Standard_Standard
9580 Need_Subprogram_Instance_Body
9581 (Next
(Unit_Declaration_Node
9582 (Scope
(Alias
(Subp
)))), Subp
)
9587 -- Inline is a program unit pragma (RM 10.1.5) and cannot
9588 -- appear in a formal part to apply to a formal subprogram.
9589 -- Do not apply check within an instance or a formal package
9590 -- the test will have been applied to the original generic.
9592 elsif Nkind
(Decl
) in N_Formal_Subprogram_Declaration
9593 and then List_Containing
(Decl
) = List_Containing
(N
)
9594 and then not In_Instance
9597 ("Inline cannot apply to a formal subprogram", N
);
9599 -- If Subp is a renaming, it is the renamed entity that
9600 -- will appear in any call, and be inlined. However, for
9601 -- ASIS uses it is convenient to indicate that the renaming
9602 -- itself is an inlined subprogram, so that some gnatcheck
9603 -- rules can be applied in the absence of expansion.
9605 elsif Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
9606 Set_Inline_Flags
(Subp
);
9612 -- For a generic subprogram set flag as well, for use at the point
9613 -- of instantiation, to determine whether the body should be
9616 elsif Is_Generic_Subprogram
(Subp
) then
9617 Set_Inline_Flags
(Subp
);
9620 -- Literals are by definition inlined
9622 elsif Kind
= E_Enumeration_Literal
then
9625 -- Anything else is an error
9629 ("expect subprogram name for pragma%", Assoc
);
9633 ----------------------
9634 -- Set_Inline_Flags --
9635 ----------------------
9637 procedure Set_Inline_Flags
(Subp
: Entity_Id
) is
9639 -- First set the Has_Pragma_XXX flags and issue the appropriate
9640 -- errors and warnings for suspicious combinations.
9642 if Prag_Id
= Pragma_No_Inline
then
9643 if Has_Pragma_Inline_Always
(Subp
) then
9645 ("Inline_Always and No_Inline are mutually exclusive", N
);
9646 elsif Has_Pragma_Inline
(Subp
) then
9648 ("Inline and No_Inline both specified for& ??",
9649 N
, Entity
(Subp_Id
));
9652 Set_Has_Pragma_No_Inline
(Subp
);
9654 if Prag_Id
= Pragma_Inline_Always
then
9655 if Has_Pragma_No_Inline
(Subp
) then
9657 ("Inline_Always and No_Inline are mutually exclusive",
9661 Set_Has_Pragma_Inline_Always
(Subp
);
9663 if Has_Pragma_No_Inline
(Subp
) then
9665 ("Inline and No_Inline both specified for& ??",
9666 N
, Entity
(Subp_Id
));
9670 Set_Has_Pragma_Inline
(Subp
);
9673 -- Then adjust the Is_Inlined flag. It can never be set if the
9674 -- subprogram is subject to pragma No_Inline.
9678 Set_Is_Inlined
(Subp
, False);
9684 if not Has_Pragma_No_Inline
(Subp
) then
9685 Set_Is_Inlined
(Subp
, True);
9689 -- A pragma that applies to a Ghost entity becomes Ghost for the
9690 -- purposes of legality checks and removal of ignored Ghost code.
9692 Mark_Ghost_Pragma
(N
, Subp
);
9694 -- Capture the entity of the first Ghost subprogram being
9695 -- processed for error detection purposes.
9697 if Is_Ghost_Entity
(Subp
) then
9698 if No
(Ghost_Id
) then
9702 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
9703 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
9705 elsif Present
(Ghost_Id
) and then not Ghost_Error_Posted
then
9706 Ghost_Error_Posted
:= True;
9708 Error_Msg_Name_1
:= Pname
;
9710 ("pragma % cannot mention ghost and non-ghost subprograms",
9713 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
9714 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
9716 Error_Msg_Sloc
:= Sloc
(Subp
);
9717 Error_Msg_NE
("\& # declared as non-ghost", N
, Subp
);
9719 end Set_Inline_Flags
;
9721 -- Start of processing for Process_Inline
9724 Check_No_Identifiers
;
9725 Check_At_Least_N_Arguments
(1);
9727 if Status
= Enabled
then
9728 Inline_Processing_Required
:= True;
9732 while Present
(Assoc
) loop
9733 Subp_Id
:= Get_Pragma_Arg
(Assoc
);
9737 if Is_Entity_Name
(Subp_Id
) then
9738 Subp
:= Entity
(Subp_Id
);
9740 if Subp
= Any_Id
then
9742 -- If previous error, avoid cascaded errors
9744 Check_Error_Detected
;
9750 -- For the pragma case, climb homonym chain. This is
9751 -- what implements allowing the pragma in the renaming
9752 -- case, with the result applying to the ancestors, and
9753 -- also allows Inline to apply to all previous homonyms.
9755 if not From_Aspect_Specification
(N
) then
9756 while Present
(Homonym
(Subp
))
9757 and then Scope
(Homonym
(Subp
)) = Current_Scope
9759 Make_Inline
(Homonym
(Subp
));
9760 Subp
:= Homonym
(Subp
);
9767 Error_Pragma_Arg
("inappropriate argument for pragma%", Assoc
);
9773 -- If the context is a package declaration, the pragma indicates
9774 -- that inlining will require the presence of the corresponding
9775 -- body. (this may be further refined).
9778 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
9779 N_Package_Declaration
9781 Set_Body_Needed_For_Inlining
(Cunit_Entity
(Current_Sem_Unit
));
9785 ----------------------------
9786 -- Process_Interface_Name --
9787 ----------------------------
9789 procedure Process_Interface_Name
9790 (Subprogram_Def
: Entity_Id
;
9797 String_Val
: String_Id
;
9799 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
);
9800 -- SN is a string literal node for an interface name. This routine
9801 -- performs some minimal checks that the name is reasonable. In
9802 -- particular that no spaces or other obviously incorrect characters
9803 -- appear. This is only a warning, since any characters are allowed.
9805 ----------------------------------
9806 -- Check_Form_Of_Interface_Name --
9807 ----------------------------------
9809 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
) is
9810 S
: constant String_Id
:= Strval
(Expr_Value_S
(SN
));
9811 SL
: constant Nat
:= String_Length
(S
);
9816 Error_Msg_N
("interface name cannot be null string", SN
);
9819 for J
in 1 .. SL
loop
9820 C
:= Get_String_Char
(S
, J
);
9822 -- Look for dubious character and issue unconditional warning.
9823 -- Definitely dubious if not in character range.
9825 if not In_Character_Range
(C
)
9827 -- Commas, spaces and (back)slashes are dubious
9829 or else Get_Character
(C
) = ','
9830 or else Get_Character
(C
) = '\'
9831 or else Get_Character
(C
) = ' '
9832 or else Get_Character
(C
) = '/'
9835 ("??interface name contains illegal character",
9836 Sloc
(SN
) + Source_Ptr
(J
));
9839 end Check_Form_Of_Interface_Name
;
9841 -- Start of processing for Process_Interface_Name
9844 -- If we are looking at a pragma that comes from an aspect then it
9845 -- needs to have its corresponding aspect argument expressions
9846 -- analyzed in addition to the generated pragma so that aspects
9847 -- within generic units get properly resolved.
9849 if Present
(Prag
) and then From_Aspect_Specification
(Prag
) then
9851 Asp
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
9859 -- Obtain all interfacing aspects used to construct the pragma
9861 Get_Interfacing_Aspects
9862 (Asp
, Dummy_1
, EN
, Dummy_2
, Dummy_3
, LN
);
9864 -- Analyze the expression of aspect External_Name
9866 if Present
(EN
) then
9867 Analyze
(Expression
(EN
));
9870 -- Analyze the expressio of aspect Link_Name
9872 if Present
(LN
) then
9873 Analyze
(Expression
(LN
));
9878 if No
(Link_Arg
) then
9879 if No
(Ext_Arg
) then
9882 elsif Chars
(Ext_Arg
) = Name_Link_Name
then
9884 Link_Nam
:= Expression
(Ext_Arg
);
9887 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
9888 Ext_Nam
:= Expression
(Ext_Arg
);
9893 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
9894 Check_Optional_Identifier
(Link_Arg
, Name_Link_Name
);
9895 Ext_Nam
:= Expression
(Ext_Arg
);
9896 Link_Nam
:= Expression
(Link_Arg
);
9899 -- Check expressions for external name and link name are static
9901 if Present
(Ext_Nam
) then
9902 Check_Arg_Is_OK_Static_Expression
(Ext_Nam
, Standard_String
);
9903 Check_Form_Of_Interface_Name
(Ext_Nam
);
9905 -- Verify that external name is not the name of a local entity,
9906 -- which would hide the imported one and could lead to run-time
9907 -- surprises. The problem can only arise for entities declared in
9908 -- a package body (otherwise the external name is fully qualified
9909 -- and will not conflict).
9917 if Prag_Id
= Pragma_Import
then
9918 Nam
:= String_To_Name
(Strval
(Expr_Value_S
(Ext_Nam
)));
9919 E
:= Entity_Id
(Get_Name_Table_Int
(Nam
));
9921 if Nam
/= Chars
(Subprogram_Def
)
9922 and then Present
(E
)
9923 and then not Is_Overloadable
(E
)
9924 and then Is_Immediately_Visible
(E
)
9925 and then not Is_Imported
(E
)
9926 and then Ekind
(Scope
(E
)) = E_Package
9929 while Present
(Par
) loop
9930 if Nkind
(Par
) = N_Package_Body
then
9931 Error_Msg_Sloc
:= Sloc
(E
);
9933 ("imported entity is hidden by & declared#",
9938 Par
:= Parent
(Par
);
9945 if Present
(Link_Nam
) then
9946 Check_Arg_Is_OK_Static_Expression
(Link_Nam
, Standard_String
);
9947 Check_Form_Of_Interface_Name
(Link_Nam
);
9950 -- If there is no link name, just set the external name
9952 if No
(Link_Nam
) then
9953 Link_Nam
:= Adjust_External_Name_Case
(Expr_Value_S
(Ext_Nam
));
9955 -- For the Link_Name case, the given literal is preceded by an
9956 -- asterisk, which indicates to GCC that the given name should be
9957 -- taken literally, and in particular that no prepending of
9958 -- underlines should occur, even in systems where this is the
9963 Store_String_Char
(Get_Char_Code
('*'));
9964 String_Val
:= Strval
(Expr_Value_S
(Link_Nam
));
9965 Store_String_Chars
(String_Val
);
9967 Make_String_Literal
(Sloc
(Link_Nam
),
9968 Strval
=> End_String
);
9971 -- Set the interface name. If the entity is a generic instance, use
9972 -- its alias, which is the callable entity.
9974 if Is_Generic_Instance
(Subprogram_Def
) then
9975 Set_Encoded_Interface_Name
9976 (Alias
(Get_Base_Subprogram
(Subprogram_Def
)), Link_Nam
);
9978 Set_Encoded_Interface_Name
9979 (Get_Base_Subprogram
(Subprogram_Def
), Link_Nam
);
9982 Check_Duplicated_Export_Name
(Link_Nam
);
9983 end Process_Interface_Name
;
9985 -----------------------------------------
9986 -- Process_Interrupt_Or_Attach_Handler --
9987 -----------------------------------------
9989 procedure Process_Interrupt_Or_Attach_Handler
is
9990 Handler
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
9991 Prot_Typ
: constant Entity_Id
:= Scope
(Handler
);
9994 -- A pragma that applies to a Ghost entity becomes Ghost for the
9995 -- purposes of legality checks and removal of ignored Ghost code.
9997 Mark_Ghost_Pragma
(N
, Handler
);
9998 Set_Is_Interrupt_Handler
(Handler
);
10000 pragma Assert
(Ekind
(Prot_Typ
) = E_Protected_Type
);
10002 Record_Rep_Item
(Prot_Typ
, N
);
10004 -- Chain the pragma on the contract for completeness
10006 Add_Contract_Item
(N
, Handler
);
10007 end Process_Interrupt_Or_Attach_Handler
;
10009 --------------------------------------------------
10010 -- Process_Restrictions_Or_Restriction_Warnings --
10011 --------------------------------------------------
10013 -- Note: some of the simple identifier cases were handled in par-prag,
10014 -- but it is harmless (and more straightforward) to simply handle all
10015 -- cases here, even if it means we repeat a bit of work in some cases.
10017 procedure Process_Restrictions_Or_Restriction_Warnings
10021 R_Id
: Restriction_Id
;
10027 -- Ignore all Restrictions pragmas in CodePeer mode
10029 if CodePeer_Mode
then
10033 Check_Ada_83_Warning
;
10034 Check_At_Least_N_Arguments
(1);
10035 Check_Valid_Configuration_Pragma
;
10038 while Present
(Arg
) loop
10040 Expr
:= Get_Pragma_Arg
(Arg
);
10042 -- Case of no restriction identifier present
10044 if Id
= No_Name
then
10045 if Nkind
(Expr
) /= N_Identifier
then
10047 ("invalid form for restriction", Arg
);
10052 (Process_Restriction_Synonyms
(Expr
));
10054 if R_Id
not in All_Boolean_Restrictions
then
10055 Error_Msg_Name_1
:= Pname
;
10057 ("invalid restriction identifier&", Get_Pragma_Arg
(Arg
));
10059 -- Check for possible misspelling
10061 for J
in Restriction_Id
loop
10063 Rnm
: constant String := Restriction_Id
'Image (J
);
10066 Name_Buffer
(1 .. Rnm
'Length) := Rnm
;
10067 Name_Len
:= Rnm
'Length;
10068 Set_Casing
(All_Lower_Case
);
10070 if Is_Bad_Spelling_Of
(Chars
(Expr
), Name_Enter
) then
10073 (Source_Index
(Current_Sem_Unit
)));
10074 Error_Msg_String
(1 .. Rnm
'Length) :=
10075 Name_Buffer
(1 .. Name_Len
);
10076 Error_Msg_Strlen
:= Rnm
'Length;
10077 Error_Msg_N
-- CODEFIX
10078 ("\possible misspelling of ""~""",
10079 Get_Pragma_Arg
(Arg
));
10088 if Implementation_Restriction
(R_Id
) then
10089 Check_Restriction
(No_Implementation_Restrictions
, Arg
);
10092 -- Special processing for No_Elaboration_Code restriction
10094 if R_Id
= No_Elaboration_Code
then
10096 -- Restriction is only recognized within a configuration
10097 -- pragma file, or within a unit of the main extended
10098 -- program. Note: the test for Main_Unit is needed to
10099 -- properly include the case of configuration pragma files.
10101 if not (Current_Sem_Unit
= Main_Unit
10102 or else In_Extended_Main_Source_Unit
(N
))
10106 -- Don't allow in a subunit unless already specified in
10109 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
10110 and then Nkind
(Unit
(Parent
(N
))) = N_Subunit
10111 and then not Restriction_Active
(No_Elaboration_Code
)
10114 ("invalid specification of ""No_Elaboration_Code""",
10117 ("\restriction cannot be specified in a subunit", N
);
10119 ("\unless also specified in body or spec", N
);
10122 -- If we accept a No_Elaboration_Code restriction, then it
10123 -- needs to be added to the configuration restriction set so
10124 -- that we get proper application to other units in the main
10125 -- extended source as required.
10128 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
10132 -- If this is a warning, then set the warning unless we already
10133 -- have a real restriction active (we never want a warning to
10134 -- override a real restriction).
10137 if not Restriction_Active
(R_Id
) then
10138 Set_Restriction
(R_Id
, N
);
10139 Restriction_Warnings
(R_Id
) := True;
10142 -- If real restriction case, then set it and make sure that the
10143 -- restriction warning flag is off, since a real restriction
10144 -- always overrides a warning.
10147 Set_Restriction
(R_Id
, N
);
10148 Restriction_Warnings
(R_Id
) := False;
10151 -- Check for obsolescent restrictions in Ada 2005 mode
10154 and then Ada_Version
>= Ada_2005
10155 and then (R_Id
= No_Asynchronous_Control
10157 R_Id
= No_Unchecked_Deallocation
10159 R_Id
= No_Unchecked_Conversion
)
10161 Check_Restriction
(No_Obsolescent_Features
, N
);
10164 -- A very special case that must be processed here: pragma
10165 -- Restrictions (No_Exceptions) turns off all run-time
10166 -- checking. This is a bit dubious in terms of the formal
10167 -- language definition, but it is what is intended by RM
10168 -- H.4(12). Restriction_Warnings never affects generated code
10169 -- so this is done only in the real restriction case.
10171 -- Atomic_Synchronization is not a real check, so it is not
10172 -- affected by this processing).
10174 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
10175 -- run-time checks in CodePeer and GNATprove modes: we want to
10176 -- generate checks for analysis purposes, as set respectively
10177 -- by -gnatC and -gnatd.F
10180 and then not (CodePeer_Mode
or GNATprove_Mode
)
10181 and then R_Id
= No_Exceptions
10183 for J
in Scope_Suppress
.Suppress
'Range loop
10184 if J
/= Atomic_Synchronization
then
10185 Scope_Suppress
.Suppress
(J
) := True;
10190 -- Case of No_Dependence => unit-name. Note that the parser
10191 -- already made the necessary entry in the No_Dependence table.
10193 elsif Id
= Name_No_Dependence
then
10194 if not OK_No_Dependence_Unit_Name
(Expr
) then
10198 -- Case of No_Specification_Of_Aspect => aspect-identifier
10200 elsif Id
= Name_No_Specification_Of_Aspect
then
10205 if Nkind
(Expr
) /= N_Identifier
then
10208 A_Id
:= Get_Aspect_Id
(Chars
(Expr
));
10211 if A_Id
= No_Aspect
then
10212 Error_Pragma_Arg
("invalid restriction name", Arg
);
10214 Set_Restriction_No_Specification_Of_Aspect
(Expr
, Warn
);
10218 -- Case of No_Use_Of_Attribute => attribute-identifier
10220 elsif Id
= Name_No_Use_Of_Attribute
then
10221 if Nkind
(Expr
) /= N_Identifier
10222 or else not Is_Attribute_Name
(Chars
(Expr
))
10224 Error_Msg_N
("unknown attribute name??", Expr
);
10227 Set_Restriction_No_Use_Of_Attribute
(Expr
, Warn
);
10230 -- Case of No_Use_Of_Entity => fully-qualified-name
10232 elsif Id
= Name_No_Use_Of_Entity
then
10234 -- Restriction is only recognized within a configuration
10235 -- pragma file, or within a unit of the main extended
10236 -- program. Note: the test for Main_Unit is needed to
10237 -- properly include the case of configuration pragma files.
10239 if Current_Sem_Unit
= Main_Unit
10240 or else In_Extended_Main_Source_Unit
(N
)
10242 if not OK_No_Dependence_Unit_Name
(Expr
) then
10243 Error_Msg_N
("wrong form for entity name", Expr
);
10245 Set_Restriction_No_Use_Of_Entity
10246 (Expr
, Warn
, No_Profile
);
10250 -- Case of No_Use_Of_Pragma => pragma-identifier
10252 elsif Id
= Name_No_Use_Of_Pragma
then
10253 if Nkind
(Expr
) /= N_Identifier
10254 or else not Is_Pragma_Name
(Chars
(Expr
))
10256 Error_Msg_N
("unknown pragma name??", Expr
);
10258 Set_Restriction_No_Use_Of_Pragma
(Expr
, Warn
);
10261 -- All other cases of restriction identifier present
10264 R_Id
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(Arg
));
10265 Analyze_And_Resolve
(Expr
, Any_Integer
);
10267 if R_Id
not in All_Parameter_Restrictions
then
10269 ("invalid restriction parameter identifier", Arg
);
10271 elsif not Is_OK_Static_Expression
(Expr
) then
10272 Flag_Non_Static_Expr
10273 ("value must be static expression!", Expr
);
10276 elsif not Is_Integer_Type
(Etype
(Expr
))
10277 or else Expr_Value
(Expr
) < 0
10280 ("value must be non-negative integer", Arg
);
10283 -- Restriction pragma is active
10285 Val
:= Expr_Value
(Expr
);
10287 if not UI_Is_In_Int_Range
(Val
) then
10289 ("pragma ignored, value too large??", Arg
);
10292 -- Warning case. If the real restriction is active, then we
10293 -- ignore the request, since warning never overrides a real
10294 -- restriction. Otherwise we set the proper warning. Note that
10295 -- this circuit sets the warning again if it is already set,
10296 -- which is what we want, since the constant may have changed.
10299 if not Restriction_Active
(R_Id
) then
10301 (R_Id
, N
, Integer (UI_To_Int
(Val
)));
10302 Restriction_Warnings
(R_Id
) := True;
10305 -- Real restriction case, set restriction and make sure warning
10306 -- flag is off since real restriction always overrides warning.
10309 Set_Restriction
(R_Id
, N
, Integer (UI_To_Int
(Val
)));
10310 Restriction_Warnings
(R_Id
) := False;
10316 end Process_Restrictions_Or_Restriction_Warnings
;
10318 ---------------------------------
10319 -- Process_Suppress_Unsuppress --
10320 ---------------------------------
10322 -- Note: this procedure makes entries in the check suppress data
10323 -- structures managed by Sem. See spec of package Sem for full
10324 -- details on how we handle recording of check suppression.
10326 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean) is
10331 In_Package_Spec
: constant Boolean :=
10332 Is_Package_Or_Generic_Package
(Current_Scope
)
10333 and then not In_Package_Body
(Current_Scope
);
10335 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
);
10336 -- Used to suppress a single check on the given entity
10338 --------------------------------
10339 -- Suppress_Unsuppress_Echeck --
10340 --------------------------------
10342 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
) is
10344 -- Check for error of trying to set atomic synchronization for
10345 -- a non-atomic variable.
10347 if C
= Atomic_Synchronization
10348 and then not (Is_Atomic
(E
) or else Has_Atomic_Components
(E
))
10351 ("pragma & requires atomic type or variable",
10352 Pragma_Identifier
(Original_Node
(N
)));
10355 Set_Checks_May_Be_Suppressed
(E
);
10357 if In_Package_Spec
then
10358 Push_Global_Suppress_Stack_Entry
10361 Suppress
=> Suppress_Case
);
10363 Push_Local_Suppress_Stack_Entry
10366 Suppress
=> Suppress_Case
);
10369 -- If this is a first subtype, and the base type is distinct,
10370 -- then also set the suppress flags on the base type.
10372 if Is_First_Subtype
(E
) and then Etype
(E
) /= E
then
10373 Suppress_Unsuppress_Echeck
(Etype
(E
), C
);
10375 end Suppress_Unsuppress_Echeck
;
10377 -- Start of processing for Process_Suppress_Unsuppress
10380 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
10381 -- on user code: we want to generate checks for analysis purposes, as
10382 -- set respectively by -gnatC and -gnatd.F
10384 if Comes_From_Source
(N
)
10385 and then (CodePeer_Mode
or GNATprove_Mode
)
10390 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
10391 -- declarative part or a package spec (RM 11.5(5)).
10393 if not Is_Configuration_Pragma
then
10394 Check_Is_In_Decl_Part_Or_Package_Spec
;
10397 Check_At_Least_N_Arguments
(1);
10398 Check_At_Most_N_Arguments
(2);
10399 Check_No_Identifier
(Arg1
);
10400 Check_Arg_Is_Identifier
(Arg1
);
10402 C
:= Get_Check_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
10404 if C
= No_Check_Id
then
10406 ("argument of pragma% is not valid check name", Arg1
);
10409 -- Warn that suppress of Elaboration_Check has no effect in SPARK
10411 if C
= Elaboration_Check
and then SPARK_Mode
= On
then
10413 ("Suppress of Elaboration_Check ignored in SPARK??",
10414 "\elaboration checking rules are statically enforced "
10415 & "(SPARK RM 7.7)", Arg1
);
10418 -- One-argument case
10420 if Arg_Count
= 1 then
10422 -- Make an entry in the local scope suppress table. This is the
10423 -- table that directly shows the current value of the scope
10424 -- suppress check for any check id value.
10426 if C
= All_Checks
then
10428 -- For All_Checks, we set all specific predefined checks with
10429 -- the exception of Elaboration_Check, which is handled
10430 -- specially because of not wanting All_Checks to have the
10431 -- effect of deactivating static elaboration order processing.
10432 -- Atomic_Synchronization is also not affected, since this is
10433 -- not a real check.
10435 for J
in Scope_Suppress
.Suppress
'Range loop
10436 if J
/= Elaboration_Check
10438 J
/= Atomic_Synchronization
10440 Scope_Suppress
.Suppress
(J
) := Suppress_Case
;
10444 -- If not All_Checks, and predefined check, then set appropriate
10445 -- scope entry. Note that we will set Elaboration_Check if this
10446 -- is explicitly specified. Atomic_Synchronization is allowed
10447 -- only if internally generated and entity is atomic.
10449 elsif C
in Predefined_Check_Id
10450 and then (not Comes_From_Source
(N
)
10451 or else C
/= Atomic_Synchronization
)
10453 Scope_Suppress
.Suppress
(C
) := Suppress_Case
;
10456 -- Also make an entry in the Local_Entity_Suppress table
10458 Push_Local_Suppress_Stack_Entry
10461 Suppress
=> Suppress_Case
);
10463 -- Case of two arguments present, where the check is suppressed for
10464 -- a specified entity (given as the second argument of the pragma)
10467 -- This is obsolescent in Ada 2005 mode
10469 if Ada_Version
>= Ada_2005
then
10470 Check_Restriction
(No_Obsolescent_Features
, Arg2
);
10473 Check_Optional_Identifier
(Arg2
, Name_On
);
10474 E_Id
:= Get_Pragma_Arg
(Arg2
);
10477 if not Is_Entity_Name
(E_Id
) then
10479 ("second argument of pragma% must be entity name", Arg2
);
10482 E
:= Entity
(E_Id
);
10488 -- A pragma that applies to a Ghost entity becomes Ghost for the
10489 -- purposes of legality checks and removal of ignored Ghost code.
10491 Mark_Ghost_Pragma
(N
, E
);
10493 -- Enforce RM 11.5(7) which requires that for a pragma that
10494 -- appears within a package spec, the named entity must be
10495 -- within the package spec. We allow the package name itself
10496 -- to be mentioned since that makes sense, although it is not
10497 -- strictly allowed by 11.5(7).
10500 and then E
/= Current_Scope
10501 and then Scope
(E
) /= Current_Scope
10504 ("entity in pragma% is not in package spec (RM 11.5(7))",
10508 -- Loop through homonyms. As noted below, in the case of a package
10509 -- spec, only homonyms within the package spec are considered.
10512 Suppress_Unsuppress_Echeck
(E
, C
);
10514 if Is_Generic_Instance
(E
)
10515 and then Is_Subprogram
(E
)
10516 and then Present
(Alias
(E
))
10518 Suppress_Unsuppress_Echeck
(Alias
(E
), C
);
10521 -- Move to next homonym if not aspect spec case
10523 exit when From_Aspect_Specification
(N
);
10527 -- If we are within a package specification, the pragma only
10528 -- applies to homonyms in the same scope.
10530 exit when In_Package_Spec
10531 and then Scope
(E
) /= Current_Scope
;
10534 end Process_Suppress_Unsuppress
;
10536 -------------------------------
10537 -- Record_Independence_Check --
10538 -------------------------------
10540 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
) is
10541 pragma Unreferenced
(N
, E
);
10543 -- For GCC back ends the validation is done a priori
10544 -- ??? This code is dead, might be useful in the future
10546 -- if not AAMP_On_Target then
10550 -- Independence_Checks.Append ((N, E));
10553 end Record_Independence_Check
;
10559 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
) is
10561 if Is_Imported
(E
) then
10563 ("cannot export entity& that was previously imported", Arg
);
10565 elsif Present
(Address_Clause
(E
))
10566 and then not Relaxed_RM_Semantics
10569 ("cannot export entity& that has an address clause", Arg
);
10572 Set_Is_Exported
(E
);
10574 -- Generate a reference for entity explicitly, because the
10575 -- identifier may be overloaded and name resolution will not
10578 Generate_Reference
(E
, Arg
);
10580 -- Deal with exporting non-library level entity
10582 if not Is_Library_Level_Entity
(E
) then
10584 -- Not allowed at all for subprograms
10586 if Is_Subprogram
(E
) then
10587 Error_Pragma_Arg
("local subprogram& cannot be exported", Arg
);
10589 -- Otherwise set public and statically allocated
10593 Set_Is_Statically_Allocated
(E
);
10595 -- Warn if the corresponding W flag is set
10597 if Warn_On_Export_Import
10599 -- Only do this for something that was in the source. Not
10600 -- clear if this can be False now (there used for sure to be
10601 -- cases on some systems where it was False), but anyway the
10602 -- test is harmless if not needed, so it is retained.
10604 and then Comes_From_Source
(Arg
)
10607 ("?x?& has been made static as a result of Export",
10610 ("\?x?this usage is non-standard and non-portable",
10616 if Warn_On_Export_Import
and then Is_Type
(E
) then
10617 Error_Msg_NE
("exporting a type has no effect?x?", Arg
, E
);
10620 if Warn_On_Export_Import
and Inside_A_Generic
then
10622 ("all instances of& will have the same external name?x?",
10627 ----------------------------------------------
10628 -- Set_Extended_Import_Export_External_Name --
10629 ----------------------------------------------
10631 procedure Set_Extended_Import_Export_External_Name
10632 (Internal_Ent
: Entity_Id
;
10633 Arg_External
: Node_Id
)
10635 Old_Name
: constant Node_Id
:= Interface_Name
(Internal_Ent
);
10636 New_Name
: Node_Id
;
10639 if No
(Arg_External
) then
10643 Check_Arg_Is_External_Name
(Arg_External
);
10645 if Nkind
(Arg_External
) = N_String_Literal
then
10646 if String_Length
(Strval
(Arg_External
)) = 0 then
10649 New_Name
:= Adjust_External_Name_Case
(Arg_External
);
10652 elsif Nkind
(Arg_External
) = N_Identifier
then
10653 New_Name
:= Get_Default_External_Name
(Arg_External
);
10655 -- Check_Arg_Is_External_Name should let through only identifiers and
10656 -- string literals or static string expressions (which are folded to
10657 -- string literals).
10660 raise Program_Error
;
10663 -- If we already have an external name set (by a prior normal Import
10664 -- or Export pragma), then the external names must match
10666 if Present
(Interface_Name
(Internal_Ent
)) then
10668 -- Ignore mismatching names in CodePeer mode, to support some
10669 -- old compilers which would export the same procedure under
10670 -- different names, e.g:
10672 -- pragma Export_Procedure (P, "a");
10673 -- pragma Export_Procedure (P, "b");
10675 if CodePeer_Mode
then
10679 Check_Matching_Internal_Names
: declare
10680 S1
: constant String_Id
:= Strval
(Old_Name
);
10681 S2
: constant String_Id
:= Strval
(New_Name
);
10683 procedure Mismatch
;
10684 pragma No_Return
(Mismatch
);
10685 -- Called if names do not match
10691 procedure Mismatch
is
10693 Error_Msg_Sloc
:= Sloc
(Old_Name
);
10695 ("external name does not match that given #",
10699 -- Start of processing for Check_Matching_Internal_Names
10702 if String_Length
(S1
) /= String_Length
(S2
) then
10706 for J
in 1 .. String_Length
(S1
) loop
10707 if Get_String_Char
(S1
, J
) /= Get_String_Char
(S2
, J
) then
10712 end Check_Matching_Internal_Names
;
10714 -- Otherwise set the given name
10717 Set_Encoded_Interface_Name
(Internal_Ent
, New_Name
);
10718 Check_Duplicated_Export_Name
(New_Name
);
10720 end Set_Extended_Import_Export_External_Name
;
10726 procedure Set_Imported
(E
: Entity_Id
) is
10728 -- Error message if already imported or exported
10730 if Is_Exported
(E
) or else Is_Imported
(E
) then
10732 -- Error if being set Exported twice
10734 if Is_Exported
(E
) then
10735 Error_Msg_NE
("entity& was previously exported", N
, E
);
10737 -- Ignore error in CodePeer mode where we treat all imported
10738 -- subprograms as unknown.
10740 elsif CodePeer_Mode
then
10743 -- OK if Import/Interface case
10745 elsif Import_Interface_Present
(N
) then
10748 -- Error if being set Imported twice
10751 Error_Msg_NE
("entity& was previously imported", N
, E
);
10754 Error_Msg_Name_1
:= Pname
;
10756 ("\(pragma% applies to all previous entities)", N
);
10758 Error_Msg_Sloc
:= Sloc
(E
);
10759 Error_Msg_NE
("\import not allowed for& declared#", N
, E
);
10761 -- Here if not previously imported or exported, OK to import
10764 Set_Is_Imported
(E
);
10766 -- For subprogram, set Import_Pragma field
10768 if Is_Subprogram
(E
) then
10769 Set_Import_Pragma
(E
, N
);
10772 -- If the entity is an object that is not at the library level,
10773 -- then it is statically allocated. We do not worry about objects
10774 -- with address clauses in this context since they are not really
10775 -- imported in the linker sense.
10778 and then not Is_Library_Level_Entity
(E
)
10779 and then No
(Address_Clause
(E
))
10781 Set_Is_Statically_Allocated
(E
);
10788 -------------------------
10789 -- Set_Mechanism_Value --
10790 -------------------------
10792 -- Note: the mechanism name has not been analyzed (and cannot indeed be
10793 -- analyzed, since it is semantic nonsense), so we get it in the exact
10794 -- form created by the parser.
10796 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
) is
10797 procedure Bad_Mechanism
;
10798 pragma No_Return
(Bad_Mechanism
);
10799 -- Signal bad mechanism name
10801 -------------------------
10802 -- Bad_Mechanism_Value --
10803 -------------------------
10805 procedure Bad_Mechanism
is
10807 Error_Pragma_Arg
("unrecognized mechanism name", Mech_Name
);
10810 -- Start of processing for Set_Mechanism_Value
10813 if Mechanism
(Ent
) /= Default_Mechanism
then
10815 ("mechanism for & has already been set", Mech_Name
, Ent
);
10818 -- MECHANISM_NAME ::= value | reference
10820 if Nkind
(Mech_Name
) = N_Identifier
then
10821 if Chars
(Mech_Name
) = Name_Value
then
10822 Set_Mechanism
(Ent
, By_Copy
);
10825 elsif Chars
(Mech_Name
) = Name_Reference
then
10826 Set_Mechanism
(Ent
, By_Reference
);
10829 elsif Chars
(Mech_Name
) = Name_Copy
then
10831 ("bad mechanism name, Value assumed", Mech_Name
);
10840 end Set_Mechanism_Value
;
10842 --------------------------
10843 -- Set_Rational_Profile --
10844 --------------------------
10846 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
10847 -- extension to the semantics of renaming declarations.
10849 procedure Set_Rational_Profile
is
10851 Implicit_Packing
:= True;
10852 Overriding_Renamings
:= True;
10853 Use_VADS_Size
:= True;
10854 end Set_Rational_Profile
;
10856 ---------------------------
10857 -- Set_Ravenscar_Profile --
10858 ---------------------------
10860 -- The tasks to be done here are
10862 -- Set required policies
10864 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10865 -- (For Ravenscar and GNAT_Extended_Ravenscar profiles)
10866 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10867 -- (For GNAT_Ravenscar_EDF profile)
10868 -- pragma Locking_Policy (Ceiling_Locking)
10870 -- Set Detect_Blocking mode
10872 -- Set required restrictions (see System.Rident for detailed list)
10874 -- Set the No_Dependence rules
10875 -- No_Dependence => Ada.Asynchronous_Task_Control
10876 -- No_Dependence => Ada.Calendar
10877 -- No_Dependence => Ada.Execution_Time.Group_Budget
10878 -- No_Dependence => Ada.Execution_Time.Timers
10879 -- No_Dependence => Ada.Task_Attributes
10880 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10882 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
) is
10883 procedure Set_Error_Msg_To_Profile_Name
;
10884 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
10887 -----------------------------------
10888 -- Set_Error_Msg_To_Profile_Name --
10889 -----------------------------------
10891 procedure Set_Error_Msg_To_Profile_Name
is
10892 Prof_Nam
: constant Node_Id
:=
10894 (First
(Pragma_Argument_Associations
(N
)));
10897 Get_Name_String
(Chars
(Prof_Nam
));
10898 Adjust_Name_Case
(Global_Name_Buffer
, Sloc
(Prof_Nam
));
10899 Error_Msg_Strlen
:= Name_Len
;
10900 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
10901 end Set_Error_Msg_To_Profile_Name
;
10910 Profile_Dispatching_Policy
: Character;
10912 -- Start of processing for Set_Ravenscar_Profile
10915 -- pragma Task_Dispatching_Policy (EDF_Across_Priorities)
10917 if Profile
= GNAT_Ravenscar_EDF
then
10918 Profile_Dispatching_Policy
:= 'E';
10920 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
10923 Profile_Dispatching_Policy
:= 'F';
10926 if Task_Dispatching_Policy
/= ' '
10927 and then Task_Dispatching_Policy
/= Profile_Dispatching_Policy
10929 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
10930 Set_Error_Msg_To_Profile_Name
;
10931 Error_Pragma
("Profile (~) incompatible with policy#");
10933 -- Set the FIFO_Within_Priorities policy, but always preserve
10934 -- System_Location since we like the error message with the run time
10938 Task_Dispatching_Policy
:= Profile_Dispatching_Policy
;
10940 if Task_Dispatching_Policy_Sloc
/= System_Location
then
10941 Task_Dispatching_Policy_Sloc
:= Loc
;
10945 -- pragma Locking_Policy (Ceiling_Locking)
10947 if Locking_Policy
/= ' '
10948 and then Locking_Policy
/= 'C'
10950 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
10951 Set_Error_Msg_To_Profile_Name
;
10952 Error_Pragma
("Profile (~) incompatible with policy#");
10954 -- Set the Ceiling_Locking policy, but preserve System_Location since
10955 -- we like the error message with the run time name.
10958 Locking_Policy
:= 'C';
10960 if Locking_Policy_Sloc
/= System_Location
then
10961 Locking_Policy_Sloc
:= Loc
;
10965 -- pragma Detect_Blocking
10967 Detect_Blocking
:= True;
10969 -- Set the corresponding restrictions
10971 Set_Profile_Restrictions
10972 (Profile
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
10974 -- Set the No_Dependence restrictions
10976 -- The following No_Dependence restrictions:
10977 -- No_Dependence => Ada.Asynchronous_Task_Control
10978 -- No_Dependence => Ada.Calendar
10979 -- No_Dependence => Ada.Task_Attributes
10980 -- are already set by previous call to Set_Profile_Restrictions.
10982 -- Set the following restrictions which were added to Ada 2005:
10983 -- No_Dependence => Ada.Execution_Time.Group_Budget
10984 -- No_Dependence => Ada.Execution_Time.Timers
10986 if Ada_Version
>= Ada_2005
then
10987 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
("ada"));
10988 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("execution_time"));
10991 Make_Selected_Component
10994 Selector_Name
=> Sel_Id
);
10996 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("group_budgets"));
10999 Make_Selected_Component
11002 Selector_Name
=> Sel_Id
);
11004 Set_Restriction_No_Dependence
11006 Warn
=> Treat_Restrictions_As_Warnings
,
11007 Profile
=> Ravenscar
);
11009 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("timers"));
11012 Make_Selected_Component
11015 Selector_Name
=> Sel_Id
);
11017 Set_Restriction_No_Dependence
11019 Warn
=> Treat_Restrictions_As_Warnings
,
11020 Profile
=> Ravenscar
);
11023 -- Set the following restriction which was added to Ada 2012 (see
11025 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
11027 if Ada_Version
>= Ada_2012
then
11028 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
("system"));
11029 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("multiprocessors"));
11032 Make_Selected_Component
11035 Selector_Name
=> Sel_Id
);
11037 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
("dispatching_domains"));
11040 Make_Selected_Component
11043 Selector_Name
=> Sel_Id
);
11045 Set_Restriction_No_Dependence
11047 Warn
=> Treat_Restrictions_As_Warnings
,
11048 Profile
=> Ravenscar
);
11050 end Set_Ravenscar_Profile
;
11052 -- Start of processing for Analyze_Pragma
11055 -- The following code is a defense against recursion. Not clear that
11056 -- this can happen legitimately, but perhaps some error situations can
11057 -- cause it, and we did see this recursion during testing.
11059 if Analyzed
(N
) then
11065 Check_Restriction_No_Use_Of_Pragma
(N
);
11067 -- Ignore pragma if Ignore_Pragma applies. Also ignore pragma
11068 -- Default_Scalar_Storage_Order if the -gnatI switch was given.
11070 if Should_Ignore_Pragma_Sem
(N
)
11071 or else (Prag_Id
= Pragma_Default_Scalar_Storage_Order
11072 and then Ignore_Rep_Clauses
)
11077 -- Deal with unrecognized pragma
11079 if not Is_Pragma_Name
(Pname
) then
11080 if Warn_On_Unrecognized_Pragma
then
11081 Error_Msg_Name_1
:= Pname
;
11082 Error_Msg_N
("?g?unrecognized pragma%!", Pragma_Identifier
(N
));
11084 for PN
in First_Pragma_Name
.. Last_Pragma_Name
loop
11085 if Is_Bad_Spelling_Of
(Pname
, PN
) then
11086 Error_Msg_Name_1
:= PN
;
11087 Error_Msg_N
-- CODEFIX
11088 ("\?g?possible misspelling of %!", Pragma_Identifier
(N
));
11097 -- Here to start processing for recognized pragma
11099 Pname
:= Original_Aspect_Pragma_Name
(N
);
11101 -- Capture setting of Opt.Uneval_Old
11103 case Opt
.Uneval_Old
is
11105 Set_Uneval_Old_Accept
(N
);
11111 Set_Uneval_Old_Warn
(N
);
11114 raise Program_Error
;
11117 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
11118 -- is already set, indicating that we have already checked the policy
11119 -- at the right point. This happens for example in the case of a pragma
11120 -- that is derived from an Aspect.
11122 if Is_Ignored
(N
) or else Is_Checked
(N
) then
11125 -- For a pragma that is a rewriting of another pragma, copy the
11126 -- Is_Checked/Is_Ignored status from the rewritten pragma.
11128 elsif Is_Rewrite_Substitution
(N
)
11129 and then Nkind
(Original_Node
(N
)) = N_Pragma
11130 and then Original_Node
(N
) /= N
11132 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
11133 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
11135 -- Otherwise query the applicable policy at this point
11138 Check_Applicable_Policy
(N
);
11140 -- If pragma is disabled, rewrite as NULL and skip analysis
11142 if Is_Disabled
(N
) then
11143 Rewrite
(N
, Make_Null_Statement
(Loc
));
11149 -- Preset arguments
11157 if Present
(Pragma_Argument_Associations
(N
)) then
11158 Arg_Count
:= List_Length
(Pragma_Argument_Associations
(N
));
11159 Arg1
:= First
(Pragma_Argument_Associations
(N
));
11161 if Present
(Arg1
) then
11162 Arg2
:= Next
(Arg1
);
11164 if Present
(Arg2
) then
11165 Arg3
:= Next
(Arg2
);
11167 if Present
(Arg3
) then
11168 Arg4
:= Next
(Arg3
);
11174 -- An enumeration type defines the pragmas that are supported by the
11175 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
11176 -- into the corresponding enumeration value for the following case.
11184 -- pragma Abort_Defer;
11186 when Pragma_Abort_Defer
=>
11188 Check_Arg_Count
(0);
11190 -- The only required semantic processing is to check the
11191 -- placement. This pragma must appear at the start of the
11192 -- statement sequence of a handled sequence of statements.
11194 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
11195 or else N
/= First
(Statements
(Parent
(N
)))
11200 --------------------
11201 -- Abstract_State --
11202 --------------------
11204 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
11206 -- ABSTRACT_STATE_LIST ::=
11208 -- | STATE_NAME_WITH_OPTIONS
11209 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
11211 -- STATE_NAME_WITH_OPTIONS ::=
11213 -- | (STATE_NAME with OPTION_LIST)
11215 -- OPTION_LIST ::= OPTION {, OPTION}
11219 -- | NAME_VALUE_OPTION
11221 -- SIMPLE_OPTION ::= Ghost | Synchronous
11223 -- NAME_VALUE_OPTION ::=
11224 -- Part_Of => ABSTRACT_STATE
11225 -- | External [=> EXTERNAL_PROPERTY_LIST]
11227 -- EXTERNAL_PROPERTY_LIST ::=
11228 -- EXTERNAL_PROPERTY
11229 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
11231 -- EXTERNAL_PROPERTY ::=
11232 -- Async_Readers [=> boolean_EXPRESSION]
11233 -- | Async_Writers [=> boolean_EXPRESSION]
11234 -- | Effective_Reads [=> boolean_EXPRESSION]
11235 -- | Effective_Writes [=> boolean_EXPRESSION]
11236 -- others => boolean_EXPRESSION
11238 -- STATE_NAME ::= defining_identifier
11240 -- ABSTRACT_STATE ::= name
11242 -- Characteristics:
11244 -- * Analysis - The annotation is fully analyzed immediately upon
11245 -- elaboration as it cannot forward reference entities.
11247 -- * Expansion - None.
11249 -- * Template - The annotation utilizes the generic template of the
11250 -- related package declaration.
11252 -- * Globals - The annotation cannot reference global entities.
11254 -- * Instance - The annotation is instantiated automatically when
11255 -- the related generic package is instantiated.
11257 when Pragma_Abstract_State
=> Abstract_State
: declare
11258 Missing_Parentheses
: Boolean := False;
11259 -- Flag set when a state declaration with options is not properly
11262 -- Flags used to verify the consistency of states
11264 Non_Null_Seen
: Boolean := False;
11265 Null_Seen
: Boolean := False;
11267 procedure Analyze_Abstract_State
11269 Pack_Id
: Entity_Id
);
11270 -- Verify the legality of a single state declaration. Create and
11271 -- decorate a state abstraction entity and introduce it into the
11272 -- visibility chain. Pack_Id denotes the entity or the related
11273 -- package where pragma Abstract_State appears.
11275 procedure Malformed_State_Error
(State
: Node_Id
);
11276 -- Emit an error concerning the illegal declaration of abstract
11277 -- state State. This routine diagnoses syntax errors that lead to
11278 -- a different parse tree. The error is issued regardless of the
11279 -- SPARK mode in effect.
11281 ----------------------------
11282 -- Analyze_Abstract_State --
11283 ----------------------------
11285 procedure Analyze_Abstract_State
11287 Pack_Id
: Entity_Id
)
11289 -- Flags used to verify the consistency of options
11291 AR_Seen
: Boolean := False;
11292 AW_Seen
: Boolean := False;
11293 ER_Seen
: Boolean := False;
11294 EW_Seen
: Boolean := False;
11295 External_Seen
: Boolean := False;
11296 Ghost_Seen
: Boolean := False;
11297 Others_Seen
: Boolean := False;
11298 Part_Of_Seen
: Boolean := False;
11299 Synchronous_Seen
: Boolean := False;
11301 -- Flags used to store the static value of all external states'
11304 AR_Val
: Boolean := False;
11305 AW_Val
: Boolean := False;
11306 ER_Val
: Boolean := False;
11307 EW_Val
: Boolean := False;
11309 State_Id
: Entity_Id
:= Empty
;
11310 -- The entity to be generated for the current state declaration
11312 procedure Analyze_External_Option
(Opt
: Node_Id
);
11313 -- Verify the legality of option External
11315 procedure Analyze_External_Property
11317 Expr
: Node_Id
:= Empty
);
11318 -- Verify the legailty of a single external property. Prop
11319 -- denotes the external property. Expr is the expression used
11320 -- to set the property.
11322 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
);
11323 -- Verify the legality of option Part_Of
11325 procedure Check_Duplicate_Option
11327 Status
: in out Boolean);
11328 -- Flag Status denotes whether a particular option has been
11329 -- seen while processing a state. This routine verifies that
11330 -- Opt is not a duplicate option and sets the flag Status
11331 -- (SPARK RM 7.1.4(1)).
11333 procedure Check_Duplicate_Property
11335 Status
: in out Boolean);
11336 -- Flag Status denotes whether a particular property has been
11337 -- seen while processing option External. This routine verifies
11338 -- that Prop is not a duplicate property and sets flag Status.
11339 -- Opt is not a duplicate property and sets the flag Status.
11340 -- (SPARK RM 7.1.4(2))
11342 procedure Check_Ghost_Synchronous
;
11343 -- Ensure that the abstract state is not subject to both Ghost
11344 -- and Synchronous simple options. Emit an error if this is the
11347 procedure Create_Abstract_State
11351 Is_Null
: Boolean);
11352 -- Generate an abstract state entity with name Nam and enter it
11353 -- into visibility. Decl is the "declaration" of the state as
11354 -- it appears in pragma Abstract_State. Loc is the location of
11355 -- the related state "declaration". Flag Is_Null should be set
11356 -- when the associated Abstract_State pragma defines a null
11359 -----------------------------
11360 -- Analyze_External_Option --
11361 -----------------------------
11363 procedure Analyze_External_Option
(Opt
: Node_Id
) is
11364 Errors
: constant Nat
:= Serious_Errors_Detected
;
11366 Props
: Node_Id
:= Empty
;
11369 if Nkind
(Opt
) = N_Component_Association
then
11370 Props
:= Expression
(Opt
);
11373 -- External state with properties
11375 if Present
(Props
) then
11377 -- Multiple properties appear as an aggregate
11379 if Nkind
(Props
) = N_Aggregate
then
11381 -- Simple property form
11383 Prop
:= First
(Expressions
(Props
));
11384 while Present
(Prop
) loop
11385 Analyze_External_Property
(Prop
);
11389 -- Property with expression form
11391 Prop
:= First
(Component_Associations
(Props
));
11392 while Present
(Prop
) loop
11393 Analyze_External_Property
11394 (Prop
=> First
(Choices
(Prop
)),
11395 Expr
=> Expression
(Prop
));
11403 Analyze_External_Property
(Props
);
11406 -- An external state defined without any properties defaults
11407 -- all properties to True.
11416 -- Once all external properties have been processed, verify
11417 -- their mutual interaction. Do not perform the check when
11418 -- at least one of the properties is illegal as this will
11419 -- produce a bogus error.
11421 if Errors
= Serious_Errors_Detected
then
11422 Check_External_Properties
11423 (State
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
11425 end Analyze_External_Option
;
11427 -------------------------------
11428 -- Analyze_External_Property --
11429 -------------------------------
11431 procedure Analyze_External_Property
11433 Expr
: Node_Id
:= Empty
)
11435 Expr_Val
: Boolean;
11438 -- Check the placement of "others" (if available)
11440 if Nkind
(Prop
) = N_Others_Choice
then
11441 if Others_Seen
then
11443 ("only one others choice allowed in option External",
11446 Others_Seen
:= True;
11449 elsif Others_Seen
then
11451 ("others must be the last property in option External",
11454 -- The only remaining legal options are the four predefined
11455 -- external properties.
11457 elsif Nkind
(Prop
) = N_Identifier
11458 and then Nam_In
(Chars
(Prop
), Name_Async_Readers
,
11459 Name_Async_Writers
,
11460 Name_Effective_Reads
,
11461 Name_Effective_Writes
)
11465 -- Otherwise the construct is not a valid property
11468 SPARK_Msg_N
("invalid external state property", Prop
);
11472 -- Ensure that the expression of the external state property
11473 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
11475 if Present
(Expr
) then
11476 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
11478 if Is_OK_Static_Expression
(Expr
) then
11479 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
11482 ("expression of external state property must be "
11487 -- The lack of expression defaults the property to True
11493 -- Named properties
11495 if Nkind
(Prop
) = N_Identifier
then
11496 if Chars
(Prop
) = Name_Async_Readers
then
11497 Check_Duplicate_Property
(Prop
, AR_Seen
);
11498 AR_Val
:= Expr_Val
;
11500 elsif Chars
(Prop
) = Name_Async_Writers
then
11501 Check_Duplicate_Property
(Prop
, AW_Seen
);
11502 AW_Val
:= Expr_Val
;
11504 elsif Chars
(Prop
) = Name_Effective_Reads
then
11505 Check_Duplicate_Property
(Prop
, ER_Seen
);
11506 ER_Val
:= Expr_Val
;
11509 Check_Duplicate_Property
(Prop
, EW_Seen
);
11510 EW_Val
:= Expr_Val
;
11513 -- The handling of property "others" must take into account
11514 -- all other named properties that have been encountered so
11515 -- far. Only those that have not been seen are affected by
11519 if not AR_Seen
then
11520 AR_Val
:= Expr_Val
;
11523 if not AW_Seen
then
11524 AW_Val
:= Expr_Val
;
11527 if not ER_Seen
then
11528 ER_Val
:= Expr_Val
;
11531 if not EW_Seen
then
11532 EW_Val
:= Expr_Val
;
11535 end Analyze_External_Property
;
11537 ----------------------------
11538 -- Analyze_Part_Of_Option --
11539 ----------------------------
11541 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
) is
11542 Encap
: constant Node_Id
:= Expression
(Opt
);
11543 Constits
: Elist_Id
;
11544 Encap_Id
: Entity_Id
;
11548 Check_Duplicate_Option
(Opt
, Part_Of_Seen
);
11551 (Indic
=> First
(Choices
(Opt
)),
11552 Item_Id
=> State_Id
,
11554 Encap_Id
=> Encap_Id
,
11557 -- The Part_Of indicator transforms the abstract state into
11558 -- a constituent of the encapsulating state or single
11559 -- concurrent type.
11562 pragma Assert
(Present
(Encap_Id
));
11563 Constits
:= Part_Of_Constituents
(Encap_Id
);
11565 if No
(Constits
) then
11566 Constits
:= New_Elmt_List
;
11567 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
11570 Append_Elmt
(State_Id
, Constits
);
11571 Set_Encapsulating_State
(State_Id
, Encap_Id
);
11573 end Analyze_Part_Of_Option
;
11575 ----------------------------
11576 -- Check_Duplicate_Option --
11577 ----------------------------
11579 procedure Check_Duplicate_Option
11581 Status
: in out Boolean)
11585 SPARK_Msg_N
("duplicate state option", Opt
);
11589 end Check_Duplicate_Option
;
11591 ------------------------------
11592 -- Check_Duplicate_Property --
11593 ------------------------------
11595 procedure Check_Duplicate_Property
11597 Status
: in out Boolean)
11601 SPARK_Msg_N
("duplicate external property", Prop
);
11605 end Check_Duplicate_Property
;
11607 -----------------------------
11608 -- Check_Ghost_Synchronous --
11609 -----------------------------
11611 procedure Check_Ghost_Synchronous
is
11613 -- A synchronized abstract state cannot be Ghost and vice
11614 -- versa (SPARK RM 6.9(19)).
11616 if Ghost_Seen
and Synchronous_Seen
then
11617 SPARK_Msg_N
("synchronized state cannot be ghost", State
);
11619 end Check_Ghost_Synchronous
;
11621 ---------------------------
11622 -- Create_Abstract_State --
11623 ---------------------------
11625 procedure Create_Abstract_State
11632 -- The abstract state may be semi-declared when the related
11633 -- package was withed through a limited with clause. In that
11634 -- case reuse the entity to fully declare the state.
11636 if Present
(Decl
) and then Present
(Entity
(Decl
)) then
11637 State_Id
:= Entity
(Decl
);
11639 -- Otherwise the elaboration of pragma Abstract_State
11640 -- declares the state.
11643 State_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
11645 if Present
(Decl
) then
11646 Set_Entity
(Decl
, State_Id
);
11650 -- Null states never come from source
11652 Set_Comes_From_Source
(State_Id
, not Is_Null
);
11653 Set_Parent
(State_Id
, State
);
11654 Set_Ekind
(State_Id
, E_Abstract_State
);
11655 Set_Etype
(State_Id
, Standard_Void_Type
);
11656 Set_Encapsulating_State
(State_Id
, Empty
);
11658 -- Set the SPARK mode from the current context
11660 Set_SPARK_Pragma
(State_Id
, SPARK_Mode_Pragma
);
11661 Set_SPARK_Pragma_Inherited
(State_Id
);
11663 -- An abstract state declared within a Ghost region becomes
11664 -- Ghost (SPARK RM 6.9(2)).
11666 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Pack_Id
) then
11667 Set_Is_Ghost_Entity
(State_Id
);
11670 -- Establish a link between the state declaration and the
11671 -- abstract state entity. Note that a null state remains as
11672 -- N_Null and does not carry any linkages.
11674 if not Is_Null
then
11675 if Present
(Decl
) then
11676 Set_Entity
(Decl
, State_Id
);
11677 Set_Etype
(Decl
, Standard_Void_Type
);
11680 -- Every non-null state must be defined, nameable and
11683 Push_Scope
(Pack_Id
);
11684 Generate_Definition
(State_Id
);
11685 Enter_Name
(State_Id
);
11688 end Create_Abstract_State
;
11695 -- Start of processing for Analyze_Abstract_State
11698 -- A package with a null abstract state is not allowed to
11699 -- declare additional states.
11703 ("package & has null abstract state", State
, Pack_Id
);
11705 -- Null states appear as internally generated entities
11707 elsif Nkind
(State
) = N_Null
then
11708 Create_Abstract_State
11709 (Nam
=> New_Internal_Name
('S'),
11711 Loc
=> Sloc
(State
),
11715 -- Catch a case where a null state appears in a list of
11716 -- non-null states.
11718 if Non_Null_Seen
then
11720 ("package & has non-null abstract state",
11724 -- Simple state declaration
11726 elsif Nkind
(State
) = N_Identifier
then
11727 Create_Abstract_State
11728 (Nam
=> Chars
(State
),
11730 Loc
=> Sloc
(State
),
11732 Non_Null_Seen
:= True;
11734 -- State declaration with various options. This construct
11735 -- appears as an extension aggregate in the tree.
11737 elsif Nkind
(State
) = N_Extension_Aggregate
then
11738 if Nkind
(Ancestor_Part
(State
)) = N_Identifier
then
11739 Create_Abstract_State
11740 (Nam
=> Chars
(Ancestor_Part
(State
)),
11741 Decl
=> Ancestor_Part
(State
),
11742 Loc
=> Sloc
(Ancestor_Part
(State
)),
11744 Non_Null_Seen
:= True;
11747 ("state name must be an identifier",
11748 Ancestor_Part
(State
));
11751 -- Options External, Ghost and Synchronous appear as
11754 Opt
:= First
(Expressions
(State
));
11755 while Present
(Opt
) loop
11756 if Nkind
(Opt
) = N_Identifier
then
11760 if Chars
(Opt
) = Name_External
then
11761 Check_Duplicate_Option
(Opt
, External_Seen
);
11762 Analyze_External_Option
(Opt
);
11766 elsif Chars
(Opt
) = Name_Ghost
then
11767 Check_Duplicate_Option
(Opt
, Ghost_Seen
);
11768 Check_Ghost_Synchronous
;
11770 if Present
(State_Id
) then
11771 Set_Is_Ghost_Entity
(State_Id
);
11776 elsif Chars
(Opt
) = Name_Synchronous
then
11777 Check_Duplicate_Option
(Opt
, Synchronous_Seen
);
11778 Check_Ghost_Synchronous
;
11780 -- Option Part_Of without an encapsulating state is
11781 -- illegal (SPARK RM 7.1.4(9)).
11783 elsif Chars
(Opt
) = Name_Part_Of
then
11785 ("indicator Part_Of must denote abstract state, "
11786 & "single protected type or single task type",
11789 -- Do not emit an error message when a previous state
11790 -- declaration with options was not parenthesized as
11791 -- the option is actually another state declaration.
11793 -- with Abstract_State
11794 -- (State_1 with ..., -- missing parentheses
11795 -- (State_2 with ...),
11796 -- State_3) -- ok state declaration
11798 elsif Missing_Parentheses
then
11801 -- Otherwise the option is not allowed. Note that it
11802 -- is not possible to distinguish between an option
11803 -- and a state declaration when a previous state with
11804 -- options not properly parentheses.
11806 -- with Abstract_State
11807 -- (State_1 with ..., -- missing parentheses
11808 -- State_2); -- could be an option
11812 ("simple option not allowed in state declaration",
11816 -- Catch a case where missing parentheses around a state
11817 -- declaration with options cause a subsequent state
11818 -- declaration with options to be treated as an option.
11820 -- with Abstract_State
11821 -- (State_1 with ..., -- missing parentheses
11822 -- (State_2 with ...))
11824 elsif Nkind
(Opt
) = N_Extension_Aggregate
then
11825 Missing_Parentheses
:= True;
11827 ("state declaration must be parenthesized",
11828 Ancestor_Part
(State
));
11830 -- Otherwise the option is malformed
11833 SPARK_Msg_N
("malformed option", Opt
);
11839 -- Options External and Part_Of appear as component
11842 Opt
:= First
(Component_Associations
(State
));
11843 while Present
(Opt
) loop
11844 Opt_Nam
:= First
(Choices
(Opt
));
11846 if Nkind
(Opt_Nam
) = N_Identifier
then
11847 if Chars
(Opt_Nam
) = Name_External
then
11848 Analyze_External_Option
(Opt
);
11850 elsif Chars
(Opt_Nam
) = Name_Part_Of
then
11851 Analyze_Part_Of_Option
(Opt
);
11854 SPARK_Msg_N
("invalid state option", Opt
);
11857 SPARK_Msg_N
("invalid state option", Opt
);
11863 -- Any other attempt to declare a state is illegal
11866 Malformed_State_Error
(State
);
11870 -- Guard against a junk state. In such cases no entity is
11871 -- generated and the subsequent checks cannot be applied.
11873 if Present
(State_Id
) then
11875 -- Verify whether the state does not introduce an illegal
11876 -- hidden state within a package subject to a null abstract
11879 Check_No_Hidden_State
(State_Id
);
11881 -- Check whether the lack of option Part_Of agrees with the
11882 -- placement of the abstract state with respect to the state
11885 if not Part_Of_Seen
then
11886 Check_Missing_Part_Of
(State_Id
);
11889 -- Associate the state with its related package
11891 if No
(Abstract_States
(Pack_Id
)) then
11892 Set_Abstract_States
(Pack_Id
, New_Elmt_List
);
11895 Append_Elmt
(State_Id
, Abstract_States
(Pack_Id
));
11897 end Analyze_Abstract_State
;
11899 ---------------------------
11900 -- Malformed_State_Error --
11901 ---------------------------
11903 procedure Malformed_State_Error
(State
: Node_Id
) is
11905 Error_Msg_N
("malformed abstract state declaration", State
);
11907 -- An abstract state with a simple option is being declared
11908 -- with "=>" rather than the legal "with". The state appears
11909 -- as a component association.
11911 if Nkind
(State
) = N_Component_Association
then
11912 Error_Msg_N
("\use WITH to specify simple option", State
);
11914 end Malformed_State_Error
;
11918 Pack_Decl
: Node_Id
;
11919 Pack_Id
: Entity_Id
;
11923 -- Start of processing for Abstract_State
11927 Check_No_Identifiers
;
11928 Check_Arg_Count
(1);
11930 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
11932 -- Ensure the proper placement of the pragma. Abstract states must
11933 -- be associated with a package declaration.
11935 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
11936 N_Package_Declaration
)
11940 -- Otherwise the pragma is associated with an illegal construct
11947 Pack_Id
:= Defining_Entity
(Pack_Decl
);
11949 -- A pragma that applies to a Ghost entity becomes Ghost for the
11950 -- purposes of legality checks and removal of ignored Ghost code.
11952 Mark_Ghost_Pragma
(N
, Pack_Id
);
11953 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
11955 -- Chain the pragma on the contract for completeness
11957 Add_Contract_Item
(N
, Pack_Id
);
11959 -- The legality checks of pragmas Abstract_State, Initializes, and
11960 -- Initial_Condition are affected by the SPARK mode in effect. In
11961 -- addition, these three pragmas are subject to an inherent order:
11963 -- 1) Abstract_State
11965 -- 3) Initial_Condition
11967 -- Analyze all these pragmas in the order outlined above
11969 Analyze_If_Present
(Pragma_SPARK_Mode
);
11970 States
:= Expression
(Get_Argument
(N
, Pack_Id
));
11972 -- Multiple non-null abstract states appear as an aggregate
11974 if Nkind
(States
) = N_Aggregate
then
11975 State
:= First
(Expressions
(States
));
11976 while Present
(State
) loop
11977 Analyze_Abstract_State
(State
, Pack_Id
);
11981 -- An abstract state with a simple option is being illegaly
11982 -- declared with "=>" rather than "with". In this case the
11983 -- state declaration appears as a component association.
11985 if Present
(Component_Associations
(States
)) then
11986 State
:= First
(Component_Associations
(States
));
11987 while Present
(State
) loop
11988 Malformed_State_Error
(State
);
11993 -- Various forms of a single abstract state. Note that these may
11994 -- include malformed state declarations.
11997 Analyze_Abstract_State
(States
, Pack_Id
);
12000 Analyze_If_Present
(Pragma_Initializes
);
12001 Analyze_If_Present
(Pragma_Initial_Condition
);
12002 end Abstract_State
;
12010 -- Note: this pragma also has some specific processing in Par.Prag
12011 -- because we want to set the Ada version mode during parsing.
12013 when Pragma_Ada_83
=>
12015 Check_Arg_Count
(0);
12017 -- We really should check unconditionally for proper configuration
12018 -- pragma placement, since we really don't want mixed Ada modes
12019 -- within a single unit, and the GNAT reference manual has always
12020 -- said this was a configuration pragma, but we did not check and
12021 -- are hesitant to add the check now.
12023 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
12024 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
12025 -- or Ada 2012 mode.
12027 if Ada_Version
>= Ada_2005
then
12028 Check_Valid_Configuration_Pragma
;
12031 -- Now set Ada 83 mode
12033 if Latest_Ada_Only
then
12034 Error_Pragma
("??pragma% ignored");
12036 Ada_Version
:= Ada_83
;
12037 Ada_Version_Explicit
:= Ada_83
;
12038 Ada_Version_Pragma
:= N
;
12047 -- Note: this pragma also has some specific processing in Par.Prag
12048 -- because we want to set the Ada 83 version mode during parsing.
12050 when Pragma_Ada_95
=>
12052 Check_Arg_Count
(0);
12054 -- We really should check unconditionally for proper configuration
12055 -- pragma placement, since we really don't want mixed Ada modes
12056 -- within a single unit, and the GNAT reference manual has always
12057 -- said this was a configuration pragma, but we did not check and
12058 -- are hesitant to add the check now.
12060 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
12061 -- or Ada 95, so we must check if we are in Ada 2005 mode.
12063 if Ada_Version
>= Ada_2005
then
12064 Check_Valid_Configuration_Pragma
;
12067 -- Now set Ada 95 mode
12069 if Latest_Ada_Only
then
12070 Error_Pragma
("??pragma% ignored");
12072 Ada_Version
:= Ada_95
;
12073 Ada_Version_Explicit
:= Ada_95
;
12074 Ada_Version_Pragma
:= N
;
12077 ---------------------
12078 -- Ada_05/Ada_2005 --
12079 ---------------------
12082 -- pragma Ada_05 (LOCAL_NAME);
12084 -- pragma Ada_2005;
12085 -- pragma Ada_2005 (LOCAL_NAME):
12087 -- Note: these pragmas also have some specific processing in Par.Prag
12088 -- because we want to set the Ada 2005 version mode during parsing.
12090 -- The one argument form is used for managing the transition from
12091 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
12092 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
12093 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
12094 -- mode, a preference rule is established which does not choose
12095 -- such an entity unless it is unambiguously specified. This avoids
12096 -- extra subprograms marked this way from generating ambiguities in
12097 -- otherwise legal pre-Ada_2005 programs. The one argument form is
12098 -- intended for exclusive use in the GNAT run-time library.
12109 if Arg_Count
= 1 then
12110 Check_Arg_Is_Local_Name
(Arg1
);
12111 E_Id
:= Get_Pragma_Arg
(Arg1
);
12113 if Etype
(E_Id
) = Any_Type
then
12117 Set_Is_Ada_2005_Only
(Entity
(E_Id
));
12118 Record_Rep_Item
(Entity
(E_Id
), N
);
12121 Check_Arg_Count
(0);
12123 -- For Ada_2005 we unconditionally enforce the documented
12124 -- configuration pragma placement, since we do not want to
12125 -- tolerate mixed modes in a unit involving Ada 2005. That
12126 -- would cause real difficulties for those cases where there
12127 -- are incompatibilities between Ada 95 and Ada 2005.
12129 Check_Valid_Configuration_Pragma
;
12131 -- Now set appropriate Ada mode
12133 if Latest_Ada_Only
then
12134 Error_Pragma
("??pragma% ignored");
12136 Ada_Version
:= Ada_2005
;
12137 Ada_Version_Explicit
:= Ada_2005
;
12138 Ada_Version_Pragma
:= N
;
12143 ---------------------
12144 -- Ada_12/Ada_2012 --
12145 ---------------------
12148 -- pragma Ada_12 (LOCAL_NAME);
12150 -- pragma Ada_2012;
12151 -- pragma Ada_2012 (LOCAL_NAME):
12153 -- Note: these pragmas also have some specific processing in Par.Prag
12154 -- because we want to set the Ada 2012 version mode during parsing.
12156 -- The one argument form is used for managing the transition from Ada
12157 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
12158 -- as Ada_2012 only, then referencing the entity in any pre-Ada_2012
12159 -- mode will generate a warning. In addition, in any pre-Ada_2012
12160 -- mode, a preference rule is established which does not choose
12161 -- such an entity unless it is unambiguously specified. This avoids
12162 -- extra subprograms marked this way from generating ambiguities in
12163 -- otherwise legal pre-Ada_2012 programs. The one argument form is
12164 -- intended for exclusive use in the GNAT run-time library.
12175 if Arg_Count
= 1 then
12176 Check_Arg_Is_Local_Name
(Arg1
);
12177 E_Id
:= Get_Pragma_Arg
(Arg1
);
12179 if Etype
(E_Id
) = Any_Type
then
12183 Set_Is_Ada_2012_Only
(Entity
(E_Id
));
12184 Record_Rep_Item
(Entity
(E_Id
), N
);
12187 Check_Arg_Count
(0);
12189 -- For Ada_2012 we unconditionally enforce the documented
12190 -- configuration pragma placement, since we do not want to
12191 -- tolerate mixed modes in a unit involving Ada 2012. That
12192 -- would cause real difficulties for those cases where there
12193 -- are incompatibilities between Ada 95 and Ada 2012. We could
12194 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
12196 Check_Valid_Configuration_Pragma
;
12198 -- Now set appropriate Ada mode
12200 Ada_Version
:= Ada_2012
;
12201 Ada_Version_Explicit
:= Ada_2012
;
12202 Ada_Version_Pragma
:= N
;
12210 -- pragma Ada_2020;
12212 -- Note: this pragma also has some specific processing in Par.Prag
12213 -- because we want to set the Ada 2020 version mode during parsing.
12215 when Pragma_Ada_2020
=>
12218 Check_Arg_Count
(0);
12220 Check_Valid_Configuration_Pragma
;
12222 -- Now set appropriate Ada mode
12224 Ada_Version
:= Ada_2020
;
12225 Ada_Version_Explicit
:= Ada_2020
;
12226 Ada_Version_Pragma
:= N
;
12228 ----------------------
12229 -- All_Calls_Remote --
12230 ----------------------
12232 -- pragma All_Calls_Remote [(library_package_NAME)];
12234 when Pragma_All_Calls_Remote
=> All_Calls_Remote
: declare
12235 Lib_Entity
: Entity_Id
;
12238 Check_Ada_83_Warning
;
12239 Check_Valid_Library_Unit_Pragma
;
12241 if Nkind
(N
) = N_Null_Statement
then
12245 Lib_Entity
:= Find_Lib_Unit_Name
;
12247 -- A pragma that applies to a Ghost entity becomes Ghost for the
12248 -- purposes of legality checks and removal of ignored Ghost code.
12250 Mark_Ghost_Pragma
(N
, Lib_Entity
);
12252 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
12254 if Present
(Lib_Entity
) and then not Debug_Flag_U
then
12255 if not Is_Remote_Call_Interface
(Lib_Entity
) then
12256 Error_Pragma
("pragma% only apply to rci unit");
12258 -- Set flag for entity of the library unit
12261 Set_Has_All_Calls_Remote
(Lib_Entity
);
12264 end All_Calls_Remote
;
12266 ---------------------------
12267 -- Allow_Integer_Address --
12268 ---------------------------
12270 -- pragma Allow_Integer_Address;
12272 when Pragma_Allow_Integer_Address
=>
12274 Check_Valid_Configuration_Pragma
;
12275 Check_Arg_Count
(0);
12277 -- If Address is a private type, then set the flag to allow
12278 -- integer address values. If Address is not private, then this
12279 -- pragma has no purpose, so it is simply ignored. Not clear if
12280 -- there are any such targets now.
12282 if Opt
.Address_Is_Private
then
12283 Opt
.Allow_Integer_Address
:= True;
12291 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
12292 -- ARG ::= NAME | EXPRESSION
12294 -- The first two arguments are by convention intended to refer to an
12295 -- external tool and a tool-specific function. These arguments are
12298 when Pragma_Annotate
=> Annotate
: declare
12305 Check_At_Least_N_Arguments
(1);
12307 Nam_Arg
:= Last
(Pragma_Argument_Associations
(N
));
12309 -- Determine whether the last argument is "Entity => local_NAME"
12310 -- and if it is, perform the required semantic checks. Remove the
12311 -- argument from further processing.
12313 if Nkind
(Nam_Arg
) = N_Pragma_Argument_Association
12314 and then Chars
(Nam_Arg
) = Name_Entity
12316 Check_Arg_Is_Local_Name
(Nam_Arg
);
12317 Arg_Count
:= Arg_Count
- 1;
12319 -- A pragma that applies to a Ghost entity becomes Ghost for
12320 -- the purposes of legality checks and removal of ignored Ghost
12323 if Is_Entity_Name
(Get_Pragma_Arg
(Nam_Arg
))
12324 and then Present
(Entity
(Get_Pragma_Arg
(Nam_Arg
)))
12326 Mark_Ghost_Pragma
(N
, Entity
(Get_Pragma_Arg
(Nam_Arg
)));
12329 -- Not allowed in compiler units (bootstrap issues)
12331 Check_Compiler_Unit
("Entity for pragma Annotate", N
);
12334 -- Continue the processing with last argument removed for now
12336 Check_Arg_Is_Identifier
(Arg1
);
12337 Check_No_Identifiers
;
12340 -- The second parameter is optional, it is never analyzed
12345 -- Otherwise there is a second parameter
12348 -- The second parameter must be an identifier
12350 Check_Arg_Is_Identifier
(Arg2
);
12352 -- Process the remaining parameters (if any)
12354 Arg
:= Next
(Arg2
);
12355 while Present
(Arg
) loop
12356 Expr
:= Get_Pragma_Arg
(Arg
);
12359 if Is_Entity_Name
(Expr
) then
12362 -- For string literals, we assume Standard_String as the
12363 -- type, unless the string contains wide or wide_wide
12366 elsif Nkind
(Expr
) = N_String_Literal
then
12367 if Has_Wide_Wide_Character
(Expr
) then
12368 Resolve
(Expr
, Standard_Wide_Wide_String
);
12369 elsif Has_Wide_Character
(Expr
) then
12370 Resolve
(Expr
, Standard_Wide_String
);
12372 Resolve
(Expr
, Standard_String
);
12375 elsif Is_Overloaded
(Expr
) then
12376 Error_Pragma_Arg
("ambiguous argument for pragma%", Expr
);
12387 -------------------------------------------------
12388 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
12389 -------------------------------------------------
12392 -- ( [Check => ] Boolean_EXPRESSION
12393 -- [, [Message =>] Static_String_EXPRESSION]);
12395 -- pragma Assert_And_Cut
12396 -- ( [Check => ] Boolean_EXPRESSION
12397 -- [, [Message =>] Static_String_EXPRESSION]);
12400 -- ( [Check => ] Boolean_EXPRESSION
12401 -- [, [Message =>] Static_String_EXPRESSION]);
12403 -- pragma Loop_Invariant
12404 -- ( [Check => ] Boolean_EXPRESSION
12405 -- [, [Message =>] Static_String_EXPRESSION]);
12408 | Pragma_Assert_And_Cut
12410 | Pragma_Loop_Invariant
12413 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean;
12414 -- Determine whether expression Expr contains a Loop_Entry
12415 -- attribute reference.
12417 -------------------------
12418 -- Contains_Loop_Entry --
12419 -------------------------
12421 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean is
12422 Has_Loop_Entry
: Boolean := False;
12424 function Process
(N
: Node_Id
) return Traverse_Result
;
12425 -- Process function for traversal to look for Loop_Entry
12431 function Process
(N
: Node_Id
) return Traverse_Result
is
12433 if Nkind
(N
) = N_Attribute_Reference
12434 and then Attribute_Name
(N
) = Name_Loop_Entry
12436 Has_Loop_Entry
:= True;
12443 procedure Traverse
is new Traverse_Proc
(Process
);
12445 -- Start of processing for Contains_Loop_Entry
12449 return Has_Loop_Entry
;
12450 end Contains_Loop_Entry
;
12455 New_Args
: List_Id
;
12457 -- Start of processing for Assert
12460 -- Assert is an Ada 2005 RM-defined pragma
12462 if Prag_Id
= Pragma_Assert
then
12465 -- The remaining ones are GNAT pragmas
12471 Check_At_Least_N_Arguments
(1);
12472 Check_At_Most_N_Arguments
(2);
12473 Check_Arg_Order
((Name_Check
, Name_Message
));
12474 Check_Optional_Identifier
(Arg1
, Name_Check
);
12475 Expr
:= Get_Pragma_Arg
(Arg1
);
12477 -- Special processing for Loop_Invariant, Loop_Variant or for
12478 -- other cases where a Loop_Entry attribute is present. If the
12479 -- assertion pragma contains attribute Loop_Entry, ensure that
12480 -- the related pragma is within a loop.
12482 if Prag_Id
= Pragma_Loop_Invariant
12483 or else Prag_Id
= Pragma_Loop_Variant
12484 or else Contains_Loop_Entry
(Expr
)
12486 Check_Loop_Pragma_Placement
;
12488 -- Perform preanalysis to deal with embedded Loop_Entry
12491 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
12494 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
12495 -- a corresponding Check pragma:
12497 -- pragma Check (name, condition [, msg]);
12499 -- Where name is the identifier matching the pragma name. So
12500 -- rewrite pragma in this manner, transfer the message argument
12501 -- if present, and analyze the result
12503 -- Note: When dealing with a semantically analyzed tree, the
12504 -- information that a Check node N corresponds to a source Assert,
12505 -- Assume, or Assert_And_Cut pragma can be retrieved from the
12506 -- pragma kind of Original_Node(N).
12508 New_Args
:= New_List
(
12509 Make_Pragma_Argument_Association
(Loc
,
12510 Expression
=> Make_Identifier
(Loc
, Pname
)),
12511 Make_Pragma_Argument_Association
(Sloc
(Expr
),
12512 Expression
=> Expr
));
12514 if Arg_Count
> 1 then
12515 Check_Optional_Identifier
(Arg2
, Name_Message
);
12517 -- Provide semantic annnotations for optional argument, for
12518 -- ASIS use, before rewriting.
12520 Preanalyze_And_Resolve
(Expression
(Arg2
), Standard_String
);
12521 Append_To
(New_Args
, New_Copy_Tree
(Arg2
));
12524 -- Rewrite as Check pragma
12528 Chars
=> Name_Check
,
12529 Pragma_Argument_Associations
=> New_Args
));
12534 ----------------------
12535 -- Assertion_Policy --
12536 ----------------------
12538 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
12540 -- The following form is Ada 2012 only, but we allow it in all modes
12542 -- Pragma Assertion_Policy (
12543 -- ASSERTION_KIND => POLICY_IDENTIFIER
12544 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
12546 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
12548 -- RM_ASSERTION_KIND ::= Assert |
12549 -- Static_Predicate |
12550 -- Dynamic_Predicate |
12555 -- Type_Invariant |
12556 -- Type_Invariant'Class
12558 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
12560 -- Contract_Cases |
12562 -- Default_Initial_Condition |
12564 -- Initial_Condition |
12565 -- Loop_Invariant |
12571 -- Statement_Assertions
12573 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
12574 -- ID_ASSERTION_KIND list contains implementation-defined additions
12575 -- recognized by GNAT. The effect is to control the behavior of
12576 -- identically named aspects and pragmas, depending on the specified
12577 -- policy identifier:
12579 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible
12581 -- Note: Check and Ignore are language-defined. Disable is a GNAT
12582 -- implementation-defined addition that results in totally ignoring
12583 -- the corresponding assertion. If Disable is specified, then the
12584 -- argument of the assertion is not even analyzed. This is useful
12585 -- when the aspect/pragma argument references entities in a with'ed
12586 -- package that is replaced by a dummy package in the final build.
12588 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
12589 -- and Type_Invariant'Class were recognized by the parser and
12590 -- transformed into references to the special internal identifiers
12591 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
12592 -- processing is required here.
12594 when Pragma_Assertion_Policy
=> Assertion_Policy
: declare
12595 procedure Resolve_Suppressible
(Policy
: Node_Id
);
12596 -- Converts the assertion policy 'Suppressible' to either Check or
12597 -- Ignore based on whether checks are suppressed via -gnatp.
12599 --------------------------
12600 -- Resolve_Suppressible --
12601 --------------------------
12603 procedure Resolve_Suppressible
(Policy
: Node_Id
) is
12604 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Policy
);
12608 -- Transform policy argument Suppressible into either Ignore or
12609 -- Check depending on whether checks are enabled or suppressed.
12611 if Chars
(Arg
) = Name_Suppressible
then
12612 if Suppress_Checks
then
12613 Nam
:= Name_Ignore
;
12618 Rewrite
(Arg
, Make_Identifier
(Sloc
(Arg
), Nam
));
12620 end Resolve_Suppressible
;
12632 -- This can always appear as a configuration pragma
12634 if Is_Configuration_Pragma
then
12637 -- It can also appear in a declarative part or package spec in Ada
12638 -- 2012 mode. We allow this in other modes, but in that case we
12639 -- consider that we have an Ada 2012 pragma on our hands.
12642 Check_Is_In_Decl_Part_Or_Package_Spec
;
12646 -- One argument case with no identifier (first form above)
12649 and then (Nkind
(Arg1
) /= N_Pragma_Argument_Association
12650 or else Chars
(Arg1
) = No_Name
)
12652 Check_Arg_Is_One_Of
(Arg1
,
12653 Name_Check
, Name_Disable
, Name_Ignore
, Name_Suppressible
);
12655 Resolve_Suppressible
(Arg1
);
12657 -- Treat one argument Assertion_Policy as equivalent to:
12659 -- pragma Check_Policy (Assertion, policy)
12661 -- So rewrite pragma in that manner and link on to the chain
12662 -- of Check_Policy pragmas, marking the pragma as analyzed.
12664 Policy
:= Get_Pragma_Arg
(Arg1
);
12668 Chars
=> Name_Check_Policy
,
12669 Pragma_Argument_Associations
=> New_List
(
12670 Make_Pragma_Argument_Association
(Loc
,
12671 Expression
=> Make_Identifier
(Loc
, Name_Assertion
)),
12673 Make_Pragma_Argument_Association
(Loc
,
12675 Make_Identifier
(Sloc
(Policy
), Chars
(Policy
))))));
12678 -- Here if we have two or more arguments
12681 Check_At_Least_N_Arguments
(1);
12684 -- Loop through arguments
12687 while Present
(Arg
) loop
12688 LocP
:= Sloc
(Arg
);
12690 -- Kind must be specified
12692 if Nkind
(Arg
) /= N_Pragma_Argument_Association
12693 or else Chars
(Arg
) = No_Name
12696 ("missing assertion kind for pragma%", Arg
);
12699 -- Check Kind and Policy have allowed forms
12701 Kind
:= Chars
(Arg
);
12702 Policy
:= Get_Pragma_Arg
(Arg
);
12704 if not Is_Valid_Assertion_Kind
(Kind
) then
12706 ("invalid assertion kind for pragma%", Arg
);
12709 Check_Arg_Is_One_Of
(Arg
,
12710 Name_Check
, Name_Disable
, Name_Ignore
, Name_Suppressible
);
12712 Resolve_Suppressible
(Arg
);
12714 if Kind
= Name_Ghost
then
12716 -- The Ghost policy must be either Check or Ignore
12717 -- (SPARK RM 6.9(6)).
12719 if not Nam_In
(Chars
(Policy
), Name_Check
,
12723 ("argument of pragma % Ghost must be Check or "
12724 & "Ignore", Policy
);
12727 -- Pragma Assertion_Policy specifying a Ghost policy
12728 -- cannot occur within a Ghost subprogram or package
12729 -- (SPARK RM 6.9(14)).
12731 if Ghost_Mode
> None
then
12733 ("pragma % cannot appear within ghost subprogram or "
12738 -- Rewrite the Assertion_Policy pragma as a series of
12739 -- Check_Policy pragmas of the form:
12741 -- Check_Policy (Kind, Policy);
12743 -- Note: the insertion of the pragmas cannot be done with
12744 -- Insert_Action because in the configuration case, there
12745 -- are no scopes on the scope stack and the mechanism will
12748 Insert_Before_And_Analyze
(N
,
12750 Chars
=> Name_Check_Policy
,
12751 Pragma_Argument_Associations
=> New_List
(
12752 Make_Pragma_Argument_Association
(LocP
,
12753 Expression
=> Make_Identifier
(LocP
, Kind
)),
12754 Make_Pragma_Argument_Association
(LocP
,
12755 Expression
=> Policy
))));
12760 -- Rewrite the Assertion_Policy pragma as null since we have
12761 -- now inserted all the equivalent Check pragmas.
12763 Rewrite
(N
, Make_Null_Statement
(Loc
));
12766 end Assertion_Policy
;
12768 ------------------------------
12769 -- Assume_No_Invalid_Values --
12770 ------------------------------
12772 -- pragma Assume_No_Invalid_Values (On | Off);
12774 when Pragma_Assume_No_Invalid_Values
=>
12776 Check_Valid_Configuration_Pragma
;
12777 Check_Arg_Count
(1);
12778 Check_No_Identifiers
;
12779 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
12781 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
12782 Assume_No_Invalid_Values
:= True;
12784 Assume_No_Invalid_Values
:= False;
12787 --------------------------
12788 -- Attribute_Definition --
12789 --------------------------
12791 -- pragma Attribute_Definition
12792 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
12793 -- [Entity =>] LOCAL_NAME,
12794 -- [Expression =>] EXPRESSION | NAME);
12796 when Pragma_Attribute_Definition
=> Attribute_Definition
: declare
12797 Attribute_Designator
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
12802 Check_Arg_Count
(3);
12803 Check_Optional_Identifier
(Arg1
, "attribute");
12804 Check_Optional_Identifier
(Arg2
, "entity");
12805 Check_Optional_Identifier
(Arg3
, "expression");
12807 if Nkind
(Attribute_Designator
) /= N_Identifier
then
12808 Error_Msg_N
("attribute name expected", Attribute_Designator
);
12812 Check_Arg_Is_Local_Name
(Arg2
);
12814 -- If the attribute is not recognized, then issue a warning (not
12815 -- an error), and ignore the pragma.
12817 Aname
:= Chars
(Attribute_Designator
);
12819 if not Is_Attribute_Name
(Aname
) then
12820 Bad_Attribute
(Attribute_Designator
, Aname
, Warn
=> True);
12824 -- Otherwise, rewrite the pragma as an attribute definition clause
12827 Make_Attribute_Definition_Clause
(Loc
,
12828 Name
=> Get_Pragma_Arg
(Arg2
),
12830 Expression
=> Get_Pragma_Arg
(Arg3
)));
12832 end Attribute_Definition
;
12834 ------------------------------------------------------------------
12835 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
12836 ------------------------------------------------------------------
12838 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
12839 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
12840 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
12841 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
12843 when Pragma_Async_Readers
12844 | Pragma_Async_Writers
12845 | Pragma_Effective_Reads
12846 | Pragma_Effective_Writes
12848 Async_Effective
: declare
12849 Obj_Decl
: Node_Id
;
12850 Obj_Id
: Entity_Id
;
12854 Check_No_Identifiers
;
12855 Check_At_Most_N_Arguments
(1);
12857 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
12859 -- Object declaration
12861 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
12864 -- Otherwise the pragma is associated with an illegal construact
12871 Obj_Id
:= Defining_Entity
(Obj_Decl
);
12873 -- Perform minimal verification to ensure that the argument is at
12874 -- least a variable. Subsequent finer grained checks will be done
12875 -- at the end of the declarative region the contains the pragma.
12877 if Ekind
(Obj_Id
) = E_Variable
then
12879 -- A pragma that applies to a Ghost entity becomes Ghost for
12880 -- the purposes of legality checks and removal of ignored Ghost
12883 Mark_Ghost_Pragma
(N
, Obj_Id
);
12885 -- Chain the pragma on the contract for further processing by
12886 -- Analyze_External_Property_In_Decl_Part.
12888 Add_Contract_Item
(N
, Obj_Id
);
12890 -- Analyze the Boolean expression (if any)
12892 if Present
(Arg1
) then
12893 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
12896 -- Otherwise the external property applies to a constant
12899 Error_Pragma
("pragma % must apply to a volatile object");
12901 end Async_Effective
;
12907 -- pragma Asynchronous (LOCAL_NAME);
12909 when Pragma_Asynchronous
=> Asynchronous
: declare
12912 Formal
: Entity_Id
;
12917 procedure Process_Async_Pragma
;
12918 -- Common processing for procedure and access-to-procedure case
12920 --------------------------
12921 -- Process_Async_Pragma --
12922 --------------------------
12924 procedure Process_Async_Pragma
is
12927 Set_Is_Asynchronous
(Nm
);
12931 -- The formals should be of mode IN (RM E.4.1(6))
12934 while Present
(S
) loop
12935 Formal
:= Defining_Identifier
(S
);
12937 if Nkind
(Formal
) = N_Defining_Identifier
12938 and then Ekind
(Formal
) /= E_In_Parameter
12941 ("pragma% procedure can only have IN parameter",
12948 Set_Is_Asynchronous
(Nm
);
12949 end Process_Async_Pragma
;
12951 -- Start of processing for pragma Asynchronous
12954 Check_Ada_83_Warning
;
12955 Check_No_Identifiers
;
12956 Check_Arg_Count
(1);
12957 Check_Arg_Is_Local_Name
(Arg1
);
12959 if Debug_Flag_U
then
12963 C_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
12964 Analyze
(Get_Pragma_Arg
(Arg1
));
12965 Nm
:= Entity
(Get_Pragma_Arg
(Arg1
));
12967 -- A pragma that applies to a Ghost entity becomes Ghost for the
12968 -- purposes of legality checks and removal of ignored Ghost code.
12970 Mark_Ghost_Pragma
(N
, Nm
);
12972 if not Is_Remote_Call_Interface
(C_Ent
)
12973 and then not Is_Remote_Types
(C_Ent
)
12975 -- This pragma should only appear in an RCI or Remote Types
12976 -- unit (RM E.4.1(4)).
12979 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
12982 if Ekind
(Nm
) = E_Procedure
12983 and then Nkind
(Parent
(Nm
)) = N_Procedure_Specification
12985 if not Is_Remote_Call_Interface
(Nm
) then
12987 ("pragma% cannot be applied on non-remote procedure",
12991 L
:= Parameter_Specifications
(Parent
(Nm
));
12992 Process_Async_Pragma
;
12995 elsif Ekind
(Nm
) = E_Function
then
12997 ("pragma% cannot be applied to function", Arg1
);
12999 elsif Is_Remote_Access_To_Subprogram_Type
(Nm
) then
13000 if Is_Record_Type
(Nm
) then
13002 -- A record type that is the Equivalent_Type for a remote
13003 -- access-to-subprogram type.
13005 Decl
:= Declaration_Node
(Corresponding_Remote_Type
(Nm
));
13008 -- A non-expanded RAS type (distribution is not enabled)
13010 Decl
:= Declaration_Node
(Nm
);
13013 if Nkind
(Decl
) = N_Full_Type_Declaration
13014 and then Nkind
(Type_Definition
(Decl
)) =
13015 N_Access_Procedure_Definition
13017 L
:= Parameter_Specifications
(Type_Definition
(Decl
));
13018 Process_Async_Pragma
;
13020 if Is_Asynchronous
(Nm
)
13021 and then Expander_Active
13022 and then Get_PCS_Name
/= Name_No_DSA
13024 RACW_Type_Is_Asynchronous
(Underlying_RACW_Type
(Nm
));
13029 ("pragma% cannot reference access-to-function type",
13033 -- Only other possibility is Access-to-class-wide type
13035 elsif Is_Access_Type
(Nm
)
13036 and then Is_Class_Wide_Type
(Designated_Type
(Nm
))
13038 Check_First_Subtype
(Arg1
);
13039 Set_Is_Asynchronous
(Nm
);
13040 if Expander_Active
then
13041 RACW_Type_Is_Asynchronous
(Nm
);
13045 Error_Pragma_Arg
("inappropriate argument for pragma%", Arg1
);
13053 -- pragma Atomic (LOCAL_NAME);
13055 when Pragma_Atomic
=>
13056 Process_Atomic_Independent_Shared_Volatile
;
13058 -----------------------
13059 -- Atomic_Components --
13060 -----------------------
13062 -- pragma Atomic_Components (array_LOCAL_NAME);
13064 -- This processing is shared by Volatile_Components
13066 when Pragma_Atomic_Components
13067 | Pragma_Volatile_Components
13069 Atomic_Components
: declare
13076 Check_Ada_83_Warning
;
13077 Check_No_Identifiers
;
13078 Check_Arg_Count
(1);
13079 Check_Arg_Is_Local_Name
(Arg1
);
13080 E_Id
:= Get_Pragma_Arg
(Arg1
);
13082 if Etype
(E_Id
) = Any_Type
then
13086 E
:= Entity
(E_Id
);
13088 -- A pragma that applies to a Ghost entity becomes Ghost for the
13089 -- purposes of legality checks and removal of ignored Ghost code.
13091 Mark_Ghost_Pragma
(N
, E
);
13092 Check_Duplicate_Pragma
(E
);
13094 if Rep_Item_Too_Early
(E
, N
)
13096 Rep_Item_Too_Late
(E
, N
)
13101 D
:= Declaration_Node
(E
);
13104 if (K
= N_Full_Type_Declaration
and then Is_Array_Type
(E
))
13106 ((Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
13107 and then Nkind
(D
) = N_Object_Declaration
13108 and then Nkind
(Object_Definition
(D
)) =
13109 N_Constrained_Array_Definition
)
13111 -- The flag is set on the object, or on the base type
13113 if Nkind
(D
) /= N_Object_Declaration
then
13114 E
:= Base_Type
(E
);
13117 -- Atomic implies both Independent and Volatile
13119 if Prag_Id
= Pragma_Atomic_Components
then
13120 Set_Has_Atomic_Components
(E
);
13121 Set_Has_Independent_Components
(E
);
13124 Set_Has_Volatile_Components
(E
);
13127 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
13129 end Atomic_Components
;
13131 --------------------
13132 -- Attach_Handler --
13133 --------------------
13135 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
13137 when Pragma_Attach_Handler
=>
13138 Check_Ada_83_Warning
;
13139 Check_No_Identifiers
;
13140 Check_Arg_Count
(2);
13142 if No_Run_Time_Mode
then
13143 Error_Msg_CRT
("Attach_Handler pragma", N
);
13145 Check_Interrupt_Or_Attach_Handler
;
13147 -- The expression that designates the attribute may depend on a
13148 -- discriminant, and is therefore a per-object expression, to
13149 -- be expanded in the init proc. If expansion is enabled, then
13150 -- perform semantic checks on a copy only.
13155 Parg2
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
13158 -- In Relaxed_RM_Semantics mode, we allow any static
13159 -- integer value, for compatibility with other compilers.
13161 if Relaxed_RM_Semantics
13162 and then Nkind
(Parg2
) = N_Integer_Literal
13164 Typ
:= Standard_Integer
;
13166 Typ
:= RTE
(RE_Interrupt_ID
);
13169 if Expander_Active
then
13170 Temp
:= New_Copy_Tree
(Parg2
);
13171 Set_Parent
(Temp
, N
);
13172 Preanalyze_And_Resolve
(Temp
, Typ
);
13175 Resolve
(Parg2
, Typ
);
13179 Process_Interrupt_Or_Attach_Handler
;
13182 --------------------
13183 -- C_Pass_By_Copy --
13184 --------------------
13186 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
13188 when Pragma_C_Pass_By_Copy
=> C_Pass_By_Copy
: declare
13194 Check_Valid_Configuration_Pragma
;
13195 Check_Arg_Count
(1);
13196 Check_Optional_Identifier
(Arg1
, "max_size");
13198 Arg
:= Get_Pragma_Arg
(Arg1
);
13199 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
13201 Val
:= Expr_Value
(Arg
);
13205 ("maximum size for pragma% must be positive", Arg1
);
13207 elsif UI_Is_In_Int_Range
(Val
) then
13208 Default_C_Record_Mechanism
:= UI_To_Int
(Val
);
13210 -- If a giant value is given, Int'Last will do well enough.
13211 -- If sometime someone complains that a record larger than
13212 -- two gigabytes is not copied, we will worry about it then.
13215 Default_C_Record_Mechanism
:= Mechanism_Type
'Last;
13217 end C_Pass_By_Copy
;
13223 -- pragma Check ([Name =>] CHECK_KIND,
13224 -- [Check =>] Boolean_EXPRESSION
13225 -- [,[Message =>] String_EXPRESSION]);
13227 -- CHECK_KIND ::= IDENTIFIER |
13230 -- Invariant'Class |
13231 -- Type_Invariant'Class
13233 -- The identifiers Assertions and Statement_Assertions are not
13234 -- allowed, since they have special meaning for Check_Policy.
13236 -- WARNING: The code below manages Ghost regions. Return statements
13237 -- must be replaced by gotos which jump to the end of the code and
13238 -- restore the Ghost mode.
13240 when Pragma_Check
=> Check
: declare
13241 Saved_GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
13242 -- Save the Ghost mode to restore on exit
13248 pragma Warnings
(Off
, Str
);
13251 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
13252 -- the mode now to ensure that any nodes generated during analysis
13253 -- and expansion are marked as Ghost.
13255 Set_Ghost_Mode
(N
);
13258 Check_At_Least_N_Arguments
(2);
13259 Check_At_Most_N_Arguments
(3);
13260 Check_Optional_Identifier
(Arg1
, Name_Name
);
13261 Check_Optional_Identifier
(Arg2
, Name_Check
);
13263 if Arg_Count
= 3 then
13264 Check_Optional_Identifier
(Arg3
, Name_Message
);
13265 Str
:= Get_Pragma_Arg
(Arg3
);
13268 Rewrite_Assertion_Kind
(Get_Pragma_Arg
(Arg1
));
13269 Check_Arg_Is_Identifier
(Arg1
);
13270 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
13272 -- Check forbidden name Assertions or Statement_Assertions
13275 when Name_Assertions
=>
13277 ("""Assertions"" is not allowed as a check kind for "
13278 & "pragma%", Arg1
);
13280 when Name_Statement_Assertions
=>
13282 ("""Statement_Assertions"" is not allowed as a check kind "
13283 & "for pragma%", Arg1
);
13289 -- Check applicable policy. We skip this if Checked/Ignored status
13290 -- is already set (e.g. in the case of a pragma from an aspect).
13292 if Is_Checked
(N
) or else Is_Ignored
(N
) then
13295 -- For a non-source pragma that is a rewriting of another pragma,
13296 -- copy the Is_Checked/Ignored status from the rewritten pragma.
13298 elsif Is_Rewrite_Substitution
(N
)
13299 and then Nkind
(Original_Node
(N
)) = N_Pragma
13300 and then Original_Node
(N
) /= N
13302 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
13303 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
13305 -- Otherwise query the applicable policy at this point
13308 case Check_Kind
(Cname
) is
13309 when Name_Ignore
=>
13310 Set_Is_Ignored
(N
, True);
13311 Set_Is_Checked
(N
, False);
13314 Set_Is_Ignored
(N
, False);
13315 Set_Is_Checked
(N
, True);
13317 -- For disable, rewrite pragma as null statement and skip
13318 -- rest of the analysis of the pragma.
13320 when Name_Disable
=>
13321 Rewrite
(N
, Make_Null_Statement
(Loc
));
13325 -- No other possibilities
13328 raise Program_Error
;
13332 -- If check kind was not Disable, then continue pragma analysis
13334 Expr
:= Get_Pragma_Arg
(Arg2
);
13336 -- Deal with SCO generation
13338 if Is_Checked
(N
) and then not Split_PPC
(N
) then
13339 Set_SCO_Pragma_Enabled
(Loc
);
13342 -- Deal with analyzing the string argument. If checks are not
13343 -- on we don't want any expansion (since such expansion would
13344 -- not get properly deleted) but we do want to analyze (to get
13345 -- proper references). The Preanalyze_And_Resolve routine does
13346 -- just what we want. Ditto if pragma is active, because it will
13347 -- be rewritten as an if-statement whose analysis will complete
13348 -- analysis and expansion of the string message. This makes a
13349 -- difference in the unusual case where the expression for the
13350 -- string may have a side effect, such as raising an exception.
13351 -- This is mandated by RM 11.4.2, which specifies that the string
13352 -- expression is only evaluated if the check fails and
13353 -- Assertion_Error is to be raised.
13355 if Arg_Count
= 3 then
13356 Preanalyze_And_Resolve
(Str
, Standard_String
);
13359 -- Now you might think we could just do the same with the Boolean
13360 -- expression if checks are off (and expansion is on) and then
13361 -- rewrite the check as a null statement. This would work but we
13362 -- would lose the useful warnings about an assertion being bound
13363 -- to fail even if assertions are turned off.
13365 -- So instead we wrap the boolean expression in an if statement
13366 -- that looks like:
13368 -- if False and then condition then
13372 -- The reason we do this rewriting during semantic analysis rather
13373 -- than as part of normal expansion is that we cannot analyze and
13374 -- expand the code for the boolean expression directly, or it may
13375 -- cause insertion of actions that would escape the attempt to
13376 -- suppress the check code.
13378 -- Note that the Sloc for the if statement corresponds to the
13379 -- argument condition, not the pragma itself. The reason for
13380 -- this is that we may generate a warning if the condition is
13381 -- False at compile time, and we do not want to delete this
13382 -- warning when we delete the if statement.
13384 if Expander_Active
and Is_Ignored
(N
) then
13385 Eloc
:= Sloc
(Expr
);
13388 Make_If_Statement
(Eloc
,
13390 Make_And_Then
(Eloc
,
13391 Left_Opnd
=> Make_Identifier
(Eloc
, Name_False
),
13392 Right_Opnd
=> Expr
),
13393 Then_Statements
=> New_List
(
13394 Make_Null_Statement
(Eloc
))));
13396 -- Now go ahead and analyze the if statement
13398 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
13400 -- One rather special treatment. If we are now in Eliminated
13401 -- overflow mode, then suppress overflow checking since we do
13402 -- not want to drag in the bignum stuff if we are in Ignore
13403 -- mode anyway. This is particularly important if we are using
13404 -- a configurable run time that does not support bignum ops.
13406 if Scope_Suppress
.Overflow_Mode_Assertions
= Eliminated
then
13408 Svo
: constant Boolean :=
13409 Scope_Suppress
.Suppress
(Overflow_Check
);
13411 Scope_Suppress
.Overflow_Mode_Assertions
:= Strict
;
13412 Scope_Suppress
.Suppress
(Overflow_Check
) := True;
13414 Scope_Suppress
.Suppress
(Overflow_Check
) := Svo
;
13415 Scope_Suppress
.Overflow_Mode_Assertions
:= Eliminated
;
13418 -- Not that special case
13424 -- All done with this check
13426 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
13428 -- Check is active or expansion not active. In these cases we can
13429 -- just go ahead and analyze the boolean with no worries.
13432 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
13433 Analyze_And_Resolve
(Expr
, Any_Boolean
);
13434 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
13437 Restore_Ghost_Mode
(Saved_GM
);
13440 --------------------------
13441 -- Check_Float_Overflow --
13442 --------------------------
13444 -- pragma Check_Float_Overflow;
13446 when Pragma_Check_Float_Overflow
=>
13448 Check_Valid_Configuration_Pragma
;
13449 Check_Arg_Count
(0);
13450 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
13456 -- pragma Check_Name (check_IDENTIFIER);
13458 when Pragma_Check_Name
=>
13460 Check_No_Identifiers
;
13461 Check_Valid_Configuration_Pragma
;
13462 Check_Arg_Count
(1);
13463 Check_Arg_Is_Identifier
(Arg1
);
13466 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
13469 for J
in Check_Names
.First
.. Check_Names
.Last
loop
13470 if Check_Names
.Table
(J
) = Nam
then
13475 Check_Names
.Append
(Nam
);
13482 -- This is the old style syntax, which is still allowed in all modes:
13484 -- pragma Check_Policy ([Name =>] CHECK_KIND
13485 -- [Policy =>] POLICY_IDENTIFIER);
13487 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
13489 -- CHECK_KIND ::= IDENTIFIER |
13492 -- Type_Invariant'Class |
13495 -- This is the new style syntax, compatible with Assertion_Policy
13496 -- and also allowed in all modes.
13498 -- Pragma Check_Policy (
13499 -- CHECK_KIND => POLICY_IDENTIFIER
13500 -- {, CHECK_KIND => POLICY_IDENTIFIER});
13502 -- Note: the identifiers Name and Policy are not allowed as
13503 -- Check_Kind values. This avoids ambiguities between the old and
13504 -- new form syntax.
13506 when Pragma_Check_Policy
=> Check_Policy
: declare
13511 Check_At_Least_N_Arguments
(1);
13513 -- A Check_Policy pragma can appear either as a configuration
13514 -- pragma, or in a declarative part or a package spec (see RM
13515 -- 11.5(5) for rules for Suppress/Unsuppress which are also
13516 -- followed for Check_Policy).
13518 if not Is_Configuration_Pragma
then
13519 Check_Is_In_Decl_Part_Or_Package_Spec
;
13522 -- Figure out if we have the old or new syntax. We have the
13523 -- old syntax if the first argument has no identifier, or the
13524 -- identifier is Name.
13526 if Nkind
(Arg1
) /= N_Pragma_Argument_Association
13527 or else Nam_In
(Chars
(Arg1
), No_Name
, Name_Name
)
13531 Check_Arg_Count
(2);
13532 Check_Optional_Identifier
(Arg1
, Name_Name
);
13533 Kind
:= Get_Pragma_Arg
(Arg1
);
13534 Rewrite_Assertion_Kind
(Kind
,
13535 From_Policy
=> Comes_From_Source
(N
));
13536 Check_Arg_Is_Identifier
(Arg1
);
13538 -- Check forbidden check kind
13540 if Nam_In
(Chars
(Kind
), Name_Name
, Name_Policy
) then
13541 Error_Msg_Name_2
:= Chars
(Kind
);
13543 ("pragma% does not allow% as check name", Arg1
);
13548 Check_Optional_Identifier
(Arg2
, Name_Policy
);
13549 Check_Arg_Is_One_Of
13551 Name_On
, Name_Off
, Name_Check
, Name_Disable
, Name_Ignore
);
13553 -- And chain pragma on the Check_Policy_List for search
13555 Set_Next_Pragma
(N
, Opt
.Check_Policy_List
);
13556 Opt
.Check_Policy_List
:= N
;
13558 -- For the new syntax, what we do is to convert each argument to
13559 -- an old syntax equivalent. We do that because we want to chain
13560 -- old style Check_Policy pragmas for the search (we don't want
13561 -- to have to deal with multiple arguments in the search).
13572 while Present
(Arg
) loop
13573 LocP
:= Sloc
(Arg
);
13574 Argx
:= Get_Pragma_Arg
(Arg
);
13576 -- Kind must be specified
13578 if Nkind
(Arg
) /= N_Pragma_Argument_Association
13579 or else Chars
(Arg
) = No_Name
13582 ("missing assertion kind for pragma%", Arg
);
13585 -- Construct equivalent old form syntax Check_Policy
13586 -- pragma and insert it to get remaining checks.
13590 Chars
=> Name_Check_Policy
,
13591 Pragma_Argument_Associations
=> New_List
(
13592 Make_Pragma_Argument_Association
(LocP
,
13594 Make_Identifier
(LocP
, Chars
(Arg
))),
13595 Make_Pragma_Argument_Association
(Sloc
(Argx
),
13596 Expression
=> Argx
)));
13600 -- For a configuration pragma, insert old form in
13601 -- the corresponding file.
13603 if Is_Configuration_Pragma
then
13604 Insert_After
(N
, New_P
);
13608 Insert_Action
(N
, New_P
);
13612 -- Rewrite original Check_Policy pragma to null, since we
13613 -- have converted it into a series of old syntax pragmas.
13615 Rewrite
(N
, Make_Null_Statement
(Loc
));
13625 -- pragma Comment (static_string_EXPRESSION)
13627 -- Processing for pragma Comment shares the circuitry for pragma
13628 -- Ident. The only differences are that Ident enforces a limit of 31
13629 -- characters on its argument, and also enforces limitations on
13630 -- placement for DEC compatibility. Pragma Comment shares neither of
13631 -- these restrictions.
13633 -------------------
13634 -- Common_Object --
13635 -------------------
13637 -- pragma Common_Object (
13638 -- [Internal =>] LOCAL_NAME
13639 -- [, [External =>] EXTERNAL_SYMBOL]
13640 -- [, [Size =>] EXTERNAL_SYMBOL]);
13642 -- Processing for this pragma is shared with Psect_Object
13644 ------------------------
13645 -- Compile_Time_Error --
13646 ------------------------
13648 -- pragma Compile_Time_Error
13649 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13651 when Pragma_Compile_Time_Error
=>
13653 Process_Compile_Time_Warning_Or_Error
;
13655 --------------------------
13656 -- Compile_Time_Warning --
13657 --------------------------
13659 -- pragma Compile_Time_Warning
13660 -- (boolean_EXPRESSION, static_string_EXPRESSION);
13662 when Pragma_Compile_Time_Warning
=>
13664 Process_Compile_Time_Warning_Or_Error
;
13666 ---------------------------
13667 -- Compiler_Unit_Warning --
13668 ---------------------------
13670 -- pragma Compiler_Unit_Warning;
13674 -- Originally, we had only pragma Compiler_Unit, and it resulted in
13675 -- errors not warnings. This means that we had introduced a big extra
13676 -- inertia to compiler changes, since even if we implemented a new
13677 -- feature, and even if all versions to be used for bootstrapping
13678 -- implemented this new feature, we could not use it, since old
13679 -- compilers would give errors for using this feature in units
13680 -- having Compiler_Unit pragmas.
13682 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
13683 -- problem. We no longer have any units mentioning Compiler_Unit,
13684 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
13685 -- and thus generates a warning which can be ignored. So that deals
13686 -- with the problem of old compilers not implementing the newer form
13689 -- Newer compilers recognize the new pragma, but generate warning
13690 -- messages instead of errors, which again can be ignored in the
13691 -- case of an old compiler which implements a wanted new feature
13692 -- but at the time felt like warning about it for older compilers.
13694 -- We retain Compiler_Unit so that new compilers can be used to build
13695 -- older run-times that use this pragma. That's an unusual case, but
13696 -- it's easy enough to handle, so why not?
13698 when Pragma_Compiler_Unit
13699 | Pragma_Compiler_Unit_Warning
13702 Check_Arg_Count
(0);
13704 -- Only recognized in main unit
13706 if Current_Sem_Unit
= Main_Unit
then
13707 Compiler_Unit
:= True;
13710 -----------------------------
13711 -- Complete_Representation --
13712 -----------------------------
13714 -- pragma Complete_Representation;
13716 when Pragma_Complete_Representation
=>
13718 Check_Arg_Count
(0);
13720 if Nkind
(Parent
(N
)) /= N_Record_Representation_Clause
then
13722 ("pragma & must appear within record representation clause");
13725 ----------------------------
13726 -- Complex_Representation --
13727 ----------------------------
13729 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
13731 when Pragma_Complex_Representation
=> Complex_Representation
: declare
13738 Check_Arg_Count
(1);
13739 Check_Optional_Identifier
(Arg1
, Name_Entity
);
13740 Check_Arg_Is_Local_Name
(Arg1
);
13741 E_Id
:= Get_Pragma_Arg
(Arg1
);
13743 if Etype
(E_Id
) = Any_Type
then
13747 E
:= Entity
(E_Id
);
13749 if not Is_Record_Type
(E
) then
13751 ("argument for pragma% must be record type", Arg1
);
13754 Ent
:= First_Entity
(E
);
13757 or else No
(Next_Entity
(Ent
))
13758 or else Present
(Next_Entity
(Next_Entity
(Ent
)))
13759 or else not Is_Floating_Point_Type
(Etype
(Ent
))
13760 or else Etype
(Ent
) /= Etype
(Next_Entity
(Ent
))
13763 ("record for pragma% must have two fields of the same "
13764 & "floating-point type", Arg1
);
13767 Set_Has_Complex_Representation
(Base_Type
(E
));
13769 -- We need to treat the type has having a non-standard
13770 -- representation, for back-end purposes, even though in
13771 -- general a complex will have the default representation
13772 -- of a record with two real components.
13774 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
13776 end Complex_Representation
;
13778 -------------------------
13779 -- Component_Alignment --
13780 -------------------------
13782 -- pragma Component_Alignment (
13783 -- [Form =>] ALIGNMENT_CHOICE
13784 -- [, [Name =>] type_LOCAL_NAME]);
13786 -- ALIGNMENT_CHOICE ::=
13788 -- | Component_Size_4
13792 when Pragma_Component_Alignment
=> Component_AlignmentP
: declare
13793 Args
: Args_List
(1 .. 2);
13794 Names
: constant Name_List
(1 .. 2) := (
13798 Form
: Node_Id
renames Args
(1);
13799 Name
: Node_Id
renames Args
(2);
13801 Atype
: Component_Alignment_Kind
;
13806 Gather_Associations
(Names
, Args
);
13809 Error_Pragma
("missing Form argument for pragma%");
13812 Check_Arg_Is_Identifier
(Form
);
13814 -- Get proper alignment, note that Default = Component_Size on all
13815 -- machines we have so far, and we want to set this value rather
13816 -- than the default value to indicate that it has been explicitly
13817 -- set (and thus will not get overridden by the default component
13818 -- alignment for the current scope)
13820 if Chars
(Form
) = Name_Component_Size
then
13821 Atype
:= Calign_Component_Size
;
13823 elsif Chars
(Form
) = Name_Component_Size_4
then
13824 Atype
:= Calign_Component_Size_4
;
13826 elsif Chars
(Form
) = Name_Default
then
13827 Atype
:= Calign_Component_Size
;
13829 elsif Chars
(Form
) = Name_Storage_Unit
then
13830 Atype
:= Calign_Storage_Unit
;
13834 ("invalid Form parameter for pragma%", Form
);
13837 -- The pragma appears in a configuration file
13839 if No
(Parent
(N
)) then
13840 Check_Valid_Configuration_Pragma
;
13842 -- Capture the component alignment in a global variable when
13843 -- the pragma appears in a configuration file. Note that the
13844 -- scope stack is empty at this point and cannot be used to
13845 -- store the alignment value.
13847 Configuration_Component_Alignment
:= Atype
;
13849 -- Case with no name, supplied, affects scope table entry
13851 elsif No
(Name
) then
13853 (Scope_Stack
.Last
).Component_Alignment_Default
:= Atype
;
13855 -- Case of name supplied
13858 Check_Arg_Is_Local_Name
(Name
);
13860 Typ
:= Entity
(Name
);
13863 or else Rep_Item_Too_Early
(Typ
, N
)
13867 Typ
:= Underlying_Type
(Typ
);
13870 if not Is_Record_Type
(Typ
)
13871 and then not Is_Array_Type
(Typ
)
13874 ("Name parameter of pragma% must identify record or "
13875 & "array type", Name
);
13878 -- An explicit Component_Alignment pragma overrides an
13879 -- implicit pragma Pack, but not an explicit one.
13881 if not Has_Pragma_Pack
(Base_Type
(Typ
)) then
13882 Set_Is_Packed
(Base_Type
(Typ
), False);
13883 Set_Component_Alignment
(Base_Type
(Typ
), Atype
);
13886 end Component_AlignmentP
;
13888 --------------------------------
13889 -- Constant_After_Elaboration --
13890 --------------------------------
13892 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
13894 when Pragma_Constant_After_Elaboration
=> Constant_After_Elaboration
:
13896 Obj_Decl
: Node_Id
;
13897 Obj_Id
: Entity_Id
;
13901 Check_No_Identifiers
;
13902 Check_At_Most_N_Arguments
(1);
13904 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
13906 -- Object declaration
13908 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
13911 -- Otherwise the pragma is associated with an illegal construct
13918 Obj_Id
:= Defining_Entity
(Obj_Decl
);
13920 -- The object declaration must be a library-level variable which
13921 -- is either explicitly initialized or obtains a value during the
13922 -- elaboration of a package body (SPARK RM 3.3.1).
13924 if Ekind
(Obj_Id
) = E_Variable
then
13925 if not Is_Library_Level_Entity
(Obj_Id
) then
13927 ("pragma % must apply to a library level variable");
13931 -- Otherwise the pragma applies to a constant, which is illegal
13934 Error_Pragma
("pragma % must apply to a variable declaration");
13938 -- A pragma that applies to a Ghost entity becomes Ghost for the
13939 -- purposes of legality checks and removal of ignored Ghost code.
13941 Mark_Ghost_Pragma
(N
, Obj_Id
);
13943 -- Chain the pragma on the contract for completeness
13945 Add_Contract_Item
(N
, Obj_Id
);
13947 -- Analyze the Boolean expression (if any)
13949 if Present
(Arg1
) then
13950 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
13952 end Constant_After_Elaboration
;
13954 --------------------
13955 -- Contract_Cases --
13956 --------------------
13958 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
13960 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
13962 -- CASE_GUARD ::= boolean_EXPRESSION | others
13964 -- CONSEQUENCE ::= boolean_EXPRESSION
13966 -- Characteristics:
13968 -- * Analysis - The annotation undergoes initial checks to verify
13969 -- the legal placement and context. Secondary checks preanalyze the
13972 -- Analyze_Contract_Cases_In_Decl_Part
13974 -- * Expansion - The annotation is expanded during the expansion of
13975 -- the related subprogram [body] contract as performed in:
13977 -- Expand_Subprogram_Contract
13979 -- * Template - The annotation utilizes the generic template of the
13980 -- related subprogram [body] when it is:
13982 -- aspect on subprogram declaration
13983 -- aspect on stand-alone subprogram body
13984 -- pragma on stand-alone subprogram body
13986 -- The annotation must prepare its own template when it is:
13988 -- pragma on subprogram declaration
13990 -- * Globals - Capture of global references must occur after full
13993 -- * Instance - The annotation is instantiated automatically when
13994 -- the related generic subprogram [body] is instantiated except for
13995 -- the "pragma on subprogram declaration" case. In that scenario
13996 -- the annotation must instantiate itself.
13998 when Pragma_Contract_Cases
=> Contract_Cases
: declare
13999 Spec_Id
: Entity_Id
;
14000 Subp_Decl
: Node_Id
;
14001 Subp_Spec
: Node_Id
;
14005 Check_No_Identifiers
;
14006 Check_Arg_Count
(1);
14008 -- Ensure the proper placement of the pragma. Contract_Cases must
14009 -- be associated with a subprogram declaration or a body that acts
14013 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
14017 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
14020 -- Generic subprogram
14022 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
14025 -- Body acts as spec
14027 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
14028 and then No
(Corresponding_Spec
(Subp_Decl
))
14032 -- Body stub acts as spec
14034 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
14035 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
14041 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
14042 Subp_Spec
:= Specification
(Subp_Decl
);
14044 -- Pragma Contract_Cases is forbidden on null procedures, as
14045 -- this may lead to potential ambiguities in behavior when
14046 -- interface null procedures are involved.
14048 if Nkind
(Subp_Spec
) = N_Procedure_Specification
14049 and then Null_Present
(Subp_Spec
)
14051 Error_Msg_N
(Fix_Error
14052 ("pragma % cannot apply to null procedure"), N
);
14061 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
14063 -- A pragma that applies to a Ghost entity becomes Ghost for the
14064 -- purposes of legality checks and removal of ignored Ghost code.
14066 Mark_Ghost_Pragma
(N
, Spec_Id
);
14067 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
14069 -- Chain the pragma on the contract for further processing by
14070 -- Analyze_Contract_Cases_In_Decl_Part.
14072 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
14074 -- Fully analyze the pragma when it appears inside an entry
14075 -- or subprogram body because it cannot benefit from forward
14078 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
14080 N_Subprogram_Body_Stub
)
14082 -- The legality checks of pragma Contract_Cases are affected by
14083 -- the SPARK mode in effect and the volatility of the context.
14084 -- Analyze all pragmas in a specific order.
14086 Analyze_If_Present
(Pragma_SPARK_Mode
);
14087 Analyze_If_Present
(Pragma_Volatile_Function
);
14088 Analyze_Contract_Cases_In_Decl_Part
(N
);
14090 end Contract_Cases
;
14096 -- pragma Controlled (first_subtype_LOCAL_NAME);
14098 when Pragma_Controlled
=> Controlled
: declare
14102 Check_No_Identifiers
;
14103 Check_Arg_Count
(1);
14104 Check_Arg_Is_Local_Name
(Arg1
);
14105 Arg
:= Get_Pragma_Arg
(Arg1
);
14107 if not Is_Entity_Name
(Arg
)
14108 or else not Is_Access_Type
(Entity
(Arg
))
14110 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
14112 Set_Has_Pragma_Controlled
(Base_Type
(Entity
(Arg
)));
14120 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
14121 -- [Entity =>] LOCAL_NAME);
14123 when Pragma_Convention
=> Convention
: declare
14126 pragma Warnings
(Off
, C
);
14127 pragma Warnings
(Off
, E
);
14130 Check_Arg_Order
((Name_Convention
, Name_Entity
));
14131 Check_Ada_83_Warning
;
14132 Check_Arg_Count
(2);
14133 Process_Convention
(C
, E
);
14135 -- A pragma that applies to a Ghost entity becomes Ghost for the
14136 -- purposes of legality checks and removal of ignored Ghost code.
14138 Mark_Ghost_Pragma
(N
, E
);
14141 ---------------------------
14142 -- Convention_Identifier --
14143 ---------------------------
14145 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
14146 -- [Convention =>] convention_IDENTIFIER);
14148 when Pragma_Convention_Identifier
=> Convention_Identifier
: declare
14154 Check_Arg_Order
((Name_Name
, Name_Convention
));
14155 Check_Arg_Count
(2);
14156 Check_Optional_Identifier
(Arg1
, Name_Name
);
14157 Check_Optional_Identifier
(Arg2
, Name_Convention
);
14158 Check_Arg_Is_Identifier
(Arg1
);
14159 Check_Arg_Is_Identifier
(Arg2
);
14160 Idnam
:= Chars
(Get_Pragma_Arg
(Arg1
));
14161 Cname
:= Chars
(Get_Pragma_Arg
(Arg2
));
14163 if Is_Convention_Name
(Cname
) then
14164 Record_Convention_Identifier
14165 (Idnam
, Get_Convention_Id
(Cname
));
14168 ("second arg for % pragma must be convention", Arg2
);
14170 end Convention_Identifier
;
14176 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
14178 when Pragma_CPP_Class
=>
14181 if Warn_On_Obsolescent_Feature
then
14183 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
14184 & "effect; replace it by pragma import?j?", N
);
14187 Check_Arg_Count
(1);
14191 Chars
=> Name_Import
,
14192 Pragma_Argument_Associations
=> New_List
(
14193 Make_Pragma_Argument_Association
(Loc
,
14194 Expression
=> Make_Identifier
(Loc
, Name_CPP
)),
14195 New_Copy
(First
(Pragma_Argument_Associations
(N
))))));
14198 ---------------------
14199 -- CPP_Constructor --
14200 ---------------------
14202 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
14203 -- [, [External_Name =>] static_string_EXPRESSION ]
14204 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14206 when Pragma_CPP_Constructor
=> CPP_Constructor
: declare
14209 Def_Id
: Entity_Id
;
14210 Tag_Typ
: Entity_Id
;
14214 Check_At_Least_N_Arguments
(1);
14215 Check_At_Most_N_Arguments
(3);
14216 Check_Optional_Identifier
(Arg1
, Name_Entity
);
14217 Check_Arg_Is_Local_Name
(Arg1
);
14219 Id
:= Get_Pragma_Arg
(Arg1
);
14220 Find_Program_Unit_Name
(Id
);
14222 -- If we did not find the name, we are done
14224 if Etype
(Id
) = Any_Type
then
14228 Def_Id
:= Entity
(Id
);
14230 -- Check if already defined as constructor
14232 if Is_Constructor
(Def_Id
) then
14234 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1
);
14238 if Ekind
(Def_Id
) = E_Function
14239 and then (Is_CPP_Class
(Etype
(Def_Id
))
14240 or else (Is_Class_Wide_Type
(Etype
(Def_Id
))
14242 Is_CPP_Class
(Root_Type
(Etype
(Def_Id
)))))
14244 if Scope
(Def_Id
) /= Scope
(Etype
(Def_Id
)) then
14246 ("'C'P'P constructor must be defined in the scope of "
14247 & "its returned type", Arg1
);
14250 if Arg_Count
>= 2 then
14251 Set_Imported
(Def_Id
);
14252 Set_Is_Public
(Def_Id
);
14253 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
14256 Set_Has_Completion
(Def_Id
);
14257 Set_Is_Constructor
(Def_Id
);
14258 Set_Convention
(Def_Id
, Convention_CPP
);
14260 -- Imported C++ constructors are not dispatching primitives
14261 -- because in C++ they don't have a dispatch table slot.
14262 -- However, in Ada the constructor has the profile of a
14263 -- function that returns a tagged type and therefore it has
14264 -- been treated as a primitive operation during semantic
14265 -- analysis. We now remove it from the list of primitive
14266 -- operations of the type.
14268 if Is_Tagged_Type
(Etype
(Def_Id
))
14269 and then not Is_Class_Wide_Type
(Etype
(Def_Id
))
14270 and then Is_Dispatching_Operation
(Def_Id
)
14272 Tag_Typ
:= Etype
(Def_Id
);
14274 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
14275 while Present
(Elmt
) and then Node
(Elmt
) /= Def_Id
loop
14279 Remove_Elmt
(Primitive_Operations
(Tag_Typ
), Elmt
);
14280 Set_Is_Dispatching_Operation
(Def_Id
, False);
14283 -- For backward compatibility, if the constructor returns a
14284 -- class wide type, and we internally change the return type to
14285 -- the corresponding root type.
14287 if Is_Class_Wide_Type
(Etype
(Def_Id
)) then
14288 Set_Etype
(Def_Id
, Root_Type
(Etype
(Def_Id
)));
14292 ("pragma% requires function returning a 'C'P'P_Class type",
14295 end CPP_Constructor
;
14301 when Pragma_CPP_Virtual
=>
14304 if Warn_On_Obsolescent_Feature
then
14306 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
14314 when Pragma_CPP_Vtable
=>
14317 if Warn_On_Obsolescent_Feature
then
14319 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
14327 -- pragma CPU (EXPRESSION);
14329 when Pragma_CPU
=> CPU
: declare
14330 P
: constant Node_Id
:= Parent
(N
);
14336 Check_No_Identifiers
;
14337 Check_Arg_Count
(1);
14341 if Nkind
(P
) = N_Subprogram_Body
then
14342 Check_In_Main_Program
;
14344 Arg
:= Get_Pragma_Arg
(Arg1
);
14345 Analyze_And_Resolve
(Arg
, Any_Integer
);
14347 Ent
:= Defining_Unit_Name
(Specification
(P
));
14349 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
14350 Ent
:= Defining_Identifier
(Ent
);
14355 if not Is_OK_Static_Expression
(Arg
) then
14356 Flag_Non_Static_Expr
14357 ("main subprogram affinity is not static!", Arg
);
14360 -- If constraint error, then we already signalled an error
14362 elsif Raises_Constraint_Error
(Arg
) then
14365 -- Otherwise check in range
14369 CPU_Id
: constant Entity_Id
:= RTE
(RE_CPU_Range
);
14370 -- This is the entity System.Multiprocessors.CPU_Range;
14372 Val
: constant Uint
:= Expr_Value
(Arg
);
14375 if Val
< Expr_Value
(Type_Low_Bound
(CPU_Id
))
14377 Val
> Expr_Value
(Type_High_Bound
(CPU_Id
))
14380 ("main subprogram CPU is out of range", Arg1
);
14386 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
14390 elsif Nkind
(P
) = N_Task_Definition
then
14391 Arg
:= Get_Pragma_Arg
(Arg1
);
14392 Ent
:= Defining_Identifier
(Parent
(P
));
14394 -- The expression must be analyzed in the special manner
14395 -- described in "Handling of Default and Per-Object
14396 -- Expressions" in sem.ads.
14398 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_CPU_Range
));
14400 -- Anything else is incorrect
14406 -- Check duplicate pragma before we chain the pragma in the Rep
14407 -- Item chain of Ent.
14409 Check_Duplicate_Pragma
(Ent
);
14410 Record_Rep_Item
(Ent
, N
);
14413 --------------------
14414 -- Deadline_Floor --
14415 --------------------
14417 -- pragma Deadline_Floor (time_span_EXPRESSION);
14419 when Pragma_Deadline_Floor
=> Deadline_Floor
: declare
14420 P
: constant Node_Id
:= Parent
(N
);
14426 Check_No_Identifiers
;
14427 Check_Arg_Count
(1);
14429 Arg
:= Get_Pragma_Arg
(Arg1
);
14431 -- The expression must be analyzed in the special manner described
14432 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
14434 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
14436 -- Only protected types allowed
14438 if Nkind
(P
) /= N_Protected_Definition
then
14442 Ent
:= Defining_Identifier
(Parent
(P
));
14444 -- Check duplicate pragma before we chain the pragma in the Rep
14445 -- Item chain of Ent.
14447 Check_Duplicate_Pragma
(Ent
);
14448 Record_Rep_Item
(Ent
, N
);
14450 end Deadline_Floor
;
14456 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
14458 when Pragma_Debug
=> Debug
: declare
14465 -- The condition for executing the call is that the expander
14466 -- is active and that we are not ignoring this debug pragma.
14471 (Expander_Active
and then not Is_Ignored
(N
)),
14474 if not Is_Ignored
(N
) then
14475 Set_SCO_Pragma_Enabled
(Loc
);
14478 if Arg_Count
= 2 then
14480 Make_And_Then
(Loc
,
14481 Left_Opnd
=> Relocate_Node
(Cond
),
14482 Right_Opnd
=> Get_Pragma_Arg
(Arg1
));
14483 Call
:= Get_Pragma_Arg
(Arg2
);
14485 Call
:= Get_Pragma_Arg
(Arg1
);
14488 if Nkind_In
(Call
, N_Expanded_Name
,
14491 N_Indexed_Component
,
14492 N_Selected_Component
)
14494 -- If this pragma Debug comes from source, its argument was
14495 -- parsed as a name form (which is syntactically identical).
14496 -- In a generic context a parameterless call will be left as
14497 -- an expanded name (if global) or selected_component if local.
14498 -- Change it to a procedure call statement now.
14500 Change_Name_To_Procedure_Call_Statement
(Call
);
14502 elsif Nkind
(Call
) = N_Procedure_Call_Statement
then
14504 -- Already in the form of a procedure call statement: nothing
14505 -- to do (could happen in case of an internally generated
14511 -- All other cases: diagnose error
14514 ("argument of pragma ""Debug"" is not procedure call",
14519 -- Rewrite into a conditional with an appropriate condition. We
14520 -- wrap the procedure call in a block so that overhead from e.g.
14521 -- use of the secondary stack does not generate execution overhead
14522 -- for suppressed conditions.
14524 -- Normally the analysis that follows will freeze the subprogram
14525 -- being called. However, if the call is to a null procedure,
14526 -- we want to freeze it before creating the block, because the
14527 -- analysis that follows may be done with expansion disabled, in
14528 -- which case the body will not be generated, leading to spurious
14531 if Nkind
(Call
) = N_Procedure_Call_Statement
14532 and then Is_Entity_Name
(Name
(Call
))
14534 Analyze
(Name
(Call
));
14535 Freeze_Before
(N
, Entity
(Name
(Call
)));
14539 Make_Implicit_If_Statement
(N
,
14541 Then_Statements
=> New_List
(
14542 Make_Block_Statement
(Loc
,
14543 Handled_Statement_Sequence
=>
14544 Make_Handled_Sequence_Of_Statements
(Loc
,
14545 Statements
=> New_List
(Relocate_Node
(Call
)))))));
14548 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
14549 -- after analysis of the normally rewritten node, to capture all
14550 -- references to entities, which avoids issuing wrong warnings
14551 -- about unused entities.
14553 if GNATprove_Mode
then
14554 Rewrite
(N
, Make_Null_Statement
(Loc
));
14562 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
14564 when Pragma_Debug_Policy
=>
14566 Check_Arg_Count
(1);
14567 Check_No_Identifiers
;
14568 Check_Arg_Is_Identifier
(Arg1
);
14570 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
14571 -- rewrite it that way, and let the rest of the checking come
14572 -- from analyzing the rewritten pragma.
14576 Chars
=> Name_Check_Policy
,
14577 Pragma_Argument_Associations
=> New_List
(
14578 Make_Pragma_Argument_Association
(Loc
,
14579 Expression
=> Make_Identifier
(Loc
, Name_Debug
)),
14581 Make_Pragma_Argument_Association
(Loc
,
14582 Expression
=> Get_Pragma_Arg
(Arg1
)))));
14585 -------------------------------
14586 -- Default_Initial_Condition --
14587 -------------------------------
14589 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
14591 when Pragma_Default_Initial_Condition
=> DIC
: declare
14598 Check_No_Identifiers
;
14599 Check_At_Most_N_Arguments
(1);
14603 while Present
(Stmt
) loop
14605 -- Skip prior pragmas, but check for duplicates
14607 if Nkind
(Stmt
) = N_Pragma
then
14608 if Pragma_Name
(Stmt
) = Pname
then
14615 -- Skip internally generated code. Note that derived type
14616 -- declarations of untagged types with discriminants are
14617 -- rewritten as private type declarations.
14619 elsif not Comes_From_Source
(Stmt
)
14620 and then Nkind
(Stmt
) /= N_Private_Type_Declaration
14624 -- The associated private type [extension] has been found, stop
14627 elsif Nkind_In
(Stmt
, N_Private_Extension_Declaration
,
14628 N_Private_Type_Declaration
)
14630 Typ
:= Defining_Entity
(Stmt
);
14633 -- The pragma does not apply to a legal construct, issue an
14634 -- error and stop the analysis.
14641 Stmt
:= Prev
(Stmt
);
14644 -- The pragma does not apply to a legal construct, issue an error
14645 -- and stop the analysis.
14652 -- A pragma that applies to a Ghost entity becomes Ghost for the
14653 -- purposes of legality checks and removal of ignored Ghost code.
14655 Mark_Ghost_Pragma
(N
, Typ
);
14657 -- The pragma signals that the type defines its own DIC assertion
14660 Set_Has_Own_DIC
(Typ
);
14662 -- Chain the pragma on the rep item chain for further processing
14664 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
14666 -- Create the declaration of the procedure which verifies the
14667 -- assertion expression of pragma DIC at runtime.
14669 Build_DIC_Procedure_Declaration
(Typ
);
14672 ----------------------------------
14673 -- Default_Scalar_Storage_Order --
14674 ----------------------------------
14676 -- pragma Default_Scalar_Storage_Order
14677 -- (High_Order_First | Low_Order_First);
14679 when Pragma_Default_Scalar_Storage_Order
=> DSSO
: declare
14680 Default
: Character;
14684 Check_Arg_Count
(1);
14686 -- Default_Scalar_Storage_Order can appear as a configuration
14687 -- pragma, or in a declarative part of a package spec.
14689 if not Is_Configuration_Pragma
then
14690 Check_Is_In_Decl_Part_Or_Package_Spec
;
14693 Check_No_Identifiers
;
14694 Check_Arg_Is_One_Of
14695 (Arg1
, Name_High_Order_First
, Name_Low_Order_First
);
14696 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
14697 Default
:= Fold_Upper
(Name_Buffer
(1));
14699 if not Support_Nondefault_SSO_On_Target
14700 and then (Ttypes
.Bytes_Big_Endian
/= (Default
= 'H'))
14702 if Warn_On_Unrecognized_Pragma
then
14704 ("non-default Scalar_Storage_Order not supported "
14705 & "on target?g?", N
);
14707 ("\pragma Default_Scalar_Storage_Order ignored?g?", N
);
14710 -- Here set the specified default
14713 Opt
.Default_SSO
:= Default
;
14717 --------------------------
14718 -- Default_Storage_Pool --
14719 --------------------------
14721 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
14723 when Pragma_Default_Storage_Pool
=> Default_Storage_Pool
: declare
14728 Check_Arg_Count
(1);
14730 -- Default_Storage_Pool can appear as a configuration pragma, or
14731 -- in a declarative part of a package spec.
14733 if not Is_Configuration_Pragma
then
14734 Check_Is_In_Decl_Part_Or_Package_Spec
;
14737 if From_Aspect_Specification
(N
) then
14739 E
: constant Entity_Id
:= Entity
(Corresponding_Aspect
(N
));
14741 if not In_Open_Scopes
(E
) then
14743 ("aspect must apply to package or subprogram", N
);
14748 if Present
(Arg1
) then
14749 Pool
:= Get_Pragma_Arg
(Arg1
);
14751 -- Case of Default_Storage_Pool (null);
14753 if Nkind
(Pool
) = N_Null
then
14756 -- This is an odd case, this is not really an expression,
14757 -- so we don't have a type for it. So just set the type to
14760 Set_Etype
(Pool
, Empty
);
14762 -- Case of Default_Storage_Pool (storage_pool_NAME);
14765 -- If it's a configuration pragma, then the only allowed
14766 -- argument is "null".
14768 if Is_Configuration_Pragma
then
14769 Error_Pragma_Arg
("NULL expected", Arg1
);
14772 -- The expected type for a non-"null" argument is
14773 -- Root_Storage_Pool'Class, and the pool must be a variable.
14775 Analyze_And_Resolve
14776 (Pool
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
14778 if Is_Variable
(Pool
) then
14780 -- A pragma that applies to a Ghost entity becomes Ghost
14781 -- for the purposes of legality checks and removal of
14782 -- ignored Ghost code.
14784 Mark_Ghost_Pragma
(N
, Entity
(Pool
));
14788 ("default storage pool must be a variable", Arg1
);
14792 -- Record the pool name (or null). Freeze.Freeze_Entity for an
14793 -- access type will use this information to set the appropriate
14794 -- attributes of the access type. If the pragma appears in a
14795 -- generic unit it is ignored, given that it may refer to a
14798 if not Inside_A_Generic
then
14799 Default_Pool
:= Pool
;
14802 end Default_Storage_Pool
;
14808 -- pragma Depends (DEPENDENCY_RELATION);
14810 -- DEPENDENCY_RELATION ::=
14812 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
14814 -- DEPENDENCY_CLAUSE ::=
14815 -- OUTPUT_LIST =>[+] INPUT_LIST
14816 -- | NULL_DEPENDENCY_CLAUSE
14818 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
14820 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
14822 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
14824 -- OUTPUT ::= NAME | FUNCTION_RESULT
14827 -- where FUNCTION_RESULT is a function Result attribute_reference
14829 -- Characteristics:
14831 -- * Analysis - The annotation undergoes initial checks to verify
14832 -- the legal placement and context. Secondary checks fully analyze
14833 -- the dependency clauses in:
14835 -- Analyze_Depends_In_Decl_Part
14837 -- * Expansion - None.
14839 -- * Template - The annotation utilizes the generic template of the
14840 -- related subprogram [body] when it is:
14842 -- aspect on subprogram declaration
14843 -- aspect on stand-alone subprogram body
14844 -- pragma on stand-alone subprogram body
14846 -- The annotation must prepare its own template when it is:
14848 -- pragma on subprogram declaration
14850 -- * Globals - Capture of global references must occur after full
14853 -- * Instance - The annotation is instantiated automatically when
14854 -- the related generic subprogram [body] is instantiated except for
14855 -- the "pragma on subprogram declaration" case. In that scenario
14856 -- the annotation must instantiate itself.
14858 when Pragma_Depends
=> Depends
: declare
14860 Spec_Id
: Entity_Id
;
14861 Subp_Decl
: Node_Id
;
14864 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
14868 -- Chain the pragma on the contract for further processing by
14869 -- Analyze_Depends_In_Decl_Part.
14871 Add_Contract_Item
(N
, Spec_Id
);
14873 -- Fully analyze the pragma when it appears inside an entry
14874 -- or subprogram body because it cannot benefit from forward
14877 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
14879 N_Subprogram_Body_Stub
)
14881 -- The legality checks of pragmas Depends and Global are
14882 -- affected by the SPARK mode in effect and the volatility
14883 -- of the context. In addition these two pragmas are subject
14884 -- to an inherent order:
14889 -- Analyze all these pragmas in the order outlined above
14891 Analyze_If_Present
(Pragma_SPARK_Mode
);
14892 Analyze_If_Present
(Pragma_Volatile_Function
);
14893 Analyze_If_Present
(Pragma_Global
);
14894 Analyze_Depends_In_Decl_Part
(N
);
14899 ---------------------
14900 -- Detect_Blocking --
14901 ---------------------
14903 -- pragma Detect_Blocking;
14905 when Pragma_Detect_Blocking
=>
14907 Check_Arg_Count
(0);
14908 Check_Valid_Configuration_Pragma
;
14909 Detect_Blocking
:= True;
14911 ------------------------------------
14912 -- Disable_Atomic_Synchronization --
14913 ------------------------------------
14915 -- pragma Disable_Atomic_Synchronization [(Entity)];
14917 when Pragma_Disable_Atomic_Synchronization
=>
14919 Process_Disable_Enable_Atomic_Sync
(Name_Suppress
);
14921 -------------------
14922 -- Discard_Names --
14923 -------------------
14925 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
14927 when Pragma_Discard_Names
=> Discard_Names
: declare
14932 Check_Ada_83_Warning
;
14934 -- Deal with configuration pragma case
14936 if Arg_Count
= 0 and then Is_Configuration_Pragma
then
14937 Global_Discard_Names
:= True;
14940 -- Otherwise, check correct appropriate context
14943 Check_Is_In_Decl_Part_Or_Package_Spec
;
14945 if Arg_Count
= 0 then
14947 -- If there is no parameter, then from now on this pragma
14948 -- applies to any enumeration, exception or tagged type
14949 -- defined in the current declarative part, and recursively
14950 -- to any nested scope.
14952 Set_Discard_Names
(Current_Scope
);
14956 Check_Arg_Count
(1);
14957 Check_Optional_Identifier
(Arg1
, Name_On
);
14958 Check_Arg_Is_Local_Name
(Arg1
);
14960 E_Id
:= Get_Pragma_Arg
(Arg1
);
14962 if Etype
(E_Id
) = Any_Type
then
14966 E
:= Entity
(E_Id
);
14968 -- A pragma that applies to a Ghost entity becomes Ghost for
14969 -- the purposes of legality checks and removal of ignored
14972 Mark_Ghost_Pragma
(N
, E
);
14974 if (Is_First_Subtype
(E
)
14976 (Is_Enumeration_Type
(E
) or else Is_Tagged_Type
(E
)))
14977 or else Ekind
(E
) = E_Exception
14979 Set_Discard_Names
(E
);
14980 Record_Rep_Item
(E
, N
);
14984 ("inappropriate entity for pragma%", Arg1
);
14990 ------------------------
14991 -- Dispatching_Domain --
14992 ------------------------
14994 -- pragma Dispatching_Domain (EXPRESSION);
14996 when Pragma_Dispatching_Domain
=> Dispatching_Domain
: declare
14997 P
: constant Node_Id
:= Parent
(N
);
15003 Check_No_Identifiers
;
15004 Check_Arg_Count
(1);
15006 -- This pragma is born obsolete, but not the aspect
15008 if not From_Aspect_Specification
(N
) then
15010 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
15013 if Nkind
(P
) = N_Task_Definition
then
15014 Arg
:= Get_Pragma_Arg
(Arg1
);
15015 Ent
:= Defining_Identifier
(Parent
(P
));
15017 -- A pragma that applies to a Ghost entity becomes Ghost for
15018 -- the purposes of legality checks and removal of ignored Ghost
15021 Mark_Ghost_Pragma
(N
, Ent
);
15023 -- The expression must be analyzed in the special manner
15024 -- described in "Handling of Default and Per-Object
15025 -- Expressions" in sem.ads.
15027 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Dispatching_Domain
));
15029 -- Check duplicate pragma before we chain the pragma in the Rep
15030 -- Item chain of Ent.
15032 Check_Duplicate_Pragma
(Ent
);
15033 Record_Rep_Item
(Ent
, N
);
15035 -- Anything else is incorrect
15040 end Dispatching_Domain
;
15046 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
15048 when Pragma_Elaborate
=> Elaborate
: declare
15053 -- Pragma must be in context items list of a compilation unit
15055 if not Is_In_Context_Clause
then
15059 -- Must be at least one argument
15061 if Arg_Count
= 0 then
15062 Error_Pragma
("pragma% requires at least one argument");
15065 -- In Ada 83 mode, there can be no items following it in the
15066 -- context list except other pragmas and implicit with clauses
15067 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
15068 -- placement rule does not apply.
15070 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
15072 while Present
(Citem
) loop
15073 if Nkind
(Citem
) = N_Pragma
15074 or else (Nkind
(Citem
) = N_With_Clause
15075 and then Implicit_With
(Citem
))
15080 ("(Ada 83) pragma% must be at end of context clause");
15087 -- Finally, the arguments must all be units mentioned in a with
15088 -- clause in the same context clause. Note we already checked (in
15089 -- Par.Prag) that the arguments are all identifiers or selected
15093 Outer
: while Present
(Arg
) loop
15094 Citem
:= First
(List_Containing
(N
));
15095 Inner
: while Citem
/= N
loop
15096 if Nkind
(Citem
) = N_With_Clause
15097 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
15099 Set_Elaborate_Present
(Citem
, True);
15100 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
15102 -- With the pragma present, elaboration calls on
15103 -- subprograms from the named unit need no further
15104 -- checks, as long as the pragma appears in the current
15105 -- compilation unit. If the pragma appears in some unit
15106 -- in the context, there might still be a need for an
15107 -- Elaborate_All_Desirable from the current compilation
15108 -- to the named unit, so we keep the check enabled. This
15109 -- does not apply in SPARK mode, where we allow pragma
15110 -- Elaborate, but we don't trust it to be right so we
15111 -- will still insist on the Elaborate_All.
15113 if Legacy_Elaboration_Checks
15114 and then In_Extended_Main_Source_Unit
(N
)
15115 and then SPARK_Mode
/= On
15117 Set_Suppress_Elaboration_Warnings
15118 (Entity
(Name
(Citem
)));
15129 ("argument of pragma% is not withed unit", Arg
);
15136 -------------------
15137 -- Elaborate_All --
15138 -------------------
15140 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
15142 when Pragma_Elaborate_All
=> Elaborate_All
: declare
15147 Check_Ada_83_Warning
;
15149 -- Pragma must be in context items list of a compilation unit
15151 if not Is_In_Context_Clause
then
15155 -- Must be at least one argument
15157 if Arg_Count
= 0 then
15158 Error_Pragma
("pragma% requires at least one argument");
15161 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
15162 -- have to appear at the end of the context clause, but may
15163 -- appear mixed in with other items, even in Ada 83 mode.
15165 -- Final check: the arguments must all be units mentioned in
15166 -- a with clause in the same context clause. Note that we
15167 -- already checked (in Par.Prag) that all the arguments are
15168 -- either identifiers or selected components.
15171 Outr
: while Present
(Arg
) loop
15172 Citem
:= First
(List_Containing
(N
));
15173 Innr
: while Citem
/= N
loop
15174 if Nkind
(Citem
) = N_With_Clause
15175 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
15177 Set_Elaborate_All_Present
(Citem
, True);
15178 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
15180 -- Suppress warnings and elaboration checks on the named
15181 -- unit if the pragma is in the current compilation, as
15182 -- for pragma Elaborate.
15184 if Legacy_Elaboration_Checks
15185 and then In_Extended_Main_Source_Unit
(N
)
15187 Set_Suppress_Elaboration_Warnings
15188 (Entity
(Name
(Citem
)));
15198 Set_Error_Posted
(N
);
15200 ("argument of pragma% is not withed unit", Arg
);
15207 --------------------
15208 -- Elaborate_Body --
15209 --------------------
15211 -- pragma Elaborate_Body [( library_unit_NAME )];
15213 when Pragma_Elaborate_Body
=> Elaborate_Body
: declare
15214 Cunit_Node
: Node_Id
;
15215 Cunit_Ent
: Entity_Id
;
15218 Check_Ada_83_Warning
;
15219 Check_Valid_Library_Unit_Pragma
;
15221 if Nkind
(N
) = N_Null_Statement
then
15225 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
15226 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
15228 -- A pragma that applies to a Ghost entity becomes Ghost for the
15229 -- purposes of legality checks and removal of ignored Ghost code.
15231 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
15233 if Nkind_In
(Unit
(Cunit_Node
), N_Package_Body
,
15236 Error_Pragma
("pragma% must refer to a spec, not a body");
15238 Set_Body_Required
(Cunit_Node
);
15239 Set_Has_Pragma_Elaborate_Body
(Cunit_Ent
);
15241 -- If we are in dynamic elaboration mode, then we suppress
15242 -- elaboration warnings for the unit, since it is definitely
15243 -- fine NOT to do dynamic checks at the first level (and such
15244 -- checks will be suppressed because no elaboration boolean
15245 -- is created for Elaborate_Body packages).
15247 -- But in the static model of elaboration, Elaborate_Body is
15248 -- definitely NOT good enough to ensure elaboration safety on
15249 -- its own, since the body may WITH other units that are not
15250 -- safe from an elaboration point of view, so a client must
15251 -- still do an Elaborate_All on such units.
15253 -- Debug flag -gnatdD restores the old behavior of 3.13, where
15254 -- Elaborate_Body always suppressed elab warnings.
15256 if Legacy_Elaboration_Checks
15257 and then (Dynamic_Elaboration_Checks
or Debug_Flag_DD
)
15259 Set_Suppress_Elaboration_Warnings
(Cunit_Ent
);
15262 end Elaborate_Body
;
15264 ------------------------
15265 -- Elaboration_Checks --
15266 ------------------------
15268 -- pragma Elaboration_Checks (Static | Dynamic);
15270 when Pragma_Elaboration_Checks
=>
15272 Check_Arg_Count
(1);
15273 Check_Arg_Is_One_Of
(Arg1
, Name_Static
, Name_Dynamic
);
15275 -- Set flag accordingly (ignore attempt at dynamic elaboration
15276 -- checks in SPARK mode).
15278 Dynamic_Elaboration_Checks
:=
15279 Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Dynamic
;
15285 -- pragma Eliminate (
15286 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
15287 -- [Entity =>] IDENTIFIER |
15288 -- SELECTED_COMPONENT |
15290 -- [, Source_Location => SOURCE_TRACE]);
15292 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
15293 -- SOURCE_TRACE ::= STRING_LITERAL
15295 when Pragma_Eliminate
=> Eliminate
: declare
15296 Args
: Args_List
(1 .. 5);
15297 Names
: constant Name_List
(1 .. 5) := (
15300 Name_Parameter_Types
,
15302 Name_Source_Location
);
15304 -- Note : Parameter_Types and Result_Type are leftovers from
15305 -- prior implementations of the pragma. They are not generated
15306 -- by the gnatelim tool, and play no role in selecting which
15307 -- of a set of overloaded names is chosen for elimination.
15309 Unit_Name
: Node_Id
renames Args
(1);
15310 Entity
: Node_Id
renames Args
(2);
15311 Parameter_Types
: Node_Id
renames Args
(3);
15312 Result_Type
: Node_Id
renames Args
(4);
15313 Source_Location
: Node_Id
renames Args
(5);
15317 Check_Valid_Configuration_Pragma
;
15318 Gather_Associations
(Names
, Args
);
15320 if No
(Unit_Name
) then
15321 Error_Pragma
("missing Unit_Name argument for pragma%");
15325 and then (Present
(Parameter_Types
)
15327 Present
(Result_Type
)
15329 Present
(Source_Location
))
15331 Error_Pragma
("missing Entity argument for pragma%");
15334 if (Present
(Parameter_Types
)
15336 Present
(Result_Type
))
15338 Present
(Source_Location
)
15341 ("parameter profile and source location cannot be used "
15342 & "together in pragma%");
15345 Process_Eliminate_Pragma
15354 -----------------------------------
15355 -- Enable_Atomic_Synchronization --
15356 -----------------------------------
15358 -- pragma Enable_Atomic_Synchronization [(Entity)];
15360 when Pragma_Enable_Atomic_Synchronization
=>
15362 Process_Disable_Enable_Atomic_Sync
(Name_Unsuppress
);
15369 -- [ Convention =>] convention_IDENTIFIER,
15370 -- [ Entity =>] LOCAL_NAME
15371 -- [, [External_Name =>] static_string_EXPRESSION ]
15372 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15374 when Pragma_Export
=> Export
: declare
15376 Def_Id
: Entity_Id
;
15378 pragma Warnings
(Off
, C
);
15381 Check_Ada_83_Warning
;
15385 Name_External_Name
,
15388 Check_At_Least_N_Arguments
(2);
15389 Check_At_Most_N_Arguments
(4);
15391 -- In Relaxed_RM_Semantics, support old Ada 83 style:
15392 -- pragma Export (Entity, "external name");
15394 if Relaxed_RM_Semantics
15395 and then Arg_Count
= 2
15396 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
15399 Def_Id
:= Get_Pragma_Arg
(Arg1
);
15402 if not Is_Entity_Name
(Def_Id
) then
15403 Error_Pragma_Arg
("entity name required", Arg1
);
15406 Def_Id
:= Entity
(Def_Id
);
15407 Set_Exported
(Def_Id
, Arg1
);
15410 Process_Convention
(C
, Def_Id
);
15412 -- A pragma that applies to a Ghost entity becomes Ghost for
15413 -- the purposes of legality checks and removal of ignored Ghost
15416 Mark_Ghost_Pragma
(N
, Def_Id
);
15418 if Ekind
(Def_Id
) /= E_Constant
then
15419 Note_Possible_Modification
15420 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
15423 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
, N
);
15424 Set_Exported
(Def_Id
, Arg2
);
15427 -- If the entity is a deferred constant, propagate the information
15428 -- to the full view, because gigi elaborates the full view only.
15430 if Ekind
(Def_Id
) = E_Constant
15431 and then Present
(Full_View
(Def_Id
))
15434 Id2
: constant Entity_Id
:= Full_View
(Def_Id
);
15436 Set_Is_Exported
(Id2
, Is_Exported
(Def_Id
));
15437 Set_First_Rep_Item
(Id2
, First_Rep_Item
(Def_Id
));
15438 Set_Interface_Name
(Id2
, Einfo
.Interface_Name
(Def_Id
));
15443 ---------------------
15444 -- Export_Function --
15445 ---------------------
15447 -- pragma Export_Function (
15448 -- [Internal =>] LOCAL_NAME
15449 -- [, [External =>] EXTERNAL_SYMBOL]
15450 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15451 -- [, [Result_Type =>] TYPE_DESIGNATOR]
15452 -- [, [Mechanism =>] MECHANISM]
15453 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15455 -- EXTERNAL_SYMBOL ::=
15457 -- | static_string_EXPRESSION
15459 -- PARAMETER_TYPES ::=
15461 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15463 -- TYPE_DESIGNATOR ::=
15465 -- | subtype_Name ' Access
15469 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15471 -- MECHANISM_ASSOCIATION ::=
15472 -- [formal_parameter_NAME =>] MECHANISM_NAME
15474 -- MECHANISM_NAME ::=
15478 when Pragma_Export_Function
=> Export_Function
: declare
15479 Args
: Args_List
(1 .. 6);
15480 Names
: constant Name_List
(1 .. 6) := (
15483 Name_Parameter_Types
,
15486 Name_Result_Mechanism
);
15488 Internal
: Node_Id
renames Args
(1);
15489 External
: Node_Id
renames Args
(2);
15490 Parameter_Types
: Node_Id
renames Args
(3);
15491 Result_Type
: Node_Id
renames Args
(4);
15492 Mechanism
: Node_Id
renames Args
(5);
15493 Result_Mechanism
: Node_Id
renames Args
(6);
15497 Gather_Associations
(Names
, Args
);
15498 Process_Extended_Import_Export_Subprogram_Pragma
(
15499 Arg_Internal
=> Internal
,
15500 Arg_External
=> External
,
15501 Arg_Parameter_Types
=> Parameter_Types
,
15502 Arg_Result_Type
=> Result_Type
,
15503 Arg_Mechanism
=> Mechanism
,
15504 Arg_Result_Mechanism
=> Result_Mechanism
);
15505 end Export_Function
;
15507 -------------------
15508 -- Export_Object --
15509 -------------------
15511 -- pragma Export_Object (
15512 -- [Internal =>] LOCAL_NAME
15513 -- [, [External =>] EXTERNAL_SYMBOL]
15514 -- [, [Size =>] EXTERNAL_SYMBOL]);
15516 -- EXTERNAL_SYMBOL ::=
15518 -- | static_string_EXPRESSION
15520 -- PARAMETER_TYPES ::=
15522 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15524 -- TYPE_DESIGNATOR ::=
15526 -- | subtype_Name ' Access
15530 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15532 -- MECHANISM_ASSOCIATION ::=
15533 -- [formal_parameter_NAME =>] MECHANISM_NAME
15535 -- MECHANISM_NAME ::=
15539 when Pragma_Export_Object
=> Export_Object
: declare
15540 Args
: Args_List
(1 .. 3);
15541 Names
: constant Name_List
(1 .. 3) := (
15546 Internal
: Node_Id
renames Args
(1);
15547 External
: Node_Id
renames Args
(2);
15548 Size
: Node_Id
renames Args
(3);
15552 Gather_Associations
(Names
, Args
);
15553 Process_Extended_Import_Export_Object_Pragma
(
15554 Arg_Internal
=> Internal
,
15555 Arg_External
=> External
,
15559 ----------------------
15560 -- Export_Procedure --
15561 ----------------------
15563 -- pragma Export_Procedure (
15564 -- [Internal =>] LOCAL_NAME
15565 -- [, [External =>] EXTERNAL_SYMBOL]
15566 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15567 -- [, [Mechanism =>] MECHANISM]);
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_Procedure
=> Export_Procedure
: declare
15593 Args
: Args_List
(1 .. 4);
15594 Names
: constant Name_List
(1 .. 4) := (
15597 Name_Parameter_Types
,
15600 Internal
: Node_Id
renames Args
(1);
15601 External
: Node_Id
renames Args
(2);
15602 Parameter_Types
: Node_Id
renames Args
(3);
15603 Mechanism
: Node_Id
renames Args
(4);
15607 Gather_Associations
(Names
, Args
);
15608 Process_Extended_Import_Export_Subprogram_Pragma
(
15609 Arg_Internal
=> Internal
,
15610 Arg_External
=> External
,
15611 Arg_Parameter_Types
=> Parameter_Types
,
15612 Arg_Mechanism
=> Mechanism
);
15613 end Export_Procedure
;
15619 -- pragma Export_Value (
15620 -- [Value =>] static_integer_EXPRESSION,
15621 -- [Link_Name =>] static_string_EXPRESSION);
15623 when Pragma_Export_Value
=>
15625 Check_Arg_Order
((Name_Value
, Name_Link_Name
));
15626 Check_Arg_Count
(2);
15628 Check_Optional_Identifier
(Arg1
, Name_Value
);
15629 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
15631 Check_Optional_Identifier
(Arg2
, Name_Link_Name
);
15632 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
15634 -----------------------------
15635 -- Export_Valued_Procedure --
15636 -----------------------------
15638 -- pragma Export_Valued_Procedure (
15639 -- [Internal =>] LOCAL_NAME
15640 -- [, [External =>] EXTERNAL_SYMBOL,]
15641 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15642 -- [, [Mechanism =>] MECHANISM]);
15644 -- EXTERNAL_SYMBOL ::=
15646 -- | static_string_EXPRESSION
15648 -- PARAMETER_TYPES ::=
15650 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15652 -- TYPE_DESIGNATOR ::=
15654 -- | subtype_Name ' Access
15658 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15660 -- MECHANISM_ASSOCIATION ::=
15661 -- [formal_parameter_NAME =>] MECHANISM_NAME
15663 -- MECHANISM_NAME ::=
15667 when Pragma_Export_Valued_Procedure
=>
15668 Export_Valued_Procedure
: declare
15669 Args
: Args_List
(1 .. 4);
15670 Names
: constant Name_List
(1 .. 4) := (
15673 Name_Parameter_Types
,
15676 Internal
: Node_Id
renames Args
(1);
15677 External
: Node_Id
renames Args
(2);
15678 Parameter_Types
: Node_Id
renames Args
(3);
15679 Mechanism
: Node_Id
renames Args
(4);
15683 Gather_Associations
(Names
, Args
);
15684 Process_Extended_Import_Export_Subprogram_Pragma
(
15685 Arg_Internal
=> Internal
,
15686 Arg_External
=> External
,
15687 Arg_Parameter_Types
=> Parameter_Types
,
15688 Arg_Mechanism
=> Mechanism
);
15689 end Export_Valued_Procedure
;
15691 -------------------
15692 -- Extend_System --
15693 -------------------
15695 -- pragma Extend_System ([Name =>] Identifier);
15697 when Pragma_Extend_System
=>
15699 Check_Valid_Configuration_Pragma
;
15700 Check_Arg_Count
(1);
15701 Check_Optional_Identifier
(Arg1
, Name_Name
);
15702 Check_Arg_Is_Identifier
(Arg1
);
15704 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
15707 and then Name_Buffer
(1 .. 4) = "aux_"
15709 if Present
(System_Extend_Pragma_Arg
) then
15710 if Chars
(Get_Pragma_Arg
(Arg1
)) =
15711 Chars
(Expression
(System_Extend_Pragma_Arg
))
15715 Error_Msg_Sloc
:= Sloc
(System_Extend_Pragma_Arg
);
15716 Error_Pragma
("pragma% conflicts with that #");
15720 System_Extend_Pragma_Arg
:= Arg1
;
15722 if not GNAT_Mode
then
15723 System_Extend_Unit
:= Arg1
;
15727 Error_Pragma
("incorrect name for pragma%, must be Aux_xxx");
15730 ------------------------
15731 -- Extensions_Allowed --
15732 ------------------------
15734 -- pragma Extensions_Allowed (ON | OFF);
15736 when Pragma_Extensions_Allowed
=>
15738 Check_Arg_Count
(1);
15739 Check_No_Identifiers
;
15740 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
15742 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
15743 Extensions_Allowed
:= True;
15744 Ada_Version
:= Ada_Version_Type
'Last;
15747 Extensions_Allowed
:= False;
15748 Ada_Version
:= Ada_Version_Explicit
;
15749 Ada_Version_Pragma
:= Empty
;
15752 ------------------------
15753 -- Extensions_Visible --
15754 ------------------------
15756 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
15758 -- Characteristics:
15760 -- * Analysis - The annotation is fully analyzed immediately upon
15761 -- elaboration as its expression must be static.
15763 -- * Expansion - None.
15765 -- * Template - The annotation utilizes the generic template of the
15766 -- related subprogram [body] when it is:
15768 -- aspect on subprogram declaration
15769 -- aspect on stand-alone subprogram body
15770 -- pragma on stand-alone subprogram body
15772 -- The annotation must prepare its own template when it is:
15774 -- pragma on subprogram declaration
15776 -- * Globals - Capture of global references must occur after full
15779 -- * Instance - The annotation is instantiated automatically when
15780 -- the related generic subprogram [body] is instantiated except for
15781 -- the "pragma on subprogram declaration" case. In that scenario
15782 -- the annotation must instantiate itself.
15784 when Pragma_Extensions_Visible
=> Extensions_Visible
: declare
15785 Formal
: Entity_Id
;
15786 Has_OK_Formal
: Boolean := False;
15787 Spec_Id
: Entity_Id
;
15788 Subp_Decl
: Node_Id
;
15792 Check_No_Identifiers
;
15793 Check_At_Most_N_Arguments
(1);
15796 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
15798 -- Abstract subprogram declaration
15800 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
15803 -- Generic subprogram declaration
15805 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
15808 -- Body acts as spec
15810 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
15811 and then No
(Corresponding_Spec
(Subp_Decl
))
15815 -- Body stub acts as spec
15817 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
15818 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
15822 -- Subprogram declaration
15824 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
15827 -- Otherwise the pragma is associated with an illegal construct
15830 Error_Pragma
("pragma % must apply to a subprogram");
15834 -- Mark the pragma as Ghost if the related subprogram is also
15835 -- Ghost. This also ensures that any expansion performed further
15836 -- below will produce Ghost nodes.
15838 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
15839 Mark_Ghost_Pragma
(N
, Spec_Id
);
15841 -- Chain the pragma on the contract for completeness
15843 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
15845 -- The legality checks of pragma Extension_Visible are affected
15846 -- by the SPARK mode in effect. Analyze all pragmas in specific
15849 Analyze_If_Present
(Pragma_SPARK_Mode
);
15851 -- Examine the formals of the related subprogram
15853 Formal
:= First_Formal
(Spec_Id
);
15854 while Present
(Formal
) loop
15856 -- At least one of the formals is of a specific tagged type,
15857 -- the pragma is legal.
15859 if Is_Specific_Tagged_Type
(Etype
(Formal
)) then
15860 Has_OK_Formal
:= True;
15863 -- A generic subprogram with at least one formal of a private
15864 -- type ensures the legality of the pragma because the actual
15865 -- may be specifically tagged. Note that this is verified by
15866 -- the check above at instantiation time.
15868 elsif Is_Private_Type
(Etype
(Formal
))
15869 and then Is_Generic_Type
(Etype
(Formal
))
15871 Has_OK_Formal
:= True;
15875 Next_Formal
(Formal
);
15878 if not Has_OK_Formal
then
15879 Error_Msg_Name_1
:= Pname
;
15880 Error_Msg_N
(Fix_Error
("incorrect placement of pragma %"), N
);
15882 ("\subprogram & lacks parameter of specific tagged or "
15883 & "generic private type", N
, Spec_Id
);
15888 -- Analyze the Boolean expression (if any)
15890 if Present
(Arg1
) then
15891 Check_Static_Boolean_Expression
15892 (Expression
(Get_Argument
(N
, Spec_Id
)));
15894 end Extensions_Visible
;
15900 -- pragma External (
15901 -- [ Convention =>] convention_IDENTIFIER,
15902 -- [ Entity =>] LOCAL_NAME
15903 -- [, [External_Name =>] static_string_EXPRESSION ]
15904 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15906 when Pragma_External
=> External
: declare
15909 pragma Warnings
(Off
, C
);
15916 Name_External_Name
,
15918 Check_At_Least_N_Arguments
(2);
15919 Check_At_Most_N_Arguments
(4);
15920 Process_Convention
(C
, E
);
15922 -- A pragma that applies to a Ghost entity becomes Ghost for the
15923 -- purposes of legality checks and removal of ignored Ghost code.
15925 Mark_Ghost_Pragma
(N
, E
);
15927 Note_Possible_Modification
15928 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
15929 Process_Interface_Name
(E
, Arg3
, Arg4
, N
);
15930 Set_Exported
(E
, Arg2
);
15933 --------------------------
15934 -- External_Name_Casing --
15935 --------------------------
15937 -- pragma External_Name_Casing (
15938 -- UPPERCASE | LOWERCASE
15939 -- [, AS_IS | UPPERCASE | LOWERCASE]);
15941 when Pragma_External_Name_Casing
=>
15943 Check_No_Identifiers
;
15945 if Arg_Count
= 2 then
15946 Check_Arg_Is_One_Of
15947 (Arg2
, Name_As_Is
, Name_Uppercase
, Name_Lowercase
);
15949 case Chars
(Get_Pragma_Arg
(Arg2
)) is
15951 Opt
.External_Name_Exp_Casing
:= As_Is
;
15953 when Name_Uppercase
=>
15954 Opt
.External_Name_Exp_Casing
:= Uppercase
;
15956 when Name_Lowercase
=>
15957 Opt
.External_Name_Exp_Casing
:= Lowercase
;
15964 Check_Arg_Count
(1);
15967 Check_Arg_Is_One_Of
(Arg1
, Name_Uppercase
, Name_Lowercase
);
15969 case Chars
(Get_Pragma_Arg
(Arg1
)) is
15970 when Name_Uppercase
=>
15971 Opt
.External_Name_Imp_Casing
:= Uppercase
;
15973 when Name_Lowercase
=>
15974 Opt
.External_Name_Imp_Casing
:= Lowercase
;
15984 -- pragma Fast_Math;
15986 when Pragma_Fast_Math
=>
15988 Check_No_Identifiers
;
15989 Check_Valid_Configuration_Pragma
;
15992 --------------------------
15993 -- Favor_Top_Level --
15994 --------------------------
15996 -- pragma Favor_Top_Level (type_NAME);
15998 when Pragma_Favor_Top_Level
=> Favor_Top_Level
: declare
16003 Check_No_Identifiers
;
16004 Check_Arg_Count
(1);
16005 Check_Arg_Is_Local_Name
(Arg1
);
16006 Typ
:= Entity
(Get_Pragma_Arg
(Arg1
));
16008 -- A pragma that applies to a Ghost entity becomes Ghost for the
16009 -- purposes of legality checks and removal of ignored Ghost code.
16011 Mark_Ghost_Pragma
(N
, Typ
);
16013 -- If it's an access-to-subprogram type (in particular, not a
16014 -- subtype), set the flag on that type.
16016 if Is_Access_Subprogram_Type
(Typ
) then
16017 Set_Can_Use_Internal_Rep
(Typ
, False);
16019 -- Otherwise it's an error (name denotes the wrong sort of entity)
16023 ("access-to-subprogram type expected",
16024 Get_Pragma_Arg
(Arg1
));
16026 end Favor_Top_Level
;
16028 ---------------------------
16029 -- Finalize_Storage_Only --
16030 ---------------------------
16032 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
16034 when Pragma_Finalize_Storage_Only
=> Finalize_Storage
: declare
16035 Assoc
: constant Node_Id
:= Arg1
;
16036 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
16041 Check_No_Identifiers
;
16042 Check_Arg_Count
(1);
16043 Check_Arg_Is_Local_Name
(Arg1
);
16045 Find_Type
(Type_Id
);
16046 Typ
:= Entity
(Type_Id
);
16049 or else Rep_Item_Too_Early
(Typ
, N
)
16053 Typ
:= Underlying_Type
(Typ
);
16056 if not Is_Controlled
(Typ
) then
16057 Error_Pragma
("pragma% must specify controlled type");
16060 Check_First_Subtype
(Arg1
);
16062 if Finalize_Storage_Only
(Typ
) then
16063 Error_Pragma
("duplicate pragma%, only one allowed");
16065 elsif not Rep_Item_Too_Late
(Typ
, N
) then
16066 Set_Finalize_Storage_Only
(Base_Type
(Typ
), True);
16068 end Finalize_Storage
;
16074 -- pragma Ghost [ (boolean_EXPRESSION) ];
16076 when Pragma_Ghost
=> Ghost
: declare
16080 Orig_Stmt
: Node_Id
;
16081 Prev_Id
: Entity_Id
;
16086 Check_No_Identifiers
;
16087 Check_At_Most_N_Arguments
(1);
16091 while Present
(Stmt
) loop
16093 -- Skip prior pragmas, but check for duplicates
16095 if Nkind
(Stmt
) = N_Pragma
then
16096 if Pragma_Name
(Stmt
) = Pname
then
16103 -- Task unit declared without a definition cannot be subject to
16104 -- pragma Ghost (SPARK RM 6.9(19)).
16106 elsif Nkind_In
(Stmt
, N_Single_Task_Declaration
,
16107 N_Task_Type_Declaration
)
16109 Error_Pragma
("pragma % cannot apply to a task type");
16112 -- Skip internally generated code
16114 elsif not Comes_From_Source
(Stmt
) then
16115 Orig_Stmt
:= Original_Node
(Stmt
);
16117 -- When pragma Ghost applies to an untagged derivation, the
16118 -- derivation is transformed into a [sub]type declaration.
16120 if Nkind_In
(Stmt
, N_Full_Type_Declaration
,
16121 N_Subtype_Declaration
)
16122 and then Comes_From_Source
(Orig_Stmt
)
16123 and then Nkind
(Orig_Stmt
) = N_Full_Type_Declaration
16124 and then Nkind
(Type_Definition
(Orig_Stmt
)) =
16125 N_Derived_Type_Definition
16127 Id
:= Defining_Entity
(Stmt
);
16130 -- When pragma Ghost applies to an object declaration which
16131 -- is initialized by means of a function call that returns
16132 -- on the secondary stack, the object declaration becomes a
16135 elsif Nkind
(Stmt
) = N_Object_Renaming_Declaration
16136 and then Comes_From_Source
(Orig_Stmt
)
16137 and then Nkind
(Orig_Stmt
) = N_Object_Declaration
16139 Id
:= Defining_Entity
(Stmt
);
16142 -- When pragma Ghost applies to an expression function, the
16143 -- expression function is transformed into a subprogram.
16145 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
16146 and then Comes_From_Source
(Orig_Stmt
)
16147 and then Nkind
(Orig_Stmt
) = N_Expression_Function
16149 Id
:= Defining_Entity
(Stmt
);
16153 -- The pragma applies to a legal construct, stop the traversal
16155 elsif Nkind_In
(Stmt
, N_Abstract_Subprogram_Declaration
,
16156 N_Full_Type_Declaration
,
16157 N_Generic_Subprogram_Declaration
,
16158 N_Object_Declaration
,
16159 N_Private_Extension_Declaration
,
16160 N_Private_Type_Declaration
,
16161 N_Subprogram_Declaration
,
16162 N_Subtype_Declaration
)
16164 Id
:= Defining_Entity
(Stmt
);
16167 -- The pragma does not apply to a legal construct, issue an
16168 -- error and stop the analysis.
16172 ("pragma % must apply to an object, package, subprogram "
16177 Stmt
:= Prev
(Stmt
);
16180 Context
:= Parent
(N
);
16182 -- Handle compilation units
16184 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
16185 Context
:= Unit
(Parent
(Context
));
16188 -- Protected and task types cannot be subject to pragma Ghost
16189 -- (SPARK RM 6.9(19)).
16191 if Nkind_In
(Context
, N_Protected_Body
, N_Protected_Definition
)
16193 Error_Pragma
("pragma % cannot apply to a protected type");
16196 elsif Nkind_In
(Context
, N_Task_Body
, N_Task_Definition
) then
16197 Error_Pragma
("pragma % cannot apply to a task type");
16203 -- When pragma Ghost is associated with a [generic] package, it
16204 -- appears in the visible declarations.
16206 if Nkind
(Context
) = N_Package_Specification
16207 and then Present
(Visible_Declarations
(Context
))
16208 and then List_Containing
(N
) = Visible_Declarations
(Context
)
16210 Id
:= Defining_Entity
(Context
);
16212 -- Pragma Ghost applies to a stand-alone subprogram body
16214 elsif Nkind
(Context
) = N_Subprogram_Body
16215 and then No
(Corresponding_Spec
(Context
))
16217 Id
:= Defining_Entity
(Context
);
16219 -- Pragma Ghost applies to a subprogram declaration that acts
16220 -- as a compilation unit.
16222 elsif Nkind
(Context
) = N_Subprogram_Declaration
then
16223 Id
:= Defining_Entity
(Context
);
16225 -- Pragma Ghost applies to a generic subprogram
16227 elsif Nkind
(Context
) = N_Generic_Subprogram_Declaration
then
16228 Id
:= Defining_Entity
(Specification
(Context
));
16234 ("pragma % must apply to an object, package, subprogram or "
16239 -- Handle completions of types and constants that are subject to
16242 if Is_Record_Type
(Id
) or else Ekind
(Id
) = E_Constant
then
16243 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
16245 if Present
(Prev_Id
) and then not Is_Ghost_Entity
(Prev_Id
) then
16246 Error_Msg_Name_1
:= Pname
;
16248 -- The full declaration of a deferred constant cannot be
16249 -- subject to pragma Ghost unless the deferred declaration
16250 -- is also Ghost (SPARK RM 6.9(9)).
16252 if Ekind
(Prev_Id
) = E_Constant
then
16253 Error_Msg_Name_1
:= Pname
;
16254 Error_Msg_NE
(Fix_Error
16255 ("pragma % must apply to declaration of deferred "
16256 & "constant &"), N
, Id
);
16259 -- Pragma Ghost may appear on the full view of an incomplete
16260 -- type because the incomplete declaration lacks aspects and
16261 -- cannot be subject to pragma Ghost.
16263 elsif Ekind
(Prev_Id
) = E_Incomplete_Type
then
16266 -- The full declaration of a type cannot be subject to
16267 -- pragma Ghost unless the partial view is also Ghost
16268 -- (SPARK RM 6.9(9)).
16271 Error_Msg_NE
(Fix_Error
16272 ("pragma % must apply to partial view of type &"),
16278 -- A synchronized object cannot be subject to pragma Ghost
16279 -- (SPARK RM 6.9(19)).
16281 elsif Ekind
(Id
) = E_Variable
then
16282 if Is_Protected_Type
(Etype
(Id
)) then
16283 Error_Pragma
("pragma % cannot apply to a protected object");
16286 elsif Is_Task_Type
(Etype
(Id
)) then
16287 Error_Pragma
("pragma % cannot apply to a task object");
16292 -- Analyze the Boolean expression (if any)
16294 if Present
(Arg1
) then
16295 Expr
:= Get_Pragma_Arg
(Arg1
);
16297 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
16299 if Is_OK_Static_Expression
(Expr
) then
16301 -- "Ghostness" cannot be turned off once enabled within a
16302 -- region (SPARK RM 6.9(6)).
16304 if Is_False
(Expr_Value
(Expr
))
16305 and then Ghost_Mode
> None
16308 ("pragma % with value False cannot appear in enabled "
16313 -- Otherwie the expression is not static
16317 ("expression of pragma % must be static", Expr
);
16322 Set_Is_Ghost_Entity
(Id
);
16329 -- pragma Global (GLOBAL_SPECIFICATION);
16331 -- GLOBAL_SPECIFICATION ::=
16334 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
16336 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
16338 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
16339 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
16340 -- GLOBAL_ITEM ::= NAME
16342 -- Characteristics:
16344 -- * Analysis - The annotation undergoes initial checks to verify
16345 -- the legal placement and context. Secondary checks fully analyze
16346 -- the dependency clauses in:
16348 -- Analyze_Global_In_Decl_Part
16350 -- * Expansion - None.
16352 -- * Template - The annotation utilizes the generic template of the
16353 -- related subprogram [body] when it is:
16355 -- aspect on subprogram declaration
16356 -- aspect on stand-alone subprogram body
16357 -- pragma on stand-alone subprogram body
16359 -- The annotation must prepare its own template when it is:
16361 -- pragma on subprogram declaration
16363 -- * Globals - Capture of global references must occur after full
16366 -- * Instance - The annotation is instantiated automatically when
16367 -- the related generic subprogram [body] is instantiated except for
16368 -- the "pragma on subprogram declaration" case. In that scenario
16369 -- the annotation must instantiate itself.
16371 when Pragma_Global
=> Global
: declare
16373 Spec_Id
: Entity_Id
;
16374 Subp_Decl
: Node_Id
;
16377 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
16381 -- Chain the pragma on the contract for further processing by
16382 -- Analyze_Global_In_Decl_Part.
16384 Add_Contract_Item
(N
, Spec_Id
);
16386 -- Fully analyze the pragma when it appears inside an entry
16387 -- or subprogram body because it cannot benefit from forward
16390 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
16392 N_Subprogram_Body_Stub
)
16394 -- The legality checks of pragmas Depends and Global are
16395 -- affected by the SPARK mode in effect and the volatility
16396 -- of the context. In addition these two pragmas are subject
16397 -- to an inherent order:
16402 -- Analyze all these pragmas in the order outlined above
16404 Analyze_If_Present
(Pragma_SPARK_Mode
);
16405 Analyze_If_Present
(Pragma_Volatile_Function
);
16406 Analyze_Global_In_Decl_Part
(N
);
16407 Analyze_If_Present
(Pragma_Depends
);
16416 -- pragma Ident (static_string_EXPRESSION)
16418 -- Note: pragma Comment shares this processing. Pragma Ident is
16419 -- identical in effect to pragma Commment.
16421 when Pragma_Comment
16429 Check_Arg_Count
(1);
16430 Check_No_Identifiers
;
16431 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16434 Str
:= Expr_Value_S
(Get_Pragma_Arg
(Arg1
));
16441 GP
:= Parent
(Parent
(N
));
16443 if Nkind_In
(GP
, N_Package_Declaration
,
16444 N_Generic_Package_Declaration
)
16449 -- If we have a compilation unit, then record the ident value,
16450 -- checking for improper duplication.
16452 if Nkind
(GP
) = N_Compilation_Unit
then
16453 CS
:= Ident_String
(Current_Sem_Unit
);
16455 if Present
(CS
) then
16457 -- If we have multiple instances, concatenate them, but
16458 -- not in ASIS, where we want the original tree.
16460 if not ASIS_Mode
then
16461 Start_String
(Strval
(CS
));
16462 Store_String_Char
(' ');
16463 Store_String_Chars
(Strval
(Str
));
16464 Set_Strval
(CS
, End_String
);
16468 Set_Ident_String
(Current_Sem_Unit
, Str
);
16471 -- For subunits, we just ignore the Ident, since in GNAT these
16472 -- are not separate object files, and hence not separate units
16473 -- in the unit table.
16475 elsif Nkind
(GP
) = N_Subunit
then
16481 -------------------
16482 -- Ignore_Pragma --
16483 -------------------
16485 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
16487 -- Entirely handled in the parser, nothing to do here
16489 when Pragma_Ignore_Pragma
=>
16492 ----------------------------
16493 -- Implementation_Defined --
16494 ----------------------------
16496 -- pragma Implementation_Defined (LOCAL_NAME);
16498 -- Marks previously declared entity as implementation defined. For
16499 -- an overloaded entity, applies to the most recent homonym.
16501 -- pragma Implementation_Defined;
16503 -- The form with no arguments appears anywhere within a scope, most
16504 -- typically a package spec, and indicates that all entities that are
16505 -- defined within the package spec are Implementation_Defined.
16507 when Pragma_Implementation_Defined
=> Implementation_Defined
: declare
16512 Check_No_Identifiers
;
16514 -- Form with no arguments
16516 if Arg_Count
= 0 then
16517 Set_Is_Implementation_Defined
(Current_Scope
);
16519 -- Form with one argument
16522 Check_Arg_Count
(1);
16523 Check_Arg_Is_Local_Name
(Arg1
);
16524 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
16525 Set_Is_Implementation_Defined
(Ent
);
16527 end Implementation_Defined
;
16533 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
16535 -- IMPLEMENTATION_KIND ::=
16536 -- By_Entry | By_Protected_Procedure | By_Any | Optional
16538 -- "By_Any" and "Optional" are treated as synonyms in order to
16539 -- support Ada 2012 aspect Synchronization.
16541 when Pragma_Implemented
=> Implemented
: declare
16542 Proc_Id
: Entity_Id
;
16547 Check_Arg_Count
(2);
16548 Check_No_Identifiers
;
16549 Check_Arg_Is_Identifier
(Arg1
);
16550 Check_Arg_Is_Local_Name
(Arg1
);
16551 Check_Arg_Is_One_Of
(Arg2
,
16554 Name_By_Protected_Procedure
,
16557 -- Extract the name of the local procedure
16559 Proc_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
16561 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
16562 -- primitive procedure of a synchronized tagged type.
16564 if Ekind
(Proc_Id
) = E_Procedure
16565 and then Is_Primitive
(Proc_Id
)
16566 and then Present
(First_Formal
(Proc_Id
))
16568 Typ
:= Etype
(First_Formal
(Proc_Id
));
16570 if Is_Tagged_Type
(Typ
)
16573 -- Check for a protected, a synchronized or a task interface
16575 ((Is_Interface
(Typ
)
16576 and then Is_Synchronized_Interface
(Typ
))
16578 -- Check for a protected type or a task type that implements
16582 (Is_Concurrent_Record_Type
(Typ
)
16583 and then Present
(Interfaces
(Typ
)))
16585 -- In analysis-only mode, examine original protected type
16588 (Nkind
(Parent
(Typ
)) = N_Protected_Type_Declaration
16589 and then Present
(Interface_List
(Parent
(Typ
))))
16591 -- Check for a private record extension with keyword
16595 (Ekind_In
(Typ
, E_Record_Type_With_Private
,
16596 E_Record_Subtype_With_Private
)
16597 and then Synchronized_Present
(Parent
(Typ
))))
16602 ("controlling formal must be of synchronized tagged type",
16607 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
16608 -- By_Protected_Procedure to the primitive procedure of a task
16611 if Chars
(Arg2
) = Name_By_Protected_Procedure
16612 and then Is_Interface
(Typ
)
16613 and then Is_Task_Interface
(Typ
)
16616 ("implementation kind By_Protected_Procedure cannot be "
16617 & "applied to a task interface primitive", Arg2
);
16621 -- Procedures declared inside a protected type must be accepted
16623 elsif Ekind
(Proc_Id
) = E_Procedure
16624 and then Is_Protected_Type
(Scope
(Proc_Id
))
16628 -- The first argument is not a primitive procedure
16632 ("pragma % must be applied to a primitive procedure", Arg1
);
16636 Record_Rep_Item
(Proc_Id
, N
);
16639 ----------------------
16640 -- Implicit_Packing --
16641 ----------------------
16643 -- pragma Implicit_Packing;
16645 when Pragma_Implicit_Packing
=>
16647 Check_Arg_Count
(0);
16648 Implicit_Packing
:= True;
16655 -- [Convention =>] convention_IDENTIFIER,
16656 -- [Entity =>] LOCAL_NAME
16657 -- [, [External_Name =>] static_string_EXPRESSION ]
16658 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16660 when Pragma_Import
=>
16661 Check_Ada_83_Warning
;
16665 Name_External_Name
,
16668 Check_At_Least_N_Arguments
(2);
16669 Check_At_Most_N_Arguments
(4);
16670 Process_Import_Or_Interface
;
16672 ---------------------
16673 -- Import_Function --
16674 ---------------------
16676 -- pragma Import_Function (
16677 -- [Internal =>] LOCAL_NAME,
16678 -- [, [External =>] EXTERNAL_SYMBOL]
16679 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16680 -- [, [Result_Type =>] SUBTYPE_MARK]
16681 -- [, [Mechanism =>] MECHANISM]
16682 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
16684 -- EXTERNAL_SYMBOL ::=
16686 -- | static_string_EXPRESSION
16688 -- PARAMETER_TYPES ::=
16690 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16692 -- TYPE_DESIGNATOR ::=
16694 -- | subtype_Name ' Access
16698 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16700 -- MECHANISM_ASSOCIATION ::=
16701 -- [formal_parameter_NAME =>] MECHANISM_NAME
16703 -- MECHANISM_NAME ::=
16707 when Pragma_Import_Function
=> Import_Function
: declare
16708 Args
: Args_List
(1 .. 6);
16709 Names
: constant Name_List
(1 .. 6) := (
16712 Name_Parameter_Types
,
16715 Name_Result_Mechanism
);
16717 Internal
: Node_Id
renames Args
(1);
16718 External
: Node_Id
renames Args
(2);
16719 Parameter_Types
: Node_Id
renames Args
(3);
16720 Result_Type
: Node_Id
renames Args
(4);
16721 Mechanism
: Node_Id
renames Args
(5);
16722 Result_Mechanism
: Node_Id
renames Args
(6);
16726 Gather_Associations
(Names
, Args
);
16727 Process_Extended_Import_Export_Subprogram_Pragma
(
16728 Arg_Internal
=> Internal
,
16729 Arg_External
=> External
,
16730 Arg_Parameter_Types
=> Parameter_Types
,
16731 Arg_Result_Type
=> Result_Type
,
16732 Arg_Mechanism
=> Mechanism
,
16733 Arg_Result_Mechanism
=> Result_Mechanism
);
16734 end Import_Function
;
16736 -------------------
16737 -- Import_Object --
16738 -------------------
16740 -- pragma Import_Object (
16741 -- [Internal =>] LOCAL_NAME
16742 -- [, [External =>] EXTERNAL_SYMBOL]
16743 -- [, [Size =>] EXTERNAL_SYMBOL]);
16745 -- EXTERNAL_SYMBOL ::=
16747 -- | static_string_EXPRESSION
16749 when Pragma_Import_Object
=> Import_Object
: declare
16750 Args
: Args_List
(1 .. 3);
16751 Names
: constant Name_List
(1 .. 3) := (
16756 Internal
: Node_Id
renames Args
(1);
16757 External
: Node_Id
renames Args
(2);
16758 Size
: Node_Id
renames Args
(3);
16762 Gather_Associations
(Names
, Args
);
16763 Process_Extended_Import_Export_Object_Pragma
(
16764 Arg_Internal
=> Internal
,
16765 Arg_External
=> External
,
16769 ----------------------
16770 -- Import_Procedure --
16771 ----------------------
16773 -- pragma Import_Procedure (
16774 -- [Internal =>] LOCAL_NAME
16775 -- [, [External =>] EXTERNAL_SYMBOL]
16776 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16777 -- [, [Mechanism =>] MECHANISM]);
16779 -- EXTERNAL_SYMBOL ::=
16781 -- | static_string_EXPRESSION
16783 -- PARAMETER_TYPES ::=
16785 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16787 -- TYPE_DESIGNATOR ::=
16789 -- | subtype_Name ' Access
16793 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16795 -- MECHANISM_ASSOCIATION ::=
16796 -- [formal_parameter_NAME =>] MECHANISM_NAME
16798 -- MECHANISM_NAME ::=
16802 when Pragma_Import_Procedure
=> Import_Procedure
: declare
16803 Args
: Args_List
(1 .. 4);
16804 Names
: constant Name_List
(1 .. 4) := (
16807 Name_Parameter_Types
,
16810 Internal
: Node_Id
renames Args
(1);
16811 External
: Node_Id
renames Args
(2);
16812 Parameter_Types
: Node_Id
renames Args
(3);
16813 Mechanism
: Node_Id
renames Args
(4);
16817 Gather_Associations
(Names
, Args
);
16818 Process_Extended_Import_Export_Subprogram_Pragma
(
16819 Arg_Internal
=> Internal
,
16820 Arg_External
=> External
,
16821 Arg_Parameter_Types
=> Parameter_Types
,
16822 Arg_Mechanism
=> Mechanism
);
16823 end Import_Procedure
;
16825 -----------------------------
16826 -- Import_Valued_Procedure --
16827 -----------------------------
16829 -- pragma Import_Valued_Procedure (
16830 -- [Internal =>] LOCAL_NAME
16831 -- [, [External =>] EXTERNAL_SYMBOL]
16832 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
16833 -- [, [Mechanism =>] MECHANISM]);
16835 -- EXTERNAL_SYMBOL ::=
16837 -- | static_string_EXPRESSION
16839 -- PARAMETER_TYPES ::=
16841 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
16843 -- TYPE_DESIGNATOR ::=
16845 -- | subtype_Name ' Access
16849 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
16851 -- MECHANISM_ASSOCIATION ::=
16852 -- [formal_parameter_NAME =>] MECHANISM_NAME
16854 -- MECHANISM_NAME ::=
16858 when Pragma_Import_Valued_Procedure
=>
16859 Import_Valued_Procedure
: declare
16860 Args
: Args_List
(1 .. 4);
16861 Names
: constant Name_List
(1 .. 4) := (
16864 Name_Parameter_Types
,
16867 Internal
: Node_Id
renames Args
(1);
16868 External
: Node_Id
renames Args
(2);
16869 Parameter_Types
: Node_Id
renames Args
(3);
16870 Mechanism
: Node_Id
renames Args
(4);
16874 Gather_Associations
(Names
, Args
);
16875 Process_Extended_Import_Export_Subprogram_Pragma
(
16876 Arg_Internal
=> Internal
,
16877 Arg_External
=> External
,
16878 Arg_Parameter_Types
=> Parameter_Types
,
16879 Arg_Mechanism
=> Mechanism
);
16880 end Import_Valued_Procedure
;
16886 -- pragma Independent (LOCAL_NAME);
16888 when Pragma_Independent
=>
16889 Process_Atomic_Independent_Shared_Volatile
;
16891 ----------------------------
16892 -- Independent_Components --
16893 ----------------------------
16895 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
16897 when Pragma_Independent_Components
=> Independent_Components
: declare
16905 Check_Ada_83_Warning
;
16907 Check_No_Identifiers
;
16908 Check_Arg_Count
(1);
16909 Check_Arg_Is_Local_Name
(Arg1
);
16910 E_Id
:= Get_Pragma_Arg
(Arg1
);
16912 if Etype
(E_Id
) = Any_Type
then
16916 E
:= Entity
(E_Id
);
16918 -- A pragma that applies to a Ghost entity becomes Ghost for the
16919 -- purposes of legality checks and removal of ignored Ghost code.
16921 Mark_Ghost_Pragma
(N
, E
);
16923 -- Check duplicate before we chain ourselves
16925 Check_Duplicate_Pragma
(E
);
16927 -- Check appropriate entity
16929 if Rep_Item_Too_Early
(E
, N
)
16931 Rep_Item_Too_Late
(E
, N
)
16936 D
:= Declaration_Node
(E
);
16939 -- The flag is set on the base type, or on the object
16941 if K
= N_Full_Type_Declaration
16942 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
16944 Set_Has_Independent_Components
(Base_Type
(E
));
16945 Record_Independence_Check
(N
, Base_Type
(E
));
16947 -- For record type, set all components independent
16949 if Is_Record_Type
(E
) then
16950 C
:= First_Component
(E
);
16951 while Present
(C
) loop
16952 Set_Is_Independent
(C
);
16953 Next_Component
(C
);
16957 elsif (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
16958 and then Nkind
(D
) = N_Object_Declaration
16959 and then Nkind
(Object_Definition
(D
)) =
16960 N_Constrained_Array_Definition
16962 Set_Has_Independent_Components
(E
);
16963 Record_Independence_Check
(N
, E
);
16966 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
16968 end Independent_Components
;
16970 -----------------------
16971 -- Initial_Condition --
16972 -----------------------
16974 -- pragma Initial_Condition (boolean_EXPRESSION);
16976 -- Characteristics:
16978 -- * Analysis - The annotation undergoes initial checks to verify
16979 -- the legal placement and context. Secondary checks preanalyze the
16982 -- Analyze_Initial_Condition_In_Decl_Part
16984 -- * Expansion - The annotation is expanded during the expansion of
16985 -- the package body whose declaration is subject to the annotation
16988 -- Expand_Pragma_Initial_Condition
16990 -- * Template - The annotation utilizes the generic template of the
16991 -- related package declaration.
16993 -- * Globals - Capture of global references must occur after full
16996 -- * Instance - The annotation is instantiated automatically when
16997 -- the related generic package is instantiated.
16999 when Pragma_Initial_Condition
=> Initial_Condition
: declare
17000 Pack_Decl
: Node_Id
;
17001 Pack_Id
: Entity_Id
;
17005 Check_No_Identifiers
;
17006 Check_Arg_Count
(1);
17008 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
17010 -- Ensure the proper placement of the pragma. Initial_Condition
17011 -- must be associated with a package declaration.
17013 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
17014 N_Package_Declaration
)
17018 -- Otherwise the pragma is associated with an illegal context
17025 Pack_Id
:= Defining_Entity
(Pack_Decl
);
17027 -- A pragma that applies to a Ghost entity becomes Ghost for the
17028 -- purposes of legality checks and removal of ignored Ghost code.
17030 Mark_Ghost_Pragma
(N
, Pack_Id
);
17032 -- Chain the pragma on the contract for further processing by
17033 -- Analyze_Initial_Condition_In_Decl_Part.
17035 Add_Contract_Item
(N
, Pack_Id
);
17037 -- The legality checks of pragmas Abstract_State, Initializes, and
17038 -- Initial_Condition are affected by the SPARK mode in effect. In
17039 -- addition, these three pragmas are subject to an inherent order:
17041 -- 1) Abstract_State
17043 -- 3) Initial_Condition
17045 -- Analyze all these pragmas in the order outlined above
17047 Analyze_If_Present
(Pragma_SPARK_Mode
);
17048 Analyze_If_Present
(Pragma_Abstract_State
);
17049 Analyze_If_Present
(Pragma_Initializes
);
17050 end Initial_Condition
;
17052 ------------------------
17053 -- Initialize_Scalars --
17054 ------------------------
17056 -- pragma Initialize_Scalars;
17058 when Pragma_Initialize_Scalars
=>
17060 Check_Arg_Count
(0);
17061 Check_Valid_Configuration_Pragma
;
17062 Check_Restriction
(No_Initialize_Scalars
, N
);
17064 -- Initialize_Scalars creates false positives in CodePeer, and
17065 -- incorrect negative results in GNATprove mode, so ignore this
17066 -- pragma in these modes.
17068 if not Restriction_Active
(No_Initialize_Scalars
)
17069 and then not (CodePeer_Mode
or GNATprove_Mode
)
17071 Init_Or_Norm_Scalars
:= True;
17072 Initialize_Scalars
:= True;
17079 -- pragma Initializes (INITIALIZATION_LIST);
17081 -- INITIALIZATION_LIST ::=
17083 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
17085 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
17090 -- | (INPUT {, INPUT})
17094 -- Characteristics:
17096 -- * Analysis - The annotation undergoes initial checks to verify
17097 -- the legal placement and context. Secondary checks preanalyze the
17100 -- Analyze_Initializes_In_Decl_Part
17102 -- * Expansion - None.
17104 -- * Template - The annotation utilizes the generic template of the
17105 -- related package declaration.
17107 -- * Globals - Capture of global references must occur after full
17110 -- * Instance - The annotation is instantiated automatically when
17111 -- the related generic package is instantiated.
17113 when Pragma_Initializes
=> Initializes
: declare
17114 Pack_Decl
: Node_Id
;
17115 Pack_Id
: Entity_Id
;
17119 Check_No_Identifiers
;
17120 Check_Arg_Count
(1);
17122 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
17124 -- Ensure the proper placement of the pragma. Initializes must be
17125 -- associated with a package declaration.
17127 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
17128 N_Package_Declaration
)
17132 -- Otherwise the pragma is associated with an illegal construc
17139 Pack_Id
:= Defining_Entity
(Pack_Decl
);
17141 -- A pragma that applies to a Ghost entity becomes Ghost for the
17142 -- purposes of legality checks and removal of ignored Ghost code.
17144 Mark_Ghost_Pragma
(N
, Pack_Id
);
17145 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
17147 -- Chain the pragma on the contract for further processing by
17148 -- Analyze_Initializes_In_Decl_Part.
17150 Add_Contract_Item
(N
, Pack_Id
);
17152 -- The legality checks of pragmas Abstract_State, Initializes, and
17153 -- Initial_Condition are affected by the SPARK mode in effect. In
17154 -- addition, these three pragmas are subject to an inherent order:
17156 -- 1) Abstract_State
17158 -- 3) Initial_Condition
17160 -- Analyze all these pragmas in the order outlined above
17162 Analyze_If_Present
(Pragma_SPARK_Mode
);
17163 Analyze_If_Present
(Pragma_Abstract_State
);
17164 Analyze_If_Present
(Pragma_Initial_Condition
);
17171 -- pragma Inline ( NAME {, NAME} );
17173 when Pragma_Inline
=>
17175 -- Pragma always active unless in GNATprove mode. It is disabled
17176 -- in GNATprove mode because frontend inlining is applied
17177 -- independently of pragmas Inline and Inline_Always for
17178 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
17181 if not GNATprove_Mode
then
17183 -- Inline status is Enabled if option -gnatn is specified.
17184 -- However this status determines only the value of the
17185 -- Is_Inlined flag on the subprogram and does not prevent
17186 -- the pragma itself from being recorded for later use,
17187 -- in particular for a later modification of Is_Inlined
17188 -- independently of the -gnatn option.
17190 -- In other words, if -gnatn is specified for a unit, then
17191 -- all Inline pragmas processed for the compilation of this
17192 -- unit, including those in the spec of other units, are
17193 -- activated, so subprograms will be inlined across units.
17195 -- If -gnatn is not specified, no Inline pragma is activated
17196 -- here, which means that subprograms will not be inlined
17197 -- across units. The Is_Inlined flag will nevertheless be
17198 -- set later when bodies are analyzed, so subprograms will
17199 -- be inlined within the unit.
17201 if Inline_Active
then
17202 Process_Inline
(Enabled
);
17204 Process_Inline
(Disabled
);
17208 -------------------
17209 -- Inline_Always --
17210 -------------------
17212 -- pragma Inline_Always ( NAME {, NAME} );
17214 when Pragma_Inline_Always
=>
17217 -- Pragma always active unless in CodePeer mode or GNATprove
17218 -- mode. It is disabled in CodePeer mode because inlining is
17219 -- not helpful, and enabling it caused walk order issues. It
17220 -- is disabled in GNATprove mode because frontend inlining is
17221 -- applied independently of pragmas Inline and Inline_Always for
17222 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
17225 if not CodePeer_Mode
and not GNATprove_Mode
then
17226 Process_Inline
(Enabled
);
17229 --------------------
17230 -- Inline_Generic --
17231 --------------------
17233 -- pragma Inline_Generic (NAME {, NAME});
17235 when Pragma_Inline_Generic
=>
17237 Process_Generic_List
;
17239 ----------------------
17240 -- Inspection_Point --
17241 ----------------------
17243 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
17245 when Pragma_Inspection_Point
=> Inspection_Point
: declare
17252 if Arg_Count
> 0 then
17255 Exp
:= Get_Pragma_Arg
(Arg
);
17258 if not Is_Entity_Name
(Exp
)
17259 or else not Is_Object
(Entity
(Exp
))
17261 Error_Pragma_Arg
("object name required", Arg
);
17265 exit when No
(Arg
);
17268 end Inspection_Point
;
17274 -- pragma Interface (
17275 -- [ Convention =>] convention_IDENTIFIER,
17276 -- [ Entity =>] LOCAL_NAME
17277 -- [, [External_Name =>] static_string_EXPRESSION ]
17278 -- [, [Link_Name =>] static_string_EXPRESSION ]);
17280 when Pragma_Interface
=>
17285 Name_External_Name
,
17287 Check_At_Least_N_Arguments
(2);
17288 Check_At_Most_N_Arguments
(4);
17289 Process_Import_Or_Interface
;
17291 -- In Ada 2005, the permission to use Interface (a reserved word)
17292 -- as a pragma name is considered an obsolescent feature, and this
17293 -- pragma was already obsolescent in Ada 95.
17295 if Ada_Version
>= Ada_95
then
17297 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
17299 if Warn_On_Obsolescent_Feature
then
17301 ("pragma Interface is an obsolescent feature?j?", N
);
17303 ("|use pragma Import instead?j?", N
);
17307 --------------------
17308 -- Interface_Name --
17309 --------------------
17311 -- pragma Interface_Name (
17312 -- [ Entity =>] LOCAL_NAME
17313 -- [,[External_Name =>] static_string_EXPRESSION ]
17314 -- [,[Link_Name =>] static_string_EXPRESSION ]);
17316 when Pragma_Interface_Name
=> Interface_Name
: declare
17318 Def_Id
: Entity_Id
;
17319 Hom_Id
: Entity_Id
;
17325 ((Name_Entity
, Name_External_Name
, Name_Link_Name
));
17326 Check_At_Least_N_Arguments
(2);
17327 Check_At_Most_N_Arguments
(3);
17328 Id
:= Get_Pragma_Arg
(Arg1
);
17331 -- This is obsolete from Ada 95 on, but it is an implementation
17332 -- defined pragma, so we do not consider that it violates the
17333 -- restriction (No_Obsolescent_Features).
17335 if Ada_Version
>= Ada_95
then
17336 if Warn_On_Obsolescent_Feature
then
17338 ("pragma Interface_Name is an obsolescent feature?j?", N
);
17340 ("|use pragma Import instead?j?", N
);
17344 if not Is_Entity_Name
(Id
) then
17346 ("first argument for pragma% must be entity name", Arg1
);
17347 elsif Etype
(Id
) = Any_Type
then
17350 Def_Id
:= Entity
(Id
);
17353 -- Special DEC-compatible processing for the object case, forces
17354 -- object to be imported.
17356 if Ekind
(Def_Id
) = E_Variable
then
17357 Kill_Size_Check_Code
(Def_Id
);
17358 Note_Possible_Modification
(Id
, Sure
=> False);
17360 -- Initialization is not allowed for imported variable
17362 if Present
(Expression
(Parent
(Def_Id
)))
17363 and then Comes_From_Source
(Expression
(Parent
(Def_Id
)))
17365 Error_Msg_Sloc
:= Sloc
(Def_Id
);
17367 ("no initialization allowed for declaration of& #",
17371 -- For compatibility, support VADS usage of providing both
17372 -- pragmas Interface and Interface_Name to obtain the effect
17373 -- of a single Import pragma.
17375 if Is_Imported
(Def_Id
)
17376 and then Present
(First_Rep_Item
(Def_Id
))
17377 and then Nkind
(First_Rep_Item
(Def_Id
)) = N_Pragma
17378 and then Pragma_Name
(First_Rep_Item
(Def_Id
)) =
17383 Set_Imported
(Def_Id
);
17386 Set_Is_Public
(Def_Id
);
17387 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
17390 -- Otherwise must be subprogram
17392 elsif not Is_Subprogram
(Def_Id
) then
17394 ("argument of pragma% is not subprogram", Arg1
);
17397 Check_At_Most_N_Arguments
(3);
17401 -- Loop through homonyms
17404 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
17406 if Is_Imported
(Def_Id
) then
17407 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
, N
);
17411 exit when From_Aspect_Specification
(N
);
17412 Hom_Id
:= Homonym
(Hom_Id
);
17414 exit when No
(Hom_Id
)
17415 or else Scope
(Hom_Id
) /= Current_Scope
;
17420 ("argument of pragma% is not imported subprogram",
17424 end Interface_Name
;
17426 -----------------------
17427 -- Interrupt_Handler --
17428 -----------------------
17430 -- pragma Interrupt_Handler (handler_NAME);
17432 when Pragma_Interrupt_Handler
=>
17433 Check_Ada_83_Warning
;
17434 Check_Arg_Count
(1);
17435 Check_No_Identifiers
;
17437 if No_Run_Time_Mode
then
17438 Error_Msg_CRT
("Interrupt_Handler pragma", N
);
17440 Check_Interrupt_Or_Attach_Handler
;
17441 Process_Interrupt_Or_Attach_Handler
;
17444 ------------------------
17445 -- Interrupt_Priority --
17446 ------------------------
17448 -- pragma Interrupt_Priority [(EXPRESSION)];
17450 when Pragma_Interrupt_Priority
=> Interrupt_Priority
: declare
17451 P
: constant Node_Id
:= Parent
(N
);
17456 Check_Ada_83_Warning
;
17458 if Arg_Count
/= 0 then
17459 Arg
:= Get_Pragma_Arg
(Arg1
);
17460 Check_Arg_Count
(1);
17461 Check_No_Identifiers
;
17463 -- The expression must be analyzed in the special manner
17464 -- described in "Handling of Default and Per-Object
17465 -- Expressions" in sem.ads.
17467 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Interrupt_Priority
));
17470 if not Nkind_In
(P
, N_Task_Definition
, N_Protected_Definition
) then
17475 Ent
:= Defining_Identifier
(Parent
(P
));
17477 -- Check duplicate pragma before we chain the pragma in the Rep
17478 -- Item chain of Ent.
17480 Check_Duplicate_Pragma
(Ent
);
17481 Record_Rep_Item
(Ent
, N
);
17483 -- Check the No_Task_At_Interrupt_Priority restriction
17485 if Nkind
(P
) = N_Task_Definition
then
17486 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
17489 end Interrupt_Priority
;
17491 ---------------------
17492 -- Interrupt_State --
17493 ---------------------
17495 -- pragma Interrupt_State (
17496 -- [Name =>] INTERRUPT_ID,
17497 -- [State =>] INTERRUPT_STATE);
17499 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
17500 -- INTERRUPT_STATE => System | Runtime | User
17502 -- Note: if the interrupt id is given as an identifier, then it must
17503 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
17504 -- given as a static integer expression which must be in the range of
17505 -- Ada.Interrupts.Interrupt_ID.
17507 when Pragma_Interrupt_State
=> Interrupt_State
: declare
17508 Int_Id
: constant Entity_Id
:= RTE
(RE_Interrupt_ID
);
17509 -- This is the entity Ada.Interrupts.Interrupt_ID;
17511 State_Type
: Character;
17512 -- Set to 's'/'r'/'u' for System/Runtime/User
17515 -- Index to entry in Interrupt_States table
17518 -- Value of interrupt
17520 Arg1X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
17521 -- The first argument to the pragma
17523 Int_Ent
: Entity_Id
;
17524 -- Interrupt entity in Ada.Interrupts.Names
17528 Check_Arg_Order
((Name_Name
, Name_State
));
17529 Check_Arg_Count
(2);
17531 Check_Optional_Identifier
(Arg1
, Name_Name
);
17532 Check_Optional_Identifier
(Arg2
, Name_State
);
17533 Check_Arg_Is_Identifier
(Arg2
);
17535 -- First argument is identifier
17537 if Nkind
(Arg1X
) = N_Identifier
then
17539 -- Search list of names in Ada.Interrupts.Names
17541 Int_Ent
:= First_Entity
(RTE
(RE_Names
));
17543 if No
(Int_Ent
) then
17544 Error_Pragma_Arg
("invalid interrupt name", Arg1
);
17546 elsif Chars
(Int_Ent
) = Chars
(Arg1X
) then
17547 Int_Val
:= Expr_Value
(Constant_Value
(Int_Ent
));
17551 Next_Entity
(Int_Ent
);
17554 -- First argument is not an identifier, so it must be a static
17555 -- expression of type Ada.Interrupts.Interrupt_ID.
17558 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
17559 Int_Val
:= Expr_Value
(Arg1X
);
17561 if Int_Val
< Expr_Value
(Type_Low_Bound
(Int_Id
))
17563 Int_Val
> Expr_Value
(Type_High_Bound
(Int_Id
))
17566 ("value not in range of type "
17567 & """Ada.Interrupts.Interrupt_'I'D""", Arg1
);
17573 case Chars
(Get_Pragma_Arg
(Arg2
)) is
17574 when Name_Runtime
=> State_Type
:= 'r';
17575 when Name_System
=> State_Type
:= 's';
17576 when Name_User
=> State_Type
:= 'u';
17579 Error_Pragma_Arg
("invalid interrupt state", Arg2
);
17582 -- Check if entry is already stored
17584 IST_Num
:= Interrupt_States
.First
;
17586 -- If entry not found, add it
17588 if IST_Num
> Interrupt_States
.Last
then
17589 Interrupt_States
.Append
17590 ((Interrupt_Number
=> UI_To_Int
(Int_Val
),
17591 Interrupt_State
=> State_Type
,
17592 Pragma_Loc
=> Loc
));
17595 -- Case of entry for the same entry
17597 elsif Int_Val
= Interrupt_States
.Table
(IST_Num
).
17600 -- If state matches, done, no need to make redundant entry
17603 State_Type
= Interrupt_States
.Table
(IST_Num
).
17606 -- Otherwise if state does not match, error
17609 Interrupt_States
.Table
(IST_Num
).Pragma_Loc
;
17611 ("state conflicts with that given #", Arg2
);
17615 IST_Num
:= IST_Num
+ 1;
17617 end Interrupt_State
;
17623 -- pragma Invariant
17624 -- ([Entity =>] type_LOCAL_NAME,
17625 -- [Check =>] EXPRESSION
17626 -- [,[Message =>] String_Expression]);
17628 when Pragma_Invariant
=> Invariant
: declare
17635 Check_At_Least_N_Arguments
(2);
17636 Check_At_Most_N_Arguments
(3);
17637 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17638 Check_Optional_Identifier
(Arg2
, Name_Check
);
17640 if Arg_Count
= 3 then
17641 Check_Optional_Identifier
(Arg3
, Name_Message
);
17642 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
17645 Check_Arg_Is_Local_Name
(Arg1
);
17647 Typ_Arg
:= Get_Pragma_Arg
(Arg1
);
17648 Find_Type
(Typ_Arg
);
17649 Typ
:= Entity
(Typ_Arg
);
17651 -- Nothing to do of the related type is erroneous in some way
17653 if Typ
= Any_Type
then
17656 -- AI12-0041: Invariants are allowed in interface types
17658 elsif Is_Interface
(Typ
) then
17661 -- An invariant must apply to a private type, or appear in the
17662 -- private part of a package spec and apply to a completion.
17663 -- a class-wide invariant can only appear on a private declaration
17664 -- or private extension, not a completion.
17666 -- A [class-wide] invariant may be associated a [limited] private
17667 -- type or a private extension.
17669 elsif Ekind_In
(Typ
, E_Limited_Private_Type
,
17671 E_Record_Type_With_Private
)
17675 -- A non-class-wide invariant may be associated with the full view
17676 -- of a [limited] private type or a private extension.
17678 elsif Has_Private_Declaration
(Typ
)
17679 and then not Class_Present
(N
)
17683 -- A class-wide invariant may appear on the partial view only
17685 elsif Class_Present
(N
) then
17687 ("pragma % only allowed for private type", Arg1
);
17690 -- A regular invariant may appear on both views
17694 ("pragma % only allowed for private type or corresponding "
17695 & "full view", Arg1
);
17699 -- An invariant associated with an abstract type (this includes
17700 -- interfaces) must be class-wide.
17702 if Is_Abstract_Type
(Typ
) and then not Class_Present
(N
) then
17704 ("pragma % not allowed for abstract type", Arg1
);
17708 -- A pragma that applies to a Ghost entity becomes Ghost for the
17709 -- purposes of legality checks and removal of ignored Ghost code.
17711 Mark_Ghost_Pragma
(N
, Typ
);
17713 -- The pragma defines a type-specific invariant, the type is said
17714 -- to have invariants of its "own".
17716 Set_Has_Own_Invariants
(Typ
);
17718 -- If the invariant is class-wide, then it can be inherited by
17719 -- derived or interface implementing types. The type is said to
17720 -- have "inheritable" invariants.
17722 if Class_Present
(N
) then
17723 Set_Has_Inheritable_Invariants
(Typ
);
17726 -- Chain the pragma on to the rep item chain, for processing when
17727 -- the type is frozen.
17729 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
17731 -- Create the declaration of the invariant procedure that will
17732 -- verify the invariant at run time. Interfaces are treated as the
17733 -- partial view of a private type in order to achieve uniformity
17734 -- with the general case. As a result, an interface receives only
17735 -- a "partial" invariant procedure, which is never called.
17737 Build_Invariant_Procedure_Declaration
17739 Partial_Invariant
=> Is_Interface
(Typ
));
17746 -- pragma Keep_Names ([On => ] LOCAL_NAME);
17748 when Pragma_Keep_Names
=> Keep_Names
: declare
17753 Check_Arg_Count
(1);
17754 Check_Optional_Identifier
(Arg1
, Name_On
);
17755 Check_Arg_Is_Local_Name
(Arg1
);
17757 Arg
:= Get_Pragma_Arg
(Arg1
);
17760 if Etype
(Arg
) = Any_Type
then
17764 if not Is_Entity_Name
(Arg
)
17765 or else Ekind
(Entity
(Arg
)) /= E_Enumeration_Type
17768 ("pragma% requires a local enumeration type", Arg1
);
17771 Set_Discard_Names
(Entity
(Arg
), False);
17778 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
17780 when Pragma_License
=>
17783 -- Do not analyze pragma any further in CodePeer mode, to avoid
17784 -- extraneous errors in this implementation-dependent pragma,
17785 -- which has a different profile on other compilers.
17787 if CodePeer_Mode
then
17791 Check_Arg_Count
(1);
17792 Check_No_Identifiers
;
17793 Check_Valid_Configuration_Pragma
;
17794 Check_Arg_Is_Identifier
(Arg1
);
17797 Sind
: constant Source_File_Index
:=
17798 Source_Index
(Current_Sem_Unit
);
17801 case Chars
(Get_Pragma_Arg
(Arg1
)) is
17803 Set_License
(Sind
, GPL
);
17805 when Name_Modified_GPL
=>
17806 Set_License
(Sind
, Modified_GPL
);
17808 when Name_Restricted
=>
17809 Set_License
(Sind
, Restricted
);
17811 when Name_Unrestricted
=>
17812 Set_License
(Sind
, Unrestricted
);
17815 Error_Pragma_Arg
("invalid license name", Arg1
);
17823 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
17825 when Pragma_Link_With
=> Link_With
: declare
17831 if Operating_Mode
= Generate_Code
17832 and then In_Extended_Main_Source_Unit
(N
)
17834 Check_At_Least_N_Arguments
(1);
17835 Check_No_Identifiers
;
17836 Check_Is_In_Decl_Part_Or_Package_Spec
;
17837 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
17841 while Present
(Arg
) loop
17842 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
17844 -- Store argument, converting sequences of spaces to a
17845 -- single null character (this is one of the differences
17846 -- in processing between Link_With and Linker_Options).
17848 Arg_Store
: declare
17849 C
: constant Char_Code
:= Get_Char_Code
(' ');
17850 S
: constant String_Id
:=
17851 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
)));
17852 L
: constant Nat
:= String_Length
(S
);
17855 procedure Skip_Spaces
;
17856 -- Advance F past any spaces
17862 procedure Skip_Spaces
is
17864 while F
<= L
and then Get_String_Char
(S
, F
) = C
loop
17869 -- Start of processing for Arg_Store
17872 Skip_Spaces
; -- skip leading spaces
17874 -- Loop through characters, changing any embedded
17875 -- sequence of spaces to a single null character (this
17876 -- is how Link_With/Linker_Options differ)
17879 if Get_String_Char
(S
, F
) = C
then
17882 Store_String_Char
(ASCII
.NUL
);
17885 Store_String_Char
(Get_String_Char
(S
, F
));
17893 if Present
(Arg
) then
17894 Store_String_Char
(ASCII
.NUL
);
17898 Store_Linker_Option_String
(End_String
);
17906 -- pragma Linker_Alias (
17907 -- [Entity =>] LOCAL_NAME
17908 -- [Target =>] static_string_EXPRESSION);
17910 when Pragma_Linker_Alias
=>
17912 Check_Arg_Order
((Name_Entity
, Name_Target
));
17913 Check_Arg_Count
(2);
17914 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17915 Check_Optional_Identifier
(Arg2
, Name_Target
);
17916 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
17917 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
17919 -- The only processing required is to link this item on to the
17920 -- list of rep items for the given entity. This is accomplished
17921 -- by the call to Rep_Item_Too_Late (when no error is detected
17922 -- and False is returned).
17924 if Rep_Item_Too_Late
(Entity
(Get_Pragma_Arg
(Arg1
)), N
) then
17927 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
17930 ------------------------
17931 -- Linker_Constructor --
17932 ------------------------
17934 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
17936 -- Code is shared with Linker_Destructor
17938 -----------------------
17939 -- Linker_Destructor --
17940 -----------------------
17942 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
17944 when Pragma_Linker_Constructor
17945 | Pragma_Linker_Destructor
17947 Linker_Constructor
: declare
17953 Check_Arg_Count
(1);
17954 Check_No_Identifiers
;
17955 Check_Arg_Is_Local_Name
(Arg1
);
17956 Arg1_X
:= Get_Pragma_Arg
(Arg1
);
17958 Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
17960 if not Is_Library_Level_Entity
(Proc
) then
17962 ("argument for pragma% must be library level entity", Arg1
);
17965 -- The only processing required is to link this item on to the
17966 -- list of rep items for the given entity. This is accomplished
17967 -- by the call to Rep_Item_Too_Late (when no error is detected
17968 -- and False is returned).
17970 if Rep_Item_Too_Late
(Proc
, N
) then
17973 Set_Has_Gigi_Rep_Item
(Proc
);
17975 end Linker_Constructor
;
17977 --------------------
17978 -- Linker_Options --
17979 --------------------
17981 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
17983 when Pragma_Linker_Options
=> Linker_Options
: declare
17987 Check_Ada_83_Warning
;
17988 Check_No_Identifiers
;
17989 Check_Arg_Count
(1);
17990 Check_Is_In_Decl_Part_Or_Package_Spec
;
17991 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
17992 Start_String
(Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg1
))));
17995 while Present
(Arg
) loop
17996 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
17997 Store_String_Char
(ASCII
.NUL
);
17999 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
18003 if Operating_Mode
= Generate_Code
18004 and then In_Extended_Main_Source_Unit
(N
)
18006 Store_Linker_Option_String
(End_String
);
18008 end Linker_Options
;
18010 --------------------
18011 -- Linker_Section --
18012 --------------------
18014 -- pragma Linker_Section (
18015 -- [Entity =>] LOCAL_NAME
18016 -- [Section =>] static_string_EXPRESSION);
18018 when Pragma_Linker_Section
=> Linker_Section
: declare
18023 Ghost_Error_Posted
: Boolean := False;
18024 -- Flag set when an error concerning the illegal mix of Ghost and
18025 -- non-Ghost subprograms is emitted.
18027 Ghost_Id
: Entity_Id
:= Empty
;
18028 -- The entity of the first Ghost subprogram encountered while
18029 -- processing the arguments of the pragma.
18033 Check_Arg_Order
((Name_Entity
, Name_Section
));
18034 Check_Arg_Count
(2);
18035 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18036 Check_Optional_Identifier
(Arg2
, Name_Section
);
18037 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
18038 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
18040 -- Check kind of entity
18042 Arg
:= Get_Pragma_Arg
(Arg1
);
18043 Ent
:= Entity
(Arg
);
18045 case Ekind
(Ent
) is
18047 -- Objects (constants and variables) and types. For these cases
18048 -- all we need to do is to set the Linker_Section_pragma field,
18049 -- checking that we do not have a duplicate.
18055 LPE
:= Linker_Section_Pragma
(Ent
);
18057 if Present
(LPE
) then
18058 Error_Msg_Sloc
:= Sloc
(LPE
);
18060 ("Linker_Section already specified for &#", Arg1
, Ent
);
18063 Set_Linker_Section_Pragma
(Ent
, N
);
18065 -- A pragma that applies to a Ghost entity becomes Ghost for
18066 -- the purposes of legality checks and removal of ignored
18069 Mark_Ghost_Pragma
(N
, Ent
);
18073 when Subprogram_Kind
=>
18075 -- Aspect case, entity already set
18077 if From_Aspect_Specification
(N
) then
18078 Set_Linker_Section_Pragma
18079 (Entity
(Corresponding_Aspect
(N
)), N
);
18081 -- Pragma case, we must climb the homonym chain, but skip
18082 -- any for which the linker section is already set.
18086 if No
(Linker_Section_Pragma
(Ent
)) then
18087 Set_Linker_Section_Pragma
(Ent
, N
);
18089 -- A pragma that applies to a Ghost entity becomes
18090 -- Ghost for the purposes of legality checks and
18091 -- removal of ignored Ghost code.
18093 Mark_Ghost_Pragma
(N
, Ent
);
18095 -- Capture the entity of the first Ghost subprogram
18096 -- being processed for error detection purposes.
18098 if Is_Ghost_Entity
(Ent
) then
18099 if No
(Ghost_Id
) then
18103 -- Otherwise the subprogram is non-Ghost. It is
18104 -- illegal to mix references to Ghost and non-Ghost
18105 -- entities (SPARK RM 6.9).
18107 elsif Present
(Ghost_Id
)
18108 and then not Ghost_Error_Posted
18110 Ghost_Error_Posted
:= True;
18112 Error_Msg_Name_1
:= Pname
;
18114 ("pragma % cannot mention ghost and "
18115 & "non-ghost subprograms", N
);
18117 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
18119 ("\& # declared as ghost", N
, Ghost_Id
);
18121 Error_Msg_Sloc
:= Sloc
(Ent
);
18123 ("\& # declared as non-ghost", N
, Ent
);
18127 Ent
:= Homonym
(Ent
);
18129 or else Scope
(Ent
) /= Current_Scope
;
18133 -- All other cases are illegal
18137 ("pragma% applies only to objects, subprograms, and types",
18140 end Linker_Section
;
18146 -- pragma List (On | Off)
18148 -- There is nothing to do here, since we did all the processing for
18149 -- this pragma in Par.Prag (so that it works properly even in syntax
18152 when Pragma_List
=>
18159 -- pragma Lock_Free [(Boolean_EXPRESSION)];
18161 when Pragma_Lock_Free
=> Lock_Free
: declare
18162 P
: constant Node_Id
:= Parent
(N
);
18168 Check_No_Identifiers
;
18169 Check_At_Most_N_Arguments
(1);
18171 -- Protected definition case
18173 if Nkind
(P
) = N_Protected_Definition
then
18174 Ent
:= Defining_Identifier
(Parent
(P
));
18178 if Arg_Count
= 1 then
18179 Arg
:= Get_Pragma_Arg
(Arg1
);
18180 Val
:= Is_True
(Static_Boolean
(Arg
));
18182 -- No arguments (expression is considered to be True)
18188 -- Check duplicate pragma before we chain the pragma in the Rep
18189 -- Item chain of Ent.
18191 Check_Duplicate_Pragma
(Ent
);
18192 Record_Rep_Item
(Ent
, N
);
18193 Set_Uses_Lock_Free
(Ent
, Val
);
18195 -- Anything else is incorrect placement
18202 --------------------
18203 -- Locking_Policy --
18204 --------------------
18206 -- pragma Locking_Policy (policy_IDENTIFIER);
18208 when Pragma_Locking_Policy
=> declare
18209 subtype LP_Range
is Name_Id
18210 range First_Locking_Policy_Name
.. Last_Locking_Policy_Name
;
18215 Check_Ada_83_Warning
;
18216 Check_Arg_Count
(1);
18217 Check_No_Identifiers
;
18218 Check_Arg_Is_Locking_Policy
(Arg1
);
18219 Check_Valid_Configuration_Pragma
;
18220 LP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
18223 when Name_Ceiling_Locking
=> LP
:= 'C';
18224 when Name_Concurrent_Readers_Locking
=> LP
:= 'R';
18225 when Name_Inheritance_Locking
=> LP
:= 'I';
18228 if Locking_Policy
/= ' '
18229 and then Locking_Policy
/= LP
18231 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
18232 Error_Pragma
("locking policy incompatible with policy#");
18234 -- Set new policy, but always preserve System_Location since we
18235 -- like the error message with the run time name.
18238 Locking_Policy
:= LP
;
18240 if Locking_Policy_Sloc
/= System_Location
then
18241 Locking_Policy_Sloc
:= Loc
;
18246 -------------------
18247 -- Loop_Optimize --
18248 -------------------
18250 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
18252 -- OPTIMIZATION_HINT ::=
18253 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
18255 when Pragma_Loop_Optimize
=> Loop_Optimize
: declare
18260 Check_At_Least_N_Arguments
(1);
18261 Check_No_Identifiers
;
18263 Hint
:= First
(Pragma_Argument_Associations
(N
));
18264 while Present
(Hint
) loop
18265 Check_Arg_Is_One_Of
(Hint
, Name_Ivdep
,
18273 Check_Loop_Pragma_Placement
;
18280 -- pragma Loop_Variant
18281 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
18283 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
18285 -- CHANGE_DIRECTION ::= Increases | Decreases
18287 when Pragma_Loop_Variant
=> Loop_Variant
: declare
18292 Check_At_Least_N_Arguments
(1);
18293 Check_Loop_Pragma_Placement
;
18295 -- Process all increasing / decreasing expressions
18297 Variant
:= First
(Pragma_Argument_Associations
(N
));
18298 while Present
(Variant
) loop
18299 if Chars
(Variant
) = No_Name
then
18300 Error_Pragma_Arg_Ident
("expect name `Increases`", Variant
);
18302 elsif not Nam_In
(Chars
(Variant
), Name_Decreases
,
18306 Name
: String := Get_Name_String
(Chars
(Variant
));
18309 -- It is a common mistake to write "Increasing" for
18310 -- "Increases" or "Decreasing" for "Decreases". Recognize
18311 -- specially names starting with "incr" or "decr" to
18312 -- suggest the corresponding name.
18314 System
.Case_Util
.To_Lower
(Name
);
18316 if Name
'Length >= 4
18317 and then Name
(1 .. 4) = "incr"
18319 Error_Pragma_Arg_Ident
18320 ("expect name `Increases`", Variant
);
18322 elsif Name
'Length >= 4
18323 and then Name
(1 .. 4) = "decr"
18325 Error_Pragma_Arg_Ident
18326 ("expect name `Decreases`", Variant
);
18329 Error_Pragma_Arg_Ident
18330 ("expect name `Increases` or `Decreases`", Variant
);
18335 Preanalyze_Assert_Expression
18336 (Expression
(Variant
), Any_Discrete
);
18342 -----------------------
18343 -- Machine_Attribute --
18344 -----------------------
18346 -- pragma Machine_Attribute (
18347 -- [Entity =>] LOCAL_NAME,
18348 -- [Attribute_Name =>] static_string_EXPRESSION
18349 -- [, [Info =>] static_EXPRESSION] );
18351 when Pragma_Machine_Attribute
=> Machine_Attribute
: declare
18352 Def_Id
: Entity_Id
;
18356 Check_Arg_Order
((Name_Entity
, Name_Attribute_Name
, Name_Info
));
18358 if Arg_Count
= 3 then
18359 Check_Optional_Identifier
(Arg3
, Name_Info
);
18360 Check_Arg_Is_OK_Static_Expression
(Arg3
);
18362 Check_Arg_Count
(2);
18365 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18366 Check_Optional_Identifier
(Arg2
, Name_Attribute_Name
);
18367 Check_Arg_Is_Local_Name
(Arg1
);
18368 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
18369 Def_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
18371 if Is_Access_Type
(Def_Id
) then
18372 Def_Id
:= Designated_Type
(Def_Id
);
18375 if Rep_Item_Too_Early
(Def_Id
, N
) then
18379 Def_Id
:= Underlying_Type
(Def_Id
);
18381 -- The only processing required is to link this item on to the
18382 -- list of rep items for the given entity. This is accomplished
18383 -- by the call to Rep_Item_Too_Late (when no error is detected
18384 -- and False is returned).
18386 if Rep_Item_Too_Late
(Def_Id
, N
) then
18389 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
18391 end Machine_Attribute
;
18398 -- (MAIN_OPTION [, MAIN_OPTION]);
18401 -- [STACK_SIZE =>] static_integer_EXPRESSION
18402 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
18403 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
18405 when Pragma_Main
=> Main
: declare
18406 Args
: Args_List
(1 .. 3);
18407 Names
: constant Name_List
(1 .. 3) := (
18409 Name_Task_Stack_Size_Default
,
18410 Name_Time_Slicing_Enabled
);
18416 Gather_Associations
(Names
, Args
);
18418 for J
in 1 .. 2 loop
18419 if Present
(Args
(J
)) then
18420 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
18424 if Present
(Args
(3)) then
18425 Check_Arg_Is_OK_Static_Expression
(Args
(3), Standard_Boolean
);
18429 while Present
(Nod
) loop
18430 if Nkind
(Nod
) = N_Pragma
18431 and then Pragma_Name
(Nod
) = Name_Main
18433 Error_Msg_Name_1
:= Pname
;
18434 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
18445 -- pragma Main_Storage
18446 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
18448 -- MAIN_STORAGE_OPTION ::=
18449 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
18450 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
18452 when Pragma_Main_Storage
=> Main_Storage
: declare
18453 Args
: Args_List
(1 .. 2);
18454 Names
: constant Name_List
(1 .. 2) := (
18455 Name_Working_Storage
,
18462 Gather_Associations
(Names
, Args
);
18464 for J
in 1 .. 2 loop
18465 if Present
(Args
(J
)) then
18466 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
18470 Check_In_Main_Program
;
18473 while Present
(Nod
) loop
18474 if Nkind
(Nod
) = N_Pragma
18475 and then Pragma_Name
(Nod
) = Name_Main_Storage
18477 Error_Msg_Name_1
:= Pname
;
18478 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
18485 ----------------------
18486 -- Max_Queue_Length --
18487 ----------------------
18489 -- pragma Max_Queue_Length (static_integer_EXPRESSION);
18491 when Pragma_Max_Queue_Length
=> Max_Queue_Length
: declare
18493 Entry_Decl
: Node_Id
;
18494 Entry_Id
: Entity_Id
;
18499 Check_Arg_Count
(1);
18502 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
18504 -- Entry declaration
18506 if Nkind
(Entry_Decl
) = N_Entry_Declaration
then
18508 -- Entry illegally within a task
18510 if Nkind
(Parent
(N
)) = N_Task_Definition
then
18511 Error_Pragma
("pragma % cannot apply to task entries");
18515 Entry_Id
:= Unique_Defining_Entity
(Entry_Decl
);
18517 -- Otherwise the pragma is associated with an illegal construct
18520 Error_Pragma
("pragma % must apply to a protected entry");
18524 -- Mark the pragma as Ghost if the related subprogram is also
18525 -- Ghost. This also ensures that any expansion performed further
18526 -- below will produce Ghost nodes.
18528 Mark_Ghost_Pragma
(N
, Entry_Id
);
18530 -- Analyze the Integer expression
18532 Arg
:= Get_Pragma_Arg
(Arg1
);
18533 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
18535 Val
:= Expr_Value
(Arg
);
18539 ("argument for pragma% must be positive", Arg1
);
18541 elsif not UI_Is_In_Int_Range
(Val
) then
18543 ("argument for pragma% out of range of Integer", Arg1
);
18547 -- Manually substitute the expression value of the pragma argument
18548 -- if it's not an integer literal because this is not taken care
18549 -- of automatically elsewhere.
18551 if Nkind
(Arg
) /= N_Integer_Literal
then
18552 Rewrite
(Arg
, Make_Integer_Literal
(Sloc
(Arg
), Val
));
18555 Record_Rep_Item
(Entry_Id
, N
);
18556 end Max_Queue_Length
;
18562 -- pragma Memory_Size (NUMERIC_LITERAL)
18564 when Pragma_Memory_Size
=>
18567 -- Memory size is simply ignored
18569 Check_No_Identifiers
;
18570 Check_Arg_Count
(1);
18571 Check_Arg_Is_Integer_Literal
(Arg1
);
18579 -- The only correct use of this pragma is on its own in a file, in
18580 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
18581 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
18582 -- check for a file containing nothing but a No_Body pragma). If we
18583 -- attempt to process it during normal semantics processing, it means
18584 -- it was misplaced.
18586 when Pragma_No_Body
=>
18590 -----------------------------
18591 -- No_Elaboration_Code_All --
18592 -----------------------------
18594 -- pragma No_Elaboration_Code_All;
18596 when Pragma_No_Elaboration_Code_All
=>
18598 Check_Valid_Library_Unit_Pragma
;
18600 if Nkind
(N
) = N_Null_Statement
then
18604 -- Must appear for a spec or generic spec
18606 if not Nkind_In
(Unit
(Cunit
(Current_Sem_Unit
)),
18607 N_Generic_Package_Declaration
,
18608 N_Generic_Subprogram_Declaration
,
18609 N_Package_Declaration
,
18610 N_Subprogram_Declaration
)
18614 ("pragma% can only occur for package "
18615 & "or subprogram spec"));
18618 -- Set flag in unit table
18620 Set_No_Elab_Code_All
(Current_Sem_Unit
);
18622 -- Set restriction No_Elaboration_Code if this is the main unit
18624 if Current_Sem_Unit
= Main_Unit
then
18625 Set_Restriction
(No_Elaboration_Code
, N
);
18628 -- If we are in the main unit or in an extended main source unit,
18629 -- then we also add it to the configuration restrictions so that
18630 -- it will apply to all units in the extended main source.
18632 if Current_Sem_Unit
= Main_Unit
18633 or else In_Extended_Main_Source_Unit
(N
)
18635 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
18638 -- If in main extended unit, activate transitive with test
18640 if In_Extended_Main_Source_Unit
(N
) then
18641 Opt
.No_Elab_Code_All_Pragma
:= N
;
18644 -----------------------------
18645 -- No_Component_Reordering --
18646 -----------------------------
18648 -- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)];
18650 when Pragma_No_Component_Reordering
=> No_Comp_Reordering
: declare
18656 Check_At_Most_N_Arguments
(1);
18658 if Arg_Count
= 0 then
18659 Check_Valid_Configuration_Pragma
;
18660 Opt
.No_Component_Reordering
:= True;
18663 Check_Optional_Identifier
(Arg2
, Name_Entity
);
18664 Check_Arg_Is_Local_Name
(Arg1
);
18665 E_Id
:= Get_Pragma_Arg
(Arg1
);
18667 if Etype
(E_Id
) = Any_Type
then
18671 E
:= Entity
(E_Id
);
18673 if not Is_Record_Type
(E
) then
18674 Error_Pragma_Arg
("pragma% requires record type", Arg1
);
18677 Set_No_Reordering
(Base_Type
(E
));
18679 end No_Comp_Reordering
;
18681 --------------------------
18682 -- No_Heap_Finalization --
18683 --------------------------
18685 -- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ];
18687 when Pragma_No_Heap_Finalization
=> No_Heap_Finalization
: declare
18688 Context
: constant Node_Id
:= Parent
(N
);
18689 Typ_Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
18695 Check_No_Identifiers
;
18697 -- The pragma appears in a configuration file
18699 if No
(Context
) then
18700 Check_Arg_Count
(0);
18701 Check_Valid_Configuration_Pragma
;
18703 -- Detect a duplicate pragma
18705 if Present
(No_Heap_Finalization_Pragma
) then
18708 Prev
=> No_Heap_Finalization_Pragma
);
18712 No_Heap_Finalization_Pragma
:= N
;
18714 -- Otherwise the pragma should be associated with a library-level
18715 -- named access-to-object type.
18718 Check_Arg_Count
(1);
18719 Check_Arg_Is_Local_Name
(Arg1
);
18721 Find_Type
(Typ_Arg
);
18722 Typ
:= Entity
(Typ_Arg
);
18724 -- The type being subjected to the pragma is erroneous
18726 if Typ
= Any_Type
then
18727 Error_Pragma
("cannot find type referenced by pragma %");
18729 -- The pragma is applied to an incomplete or generic formal
18730 -- type way too early.
18732 elsif Rep_Item_Too_Early
(Typ
, N
) then
18736 Typ
:= Underlying_Type
(Typ
);
18739 -- The pragma must apply to an access-to-object type
18741 if Ekind_In
(Typ
, E_Access_Type
, E_General_Access_Type
) then
18744 -- Give a detailed error message on all other access type kinds
18746 elsif Ekind
(Typ
) = E_Access_Protected_Subprogram_Type
then
18748 ("pragma % cannot apply to access protected subprogram "
18751 elsif Ekind
(Typ
) = E_Access_Subprogram_Type
then
18753 ("pragma % cannot apply to access subprogram type");
18755 elsif Is_Anonymous_Access_Type
(Typ
) then
18757 ("pragma % cannot apply to anonymous access type");
18759 -- Give a general error message in case the pragma applies to a
18760 -- non-access type.
18764 ("pragma % must apply to library level access type");
18767 -- At this point the argument denotes an access-to-object type.
18768 -- Ensure that the type is declared at the library level.
18770 if Is_Library_Level_Entity
(Typ
) then
18773 -- Quietly ignore an access-to-object type originally declared
18774 -- at the library level within a generic, but instantiated at
18775 -- a non-library level. As a result the access-to-object type
18776 -- "loses" its No_Heap_Finalization property.
18778 elsif In_Instance
then
18783 ("pragma % must apply to library level access type");
18786 -- Detect a duplicate pragma
18788 if Present
(No_Heap_Finalization_Pragma
) then
18791 Prev
=> No_Heap_Finalization_Pragma
);
18795 Prev
:= Get_Pragma
(Typ
, Pragma_No_Heap_Finalization
);
18797 if Present
(Prev
) then
18805 Record_Rep_Item
(Typ
, N
);
18807 end No_Heap_Finalization
;
18813 -- pragma No_Inline ( NAME {, NAME} );
18815 when Pragma_No_Inline
=>
18817 Process_Inline
(Suppressed
);
18823 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
18825 when Pragma_No_Return
=> No_Return
: declare
18831 Ghost_Error_Posted
: Boolean := False;
18832 -- Flag set when an error concerning the illegal mix of Ghost and
18833 -- non-Ghost subprograms is emitted.
18835 Ghost_Id
: Entity_Id
:= Empty
;
18836 -- The entity of the first Ghost procedure encountered while
18837 -- processing the arguments of the pragma.
18841 Check_At_Least_N_Arguments
(1);
18843 -- Loop through arguments of pragma
18846 while Present
(Arg
) loop
18847 Check_Arg_Is_Local_Name
(Arg
);
18848 Id
:= Get_Pragma_Arg
(Arg
);
18851 if not Is_Entity_Name
(Id
) then
18852 Error_Pragma_Arg
("entity name required", Arg
);
18855 if Etype
(Id
) = Any_Type
then
18859 -- Loop to find matching procedures
18865 and then Scope
(E
) = Current_Scope
18867 if Ekind_In
(E
, E_Generic_Procedure
, E_Procedure
) then
18869 -- Check that the pragma is not applied to a body.
18870 -- First check the specless body case, to give a
18871 -- different error message. These checks do not apply
18872 -- if Relaxed_RM_Semantics, to accommodate other Ada
18873 -- compilers. Disable these checks under -gnatd.J.
18875 if not Debug_Flag_Dot_JJ
then
18876 if Nkind
(Parent
(Declaration_Node
(E
))) =
18878 and then not Relaxed_RM_Semantics
18881 ("pragma% requires separate spec and must come "
18885 -- Now the "specful" body case
18887 if Rep_Item_Too_Late
(E
, N
) then
18894 -- A pragma that applies to a Ghost entity becomes Ghost
18895 -- for the purposes of legality checks and removal of
18896 -- ignored Ghost code.
18898 Mark_Ghost_Pragma
(N
, E
);
18900 -- Capture the entity of the first Ghost procedure being
18901 -- processed for error detection purposes.
18903 if Is_Ghost_Entity
(E
) then
18904 if No
(Ghost_Id
) then
18908 -- Otherwise the subprogram is non-Ghost. It is illegal
18909 -- to mix references to Ghost and non-Ghost entities
18912 elsif Present
(Ghost_Id
)
18913 and then not Ghost_Error_Posted
18915 Ghost_Error_Posted
:= True;
18917 Error_Msg_Name_1
:= Pname
;
18919 ("pragma % cannot mention ghost and non-ghost "
18920 & "procedures", N
);
18922 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
18923 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
18925 Error_Msg_Sloc
:= Sloc
(E
);
18926 Error_Msg_NE
("\& # declared as non-ghost", N
, E
);
18929 -- Set flag on any alias as well
18931 if Is_Overloadable
(E
) and then Present
(Alias
(E
)) then
18932 Set_No_Return
(Alias
(E
));
18938 exit when From_Aspect_Specification
(N
);
18942 -- If entity in not in current scope it may be the enclosing
18943 -- suprogram body to which the aspect applies.
18946 if Entity
(Id
) = Current_Scope
18947 and then From_Aspect_Specification
(N
)
18949 Set_No_Return
(Entity
(Id
));
18951 Error_Pragma_Arg
("no procedure& found for pragma%", Arg
);
18963 -- pragma No_Run_Time;
18965 -- Note: this pragma is retained for backwards compatibility. See
18966 -- body of Rtsfind for full details on its handling.
18968 when Pragma_No_Run_Time
=>
18970 Check_Valid_Configuration_Pragma
;
18971 Check_Arg_Count
(0);
18973 -- Remove backward compatibility if Build_Type is FSF or GPL and
18974 -- generate a warning.
18977 Ignore
: constant Boolean := Build_Type
in FSF
.. GPL
;
18980 Error_Pragma
("pragma% is ignored, has no effect??");
18982 No_Run_Time_Mode
:= True;
18983 Configurable_Run_Time_Mode
:= True;
18985 -- Set Duration to 32 bits if word size is 32
18987 if Ttypes
.System_Word_Size
= 32 then
18988 Duration_32_Bits_On_Target
:= True;
18991 -- Set appropriate restrictions
18993 Set_Restriction
(No_Finalization
, N
);
18994 Set_Restriction
(No_Exception_Handlers
, N
);
18995 Set_Restriction
(Max_Tasks
, N
, 0);
18996 Set_Restriction
(No_Tasking
, N
);
19000 -----------------------
19001 -- No_Tagged_Streams --
19002 -----------------------
19004 -- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)];
19006 when Pragma_No_Tagged_Streams
=> No_Tagged_Strms
: declare
19012 Check_At_Most_N_Arguments
(1);
19014 -- One argument case
19016 if Arg_Count
= 1 then
19017 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19018 Check_Arg_Is_Local_Name
(Arg1
);
19019 E_Id
:= Get_Pragma_Arg
(Arg1
);
19021 if Etype
(E_Id
) = Any_Type
then
19025 E
:= Entity
(E_Id
);
19027 Check_Duplicate_Pragma
(E
);
19029 if not Is_Tagged_Type
(E
) or else Is_Derived_Type
(E
) then
19031 ("argument for pragma% must be root tagged type", Arg1
);
19034 if Rep_Item_Too_Early
(E
, N
)
19036 Rep_Item_Too_Late
(E
, N
)
19040 Set_No_Tagged_Streams_Pragma
(E
, N
);
19043 -- Zero argument case
19046 Check_Is_In_Decl_Part_Or_Package_Spec
;
19047 No_Tagged_Streams
:= N
;
19049 end No_Tagged_Strms
;
19051 ------------------------
19052 -- No_Strict_Aliasing --
19053 ------------------------
19055 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
19057 when Pragma_No_Strict_Aliasing
=> No_Strict_Aliasing
: declare
19063 Check_At_Most_N_Arguments
(1);
19065 if Arg_Count
= 0 then
19066 Check_Valid_Configuration_Pragma
;
19067 Opt
.No_Strict_Aliasing
:= True;
19070 Check_Optional_Identifier
(Arg2
, Name_Entity
);
19071 Check_Arg_Is_Local_Name
(Arg1
);
19072 E_Id
:= Get_Pragma_Arg
(Arg1
);
19074 if Etype
(E_Id
) = Any_Type
then
19078 E
:= Entity
(E_Id
);
19080 if not Is_Access_Type
(E
) then
19081 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
19084 Set_No_Strict_Aliasing
(Base_Type
(E
));
19086 end No_Strict_Aliasing
;
19088 -----------------------
19089 -- Normalize_Scalars --
19090 -----------------------
19092 -- pragma Normalize_Scalars;
19094 when Pragma_Normalize_Scalars
=>
19095 Check_Ada_83_Warning
;
19096 Check_Arg_Count
(0);
19097 Check_Valid_Configuration_Pragma
;
19099 -- Normalize_Scalars creates false positives in CodePeer, and
19100 -- incorrect negative results in GNATprove mode, so ignore this
19101 -- pragma in these modes.
19103 if not (CodePeer_Mode
or GNATprove_Mode
) then
19104 Normalize_Scalars
:= True;
19105 Init_Or_Norm_Scalars
:= True;
19112 -- pragma Obsolescent;
19114 -- pragma Obsolescent (
19115 -- [Message =>] static_string_EXPRESSION
19116 -- [,[Version =>] Ada_05]]);
19118 -- pragma Obsolescent (
19119 -- [Entity =>] NAME
19120 -- [,[Message =>] static_string_EXPRESSION
19121 -- [,[Version =>] Ada_05]] );
19123 when Pragma_Obsolescent
=> Obsolescent
: declare
19127 procedure Set_Obsolescent
(E
: Entity_Id
);
19128 -- Given an entity Ent, mark it as obsolescent if appropriate
19130 ---------------------
19131 -- Set_Obsolescent --
19132 ---------------------
19134 procedure Set_Obsolescent
(E
: Entity_Id
) is
19143 -- A pragma that applies to a Ghost entity becomes Ghost for
19144 -- the purposes of legality checks and removal of ignored Ghost
19147 Mark_Ghost_Pragma
(N
, E
);
19149 -- Entity name was given
19151 if Present
(Ename
) then
19153 -- If entity name matches, we are fine. Save entity in
19154 -- pragma argument, for ASIS use.
19156 if Chars
(Ename
) = Chars
(Ent
) then
19157 Set_Entity
(Ename
, Ent
);
19158 Generate_Reference
(Ent
, Ename
);
19160 -- If entity name does not match, only possibility is an
19161 -- enumeration literal from an enumeration type declaration.
19163 elsif Ekind
(Ent
) /= E_Enumeration_Type
then
19165 ("pragma % entity name does not match declaration");
19168 Ent
:= First_Literal
(E
);
19172 ("pragma % entity name does not match any "
19173 & "enumeration literal");
19175 elsif Chars
(Ent
) = Chars
(Ename
) then
19176 Set_Entity
(Ename
, Ent
);
19177 Generate_Reference
(Ent
, Ename
);
19181 Ent
:= Next_Literal
(Ent
);
19187 -- Ent points to entity to be marked
19189 if Arg_Count
>= 1 then
19191 -- Deal with static string argument
19193 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
19194 S
:= Strval
(Get_Pragma_Arg
(Arg1
));
19196 for J
in 1 .. String_Length
(S
) loop
19197 if not In_Character_Range
(Get_String_Char
(S
, J
)) then
19199 ("pragma% argument does not allow wide characters",
19204 Obsolescent_Warnings
.Append
19205 ((Ent
=> Ent
, Msg
=> Strval
(Get_Pragma_Arg
(Arg1
))));
19207 -- Check for Ada_05 parameter
19209 if Arg_Count
/= 1 then
19210 Check_Arg_Count
(2);
19213 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
19216 Check_Arg_Is_Identifier
(Argx
);
19218 if Chars
(Argx
) /= Name_Ada_05
then
19219 Error_Msg_Name_2
:= Name_Ada_05
;
19221 ("only allowed argument for pragma% is %", Argx
);
19224 if Ada_Version_Explicit
< Ada_2005
19225 or else not Warn_On_Ada_2005_Compatibility
19233 -- Set flag if pragma active
19236 Set_Is_Obsolescent
(Ent
);
19240 end Set_Obsolescent
;
19242 -- Start of processing for pragma Obsolescent
19247 Check_At_Most_N_Arguments
(3);
19249 -- See if first argument specifies an entity name
19253 (Chars
(Arg1
) = Name_Entity
19255 Nkind_In
(Get_Pragma_Arg
(Arg1
), N_Character_Literal
,
19257 N_Operator_Symbol
))
19259 Ename
:= Get_Pragma_Arg
(Arg1
);
19261 -- Eliminate first argument, so we can share processing
19265 Arg_Count
:= Arg_Count
- 1;
19267 -- No Entity name argument given
19273 if Arg_Count
>= 1 then
19274 Check_Optional_Identifier
(Arg1
, Name_Message
);
19276 if Arg_Count
= 2 then
19277 Check_Optional_Identifier
(Arg2
, Name_Version
);
19281 -- Get immediately preceding declaration
19284 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
19288 -- Cases where we do not follow anything other than another pragma
19292 -- First case: library level compilation unit declaration with
19293 -- the pragma immediately following the declaration.
19295 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
19297 (Defining_Entity
(Unit
(Parent
(Parent
(N
)))));
19300 -- Case 2: library unit placement for package
19304 Ent
: constant Entity_Id
:= Find_Lib_Unit_Name
;
19306 if Is_Package_Or_Generic_Package
(Ent
) then
19307 Set_Obsolescent
(Ent
);
19313 -- Cases where we must follow a declaration, including an
19314 -- abstract subprogram declaration, which is not in the
19315 -- other node subtypes.
19318 if Nkind
(Decl
) not in N_Declaration
19319 and then Nkind
(Decl
) not in N_Later_Decl_Item
19320 and then Nkind
(Decl
) not in N_Generic_Declaration
19321 and then Nkind
(Decl
) not in N_Renaming_Declaration
19322 and then Nkind
(Decl
) /= N_Abstract_Subprogram_Declaration
19325 ("pragma% misplaced, "
19326 & "must immediately follow a declaration");
19329 Set_Obsolescent
(Defining_Entity
(Decl
));
19339 -- pragma Optimize (Time | Space | Off);
19341 -- The actual check for optimize is done in Gigi. Note that this
19342 -- pragma does not actually change the optimization setting, it
19343 -- simply checks that it is consistent with the pragma.
19345 when Pragma_Optimize
=>
19346 Check_No_Identifiers
;
19347 Check_Arg_Count
(1);
19348 Check_Arg_Is_One_Of
(Arg1
, Name_Time
, Name_Space
, Name_Off
);
19350 ------------------------
19351 -- Optimize_Alignment --
19352 ------------------------
19354 -- pragma Optimize_Alignment (Time | Space | Off);
19356 when Pragma_Optimize_Alignment
=> Optimize_Alignment
: begin
19358 Check_No_Identifiers
;
19359 Check_Arg_Count
(1);
19360 Check_Valid_Configuration_Pragma
;
19363 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
19366 when Name_Off
=> Opt
.Optimize_Alignment
:= 'O';
19367 when Name_Space
=> Opt
.Optimize_Alignment
:= 'S';
19368 when Name_Time
=> Opt
.Optimize_Alignment
:= 'T';
19371 Error_Pragma_Arg
("invalid argument for pragma%", Arg1
);
19375 -- Set indication that mode is set locally. If we are in fact in a
19376 -- configuration pragma file, this setting is harmless since the
19377 -- switch will get reset anyway at the start of each unit.
19379 Optimize_Alignment_Local
:= True;
19380 end Optimize_Alignment
;
19386 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
19388 when Pragma_Ordered
=> Ordered
: declare
19389 Assoc
: constant Node_Id
:= Arg1
;
19395 Check_No_Identifiers
;
19396 Check_Arg_Count
(1);
19397 Check_Arg_Is_Local_Name
(Arg1
);
19399 Type_Id
:= Get_Pragma_Arg
(Assoc
);
19400 Find_Type
(Type_Id
);
19401 Typ
:= Entity
(Type_Id
);
19403 if Typ
= Any_Type
then
19406 Typ
:= Underlying_Type
(Typ
);
19409 if not Is_Enumeration_Type
(Typ
) then
19410 Error_Pragma
("pragma% must specify enumeration type");
19413 Check_First_Subtype
(Arg1
);
19414 Set_Has_Pragma_Ordered
(Base_Type
(Typ
));
19417 -------------------
19418 -- Overflow_Mode --
19419 -------------------
19421 -- pragma Overflow_Mode
19422 -- ([General => ] MODE [, [Assertions => ] MODE]);
19424 -- MODE := STRICT | MINIMIZED | ELIMINATED
19426 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
19427 -- since System.Bignums makes this assumption. This is true of nearly
19428 -- all (all?) targets.
19430 when Pragma_Overflow_Mode
=> Overflow_Mode
: declare
19431 function Get_Overflow_Mode
19433 Arg
: Node_Id
) return Overflow_Mode_Type
;
19434 -- Function to process one pragma argument, Arg. If an identifier
19435 -- is present, it must be Name. Mode type is returned if a valid
19436 -- argument exists, otherwise an error is signalled.
19438 -----------------------
19439 -- Get_Overflow_Mode --
19440 -----------------------
19442 function Get_Overflow_Mode
19444 Arg
: Node_Id
) return Overflow_Mode_Type
19446 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
19449 Check_Optional_Identifier
(Arg
, Name
);
19450 Check_Arg_Is_Identifier
(Argx
);
19452 if Chars
(Argx
) = Name_Strict
then
19455 elsif Chars
(Argx
) = Name_Minimized
then
19458 elsif Chars
(Argx
) = Name_Eliminated
then
19459 if Ttypes
.Standard_Long_Long_Integer_Size
/= 64 then
19461 ("Eliminated not implemented on this target", Argx
);
19467 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
19469 end Get_Overflow_Mode
;
19471 -- Start of processing for Overflow_Mode
19475 Check_At_Least_N_Arguments
(1);
19476 Check_At_Most_N_Arguments
(2);
19478 -- Process first argument
19480 Scope_Suppress
.Overflow_Mode_General
:=
19481 Get_Overflow_Mode
(Name_General
, Arg1
);
19483 -- Case of only one argument
19485 if Arg_Count
= 1 then
19486 Scope_Suppress
.Overflow_Mode_Assertions
:=
19487 Scope_Suppress
.Overflow_Mode_General
;
19489 -- Case of two arguments present
19492 Scope_Suppress
.Overflow_Mode_Assertions
:=
19493 Get_Overflow_Mode
(Name_Assertions
, Arg2
);
19497 --------------------------
19498 -- Overriding Renamings --
19499 --------------------------
19501 -- pragma Overriding_Renamings;
19503 when Pragma_Overriding_Renamings
=>
19505 Check_Arg_Count
(0);
19506 Check_Valid_Configuration_Pragma
;
19507 Overriding_Renamings
:= True;
19513 -- pragma Pack (first_subtype_LOCAL_NAME);
19515 when Pragma_Pack
=> Pack
: declare
19516 Assoc
: constant Node_Id
:= Arg1
;
19518 Ignore
: Boolean := False;
19523 Check_No_Identifiers
;
19524 Check_Arg_Count
(1);
19525 Check_Arg_Is_Local_Name
(Arg1
);
19526 Type_Id
:= Get_Pragma_Arg
(Assoc
);
19528 if not Is_Entity_Name
(Type_Id
)
19529 or else not Is_Type
(Entity
(Type_Id
))
19532 ("argument for pragma% must be type or subtype", Arg1
);
19535 Find_Type
(Type_Id
);
19536 Typ
:= Entity
(Type_Id
);
19539 or else Rep_Item_Too_Early
(Typ
, N
)
19543 Typ
:= Underlying_Type
(Typ
);
19546 -- A pragma that applies to a Ghost entity becomes Ghost for the
19547 -- purposes of legality checks and removal of ignored Ghost code.
19549 Mark_Ghost_Pragma
(N
, Typ
);
19551 if not Is_Array_Type
(Typ
) and then not Is_Record_Type
(Typ
) then
19552 Error_Pragma
("pragma% must specify array or record type");
19555 Check_First_Subtype
(Arg1
);
19556 Check_Duplicate_Pragma
(Typ
);
19560 if Is_Array_Type
(Typ
) then
19561 Ctyp
:= Component_Type
(Typ
);
19563 -- Ignore pack that does nothing
19565 if Known_Static_Esize
(Ctyp
)
19566 and then Known_Static_RM_Size
(Ctyp
)
19567 and then Esize
(Ctyp
) = RM_Size
(Ctyp
)
19568 and then Addressable
(Esize
(Ctyp
))
19573 -- Process OK pragma Pack. Note that if there is a separate
19574 -- component clause present, the Pack will be cancelled. This
19575 -- processing is in Freeze.
19577 if not Rep_Item_Too_Late
(Typ
, N
) then
19579 -- In CodePeer mode, we do not need complex front-end
19580 -- expansions related to pragma Pack, so disable handling
19583 if CodePeer_Mode
then
19586 -- Normal case where we do the pack action
19590 Set_Is_Packed
(Base_Type
(Typ
));
19591 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
19594 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
19598 -- For record types, the pack is always effective
19600 else pragma Assert
(Is_Record_Type
(Typ
));
19601 if not Rep_Item_Too_Late
(Typ
, N
) then
19602 Set_Is_Packed
(Base_Type
(Typ
));
19603 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
19604 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
19615 -- There is nothing to do here, since we did all the processing for
19616 -- this pragma in Par.Prag (so that it works properly even in syntax
19619 when Pragma_Page
=>
19626 -- pragma Part_Of (ABSTRACT_STATE);
19628 -- ABSTRACT_STATE ::= NAME
19630 when Pragma_Part_Of
=> Part_Of
: declare
19631 procedure Propagate_Part_Of
19632 (Pack_Id
: Entity_Id
;
19633 State_Id
: Entity_Id
;
19634 Instance
: Node_Id
);
19635 -- Propagate the Part_Of indicator to all abstract states and
19636 -- objects declared in the visible state space of a package
19637 -- denoted by Pack_Id. State_Id is the encapsulating state.
19638 -- Instance is the package instantiation node.
19640 -----------------------
19641 -- Propagate_Part_Of --
19642 -----------------------
19644 procedure Propagate_Part_Of
19645 (Pack_Id
: Entity_Id
;
19646 State_Id
: Entity_Id
;
19647 Instance
: Node_Id
)
19649 Has_Item
: Boolean := False;
19650 -- Flag set when the visible state space contains at least one
19651 -- abstract state or variable.
19653 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
);
19654 -- Propagate the Part_Of indicator to all abstract states and
19655 -- objects declared in the visible state space of a package
19656 -- denoted by Pack_Id.
19658 -----------------------
19659 -- Propagate_Part_Of --
19660 -----------------------
19662 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
) is
19663 Constits
: Elist_Id
;
19664 Item_Id
: Entity_Id
;
19667 -- Traverse the entity chain of the package and set relevant
19668 -- attributes of abstract states and objects declared in the
19669 -- visible state space of the package.
19671 Item_Id
:= First_Entity
(Pack_Id
);
19672 while Present
(Item_Id
)
19673 and then not In_Private_Part
(Item_Id
)
19675 -- Do not consider internally generated items
19677 if not Comes_From_Source
(Item_Id
) then
19680 -- The Part_Of indicator turns an abstract state or an
19681 -- object into a constituent of the encapsulating state.
19683 elsif Ekind_In
(Item_Id
, E_Abstract_State
,
19688 Constits
:= Part_Of_Constituents
(State_Id
);
19690 if No
(Constits
) then
19691 Constits
:= New_Elmt_List
;
19692 Set_Part_Of_Constituents
(State_Id
, Constits
);
19695 Append_Elmt
(Item_Id
, Constits
);
19696 Set_Encapsulating_State
(Item_Id
, State_Id
);
19698 -- Recursively handle nested packages and instantiations
19700 elsif Ekind
(Item_Id
) = E_Package
then
19701 Propagate_Part_Of
(Item_Id
);
19704 Next_Entity
(Item_Id
);
19706 end Propagate_Part_Of
;
19708 -- Start of processing for Propagate_Part_Of
19711 Propagate_Part_Of
(Pack_Id
);
19713 -- Detect a package instantiation that is subject to a Part_Of
19714 -- indicator, but has no visible state.
19716 if not Has_Item
then
19718 ("package instantiation & has Part_Of indicator but "
19719 & "lacks visible state", Instance
, Pack_Id
);
19721 end Propagate_Part_Of
;
19725 Constits
: Elist_Id
;
19727 Encap_Id
: Entity_Id
;
19728 Item_Id
: Entity_Id
;
19732 -- Start of processing for Part_Of
19736 Check_No_Identifiers
;
19737 Check_Arg_Count
(1);
19739 Stmt
:= Find_Related_Context
(N
, Do_Checks
=> True);
19741 -- Object declaration
19743 if Nkind
(Stmt
) = N_Object_Declaration
then
19746 -- Package instantiation
19748 elsif Nkind
(Stmt
) = N_Package_Instantiation
then
19751 -- Single concurrent type declaration
19753 elsif Is_Single_Concurrent_Type_Declaration
(Stmt
) then
19756 -- Otherwise the pragma is associated with an illegal construct
19763 -- Extract the entity of the related object declaration or package
19764 -- instantiation. In the case of the instantiation, use the entity
19765 -- of the instance spec.
19767 if Nkind
(Stmt
) = N_Package_Instantiation
then
19768 Stmt
:= Instance_Spec
(Stmt
);
19771 Item_Id
:= Defining_Entity
(Stmt
);
19773 -- A pragma that applies to a Ghost entity becomes Ghost for the
19774 -- purposes of legality checks and removal of ignored Ghost code.
19776 Mark_Ghost_Pragma
(N
, Item_Id
);
19778 -- Chain the pragma on the contract for further processing by
19779 -- Analyze_Part_Of_In_Decl_Part or for completeness.
19781 Add_Contract_Item
(N
, Item_Id
);
19783 -- A variable may act as constituent of a single concurrent type
19784 -- which in turn could be declared after the variable. Due to this
19785 -- discrepancy, the full analysis of indicator Part_Of is delayed
19786 -- until the end of the enclosing declarative region (see routine
19787 -- Analyze_Part_Of_In_Decl_Part).
19789 if Ekind
(Item_Id
) = E_Variable
then
19792 -- Otherwise indicator Part_Of applies to a constant or a package
19796 Encap
:= Get_Pragma_Arg
(Arg1
);
19798 -- Detect any discrepancies between the placement of the
19799 -- constant or package instantiation with respect to state
19800 -- space and the encapsulating state.
19804 Item_Id
=> Item_Id
,
19806 Encap_Id
=> Encap_Id
,
19810 pragma Assert
(Present
(Encap_Id
));
19812 if Ekind
(Item_Id
) = E_Constant
then
19813 Constits
:= Part_Of_Constituents
(Encap_Id
);
19815 if No
(Constits
) then
19816 Constits
:= New_Elmt_List
;
19817 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
19820 Append_Elmt
(Item_Id
, Constits
);
19821 Set_Encapsulating_State
(Item_Id
, Encap_Id
);
19823 -- Propagate the Part_Of indicator to the visible state
19824 -- space of the package instantiation.
19828 (Pack_Id
=> Item_Id
,
19829 State_Id
=> Encap_Id
,
19836 ----------------------------------
19837 -- Partition_Elaboration_Policy --
19838 ----------------------------------
19840 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
19842 when Pragma_Partition_Elaboration_Policy
=> PEP
: declare
19843 subtype PEP_Range
is Name_Id
19844 range First_Partition_Elaboration_Policy_Name
19845 .. Last_Partition_Elaboration_Policy_Name
;
19846 PEP_Val
: PEP_Range
;
19851 Check_Arg_Count
(1);
19852 Check_No_Identifiers
;
19853 Check_Arg_Is_Partition_Elaboration_Policy
(Arg1
);
19854 Check_Valid_Configuration_Pragma
;
19855 PEP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
19858 when Name_Concurrent
=> PEP
:= 'C';
19859 when Name_Sequential
=> PEP
:= 'S';
19862 if Partition_Elaboration_Policy
/= ' '
19863 and then Partition_Elaboration_Policy
/= PEP
19865 Error_Msg_Sloc
:= Partition_Elaboration_Policy_Sloc
;
19867 ("partition elaboration policy incompatible with policy#");
19869 -- Set new policy, but always preserve System_Location since we
19870 -- like the error message with the run time name.
19873 Partition_Elaboration_Policy
:= PEP
;
19875 if Partition_Elaboration_Policy_Sloc
/= System_Location
then
19876 Partition_Elaboration_Policy_Sloc
:= Loc
;
19885 -- pragma Passive [(PASSIVE_FORM)];
19887 -- PASSIVE_FORM ::= Semaphore | No
19889 when Pragma_Passive
=>
19892 if Nkind
(Parent
(N
)) /= N_Task_Definition
then
19893 Error_Pragma
("pragma% must be within task definition");
19896 if Arg_Count
/= 0 then
19897 Check_Arg_Count
(1);
19898 Check_Arg_Is_One_Of
(Arg1
, Name_Semaphore
, Name_No
);
19901 ----------------------------------
19902 -- Preelaborable_Initialization --
19903 ----------------------------------
19905 -- pragma Preelaborable_Initialization (DIRECT_NAME);
19907 when Pragma_Preelaborable_Initialization
=> Preelab_Init
: declare
19912 Check_Arg_Count
(1);
19913 Check_No_Identifiers
;
19914 Check_Arg_Is_Identifier
(Arg1
);
19915 Check_Arg_Is_Local_Name
(Arg1
);
19916 Check_First_Subtype
(Arg1
);
19917 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
19919 -- A pragma that applies to a Ghost entity becomes Ghost for the
19920 -- purposes of legality checks and removal of ignored Ghost code.
19922 Mark_Ghost_Pragma
(N
, Ent
);
19924 -- The pragma may come from an aspect on a private declaration,
19925 -- even if the freeze point at which this is analyzed in the
19926 -- private part after the full view.
19928 if Has_Private_Declaration
(Ent
)
19929 and then From_Aspect_Specification
(N
)
19933 -- Check appropriate type argument
19935 elsif Is_Private_Type
(Ent
)
19936 or else Is_Protected_Type
(Ent
)
19937 or else (Is_Generic_Type
(Ent
) and then Is_Derived_Type
(Ent
))
19939 -- AI05-0028: The pragma applies to all composite types. Note
19940 -- that we apply this binding interpretation to earlier versions
19941 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
19942 -- choice since there are other compilers that do the same.
19944 or else Is_Composite_Type
(Ent
)
19950 ("pragma % can only be applied to private, formal derived, "
19951 & "protected, or composite type", Arg1
);
19954 -- Give an error if the pragma is applied to a protected type that
19955 -- does not qualify (due to having entries, or due to components
19956 -- that do not qualify).
19958 if Is_Protected_Type
(Ent
)
19959 and then not Has_Preelaborable_Initialization
(Ent
)
19962 ("protected type & does not have preelaborable "
19963 & "initialization", Ent
);
19965 -- Otherwise mark the type as definitely having preelaborable
19969 Set_Known_To_Have_Preelab_Init
(Ent
);
19972 if Has_Pragma_Preelab_Init
(Ent
)
19973 and then Warn_On_Redundant_Constructs
19975 Error_Pragma
("?r?duplicate pragma%!");
19977 Set_Has_Pragma_Preelab_Init
(Ent
);
19981 --------------------
19982 -- Persistent_BSS --
19983 --------------------
19985 -- pragma Persistent_BSS [(object_NAME)];
19987 when Pragma_Persistent_BSS
=> Persistent_BSS
: declare
19994 Check_At_Most_N_Arguments
(1);
19996 -- Case of application to specific object (one argument)
19998 if Arg_Count
= 1 then
19999 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
20001 if not Is_Entity_Name
(Get_Pragma_Arg
(Arg1
))
20003 Ekind_In
(Entity
(Get_Pragma_Arg
(Arg1
)), E_Variable
,
20006 Error_Pragma_Arg
("pragma% only applies to objects", Arg1
);
20009 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
20011 -- A pragma that applies to a Ghost entity becomes Ghost for
20012 -- the purposes of legality checks and removal of ignored Ghost
20015 Mark_Ghost_Pragma
(N
, Ent
);
20017 -- Check for duplication before inserting in list of
20018 -- representation items.
20020 Check_Duplicate_Pragma
(Ent
);
20022 if Rep_Item_Too_Late
(Ent
, N
) then
20026 Decl
:= Parent
(Ent
);
20028 if Present
(Expression
(Decl
)) then
20030 ("object for pragma% cannot have initialization", Arg1
);
20033 if not Is_Potentially_Persistent_Type
(Etype
(Ent
)) then
20035 ("object type for pragma% is not potentially persistent",
20040 Make_Linker_Section_Pragma
20041 (Ent
, Sloc
(N
), ".persistent.bss");
20042 Insert_After
(N
, Prag
);
20045 -- Case of use as configuration pragma with no arguments
20048 Check_Valid_Configuration_Pragma
;
20049 Persistent_BSS_Mode
:= True;
20051 end Persistent_BSS
;
20053 --------------------
20054 -- Rename_Pragma --
20055 --------------------
20057 -- pragma Rename_Pragma (
20058 -- [New_Name =>] IDENTIFIER,
20059 -- [Renamed =>] pragma_IDENTIFIER);
20061 when Pragma_Rename_Pragma
=> Rename_Pragma
: declare
20062 New_Name
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20063 Old_Name
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
20067 Check_Valid_Configuration_Pragma
;
20068 Check_Arg_Count
(2);
20069 Check_Optional_Identifier
(Arg1
, Name_New_Name
);
20070 Check_Optional_Identifier
(Arg2
, Name_Renamed
);
20072 if Nkind
(New_Name
) /= N_Identifier
then
20073 Error_Pragma_Arg
("identifier expected", Arg1
);
20076 if Nkind
(Old_Name
) /= N_Identifier
then
20077 Error_Pragma_Arg
("identifier expected", Arg2
);
20080 -- The New_Name arg should not be an existing pragma (but we allow
20081 -- it; it's just a warning). The Old_Name arg must be an existing
20084 if Is_Pragma_Name
(Chars
(New_Name
)) then
20085 Error_Pragma_Arg
("??pragma is already defined", Arg1
);
20088 if not Is_Pragma_Name
(Chars
(Old_Name
)) then
20089 Error_Pragma_Arg
("existing pragma name expected", Arg1
);
20092 Map_Pragma_Name
(From
=> Chars
(New_Name
), To
=> Chars
(Old_Name
));
20099 -- pragma Polling (ON | OFF);
20101 when Pragma_Polling
=>
20103 Check_Arg_Count
(1);
20104 Check_No_Identifiers
;
20105 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
20106 Polling_Required
:= (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
);
20108 -----------------------------------
20109 -- Post/Post_Class/Postcondition --
20110 -----------------------------------
20112 -- pragma Post (Boolean_EXPRESSION);
20113 -- pragma Post_Class (Boolean_EXPRESSION);
20114 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
20115 -- [,[Message =>] String_EXPRESSION]);
20117 -- Characteristics:
20119 -- * Analysis - The annotation undergoes initial checks to verify
20120 -- the legal placement and context. Secondary checks preanalyze the
20123 -- Analyze_Pre_Post_Condition_In_Decl_Part
20125 -- * Expansion - The annotation is expanded during the expansion of
20126 -- the related subprogram [body] contract as performed in:
20128 -- Expand_Subprogram_Contract
20130 -- * Template - The annotation utilizes the generic template of the
20131 -- related subprogram [body] when it is:
20133 -- aspect on subprogram declaration
20134 -- aspect on stand-alone subprogram body
20135 -- pragma on stand-alone subprogram body
20137 -- The annotation must prepare its own template when it is:
20139 -- pragma on subprogram declaration
20141 -- * Globals - Capture of global references must occur after full
20144 -- * Instance - The annotation is instantiated automatically when
20145 -- the related generic subprogram [body] is instantiated except for
20146 -- the "pragma on subprogram declaration" case. In that scenario
20147 -- the annotation must instantiate itself.
20150 | Pragma_Post_Class
20151 | Pragma_Postcondition
20153 Analyze_Pre_Post_Condition
;
20155 --------------------------------
20156 -- Pre/Pre_Class/Precondition --
20157 --------------------------------
20159 -- pragma Pre (Boolean_EXPRESSION);
20160 -- pragma Pre_Class (Boolean_EXPRESSION);
20161 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
20162 -- [,[Message =>] String_EXPRESSION]);
20164 -- Characteristics:
20166 -- * Analysis - The annotation undergoes initial checks to verify
20167 -- the legal placement and context. Secondary checks preanalyze the
20170 -- Analyze_Pre_Post_Condition_In_Decl_Part
20172 -- * Expansion - The annotation is expanded during the expansion of
20173 -- the related subprogram [body] contract as performed in:
20175 -- Expand_Subprogram_Contract
20177 -- * Template - The annotation utilizes the generic template of the
20178 -- related subprogram [body] when it is:
20180 -- aspect on subprogram declaration
20181 -- aspect on stand-alone subprogram body
20182 -- pragma on stand-alone subprogram body
20184 -- The annotation must prepare its own template when it is:
20186 -- pragma on subprogram declaration
20188 -- * Globals - Capture of global references must occur after full
20191 -- * Instance - The annotation is instantiated automatically when
20192 -- the related generic subprogram [body] is instantiated except for
20193 -- the "pragma on subprogram declaration" case. In that scenario
20194 -- the annotation must instantiate itself.
20198 | Pragma_Precondition
20200 Analyze_Pre_Post_Condition
;
20206 -- pragma Predicate
20207 -- ([Entity =>] type_LOCAL_NAME,
20208 -- [Check =>] boolean_EXPRESSION);
20210 when Pragma_Predicate
=> Predicate
: declare
20217 Check_Arg_Count
(2);
20218 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20219 Check_Optional_Identifier
(Arg2
, Name_Check
);
20221 Check_Arg_Is_Local_Name
(Arg1
);
20223 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20224 Find_Type
(Type_Id
);
20225 Typ
:= Entity
(Type_Id
);
20227 if Typ
= Any_Type
then
20231 -- A pragma that applies to a Ghost entity becomes Ghost for the
20232 -- purposes of legality checks and removal of ignored Ghost code.
20234 Mark_Ghost_Pragma
(N
, Typ
);
20236 -- The remaining processing is simply to link the pragma on to
20237 -- the rep item chain, for processing when the type is frozen.
20238 -- This is accomplished by a call to Rep_Item_Too_Late. We also
20239 -- mark the type as having predicates.
20241 -- If the current policy for predicate checking is Ignore mark the
20242 -- subtype accordingly. In the case of predicates we consider them
20243 -- enabled unless Ignore is specified (either directly or with a
20244 -- general Assertion_Policy pragma) to preserve existing warnings.
20246 Set_Has_Predicates
(Typ
);
20248 -- Indicate that the pragma must be processed at the point the
20249 -- type is frozen, as is done for the corresponding aspect.
20251 Set_Has_Delayed_Aspects
(Typ
);
20252 Set_Has_Delayed_Freeze
(Typ
);
20254 Set_Predicates_Ignored
(Typ
,
20255 Present
(Check_Policy_List
)
20257 Policy_In_Effect
(Name_Dynamic_Predicate
) = Name_Ignore
);
20258 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
20261 -----------------------
20262 -- Predicate_Failure --
20263 -----------------------
20265 -- pragma Predicate_Failure
20266 -- ([Entity =>] type_LOCAL_NAME,
20267 -- [Message =>] string_EXPRESSION);
20269 when Pragma_Predicate_Failure
=> Predicate_Failure
: declare
20276 Check_Arg_Count
(2);
20277 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20278 Check_Optional_Identifier
(Arg2
, Name_Message
);
20280 Check_Arg_Is_Local_Name
(Arg1
);
20282 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20283 Find_Type
(Type_Id
);
20284 Typ
:= Entity
(Type_Id
);
20286 if Typ
= Any_Type
then
20290 -- A pragma that applies to a Ghost entity becomes Ghost for the
20291 -- purposes of legality checks and removal of ignored Ghost code.
20293 Mark_Ghost_Pragma
(N
, Typ
);
20295 -- The remaining processing is simply to link the pragma on to
20296 -- the rep item chain, for processing when the type is frozen.
20297 -- This is accomplished by a call to Rep_Item_Too_Late.
20299 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
20300 end Predicate_Failure
;
20306 -- pragma Preelaborate [(library_unit_NAME)];
20308 -- Set the flag Is_Preelaborated of program unit name entity
20310 when Pragma_Preelaborate
=> Preelaborate
: declare
20311 Pa
: constant Node_Id
:= Parent
(N
);
20312 Pk
: constant Node_Kind
:= Nkind
(Pa
);
20316 Check_Ada_83_Warning
;
20317 Check_Valid_Library_Unit_Pragma
;
20319 if Nkind
(N
) = N_Null_Statement
then
20323 Ent
:= Find_Lib_Unit_Name
;
20325 -- A pragma that applies to a Ghost entity becomes Ghost for the
20326 -- purposes of legality checks and removal of ignored Ghost code.
20328 Mark_Ghost_Pragma
(N
, Ent
);
20329 Check_Duplicate_Pragma
(Ent
);
20331 -- This filters out pragmas inside generic parents that show up
20332 -- inside instantiations. Pragmas that come from aspects in the
20333 -- unit are not ignored.
20335 if Present
(Ent
) then
20336 if Pk
= N_Package_Specification
20337 and then Present
(Generic_Parent
(Pa
))
20338 and then not From_Aspect_Specification
(N
)
20343 if not Debug_Flag_U
then
20344 Set_Is_Preelaborated
(Ent
);
20346 if Legacy_Elaboration_Checks
then
20347 Set_Suppress_Elaboration_Warnings
(Ent
);
20354 -------------------------------
20355 -- Prefix_Exception_Messages --
20356 -------------------------------
20358 -- pragma Prefix_Exception_Messages;
20360 when Pragma_Prefix_Exception_Messages
=>
20362 Check_Valid_Configuration_Pragma
;
20363 Check_Arg_Count
(0);
20364 Prefix_Exception_Messages
:= True;
20370 -- pragma Priority (EXPRESSION);
20372 when Pragma_Priority
=> Priority
: declare
20373 P
: constant Node_Id
:= Parent
(N
);
20378 Check_No_Identifiers
;
20379 Check_Arg_Count
(1);
20383 if Nkind
(P
) = N_Subprogram_Body
then
20384 Check_In_Main_Program
;
20386 Ent
:= Defining_Unit_Name
(Specification
(P
));
20388 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
20389 Ent
:= Defining_Identifier
(Ent
);
20392 Arg
:= Get_Pragma_Arg
(Arg1
);
20393 Analyze_And_Resolve
(Arg
, Standard_Integer
);
20397 if not Is_OK_Static_Expression
(Arg
) then
20398 Flag_Non_Static_Expr
20399 ("main subprogram priority is not static!", Arg
);
20402 -- If constraint error, then we already signalled an error
20404 elsif Raises_Constraint_Error
(Arg
) then
20407 -- Otherwise check in range except if Relaxed_RM_Semantics
20408 -- where we ignore the value if out of range.
20411 if not Relaxed_RM_Semantics
20412 and then not Is_In_Range
(Arg
, RTE
(RE_Priority
))
20415 ("main subprogram priority is out of range", Arg1
);
20418 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
20422 -- Load an arbitrary entity from System.Tasking.Stages or
20423 -- System.Tasking.Restricted.Stages (depending on the
20424 -- supported profile) to make sure that one of these packages
20425 -- is implicitly with'ed, since we need to have the tasking
20426 -- run time active for the pragma Priority to have any effect.
20427 -- Previously we with'ed the package System.Tasking, but this
20428 -- package does not trigger the required initialization of the
20429 -- run-time library.
20432 Discard
: Entity_Id
;
20433 pragma Warnings
(Off
, Discard
);
20435 if Restricted_Profile
then
20436 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
20438 Discard
:= RTE
(RE_Activate_Tasks
);
20442 -- Task or Protected, must be of type Integer
20444 elsif Nkind_In
(P
, N_Protected_Definition
, N_Task_Definition
) then
20445 Arg
:= Get_Pragma_Arg
(Arg1
);
20446 Ent
:= Defining_Identifier
(Parent
(P
));
20448 -- The expression must be analyzed in the special manner
20449 -- described in "Handling of Default and Per-Object
20450 -- Expressions" in sem.ads.
20452 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Any_Priority
));
20454 if not Is_OK_Static_Expression
(Arg
) then
20455 Check_Restriction
(Static_Priorities
, Arg
);
20458 -- Anything else is incorrect
20464 -- Check duplicate pragma before we chain the pragma in the Rep
20465 -- Item chain of Ent.
20467 Check_Duplicate_Pragma
(Ent
);
20468 Record_Rep_Item
(Ent
, N
);
20471 -----------------------------------
20472 -- Priority_Specific_Dispatching --
20473 -----------------------------------
20475 -- pragma Priority_Specific_Dispatching (
20476 -- policy_IDENTIFIER,
20477 -- first_priority_EXPRESSION,
20478 -- last_priority_EXPRESSION);
20480 when Pragma_Priority_Specific_Dispatching
=>
20481 Priority_Specific_Dispatching
: declare
20482 Prio_Id
: constant Entity_Id
:= RTE
(RE_Any_Priority
);
20483 -- This is the entity System.Any_Priority;
20486 Lower_Bound
: Node_Id
;
20487 Upper_Bound
: Node_Id
;
20493 Check_Arg_Count
(3);
20494 Check_No_Identifiers
;
20495 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
20496 Check_Valid_Configuration_Pragma
;
20497 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
20498 DP
:= Fold_Upper
(Name_Buffer
(1));
20500 Lower_Bound
:= Get_Pragma_Arg
(Arg2
);
20501 Check_Arg_Is_OK_Static_Expression
(Lower_Bound
, Standard_Integer
);
20502 Lower_Val
:= Expr_Value
(Lower_Bound
);
20504 Upper_Bound
:= Get_Pragma_Arg
(Arg3
);
20505 Check_Arg_Is_OK_Static_Expression
(Upper_Bound
, Standard_Integer
);
20506 Upper_Val
:= Expr_Value
(Upper_Bound
);
20508 -- It is not allowed to use Task_Dispatching_Policy and
20509 -- Priority_Specific_Dispatching in the same partition.
20511 if Task_Dispatching_Policy
/= ' ' then
20512 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
20514 ("pragma% incompatible with Task_Dispatching_Policy#");
20516 -- Check lower bound in range
20518 elsif Lower_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
20520 Lower_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
20523 ("first_priority is out of range", Arg2
);
20525 -- Check upper bound in range
20527 elsif Upper_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
20529 Upper_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
20532 ("last_priority is out of range", Arg3
);
20534 -- Check that the priority range is valid
20536 elsif Lower_Val
> Upper_Val
then
20538 ("last_priority_expression must be greater than or equal to "
20539 & "first_priority_expression");
20541 -- Store the new policy, but always preserve System_Location since
20542 -- we like the error message with the run-time name.
20545 -- Check overlapping in the priority ranges specified in other
20546 -- Priority_Specific_Dispatching pragmas within the same
20547 -- partition. We can only check those we know about.
20550 Specific_Dispatching
.First
.. Specific_Dispatching
.Last
20552 if Specific_Dispatching
.Table
(J
).First_Priority
in
20553 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
20554 or else Specific_Dispatching
.Table
(J
).Last_Priority
in
20555 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
20558 Specific_Dispatching
.Table
(J
).Pragma_Loc
;
20560 ("priority range overlaps with "
20561 & "Priority_Specific_Dispatching#");
20565 -- The use of Priority_Specific_Dispatching is incompatible
20566 -- with Task_Dispatching_Policy.
20568 if Task_Dispatching_Policy
/= ' ' then
20569 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
20571 ("Priority_Specific_Dispatching incompatible "
20572 & "with Task_Dispatching_Policy#");
20575 -- The use of Priority_Specific_Dispatching forces ceiling
20578 if Locking_Policy
/= ' ' and then Locking_Policy
/= 'C' then
20579 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
20581 ("Priority_Specific_Dispatching incompatible "
20582 & "with Locking_Policy#");
20584 -- Set the Ceiling_Locking policy, but preserve System_Location
20585 -- since we like the error message with the run time name.
20588 Locking_Policy
:= 'C';
20590 if Locking_Policy_Sloc
/= System_Location
then
20591 Locking_Policy_Sloc
:= Loc
;
20595 -- Add entry in the table
20597 Specific_Dispatching
.Append
20598 ((Dispatching_Policy
=> DP
,
20599 First_Priority
=> UI_To_Int
(Lower_Val
),
20600 Last_Priority
=> UI_To_Int
(Upper_Val
),
20601 Pragma_Loc
=> Loc
));
20603 end Priority_Specific_Dispatching
;
20609 -- pragma Profile (profile_IDENTIFIER);
20611 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
20613 when Pragma_Profile
=>
20615 Check_Arg_Count
(1);
20616 Check_Valid_Configuration_Pragma
;
20617 Check_No_Identifiers
;
20620 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20623 if Chars
(Argx
) = Name_Ravenscar
then
20624 Set_Ravenscar_Profile
(Ravenscar
, N
);
20626 elsif Chars
(Argx
) = Name_Gnat_Extended_Ravenscar
then
20627 Set_Ravenscar_Profile
(GNAT_Extended_Ravenscar
, N
);
20629 elsif Chars
(Argx
) = Name_Gnat_Ravenscar_EDF
then
20630 Set_Ravenscar_Profile
(GNAT_Ravenscar_EDF
, N
);
20632 elsif Chars
(Argx
) = Name_Restricted
then
20633 Set_Profile_Restrictions
20635 N
, Warn
=> Treat_Restrictions_As_Warnings
);
20637 elsif Chars
(Argx
) = Name_Rational
then
20638 Set_Rational_Profile
;
20640 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
20641 Set_Profile_Restrictions
20642 (No_Implementation_Extensions
,
20643 N
, Warn
=> Treat_Restrictions_As_Warnings
);
20646 Error_Pragma_Arg
("& is not a valid profile", Argx
);
20650 ----------------------
20651 -- Profile_Warnings --
20652 ----------------------
20654 -- pragma Profile_Warnings (profile_IDENTIFIER);
20656 -- profile_IDENTIFIER => Restricted | Ravenscar
20658 when Pragma_Profile_Warnings
=>
20660 Check_Arg_Count
(1);
20661 Check_Valid_Configuration_Pragma
;
20662 Check_No_Identifiers
;
20665 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20668 if Chars
(Argx
) = Name_Ravenscar
then
20669 Set_Profile_Restrictions
(Ravenscar
, N
, Warn
=> True);
20671 elsif Chars
(Argx
) = Name_Restricted
then
20672 Set_Profile_Restrictions
(Restricted
, N
, Warn
=> True);
20674 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
20675 Set_Profile_Restrictions
20676 (No_Implementation_Extensions
, N
, Warn
=> True);
20679 Error_Pragma_Arg
("& is not a valid profile", Argx
);
20683 --------------------------
20684 -- Propagate_Exceptions --
20685 --------------------------
20687 -- pragma Propagate_Exceptions;
20689 -- Note: this pragma is obsolete and has no effect
20691 when Pragma_Propagate_Exceptions
=>
20693 Check_Arg_Count
(0);
20695 if Warn_On_Obsolescent_Feature
then
20697 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
20698 "and has no effect?j?", N
);
20701 -----------------------------
20702 -- Provide_Shift_Operators --
20703 -----------------------------
20705 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
20707 when Pragma_Provide_Shift_Operators
=>
20708 Provide_Shift_Operators
: declare
20711 procedure Declare_Shift_Operator
(Nam
: Name_Id
);
20712 -- Insert declaration and pragma Instrinsic for named shift op
20714 ----------------------------
20715 -- Declare_Shift_Operator --
20716 ----------------------------
20718 procedure Declare_Shift_Operator
(Nam
: Name_Id
) is
20724 Make_Subprogram_Declaration
(Loc
,
20725 Make_Function_Specification
(Loc
,
20726 Defining_Unit_Name
=>
20727 Make_Defining_Identifier
(Loc
, Chars
=> Nam
),
20729 Result_Definition
=>
20730 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
)),
20732 Parameter_Specifications
=> New_List
(
20733 Make_Parameter_Specification
(Loc
,
20734 Defining_Identifier
=>
20735 Make_Defining_Identifier
(Loc
, Name_Value
),
20737 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
))),
20739 Make_Parameter_Specification
(Loc
,
20740 Defining_Identifier
=>
20741 Make_Defining_Identifier
(Loc
, Name_Amount
),
20743 New_Occurrence_Of
(Standard_Natural
, Loc
)))));
20747 Chars
=> Name_Import
,
20748 Pragma_Argument_Associations
=> New_List
(
20749 Make_Pragma_Argument_Association
(Loc
,
20750 Expression
=> Make_Identifier
(Loc
, Name_Intrinsic
)),
20751 Make_Pragma_Argument_Association
(Loc
,
20752 Expression
=> Make_Identifier
(Loc
, Nam
))));
20754 Insert_After
(N
, Import
);
20755 Insert_After
(N
, Func
);
20756 end Declare_Shift_Operator
;
20758 -- Start of processing for Provide_Shift_Operators
20762 Check_Arg_Count
(1);
20763 Check_Arg_Is_Local_Name
(Arg1
);
20765 Arg1
:= Get_Pragma_Arg
(Arg1
);
20767 -- We must have an entity name
20769 if not Is_Entity_Name
(Arg1
) then
20771 ("pragma % must apply to integer first subtype", Arg1
);
20774 -- If no Entity, means there was a prior error so ignore
20776 if Present
(Entity
(Arg1
)) then
20777 Ent
:= Entity
(Arg1
);
20779 -- Apply error checks
20781 if not Is_First_Subtype
(Ent
) then
20783 ("cannot apply pragma %",
20784 "\& is not a first subtype",
20787 elsif not Is_Integer_Type
(Ent
) then
20789 ("cannot apply pragma %",
20790 "\& is not an integer type",
20793 elsif Has_Shift_Operator
(Ent
) then
20795 ("cannot apply pragma %",
20796 "\& already has declared shift operators",
20799 elsif Is_Frozen
(Ent
) then
20801 ("pragma % appears too late",
20802 "\& is already frozen",
20806 -- Now declare the operators. We do this during analysis rather
20807 -- than expansion, since we want the operators available if we
20808 -- are operating in -gnatc or ASIS mode.
20810 Declare_Shift_Operator
(Name_Rotate_Left
);
20811 Declare_Shift_Operator
(Name_Rotate_Right
);
20812 Declare_Shift_Operator
(Name_Shift_Left
);
20813 Declare_Shift_Operator
(Name_Shift_Right
);
20814 Declare_Shift_Operator
(Name_Shift_Right_Arithmetic
);
20816 end Provide_Shift_Operators
;
20822 -- pragma Psect_Object (
20823 -- [Internal =>] LOCAL_NAME,
20824 -- [, [External =>] EXTERNAL_SYMBOL]
20825 -- [, [Size =>] EXTERNAL_SYMBOL]);
20827 when Pragma_Common_Object
20828 | Pragma_Psect_Object
20830 Psect_Object
: declare
20831 Args
: Args_List
(1 .. 3);
20832 Names
: constant Name_List
(1 .. 3) := (
20837 Internal
: Node_Id
renames Args
(1);
20838 External
: Node_Id
renames Args
(2);
20839 Size
: Node_Id
renames Args
(3);
20841 Def_Id
: Entity_Id
;
20843 procedure Check_Arg
(Arg
: Node_Id
);
20844 -- Checks that argument is either a string literal or an
20845 -- identifier, and posts error message if not.
20851 procedure Check_Arg
(Arg
: Node_Id
) is
20853 if not Nkind_In
(Original_Node
(Arg
),
20858 ("inappropriate argument for pragma %", Arg
);
20862 -- Start of processing for Common_Object/Psect_Object
20866 Gather_Associations
(Names
, Args
);
20867 Process_Extended_Import_Export_Internal_Arg
(Internal
);
20869 Def_Id
:= Entity
(Internal
);
20871 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
20873 ("pragma% must designate an object", Internal
);
20876 Check_Arg
(Internal
);
20878 if Is_Imported
(Def_Id
) or else Is_Exported
(Def_Id
) then
20880 ("cannot use pragma% for imported/exported object",
20884 if Is_Concurrent_Type
(Etype
(Internal
)) then
20886 ("cannot specify pragma % for task/protected object",
20890 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
20892 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
20894 Error_Msg_N
("??duplicate Common/Psect_Object pragma", N
);
20897 if Ekind
(Def_Id
) = E_Constant
then
20899 ("cannot specify pragma % for a constant", Internal
);
20902 if Is_Record_Type
(Etype
(Internal
)) then
20908 Ent
:= First_Entity
(Etype
(Internal
));
20909 while Present
(Ent
) loop
20910 Decl
:= Declaration_Node
(Ent
);
20912 if Ekind
(Ent
) = E_Component
20913 and then Nkind
(Decl
) = N_Component_Declaration
20914 and then Present
(Expression
(Decl
))
20915 and then Warn_On_Export_Import
20918 ("?x?object for pragma % has defaults", Internal
);
20928 if Present
(Size
) then
20932 if Present
(External
) then
20933 Check_Arg_Is_External_Name
(External
);
20936 -- If all error tests pass, link pragma on to the rep item chain
20938 Record_Rep_Item
(Def_Id
, N
);
20945 -- pragma Pure [(library_unit_NAME)];
20947 when Pragma_Pure
=> Pure
: declare
20951 Check_Ada_83_Warning
;
20953 -- If the pragma comes from a subprogram instantiation, nothing to
20954 -- check, this can happen at any level of nesting.
20956 if Is_Wrapper_Package
(Current_Scope
) then
20959 Check_Valid_Library_Unit_Pragma
;
20962 if Nkind
(N
) = N_Null_Statement
then
20966 Ent
:= Find_Lib_Unit_Name
;
20968 -- A pragma that applies to a Ghost entity becomes Ghost for the
20969 -- purposes of legality checks and removal of ignored Ghost code.
20971 Mark_Ghost_Pragma
(N
, Ent
);
20973 if not Debug_Flag_U
then
20975 Set_Has_Pragma_Pure
(Ent
);
20977 if Legacy_Elaboration_Checks
then
20978 Set_Suppress_Elaboration_Warnings
(Ent
);
20983 -------------------
20984 -- Pure_Function --
20985 -------------------
20987 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
20989 when Pragma_Pure_Function
=> Pure_Function
: declare
20990 Def_Id
: Entity_Id
;
20993 Effective
: Boolean := False;
20997 Check_Arg_Count
(1);
20998 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20999 Check_Arg_Is_Local_Name
(Arg1
);
21000 E_Id
:= Get_Pragma_Arg
(Arg1
);
21002 if Etype
(E_Id
) = Any_Type
then
21006 -- Loop through homonyms (overloadings) of referenced entity
21008 E
:= Entity
(E_Id
);
21010 -- A pragma that applies to a Ghost entity becomes Ghost for the
21011 -- purposes of legality checks and removal of ignored Ghost code.
21013 Mark_Ghost_Pragma
(N
, E
);
21015 if Present
(E
) then
21017 Def_Id
:= Get_Base_Subprogram
(E
);
21019 if not Ekind_In
(Def_Id
, E_Function
,
21020 E_Generic_Function
,
21024 ("pragma% requires a function name", Arg1
);
21027 Set_Is_Pure
(Def_Id
);
21029 if not Has_Pragma_Pure_Function
(Def_Id
) then
21030 Set_Has_Pragma_Pure_Function
(Def_Id
);
21034 exit when From_Aspect_Specification
(N
);
21036 exit when No
(E
) or else Scope
(E
) /= Current_Scope
;
21040 and then Warn_On_Redundant_Constructs
21043 ("pragma Pure_Function on& is redundant?r?",
21049 --------------------
21050 -- Queuing_Policy --
21051 --------------------
21053 -- pragma Queuing_Policy (policy_IDENTIFIER);
21055 when Pragma_Queuing_Policy
=> declare
21059 Check_Ada_83_Warning
;
21060 Check_Arg_Count
(1);
21061 Check_No_Identifiers
;
21062 Check_Arg_Is_Queuing_Policy
(Arg1
);
21063 Check_Valid_Configuration_Pragma
;
21064 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
21065 QP
:= Fold_Upper
(Name_Buffer
(1));
21067 if Queuing_Policy
/= ' '
21068 and then Queuing_Policy
/= QP
21070 Error_Msg_Sloc
:= Queuing_Policy_Sloc
;
21071 Error_Pragma
("queuing policy incompatible with policy#");
21073 -- Set new policy, but always preserve System_Location since we
21074 -- like the error message with the run time name.
21077 Queuing_Policy
:= QP
;
21079 if Queuing_Policy_Sloc
/= System_Location
then
21080 Queuing_Policy_Sloc
:= Loc
;
21089 -- pragma Rational, for compatibility with foreign compiler
21091 when Pragma_Rational
=>
21092 Set_Rational_Profile
;
21094 ---------------------
21095 -- Refined_Depends --
21096 ---------------------
21098 -- pragma Refined_Depends (DEPENDENCY_RELATION);
21100 -- DEPENDENCY_RELATION ::=
21102 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
21104 -- DEPENDENCY_CLAUSE ::=
21105 -- OUTPUT_LIST =>[+] INPUT_LIST
21106 -- | NULL_DEPENDENCY_CLAUSE
21108 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
21110 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
21112 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
21114 -- OUTPUT ::= NAME | FUNCTION_RESULT
21117 -- where FUNCTION_RESULT is a function Result attribute_reference
21119 -- Characteristics:
21121 -- * Analysis - The annotation undergoes initial checks to verify
21122 -- the legal placement and context. Secondary checks fully analyze
21123 -- the dependency clauses/global list in:
21125 -- Analyze_Refined_Depends_In_Decl_Part
21127 -- * Expansion - None.
21129 -- * Template - The annotation utilizes the generic template of the
21130 -- related subprogram body.
21132 -- * Globals - Capture of global references must occur after full
21135 -- * Instance - The annotation is instantiated automatically when
21136 -- the related generic subprogram body is instantiated.
21138 when Pragma_Refined_Depends
=> Refined_Depends
: declare
21139 Body_Id
: Entity_Id
;
21141 Spec_Id
: Entity_Id
;
21144 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21148 -- Chain the pragma on the contract for further processing by
21149 -- Analyze_Refined_Depends_In_Decl_Part.
21151 Add_Contract_Item
(N
, Body_Id
);
21153 -- The legality checks of pragmas Refined_Depends and
21154 -- Refined_Global are affected by the SPARK mode in effect and
21155 -- the volatility of the context. In addition these two pragmas
21156 -- are subject to an inherent order:
21158 -- 1) Refined_Global
21159 -- 2) Refined_Depends
21161 -- Analyze all these pragmas in the order outlined above
21163 Analyze_If_Present
(Pragma_SPARK_Mode
);
21164 Analyze_If_Present
(Pragma_Volatile_Function
);
21165 Analyze_If_Present
(Pragma_Refined_Global
);
21166 Analyze_Refined_Depends_In_Decl_Part
(N
);
21168 end Refined_Depends
;
21170 --------------------
21171 -- Refined_Global --
21172 --------------------
21174 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
21176 -- GLOBAL_SPECIFICATION ::=
21179 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
21181 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
21183 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
21184 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
21185 -- GLOBAL_ITEM ::= NAME
21187 -- Characteristics:
21189 -- * Analysis - The annotation undergoes initial checks to verify
21190 -- the legal placement and context. Secondary checks fully analyze
21191 -- the dependency clauses/global list in:
21193 -- Analyze_Refined_Global_In_Decl_Part
21195 -- * Expansion - None.
21197 -- * Template - The annotation utilizes the generic template of the
21198 -- related subprogram body.
21200 -- * Globals - Capture of global references must occur after full
21203 -- * Instance - The annotation is instantiated automatically when
21204 -- the related generic subprogram body is instantiated.
21206 when Pragma_Refined_Global
=> Refined_Global
: declare
21207 Body_Id
: Entity_Id
;
21209 Spec_Id
: Entity_Id
;
21212 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21216 -- Chain the pragma on the contract for further processing by
21217 -- Analyze_Refined_Global_In_Decl_Part.
21219 Add_Contract_Item
(N
, Body_Id
);
21221 -- The legality checks of pragmas Refined_Depends and
21222 -- Refined_Global are affected by the SPARK mode in effect and
21223 -- the volatility of the context. In addition these two pragmas
21224 -- are subject to an inherent order:
21226 -- 1) Refined_Global
21227 -- 2) Refined_Depends
21229 -- Analyze all these pragmas in the order outlined above
21231 Analyze_If_Present
(Pragma_SPARK_Mode
);
21232 Analyze_If_Present
(Pragma_Volatile_Function
);
21233 Analyze_Refined_Global_In_Decl_Part
(N
);
21234 Analyze_If_Present
(Pragma_Refined_Depends
);
21236 end Refined_Global
;
21242 -- pragma Refined_Post (boolean_EXPRESSION);
21244 -- Characteristics:
21246 -- * Analysis - The annotation is fully analyzed immediately upon
21247 -- elaboration as it cannot forward reference entities.
21249 -- * Expansion - The annotation is expanded during the expansion of
21250 -- the related subprogram body contract as performed in:
21252 -- Expand_Subprogram_Contract
21254 -- * Template - The annotation utilizes the generic template of the
21255 -- related subprogram body.
21257 -- * Globals - Capture of global references must occur after full
21260 -- * Instance - The annotation is instantiated automatically when
21261 -- the related generic subprogram body is instantiated.
21263 when Pragma_Refined_Post
=> Refined_Post
: declare
21264 Body_Id
: Entity_Id
;
21266 Spec_Id
: Entity_Id
;
21269 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
21271 -- Fully analyze the pragma when it appears inside a subprogram
21272 -- body because it cannot benefit from forward references.
21276 -- Chain the pragma on the contract for completeness
21278 Add_Contract_Item
(N
, Body_Id
);
21280 -- The legality checks of pragma Refined_Post are affected by
21281 -- the SPARK mode in effect and the volatility of the context.
21282 -- Analyze all pragmas in a specific order.
21284 Analyze_If_Present
(Pragma_SPARK_Mode
);
21285 Analyze_If_Present
(Pragma_Volatile_Function
);
21286 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
21288 -- Currently it is not possible to inline pre/postconditions on
21289 -- a subprogram subject to pragma Inline_Always.
21291 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
21295 -------------------
21296 -- Refined_State --
21297 -------------------
21299 -- pragma Refined_State (REFINEMENT_LIST);
21301 -- REFINEMENT_LIST ::=
21302 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
21304 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
21306 -- CONSTITUENT_LIST ::=
21309 -- | (CONSTITUENT {, CONSTITUENT})
21311 -- CONSTITUENT ::= object_NAME | state_NAME
21313 -- Characteristics:
21315 -- * Analysis - The annotation undergoes initial checks to verify
21316 -- the legal placement and context. Secondary checks preanalyze the
21317 -- refinement clauses in:
21319 -- Analyze_Refined_State_In_Decl_Part
21321 -- * Expansion - None.
21323 -- * Template - The annotation utilizes the template of the related
21326 -- * Globals - Capture of global references must occur after full
21329 -- * Instance - The annotation is instantiated automatically when
21330 -- the related generic package body is instantiated.
21332 when Pragma_Refined_State
=> Refined_State
: declare
21333 Pack_Decl
: Node_Id
;
21334 Spec_Id
: Entity_Id
;
21338 Check_No_Identifiers
;
21339 Check_Arg_Count
(1);
21341 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
21343 -- Ensure the proper placement of the pragma. Refined states must
21344 -- be associated with a package body.
21346 if Nkind
(Pack_Decl
) = N_Package_Body
then
21349 -- Otherwise the pragma is associated with an illegal construct
21356 Spec_Id
:= Corresponding_Spec
(Pack_Decl
);
21358 -- A pragma that applies to a Ghost entity becomes Ghost for the
21359 -- purposes of legality checks and removal of ignored Ghost code.
21361 Mark_Ghost_Pragma
(N
, Spec_Id
);
21363 -- Chain the pragma on the contract for further processing by
21364 -- Analyze_Refined_State_In_Decl_Part.
21366 Add_Contract_Item
(N
, Defining_Entity
(Pack_Decl
));
21368 -- The legality checks of pragma Refined_State are affected by the
21369 -- SPARK mode in effect. Analyze all pragmas in a specific order.
21371 Analyze_If_Present
(Pragma_SPARK_Mode
);
21373 -- State refinement is allowed only when the corresponding package
21374 -- declaration has non-null pragma Abstract_State. Refinement not
21375 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
21377 if SPARK_Mode
/= Off
21379 (No
(Abstract_States
(Spec_Id
))
21380 or else Has_Null_Abstract_State
(Spec_Id
))
21383 ("useless refinement, package & does not define abstract "
21384 & "states", N
, Spec_Id
);
21389 -----------------------
21390 -- Relative_Deadline --
21391 -----------------------
21393 -- pragma Relative_Deadline (time_span_EXPRESSION);
21395 when Pragma_Relative_Deadline
=> Relative_Deadline
: declare
21396 P
: constant Node_Id
:= Parent
(N
);
21401 Check_No_Identifiers
;
21402 Check_Arg_Count
(1);
21404 Arg
:= Get_Pragma_Arg
(Arg1
);
21406 -- The expression must be analyzed in the special manner described
21407 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
21409 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
21413 if Nkind
(P
) = N_Subprogram_Body
then
21414 Check_In_Main_Program
;
21416 -- Only Task and subprogram cases allowed
21418 elsif Nkind
(P
) /= N_Task_Definition
then
21422 -- Check duplicate pragma before we set the corresponding flag
21424 if Has_Relative_Deadline_Pragma
(P
) then
21425 Error_Pragma
("duplicate pragma% not allowed");
21428 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
21429 -- Relative_Deadline pragma node cannot be inserted in the Rep
21430 -- Item chain of Ent since it is rewritten by the expander as a
21431 -- procedure call statement that will break the chain.
21433 Set_Has_Relative_Deadline_Pragma
(P
);
21434 end Relative_Deadline
;
21436 ------------------------
21437 -- Remote_Access_Type --
21438 ------------------------
21440 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
21442 when Pragma_Remote_Access_Type
=> Remote_Access_Type
: declare
21447 Check_Arg_Count
(1);
21448 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21449 Check_Arg_Is_Local_Name
(Arg1
);
21451 E
:= Entity
(Get_Pragma_Arg
(Arg1
));
21453 -- A pragma that applies to a Ghost entity becomes Ghost for the
21454 -- purposes of legality checks and removal of ignored Ghost code.
21456 Mark_Ghost_Pragma
(N
, E
);
21458 if Nkind
(Parent
(E
)) = N_Formal_Type_Declaration
21459 and then Ekind
(E
) = E_General_Access_Type
21460 and then Is_Class_Wide_Type
(Directly_Designated_Type
(E
))
21461 and then Scope
(Root_Type
(Directly_Designated_Type
(E
)))
21463 and then Is_Valid_Remote_Object_Type
21464 (Root_Type
(Directly_Designated_Type
(E
)))
21466 Set_Is_Remote_Types
(E
);
21470 ("pragma% applies only to formal access-to-class-wide types",
21473 end Remote_Access_Type
;
21475 ---------------------------
21476 -- Remote_Call_Interface --
21477 ---------------------------
21479 -- pragma Remote_Call_Interface [(library_unit_NAME)];
21481 when Pragma_Remote_Call_Interface
=> Remote_Call_Interface
: declare
21482 Cunit_Node
: Node_Id
;
21483 Cunit_Ent
: Entity_Id
;
21487 Check_Ada_83_Warning
;
21488 Check_Valid_Library_Unit_Pragma
;
21490 if Nkind
(N
) = N_Null_Statement
then
21494 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21495 K
:= Nkind
(Unit
(Cunit_Node
));
21496 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21498 -- A pragma that applies to a Ghost entity becomes Ghost for the
21499 -- purposes of legality checks and removal of ignored Ghost code.
21501 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21503 if K
= N_Package_Declaration
21504 or else K
= N_Generic_Package_Declaration
21505 or else K
= N_Subprogram_Declaration
21506 or else K
= N_Generic_Subprogram_Declaration
21507 or else (K
= N_Subprogram_Body
21508 and then Acts_As_Spec
(Unit
(Cunit_Node
)))
21513 "pragma% must apply to package or subprogram declaration");
21516 Set_Is_Remote_Call_Interface
(Cunit_Ent
);
21517 end Remote_Call_Interface
;
21523 -- pragma Remote_Types [(library_unit_NAME)];
21525 when Pragma_Remote_Types
=> Remote_Types
: declare
21526 Cunit_Node
: Node_Id
;
21527 Cunit_Ent
: Entity_Id
;
21530 Check_Ada_83_Warning
;
21531 Check_Valid_Library_Unit_Pragma
;
21533 if Nkind
(N
) = N_Null_Statement
then
21537 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21538 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21540 -- A pragma that applies to a Ghost entity becomes Ghost for the
21541 -- purposes of legality checks and removal of ignored Ghost code.
21543 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21545 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
21546 N_Generic_Package_Declaration
)
21549 ("pragma% can only apply to a package declaration");
21552 Set_Is_Remote_Types
(Cunit_Ent
);
21559 -- pragma Ravenscar;
21561 when Pragma_Ravenscar
=>
21563 Check_Arg_Count
(0);
21564 Check_Valid_Configuration_Pragma
;
21565 Set_Ravenscar_Profile
(Ravenscar
, N
);
21567 if Warn_On_Obsolescent_Feature
then
21569 ("pragma Ravenscar is an obsolescent feature?j?", N
);
21571 ("|use pragma Profile (Ravenscar) instead?j?", N
);
21574 -------------------------
21575 -- Restricted_Run_Time --
21576 -------------------------
21578 -- pragma Restricted_Run_Time;
21580 when Pragma_Restricted_Run_Time
=>
21582 Check_Arg_Count
(0);
21583 Check_Valid_Configuration_Pragma
;
21584 Set_Profile_Restrictions
21585 (Restricted
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
21587 if Warn_On_Obsolescent_Feature
then
21589 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
21592 ("|use pragma Profile (Restricted) instead?j?", N
);
21599 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
21602 -- restriction_IDENTIFIER
21603 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21605 when Pragma_Restrictions
=>
21606 Process_Restrictions_Or_Restriction_Warnings
21607 (Warn
=> Treat_Restrictions_As_Warnings
);
21609 --------------------------
21610 -- Restriction_Warnings --
21611 --------------------------
21613 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
21616 -- restriction_IDENTIFIER
21617 -- | restriction_parameter_IDENTIFIER => EXPRESSION
21619 when Pragma_Restriction_Warnings
=>
21621 Process_Restrictions_Or_Restriction_Warnings
(Warn
=> True);
21627 -- pragma Reviewable;
21629 when Pragma_Reviewable
=>
21630 Check_Ada_83_Warning
;
21631 Check_Arg_Count
(0);
21633 -- Call dummy debugging function rv. This is done to assist front
21634 -- end debugging. By placing a Reviewable pragma in the source
21635 -- program, a breakpoint on rv catches this place in the source,
21636 -- allowing convenient stepping to the point of interest.
21640 --------------------------
21641 -- Secondary_Stack_Size --
21642 --------------------------
21644 -- pragma Secondary_Stack_Size (EXPRESSION);
21646 when Pragma_Secondary_Stack_Size
=> Secondary_Stack_Size
: declare
21647 P
: constant Node_Id
:= Parent
(N
);
21653 Check_No_Identifiers
;
21654 Check_Arg_Count
(1);
21656 if Nkind
(P
) = N_Task_Definition
then
21657 Arg
:= Get_Pragma_Arg
(Arg1
);
21658 Ent
:= Defining_Identifier
(Parent
(P
));
21660 -- The expression must be analyzed in the special manner
21661 -- described in "Handling of Default Expressions" in sem.ads.
21663 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
21665 -- The pragma cannot appear if the No_Secondary_Stack
21666 -- restriction is in effect.
21668 Check_Restriction
(No_Secondary_Stack
, Arg
);
21670 -- Anything else is incorrect
21676 -- Check duplicate pragma before we chain the pragma in the Rep
21677 -- Item chain of Ent.
21679 Check_Duplicate_Pragma
(Ent
);
21680 Record_Rep_Item
(Ent
, N
);
21681 end Secondary_Stack_Size
;
21683 --------------------------
21684 -- Short_Circuit_And_Or --
21685 --------------------------
21687 -- pragma Short_Circuit_And_Or;
21689 when Pragma_Short_Circuit_And_Or
=>
21691 Check_Arg_Count
(0);
21692 Check_Valid_Configuration_Pragma
;
21693 Short_Circuit_And_Or
:= True;
21695 -------------------
21696 -- Share_Generic --
21697 -------------------
21699 -- pragma Share_Generic (GNAME {, GNAME});
21701 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
21703 when Pragma_Share_Generic
=>
21705 Process_Generic_List
;
21711 -- pragma Shared (LOCAL_NAME);
21713 when Pragma_Shared
=>
21715 Process_Atomic_Independent_Shared_Volatile
;
21717 --------------------
21718 -- Shared_Passive --
21719 --------------------
21721 -- pragma Shared_Passive [(library_unit_NAME)];
21723 -- Set the flag Is_Shared_Passive of program unit name entity
21725 when Pragma_Shared_Passive
=> Shared_Passive
: declare
21726 Cunit_Node
: Node_Id
;
21727 Cunit_Ent
: Entity_Id
;
21730 Check_Ada_83_Warning
;
21731 Check_Valid_Library_Unit_Pragma
;
21733 if Nkind
(N
) = N_Null_Statement
then
21737 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
21738 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
21740 -- A pragma that applies to a Ghost entity becomes Ghost for the
21741 -- purposes of legality checks and removal of ignored Ghost code.
21743 Mark_Ghost_Pragma
(N
, Cunit_Ent
);
21745 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
21746 N_Generic_Package_Declaration
)
21749 ("pragma% can only apply to a package declaration");
21752 Set_Is_Shared_Passive
(Cunit_Ent
);
21753 end Shared_Passive
;
21755 -----------------------
21756 -- Short_Descriptors --
21757 -----------------------
21759 -- pragma Short_Descriptors;
21761 -- Recognize and validate, but otherwise ignore
21763 when Pragma_Short_Descriptors
=>
21765 Check_Arg_Count
(0);
21766 Check_Valid_Configuration_Pragma
;
21768 ------------------------------
21769 -- Simple_Storage_Pool_Type --
21770 ------------------------------
21772 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
21774 when Pragma_Simple_Storage_Pool_Type
=>
21775 Simple_Storage_Pool_Type
: declare
21781 Check_Arg_Count
(1);
21782 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
21784 Type_Id
:= Get_Pragma_Arg
(Arg1
);
21785 Find_Type
(Type_Id
);
21786 Typ
:= Entity
(Type_Id
);
21788 if Typ
= Any_Type
then
21792 -- A pragma that applies to a Ghost entity becomes Ghost for the
21793 -- purposes of legality checks and removal of ignored Ghost code.
21795 Mark_Ghost_Pragma
(N
, Typ
);
21797 -- We require the pragma to apply to a type declared in a package
21798 -- declaration, but not (immediately) within a package body.
21800 if Ekind
(Current_Scope
) /= E_Package
21801 or else In_Package_Body
(Current_Scope
)
21804 ("pragma% can only apply to type declared immediately "
21805 & "within a package declaration");
21808 -- A simple storage pool type must be an immutably limited record
21809 -- or private type. If the pragma is given for a private type,
21810 -- the full type is similarly restricted (which is checked later
21811 -- in Freeze_Entity).
21813 if Is_Record_Type
(Typ
)
21814 and then not Is_Limited_View
(Typ
)
21817 ("pragma% can only apply to explicitly limited record type");
21819 elsif Is_Private_Type
(Typ
) and then not Is_Limited_Type
(Typ
) then
21821 ("pragma% can only apply to a private type that is limited");
21823 elsif not Is_Record_Type
(Typ
)
21824 and then not Is_Private_Type
(Typ
)
21827 ("pragma% can only apply to limited record or private type");
21830 Record_Rep_Item
(Typ
, N
);
21831 end Simple_Storage_Pool_Type
;
21833 ----------------------
21834 -- Source_File_Name --
21835 ----------------------
21837 -- There are five forms for this pragma:
21839 -- pragma Source_File_Name (
21840 -- [UNIT_NAME =>] unit_NAME,
21841 -- BODY_FILE_NAME => STRING_LITERAL
21842 -- [, [INDEX =>] INTEGER_LITERAL]);
21844 -- pragma Source_File_Name (
21845 -- [UNIT_NAME =>] unit_NAME,
21846 -- SPEC_FILE_NAME => STRING_LITERAL
21847 -- [, [INDEX =>] INTEGER_LITERAL]);
21849 -- pragma Source_File_Name (
21850 -- BODY_FILE_NAME => STRING_LITERAL
21851 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21852 -- [, CASING => CASING_SPEC]);
21854 -- pragma Source_File_Name (
21855 -- SPEC_FILE_NAME => STRING_LITERAL
21856 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21857 -- [, CASING => CASING_SPEC]);
21859 -- pragma Source_File_Name (
21860 -- SUBUNIT_FILE_NAME => STRING_LITERAL
21861 -- [, DOT_REPLACEMENT => STRING_LITERAL]
21862 -- [, CASING => CASING_SPEC]);
21864 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
21866 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
21867 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
21868 -- only be used when no project file is used, while SFNP can only be
21869 -- used when a project file is used.
21871 -- No processing here. Processing was completed during parsing, since
21872 -- we need to have file names set as early as possible. Units are
21873 -- loaded well before semantic processing starts.
21875 -- The only processing we defer to this point is the check for
21876 -- correct placement.
21878 when Pragma_Source_File_Name
=>
21880 Check_Valid_Configuration_Pragma
;
21882 ------------------------------
21883 -- Source_File_Name_Project --
21884 ------------------------------
21886 -- See Source_File_Name for syntax
21888 -- No processing here. Processing was completed during parsing, since
21889 -- we need to have file names set as early as possible. Units are
21890 -- loaded well before semantic processing starts.
21892 -- The only processing we defer to this point is the check for
21893 -- correct placement.
21895 when Pragma_Source_File_Name_Project
=>
21897 Check_Valid_Configuration_Pragma
;
21899 -- Check that a pragma Source_File_Name_Project is used only in a
21900 -- configuration pragmas file.
21902 -- Pragmas Source_File_Name_Project should only be generated by
21903 -- the Project Manager in configuration pragmas files.
21905 -- This is really an ugly test. It seems to depend on some
21906 -- accidental and undocumented property. At the very least it
21907 -- needs to be documented, but it would be better to have a
21908 -- clean way of testing if we are in a configuration file???
21910 if Present
(Parent
(N
)) then
21912 ("pragma% can only appear in a configuration pragmas file");
21915 ----------------------
21916 -- Source_Reference --
21917 ----------------------
21919 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
21921 -- Nothing to do, all processing completed in Par.Prag, since we need
21922 -- the information for possible parser messages that are output.
21924 when Pragma_Source_Reference
=>
21931 -- pragma SPARK_Mode [(On | Off)];
21933 when Pragma_SPARK_Mode
=> Do_SPARK_Mode
: declare
21934 Mode_Id
: SPARK_Mode_Type
;
21936 procedure Check_Pragma_Conformance
21937 (Context_Pragma
: Node_Id
;
21938 Entity
: Entity_Id
;
21939 Entity_Pragma
: Node_Id
);
21940 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
21941 -- conformance of pragma N depending the following scenarios:
21943 -- If pragma Context_Pragma is not Empty, verify that pragma N is
21944 -- compatible with the pragma Context_Pragma that was inherited
21945 -- from the context:
21946 -- * If the mode of Context_Pragma is ON, then the new mode can
21948 -- * If the mode of Context_Pragma is OFF, then the only allowed
21949 -- new mode is also OFF. Emit error if this is not the case.
21951 -- If Entity is not Empty, verify that pragma N is compatible with
21952 -- pragma Entity_Pragma that belongs to Entity.
21953 -- * If Entity_Pragma is Empty, always issue an error as this
21954 -- corresponds to the case where a previous section of Entity
21955 -- has no SPARK_Mode set.
21956 -- * If the mode of Entity_Pragma is ON, then the new mode can
21958 -- * If the mode of Entity_Pragma is OFF, then the only allowed
21959 -- new mode is also OFF. Emit error if this is not the case.
21961 procedure Check_Library_Level_Entity
(E
: Entity_Id
);
21962 -- Subsidiary to routines Process_xxx. Verify that the related
21963 -- entity E subject to pragma SPARK_Mode is library-level.
21965 procedure Process_Body
(Decl
: Node_Id
);
21966 -- Verify the legality of pragma SPARK_Mode when it appears as the
21967 -- top of the body declarations of entry, package, protected unit,
21968 -- subprogram or task unit body denoted by Decl.
21970 procedure Process_Overloadable
(Decl
: Node_Id
);
21971 -- Verify the legality of pragma SPARK_Mode when it applies to an
21972 -- entry or [generic] subprogram declaration denoted by Decl.
21974 procedure Process_Private_Part
(Decl
: Node_Id
);
21975 -- Verify the legality of pragma SPARK_Mode when it appears at the
21976 -- top of the private declarations of a package spec, protected or
21977 -- task unit declaration denoted by Decl.
21979 procedure Process_Statement_Part
(Decl
: Node_Id
);
21980 -- Verify the legality of pragma SPARK_Mode when it appears at the
21981 -- top of the statement sequence of a package body denoted by node
21984 procedure Process_Visible_Part
(Decl
: Node_Id
);
21985 -- Verify the legality of pragma SPARK_Mode when it appears at the
21986 -- top of the visible declarations of a package spec, protected or
21987 -- task unit declaration denoted by Decl. The routine is also used
21988 -- on protected or task units declared without a definition.
21990 procedure Set_SPARK_Context
;
21991 -- Subsidiary to routines Process_xxx. Set the global variables
21992 -- which represent the mode of the context from pragma N. Ensure
21993 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
21995 ------------------------------
21996 -- Check_Pragma_Conformance --
21997 ------------------------------
21999 procedure Check_Pragma_Conformance
22000 (Context_Pragma
: Node_Id
;
22001 Entity
: Entity_Id
;
22002 Entity_Pragma
: Node_Id
)
22004 Err_Id
: Entity_Id
;
22008 -- The current pragma may appear without an argument. If this
22009 -- is the case, associate all error messages with the pragma
22012 if Present
(Arg1
) then
22018 -- The mode of the current pragma is compared against that of
22019 -- an enclosing context.
22021 if Present
(Context_Pragma
) then
22022 pragma Assert
(Nkind
(Context_Pragma
) = N_Pragma
);
22024 -- Issue an error if the new mode is less restrictive than
22025 -- that of the context.
22027 if Get_SPARK_Mode_From_Annotation
(Context_Pragma
) = Off
22028 and then Get_SPARK_Mode_From_Annotation
(N
) = On
22031 ("cannot change SPARK_Mode from Off to On", Err_N
);
22032 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
22033 Error_Msg_N
("\SPARK_Mode was set to Off#", Err_N
);
22038 -- The mode of the current pragma is compared against that of
22039 -- an initial package, protected type, subprogram or task type
22042 if Present
(Entity
) then
22044 -- A simple protected or task type is transformed into an
22045 -- anonymous type whose name cannot be used to issue error
22046 -- messages. Recover the original entity of the type.
22048 if Ekind_In
(Entity
, E_Protected_Type
, E_Task_Type
) then
22051 (Original_Node
(Unit_Declaration_Node
(Entity
)));
22056 -- Both the initial declaration and the completion carry
22057 -- SPARK_Mode pragmas.
22059 if Present
(Entity_Pragma
) then
22060 pragma Assert
(Nkind
(Entity_Pragma
) = N_Pragma
);
22062 -- Issue an error if the new mode is less restrictive
22063 -- than that of the initial declaration.
22065 if Get_SPARK_Mode_From_Annotation
(Entity_Pragma
) = Off
22066 and then Get_SPARK_Mode_From_Annotation
(N
) = On
22068 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
22069 Error_Msg_Sloc
:= Sloc
(Entity_Pragma
);
22071 ("\value Off was set for SPARK_Mode on&#",
22076 -- Otherwise the initial declaration lacks a SPARK_Mode
22077 -- pragma in which case the current pragma is illegal as
22078 -- it cannot "complete".
22081 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
22082 Error_Msg_Sloc
:= Sloc
(Err_Id
);
22084 ("\no value was set for SPARK_Mode on&#",
22089 end Check_Pragma_Conformance
;
22091 --------------------------------
22092 -- Check_Library_Level_Entity --
22093 --------------------------------
22095 procedure Check_Library_Level_Entity
(E
: Entity_Id
) is
22096 procedure Add_Entity_To_Name_Buffer
;
22097 -- Add the E_Kind of entity E to the name buffer
22099 -------------------------------
22100 -- Add_Entity_To_Name_Buffer --
22101 -------------------------------
22103 procedure Add_Entity_To_Name_Buffer
is
22105 if Ekind_In
(E
, E_Entry
, E_Entry_Family
) then
22106 Add_Str_To_Name_Buffer
("entry");
22108 elsif Ekind_In
(E
, E_Generic_Package
,
22112 Add_Str_To_Name_Buffer
("package");
22114 elsif Ekind_In
(E
, E_Protected_Body
, E_Protected_Type
) then
22115 Add_Str_To_Name_Buffer
("protected type");
22117 elsif Ekind_In
(E
, E_Function
,
22118 E_Generic_Function
,
22119 E_Generic_Procedure
,
22123 Add_Str_To_Name_Buffer
("subprogram");
22126 pragma Assert
(Ekind_In
(E
, E_Task_Body
, E_Task_Type
));
22127 Add_Str_To_Name_Buffer
("task type");
22129 end Add_Entity_To_Name_Buffer
;
22133 Msg_1
: constant String := "incorrect placement of pragma%";
22136 -- Start of processing for Check_Library_Level_Entity
22139 if not Is_Library_Level_Entity
(E
) then
22140 Error_Msg_Name_1
:= Pname
;
22141 Error_Msg_N
(Fix_Error
(Msg_1
), N
);
22144 Add_Str_To_Name_Buffer
("\& is not a library-level ");
22145 Add_Entity_To_Name_Buffer
;
22147 Msg_2
:= Name_Find
;
22148 Error_Msg_NE
(Get_Name_String
(Msg_2
), N
, E
);
22152 end Check_Library_Level_Entity
;
22158 procedure Process_Body
(Decl
: Node_Id
) is
22159 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22160 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
22163 -- Ignore pragma when applied to the special body created for
22164 -- inlining, recognized by its internal name _Parent.
22166 if Chars
(Body_Id
) = Name_uParent
then
22170 Check_Library_Level_Entity
(Body_Id
);
22172 -- For entry bodies, verify the legality against:
22173 -- * The mode of the context
22174 -- * The mode of the spec (if any)
22176 if Nkind_In
(Decl
, N_Entry_Body
, N_Subprogram_Body
) then
22178 -- A stand-alone subprogram body
22180 if Body_Id
= Spec_Id
then
22181 Check_Pragma_Conformance
22182 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22184 Entity_Pragma
=> Empty
);
22186 -- An entry or subprogram body that completes a previous
22190 Check_Pragma_Conformance
22191 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22193 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
22197 Set_SPARK_Pragma
(Body_Id
, N
);
22198 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22200 -- For package bodies, verify the legality against:
22201 -- * The mode of the context
22202 -- * The mode of the private part
22204 -- This case is separated from protected and task bodies
22205 -- because the statement part of the package body inherits
22206 -- the mode of the body declarations.
22208 elsif Nkind
(Decl
) = N_Package_Body
then
22209 Check_Pragma_Conformance
22210 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22212 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
22215 Set_SPARK_Pragma
(Body_Id
, N
);
22216 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22217 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
22218 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
22220 -- For protected and task bodies, verify the legality against:
22221 -- * The mode of the context
22222 -- * The mode of the private part
22226 (Nkind_In
(Decl
, N_Protected_Body
, N_Task_Body
));
22228 Check_Pragma_Conformance
22229 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
22231 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
22234 Set_SPARK_Pragma
(Body_Id
, N
);
22235 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
22239 --------------------------
22240 -- Process_Overloadable --
22241 --------------------------
22243 procedure Process_Overloadable
(Decl
: Node_Id
) is
22244 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22245 Spec_Typ
: constant Entity_Id
:= Etype
(Spec_Id
);
22248 Check_Library_Level_Entity
(Spec_Id
);
22250 -- Verify the legality against:
22251 -- * The mode of the context
22253 Check_Pragma_Conformance
22254 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
22256 Entity_Pragma
=> Empty
);
22258 Set_SPARK_Pragma
(Spec_Id
, N
);
22259 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
22261 -- When the pragma applies to the anonymous object created for
22262 -- a single task type, decorate the type as well. This scenario
22263 -- arises when the single task type lacks a task definition,
22264 -- therefore there is no issue with respect to a potential
22265 -- pragma SPARK_Mode in the private part.
22267 -- task type Anon_Task_Typ;
22268 -- Obj : Anon_Task_Typ;
22269 -- pragma SPARK_Mode ...;
22271 if Is_Single_Task_Object
(Spec_Id
) then
22272 Set_SPARK_Pragma
(Spec_Typ
, N
);
22273 Set_SPARK_Pragma_Inherited
(Spec_Typ
, False);
22274 Set_SPARK_Aux_Pragma
(Spec_Typ
, N
);
22275 Set_SPARK_Aux_Pragma_Inherited
(Spec_Typ
, True);
22277 end Process_Overloadable
;
22279 --------------------------
22280 -- Process_Private_Part --
22281 --------------------------
22283 procedure Process_Private_Part
(Decl
: Node_Id
) is
22284 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22287 Check_Library_Level_Entity
(Spec_Id
);
22289 -- Verify the legality against:
22290 -- * The mode of the visible declarations
22292 Check_Pragma_Conformance
22293 (Context_Pragma
=> Empty
,
22295 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
22298 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
22299 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, False);
22300 end Process_Private_Part
;
22302 ----------------------------
22303 -- Process_Statement_Part --
22304 ----------------------------
22306 procedure Process_Statement_Part
(Decl
: Node_Id
) is
22307 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22310 Check_Library_Level_Entity
(Body_Id
);
22312 -- Verify the legality against:
22313 -- * The mode of the body declarations
22315 Check_Pragma_Conformance
22316 (Context_Pragma
=> Empty
,
22318 Entity_Pragma
=> SPARK_Pragma
(Body_Id
));
22321 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
22322 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, False);
22323 end Process_Statement_Part
;
22325 --------------------------
22326 -- Process_Visible_Part --
22327 --------------------------
22329 procedure Process_Visible_Part
(Decl
: Node_Id
) is
22330 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
22331 Obj_Id
: Entity_Id
;
22334 Check_Library_Level_Entity
(Spec_Id
);
22336 -- Verify the legality against:
22337 -- * The mode of the context
22339 Check_Pragma_Conformance
22340 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
22342 Entity_Pragma
=> Empty
);
22344 -- A task unit declared without a definition does not set the
22345 -- SPARK_Mode of the context because the task does not have any
22346 -- entries that could inherit the mode.
22348 if not Nkind_In
(Decl
, N_Single_Task_Declaration
,
22349 N_Task_Type_Declaration
)
22354 Set_SPARK_Pragma
(Spec_Id
, N
);
22355 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
22356 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
22357 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, True);
22359 -- When the pragma applies to a single protected or task type,
22360 -- decorate the corresponding anonymous object as well.
22362 -- protected Anon_Prot_Typ is
22363 -- pragma SPARK_Mode ...;
22365 -- end Anon_Prot_Typ;
22367 -- Obj : Anon_Prot_Typ;
22369 if Is_Single_Concurrent_Type
(Spec_Id
) then
22370 Obj_Id
:= Anonymous_Object
(Spec_Id
);
22372 Set_SPARK_Pragma
(Obj_Id
, N
);
22373 Set_SPARK_Pragma_Inherited
(Obj_Id
, False);
22375 end Process_Visible_Part
;
22377 -----------------------
22378 -- Set_SPARK_Context --
22379 -----------------------
22381 procedure Set_SPARK_Context
is
22383 SPARK_Mode
:= Mode_Id
;
22384 SPARK_Mode_Pragma
:= N
;
22385 end Set_SPARK_Context
;
22393 -- Start of processing for Do_SPARK_Mode
22396 -- When a SPARK_Mode pragma appears inside an instantiation whose
22397 -- enclosing context has SPARK_Mode set to "off", the pragma has
22398 -- no semantic effect.
22400 if Ignore_SPARK_Mode_Pragmas_In_Instance
then
22401 Rewrite
(N
, Make_Null_Statement
(Loc
));
22407 Check_No_Identifiers
;
22408 Check_At_Most_N_Arguments
(1);
22410 -- Check the legality of the mode (no argument = ON)
22412 if Arg_Count
= 1 then
22413 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
22414 Mode
:= Chars
(Get_Pragma_Arg
(Arg1
));
22419 Mode_Id
:= Get_SPARK_Mode_Type
(Mode
);
22420 Context
:= Parent
(N
);
22422 -- The pragma appears in a configuration file
22424 if No
(Context
) then
22425 Check_Valid_Configuration_Pragma
;
22427 if Present
(SPARK_Mode_Pragma
) then
22430 Prev
=> SPARK_Mode_Pragma
);
22436 -- The pragma acts as a configuration pragma in a compilation unit
22438 -- pragma SPARK_Mode ...;
22439 -- package Pack is ...;
22441 elsif Nkind
(Context
) = N_Compilation_Unit
22442 and then List_Containing
(N
) = Context_Items
(Context
)
22444 Check_Valid_Configuration_Pragma
;
22447 -- Otherwise the placement of the pragma within the tree dictates
22448 -- its associated construct. Inspect the declarative list where
22449 -- the pragma resides to find a potential construct.
22453 while Present
(Stmt
) loop
22455 -- Skip prior pragmas, but check for duplicates. Note that
22456 -- this also takes care of pragmas generated for aspects.
22458 if Nkind
(Stmt
) = N_Pragma
then
22459 if Pragma_Name
(Stmt
) = Pname
then
22466 -- The pragma applies to an expression function that has
22467 -- already been rewritten into a subprogram declaration.
22469 -- function Expr_Func return ... is (...);
22470 -- pragma SPARK_Mode ...;
22472 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
22473 and then Nkind
(Original_Node
(Stmt
)) =
22474 N_Expression_Function
22476 Process_Overloadable
(Stmt
);
22479 -- The pragma applies to the anonymous object created for a
22480 -- single concurrent type.
22482 -- protected type Anon_Prot_Typ ...;
22483 -- Obj : Anon_Prot_Typ;
22484 -- pragma SPARK_Mode ...;
22486 elsif Nkind
(Stmt
) = N_Object_Declaration
22487 and then Is_Single_Concurrent_Object
22488 (Defining_Entity
(Stmt
))
22490 Process_Overloadable
(Stmt
);
22493 -- Skip internally generated code
22495 elsif not Comes_From_Source
(Stmt
) then
22498 -- The pragma applies to an entry or [generic] subprogram
22502 -- pragma SPARK_Mode ...;
22505 -- procedure Proc ...;
22506 -- pragma SPARK_Mode ...;
22508 elsif Nkind_In
(Stmt
, N_Generic_Subprogram_Declaration
,
22509 N_Subprogram_Declaration
)
22510 or else (Nkind
(Stmt
) = N_Entry_Declaration
22511 and then Is_Protected_Type
22512 (Scope
(Defining_Entity
(Stmt
))))
22514 Process_Overloadable
(Stmt
);
22517 -- Otherwise the pragma does not apply to a legal construct
22518 -- or it does not appear at the top of a declarative or a
22519 -- statement list. Issue an error and stop the analysis.
22529 -- The pragma applies to a package or a subprogram that acts as
22530 -- a compilation unit.
22532 -- procedure Proc ...;
22533 -- pragma SPARK_Mode ...;
22535 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
22536 Context
:= Unit
(Parent
(Context
));
22539 -- The pragma appears at the top of entry, package, protected
22540 -- unit, subprogram or task unit body declarations.
22542 -- entry Ent when ... is
22543 -- pragma SPARK_Mode ...;
22545 -- package body Pack is
22546 -- pragma SPARK_Mode ...;
22548 -- procedure Proc ... is
22549 -- pragma SPARK_Mode;
22551 -- protected body Prot is
22552 -- pragma SPARK_Mode ...;
22554 if Nkind_In
(Context
, N_Entry_Body
,
22560 Process_Body
(Context
);
22562 -- The pragma appears at the top of the visible or private
22563 -- declaration of a package spec, protected or task unit.
22566 -- pragma SPARK_Mode ...;
22568 -- pragma SPARK_Mode ...;
22570 -- protected [type] Prot is
22571 -- pragma SPARK_Mode ...;
22573 -- pragma SPARK_Mode ...;
22575 elsif Nkind_In
(Context
, N_Package_Specification
,
22576 N_Protected_Definition
,
22579 if List_Containing
(N
) = Visible_Declarations
(Context
) then
22580 Process_Visible_Part
(Parent
(Context
));
22582 Process_Private_Part
(Parent
(Context
));
22585 -- The pragma appears at the top of package body statements
22587 -- package body Pack is
22589 -- pragma SPARK_Mode;
22591 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
22592 and then Nkind
(Parent
(Context
)) = N_Package_Body
22594 Process_Statement_Part
(Parent
(Context
));
22596 -- The pragma appeared as an aspect of a [generic] subprogram
22597 -- declaration that acts as a compilation unit.
22600 -- procedure Proc ...;
22601 -- pragma SPARK_Mode ...;
22603 elsif Nkind_In
(Context
, N_Generic_Subprogram_Declaration
,
22604 N_Subprogram_Declaration
)
22606 Process_Overloadable
(Context
);
22608 -- The pragma does not apply to a legal construct, issue error
22616 --------------------------------
22617 -- Static_Elaboration_Desired --
22618 --------------------------------
22620 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
22622 when Pragma_Static_Elaboration_Desired
=>
22624 Check_At_Most_N_Arguments
(1);
22626 if Is_Compilation_Unit
(Current_Scope
)
22627 and then Ekind
(Current_Scope
) = E_Package
22629 Set_Static_Elaboration_Desired
(Current_Scope
, True);
22631 Error_Pragma
("pragma% must apply to a library-level package");
22638 -- pragma Storage_Size (EXPRESSION);
22640 when Pragma_Storage_Size
=> Storage_Size
: declare
22641 P
: constant Node_Id
:= Parent
(N
);
22645 Check_No_Identifiers
;
22646 Check_Arg_Count
(1);
22648 -- The expression must be analyzed in the special manner described
22649 -- in "Handling of Default Expressions" in sem.ads.
22651 Arg
:= Get_Pragma_Arg
(Arg1
);
22652 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
22654 if not Is_OK_Static_Expression
(Arg
) then
22655 Check_Restriction
(Static_Storage_Size
, Arg
);
22658 if Nkind
(P
) /= N_Task_Definition
then
22663 if Has_Storage_Size_Pragma
(P
) then
22664 Error_Pragma
("duplicate pragma% not allowed");
22666 Set_Has_Storage_Size_Pragma
(P
, True);
22669 Record_Rep_Item
(Defining_Identifier
(Parent
(P
)), N
);
22677 -- pragma Storage_Unit (NUMERIC_LITERAL);
22679 -- Only permitted argument is System'Storage_Unit value
22681 when Pragma_Storage_Unit
=>
22682 Check_No_Identifiers
;
22683 Check_Arg_Count
(1);
22684 Check_Arg_Is_Integer_Literal
(Arg1
);
22686 if Intval
(Get_Pragma_Arg
(Arg1
)) /=
22687 UI_From_Int
(Ttypes
.System_Storage_Unit
)
22689 Error_Msg_Uint_1
:= UI_From_Int
(Ttypes
.System_Storage_Unit
);
22691 ("the only allowed argument for pragma% is ^", Arg1
);
22694 --------------------
22695 -- Stream_Convert --
22696 --------------------
22698 -- pragma Stream_Convert (
22699 -- [Entity =>] type_LOCAL_NAME,
22700 -- [Read =>] function_NAME,
22701 -- [Write =>] function NAME);
22703 when Pragma_Stream_Convert
=> Stream_Convert
: declare
22704 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
);
22705 -- Check that the given argument is the name of a local function
22706 -- of one argument that is not overloaded earlier in the current
22707 -- local scope. A check is also made that the argument is a
22708 -- function with one parameter.
22710 --------------------------------------
22711 -- Check_OK_Stream_Convert_Function --
22712 --------------------------------------
22714 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
) is
22718 Check_Arg_Is_Local_Name
(Arg
);
22719 Ent
:= Entity
(Get_Pragma_Arg
(Arg
));
22721 if Has_Homonym
(Ent
) then
22723 ("argument for pragma% may not be overloaded", Arg
);
22726 if Ekind
(Ent
) /= E_Function
22727 or else No
(First_Formal
(Ent
))
22728 or else Present
(Next_Formal
(First_Formal
(Ent
)))
22731 ("argument for pragma% must be function of one argument",
22734 end Check_OK_Stream_Convert_Function
;
22736 -- Start of processing for Stream_Convert
22740 Check_Arg_Order
((Name_Entity
, Name_Read
, Name_Write
));
22741 Check_Arg_Count
(3);
22742 Check_Optional_Identifier
(Arg1
, Name_Entity
);
22743 Check_Optional_Identifier
(Arg2
, Name_Read
);
22744 Check_Optional_Identifier
(Arg3
, Name_Write
);
22745 Check_Arg_Is_Local_Name
(Arg1
);
22746 Check_OK_Stream_Convert_Function
(Arg2
);
22747 Check_OK_Stream_Convert_Function
(Arg3
);
22750 Typ
: constant Entity_Id
:=
22751 Underlying_Type
(Entity
(Get_Pragma_Arg
(Arg1
)));
22752 Read
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg2
));
22753 Write
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg3
));
22756 Check_First_Subtype
(Arg1
);
22758 -- Check for too early or too late. Note that we don't enforce
22759 -- the rule about primitive operations in this case, since, as
22760 -- is the case for explicit stream attributes themselves, these
22761 -- restrictions are not appropriate. Note that the chaining of
22762 -- the pragma by Rep_Item_Too_Late is actually the critical
22763 -- processing done for this pragma.
22765 if Rep_Item_Too_Early
(Typ
, N
)
22767 Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True)
22772 -- Return if previous error
22774 if Etype
(Typ
) = Any_Type
22776 Etype
(Read
) = Any_Type
22778 Etype
(Write
) = Any_Type
22785 if Underlying_Type
(Etype
(Read
)) /= Typ
then
22787 ("incorrect return type for function&", Arg2
);
22790 if Underlying_Type
(Etype
(First_Formal
(Write
))) /= Typ
then
22792 ("incorrect parameter type for function&", Arg3
);
22795 if Underlying_Type
(Etype
(First_Formal
(Read
))) /=
22796 Underlying_Type
(Etype
(Write
))
22799 ("result type of & does not match Read parameter type",
22803 end Stream_Convert
;
22809 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22811 -- This is processed by the parser since some of the style checks
22812 -- take place during source scanning and parsing. This means that
22813 -- we don't need to issue error messages here.
22815 when Pragma_Style_Checks
=> Style_Checks
: declare
22816 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
22822 Check_No_Identifiers
;
22824 -- Two argument form
22826 if Arg_Count
= 2 then
22827 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
22834 E_Id
:= Get_Pragma_Arg
(Arg2
);
22837 if not Is_Entity_Name
(E_Id
) then
22839 ("second argument of pragma% must be entity name",
22843 E
:= Entity
(E_Id
);
22845 if not Ignore_Style_Checks_Pragmas
then
22850 Set_Suppress_Style_Checks
22851 (E
, Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Off
);
22852 exit when No
(Homonym
(E
));
22859 -- One argument form
22862 Check_Arg_Count
(1);
22864 if Nkind
(A
) = N_String_Literal
then
22868 Slen
: constant Natural := Natural (String_Length
(S
));
22869 Options
: String (1 .. Slen
);
22875 C
:= Get_String_Char
(S
, Pos
(J
));
22876 exit when not In_Character_Range
(C
);
22877 Options
(J
) := Get_Character
(C
);
22879 -- If at end of string, set options. As per discussion
22880 -- above, no need to check for errors, since we issued
22881 -- them in the parser.
22884 if not Ignore_Style_Checks_Pragmas
then
22885 Set_Style_Check_Options
(Options
);
22895 elsif Nkind
(A
) = N_Identifier
then
22896 if Chars
(A
) = Name_All_Checks
then
22897 if not Ignore_Style_Checks_Pragmas
then
22899 Set_GNAT_Style_Check_Options
;
22901 Set_Default_Style_Check_Options
;
22905 elsif Chars
(A
) = Name_On
then
22906 if not Ignore_Style_Checks_Pragmas
then
22907 Style_Check
:= True;
22910 elsif Chars
(A
) = Name_Off
then
22911 if not Ignore_Style_Checks_Pragmas
then
22912 Style_Check
:= False;
22923 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
22925 when Pragma_Subtitle
=>
22927 Check_Arg_Count
(1);
22928 Check_Optional_Identifier
(Arg1
, Name_Subtitle
);
22929 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
22936 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
22938 when Pragma_Suppress
=>
22939 Process_Suppress_Unsuppress
(Suppress_Case
=> True);
22945 -- pragma Suppress_All;
22947 -- The only check made here is that the pragma has no arguments.
22948 -- There are no placement rules, and the processing required (setting
22949 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
22950 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
22951 -- then creates and inserts a pragma Suppress (All_Checks).
22953 when Pragma_Suppress_All
=>
22955 Check_Arg_Count
(0);
22957 -------------------------
22958 -- Suppress_Debug_Info --
22959 -------------------------
22961 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
22963 when Pragma_Suppress_Debug_Info
=> Suppress_Debug_Info
: declare
22964 Nam_Id
: Entity_Id
;
22968 Check_Arg_Count
(1);
22969 Check_Optional_Identifier
(Arg1
, Name_Entity
);
22970 Check_Arg_Is_Local_Name
(Arg1
);
22972 Nam_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
22974 -- A pragma that applies to a Ghost entity becomes Ghost for the
22975 -- purposes of legality checks and removal of ignored Ghost code.
22977 Mark_Ghost_Pragma
(N
, Nam_Id
);
22978 Set_Debug_Info_Off
(Nam_Id
);
22979 end Suppress_Debug_Info
;
22981 ----------------------------------
22982 -- Suppress_Exception_Locations --
22983 ----------------------------------
22985 -- pragma Suppress_Exception_Locations;
22987 when Pragma_Suppress_Exception_Locations
=>
22989 Check_Arg_Count
(0);
22990 Check_Valid_Configuration_Pragma
;
22991 Exception_Locations_Suppressed
:= True;
22993 -----------------------------
22994 -- Suppress_Initialization --
22995 -----------------------------
22997 -- pragma Suppress_Initialization ([Entity =>] type_Name);
22999 when Pragma_Suppress_Initialization
=> Suppress_Init
: declare
23005 Check_Arg_Count
(1);
23006 Check_Optional_Identifier
(Arg1
, Name_Entity
);
23007 Check_Arg_Is_Local_Name
(Arg1
);
23009 E_Id
:= Get_Pragma_Arg
(Arg1
);
23011 if Etype
(E_Id
) = Any_Type
then
23015 E
:= Entity
(E_Id
);
23017 -- A pragma that applies to a Ghost entity becomes Ghost for the
23018 -- purposes of legality checks and removal of ignored Ghost code.
23020 Mark_Ghost_Pragma
(N
, E
);
23022 if not Is_Type
(E
) and then Ekind
(E
) /= E_Variable
then
23024 ("pragma% requires variable, type or subtype", Arg1
);
23027 if Rep_Item_Too_Early
(E
, N
)
23029 Rep_Item_Too_Late
(E
, N
, FOnly
=> True)
23034 -- For incomplete/private type, set flag on full view
23036 if Is_Incomplete_Or_Private_Type
(E
) then
23037 if No
(Full_View
(Base_Type
(E
))) then
23039 ("argument of pragma% cannot be an incomplete type", Arg1
);
23041 Set_Suppress_Initialization
(Full_View
(Base_Type
(E
)));
23044 -- For first subtype, set flag on base type
23046 elsif Is_First_Subtype
(E
) then
23047 Set_Suppress_Initialization
(Base_Type
(E
));
23049 -- For other than first subtype, set flag on subtype or variable
23052 Set_Suppress_Initialization
(E
);
23060 -- pragma System_Name (DIRECT_NAME);
23062 -- Syntax check: one argument, which must be the identifier GNAT or
23063 -- the identifier GCC, no other identifiers are acceptable.
23065 when Pragma_System_Name
=>
23067 Check_No_Identifiers
;
23068 Check_Arg_Count
(1);
23069 Check_Arg_Is_One_Of
(Arg1
, Name_Gcc
, Name_Gnat
);
23071 -----------------------------
23072 -- Task_Dispatching_Policy --
23073 -----------------------------
23075 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
23077 when Pragma_Task_Dispatching_Policy
=> declare
23081 Check_Ada_83_Warning
;
23082 Check_Arg_Count
(1);
23083 Check_No_Identifiers
;
23084 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
23085 Check_Valid_Configuration_Pragma
;
23086 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
23087 DP
:= Fold_Upper
(Name_Buffer
(1));
23089 if Task_Dispatching_Policy
/= ' '
23090 and then Task_Dispatching_Policy
/= DP
23092 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
23094 ("task dispatching policy incompatible with policy#");
23096 -- Set new policy, but always preserve System_Location since we
23097 -- like the error message with the run time name.
23100 Task_Dispatching_Policy
:= DP
;
23102 if Task_Dispatching_Policy_Sloc
/= System_Location
then
23103 Task_Dispatching_Policy_Sloc
:= Loc
;
23112 -- pragma Task_Info (EXPRESSION);
23114 when Pragma_Task_Info
=> Task_Info
: declare
23115 P
: constant Node_Id
:= Parent
(N
);
23121 if Warn_On_Obsolescent_Feature
then
23123 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
23124 & "instead?j?", N
);
23127 if Nkind
(P
) /= N_Task_Definition
then
23128 Error_Pragma
("pragma% must appear in task definition");
23131 Check_No_Identifiers
;
23132 Check_Arg_Count
(1);
23134 Analyze_And_Resolve
23135 (Get_Pragma_Arg
(Arg1
), RTE
(RE_Task_Info_Type
));
23137 if Etype
(Get_Pragma_Arg
(Arg1
)) = Any_Type
then
23141 Ent
:= Defining_Identifier
(Parent
(P
));
23143 -- Check duplicate pragma before we chain the pragma in the Rep
23144 -- Item chain of Ent.
23147 (Ent
, Name_Task_Info
, Check_Parents
=> False)
23149 Error_Pragma
("duplicate pragma% not allowed");
23152 Record_Rep_Item
(Ent
, N
);
23159 -- pragma Task_Name (string_EXPRESSION);
23161 when Pragma_Task_Name
=> Task_Name
: declare
23162 P
: constant Node_Id
:= Parent
(N
);
23167 Check_No_Identifiers
;
23168 Check_Arg_Count
(1);
23170 Arg
:= Get_Pragma_Arg
(Arg1
);
23172 -- The expression is used in the call to Create_Task, and must be
23173 -- expanded there, not in the context of the current spec. It must
23174 -- however be analyzed to capture global references, in case it
23175 -- appears in a generic context.
23177 Preanalyze_And_Resolve
(Arg
, Standard_String
);
23179 if Nkind
(P
) /= N_Task_Definition
then
23183 Ent
:= Defining_Identifier
(Parent
(P
));
23185 -- Check duplicate pragma before we chain the pragma in the Rep
23186 -- Item chain of Ent.
23189 (Ent
, Name_Task_Name
, Check_Parents
=> False)
23191 Error_Pragma
("duplicate pragma% not allowed");
23194 Record_Rep_Item
(Ent
, N
);
23201 -- pragma Task_Storage (
23202 -- [Task_Type =>] LOCAL_NAME,
23203 -- [Top_Guard =>] static_integer_EXPRESSION);
23205 when Pragma_Task_Storage
=> Task_Storage
: declare
23206 Args
: Args_List
(1 .. 2);
23207 Names
: constant Name_List
(1 .. 2) := (
23211 Task_Type
: Node_Id
renames Args
(1);
23212 Top_Guard
: Node_Id
renames Args
(2);
23218 Gather_Associations
(Names
, Args
);
23220 if No
(Task_Type
) then
23222 ("missing task_type argument for pragma%");
23225 Check_Arg_Is_Local_Name
(Task_Type
);
23227 Ent
:= Entity
(Task_Type
);
23229 if not Is_Task_Type
(Ent
) then
23231 ("argument for pragma% must be task type", Task_Type
);
23234 if No
(Top_Guard
) then
23236 ("pragma% takes two arguments", Task_Type
);
23238 Check_Arg_Is_OK_Static_Expression
(Top_Guard
, Any_Integer
);
23241 Check_First_Subtype
(Task_Type
);
23243 if Rep_Item_Too_Late
(Ent
, N
) then
23252 -- pragma Test_Case
23253 -- ([Name =>] Static_String_EXPRESSION
23254 -- ,[Mode =>] MODE_TYPE
23255 -- [, Requires => Boolean_EXPRESSION]
23256 -- [, Ensures => Boolean_EXPRESSION]);
23258 -- MODE_TYPE ::= Nominal | Robustness
23260 -- Characteristics:
23262 -- * Analysis - The annotation undergoes initial checks to verify
23263 -- the legal placement and context. Secondary checks preanalyze the
23266 -- Analyze_Test_Case_In_Decl_Part
23268 -- * Expansion - None.
23270 -- * Template - The annotation utilizes the generic template of the
23271 -- related subprogram when it is:
23273 -- aspect on subprogram declaration
23275 -- The annotation must prepare its own template when it is:
23277 -- pragma on subprogram declaration
23279 -- * Globals - Capture of global references must occur after full
23282 -- * Instance - The annotation is instantiated automatically when
23283 -- the related generic subprogram is instantiated except for the
23284 -- "pragma on subprogram declaration" case. In that scenario the
23285 -- annotation must instantiate itself.
23287 when Pragma_Test_Case
=> Test_Case
: declare
23288 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
);
23289 -- Ensure that the contract of subprogram Subp_Id does not contain
23290 -- another Test_Case pragma with the same Name as the current one.
23292 -------------------------
23293 -- Check_Distinct_Name --
23294 -------------------------
23296 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
) is
23297 Items
: constant Node_Id
:= Contract
(Subp_Id
);
23298 Name
: constant String_Id
:= Get_Name_From_CTC_Pragma
(N
);
23302 -- Inspect all Test_Case pragma of the related subprogram
23303 -- looking for one with a duplicate "Name" argument.
23305 if Present
(Items
) then
23306 Prag
:= Contract_Test_Cases
(Items
);
23307 while Present
(Prag
) loop
23308 if Pragma_Name
(Prag
) = Name_Test_Case
23310 and then String_Equal
23311 (Name
, Get_Name_From_CTC_Pragma
(Prag
))
23313 Error_Msg_Sloc
:= Sloc
(Prag
);
23314 Error_Pragma
("name for pragma % is already used #");
23317 Prag
:= Next_Pragma
(Prag
);
23320 end Check_Distinct_Name
;
23324 Pack_Decl
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
23327 Subp_Decl
: Node_Id
;
23328 Subp_Id
: Entity_Id
;
23330 -- Start of processing for Test_Case
23334 Check_At_Least_N_Arguments
(2);
23335 Check_At_Most_N_Arguments
(4);
23337 ((Name_Name
, Name_Mode
, Name_Requires
, Name_Ensures
));
23341 Check_Optional_Identifier
(Arg1
, Name_Name
);
23342 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
23346 Check_Optional_Identifier
(Arg2
, Name_Mode
);
23347 Check_Arg_Is_One_Of
(Arg2
, Name_Nominal
, Name_Robustness
);
23349 -- Arguments "Requires" and "Ensures"
23351 if Present
(Arg3
) then
23352 if Present
(Arg4
) then
23353 Check_Identifier
(Arg3
, Name_Requires
);
23354 Check_Identifier
(Arg4
, Name_Ensures
);
23356 Check_Identifier_Is_One_Of
23357 (Arg3
, Name_Requires
, Name_Ensures
);
23361 -- Pragma Test_Case must be associated with a subprogram declared
23362 -- in a library-level package. First determine whether the current
23363 -- compilation unit is a legal context.
23365 if Nkind_In
(Pack_Decl
, N_Package_Declaration
,
23366 N_Generic_Package_Declaration
)
23370 -- Otherwise the placement is illegal
23374 ("pragma % must be specified within a package declaration");
23378 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
);
23380 -- Find the enclosing context
23382 Context
:= Parent
(Subp_Decl
);
23384 if Present
(Context
) then
23385 Context
:= Parent
(Context
);
23388 -- Verify the placement of the pragma
23390 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
23392 ("pragma % cannot be applied to abstract subprogram");
23395 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
23396 Error_Pragma
("pragma % cannot be applied to entry");
23399 -- The context is a [generic] subprogram declared at the top level
23400 -- of the [generic] package unit.
23402 elsif Nkind_In
(Subp_Decl
, N_Generic_Subprogram_Declaration
,
23403 N_Subprogram_Declaration
)
23404 and then Present
(Context
)
23405 and then Nkind_In
(Context
, N_Generic_Package_Declaration
,
23406 N_Package_Declaration
)
23410 -- Otherwise the placement is illegal
23414 ("pragma % must be applied to a library-level subprogram "
23419 Subp_Id
:= Defining_Entity
(Subp_Decl
);
23421 -- A pragma that applies to a Ghost entity becomes Ghost for the
23422 -- purposes of legality checks and removal of ignored Ghost code.
23424 Mark_Ghost_Pragma
(N
, Subp_Id
);
23426 -- Chain the pragma on the contract for further processing by
23427 -- Analyze_Test_Case_In_Decl_Part.
23429 Add_Contract_Item
(N
, Subp_Id
);
23431 -- Preanalyze the original aspect argument "Name" for ASIS or for
23432 -- a generic subprogram to properly capture global references.
23434 if ASIS_Mode
or else Is_Generic_Subprogram
(Subp_Id
) then
23435 Asp_Arg
:= Test_Case_Arg
(N
, Name_Name
, From_Aspect
=> True);
23437 if Present
(Asp_Arg
) then
23439 -- The argument appears with an identifier in association
23442 if Nkind
(Asp_Arg
) = N_Component_Association
then
23443 Asp_Arg
:= Expression
(Asp_Arg
);
23446 Check_Expr_Is_OK_Static_Expression
23447 (Asp_Arg
, Standard_String
);
23451 -- Ensure that the all Test_Case pragmas of the related subprogram
23452 -- have distinct names.
23454 Check_Distinct_Name
(Subp_Id
);
23456 -- Fully analyze the pragma when it appears inside an entry
23457 -- or subprogram body because it cannot benefit from forward
23460 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
23462 N_Subprogram_Body_Stub
)
23464 -- The legality checks of pragma Test_Case are affected by the
23465 -- SPARK mode in effect and the volatility of the context.
23466 -- Analyze all pragmas in a specific order.
23468 Analyze_If_Present
(Pragma_SPARK_Mode
);
23469 Analyze_If_Present
(Pragma_Volatile_Function
);
23470 Analyze_Test_Case_In_Decl_Part
(N
);
23474 --------------------------
23475 -- Thread_Local_Storage --
23476 --------------------------
23478 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
23480 when Pragma_Thread_Local_Storage
=> Thread_Local_Storage
: declare
23486 Check_Arg_Count
(1);
23487 Check_Optional_Identifier
(Arg1
, Name_Entity
);
23488 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
23490 Id
:= Get_Pragma_Arg
(Arg1
);
23493 if not Is_Entity_Name
(Id
)
23494 or else Ekind
(Entity
(Id
)) /= E_Variable
23496 Error_Pragma_Arg
("local variable name required", Arg1
);
23501 -- A pragma that applies to a Ghost entity becomes Ghost for the
23502 -- purposes of legality checks and removal of ignored Ghost code.
23504 Mark_Ghost_Pragma
(N
, E
);
23506 if Rep_Item_Too_Early
(E
, N
)
23508 Rep_Item_Too_Late
(E
, N
)
23513 Set_Has_Pragma_Thread_Local_Storage
(E
);
23514 Set_Has_Gigi_Rep_Item
(E
);
23515 end Thread_Local_Storage
;
23521 -- pragma Time_Slice (static_duration_EXPRESSION);
23523 when Pragma_Time_Slice
=> Time_Slice
: declare
23529 Check_Arg_Count
(1);
23530 Check_No_Identifiers
;
23531 Check_In_Main_Program
;
23532 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_Duration
);
23534 if not Error_Posted
(Arg1
) then
23536 while Present
(Nod
) loop
23537 if Nkind
(Nod
) = N_Pragma
23538 and then Pragma_Name
(Nod
) = Name_Time_Slice
23540 Error_Msg_Name_1
:= Pname
;
23541 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
23548 -- Process only if in main unit
23550 if Get_Source_Unit
(Loc
) = Main_Unit
then
23551 Opt
.Time_Slice_Set
:= True;
23552 Val
:= Expr_Value_R
(Get_Pragma_Arg
(Arg1
));
23554 if Val
<= Ureal_0
then
23555 Opt
.Time_Slice_Value
:= 0;
23557 elsif Val
> UR_From_Uint
(UI_From_Int
(1000)) then
23558 Opt
.Time_Slice_Value
:= 1_000_000_000
;
23561 Opt
.Time_Slice_Value
:=
23562 UI_To_Int
(UR_To_Uint
(Val
* UI_From_Int
(1_000_000
)));
23571 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
23573 -- TITLING_OPTION ::=
23574 -- [Title =>] STRING_LITERAL
23575 -- | [Subtitle =>] STRING_LITERAL
23577 when Pragma_Title
=> Title
: declare
23578 Args
: Args_List
(1 .. 2);
23579 Names
: constant Name_List
(1 .. 2) := (
23585 Gather_Associations
(Names
, Args
);
23588 for J
in 1 .. 2 loop
23589 if Present
(Args
(J
)) then
23590 Check_Arg_Is_OK_Static_Expression
23591 (Args
(J
), Standard_String
);
23596 ----------------------------
23597 -- Type_Invariant[_Class] --
23598 ----------------------------
23600 -- pragma Type_Invariant[_Class]
23601 -- ([Entity =>] type_LOCAL_NAME,
23602 -- [Check =>] EXPRESSION);
23604 when Pragma_Type_Invariant
23605 | Pragma_Type_Invariant_Class
23607 Type_Invariant
: declare
23608 I_Pragma
: Node_Id
;
23611 Check_Arg_Count
(2);
23613 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
23614 -- setting Class_Present for the Type_Invariant_Class case.
23616 Set_Class_Present
(N
, Prag_Id
= Pragma_Type_Invariant_Class
);
23617 I_Pragma
:= New_Copy
(N
);
23618 Set_Pragma_Identifier
23619 (I_Pragma
, Make_Identifier
(Loc
, Name_Invariant
));
23620 Rewrite
(N
, I_Pragma
);
23621 Set_Analyzed
(N
, False);
23623 end Type_Invariant
;
23625 ---------------------
23626 -- Unchecked_Union --
23627 ---------------------
23629 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
23631 when Pragma_Unchecked_Union
=> Unchecked_Union
: declare
23632 Assoc
: constant Node_Id
:= Arg1
;
23633 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
23643 Check_No_Identifiers
;
23644 Check_Arg_Count
(1);
23645 Check_Arg_Is_Local_Name
(Arg1
);
23647 Find_Type
(Type_Id
);
23649 Typ
:= Entity
(Type_Id
);
23651 -- A pragma that applies to a Ghost entity becomes Ghost for the
23652 -- purposes of legality checks and removal of ignored Ghost code.
23654 Mark_Ghost_Pragma
(N
, Typ
);
23657 or else Rep_Item_Too_Early
(Typ
, N
)
23661 Typ
:= Underlying_Type
(Typ
);
23664 if Rep_Item_Too_Late
(Typ
, N
) then
23668 Check_First_Subtype
(Arg1
);
23670 -- Note remaining cases are references to a type in the current
23671 -- declarative part. If we find an error, we post the error on
23672 -- the relevant type declaration at an appropriate point.
23674 if not Is_Record_Type
(Typ
) then
23675 Error_Msg_N
("unchecked union must be record type", Typ
);
23678 elsif Is_Tagged_Type
(Typ
) then
23679 Error_Msg_N
("unchecked union must not be tagged", Typ
);
23682 elsif not Has_Discriminants
(Typ
) then
23684 ("unchecked union must have one discriminant", Typ
);
23687 -- Note: in previous versions of GNAT we used to check for limited
23688 -- types and give an error, but in fact the standard does allow
23689 -- Unchecked_Union on limited types, so this check was removed.
23691 -- Similarly, GNAT used to require that all discriminants have
23692 -- default values, but this is not mandated by the RM.
23694 -- Proceed with basic error checks completed
23697 Tdef
:= Type_Definition
(Declaration_Node
(Typ
));
23698 Clist
:= Component_List
(Tdef
);
23700 -- Check presence of component list and variant part
23702 if No
(Clist
) or else No
(Variant_Part
(Clist
)) then
23704 ("unchecked union must have variant part", Tdef
);
23708 -- Check components
23710 Comp
:= First_Non_Pragma
(Component_Items
(Clist
));
23711 while Present
(Comp
) loop
23712 Check_Component
(Comp
, Typ
);
23713 Next_Non_Pragma
(Comp
);
23716 -- Check variant part
23718 Vpart
:= Variant_Part
(Clist
);
23720 Variant
:= First_Non_Pragma
(Variants
(Vpart
));
23721 while Present
(Variant
) loop
23722 Check_Variant
(Variant
, Typ
);
23723 Next_Non_Pragma
(Variant
);
23727 Set_Is_Unchecked_Union
(Typ
);
23728 Set_Convention
(Typ
, Convention_C
);
23729 Set_Has_Unchecked_Union
(Base_Type
(Typ
));
23730 Set_Is_Unchecked_Union
(Base_Type
(Typ
));
23731 end Unchecked_Union
;
23733 ----------------------------
23734 -- Unevaluated_Use_Of_Old --
23735 ----------------------------
23737 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
23739 when Pragma_Unevaluated_Use_Of_Old
=>
23741 Check_Arg_Count
(1);
23742 Check_No_Identifiers
;
23743 Check_Arg_Is_One_Of
(Arg1
, Name_Error
, Name_Warn
, Name_Allow
);
23745 -- Suppress/Unsuppress can appear as a configuration pragma, or in
23746 -- a declarative part or a package spec.
23748 if not Is_Configuration_Pragma
then
23749 Check_Is_In_Decl_Part_Or_Package_Spec
;
23752 -- Store proper setting of Uneval_Old
23754 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
23755 Uneval_Old
:= Fold_Upper
(Name_Buffer
(1));
23757 ------------------------
23758 -- Unimplemented_Unit --
23759 ------------------------
23761 -- pragma Unimplemented_Unit;
23763 -- Note: this only gives an error if we are generating code, or if
23764 -- we are in a generic library unit (where the pragma appears in the
23765 -- body, not in the spec).
23767 when Pragma_Unimplemented_Unit
=> Unimplemented_Unit
: declare
23768 Cunitent
: constant Entity_Id
:=
23769 Cunit_Entity
(Get_Source_Unit
(Loc
));
23770 Ent_Kind
: constant Entity_Kind
:= Ekind
(Cunitent
);
23774 Check_Arg_Count
(0);
23776 if Operating_Mode
= Generate_Code
23777 or else Ent_Kind
= E_Generic_Function
23778 or else Ent_Kind
= E_Generic_Procedure
23779 or else Ent_Kind
= E_Generic_Package
23781 Get_Name_String
(Chars
(Cunitent
));
23782 Set_Casing
(Mixed_Case
);
23783 Write_Str
(Name_Buffer
(1 .. Name_Len
));
23784 Write_Str
(" is not supported in this configuration");
23786 raise Unrecoverable_Error
;
23788 end Unimplemented_Unit
;
23790 ------------------------
23791 -- Universal_Aliasing --
23792 ------------------------
23794 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
23796 when Pragma_Universal_Aliasing
=> Universal_Alias
: declare
23802 Check_Arg_Count
(1);
23803 Check_Optional_Identifier
(Arg2
, Name_Entity
);
23804 Check_Arg_Is_Local_Name
(Arg1
);
23805 E_Id
:= Get_Pragma_Arg
(Arg1
);
23807 if Etype
(E_Id
) = Any_Type
then
23811 E
:= Entity
(E_Id
);
23813 if not Is_Type
(E
) then
23814 Error_Pragma_Arg
("pragma% requires type", Arg1
);
23817 -- A pragma that applies to a Ghost entity becomes Ghost for the
23818 -- purposes of legality checks and removal of ignored Ghost code.
23820 Mark_Ghost_Pragma
(N
, E
);
23821 Set_Universal_Aliasing
(Base_Type
(E
));
23822 Record_Rep_Item
(E
, N
);
23823 end Universal_Alias
;
23825 --------------------
23826 -- Universal_Data --
23827 --------------------
23829 -- pragma Universal_Data [(library_unit_NAME)];
23831 when Pragma_Universal_Data
=>
23833 Error_Pragma
("??pragma% ignored (applies only to AAMP)");
23839 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
23841 when Pragma_Unmodified
=>
23842 Analyze_Unmodified_Or_Unused
;
23848 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
23850 -- or when used in a context clause:
23852 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
23854 when Pragma_Unreferenced
=>
23855 Analyze_Unreferenced_Or_Unused
;
23857 --------------------------
23858 -- Unreferenced_Objects --
23859 --------------------------
23861 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
23863 when Pragma_Unreferenced_Objects
=> Unreferenced_Objects
: declare
23865 Arg_Expr
: Node_Id
;
23866 Arg_Id
: Entity_Id
;
23868 Ghost_Error_Posted
: Boolean := False;
23869 -- Flag set when an error concerning the illegal mix of Ghost and
23870 -- non-Ghost types is emitted.
23872 Ghost_Id
: Entity_Id
:= Empty
;
23873 -- The entity of the first Ghost type encountered while processing
23874 -- the arguments of the pragma.
23878 Check_At_Least_N_Arguments
(1);
23881 while Present
(Arg
) loop
23882 Check_No_Identifier
(Arg
);
23883 Check_Arg_Is_Local_Name
(Arg
);
23884 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
23886 if Is_Entity_Name
(Arg_Expr
) then
23887 Arg_Id
:= Entity
(Arg_Expr
);
23889 if Is_Type
(Arg_Id
) then
23890 Set_Has_Pragma_Unreferenced_Objects
(Arg_Id
);
23892 -- A pragma that applies to a Ghost entity becomes Ghost
23893 -- for the purposes of legality checks and removal of
23894 -- ignored Ghost code.
23896 Mark_Ghost_Pragma
(N
, Arg_Id
);
23898 -- Capture the entity of the first Ghost type being
23899 -- processed for error detection purposes.
23901 if Is_Ghost_Entity
(Arg_Id
) then
23902 if No
(Ghost_Id
) then
23903 Ghost_Id
:= Arg_Id
;
23906 -- Otherwise the type is non-Ghost. It is illegal to mix
23907 -- references to Ghost and non-Ghost entities
23910 elsif Present
(Ghost_Id
)
23911 and then not Ghost_Error_Posted
23913 Ghost_Error_Posted
:= True;
23915 Error_Msg_Name_1
:= Pname
;
23917 ("pragma % cannot mention ghost and non-ghost types",
23920 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
23921 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
23923 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
23924 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
23928 ("argument for pragma% must be type or subtype", Arg
);
23932 ("argument for pragma% must be type or subtype", Arg
);
23937 end Unreferenced_Objects
;
23939 ------------------------------
23940 -- Unreserve_All_Interrupts --
23941 ------------------------------
23943 -- pragma Unreserve_All_Interrupts;
23945 when Pragma_Unreserve_All_Interrupts
=>
23947 Check_Arg_Count
(0);
23949 if In_Extended_Main_Code_Unit
(Main_Unit_Entity
) then
23950 Unreserve_All_Interrupts
:= True;
23957 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
23959 when Pragma_Unsuppress
=>
23961 Process_Suppress_Unsuppress
(Suppress_Case
=> False);
23967 -- pragma Unused (LOCAL_NAME {, LOCAL_NAME});
23969 when Pragma_Unused
=>
23970 Analyze_Unmodified_Or_Unused
(Is_Unused
=> True);
23971 Analyze_Unreferenced_Or_Unused
(Is_Unused
=> True);
23973 -------------------
23974 -- Use_VADS_Size --
23975 -------------------
23977 -- pragma Use_VADS_Size;
23979 when Pragma_Use_VADS_Size
=>
23981 Check_Arg_Count
(0);
23982 Check_Valid_Configuration_Pragma
;
23983 Use_VADS_Size
:= True;
23985 ---------------------
23986 -- Validity_Checks --
23987 ---------------------
23989 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
23991 when Pragma_Validity_Checks
=> Validity_Checks
: declare
23992 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
23998 Check_Arg_Count
(1);
23999 Check_No_Identifiers
;
24001 -- Pragma always active unless in CodePeer or GNATprove modes,
24002 -- which use a fixed configuration of validity checks.
24004 if not (CodePeer_Mode
or GNATprove_Mode
) then
24005 if Nkind
(A
) = N_String_Literal
then
24009 Slen
: constant Natural := Natural (String_Length
(S
));
24010 Options
: String (1 .. Slen
);
24014 -- Couldn't we use a for loop here over Options'Range???
24018 C
:= Get_String_Char
(S
, Pos
(J
));
24020 -- This is a weird test, it skips setting validity
24021 -- checks entirely if any element of S is out of
24022 -- range of Character, what is that about ???
24024 exit when not In_Character_Range
(C
);
24025 Options
(J
) := Get_Character
(C
);
24028 Set_Validity_Check_Options
(Options
);
24036 elsif Nkind
(A
) = N_Identifier
then
24037 if Chars
(A
) = Name_All_Checks
then
24038 Set_Validity_Check_Options
("a");
24039 elsif Chars
(A
) = Name_On
then
24040 Validity_Checks_On
:= True;
24041 elsif Chars
(A
) = Name_Off
then
24042 Validity_Checks_On
:= False;
24046 end Validity_Checks
;
24052 -- pragma Volatile (LOCAL_NAME);
24054 when Pragma_Volatile
=>
24055 Process_Atomic_Independent_Shared_Volatile
;
24057 -------------------------
24058 -- Volatile_Components --
24059 -------------------------
24061 -- pragma Volatile_Components (array_LOCAL_NAME);
24063 -- Volatile is handled by the same circuit as Atomic_Components
24065 --------------------------
24066 -- Volatile_Full_Access --
24067 --------------------------
24069 -- pragma Volatile_Full_Access (LOCAL_NAME);
24071 when Pragma_Volatile_Full_Access
=>
24073 Process_Atomic_Independent_Shared_Volatile
;
24075 -----------------------
24076 -- Volatile_Function --
24077 -----------------------
24079 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
24081 when Pragma_Volatile_Function
=> Volatile_Function
: declare
24082 Over_Id
: Entity_Id
;
24083 Spec_Id
: Entity_Id
;
24084 Subp_Decl
: Node_Id
;
24088 Check_No_Identifiers
;
24089 Check_At_Most_N_Arguments
(1);
24092 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
24094 -- Generic subprogram
24096 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
24099 -- Body acts as spec
24101 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
24102 and then No
(Corresponding_Spec
(Subp_Decl
))
24106 -- Body stub acts as spec
24108 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
24109 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
24115 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
24123 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
24125 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
24130 -- A pragma that applies to a Ghost entity becomes Ghost for the
24131 -- purposes of legality checks and removal of ignored Ghost code.
24133 Mark_Ghost_Pragma
(N
, Spec_Id
);
24135 -- Chain the pragma on the contract for completeness
24137 Add_Contract_Item
(N
, Spec_Id
);
24139 -- The legality checks of pragma Volatile_Function are affected by
24140 -- the SPARK mode in effect. Analyze all pragmas in a specific
24143 Analyze_If_Present
(Pragma_SPARK_Mode
);
24145 -- A volatile function cannot override a non-volatile function
24146 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
24147 -- in New_Overloaded_Entity, however at that point the pragma has
24148 -- not been processed yet.
24150 Over_Id
:= Overridden_Operation
(Spec_Id
);
24152 if Present
(Over_Id
)
24153 and then not Is_Volatile_Function
(Over_Id
)
24156 ("incompatible volatile function values in effect", Spec_Id
);
24158 Error_Msg_Sloc
:= Sloc
(Over_Id
);
24160 ("\& declared # with Volatile_Function value False",
24163 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
24165 ("\overridden # with Volatile_Function value True",
24169 -- Analyze the Boolean expression (if any)
24171 if Present
(Arg1
) then
24172 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
24174 end Volatile_Function
;
24176 ----------------------
24177 -- Warning_As_Error --
24178 ----------------------
24180 -- pragma Warning_As_Error (static_string_EXPRESSION);
24182 when Pragma_Warning_As_Error
=>
24184 Check_Arg_Count
(1);
24185 Check_No_Identifiers
;
24186 Check_Valid_Configuration_Pragma
;
24188 if not Is_Static_String_Expression
(Arg1
) then
24190 ("argument of pragma% must be static string expression",
24193 -- OK static string expression
24196 Acquire_Warning_Match_String
(Arg1
);
24197 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
24198 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
24199 new String'(Name_Buffer (1 .. Name_Len));
24206 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
24208 -- DETAILS ::= On | Off
24209 -- DETAILS ::= On | Off, local_NAME
24210 -- DETAILS ::= static_string_EXPRESSION
24211 -- DETAILS ::= On | Off, static_string_EXPRESSION
24213 -- TOOL_NAME ::= GNAT | GNATProve
24215 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
24217 -- Note: If the first argument matches an allowed tool name, it is
24218 -- always considered to be a tool name, even if there is a string
24219 -- variable of that name.
24221 -- Note if the second argument of DETAILS is a local_NAME then the
24222 -- second form is always understood. If the intention is to use
24223 -- the fourth form, then you can write NAME & "" to force the
24224 -- intepretation as a static_string_EXPRESSION.
24226 when Pragma_Warnings => Warnings : declare
24227 Reason : String_Id;
24231 Check_At_Least_N_Arguments (1);
24233 -- See if last argument is labeled Reason. If so, make sure we
24234 -- have a string literal or a concatenation of string literals,
24235 -- and acquire the REASON string. Then remove the REASON argument
24236 -- by decreasing Num_Args by one; Remaining processing looks only
24237 -- at first Num_Args arguments).
24240 Last_Arg : constant Node_Id :=
24241 Last (Pragma_Argument_Associations (N));
24244 if Nkind (Last_Arg) = N_Pragma_Argument_Association
24245 and then Chars (Last_Arg) = Name_Reason
24248 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
24249 Reason := End_String;
24250 Arg_Count := Arg_Count - 1;
24252 -- Not allowed in compiler units (bootstrap issues)
24254 Check_Compiler_Unit ("Reason for pragma Warnings", N);
24256 -- No REASON string, set null string as reason
24259 Reason := Null_String_Id;
24263 -- Now proceed with REASON taken care of and eliminated
24265 Check_No_Identifiers;
24267 -- If debug flag -gnatd.i is set, pragma is ignored
24269 if Debug_Flag_Dot_I then
24273 -- Process various forms of the pragma
24276 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
24277 Shifted_Args : List_Id;
24280 -- See if first argument is a tool name, currently either
24281 -- GNAT or GNATprove. If so, either ignore the pragma if the
24282 -- tool used does not match, or continue as if no tool name
24283 -- was given otherwise, by shifting the arguments.
24285 if Nkind (Argx) = N_Identifier
24286 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
24288 if Chars (Argx) = Name_Gnat then
24289 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
24290 Rewrite (N, Make_Null_Statement (Loc));
24295 elsif Chars (Argx) = Name_Gnatprove then
24296 if not GNATprove_Mode then
24297 Rewrite (N, Make_Null_Statement (Loc));
24303 raise Program_Error;
24306 -- At this point, the pragma Warnings applies to the tool,
24307 -- so continue with shifted arguments.
24309 Arg_Count := Arg_Count - 1;
24311 if Arg_Count = 1 then
24312 Shifted_Args := New_List (New_Copy (Arg2));
24313 elsif Arg_Count = 2 then
24314 Shifted_Args := New_List (New_Copy (Arg2),
24316 elsif Arg_Count = 3 then
24317 Shifted_Args := New_List (New_Copy (Arg2),
24321 raise Program_Error;
24326 Chars => Name_Warnings,
24327 Pragma_Argument_Associations => Shifted_Args));
24332 -- One argument case
24334 if Arg_Count = 1 then
24336 -- On/Off one argument case was processed by parser
24338 if Nkind (Argx) = N_Identifier
24339 and then Nam_In (Chars (Argx), Name_On, Name_Off)
24343 -- One argument case must be ON/OFF or static string expr
24345 elsif not Is_Static_String_Expression (Arg1) then
24347 ("argument of pragma% must be On/Off or static string "
24348 & "expression", Arg1);
24350 -- One argument string expression case
24354 Lit : constant Node_Id := Expr_Value_S (Argx);
24355 Str : constant String_Id := Strval (Lit);
24356 Len : constant Nat := String_Length (Str);
24364 while J <= Len loop
24365 C := Get_String_Char (Str, J);
24366 OK := In_Character_Range (C);
24369 Chr := Get_Character (C);
24371 -- Dash case: only -Wxxx is accepted
24378 C := Get_String_Char (Str, J);
24379 Chr := Get_Character (C);
24380 exit when Chr = 'W
';
24385 elsif J < Len and then Chr = '.' then
24387 C := Get_String_Char (Str, J);
24388 Chr := Get_Character (C);
24390 if not Set_Dot_Warning_Switch (Chr) then
24392 ("invalid warning switch character "
24393 & '.' & Chr, Arg1);
24399 OK := Set_Warning_Switch (Chr);
24404 ("invalid warning switch character " & Chr,
24410 ("invalid wide character in warning switch ",
24419 -- Two or more arguments (must be two)
24422 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
24423 Check_Arg_Count (2);
24431 E_Id := Get_Pragma_Arg (Arg2);
24434 -- In the expansion of an inlined body, a reference to
24435 -- the formal may be wrapped in a conversion if the
24436 -- actual is a conversion. Retrieve the real entity name.
24438 if (In_Instance_Body or In_Inlined_Body)
24439 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
24441 E_Id := Expression (E_Id);
24444 -- Entity name case
24446 if Is_Entity_Name (E_Id) then
24447 E := Entity (E_Id);
24454 (E, (Chars (Get_Pragma_Arg (Arg1)) =
24457 -- For OFF case, make entry in warnings off
24458 -- pragma table for later processing. But we do
24459 -- not do that within an instance, since these
24460 -- warnings are about what is needed in the
24461 -- template, not an instance of it.
24463 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
24464 and then Warn_On_Warnings_Off
24465 and then not In_Instance
24467 Warnings_Off_Pragmas.Append ((N, E, Reason));
24470 if Is_Enumeration_Type (E) then
24474 Lit := First_Literal (E);
24475 while Present (Lit) loop
24476 Set_Warnings_Off (Lit);
24477 Next_Literal (Lit);
24482 exit when No (Homonym (E));
24487 -- Error if not entity or static string expression case
24489 elsif not Is_Static_String_Expression (Arg2) then
24491 ("second argument of pragma% must be entity name "
24492 & "or static string expression", Arg2);
24494 -- Static string expression case
24497 Acquire_Warning_Match_String (Arg2);
24499 -- Note on configuration pragma case: If this is a
24500 -- configuration pragma, then for an OFF pragma, we
24501 -- just set Config True in the call, which is all
24502 -- that needs to be done. For the case of ON, this
24503 -- is normally an error, unless it is canceling the
24504 -- effect of a previous OFF pragma in the same file.
24505 -- In any other case, an error will be signalled (ON
24506 -- with no matching OFF).
24508 -- Note: We set Used if we are inside a generic to
24509 -- disable the test that the non-config case actually
24510 -- cancels a warning. That's because we can't be sure
24511 -- there isn't an instantiation in some other unit
24512 -- where a warning is suppressed.
24514 -- We could do a little better here by checking if the
24515 -- generic unit we are inside is public, but for now
24516 -- we don't bother with that refinement.
24518 if Chars (Argx) = Name_Off then
24519 Set_Specific_Warning_Off
24520 (Loc, Name_Buffer (1 .. Name_Len), Reason,
24521 Config => Is_Configuration_Pragma,
24522 Used => Inside_A_Generic or else In_Instance);
24524 elsif Chars (Argx) = Name_On then
24525 Set_Specific_Warning_On
24526 (Loc, Name_Buffer (1 .. Name_Len), Err);
24530 ("??pragma Warnings On with no matching "
24531 & "Warnings Off", Loc);
24540 -------------------
24541 -- Weak_External --
24542 -------------------
24544 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
24546 when Pragma_Weak_External => Weak_External : declare
24551 Check_Arg_Count (1);
24552 Check_Optional_Identifier (Arg1, Name_Entity);
24553 Check_Arg_Is_Library_Level_Local_Name (Arg1);
24554 Ent := Entity (Get_Pragma_Arg (Arg1));
24556 if Rep_Item_Too_Early (Ent, N) then
24559 Ent := Underlying_Type (Ent);
24562 -- The only processing required is to link this item on to the
24563 -- list of rep items for the given entity. This is accomplished
24564 -- by the call to Rep_Item_Too_Late (when no error is detected
24565 -- and False is returned).
24567 if Rep_Item_Too_Late (Ent, N) then
24570 Set_Has_Gigi_Rep_Item (Ent);
24574 -----------------------------
24575 -- Wide_Character_Encoding --
24576 -----------------------------
24578 -- pragma Wide_Character_Encoding (IDENTIFIER);
24580 when Pragma_Wide_Character_Encoding =>
24583 -- Nothing to do, handled in parser. Note that we do not enforce
24584 -- configuration pragma placement, this pragma can appear at any
24585 -- place in the source, allowing mixed encodings within a single
24590 --------------------
24591 -- Unknown_Pragma --
24592 --------------------
24594 -- Should be impossible, since the case of an unknown pragma is
24595 -- separately processed before the case statement is entered.
24597 when Unknown_Pragma =>
24598 raise Program_Error;
24601 -- AI05-0144: detect dangerous order dependence. Disabled for now,
24602 -- until AI is formally approved.
24604 -- Check_Order_Dependence;
24607 when Pragma_Exit => null;
24608 end Analyze_Pragma;
24610 ---------------------------------------------
24611 -- Analyze_Pre_Post_Condition_In_Decl_Part --
24612 ---------------------------------------------
24614 -- WARNING: This routine manages Ghost regions. Return statements must be
24615 -- replaced by gotos which jump to the end of the routine and restore the
24618 procedure Analyze_Pre_Post_Condition_In_Decl_Part
24620 Freeze_Id : Entity_Id := Empty)
24622 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
24623 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
24625 Disp_Typ : Entity_Id;
24626 -- The dispatching type of the subprogram subject to the pre- or
24629 function Check_References (Nod : Node_Id) return Traverse_Result;
24630 -- Check that expression Nod does not mention non-primitives of the
24631 -- type, global objects of the type, or other illegalities described
24632 -- and implied by AI12-0113.
24634 ----------------------
24635 -- Check_References --
24636 ----------------------
24638 function Check_References (Nod : Node_Id) return Traverse_Result is
24640 if Nkind (Nod) = N_Function_Call
24641 and then Is_Entity_Name (Name (Nod))
24644 Func : constant Entity_Id := Entity (Name (Nod));
24648 -- An operation of the type must be a primitive
24650 if No (Find_Dispatching_Type (Func)) then
24651 Form := First_Formal (Func);
24652 while Present (Form) loop
24653 if Etype (Form) = Disp_Typ then
24655 ("operation in class-wide condition must be "
24656 & "primitive of &", Nod, Disp_Typ);
24659 Next_Formal (Form);
24662 -- A return object of the type is illegal as well
24664 if Etype (Func) = Disp_Typ
24665 or else Etype (Func) = Class_Wide_Type (Disp_Typ)
24668 ("operation in class-wide condition must be primitive "
24669 & "of &", Nod, Disp_Typ);
24672 -- Otherwise we have a call to an overridden primitive, and we
24673 -- will create a common class-wide clone for the body of
24674 -- original operation and its eventual inherited versions. If
24675 -- the original operation dispatches on result it is never
24676 -- inherited and there is no need for a clone. There is not
24677 -- need for a clone either in GNATprove mode, as cases that
24678 -- would require it are rejected (when an inherited primitive
24679 -- calls an overridden operation in a class-wide contract), and
24680 -- the clone would make proof impossible in some cases.
24682 elsif not Is_Abstract_Subprogram (Spec_Id)
24683 and then No (Class_Wide_Clone (Spec_Id))
24684 and then not Has_Controlling_Result (Spec_Id)
24685 and then not GNATprove_Mode
24687 Build_Class_Wide_Clone_Decl (Spec_Id);
24691 elsif Is_Entity_Name (Nod)
24693 (Etype (Nod) = Disp_Typ
24694 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24695 and then Ekind_In (Entity (Nod), E_Constant, E_Variable)
24698 ("object in class-wide condition must be formal of type &",
24701 elsif Nkind (Nod) = N_Explicit_Dereference
24702 and then (Etype (Nod) = Disp_Typ
24703 or else Etype (Nod) = Class_Wide_Type (Disp_Typ))
24704 and then (not Is_Entity_Name (Prefix (Nod))
24705 or else not Is_Formal (Entity (Prefix (Nod))))
24708 ("operation in class-wide condition must be primitive of &",
24713 end Check_References;
24715 procedure Check_Class_Wide_Condition is
24716 new Traverse_Proc (Check_References);
24720 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
24721 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
24722 -- Save the Ghost mode to restore on exit
24725 Restore_Scope : Boolean := False;
24727 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
24730 -- Do not analyze the pragma multiple times
24732 if Is_Analyzed_Pragma (N) then
24736 -- Set the Ghost mode in effect from the pragma. Due to the delayed
24737 -- analysis of the pragma, the Ghost mode at point of declaration and
24738 -- point of analysis may not necessarily be the same. Use the mode in
24739 -- effect at the point of declaration.
24741 Set_Ghost_Mode (N);
24743 -- Ensure that the subprogram and its formals are visible when analyzing
24744 -- the expression of the pragma.
24746 if not In_Open_Scopes (Spec_Id) then
24747 Restore_Scope := True;
24748 Push_Scope (Spec_Id);
24750 if Is_Generic_Subprogram (Spec_Id) then
24751 Install_Generic_Formals (Spec_Id);
24753 Install_Formals (Spec_Id);
24757 Errors := Serious_Errors_Detected;
24758 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
24760 -- Emit a clarification message when the expression contains at least
24761 -- one undefined reference, possibly due to contract freezing.
24763 if Errors /= Serious_Errors_Detected
24764 and then Present (Freeze_Id)
24765 and then Has_Undefined_Reference (Expr)
24767 Contract_Freeze_Error (Spec_Id, Freeze_Id);
24770 if Class_Present (N) then
24772 -- Verify that a class-wide condition is legal, i.e. the operation is
24773 -- a primitive of a tagged type. Note that a generic subprogram is
24774 -- not a primitive operation.
24776 Disp_Typ := Find_Dispatching_Type (Spec_Id);
24778 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
24779 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
24781 if From_Aspect_Specification (N) then
24783 ("aspect % can only be specified for a primitive operation "
24784 & "of a tagged type", Corresponding_Aspect (N));
24786 -- The pragma is a source construct
24790 ("pragma % can only be specified for a primitive operation "
24791 & "of a tagged type", N);
24794 -- Remaining semantic checks require a full tree traversal
24797 Check_Class_Wide_Condition (Expr);
24802 if Restore_Scope then
24806 -- If analysis of the condition indicates that a class-wide clone
24807 -- has been created, build and analyze its declaration.
24809 if Is_Subprogram (Spec_Id)
24810 and then Present (Class_Wide_Clone (Spec_Id))
24812 Analyze (Unit_Declaration_Node (Class_Wide_Clone (Spec_Id)));
24815 -- Currently it is not possible to inline pre/postconditions on a
24816 -- subprogram subject to pragma Inline_Always.
24818 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
24819 Set_Is_Analyzed_Pragma (N);
24821 Restore_Ghost_Mode (Saved_GM);
24822 end Analyze_Pre_Post_Condition_In_Decl_Part;
24824 ------------------------------------------
24825 -- Analyze_Refined_Depends_In_Decl_Part --
24826 ------------------------------------------
24828 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
24829 procedure Check_Dependency_Clause
24830 (Spec_Id : Entity_Id;
24831 Dep_Clause : Node_Id;
24832 Dep_States : Elist_Id;
24833 Refinements : List_Id;
24834 Matched_Items : in out Elist_Id);
24835 -- Try to match a single dependency clause Dep_Clause against one or
24836 -- more refinement clauses found in list Refinements. Each successful
24837 -- match eliminates at least one refinement clause from Refinements.
24838 -- Spec_Id denotes the entity of the related subprogram. Dep_States
24839 -- denotes the entities of all abstract states which appear in pragma
24840 -- Depends. Matched_Items contains the entities of all successfully
24841 -- matched items found in pragma Depends.
24843 procedure Check_Output_States
24844 (Spec_Id : Entity_Id;
24845 Spec_Inputs : Elist_Id;
24846 Spec_Outputs : Elist_Id;
24847 Body_Inputs : Elist_Id;
24848 Body_Outputs : Elist_Id);
24849 -- Determine whether pragma Depends contains an output state with a
24850 -- visible refinement and if so, ensure that pragma Refined_Depends
24851 -- mentions all its constituents as outputs. Spec_Id is the entity of
24852 -- the related subprograms. Spec_Inputs and Spec_Outputs denote the
24853 -- inputs and outputs of the subprogram spec synthesized from pragma
24854 -- Depends. Body_Inputs and Body_Outputs denote the inputs and outputs
24855 -- of the subprogram body synthesized from pragma Refined_Depends.
24857 function Collect_States (Clauses : List_Id) return Elist_Id;
24858 -- Given a normalized list of dependencies obtained from calling
24859 -- Normalize_Clauses, return a list containing the entities of all
24860 -- states appearing in dependencies. It helps in checking refinements
24861 -- involving a state and a corresponding constituent which is not a
24862 -- direct constituent of the state.
24864 procedure Normalize_Clauses (Clauses : List_Id);
24865 -- Given a list of dependence or refinement clauses Clauses, normalize
24866 -- each clause by creating multiple dependencies with exactly one input
24869 procedure Remove_Extra_Clauses
24870 (Clauses : List_Id;
24871 Matched_Items : Elist_Id);
24872 -- Given a list of refinement clauses Clauses, remove all clauses whose
24873 -- inputs and/or outputs have been previously matched. See the body for
24874 -- all special cases. Matched_Items contains the entities of all matched
24875 -- items found in pragma Depends.
24877 procedure Report_Extra_Clauses
24878 (Spec_Id : Entity_Id;
24879 Clauses : List_Id);
24880 -- Emit an error for each extra clause found in list Clauses. Spec_Id
24881 -- denotes the entity of the related subprogram.
24883 -----------------------------
24884 -- Check_Dependency_Clause --
24885 -----------------------------
24887 procedure Check_Dependency_Clause
24888 (Spec_Id : Entity_Id;
24889 Dep_Clause : Node_Id;
24890 Dep_States : Elist_Id;
24891 Refinements : List_Id;
24892 Matched_Items : in out Elist_Id)
24894 Dep_Input : constant Node_Id := Expression (Dep_Clause);
24895 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
24897 function Is_Already_Matched (Dep_Item : Node_Id) return Boolean;
24898 -- Determine whether dependency item Dep_Item has been matched in a
24899 -- previous clause.
24901 function Is_In_Out_State_Clause return Boolean;
24902 -- Determine whether dependence clause Dep_Clause denotes an abstract
24903 -- state that depends on itself (State => State).
24905 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
24906 -- Determine whether item Item denotes an abstract state with visible
24907 -- null refinement.
24909 procedure Match_Items
24910 (Dep_Item : Node_Id;
24911 Ref_Item : Node_Id;
24912 Matched : out Boolean);
24913 -- Try to match dependence item Dep_Item against refinement item
24914 -- Ref_Item. To match against a possible null refinement (see 2, 9),
24915 -- set Ref_Item to Empty. Flag Matched is set to True when one of
24916 -- the following conformance scenarios is in effect:
24917 -- 1) Both items denote null
24918 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
24919 -- 3) Both items denote attribute 'Result
24920 -- 4) Both items denote the same object
24921 -- 5) Both items denote the same formal parameter
24922 -- 6) Both items denote the same current instance of a type
24923 -- 7) Both items denote the same discriminant
24924 -- 8) Dep_Item is an abstract state with visible null refinement
24925 -- and Ref_Item denotes null.
24926 -- 9) Dep_Item is an abstract state with visible null refinement
24927 -- and Ref_Item is Empty (special case).
24928 -- 10) Dep_Item is an abstract state with full or partial visible
24929 -- non-null refinement and Ref_Item denotes one of its
24931 -- 11) Dep_Item is an abstract state without a full visible
24932 -- refinement and Ref_Item denotes the same state.
24933 -- When scenario 10 is in effect, the entity of the abstract state
24934 -- denoted by Dep_Item is added to list Refined_States.
24936 procedure Record_Item
(Item_Id
: Entity_Id
);
24937 -- Store the entity of an item denoted by Item_Id in Matched_Items
24939 ------------------------
24940 -- Is_Already_Matched --
24941 ------------------------
24943 function Is_Already_Matched
(Dep_Item
: Node_Id
) return Boolean is
24944 Item_Id
: Entity_Id
:= Empty
;
24947 -- When the dependency item denotes attribute 'Result, check for
24948 -- the entity of the related subprogram.
24950 if Is_Attribute_Result
(Dep_Item
) then
24951 Item_Id
:= Spec_Id
;
24953 elsif Is_Entity_Name
(Dep_Item
) then
24954 Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
24958 Present
(Item_Id
) and then Contains
(Matched_Items
, Item_Id
);
24959 end Is_Already_Matched
;
24961 ----------------------------
24962 -- Is_In_Out_State_Clause --
24963 ----------------------------
24965 function Is_In_Out_State_Clause
return Boolean is
24966 Dep_Input_Id
: Entity_Id
;
24967 Dep_Output_Id
: Entity_Id
;
24970 -- Detect the following clause:
24973 if Is_Entity_Name
(Dep_Input
)
24974 and then Is_Entity_Name
(Dep_Output
)
24976 -- Handle abstract views generated for limited with clauses
24978 Dep_Input_Id
:= Available_View
(Entity_Of
(Dep_Input
));
24979 Dep_Output_Id
:= Available_View
(Entity_Of
(Dep_Output
));
24982 Ekind
(Dep_Input_Id
) = E_Abstract_State
24983 and then Dep_Input_Id
= Dep_Output_Id
;
24987 end Is_In_Out_State_Clause
;
24989 ---------------------------
24990 -- Is_Null_Refined_State --
24991 ---------------------------
24993 function Is_Null_Refined_State
(Item
: Node_Id
) return Boolean is
24994 Item_Id
: Entity_Id
;
24997 if Is_Entity_Name
(Item
) then
24999 -- Handle abstract views generated for limited with clauses
25001 Item_Id
:= Available_View
(Entity_Of
(Item
));
25004 Ekind
(Item_Id
) = E_Abstract_State
25005 and then Has_Null_Visible_Refinement
(Item_Id
);
25009 end Is_Null_Refined_State
;
25015 procedure Match_Items
25016 (Dep_Item
: Node_Id
;
25017 Ref_Item
: Node_Id
;
25018 Matched
: out Boolean)
25020 Dep_Item_Id
: Entity_Id
;
25021 Ref_Item_Id
: Entity_Id
;
25024 -- Assume that the two items do not match
25028 -- A null matches null or Empty (special case)
25030 if Nkind
(Dep_Item
) = N_Null
25031 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
25035 -- Attribute 'Result matches attribute 'Result
25037 elsif Is_Attribute_Result
(Dep_Item
)
25038 and then Is_Attribute_Result
(Ref_Item
)
25040 -- Put the entity of the related function on the list of
25041 -- matched items because attribute 'Result does not carry
25042 -- an entity similar to states and constituents.
25044 Record_Item
(Spec_Id
);
25047 -- Abstract states, current instances of concurrent types,
25048 -- discriminants, formal parameters and objects.
25050 elsif Is_Entity_Name
(Dep_Item
) then
25052 -- Handle abstract views generated for limited with clauses
25054 Dep_Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
25056 if Ekind
(Dep_Item_Id
) = E_Abstract_State
then
25058 -- An abstract state with visible null refinement matches
25059 -- null or Empty (special case).
25061 if Has_Null_Visible_Refinement
(Dep_Item_Id
)
25062 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
25064 Record_Item
(Dep_Item_Id
);
25067 -- An abstract state with visible non-null refinement
25068 -- matches one of its constituents, or itself for an
25069 -- abstract state with partial visible refinement.
25071 elsif Has_Non_Null_Visible_Refinement
(Dep_Item_Id
) then
25072 if Is_Entity_Name
(Ref_Item
) then
25073 Ref_Item_Id
:= Entity_Of
(Ref_Item
);
25075 if Ekind_In
(Ref_Item_Id
, E_Abstract_State
,
25078 and then Present
(Encapsulating_State
(Ref_Item_Id
))
25079 and then Find_Encapsulating_State
25080 (Dep_States
, Ref_Item_Id
) = Dep_Item_Id
25082 Record_Item
(Dep_Item_Id
);
25085 elsif not Has_Visible_Refinement
(Dep_Item_Id
)
25086 and then Ref_Item_Id
= Dep_Item_Id
25088 Record_Item
(Dep_Item_Id
);
25093 -- An abstract state without a visible refinement matches
25096 elsif Is_Entity_Name
(Ref_Item
)
25097 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
25099 Record_Item
(Dep_Item_Id
);
25103 -- A current instance of a concurrent type, discriminant,
25104 -- formal parameter or an object matches itself.
25106 elsif Is_Entity_Name
(Ref_Item
)
25107 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
25109 Record_Item
(Dep_Item_Id
);
25119 procedure Record_Item
(Item_Id
: Entity_Id
) is
25121 if No
(Matched_Items
) then
25122 Matched_Items
:= New_Elmt_List
;
25125 Append_Unique_Elmt
(Item_Id
, Matched_Items
);
25130 Clause_Matched
: Boolean := False;
25131 Dummy
: Boolean := False;
25132 Inputs_Match
: Boolean;
25133 Next_Ref_Clause
: Node_Id
;
25134 Outputs_Match
: Boolean;
25135 Ref_Clause
: Node_Id
;
25136 Ref_Input
: Node_Id
;
25137 Ref_Output
: Node_Id
;
25139 -- Start of processing for Check_Dependency_Clause
25142 -- Do not perform this check in an instance because it was already
25143 -- performed successfully in the generic template.
25145 if Is_Generic_Instance
(Spec_Id
) then
25149 -- Examine all refinement clauses and compare them against the
25150 -- dependence clause.
25152 Ref_Clause
:= First
(Refinements
);
25153 while Present
(Ref_Clause
) loop
25154 Next_Ref_Clause
:= Next
(Ref_Clause
);
25156 -- Obtain the attributes of the current refinement clause
25158 Ref_Input
:= Expression
(Ref_Clause
);
25159 Ref_Output
:= First
(Choices
(Ref_Clause
));
25161 -- The current refinement clause matches the dependence clause
25162 -- when both outputs match and both inputs match. See routine
25163 -- Match_Items for all possible conformance scenarios.
25165 -- Depends Dep_Output => Dep_Input
25169 -- Refined_Depends Ref_Output => Ref_Input
25172 (Dep_Item
=> Dep_Input
,
25173 Ref_Item
=> Ref_Input
,
25174 Matched
=> Inputs_Match
);
25177 (Dep_Item
=> Dep_Output
,
25178 Ref_Item
=> Ref_Output
,
25179 Matched
=> Outputs_Match
);
25181 -- An In_Out state clause may be matched against a refinement with
25182 -- a null input or null output as long as the non-null side of the
25183 -- relation contains a valid constituent of the In_Out_State.
25185 if Is_In_Out_State_Clause
then
25187 -- Depends => (State => State)
25188 -- Refined_Depends => (null => Constit) -- OK
25191 and then not Outputs_Match
25192 and then Nkind
(Ref_Output
) = N_Null
25194 Outputs_Match
:= True;
25197 -- Depends => (State => State)
25198 -- Refined_Depends => (Constit => null) -- OK
25200 if not Inputs_Match
25201 and then Outputs_Match
25202 and then Nkind
(Ref_Input
) = N_Null
25204 Inputs_Match
:= True;
25208 -- The current refinement clause is legally constructed following
25209 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
25210 -- the pool of candidates. The seach continues because a single
25211 -- dependence clause may have multiple matching refinements.
25213 if Inputs_Match
and Outputs_Match
then
25214 Clause_Matched
:= True;
25215 Remove
(Ref_Clause
);
25218 Ref_Clause
:= Next_Ref_Clause
;
25221 -- Depending on the order or composition of refinement clauses, an
25222 -- In_Out state clause may not be directly refinable.
25224 -- Refined_State => (State => (Constit_1, Constit_2))
25225 -- Depends => ((Output, State) => (Input, State))
25226 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
25228 -- Matching normalized clause (State => State) fails because there is
25229 -- no direct refinement capable of satisfying this relation. Another
25230 -- similar case arises when clauses (Constit_1 => Input) and (Output
25231 -- => Constit_2) are matched first, leaving no candidates for clause
25232 -- (State => State). Both scenarios are legal as long as one of the
25233 -- previous clauses mentioned a valid constituent of State.
25235 if not Clause_Matched
25236 and then Is_In_Out_State_Clause
25237 and then Is_Already_Matched
(Dep_Input
)
25239 Clause_Matched
:= True;
25242 -- A clause where the input is an abstract state with visible null
25243 -- refinement or a 'Result attribute is implicitly matched when the
25244 -- output has already been matched in a previous clause.
25246 -- Refined_State => (State => null)
25247 -- Depends => (Output => State) -- implicitly OK
25248 -- Refined_Depends => (Output => ...)
25249 -- Depends => (...'Result => State) -- implicitly OK
25250 -- Refined_Depends => (...'Result => ...)
25252 if not Clause_Matched
25253 and then Is_Null_Refined_State
(Dep_Input
)
25254 and then Is_Already_Matched
(Dep_Output
)
25256 Clause_Matched
:= True;
25259 -- A clause where the output is an abstract state with visible null
25260 -- refinement is implicitly matched when the input has already been
25261 -- matched in a previous clause.
25263 -- Refined_State => (State => null)
25264 -- Depends => (State => Input) -- implicitly OK
25265 -- Refined_Depends => (... => Input)
25267 if not Clause_Matched
25268 and then Is_Null_Refined_State
(Dep_Output
)
25269 and then Is_Already_Matched
(Dep_Input
)
25271 Clause_Matched
:= True;
25274 -- At this point either all refinement clauses have been examined or
25275 -- pragma Refined_Depends contains a solitary null. Only an abstract
25276 -- state with null refinement can possibly match these cases.
25278 -- Refined_State => (State => null)
25279 -- Depends => (State => null)
25280 -- Refined_Depends => null -- OK
25282 if not Clause_Matched
then
25284 (Dep_Item
=> Dep_Input
,
25286 Matched
=> Inputs_Match
);
25289 (Dep_Item
=> Dep_Output
,
25291 Matched
=> Outputs_Match
);
25293 Clause_Matched
:= Inputs_Match
and Outputs_Match
;
25296 -- If the contents of Refined_Depends are legal, then the current
25297 -- dependence clause should be satisfied either by an explicit match
25298 -- or by one of the special cases.
25300 if not Clause_Matched
then
25302 (Fix_Msg
(Spec_Id
, "dependence clause of subprogram & has no "
25303 & "matching refinement in body"), Dep_Clause
, Spec_Id
);
25305 end Check_Dependency_Clause
;
25307 -------------------------
25308 -- Check_Output_States --
25309 -------------------------
25311 procedure Check_Output_States
25312 (Spec_Id
: Entity_Id
;
25313 Spec_Inputs
: Elist_Id
;
25314 Spec_Outputs
: Elist_Id
;
25315 Body_Inputs
: Elist_Id
;
25316 Body_Outputs
: Elist_Id
)
25318 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
25319 -- Determine whether all constituents of state State_Id with full
25320 -- visible refinement are used as outputs in pragma Refined_Depends.
25321 -- Emit an error if this is not the case (SPARK RM 7.2.4(5)).
25323 -----------------------------
25324 -- Check_Constituent_Usage --
25325 -----------------------------
25327 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
25328 Constits
: constant Elist_Id
:=
25329 Partial_Refinement_Constituents
(State_Id
);
25330 Constit_Elmt
: Elmt_Id
;
25331 Constit_Id
: Entity_Id
;
25332 Only_Partial
: constant Boolean :=
25333 not Has_Visible_Refinement
(State_Id
);
25334 Posted
: Boolean := False;
25337 if Present
(Constits
) then
25338 Constit_Elmt
:= First_Elmt
(Constits
);
25339 while Present
(Constit_Elmt
) loop
25340 Constit_Id
:= Node
(Constit_Elmt
);
25342 -- Issue an error when a constituent of State_Id is used,
25343 -- and State_Id has only partial visible refinement
25344 -- (SPARK RM 7.2.4(3d)).
25346 if Only_Partial
then
25347 if (Present
(Body_Inputs
)
25348 and then Appears_In
(Body_Inputs
, Constit_Id
))
25350 (Present
(Body_Outputs
)
25351 and then Appears_In
(Body_Outputs
, Constit_Id
))
25353 Error_Msg_Name_1
:= Chars
(State_Id
);
25355 ("constituent & of state % cannot be used in "
25356 & "dependence refinement", N
, Constit_Id
);
25357 Error_Msg_Name_1
:= Chars
(State_Id
);
25358 SPARK_Msg_N
("\use state % instead", N
);
25361 -- The constituent acts as an input (SPARK RM 7.2.5(3))
25363 elsif Present
(Body_Inputs
)
25364 and then Appears_In
(Body_Inputs
, Constit_Id
)
25366 Error_Msg_Name_1
:= Chars
(State_Id
);
25368 ("constituent & of state % must act as output in "
25369 & "dependence refinement", N
, Constit_Id
);
25371 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
25373 elsif No
(Body_Outputs
)
25374 or else not Appears_In
(Body_Outputs
, Constit_Id
)
25379 ("output state & must be replaced by all its "
25380 & "constituents in dependence refinement",
25385 ("\constituent & is missing in output list",
25389 Next_Elmt
(Constit_Elmt
);
25392 end Check_Constituent_Usage
;
25397 Item_Elmt
: Elmt_Id
;
25398 Item_Id
: Entity_Id
;
25400 -- Start of processing for Check_Output_States
25403 -- Do not perform this check in an instance because it was already
25404 -- performed successfully in the generic template.
25406 if Is_Generic_Instance
(Spec_Id
) then
25409 -- Inspect the outputs of pragma Depends looking for a state with a
25410 -- visible refinement.
25412 elsif Present
(Spec_Outputs
) then
25413 Item_Elmt
:= First_Elmt
(Spec_Outputs
);
25414 while Present
(Item_Elmt
) loop
25415 Item
:= Node
(Item_Elmt
);
25417 -- Deal with the mixed nature of the input and output lists
25419 if Nkind
(Item
) = N_Defining_Identifier
then
25422 Item_Id
:= Available_View
(Entity_Of
(Item
));
25425 if Ekind
(Item_Id
) = E_Abstract_State
then
25427 -- The state acts as an input-output, skip it
25429 if Present
(Spec_Inputs
)
25430 and then Appears_In
(Spec_Inputs
, Item_Id
)
25434 -- Ensure that all of the constituents are utilized as
25435 -- outputs in pragma Refined_Depends.
25437 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
25438 Check_Constituent_Usage
(Item_Id
);
25442 Next_Elmt
(Item_Elmt
);
25445 end Check_Output_States
;
25447 --------------------
25448 -- Collect_States --
25449 --------------------
25451 function Collect_States
(Clauses
: List_Id
) return Elist_Id
is
25452 procedure Collect_State
25454 States
: in out Elist_Id
);
25455 -- Add the entity of Item to list States when it denotes to a state
25457 -------------------
25458 -- Collect_State --
25459 -------------------
25461 procedure Collect_State
25463 States
: in out Elist_Id
)
25468 if Is_Entity_Name
(Item
) then
25469 Id
:= Entity_Of
(Item
);
25471 if Ekind
(Id
) = E_Abstract_State
then
25472 if No
(States
) then
25473 States
:= New_Elmt_List
;
25476 Append_Unique_Elmt
(Id
, States
);
25486 States
: Elist_Id
:= No_Elist
;
25488 -- Start of processing for Collect_States
25491 Clause
:= First
(Clauses
);
25492 while Present
(Clause
) loop
25493 Input
:= Expression
(Clause
);
25494 Output
:= First
(Choices
(Clause
));
25496 Collect_State
(Input
, States
);
25497 Collect_State
(Output
, States
);
25503 end Collect_States
;
25505 -----------------------
25506 -- Normalize_Clauses --
25507 -----------------------
25509 procedure Normalize_Clauses
(Clauses
: List_Id
) is
25510 procedure Normalize_Inputs
(Clause
: Node_Id
);
25511 -- Normalize clause Clause by creating multiple clauses for each
25512 -- input item of Clause. It is assumed that Clause has exactly one
25513 -- output. The transformation is as follows:
25515 -- Output => (Input_1, Input_2) -- original
25517 -- Output => Input_1 -- normalizations
25518 -- Output => Input_2
25520 procedure Normalize_Outputs
(Clause
: Node_Id
);
25521 -- Normalize clause Clause by creating multiple clause for each
25522 -- output item of Clause. The transformation is as follows:
25524 -- (Output_1, Output_2) => Input -- original
25526 -- Output_1 => Input -- normalization
25527 -- Output_2 => Input
25529 ----------------------
25530 -- Normalize_Inputs --
25531 ----------------------
25533 procedure Normalize_Inputs
(Clause
: Node_Id
) is
25534 Inputs
: constant Node_Id
:= Expression
(Clause
);
25535 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
25536 Output
: constant List_Id
:= Choices
(Clause
);
25537 Last_Input
: Node_Id
;
25539 New_Clause
: Node_Id
;
25540 Next_Input
: Node_Id
;
25543 -- Normalization is performed only when the original clause has
25544 -- more than one input. Multiple inputs appear as an aggregate.
25546 if Nkind
(Inputs
) = N_Aggregate
then
25547 Last_Input
:= Last
(Expressions
(Inputs
));
25549 -- Create a new clause for each input
25551 Input
:= First
(Expressions
(Inputs
));
25552 while Present
(Input
) loop
25553 Next_Input
:= Next
(Input
);
25555 -- Unhook the current input from the original input list
25556 -- because it will be relocated to a new clause.
25560 -- Special processing for the last input. At this point the
25561 -- original aggregate has been stripped down to one element.
25562 -- Replace the aggregate by the element itself.
25564 if Input
= Last_Input
then
25565 Rewrite
(Inputs
, Input
);
25567 -- Generate a clause of the form:
25572 Make_Component_Association
(Loc
,
25573 Choices
=> New_Copy_List_Tree
(Output
),
25574 Expression
=> Input
);
25576 -- The new clause contains replicated content that has
25577 -- already been analyzed, mark the clause as analyzed.
25579 Set_Analyzed
(New_Clause
);
25580 Insert_After
(Clause
, New_Clause
);
25583 Input
:= Next_Input
;
25586 end Normalize_Inputs
;
25588 -----------------------
25589 -- Normalize_Outputs --
25590 -----------------------
25592 procedure Normalize_Outputs
(Clause
: Node_Id
) is
25593 Inputs
: constant Node_Id
:= Expression
(Clause
);
25594 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
25595 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
25596 Last_Output
: Node_Id
;
25597 New_Clause
: Node_Id
;
25598 Next_Output
: Node_Id
;
25602 -- Multiple outputs appear as an aggregate. Nothing to do when
25603 -- the clause has exactly one output.
25605 if Nkind
(Outputs
) = N_Aggregate
then
25606 Last_Output
:= Last
(Expressions
(Outputs
));
25608 -- Create a clause for each output. Note that each time a new
25609 -- clause is created, the original output list slowly shrinks
25610 -- until there is one item left.
25612 Output
:= First
(Expressions
(Outputs
));
25613 while Present
(Output
) loop
25614 Next_Output
:= Next
(Output
);
25616 -- Unhook the output from the original output list as it
25617 -- will be relocated to a new clause.
25621 -- Special processing for the last output. At this point
25622 -- the original aggregate has been stripped down to one
25623 -- element. Replace the aggregate by the element itself.
25625 if Output
= Last_Output
then
25626 Rewrite
(Outputs
, Output
);
25629 -- Generate a clause of the form:
25630 -- (Output => Inputs)
25633 Make_Component_Association
(Loc
,
25634 Choices
=> New_List
(Output
),
25635 Expression
=> New_Copy_Tree
(Inputs
));
25637 -- The new clause contains replicated content that has
25638 -- already been analyzed. There is not need to reanalyze
25641 Set_Analyzed
(New_Clause
);
25642 Insert_After
(Clause
, New_Clause
);
25645 Output
:= Next_Output
;
25648 end Normalize_Outputs
;
25654 -- Start of processing for Normalize_Clauses
25657 Clause
:= First
(Clauses
);
25658 while Present
(Clause
) loop
25659 Normalize_Outputs
(Clause
);
25663 Clause
:= First
(Clauses
);
25664 while Present
(Clause
) loop
25665 Normalize_Inputs
(Clause
);
25668 end Normalize_Clauses
;
25670 --------------------------
25671 -- Remove_Extra_Clauses --
25672 --------------------------
25674 procedure Remove_Extra_Clauses
25675 (Clauses
: List_Id
;
25676 Matched_Items
: Elist_Id
)
25680 Input_Id
: Entity_Id
;
25681 Next_Clause
: Node_Id
;
25683 State_Id
: Entity_Id
;
25686 Clause
:= First
(Clauses
);
25687 while Present
(Clause
) loop
25688 Next_Clause
:= Next
(Clause
);
25690 Input
:= Expression
(Clause
);
25691 Output
:= First
(Choices
(Clause
));
25693 -- Recognize a clause of the form
25697 -- where Input is a constituent of a state which was already
25698 -- successfully matched. This clause must be removed because it
25699 -- simply indicates that some of the constituents of the state
25702 -- Refined_State => (State => (Constit_1, Constit_2))
25703 -- Depends => (Output => State)
25704 -- Refined_Depends => ((Output => Constit_1), -- State matched
25705 -- (null => Constit_2)) -- OK
25707 if Nkind
(Output
) = N_Null
and then Is_Entity_Name
(Input
) then
25709 -- Handle abstract views generated for limited with clauses
25711 Input_Id
:= Available_View
(Entity_Of
(Input
));
25713 -- The input must be a constituent of a state
25715 if Ekind_In
(Input_Id
, E_Abstract_State
,
25718 and then Present
(Encapsulating_State
(Input_Id
))
25720 State_Id
:= Encapsulating_State
(Input_Id
);
25722 -- The state must have a non-null visible refinement and be
25723 -- matched in a previous clause.
25725 if Has_Non_Null_Visible_Refinement
(State_Id
)
25726 and then Contains
(Matched_Items
, State_Id
)
25732 -- Recognize a clause of the form
25736 -- where Output is an arbitrary item. This clause must be removed
25737 -- because a null input legitimately matches anything.
25739 elsif Nkind
(Input
) = N_Null
then
25743 Clause
:= Next_Clause
;
25745 end Remove_Extra_Clauses
;
25747 --------------------------
25748 -- Report_Extra_Clauses --
25749 --------------------------
25751 procedure Report_Extra_Clauses
25752 (Spec_Id
: Entity_Id
;
25758 -- Do not perform this check in an instance because it was already
25759 -- performed successfully in the generic template.
25761 if Is_Generic_Instance
(Spec_Id
) then
25764 elsif Present
(Clauses
) then
25765 Clause
:= First
(Clauses
);
25766 while Present
(Clause
) loop
25768 ("unmatched or extra clause in dependence refinement",
25774 end Report_Extra_Clauses
;
25778 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
25779 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
25780 Errors
: constant Nat
:= Serious_Errors_Detected
;
25787 Body_Inputs
: Elist_Id
:= No_Elist
;
25788 Body_Outputs
: Elist_Id
:= No_Elist
;
25789 -- The inputs and outputs of the subprogram body synthesized from pragma
25790 -- Refined_Depends.
25792 Dependencies
: List_Id
:= No_List
;
25794 -- The corresponding Depends pragma along with its clauses
25796 Matched_Items
: Elist_Id
:= No_Elist
;
25797 -- A list containing the entities of all successfully matched items
25798 -- found in pragma Depends.
25800 Refinements
: List_Id
:= No_List
;
25801 -- The clauses of pragma Refined_Depends
25803 Spec_Id
: Entity_Id
;
25804 -- The entity of the subprogram subject to pragma Refined_Depends
25806 Spec_Inputs
: Elist_Id
:= No_Elist
;
25807 Spec_Outputs
: Elist_Id
:= No_Elist
;
25808 -- The inputs and outputs of the subprogram spec synthesized from pragma
25811 States
: Elist_Id
:= No_Elist
;
25812 -- A list containing the entities of all states whose constituents
25813 -- appear in pragma Depends.
25815 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
25818 -- Do not analyze the pragma multiple times
25820 if Is_Analyzed_Pragma
(N
) then
25824 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
25826 -- Use the anonymous object as the proper spec when Refined_Depends
25827 -- applies to the body of a single task type. The object carries the
25828 -- proper Chars as well as all non-refined versions of pragmas.
25830 if Is_Single_Concurrent_Type
(Spec_Id
) then
25831 Spec_Id
:= Anonymous_Object
(Spec_Id
);
25834 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
25836 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
25837 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
25839 if No
(Depends
) then
25841 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
25842 & "& lacks aspect or pragma Depends"), N
, Spec_Id
);
25846 Deps
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
25848 -- A null dependency relation renders the refinement useless because it
25849 -- cannot possibly mention abstract states with visible refinement. Note
25850 -- that the inverse is not true as states may be refined to null
25851 -- (SPARK RM 7.2.5(2)).
25853 if Nkind
(Deps
) = N_Null
then
25855 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
25856 & "depend on abstract state with visible refinement"), N
, Spec_Id
);
25860 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
25861 -- This ensures that the categorization of all refined dependency items
25862 -- is consistent with their role.
25864 Analyze_Depends_In_Decl_Part
(N
);
25866 -- Do not match dependencies against refinements if Refined_Depends is
25867 -- illegal to avoid emitting misleading error.
25869 if Serious_Errors_Detected
= Errors
then
25871 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
25872 -- the inputs and outputs of the subprogram spec and body to verify
25873 -- the use of states with visible refinement and their constituents.
25875 if No
(Get_Pragma
(Spec_Id
, Pragma_Global
))
25876 or else No
(Get_Pragma
(Body_Id
, Pragma_Refined_Global
))
25878 Collect_Subprogram_Inputs_Outputs
25879 (Subp_Id
=> Spec_Id
,
25880 Synthesize
=> True,
25881 Subp_Inputs
=> Spec_Inputs
,
25882 Subp_Outputs
=> Spec_Outputs
,
25883 Global_Seen
=> Dummy
);
25885 Collect_Subprogram_Inputs_Outputs
25886 (Subp_Id
=> Body_Id
,
25887 Synthesize
=> True,
25888 Subp_Inputs
=> Body_Inputs
,
25889 Subp_Outputs
=> Body_Outputs
,
25890 Global_Seen
=> Dummy
);
25892 -- For an output state with a visible refinement, ensure that all
25893 -- constituents appear as outputs in the dependency refinement.
25895 Check_Output_States
25896 (Spec_Id
=> Spec_Id
,
25897 Spec_Inputs
=> Spec_Inputs
,
25898 Spec_Outputs
=> Spec_Outputs
,
25899 Body_Inputs
=> Body_Inputs
,
25900 Body_Outputs
=> Body_Outputs
);
25903 -- Matching is disabled in ASIS because clauses are not normalized as
25904 -- this is a tree altering activity similar to expansion.
25910 -- Multiple dependency clauses appear as component associations of an
25911 -- aggregate. Note that the clauses are copied because the algorithm
25912 -- modifies them and this should not be visible in Depends.
25914 pragma Assert
(Nkind
(Deps
) = N_Aggregate
);
25915 Dependencies
:= New_Copy_List_Tree
(Component_Associations
(Deps
));
25916 Normalize_Clauses
(Dependencies
);
25918 -- Gather all states which appear in Depends
25920 States
:= Collect_States
(Dependencies
);
25922 Refs
:= Expression
(Get_Argument
(N
, Spec_Id
));
25924 if Nkind
(Refs
) = N_Null
then
25925 Refinements
:= No_List
;
25927 -- Multiple dependency clauses appear as component associations of an
25928 -- aggregate. Note that the clauses are copied because the algorithm
25929 -- modifies them and this should not be visible in Refined_Depends.
25931 else pragma Assert
(Nkind
(Refs
) = N_Aggregate
);
25932 Refinements
:= New_Copy_List_Tree
(Component_Associations
(Refs
));
25933 Normalize_Clauses
(Refinements
);
25936 -- At this point the clauses of pragmas Depends and Refined_Depends
25937 -- have been normalized into simple dependencies between one output
25938 -- and one input. Examine all clauses of pragma Depends looking for
25939 -- matching clauses in pragma Refined_Depends.
25941 Clause
:= First
(Dependencies
);
25942 while Present
(Clause
) loop
25943 Check_Dependency_Clause
25944 (Spec_Id
=> Spec_Id
,
25945 Dep_Clause
=> Clause
,
25946 Dep_States
=> States
,
25947 Refinements
=> Refinements
,
25948 Matched_Items
=> Matched_Items
);
25953 -- Pragma Refined_Depends may contain multiple clarification clauses
25954 -- which indicate that certain constituents do not influence the data
25955 -- flow in any way. Such clauses must be removed as long as the state
25956 -- has been matched, otherwise they will be incorrectly flagged as
25959 -- Refined_State => (State => (Constit_1, Constit_2))
25960 -- Depends => (Output => State)
25961 -- Refined_Depends => ((Output => Constit_1), -- State matched
25962 -- (null => Constit_2)) -- must be removed
25964 Remove_Extra_Clauses
(Refinements
, Matched_Items
);
25966 if Serious_Errors_Detected
= Errors
then
25967 Report_Extra_Clauses
(Spec_Id
, Refinements
);
25972 Set_Is_Analyzed_Pragma
(N
);
25973 end Analyze_Refined_Depends_In_Decl_Part
;
25975 -----------------------------------------
25976 -- Analyze_Refined_Global_In_Decl_Part --
25977 -----------------------------------------
25979 procedure Analyze_Refined_Global_In_Decl_Part
(N
: Node_Id
) is
25981 -- The corresponding Global pragma
25983 Has_In_State
: Boolean := False;
25984 Has_In_Out_State
: Boolean := False;
25985 Has_Out_State
: Boolean := False;
25986 Has_Proof_In_State
: Boolean := False;
25987 -- These flags are set when the corresponding Global pragma has a state
25988 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
25991 Has_Null_State
: Boolean := False;
25992 -- This flag is set when the corresponding Global pragma has at least
25993 -- one state with a null refinement.
25995 In_Constits
: Elist_Id
:= No_Elist
;
25996 In_Out_Constits
: Elist_Id
:= No_Elist
;
25997 Out_Constits
: Elist_Id
:= No_Elist
;
25998 Proof_In_Constits
: Elist_Id
:= No_Elist
;
25999 -- These lists contain the entities of all Input, In_Out, Output and
26000 -- Proof_In constituents that appear in Refined_Global and participate
26001 -- in state refinement.
26003 In_Items
: Elist_Id
:= No_Elist
;
26004 In_Out_Items
: Elist_Id
:= No_Elist
;
26005 Out_Items
: Elist_Id
:= No_Elist
;
26006 Proof_In_Items
: Elist_Id
:= No_Elist
;
26007 -- These lists contain the entities of all Input, In_Out, Output and
26008 -- Proof_In items defined in the corresponding Global pragma.
26010 Repeat_Items
: Elist_Id
:= No_Elist
;
26011 -- A list of all global items without full visible refinement found
26012 -- in pragma Global. These states should be repeated in the global
26013 -- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible
26014 -- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)).
26016 Spec_Id
: Entity_Id
;
26017 -- The entity of the subprogram subject to pragma Refined_Global
26019 States
: Elist_Id
:= No_Elist
;
26020 -- A list of all states with full or partial visible refinement found in
26023 procedure Check_In_Out_States
;
26024 -- Determine whether the corresponding Global pragma mentions In_Out
26025 -- states with visible refinement and if so, ensure that one of the
26026 -- following completions apply to the constituents of the state:
26027 -- 1) there is at least one constituent of mode In_Out
26028 -- 2) there is at least one Input and one Output constituent
26029 -- 3) not all constituents are present and one of them is of mode
26031 -- This routine may remove elements from In_Constits, In_Out_Constits,
26032 -- Out_Constits and Proof_In_Constits.
26034 procedure Check_Input_States
;
26035 -- Determine whether the corresponding Global pragma mentions Input
26036 -- states with visible refinement and if so, ensure that at least one of
26037 -- its constituents appears as an Input item in Refined_Global.
26038 -- This routine may remove elements from In_Constits, In_Out_Constits,
26039 -- Out_Constits and Proof_In_Constits.
26041 procedure Check_Output_States
;
26042 -- Determine whether the corresponding Global pragma mentions Output
26043 -- states with visible refinement and if so, ensure that all of its
26044 -- constituents appear as Output items in Refined_Global.
26045 -- This routine may remove elements from In_Constits, In_Out_Constits,
26046 -- Out_Constits and Proof_In_Constits.
26048 procedure Check_Proof_In_States
;
26049 -- Determine whether the corresponding Global pragma mentions Proof_In
26050 -- states with visible refinement and if so, ensure that at least one of
26051 -- its constituents appears as a Proof_In item in Refined_Global.
26052 -- This routine may remove elements from In_Constits, In_Out_Constits,
26053 -- Out_Constits and Proof_In_Constits.
26055 procedure Check_Refined_Global_List
26057 Global_Mode
: Name_Id
:= Name_Input
);
26058 -- Verify the legality of a single global list declaration. Global_Mode
26059 -- denotes the current mode in effect.
26061 procedure Collect_Global_Items
26063 Mode
: Name_Id
:= Name_Input
);
26064 -- Gather all Input, In_Out, Output and Proof_In items from node List
26065 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
26066 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
26067 -- and Has_Proof_In_State are set when there is at least one abstract
26068 -- state with full or partial visible refinement available in the
26069 -- corresponding mode. Flag Has_Null_State is set when at least state
26070 -- has a null refinement. Mode denotes the current global mode in
26073 function Present_Then_Remove
26075 Item
: Entity_Id
) return Boolean;
26076 -- Search List for a particular entity Item. If Item has been found,
26077 -- remove it from List. This routine is used to strip lists In_Constits,
26078 -- In_Out_Constits and Out_Constits of valid constituents.
26080 procedure Present_Then_Remove
(List
: Elist_Id
; Item
: Entity_Id
);
26081 -- Same as function Present_Then_Remove, but do not report the presence
26082 -- of Item in List.
26084 procedure Report_Extra_Constituents
;
26085 -- Emit an error for each constituent found in lists In_Constits,
26086 -- In_Out_Constits and Out_Constits.
26088 procedure Report_Missing_Items
;
26089 -- Emit an error for each global item not repeated found in list
26092 -------------------------
26093 -- Check_In_Out_States --
26094 -------------------------
26096 procedure Check_In_Out_States
is
26097 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26098 -- Determine whether one of the following coverage scenarios is in
26100 -- 1) there is at least one constituent of mode In_Out or Output
26101 -- 2) there is at least one pair of constituents with modes Input
26102 -- and Output, or Proof_In and Output.
26103 -- 3) there is at least one constituent of mode Output and not all
26104 -- constituents are present.
26105 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
26107 -----------------------------
26108 -- Check_Constituent_Usage --
26109 -----------------------------
26111 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26112 Constits
: constant Elist_Id
:=
26113 Partial_Refinement_Constituents
(State_Id
);
26114 Constit_Elmt
: Elmt_Id
;
26115 Constit_Id
: Entity_Id
;
26116 Has_Missing
: Boolean := False;
26117 In_Out_Seen
: Boolean := False;
26118 Input_Seen
: Boolean := False;
26119 Output_Seen
: Boolean := False;
26120 Proof_In_Seen
: Boolean := False;
26123 -- Process all the constituents of the state and note their modes
26124 -- within the global refinement.
26126 if Present
(Constits
) then
26127 Constit_Elmt
:= First_Elmt
(Constits
);
26128 while Present
(Constit_Elmt
) loop
26129 Constit_Id
:= Node
(Constit_Elmt
);
26131 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
26132 Input_Seen
:= True;
26134 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
) then
26135 In_Out_Seen
:= True;
26137 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
26138 Output_Seen
:= True;
26140 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26142 Proof_In_Seen
:= True;
26145 Has_Missing
:= True;
26148 Next_Elmt
(Constit_Elmt
);
26152 -- An In_Out constituent is a valid completion
26154 if In_Out_Seen
then
26157 -- A pair of one Input/Proof_In and one Output constituent is a
26158 -- valid completion.
26160 elsif (Input_Seen
or Proof_In_Seen
) and Output_Seen
then
26163 elsif Output_Seen
then
26165 -- A single Output constituent is a valid completion only when
26166 -- some of the other constituents are missing.
26168 if Has_Missing
then
26171 -- Otherwise all constituents are of mode Output
26175 ("global refinement of state & must include at least one "
26176 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
26180 -- The state lacks a completion. When full refinement is visible,
26181 -- always emit an error (SPARK RM 7.2.4(3a)). When only partial
26182 -- refinement is visible, emit an error if the abstract state
26183 -- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where
26184 -- both are utilized, Check_State_And_Constituent_Use. will issue
26187 elsif not Input_Seen
26188 and then not In_Out_Seen
26189 and then not Output_Seen
26190 and then not Proof_In_Seen
26192 if Has_Visible_Refinement
(State_Id
)
26193 or else Contains
(Repeat_Items
, State_Id
)
26196 ("missing global refinement of state &", N
, State_Id
);
26199 -- Otherwise the state has a malformed completion where at least
26200 -- one of the constituents has a different mode.
26204 ("global refinement of state & redefines the mode of its "
26205 & "constituents", N
, State_Id
);
26207 end Check_Constituent_Usage
;
26211 Item_Elmt
: Elmt_Id
;
26212 Item_Id
: Entity_Id
;
26214 -- Start of processing for Check_In_Out_States
26217 -- Do not perform this check in an instance because it was already
26218 -- performed successfully in the generic template.
26220 if Is_Generic_Instance
(Spec_Id
) then
26223 -- Inspect the In_Out items of the corresponding Global pragma
26224 -- looking for a state with a visible refinement.
26226 elsif Has_In_Out_State
and then Present
(In_Out_Items
) then
26227 Item_Elmt
:= First_Elmt
(In_Out_Items
);
26228 while Present
(Item_Elmt
) loop
26229 Item_Id
:= Node
(Item_Elmt
);
26231 -- Ensure that one of the three coverage variants is satisfied
26233 if Ekind
(Item_Id
) = E_Abstract_State
26234 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26236 Check_Constituent_Usage
(Item_Id
);
26239 Next_Elmt
(Item_Elmt
);
26242 end Check_In_Out_States
;
26244 ------------------------
26245 -- Check_Input_States --
26246 ------------------------
26248 procedure Check_Input_States
is
26249 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26250 -- Determine whether at least one constituent of state State_Id with
26251 -- full or partial visible refinement is used and has mode Input.
26252 -- Ensure that the remaining constituents do not have In_Out or
26253 -- Output modes. Emit an error if this is not the case
26254 -- (SPARK RM 7.2.4(5)).
26256 -----------------------------
26257 -- Check_Constituent_Usage --
26258 -----------------------------
26260 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26261 Constits
: constant Elist_Id
:=
26262 Partial_Refinement_Constituents
(State_Id
);
26263 Constit_Elmt
: Elmt_Id
;
26264 Constit_Id
: Entity_Id
;
26265 In_Seen
: Boolean := False;
26268 if Present
(Constits
) then
26269 Constit_Elmt
:= First_Elmt
(Constits
);
26270 while Present
(Constit_Elmt
) loop
26271 Constit_Id
:= Node
(Constit_Elmt
);
26273 -- At least one of the constituents appears as an Input
26275 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
26278 -- A Proof_In constituent can refine an Input state as long
26279 -- as there is at least one Input constituent present.
26281 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26285 -- The constituent appears in the global refinement, but has
26286 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
26288 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26289 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
26291 Error_Msg_Name_1
:= Chars
(State_Id
);
26293 ("constituent & of state % must have mode `Input` in "
26294 & "global refinement", N
, Constit_Id
);
26297 Next_Elmt
(Constit_Elmt
);
26301 -- Not one of the constituents appeared as Input. Always emit an
26302 -- error when the full refinement is visible (SPARK RM 7.2.4(3a)).
26303 -- When only partial refinement is visible, emit an error if the
26304 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26305 -- the case where both are utilized, an error will be issued in
26306 -- Check_State_And_Constituent_Use.
26309 and then (Has_Visible_Refinement
(State_Id
)
26310 or else Contains
(Repeat_Items
, State_Id
))
26313 ("global refinement of state & must include at least one "
26314 & "constituent of mode `Input`", N
, State_Id
);
26316 end Check_Constituent_Usage
;
26320 Item_Elmt
: Elmt_Id
;
26321 Item_Id
: Entity_Id
;
26323 -- Start of processing for Check_Input_States
26326 -- Do not perform this check in an instance because it was already
26327 -- performed successfully in the generic template.
26329 if Is_Generic_Instance
(Spec_Id
) then
26332 -- Inspect the Input items of the corresponding Global pragma looking
26333 -- for a state with a visible refinement.
26335 elsif Has_In_State
and then Present
(In_Items
) then
26336 Item_Elmt
:= First_Elmt
(In_Items
);
26337 while Present
(Item_Elmt
) loop
26338 Item_Id
:= Node
(Item_Elmt
);
26340 -- When full refinement is visible, ensure that at least one of
26341 -- the constituents is utilized and is of mode Input. When only
26342 -- partial refinement is visible, ensure that either one of
26343 -- the constituents is utilized and is of mode Input, or the
26344 -- abstract state is repeated and no constituent is utilized.
26346 if Ekind
(Item_Id
) = E_Abstract_State
26347 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26349 Check_Constituent_Usage
(Item_Id
);
26352 Next_Elmt
(Item_Elmt
);
26355 end Check_Input_States
;
26357 -------------------------
26358 -- Check_Output_States --
26359 -------------------------
26361 procedure Check_Output_States
is
26362 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26363 -- Determine whether all constituents of state State_Id with full
26364 -- visible refinement are used and have mode Output. Emit an error
26365 -- if this is not the case (SPARK RM 7.2.4(5)).
26367 -----------------------------
26368 -- Check_Constituent_Usage --
26369 -----------------------------
26371 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26372 Constits
: constant Elist_Id
:=
26373 Partial_Refinement_Constituents
(State_Id
);
26374 Only_Partial
: constant Boolean :=
26375 not Has_Visible_Refinement
(State_Id
);
26376 Constit_Elmt
: Elmt_Id
;
26377 Constit_Id
: Entity_Id
;
26378 Posted
: Boolean := False;
26381 if Present
(Constits
) then
26382 Constit_Elmt
:= First_Elmt
(Constits
);
26383 while Present
(Constit_Elmt
) loop
26384 Constit_Id
:= Node
(Constit_Elmt
);
26386 -- Issue an error when a constituent of State_Id is utilized
26387 -- and State_Id has only partial visible refinement
26388 -- (SPARK RM 7.2.4(3d)).
26390 if Only_Partial
then
26391 if Present_Then_Remove
(Out_Constits
, Constit_Id
)
26392 or else Present_Then_Remove
(In_Constits
, Constit_Id
)
26394 Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26396 Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26398 Error_Msg_Name_1
:= Chars
(State_Id
);
26400 ("constituent & of state % cannot be used in global "
26401 & "refinement", N
, Constit_Id
);
26402 Error_Msg_Name_1
:= Chars
(State_Id
);
26403 SPARK_Msg_N
("\use state % instead", N
);
26406 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
26409 -- The constituent appears in the global refinement, but has
26410 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
26412 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
26413 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26414 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
26416 Error_Msg_Name_1
:= Chars
(State_Id
);
26418 ("constituent & of state % must have mode `Output` in "
26419 & "global refinement", N
, Constit_Id
);
26421 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
26427 ("`Output` state & must be replaced by all its "
26428 & "constituents in global refinement", N
, State_Id
);
26432 ("\constituent & is missing in output list",
26436 Next_Elmt
(Constit_Elmt
);
26439 end Check_Constituent_Usage
;
26443 Item_Elmt
: Elmt_Id
;
26444 Item_Id
: Entity_Id
;
26446 -- Start of processing for Check_Output_States
26449 -- Do not perform this check in an instance because it was already
26450 -- performed successfully in the generic template.
26452 if Is_Generic_Instance
(Spec_Id
) then
26455 -- Inspect the Output items of the corresponding Global pragma
26456 -- looking for a state with a visible refinement.
26458 elsif Has_Out_State
and then Present
(Out_Items
) then
26459 Item_Elmt
:= First_Elmt
(Out_Items
);
26460 while Present
(Item_Elmt
) loop
26461 Item_Id
:= Node
(Item_Elmt
);
26463 -- When full refinement is visible, ensure that all of the
26464 -- constituents are utilized and they have mode Output. When
26465 -- only partial refinement is visible, ensure that no
26466 -- constituent is utilized.
26468 if Ekind
(Item_Id
) = E_Abstract_State
26469 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26471 Check_Constituent_Usage
(Item_Id
);
26474 Next_Elmt
(Item_Elmt
);
26477 end Check_Output_States
;
26479 ---------------------------
26480 -- Check_Proof_In_States --
26481 ---------------------------
26483 procedure Check_Proof_In_States
is
26484 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
26485 -- Determine whether at least one constituent of state State_Id with
26486 -- full or partial visible refinement is used and has mode Proof_In.
26487 -- Ensure that the remaining constituents do not have Input, In_Out,
26488 -- or Output modes. Emit an error if this is not the case
26489 -- (SPARK RM 7.2.4(5)).
26491 -----------------------------
26492 -- Check_Constituent_Usage --
26493 -----------------------------
26495 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
26496 Constits
: constant Elist_Id
:=
26497 Partial_Refinement_Constituents
(State_Id
);
26498 Constit_Elmt
: Elmt_Id
;
26499 Constit_Id
: Entity_Id
;
26500 Proof_In_Seen
: Boolean := False;
26503 if Present
(Constits
) then
26504 Constit_Elmt
:= First_Elmt
(Constits
);
26505 while Present
(Constit_Elmt
) loop
26506 Constit_Id
:= Node
(Constit_Elmt
);
26508 -- At least one of the constituents appears as Proof_In
26510 if Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
26511 Proof_In_Seen
:= True;
26513 -- The constituent appears in the global refinement, but has
26514 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
26516 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
26517 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
26518 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
26520 Error_Msg_Name_1
:= Chars
(State_Id
);
26522 ("constituent & of state % must have mode `Proof_In` "
26523 & "in global refinement", N
, Constit_Id
);
26526 Next_Elmt
(Constit_Elmt
);
26530 -- Not one of the constituents appeared as Proof_In. Always emit
26531 -- an error when full refinement is visible (SPARK RM 7.2.4(3a)).
26532 -- When only partial refinement is visible, emit an error if the
26533 -- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In
26534 -- the case where both are utilized, an error will be issued by
26535 -- Check_State_And_Constituent_Use.
26537 if not Proof_In_Seen
26538 and then (Has_Visible_Refinement
(State_Id
)
26539 or else Contains
(Repeat_Items
, State_Id
))
26542 ("global refinement of state & must include at least one "
26543 & "constituent of mode `Proof_In`", N
, State_Id
);
26545 end Check_Constituent_Usage
;
26549 Item_Elmt
: Elmt_Id
;
26550 Item_Id
: Entity_Id
;
26552 -- Start of processing for Check_Proof_In_States
26555 -- Do not perform this check in an instance because it was already
26556 -- performed successfully in the generic template.
26558 if Is_Generic_Instance
(Spec_Id
) then
26561 -- Inspect the Proof_In items of the corresponding Global pragma
26562 -- looking for a state with a visible refinement.
26564 elsif Has_Proof_In_State
and then Present
(Proof_In_Items
) then
26565 Item_Elmt
:= First_Elmt
(Proof_In_Items
);
26566 while Present
(Item_Elmt
) loop
26567 Item_Id
:= Node
(Item_Elmt
);
26569 -- Ensure that at least one of the constituents is utilized
26570 -- and is of mode Proof_In. When only partial refinement is
26571 -- visible, ensure that either one of the constituents is
26572 -- utilized and is of mode Proof_In, or the abstract state
26573 -- is repeated and no constituent is utilized.
26575 if Ekind
(Item_Id
) = E_Abstract_State
26576 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
26578 Check_Constituent_Usage
(Item_Id
);
26581 Next_Elmt
(Item_Elmt
);
26584 end Check_Proof_In_States
;
26586 -------------------------------
26587 -- Check_Refined_Global_List --
26588 -------------------------------
26590 procedure Check_Refined_Global_List
26592 Global_Mode
: Name_Id
:= Name_Input
)
26594 procedure Check_Refined_Global_Item
26596 Global_Mode
: Name_Id
);
26597 -- Verify the legality of a single global item declaration. Parameter
26598 -- Global_Mode denotes the current mode in effect.
26600 -------------------------------
26601 -- Check_Refined_Global_Item --
26602 -------------------------------
26604 procedure Check_Refined_Global_Item
26606 Global_Mode
: Name_Id
)
26608 Item_Id
: constant Entity_Id
:= Entity_Of
(Item
);
26610 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
);
26611 -- Issue a common error message for all mode mismatches. Expect
26612 -- denotes the expected mode.
26614 -----------------------------
26615 -- Inconsistent_Mode_Error --
26616 -----------------------------
26618 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
) is
26621 ("global item & has inconsistent modes", Item
, Item_Id
);
26623 Error_Msg_Name_1
:= Global_Mode
;
26624 Error_Msg_Name_2
:= Expect
;
26625 SPARK_Msg_N
("\expected mode %, found mode %", Item
);
26626 end Inconsistent_Mode_Error
;
26630 Enc_State
: Entity_Id
:= Empty
;
26631 -- Encapsulating state for constituent, Empty otherwise
26633 -- Start of processing for Check_Refined_Global_Item
26636 if Ekind_In
(Item_Id
, E_Abstract_State
,
26640 Enc_State
:= Find_Encapsulating_State
(States
, Item_Id
);
26643 -- When the state or object acts as a constituent of another
26644 -- state with a visible refinement, collect it for the state
26645 -- completeness checks performed later on. Note that the item
26646 -- acts as a constituent only when the encapsulating state is
26647 -- present in pragma Global.
26649 if Present
(Enc_State
)
26650 and then (Has_Visible_Refinement
(Enc_State
)
26651 or else Has_Partial_Visible_Refinement
(Enc_State
))
26652 and then Contains
(States
, Enc_State
)
26654 -- If the state has only partial visible refinement, remove it
26655 -- from the list of items that should be repeated from pragma
26658 if not Has_Visible_Refinement
(Enc_State
) then
26659 Present_Then_Remove
(Repeat_Items
, Enc_State
);
26662 if Global_Mode
= Name_Input
then
26663 Append_New_Elmt
(Item_Id
, In_Constits
);
26665 elsif Global_Mode
= Name_In_Out
then
26666 Append_New_Elmt
(Item_Id
, In_Out_Constits
);
26668 elsif Global_Mode
= Name_Output
then
26669 Append_New_Elmt
(Item_Id
, Out_Constits
);
26671 elsif Global_Mode
= Name_Proof_In
then
26672 Append_New_Elmt
(Item_Id
, Proof_In_Constits
);
26675 -- When not a constituent, ensure that both occurrences of the
26676 -- item in pragmas Global and Refined_Global match. Also remove
26677 -- it when present from the list of items that should be repeated
26678 -- from pragma Global.
26681 Present_Then_Remove
(Repeat_Items
, Item_Id
);
26683 if Contains
(In_Items
, Item_Id
) then
26684 if Global_Mode
/= Name_Input
then
26685 Inconsistent_Mode_Error
(Name_Input
);
26688 elsif Contains
(In_Out_Items
, Item_Id
) then
26689 if Global_Mode
/= Name_In_Out
then
26690 Inconsistent_Mode_Error
(Name_In_Out
);
26693 elsif Contains
(Out_Items
, Item_Id
) then
26694 if Global_Mode
/= Name_Output
then
26695 Inconsistent_Mode_Error
(Name_Output
);
26698 elsif Contains
(Proof_In_Items
, Item_Id
) then
26701 -- The item does not appear in the corresponding Global pragma,
26702 -- it must be an extra (SPARK RM 7.2.4(3)).
26705 SPARK_Msg_NE
("extra global item &", Item
, Item_Id
);
26708 end Check_Refined_Global_Item
;
26714 -- Start of processing for Check_Refined_Global_List
26717 -- Do not perform this check in an instance because it was already
26718 -- performed successfully in the generic template.
26720 if Is_Generic_Instance
(Spec_Id
) then
26723 elsif Nkind
(List
) = N_Null
then
26726 -- Single global item declaration
26728 elsif Nkind_In
(List
, N_Expanded_Name
,
26730 N_Selected_Component
)
26732 Check_Refined_Global_Item
(List
, Global_Mode
);
26734 -- Simple global list or moded global list declaration
26736 elsif Nkind
(List
) = N_Aggregate
then
26738 -- The declaration of a simple global list appear as a collection
26741 if Present
(Expressions
(List
)) then
26742 Item
:= First
(Expressions
(List
));
26743 while Present
(Item
) loop
26744 Check_Refined_Global_Item
(Item
, Global_Mode
);
26748 -- The declaration of a moded global list appears as a collection
26749 -- of component associations where individual choices denote
26752 elsif Present
(Component_Associations
(List
)) then
26753 Item
:= First
(Component_Associations
(List
));
26754 while Present
(Item
) loop
26755 Check_Refined_Global_List
26756 (List
=> Expression
(Item
),
26757 Global_Mode
=> Chars
(First
(Choices
(Item
))));
26765 raise Program_Error
;
26771 raise Program_Error
;
26773 end Check_Refined_Global_List
;
26775 --------------------------
26776 -- Collect_Global_Items --
26777 --------------------------
26779 procedure Collect_Global_Items
26781 Mode
: Name_Id
:= Name_Input
)
26783 procedure Collect_Global_Item
26785 Item_Mode
: Name_Id
);
26786 -- Add a single item to the appropriate list. Item_Mode denotes the
26787 -- current mode in effect.
26789 -------------------------
26790 -- Collect_Global_Item --
26791 -------------------------
26793 procedure Collect_Global_Item
26795 Item_Mode
: Name_Id
)
26797 Item_Id
: constant Entity_Id
:= Available_View
(Entity_Of
(Item
));
26798 -- The above handles abstract views of variables and states built
26799 -- for limited with clauses.
26802 -- Signal that the global list contains at least one abstract
26803 -- state with a visible refinement. Note that the refinement may
26804 -- be null in which case there are no constituents.
26806 if Ekind
(Item_Id
) = E_Abstract_State
then
26807 if Has_Null_Visible_Refinement
(Item_Id
) then
26808 Has_Null_State
:= True;
26810 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
26811 Append_New_Elmt
(Item_Id
, States
);
26813 if Item_Mode
= Name_Input
then
26814 Has_In_State
:= True;
26815 elsif Item_Mode
= Name_In_Out
then
26816 Has_In_Out_State
:= True;
26817 elsif Item_Mode
= Name_Output
then
26818 Has_Out_State
:= True;
26819 elsif Item_Mode
= Name_Proof_In
then
26820 Has_Proof_In_State
:= True;
26825 -- Record global items without full visible refinement found in
26826 -- pragma Global which should be repeated in the global refinement
26827 -- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)).
26829 if Ekind
(Item_Id
) /= E_Abstract_State
26830 or else not Has_Visible_Refinement
(Item_Id
)
26832 Append_New_Elmt
(Item_Id
, Repeat_Items
);
26835 -- Add the item to the proper list
26837 if Item_Mode
= Name_Input
then
26838 Append_New_Elmt
(Item_Id
, In_Items
);
26839 elsif Item_Mode
= Name_In_Out
then
26840 Append_New_Elmt
(Item_Id
, In_Out_Items
);
26841 elsif Item_Mode
= Name_Output
then
26842 Append_New_Elmt
(Item_Id
, Out_Items
);
26843 elsif Item_Mode
= Name_Proof_In
then
26844 Append_New_Elmt
(Item_Id
, Proof_In_Items
);
26846 end Collect_Global_Item
;
26852 -- Start of processing for Collect_Global_Items
26855 if Nkind
(List
) = N_Null
then
26858 -- Single global item declaration
26860 elsif Nkind_In
(List
, N_Expanded_Name
,
26862 N_Selected_Component
)
26864 Collect_Global_Item
(List
, Mode
);
26866 -- Single global list or moded global list declaration
26868 elsif Nkind
(List
) = N_Aggregate
then
26870 -- The declaration of a simple global list appear as a collection
26873 if Present
(Expressions
(List
)) then
26874 Item
:= First
(Expressions
(List
));
26875 while Present
(Item
) loop
26876 Collect_Global_Item
(Item
, Mode
);
26880 -- The declaration of a moded global list appears as a collection
26881 -- of component associations where individual choices denote mode.
26883 elsif Present
(Component_Associations
(List
)) then
26884 Item
:= First
(Component_Associations
(List
));
26885 while Present
(Item
) loop
26886 Collect_Global_Items
26887 (List
=> Expression
(Item
),
26888 Mode
=> Chars
(First
(Choices
(Item
))));
26896 raise Program_Error
;
26899 -- To accommodate partial decoration of disabled SPARK features, this
26900 -- routine may be called with illegal input. If this is the case, do
26901 -- not raise Program_Error.
26906 end Collect_Global_Items
;
26908 -------------------------
26909 -- Present_Then_Remove --
26910 -------------------------
26912 function Present_Then_Remove
26914 Item
: Entity_Id
) return Boolean
26919 if Present
(List
) then
26920 Elmt
:= First_Elmt
(List
);
26921 while Present
(Elmt
) loop
26922 if Node
(Elmt
) = Item
then
26923 Remove_Elmt
(List
, Elmt
);
26932 end Present_Then_Remove
;
26934 procedure Present_Then_Remove
(List
: Elist_Id
; Item
: Entity_Id
) is
26937 Ignore
:= Present_Then_Remove
(List
, Item
);
26938 end Present_Then_Remove
;
26940 -------------------------------
26941 -- Report_Extra_Constituents --
26942 -------------------------------
26944 procedure Report_Extra_Constituents
is
26945 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
);
26946 -- Emit an error for every element of List
26948 ---------------------------------------
26949 -- Report_Extra_Constituents_In_List --
26950 ---------------------------------------
26952 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
) is
26953 Constit_Elmt
: Elmt_Id
;
26956 if Present
(List
) then
26957 Constit_Elmt
:= First_Elmt
(List
);
26958 while Present
(Constit_Elmt
) loop
26959 SPARK_Msg_NE
("extra constituent &", N
, Node
(Constit_Elmt
));
26960 Next_Elmt
(Constit_Elmt
);
26963 end Report_Extra_Constituents_In_List
;
26965 -- Start of processing for Report_Extra_Constituents
26968 -- Do not perform this check in an instance because it was already
26969 -- performed successfully in the generic template.
26971 if Is_Generic_Instance
(Spec_Id
) then
26975 Report_Extra_Constituents_In_List
(In_Constits
);
26976 Report_Extra_Constituents_In_List
(In_Out_Constits
);
26977 Report_Extra_Constituents_In_List
(Out_Constits
);
26978 Report_Extra_Constituents_In_List
(Proof_In_Constits
);
26980 end Report_Extra_Constituents
;
26982 --------------------------
26983 -- Report_Missing_Items --
26984 --------------------------
26986 procedure Report_Missing_Items
is
26987 Item_Elmt
: Elmt_Id
;
26988 Item_Id
: Entity_Id
;
26991 -- Do not perform this check in an instance because it was already
26992 -- performed successfully in the generic template.
26994 if Is_Generic_Instance
(Spec_Id
) then
26998 if Present
(Repeat_Items
) then
26999 Item_Elmt
:= First_Elmt
(Repeat_Items
);
27000 while Present
(Item_Elmt
) loop
27001 Item_Id
:= Node
(Item_Elmt
);
27002 SPARK_Msg_NE
("missing global item &", N
, Item_Id
);
27003 Next_Elmt
(Item_Elmt
);
27007 end Report_Missing_Items
;
27011 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
27012 Errors
: constant Nat
:= Serious_Errors_Detected
;
27014 No_Constit
: Boolean;
27016 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
27019 -- Do not analyze the pragma multiple times
27021 if Is_Analyzed_Pragma
(N
) then
27025 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
27027 -- Use the anonymous object as the proper spec when Refined_Global
27028 -- applies to the body of a single task type. The object carries the
27029 -- proper Chars as well as all non-refined versions of pragmas.
27031 if Is_Single_Concurrent_Type
(Spec_Id
) then
27032 Spec_Id
:= Anonymous_Object
(Spec_Id
);
27035 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
27036 Items
:= Expression
(Get_Argument
(N
, Spec_Id
));
27038 -- The subprogram declaration lacks pragma Global. This renders
27039 -- Refined_Global useless as there is nothing to refine.
27041 if No
(Global
) then
27043 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
27044 & "& lacks aspect or pragma Global"), N
, Spec_Id
);
27048 -- Extract all relevant items from the corresponding Global pragma
27050 Collect_Global_Items
(Expression
(Get_Argument
(Global
, Spec_Id
)));
27052 -- Package and subprogram bodies are instantiated individually in
27053 -- a separate compiler pass. Due to this mode of instantiation, the
27054 -- refinement of a state may no longer be visible when a subprogram
27055 -- body contract is instantiated. Since the generic template is legal,
27056 -- do not perform this check in the instance to circumvent this oddity.
27058 if Is_Generic_Instance
(Spec_Id
) then
27061 -- Non-instance case
27064 -- The corresponding Global pragma must mention at least one
27065 -- state with a visible refinement at the point Refined_Global
27066 -- is processed. States with null refinements need Refined_Global
27067 -- pragma (SPARK RM 7.2.4(2)).
27069 if not Has_In_State
27070 and then not Has_In_Out_State
27071 and then not Has_Out_State
27072 and then not Has_Proof_In_State
27073 and then not Has_Null_State
27076 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
27077 & "depend on abstract state with visible refinement"),
27081 -- The global refinement of inputs and outputs cannot be null when
27082 -- the corresponding Global pragma contains at least one item except
27083 -- in the case where we have states with null refinements.
27085 elsif Nkind
(Items
) = N_Null
27087 (Present
(In_Items
)
27088 or else Present
(In_Out_Items
)
27089 or else Present
(Out_Items
)
27090 or else Present
(Proof_In_Items
))
27091 and then not Has_Null_State
27094 (Fix_Msg
(Spec_Id
, "refinement cannot be null, subprogram & has "
27095 & "global items"), N
, Spec_Id
);
27100 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
27101 -- This ensures that the categorization of all refined global items is
27102 -- consistent with their role.
27104 Analyze_Global_In_Decl_Part
(N
);
27106 -- Perform all refinement checks with respect to completeness and mode
27109 if Serious_Errors_Detected
= Errors
then
27110 Check_Refined_Global_List
(Items
);
27113 -- Store the information that no constituent is used in the global
27114 -- refinement, prior to calling checking procedures which remove items
27115 -- from the list of constituents.
27119 and then No
(In_Out_Constits
)
27120 and then No
(Out_Constits
)
27121 and then No
(Proof_In_Constits
);
27123 -- For Input states with visible refinement, at least one constituent
27124 -- must be used as an Input in the global refinement.
27126 if Serious_Errors_Detected
= Errors
then
27127 Check_Input_States
;
27130 -- Verify all possible completion variants for In_Out states with
27131 -- visible refinement.
27133 if Serious_Errors_Detected
= Errors
then
27134 Check_In_Out_States
;
27137 -- For Output states with visible refinement, all constituents must be
27138 -- used as Outputs in the global refinement.
27140 if Serious_Errors_Detected
= Errors
then
27141 Check_Output_States
;
27144 -- For Proof_In states with visible refinement, at least one constituent
27145 -- must be used as Proof_In in the global refinement.
27147 if Serious_Errors_Detected
= Errors
then
27148 Check_Proof_In_States
;
27151 -- Emit errors for all constituents that belong to other states with
27152 -- visible refinement that do not appear in Global.
27154 if Serious_Errors_Detected
= Errors
then
27155 Report_Extra_Constituents
;
27158 -- Emit errors for all items in Global that are not repeated in the
27159 -- global refinement and for which there is no full visible refinement
27160 -- and, in the case of states with partial visible refinement, no
27161 -- constituent is mentioned in the global refinement.
27163 if Serious_Errors_Detected
= Errors
then
27164 Report_Missing_Items
;
27167 -- Emit an error if no constituent is used in the global refinement
27168 -- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise
27169 -- one may be issued by the checking procedures. Do not perform this
27170 -- check in an instance because it was already performed successfully
27171 -- in the generic template.
27173 if Serious_Errors_Detected
= Errors
27174 and then not Is_Generic_Instance
(Spec_Id
)
27175 and then not Has_Null_State
27176 and then No_Constit
27178 SPARK_Msg_N
("missing refinement", N
);
27182 Set_Is_Analyzed_Pragma
(N
);
27183 end Analyze_Refined_Global_In_Decl_Part
;
27185 ----------------------------------------
27186 -- Analyze_Refined_State_In_Decl_Part --
27187 ----------------------------------------
27189 procedure Analyze_Refined_State_In_Decl_Part
27191 Freeze_Id
: Entity_Id
:= Empty
)
27193 Body_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
27194 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
27195 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(Body_Decl
);
27197 Available_States
: Elist_Id
:= No_Elist
;
27198 -- A list of all abstract states defined in the package declaration that
27199 -- are available for refinement. The list is used to report unrefined
27202 Body_States
: Elist_Id
:= No_Elist
;
27203 -- A list of all hidden states that appear in the body of the related
27204 -- package. The list is used to report unused hidden states.
27206 Constituents_Seen
: Elist_Id
:= No_Elist
;
27207 -- A list that contains all constituents processed so far. The list is
27208 -- used to detect multiple uses of the same constituent.
27210 Freeze_Posted
: Boolean := False;
27211 -- A flag that controls the output of a freezing-related error (see use
27214 Refined_States_Seen
: Elist_Id
:= No_Elist
;
27215 -- A list that contains all refined states processed so far. The list is
27216 -- used to detect duplicate refinements.
27218 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
);
27219 -- Perform full analysis of a single refinement clause
27221 procedure Report_Unrefined_States
(States
: Elist_Id
);
27222 -- Emit errors for all unrefined abstract states found in list States
27224 -------------------------------
27225 -- Analyze_Refinement_Clause --
27226 -------------------------------
27228 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
) is
27229 AR_Constit
: Entity_Id
:= Empty
;
27230 AW_Constit
: Entity_Id
:= Empty
;
27231 ER_Constit
: Entity_Id
:= Empty
;
27232 EW_Constit
: Entity_Id
:= Empty
;
27233 -- The entities of external constituents that contain one of the
27234 -- following enabled properties: Async_Readers, Async_Writers,
27235 -- Effective_Reads and Effective_Writes.
27237 External_Constit_Seen
: Boolean := False;
27238 -- Flag used to mark when at least one external constituent is part
27239 -- of the state refinement.
27241 Non_Null_Seen
: Boolean := False;
27242 Null_Seen
: Boolean := False;
27243 -- Flags used to detect multiple uses of null in a single clause or a
27244 -- mixture of null and non-null constituents.
27246 Part_Of_Constits
: Elist_Id
:= No_Elist
;
27247 -- A list of all candidate constituents subject to indicator Part_Of
27248 -- where the encapsulating state is the current state.
27251 State_Id
: Entity_Id
;
27252 -- The current state being refined
27254 procedure Analyze_Constituent
(Constit
: Node_Id
);
27255 -- Perform full analysis of a single constituent
27257 procedure Check_External_Property
27258 (Prop_Nam
: Name_Id
;
27260 Constit
: Entity_Id
);
27261 -- Determine whether a property denoted by name Prop_Nam is present
27262 -- in the refined state. Emit an error if this is not the case. Flag
27263 -- Enabled should be set when the property applies to the refined
27264 -- state. Constit denotes the constituent (if any) which introduces
27265 -- the property in the refinement.
27267 procedure Match_State
;
27268 -- Determine whether the state being refined appears in list
27269 -- Available_States. Emit an error when attempting to re-refine the
27270 -- state or when the state is not defined in the package declaration,
27271 -- otherwise remove the state from Available_States.
27273 procedure Report_Unused_Constituents
(Constits
: Elist_Id
);
27274 -- Emit errors for all unused Part_Of constituents in list Constits
27276 -------------------------
27277 -- Analyze_Constituent --
27278 -------------------------
27280 procedure Analyze_Constituent
(Constit
: Node_Id
) is
27281 procedure Match_Constituent
(Constit_Id
: Entity_Id
);
27282 -- Determine whether constituent Constit denoted by its entity
27283 -- Constit_Id appears in Body_States. Emit an error when the
27284 -- constituent is not a valid hidden state of the related package
27285 -- or when it is used more than once. Otherwise remove the
27286 -- constituent from Body_States.
27288 -----------------------
27289 -- Match_Constituent --
27290 -----------------------
27292 procedure Match_Constituent
(Constit_Id
: Entity_Id
) is
27293 procedure Collect_Constituent
;
27294 -- Verify the legality of constituent Constit_Id and add it to
27295 -- the refinements of State_Id.
27297 -------------------------
27298 -- Collect_Constituent --
27299 -------------------------
27301 procedure Collect_Constituent
is
27302 Constits
: Elist_Id
;
27305 -- The Ghost policy in effect at the point of abstract state
27306 -- declaration and constituent must match (SPARK RM 6.9(15))
27308 Check_Ghost_Refinement
27309 (State
, State_Id
, Constit
, Constit_Id
);
27311 -- A synchronized state must be refined by a synchronized
27312 -- object or another synchronized state (SPARK RM 9.6).
27314 if Is_Synchronized_State
(State_Id
)
27315 and then not Is_Synchronized_Object
(Constit_Id
)
27316 and then not Is_Synchronized_State
(Constit_Id
)
27319 ("constituent of synchronized state & must be "
27320 & "synchronized", Constit
, State_Id
);
27323 -- Add the constituent to the list of processed items to aid
27324 -- with the detection of duplicates.
27326 Append_New_Elmt
(Constit_Id
, Constituents_Seen
);
27328 -- Collect the constituent in the list of refinement items
27329 -- and establish a relation between the refined state and
27332 Constits
:= Refinement_Constituents
(State_Id
);
27334 if No
(Constits
) then
27335 Constits
:= New_Elmt_List
;
27336 Set_Refinement_Constituents
(State_Id
, Constits
);
27339 Append_Elmt
(Constit_Id
, Constits
);
27340 Set_Encapsulating_State
(Constit_Id
, State_Id
);
27342 -- The state has at least one legal constituent, mark the
27343 -- start of the refinement region. The region ends when the
27344 -- body declarations end (see routine Analyze_Declarations).
27346 Set_Has_Visible_Refinement
(State_Id
);
27348 -- When the constituent is external, save its relevant
27349 -- property for further checks.
27351 if Async_Readers_Enabled
(Constit_Id
) then
27352 AR_Constit
:= Constit_Id
;
27353 External_Constit_Seen
:= True;
27356 if Async_Writers_Enabled
(Constit_Id
) then
27357 AW_Constit
:= Constit_Id
;
27358 External_Constit_Seen
:= True;
27361 if Effective_Reads_Enabled
(Constit_Id
) then
27362 ER_Constit
:= Constit_Id
;
27363 External_Constit_Seen
:= True;
27366 if Effective_Writes_Enabled
(Constit_Id
) then
27367 EW_Constit
:= Constit_Id
;
27368 External_Constit_Seen
:= True;
27370 end Collect_Constituent
;
27374 State_Elmt
: Elmt_Id
;
27376 -- Start of processing for Match_Constituent
27379 -- Detect a duplicate use of a constituent
27381 if Contains
(Constituents_Seen
, Constit_Id
) then
27383 ("duplicate use of constituent &", Constit
, Constit_Id
);
27387 -- The constituent is subject to a Part_Of indicator
27389 if Present
(Encapsulating_State
(Constit_Id
)) then
27390 if Encapsulating_State
(Constit_Id
) = State_Id
then
27391 Remove
(Part_Of_Constits
, Constit_Id
);
27392 Collect_Constituent
;
27394 -- The constituent is part of another state and is used
27395 -- incorrectly in the refinement of the current state.
27398 Error_Msg_Name_1
:= Chars
(State_Id
);
27400 ("& cannot act as constituent of state %",
27401 Constit
, Constit_Id
);
27403 ("\Part_Of indicator specifies encapsulator &",
27404 Constit
, Encapsulating_State
(Constit_Id
));
27407 -- The only other source of legal constituents is the body
27408 -- state space of the related package.
27411 if Present
(Body_States
) then
27412 State_Elmt
:= First_Elmt
(Body_States
);
27413 while Present
(State_Elmt
) loop
27415 -- Consume a valid constituent to signal that it has
27416 -- been encountered.
27418 if Node
(State_Elmt
) = Constit_Id
then
27419 Remove_Elmt
(Body_States
, State_Elmt
);
27420 Collect_Constituent
;
27424 Next_Elmt
(State_Elmt
);
27428 -- At this point it is known that the constituent is not
27429 -- part of the package hidden state and cannot be used in
27430 -- a refinement (SPARK RM 7.2.2(9)).
27432 Error_Msg_Name_1
:= Chars
(Spec_Id
);
27434 ("cannot use & in refinement, constituent is not a hidden "
27435 & "state of package %", Constit
, Constit_Id
);
27437 end Match_Constituent
;
27441 Constit_Id
: Entity_Id
;
27442 Constits
: Elist_Id
;
27444 -- Start of processing for Analyze_Constituent
27447 -- Detect multiple uses of null in a single refinement clause or a
27448 -- mixture of null and non-null constituents.
27450 if Nkind
(Constit
) = N_Null
then
27453 ("multiple null constituents not allowed", Constit
);
27455 elsif Non_Null_Seen
then
27457 ("cannot mix null and non-null constituents", Constit
);
27462 -- Collect the constituent in the list of refinement items
27464 Constits
:= Refinement_Constituents
(State_Id
);
27466 if No
(Constits
) then
27467 Constits
:= New_Elmt_List
;
27468 Set_Refinement_Constituents
(State_Id
, Constits
);
27471 Append_Elmt
(Constit
, Constits
);
27473 -- The state has at least one legal constituent, mark the
27474 -- start of the refinement region. The region ends when the
27475 -- body declarations end (see Analyze_Declarations).
27477 Set_Has_Visible_Refinement
(State_Id
);
27480 -- Non-null constituents
27483 Non_Null_Seen
:= True;
27487 ("cannot mix null and non-null constituents", Constit
);
27491 Resolve_State
(Constit
);
27493 -- Ensure that the constituent denotes a valid state or a
27494 -- whole object (SPARK RM 7.2.2(5)).
27496 if Is_Entity_Name
(Constit
) then
27497 Constit_Id
:= Entity_Of
(Constit
);
27499 -- When a constituent is declared after a subprogram body
27500 -- that caused freezing of the related contract where
27501 -- pragma Refined_State resides, the constituent appears
27502 -- undefined and carries Any_Id as its entity.
27504 -- package body Pack
27505 -- with Refined_State => (State => Constit)
27508 -- with Refined_Global => (Input => Constit)
27516 if Constit_Id
= Any_Id
then
27517 SPARK_Msg_NE
("& is undefined", Constit
, Constit_Id
);
27519 -- Emit a specialized info message when the contract of
27520 -- the related package body was "frozen" by another body.
27521 -- Note that it is not possible to precisely identify why
27522 -- the constituent is undefined because it is not visible
27523 -- when pragma Refined_State is analyzed. This message is
27524 -- a reasonable approximation.
27526 if Present
(Freeze_Id
) and then not Freeze_Posted
then
27527 Freeze_Posted
:= True;
27529 Error_Msg_Name_1
:= Chars
(Body_Id
);
27530 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
27532 ("body & declared # freezes the contract of %",
27535 ("\all constituents must be declared before body #",
27538 -- A misplaced constituent is a critical error because
27539 -- pragma Refined_Depends or Refined_Global depends on
27540 -- the proper link between a state and a constituent.
27541 -- Stop the compilation, as this leads to a multitude
27542 -- of misleading cascaded errors.
27544 raise Unrecoverable_Error
;
27547 -- The constituent is a valid state or object
27549 elsif Ekind_In
(Constit_Id
, E_Abstract_State
,
27553 Match_Constituent
(Constit_Id
);
27555 -- The variable may eventually become a constituent of a
27556 -- single protected/task type. Record the reference now
27557 -- and verify its legality when analyzing the contract of
27558 -- the variable (SPARK RM 9.3).
27560 if Ekind
(Constit_Id
) = E_Variable
then
27561 Record_Possible_Part_Of_Reference
27562 (Var_Id
=> Constit_Id
,
27566 -- Otherwise the constituent is illegal
27570 ("constituent & must denote object or state",
27571 Constit
, Constit_Id
);
27574 -- The constituent is illegal
27577 SPARK_Msg_N
("malformed constituent", Constit
);
27580 end Analyze_Constituent
;
27582 -----------------------------
27583 -- Check_External_Property --
27584 -----------------------------
27586 procedure Check_External_Property
27587 (Prop_Nam
: Name_Id
;
27589 Constit
: Entity_Id
)
27592 -- The property is missing in the declaration of the state, but
27593 -- a constituent is introducing it in the state refinement
27594 -- (SPARK RM 7.2.8(2)).
27596 if not Enabled
and then Present
(Constit
) then
27597 Error_Msg_Name_1
:= Prop_Nam
;
27598 Error_Msg_Name_2
:= Chars
(State_Id
);
27600 ("constituent & introduces external property % in refinement "
27601 & "of state %", State
, Constit
);
27603 Error_Msg_Sloc
:= Sloc
(State_Id
);
27605 ("\property is missing in abstract state declaration #",
27608 end Check_External_Property
;
27614 procedure Match_State
is
27615 State_Elmt
: Elmt_Id
;
27618 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
27620 if Contains
(Refined_States_Seen
, State_Id
) then
27622 ("duplicate refinement of state &", State
, State_Id
);
27626 -- Inspect the abstract states defined in the package declaration
27627 -- looking for a match.
27629 State_Elmt
:= First_Elmt
(Available_States
);
27630 while Present
(State_Elmt
) loop
27632 -- A valid abstract state is being refined in the body. Add
27633 -- the state to the list of processed refined states to aid
27634 -- with the detection of duplicate refinements. Remove the
27635 -- state from Available_States to signal that it has already
27638 if Node
(State_Elmt
) = State_Id
then
27639 Append_New_Elmt
(State_Id
, Refined_States_Seen
);
27640 Remove_Elmt
(Available_States
, State_Elmt
);
27644 Next_Elmt
(State_Elmt
);
27647 -- If we get here, we are refining a state that is not defined in
27648 -- the package declaration.
27650 Error_Msg_Name_1
:= Chars
(Spec_Id
);
27652 ("cannot refine state, & is not defined in package %",
27656 --------------------------------
27657 -- Report_Unused_Constituents --
27658 --------------------------------
27660 procedure Report_Unused_Constituents
(Constits
: Elist_Id
) is
27661 Constit_Elmt
: Elmt_Id
;
27662 Constit_Id
: Entity_Id
;
27663 Posted
: Boolean := False;
27666 if Present
(Constits
) then
27667 Constit_Elmt
:= First_Elmt
(Constits
);
27668 while Present
(Constit_Elmt
) loop
27669 Constit_Id
:= Node
(Constit_Elmt
);
27671 -- Generate an error message of the form:
27673 -- state ... has unused Part_Of constituents
27674 -- abstract state ... defined at ...
27675 -- constant ... defined at ...
27676 -- variable ... defined at ...
27681 ("state & has unused Part_Of constituents",
27685 Error_Msg_Sloc
:= Sloc
(Constit_Id
);
27687 if Ekind
(Constit_Id
) = E_Abstract_State
then
27689 ("\abstract state & defined #", State
, Constit_Id
);
27691 elsif Ekind
(Constit_Id
) = E_Constant
then
27693 ("\constant & defined #", State
, Constit_Id
);
27696 pragma Assert
(Ekind
(Constit_Id
) = E_Variable
);
27697 SPARK_Msg_NE
("\variable & defined #", State
, Constit_Id
);
27700 Next_Elmt
(Constit_Elmt
);
27703 end Report_Unused_Constituents
;
27705 -- Local declarations
27707 Body_Ref
: Node_Id
;
27708 Body_Ref_Elmt
: Elmt_Id
;
27710 Extra_State
: Node_Id
;
27712 -- Start of processing for Analyze_Refinement_Clause
27715 -- A refinement clause appears as a component association where the
27716 -- sole choice is the state and the expressions are the constituents.
27717 -- This is a syntax error, always report.
27719 if Nkind
(Clause
) /= N_Component_Association
then
27720 Error_Msg_N
("malformed state refinement clause", Clause
);
27724 -- Analyze the state name of a refinement clause
27726 State
:= First
(Choices
(Clause
));
27729 Resolve_State
(State
);
27731 -- Ensure that the state name denotes a valid abstract state that is
27732 -- defined in the spec of the related package.
27734 if Is_Entity_Name
(State
) then
27735 State_Id
:= Entity_Of
(State
);
27737 -- When the abstract state is undefined, it appears as Any_Id. Do
27738 -- not continue with the analysis of the clause.
27740 if State_Id
= Any_Id
then
27743 -- Catch any attempts to re-refine a state or refine a state that
27744 -- is not defined in the package declaration.
27746 elsif Ekind
(State_Id
) = E_Abstract_State
then
27750 SPARK_Msg_NE
("& must denote abstract state", State
, State_Id
);
27754 -- References to a state with visible refinement are illegal.
27755 -- When nested packages are involved, detecting such references is
27756 -- tricky because pragma Refined_State is analyzed later than the
27757 -- offending pragma Depends or Global. References that occur in
27758 -- such nested context are stored in a list. Emit errors for all
27759 -- references found in Body_References (SPARK RM 6.1.4(8)).
27761 if Present
(Body_References
(State_Id
)) then
27762 Body_Ref_Elmt
:= First_Elmt
(Body_References
(State_Id
));
27763 while Present
(Body_Ref_Elmt
) loop
27764 Body_Ref
:= Node
(Body_Ref_Elmt
);
27766 SPARK_Msg_N
("reference to & not allowed", Body_Ref
);
27767 Error_Msg_Sloc
:= Sloc
(State
);
27768 SPARK_Msg_N
("\refinement of & is visible#", Body_Ref
);
27770 Next_Elmt
(Body_Ref_Elmt
);
27774 -- The state name is illegal. This is a syntax error, always report.
27777 Error_Msg_N
("malformed state name in refinement clause", State
);
27781 -- A refinement clause may only refine one state at a time
27783 Extra_State
:= Next
(State
);
27785 if Present
(Extra_State
) then
27787 ("refinement clause cannot cover multiple states", Extra_State
);
27790 -- Replicate the Part_Of constituents of the refined state because
27791 -- the algorithm will consume items.
27793 Part_Of_Constits
:= New_Copy_Elist
(Part_Of_Constituents
(State_Id
));
27795 -- Analyze all constituents of the refinement. Multiple constituents
27796 -- appear as an aggregate.
27798 Constit
:= Expression
(Clause
);
27800 if Nkind
(Constit
) = N_Aggregate
then
27801 if Present
(Component_Associations
(Constit
)) then
27803 ("constituents of refinement clause must appear in "
27804 & "positional form", Constit
);
27806 else pragma Assert
(Present
(Expressions
(Constit
)));
27807 Constit
:= First
(Expressions
(Constit
));
27808 while Present
(Constit
) loop
27809 Analyze_Constituent
(Constit
);
27814 -- Various forms of a single constituent. Note that these may include
27815 -- malformed constituents.
27818 Analyze_Constituent
(Constit
);
27821 -- Verify that external constituents do not introduce new external
27822 -- property in the state refinement (SPARK RM 7.2.8(2)).
27824 if Is_External_State
(State_Id
) then
27825 Check_External_Property
27826 (Prop_Nam
=> Name_Async_Readers
,
27827 Enabled
=> Async_Readers_Enabled
(State_Id
),
27828 Constit
=> AR_Constit
);
27830 Check_External_Property
27831 (Prop_Nam
=> Name_Async_Writers
,
27832 Enabled
=> Async_Writers_Enabled
(State_Id
),
27833 Constit
=> AW_Constit
);
27835 Check_External_Property
27836 (Prop_Nam
=> Name_Effective_Reads
,
27837 Enabled
=> Effective_Reads_Enabled
(State_Id
),
27838 Constit
=> ER_Constit
);
27840 Check_External_Property
27841 (Prop_Nam
=> Name_Effective_Writes
,
27842 Enabled
=> Effective_Writes_Enabled
(State_Id
),
27843 Constit
=> EW_Constit
);
27845 -- When a refined state is not external, it should not have external
27846 -- constituents (SPARK RM 7.2.8(1)).
27848 elsif External_Constit_Seen
then
27850 ("non-external state & cannot contain external constituents in "
27851 & "refinement", State
, State_Id
);
27854 -- Ensure that all Part_Of candidate constituents have been mentioned
27855 -- in the refinement clause.
27857 Report_Unused_Constituents
(Part_Of_Constits
);
27858 end Analyze_Refinement_Clause
;
27860 -----------------------------
27861 -- Report_Unrefined_States --
27862 -----------------------------
27864 procedure Report_Unrefined_States
(States
: Elist_Id
) is
27865 State_Elmt
: Elmt_Id
;
27868 if Present
(States
) then
27869 State_Elmt
:= First_Elmt
(States
);
27870 while Present
(State_Elmt
) loop
27872 ("abstract state & must be refined", Node
(State_Elmt
));
27874 Next_Elmt
(State_Elmt
);
27877 end Report_Unrefined_States
;
27879 -- Local declarations
27881 Clauses
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
27884 -- Start of processing for Analyze_Refined_State_In_Decl_Part
27887 -- Do not analyze the pragma multiple times
27889 if Is_Analyzed_Pragma
(N
) then
27893 -- Save the scenario for examination by the ABE Processing phase
27895 Record_Elaboration_Scenario
(N
);
27897 -- Replicate the abstract states declared by the package because the
27898 -- matching algorithm will consume states.
27900 Available_States
:= New_Copy_Elist
(Abstract_States
(Spec_Id
));
27902 -- Gather all abstract states and objects declared in the visible
27903 -- state space of the package body. These items must be utilized as
27904 -- constituents in a state refinement.
27906 Body_States
:= Collect_Body_States
(Body_Id
);
27908 -- Multiple non-null state refinements appear as an aggregate
27910 if Nkind
(Clauses
) = N_Aggregate
then
27911 if Present
(Expressions
(Clauses
)) then
27913 ("state refinements must appear as component associations",
27916 else pragma Assert
(Present
(Component_Associations
(Clauses
)));
27917 Clause
:= First
(Component_Associations
(Clauses
));
27918 while Present
(Clause
) loop
27919 Analyze_Refinement_Clause
(Clause
);
27924 -- Various forms of a single state refinement. Note that these may
27925 -- include malformed refinements.
27928 Analyze_Refinement_Clause
(Clauses
);
27931 -- List all abstract states that were left unrefined
27933 Report_Unrefined_States
(Available_States
);
27935 Set_Is_Analyzed_Pragma
(N
);
27936 end Analyze_Refined_State_In_Decl_Part
;
27938 ------------------------------------
27939 -- Analyze_Test_Case_In_Decl_Part --
27940 ------------------------------------
27942 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
) is
27943 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
27944 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
27946 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
);
27947 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
27948 -- denoted by Arg_Nam.
27950 ------------------------------
27951 -- Preanalyze_Test_Case_Arg --
27952 ------------------------------
27954 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
) is
27958 -- Preanalyze the original aspect argument for ASIS or for a generic
27959 -- subprogram to properly capture global references.
27961 if ASIS_Mode
or else Is_Generic_Subprogram
(Spec_Id
) then
27965 Arg_Nam
=> Arg_Nam
,
27966 From_Aspect
=> True);
27968 if Present
(Arg
) then
27969 Preanalyze_Assert_Expression
27970 (Expression
(Arg
), Standard_Boolean
);
27974 Arg
:= Test_Case_Arg
(N
, Arg_Nam
);
27976 if Present
(Arg
) then
27977 Preanalyze_Assert_Expression
(Expression
(Arg
), Standard_Boolean
);
27979 end Preanalyze_Test_Case_Arg
;
27983 Restore_Scope
: Boolean := False;
27985 -- Start of processing for Analyze_Test_Case_In_Decl_Part
27988 -- Do not analyze the pragma multiple times
27990 if Is_Analyzed_Pragma
(N
) then
27994 -- Ensure that the formal parameters are visible when analyzing all
27995 -- clauses. This falls out of the general rule of aspects pertaining
27996 -- to subprogram declarations.
27998 if not In_Open_Scopes
(Spec_Id
) then
27999 Restore_Scope
:= True;
28000 Push_Scope
(Spec_Id
);
28002 if Is_Generic_Subprogram
(Spec_Id
) then
28003 Install_Generic_Formals
(Spec_Id
);
28005 Install_Formals
(Spec_Id
);
28009 Preanalyze_Test_Case_Arg
(Name_Requires
);
28010 Preanalyze_Test_Case_Arg
(Name_Ensures
);
28012 if Restore_Scope
then
28016 -- Currently it is not possible to inline pre/postconditions on a
28017 -- subprogram subject to pragma Inline_Always.
28019 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
28021 Set_Is_Analyzed_Pragma
(N
);
28022 end Analyze_Test_Case_In_Decl_Part
;
28028 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean is
28033 if Present
(List
) then
28034 Elmt
:= First_Elmt
(List
);
28035 while Present
(Elmt
) loop
28036 if Nkind
(Node
(Elmt
)) = N_Defining_Identifier
then
28039 Id
:= Entity_Of
(Node
(Elmt
));
28042 if Id
= Item_Id
then
28053 -----------------------------------
28054 -- Build_Pragma_Check_Equivalent --
28055 -----------------------------------
28057 function Build_Pragma_Check_Equivalent
28059 Subp_Id
: Entity_Id
:= Empty
;
28060 Inher_Id
: Entity_Id
:= Empty
;
28061 Keep_Pragma_Id
: Boolean := False) return Node_Id
28063 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
;
28064 -- Detect whether node N references a formal parameter subject to
28065 -- pragma Unreferenced. If this is the case, set Comes_From_Source
28066 -- to False to suppress the generation of a reference when analyzing
28069 ------------------------
28070 -- Suppress_Reference --
28071 ------------------------
28073 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
is
28074 Formal
: Entity_Id
;
28077 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
28078 Formal
:= Entity
(N
);
28080 -- The formal parameter is subject to pragma Unreferenced. Prevent
28081 -- the generation of references by resetting the Comes_From_Source
28084 if Is_Formal
(Formal
)
28085 and then Has_Pragma_Unreferenced
(Formal
)
28087 Set_Comes_From_Source
(N
, False);
28092 end Suppress_Reference
;
28094 procedure Suppress_References
is
28095 new Traverse_Proc
(Suppress_Reference
);
28099 Loc
: constant Source_Ptr
:= Sloc
(Prag
);
28100 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
28101 Check_Prag
: Node_Id
;
28105 Needs_Wrapper
: Boolean;
28106 pragma Unreferenced
(Needs_Wrapper
);
28108 -- Start of processing for Build_Pragma_Check_Equivalent
28111 -- When the pre- or postcondition is inherited, map the formals of the
28112 -- inherited subprogram to those of the current subprogram. In addition,
28113 -- map primitive operations of the parent type into the corresponding
28114 -- primitive operations of the descendant.
28116 if Present
(Inher_Id
) then
28117 pragma Assert
(Present
(Subp_Id
));
28119 Update_Primitives_Mapping
(Inher_Id
, Subp_Id
);
28121 -- Use generic machinery to copy inherited pragma, as if it were an
28122 -- instantiation, resetting source locations appropriately, so that
28123 -- expressions inside the inherited pragma use chained locations.
28124 -- This is used in particular in GNATprove to locate precisely
28125 -- messages on a given inherited pragma.
28127 Set_Copied_Sloc_For_Inherited_Pragma
28128 (Unit_Declaration_Node
(Subp_Id
), Inher_Id
);
28129 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
28131 -- Build the inherited class-wide condition
28133 Build_Class_Wide_Expression
28134 (Prag
=> Check_Prag
,
28136 Par_Subp
=> Inher_Id
,
28137 Adjust_Sloc
=> True,
28138 Needs_Wrapper
=> Needs_Wrapper
);
28140 -- If not an inherited condition simply copy the original pragma
28143 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
28146 -- Mark the pragma as being internally generated and reset the Analyzed
28149 Set_Analyzed
(Check_Prag
, False);
28150 Set_Comes_From_Source
(Check_Prag
, False);
28152 -- The tree of the original pragma may contain references to the
28153 -- formal parameters of the related subprogram. At the same time
28154 -- the corresponding body may mark the formals as unreferenced:
28156 -- procedure Proc (Formal : ...)
28157 -- with Pre => Formal ...;
28159 -- procedure Proc (Formal : ...) is
28160 -- pragma Unreferenced (Formal);
28163 -- This creates problems because all pragma Check equivalents are
28164 -- analyzed at the end of the body declarations. Since all source
28165 -- references have already been accounted for, reset any references
28166 -- to such formals in the generated pragma Check equivalent.
28168 Suppress_References
(Check_Prag
);
28170 if Present
(Corresponding_Aspect
(Prag
)) then
28171 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Prag
)));
28176 -- Unless Keep_Pragma_Id is True in order to keep the identifier of
28177 -- the copied pragma in the newly created pragma, convert the copy into
28178 -- pragma Check by correcting the name and adding a check_kind argument.
28180 if not Keep_Pragma_Id
then
28181 Set_Class_Present
(Check_Prag
, False);
28183 Set_Pragma_Identifier
28184 (Check_Prag
, Make_Identifier
(Loc
, Name_Check
));
28186 Prepend_To
(Pragma_Argument_Associations
(Check_Prag
),
28187 Make_Pragma_Argument_Association
(Loc
,
28188 Expression
=> Make_Identifier
(Loc
, Nam
)));
28191 -- Update the error message when the pragma is inherited
28193 if Present
(Inher_Id
) then
28194 Msg_Arg
:= Last
(Pragma_Argument_Associations
(Check_Prag
));
28196 if Chars
(Msg_Arg
) = Name_Message
then
28197 String_To_Name_Buffer
(Strval
(Expression
(Msg_Arg
)));
28199 -- Insert "inherited" to improve the error message
28201 if Name_Buffer
(1 .. 8) = "failed p" then
28202 Insert_Str_In_Name_Buffer
("inherited ", 8);
28203 Set_Strval
(Expression
(Msg_Arg
), String_From_Name_Buffer
);
28209 end Build_Pragma_Check_Equivalent
;
28211 -----------------------------
28212 -- Check_Applicable_Policy --
28213 -----------------------------
28215 procedure Check_Applicable_Policy
(N
: Node_Id
) is
28219 Ename
: constant Name_Id
:= Original_Aspect_Pragma_Name
(N
);
28222 -- No effect if not valid assertion kind name
28224 if not Is_Valid_Assertion_Kind
(Ename
) then
28228 -- Loop through entries in check policy list
28230 PP
:= Opt
.Check_Policy_List
;
28231 while Present
(PP
) loop
28233 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
28234 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
28238 or else Pnm
= Name_Assertion
28239 or else (Pnm
= Name_Statement_Assertions
28240 and then Nam_In
(Ename
, Name_Assert
,
28241 Name_Assert_And_Cut
,
28243 Name_Loop_Invariant
,
28244 Name_Loop_Variant
))
28246 Policy
:= Chars
(Get_Pragma_Arg
(Last
(PPA
)));
28252 Set_Is_Ignored
(N
, True);
28253 Set_Is_Checked
(N
, False);
28258 Set_Is_Checked
(N
, True);
28259 Set_Is_Ignored
(N
, False);
28261 when Name_Disable
=>
28262 Set_Is_Ignored
(N
, True);
28263 Set_Is_Checked
(N
, False);
28264 Set_Is_Disabled
(N
, True);
28266 -- That should be exhaustive, the null here is a defence
28267 -- against a malformed tree from previous errors.
28276 PP
:= Next_Pragma
(PP
);
28280 -- If there are no specific entries that matched, then we let the
28281 -- setting of assertions govern. Note that this provides the needed
28282 -- compatibility with the RM for the cases of assertion, invariant,
28283 -- precondition, predicate, and postcondition.
28285 if Assertions_Enabled
then
28286 Set_Is_Checked
(N
, True);
28287 Set_Is_Ignored
(N
, False);
28289 Set_Is_Checked
(N
, False);
28290 Set_Is_Ignored
(N
, True);
28292 end Check_Applicable_Policy
;
28294 -------------------------------
28295 -- Check_External_Properties --
28296 -------------------------------
28298 procedure Check_External_Properties
28306 -- All properties enabled
28308 if AR
and AW
and ER
and EW
then
28311 -- Async_Readers + Effective_Writes
28312 -- Async_Readers + Async_Writers + Effective_Writes
28314 elsif AR
and EW
and not ER
then
28317 -- Async_Writers + Effective_Reads
28318 -- Async_Readers + Async_Writers + Effective_Reads
28320 elsif AW
and ER
and not EW
then
28323 -- Async_Readers + Async_Writers
28325 elsif AR
and AW
and not ER
and not EW
then
28330 elsif AR
and not AW
and not ER
and not EW
then
28335 elsif AW
and not AR
and not ER
and not EW
then
28340 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
28343 end Check_External_Properties
;
28349 function Check_Kind
(Nam
: Name_Id
) return Name_Id
is
28353 -- Loop through entries in check policy list
28355 PP
:= Opt
.Check_Policy_List
;
28356 while Present
(PP
) loop
28358 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
28359 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
28363 or else (Pnm
= Name_Assertion
28364 and then Is_Valid_Assertion_Kind
(Nam
))
28365 or else (Pnm
= Name_Statement_Assertions
28366 and then Nam_In
(Nam
, Name_Assert
,
28367 Name_Assert_And_Cut
,
28369 Name_Loop_Invariant
,
28370 Name_Loop_Variant
))
28372 case (Chars
(Get_Pragma_Arg
(Last
(PPA
)))) is
28381 return Name_Ignore
;
28383 when Name_Disable
=>
28384 return Name_Disable
;
28387 raise Program_Error
;
28391 PP
:= Next_Pragma
(PP
);
28396 -- If there are no specific entries that matched, then we let the
28397 -- setting of assertions govern. Note that this provides the needed
28398 -- compatibility with the RM for the cases of assertion, invariant,
28399 -- precondition, predicate, and postcondition.
28401 if Assertions_Enabled
then
28404 return Name_Ignore
;
28408 ---------------------------
28409 -- Check_Missing_Part_Of --
28410 ---------------------------
28412 procedure Check_Missing_Part_Of
(Item_Id
: Entity_Id
) is
28413 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean;
28414 -- Determine whether a package denoted by Pack_Id declares at least one
28417 -----------------------
28418 -- Has_Visible_State --
28419 -----------------------
28421 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean is
28422 Item_Id
: Entity_Id
;
28425 -- Traverse the entity chain of the package trying to find at least
28426 -- one visible abstract state, variable or a package [instantiation]
28427 -- that declares a visible state.
28429 Item_Id
:= First_Entity
(Pack_Id
);
28430 while Present
(Item_Id
)
28431 and then not In_Private_Part
(Item_Id
)
28433 -- Do not consider internally generated items
28435 if not Comes_From_Source
(Item_Id
) then
28438 -- A visible state has been found
28440 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
28443 -- Recursively peek into nested packages and instantiations
28445 elsif Ekind
(Item_Id
) = E_Package
28446 and then Has_Visible_State
(Item_Id
)
28451 Next_Entity
(Item_Id
);
28455 end Has_Visible_State
;
28459 Pack_Id
: Entity_Id
;
28460 Placement
: State_Space_Kind
;
28462 -- Start of processing for Check_Missing_Part_Of
28465 -- Do not consider abstract states, variables or package instantiations
28466 -- coming from an instance as those always inherit the Part_Of indicator
28467 -- of the instance itself.
28469 if In_Instance
then
28472 -- Do not consider internally generated entities as these can never
28473 -- have a Part_Of indicator.
28475 elsif not Comes_From_Source
(Item_Id
) then
28478 -- Perform these checks only when SPARK_Mode is enabled as they will
28479 -- interfere with standard Ada rules and produce false positives.
28481 elsif SPARK_Mode
/= On
then
28484 -- Do not consider constants, because the compiler cannot accurately
28485 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
28486 -- act as a hidden state of a package.
28488 elsif Ekind
(Item_Id
) = E_Constant
then
28492 -- Find where the abstract state, variable or package instantiation
28493 -- lives with respect to the state space.
28495 Find_Placement_In_State_Space
28496 (Item_Id
=> Item_Id
,
28497 Placement
=> Placement
,
28498 Pack_Id
=> Pack_Id
);
28500 -- Items that appear in a non-package construct (subprogram, block, etc)
28501 -- do not require a Part_Of indicator because they can never act as a
28504 if Placement
= Not_In_Package
then
28507 -- An item declared in the body state space of a package always act as a
28508 -- constituent and does not need explicit Part_Of indicator.
28510 elsif Placement
= Body_State_Space
then
28513 -- In general an item declared in the visible state space of a package
28514 -- does not require a Part_Of indicator. The only exception is when the
28515 -- related package is a private child unit in which case Part_Of must
28516 -- denote a state in the parent unit or in one of its descendants.
28518 elsif Placement
= Visible_State_Space
then
28519 if Is_Child_Unit
(Pack_Id
)
28520 and then Is_Private_Descendant
(Pack_Id
)
28522 -- A package instantiation does not need a Part_Of indicator when
28523 -- the related generic template has no visible state.
28525 if Ekind
(Item_Id
) = E_Package
28526 and then Is_Generic_Instance
(Item_Id
)
28527 and then not Has_Visible_State
(Item_Id
)
28531 -- All other cases require Part_Of
28535 ("indicator Part_Of is required in this context "
28536 & "(SPARK RM 7.2.6(3))", Item_Id
);
28537 Error_Msg_Name_1
:= Chars
(Pack_Id
);
28539 ("\& is declared in the visible part of private child "
28540 & "unit %", Item_Id
);
28544 -- When the item appears in the private state space of a package, it
28545 -- must be a part of some state declared by the said package.
28547 else pragma Assert
(Placement
= Private_State_Space
);
28549 -- The related package does not declare a state, the item cannot act
28550 -- as a Part_Of constituent.
28552 if No
(Get_Pragma
(Pack_Id
, Pragma_Abstract_State
)) then
28555 -- A package instantiation does not need a Part_Of indicator when the
28556 -- related generic template has no visible state.
28558 elsif Ekind
(Pack_Id
) = E_Package
28559 and then Is_Generic_Instance
(Pack_Id
)
28560 and then not Has_Visible_State
(Pack_Id
)
28564 -- All other cases require Part_Of
28568 ("indicator Part_Of is required in this context "
28569 & "(SPARK RM 7.2.6(2))", Item_Id
);
28570 Error_Msg_Name_1
:= Chars
(Pack_Id
);
28572 ("\& is declared in the private part of package %", Item_Id
);
28575 end Check_Missing_Part_Of
;
28577 ---------------------------------------------------
28578 -- Check_Postcondition_Use_In_Inlined_Subprogram --
28579 ---------------------------------------------------
28581 procedure Check_Postcondition_Use_In_Inlined_Subprogram
28583 Spec_Id
: Entity_Id
)
28586 if Warn_On_Redundant_Constructs
28587 and then Has_Pragma_Inline_Always
(Spec_Id
)
28588 and then Assertions_Enabled
28590 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
28592 if From_Aspect_Specification
(Prag
) then
28594 ("aspect % not enforced on inlined subprogram &?r?",
28595 Corresponding_Aspect
(Prag
), Spec_Id
);
28598 ("pragma % not enforced on inlined subprogram &?r?",
28602 end Check_Postcondition_Use_In_Inlined_Subprogram
;
28604 -------------------------------------
28605 -- Check_State_And_Constituent_Use --
28606 -------------------------------------
28608 procedure Check_State_And_Constituent_Use
28609 (States
: Elist_Id
;
28610 Constits
: Elist_Id
;
28613 Constit_Elmt
: Elmt_Id
;
28614 Constit_Id
: Entity_Id
;
28615 State_Id
: Entity_Id
;
28618 -- Nothing to do if there are no states or constituents
28620 if No
(States
) or else No
(Constits
) then
28624 -- Inspect the list of constituents and try to determine whether its
28625 -- encapsulating state is in list States.
28627 Constit_Elmt
:= First_Elmt
(Constits
);
28628 while Present
(Constit_Elmt
) loop
28629 Constit_Id
:= Node
(Constit_Elmt
);
28631 -- Determine whether the constituent is part of an encapsulating
28632 -- state that appears in the same context and if this is the case,
28633 -- emit an error (SPARK RM 7.2.6(7)).
28635 State_Id
:= Find_Encapsulating_State
(States
, Constit_Id
);
28637 if Present
(State_Id
) then
28638 Error_Msg_Name_1
:= Chars
(Constit_Id
);
28640 ("cannot mention state & and its constituent % in the same "
28641 & "context", Context
, State_Id
);
28645 Next_Elmt
(Constit_Elmt
);
28647 end Check_State_And_Constituent_Use
;
28649 ---------------------------------------------
28650 -- Collect_Inherited_Class_Wide_Conditions --
28651 ---------------------------------------------
28653 procedure Collect_Inherited_Class_Wide_Conditions
(Subp
: Entity_Id
) is
28654 Parent_Subp
: constant Entity_Id
:=
28655 Ultimate_Alias
(Overridden_Operation
(Subp
));
28656 -- The Overridden_Operation may itself be inherited and as such have no
28657 -- explicit contract.
28659 Prags
: constant Node_Id
:= Contract
(Parent_Subp
);
28660 In_Spec_Expr
: Boolean;
28661 Installed
: Boolean;
28663 New_Prag
: Node_Id
;
28666 Installed
:= False;
28668 -- Iterate over the contract of the overridden subprogram to find all
28669 -- inherited class-wide pre- and postconditions.
28671 if Present
(Prags
) then
28672 Prag
:= Pre_Post_Conditions
(Prags
);
28674 while Present
(Prag
) loop
28675 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
28676 Name_Precondition
, Name_Postcondition
)
28677 and then Class_Present
(Prag
)
28679 -- The generated pragma must be analyzed in the context of
28680 -- the subprogram, to make its formals visible. In addition,
28681 -- we must inhibit freezing and full analysis because the
28682 -- controlling type of the subprogram is not frozen yet, and
28683 -- may have further primitives.
28685 if not Installed
then
28688 Install_Formals
(Subp
);
28689 In_Spec_Expr
:= In_Spec_Expression
;
28690 In_Spec_Expression
:= True;
28694 Build_Pragma_Check_Equivalent
28695 (Prag
, Subp
, Parent_Subp
, Keep_Pragma_Id
=> True);
28697 Insert_After
(Unit_Declaration_Node
(Subp
), New_Prag
);
28698 Preanalyze
(New_Prag
);
28700 -- Prevent further analysis in subsequent processing of the
28701 -- current list of declarations
28703 Set_Analyzed
(New_Prag
);
28706 Prag
:= Next_Pragma
(Prag
);
28710 In_Spec_Expression
:= In_Spec_Expr
;
28714 end Collect_Inherited_Class_Wide_Conditions
;
28716 ---------------------------------------
28717 -- Collect_Subprogram_Inputs_Outputs --
28718 ---------------------------------------
28720 procedure Collect_Subprogram_Inputs_Outputs
28721 (Subp_Id
: Entity_Id
;
28722 Synthesize
: Boolean := False;
28723 Subp_Inputs
: in out Elist_Id
;
28724 Subp_Outputs
: in out Elist_Id
;
28725 Global_Seen
: out Boolean)
28727 procedure Collect_Dependency_Clause
(Clause
: Node_Id
);
28728 -- Collect all relevant items from a dependency clause
28730 procedure Collect_Global_List
28732 Mode
: Name_Id
:= Name_Input
);
28733 -- Collect all relevant items from a global list
28735 -------------------------------
28736 -- Collect_Dependency_Clause --
28737 -------------------------------
28739 procedure Collect_Dependency_Clause
(Clause
: Node_Id
) is
28740 procedure Collect_Dependency_Item
28742 Is_Input
: Boolean);
28743 -- Add an item to the proper subprogram input or output collection
28745 -----------------------------
28746 -- Collect_Dependency_Item --
28747 -----------------------------
28749 procedure Collect_Dependency_Item
28751 Is_Input
: Boolean)
28756 -- Nothing to collect when the item is null
28758 if Nkind
(Item
) = N_Null
then
28761 -- Ditto for attribute 'Result
28763 elsif Is_Attribute_Result
(Item
) then
28766 -- Multiple items appear as an aggregate
28768 elsif Nkind
(Item
) = N_Aggregate
then
28769 Extra
:= First
(Expressions
(Item
));
28770 while Present
(Extra
) loop
28771 Collect_Dependency_Item
(Extra
, Is_Input
);
28775 -- Otherwise this is a solitary item
28779 Append_New_Elmt
(Item
, Subp_Inputs
);
28781 Append_New_Elmt
(Item
, Subp_Outputs
);
28784 end Collect_Dependency_Item
;
28786 -- Start of processing for Collect_Dependency_Clause
28789 if Nkind
(Clause
) = N_Null
then
28792 -- A dependency clause appears as component association
28794 elsif Nkind
(Clause
) = N_Component_Association
then
28795 Collect_Dependency_Item
28796 (Item
=> Expression
(Clause
),
28799 Collect_Dependency_Item
28800 (Item
=> First
(Choices
(Clause
)),
28801 Is_Input
=> False);
28803 -- To accommodate partial decoration of disabled SPARK features, this
28804 -- routine may be called with illegal input. If this is the case, do
28805 -- not raise Program_Error.
28810 end Collect_Dependency_Clause
;
28812 -------------------------
28813 -- Collect_Global_List --
28814 -------------------------
28816 procedure Collect_Global_List
28818 Mode
: Name_Id
:= Name_Input
)
28820 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
28821 -- Add an item to the proper subprogram input or output collection
28823 -------------------------
28824 -- Collect_Global_Item --
28825 -------------------------
28827 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
28829 if Nam_In
(Mode
, Name_In_Out
, Name_Input
) then
28830 Append_New_Elmt
(Item
, Subp_Inputs
);
28833 if Nam_In
(Mode
, Name_In_Out
, Name_Output
) then
28834 Append_New_Elmt
(Item
, Subp_Outputs
);
28836 end Collect_Global_Item
;
28843 -- Start of processing for Collect_Global_List
28846 if Nkind
(List
) = N_Null
then
28849 -- Single global item declaration
28851 elsif Nkind_In
(List
, N_Expanded_Name
,
28853 N_Selected_Component
)
28855 Collect_Global_Item
(List
, Mode
);
28857 -- Simple global list or moded global list declaration
28859 elsif Nkind
(List
) = N_Aggregate
then
28860 if Present
(Expressions
(List
)) then
28861 Item
:= First
(Expressions
(List
));
28862 while Present
(Item
) loop
28863 Collect_Global_Item
(Item
, Mode
);
28868 Assoc
:= First
(Component_Associations
(List
));
28869 while Present
(Assoc
) loop
28870 Collect_Global_List
28871 (List
=> Expression
(Assoc
),
28872 Mode
=> Chars
(First
(Choices
(Assoc
))));
28877 -- To accommodate partial decoration of disabled SPARK features, this
28878 -- routine may be called with illegal input. If this is the case, do
28879 -- not raise Program_Error.
28884 end Collect_Global_List
;
28891 Formal
: Entity_Id
;
28893 Spec_Id
: Entity_Id
:= Empty
;
28894 Subp_Decl
: Node_Id
;
28897 -- Start of processing for Collect_Subprogram_Inputs_Outputs
28900 Global_Seen
:= False;
28902 -- Process all formal parameters of entries, [generic] subprograms, and
28905 if Ekind_In
(Subp_Id
, E_Entry
,
28908 E_Generic_Function
,
28909 E_Generic_Procedure
,
28913 Subp_Decl
:= Unit_Declaration_Node
(Subp_Id
);
28914 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
28916 -- Process all formal parameters
28918 Formal
:= First_Entity
(Spec_Id
);
28919 while Present
(Formal
) loop
28920 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_In_Parameter
) then
28921 Append_New_Elmt
(Formal
, Subp_Inputs
);
28924 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
28925 Append_New_Elmt
(Formal
, Subp_Outputs
);
28927 -- Out parameters can act as inputs when the related type is
28928 -- tagged, unconstrained array, unconstrained record, or record
28929 -- with unconstrained components.
28931 if Ekind
(Formal
) = E_Out_Parameter
28932 and then Is_Unconstrained_Or_Tagged_Item
(Formal
)
28934 Append_New_Elmt
(Formal
, Subp_Inputs
);
28938 Next_Entity
(Formal
);
28941 -- Otherwise the input denotes a task type, a task body, or the
28942 -- anonymous object created for a single task type.
28944 elsif Ekind_In
(Subp_Id
, E_Task_Type
, E_Task_Body
)
28945 or else Is_Single_Task_Object
(Subp_Id
)
28947 Subp_Decl
:= Declaration_Node
(Subp_Id
);
28948 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
28951 -- When processing an entry, subprogram or task body, look for pragmas
28952 -- Refined_Depends and Refined_Global as they specify the inputs and
28955 if Is_Entry_Body
(Subp_Id
)
28956 or else Ekind_In
(Subp_Id
, E_Subprogram_Body
, E_Task_Body
)
28958 Depends
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Depends
);
28959 Global
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Global
);
28961 -- Subprogram declaration or stand-alone body case, look for pragmas
28962 -- Depends and Global
28965 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
28966 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
28969 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
28970 -- because it provides finer granularity of inputs and outputs.
28972 if Present
(Global
) then
28973 Global_Seen
:= True;
28974 Collect_Global_List
(Expression
(Get_Argument
(Global
, Spec_Id
)));
28976 -- When the related subprogram lacks pragma [Refined_]Global, fall back
28977 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
28978 -- the inputs and outputs from [Refined_]Depends.
28980 elsif Synthesize
and then Present
(Depends
) then
28981 Clauses
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
28983 -- Multiple dependency clauses appear as an aggregate
28985 if Nkind
(Clauses
) = N_Aggregate
then
28986 Clause
:= First
(Component_Associations
(Clauses
));
28987 while Present
(Clause
) loop
28988 Collect_Dependency_Clause
(Clause
);
28992 -- Otherwise this is a single dependency clause
28995 Collect_Dependency_Clause
(Clauses
);
28999 -- The current instance of a protected type acts as a formal parameter
29000 -- of mode IN for functions and IN OUT for entries and procedures
29001 -- (SPARK RM 6.1.4).
29003 if Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
29004 Typ
:= Scope
(Spec_Id
);
29006 -- Use the anonymous object when the type is single protected
29008 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
29009 Typ
:= Anonymous_Object
(Typ
);
29012 Append_New_Elmt
(Typ
, Subp_Inputs
);
29014 if Ekind_In
(Spec_Id
, E_Entry
, E_Entry_Family
, E_Procedure
) then
29015 Append_New_Elmt
(Typ
, Subp_Outputs
);
29018 -- The current instance of a task type acts as a formal parameter of
29019 -- mode IN OUT (SPARK RM 6.1.4).
29021 elsif Ekind
(Spec_Id
) = E_Task_Type
then
29024 -- Use the anonymous object when the type is single task
29026 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
29027 Typ
:= Anonymous_Object
(Typ
);
29030 Append_New_Elmt
(Typ
, Subp_Inputs
);
29031 Append_New_Elmt
(Typ
, Subp_Outputs
);
29033 elsif Is_Single_Task_Object
(Spec_Id
) then
29034 Append_New_Elmt
(Spec_Id
, Subp_Inputs
);
29035 Append_New_Elmt
(Spec_Id
, Subp_Outputs
);
29037 end Collect_Subprogram_Inputs_Outputs
;
29039 ---------------------------
29040 -- Contract_Freeze_Error --
29041 ---------------------------
29043 procedure Contract_Freeze_Error
29044 (Contract_Id
: Entity_Id
;
29045 Freeze_Id
: Entity_Id
)
29048 Error_Msg_Name_1
:= Chars
(Contract_Id
);
29049 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
29052 ("body & declared # freezes the contract of%", Contract_Id
, Freeze_Id
);
29054 ("\all contractual items must be declared before body #", Contract_Id
);
29055 end Contract_Freeze_Error
;
29057 ---------------------------------
29058 -- Delay_Config_Pragma_Analyze --
29059 ---------------------------------
29061 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean is
29063 return Nam_In
(Pragma_Name_Unmapped
(N
),
29064 Name_Interrupt_State
, Name_Priority_Specific_Dispatching
);
29065 end Delay_Config_Pragma_Analyze
;
29067 -----------------------
29068 -- Duplication_Error --
29069 -----------------------
29071 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
) is
29072 Prag_From_Asp
: constant Boolean := From_Aspect_Specification
(Prag
);
29073 Prev_From_Asp
: constant Boolean := From_Aspect_Specification
(Prev
);
29076 Error_Msg_Sloc
:= Sloc
(Prev
);
29077 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
29079 -- Emit a precise message to distinguish between source pragmas and
29080 -- pragmas generated from aspects. The ordering of the two pragmas is
29084 -- Prag -- duplicate
29086 -- No error is emitted when both pragmas come from aspects because this
29087 -- is already detected by the general aspect analysis mechanism.
29089 if Prag_From_Asp
and Prev_From_Asp
then
29091 elsif Prag_From_Asp
then
29092 Error_Msg_N
("aspect % duplicates pragma declared #", Prag
);
29093 elsif Prev_From_Asp
then
29094 Error_Msg_N
("pragma % duplicates aspect declared #", Prag
);
29096 Error_Msg_N
("pragma % duplicates pragma declared #", Prag
);
29098 end Duplication_Error
;
29100 ------------------------------
29101 -- Find_Encapsulating_State --
29102 ------------------------------
29104 function Find_Encapsulating_State
29105 (States
: Elist_Id
;
29106 Constit_Id
: Entity_Id
) return Entity_Id
29108 State_Id
: Entity_Id
;
29111 -- Since a constituent may be part of a larger constituent set, climb
29112 -- the encapsulating state chain looking for a state that appears in
29115 State_Id
:= Encapsulating_State
(Constit_Id
);
29116 while Present
(State_Id
) loop
29117 if Contains
(States
, State_Id
) then
29121 State_Id
:= Encapsulating_State
(State_Id
);
29125 end Find_Encapsulating_State
;
29127 --------------------------
29128 -- Find_Related_Context --
29129 --------------------------
29131 function Find_Related_Context
29133 Do_Checks
: Boolean := False) return Node_Id
29138 Stmt
:= Prev
(Prag
);
29139 while Present
(Stmt
) loop
29141 -- Skip prior pragmas, but check for duplicates
29143 if Nkind
(Stmt
) = N_Pragma
then
29145 and then Pragma_Name
(Stmt
) = Pragma_Name
(Prag
)
29152 -- Skip internally generated code
29154 elsif not Comes_From_Source
(Stmt
) then
29156 -- The anonymous object created for a single concurrent type is a
29157 -- suitable context.
29159 if Nkind
(Stmt
) = N_Object_Declaration
29160 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
29165 -- Return the current source construct
29175 end Find_Related_Context
;
29177 --------------------------------------
29178 -- Find_Related_Declaration_Or_Body --
29179 --------------------------------------
29181 function Find_Related_Declaration_Or_Body
29183 Do_Checks
: Boolean := False) return Node_Id
29185 Prag_Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
29187 procedure Expression_Function_Error
;
29188 -- Emit an error concerning pragma Prag that illegaly applies to an
29189 -- expression function.
29191 -------------------------------
29192 -- Expression_Function_Error --
29193 -------------------------------
29195 procedure Expression_Function_Error
is
29197 Error_Msg_Name_1
:= Prag_Nam
;
29199 -- Emit a precise message to distinguish between source pragmas and
29200 -- pragmas generated from aspects.
29202 if From_Aspect_Specification
(Prag
) then
29204 ("aspect % cannot apply to a stand alone expression function",
29208 ("pragma % cannot apply to a stand alone expression function",
29211 end Expression_Function_Error
;
29215 Context
: constant Node_Id
:= Parent
(Prag
);
29218 Look_For_Body
: constant Boolean :=
29219 Nam_In
(Prag_Nam
, Name_Refined_Depends
,
29220 Name_Refined_Global
,
29222 Name_Refined_State
);
29223 -- Refinement pragmas must be associated with a subprogram body [stub]
29225 -- Start of processing for Find_Related_Declaration_Or_Body
29228 Stmt
:= Prev
(Prag
);
29229 while Present
(Stmt
) loop
29231 -- Skip prior pragmas, but check for duplicates. Pragmas produced
29232 -- by splitting a complex pre/postcondition are not considered to
29235 if Nkind
(Stmt
) = N_Pragma
then
29237 and then not Split_PPC
(Stmt
)
29238 and then Original_Aspect_Pragma_Name
(Stmt
) = Prag_Nam
29245 -- Emit an error when a refinement pragma appears on an expression
29246 -- function without a completion.
29249 and then Look_For_Body
29250 and then Nkind
(Stmt
) = N_Subprogram_Declaration
29251 and then Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
29252 and then not Has_Completion
(Defining_Entity
(Stmt
))
29254 Expression_Function_Error
;
29257 -- The refinement pragma applies to a subprogram body stub
29259 elsif Look_For_Body
29260 and then Nkind
(Stmt
) = N_Subprogram_Body_Stub
29264 -- Skip internally generated code
29266 elsif not Comes_From_Source
(Stmt
) then
29268 -- The anonymous object created for a single concurrent type is a
29269 -- suitable context.
29271 if Nkind
(Stmt
) = N_Object_Declaration
29272 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
29276 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
then
29278 -- The subprogram declaration is an internally generated spec
29279 -- for an expression function.
29281 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
29284 -- The subprogram is actually an instance housed within an
29285 -- anonymous wrapper package.
29287 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
29292 -- Return the current construct which is either a subprogram body,
29293 -- a subprogram declaration or is illegal.
29302 -- If we fall through, then the pragma was either the first declaration
29303 -- or it was preceded by other pragmas and no source constructs.
29305 -- The pragma is associated with a library-level subprogram
29307 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
29308 return Unit
(Parent
(Context
));
29310 -- The pragma appears inside the declarations of an entry body
29312 elsif Nkind
(Context
) = N_Entry_Body
then
29315 -- The pragma appears inside the statements of a subprogram body. This
29316 -- placement is the result of subprogram contract expansion.
29318 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
then
29319 return Parent
(Context
);
29321 -- The pragma appears inside the declarative part of a package body
29323 elsif Nkind
(Context
) = N_Package_Body
then
29326 -- The pragma appears inside the declarative part of a subprogram body
29328 elsif Nkind
(Context
) = N_Subprogram_Body
then
29331 -- The pragma appears inside the declarative part of a task body
29333 elsif Nkind
(Context
) = N_Task_Body
then
29336 -- The pragma appears inside the visible part of a package specification
29338 elsif Nkind
(Context
) = N_Package_Specification
then
29339 return Parent
(Context
);
29341 -- The pragma is a byproduct of aspect expansion, return the related
29342 -- context of the original aspect. This case has a lower priority as
29343 -- the above circuitry pinpoints precisely the related context.
29345 elsif Present
(Corresponding_Aspect
(Prag
)) then
29346 return Parent
(Corresponding_Aspect
(Prag
));
29348 -- No candidate subprogram [body] found
29353 end Find_Related_Declaration_Or_Body
;
29355 ----------------------------------
29356 -- Find_Related_Package_Or_Body --
29357 ----------------------------------
29359 function Find_Related_Package_Or_Body
29361 Do_Checks
: Boolean := False) return Node_Id
29363 Context
: constant Node_Id
:= Parent
(Prag
);
29364 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
29368 Stmt
:= Prev
(Prag
);
29369 while Present
(Stmt
) loop
29371 -- Skip prior pragmas, but check for duplicates
29373 if Nkind
(Stmt
) = N_Pragma
then
29374 if Do_Checks
and then Pragma_Name
(Stmt
) = Prag_Nam
then
29380 -- Skip internally generated code
29382 elsif not Comes_From_Source
(Stmt
) then
29383 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
29385 -- The subprogram declaration is an internally generated spec
29386 -- for an expression function.
29388 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
29391 -- The subprogram is actually an instance housed within an
29392 -- anonymous wrapper package.
29394 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
29399 -- Return the current source construct which is illegal
29408 -- If we fall through, then the pragma was either the first declaration
29409 -- or it was preceded by other pragmas and no source constructs.
29411 -- The pragma is associated with a package. The immediate context in
29412 -- this case is the specification of the package.
29414 if Nkind
(Context
) = N_Package_Specification
then
29415 return Parent
(Context
);
29417 -- The pragma appears in the declarations of a package body
29419 elsif Nkind
(Context
) = N_Package_Body
then
29422 -- The pragma appears in the statements of a package body
29424 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
29425 and then Nkind
(Parent
(Context
)) = N_Package_Body
29427 return Parent
(Context
);
29429 -- The pragma is a byproduct of aspect expansion, return the related
29430 -- context of the original aspect. This case has a lower priority as
29431 -- the above circuitry pinpoints precisely the related context.
29433 elsif Present
(Corresponding_Aspect
(Prag
)) then
29434 return Parent
(Corresponding_Aspect
(Prag
));
29436 -- No candidate package [body] found
29441 end Find_Related_Package_Or_Body
;
29447 function Get_Argument
29449 Context_Id
: Entity_Id
:= Empty
) return Node_Id
29451 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
29454 -- Use the expression of the original aspect when compiling for ASIS or
29455 -- when analyzing the template of a generic unit. In both cases the
29456 -- aspect's tree must be decorated to allow for ASIS queries or to save
29457 -- the global references in the generic context.
29459 if From_Aspect_Specification
(Prag
)
29460 and then (ASIS_Mode
or else (Present
(Context_Id
)
29461 and then Is_Generic_Unit
(Context_Id
)))
29463 return Corresponding_Aspect
(Prag
);
29465 -- Otherwise use the expression of the pragma
29467 elsif Present
(Args
) then
29468 return First
(Args
);
29475 -------------------------
29476 -- Get_Base_Subprogram --
29477 -------------------------
29479 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
is
29480 Result
: Entity_Id
;
29483 -- Follow subprogram renaming chain
29487 if Is_Subprogram
(Result
)
29489 Nkind
(Parent
(Declaration_Node
(Result
))) =
29490 N_Subprogram_Renaming_Declaration
29491 and then Present
(Alias
(Result
))
29493 Result
:= Alias
(Result
);
29497 end Get_Base_Subprogram
;
29499 -----------------------
29500 -- Get_SPARK_Mode_Type --
29501 -----------------------
29503 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
is
29505 if N
= Name_On
then
29507 elsif N
= Name_Off
then
29510 -- Any other argument is illegal. Assume that no SPARK mode applies to
29511 -- avoid potential cascaded errors.
29516 end Get_SPARK_Mode_Type
;
29518 ------------------------------------
29519 -- Get_SPARK_Mode_From_Annotation --
29520 ------------------------------------
29522 function Get_SPARK_Mode_From_Annotation
29523 (N
: Node_Id
) return SPARK_Mode_Type
29528 if Nkind
(N
) = N_Aspect_Specification
then
29529 Mode
:= Expression
(N
);
29531 else pragma Assert
(Nkind
(N
) = N_Pragma
);
29532 Mode
:= First
(Pragma_Argument_Associations
(N
));
29534 if Present
(Mode
) then
29535 Mode
:= Get_Pragma_Arg
(Mode
);
29539 -- Aspect or pragma SPARK_Mode specifies an explicit mode
29541 if Present
(Mode
) then
29542 if Nkind
(Mode
) = N_Identifier
then
29543 return Get_SPARK_Mode_Type
(Chars
(Mode
));
29545 -- In case of a malformed aspect or pragma, return the default None
29551 -- Otherwise the lack of an expression defaults SPARK_Mode to On
29556 end Get_SPARK_Mode_From_Annotation
;
29558 ---------------------------
29559 -- Has_Extra_Parentheses --
29560 ---------------------------
29562 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean is
29566 -- The aggregate should not have an expression list because a clause
29567 -- is always interpreted as a component association. The only way an
29568 -- expression list can sneak in is by adding extra parentheses around
29569 -- the individual clauses:
29571 -- Depends (Output => Input) -- proper form
29572 -- Depends ((Output => Input)) -- extra parentheses
29574 -- Since the extra parentheses are not allowed by the syntax of the
29575 -- pragma, flag them now to avoid emitting misleading errors down the
29578 if Nkind
(Clause
) = N_Aggregate
29579 and then Present
(Expressions
(Clause
))
29581 Expr
:= First
(Expressions
(Clause
));
29582 while Present
(Expr
) loop
29584 -- A dependency clause surrounded by extra parentheses appears
29585 -- as an aggregate of component associations with an optional
29586 -- Paren_Count set.
29588 if Nkind
(Expr
) = N_Aggregate
29589 and then Present
(Component_Associations
(Expr
))
29592 ("dependency clause contains extra parentheses", Expr
);
29594 -- Otherwise the expression is a malformed construct
29597 SPARK_Msg_N
("malformed dependency clause", Expr
);
29607 end Has_Extra_Parentheses
;
29613 procedure Initialize
is
29624 Dummy
:= Dummy
+ 1;
29627 -----------------------------
29628 -- Is_Config_Static_String --
29629 -----------------------------
29631 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean is
29633 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean;
29634 -- This is an internal recursive function that is just like the outer
29635 -- function except that it adds the string to the name buffer rather
29636 -- than placing the string in the name buffer.
29638 ------------------------------
29639 -- Add_Config_Static_String --
29640 ------------------------------
29642 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean is
29649 if Nkind
(N
) = N_Op_Concat
then
29650 if Add_Config_Static_String
(Left_Opnd
(N
)) then
29651 N
:= Right_Opnd
(N
);
29657 if Nkind
(N
) /= N_String_Literal
then
29658 Error_Msg_N
("string literal expected for pragma argument", N
);
29662 for J
in 1 .. String_Length
(Strval
(N
)) loop
29663 C
:= Get_String_Char
(Strval
(N
), J
);
29665 if not In_Character_Range
(C
) then
29667 ("string literal contains invalid wide character",
29668 Sloc
(N
) + 1 + Source_Ptr
(J
));
29672 Add_Char_To_Name_Buffer
(Get_Character
(C
));
29677 end Add_Config_Static_String
;
29679 -- Start of processing for Is_Config_Static_String
29684 return Add_Config_Static_String
(Arg
);
29685 end Is_Config_Static_String
;
29687 -------------------------------
29688 -- Is_Elaboration_SPARK_Mode --
29689 -------------------------------
29691 function Is_Elaboration_SPARK_Mode
(N
: Node_Id
) return Boolean is
29694 (Nkind
(N
) = N_Pragma
29695 and then Pragma_Name
(N
) = Name_SPARK_Mode
29696 and then Is_List_Member
(N
));
29698 -- Pragma SPARK_Mode affects the elaboration of a package body when it
29699 -- appears in the statement part of the body.
29702 Present
(Parent
(N
))
29703 and then Nkind
(Parent
(N
)) = N_Handled_Sequence_Of_Statements
29704 and then List_Containing
(N
) = Statements
(Parent
(N
))
29705 and then Present
(Parent
(Parent
(N
)))
29706 and then Nkind
(Parent
(Parent
(N
))) = N_Package_Body
;
29707 end Is_Elaboration_SPARK_Mode
;
29709 -----------------------
29710 -- Is_Enabled_Pragma --
29711 -----------------------
29713 function Is_Enabled_Pragma
(Prag
: Node_Id
) return Boolean is
29717 if Present
(Prag
) then
29718 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
29720 if Present
(Arg
) then
29721 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg
)));
29723 -- The lack of a Boolean argument automatically enables the pragma
29729 -- The pragma is missing, therefore it is not enabled
29734 end Is_Enabled_Pragma
;
29736 -----------------------------------------
29737 -- Is_Non_Significant_Pragma_Reference --
29738 -----------------------------------------
29740 -- This function makes use of the following static table which indicates
29741 -- whether appearance of some name in a given pragma is to be considered
29742 -- as a reference for the purposes of warnings about unreferenced objects.
29744 -- -1 indicates that appearence in any argument is significant
29745 -- 0 indicates that appearance in any argument is not significant
29746 -- +n indicates that appearance as argument n is significant, but all
29747 -- other arguments are not significant
29748 -- 9n arguments from n on are significant, before n insignificant
29750 Sig_Flags
: constant array (Pragma_Id
) of Int
:=
29751 (Pragma_Abort_Defer
=> -1,
29752 Pragma_Abstract_State
=> -1,
29753 Pragma_Ada_83
=> -1,
29754 Pragma_Ada_95
=> -1,
29755 Pragma_Ada_05
=> -1,
29756 Pragma_Ada_2005
=> -1,
29757 Pragma_Ada_12
=> -1,
29758 Pragma_Ada_2012
=> -1,
29759 Pragma_Ada_2020
=> -1,
29760 Pragma_All_Calls_Remote
=> -1,
29761 Pragma_Allow_Integer_Address
=> -1,
29762 Pragma_Annotate
=> 93,
29763 Pragma_Assert
=> -1,
29764 Pragma_Assert_And_Cut
=> -1,
29765 Pragma_Assertion_Policy
=> 0,
29766 Pragma_Assume
=> -1,
29767 Pragma_Assume_No_Invalid_Values
=> 0,
29768 Pragma_Async_Readers
=> 0,
29769 Pragma_Async_Writers
=> 0,
29770 Pragma_Asynchronous
=> 0,
29771 Pragma_Atomic
=> 0,
29772 Pragma_Atomic_Components
=> 0,
29773 Pragma_Attach_Handler
=> -1,
29774 Pragma_Attribute_Definition
=> 92,
29775 Pragma_Check
=> -1,
29776 Pragma_Check_Float_Overflow
=> 0,
29777 Pragma_Check_Name
=> 0,
29778 Pragma_Check_Policy
=> 0,
29779 Pragma_CPP_Class
=> 0,
29780 Pragma_CPP_Constructor
=> 0,
29781 Pragma_CPP_Virtual
=> 0,
29782 Pragma_CPP_Vtable
=> 0,
29784 Pragma_C_Pass_By_Copy
=> 0,
29785 Pragma_Comment
=> -1,
29786 Pragma_Common_Object
=> 0,
29787 Pragma_Compile_Time_Error
=> -1,
29788 Pragma_Compile_Time_Warning
=> -1,
29789 Pragma_Compiler_Unit
=> -1,
29790 Pragma_Compiler_Unit_Warning
=> -1,
29791 Pragma_Complete_Representation
=> 0,
29792 Pragma_Complex_Representation
=> 0,
29793 Pragma_Component_Alignment
=> 0,
29794 Pragma_Constant_After_Elaboration
=> 0,
29795 Pragma_Contract_Cases
=> -1,
29796 Pragma_Controlled
=> 0,
29797 Pragma_Convention
=> 0,
29798 Pragma_Convention_Identifier
=> 0,
29799 Pragma_Deadline_Floor
=> -1,
29800 Pragma_Debug
=> -1,
29801 Pragma_Debug_Policy
=> 0,
29802 Pragma_Detect_Blocking
=> 0,
29803 Pragma_Default_Initial_Condition
=> -1,
29804 Pragma_Default_Scalar_Storage_Order
=> 0,
29805 Pragma_Default_Storage_Pool
=> 0,
29806 Pragma_Depends
=> -1,
29807 Pragma_Disable_Atomic_Synchronization
=> 0,
29808 Pragma_Discard_Names
=> 0,
29809 Pragma_Dispatching_Domain
=> -1,
29810 Pragma_Effective_Reads
=> 0,
29811 Pragma_Effective_Writes
=> 0,
29812 Pragma_Elaborate
=> 0,
29813 Pragma_Elaborate_All
=> 0,
29814 Pragma_Elaborate_Body
=> 0,
29815 Pragma_Elaboration_Checks
=> 0,
29816 Pragma_Eliminate
=> 0,
29817 Pragma_Enable_Atomic_Synchronization
=> 0,
29818 Pragma_Export
=> -1,
29819 Pragma_Export_Function
=> -1,
29820 Pragma_Export_Object
=> -1,
29821 Pragma_Export_Procedure
=> -1,
29822 Pragma_Export_Value
=> -1,
29823 Pragma_Export_Valued_Procedure
=> -1,
29824 Pragma_Extend_System
=> -1,
29825 Pragma_Extensions_Allowed
=> 0,
29826 Pragma_Extensions_Visible
=> 0,
29827 Pragma_External
=> -1,
29828 Pragma_Favor_Top_Level
=> 0,
29829 Pragma_External_Name_Casing
=> 0,
29830 Pragma_Fast_Math
=> 0,
29831 Pragma_Finalize_Storage_Only
=> 0,
29833 Pragma_Global
=> -1,
29834 Pragma_Ident
=> -1,
29835 Pragma_Ignore_Pragma
=> 0,
29836 Pragma_Implementation_Defined
=> -1,
29837 Pragma_Implemented
=> -1,
29838 Pragma_Implicit_Packing
=> 0,
29839 Pragma_Import
=> 93,
29840 Pragma_Import_Function
=> 0,
29841 Pragma_Import_Object
=> 0,
29842 Pragma_Import_Procedure
=> 0,
29843 Pragma_Import_Valued_Procedure
=> 0,
29844 Pragma_Independent
=> 0,
29845 Pragma_Independent_Components
=> 0,
29846 Pragma_Initial_Condition
=> -1,
29847 Pragma_Initialize_Scalars
=> 0,
29848 Pragma_Initializes
=> -1,
29849 Pragma_Inline
=> 0,
29850 Pragma_Inline_Always
=> 0,
29851 Pragma_Inline_Generic
=> 0,
29852 Pragma_Inspection_Point
=> -1,
29853 Pragma_Interface
=> 92,
29854 Pragma_Interface_Name
=> 0,
29855 Pragma_Interrupt_Handler
=> -1,
29856 Pragma_Interrupt_Priority
=> -1,
29857 Pragma_Interrupt_State
=> -1,
29858 Pragma_Invariant
=> -1,
29859 Pragma_Keep_Names
=> 0,
29860 Pragma_License
=> 0,
29861 Pragma_Link_With
=> -1,
29862 Pragma_Linker_Alias
=> -1,
29863 Pragma_Linker_Constructor
=> -1,
29864 Pragma_Linker_Destructor
=> -1,
29865 Pragma_Linker_Options
=> -1,
29866 Pragma_Linker_Section
=> -1,
29868 Pragma_Lock_Free
=> 0,
29869 Pragma_Locking_Policy
=> 0,
29870 Pragma_Loop_Invariant
=> -1,
29871 Pragma_Loop_Optimize
=> 0,
29872 Pragma_Loop_Variant
=> -1,
29873 Pragma_Machine_Attribute
=> -1,
29875 Pragma_Main_Storage
=> -1,
29876 Pragma_Max_Queue_Length
=> 0,
29877 Pragma_Memory_Size
=> 0,
29878 Pragma_No_Return
=> 0,
29879 Pragma_No_Body
=> 0,
29880 Pragma_No_Component_Reordering
=> -1,
29881 Pragma_No_Elaboration_Code_All
=> 0,
29882 Pragma_No_Heap_Finalization
=> 0,
29883 Pragma_No_Inline
=> 0,
29884 Pragma_No_Run_Time
=> -1,
29885 Pragma_No_Strict_Aliasing
=> -1,
29886 Pragma_No_Tagged_Streams
=> 0,
29887 Pragma_Normalize_Scalars
=> 0,
29888 Pragma_Obsolescent
=> 0,
29889 Pragma_Optimize
=> 0,
29890 Pragma_Optimize_Alignment
=> 0,
29891 Pragma_Overflow_Mode
=> 0,
29892 Pragma_Overriding_Renamings
=> 0,
29893 Pragma_Ordered
=> 0,
29896 Pragma_Part_Of
=> 0,
29897 Pragma_Partition_Elaboration_Policy
=> 0,
29898 Pragma_Passive
=> 0,
29899 Pragma_Persistent_BSS
=> 0,
29900 Pragma_Polling
=> 0,
29901 Pragma_Prefix_Exception_Messages
=> 0,
29903 Pragma_Postcondition
=> -1,
29904 Pragma_Post_Class
=> -1,
29906 Pragma_Precondition
=> -1,
29907 Pragma_Predicate
=> -1,
29908 Pragma_Predicate_Failure
=> -1,
29909 Pragma_Preelaborable_Initialization
=> -1,
29910 Pragma_Preelaborate
=> 0,
29911 Pragma_Pre_Class
=> -1,
29912 Pragma_Priority
=> -1,
29913 Pragma_Priority_Specific_Dispatching
=> 0,
29914 Pragma_Profile
=> 0,
29915 Pragma_Profile_Warnings
=> 0,
29916 Pragma_Propagate_Exceptions
=> 0,
29917 Pragma_Provide_Shift_Operators
=> 0,
29918 Pragma_Psect_Object
=> 0,
29920 Pragma_Pure_Function
=> 0,
29921 Pragma_Queuing_Policy
=> 0,
29922 Pragma_Rational
=> 0,
29923 Pragma_Ravenscar
=> 0,
29924 Pragma_Refined_Depends
=> -1,
29925 Pragma_Refined_Global
=> -1,
29926 Pragma_Refined_Post
=> -1,
29927 Pragma_Refined_State
=> -1,
29928 Pragma_Relative_Deadline
=> 0,
29929 Pragma_Rename_Pragma
=> 0,
29930 Pragma_Remote_Access_Type
=> -1,
29931 Pragma_Remote_Call_Interface
=> -1,
29932 Pragma_Remote_Types
=> -1,
29933 Pragma_Restricted_Run_Time
=> 0,
29934 Pragma_Restriction_Warnings
=> 0,
29935 Pragma_Restrictions
=> 0,
29936 Pragma_Reviewable
=> -1,
29937 Pragma_Secondary_Stack_Size
=> -1,
29938 Pragma_Short_Circuit_And_Or
=> 0,
29939 Pragma_Share_Generic
=> 0,
29940 Pragma_Shared
=> 0,
29941 Pragma_Shared_Passive
=> 0,
29942 Pragma_Short_Descriptors
=> 0,
29943 Pragma_Simple_Storage_Pool_Type
=> 0,
29944 Pragma_Source_File_Name
=> 0,
29945 Pragma_Source_File_Name_Project
=> 0,
29946 Pragma_Source_Reference
=> 0,
29947 Pragma_SPARK_Mode
=> 0,
29948 Pragma_Storage_Size
=> -1,
29949 Pragma_Storage_Unit
=> 0,
29950 Pragma_Static_Elaboration_Desired
=> 0,
29951 Pragma_Stream_Convert
=> 0,
29952 Pragma_Style_Checks
=> 0,
29953 Pragma_Subtitle
=> 0,
29954 Pragma_Suppress
=> 0,
29955 Pragma_Suppress_Exception_Locations
=> 0,
29956 Pragma_Suppress_All
=> 0,
29957 Pragma_Suppress_Debug_Info
=> 0,
29958 Pragma_Suppress_Initialization
=> 0,
29959 Pragma_System_Name
=> 0,
29960 Pragma_Task_Dispatching_Policy
=> 0,
29961 Pragma_Task_Info
=> -1,
29962 Pragma_Task_Name
=> -1,
29963 Pragma_Task_Storage
=> -1,
29964 Pragma_Test_Case
=> -1,
29965 Pragma_Thread_Local_Storage
=> -1,
29966 Pragma_Time_Slice
=> -1,
29968 Pragma_Type_Invariant
=> -1,
29969 Pragma_Type_Invariant_Class
=> -1,
29970 Pragma_Unchecked_Union
=> 0,
29971 Pragma_Unevaluated_Use_Of_Old
=> 0,
29972 Pragma_Unimplemented_Unit
=> 0,
29973 Pragma_Universal_Aliasing
=> 0,
29974 Pragma_Universal_Data
=> 0,
29975 Pragma_Unmodified
=> 0,
29976 Pragma_Unreferenced
=> 0,
29977 Pragma_Unreferenced_Objects
=> 0,
29978 Pragma_Unreserve_All_Interrupts
=> 0,
29979 Pragma_Unsuppress
=> 0,
29980 Pragma_Unused
=> 0,
29981 Pragma_Use_VADS_Size
=> 0,
29982 Pragma_Validity_Checks
=> 0,
29983 Pragma_Volatile
=> 0,
29984 Pragma_Volatile_Components
=> 0,
29985 Pragma_Volatile_Full_Access
=> 0,
29986 Pragma_Volatile_Function
=> 0,
29987 Pragma_Warning_As_Error
=> 0,
29988 Pragma_Warnings
=> 0,
29989 Pragma_Weak_External
=> 0,
29990 Pragma_Wide_Character_Encoding
=> 0,
29991 Unknown_Pragma
=> 0);
29993 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean is
29999 function Arg_No
return Nat
;
30000 -- Returns an integer showing what argument we are in. A value of
30001 -- zero means we are not in any of the arguments.
30007 function Arg_No
return Nat
is
30012 A
:= First
(Pragma_Argument_Associations
(Parent
(P
)));
30026 -- Start of processing for Non_Significant_Pragma_Reference
30031 if Nkind
(P
) /= N_Pragma_Argument_Association
then
30035 Id
:= Get_Pragma_Id
(Parent
(P
));
30036 C
:= Sig_Flags
(Id
);
30051 return AN
< (C
- 90);
30057 end Is_Non_Significant_Pragma_Reference
;
30059 ------------------------------
30060 -- Is_Pragma_String_Literal --
30061 ------------------------------
30063 -- This function returns true if the corresponding pragma argument is a
30064 -- static string expression. These are the only cases in which string
30065 -- literals can appear as pragma arguments. We also allow a string literal
30066 -- as the first argument to pragma Assert (although it will of course
30067 -- always generate a type error).
30069 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean is
30070 Pragn
: constant Node_Id
:= Parent
(Par
);
30071 Assoc
: constant List_Id
:= Pragma_Argument_Associations
(Pragn
);
30072 Pname
: constant Name_Id
:= Pragma_Name
(Pragn
);
30078 N
:= First
(Assoc
);
30085 if Pname
= Name_Assert
then
30088 elsif Pname
= Name_Export
then
30091 elsif Pname
= Name_Ident
then
30094 elsif Pname
= Name_Import
then
30097 elsif Pname
= Name_Interface_Name
then
30100 elsif Pname
= Name_Linker_Alias
then
30103 elsif Pname
= Name_Linker_Section
then
30106 elsif Pname
= Name_Machine_Attribute
then
30109 elsif Pname
= Name_Source_File_Name
then
30112 elsif Pname
= Name_Source_Reference
then
30115 elsif Pname
= Name_Title
then
30118 elsif Pname
= Name_Subtitle
then
30124 end Is_Pragma_String_Literal
;
30126 ---------------------------
30127 -- Is_Private_SPARK_Mode --
30128 ---------------------------
30130 function Is_Private_SPARK_Mode
(N
: Node_Id
) return Boolean is
30133 (Nkind
(N
) = N_Pragma
30134 and then Pragma_Name
(N
) = Name_SPARK_Mode
30135 and then Is_List_Member
(N
));
30137 -- For pragma SPARK_Mode to be private, it has to appear in the private
30138 -- declarations of a package.
30141 Present
(Parent
(N
))
30142 and then Nkind
(Parent
(N
)) = N_Package_Specification
30143 and then List_Containing
(N
) = Private_Declarations
(Parent
(N
));
30144 end Is_Private_SPARK_Mode
;
30146 -------------------------------------
30147 -- Is_Unconstrained_Or_Tagged_Item --
30148 -------------------------------------
30150 function Is_Unconstrained_Or_Tagged_Item
30151 (Item
: Entity_Id
) return Boolean
30153 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean;
30154 -- Determine whether record type Typ has at least one unconstrained
30157 ---------------------------------
30158 -- Has_Unconstrained_Component --
30159 ---------------------------------
30161 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean is
30165 Comp
:= First_Component
(Typ
);
30166 while Present
(Comp
) loop
30167 if Is_Unconstrained_Or_Tagged_Item
(Comp
) then
30171 Next_Component
(Comp
);
30175 end Has_Unconstrained_Component
;
30179 Typ
: constant Entity_Id
:= Etype
(Item
);
30181 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
30184 if Is_Tagged_Type
(Typ
) then
30187 elsif Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
30190 elsif Is_Record_Type
(Typ
) then
30191 if Has_Discriminants
(Typ
) and then not Is_Constrained
(Typ
) then
30194 return Has_Unconstrained_Component
(Typ
);
30197 elsif Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
) then
30203 end Is_Unconstrained_Or_Tagged_Item
;
30205 -----------------------------
30206 -- Is_Valid_Assertion_Kind --
30207 -----------------------------
30209 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean is
30216 | Name_Assertion_Policy
30217 | Name_Static_Predicate
30218 | Name_Dynamic_Predicate
30223 | Name_Type_Invariant
30224 | Name_uType_Invariant
30228 | Name_Assert_And_Cut
30230 | Name_Contract_Cases
30232 | Name_Default_Initial_Condition
30234 | Name_Initial_Condition
30237 | Name_Loop_Invariant
30238 | Name_Loop_Variant
30239 | Name_Postcondition
30240 | Name_Precondition
30242 | Name_Refined_Post
30243 | Name_Statement_Assertions
30250 end Is_Valid_Assertion_Kind
;
30252 --------------------------------------
30253 -- Process_Compilation_Unit_Pragmas --
30254 --------------------------------------
30256 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
) is
30258 -- A special check for pragma Suppress_All, a very strange DEC pragma,
30259 -- strange because it comes at the end of the unit. Rational has the
30260 -- same name for a pragma, but treats it as a program unit pragma, In
30261 -- GNAT we just decide to allow it anywhere at all. If it appeared then
30262 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
30263 -- node, and we insert a pragma Suppress (All_Checks) at the start of
30264 -- the context clause to ensure the correct processing.
30266 if Has_Pragma_Suppress_All
(N
) then
30267 Prepend_To
(Context_Items
(N
),
30268 Make_Pragma
(Sloc
(N
),
30269 Chars
=> Name_Suppress
,
30270 Pragma_Argument_Associations
=> New_List
(
30271 Make_Pragma_Argument_Association
(Sloc
(N
),
30272 Expression
=> Make_Identifier
(Sloc
(N
), Name_All_Checks
)))));
30275 -- Nothing else to do at the current time
30277 end Process_Compilation_Unit_Pragmas
;
30279 -------------------------------------------
30280 -- Process_Compile_Time_Warning_Or_Error --
30281 -------------------------------------------
30283 procedure Process_Compile_Time_Warning_Or_Error
30287 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
30288 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
30289 Arg2
: constant Node_Id
:= Next
(Arg1
);
30292 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
30294 if Compile_Time_Known_Value
(Arg1x
) then
30295 if Is_True
(Expr_Value
(Arg1x
)) then
30297 Cent
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
30298 Pname
: constant Name_Id
:= Pragma_Name_Unmapped
(N
);
30299 Prag_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Pname
);
30300 Str
: constant String_Id
:= Strval
(Get_Pragma_Arg
(Arg2
));
30301 Str_Len
: constant Nat
:= String_Length
(Str
);
30303 Force
: constant Boolean :=
30304 Prag_Id
= Pragma_Compile_Time_Warning
30305 and then Is_Spec_Name
(Unit_Name
(Current_Sem_Unit
))
30306 and then (Ekind
(Cent
) /= E_Package
30307 or else not In_Private_Part
(Cent
));
30308 -- Set True if this is the warning case, and we are in the
30309 -- visible part of a package spec, or in a subprogram spec,
30310 -- in which case we want to force the client to see the
30311 -- warning, even though it is not in the main unit.
30319 -- Loop through segments of message separated by line feeds.
30320 -- We output these segments as separate messages with
30321 -- continuation marks for all but the first.
30326 Error_Msg_Strlen
:= 0;
30328 -- Loop to copy characters from argument to error message
30332 exit when Ptr
> Str_Len
;
30333 CC
:= Get_String_Char
(Str
, Ptr
);
30336 -- Ignore wide chars ??? else store character
30338 if In_Character_Range
(CC
) then
30339 C
:= Get_Character
(CC
);
30340 exit when C
= ASCII
.LF
;
30341 Error_Msg_Strlen
:= Error_Msg_Strlen
+ 1;
30342 Error_Msg_String
(Error_Msg_Strlen
) := C
;
30346 -- Here with one line ready to go
30348 Error_Msg_Warn
:= Prag_Id
= Pragma_Compile_Time_Warning
;
30350 -- If this is a warning in a spec, then we want clients
30351 -- to see the warning, so mark the message with the
30352 -- special sequence !! to force the warning. In the case
30353 -- of a package spec, we do not force this if we are in
30354 -- the private part of the spec.
30357 if Cont
= False then
30358 Error_Msg
("<<~!!", Eloc
);
30361 Error_Msg
("\<<~!!", Eloc
);
30364 -- Error, rather than warning, or in a body, so we do not
30365 -- need to force visibility for client (error will be
30366 -- output in any case, and this is the situation in which
30367 -- we do not want a client to get a warning, since the
30368 -- warning is in the body or the spec private part).
30371 if Cont
= False then
30372 Error_Msg
("<<~", Eloc
);
30375 Error_Msg
("\<<~", Eloc
);
30379 exit when Ptr
> Str_Len
;
30384 end Process_Compile_Time_Warning_Or_Error
;
30386 ------------------------------------
30387 -- Record_Possible_Body_Reference --
30388 ------------------------------------
30390 procedure Record_Possible_Body_Reference
30391 (State_Id
: Entity_Id
;
30395 Spec_Id
: Entity_Id
;
30398 -- Ensure that we are dealing with a reference to a state
30400 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
30402 -- Climb the tree starting from the reference looking for a package body
30403 -- whose spec declares the referenced state. This criteria automatically
30404 -- excludes references in package specs which are legal. Note that it is
30405 -- not wise to emit an error now as the package body may lack pragma
30406 -- Refined_State or the referenced state may not be mentioned in the
30407 -- refinement. This approach avoids the generation of misleading errors.
30410 while Present
(Context
) loop
30411 if Nkind
(Context
) = N_Package_Body
then
30412 Spec_Id
:= Corresponding_Spec
(Context
);
30414 if Present
(Abstract_States
(Spec_Id
))
30415 and then Contains
(Abstract_States
(Spec_Id
), State_Id
)
30417 if No
(Body_References
(State_Id
)) then
30418 Set_Body_References
(State_Id
, New_Elmt_List
);
30421 Append_Elmt
(Ref
, To
=> Body_References
(State_Id
));
30426 Context
:= Parent
(Context
);
30428 end Record_Possible_Body_Reference
;
30430 ------------------------------------------
30431 -- Relocate_Pragmas_To_Anonymous_Object --
30432 ------------------------------------------
30434 procedure Relocate_Pragmas_To_Anonymous_Object
30435 (Typ_Decl
: Node_Id
;
30436 Obj_Decl
: Node_Id
)
30440 Next_Decl
: Node_Id
;
30443 if Nkind
(Typ_Decl
) = N_Protected_Type_Declaration
then
30444 Def
:= Protected_Definition
(Typ_Decl
);
30446 pragma Assert
(Nkind
(Typ_Decl
) = N_Task_Type_Declaration
);
30447 Def
:= Task_Definition
(Typ_Decl
);
30450 -- The concurrent definition has a visible declaration list. Inspect it
30451 -- and relocate all canidate pragmas.
30453 if Present
(Def
) and then Present
(Visible_Declarations
(Def
)) then
30454 Decl
:= First
(Visible_Declarations
(Def
));
30455 while Present
(Decl
) loop
30457 -- Preserve the following declaration for iteration purposes due
30458 -- to possible relocation of a pragma.
30460 Next_Decl
:= Next
(Decl
);
30462 if Nkind
(Decl
) = N_Pragma
30463 and then Pragma_On_Anonymous_Object_OK
(Get_Pragma_Id
(Decl
))
30466 Insert_After
(Obj_Decl
, Decl
);
30468 -- Skip internally generated code
30470 elsif not Comes_From_Source
(Decl
) then
30473 -- No candidate pragmas are available for relocation
30482 end Relocate_Pragmas_To_Anonymous_Object
;
30484 ------------------------------
30485 -- Relocate_Pragmas_To_Body --
30486 ------------------------------
30488 procedure Relocate_Pragmas_To_Body
30489 (Subp_Body
: Node_Id
;
30490 Target_Body
: Node_Id
:= Empty
)
30492 procedure Relocate_Pragma
(Prag
: Node_Id
);
30493 -- Remove a single pragma from its current list and add it to the
30494 -- declarations of the proper body (either Subp_Body or Target_Body).
30496 ---------------------
30497 -- Relocate_Pragma --
30498 ---------------------
30500 procedure Relocate_Pragma
(Prag
: Node_Id
) is
30505 -- When subprogram stubs or expression functions are involves, the
30506 -- destination declaration list belongs to the proper body.
30508 if Present
(Target_Body
) then
30509 Target
:= Target_Body
;
30511 Target
:= Subp_Body
;
30514 Decls
:= Declarations
(Target
);
30518 Set_Declarations
(Target
, Decls
);
30521 -- Unhook the pragma from its current list
30524 Prepend
(Prag
, Decls
);
30525 end Relocate_Pragma
;
30529 Body_Id
: constant Entity_Id
:=
30530 Defining_Unit_Name
(Specification
(Subp_Body
));
30531 Next_Stmt
: Node_Id
;
30534 -- Start of processing for Relocate_Pragmas_To_Body
30537 -- Do not process a body that comes from a separate unit as no construct
30538 -- can possibly follow it.
30540 if not Is_List_Member
(Subp_Body
) then
30543 -- Do not relocate pragmas that follow a stub if the stub does not have
30546 elsif Nkind
(Subp_Body
) = N_Subprogram_Body_Stub
30547 and then No
(Target_Body
)
30551 -- Do not process internally generated routine _Postconditions
30553 elsif Ekind
(Body_Id
) = E_Procedure
30554 and then Chars
(Body_Id
) = Name_uPostconditions
30559 -- Look at what is following the body. We are interested in certain kind
30560 -- of pragmas (either from source or byproducts of expansion) that can
30561 -- apply to a body [stub].
30563 Stmt
:= Next
(Subp_Body
);
30564 while Present
(Stmt
) loop
30566 -- Preserve the following statement for iteration purposes due to a
30567 -- possible relocation of a pragma.
30569 Next_Stmt
:= Next
(Stmt
);
30571 -- Move a candidate pragma following the body to the declarations of
30574 if Nkind
(Stmt
) = N_Pragma
30575 and then Pragma_On_Body_Or_Stub_OK
(Get_Pragma_Id
(Stmt
))
30578 -- If a source pragma Warnings follows the body, it applies to
30579 -- following statements and does not belong in the body.
30581 if Get_Pragma_Id
(Stmt
) = Pragma_Warnings
30582 and then Comes_From_Source
(Stmt
)
30586 Relocate_Pragma
(Stmt
);
30589 -- Skip internally generated code
30591 elsif not Comes_From_Source
(Stmt
) then
30594 -- No candidate pragmas are available for relocation
30602 end Relocate_Pragmas_To_Body
;
30604 -------------------
30605 -- Resolve_State --
30606 -------------------
30608 procedure Resolve_State
(N
: Node_Id
) is
30613 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
30614 Func
:= Entity
(N
);
30616 -- Handle overloading of state names by functions. Traverse the
30617 -- homonym chain looking for an abstract state.
30619 if Ekind
(Func
) = E_Function
and then Has_Homonym
(Func
) then
30620 pragma Assert
(Is_Overloaded
(N
));
30622 State
:= Homonym
(Func
);
30623 while Present
(State
) loop
30624 if Ekind
(State
) = E_Abstract_State
then
30626 -- Resolve the overloading by setting the proper entity of
30627 -- the reference to that of the state.
30629 Set_Etype
(N
, Standard_Void_Type
);
30630 Set_Entity
(N
, State
);
30631 Set_Is_Overloaded
(N
, False);
30633 Generate_Reference
(State
, N
);
30637 State
:= Homonym
(State
);
30640 -- A function can never act as a state. If the homonym chain does
30641 -- not contain a corresponding state, then something went wrong in
30642 -- the overloading mechanism.
30644 raise Program_Error
;
30649 ----------------------------
30650 -- Rewrite_Assertion_Kind --
30651 ----------------------------
30653 procedure Rewrite_Assertion_Kind
30655 From_Policy
: Boolean := False)
30661 if Nkind
(N
) = N_Attribute_Reference
30662 and then Attribute_Name
(N
) = Name_Class
30663 and then Nkind
(Prefix
(N
)) = N_Identifier
30665 case Chars
(Prefix
(N
)) is
30672 when Name_Type_Invariant
=>
30673 Nam
:= Name_uType_Invariant
;
30675 when Name_Invariant
=>
30676 Nam
:= Name_uInvariant
;
30682 -- Recommend standard use of aspect names Pre/Post
30684 elsif Nkind
(N
) = N_Identifier
30685 and then From_Policy
30686 and then Serious_Errors_Detected
= 0
30687 and then not ASIS_Mode
30689 if Chars
(N
) = Name_Precondition
30690 or else Chars
(N
) = Name_Postcondition
30692 Error_Msg_N
("Check_Policy is a non-standard pragma??", N
);
30694 ("\use Assertion_Policy and aspect names Pre/Post for "
30695 & "Ada2012 conformance?", N
);
30701 if Nam
/= No_Name
then
30702 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
=> Nam
));
30704 end Rewrite_Assertion_Kind
;
30712 Dummy
:= Dummy
+ 1;
30715 --------------------------------
30716 -- Set_Encoded_Interface_Name --
30717 --------------------------------
30719 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
) is
30720 Str
: constant String_Id
:= Strval
(S
);
30721 Len
: constant Nat
:= String_Length
(Str
);
30726 Hex
: constant array (0 .. 15) of Character := "0123456789abcdef";
30729 -- Stores encoded value of character code CC. The encoding we use an
30730 -- underscore followed by four lower case hex digits.
30736 procedure Encode
is
30738 Store_String_Char
(Get_Char_Code
('_'));
30740 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 12))));
30742 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 8 and 16#
0F#
))));
30744 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 4 and 16#
0F#
))));
30746 (Get_Char_Code
(Hex
(Integer (CC
and 16#
0F#
))));
30749 -- Start of processing for Set_Encoded_Interface_Name
30752 -- If first character is asterisk, this is a link name, and we leave it
30753 -- completely unmodified. We also ignore null strings (the latter case
30754 -- happens only in error cases).
30757 or else Get_String_Char
(Str
, 1) = Get_Char_Code
('*')
30759 Set_Interface_Name
(E
, S
);
30764 CC
:= Get_String_Char
(Str
, J
);
30766 exit when not In_Character_Range
(CC
);
30768 C
:= Get_Character
(CC
);
30770 exit when C
/= '_' and then C
/= '$'
30771 and then C
not in '0' .. '9'
30772 and then C
not in 'a' .. 'z'
30773 and then C
not in 'A' .. 'Z';
30776 Set_Interface_Name
(E
, S
);
30784 -- Here we need to encode. The encoding we use as follows:
30785 -- three underscores + four hex digits (lower case)
30789 for J
in 1 .. String_Length
(Str
) loop
30790 CC
:= Get_String_Char
(Str
, J
);
30792 if not In_Character_Range
(CC
) then
30795 C
:= Get_Character
(CC
);
30797 if C
= '_' or else C
= '$'
30798 or else C
in '0' .. '9'
30799 or else C
in 'a' .. 'z'
30800 or else C
in 'A' .. 'Z'
30802 Store_String_Char
(CC
);
30809 Set_Interface_Name
(E
,
30810 Make_String_Literal
(Sloc
(S
),
30811 Strval
=> End_String
));
30813 end Set_Encoded_Interface_Name
;
30815 ------------------------
30816 -- Set_Elab_Unit_Name --
30817 ------------------------
30819 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
) is
30824 if Nkind
(N
) = N_Identifier
30825 and then Nkind
(With_Item
) = N_Identifier
30827 Set_Entity
(N
, Entity
(With_Item
));
30829 elsif Nkind
(N
) = N_Selected_Component
then
30830 Change_Selected_Component_To_Expanded_Name
(N
);
30831 Set_Entity
(N
, Entity
(With_Item
));
30832 Set_Entity
(Selector_Name
(N
), Entity
(N
));
30834 Pref
:= Prefix
(N
);
30835 Scop
:= Scope
(Entity
(N
));
30836 while Nkind
(Pref
) = N_Selected_Component
loop
30837 Change_Selected_Component_To_Expanded_Name
(Pref
);
30838 Set_Entity
(Selector_Name
(Pref
), Scop
);
30839 Set_Entity
(Pref
, Scop
);
30840 Pref
:= Prefix
(Pref
);
30841 Scop
:= Scope
(Scop
);
30844 Set_Entity
(Pref
, Scop
);
30847 Generate_Reference
(Entity
(With_Item
), N
, Set_Ref
=> False);
30848 end Set_Elab_Unit_Name
;
30850 -------------------
30851 -- Test_Case_Arg --
30852 -------------------
30854 function Test_Case_Arg
30857 From_Aspect
: Boolean := False) return Node_Id
30859 Aspect
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
30864 pragma Assert
(Nam_In
(Arg_Nam
, Name_Ensures
,
30869 -- The caller requests the aspect argument
30871 if From_Aspect
then
30872 if Present
(Aspect
)
30873 and then Nkind
(Expression
(Aspect
)) = N_Aggregate
30875 Args
:= Expression
(Aspect
);
30877 -- "Name" and "Mode" may appear without an identifier as a
30878 -- positional association.
30880 if Present
(Expressions
(Args
)) then
30881 Arg
:= First
(Expressions
(Args
));
30883 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
30891 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
30896 -- Some or all arguments may appear as component associatons
30898 if Present
(Component_Associations
(Args
)) then
30899 Arg
:= First
(Component_Associations
(Args
));
30900 while Present
(Arg
) loop
30901 if Chars
(First
(Choices
(Arg
))) = Arg_Nam
then
30910 -- Otherwise retrieve the argument directly from the pragma
30913 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
30915 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
30919 -- Skip argument "Name"
30923 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
30927 -- Skip argument "Mode"
30931 -- Arguments "Requires" and "Ensures" are optional and may not be
30934 while Present
(Arg
) loop
30935 if Chars
(Arg
) = Arg_Nam
then