1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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
;
47 with Lib
.Writ
; use Lib
.Writ
;
48 with Lib
.Xref
; use Lib
.Xref
;
49 with Namet
.Sp
; use Namet
.Sp
;
50 with Nlists
; use Nlists
;
51 with Nmake
; use Nmake
;
52 with Output
; use Output
;
53 with Par_SCO
; use Par_SCO
;
54 with Restrict
; use Restrict
;
55 with Rident
; use Rident
;
56 with Rtsfind
; use Rtsfind
;
58 with Sem_Aux
; use Sem_Aux
;
59 with Sem_Ch3
; use Sem_Ch3
;
60 with Sem_Ch6
; use Sem_Ch6
;
61 with Sem_Ch8
; use Sem_Ch8
;
62 with Sem_Ch12
; use Sem_Ch12
;
63 with Sem_Ch13
; use Sem_Ch13
;
64 with Sem_Disp
; use Sem_Disp
;
65 with Sem_Dist
; use Sem_Dist
;
66 with Sem_Elim
; use Sem_Elim
;
67 with Sem_Eval
; use Sem_Eval
;
68 with Sem_Intr
; use Sem_Intr
;
69 with Sem_Mech
; use Sem_Mech
;
70 with Sem_Res
; use Sem_Res
;
71 with Sem_Type
; use Sem_Type
;
72 with Sem_Util
; use Sem_Util
;
73 with Sem_Warn
; use Sem_Warn
;
74 with Stand
; use Stand
;
75 with Sinfo
; use Sinfo
;
76 with Sinfo
.CN
; use Sinfo
.CN
;
77 with Sinput
; use Sinput
;
78 with Stringt
; use Stringt
;
79 with Stylesw
; use Stylesw
;
81 with Targparm
; use Targparm
;
82 with Tbuild
; use Tbuild
;
84 with Uintp
; use Uintp
;
85 with Uname
; use Uname
;
86 with Urealp
; use Urealp
;
87 with Validsw
; use Validsw
;
88 with Warnsw
; use Warnsw
;
90 package body Sem_Prag
is
92 ----------------------------------------------
93 -- Common Handling of Import-Export Pragmas --
94 ----------------------------------------------
96 -- In the following section, a number of Import_xxx and Export_xxx pragmas
97 -- are defined by GNAT. These are compatible with the DEC pragmas of the
98 -- same name, and all have the following common form and processing:
101 -- [Internal =>] LOCAL_NAME
102 -- [, [External =>] EXTERNAL_SYMBOL]
103 -- [, other optional parameters ]);
106 -- [Internal =>] LOCAL_NAME
107 -- [, [External =>] EXTERNAL_SYMBOL]
108 -- [, other optional parameters ]);
110 -- EXTERNAL_SYMBOL ::=
112 -- | static_string_EXPRESSION
114 -- The internal LOCAL_NAME designates the entity that is imported or
115 -- exported, and must refer to an entity in the current declarative
116 -- part (as required by the rules for LOCAL_NAME).
118 -- The external linker name is designated by the External parameter if
119 -- given, or the Internal parameter if not (if there is no External
120 -- parameter, the External parameter is a copy of the Internal name).
122 -- If the External parameter is given as a string, then this string is
123 -- treated as an external name (exactly as though it had been given as an
124 -- External_Name parameter for a normal Import pragma).
126 -- If the External parameter is given as an identifier (or there is no
127 -- External parameter, so that the Internal identifier is used), then
128 -- the external name is the characters of the identifier, translated
129 -- to all lower case letters.
131 -- Note: the external name specified or implied by any of these special
132 -- Import_xxx or Export_xxx pragmas override an external or link name
133 -- specified in a previous Import or Export pragma.
135 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
136 -- named notation, following the standard rules for subprogram calls, i.e.
137 -- parameters can be given in any order if named notation is used, and
138 -- positional and named notation can be mixed, subject to the rule that all
139 -- positional parameters must appear first.
141 -- Note: All these pragmas are implemented exactly following the DEC design
142 -- and implementation and are intended to be fully compatible with the use
143 -- of these pragmas in the DEC Ada compiler.
145 --------------------------------------------
146 -- Checking for Duplicated External Names --
147 --------------------------------------------
149 -- It is suspicious if two separate Export pragmas use the same external
150 -- name. The following table is used to diagnose this situation so that
151 -- an appropriate warning can be issued.
153 -- The Node_Id stored is for the N_String_Literal node created to hold
154 -- the value of the external name. The Sloc of this node is used to
155 -- cross-reference the location of the duplication.
157 package Externals
is new Table
.Table
(
158 Table_Component_Type
=> Node_Id
,
159 Table_Index_Type
=> Int
,
160 Table_Low_Bound
=> 0,
161 Table_Initial
=> 100,
162 Table_Increment
=> 100,
163 Table_Name
=> "Name_Externals");
165 -------------------------------------
166 -- Local Subprograms and Variables --
167 -------------------------------------
169 function Adjust_External_Name_Case
(N
: Node_Id
) return Node_Id
;
170 -- This routine is used for possible casing adjustment of an explicit
171 -- external name supplied as a string literal (the node N), according to
172 -- the casing requirement of Opt.External_Name_Casing. If this is set to
173 -- As_Is, then the string literal is returned unchanged, but if it is set
174 -- to Uppercase or Lowercase, then a new string literal with appropriate
175 -- casing is constructed.
177 procedure Analyze_Part_Of
181 Encap_Id
: out Entity_Id
;
182 Legal
: out Boolean);
183 -- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and
184 -- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the
185 -- Part_Of indicator. Item_Id is the entity of an abstract state, object or
186 -- package instantiation. Encap denotes the encapsulating state or single
187 -- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when
188 -- the indicator is legal.
190 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean;
191 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
192 -- Query whether a particular item appears in a mixed list of nodes and
193 -- entities. It is assumed that all nodes in the list have entities.
195 procedure Check_Postcondition_Use_In_Inlined_Subprogram
197 Spec_Id
: Entity_Id
);
198 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
199 -- Precondition, Refined_Post and Test_Case. Emit a warning when pragma
200 -- Prag is associated with subprogram Spec_Id subject to Inline_Always.
202 procedure Check_State_And_Constituent_Use
206 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
207 -- Global and Initializes. Determine whether a state from list States and a
208 -- corresponding constituent from list Constits (if any) appear in the same
209 -- context denoted by Context. If this is the case, emit an error.
211 procedure Contract_Freeze_Error
212 (Contract_Id
: Entity_Id
;
213 Freeze_Id
: Entity_Id
);
214 -- Subsidiary to the analysis of pragmas Contract_Cases, Part_Of, Post, and
215 -- Pre. Emit a freezing-related error message where Freeze_Id is the entity
216 -- of a body which caused contract "freezing" and Contract_Id denotes the
217 -- entity of the affected contstruct.
219 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
);
220 -- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma
221 -- Prag that duplicates previous pragma Prev.
223 function Find_Related_Context
225 Do_Checks
: Boolean := False) return Node_Id
;
226 -- Subsidiaty to the analysis of pragmas Async_Readers, Async_Writers,
227 -- Constant_After_Elaboration, Effective_Reads, Effective_Writers and
228 -- Part_Of. Find the first source declaration or statement found while
229 -- traversing the previous node chain starting from pragma Prag. If flag
230 -- Do_Checks is set, the routine reports duplicate pragmas. The routine
231 -- returns Empty when reaching the start of the node chain.
233 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
;
234 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
235 -- original one, following the renaming chain) is returned. Otherwise the
236 -- entity is returned unchanged. Should be in Einfo???
238 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
;
239 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
240 -- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding
241 -- value of type SPARK_Mode_Type.
243 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean;
244 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
245 -- Determine whether dependency clause Clause is surrounded by extra
246 -- parentheses. If this is the case, issue an error message.
248 function Is_CCT_Instance
250 Context_Id
: Entity_Id
) return Boolean;
251 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
252 -- Global. Determine whether entity Ref_Id denotes the current instance of
253 -- a concurrent type. Context_Id denotes the associated context where the
256 function Is_Unconstrained_Or_Tagged_Item
(Item
: Entity_Id
) return Boolean;
257 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
258 -- pragma Depends. Determine whether the type of dependency item Item is
259 -- tagged, unconstrained array, unconstrained record or a record with at
260 -- least one unconstrained component.
262 procedure Record_Possible_Body_Reference
263 (State_Id
: Entity_Id
;
265 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
266 -- Global. Given an abstract state denoted by State_Id and a reference Ref
267 -- to it, determine whether the reference appears in a package body that
268 -- will eventually refine the state. If this is the case, record the
269 -- reference for future checks (see Analyze_Refined_State_In_Decls).
271 procedure Resolve_State
(N
: Node_Id
);
272 -- Handle the overloading of state names by functions. When N denotes a
273 -- function, this routine finds the corresponding state and sets the entity
274 -- of N to that of the state.
276 procedure Rewrite_Assertion_Kind
(N
: Node_Id
);
277 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
278 -- then it is rewritten as an identifier with the corresponding special
279 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
282 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
);
283 -- Place semantic information on the argument of an Elaborate/Elaborate_All
284 -- pragma. Entity name for unit and its parents is taken from item in
285 -- previous with_clause that mentions the unit.
287 Dummy
: Integer := 0;
288 pragma Volatile
(Dummy
);
289 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
292 pragma No_Inline
(ip
);
293 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
294 -- is just to help debugging the front end. If a pragma Inspection_Point
295 -- is added to a source program, then breaking on ip will get you to that
296 -- point in the program.
299 pragma No_Inline
(rv
);
300 -- This is a dummy function called by the processing for pragma Reviewable.
301 -- It is there for assisting front end debugging. By placing a Reviewable
302 -- pragma in the source program, a breakpoint on rv catches this place in
303 -- the source, allowing convenient stepping to the point of interest.
305 -------------------------------
306 -- Adjust_External_Name_Case --
307 -------------------------------
309 function Adjust_External_Name_Case
(N
: Node_Id
) return Node_Id
is
313 -- Adjust case of literal if required
315 if Opt
.External_Name_Exp_Casing
= As_Is
then
319 -- Copy existing string
325 for J
in 1 .. String_Length
(Strval
(N
)) loop
326 CC
:= Get_String_Char
(Strval
(N
), J
);
328 if Opt
.External_Name_Exp_Casing
= Uppercase
329 and then CC
>= Get_Char_Code
('a')
330 and then CC
<= Get_Char_Code
('z')
332 Store_String_Char
(CC
- 32);
334 elsif Opt
.External_Name_Exp_Casing
= Lowercase
335 and then CC
>= Get_Char_Code
('A')
336 and then CC
<= Get_Char_Code
('Z')
338 Store_String_Char
(CC
+ 32);
341 Store_String_Char
(CC
);
346 Make_String_Literal
(Sloc
(N
),
347 Strval
=> End_String
);
349 end Adjust_External_Name_Case
;
351 -----------------------------------------
352 -- Analyze_Contract_Cases_In_Decl_Part --
353 -----------------------------------------
355 procedure Analyze_Contract_Cases_In_Decl_Part
357 Freeze_Id
: Entity_Id
:= Empty
)
359 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
360 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
362 Others_Seen
: Boolean := False;
363 -- This flag is set when an "others" choice is encountered. It is used
364 -- to detect multiple illegal occurrences of "others".
366 procedure Analyze_Contract_Case
(CCase
: Node_Id
);
367 -- Verify the legality of a single contract case
369 ---------------------------
370 -- Analyze_Contract_Case --
371 ---------------------------
373 procedure Analyze_Contract_Case
(CCase
: Node_Id
) is
374 Case_Guard
: Node_Id
;
377 Extra_Guard
: Node_Id
;
380 if Nkind
(CCase
) = N_Component_Association
then
381 Case_Guard
:= First
(Choices
(CCase
));
382 Conseq
:= Expression
(CCase
);
384 -- Each contract case must have exactly one case guard
386 Extra_Guard
:= Next
(Case_Guard
);
388 if Present
(Extra_Guard
) then
390 ("contract case must have exactly one case guard",
394 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
396 if Nkind
(Case_Guard
) = N_Others_Choice
then
399 ("only one others choice allowed in contract cases",
405 elsif Others_Seen
then
407 ("others must be the last choice in contract cases", N
);
410 -- Preanalyze the case guard and consequence
412 if Nkind
(Case_Guard
) /= N_Others_Choice
then
413 Errors
:= Serious_Errors_Detected
;
414 Preanalyze_Assert_Expression
(Case_Guard
, Standard_Boolean
);
416 -- Emit a clarification message when the case guard contains
417 -- at least one undefined reference, possibly due to contract
420 if Errors
/= Serious_Errors_Detected
421 and then Present
(Freeze_Id
)
422 and then Has_Undefined_Reference
(Case_Guard
)
424 Contract_Freeze_Error
(Spec_Id
, Freeze_Id
);
428 Errors
:= Serious_Errors_Detected
;
429 Preanalyze_Assert_Expression
(Conseq
, Standard_Boolean
);
431 -- Emit a clarification message when the consequence contains
432 -- at least one undefined reference, possibly due to contract
435 if Errors
/= Serious_Errors_Detected
436 and then Present
(Freeze_Id
)
437 and then Has_Undefined_Reference
(Conseq
)
439 Contract_Freeze_Error
(Spec_Id
, Freeze_Id
);
442 -- The contract case is malformed
445 Error_Msg_N
("wrong syntax in contract case", CCase
);
447 end Analyze_Contract_Case
;
451 CCases
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
453 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
456 Restore_Scope
: Boolean := False;
458 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
461 -- Do not analyze the pragma multiple times
463 if Is_Analyzed_Pragma
(N
) then
467 -- Set the Ghost mode in effect from the pragma. Due to the delayed
468 -- analysis of the pragma, the Ghost mode at point of declaration and
469 -- point of analysis may not necessarely be the same. Use the mode in
470 -- effect at the point of declaration.
474 -- Single and multiple contract cases must appear in aggregate form. If
475 -- this is not the case, then either the parser of the analysis of the
476 -- pragma failed to produce an aggregate.
478 pragma Assert
(Nkind
(CCases
) = N_Aggregate
);
480 if Present
(Component_Associations
(CCases
)) then
482 -- Ensure that the formal parameters are visible when analyzing all
483 -- clauses. This falls out of the general rule of aspects pertaining
484 -- to subprogram declarations.
486 if not In_Open_Scopes
(Spec_Id
) then
487 Restore_Scope
:= True;
488 Push_Scope
(Spec_Id
);
490 if Is_Generic_Subprogram
(Spec_Id
) then
491 Install_Generic_Formals
(Spec_Id
);
493 Install_Formals
(Spec_Id
);
497 CCase
:= First
(Component_Associations
(CCases
));
498 while Present
(CCase
) loop
499 Analyze_Contract_Case
(CCase
);
503 if Restore_Scope
then
507 -- Currently it is not possible to inline pre/postconditions on a
508 -- subprogram subject to pragma Inline_Always.
510 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
512 -- Otherwise the pragma is illegal
515 Error_Msg_N
("wrong syntax for constract cases", N
);
518 Ghost_Mode
:= Save_Ghost_Mode
;
519 Set_Is_Analyzed_Pragma
(N
);
520 end Analyze_Contract_Cases_In_Decl_Part
;
522 ----------------------------------
523 -- Analyze_Depends_In_Decl_Part --
524 ----------------------------------
526 procedure Analyze_Depends_In_Decl_Part
(N
: Node_Id
) is
527 Loc
: constant Source_Ptr
:= Sloc
(N
);
528 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
529 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
531 All_Inputs_Seen
: Elist_Id
:= No_Elist
;
532 -- A list containing the entities of all the inputs processed so far.
533 -- The list is populated with unique entities because the same input
534 -- may appear in multiple input lists.
536 All_Outputs_Seen
: Elist_Id
:= No_Elist
;
537 -- A list containing the entities of all the outputs processed so far.
538 -- The list is populated with unique entities because output items are
539 -- unique in a dependence relation.
541 Constits_Seen
: Elist_Id
:= No_Elist
;
542 -- A list containing the entities of all constituents processed so far.
543 -- It aids in detecting illegal usage of a state and a corresponding
544 -- constituent in pragma [Refinde_]Depends.
546 Global_Seen
: Boolean := False;
547 -- A flag set when pragma Global has been processed
549 Null_Output_Seen
: Boolean := False;
550 -- A flag used to track the legality of a null output
552 Result_Seen
: Boolean := False;
553 -- A flag set when Spec_Id'Result is processed
555 States_Seen
: Elist_Id
:= No_Elist
;
556 -- A list containing the entities of all states processed so far. It
557 -- helps in detecting illegal usage of a state and a corresponding
558 -- constituent in pragma [Refined_]Depends.
560 Subp_Inputs
: Elist_Id
:= No_Elist
;
561 Subp_Outputs
: Elist_Id
:= No_Elist
;
562 -- Two lists containing the full set of inputs and output of the related
563 -- subprograms. Note that these lists contain both nodes and entities.
565 Task_Input_Seen
: Boolean := False;
566 Task_Output_Seen
: Boolean := False;
567 -- Flags used to track the implicit dependence of a task unit on itself
569 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
);
570 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
571 -- to the name buffer. The individual kinds are as follows:
572 -- E_Abstract_State - "state"
573 -- E_Constant - "constant"
574 -- E_Discriminant - "discriminant"
575 -- E_Generic_In_Out_Parameter - "generic parameter"
576 -- E_Generic_In_Parameter - "generic parameter"
577 -- E_In_Parameter - "parameter"
578 -- E_In_Out_Parameter - "parameter"
579 -- E_Loop_Parameter - "loop parameter"
580 -- E_Out_Parameter - "parameter"
581 -- E_Protected_Type - "current instance of protected type"
582 -- E_Task_Type - "current instance of task type"
583 -- E_Variable - "global"
585 procedure Analyze_Dependency_Clause
588 -- Verify the legality of a single dependency clause. Flag Is_Last
589 -- denotes whether Clause is the last clause in the relation.
591 procedure Check_Function_Return
;
592 -- Verify that Funtion'Result appears as one of the outputs
593 -- (SPARK RM 6.1.5(10)).
600 -- Ensure that an item fulfills its designated input and/or output role
601 -- as specified by pragma Global (if any) or the enclosing context. If
602 -- this is not the case, emit an error. Item and Item_Id denote the
603 -- attributes of an item. Flag Is_Input should be set when item comes
604 -- from an input list. Flag Self_Ref should be set when the item is an
605 -- output and the dependency clause has operator "+".
607 procedure Check_Usage
608 (Subp_Items
: Elist_Id
;
609 Used_Items
: Elist_Id
;
611 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
612 -- error if this is not the case.
614 procedure Normalize_Clause
(Clause
: Node_Id
);
615 -- Remove a self-dependency "+" from the input list of a clause
617 -----------------------------
618 -- Add_Item_To_Name_Buffer --
619 -----------------------------
621 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
) is
623 if Ekind
(Item_Id
) = E_Abstract_State
then
624 Add_Str_To_Name_Buffer
("state");
626 elsif Ekind
(Item_Id
) = E_Constant
then
627 Add_Str_To_Name_Buffer
("constant");
629 elsif Ekind
(Item_Id
) = E_Discriminant
then
630 Add_Str_To_Name_Buffer
("discriminant");
632 elsif Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
633 E_Generic_In_Parameter
)
635 Add_Str_To_Name_Buffer
("generic parameter");
637 elsif Is_Formal
(Item_Id
) then
638 Add_Str_To_Name_Buffer
("parameter");
640 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
641 Add_Str_To_Name_Buffer
("loop parameter");
643 elsif Ekind
(Item_Id
) = E_Protected_Type
644 or else Is_Single_Protected_Object
(Item_Id
)
646 Add_Str_To_Name_Buffer
("current instance of protected type");
648 elsif Ekind
(Item_Id
) = E_Task_Type
649 or else Is_Single_Task_Object
(Item_Id
)
651 Add_Str_To_Name_Buffer
("current instance of task type");
653 elsif Ekind
(Item_Id
) = E_Variable
then
654 Add_Str_To_Name_Buffer
("global");
656 -- The routine should not be called with non-SPARK items
661 end Add_Item_To_Name_Buffer
;
663 -------------------------------
664 -- Analyze_Dependency_Clause --
665 -------------------------------
667 procedure Analyze_Dependency_Clause
671 procedure Analyze_Input_List
(Inputs
: Node_Id
);
672 -- Verify the legality of a single input list
674 procedure Analyze_Input_Output
679 Seen
: in out Elist_Id
;
680 Null_Seen
: in out Boolean;
681 Non_Null_Seen
: in out Boolean);
682 -- Verify the legality of a single input or output item. Flag
683 -- Is_Input should be set whenever Item is an input, False when it
684 -- denotes an output. Flag Self_Ref should be set when the item is an
685 -- output and the dependency clause has a "+". Flag Top_Level should
686 -- be set whenever Item appears immediately within an input or output
687 -- list. Seen is a collection of all abstract states, objects and
688 -- formals processed so far. Flag Null_Seen denotes whether a null
689 -- input or output has been encountered. Flag Non_Null_Seen denotes
690 -- whether a non-null input or output has been encountered.
692 ------------------------
693 -- Analyze_Input_List --
694 ------------------------
696 procedure Analyze_Input_List
(Inputs
: Node_Id
) is
697 Inputs_Seen
: Elist_Id
:= No_Elist
;
698 -- A list containing the entities of all inputs that appear in the
699 -- current input list.
701 Non_Null_Input_Seen
: Boolean := False;
702 Null_Input_Seen
: Boolean := False;
703 -- Flags used to check the legality of an input list
708 -- Multiple inputs appear as an aggregate
710 if Nkind
(Inputs
) = N_Aggregate
then
711 if Present
(Component_Associations
(Inputs
)) then
713 ("nested dependency relations not allowed", Inputs
);
715 elsif Present
(Expressions
(Inputs
)) then
716 Input
:= First
(Expressions
(Inputs
));
717 while Present
(Input
) loop
724 Null_Seen
=> Null_Input_Seen
,
725 Non_Null_Seen
=> Non_Null_Input_Seen
);
730 -- Syntax error, always report
733 Error_Msg_N
("malformed input dependency list", Inputs
);
736 -- Process a solitary input
745 Null_Seen
=> Null_Input_Seen
,
746 Non_Null_Seen
=> Non_Null_Input_Seen
);
749 -- Detect an illegal dependency clause of the form
753 if Null_Output_Seen
and then Null_Input_Seen
then
755 ("null dependency clause cannot have a null input list",
758 end Analyze_Input_List
;
760 --------------------------
761 -- Analyze_Input_Output --
762 --------------------------
764 procedure Analyze_Input_Output
769 Seen
: in out Elist_Id
;
770 Null_Seen
: in out Boolean;
771 Non_Null_Seen
: in out Boolean)
773 procedure Current_Task_Instance_Seen
;
774 -- Set the appropriate global flag when the current instance of a
775 -- task unit is encountered.
777 --------------------------------
778 -- Current_Task_Instance_Seen --
779 --------------------------------
781 procedure Current_Task_Instance_Seen
is
784 Task_Input_Seen
:= True;
786 Task_Output_Seen
:= True;
788 end Current_Task_Instance_Seen
;
792 Is_Output
: constant Boolean := not Is_Input
;
796 -- Start of processing for Analyze_Input_Output
799 -- Multiple input or output items appear as an aggregate
801 if Nkind
(Item
) = N_Aggregate
then
802 if not Top_Level
then
803 SPARK_Msg_N
("nested grouping of items not allowed", Item
);
805 elsif Present
(Component_Associations
(Item
)) then
807 ("nested dependency relations not allowed", Item
);
809 -- Recursively analyze the grouped items
811 elsif Present
(Expressions
(Item
)) then
812 Grouped
:= First
(Expressions
(Item
));
813 while Present
(Grouped
) loop
816 Is_Input
=> Is_Input
,
817 Self_Ref
=> Self_Ref
,
820 Null_Seen
=> Null_Seen
,
821 Non_Null_Seen
=> Non_Null_Seen
);
826 -- Syntax error, always report
829 Error_Msg_N
("malformed dependency list", Item
);
832 -- Process attribute 'Result in the context of a dependency clause
834 elsif Is_Attribute_Result
(Item
) then
835 Non_Null_Seen
:= True;
839 -- Attribute 'Result is allowed to appear on the output side of
840 -- a dependency clause (SPARK RM 6.1.5(6)).
843 SPARK_Msg_N
("function result cannot act as input", Item
);
847 ("cannot mix null and non-null dependency items", Item
);
853 -- Detect multiple uses of null in a single dependency list or
854 -- throughout the whole relation. Verify the placement of a null
855 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
857 elsif Nkind
(Item
) = N_Null
then
860 ("multiple null dependency relations not allowed", Item
);
862 elsif Non_Null_Seen
then
864 ("cannot mix null and non-null dependency items", Item
);
872 ("null output list must be the last clause in a "
873 & "dependency relation", Item
);
875 -- Catch a useless dependence of the form:
880 ("useless dependence, null depends on itself", Item
);
888 Non_Null_Seen
:= True;
891 SPARK_Msg_N
("cannot mix null and non-null items", Item
);
895 Resolve_State
(Item
);
897 -- Find the entity of the item. If this is a renaming, climb
898 -- the renaming chain to reach the root object. Renamings of
899 -- non-entire objects do not yield an entity (Empty).
901 Item_Id
:= Entity_Of
(Item
);
903 if Present
(Item_Id
) then
907 if Ekind_In
(Item_Id
, E_Constant
,
912 -- Current instances of concurrent types
914 Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
)
919 Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
920 E_Generic_In_Parameter
,
928 Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
)
930 -- The item denotes a concurrent type. Note that single
931 -- protected/task types are not considered here because
932 -- they behave as objects in the context of pragma
933 -- [Refined_]Depends.
935 if Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
937 -- This use is legal as long as the concurrent type is
938 -- the current instance of an enclosing type.
940 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
942 -- The dependence of a task unit on itself is
943 -- implicit and may or may not be explicitly
944 -- specified (SPARK RM 6.1.4).
946 if Ekind
(Item_Id
) = E_Task_Type
then
947 Current_Task_Instance_Seen
;
950 -- Otherwise this is not the current instance
954 ("invalid use of subtype mark in dependency "
958 -- The dependency of a task unit on itself is implicit
959 -- and may or may not be explicitly specified
962 elsif Is_Single_Task_Object
(Item_Id
)
963 and then Is_CCT_Instance
(Item_Id
, Spec_Id
)
965 Current_Task_Instance_Seen
;
968 -- Ensure that the item fulfills its role as input and/or
969 -- output as specified by pragma Global or the enclosing
972 Check_Role
(Item
, Item_Id
, Is_Input
, Self_Ref
);
974 -- Detect multiple uses of the same state, variable or
975 -- formal parameter. If this is not the case, add the
976 -- item to the list of processed relations.
978 if Contains
(Seen
, Item_Id
) then
980 ("duplicate use of item &", Item
, Item_Id
);
982 Append_New_Elmt
(Item_Id
, Seen
);
985 -- Detect illegal use of an input related to a null
986 -- output. Such input items cannot appear in other
987 -- input lists (SPARK RM 6.1.5(13)).
990 and then Null_Output_Seen
991 and then Contains
(All_Inputs_Seen
, Item_Id
)
994 ("input of a null output list cannot appear in "
995 & "multiple input lists", Item
);
998 -- Add an input or a self-referential output to the list
999 -- of all processed inputs.
1001 if Is_Input
or else Self_Ref
then
1002 Append_New_Elmt
(Item_Id
, All_Inputs_Seen
);
1005 -- State related checks (SPARK RM 6.1.5(3))
1007 if Ekind
(Item_Id
) = E_Abstract_State
then
1009 -- Package and subprogram bodies are instantiated
1010 -- individually in a separate compiler pass. Due to
1011 -- this mode of instantiation, the refinement of a
1012 -- state may no longer be visible when a subprogram
1013 -- body contract is instantiated. Since the generic
1014 -- template is legal, do not perform this check in
1015 -- the instance to circumvent this oddity.
1017 if Is_Generic_Instance
(Spec_Id
) then
1020 -- An abstract state with visible refinement cannot
1021 -- appear in pragma [Refined_]Depends as its place
1022 -- must be taken by some of its constituents
1023 -- (SPARK RM 6.1.4(7)).
1025 elsif Has_Visible_Refinement
(Item_Id
) then
1027 ("cannot mention state & in dependence relation",
1029 SPARK_Msg_N
("\use its constituents instead", Item
);
1032 -- If the reference to the abstract state appears in
1033 -- an enclosing package body that will eventually
1034 -- refine the state, record the reference for future
1038 Record_Possible_Body_Reference
1039 (State_Id
=> Item_Id
,
1044 -- When the item renames an entire object, replace the
1045 -- item with a reference to the object.
1047 if Entity
(Item
) /= Item_Id
then
1049 New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
1053 -- Add the entity of the current item to the list of
1056 if Ekind
(Item_Id
) = E_Abstract_State
then
1057 Append_New_Elmt
(Item_Id
, States_Seen
);
1059 -- The variable may eventually become a constituent of a
1060 -- single protected/task type. Record the reference now
1061 -- and verify its legality when analyzing the contract of
1062 -- the variable (SPARK RM 9.3).
1064 elsif Ekind
(Item_Id
) = E_Variable
then
1065 Record_Possible_Part_Of_Reference
1070 if Ekind_In
(Item_Id
, E_Abstract_State
,
1073 and then Present
(Encapsulating_State
(Item_Id
))
1075 Append_New_Elmt
(Item_Id
, Constits_Seen
);
1078 -- All other input/output items are illegal
1079 -- (SPARK RM 6.1.5(1)).
1083 ("item must denote parameter, variable, state or "
1084 & "current instance of concurren type", Item
);
1087 -- All other input/output items are illegal
1088 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1092 ("item must denote parameter, variable, state or current "
1093 & "instance of concurrent type", Item
);
1096 end Analyze_Input_Output
;
1104 Non_Null_Output_Seen
: Boolean := False;
1105 -- Flag used to check the legality of an output list
1107 -- Start of processing for Analyze_Dependency_Clause
1110 Inputs
:= Expression
(Clause
);
1113 -- An input list with a self-dependency appears as operator "+" where
1114 -- the actuals inputs are the right operand.
1116 if Nkind
(Inputs
) = N_Op_Plus
then
1117 Inputs
:= Right_Opnd
(Inputs
);
1121 -- Process the output_list of a dependency_clause
1123 Output
:= First
(Choices
(Clause
));
1124 while Present
(Output
) loop
1125 Analyze_Input_Output
1128 Self_Ref
=> Self_Ref
,
1130 Seen
=> All_Outputs_Seen
,
1131 Null_Seen
=> Null_Output_Seen
,
1132 Non_Null_Seen
=> Non_Null_Output_Seen
);
1137 -- Process the input_list of a dependency_clause
1139 Analyze_Input_List
(Inputs
);
1140 end Analyze_Dependency_Clause
;
1142 ---------------------------
1143 -- Check_Function_Return --
1144 ---------------------------
1146 procedure Check_Function_Return
is
1148 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
1149 and then not Result_Seen
1152 ("result of & must appear in exactly one output list",
1155 end Check_Function_Return
;
1161 procedure Check_Role
1163 Item_Id
: Entity_Id
;
1168 (Item_Is_Input
: out Boolean;
1169 Item_Is_Output
: out Boolean);
1170 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1171 -- Item_Is_Output are set depending on the role.
1173 procedure Role_Error
1174 (Item_Is_Input
: Boolean;
1175 Item_Is_Output
: Boolean);
1176 -- Emit an error message concerning the incorrect use of Item in
1177 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1178 -- denote whether the item is an input and/or an output.
1185 (Item_Is_Input
: out Boolean;
1186 Item_Is_Output
: out Boolean)
1189 Item_Is_Input
:= False;
1190 Item_Is_Output
:= False;
1194 if Ekind
(Item_Id
) = E_Abstract_State
then
1196 -- When pragma Global is present, the mode of the state may be
1197 -- further constrained by setting a more restrictive mode.
1200 if Appears_In
(Subp_Inputs
, Item_Id
) then
1201 Item_Is_Input
:= True;
1204 if Appears_In
(Subp_Outputs
, Item_Id
) then
1205 Item_Is_Output
:= True;
1208 -- Otherwise the state has a default IN OUT mode
1211 Item_Is_Input
:= True;
1212 Item_Is_Output
:= True;
1217 elsif Ekind_In
(Item_Id
, E_Constant
,
1221 Item_Is_Input
:= True;
1225 elsif Ekind_In
(Item_Id
, E_Generic_In_Parameter
,
1228 Item_Is_Input
:= True;
1230 elsif Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
1233 Item_Is_Input
:= True;
1234 Item_Is_Output
:= True;
1236 elsif Ekind
(Item_Id
) = E_Out_Parameter
then
1237 if Scope
(Item_Id
) = Spec_Id
then
1239 -- An OUT parameter of the related subprogram has mode IN
1240 -- if its type is unconstrained or tagged because array
1241 -- bounds, discriminants or tags can be read.
1243 if Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1244 Item_Is_Input
:= True;
1247 Item_Is_Output
:= True;
1249 -- An OUT parameter of an enclosing subprogram behaves as a
1250 -- read-write variable in which case the mode is IN OUT.
1253 Item_Is_Input
:= True;
1254 Item_Is_Output
:= True;
1259 elsif Ekind
(Item_Id
) = E_Protected_Type
then
1261 -- A protected type acts as a formal parameter of mode IN when
1262 -- it applies to a protected function.
1264 if Ekind
(Spec_Id
) = E_Function
then
1265 Item_Is_Input
:= True;
1267 -- Otherwise the protected type acts as a formal of mode IN OUT
1270 Item_Is_Input
:= True;
1271 Item_Is_Output
:= True;
1276 elsif Ekind
(Item_Id
) = E_Task_Type
then
1277 Item_Is_Input
:= True;
1278 Item_Is_Output
:= True;
1282 else pragma Assert
(Ekind
(Item_Id
) = E_Variable
);
1284 -- When pragma Global is present, the mode of the variable may
1285 -- be further constrained by setting a more restrictive mode.
1289 -- A variable has mode IN when its type is unconstrained or
1290 -- tagged because array bounds, discriminants or tags can be
1293 if Appears_In
(Subp_Inputs
, Item_Id
)
1294 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
)
1296 Item_Is_Input
:= True;
1299 if Appears_In
(Subp_Outputs
, Item_Id
) then
1300 Item_Is_Output
:= True;
1303 -- Otherwise the variable has a default IN OUT mode
1306 Item_Is_Input
:= True;
1307 Item_Is_Output
:= True;
1316 procedure Role_Error
1317 (Item_Is_Input
: Boolean;
1318 Item_Is_Output
: Boolean)
1320 Error_Msg
: Name_Id
;
1325 -- When the item is not part of the input and the output set of
1326 -- the related subprogram, then it appears as extra in pragma
1327 -- [Refined_]Depends.
1329 if not Item_Is_Input
and then not Item_Is_Output
then
1330 Add_Item_To_Name_Buffer
(Item_Id
);
1331 Add_Str_To_Name_Buffer
1332 (" & cannot appear in dependence relation");
1334 Error_Msg
:= Name_Find
;
1335 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1337 Error_Msg_Name_1
:= Chars
(Spec_Id
);
1339 (Fix_Msg
(Spec_Id
, "\& is not part of the input or output "
1340 & "set of subprogram %"), Item
, Item_Id
);
1342 -- The mode of the item and its role in pragma [Refined_]Depends
1343 -- are in conflict. Construct a detailed message explaining the
1344 -- illegality (SPARK RM 6.1.5(5-6)).
1347 if Item_Is_Input
then
1348 Add_Str_To_Name_Buffer
("read-only");
1350 Add_Str_To_Name_Buffer
("write-only");
1353 Add_Char_To_Name_Buffer
(' ');
1354 Add_Item_To_Name_Buffer
(Item_Id
);
1355 Add_Str_To_Name_Buffer
(" & cannot appear as ");
1357 if Item_Is_Input
then
1358 Add_Str_To_Name_Buffer
("output");
1360 Add_Str_To_Name_Buffer
("input");
1363 Add_Str_To_Name_Buffer
(" in dependence relation");
1364 Error_Msg
:= Name_Find
;
1365 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1371 Item_Is_Input
: Boolean;
1372 Item_Is_Output
: Boolean;
1374 -- Start of processing for Check_Role
1377 Find_Role
(Item_Is_Input
, Item_Is_Output
);
1382 if not Item_Is_Input
then
1383 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1386 -- Self-referential item
1389 if not Item_Is_Input
or else not Item_Is_Output
then
1390 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1395 elsif not Item_Is_Output
then
1396 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1404 procedure Check_Usage
1405 (Subp_Items
: Elist_Id
;
1406 Used_Items
: Elist_Id
;
1409 procedure Usage_Error
(Item_Id
: Entity_Id
);
1410 -- Emit an error concerning the illegal usage of an item
1416 procedure Usage_Error
(Item_Id
: Entity_Id
) is
1417 Error_Msg
: Name_Id
;
1424 -- Unconstrained and tagged items are not part of the explicit
1425 -- input set of the related subprogram, they do not have to be
1426 -- present in a dependence relation and should not be flagged
1427 -- (SPARK RM 6.1.5(8)).
1429 if not Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1432 Add_Item_To_Name_Buffer
(Item_Id
);
1433 Add_Str_To_Name_Buffer
1434 (" & is missing from input dependence list");
1436 Error_Msg
:= Name_Find
;
1437 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1440 -- Output case (SPARK RM 6.1.5(10))
1445 Add_Item_To_Name_Buffer
(Item_Id
);
1446 Add_Str_To_Name_Buffer
1447 (" & is missing from output dependence list");
1449 Error_Msg
:= Name_Find
;
1450 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1458 Item_Id
: Entity_Id
;
1460 -- Start of processing for Check_Usage
1463 if No
(Subp_Items
) then
1467 -- Each input or output of the subprogram must appear in a dependency
1470 Elmt
:= First_Elmt
(Subp_Items
);
1471 while Present
(Elmt
) loop
1472 Item
:= Node
(Elmt
);
1474 if Nkind
(Item
) = N_Defining_Identifier
then
1477 Item_Id
:= Entity_Of
(Item
);
1480 -- The item does not appear in a dependency
1482 if Present
(Item_Id
)
1483 and then not Contains
(Used_Items
, Item_Id
)
1485 if Is_Formal
(Item_Id
) then
1486 Usage_Error
(Item_Id
);
1488 -- The current instance of a protected type behaves as a formal
1489 -- parameter (SPARK RM 6.1.4).
1491 elsif Ekind
(Item_Id
) = E_Protected_Type
1492 or else Is_Single_Protected_Object
(Item_Id
)
1494 Usage_Error
(Item_Id
);
1496 -- The current instance of a task type behaves as a formal
1497 -- parameter (SPARK RM 6.1.4).
1499 elsif Ekind
(Item_Id
) = E_Task_Type
1500 or else Is_Single_Task_Object
(Item_Id
)
1502 -- The dependence of a task unit on itself is implicit and
1503 -- may or may not be explicitly specified (SPARK RM 6.1.4).
1504 -- Emit an error if only one input/output is present.
1506 if Task_Input_Seen
/= Task_Output_Seen
then
1507 Usage_Error
(Item_Id
);
1510 -- States and global objects are not used properly only when
1511 -- the subprogram is subject to pragma Global.
1513 elsif Global_Seen
then
1514 Usage_Error
(Item_Id
);
1522 ----------------------
1523 -- Normalize_Clause --
1524 ----------------------
1526 procedure Normalize_Clause
(Clause
: Node_Id
) is
1527 procedure Create_Or_Modify_Clause
1533 Multiple
: Boolean);
1534 -- Create a brand new clause to represent the self-reference or
1535 -- modify the input and/or output lists of an existing clause. Output
1536 -- denotes a self-referencial output. Outputs is the output list of a
1537 -- clause. Inputs is the input list of a clause. After denotes the
1538 -- clause after which the new clause is to be inserted. Flag In_Place
1539 -- should be set when normalizing the last output of an output list.
1540 -- Flag Multiple should be set when Output comes from a list with
1543 -----------------------------
1544 -- Create_Or_Modify_Clause --
1545 -----------------------------
1547 procedure Create_Or_Modify_Clause
1555 procedure Propagate_Output
1558 -- Handle the various cases of output propagation to the input
1559 -- list. Output denotes a self-referencial output item. Inputs
1560 -- is the input list of a clause.
1562 ----------------------
1563 -- Propagate_Output --
1564 ----------------------
1566 procedure Propagate_Output
1570 function In_Input_List
1572 Inputs
: List_Id
) return Boolean;
1573 -- Determine whether a particulat item appears in the input
1574 -- list of a clause.
1580 function In_Input_List
1582 Inputs
: List_Id
) return Boolean
1587 Elmt
:= First
(Inputs
);
1588 while Present
(Elmt
) loop
1589 if Entity_Of
(Elmt
) = Item
then
1601 Output_Id
: constant Entity_Id
:= Entity_Of
(Output
);
1604 -- Start of processing for Propagate_Output
1607 -- The clause is of the form:
1609 -- (Output =>+ null)
1611 -- Remove null input and replace it with a copy of the output:
1613 -- (Output => Output)
1615 if Nkind
(Inputs
) = N_Null
then
1616 Rewrite
(Inputs
, New_Copy_Tree
(Output
));
1618 -- The clause is of the form:
1620 -- (Output =>+ (Input1, ..., InputN))
1622 -- Determine whether the output is not already mentioned in the
1623 -- input list and if not, add it to the list of inputs:
1625 -- (Output => (Output, Input1, ..., InputN))
1627 elsif Nkind
(Inputs
) = N_Aggregate
then
1628 Grouped
:= Expressions
(Inputs
);
1630 if not In_Input_List
1634 Prepend_To
(Grouped
, New_Copy_Tree
(Output
));
1637 -- The clause is of the form:
1639 -- (Output =>+ Input)
1641 -- If the input does not mention the output, group the two
1644 -- (Output => (Output, Input))
1646 elsif Entity_Of
(Inputs
) /= Output_Id
then
1648 Make_Aggregate
(Loc
,
1649 Expressions
=> New_List
(
1650 New_Copy_Tree
(Output
),
1651 New_Copy_Tree
(Inputs
))));
1653 end Propagate_Output
;
1657 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
1658 New_Clause
: Node_Id
;
1660 -- Start of processing for Create_Or_Modify_Clause
1663 -- A null output depending on itself does not require any
1666 if Nkind
(Output
) = N_Null
then
1669 -- A function result cannot depend on itself because it cannot
1670 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1672 elsif Is_Attribute_Result
(Output
) then
1673 SPARK_Msg_N
("function result cannot depend on itself", Output
);
1677 -- When performing the transformation in place, simply add the
1678 -- output to the list of inputs (if not already there). This
1679 -- case arises when dealing with the last output of an output
1680 -- list. Perform the normalization in place to avoid generating
1681 -- a malformed tree.
1684 Propagate_Output
(Output
, Inputs
);
1686 -- A list with multiple outputs is slowly trimmed until only
1687 -- one element remains. When this happens, replace aggregate
1688 -- with the element itself.
1692 Rewrite
(Outputs
, Output
);
1698 -- Unchain the output from its output list as it will appear in
1699 -- a new clause. Note that we cannot simply rewrite the output
1700 -- as null because this will violate the semantics of pragma
1705 -- Generate a new clause of the form:
1706 -- (Output => Inputs)
1709 Make_Component_Association
(Loc
,
1710 Choices
=> New_List
(Output
),
1711 Expression
=> New_Copy_Tree
(Inputs
));
1713 -- The new clause contains replicated content that has already
1714 -- been analyzed. There is not need to reanalyze or renormalize
1717 Set_Analyzed
(New_Clause
);
1720 (Output
=> First
(Choices
(New_Clause
)),
1721 Inputs
=> Expression
(New_Clause
));
1723 Insert_After
(After
, New_Clause
);
1725 end Create_Or_Modify_Clause
;
1729 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
1731 Last_Output
: Node_Id
;
1732 Next_Output
: Node_Id
;
1735 -- Start of processing for Normalize_Clause
1738 -- A self-dependency appears as operator "+". Remove the "+" from the
1739 -- tree by moving the real inputs to their proper place.
1741 if Nkind
(Expression
(Clause
)) = N_Op_Plus
then
1742 Rewrite
(Expression
(Clause
), Right_Opnd
(Expression
(Clause
)));
1743 Inputs
:= Expression
(Clause
);
1745 -- Multiple outputs appear as an aggregate
1747 if Nkind
(Outputs
) = N_Aggregate
then
1748 Last_Output
:= Last
(Expressions
(Outputs
));
1750 Output
:= First
(Expressions
(Outputs
));
1751 while Present
(Output
) loop
1753 -- Normalization may remove an output from its list,
1754 -- preserve the subsequent output now.
1756 Next_Output
:= Next
(Output
);
1758 Create_Or_Modify_Clause
1763 In_Place
=> Output
= Last_Output
,
1766 Output
:= Next_Output
;
1772 Create_Or_Modify_Clause
1781 end Normalize_Clause
;
1785 Deps
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
1786 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
1790 Last_Clause
: Node_Id
;
1791 Restore_Scope
: Boolean := False;
1793 -- Start of processing for Analyze_Depends_In_Decl_Part
1796 -- Do not analyze the pragma multiple times
1798 if Is_Analyzed_Pragma
(N
) then
1802 -- Empty dependency list
1804 if Nkind
(Deps
) = N_Null
then
1806 -- Gather all states, objects and formal parameters that the
1807 -- subprogram may depend on. These items are obtained from the
1808 -- parameter profile or pragma [Refined_]Global (if available).
1810 Collect_Subprogram_Inputs_Outputs
1811 (Subp_Id
=> Subp_Id
,
1812 Subp_Inputs
=> Subp_Inputs
,
1813 Subp_Outputs
=> Subp_Outputs
,
1814 Global_Seen
=> Global_Seen
);
1816 -- Verify that every input or output of the subprogram appear in a
1819 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1820 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1821 Check_Function_Return
;
1823 -- Dependency clauses appear as component associations of an aggregate
1825 elsif Nkind
(Deps
) = N_Aggregate
then
1827 -- Do not attempt to perform analysis of a syntactically illegal
1828 -- clause as this will lead to misleading errors.
1830 if Has_Extra_Parentheses
(Deps
) then
1834 if Present
(Component_Associations
(Deps
)) then
1835 Last_Clause
:= Last
(Component_Associations
(Deps
));
1837 -- Gather all states, objects and formal parameters that the
1838 -- subprogram may depend on. These items are obtained from the
1839 -- parameter profile or pragma [Refined_]Global (if available).
1841 Collect_Subprogram_Inputs_Outputs
1842 (Subp_Id
=> Subp_Id
,
1843 Subp_Inputs
=> Subp_Inputs
,
1844 Subp_Outputs
=> Subp_Outputs
,
1845 Global_Seen
=> Global_Seen
);
1847 -- When pragma [Refined_]Depends appears on a single concurrent
1848 -- type, it is relocated to the anonymous object.
1850 if Is_Single_Concurrent_Object
(Spec_Id
) then
1853 -- Ensure that the formal parameters are visible when analyzing
1854 -- all clauses. This falls out of the general rule of aspects
1855 -- pertaining to subprogram declarations.
1857 elsif not In_Open_Scopes
(Spec_Id
) then
1858 Restore_Scope
:= True;
1859 Push_Scope
(Spec_Id
);
1861 if Ekind
(Spec_Id
) = E_Task_Type
then
1862 if Has_Discriminants
(Spec_Id
) then
1863 Install_Discriminants
(Spec_Id
);
1866 elsif Is_Generic_Subprogram
(Spec_Id
) then
1867 Install_Generic_Formals
(Spec_Id
);
1870 Install_Formals
(Spec_Id
);
1874 Clause
:= First
(Component_Associations
(Deps
));
1875 while Present
(Clause
) loop
1876 Errors
:= Serious_Errors_Detected
;
1878 -- The normalization mechanism may create extra clauses that
1879 -- contain replicated input and output names. There is no need
1880 -- to reanalyze them.
1882 if not Analyzed
(Clause
) then
1883 Set_Analyzed
(Clause
);
1885 Analyze_Dependency_Clause
1887 Is_Last
=> Clause
= Last_Clause
);
1890 -- Do not normalize a clause if errors were detected (count
1891 -- of Serious_Errors has increased) because the inputs and/or
1892 -- outputs may denote illegal items. Normalization is disabled
1893 -- in ASIS mode as it alters the tree by introducing new nodes
1894 -- similar to expansion.
1896 if Serious_Errors_Detected
= Errors
and then not ASIS_Mode
then
1897 Normalize_Clause
(Clause
);
1903 if Restore_Scope
then
1907 -- Verify that every input or output of the subprogram appear in a
1910 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1911 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1912 Check_Function_Return
;
1914 -- The dependency list is malformed. This is a syntax error, always
1918 Error_Msg_N
("malformed dependency relation", Deps
);
1922 -- The top level dependency relation is malformed. This is a syntax
1923 -- error, always report.
1926 Error_Msg_N
("malformed dependency relation", Deps
);
1930 -- Ensure that a state and a corresponding constituent do not appear
1931 -- together in pragma [Refined_]Depends.
1933 Check_State_And_Constituent_Use
1934 (States
=> States_Seen
,
1935 Constits
=> Constits_Seen
,
1939 Set_Is_Analyzed_Pragma
(N
);
1940 end Analyze_Depends_In_Decl_Part
;
1942 --------------------------------------------
1943 -- Analyze_External_Property_In_Decl_Part --
1944 --------------------------------------------
1946 procedure Analyze_External_Property_In_Decl_Part
1948 Expr_Val
: out Boolean)
1950 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
1951 Obj_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
1952 Obj_Id
: constant Entity_Id
:= Defining_Entity
(Obj_Decl
);
1958 -- Do not analyze the pragma multiple times
1960 if Is_Analyzed_Pragma
(N
) then
1964 Error_Msg_Name_1
:= Pragma_Name
(N
);
1966 -- An external property pragma must apply to an effectively volatile
1967 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1968 -- The check is performed at the end of the declarative region due to a
1969 -- possible out-of-order arrangement of pragmas:
1972 -- pragma Async_Readers (Obj);
1973 -- pragma Volatile (Obj);
1975 if not Is_Effectively_Volatile
(Obj_Id
) then
1977 ("external property % must apply to a volatile object", N
);
1980 -- Ensure that the Boolean expression (if present) is static. A missing
1981 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1985 if Present
(Arg1
) then
1986 Expr
:= Get_Pragma_Arg
(Arg1
);
1988 if Is_OK_Static_Expression
(Expr
) then
1989 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
1993 Set_Is_Analyzed_Pragma
(N
);
1994 end Analyze_External_Property_In_Decl_Part
;
1996 ---------------------------------
1997 -- Analyze_Global_In_Decl_Part --
1998 ---------------------------------
2000 procedure Analyze_Global_In_Decl_Part
(N
: Node_Id
) is
2001 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
2002 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
2003 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
2005 Constits_Seen
: Elist_Id
:= No_Elist
;
2006 -- A list containing the entities of all constituents processed so far.
2007 -- It aids in detecting illegal usage of a state and a corresponding
2008 -- constituent in pragma [Refinde_]Global.
2010 Seen
: Elist_Id
:= No_Elist
;
2011 -- A list containing the entities of all the items processed so far. It
2012 -- plays a role in detecting distinct entities.
2014 States_Seen
: Elist_Id
:= No_Elist
;
2015 -- A list containing the entities of all states processed so far. It
2016 -- helps in detecting illegal usage of a state and a corresponding
2017 -- constituent in pragma [Refined_]Global.
2019 In_Out_Seen
: Boolean := False;
2020 Input_Seen
: Boolean := False;
2021 Output_Seen
: Boolean := False;
2022 Proof_Seen
: Boolean := False;
2023 -- Flags used to verify the consistency of modes
2025 procedure Analyze_Global_List
2027 Global_Mode
: Name_Id
:= Name_Input
);
2028 -- Verify the legality of a single global list declaration. Global_Mode
2029 -- denotes the current mode in effect.
2031 -------------------------
2032 -- Analyze_Global_List --
2033 -------------------------
2035 procedure Analyze_Global_List
2037 Global_Mode
: Name_Id
:= Name_Input
)
2039 procedure Analyze_Global_Item
2041 Global_Mode
: Name_Id
);
2042 -- Verify the legality of a single global item declaration denoted by
2043 -- Item. Global_Mode denotes the current mode in effect.
2045 procedure Check_Duplicate_Mode
2047 Status
: in out Boolean);
2048 -- Flag Status denotes whether a particular mode has been seen while
2049 -- processing a global list. This routine verifies that Mode is not a
2050 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
2052 procedure Check_Mode_Restriction_In_Enclosing_Context
2054 Item_Id
: Entity_Id
);
2055 -- Verify that an item of mode In_Out or Output does not appear as an
2056 -- input in the Global aspect of an enclosing subprogram. If this is
2057 -- the case, emit an error. Item and Item_Id are respectively the
2058 -- item and its entity.
2060 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
);
2061 -- Mode denotes either In_Out or Output. Depending on the kind of the
2062 -- related subprogram, emit an error if those two modes apply to a
2063 -- function (SPARK RM 6.1.4(10)).
2065 -------------------------
2066 -- Analyze_Global_Item --
2067 -------------------------
2069 procedure Analyze_Global_Item
2071 Global_Mode
: Name_Id
)
2073 Item_Id
: Entity_Id
;
2076 -- Detect one of the following cases
2078 -- with Global => (null, Name)
2079 -- with Global => (Name_1, null, Name_2)
2080 -- with Global => (Name, null)
2082 if Nkind
(Item
) = N_Null
then
2083 SPARK_Msg_N
("cannot mix null and non-null global items", Item
);
2088 Resolve_State
(Item
);
2090 -- Find the entity of the item. If this is a renaming, climb the
2091 -- renaming chain to reach the root object. Renamings of non-
2092 -- entire objects do not yield an entity (Empty).
2094 Item_Id
:= Entity_Of
(Item
);
2096 if Present
(Item_Id
) then
2098 -- A global item may denote a formal parameter of an enclosing
2099 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2100 -- provide a better error diagnostic.
2102 if Is_Formal
(Item_Id
) then
2103 if Scope
(Item_Id
) = Spec_Id
then
2105 (Fix_Msg
(Spec_Id
, "global item cannot reference "
2106 & "parameter of subprogram &"), Item
, Spec_Id
);
2110 -- A global item may denote a concurrent type as long as it is
2111 -- the current instance of an enclosing protected or task type
2112 -- (SPARK RM 6.1.4).
2114 elsif Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
2115 if Is_CCT_Instance
(Item_Id
, Spec_Id
) then
2117 -- Pragma [Refined_]Global associated with a protected
2118 -- subprogram cannot mention the current instance of a
2119 -- protected type because the instance behaves as a
2120 -- formal parameter.
2122 if Ekind
(Item_Id
) = E_Protected_Type
then
2123 Error_Msg_Name_1
:= Chars
(Item_Id
);
2125 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2126 & "cannot reference current instance of protected "
2127 & "type %"), Item
, Spec_Id
);
2130 -- Pragma [Refined_]Global associated with a task type
2131 -- cannot mention the current instance of a task type
2132 -- because the instance behaves as a formal parameter.
2134 else pragma Assert
(Ekind
(Item_Id
) = E_Task_Type
);
2135 Error_Msg_Name_1
:= Chars
(Item_Id
);
2137 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2138 & "cannot reference current instance of task type "
2139 & "%"), Item
, Spec_Id
);
2143 -- Otherwise the global item denotes a subtype mark that is
2144 -- not a current instance.
2148 ("invalid use of subtype mark in global list", Item
);
2152 -- A global item may denote the anonymous object created for a
2153 -- single protected/task type as long as the current instance
2154 -- is the same single type (SPARK RM 6.1.4).
2156 elsif Is_Single_Concurrent_Object
(Item_Id
)
2157 and then Is_CCT_Instance
(Item_Id
, Spec_Id
)
2159 -- Pragma [Refined_]Global associated with a protected
2160 -- subprogram cannot mention the current instance of a
2161 -- protected type because the instance behaves as a formal
2164 if Is_Single_Protected_Object
(Item_Id
) then
2165 Error_Msg_Name_1
:= Chars
(Item_Id
);
2167 (Fix_Msg
(Spec_Id
, "global item of subprogram & cannot "
2168 & "reference current instance of protected type %"),
2172 -- Pragma [Refined_]Global associated with a task type
2173 -- cannot mention the current instance of a task type
2174 -- because the instance behaves as a formal parameter.
2176 else pragma Assert
(Is_Single_Task_Object
(Item_Id
));
2177 Error_Msg_Name_1
:= Chars
(Item_Id
);
2179 (Fix_Msg
(Spec_Id
, "global item of subprogram & cannot "
2180 & "reference current instance of task type %"),
2185 -- A formal object may act as a global item inside a generic
2187 elsif Is_Formal_Object
(Item_Id
) then
2190 -- The only legal references are those to abstract states,
2191 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2193 elsif not Ekind_In
(Item_Id
, E_Abstract_State
,
2200 ("global item must denote object, state or current "
2201 & "instance of concurrent type", Item
);
2205 -- State related checks
2207 if Ekind
(Item_Id
) = E_Abstract_State
then
2209 -- Package and subprogram bodies are instantiated
2210 -- individually in a separate compiler pass. Due to this
2211 -- mode of instantiation, the refinement of a state may
2212 -- no longer be visible when a subprogram body contract
2213 -- is instantiated. Since the generic template is legal,
2214 -- do not perform this check in the instance to circumvent
2217 if Is_Generic_Instance
(Spec_Id
) then
2220 -- An abstract state with visible refinement cannot appear
2221 -- in pragma [Refined_]Global as its place must be taken by
2222 -- some of its constituents (SPARK RM 6.1.4(7)).
2224 elsif Has_Visible_Refinement
(Item_Id
) then
2226 ("cannot mention state & in global refinement",
2228 SPARK_Msg_N
("\use its constituents instead", Item
);
2231 -- An external state cannot appear as a global item of a
2232 -- nonvolatile function (SPARK RM 7.1.3(8)).
2234 elsif Is_External_State
(Item_Id
)
2235 and then Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2236 and then not Is_Volatile_Function
(Spec_Id
)
2239 ("external state & cannot act as global item of "
2240 & "nonvolatile function", Item
, Item_Id
);
2243 -- If the reference to the abstract state appears in an
2244 -- enclosing package body that will eventually refine the
2245 -- state, record the reference for future checks.
2248 Record_Possible_Body_Reference
2249 (State_Id
=> Item_Id
,
2253 -- Constant related checks
2255 elsif Ekind
(Item_Id
) = E_Constant
then
2257 -- A constant is a read-only item, therefore it cannot act
2260 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2262 ("constant & cannot act as output", Item
, Item_Id
);
2266 -- Discriminant related checks
2268 elsif Ekind
(Item_Id
) = E_Discriminant
then
2270 -- A discriminant is a read-only item, therefore it cannot
2271 -- act as an output.
2273 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2275 ("discriminant & cannot act as output", Item
, Item_Id
);
2279 -- Loop parameter related checks
2281 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
2283 -- A loop parameter is a read-only item, therefore it cannot
2284 -- act as an output.
2286 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2288 ("loop parameter & cannot act as output",
2293 -- Variable related checks. These are only relevant when
2294 -- SPARK_Mode is on as they are not standard Ada legality
2297 elsif SPARK_Mode
= On
2298 and then Ekind
(Item_Id
) = E_Variable
2299 and then Is_Effectively_Volatile
(Item_Id
)
2301 -- An effectively volatile object cannot appear as a global
2302 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2304 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2305 and then not Is_Volatile_Function
(Spec_Id
)
2308 ("volatile object & cannot act as global item of a "
2309 & "function", Item
, Item_Id
);
2312 -- An effectively volatile object with external property
2313 -- Effective_Reads set to True must have mode Output or
2314 -- In_Out (SPARK RM 7.1.3(10)).
2316 elsif Effective_Reads_Enabled
(Item_Id
)
2317 and then Global_Mode
= Name_Input
2320 ("volatile object & with property Effective_Reads must "
2321 & "have mode In_Out or Output", Item
, Item_Id
);
2326 -- When the item renames an entire object, replace the item
2327 -- with a reference to the object.
2329 if Entity
(Item
) /= Item_Id
then
2330 Rewrite
(Item
, New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
2334 -- Some form of illegal construct masquerading as a name
2335 -- (SPARK RM 6.1.4(4)).
2339 ("global item must denote object, state or current instance "
2340 & "of concurrent type", Item
);
2344 -- Verify that an output does not appear as an input in an
2345 -- enclosing subprogram.
2347 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2348 Check_Mode_Restriction_In_Enclosing_Context
(Item
, Item_Id
);
2351 -- The same entity might be referenced through various way.
2352 -- Check the entity of the item rather than the item itself
2353 -- (SPARK RM 6.1.4(10)).
2355 if Contains
(Seen
, Item_Id
) then
2356 SPARK_Msg_N
("duplicate global item", Item
);
2358 -- Add the entity of the current item to the list of processed
2362 Append_New_Elmt
(Item_Id
, Seen
);
2364 if Ekind
(Item_Id
) = E_Abstract_State
then
2365 Append_New_Elmt
(Item_Id
, States_Seen
);
2367 -- The variable may eventually become a constituent of a single
2368 -- protected/task type. Record the reference now and verify its
2369 -- legality when analyzing the contract of the variable
2372 elsif Ekind
(Item_Id
) = E_Variable
then
2373 Record_Possible_Part_Of_Reference
2378 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
2379 and then Present
(Encapsulating_State
(Item_Id
))
2381 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2384 end Analyze_Global_Item
;
2386 --------------------------
2387 -- Check_Duplicate_Mode --
2388 --------------------------
2390 procedure Check_Duplicate_Mode
2392 Status
: in out Boolean)
2396 SPARK_Msg_N
("duplicate global mode", Mode
);
2400 end Check_Duplicate_Mode
;
2402 -------------------------------------------------
2403 -- Check_Mode_Restriction_In_Enclosing_Context --
2404 -------------------------------------------------
2406 procedure Check_Mode_Restriction_In_Enclosing_Context
2408 Item_Id
: Entity_Id
)
2410 Context
: Entity_Id
;
2412 Inputs
: Elist_Id
:= No_Elist
;
2413 Outputs
: Elist_Id
:= No_Elist
;
2416 -- Traverse the scope stack looking for enclosing subprograms
2417 -- subject to pragma [Refined_]Global.
2419 Context
:= Scope
(Subp_Id
);
2420 while Present
(Context
) and then Context
/= Standard_Standard
loop
2421 if Is_Subprogram
(Context
)
2423 (Present
(Get_Pragma
(Context
, Pragma_Global
))
2425 Present
(Get_Pragma
(Context
, Pragma_Refined_Global
)))
2427 Collect_Subprogram_Inputs_Outputs
2428 (Subp_Id
=> Context
,
2429 Subp_Inputs
=> Inputs
,
2430 Subp_Outputs
=> Outputs
,
2431 Global_Seen
=> Dummy
);
2433 -- The item is classified as In_Out or Output but appears as
2434 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(11)).
2436 if Appears_In
(Inputs
, Item_Id
)
2437 and then not Appears_In
(Outputs
, Item_Id
)
2440 ("global item & cannot have mode In_Out or Output",
2444 (Fix_Msg
(Subp_Id
, "\item already appears as input of "
2445 & "subprogram &"), Item
, Context
);
2447 -- Stop the traversal once an error has been detected
2453 Context
:= Scope
(Context
);
2455 end Check_Mode_Restriction_In_Enclosing_Context
;
2457 ----------------------------------------
2458 -- Check_Mode_Restriction_In_Function --
2459 ----------------------------------------
2461 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
) is
2463 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
2465 ("global mode & is not applicable to functions", Mode
);
2467 end Check_Mode_Restriction_In_Function
;
2475 -- Start of processing for Analyze_Global_List
2478 if Nkind
(List
) = N_Null
then
2479 Set_Analyzed
(List
);
2481 -- Single global item declaration
2483 elsif Nkind_In
(List
, N_Expanded_Name
,
2485 N_Selected_Component
)
2487 Analyze_Global_Item
(List
, Global_Mode
);
2489 -- Simple global list or moded global list declaration
2491 elsif Nkind
(List
) = N_Aggregate
then
2492 Set_Analyzed
(List
);
2494 -- The declaration of a simple global list appear as a collection
2497 if Present
(Expressions
(List
)) then
2498 if Present
(Component_Associations
(List
)) then
2500 ("cannot mix moded and non-moded global lists", List
);
2503 Item
:= First
(Expressions
(List
));
2504 while Present
(Item
) loop
2505 Analyze_Global_Item
(Item
, Global_Mode
);
2509 -- The declaration of a moded global list appears as a collection
2510 -- of component associations where individual choices denote
2513 elsif Present
(Component_Associations
(List
)) then
2514 if Present
(Expressions
(List
)) then
2516 ("cannot mix moded and non-moded global lists", List
);
2519 Assoc
:= First
(Component_Associations
(List
));
2520 while Present
(Assoc
) loop
2521 Mode
:= First
(Choices
(Assoc
));
2523 if Nkind
(Mode
) = N_Identifier
then
2524 if Chars
(Mode
) = Name_In_Out
then
2525 Check_Duplicate_Mode
(Mode
, In_Out_Seen
);
2526 Check_Mode_Restriction_In_Function
(Mode
);
2528 elsif Chars
(Mode
) = Name_Input
then
2529 Check_Duplicate_Mode
(Mode
, Input_Seen
);
2531 elsif Chars
(Mode
) = Name_Output
then
2532 Check_Duplicate_Mode
(Mode
, Output_Seen
);
2533 Check_Mode_Restriction_In_Function
(Mode
);
2535 elsif Chars
(Mode
) = Name_Proof_In
then
2536 Check_Duplicate_Mode
(Mode
, Proof_Seen
);
2539 SPARK_Msg_N
("invalid mode selector", Mode
);
2543 SPARK_Msg_N
("invalid mode selector", Mode
);
2546 -- Items in a moded list appear as a collection of
2547 -- expressions. Reuse the existing machinery to analyze
2551 (List
=> Expression
(Assoc
),
2552 Global_Mode
=> Chars
(Mode
));
2560 raise Program_Error
;
2563 -- Any other attempt to declare a global item is illegal. This is a
2564 -- syntax error, always report.
2567 Error_Msg_N
("malformed global list", List
);
2569 end Analyze_Global_List
;
2573 Items
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
2575 Restore_Scope
: Boolean := False;
2577 -- Start of processing for Analyze_Global_In_Decl_Part
2580 -- Do not analyze the pragma multiple times
2582 if Is_Analyzed_Pragma
(N
) then
2586 -- There is nothing to be done for a null global list
2588 if Nkind
(Items
) = N_Null
then
2589 Set_Analyzed
(Items
);
2591 -- Analyze the various forms of global lists and items. Note that some
2592 -- of these may be malformed in which case the analysis emits error
2596 -- When pragma [Refined_]Global appears on a single concurrent type,
2597 -- it is relocated to the anonymous object.
2599 if Is_Single_Concurrent_Object
(Spec_Id
) then
2602 -- Ensure that the formal parameters are visible when processing an
2603 -- item. This falls out of the general rule of aspects pertaining to
2604 -- subprogram declarations.
2606 elsif not In_Open_Scopes
(Spec_Id
) then
2607 Restore_Scope
:= True;
2608 Push_Scope
(Spec_Id
);
2610 if Ekind
(Spec_Id
) = E_Task_Type
then
2611 if Has_Discriminants
(Spec_Id
) then
2612 Install_Discriminants
(Spec_Id
);
2615 elsif Is_Generic_Subprogram
(Spec_Id
) then
2616 Install_Generic_Formals
(Spec_Id
);
2619 Install_Formals
(Spec_Id
);
2623 Analyze_Global_List
(Items
);
2625 if Restore_Scope
then
2630 -- Ensure that a state and a corresponding constituent do not appear
2631 -- together in pragma [Refined_]Global.
2633 Check_State_And_Constituent_Use
2634 (States
=> States_Seen
,
2635 Constits
=> Constits_Seen
,
2638 Set_Is_Analyzed_Pragma
(N
);
2639 end Analyze_Global_In_Decl_Part
;
2641 --------------------------------------------
2642 -- Analyze_Initial_Condition_In_Decl_Part --
2643 --------------------------------------------
2645 procedure Analyze_Initial_Condition_In_Decl_Part
(N
: Node_Id
) is
2646 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2647 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2648 Expr
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
2650 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2653 -- Do not analyze the pragma multiple times
2655 if Is_Analyzed_Pragma
(N
) then
2659 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2660 -- analysis of the pragma, the Ghost mode at point of declaration and
2661 -- point of analysis may not necessarely be the same. Use the mode in
2662 -- effect at the point of declaration.
2666 -- The expression is preanalyzed because it has not been moved to its
2667 -- final place yet. A direct analysis may generate side effects and this
2668 -- is not desired at this point.
2670 Preanalyze_Assert_Expression
(Expr
, Standard_Boolean
);
2671 Ghost_Mode
:= Save_Ghost_Mode
;
2673 Set_Is_Analyzed_Pragma
(N
);
2674 end Analyze_Initial_Condition_In_Decl_Part
;
2676 --------------------------------------
2677 -- Analyze_Initializes_In_Decl_Part --
2678 --------------------------------------
2680 procedure Analyze_Initializes_In_Decl_Part
(N
: Node_Id
) is
2681 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2682 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2684 Constits_Seen
: Elist_Id
:= No_Elist
;
2685 -- A list containing the entities of all constituents processed so far.
2686 -- It aids in detecting illegal usage of a state and a corresponding
2687 -- constituent in pragma Initializes.
2689 Items_Seen
: Elist_Id
:= No_Elist
;
2690 -- A list of all initialization items processed so far. This list is
2691 -- used to detect duplicate items.
2693 Non_Null_Seen
: Boolean := False;
2694 Null_Seen
: Boolean := False;
2695 -- Flags used to check the legality of a null initialization list
2697 States_And_Objs
: Elist_Id
:= No_Elist
;
2698 -- A list of all abstract states and objects declared in the visible
2699 -- declarations of the related package. This list is used to detect the
2700 -- legality of initialization items.
2702 States_Seen
: Elist_Id
:= No_Elist
;
2703 -- A list containing the entities of all states processed so far. It
2704 -- helps in detecting illegal usage of a state and a corresponding
2705 -- constituent in pragma Initializes.
2707 procedure Analyze_Initialization_Item
(Item
: Node_Id
);
2708 -- Verify the legality of a single initialization item
2710 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
);
2711 -- Verify the legality of a single initialization item followed by a
2712 -- list of input items.
2714 procedure Collect_States_And_Objects
;
2715 -- Inspect the visible declarations of the related package and gather
2716 -- the entities of all abstract states and objects in States_And_Objs.
2718 ---------------------------------
2719 -- Analyze_Initialization_Item --
2720 ---------------------------------
2722 procedure Analyze_Initialization_Item
(Item
: Node_Id
) is
2723 Item_Id
: Entity_Id
;
2726 -- Null initialization list
2728 if Nkind
(Item
) = N_Null
then
2730 SPARK_Msg_N
("multiple null initializations not allowed", Item
);
2732 elsif Non_Null_Seen
then
2734 ("cannot mix null and non-null initialization items", Item
);
2739 -- Initialization item
2742 Non_Null_Seen
:= True;
2746 ("cannot mix null and non-null initialization items", Item
);
2750 Resolve_State
(Item
);
2752 if Is_Entity_Name
(Item
) then
2753 Item_Id
:= Entity_Of
(Item
);
2755 if Ekind_In
(Item_Id
, E_Abstract_State
,
2759 -- The state or variable must be declared in the visible
2760 -- declarations of the package (SPARK RM 7.1.5(7)).
2762 if not Contains
(States_And_Objs
, Item_Id
) then
2763 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2765 ("initialization item & must appear in the visible "
2766 & "declarations of package %", Item
, Item_Id
);
2768 -- Detect a duplicate use of the same initialization item
2769 -- (SPARK RM 7.1.5(5)).
2771 elsif Contains
(Items_Seen
, Item_Id
) then
2772 SPARK_Msg_N
("duplicate initialization item", Item
);
2774 -- The item is legal, add it to the list of processed states
2778 Append_New_Elmt
(Item_Id
, Items_Seen
);
2780 if Ekind
(Item_Id
) = E_Abstract_State
then
2781 Append_New_Elmt
(Item_Id
, States_Seen
);
2784 if Present
(Encapsulating_State
(Item_Id
)) then
2785 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2789 -- The item references something that is not a state or object
2790 -- (SPARK RM 7.1.5(3)).
2794 ("initialization item must denote object or state", Item
);
2797 -- Some form of illegal construct masquerading as a name
2798 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2802 ("initialization item must denote object or state", Item
);
2805 end Analyze_Initialization_Item
;
2807 ---------------------------------------------
2808 -- Analyze_Initialization_Item_With_Inputs --
2809 ---------------------------------------------
2811 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
) is
2812 Inputs_Seen
: Elist_Id
:= No_Elist
;
2813 -- A list of all inputs processed so far. This list is used to detect
2814 -- duplicate uses of an input.
2816 Non_Null_Seen
: Boolean := False;
2817 Null_Seen
: Boolean := False;
2818 -- Flags used to check the legality of an input list
2820 procedure Analyze_Input_Item
(Input
: Node_Id
);
2821 -- Verify the legality of a single input item
2823 ------------------------
2824 -- Analyze_Input_Item --
2825 ------------------------
2827 procedure Analyze_Input_Item
(Input
: Node_Id
) is
2828 Input_Id
: Entity_Id
;
2829 Input_OK
: Boolean := True;
2834 if Nkind
(Input
) = N_Null
then
2837 ("multiple null initializations not allowed", Item
);
2839 elsif Non_Null_Seen
then
2841 ("cannot mix null and non-null initialization item", Item
);
2849 Non_Null_Seen
:= True;
2853 ("cannot mix null and non-null initialization item", Item
);
2857 Resolve_State
(Input
);
2859 if Is_Entity_Name
(Input
) then
2860 Input_Id
:= Entity_Of
(Input
);
2862 if Ekind_In
(Input_Id
, E_Abstract_State
,
2864 E_Generic_In_Out_Parameter
,
2865 E_Generic_In_Parameter
,
2871 -- The input cannot denote states or objects declared
2872 -- within the related package (SPARK RM 7.1.5(4)).
2874 if Within_Scope
(Input_Id
, Current_Scope
) then
2876 -- Do not consider generic formal parameters or their
2877 -- respective mappings to generic formals. Even though
2878 -- the formals appear within the scope of the package,
2879 -- it is allowed for an initialization item to depend
2880 -- on an input item.
2882 if Ekind_In
(Input_Id
, E_Generic_In_Out_Parameter
,
2883 E_Generic_In_Parameter
)
2887 elsif Ekind_In
(Input_Id
, E_Constant
, E_Variable
)
2888 and then Present
(Corresponding_Generic_Association
2889 (Declaration_Node
(Input_Id
)))
2895 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2897 ("input item & cannot denote a visible object or "
2898 & "state of package %", Input
, Input_Id
);
2902 -- Detect a duplicate use of the same input item
2903 -- (SPARK RM 7.1.5(5)).
2905 if Contains
(Inputs_Seen
, Input_Id
) then
2907 SPARK_Msg_N
("duplicate input item", Input
);
2910 -- Input is legal, add it to the list of processed inputs
2913 Append_New_Elmt
(Input_Id
, Inputs_Seen
);
2915 if Ekind
(Input_Id
) = E_Abstract_State
then
2916 Append_New_Elmt
(Input_Id
, States_Seen
);
2919 if Ekind_In
(Input_Id
, E_Abstract_State
,
2922 and then Present
(Encapsulating_State
(Input_Id
))
2924 Append_New_Elmt
(Input_Id
, Constits_Seen
);
2928 -- The input references something that is not a state or an
2929 -- object (SPARK RM 7.1.5(3)).
2933 ("input item must denote object or state", Input
);
2936 -- Some form of illegal construct masquerading as a name
2937 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2941 ("input item must denote object or state", Input
);
2944 end Analyze_Input_Item
;
2948 Inputs
: constant Node_Id
:= Expression
(Item
);
2952 Name_Seen
: Boolean := False;
2953 -- A flag used to detect multiple item names
2955 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2958 -- Inspect the name of an item with inputs
2960 Elmt
:= First
(Choices
(Item
));
2961 while Present
(Elmt
) loop
2963 SPARK_Msg_N
("only one item allowed in initialization", Elmt
);
2966 Analyze_Initialization_Item
(Elmt
);
2972 -- Multiple input items appear as an aggregate
2974 if Nkind
(Inputs
) = N_Aggregate
then
2975 if Present
(Expressions
(Inputs
)) then
2976 Input
:= First
(Expressions
(Inputs
));
2977 while Present
(Input
) loop
2978 Analyze_Input_Item
(Input
);
2983 if Present
(Component_Associations
(Inputs
)) then
2985 ("inputs must appear in named association form", Inputs
);
2988 -- Single input item
2991 Analyze_Input_Item
(Inputs
);
2993 end Analyze_Initialization_Item_With_Inputs
;
2995 --------------------------------
2996 -- Collect_States_And_Objects --
2997 --------------------------------
2999 procedure Collect_States_And_Objects
is
3000 Pack_Spec
: constant Node_Id
:= Specification
(Pack_Decl
);
3004 -- Collect the abstract states defined in the package (if any)
3006 if Present
(Abstract_States
(Pack_Id
)) then
3007 States_And_Objs
:= New_Copy_Elist
(Abstract_States
(Pack_Id
));
3010 -- Collect all objects the appear in the visible declarations of the
3013 if Present
(Visible_Declarations
(Pack_Spec
)) then
3014 Decl
:= First
(Visible_Declarations
(Pack_Spec
));
3015 while Present
(Decl
) loop
3016 if Comes_From_Source
(Decl
)
3017 and then Nkind
(Decl
) = N_Object_Declaration
3019 Append_New_Elmt
(Defining_Entity
(Decl
), States_And_Objs
);
3025 end Collect_States_And_Objects
;
3029 Inits
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
3032 -- Start of processing for Analyze_Initializes_In_Decl_Part
3035 -- Do not analyze the pragma multiple times
3037 if Is_Analyzed_Pragma
(N
) then
3041 -- Nothing to do when the initialization list is empty
3043 if Nkind
(Inits
) = N_Null
then
3047 -- Single and multiple initialization clauses appear as an aggregate. If
3048 -- this is not the case, then either the parser or the analysis of the
3049 -- pragma failed to produce an aggregate.
3051 pragma Assert
(Nkind
(Inits
) = N_Aggregate
);
3053 -- Initialize the various lists used during analysis
3055 Collect_States_And_Objects
;
3057 if Present
(Expressions
(Inits
)) then
3058 Init
:= First
(Expressions
(Inits
));
3059 while Present
(Init
) loop
3060 Analyze_Initialization_Item
(Init
);
3065 if Present
(Component_Associations
(Inits
)) then
3066 Init
:= First
(Component_Associations
(Inits
));
3067 while Present
(Init
) loop
3068 Analyze_Initialization_Item_With_Inputs
(Init
);
3073 -- Ensure that a state and a corresponding constituent do not appear
3074 -- together in pragma Initializes.
3076 Check_State_And_Constituent_Use
3077 (States
=> States_Seen
,
3078 Constits
=> Constits_Seen
,
3081 Set_Is_Analyzed_Pragma
(N
);
3082 end Analyze_Initializes_In_Decl_Part
;
3084 ---------------------
3085 -- Analyze_Part_Of --
3086 ---------------------
3088 procedure Analyze_Part_Of
3090 Item_Id
: Entity_Id
;
3092 Encap_Id
: out Entity_Id
;
3093 Legal
: out Boolean)
3095 Encap_Typ
: Entity_Id
;
3096 Item_Decl
: Node_Id
;
3097 Pack_Id
: Entity_Id
;
3098 Placement
: State_Space_Kind
;
3099 Parent_Unit
: Entity_Id
;
3102 -- Assume that the indicator is illegal
3107 if Nkind_In
(Encap
, N_Expanded_Name
,
3109 N_Selected_Component
)
3112 Resolve_State
(Encap
);
3114 Encap_Id
:= Entity
(Encap
);
3116 -- The encapsulator is an abstract state
3118 if Ekind
(Encap_Id
) = E_Abstract_State
then
3121 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
3123 elsif Is_Single_Concurrent_Object
(Encap_Id
) then
3126 -- Otherwise the encapsulator is not a legal choice
3130 ("indicator Part_Of must denote abstract state, single "
3131 & "protected type or single task type", Encap
);
3135 -- This is a syntax error, always report
3139 ("indicator Part_Of must denote abstract state, single protected "
3140 & "type or single task type", Encap
);
3144 -- Catch a case where indicator Part_Of denotes the abstract view of a
3145 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3147 if From_Limited_With
(Encap_Id
)
3148 and then Present
(Non_Limited_View
(Encap_Id
))
3149 and then Ekind
(Non_Limited_View
(Encap_Id
)) = E_Variable
3151 SPARK_Msg_N
("indicator Part_Of must denote abstract state", Encap
);
3152 SPARK_Msg_N
("\& denotes abstract view of object", Encap
);
3156 -- The encapsulator is an abstract state
3158 if Ekind
(Encap_Id
) = E_Abstract_State
then
3160 -- Determine where the object, package instantiation or state lives
3161 -- with respect to the enclosing packages or package bodies.
3163 Find_Placement_In_State_Space
3164 (Item_Id
=> Item_Id
,
3165 Placement
=> Placement
,
3166 Pack_Id
=> Pack_Id
);
3168 -- The item appears in a non-package construct with a declarative
3169 -- part (subprogram, block, etc). As such, the item is not allowed
3170 -- to be a part of an encapsulating state because the item is not
3173 if Placement
= Not_In_Package
then
3175 ("indicator Part_Of cannot appear in this context "
3176 & "(SPARK RM 7.2.6(5))", Indic
);
3177 Error_Msg_Name_1
:= Chars
(Scope
(Encap_Id
));
3179 ("\& is not part of the hidden state of package %",
3182 -- The item appears in the visible state space of some package. In
3183 -- general this scenario does not warrant Part_Of except when the
3184 -- package is a private child unit and the encapsulating state is
3185 -- declared in a parent unit or a public descendant of that parent
3188 elsif Placement
= Visible_State_Space
then
3189 if Is_Child_Unit
(Pack_Id
)
3190 and then Is_Private_Descendant
(Pack_Id
)
3192 -- A variable or state abstraction which is part of the visible
3193 -- state of a private child unit (or one of its public
3194 -- descendants) must have its Part_Of indicator specified. The
3195 -- Part_Of indicator must denote a state abstraction declared
3196 -- by either the parent unit of the private unit or by a public
3197 -- descendant of that parent unit.
3199 -- Find nearest private ancestor (which can be the current unit
3202 Parent_Unit
:= Pack_Id
;
3203 while Present
(Parent_Unit
) loop
3206 (Parent
(Unit_Declaration_Node
(Parent_Unit
)));
3207 Parent_Unit
:= Scope
(Parent_Unit
);
3210 Parent_Unit
:= Scope
(Parent_Unit
);
3212 if not Is_Child_Or_Sibling
(Pack_Id
, Scope
(Encap_Id
)) then
3214 ("indicator Part_Of must denote abstract state or public "
3215 & "descendant of & (SPARK RM 7.2.6(3))",
3216 Indic
, Parent_Unit
);
3218 elsif Scope
(Encap_Id
) = Parent_Unit
3220 (Is_Ancestor_Package
(Parent_Unit
, Scope
(Encap_Id
))
3221 and then not Is_Private_Descendant
(Scope
(Encap_Id
)))
3227 ("indicator Part_Of must denote abstract state or public "
3228 & "descendant of & (SPARK RM 7.2.6(3))",
3229 Indic
, Parent_Unit
);
3232 -- Indicator Part_Of is not needed when the related package is not
3233 -- a private child unit or a public descendant thereof.
3237 ("indicator Part_Of cannot appear in this context "
3238 & "(SPARK RM 7.2.6(5))", Indic
);
3239 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3241 ("\& is declared in the visible part of package %",
3245 -- When the item appears in the private state space of a package, the
3246 -- encapsulating state must be declared in the same package.
3248 elsif Placement
= Private_State_Space
then
3249 if Scope
(Encap_Id
) /= Pack_Id
then
3251 ("indicator Part_Of must designate an abstract state of "
3252 & "package & (SPARK RM 7.2.6(2))", Indic
, Pack_Id
);
3253 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3255 ("\& is declared in the private part of package %",
3259 -- Items declared in the body state space of a package do not need
3260 -- Part_Of indicators as the refinement has already been seen.
3264 ("indicator Part_Of cannot appear in this context "
3265 & "(SPARK RM 7.2.6(5))", Indic
);
3267 if Scope
(Encap_Id
) = Pack_Id
then
3268 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3270 ("\& is declared in the body of package %", Indic
, Item_Id
);
3274 -- The encapsulator is a single concurrent type
3277 Encap_Typ
:= Etype
(Encap_Id
);
3279 -- Only abstract states and variables can act as constituents of an
3280 -- encapsulating single concurrent type.
3282 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
3285 -- The constituent is a constant
3287 elsif Ekind
(Item_Id
) = E_Constant
then
3288 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3290 (Fix_Msg
(Encap_Typ
, "consant & cannot act as constituent of "
3291 & "single protected type %"), Indic
, Item_Id
);
3293 -- The constituent is a package instantiation
3296 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3298 (Fix_Msg
(Encap_Typ
, "package instantiation & cannot act as "
3299 & "constituent of single protected type %"), Indic
, Item_Id
);
3302 -- When the item denotes an abstract state of a nested package, use
3303 -- the declaration of the package to detect proper placement.
3308 -- with Abstract_State => (State with Part_Of => T)
3310 if Ekind
(Item_Id
) = E_Abstract_State
then
3311 Item_Decl
:= Unit_Declaration_Node
(Scope
(Item_Id
));
3313 Item_Decl
:= Declaration_Node
(Item_Id
);
3316 -- Both the item and its encapsulating single concurrent type must
3317 -- appear in the same declarative region (SPARK RM 9.3). Note that
3318 -- privacy is ignored.
3320 if Parent
(Item_Decl
) /= Parent
(Declaration_Node
(Encap_Id
)) then
3321 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3323 (Fix_Msg
(Encap_Typ
, "constituent & must be declared "
3324 & "immediately within the same region as single protected "
3325 & "type %"), Indic
, Item_Id
);
3330 end Analyze_Part_Of
;
3332 ----------------------------------
3333 -- Analyze_Part_Of_In_Decl_Part --
3334 ----------------------------------
3336 procedure Analyze_Part_Of_In_Decl_Part
3338 Freeze_Id
: Entity_Id
:= Empty
)
3340 Encap
: constant Node_Id
:=
3341 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
3342 Errors
: constant Nat
:= Serious_Errors_Detected
;
3343 Var_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
3344 Var_Id
: constant Entity_Id
:= Defining_Entity
(Var_Decl
);
3345 Constits
: Elist_Id
;
3346 Encap_Id
: Entity_Id
;
3350 -- Detect any discrepancies between the placement of the variable with
3351 -- respect to general state space and the encapsulating state or single
3358 Encap_Id
=> Encap_Id
,
3361 -- The Part_Of indicator turns the variable into a constituent of the
3362 -- encapsulating state or single concurrent type.
3365 pragma Assert
(Present
(Encap_Id
));
3366 Constits
:= Part_Of_Constituents
(Encap_Id
);
3368 if No
(Constits
) then
3369 Constits
:= New_Elmt_List
;
3370 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
3373 Append_Elmt
(Var_Id
, Constits
);
3374 Set_Encapsulating_State
(Var_Id
, Encap_Id
);
3377 -- Emit a clarification message when the encapsulator is undefined,
3378 -- possibly due to contract "freezing".
3380 if Errors
/= Serious_Errors_Detected
3381 and then Present
(Freeze_Id
)
3382 and then Has_Undefined_Reference
(Encap
)
3384 Contract_Freeze_Error
(Var_Id
, Freeze_Id
);
3386 end Analyze_Part_Of_In_Decl_Part
;
3388 --------------------
3389 -- Analyze_Pragma --
3390 --------------------
3392 procedure Analyze_Pragma
(N
: Node_Id
) is
3393 Loc
: constant Source_Ptr
:= Sloc
(N
);
3394 Prag_Id
: Pragma_Id
;
3397 -- Name of the source pragma, or name of the corresponding aspect for
3398 -- pragmas which originate in a source aspect. In the latter case, the
3399 -- name may be different from the pragma name.
3401 Pragma_Exit
: exception;
3402 -- This exception is used to exit pragma processing completely. It
3403 -- is used when an error is detected, and no further processing is
3404 -- required. It is also used if an earlier error has left the tree in
3405 -- a state where the pragma should not be processed.
3408 -- Number of pragma argument associations
3414 -- First four pragma arguments (pragma argument association nodes, or
3415 -- Empty if the corresponding argument does not exist).
3417 type Name_List
is array (Natural range <>) of Name_Id
;
3418 type Args_List
is array (Natural range <>) of Node_Id
;
3419 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3421 -----------------------
3422 -- Local Subprograms --
3423 -----------------------
3425 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
);
3426 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3427 -- get the given string argument, and place it in Name_Buffer, adding
3428 -- leading and trailing asterisks if they are not already present. The
3429 -- caller has already checked that Arg is a static string expression.
3431 procedure Ada_2005_Pragma
;
3432 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3433 -- Ada 95 mode, these are implementation defined pragmas, so should be
3434 -- caught by the No_Implementation_Pragmas restriction.
3436 procedure Ada_2012_Pragma
;
3437 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3438 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3439 -- should be caught by the No_Implementation_Pragmas restriction.
3441 procedure Analyze_Depends_Global
3442 (Spec_Id
: out Entity_Id
;
3443 Subp_Decl
: out Node_Id
;
3444 Legal
: out Boolean);
3445 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3446 -- legality of the placement and related context of the pragma. Spec_Id
3447 -- is the entity of the related subprogram. Subp_Decl is the declaration
3448 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3450 procedure Analyze_If_Present
(Id
: Pragma_Id
);
3451 -- Inspect the remainder of the list containing pragma N and look for
3452 -- a pragma that matches Id. If found, analyze the pragma.
3454 procedure Analyze_Pre_Post_Condition
;
3455 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3457 procedure Analyze_Refined_Depends_Global_Post
3458 (Spec_Id
: out Entity_Id
;
3459 Body_Id
: out Entity_Id
;
3460 Legal
: out Boolean);
3461 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3462 -- Refined_Global and Refined_Post. Verify the legality of the placement
3463 -- and related context of the pragma. Spec_Id is the entity of the
3464 -- related subprogram. Body_Id is the entity of the subprogram body.
3465 -- Flag Legal is set when the pragma is legal.
3467 procedure Check_Ada_83_Warning
;
3468 -- Issues a warning message for the current pragma if operating in Ada
3469 -- 83 mode (used for language pragmas that are not a standard part of
3470 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3473 procedure Check_Arg_Count
(Required
: Nat
);
3474 -- Check argument count for pragma is equal to given parameter. If not,
3475 -- then issue an error message and raise Pragma_Exit.
3477 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3478 -- Arg which can either be a pragma argument association, in which case
3479 -- the check is applied to the expression of the association or an
3480 -- expression directly.
3482 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
);
3483 -- Check that an argument has the right form for an EXTERNAL_NAME
3484 -- parameter of an extended import/export pragma. The rule is that the
3485 -- name must be an identifier or string literal (in Ada 83 mode) or a
3486 -- static string expression (in Ada 95 mode).
3488 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
);
3489 -- Check the specified argument Arg to make sure that it is an
3490 -- identifier. If not give error and raise Pragma_Exit.
3492 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
);
3493 -- Check the specified argument Arg to make sure that it is an integer
3494 -- literal. If not give error and raise Pragma_Exit.
3496 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
);
3497 -- Check the specified argument Arg to make sure that it has the proper
3498 -- syntactic form for a local name and meets the semantic requirements
3499 -- for a local name. The local name is analyzed as part of the
3500 -- processing for this call. In addition, the local name is required
3501 -- to represent an entity at the library level.
3503 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
);
3504 -- Check the specified argument Arg to make sure that it has the proper
3505 -- syntactic form for a local name and meets the semantic requirements
3506 -- for a local name. The local name is analyzed as part of the
3507 -- processing for this call.
3509 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
);
3510 -- Check the specified argument Arg to make sure that it is a valid
3511 -- locking policy name. If not give error and raise Pragma_Exit.
3513 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
);
3514 -- Check the specified argument Arg to make sure that it is a valid
3515 -- elaboration policy name. If not give error and raise Pragma_Exit.
3517 procedure Check_Arg_Is_One_Of
3520 procedure Check_Arg_Is_One_Of
3522 N1
, N2
, N3
: Name_Id
);
3523 procedure Check_Arg_Is_One_Of
3525 N1
, N2
, N3
, N4
: Name_Id
);
3526 procedure Check_Arg_Is_One_Of
3528 N1
, N2
, N3
, N4
, N5
: Name_Id
);
3529 -- Check the specified argument Arg to make sure that it is an
3530 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3531 -- present). If not then give error and raise Pragma_Exit.
3533 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
);
3534 -- Check the specified argument Arg to make sure that it is a valid
3535 -- queuing policy name. If not give error and raise Pragma_Exit.
3537 procedure Check_Arg_Is_OK_Static_Expression
3539 Typ
: Entity_Id
:= Empty
);
3540 -- Check the specified argument Arg to make sure that it is a static
3541 -- expression of the given type (i.e. it will be analyzed and resolved
3542 -- using this type, which can be any valid argument to Resolve, e.g.
3543 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3544 -- Typ is left Empty, then any static expression is allowed. Includes
3545 -- checking that the argument does not raise Constraint_Error.
3547 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
);
3548 -- Check the specified argument Arg to make sure that it is a valid task
3549 -- dispatching policy name. If not give error and raise Pragma_Exit.
3551 procedure Check_Arg_Order
(Names
: Name_List
);
3552 -- Checks for an instance of two arguments with identifiers for the
3553 -- current pragma which are not in the sequence indicated by Names,
3554 -- and if so, generates a fatal message about bad order of arguments.
3556 procedure Check_At_Least_N_Arguments
(N
: Nat
);
3557 -- Check there are at least N arguments present
3559 procedure Check_At_Most_N_Arguments
(N
: Nat
);
3560 -- Check there are no more than N arguments present
3562 procedure Check_Component
3565 In_Variant_Part
: Boolean := False);
3566 -- Examine an Unchecked_Union component for correct use of per-object
3567 -- constrained subtypes, and for restrictions on finalizable components.
3568 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3569 -- should be set when Comp comes from a record variant.
3571 procedure Check_Duplicate_Pragma
(E
: Entity_Id
);
3572 -- Check if a rep item of the same name as the current pragma is already
3573 -- chained as a rep pragma to the given entity. If so give a message
3574 -- about the duplicate, and then raise Pragma_Exit so does not return.
3575 -- Note that if E is a type, then this routine avoids flagging a pragma
3576 -- which applies to a parent type from which E is derived.
3578 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
);
3579 -- Nam is an N_String_Literal node containing the external name set by
3580 -- an Import or Export pragma (or extended Import or Export pragma).
3581 -- This procedure checks for possible duplications if this is the export
3582 -- case, and if found, issues an appropriate error message.
3584 procedure Check_Expr_Is_OK_Static_Expression
3586 Typ
: Entity_Id
:= Empty
);
3587 -- Check the specified expression Expr to make sure that it is a static
3588 -- expression of the given type (i.e. it will be analyzed and resolved
3589 -- using this type, which can be any valid argument to Resolve, e.g.
3590 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3591 -- Typ is left Empty, then any static expression is allowed. Includes
3592 -- checking that the expression does not raise Constraint_Error.
3594 procedure Check_First_Subtype
(Arg
: Node_Id
);
3595 -- Checks that Arg, whose expression is an entity name, references a
3598 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3599 -- Checks that the given argument has an identifier, and if so, requires
3600 -- it to match the given identifier name. If there is no identifier, or
3601 -- a non-matching identifier, then an error message is given and
3602 -- Pragma_Exit is raised.
3604 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
);
3605 -- Checks that the given argument has an identifier, and if so, requires
3606 -- it to match one of the given identifier names. If there is no
3607 -- identifier, or a non-matching identifier, then an error message is
3608 -- given and Pragma_Exit is raised.
3610 procedure Check_In_Main_Program
;
3611 -- Common checks for pragmas that appear within a main program
3612 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3614 procedure Check_Interrupt_Or_Attach_Handler
;
3615 -- Common processing for first argument of pragma Interrupt_Handler or
3616 -- pragma Attach_Handler.
3618 procedure Check_Loop_Pragma_Placement
;
3619 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3620 -- appear immediately within a construct restricted to loops, and that
3621 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3623 procedure Check_Is_In_Decl_Part_Or_Package_Spec
;
3624 -- Check that pragma appears in a declarative part, or in a package
3625 -- specification, i.e. that it does not occur in a statement sequence
3628 procedure Check_No_Identifier
(Arg
: Node_Id
);
3629 -- Checks that the given argument does not have an identifier. If
3630 -- an identifier is present, then an error message is issued, and
3631 -- Pragma_Exit is raised.
3633 procedure Check_No_Identifiers
;
3634 -- Checks that none of the arguments to the pragma has an identifier.
3635 -- If any argument has an identifier, then an error message is issued,
3636 -- and Pragma_Exit is raised.
3638 procedure Check_No_Link_Name
;
3639 -- Checks that no link name is specified
3641 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3642 -- Checks if the given argument has an identifier, and if so, requires
3643 -- it to match the given identifier name. If there is a non-matching
3644 -- identifier, then an error message is given and Pragma_Exit is raised.
3646 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String);
3647 -- Checks if the given argument has an identifier, and if so, requires
3648 -- it to match the given identifier name. If there is a non-matching
3649 -- identifier, then an error message is given and Pragma_Exit is raised.
3650 -- In this version of the procedure, the identifier name is given as
3651 -- a string with lower case letters.
3653 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
);
3654 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3655 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3656 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3657 -- is an OK static boolean expression. Emit an error if this is not the
3660 procedure Check_Static_Constraint
(Constr
: Node_Id
);
3661 -- Constr is a constraint from an N_Subtype_Indication node from a
3662 -- component constraint in an Unchecked_Union type. This routine checks
3663 -- that the constraint is static as required by the restrictions for
3666 procedure Check_Valid_Configuration_Pragma
;
3667 -- Legality checks for placement of a configuration pragma
3669 procedure Check_Valid_Library_Unit_Pragma
;
3670 -- Legality checks for library unit pragmas. A special case arises for
3671 -- pragmas in generic instances that come from copies of the original
3672 -- library unit pragmas in the generic templates. In the case of other
3673 -- than library level instantiations these can appear in contexts which
3674 -- would normally be invalid (they only apply to the original template
3675 -- and to library level instantiations), and they are simply ignored,
3676 -- which is implemented by rewriting them as null statements.
3678 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
);
3679 -- Check an Unchecked_Union variant for lack of nested variants and
3680 -- presence of at least one component. UU_Typ is the related Unchecked_
3683 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
);
3684 -- Subsidiary routine to the processing of pragmas Abstract_State,
3685 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3686 -- Refined_Global and Refined_State. Transform argument Arg into
3687 -- an aggregate if not one already. N_Null is never transformed.
3688 -- Arg may denote an aspect specification or a pragma argument
3691 procedure Error_Pragma
(Msg
: String);
3692 pragma No_Return
(Error_Pragma
);
3693 -- Outputs error message for current pragma. The message contains a %
3694 -- that will be replaced with the pragma name, and the flag is placed
3695 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3696 -- calls Fix_Error (see spec of that procedure for details).
3698 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
);
3699 pragma No_Return
(Error_Pragma_Arg
);
3700 -- Outputs error message for current pragma. The message may contain
3701 -- a % that will be replaced with the pragma name. The parameter Arg
3702 -- may either be a pragma argument association, in which case the flag
3703 -- is placed on the expression of this association, or an expression,
3704 -- in which case the flag is placed directly on the expression. The
3705 -- message is placed using Error_Msg_N, so the message may also contain
3706 -- an & insertion character which will reference the given Arg value.
3707 -- After placing the message, Pragma_Exit is raised. Note: this routine
3708 -- calls Fix_Error (see spec of that procedure for details).
3710 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
);
3711 pragma No_Return
(Error_Pragma_Arg
);
3712 -- Similar to above form of Error_Pragma_Arg except that two messages
3713 -- are provided, the second is a continuation comment starting with \.
3715 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
);
3716 pragma No_Return
(Error_Pragma_Arg_Ident
);
3717 -- Outputs error message for current pragma. The message may contain a %
3718 -- that will be replaced with the pragma name. The parameter Arg must be
3719 -- a pragma argument association with a non-empty identifier (i.e. its
3720 -- Chars field must be set), and the error message is placed on the
3721 -- identifier. The message is placed using Error_Msg_N so the message
3722 -- may also contain an & insertion character which will reference
3723 -- the identifier. After placing the message, Pragma_Exit is raised.
3724 -- Note: this routine calls Fix_Error (see spec of that procedure for
3727 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
);
3728 pragma No_Return
(Error_Pragma_Ref
);
3729 -- Outputs error message for current pragma. The message may contain
3730 -- a % that will be replaced with the pragma name. The parameter Ref
3731 -- must be an entity whose name can be referenced by & and sloc by #.
3732 -- After placing the message, Pragma_Exit is raised. Note: this routine
3733 -- calls Fix_Error (see spec of that procedure for details).
3735 function Find_Lib_Unit_Name
return Entity_Id
;
3736 -- Used for a library unit pragma to find the entity to which the
3737 -- library unit pragma applies, returns the entity found.
3739 procedure Find_Program_Unit_Name
(Id
: Node_Id
);
3740 -- If the pragma is a compilation unit pragma, the id must denote the
3741 -- compilation unit in the same compilation, and the pragma must appear
3742 -- in the list of preceding or trailing pragmas. If it is a program
3743 -- unit pragma that is not a compilation unit pragma, then the
3744 -- identifier must be visible.
3746 function Find_Unique_Parameterless_Procedure
3748 Arg
: Node_Id
) return Entity_Id
;
3749 -- Used for a procedure pragma to find the unique parameterless
3750 -- procedure identified by Name, returns it if it exists, otherwise
3751 -- errors out and uses Arg as the pragma argument for the message.
3753 function Fix_Error
(Msg
: String) return String;
3754 -- This is called prior to issuing an error message. Msg is the normal
3755 -- error message issued in the pragma case. This routine checks for the
3756 -- case of a pragma coming from an aspect in the source, and returns a
3757 -- message suitable for the aspect case as follows:
3759 -- Each substring "pragma" is replaced by "aspect"
3761 -- If "argument of" is at the start of the error message text, it is
3762 -- replaced by "entity for".
3764 -- If "argument" is at the start of the error message text, it is
3765 -- replaced by "entity".
3767 -- So for example, "argument of pragma X must be discrete type"
3768 -- returns "entity for aspect X must be a discrete type".
3770 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3771 -- be different from the pragma name). If the current pragma results
3772 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3773 -- original pragma name.
3775 procedure Gather_Associations
3777 Args
: out Args_List
);
3778 -- This procedure is used to gather the arguments for a pragma that
3779 -- permits arbitrary ordering of parameters using the normal rules
3780 -- for named and positional parameters. The Names argument is a list
3781 -- of Name_Id values that corresponds to the allowed pragma argument
3782 -- association identifiers in order. The result returned in Args is
3783 -- a list of corresponding expressions that are the pragma arguments.
3784 -- Note that this is a list of expressions, not of pragma argument
3785 -- associations (Gather_Associations has completely checked all the
3786 -- optional identifiers when it returns). An entry in Args is Empty
3787 -- on return if the corresponding argument is not present.
3789 procedure GNAT_Pragma
;
3790 -- Called for all GNAT defined pragmas to check the relevant restriction
3791 -- (No_Implementation_Pragmas).
3793 function Is_Before_First_Decl
3794 (Pragma_Node
: Node_Id
;
3795 Decls
: List_Id
) return Boolean;
3796 -- Return True if Pragma_Node is before the first declarative item in
3797 -- Decls where Decls is the list of declarative items.
3799 function Is_Configuration_Pragma
return Boolean;
3800 -- Determines if the placement of the current pragma is appropriate
3801 -- for a configuration pragma.
3803 function Is_In_Context_Clause
return Boolean;
3804 -- Returns True if pragma appears within the context clause of a unit,
3805 -- and False for any other placement (does not generate any messages).
3807 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean;
3808 -- Analyzes the argument, and determines if it is a static string
3809 -- expression, returns True if so, False if non-static or not String.
3810 -- A special case is that a string literal returns True in Ada 83 mode
3811 -- (which has no such thing as static string expressions). Note that
3812 -- the call analyzes its argument, so this cannot be used for the case
3813 -- where an identifier might not be declared.
3815 procedure Pragma_Misplaced
;
3816 pragma No_Return
(Pragma_Misplaced
);
3817 -- Issue fatal error message for misplaced pragma
3819 procedure Process_Atomic_Independent_Shared_Volatile
;
3820 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3821 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3822 -- and treated as being identical in effect to pragma Atomic.
3824 procedure Process_Compile_Time_Warning_Or_Error
;
3825 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3827 procedure Process_Convention
3828 (C
: out Convention_Id
;
3829 Ent
: out Entity_Id
);
3830 -- Common processing for Convention, Interface, Import and Export.
3831 -- Checks first two arguments of pragma, and sets the appropriate
3832 -- convention value in the specified entity or entities. On return
3833 -- C is the convention, Ent is the referenced entity.
3835 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
);
3836 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3837 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3839 procedure Process_Extended_Import_Export_Object_Pragma
3840 (Arg_Internal
: Node_Id
;
3841 Arg_External
: Node_Id
;
3842 Arg_Size
: Node_Id
);
3843 -- Common processing for the pragmas Import/Export_Object. The three
3844 -- arguments correspond to the three named parameters of the pragmas. An
3845 -- argument is empty if the corresponding parameter is not present in
3848 procedure Process_Extended_Import_Export_Internal_Arg
3849 (Arg_Internal
: Node_Id
:= Empty
);
3850 -- Common processing for all extended Import and Export pragmas. The
3851 -- argument is the pragma parameter for the Internal argument. If
3852 -- Arg_Internal is empty or inappropriate, an error message is posted.
3853 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3854 -- set to identify the referenced entity.
3856 procedure Process_Extended_Import_Export_Subprogram_Pragma
3857 (Arg_Internal
: Node_Id
;
3858 Arg_External
: Node_Id
;
3859 Arg_Parameter_Types
: Node_Id
;
3860 Arg_Result_Type
: Node_Id
:= Empty
;
3861 Arg_Mechanism
: Node_Id
;
3862 Arg_Result_Mechanism
: Node_Id
:= Empty
);
3863 -- Common processing for all extended Import and Export pragmas applying
3864 -- to subprograms. The caller omits any arguments that do not apply to
3865 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3866 -- only in the Import_Function and Export_Function cases). The argument
3867 -- names correspond to the allowed pragma association identifiers.
3869 procedure Process_Generic_List
;
3870 -- Common processing for Share_Generic and Inline_Generic
3872 procedure Process_Import_Or_Interface
;
3873 -- Common processing for Import or Interface
3875 procedure Process_Import_Predefined_Type
;
3876 -- Processing for completing a type with pragma Import. This is used
3877 -- to declare types that match predefined C types, especially for cases
3878 -- without corresponding Ada predefined type.
3880 type Inline_Status
is (Suppressed
, Disabled
, Enabled
);
3881 -- Inline status of a subprogram, indicated as follows:
3882 -- Suppressed: inlining is suppressed for the subprogram
3883 -- Disabled: no inlining is requested for the subprogram
3884 -- Enabled: inlining is requested/required for the subprogram
3886 procedure Process_Inline
(Status
: Inline_Status
);
3887 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3888 -- indicates the inline status specified by the pragma.
3890 procedure Process_Interface_Name
3891 (Subprogram_Def
: Entity_Id
;
3893 Link_Arg
: Node_Id
);
3894 -- Given the last two arguments of pragma Import, pragma Export, or
3895 -- pragma Interface_Name, performs validity checks and sets the
3896 -- Interface_Name field of the given subprogram entity to the
3897 -- appropriate external or link name, depending on the arguments given.
3898 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3899 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3900 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3901 -- nor Link_Arg is present, the interface name is set to the default
3902 -- from the subprogram name.
3904 procedure Process_Interrupt_Or_Attach_Handler
;
3905 -- Common processing for Interrupt and Attach_Handler pragmas
3907 procedure Process_Restrictions_Or_Restriction_Warnings
(Warn
: Boolean);
3908 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3909 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3910 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3911 -- is not set in the Restrictions case.
3913 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean);
3914 -- Common processing for Suppress and Unsuppress. The boolean parameter
3915 -- Suppress_Case is True for the Suppress case, and False for the
3918 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
);
3919 -- Subsidiary to the analysis of pragmas Independent[_Components].
3920 -- Record such a pragma N applied to entity E for future checks.
3922 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
);
3923 -- This procedure sets the Is_Exported flag for the given entity,
3924 -- checking that the entity was not previously imported. Arg is
3925 -- the argument that specified the entity. A check is also made
3926 -- for exporting inappropriate entities.
3928 procedure Set_Extended_Import_Export_External_Name
3929 (Internal_Ent
: Entity_Id
;
3930 Arg_External
: Node_Id
);
3931 -- Common processing for all extended import export pragmas. The first
3932 -- argument, Internal_Ent, is the internal entity, which has already
3933 -- been checked for validity by the caller. Arg_External is from the
3934 -- Import or Export pragma, and may be null if no External parameter
3935 -- was present. If Arg_External is present and is a non-null string
3936 -- (a null string is treated as the default), then the Interface_Name
3937 -- field of Internal_Ent is set appropriately.
3939 procedure Set_Imported
(E
: Entity_Id
);
3940 -- This procedure sets the Is_Imported flag for the given entity,
3941 -- checking that it is not previously exported or imported.
3943 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
);
3944 -- Mech is a parameter passing mechanism (see Import_Function syntax
3945 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3946 -- has the right form, and if not issues an error message. If the
3947 -- argument has the right form then the Mechanism field of Ent is
3948 -- set appropriately.
3950 procedure Set_Rational_Profile
;
3951 -- Activate the set of configuration pragmas and permissions that make
3952 -- up the Rational profile.
3954 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
);
3955 -- Activate the set of configuration pragmas and restrictions that make
3956 -- up the Profile. Profile must be either GNAT_Extended_Ravencar or
3957 -- Ravenscar. N is the corresponding pragma node, which is used for
3958 -- error messages on any constructs violating the profile.
3960 ----------------------------------
3961 -- Acquire_Warning_Match_String --
3962 ----------------------------------
3964 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
) is
3966 String_To_Name_Buffer
3967 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
3969 -- Add asterisk at start if not already there
3971 if Name_Len
> 0 and then Name_Buffer
(1) /= '*' then
3972 Name_Buffer
(2 .. Name_Len
+ 1) :=
3973 Name_Buffer
(1 .. Name_Len
);
3974 Name_Buffer
(1) := '*';
3975 Name_Len
:= Name_Len
+ 1;
3978 -- Add asterisk at end if not already there
3980 if Name_Buffer
(Name_Len
) /= '*' then
3981 Name_Len
:= Name_Len
+ 1;
3982 Name_Buffer
(Name_Len
) := '*';
3984 end Acquire_Warning_Match_String
;
3986 ---------------------
3987 -- Ada_2005_Pragma --
3988 ---------------------
3990 procedure Ada_2005_Pragma
is
3992 if Ada_Version
<= Ada_95
then
3993 Check_Restriction
(No_Implementation_Pragmas
, N
);
3995 end Ada_2005_Pragma
;
3997 ---------------------
3998 -- Ada_2012_Pragma --
3999 ---------------------
4001 procedure Ada_2012_Pragma
is
4003 if Ada_Version
<= Ada_2005
then
4004 Check_Restriction
(No_Implementation_Pragmas
, N
);
4006 end Ada_2012_Pragma
;
4008 ----------------------------
4009 -- Analyze_Depends_Global --
4010 ----------------------------
4012 procedure Analyze_Depends_Global
4013 (Spec_Id
: out Entity_Id
;
4014 Subp_Decl
: out Node_Id
;
4015 Legal
: out Boolean)
4018 -- Assume that the pragma is illegal
4025 Check_Arg_Count
(1);
4027 -- Ensure the proper placement of the pragma. Depends/Global must be
4028 -- associated with a subprogram declaration or a body that acts as a
4031 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4035 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4038 -- Generic subprogram
4040 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4043 -- Object declaration of a single concurrent type
4045 elsif Nkind
(Subp_Decl
) = N_Object_Declaration
then
4050 elsif Nkind
(Subp_Decl
) = N_Single_Task_Declaration
then
4053 -- Subprogram body acts as spec
4055 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4056 and then No
(Corresponding_Spec
(Subp_Decl
))
4060 -- Subprogram body stub acts as spec
4062 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4063 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
4067 -- Subprogram declaration
4069 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4074 elsif Nkind
(Subp_Decl
) = N_Task_Type_Declaration
then
4082 -- If we get here, then the pragma is legal
4085 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
4087 -- When the related context is an entry, the entry must belong to a
4088 -- protected unit (SPARK RM 6.1.4(6)).
4090 if Is_Entry_Declaration
(Spec_Id
)
4091 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
4096 -- When the related context is an anonymous object created for a
4097 -- simple concurrent type, the type must be a task
4098 -- (SPARK RM 6.1.4(6)).
4100 elsif Is_Single_Concurrent_Object
(Spec_Id
)
4101 and then Ekind
(Etype
(Spec_Id
)) /= E_Task_Type
4107 -- A pragma that applies to a Ghost entity becomes Ghost for the
4108 -- purposes of legality checks and removal of ignored Ghost code.
4110 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
4111 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4112 end Analyze_Depends_Global
;
4114 ------------------------
4115 -- Analyze_If_Present --
4116 ------------------------
4118 procedure Analyze_If_Present
(Id
: Pragma_Id
) is
4122 pragma Assert
(Is_List_Member
(N
));
4124 -- Inspect the declarations or statements following pragma N looking
4125 -- for another pragma whose Id matches the caller's request. If it is
4126 -- available, analyze it.
4129 while Present
(Stmt
) loop
4130 if Nkind
(Stmt
) = N_Pragma
and then Get_Pragma_Id
(Stmt
) = Id
then
4131 Analyze_Pragma
(Stmt
);
4134 -- The first source declaration or statement immediately following
4135 -- N ends the region where a pragma may appear.
4137 elsif Comes_From_Source
(Stmt
) then
4143 end Analyze_If_Present
;
4145 --------------------------------
4146 -- Analyze_Pre_Post_Condition --
4147 --------------------------------
4149 procedure Analyze_Pre_Post_Condition
is
4150 Prag_Iden
: constant Node_Id
:= Pragma_Identifier
(N
);
4151 Subp_Decl
: Node_Id
;
4152 Subp_Id
: Entity_Id
;
4154 Duplicates_OK
: Boolean := False;
4155 -- Flag set when a pre/postcondition allows multiple pragmas of the
4158 In_Body_OK
: Boolean := False;
4159 -- Flag set when a pre/postcondition is allowed to appear on a body
4160 -- even though the subprogram may have a spec.
4162 Is_Pre_Post
: Boolean := False;
4163 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4167 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4168 -- offer uniformity among the various kinds of pre/postconditions by
4169 -- rewriting the pragma identifier. This allows the retrieval of the
4170 -- original pragma name by routine Original_Aspect_Pragma_Name.
4172 if Comes_From_Source
(N
) then
4173 if Nam_In
(Pname
, Name_Pre
, Name_Pre_Class
) then
4174 Is_Pre_Post
:= True;
4175 Set_Class_Present
(N
, Pname
= Name_Pre_Class
);
4176 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Precondition
));
4178 elsif Nam_In
(Pname
, Name_Post
, Name_Post_Class
) then
4179 Is_Pre_Post
:= True;
4180 Set_Class_Present
(N
, Pname
= Name_Post_Class
);
4181 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Postcondition
));
4185 -- Determine the semantics with respect to duplicates and placement
4186 -- in a body. Pragmas Precondition and Postcondition were introduced
4187 -- before aspects and are not subject to the same aspect-like rules.
4189 if Nam_In
(Pname
, Name_Precondition
, Name_Postcondition
) then
4190 Duplicates_OK
:= True;
4196 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4197 -- argument without an identifier.
4200 Check_Arg_Count
(1);
4201 Check_No_Identifiers
;
4203 -- Pragmas Precondition and Postcondition have complex argument
4207 Check_At_Least_N_Arguments
(1);
4208 Check_At_Most_N_Arguments
(2);
4209 Check_Optional_Identifier
(Arg1
, Name_Check
);
4211 if Present
(Arg2
) then
4212 Check_Optional_Identifier
(Arg2
, Name_Message
);
4213 Preanalyze_Spec_Expression
4214 (Get_Pragma_Arg
(Arg2
), Standard_String
);
4218 -- For a pragma PPC in the extended main source unit, record enabled
4220 -- ??? nothing checks that the pragma is in the main source unit
4222 if Is_Checked
(N
) and then not Split_PPC
(N
) then
4223 Set_SCO_Pragma_Enabled
(Loc
);
4226 -- Ensure the proper placement of the pragma
4229 Find_Related_Declaration_Or_Body
4230 (N
, Do_Checks
=> not Duplicates_OK
);
4232 -- When a pre/postcondition pragma applies to an abstract subprogram,
4233 -- its original form must be an aspect with 'Class.
4235 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
4236 if not From_Aspect_Specification
(N
) then
4238 ("pragma % cannot be applied to abstract subprogram");
4240 elsif not Class_Present
(N
) then
4242 ("aspect % requires ''Class for abstract subprogram");
4245 -- Entry declaration
4247 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4250 -- Generic subprogram declaration
4252 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4257 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4258 and then (No
(Corresponding_Spec
(Subp_Decl
)) or In_Body_OK
)
4262 -- Subprogram body stub
4264 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4265 and then (No
(Corresponding_Spec_Of_Stub
(Subp_Decl
)) or In_Body_OK
)
4269 -- Subprogram declaration
4271 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4273 -- AI05-0230: When a pre/postcondition pragma applies to a null
4274 -- procedure, its original form must be an aspect with 'Class.
4276 if Nkind
(Specification
(Subp_Decl
)) = N_Procedure_Specification
4277 and then Null_Present
(Specification
(Subp_Decl
))
4278 and then From_Aspect_Specification
(N
)
4279 and then not Class_Present
(N
)
4281 Error_Pragma
("aspect % requires ''Class for null procedure");
4284 -- Otherwise the placement is illegal
4291 Subp_Id
:= Defining_Entity
(Subp_Decl
);
4293 -- Chain the pragma on the contract for further processing by
4294 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4296 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
4298 -- A pragma that applies to a Ghost entity becomes Ghost for the
4299 -- purposes of legality checks and removal of ignored Ghost code.
4301 Mark_Pragma_As_Ghost
(N
, Subp_Id
);
4303 -- Fully analyze the pragma when it appears inside an entry or
4304 -- subprogram body because it cannot benefit from forward references.
4306 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
4308 N_Subprogram_Body_Stub
)
4310 -- The legality checks of pragmas Precondition and Postcondition
4311 -- are affected by the SPARK mode in effect and the volatility of
4312 -- the context. Analyze all pragmas in a specific order.
4314 Analyze_If_Present
(Pragma_SPARK_Mode
);
4315 Analyze_If_Present
(Pragma_Volatile_Function
);
4316 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
4318 end Analyze_Pre_Post_Condition
;
4320 -----------------------------------------
4321 -- Analyze_Refined_Depends_Global_Post --
4322 -----------------------------------------
4324 procedure Analyze_Refined_Depends_Global_Post
4325 (Spec_Id
: out Entity_Id
;
4326 Body_Id
: out Entity_Id
;
4327 Legal
: out Boolean)
4329 Body_Decl
: Node_Id
;
4330 Spec_Decl
: Node_Id
;
4333 -- Assume that the pragma is illegal
4340 Check_Arg_Count
(1);
4341 Check_No_Identifiers
;
4343 -- Verify the placement of the pragma and check for duplicates. The
4344 -- pragma must apply to a subprogram body [stub].
4346 Body_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4350 if Nkind
(Body_Decl
) = N_Entry_Body
then
4355 elsif Nkind
(Body_Decl
) = N_Subprogram_Body
then
4358 -- Subprogram body stub
4360 elsif Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
4365 elsif Nkind
(Body_Decl
) = N_Task_Body
then
4373 Body_Id
:= Defining_Entity
(Body_Decl
);
4374 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
4376 -- The pragma must apply to the second declaration of a subprogram.
4377 -- In other words, the body [stub] cannot acts as a spec.
4379 if No
(Spec_Id
) then
4380 Error_Pragma
("pragma % cannot apply to a stand alone body");
4383 -- Catch the case where the subprogram body is a subunit and acts as
4384 -- the third declaration of the subprogram.
4386 elsif Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
4387 Error_Pragma
("pragma % cannot apply to a subunit");
4391 -- A refined pragma can only apply to the body [stub] of a subprogram
4392 -- declared in the visible part of a package. Retrieve the context of
4393 -- the subprogram declaration.
4395 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
4397 -- When dealing with protected entries or protected subprograms, use
4398 -- the enclosing protected type as the proper context.
4400 if Ekind_In
(Spec_Id
, E_Entry
,
4404 and then Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
4406 Spec_Decl
:= Declaration_Node
(Scope
(Spec_Id
));
4409 if Nkind
(Parent
(Spec_Decl
)) /= N_Package_Specification
then
4411 (Fix_Msg
(Spec_Id
, "pragma % must apply to the body of "
4412 & "subprogram declared in a package specification"));
4416 -- If we get here, then the pragma is legal
4420 -- A pragma that applies to a Ghost entity becomes Ghost for the
4421 -- purposes of legality checks and removal of ignored Ghost code.
4423 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
4425 if Nam_In
(Pname
, Name_Refined_Depends
, Name_Refined_Global
) then
4426 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4428 end Analyze_Refined_Depends_Global_Post
;
4430 --------------------------
4431 -- Check_Ada_83_Warning --
4432 --------------------------
4434 procedure Check_Ada_83_Warning
is
4436 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4437 Error_Msg_N
("(Ada 83) pragma& is non-standard??", N
);
4439 end Check_Ada_83_Warning
;
4441 ---------------------
4442 -- Check_Arg_Count --
4443 ---------------------
4445 procedure Check_Arg_Count
(Required
: Nat
) is
4447 if Arg_Count
/= Required
then
4448 Error_Pragma
("wrong number of arguments for pragma%");
4450 end Check_Arg_Count
;
4452 --------------------------------
4453 -- Check_Arg_Is_External_Name --
4454 --------------------------------
4456 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
) is
4457 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4460 if Nkind
(Argx
) = N_Identifier
then
4464 Analyze_And_Resolve
(Argx
, Standard_String
);
4466 if Is_OK_Static_Expression
(Argx
) then
4469 elsif Etype
(Argx
) = Any_Type
then
4472 -- An interesting special case, if we have a string literal and
4473 -- we are in Ada 83 mode, then we allow it even though it will
4474 -- not be flagged as static. This allows expected Ada 83 mode
4475 -- use of external names which are string literals, even though
4476 -- technically these are not static in Ada 83.
4478 elsif Ada_Version
= Ada_83
4479 and then Nkind
(Argx
) = N_String_Literal
4483 -- Static expression that raises Constraint_Error. This has
4484 -- already been flagged, so just exit from pragma processing.
4486 elsif Is_OK_Static_Expression
(Argx
) then
4489 -- Here we have a real error (non-static expression)
4492 Error_Msg_Name_1
:= Pname
;
4495 Msg
: constant String :=
4496 "argument for pragma% must be a identifier or "
4497 & "static string expression!";
4499 Flag_Non_Static_Expr
(Fix_Error
(Msg
), Argx
);
4504 end Check_Arg_Is_External_Name
;
4506 -----------------------------
4507 -- Check_Arg_Is_Identifier --
4508 -----------------------------
4510 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
) is
4511 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4513 if Nkind
(Argx
) /= N_Identifier
then
4515 ("argument for pragma% must be identifier", Argx
);
4517 end Check_Arg_Is_Identifier
;
4519 ----------------------------------
4520 -- Check_Arg_Is_Integer_Literal --
4521 ----------------------------------
4523 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
) is
4524 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4526 if Nkind
(Argx
) /= N_Integer_Literal
then
4528 ("argument for pragma% must be integer literal", Argx
);
4530 end Check_Arg_Is_Integer_Literal
;
4532 -------------------------------------------
4533 -- Check_Arg_Is_Library_Level_Local_Name --
4534 -------------------------------------------
4538 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4539 -- | library_unit_NAME
4541 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
) is
4543 Check_Arg_Is_Local_Name
(Arg
);
4545 -- If it came from an aspect, we want to give the error just as if it
4546 -- came from source.
4548 if not Is_Library_Level_Entity
(Entity
(Get_Pragma_Arg
(Arg
)))
4549 and then (Comes_From_Source
(N
)
4550 or else Present
(Corresponding_Aspect
(Parent
(Arg
))))
4553 ("argument for pragma% must be library level entity", Arg
);
4555 end Check_Arg_Is_Library_Level_Local_Name
;
4557 -----------------------------
4558 -- Check_Arg_Is_Local_Name --
4559 -----------------------------
4563 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4564 -- | library_unit_NAME
4566 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
) is
4567 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4570 -- If this pragma came from an aspect specification, we don't want to
4571 -- check for this error, because that would cause spurious errors, in
4572 -- case a type is frozen in a scope more nested than the type. The
4573 -- aspect itself of course can't be anywhere but on the declaration
4576 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
4577 if From_Aspect_Specification
(Parent
(Arg
)) then
4581 -- Arg is the Expression of an N_Pragma_Argument_Association
4584 if From_Aspect_Specification
(Parent
(Parent
(Arg
))) then
4591 if Nkind
(Argx
) not in N_Direct_Name
4592 and then (Nkind
(Argx
) /= N_Attribute_Reference
4593 or else Present
(Expressions
(Argx
))
4594 or else Nkind
(Prefix
(Argx
)) /= N_Identifier
)
4595 and then (not Is_Entity_Name
(Argx
)
4596 or else not Is_Compilation_Unit
(Entity
(Argx
)))
4598 Error_Pragma_Arg
("argument for pragma% must be local name", Argx
);
4601 -- No further check required if not an entity name
4603 if not Is_Entity_Name
(Argx
) then
4609 Ent
: constant Entity_Id
:= Entity
(Argx
);
4610 Scop
: constant Entity_Id
:= Scope
(Ent
);
4613 -- Case of a pragma applied to a compilation unit: pragma must
4614 -- occur immediately after the program unit in the compilation.
4616 if Is_Compilation_Unit
(Ent
) then
4618 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
4621 -- Case of pragma placed immediately after spec
4623 if Parent
(N
) = Aux_Decls_Node
(Parent
(Decl
)) then
4626 -- Case of pragma placed immediately after body
4628 elsif Nkind
(Decl
) = N_Subprogram_Declaration
4629 and then Present
(Corresponding_Body
(Decl
))
4633 (Parent
(Unit_Declaration_Node
4634 (Corresponding_Body
(Decl
))));
4636 -- All other cases are illegal
4643 -- Special restricted placement rule from 10.2.1(11.8/2)
4645 elsif Is_Generic_Formal
(Ent
)
4646 and then Prag_Id
= Pragma_Preelaborable_Initialization
4648 OK
:= List_Containing
(N
) =
4649 Generic_Formal_Declarations
4650 (Unit_Declaration_Node
(Scop
));
4652 -- If this is an aspect applied to a subprogram body, the
4653 -- pragma is inserted in its declarative part.
4655 elsif From_Aspect_Specification
(N
)
4656 and then Ent
= Current_Scope
4658 Nkind
(Unit_Declaration_Node
(Ent
)) = N_Subprogram_Body
4662 -- If the aspect is a predicate (possibly others ???) and the
4663 -- context is a record type, this is a discriminant expression
4664 -- within a type declaration, that freezes the predicated
4667 elsif From_Aspect_Specification
(N
)
4668 and then Prag_Id
= Pragma_Predicate
4669 and then Ekind
(Current_Scope
) = E_Record_Type
4670 and then Scop
= Scope
(Current_Scope
)
4674 -- Default case, just check that the pragma occurs in the scope
4675 -- of the entity denoted by the name.
4678 OK
:= Current_Scope
= Scop
;
4683 ("pragma% argument must be in same declarative part", Arg
);
4687 end Check_Arg_Is_Local_Name
;
4689 ---------------------------------
4690 -- Check_Arg_Is_Locking_Policy --
4691 ---------------------------------
4693 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
) is
4694 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4697 Check_Arg_Is_Identifier
(Argx
);
4699 if not Is_Locking_Policy_Name
(Chars
(Argx
)) then
4700 Error_Pragma_Arg
("& is not a valid locking policy name", Argx
);
4702 end Check_Arg_Is_Locking_Policy
;
4704 -----------------------------------------------
4705 -- Check_Arg_Is_Partition_Elaboration_Policy --
4706 -----------------------------------------------
4708 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
) is
4709 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4712 Check_Arg_Is_Identifier
(Argx
);
4714 if not Is_Partition_Elaboration_Policy_Name
(Chars
(Argx
)) then
4716 ("& is not a valid partition elaboration policy name", Argx
);
4718 end Check_Arg_Is_Partition_Elaboration_Policy
;
4720 -------------------------
4721 -- Check_Arg_Is_One_Of --
4722 -------------------------
4724 procedure Check_Arg_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
4725 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4728 Check_Arg_Is_Identifier
(Argx
);
4730 if not Nam_In
(Chars
(Argx
), N1
, N2
) then
4731 Error_Msg_Name_2
:= N1
;
4732 Error_Msg_Name_3
:= N2
;
4733 Error_Pragma_Arg
("argument for pragma% must be% or%", Argx
);
4735 end Check_Arg_Is_One_Of
;
4737 procedure Check_Arg_Is_One_Of
4739 N1
, N2
, N3
: Name_Id
)
4741 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4744 Check_Arg_Is_Identifier
(Argx
);
4746 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
) then
4747 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
4749 end Check_Arg_Is_One_Of
;
4751 procedure Check_Arg_Is_One_Of
4753 N1
, N2
, N3
, N4
: Name_Id
)
4755 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4758 Check_Arg_Is_Identifier
(Argx
);
4760 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
) then
4761 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
4763 end Check_Arg_Is_One_Of
;
4765 procedure Check_Arg_Is_One_Of
4767 N1
, N2
, N3
, N4
, N5
: Name_Id
)
4769 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4772 Check_Arg_Is_Identifier
(Argx
);
4774 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
, N5
) then
4775 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
4777 end Check_Arg_Is_One_Of
;
4779 ---------------------------------
4780 -- Check_Arg_Is_Queuing_Policy --
4781 ---------------------------------
4783 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
) is
4784 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4787 Check_Arg_Is_Identifier
(Argx
);
4789 if not Is_Queuing_Policy_Name
(Chars
(Argx
)) then
4790 Error_Pragma_Arg
("& is not a valid queuing policy name", Argx
);
4792 end Check_Arg_Is_Queuing_Policy
;
4794 ---------------------------------------
4795 -- Check_Arg_Is_OK_Static_Expression --
4796 ---------------------------------------
4798 procedure Check_Arg_Is_OK_Static_Expression
4800 Typ
: Entity_Id
:= Empty
)
4803 Check_Expr_Is_OK_Static_Expression
(Get_Pragma_Arg
(Arg
), Typ
);
4804 end Check_Arg_Is_OK_Static_Expression
;
4806 ------------------------------------------
4807 -- Check_Arg_Is_Task_Dispatching_Policy --
4808 ------------------------------------------
4810 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
) is
4811 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4814 Check_Arg_Is_Identifier
(Argx
);
4816 if not Is_Task_Dispatching_Policy_Name
(Chars
(Argx
)) then
4818 ("& is not an allowed task dispatching policy name", Argx
);
4820 end Check_Arg_Is_Task_Dispatching_Policy
;
4822 ---------------------
4823 -- Check_Arg_Order --
4824 ---------------------
4826 procedure Check_Arg_Order
(Names
: Name_List
) is
4829 Highest_So_Far
: Natural := 0;
4830 -- Highest index in Names seen do far
4834 for J
in 1 .. Arg_Count
loop
4835 if Chars
(Arg
) /= No_Name
then
4836 for K
in Names
'Range loop
4837 if Chars
(Arg
) = Names
(K
) then
4838 if K
< Highest_So_Far
then
4839 Error_Msg_Name_1
:= Pname
;
4841 ("parameters out of order for pragma%", Arg
);
4842 Error_Msg_Name_1
:= Names
(K
);
4843 Error_Msg_Name_2
:= Names
(Highest_So_Far
);
4844 Error_Msg_N
("\% must appear before %", Arg
);
4848 Highest_So_Far
:= K
;
4856 end Check_Arg_Order
;
4858 --------------------------------
4859 -- Check_At_Least_N_Arguments --
4860 --------------------------------
4862 procedure Check_At_Least_N_Arguments
(N
: Nat
) is
4864 if Arg_Count
< N
then
4865 Error_Pragma
("too few arguments for pragma%");
4867 end Check_At_Least_N_Arguments
;
4869 -------------------------------
4870 -- Check_At_Most_N_Arguments --
4871 -------------------------------
4873 procedure Check_At_Most_N_Arguments
(N
: Nat
) is
4876 if Arg_Count
> N
then
4878 for J
in 1 .. N
loop
4880 Error_Pragma_Arg
("too many arguments for pragma%", Arg
);
4883 end Check_At_Most_N_Arguments
;
4885 ---------------------
4886 -- Check_Component --
4887 ---------------------
4889 procedure Check_Component
4892 In_Variant_Part
: Boolean := False)
4894 Comp_Id
: constant Entity_Id
:= Defining_Identifier
(Comp
);
4895 Sindic
: constant Node_Id
:=
4896 Subtype_Indication
(Component_Definition
(Comp
));
4897 Typ
: constant Entity_Id
:= Etype
(Comp_Id
);
4900 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4901 -- object constraint, then the component type shall be an Unchecked_
4904 if Nkind
(Sindic
) = N_Subtype_Indication
4905 and then Has_Per_Object_Constraint
(Comp_Id
)
4906 and then not Is_Unchecked_Union
(Etype
(Subtype_Mark
(Sindic
)))
4909 ("component subtype subject to per-object constraint "
4910 & "must be an Unchecked_Union", Comp
);
4912 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4913 -- the body of a generic unit, or within the body of any of its
4914 -- descendant library units, no part of the type of a component
4915 -- declared in a variant_part of the unchecked union type shall be of
4916 -- a formal private type or formal private extension declared within
4917 -- the formal part of the generic unit.
4919 elsif Ada_Version
>= Ada_2012
4920 and then In_Generic_Body
(UU_Typ
)
4921 and then In_Variant_Part
4922 and then Is_Private_Type
(Typ
)
4923 and then Is_Generic_Type
(Typ
)
4926 ("component of unchecked union cannot be of generic type", Comp
);
4928 elsif Needs_Finalization
(Typ
) then
4930 ("component of unchecked union cannot be controlled", Comp
);
4932 elsif Has_Task
(Typ
) then
4934 ("component of unchecked union cannot have tasks", Comp
);
4936 end Check_Component
;
4938 ----------------------------
4939 -- Check_Duplicate_Pragma --
4940 ----------------------------
4942 procedure Check_Duplicate_Pragma
(E
: Entity_Id
) is
4943 Id
: Entity_Id
:= E
;
4947 -- Nothing to do if this pragma comes from an aspect specification,
4948 -- since we could not be duplicating a pragma, and we dealt with the
4949 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4951 if From_Aspect_Specification
(N
) then
4955 -- Otherwise current pragma may duplicate previous pragma or a
4956 -- previously given aspect specification or attribute definition
4957 -- clause for the same pragma.
4959 P
:= Get_Rep_Item
(E
, Pragma_Name
(N
), Check_Parents
=> False);
4963 -- If the entity is a type, then we have to make sure that the
4964 -- ostensible duplicate is not for a parent type from which this
4968 if Nkind
(P
) = N_Pragma
then
4970 Args
: constant List_Id
:=
4971 Pragma_Argument_Associations
(P
);
4974 and then Is_Entity_Name
(Expression
(First
(Args
)))
4975 and then Is_Type
(Entity
(Expression
(First
(Args
))))
4976 and then Entity
(Expression
(First
(Args
))) /= E
4982 elsif Nkind
(P
) = N_Aspect_Specification
4983 and then Is_Type
(Entity
(P
))
4984 and then Entity
(P
) /= E
4990 -- Here we have a definite duplicate
4992 Error_Msg_Name_1
:= Pragma_Name
(N
);
4993 Error_Msg_Sloc
:= Sloc
(P
);
4995 -- For a single protected or a single task object, the error is
4996 -- issued on the original entity.
4998 if Ekind_In
(Id
, E_Task_Type
, E_Protected_Type
) then
4999 Id
:= Defining_Identifier
(Original_Node
(Parent
(Id
)));
5002 if Nkind
(P
) = N_Aspect_Specification
5003 or else From_Aspect_Specification
(P
)
5005 Error_Msg_NE
("aspect% for & previously given#", N
, Id
);
5007 Error_Msg_NE
("pragma% for & duplicates pragma#", N
, Id
);
5012 end Check_Duplicate_Pragma
;
5014 ----------------------------------
5015 -- Check_Duplicated_Export_Name --
5016 ----------------------------------
5018 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
) is
5019 String_Val
: constant String_Id
:= Strval
(Nam
);
5022 -- We are only interested in the export case, and in the case of
5023 -- generics, it is the instance, not the template, that is the
5024 -- problem (the template will generate a warning in any case).
5026 if not Inside_A_Generic
5027 and then (Prag_Id
= Pragma_Export
5029 Prag_Id
= Pragma_Export_Procedure
5031 Prag_Id
= Pragma_Export_Valued_Procedure
5033 Prag_Id
= Pragma_Export_Function
)
5035 for J
in Externals
.First
.. Externals
.Last
loop
5036 if String_Equal
(String_Val
, Strval
(Externals
.Table
(J
))) then
5037 Error_Msg_Sloc
:= Sloc
(Externals
.Table
(J
));
5038 Error_Msg_N
("external name duplicates name given#", Nam
);
5043 Externals
.Append
(Nam
);
5045 end Check_Duplicated_Export_Name
;
5047 ----------------------------------------
5048 -- Check_Expr_Is_OK_Static_Expression --
5049 ----------------------------------------
5051 procedure Check_Expr_Is_OK_Static_Expression
5053 Typ
: Entity_Id
:= Empty
)
5056 if Present
(Typ
) then
5057 Analyze_And_Resolve
(Expr
, Typ
);
5059 Analyze_And_Resolve
(Expr
);
5062 if Is_OK_Static_Expression
(Expr
) then
5065 elsif Etype
(Expr
) = Any_Type
then
5068 -- An interesting special case, if we have a string literal and we
5069 -- are in Ada 83 mode, then we allow it even though it will not be
5070 -- flagged as static. This allows the use of Ada 95 pragmas like
5071 -- Import in Ada 83 mode. They will of course be flagged with
5072 -- warnings as usual, but will not cause errors.
5074 elsif Ada_Version
= Ada_83
5075 and then Nkind
(Expr
) = N_String_Literal
5079 -- Static expression that raises Constraint_Error. This has already
5080 -- been flagged, so just exit from pragma processing.
5082 elsif Is_OK_Static_Expression
(Expr
) then
5085 -- Finally, we have a real error
5088 Error_Msg_Name_1
:= Pname
;
5089 Flag_Non_Static_Expr
5090 (Fix_Error
("argument for pragma% must be a static expression!"),
5094 end Check_Expr_Is_OK_Static_Expression
;
5096 -------------------------
5097 -- Check_First_Subtype --
5098 -------------------------
5100 procedure Check_First_Subtype
(Arg
: Node_Id
) is
5101 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5102 Ent
: constant Entity_Id
:= Entity
(Argx
);
5105 if Is_First_Subtype
(Ent
) then
5108 elsif Is_Type
(Ent
) then
5110 ("pragma% cannot apply to subtype", Argx
);
5112 elsif Is_Object
(Ent
) then
5114 ("pragma% cannot apply to object, requires a type", Argx
);
5118 ("pragma% cannot apply to&, requires a type", Argx
);
5120 end Check_First_Subtype
;
5122 ----------------------
5123 -- Check_Identifier --
5124 ----------------------
5126 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
5129 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5131 if Chars
(Arg
) = No_Name
or else Chars
(Arg
) /= Id
then
5132 Error_Msg_Name_1
:= Pname
;
5133 Error_Msg_Name_2
:= Id
;
5134 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
5138 end Check_Identifier
;
5140 --------------------------------
5141 -- Check_Identifier_Is_One_Of --
5142 --------------------------------
5144 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
5147 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5149 if Chars
(Arg
) = No_Name
then
5150 Error_Msg_Name_1
:= Pname
;
5151 Error_Msg_N
("pragma% argument expects an identifier", Arg
);
5154 elsif Chars
(Arg
) /= N1
5155 and then Chars
(Arg
) /= N2
5157 Error_Msg_Name_1
:= Pname
;
5158 Error_Msg_N
("invalid identifier for pragma% argument", Arg
);
5162 end Check_Identifier_Is_One_Of
;
5164 ---------------------------
5165 -- Check_In_Main_Program --
5166 ---------------------------
5168 procedure Check_In_Main_Program
is
5169 P
: constant Node_Id
:= Parent
(N
);
5172 -- Must be in subprogram body
5174 if Nkind
(P
) /= N_Subprogram_Body
then
5175 Error_Pragma
("% pragma allowed only in subprogram");
5177 -- Otherwise warn if obviously not main program
5179 elsif Present
(Parameter_Specifications
(Specification
(P
)))
5180 or else not Is_Compilation_Unit
(Defining_Entity
(P
))
5182 Error_Msg_Name_1
:= Pname
;
5184 ("??pragma% is only effective in main program", N
);
5186 end Check_In_Main_Program
;
5188 ---------------------------------------
5189 -- Check_Interrupt_Or_Attach_Handler --
5190 ---------------------------------------
5192 procedure Check_Interrupt_Or_Attach_Handler
is
5193 Arg1_X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
5194 Handler_Proc
, Proc_Scope
: Entity_Id
;
5199 if Prag_Id
= Pragma_Interrupt_Handler
then
5200 Check_Restriction
(No_Dynamic_Attachment
, N
);
5203 Handler_Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
5204 Proc_Scope
:= Scope
(Handler_Proc
);
5206 -- On AAMP only, a pragma Interrupt_Handler is supported for
5207 -- nonprotected parameterless procedures.
5209 if not AAMP_On_Target
5210 or else Prag_Id
= Pragma_Attach_Handler
5212 if Ekind
(Proc_Scope
) /= E_Protected_Type
then
5214 ("argument of pragma% must be protected procedure", Arg1
);
5217 -- For pragma case (as opposed to access case), check placement.
5218 -- We don't need to do that for aspects, because we have the
5219 -- check that they aspect applies an appropriate procedure.
5221 if not From_Aspect_Specification
(N
)
5222 and then Parent
(N
) /= Protected_Definition
(Parent
(Proc_Scope
))
5224 Error_Pragma
("pragma% must be in protected definition");
5228 if not Is_Library_Level_Entity
(Proc_Scope
)
5229 or else (AAMP_On_Target
5230 and then not Is_Library_Level_Entity
(Handler_Proc
))
5233 ("argument for pragma% must be library level entity", Arg1
);
5236 -- AI05-0033: A pragma cannot appear within a generic body, because
5237 -- instance can be in a nested scope. The check that protected type
5238 -- is itself a library-level declaration is done elsewhere.
5240 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5241 -- handle code prior to AI-0033. Analysis tools typically are not
5242 -- interested in this pragma in any case, so no need to worry too
5243 -- much about its placement.
5245 if Inside_A_Generic
then
5246 if Ekind
(Scope
(Current_Scope
)) = E_Generic_Package
5247 and then In_Package_Body
(Scope
(Current_Scope
))
5248 and then not Relaxed_RM_Semantics
5250 Error_Pragma
("pragma% cannot be used inside a generic");
5253 end Check_Interrupt_Or_Attach_Handler
;
5255 ---------------------------------
5256 -- Check_Loop_Pragma_Placement --
5257 ---------------------------------
5259 procedure Check_Loop_Pragma_Placement
is
5260 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
);
5261 -- Verify whether the current pragma is properly grouped with other
5262 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5263 -- related loop where the pragma appears.
5265 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean;
5266 -- Determine whether an arbitrary statement Stmt denotes pragma
5267 -- Loop_Invariant or Loop_Variant.
5269 procedure Placement_Error
(Constr
: Node_Id
);
5270 pragma No_Return
(Placement_Error
);
5271 -- Node Constr denotes the last loop restricted construct before we
5272 -- encountered an illegal relation between enclosing constructs. Emit
5273 -- an error depending on what Constr was.
5275 --------------------------------
5276 -- Check_Loop_Pragma_Grouping --
5277 --------------------------------
5279 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
) is
5280 Stop_Search
: exception;
5281 -- This exception is used to terminate the recursive descent of
5282 -- routine Check_Grouping.
5284 procedure Check_Grouping
(L
: List_Id
);
5285 -- Find the first group of pragmas in list L and if successful,
5286 -- ensure that the current pragma is part of that group. The
5287 -- routine raises Stop_Search once such a check is performed to
5288 -- halt the recursive descent.
5290 procedure Grouping_Error
(Prag
: Node_Id
);
5291 pragma No_Return
(Grouping_Error
);
5292 -- Emit an error concerning the current pragma indicating that it
5293 -- should be placed after pragma Prag.
5295 --------------------
5296 -- Check_Grouping --
5297 --------------------
5299 procedure Check_Grouping
(L
: List_Id
) is
5305 -- Inspect the list of declarations or statements looking for
5306 -- the first grouping of pragmas:
5309 -- pragma Loop_Invariant ...;
5310 -- pragma Loop_Variant ...;
5312 -- pragma Loop_Variant ...; -- current pragma
5314 -- If the current pragma is not in the grouping, then it must
5315 -- either appear in a different declarative or statement list
5316 -- or the construct at (1) is separating the pragma from the
5320 while Present
(Stmt
) loop
5322 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5323 -- inside a loop or a block housed inside a loop. Inspect
5324 -- the declarations and statements of the block as they may
5325 -- contain the first grouping.
5327 if Nkind
(Stmt
) = N_Block_Statement
then
5328 HSS
:= Handled_Statement_Sequence
(Stmt
);
5330 Check_Grouping
(Declarations
(Stmt
));
5332 if Present
(HSS
) then
5333 Check_Grouping
(Statements
(HSS
));
5336 -- First pragma of the first topmost grouping has been found
5338 elsif Is_Loop_Pragma
(Stmt
) then
5340 -- The group and the current pragma are not in the same
5341 -- declarative or statement list.
5343 if List_Containing
(Stmt
) /= List_Containing
(N
) then
5344 Grouping_Error
(Stmt
);
5346 -- Try to reach the current pragma from the first pragma
5347 -- of the grouping while skipping other members:
5349 -- pragma Loop_Invariant ...; -- first pragma
5350 -- pragma Loop_Variant ...; -- member
5352 -- pragma Loop_Variant ...; -- current pragma
5355 while Present
(Stmt
) loop
5357 -- The current pragma is either the first pragma
5358 -- of the group or is a member of the group. Stop
5359 -- the search as the placement is legal.
5364 -- Skip group members, but keep track of the last
5365 -- pragma in the group.
5367 elsif Is_Loop_Pragma
(Stmt
) then
5370 -- Skip declarations and statements generated by
5371 -- the compiler during expansion.
5373 elsif not Comes_From_Source
(Stmt
) then
5376 -- A non-pragma is separating the group from the
5377 -- current pragma, the placement is illegal.
5380 Grouping_Error
(Prag
);
5386 -- If the traversal did not reach the current pragma,
5387 -- then the list must be malformed.
5389 raise Program_Error
;
5397 --------------------
5398 -- Grouping_Error --
5399 --------------------
5401 procedure Grouping_Error
(Prag
: Node_Id
) is
5403 Error_Msg_Sloc
:= Sloc
(Prag
);
5404 Error_Pragma
("pragma% must appear next to pragma#");
5407 -- Start of processing for Check_Loop_Pragma_Grouping
5410 -- Inspect the statements of the loop or nested blocks housed
5411 -- within to determine whether the current pragma is part of the
5412 -- first topmost grouping of Loop_Invariant and Loop_Variant.
5414 Check_Grouping
(Statements
(Loop_Stmt
));
5417 when Stop_Search
=> null;
5418 end Check_Loop_Pragma_Grouping
;
5420 --------------------
5421 -- Is_Loop_Pragma --
5422 --------------------
5424 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean is
5426 -- Inspect the original node as Loop_Invariant and Loop_Variant
5427 -- pragmas are rewritten to null when assertions are disabled.
5429 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
then
5431 Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
5432 Name_Loop_Invariant
,
5439 ---------------------
5440 -- Placement_Error --
5441 ---------------------
5443 procedure Placement_Error
(Constr
: Node_Id
) is
5444 LA
: constant String := " with Loop_Entry";
5447 if Prag_Id
= Pragma_Assert
then
5448 Error_Msg_String
(1 .. LA
'Length) := LA
;
5449 Error_Msg_Strlen
:= LA
'Length;
5451 Error_Msg_Strlen
:= 0;
5454 if Nkind
(Constr
) = N_Pragma
then
5456 ("pragma %~ must appear immediately within the statements "
5460 ("block containing pragma %~ must appear immediately within "
5461 & "the statements of a loop", Constr
);
5463 end Placement_Error
;
5465 -- Local declarations
5470 -- Start of processing for Check_Loop_Pragma_Placement
5473 -- Check that pragma appears immediately within a loop statement,
5474 -- ignoring intervening block statements.
5478 while Present
(Stmt
) loop
5480 -- The pragma or previous block must appear immediately within the
5481 -- current block's declarative or statement part.
5483 if Nkind
(Stmt
) = N_Block_Statement
then
5484 if (No
(Declarations
(Stmt
))
5485 or else List_Containing
(Prev
) /= Declarations
(Stmt
))
5487 List_Containing
(Prev
) /=
5488 Statements
(Handled_Statement_Sequence
(Stmt
))
5490 Placement_Error
(Prev
);
5493 -- Keep inspecting the parents because we are now within a
5494 -- chain of nested blocks.
5498 Stmt
:= Parent
(Stmt
);
5501 -- The pragma or previous block must appear immediately within the
5502 -- statements of the loop.
5504 elsif Nkind
(Stmt
) = N_Loop_Statement
then
5505 if List_Containing
(Prev
) /= Statements
(Stmt
) then
5506 Placement_Error
(Prev
);
5509 -- Stop the traversal because we reached the innermost loop
5510 -- regardless of whether we encountered an error or not.
5514 -- Ignore a handled statement sequence. Note that this node may
5515 -- be related to a subprogram body in which case we will emit an
5516 -- error on the next iteration of the search.
5518 elsif Nkind
(Stmt
) = N_Handled_Sequence_Of_Statements
then
5519 Stmt
:= Parent
(Stmt
);
5521 -- Any other statement breaks the chain from the pragma to the
5525 Placement_Error
(Prev
);
5530 -- Check that the current pragma Loop_Invariant or Loop_Variant is
5531 -- grouped together with other such pragmas.
5533 if Is_Loop_Pragma
(N
) then
5535 -- The previous check should have located the related loop
5537 pragma Assert
(Nkind
(Stmt
) = N_Loop_Statement
);
5538 Check_Loop_Pragma_Grouping
(Stmt
);
5540 end Check_Loop_Pragma_Placement
;
5542 -------------------------------------------
5543 -- Check_Is_In_Decl_Part_Or_Package_Spec --
5544 -------------------------------------------
5546 procedure Check_Is_In_Decl_Part_Or_Package_Spec
is
5555 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
then
5558 elsif Nkind_In
(P
, N_Package_Specification
,
5563 -- Note: the following tests seem a little peculiar, because
5564 -- they test for bodies, but if we were in the statement part
5565 -- of the body, we would already have hit the handled statement
5566 -- sequence, so the only way we get here is by being in the
5567 -- declarative part of the body.
5569 elsif Nkind_In
(P
, N_Subprogram_Body
,
5580 Error_Pragma
("pragma% is not in declarative part or package spec");
5581 end Check_Is_In_Decl_Part_Or_Package_Spec
;
5583 -------------------------
5584 -- Check_No_Identifier --
5585 -------------------------
5587 procedure Check_No_Identifier
(Arg
: Node_Id
) is
5589 if Nkind
(Arg
) = N_Pragma_Argument_Association
5590 and then Chars
(Arg
) /= No_Name
5592 Error_Pragma_Arg_Ident
5593 ("pragma% does not permit identifier& here", Arg
);
5595 end Check_No_Identifier
;
5597 --------------------------
5598 -- Check_No_Identifiers --
5599 --------------------------
5601 procedure Check_No_Identifiers
is
5605 for J
in 1 .. Arg_Count
loop
5606 Check_No_Identifier
(Arg_Node
);
5609 end Check_No_Identifiers
;
5611 ------------------------
5612 -- Check_No_Link_Name --
5613 ------------------------
5615 procedure Check_No_Link_Name
is
5617 if Present
(Arg3
) and then Chars
(Arg3
) = Name_Link_Name
then
5621 if Present
(Arg4
) then
5623 ("Link_Name argument not allowed for Import Intrinsic", Arg4
);
5625 end Check_No_Link_Name
;
5627 -------------------------------
5628 -- Check_Optional_Identifier --
5629 -------------------------------
5631 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
5634 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5635 and then Chars
(Arg
) /= No_Name
5637 if Chars
(Arg
) /= Id
then
5638 Error_Msg_Name_1
:= Pname
;
5639 Error_Msg_Name_2
:= Id
;
5640 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
5644 end Check_Optional_Identifier
;
5646 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String) is
5648 Name_Buffer
(1 .. Id
'Length) := Id
;
5649 Name_Len
:= Id
'Length;
5650 Check_Optional_Identifier
(Arg
, Name_Find
);
5651 end Check_Optional_Identifier
;
5653 -------------------------------------
5654 -- Check_Static_Boolean_Expression --
5655 -------------------------------------
5657 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
) is
5659 if Present
(Expr
) then
5660 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
5662 if not Is_OK_Static_Expression
(Expr
) then
5664 ("expression of pragma % must be static", Expr
);
5667 end Check_Static_Boolean_Expression
;
5669 -----------------------------
5670 -- Check_Static_Constraint --
5671 -----------------------------
5673 -- Note: for convenience in writing this procedure, in addition to
5674 -- the officially (i.e. by spec) allowed argument which is always a
5675 -- constraint, it also allows ranges and discriminant associations.
5676 -- Above is not clear ???
5678 procedure Check_Static_Constraint
(Constr
: Node_Id
) is
5680 procedure Require_Static
(E
: Node_Id
);
5681 -- Require given expression to be static expression
5683 --------------------
5684 -- Require_Static --
5685 --------------------
5687 procedure Require_Static
(E
: Node_Id
) is
5689 if not Is_OK_Static_Expression
(E
) then
5690 Flag_Non_Static_Expr
5691 ("non-static constraint not allowed in Unchecked_Union!", E
);
5696 -- Start of processing for Check_Static_Constraint
5699 case Nkind
(Constr
) is
5700 when N_Discriminant_Association
=>
5701 Require_Static
(Expression
(Constr
));
5704 Require_Static
(Low_Bound
(Constr
));
5705 Require_Static
(High_Bound
(Constr
));
5707 when N_Attribute_Reference
=>
5708 Require_Static
(Type_Low_Bound
(Etype
(Prefix
(Constr
))));
5709 Require_Static
(Type_High_Bound
(Etype
(Prefix
(Constr
))));
5711 when N_Range_Constraint
=>
5712 Check_Static_Constraint
(Range_Expression
(Constr
));
5714 when N_Index_Or_Discriminant_Constraint
=>
5718 IDC
:= First
(Constraints
(Constr
));
5719 while Present
(IDC
) loop
5720 Check_Static_Constraint
(IDC
);
5728 end Check_Static_Constraint
;
5730 --------------------------------------
5731 -- Check_Valid_Configuration_Pragma --
5732 --------------------------------------
5734 -- A configuration pragma must appear in the context clause of a
5735 -- compilation unit, and only other pragmas may precede it. Note that
5736 -- the test also allows use in a configuration pragma file.
5738 procedure Check_Valid_Configuration_Pragma
is
5740 if not Is_Configuration_Pragma
then
5741 Error_Pragma
("incorrect placement for configuration pragma%");
5743 end Check_Valid_Configuration_Pragma
;
5745 -------------------------------------
5746 -- Check_Valid_Library_Unit_Pragma --
5747 -------------------------------------
5749 procedure Check_Valid_Library_Unit_Pragma
is
5751 Parent_Node
: Node_Id
;
5752 Unit_Name
: Entity_Id
;
5753 Unit_Kind
: Node_Kind
;
5754 Unit_Node
: Node_Id
;
5755 Sindex
: Source_File_Index
;
5758 if not Is_List_Member
(N
) then
5762 Plist
:= List_Containing
(N
);
5763 Parent_Node
:= Parent
(Plist
);
5765 if Parent_Node
= Empty
then
5768 -- Case of pragma appearing after a compilation unit. In this case
5769 -- it must have an argument with the corresponding name and must
5770 -- be part of the following pragmas of its parent.
5772 elsif Nkind
(Parent_Node
) = N_Compilation_Unit_Aux
then
5773 if Plist
/= Pragmas_After
(Parent_Node
) then
5776 elsif Arg_Count
= 0 then
5778 ("argument required if outside compilation unit");
5781 Check_No_Identifiers
;
5782 Check_Arg_Count
(1);
5783 Unit_Node
:= Unit
(Parent
(Parent_Node
));
5784 Unit_Kind
:= Nkind
(Unit_Node
);
5786 Analyze
(Get_Pragma_Arg
(Arg1
));
5788 if Unit_Kind
= N_Generic_Subprogram_Declaration
5789 or else Unit_Kind
= N_Subprogram_Declaration
5791 Unit_Name
:= Defining_Entity
(Unit_Node
);
5793 elsif Unit_Kind
in N_Generic_Instantiation
then
5794 Unit_Name
:= Defining_Entity
(Unit_Node
);
5797 Unit_Name
:= Cunit_Entity
(Current_Sem_Unit
);
5800 if Chars
(Unit_Name
) /=
5801 Chars
(Entity
(Get_Pragma_Arg
(Arg1
)))
5804 ("pragma% argument is not current unit name", Arg1
);
5807 if Ekind
(Unit_Name
) = E_Package
5808 and then Present
(Renamed_Entity
(Unit_Name
))
5810 Error_Pragma
("pragma% not allowed for renamed package");
5814 -- Pragma appears other than after a compilation unit
5817 -- Here we check for the generic instantiation case and also
5818 -- for the case of processing a generic formal package. We
5819 -- detect these cases by noting that the Sloc on the node
5820 -- does not belong to the current compilation unit.
5822 Sindex
:= Source_Index
(Current_Sem_Unit
);
5824 if Loc
not in Source_First
(Sindex
) .. Source_Last
(Sindex
) then
5825 Rewrite
(N
, Make_Null_Statement
(Loc
));
5828 -- If before first declaration, the pragma applies to the
5829 -- enclosing unit, and the name if present must be this name.
5831 elsif Is_Before_First_Decl
(N
, Plist
) then
5832 Unit_Node
:= Unit_Declaration_Node
(Current_Scope
);
5833 Unit_Kind
:= Nkind
(Unit_Node
);
5835 if Nkind
(Parent
(Unit_Node
)) /= N_Compilation_Unit
then
5838 elsif Unit_Kind
= N_Subprogram_Body
5839 and then not Acts_As_Spec
(Unit_Node
)
5843 elsif Nkind
(Parent_Node
) = N_Package_Body
then
5846 elsif Nkind
(Parent_Node
) = N_Package_Specification
5847 and then Plist
= Private_Declarations
(Parent_Node
)
5851 elsif (Nkind
(Parent_Node
) = N_Generic_Package_Declaration
5852 or else Nkind
(Parent_Node
) =
5853 N_Generic_Subprogram_Declaration
)
5854 and then Plist
= Generic_Formal_Declarations
(Parent_Node
)
5858 elsif Arg_Count
> 0 then
5859 Analyze
(Get_Pragma_Arg
(Arg1
));
5861 if Entity
(Get_Pragma_Arg
(Arg1
)) /= Current_Scope
then
5863 ("name in pragma% must be enclosing unit", Arg1
);
5866 -- It is legal to have no argument in this context
5872 -- Error if not before first declaration. This is because a
5873 -- library unit pragma argument must be the name of a library
5874 -- unit (RM 10.1.5(7)), but the only names permitted in this
5875 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5876 -- generic subprogram declarations or generic instantiations.
5880 ("pragma% misplaced, must be before first declaration");
5884 end Check_Valid_Library_Unit_Pragma
;
5890 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
) is
5891 Clist
: constant Node_Id
:= Component_List
(Variant
);
5895 Comp
:= First
(Component_Items
(Clist
));
5896 while Present
(Comp
) loop
5897 Check_Component
(Comp
, UU_Typ
, In_Variant_Part
=> True);
5902 ---------------------------
5903 -- Ensure_Aggregate_Form --
5904 ---------------------------
5906 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
) is
5907 CFSD
: constant Boolean := Get_Comes_From_Source_Default
;
5908 Expr
: constant Node_Id
:= Expression
(Arg
);
5909 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5910 Comps
: List_Id
:= No_List
;
5911 Exprs
: List_Id
:= No_List
;
5912 Nam
: Name_Id
:= No_Name
;
5913 Nam_Loc
: Source_Ptr
;
5916 -- The pragma argument is in positional form:
5918 -- pragma Depends (Nam => ...)
5922 -- Note that the Sloc of the Chars field is the Sloc of the pragma
5923 -- argument association.
5925 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
5927 Nam_Loc
:= Sloc
(Arg
);
5929 -- Remove the pragma argument name as this will be captured in the
5932 Set_Chars
(Arg
, No_Name
);
5935 -- The argument is already in aggregate form, but the presence of a
5936 -- name causes this to be interpreted as named association which in
5937 -- turn must be converted into an aggregate.
5939 -- pragma Global (In_Out => (A, B, C))
5943 -- pragma Global ((In_Out => (A, B, C)))
5945 -- aggregate aggregate
5947 if Nkind
(Expr
) = N_Aggregate
then
5948 if Nam
= No_Name
then
5952 -- Do not transform a null argument into an aggregate as N_Null has
5953 -- special meaning in formal verification pragmas.
5955 elsif Nkind
(Expr
) = N_Null
then
5959 -- Everything comes from source if the original comes from source
5961 Set_Comes_From_Source_Default
(Comes_From_Source
(Arg
));
5963 -- Positional argument is transformed into an aggregate with an
5964 -- Expressions list.
5966 if Nam
= No_Name
then
5967 Exprs
:= New_List
(Relocate_Node
(Expr
));
5969 -- An associative argument is transformed into an aggregate with
5970 -- Component_Associations.
5974 Make_Component_Association
(Loc
,
5975 Choices
=> New_List
(Make_Identifier
(Nam_Loc
, Nam
)),
5976 Expression
=> Relocate_Node
(Expr
)));
5979 Set_Expression
(Arg
,
5980 Make_Aggregate
(Loc
,
5981 Component_Associations
=> Comps
,
5982 Expressions
=> Exprs
));
5984 -- Restore Comes_From_Source default
5986 Set_Comes_From_Source_Default
(CFSD
);
5987 end Ensure_Aggregate_Form
;
5993 procedure Error_Pragma
(Msg
: String) is
5995 Error_Msg_Name_1
:= Pname
;
5996 Error_Msg_N
(Fix_Error
(Msg
), N
);
6000 ----------------------
6001 -- Error_Pragma_Arg --
6002 ----------------------
6004 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
) is
6006 Error_Msg_Name_1
:= Pname
;
6007 Error_Msg_N
(Fix_Error
(Msg
), Get_Pragma_Arg
(Arg
));
6009 end Error_Pragma_Arg
;
6011 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
) is
6013 Error_Msg_Name_1
:= Pname
;
6014 Error_Msg_N
(Fix_Error
(Msg1
), Get_Pragma_Arg
(Arg
));
6015 Error_Pragma_Arg
(Msg2
, Arg
);
6016 end Error_Pragma_Arg
;
6018 ----------------------------
6019 -- Error_Pragma_Arg_Ident --
6020 ----------------------------
6022 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
) is
6024 Error_Msg_Name_1
:= Pname
;
6025 Error_Msg_N
(Fix_Error
(Msg
), Arg
);
6027 end Error_Pragma_Arg_Ident
;
6029 ----------------------
6030 -- Error_Pragma_Ref --
6031 ----------------------
6033 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
) is
6035 Error_Msg_Name_1
:= Pname
;
6036 Error_Msg_Sloc
:= Sloc
(Ref
);
6037 Error_Msg_NE
(Fix_Error
(Msg
), N
, Ref
);
6039 end Error_Pragma_Ref
;
6041 ------------------------
6042 -- Find_Lib_Unit_Name --
6043 ------------------------
6045 function Find_Lib_Unit_Name
return Entity_Id
is
6047 -- Return inner compilation unit entity, for case of nested
6048 -- categorization pragmas. This happens in generic unit.
6050 if Nkind
(Parent
(N
)) = N_Package_Specification
6051 and then Defining_Entity
(Parent
(N
)) /= Current_Scope
6053 return Defining_Entity
(Parent
(N
));
6055 return Current_Scope
;
6057 end Find_Lib_Unit_Name
;
6059 ----------------------------
6060 -- Find_Program_Unit_Name --
6061 ----------------------------
6063 procedure Find_Program_Unit_Name
(Id
: Node_Id
) is
6064 Unit_Name
: Entity_Id
;
6065 Unit_Kind
: Node_Kind
;
6066 P
: constant Node_Id
:= Parent
(N
);
6069 if Nkind
(P
) = N_Compilation_Unit
then
6070 Unit_Kind
:= Nkind
(Unit
(P
));
6072 if Nkind_In
(Unit_Kind
, N_Subprogram_Declaration
,
6073 N_Package_Declaration
)
6074 or else Unit_Kind
in N_Generic_Declaration
6076 Unit_Name
:= Defining_Entity
(Unit
(P
));
6078 if Chars
(Id
) = Chars
(Unit_Name
) then
6079 Set_Entity
(Id
, Unit_Name
);
6080 Set_Etype
(Id
, Etype
(Unit_Name
));
6082 Set_Etype
(Id
, Any_Type
);
6084 ("cannot find program unit referenced by pragma%");
6088 Set_Etype
(Id
, Any_Type
);
6089 Error_Pragma
("pragma% inapplicable to this unit");
6095 end Find_Program_Unit_Name
;
6097 -----------------------------------------
6098 -- Find_Unique_Parameterless_Procedure --
6099 -----------------------------------------
6101 function Find_Unique_Parameterless_Procedure
6103 Arg
: Node_Id
) return Entity_Id
6105 Proc
: Entity_Id
:= Empty
;
6108 -- The body of this procedure needs some comments ???
6110 if not Is_Entity_Name
(Name
) then
6112 ("argument of pragma% must be entity name", Arg
);
6114 elsif not Is_Overloaded
(Name
) then
6115 Proc
:= Entity
(Name
);
6117 if Ekind
(Proc
) /= E_Procedure
6118 or else Present
(First_Formal
(Proc
))
6121 ("argument of pragma% must be parameterless procedure", Arg
);
6126 Found
: Boolean := False;
6128 Index
: Interp_Index
;
6131 Get_First_Interp
(Name
, Index
, It
);
6132 while Present
(It
.Nam
) loop
6135 if Ekind
(Proc
) = E_Procedure
6136 and then No
(First_Formal
(Proc
))
6140 Set_Entity
(Name
, Proc
);
6141 Set_Is_Overloaded
(Name
, False);
6144 ("ambiguous handler name for pragma% ", Arg
);
6148 Get_Next_Interp
(Index
, It
);
6153 ("argument of pragma% must be parameterless procedure",
6156 Proc
:= Entity
(Name
);
6162 end Find_Unique_Parameterless_Procedure
;
6168 function Fix_Error
(Msg
: String) return String is
6169 Res
: String (Msg
'Range) := Msg
;
6170 Res_Last
: Natural := Msg
'Last;
6174 -- If we have a rewriting of another pragma, go to that pragma
6176 if Is_Rewrite_Substitution
(N
)
6177 and then Nkind
(Original_Node
(N
)) = N_Pragma
6179 Error_Msg_Name_1
:= Pragma_Name
(Original_Node
(N
));
6182 -- Case where pragma comes from an aspect specification
6184 if From_Aspect_Specification
(N
) then
6186 -- Change appearence of "pragma" in message to "aspect"
6189 while J
<= Res_Last
- 5 loop
6190 if Res
(J
.. J
+ 5) = "pragma" then
6191 Res
(J
.. J
+ 5) := "aspect";
6199 -- Change "argument of" at start of message to "entity for"
6202 and then Res
(Res
'First .. Res
'First + 10) = "argument of"
6204 Res
(Res
'First .. Res
'First + 9) := "entity for";
6205 Res
(Res
'First + 10 .. Res_Last
- 1) :=
6206 Res
(Res
'First + 11 .. Res_Last
);
6207 Res_Last
:= Res_Last
- 1;
6210 -- Change "argument" at start of message to "entity"
6213 and then Res
(Res
'First .. Res
'First + 7) = "argument"
6215 Res
(Res
'First .. Res
'First + 5) := "entity";
6216 Res
(Res
'First + 6 .. Res_Last
- 2) :=
6217 Res
(Res
'First + 8 .. Res_Last
);
6218 Res_Last
:= Res_Last
- 2;
6221 -- Get name from corresponding aspect
6223 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(N
);
6226 -- Return possibly modified message
6228 return Res
(Res
'First .. Res_Last
);
6231 -------------------------
6232 -- Gather_Associations --
6233 -------------------------
6235 procedure Gather_Associations
6237 Args
: out Args_List
)
6242 -- Initialize all parameters to Empty
6244 for J
in Args
'Range loop
6248 -- That's all we have to do if there are no argument associations
6250 if No
(Pragma_Argument_Associations
(N
)) then
6254 -- Otherwise first deal with any positional parameters present
6256 Arg
:= First
(Pragma_Argument_Associations
(N
));
6257 for Index
in Args
'Range loop
6258 exit when No
(Arg
) or else Chars
(Arg
) /= No_Name
;
6259 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6263 -- Positional parameters all processed, if any left, then we
6264 -- have too many positional parameters.
6266 if Present
(Arg
) and then Chars
(Arg
) = No_Name
then
6268 ("too many positional associations for pragma%", Arg
);
6271 -- Process named parameters if any are present
6273 while Present
(Arg
) loop
6274 if Chars
(Arg
) = No_Name
then
6276 ("positional association cannot follow named association",
6280 for Index
in Names
'Range loop
6281 if Names
(Index
) = Chars
(Arg
) then
6282 if Present
(Args
(Index
)) then
6284 ("duplicate argument association for pragma%", Arg
);
6286 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6291 if Index
= Names
'Last then
6292 Error_Msg_Name_1
:= Pname
;
6293 Error_Msg_N
("pragma% does not allow & argument", Arg
);
6295 -- Check for possible misspelling
6297 for Index1
in Names
'Range loop
6298 if Is_Bad_Spelling_Of
6299 (Chars
(Arg
), Names
(Index1
))
6301 Error_Msg_Name_1
:= Names
(Index1
);
6302 Error_Msg_N
-- CODEFIX
6303 ("\possible misspelling of%", Arg
);
6315 end Gather_Associations
;
6321 procedure GNAT_Pragma
is
6323 -- We need to check the No_Implementation_Pragmas restriction for
6324 -- the case of a pragma from source. Note that the case of aspects
6325 -- generating corresponding pragmas marks these pragmas as not being
6326 -- from source, so this test also catches that case.
6328 if Comes_From_Source
(N
) then
6329 Check_Restriction
(No_Implementation_Pragmas
, N
);
6333 --------------------------
6334 -- Is_Before_First_Decl --
6335 --------------------------
6337 function Is_Before_First_Decl
6338 (Pragma_Node
: Node_Id
;
6339 Decls
: List_Id
) return Boolean
6341 Item
: Node_Id
:= First
(Decls
);
6344 -- Only other pragmas can come before this pragma
6347 if No
(Item
) or else Nkind
(Item
) /= N_Pragma
then
6350 elsif Item
= Pragma_Node
then
6356 end Is_Before_First_Decl
;
6358 -----------------------------
6359 -- Is_Configuration_Pragma --
6360 -----------------------------
6362 -- A configuration pragma must appear in the context clause of a
6363 -- compilation unit, and only other pragmas may precede it. Note that
6364 -- the test below also permits use in a configuration pragma file.
6366 function Is_Configuration_Pragma
return Boolean is
6367 Lis
: constant List_Id
:= List_Containing
(N
);
6368 Par
: constant Node_Id
:= Parent
(N
);
6372 -- If no parent, then we are in the configuration pragma file,
6373 -- so the placement is definitely appropriate.
6378 -- Otherwise we must be in the context clause of a compilation unit
6379 -- and the only thing allowed before us in the context list is more
6380 -- configuration pragmas.
6382 elsif Nkind
(Par
) = N_Compilation_Unit
6383 and then Context_Items
(Par
) = Lis
6390 elsif Nkind
(Prg
) /= N_Pragma
then
6400 end Is_Configuration_Pragma
;
6402 --------------------------
6403 -- Is_In_Context_Clause --
6404 --------------------------
6406 function Is_In_Context_Clause
return Boolean is
6408 Parent_Node
: Node_Id
;
6411 if not Is_List_Member
(N
) then
6415 Plist
:= List_Containing
(N
);
6416 Parent_Node
:= Parent
(Plist
);
6418 if Parent_Node
= Empty
6419 or else Nkind
(Parent_Node
) /= N_Compilation_Unit
6420 or else Context_Items
(Parent_Node
) /= Plist
6427 end Is_In_Context_Clause
;
6429 ---------------------------------
6430 -- Is_Static_String_Expression --
6431 ---------------------------------
6433 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean is
6434 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
6435 Lit
: constant Boolean := Nkind
(Argx
) = N_String_Literal
;
6438 Analyze_And_Resolve
(Argx
);
6440 -- Special case Ada 83, where the expression will never be static,
6441 -- but we will return true if we had a string literal to start with.
6443 if Ada_Version
= Ada_83
then
6446 -- Normal case, true only if we end up with a string literal that
6447 -- is marked as being the result of evaluating a static expression.
6450 return Is_OK_Static_Expression
(Argx
)
6451 and then Nkind
(Argx
) = N_String_Literal
;
6454 end Is_Static_String_Expression
;
6456 ----------------------
6457 -- Pragma_Misplaced --
6458 ----------------------
6460 procedure Pragma_Misplaced
is
6462 Error_Pragma
("incorrect placement of pragma%");
6463 end Pragma_Misplaced
;
6465 ------------------------------------------------
6466 -- Process_Atomic_Independent_Shared_Volatile --
6467 ------------------------------------------------
6469 procedure Process_Atomic_Independent_Shared_Volatile
is
6475 procedure Set_Atomic_VFA
(E
: Entity_Id
);
6476 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6477 -- no explicit alignment was given, set alignment to unknown, since
6478 -- back end knows what the alignment requirements are for atomic and
6479 -- full access arrays. Note: this is necessary for derived types.
6481 --------------------
6482 -- Set_Atomic_VFA --
6483 --------------------
6485 procedure Set_Atomic_VFA
(E
: Entity_Id
) is
6487 if Prag_Id
= Pragma_Volatile_Full_Access
then
6488 Set_Is_Volatile_Full_Access
(E
);
6493 if not Has_Alignment_Clause
(E
) then
6494 Set_Alignment
(E
, Uint_0
);
6498 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6501 Check_Ada_83_Warning
;
6502 Check_No_Identifiers
;
6503 Check_Arg_Count
(1);
6504 Check_Arg_Is_Local_Name
(Arg1
);
6505 E_Id
:= Get_Pragma_Arg
(Arg1
);
6507 if Etype
(E_Id
) = Any_Type
then
6512 D
:= Declaration_Node
(E
);
6515 -- A pragma that applies to a Ghost entity becomes Ghost for the
6516 -- purposes of legality checks and removal of ignored Ghost code.
6518 Mark_Pragma_As_Ghost
(N
, E
);
6520 -- Check duplicate before we chain ourselves
6522 Check_Duplicate_Pragma
(E
);
6524 -- Check Atomic and VFA used together
6526 if (Is_Atomic
(E
) and then Prag_Id
= Pragma_Volatile_Full_Access
)
6527 or else (Is_Volatile_Full_Access
(E
)
6528 and then (Prag_Id
= Pragma_Atomic
6530 Prag_Id
= Pragma_Shared
))
6533 ("cannot have Volatile_Full_Access and Atomic for same entity");
6536 -- Check for applying VFA to an entity which has aliased component
6538 if Prag_Id
= Pragma_Volatile_Full_Access
then
6541 Aliased_Comp
: Boolean := False;
6542 -- Set True if aliased component present
6545 if Is_Array_Type
(Etype
(E
)) then
6546 Aliased_Comp
:= Has_Aliased_Components
(Etype
(E
));
6548 -- Record case, too bad Has_Aliased_Components is not also
6549 -- set for records, should it be ???
6551 elsif Is_Record_Type
(Etype
(E
)) then
6552 Comp
:= First_Component_Or_Discriminant
(Etype
(E
));
6553 while Present
(Comp
) loop
6554 if Is_Aliased
(Comp
)
6555 or else Is_Aliased
(Etype
(Comp
))
6557 Aliased_Comp
:= True;
6561 Next_Component_Or_Discriminant
(Comp
);
6565 if Aliased_Comp
then
6567 ("cannot apply Volatile_Full_Access (aliased component "
6573 -- Now check appropriateness of the entity
6576 if Rep_Item_Too_Early
(E
, N
)
6578 Rep_Item_Too_Late
(E
, N
)
6582 Check_First_Subtype
(Arg1
);
6585 -- Attribute belongs on the base type. If the view of the type is
6586 -- currently private, it also belongs on the underlying type.
6588 if Prag_Id
= Pragma_Atomic
6590 Prag_Id
= Pragma_Shared
6592 Prag_Id
= Pragma_Volatile_Full_Access
6595 Set_Atomic_VFA
(Base_Type
(E
));
6596 Set_Atomic_VFA
(Underlying_Type
(E
));
6599 -- Atomic/Shared/Volatile_Full_Access imply Independent
6601 if Prag_Id
/= Pragma_Volatile
then
6602 Set_Is_Independent
(E
);
6603 Set_Is_Independent
(Base_Type
(E
));
6604 Set_Is_Independent
(Underlying_Type
(E
));
6606 if Prag_Id
= Pragma_Independent
then
6607 Record_Independence_Check
(N
, Base_Type
(E
));
6611 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6613 if Prag_Id
/= Pragma_Independent
then
6614 Set_Is_Volatile
(E
);
6615 Set_Is_Volatile
(Base_Type
(E
));
6616 Set_Is_Volatile
(Underlying_Type
(E
));
6618 Set_Treat_As_Volatile
(E
);
6619 Set_Treat_As_Volatile
(Underlying_Type
(E
));
6622 elsif K
= N_Object_Declaration
6623 or else (K
= N_Component_Declaration
6624 and then Original_Record_Component
(E
) = E
)
6626 if Rep_Item_Too_Late
(E
, N
) then
6630 if Prag_Id
= Pragma_Atomic
6632 Prag_Id
= Pragma_Shared
6634 Prag_Id
= Pragma_Volatile_Full_Access
6636 if Prag_Id
= Pragma_Volatile_Full_Access
then
6637 Set_Is_Volatile_Full_Access
(E
);
6642 -- If the object declaration has an explicit initialization, a
6643 -- temporary may have to be created to hold the expression, to
6644 -- ensure that access to the object remain atomic.
6646 if Nkind
(Parent
(E
)) = N_Object_Declaration
6647 and then Present
(Expression
(Parent
(E
)))
6649 Set_Has_Delayed_Freeze
(E
);
6653 -- Atomic/Shared/Volatile_Full_Access imply Independent
6655 if Prag_Id
/= Pragma_Volatile
then
6656 Set_Is_Independent
(E
);
6658 if Prag_Id
= Pragma_Independent
then
6659 Record_Independence_Check
(N
, E
);
6663 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6665 if Prag_Id
/= Pragma_Independent
then
6666 Set_Is_Volatile
(E
);
6667 Set_Treat_As_Volatile
(E
);
6671 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
6674 -- The following check is only relevant when SPARK_Mode is on as
6675 -- this is not a standard Ada legality rule. Pragma Volatile can
6676 -- only apply to a full type declaration or an object declaration
6677 -- (SPARK RM C.6(1)).
6680 and then Prag_Id
= Pragma_Volatile
6681 and then not Nkind_In
(K
, N_Full_Type_Declaration
,
6682 N_Object_Declaration
)
6685 ("argument of pragma % must denote a full type or object "
6686 & "declaration", Arg1
);
6688 end Process_Atomic_Independent_Shared_Volatile
;
6690 -------------------------------------------
6691 -- Process_Compile_Time_Warning_Or_Error --
6692 -------------------------------------------
6694 procedure Process_Compile_Time_Warning_Or_Error
is
6695 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
6698 Check_Arg_Count
(2);
6699 Check_No_Identifiers
;
6700 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
6701 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
6703 if Compile_Time_Known_Value
(Arg1x
) then
6704 if Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
))) then
6706 Str
: constant String_Id
:=
6707 Strval
(Get_Pragma_Arg
(Arg2
));
6708 Len
: constant Nat
:= String_Length
(Str
);
6713 Cent
: constant Entity_Id
:=
6714 Cunit_Entity
(Current_Sem_Unit
);
6716 Force
: constant Boolean :=
6717 Prag_Id
= Pragma_Compile_Time_Warning
6719 Is_Spec_Name
(Unit_Name
(Current_Sem_Unit
))
6720 and then (Ekind
(Cent
) /= E_Package
6721 or else not In_Private_Part
(Cent
));
6722 -- Set True if this is the warning case, and we are in the
6723 -- visible part of a package spec, or in a subprogram spec,
6724 -- in which case we want to force the client to see the
6725 -- warning, even though it is not in the main unit.
6728 -- Loop through segments of message separated by line feeds.
6729 -- We output these segments as separate messages with
6730 -- continuation marks for all but the first.
6735 Error_Msg_Strlen
:= 0;
6737 -- Loop to copy characters from argument to error message
6741 exit when Ptr
> Len
;
6742 CC
:= Get_String_Char
(Str
, Ptr
);
6745 -- Ignore wide chars ??? else store character
6747 if In_Character_Range
(CC
) then
6748 C
:= Get_Character
(CC
);
6749 exit when C
= ASCII
.LF
;
6750 Error_Msg_Strlen
:= Error_Msg_Strlen
+ 1;
6751 Error_Msg_String
(Error_Msg_Strlen
) := C
;
6755 -- Here with one line ready to go
6757 Error_Msg_Warn
:= Prag_Id
= Pragma_Compile_Time_Warning
;
6759 -- If this is a warning in a spec, then we want clients
6760 -- to see the warning, so mark the message with the
6761 -- special sequence !! to force the warning. In the case
6762 -- of a package spec, we do not force this if we are in
6763 -- the private part of the spec.
6766 if Cont
= False then
6767 Error_Msg_N
("<<~!!", Arg1
);
6770 Error_Msg_N
("\<<~!!", Arg1
);
6773 -- Error, rather than warning, or in a body, so we do not
6774 -- need to force visibility for client (error will be
6775 -- output in any case, and this is the situation in which
6776 -- we do not want a client to get a warning, since the
6777 -- warning is in the body or the spec private part).
6780 if Cont
= False then
6781 Error_Msg_N
("<<~", Arg1
);
6784 Error_Msg_N
("\<<~", Arg1
);
6788 exit when Ptr
> Len
;
6793 end Process_Compile_Time_Warning_Or_Error
;
6795 ------------------------
6796 -- Process_Convention --
6797 ------------------------
6799 procedure Process_Convention
6800 (C
: out Convention_Id
;
6801 Ent
: out Entity_Id
)
6805 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
);
6806 -- Called if we have more than one Export/Import/Convention pragma.
6807 -- This is generally illegal, but we have a special case of allowing
6808 -- Import and Interface to coexist if they specify the convention in
6809 -- a consistent manner. We are allowed to do this, since Interface is
6810 -- an implementation defined pragma, and we choose to do it since we
6811 -- know Rational allows this combination. S is the entity id of the
6812 -- subprogram in question. This procedure also sets the special flag
6813 -- Import_Interface_Present in both pragmas in the case where we do
6814 -- have matching Import and Interface pragmas.
6816 procedure Set_Convention_From_Pragma
(E
: Entity_Id
);
6817 -- Set convention in entity E, and also flag that the entity has a
6818 -- convention pragma. If entity is for a private or incomplete type,
6819 -- also set convention and flag on underlying type. This procedure
6820 -- also deals with the special case of C_Pass_By_Copy convention,
6821 -- and error checks for inappropriate convention specification.
6823 -------------------------------
6824 -- Diagnose_Multiple_Pragmas --
6825 -------------------------------
6827 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
) is
6828 Pdec
: constant Node_Id
:= Declaration_Node
(S
);
6832 function Same_Convention
(Decl
: Node_Id
) return Boolean;
6833 -- Decl is a pragma node. This function returns True if this
6834 -- pragma has a first argument that is an identifier with a
6835 -- Chars field corresponding to the Convention_Id C.
6837 function Same_Name
(Decl
: Node_Id
) return Boolean;
6838 -- Decl is a pragma node. This function returns True if this
6839 -- pragma has a second argument that is an identifier with a
6840 -- Chars field that matches the Chars of the current subprogram.
6842 ---------------------
6843 -- Same_Convention --
6844 ---------------------
6846 function Same_Convention
(Decl
: Node_Id
) return Boolean is
6847 Arg1
: constant Node_Id
:=
6848 First
(Pragma_Argument_Associations
(Decl
));
6851 if Present
(Arg1
) then
6853 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
6855 if Nkind
(Arg
) = N_Identifier
6856 and then Is_Convention_Name
(Chars
(Arg
))
6857 and then Get_Convention_Id
(Chars
(Arg
)) = C
6865 end Same_Convention
;
6871 function Same_Name
(Decl
: Node_Id
) return Boolean is
6872 Arg1
: constant Node_Id
:=
6873 First
(Pragma_Argument_Associations
(Decl
));
6881 Arg2
:= Next
(Arg1
);
6888 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
6890 if Nkind
(Arg
) = N_Identifier
6891 and then Chars
(Arg
) = Chars
(S
)
6900 -- Start of processing for Diagnose_Multiple_Pragmas
6905 -- Definitely give message if we have Convention/Export here
6907 if Prag_Id
= Pragma_Convention
or else Prag_Id
= Pragma_Export
then
6910 -- If we have an Import or Export, scan back from pragma to
6911 -- find any previous pragma applying to the same procedure.
6912 -- The scan will be terminated by the start of the list, or
6913 -- hitting the subprogram declaration. This won't allow one
6914 -- pragma to appear in the public part and one in the private
6915 -- part, but that seems very unlikely in practice.
6919 while Present
(Decl
) and then Decl
/= Pdec
loop
6921 -- Look for pragma with same name as us
6923 if Nkind
(Decl
) = N_Pragma
6924 and then Same_Name
(Decl
)
6926 -- Give error if same as our pragma or Export/Convention
6928 if Nam_In
(Pragma_Name
(Decl
), Name_Export
,
6934 -- Case of Import/Interface or the other way round
6936 elsif Nam_In
(Pragma_Name
(Decl
), Name_Interface
,
6939 -- Here we know that we have Import and Interface. It
6940 -- doesn't matter which way round they are. See if
6941 -- they specify the same convention. If so, all OK,
6942 -- and set special flags to stop other messages
6944 if Same_Convention
(Decl
) then
6945 Set_Import_Interface_Present
(N
);
6946 Set_Import_Interface_Present
(Decl
);
6949 -- If different conventions, special message
6952 Error_Msg_Sloc
:= Sloc
(Decl
);
6954 ("convention differs from that given#", Arg1
);
6964 -- Give message if needed if we fall through those tests
6965 -- except on Relaxed_RM_Semantics where we let go: either this
6966 -- is a case accepted/ignored by other Ada compilers (e.g.
6967 -- a mix of Convention and Import), or another error will be
6968 -- generated later (e.g. using both Import and Export).
6970 if Err
and not Relaxed_RM_Semantics
then
6972 ("at most one Convention/Export/Import pragma is allowed",
6975 end Diagnose_Multiple_Pragmas
;
6977 --------------------------------
6978 -- Set_Convention_From_Pragma --
6979 --------------------------------
6981 procedure Set_Convention_From_Pragma
(E
: Entity_Id
) is
6983 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6984 -- for an overridden dispatching operation. Technically this is
6985 -- an amendment and should only be done in Ada 2005 mode. However,
6986 -- this is clearly a mistake, since the problem that is addressed
6987 -- by this AI is that there is a clear gap in the RM.
6989 if Is_Dispatching_Operation
(E
)
6990 and then Present
(Overridden_Operation
(E
))
6991 and then C
/= Convention
(Overridden_Operation
(E
))
6994 ("cannot change convention for overridden dispatching "
6995 & "operation", Arg1
);
6998 -- Special checks for Convention_Stdcall
7000 if C
= Convention_Stdcall
then
7002 -- A dispatching call is not allowed. A dispatching subprogram
7003 -- cannot be used to interface to the Win32 API, so in fact
7004 -- this check does not impose any effective restriction.
7006 if Is_Dispatching_Operation
(E
) then
7007 Error_Msg_Sloc
:= Sloc
(E
);
7009 -- Note: make this unconditional so that if there is more
7010 -- than one call to which the pragma applies, we get a
7011 -- message for each call. Also don't use Error_Pragma,
7012 -- so that we get multiple messages.
7015 ("dispatching subprogram# cannot use Stdcall convention!",
7018 -- Subprograms are not allowed
7020 elsif not Is_Subprogram_Or_Generic_Subprogram
(E
)
7024 and then Ekind
(E
) /= E_Variable
7026 -- An access to subprogram is also allowed
7030 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
)
7032 -- Allow internal call to set convention of subprogram type
7034 and then not (Ekind
(E
) = E_Subprogram_Type
)
7037 ("second argument of pragma% must be subprogram (type)",
7042 -- Set the convention
7044 Set_Convention
(E
, C
);
7045 Set_Has_Convention_Pragma
(E
);
7047 -- For the case of a record base type, also set the convention of
7048 -- any anonymous access types declared in the record which do not
7049 -- currently have a specified convention.
7051 if Is_Record_Type
(E
) and then Is_Base_Type
(E
) then
7056 Comp
:= First_Component
(E
);
7057 while Present
(Comp
) loop
7058 if Present
(Etype
(Comp
))
7059 and then Ekind_In
(Etype
(Comp
),
7060 E_Anonymous_Access_Type
,
7061 E_Anonymous_Access_Subprogram_Type
)
7062 and then not Has_Convention_Pragma
(Comp
)
7064 Set_Convention
(Comp
, C
);
7067 Next_Component
(Comp
);
7072 -- Deal with incomplete/private type case, where underlying type
7073 -- is available, so set convention of that underlying type.
7075 if Is_Incomplete_Or_Private_Type
(E
)
7076 and then Present
(Underlying_Type
(E
))
7078 Set_Convention
(Underlying_Type
(E
), C
);
7079 Set_Has_Convention_Pragma
(Underlying_Type
(E
), True);
7082 -- A class-wide type should inherit the convention of the specific
7083 -- root type (although this isn't specified clearly by the RM).
7085 if Is_Type
(E
) and then Present
(Class_Wide_Type
(E
)) then
7086 Set_Convention
(Class_Wide_Type
(E
), C
);
7089 -- If the entity is a record type, then check for special case of
7090 -- C_Pass_By_Copy, which is treated the same as C except that the
7091 -- special record flag is set. This convention is only permitted
7092 -- on record types (see AI95-00131).
7094 if Cname
= Name_C_Pass_By_Copy
then
7095 if Is_Record_Type
(E
) then
7096 Set_C_Pass_By_Copy
(Base_Type
(E
));
7097 elsif Is_Incomplete_Or_Private_Type
(E
)
7098 and then Is_Record_Type
(Underlying_Type
(E
))
7100 Set_C_Pass_By_Copy
(Base_Type
(Underlying_Type
(E
)));
7103 ("C_Pass_By_Copy convention allowed only for record type",
7108 -- If the entity is a derived boolean type, check for the special
7109 -- case of convention C, C++, or Fortran, where we consider any
7110 -- nonzero value to represent true.
7112 if Is_Discrete_Type
(E
)
7113 and then Root_Type
(Etype
(E
)) = Standard_Boolean
7119 C
= Convention_Fortran
)
7121 Set_Nonzero_Is_True
(Base_Type
(E
));
7123 end Set_Convention_From_Pragma
;
7127 Comp_Unit
: Unit_Number_Type
;
7132 -- Start of processing for Process_Convention
7135 Check_At_Least_N_Arguments
(2);
7136 Check_Optional_Identifier
(Arg1
, Name_Convention
);
7137 Check_Arg_Is_Identifier
(Arg1
);
7138 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
7140 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7141 -- tested again below to set the critical flag).
7143 if Cname
= Name_C_Pass_By_Copy
then
7146 -- Otherwise we must have something in the standard convention list
7148 elsif Is_Convention_Name
(Cname
) then
7149 C
:= Get_Convention_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
7151 -- Otherwise warn on unrecognized convention
7154 if Warn_On_Export_Import
then
7156 ("??unrecognized convention name, C assumed",
7157 Get_Pragma_Arg
(Arg1
));
7163 Check_Optional_Identifier
(Arg2
, Name_Entity
);
7164 Check_Arg_Is_Local_Name
(Arg2
);
7166 Id
:= Get_Pragma_Arg
(Arg2
);
7169 if not Is_Entity_Name
(Id
) then
7170 Error_Pragma_Arg
("entity name required", Arg2
);
7175 -- Set entity to return
7179 -- Ada_Pass_By_Copy special checking
7181 if C
= Convention_Ada_Pass_By_Copy
then
7182 if not Is_First_Subtype
(E
) then
7184 ("convention `Ada_Pass_By_Copy` only allowed for types",
7188 if Is_By_Reference_Type
(E
) then
7190 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7194 -- Ada_Pass_By_Reference special checking
7196 elsif C
= Convention_Ada_Pass_By_Reference
then
7197 if not Is_First_Subtype
(E
) then
7199 ("convention `Ada_Pass_By_Reference` only allowed for types",
7203 if Is_By_Copy_Type
(E
) then
7205 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7210 -- Go to renamed subprogram if present, since convention applies to
7211 -- the actual renamed entity, not to the renaming entity. If the
7212 -- subprogram is inherited, go to parent subprogram.
7214 if Is_Subprogram
(E
)
7215 and then Present
(Alias
(E
))
7217 if Nkind
(Parent
(Declaration_Node
(E
))) =
7218 N_Subprogram_Renaming_Declaration
7220 if Scope
(E
) /= Scope
(Alias
(E
)) then
7222 ("cannot apply pragma% to non-local entity&#", E
);
7227 elsif Nkind_In
(Parent
(E
), N_Full_Type_Declaration
,
7228 N_Private_Extension_Declaration
)
7229 and then Scope
(E
) = Scope
(Alias
(E
))
7233 -- Return the parent subprogram the entity was inherited from
7239 -- Check that we are not applying this to a specless body. Relax this
7240 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
7242 if Is_Subprogram
(E
)
7243 and then Nkind
(Parent
(Declaration_Node
(E
))) = N_Subprogram_Body
7244 and then not Relaxed_RM_Semantics
7247 ("pragma% requires separate spec and must come before body");
7250 -- Check that we are not applying this to a named constant
7252 if Ekind_In
(E
, E_Named_Integer
, E_Named_Real
) then
7253 Error_Msg_Name_1
:= Pname
;
7255 ("cannot apply pragma% to named constant!",
7256 Get_Pragma_Arg
(Arg2
));
7258 ("\supply appropriate type for&!", Arg2
);
7261 if Ekind
(E
) = E_Enumeration_Literal
then
7262 Error_Pragma
("enumeration literal not allowed for pragma%");
7265 -- Check for rep item appearing too early or too late
7267 if Etype
(E
) = Any_Type
7268 or else Rep_Item_Too_Early
(E
, N
)
7272 elsif Present
(Underlying_Type
(E
)) then
7273 E
:= Underlying_Type
(E
);
7276 if Rep_Item_Too_Late
(E
, N
) then
7280 if Has_Convention_Pragma
(E
) then
7281 Diagnose_Multiple_Pragmas
(E
);
7283 elsif Convention
(E
) = Convention_Protected
7284 or else Ekind
(Scope
(E
)) = E_Protected_Type
7287 ("a protected operation cannot be given a different convention",
7291 -- For Intrinsic, a subprogram is required
7293 if C
= Convention_Intrinsic
7294 and then not Is_Subprogram_Or_Generic_Subprogram
(E
)
7296 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7298 if not (Is_Type
(E
) and then Relaxed_RM_Semantics
) then
7300 ("second argument of pragma% must be a subprogram", Arg2
);
7304 -- Deal with non-subprogram cases
7306 if not Is_Subprogram_Or_Generic_Subprogram
(E
) then
7307 Set_Convention_From_Pragma
(E
);
7311 -- The pragma must apply to a first subtype, but it can also
7312 -- apply to a generic type in a generic formal part, in which
7313 -- case it will also appear in the corresponding instance.
7315 if Is_Generic_Type
(E
) or else In_Instance
then
7318 Check_First_Subtype
(Arg2
);
7321 Set_Convention_From_Pragma
(Base_Type
(E
));
7323 -- For access subprograms, we must set the convention on the
7324 -- internally generated directly designated type as well.
7326 if Ekind
(E
) = E_Access_Subprogram_Type
then
7327 Set_Convention_From_Pragma
(Directly_Designated_Type
(E
));
7331 -- For the subprogram case, set proper convention for all homonyms
7332 -- in same scope and the same declarative part, i.e. the same
7333 -- compilation unit.
7336 Comp_Unit
:= Get_Source_Unit
(E
);
7337 Set_Convention_From_Pragma
(E
);
7339 -- Treat a pragma Import as an implicit body, and pragma import
7340 -- as implicit reference (for navigation in GPS).
7342 if Prag_Id
= Pragma_Import
then
7343 Generate_Reference
(E
, Id
, 'b');
7345 -- For exported entities we restrict the generation of references
7346 -- to entities exported to foreign languages since entities
7347 -- exported to Ada do not provide further information to GPS and
7348 -- add undesired references to the output of the gnatxref tool.
7350 elsif Prag_Id
= Pragma_Export
7351 and then Convention
(E
) /= Convention_Ada
7353 Generate_Reference
(E
, Id
, 'i');
7356 -- If the pragma comes from an aspect, it only applies to the
7357 -- given entity, not its homonyms.
7359 if From_Aspect_Specification
(N
) then
7363 -- Otherwise Loop through the homonyms of the pragma argument's
7364 -- entity, an apply convention to those in the current scope.
7370 exit when No
(E1
) or else Scope
(E1
) /= Current_Scope
;
7372 -- Ignore entry for which convention is already set
7374 if Has_Convention_Pragma
(E1
) then
7378 -- Do not set the pragma on inherited operations or on formal
7381 if Comes_From_Source
(E1
)
7382 and then Comp_Unit
= Get_Source_Unit
(E1
)
7383 and then not Is_Formal_Subprogram
(E1
)
7384 and then Nkind
(Original_Node
(Parent
(E1
))) /=
7385 N_Full_Type_Declaration
7387 if Present
(Alias
(E1
))
7388 and then Scope
(E1
) /= Scope
(Alias
(E1
))
7391 ("cannot apply pragma% to non-local entity& declared#",
7395 Set_Convention_From_Pragma
(E1
);
7397 if Prag_Id
= Pragma_Import
then
7398 Generate_Reference
(E1
, Id
, 'b');
7406 end Process_Convention
;
7408 ----------------------------------------
7409 -- Process_Disable_Enable_Atomic_Sync --
7410 ----------------------------------------
7412 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
) is
7414 Check_No_Identifiers
;
7415 Check_At_Most_N_Arguments
(1);
7417 -- Modeled internally as
7418 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7422 Pragma_Identifier
=>
7423 Make_Identifier
(Loc
, Nam
),
7424 Pragma_Argument_Associations
=> New_List
(
7425 Make_Pragma_Argument_Association
(Loc
,
7427 Make_Identifier
(Loc
, Name_Atomic_Synchronization
)))));
7429 if Present
(Arg1
) then
7430 Append_To
(Pragma_Argument_Associations
(N
), New_Copy
(Arg1
));
7434 end Process_Disable_Enable_Atomic_Sync
;
7436 -------------------------------------------------
7437 -- Process_Extended_Import_Export_Internal_Arg --
7438 -------------------------------------------------
7440 procedure Process_Extended_Import_Export_Internal_Arg
7441 (Arg_Internal
: Node_Id
:= Empty
)
7444 if No
(Arg_Internal
) then
7445 Error_Pragma
("Internal parameter required for pragma%");
7448 if Nkind
(Arg_Internal
) = N_Identifier
then
7451 elsif Nkind
(Arg_Internal
) = N_Operator_Symbol
7452 and then (Prag_Id
= Pragma_Import_Function
7454 Prag_Id
= Pragma_Export_Function
)
7460 ("wrong form for Internal parameter for pragma%", Arg_Internal
);
7463 Check_Arg_Is_Local_Name
(Arg_Internal
);
7464 end Process_Extended_Import_Export_Internal_Arg
;
7466 --------------------------------------------------
7467 -- Process_Extended_Import_Export_Object_Pragma --
7468 --------------------------------------------------
7470 procedure Process_Extended_Import_Export_Object_Pragma
7471 (Arg_Internal
: Node_Id
;
7472 Arg_External
: Node_Id
;
7478 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
7479 Def_Id
:= Entity
(Arg_Internal
);
7481 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
7483 ("pragma% must designate an object", Arg_Internal
);
7486 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
7488 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
7491 ("previous Common/Psect_Object applies, pragma % not permitted",
7495 if Rep_Item_Too_Late
(Def_Id
, N
) then
7499 Set_Extended_Import_Export_External_Name
(Def_Id
, Arg_External
);
7501 if Present
(Arg_Size
) then
7502 Check_Arg_Is_External_Name
(Arg_Size
);
7505 -- Export_Object case
7507 if Prag_Id
= Pragma_Export_Object
then
7508 if not Is_Library_Level_Entity
(Def_Id
) then
7510 ("argument for pragma% must be library level entity",
7514 if Ekind
(Current_Scope
) = E_Generic_Package
then
7515 Error_Pragma
("pragma& cannot appear in a generic unit");
7518 if not Size_Known_At_Compile_Time
(Etype
(Def_Id
)) then
7520 ("exported object must have compile time known size",
7524 if Warn_On_Export_Import
and then Is_Exported
(Def_Id
) then
7525 Error_Msg_N
("??duplicate Export_Object pragma", N
);
7527 Set_Exported
(Def_Id
, Arg_Internal
);
7530 -- Import_Object case
7533 if Is_Concurrent_Type
(Etype
(Def_Id
)) then
7535 ("cannot use pragma% for task/protected object",
7539 if Ekind
(Def_Id
) = E_Constant
then
7541 ("cannot import a constant", Arg_Internal
);
7544 if Warn_On_Export_Import
7545 and then Has_Discriminants
(Etype
(Def_Id
))
7548 ("imported value must be initialized??", Arg_Internal
);
7551 if Warn_On_Export_Import
7552 and then Is_Access_Type
(Etype
(Def_Id
))
7555 ("cannot import object of an access type??", Arg_Internal
);
7558 if Warn_On_Export_Import
7559 and then Is_Imported
(Def_Id
)
7561 Error_Msg_N
("??duplicate Import_Object pragma", N
);
7563 -- Check for explicit initialization present. Note that an
7564 -- initialization generated by the code generator, e.g. for an
7565 -- access type, does not count here.
7567 elsif Present
(Expression
(Parent
(Def_Id
)))
7570 (Original_Node
(Expression
(Parent
(Def_Id
))))
7572 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7574 ("imported entities cannot be initialized (RM B.1(24))",
7575 "\no initialization allowed for & declared#", Arg1
);
7577 Set_Imported
(Def_Id
);
7578 Note_Possible_Modification
(Arg_Internal
, Sure
=> False);
7581 end Process_Extended_Import_Export_Object_Pragma
;
7583 ------------------------------------------------------
7584 -- Process_Extended_Import_Export_Subprogram_Pragma --
7585 ------------------------------------------------------
7587 procedure Process_Extended_Import_Export_Subprogram_Pragma
7588 (Arg_Internal
: Node_Id
;
7589 Arg_External
: Node_Id
;
7590 Arg_Parameter_Types
: Node_Id
;
7591 Arg_Result_Type
: Node_Id
:= Empty
;
7592 Arg_Mechanism
: Node_Id
;
7593 Arg_Result_Mechanism
: Node_Id
:= Empty
)
7599 Ambiguous
: Boolean;
7602 function Same_Base_Type
7604 Formal
: Entity_Id
) return Boolean;
7605 -- Determines if Ptype references the type of Formal. Note that only
7606 -- the base types need to match according to the spec. Ptype here is
7607 -- the argument from the pragma, which is either a type name, or an
7608 -- access attribute.
7610 --------------------
7611 -- Same_Base_Type --
7612 --------------------
7614 function Same_Base_Type
7616 Formal
: Entity_Id
) return Boolean
7618 Ftyp
: constant Entity_Id
:= Base_Type
(Etype
(Formal
));
7622 -- Case where pragma argument is typ'Access
7624 if Nkind
(Ptype
) = N_Attribute_Reference
7625 and then Attribute_Name
(Ptype
) = Name_Access
7627 Pref
:= Prefix
(Ptype
);
7630 if not Is_Entity_Name
(Pref
)
7631 or else Entity
(Pref
) = Any_Type
7636 -- We have a match if the corresponding argument is of an
7637 -- anonymous access type, and its designated type matches the
7638 -- type of the prefix of the access attribute
7640 return Ekind
(Ftyp
) = E_Anonymous_Access_Type
7641 and then Base_Type
(Entity
(Pref
)) =
7642 Base_Type
(Etype
(Designated_Type
(Ftyp
)));
7644 -- Case where pragma argument is a type name
7649 if not Is_Entity_Name
(Ptype
)
7650 or else Entity
(Ptype
) = Any_Type
7655 -- We have a match if the corresponding argument is of the type
7656 -- given in the pragma (comparing base types)
7658 return Base_Type
(Entity
(Ptype
)) = Ftyp
;
7662 -- Start of processing for
7663 -- Process_Extended_Import_Export_Subprogram_Pragma
7666 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
7670 -- Loop through homonyms (overloadings) of the entity
7672 Hom_Id
:= Entity
(Arg_Internal
);
7673 while Present
(Hom_Id
) loop
7674 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
7676 -- We need a subprogram in the current scope
7678 if not Is_Subprogram
(Def_Id
)
7679 or else Scope
(Def_Id
) /= Current_Scope
7686 -- Pragma cannot apply to subprogram body
7688 if Is_Subprogram
(Def_Id
)
7689 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
7693 ("pragma% requires separate spec"
7694 & " and must come before body");
7697 -- Test result type if given, note that the result type
7698 -- parameter can only be present for the function cases.
7700 if Present
(Arg_Result_Type
)
7701 and then not Same_Base_Type
(Arg_Result_Type
, Def_Id
)
7705 elsif Etype
(Def_Id
) /= Standard_Void_Type
7707 Nam_In
(Pname
, Name_Export_Procedure
, Name_Import_Procedure
)
7711 -- Test parameter types if given. Note that this parameter
7712 -- has not been analyzed (and must not be, since it is
7713 -- semantic nonsense), so we get it as the parser left it.
7715 elsif Present
(Arg_Parameter_Types
) then
7716 Check_Matching_Types
: declare
7721 Formal
:= First_Formal
(Def_Id
);
7723 if Nkind
(Arg_Parameter_Types
) = N_Null
then
7724 if Present
(Formal
) then
7728 -- A list of one type, e.g. (List) is parsed as
7729 -- a parenthesized expression.
7731 elsif Nkind
(Arg_Parameter_Types
) /= N_Aggregate
7732 and then Paren_Count
(Arg_Parameter_Types
) = 1
7735 or else Present
(Next_Formal
(Formal
))
7740 Same_Base_Type
(Arg_Parameter_Types
, Formal
);
7743 -- A list of more than one type is parsed as a aggregate
7745 elsif Nkind
(Arg_Parameter_Types
) = N_Aggregate
7746 and then Paren_Count
(Arg_Parameter_Types
) = 0
7748 Ptype
:= First
(Expressions
(Arg_Parameter_Types
));
7749 while Present
(Ptype
) or else Present
(Formal
) loop
7752 or else not Same_Base_Type
(Ptype
, Formal
)
7757 Next_Formal
(Formal
);
7762 -- Anything else is of the wrong form
7766 ("wrong form for Parameter_Types parameter",
7767 Arg_Parameter_Types
);
7769 end Check_Matching_Types
;
7772 -- Match is now False if the entry we found did not match
7773 -- either a supplied Parameter_Types or Result_Types argument
7779 -- Ambiguous case, the flag Ambiguous shows if we already
7780 -- detected this and output the initial messages.
7783 if not Ambiguous
then
7785 Error_Msg_Name_1
:= Pname
;
7787 ("pragma% does not uniquely identify subprogram!",
7789 Error_Msg_Sloc
:= Sloc
(Ent
);
7790 Error_Msg_N
("matching subprogram #!", N
);
7794 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7795 Error_Msg_N
("matching subprogram #!", N
);
7800 Hom_Id
:= Homonym
(Hom_Id
);
7803 -- See if we found an entry
7806 if not Ambiguous
then
7807 if Is_Generic_Subprogram
(Entity
(Arg_Internal
)) then
7809 ("pragma% cannot be given for generic subprogram");
7812 ("pragma% does not identify local subprogram");
7819 -- Import pragmas must be for imported entities
7821 if Prag_Id
= Pragma_Import_Function
7823 Prag_Id
= Pragma_Import_Procedure
7825 Prag_Id
= Pragma_Import_Valued_Procedure
7827 if not Is_Imported
(Ent
) then
7829 ("pragma Import or Interface must precede pragma%");
7832 -- Here we have the Export case which can set the entity as exported
7834 -- But does not do so if the specified external name is null, since
7835 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7836 -- compatible) to request no external name.
7838 elsif Nkind
(Arg_External
) = N_String_Literal
7839 and then String_Length
(Strval
(Arg_External
)) = 0
7843 -- In all other cases, set entity as exported
7846 Set_Exported
(Ent
, Arg_Internal
);
7849 -- Special processing for Valued_Procedure cases
7851 if Prag_Id
= Pragma_Import_Valued_Procedure
7853 Prag_Id
= Pragma_Export_Valued_Procedure
7855 Formal
:= First_Formal
(Ent
);
7858 Error_Pragma
("at least one parameter required for pragma%");
7860 elsif Ekind
(Formal
) /= E_Out_Parameter
then
7861 Error_Pragma
("first parameter must have mode out for pragma%");
7864 Set_Is_Valued_Procedure
(Ent
);
7868 Set_Extended_Import_Export_External_Name
(Ent
, Arg_External
);
7870 -- Process Result_Mechanism argument if present. We have already
7871 -- checked that this is only allowed for the function case.
7873 if Present
(Arg_Result_Mechanism
) then
7874 Set_Mechanism_Value
(Ent
, Arg_Result_Mechanism
);
7877 -- Process Mechanism parameter if present. Note that this parameter
7878 -- is not analyzed, and must not be analyzed since it is semantic
7879 -- nonsense, so we get it in exactly as the parser left it.
7881 if Present
(Arg_Mechanism
) then
7889 -- A single mechanism association without a formal parameter
7890 -- name is parsed as a parenthesized expression. All other
7891 -- cases are parsed as aggregates, so we rewrite the single
7892 -- parameter case as an aggregate for consistency.
7894 if Nkind
(Arg_Mechanism
) /= N_Aggregate
7895 and then Paren_Count
(Arg_Mechanism
) = 1
7897 Rewrite
(Arg_Mechanism
,
7898 Make_Aggregate
(Sloc
(Arg_Mechanism
),
7899 Expressions
=> New_List
(
7900 Relocate_Node
(Arg_Mechanism
))));
7903 -- Case of only mechanism name given, applies to all formals
7905 if Nkind
(Arg_Mechanism
) /= N_Aggregate
then
7906 Formal
:= First_Formal
(Ent
);
7907 while Present
(Formal
) loop
7908 Set_Mechanism_Value
(Formal
, Arg_Mechanism
);
7909 Next_Formal
(Formal
);
7912 -- Case of list of mechanism associations given
7915 if Null_Record_Present
(Arg_Mechanism
) then
7917 ("inappropriate form for Mechanism parameter",
7921 -- Deal with positional ones first
7923 Formal
:= First_Formal
(Ent
);
7925 if Present
(Expressions
(Arg_Mechanism
)) then
7926 Mname
:= First
(Expressions
(Arg_Mechanism
));
7927 while Present
(Mname
) loop
7930 ("too many mechanism associations", Mname
);
7933 Set_Mechanism_Value
(Formal
, Mname
);
7934 Next_Formal
(Formal
);
7939 -- Deal with named entries
7941 if Present
(Component_Associations
(Arg_Mechanism
)) then
7942 Massoc
:= First
(Component_Associations
(Arg_Mechanism
));
7943 while Present
(Massoc
) loop
7944 Choice
:= First
(Choices
(Massoc
));
7946 if Nkind
(Choice
) /= N_Identifier
7947 or else Present
(Next
(Choice
))
7950 ("incorrect form for mechanism association",
7954 Formal
:= First_Formal
(Ent
);
7958 ("parameter name & not present", Choice
);
7961 if Chars
(Choice
) = Chars
(Formal
) then
7963 (Formal
, Expression
(Massoc
));
7965 -- Set entity on identifier (needed by ASIS)
7967 Set_Entity
(Choice
, Formal
);
7972 Next_Formal
(Formal
);
7981 end Process_Extended_Import_Export_Subprogram_Pragma
;
7983 --------------------------
7984 -- Process_Generic_List --
7985 --------------------------
7987 procedure Process_Generic_List
is
7992 Check_No_Identifiers
;
7993 Check_At_Least_N_Arguments
(1);
7995 -- Check all arguments are names of generic units or instances
7998 while Present
(Arg
) loop
7999 Exp
:= Get_Pragma_Arg
(Arg
);
8002 if not Is_Entity_Name
(Exp
)
8004 (not Is_Generic_Instance
(Entity
(Exp
))
8006 not Is_Generic_Unit
(Entity
(Exp
)))
8009 ("pragma% argument must be name of generic unit/instance",
8015 end Process_Generic_List
;
8017 ------------------------------------
8018 -- Process_Import_Predefined_Type --
8019 ------------------------------------
8021 procedure Process_Import_Predefined_Type
is
8022 Loc
: constant Source_Ptr
:= Sloc
(N
);
8024 Ftyp
: Node_Id
:= Empty
;
8030 String_To_Name_Buffer
(Strval
(Expression
(Arg3
)));
8033 Elmt
:= First_Elmt
(Predefined_Float_Types
);
8034 while Present
(Elmt
) and then Chars
(Node
(Elmt
)) /= Nam
loop
8038 Ftyp
:= Node
(Elmt
);
8040 if Present
(Ftyp
) then
8042 -- Don't build a derived type declaration, because predefined C
8043 -- types have no declaration anywhere, so cannot really be named.
8044 -- Instead build a full type declaration, starting with an
8045 -- appropriate type definition is built
8047 if Is_Floating_Point_Type
(Ftyp
) then
8048 Def
:= Make_Floating_Point_Definition
(Loc
,
8049 Make_Integer_Literal
(Loc
, Digits_Value
(Ftyp
)),
8050 Make_Real_Range_Specification
(Loc
,
8051 Make_Real_Literal
(Loc
, Realval
(Type_Low_Bound
(Ftyp
))),
8052 Make_Real_Literal
(Loc
, Realval
(Type_High_Bound
(Ftyp
)))));
8054 -- Should never have a predefined type we cannot handle
8057 raise Program_Error
;
8060 -- Build and insert a Full_Type_Declaration, which will be
8061 -- analyzed as soon as this list entry has been analyzed.
8063 Decl
:= Make_Full_Type_Declaration
(Loc
,
8064 Make_Defining_Identifier
(Loc
, Chars
(Expression
(Arg2
))),
8065 Type_Definition
=> Def
);
8067 Insert_After
(N
, Decl
);
8068 Mark_Rewrite_Insertion
(Decl
);
8071 Error_Pragma_Arg
("no matching type found for pragma%",
8074 end Process_Import_Predefined_Type
;
8076 ---------------------------------
8077 -- Process_Import_Or_Interface --
8078 ---------------------------------
8080 procedure Process_Import_Or_Interface
is
8086 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8087 -- pragma Import (Entity, "external name");
8089 if Relaxed_RM_Semantics
8090 and then Arg_Count
= 2
8091 and then Prag_Id
= Pragma_Import
8092 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
8095 Def_Id
:= Get_Pragma_Arg
(Arg1
);
8098 if not Is_Entity_Name
(Def_Id
) then
8099 Error_Pragma_Arg
("entity name required", Arg1
);
8102 Def_Id
:= Entity
(Def_Id
);
8103 Kill_Size_Check_Code
(Def_Id
);
8104 Note_Possible_Modification
(Get_Pragma_Arg
(Arg1
), Sure
=> False);
8107 Process_Convention
(C
, Def_Id
);
8109 -- A pragma that applies to a Ghost entity becomes Ghost for the
8110 -- purposes of legality checks and removal of ignored Ghost code.
8112 Mark_Pragma_As_Ghost
(N
, Def_Id
);
8113 Kill_Size_Check_Code
(Def_Id
);
8114 Note_Possible_Modification
(Get_Pragma_Arg
(Arg2
), Sure
=> False);
8117 -- Various error checks
8119 if Ekind_In
(Def_Id
, E_Variable
, E_Constant
) then
8121 -- We do not permit Import to apply to a renaming declaration
8123 if Present
(Renamed_Object
(Def_Id
)) then
8125 ("pragma% not allowed for object renaming", Arg2
);
8127 -- User initialization is not allowed for imported object, but
8128 -- the object declaration may contain a default initialization,
8129 -- that will be discarded. Note that an explicit initialization
8130 -- only counts if it comes from source, otherwise it is simply
8131 -- the code generator making an implicit initialization explicit.
8133 elsif Present
(Expression
(Parent
(Def_Id
)))
8134 and then Comes_From_Source
8135 (Original_Node
(Expression
(Parent
(Def_Id
))))
8137 -- Set imported flag to prevent cascaded errors
8139 Set_Is_Imported
(Def_Id
);
8141 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8143 ("no initialization allowed for declaration of& #",
8144 "\imported entities cannot be initialized (RM B.1(24))",
8148 -- If the pragma comes from an aspect specification the
8149 -- Is_Imported flag has already been set.
8151 if not From_Aspect_Specification
(N
) then
8152 Set_Imported
(Def_Id
);
8155 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
8157 -- Note that we do not set Is_Public here. That's because we
8158 -- only want to set it if there is no address clause, and we
8159 -- don't know that yet, so we delay that processing till
8162 -- pragma Import completes deferred constants
8164 if Ekind
(Def_Id
) = E_Constant
then
8165 Set_Has_Completion
(Def_Id
);
8168 -- It is not possible to import a constant of an unconstrained
8169 -- array type (e.g. string) because there is no simple way to
8170 -- write a meaningful subtype for it.
8172 if Is_Array_Type
(Etype
(Def_Id
))
8173 and then not Is_Constrained
(Etype
(Def_Id
))
8176 ("imported constant& must have a constrained subtype",
8181 elsif Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8183 -- If the name is overloaded, pragma applies to all of the denoted
8184 -- entities in the same declarative part, unless the pragma comes
8185 -- from an aspect specification or was generated by the compiler
8186 -- (such as for pragma Provide_Shift_Operators).
8189 while Present
(Hom_Id
) loop
8191 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8193 -- Ignore inherited subprograms because the pragma will apply
8194 -- to the parent operation, which is the one called.
8196 if Is_Overloadable
(Def_Id
)
8197 and then Present
(Alias
(Def_Id
))
8201 -- If it is not a subprogram, it must be in an outer scope and
8202 -- pragma does not apply.
8204 elsif not Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8207 -- The pragma does not apply to primitives of interfaces
8209 elsif Is_Dispatching_Operation
(Def_Id
)
8210 and then Present
(Find_Dispatching_Type
(Def_Id
))
8211 and then Is_Interface
(Find_Dispatching_Type
(Def_Id
))
8215 -- Verify that the homonym is in the same declarative part (not
8216 -- just the same scope). If the pragma comes from an aspect
8217 -- specification we know that it is part of the declaration.
8219 elsif Parent
(Unit_Declaration_Node
(Def_Id
)) /= Parent
(N
)
8220 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit_Aux
8221 and then not From_Aspect_Specification
(N
)
8226 -- If the pragma comes from an aspect specification the
8227 -- Is_Imported flag has already been set.
8229 if not From_Aspect_Specification
(N
) then
8230 Set_Imported
(Def_Id
);
8233 -- Reject an Import applied to an abstract subprogram
8235 if Is_Subprogram
(Def_Id
)
8236 and then Is_Abstract_Subprogram
(Def_Id
)
8238 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8240 ("cannot import abstract subprogram& declared#",
8244 -- Special processing for Convention_Intrinsic
8246 if C
= Convention_Intrinsic
then
8248 -- Link_Name argument not allowed for intrinsic
8252 Set_Is_Intrinsic_Subprogram
(Def_Id
);
8254 -- If no external name is present, then check that this
8255 -- is a valid intrinsic subprogram. If an external name
8256 -- is present, then this is handled by the back end.
8259 Check_Intrinsic_Subprogram
8260 (Def_Id
, Get_Pragma_Arg
(Arg2
));
8264 -- Verify that the subprogram does not have a completion
8265 -- through a renaming declaration. For other completions the
8266 -- pragma appears as a too late representation.
8269 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Def_Id
);
8273 and then Nkind
(Decl
) = N_Subprogram_Declaration
8274 and then Present
(Corresponding_Body
(Decl
))
8275 and then Nkind
(Unit_Declaration_Node
8276 (Corresponding_Body
(Decl
))) =
8277 N_Subprogram_Renaming_Declaration
8279 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8281 ("cannot import&, renaming already provided for "
8282 & "declaration #", N
, Def_Id
);
8286 -- If the pragma comes from an aspect specification, there
8287 -- must be an Import aspect specified as well. In the rare
8288 -- case where Import is set to False, the suprogram needs to
8289 -- have a local completion.
8292 Imp_Aspect
: constant Node_Id
:=
8293 Find_Aspect
(Def_Id
, Aspect_Import
);
8297 if Present
(Imp_Aspect
)
8298 and then Present
(Expression
(Imp_Aspect
))
8300 Expr
:= Expression
(Imp_Aspect
);
8301 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8303 if Is_Entity_Name
(Expr
)
8304 and then Entity
(Expr
) = Standard_True
8306 Set_Has_Completion
(Def_Id
);
8309 -- If there is no expression, the default is True, as for
8310 -- all boolean aspects. Same for the older pragma.
8313 Set_Has_Completion
(Def_Id
);
8317 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
8320 if Is_Compilation_Unit
(Hom_Id
) then
8322 -- Its possible homonyms are not affected by the pragma.
8323 -- Such homonyms might be present in the context of other
8324 -- units being compiled.
8328 elsif From_Aspect_Specification
(N
) then
8331 -- If the pragma was created by the compiler, then we don't
8332 -- want it to apply to other homonyms. This kind of case can
8333 -- occur when using pragma Provide_Shift_Operators, which
8334 -- generates implicit shift and rotate operators with Import
8335 -- pragmas that might apply to earlier explicit or implicit
8336 -- declarations marked with Import (for example, coming from
8337 -- an earlier pragma Provide_Shift_Operators for another type),
8338 -- and we don't generally want other homonyms being treated
8339 -- as imported or the pragma flagged as an illegal duplicate.
8341 elsif not Comes_From_Source
(N
) then
8345 Hom_Id
:= Homonym
(Hom_Id
);
8349 -- Import a CPP class
8351 elsif C
= Convention_CPP
8352 and then (Is_Record_Type
(Def_Id
)
8353 or else Ekind
(Def_Id
) = E_Incomplete_Type
)
8355 if Ekind
(Def_Id
) = E_Incomplete_Type
then
8356 if Present
(Full_View
(Def_Id
)) then
8357 Def_Id
:= Full_View
(Def_Id
);
8361 ("cannot import 'C'P'P type before full declaration seen",
8362 Get_Pragma_Arg
(Arg2
));
8364 -- Although we have reported the error we decorate it as
8365 -- CPP_Class to avoid reporting spurious errors
8367 Set_Is_CPP_Class
(Def_Id
);
8372 -- Types treated as CPP classes must be declared limited (note:
8373 -- this used to be a warning but there is no real benefit to it
8374 -- since we did effectively intend to treat the type as limited
8377 if not Is_Limited_Type
(Def_Id
) then
8379 ("imported 'C'P'P type must be limited",
8380 Get_Pragma_Arg
(Arg2
));
8383 if Etype
(Def_Id
) /= Def_Id
8384 and then not Is_CPP_Class
(Root_Type
(Def_Id
))
8386 Error_Msg_N
("root type must be a 'C'P'P type", Arg1
);
8389 Set_Is_CPP_Class
(Def_Id
);
8391 -- Imported CPP types must not have discriminants (because C++
8392 -- classes do not have discriminants).
8394 if Has_Discriminants
(Def_Id
) then
8396 ("imported 'C'P'P type cannot have discriminants",
8397 First
(Discriminant_Specifications
8398 (Declaration_Node
(Def_Id
))));
8401 -- Check that components of imported CPP types do not have default
8402 -- expressions. For private types this check is performed when the
8403 -- full view is analyzed (see Process_Full_View).
8405 if not Is_Private_Type
(Def_Id
) then
8406 Check_CPP_Type_Has_No_Defaults
(Def_Id
);
8409 -- Import a CPP exception
8411 elsif C
= Convention_CPP
8412 and then Ekind
(Def_Id
) = E_Exception
8416 ("'External_'Name arguments is required for 'Cpp exception",
8419 -- As only a string is allowed, Check_Arg_Is_External_Name
8422 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
8425 if Present
(Arg4
) then
8427 ("Link_Name argument not allowed for imported Cpp exception",
8431 -- Do not call Set_Interface_Name as the name of the exception
8432 -- shouldn't be modified (and in particular it shouldn't be
8433 -- the External_Name). For exceptions, the External_Name is the
8434 -- name of the RTTI structure.
8436 -- ??? Emit an error if pragma Import/Export_Exception is present
8438 elsif Nkind
(Parent
(Def_Id
)) = N_Incomplete_Type_Declaration
then
8440 Check_Arg_Count
(3);
8441 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
8443 Process_Import_Predefined_Type
;
8447 ("second argument of pragma% must be object, subprogram "
8448 & "or incomplete type",
8452 -- If this pragma applies to a compilation unit, then the unit, which
8453 -- is a subprogram, does not require (or allow) a body. We also do
8454 -- not need to elaborate imported procedures.
8456 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
8458 Cunit
: constant Node_Id
:= Parent
(Parent
(N
));
8460 Set_Body_Required
(Cunit
, False);
8463 end Process_Import_Or_Interface
;
8465 --------------------
8466 -- Process_Inline --
8467 --------------------
8469 procedure Process_Inline
(Status
: Inline_Status
) is
8476 Ghost_Error_Posted
: Boolean := False;
8477 -- Flag set when an error concerning the illegal mix of Ghost and
8478 -- non-Ghost subprograms is emitted.
8480 Ghost_Id
: Entity_Id
:= Empty
;
8481 -- The entity of the first Ghost subprogram encountered while
8482 -- processing the arguments of the pragma.
8484 procedure Make_Inline
(Subp
: Entity_Id
);
8485 -- Subp is the defining unit name of the subprogram declaration. Set
8486 -- the flag, as well as the flag in the corresponding body, if there
8489 procedure Set_Inline_Flags
(Subp
: Entity_Id
);
8490 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8491 -- Has_Pragma_Inline_Always for the Inline_Always case.
8493 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean;
8494 -- Returns True if it can be determined at this stage that inlining
8495 -- is not possible, for example if the body is available and contains
8496 -- exception handlers, we prevent inlining, since otherwise we can
8497 -- get undefined symbols at link time. This function also emits a
8498 -- warning if front-end inlining is enabled and the pragma appears
8501 -- ??? is business with link symbols still valid, or does it relate
8502 -- to front end ZCX which is being phased out ???
8504 ---------------------------
8505 -- Inlining_Not_Possible --
8506 ---------------------------
8508 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean is
8509 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
8513 if Nkind
(Decl
) = N_Subprogram_Body
then
8514 Stats
:= Handled_Statement_Sequence
(Decl
);
8515 return Present
(Exception_Handlers
(Stats
))
8516 or else Present
(At_End_Proc
(Stats
));
8518 elsif Nkind
(Decl
) = N_Subprogram_Declaration
8519 and then Present
(Corresponding_Body
(Decl
))
8521 if Front_End_Inlining
8522 and then Analyzed
(Corresponding_Body
(Decl
))
8524 Error_Msg_N
("pragma appears too late, ignored??", N
);
8527 -- If the subprogram is a renaming as body, the body is just a
8528 -- call to the renamed subprogram, and inlining is trivially
8532 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
8533 N_Subprogram_Renaming_Declaration
8539 Handled_Statement_Sequence
8540 (Unit_Declaration_Node
(Corresponding_Body
(Decl
)));
8543 Present
(Exception_Handlers
(Stats
))
8544 or else Present
(At_End_Proc
(Stats
));
8548 -- If body is not available, assume the best, the check is
8549 -- performed again when compiling enclosing package bodies.
8553 end Inlining_Not_Possible
;
8559 procedure Make_Inline
(Subp
: Entity_Id
) is
8560 Kind
: constant Entity_Kind
:= Ekind
(Subp
);
8561 Inner_Subp
: Entity_Id
:= Subp
;
8564 -- Ignore if bad type, avoid cascaded error
8566 if Etype
(Subp
) = Any_Type
then
8570 -- If inlining is not possible, for now do not treat as an error
8572 elsif Status
/= Suppressed
8573 and then Inlining_Not_Possible
(Subp
)
8578 -- Here we have a candidate for inlining, but we must exclude
8579 -- derived operations. Otherwise we would end up trying to inline
8580 -- a phantom declaration, and the result would be to drag in a
8581 -- body which has no direct inlining associated with it. That
8582 -- would not only be inefficient but would also result in the
8583 -- backend doing cross-unit inlining in cases where it was
8584 -- definitely inappropriate to do so.
8586 -- However, a simple Comes_From_Source test is insufficient, since
8587 -- we do want to allow inlining of generic instances which also do
8588 -- not come from source. We also need to recognize specs generated
8589 -- by the front-end for bodies that carry the pragma. Finally,
8590 -- predefined operators do not come from source but are not
8591 -- inlineable either.
8593 elsif Is_Generic_Instance
(Subp
)
8594 or else Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Declaration
8598 elsif not Comes_From_Source
(Subp
)
8599 and then Scope
(Subp
) /= Standard_Standard
8605 -- The referenced entity must either be the enclosing entity, or
8606 -- an entity declared within the current open scope.
8608 if Present
(Scope
(Subp
))
8609 and then Scope
(Subp
) /= Current_Scope
8610 and then Subp
/= Current_Scope
8613 ("argument of% must be entity in current scope", Assoc
);
8617 -- Processing for procedure, operator or function. If subprogram
8618 -- is aliased (as for an instance) indicate that the renamed
8619 -- entity (if declared in the same unit) is inlined.
8620 -- If this is the anonymous subprogram created for a subprogram
8621 -- instance, the inlining applies to it directly. Otherwise we
8622 -- retrieve it as the alias of the visible subprogram instance.
8624 if Is_Subprogram
(Subp
) then
8625 if Is_Wrapper_Package
(Scope
(Subp
)) then
8628 Inner_Subp
:= Ultimate_Alias
(Inner_Subp
);
8631 if In_Same_Source_Unit
(Subp
, Inner_Subp
) then
8632 Set_Inline_Flags
(Inner_Subp
);
8634 Decl
:= Parent
(Parent
(Inner_Subp
));
8636 if Nkind
(Decl
) = N_Subprogram_Declaration
8637 and then Present
(Corresponding_Body
(Decl
))
8639 Set_Inline_Flags
(Corresponding_Body
(Decl
));
8641 elsif Is_Generic_Instance
(Subp
)
8642 and then Comes_From_Source
(Subp
)
8644 -- Indicate that the body needs to be created for
8645 -- inlining subsequent calls. The instantiation node
8646 -- follows the declaration of the wrapper package
8647 -- created for it. The subprogram that requires the
8648 -- body is the anonymous one in the wrapper package.
8650 if Scope
(Subp
) /= Standard_Standard
8652 Need_Subprogram_Instance_Body
8653 (Next
(Unit_Declaration_Node
8654 (Scope
(Alias
(Subp
)))), Subp
)
8659 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8660 -- appear in a formal part to apply to a formal subprogram.
8661 -- Do not apply check within an instance or a formal package
8662 -- the test will have been applied to the original generic.
8664 elsif Nkind
(Decl
) in N_Formal_Subprogram_Declaration
8665 and then List_Containing
(Decl
) = List_Containing
(N
)
8666 and then not In_Instance
8669 ("Inline cannot apply to a formal subprogram", N
);
8671 -- If Subp is a renaming, it is the renamed entity that
8672 -- will appear in any call, and be inlined. However, for
8673 -- ASIS uses it is convenient to indicate that the renaming
8674 -- itself is an inlined subprogram, so that some gnatcheck
8675 -- rules can be applied in the absence of expansion.
8677 elsif Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
8678 Set_Inline_Flags
(Subp
);
8684 -- For a generic subprogram set flag as well, for use at the point
8685 -- of instantiation, to determine whether the body should be
8688 elsif Is_Generic_Subprogram
(Subp
) then
8689 Set_Inline_Flags
(Subp
);
8692 -- Literals are by definition inlined
8694 elsif Kind
= E_Enumeration_Literal
then
8697 -- Anything else is an error
8701 ("expect subprogram name for pragma%", Assoc
);
8705 ----------------------
8706 -- Set_Inline_Flags --
8707 ----------------------
8709 procedure Set_Inline_Flags
(Subp
: Entity_Id
) is
8711 -- First set the Has_Pragma_XXX flags and issue the appropriate
8712 -- errors and warnings for suspicious combinations.
8714 if Prag_Id
= Pragma_No_Inline
then
8715 if Has_Pragma_Inline_Always
(Subp
) then
8717 ("Inline_Always and No_Inline are mutually exclusive", N
);
8718 elsif Has_Pragma_Inline
(Subp
) then
8720 ("Inline and No_Inline both specified for& ??",
8721 N
, Entity
(Subp_Id
));
8724 Set_Has_Pragma_No_Inline
(Subp
);
8726 if Prag_Id
= Pragma_Inline_Always
then
8727 if Has_Pragma_No_Inline
(Subp
) then
8729 ("Inline_Always and No_Inline are mutually exclusive",
8733 Set_Has_Pragma_Inline_Always
(Subp
);
8735 if Has_Pragma_No_Inline
(Subp
) then
8737 ("Inline and No_Inline both specified for& ??",
8738 N
, Entity
(Subp_Id
));
8742 if not Has_Pragma_Inline
(Subp
) then
8743 Set_Has_Pragma_Inline
(Subp
);
8747 -- Then adjust the Is_Inlined flag. It can never be set if the
8748 -- subprogram is subject to pragma No_Inline.
8752 Set_Is_Inlined
(Subp
, False);
8756 if not Has_Pragma_No_Inline
(Subp
) then
8757 Set_Is_Inlined
(Subp
, True);
8761 -- A pragma that applies to a Ghost entity becomes Ghost for the
8762 -- purposes of legality checks and removal of ignored Ghost code.
8764 Mark_Pragma_As_Ghost
(N
, Subp
);
8766 -- Capture the entity of the first Ghost subprogram being
8767 -- processed for error detection purposes.
8769 if Is_Ghost_Entity
(Subp
) then
8770 if No
(Ghost_Id
) then
8774 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
8775 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
8777 elsif Present
(Ghost_Id
) and then not Ghost_Error_Posted
then
8778 Ghost_Error_Posted
:= True;
8780 Error_Msg_Name_1
:= Pname
;
8782 ("pragma % cannot mention ghost and non-ghost subprograms",
8785 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
8786 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
8788 Error_Msg_Sloc
:= Sloc
(Subp
);
8789 Error_Msg_NE
("\& # declared as non-ghost", N
, Subp
);
8791 end Set_Inline_Flags
;
8793 -- Start of processing for Process_Inline
8796 Check_No_Identifiers
;
8797 Check_At_Least_N_Arguments
(1);
8799 if Status
= Enabled
then
8800 Inline_Processing_Required
:= True;
8804 while Present
(Assoc
) loop
8805 Subp_Id
:= Get_Pragma_Arg
(Assoc
);
8809 if Is_Entity_Name
(Subp_Id
) then
8810 Subp
:= Entity
(Subp_Id
);
8812 if Subp
= Any_Id
then
8814 -- If previous error, avoid cascaded errors
8816 Check_Error_Detected
;
8822 -- For the pragma case, climb homonym chain. This is
8823 -- what implements allowing the pragma in the renaming
8824 -- case, with the result applying to the ancestors, and
8825 -- also allows Inline to apply to all previous homonyms.
8827 if not From_Aspect_Specification
(N
) then
8828 while Present
(Homonym
(Subp
))
8829 and then Scope
(Homonym
(Subp
)) = Current_Scope
8831 Make_Inline
(Homonym
(Subp
));
8832 Subp
:= Homonym
(Subp
);
8839 Error_Pragma_Arg
("inappropriate argument for pragma%", Assoc
);
8846 ----------------------------
8847 -- Process_Interface_Name --
8848 ----------------------------
8850 procedure Process_Interface_Name
8851 (Subprogram_Def
: Entity_Id
;
8857 String_Val
: String_Id
;
8859 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
);
8860 -- SN is a string literal node for an interface name. This routine
8861 -- performs some minimal checks that the name is reasonable. In
8862 -- particular that no spaces or other obviously incorrect characters
8863 -- appear. This is only a warning, since any characters are allowed.
8865 ----------------------------------
8866 -- Check_Form_Of_Interface_Name --
8867 ----------------------------------
8869 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
) is
8870 S
: constant String_Id
:= Strval
(Expr_Value_S
(SN
));
8871 SL
: constant Nat
:= String_Length
(S
);
8876 Error_Msg_N
("interface name cannot be null string", SN
);
8879 for J
in 1 .. SL
loop
8880 C
:= Get_String_Char
(S
, J
);
8882 -- Look for dubious character and issue unconditional warning.
8883 -- Definitely dubious if not in character range.
8885 if not In_Character_Range
(C
)
8887 -- Commas, spaces and (back)slashes are dubious
8889 or else Get_Character
(C
) = ','
8890 or else Get_Character
(C
) = '\'
8891 or else Get_Character
(C
) = ' '
8892 or else Get_Character
(C
) = '/'
8895 ("??interface name contains illegal character",
8896 Sloc
(SN
) + Source_Ptr
(J
));
8899 end Check_Form_Of_Interface_Name
;
8901 -- Start of processing for Process_Interface_Name
8904 if No
(Link_Arg
) then
8905 if No
(Ext_Arg
) then
8908 elsif Chars
(Ext_Arg
) = Name_Link_Name
then
8910 Link_Nam
:= Expression
(Ext_Arg
);
8913 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8914 Ext_Nam
:= Expression
(Ext_Arg
);
8919 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8920 Check_Optional_Identifier
(Link_Arg
, Name_Link_Name
);
8921 Ext_Nam
:= Expression
(Ext_Arg
);
8922 Link_Nam
:= Expression
(Link_Arg
);
8925 -- Check expressions for external name and link name are static
8927 if Present
(Ext_Nam
) then
8928 Check_Arg_Is_OK_Static_Expression
(Ext_Nam
, Standard_String
);
8929 Check_Form_Of_Interface_Name
(Ext_Nam
);
8931 -- Verify that external name is not the name of a local entity,
8932 -- which would hide the imported one and could lead to run-time
8933 -- surprises. The problem can only arise for entities declared in
8934 -- a package body (otherwise the external name is fully qualified
8935 -- and will not conflict).
8943 if Prag_Id
= Pragma_Import
then
8944 String_To_Name_Buffer
(Strval
(Expr_Value_S
(Ext_Nam
)));
8946 E
:= Entity_Id
(Get_Name_Table_Int
(Nam
));
8948 if Nam
/= Chars
(Subprogram_Def
)
8949 and then Present
(E
)
8950 and then not Is_Overloadable
(E
)
8951 and then Is_Immediately_Visible
(E
)
8952 and then not Is_Imported
(E
)
8953 and then Ekind
(Scope
(E
)) = E_Package
8956 while Present
(Par
) loop
8957 if Nkind
(Par
) = N_Package_Body
then
8958 Error_Msg_Sloc
:= Sloc
(E
);
8960 ("imported entity is hidden by & declared#",
8965 Par
:= Parent
(Par
);
8972 if Present
(Link_Nam
) then
8973 Check_Arg_Is_OK_Static_Expression
(Link_Nam
, Standard_String
);
8974 Check_Form_Of_Interface_Name
(Link_Nam
);
8977 -- If there is no link name, just set the external name
8979 if No
(Link_Nam
) then
8980 Link_Nam
:= Adjust_External_Name_Case
(Expr_Value_S
(Ext_Nam
));
8982 -- For the Link_Name case, the given literal is preceded by an
8983 -- asterisk, which indicates to GCC that the given name should be
8984 -- taken literally, and in particular that no prepending of
8985 -- underlines should occur, even in systems where this is the
8990 Store_String_Char
(Get_Char_Code
('*'));
8991 String_Val
:= Strval
(Expr_Value_S
(Link_Nam
));
8992 Store_String_Chars
(String_Val
);
8994 Make_String_Literal
(Sloc
(Link_Nam
),
8995 Strval
=> End_String
);
8998 -- Set the interface name. If the entity is a generic instance, use
8999 -- its alias, which is the callable entity.
9001 if Is_Generic_Instance
(Subprogram_Def
) then
9002 Set_Encoded_Interface_Name
9003 (Alias
(Get_Base_Subprogram
(Subprogram_Def
)), Link_Nam
);
9005 Set_Encoded_Interface_Name
9006 (Get_Base_Subprogram
(Subprogram_Def
), Link_Nam
);
9009 Check_Duplicated_Export_Name
(Link_Nam
);
9010 end Process_Interface_Name
;
9012 -----------------------------------------
9013 -- Process_Interrupt_Or_Attach_Handler --
9014 -----------------------------------------
9016 procedure Process_Interrupt_Or_Attach_Handler
is
9017 Handler
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
9018 Prot_Typ
: constant Entity_Id
:= Scope
(Handler
);
9021 -- A pragma that applies to a Ghost entity becomes Ghost for the
9022 -- purposes of legality checks and removal of ignored Ghost code.
9024 Mark_Pragma_As_Ghost
(N
, Handler
);
9025 Set_Is_Interrupt_Handler
(Handler
);
9027 -- If the pragma is not associated with a handler procedure within a
9028 -- protected type, then it must be for a nonprotected procedure for
9029 -- the AAMP target, in which case we don't associate a representation
9030 -- item with the procedure's scope.
9032 if Ekind
(Prot_Typ
) = E_Protected_Type
then
9033 Record_Rep_Item
(Prot_Typ
, N
);
9036 -- Chain the pragma on the contract for completeness
9038 Add_Contract_Item
(N
, Handler
);
9039 end Process_Interrupt_Or_Attach_Handler
;
9041 --------------------------------------------------
9042 -- Process_Restrictions_Or_Restriction_Warnings --
9043 --------------------------------------------------
9045 -- Note: some of the simple identifier cases were handled in par-prag,
9046 -- but it is harmless (and more straightforward) to simply handle all
9047 -- cases here, even if it means we repeat a bit of work in some cases.
9049 procedure Process_Restrictions_Or_Restriction_Warnings
9053 R_Id
: Restriction_Id
;
9059 -- Ignore all Restrictions pragmas in CodePeer mode
9061 if CodePeer_Mode
then
9065 Check_Ada_83_Warning
;
9066 Check_At_Least_N_Arguments
(1);
9067 Check_Valid_Configuration_Pragma
;
9070 while Present
(Arg
) loop
9072 Expr
:= Get_Pragma_Arg
(Arg
);
9074 -- Case of no restriction identifier present
9076 if Id
= No_Name
then
9077 if Nkind
(Expr
) /= N_Identifier
then
9079 ("invalid form for restriction", Arg
);
9084 (Process_Restriction_Synonyms
(Expr
));
9086 if R_Id
not in All_Boolean_Restrictions
then
9087 Error_Msg_Name_1
:= Pname
;
9089 ("invalid restriction identifier&", Get_Pragma_Arg
(Arg
));
9091 -- Check for possible misspelling
9093 for J
in Restriction_Id
loop
9095 Rnm
: constant String := Restriction_Id
'Image (J
);
9098 Name_Buffer
(1 .. Rnm
'Length) := Rnm
;
9099 Name_Len
:= Rnm
'Length;
9100 Set_Casing
(All_Lower_Case
);
9102 if Is_Bad_Spelling_Of
(Chars
(Expr
), Name_Enter
) then
9104 (Identifier_Casing
(Current_Source_File
));
9105 Error_Msg_String
(1 .. Rnm
'Length) :=
9106 Name_Buffer
(1 .. Name_Len
);
9107 Error_Msg_Strlen
:= Rnm
'Length;
9108 Error_Msg_N
-- CODEFIX
9109 ("\possible misspelling of ""~""",
9110 Get_Pragma_Arg
(Arg
));
9119 if Implementation_Restriction
(R_Id
) then
9120 Check_Restriction
(No_Implementation_Restrictions
, Arg
);
9123 -- Special processing for No_Elaboration_Code restriction
9125 if R_Id
= No_Elaboration_Code
then
9127 -- Restriction is only recognized within a configuration
9128 -- pragma file, or within a unit of the main extended
9129 -- program. Note: the test for Main_Unit is needed to
9130 -- properly include the case of configuration pragma files.
9132 if not (Current_Sem_Unit
= Main_Unit
9133 or else In_Extended_Main_Source_Unit
(N
))
9137 -- Don't allow in a subunit unless already specified in
9140 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
9141 and then Nkind
(Unit
(Parent
(N
))) = N_Subunit
9142 and then not Restriction_Active
(No_Elaboration_Code
)
9145 ("invalid specification of ""No_Elaboration_Code""",
9148 ("\restriction cannot be specified in a subunit", N
);
9150 ("\unless also specified in body or spec", N
);
9153 -- If we accept a No_Elaboration_Code restriction, then it
9154 -- needs to be added to the configuration restriction set so
9155 -- that we get proper application to other units in the main
9156 -- extended source as required.
9159 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
9163 -- If this is a warning, then set the warning unless we already
9164 -- have a real restriction active (we never want a warning to
9165 -- override a real restriction).
9168 if not Restriction_Active
(R_Id
) then
9169 Set_Restriction
(R_Id
, N
);
9170 Restriction_Warnings
(R_Id
) := True;
9173 -- If real restriction case, then set it and make sure that the
9174 -- restriction warning flag is off, since a real restriction
9175 -- always overrides a warning.
9178 Set_Restriction
(R_Id
, N
);
9179 Restriction_Warnings
(R_Id
) := False;
9182 -- Check for obsolescent restrictions in Ada 2005 mode
9185 and then Ada_Version
>= Ada_2005
9186 and then (R_Id
= No_Asynchronous_Control
9188 R_Id
= No_Unchecked_Deallocation
9190 R_Id
= No_Unchecked_Conversion
)
9192 Check_Restriction
(No_Obsolescent_Features
, N
);
9195 -- A very special case that must be processed here: pragma
9196 -- Restrictions (No_Exceptions) turns off all run-time
9197 -- checking. This is a bit dubious in terms of the formal
9198 -- language definition, but it is what is intended by RM
9199 -- H.4(12). Restriction_Warnings never affects generated code
9200 -- so this is done only in the real restriction case.
9202 -- Atomic_Synchronization is not a real check, so it is not
9203 -- affected by this processing).
9205 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
9206 -- run-time checks in CodePeer and GNATprove modes: we want to
9207 -- generate checks for analysis purposes, as set respectively
9208 -- by -gnatC and -gnatd.F
9211 and then not (CodePeer_Mode
or GNATprove_Mode
)
9212 and then R_Id
= No_Exceptions
9214 for J
in Scope_Suppress
.Suppress
'Range loop
9215 if J
/= Atomic_Synchronization
then
9216 Scope_Suppress
.Suppress
(J
) := True;
9221 -- Case of No_Dependence => unit-name. Note that the parser
9222 -- already made the necessary entry in the No_Dependence table.
9224 elsif Id
= Name_No_Dependence
then
9225 if not OK_No_Dependence_Unit_Name
(Expr
) then
9229 -- Case of No_Specification_Of_Aspect => aspect-identifier
9231 elsif Id
= Name_No_Specification_Of_Aspect
then
9236 if Nkind
(Expr
) /= N_Identifier
then
9239 A_Id
:= Get_Aspect_Id
(Chars
(Expr
));
9242 if A_Id
= No_Aspect
then
9243 Error_Pragma_Arg
("invalid restriction name", Arg
);
9245 Set_Restriction_No_Specification_Of_Aspect
(Expr
, Warn
);
9249 -- Case of No_Use_Of_Attribute => attribute-identifier
9251 elsif Id
= Name_No_Use_Of_Attribute
then
9252 if Nkind
(Expr
) /= N_Identifier
9253 or else not Is_Attribute_Name
(Chars
(Expr
))
9255 Error_Msg_N
("unknown attribute name??", Expr
);
9258 Set_Restriction_No_Use_Of_Attribute
(Expr
, Warn
);
9261 -- Case of No_Use_Of_Entity => fully-qualified-name
9263 elsif Id
= Name_No_Use_Of_Entity
then
9265 -- Restriction is only recognized within a configuration
9266 -- pragma file, or within a unit of the main extended
9267 -- program. Note: the test for Main_Unit is needed to
9268 -- properly include the case of configuration pragma files.
9270 if Current_Sem_Unit
= Main_Unit
9271 or else In_Extended_Main_Source_Unit
(N
)
9273 if not OK_No_Dependence_Unit_Name
(Expr
) then
9274 Error_Msg_N
("wrong form for entity name", Expr
);
9276 Set_Restriction_No_Use_Of_Entity
9277 (Expr
, Warn
, No_Profile
);
9281 -- Case of No_Use_Of_Pragma => pragma-identifier
9283 elsif Id
= Name_No_Use_Of_Pragma
then
9284 if Nkind
(Expr
) /= N_Identifier
9285 or else not Is_Pragma_Name
(Chars
(Expr
))
9287 Error_Msg_N
("unknown pragma name??", Expr
);
9289 Set_Restriction_No_Use_Of_Pragma
(Expr
, Warn
);
9292 -- All other cases of restriction identifier present
9295 R_Id
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(Arg
));
9296 Analyze_And_Resolve
(Expr
, Any_Integer
);
9298 if R_Id
not in All_Parameter_Restrictions
then
9300 ("invalid restriction parameter identifier", Arg
);
9302 elsif not Is_OK_Static_Expression
(Expr
) then
9303 Flag_Non_Static_Expr
9304 ("value must be static expression!", Expr
);
9307 elsif not Is_Integer_Type
(Etype
(Expr
))
9308 or else Expr_Value
(Expr
) < 0
9311 ("value must be non-negative integer", Arg
);
9314 -- Restriction pragma is active
9316 Val
:= Expr_Value
(Expr
);
9318 if not UI_Is_In_Int_Range
(Val
) then
9320 ("pragma ignored, value too large??", Arg
);
9323 -- Warning case. If the real restriction is active, then we
9324 -- ignore the request, since warning never overrides a real
9325 -- restriction. Otherwise we set the proper warning. Note that
9326 -- this circuit sets the warning again if it is already set,
9327 -- which is what we want, since the constant may have changed.
9330 if not Restriction_Active
(R_Id
) then
9332 (R_Id
, N
, Integer (UI_To_Int
(Val
)));
9333 Restriction_Warnings
(R_Id
) := True;
9336 -- Real restriction case, set restriction and make sure warning
9337 -- flag is off since real restriction always overrides warning.
9340 Set_Restriction
(R_Id
, N
, Integer (UI_To_Int
(Val
)));
9341 Restriction_Warnings
(R_Id
) := False;
9347 end Process_Restrictions_Or_Restriction_Warnings
;
9349 ---------------------------------
9350 -- Process_Suppress_Unsuppress --
9351 ---------------------------------
9353 -- Note: this procedure makes entries in the check suppress data
9354 -- structures managed by Sem. See spec of package Sem for full
9355 -- details on how we handle recording of check suppression.
9357 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean) is
9362 In_Package_Spec
: constant Boolean :=
9363 Is_Package_Or_Generic_Package
(Current_Scope
)
9364 and then not In_Package_Body
(Current_Scope
);
9366 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
);
9367 -- Used to suppress a single check on the given entity
9369 --------------------------------
9370 -- Suppress_Unsuppress_Echeck --
9371 --------------------------------
9373 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
) is
9375 -- Check for error of trying to set atomic synchronization for
9376 -- a non-atomic variable.
9378 if C
= Atomic_Synchronization
9379 and then not (Is_Atomic
(E
) or else Has_Atomic_Components
(E
))
9382 ("pragma & requires atomic type or variable",
9383 Pragma_Identifier
(Original_Node
(N
)));
9386 Set_Checks_May_Be_Suppressed
(E
);
9388 if In_Package_Spec
then
9389 Push_Global_Suppress_Stack_Entry
9392 Suppress
=> Suppress_Case
);
9394 Push_Local_Suppress_Stack_Entry
9397 Suppress
=> Suppress_Case
);
9400 -- If this is a first subtype, and the base type is distinct,
9401 -- then also set the suppress flags on the base type.
9403 if Is_First_Subtype
(E
) and then Etype
(E
) /= E
then
9404 Suppress_Unsuppress_Echeck
(Etype
(E
), C
);
9406 end Suppress_Unsuppress_Echeck
;
9408 -- Start of processing for Process_Suppress_Unsuppress
9411 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9412 -- on user code: we want to generate checks for analysis purposes, as
9413 -- set respectively by -gnatC and -gnatd.F
9415 if Comes_From_Source
(N
)
9416 and then (CodePeer_Mode
or GNATprove_Mode
)
9421 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9422 -- declarative part or a package spec (RM 11.5(5)).
9424 if not Is_Configuration_Pragma
then
9425 Check_Is_In_Decl_Part_Or_Package_Spec
;
9428 Check_At_Least_N_Arguments
(1);
9429 Check_At_Most_N_Arguments
(2);
9430 Check_No_Identifier
(Arg1
);
9431 Check_Arg_Is_Identifier
(Arg1
);
9433 C
:= Get_Check_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
9435 if C
= No_Check_Id
then
9437 ("argument of pragma% is not valid check name", Arg1
);
9440 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9442 if C
= Elaboration_Check
and then SPARK_Mode
= On
then
9444 ("Suppress of Elaboration_Check ignored in SPARK??",
9445 "\elaboration checking rules are statically enforced "
9446 & "(SPARK RM 7.7)", Arg1
);
9449 -- One-argument case
9451 if Arg_Count
= 1 then
9453 -- Make an entry in the local scope suppress table. This is the
9454 -- table that directly shows the current value of the scope
9455 -- suppress check for any check id value.
9457 if C
= All_Checks
then
9459 -- For All_Checks, we set all specific predefined checks with
9460 -- the exception of Elaboration_Check, which is handled
9461 -- specially because of not wanting All_Checks to have the
9462 -- effect of deactivating static elaboration order processing.
9463 -- Atomic_Synchronization is also not affected, since this is
9464 -- not a real check.
9466 for J
in Scope_Suppress
.Suppress
'Range loop
9467 if J
/= Elaboration_Check
9469 J
/= Atomic_Synchronization
9471 Scope_Suppress
.Suppress
(J
) := Suppress_Case
;
9475 -- If not All_Checks, and predefined check, then set appropriate
9476 -- scope entry. Note that we will set Elaboration_Check if this
9477 -- is explicitly specified. Atomic_Synchronization is allowed
9478 -- only if internally generated and entity is atomic.
9480 elsif C
in Predefined_Check_Id
9481 and then (not Comes_From_Source
(N
)
9482 or else C
/= Atomic_Synchronization
)
9484 Scope_Suppress
.Suppress
(C
) := Suppress_Case
;
9487 -- Also make an entry in the Local_Entity_Suppress table
9489 Push_Local_Suppress_Stack_Entry
9492 Suppress
=> Suppress_Case
);
9494 -- Case of two arguments present, where the check is suppressed for
9495 -- a specified entity (given as the second argument of the pragma)
9498 -- This is obsolescent in Ada 2005 mode
9500 if Ada_Version
>= Ada_2005
then
9501 Check_Restriction
(No_Obsolescent_Features
, Arg2
);
9504 Check_Optional_Identifier
(Arg2
, Name_On
);
9505 E_Id
:= Get_Pragma_Arg
(Arg2
);
9508 if not Is_Entity_Name
(E_Id
) then
9510 ("second argument of pragma% must be entity name", Arg2
);
9519 -- A pragma that applies to a Ghost entity becomes Ghost for the
9520 -- purposes of legality checks and removal of ignored Ghost code.
9522 Mark_Pragma_As_Ghost
(N
, E
);
9524 -- Enforce RM 11.5(7) which requires that for a pragma that
9525 -- appears within a package spec, the named entity must be
9526 -- within the package spec. We allow the package name itself
9527 -- to be mentioned since that makes sense, although it is not
9528 -- strictly allowed by 11.5(7).
9531 and then E
/= Current_Scope
9532 and then Scope
(E
) /= Current_Scope
9535 ("entity in pragma% is not in package spec (RM 11.5(7))",
9539 -- Loop through homonyms. As noted below, in the case of a package
9540 -- spec, only homonyms within the package spec are considered.
9543 Suppress_Unsuppress_Echeck
(E
, C
);
9545 if Is_Generic_Instance
(E
)
9546 and then Is_Subprogram
(E
)
9547 and then Present
(Alias
(E
))
9549 Suppress_Unsuppress_Echeck
(Alias
(E
), C
);
9552 -- Move to next homonym if not aspect spec case
9554 exit when From_Aspect_Specification
(N
);
9558 -- If we are within a package specification, the pragma only
9559 -- applies to homonyms in the same scope.
9561 exit when In_Package_Spec
9562 and then Scope
(E
) /= Current_Scope
;
9565 end Process_Suppress_Unsuppress
;
9567 -------------------------------
9568 -- Record_Independence_Check --
9569 -------------------------------
9571 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
) is
9573 -- For GCC back ends the validation is done a priori
9575 if not AAMP_On_Target
then
9579 Independence_Checks
.Append
((N
, E
));
9580 end Record_Independence_Check
;
9586 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
) is
9588 if Is_Imported
(E
) then
9590 ("cannot export entity& that was previously imported", Arg
);
9592 elsif Present
(Address_Clause
(E
))
9593 and then not Relaxed_RM_Semantics
9596 ("cannot export entity& that has an address clause", Arg
);
9599 Set_Is_Exported
(E
);
9601 -- Generate a reference for entity explicitly, because the
9602 -- identifier may be overloaded and name resolution will not
9605 Generate_Reference
(E
, Arg
);
9607 -- Deal with exporting non-library level entity
9609 if not Is_Library_Level_Entity
(E
) then
9611 -- Not allowed at all for subprograms
9613 if Is_Subprogram
(E
) then
9614 Error_Pragma_Arg
("local subprogram& cannot be exported", Arg
);
9616 -- Otherwise set public and statically allocated
9620 Set_Is_Statically_Allocated
(E
);
9622 -- Warn if the corresponding W flag is set
9624 if Warn_On_Export_Import
9626 -- Only do this for something that was in the source. Not
9627 -- clear if this can be False now (there used for sure to be
9628 -- cases on some systems where it was False), but anyway the
9629 -- test is harmless if not needed, so it is retained.
9631 and then Comes_From_Source
(Arg
)
9634 ("?x?& has been made static as a result of Export",
9637 ("\?x?this usage is non-standard and non-portable",
9643 if Warn_On_Export_Import
and then Is_Type
(E
) then
9644 Error_Msg_NE
("exporting a type has no effect?x?", Arg
, E
);
9647 if Warn_On_Export_Import
and Inside_A_Generic
then
9649 ("all instances of& will have the same external name?x?",
9654 ----------------------------------------------
9655 -- Set_Extended_Import_Export_External_Name --
9656 ----------------------------------------------
9658 procedure Set_Extended_Import_Export_External_Name
9659 (Internal_Ent
: Entity_Id
;
9660 Arg_External
: Node_Id
)
9662 Old_Name
: constant Node_Id
:= Interface_Name
(Internal_Ent
);
9666 if No
(Arg_External
) then
9670 Check_Arg_Is_External_Name
(Arg_External
);
9672 if Nkind
(Arg_External
) = N_String_Literal
then
9673 if String_Length
(Strval
(Arg_External
)) = 0 then
9676 New_Name
:= Adjust_External_Name_Case
(Arg_External
);
9679 elsif Nkind
(Arg_External
) = N_Identifier
then
9680 New_Name
:= Get_Default_External_Name
(Arg_External
);
9682 -- Check_Arg_Is_External_Name should let through only identifiers and
9683 -- string literals or static string expressions (which are folded to
9684 -- string literals).
9687 raise Program_Error
;
9690 -- If we already have an external name set (by a prior normal Import
9691 -- or Export pragma), then the external names must match
9693 if Present
(Interface_Name
(Internal_Ent
)) then
9695 -- Ignore mismatching names in CodePeer mode, to support some
9696 -- old compilers which would export the same procedure under
9697 -- different names, e.g:
9699 -- pragma Export_Procedure (P, "a");
9700 -- pragma Export_Procedure (P, "b");
9702 if CodePeer_Mode
then
9706 Check_Matching_Internal_Names
: declare
9707 S1
: constant String_Id
:= Strval
(Old_Name
);
9708 S2
: constant String_Id
:= Strval
(New_Name
);
9711 pragma No_Return
(Mismatch
);
9712 -- Called if names do not match
9718 procedure Mismatch
is
9720 Error_Msg_Sloc
:= Sloc
(Old_Name
);
9722 ("external name does not match that given #",
9726 -- Start of processing for Check_Matching_Internal_Names
9729 if String_Length
(S1
) /= String_Length
(S2
) then
9733 for J
in 1 .. String_Length
(S1
) loop
9734 if Get_String_Char
(S1
, J
) /= Get_String_Char
(S2
, J
) then
9739 end Check_Matching_Internal_Names
;
9741 -- Otherwise set the given name
9744 Set_Encoded_Interface_Name
(Internal_Ent
, New_Name
);
9745 Check_Duplicated_Export_Name
(New_Name
);
9747 end Set_Extended_Import_Export_External_Name
;
9753 procedure Set_Imported
(E
: Entity_Id
) is
9755 -- Error message if already imported or exported
9757 if Is_Exported
(E
) or else Is_Imported
(E
) then
9759 -- Error if being set Exported twice
9761 if Is_Exported
(E
) then
9762 Error_Msg_NE
("entity& was previously exported", N
, E
);
9764 -- Ignore error in CodePeer mode where we treat all imported
9765 -- subprograms as unknown.
9767 elsif CodePeer_Mode
then
9770 -- OK if Import/Interface case
9772 elsif Import_Interface_Present
(N
) then
9775 -- Error if being set Imported twice
9778 Error_Msg_NE
("entity& was previously imported", N
, E
);
9781 Error_Msg_Name_1
:= Pname
;
9783 ("\(pragma% applies to all previous entities)", N
);
9785 Error_Msg_Sloc
:= Sloc
(E
);
9786 Error_Msg_NE
("\import not allowed for& declared#", N
, E
);
9788 -- Here if not previously imported or exported, OK to import
9791 Set_Is_Imported
(E
);
9793 -- For subprogram, set Import_Pragma field
9795 if Is_Subprogram
(E
) then
9796 Set_Import_Pragma
(E
, N
);
9799 -- If the entity is an object that is not at the library level,
9800 -- then it is statically allocated. We do not worry about objects
9801 -- with address clauses in this context since they are not really
9802 -- imported in the linker sense.
9805 and then not Is_Library_Level_Entity
(E
)
9806 and then No
(Address_Clause
(E
))
9808 Set_Is_Statically_Allocated
(E
);
9815 -------------------------
9816 -- Set_Mechanism_Value --
9817 -------------------------
9819 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9820 -- analyzed, since it is semantic nonsense), so we get it in the exact
9821 -- form created by the parser.
9823 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
) is
9824 procedure Bad_Mechanism
;
9825 pragma No_Return
(Bad_Mechanism
);
9826 -- Signal bad mechanism name
9828 -------------------------
9829 -- Bad_Mechanism_Value --
9830 -------------------------
9832 procedure Bad_Mechanism
is
9834 Error_Pragma_Arg
("unrecognized mechanism name", Mech_Name
);
9837 -- Start of processing for Set_Mechanism_Value
9840 if Mechanism
(Ent
) /= Default_Mechanism
then
9842 ("mechanism for & has already been set", Mech_Name
, Ent
);
9845 -- MECHANISM_NAME ::= value | reference
9847 if Nkind
(Mech_Name
) = N_Identifier
then
9848 if Chars
(Mech_Name
) = Name_Value
then
9849 Set_Mechanism
(Ent
, By_Copy
);
9852 elsif Chars
(Mech_Name
) = Name_Reference
then
9853 Set_Mechanism
(Ent
, By_Reference
);
9856 elsif Chars
(Mech_Name
) = Name_Copy
then
9858 ("bad mechanism name, Value assumed", Mech_Name
);
9867 end Set_Mechanism_Value
;
9869 --------------------------
9870 -- Set_Rational_Profile --
9871 --------------------------
9873 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9874 -- extension to the semantics of renaming declarations.
9876 procedure Set_Rational_Profile
is
9878 Implicit_Packing
:= True;
9879 Overriding_Renamings
:= True;
9880 Use_VADS_Size
:= True;
9881 end Set_Rational_Profile
;
9883 ---------------------------
9884 -- Set_Ravenscar_Profile --
9885 ---------------------------
9887 -- The tasks to be done here are
9889 -- Set required policies
9891 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9892 -- pragma Locking_Policy (Ceiling_Locking)
9894 -- Set Detect_Blocking mode
9896 -- Set required restrictions (see System.Rident for detailed list)
9898 -- Set the No_Dependence rules
9899 -- No_Dependence => Ada.Asynchronous_Task_Control
9900 -- No_Dependence => Ada.Calendar
9901 -- No_Dependence => Ada.Execution_Time.Group_Budget
9902 -- No_Dependence => Ada.Execution_Time.Timers
9903 -- No_Dependence => Ada.Task_Attributes
9904 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9906 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
) is
9907 procedure Set_Error_Msg_To_Profile_Name
;
9908 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
9911 -----------------------------------
9912 -- Set_Error_Msg_To_Profile_Name --
9913 -----------------------------------
9915 procedure Set_Error_Msg_To_Profile_Name
is
9916 Prof_Nam
: constant Node_Id
:=
9918 (First
(Pragma_Argument_Associations
(N
)));
9921 Get_Name_String
(Chars
(Prof_Nam
));
9922 Adjust_Name_Case
(Global_Name_Buffer
, Sloc
(Prof_Nam
));
9923 Error_Msg_Strlen
:= Name_Len
;
9924 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
9925 end Set_Error_Msg_To_Profile_Name
;
9934 -- Start of processing for Set_Ravenscar_Profile
9937 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9939 if Task_Dispatching_Policy
/= ' '
9940 and then Task_Dispatching_Policy
/= 'F'
9942 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
9943 Set_Error_Msg_To_Profile_Name
;
9944 Error_Pragma
("Profile (~) incompatible with policy#");
9946 -- Set the FIFO_Within_Priorities policy, but always preserve
9947 -- System_Location since we like the error message with the run time
9951 Task_Dispatching_Policy
:= 'F';
9953 if Task_Dispatching_Policy_Sloc
/= System_Location
then
9954 Task_Dispatching_Policy_Sloc
:= Loc
;
9958 -- pragma Locking_Policy (Ceiling_Locking)
9960 if Locking_Policy
/= ' '
9961 and then Locking_Policy
/= 'C'
9963 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
9964 Set_Error_Msg_To_Profile_Name
;
9965 Error_Pragma
("Profile (~) incompatible with policy#");
9967 -- Set the Ceiling_Locking policy, but preserve System_Location since
9968 -- we like the error message with the run time name.
9971 Locking_Policy
:= 'C';
9973 if Locking_Policy_Sloc
/= System_Location
then
9974 Locking_Policy_Sloc
:= Loc
;
9978 -- pragma Detect_Blocking
9980 Detect_Blocking
:= True;
9982 -- Set the corresponding restrictions
9984 Set_Profile_Restrictions
9985 (Profile
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
9987 -- Set the No_Dependence restrictions
9989 -- The following No_Dependence restrictions:
9990 -- No_Dependence => Ada.Asynchronous_Task_Control
9991 -- No_Dependence => Ada.Calendar
9992 -- No_Dependence => Ada.Task_Attributes
9993 -- are already set by previous call to Set_Profile_Restrictions.
9995 -- Set the following restrictions which were added to Ada 2005:
9996 -- No_Dependence => Ada.Execution_Time.Group_Budget
9997 -- No_Dependence => Ada.Execution_Time.Timers
9999 -- ??? The use of Name_Buffer here is suspicious. The names should
10000 -- be registered in snames.ads-tmpl and used to build the qualified
10003 if Ada_Version
>= Ada_2005
then
10004 Name_Buffer
(1 .. 3) := "ada";
10007 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
);
10009 Name_Buffer
(1 .. 14) := "execution_time";
10012 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10015 Make_Selected_Component
10018 Selector_Name
=> Sel_Id
);
10020 Name_Buffer
(1 .. 13) := "group_budgets";
10023 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10026 Make_Selected_Component
10029 Selector_Name
=> Sel_Id
);
10031 Set_Restriction_No_Dependence
10033 Warn
=> Treat_Restrictions_As_Warnings
,
10034 Profile
=> Ravenscar
);
10036 Name_Buffer
(1 .. 6) := "timers";
10039 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10042 Make_Selected_Component
10045 Selector_Name
=> Sel_Id
);
10047 Set_Restriction_No_Dependence
10049 Warn
=> Treat_Restrictions_As_Warnings
,
10050 Profile
=> Ravenscar
);
10053 -- Set the following restriction which was added to Ada 2012 (see
10055 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10057 if Ada_Version
>= Ada_2012
then
10058 Name_Buffer
(1 .. 6) := "system";
10061 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
);
10063 Name_Buffer
(1 .. 15) := "multiprocessors";
10066 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10069 Make_Selected_Component
10072 Selector_Name
=> Sel_Id
);
10074 Name_Buffer
(1 .. 19) := "dispatching_domains";
10077 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10080 Make_Selected_Component
10083 Selector_Name
=> Sel_Id
);
10085 Set_Restriction_No_Dependence
10087 Warn
=> Treat_Restrictions_As_Warnings
,
10088 Profile
=> Ravenscar
);
10090 end Set_Ravenscar_Profile
;
10092 -- Start of processing for Analyze_Pragma
10095 -- The following code is a defense against recursion. Not clear that
10096 -- this can happen legitimately, but perhaps some error situations can
10097 -- cause it, and we did see this recursion during testing.
10099 if Analyzed
(N
) then
10105 Check_Restriction_No_Use_Of_Pragma
(N
);
10107 -- Deal with unrecognized pragma
10109 Pname
:= Pragma_Name
(N
);
10111 if not Is_Pragma_Name
(Pname
) then
10112 if Warn_On_Unrecognized_Pragma
then
10113 Error_Msg_Name_1
:= Pname
;
10114 Error_Msg_N
("?g?unrecognized pragma%!", Pragma_Identifier
(N
));
10116 for PN
in First_Pragma_Name
.. Last_Pragma_Name
loop
10117 if Is_Bad_Spelling_Of
(Pname
, PN
) then
10118 Error_Msg_Name_1
:= PN
;
10119 Error_Msg_N
-- CODEFIX
10120 ("\?g?possible misspelling of %!", Pragma_Identifier
(N
));
10129 -- Ignore pragma if Ignore_Pragma applies
10131 if Get_Name_Table_Boolean3
(Pname
) then
10135 -- Here to start processing for recognized pragma
10137 Prag_Id
:= Get_Pragma_Id
(Pname
);
10138 Pname
:= Original_Aspect_Pragma_Name
(N
);
10140 -- Capture setting of Opt.Uneval_Old
10142 case Opt
.Uneval_Old
is
10144 Set_Uneval_Old_Accept
(N
);
10148 Set_Uneval_Old_Warn
(N
);
10150 raise Program_Error
;
10153 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
10154 -- is already set, indicating that we have already checked the policy
10155 -- at the right point. This happens for example in the case of a pragma
10156 -- that is derived from an Aspect.
10158 if Is_Ignored
(N
) or else Is_Checked
(N
) then
10161 -- For a pragma that is a rewriting of another pragma, copy the
10162 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10164 elsif Is_Rewrite_Substitution
(N
)
10165 and then Nkind
(Original_Node
(N
)) = N_Pragma
10166 and then Original_Node
(N
) /= N
10168 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
10169 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
10171 -- Otherwise query the applicable policy at this point
10174 Check_Applicable_Policy
(N
);
10176 -- If pragma is disabled, rewrite as NULL and skip analysis
10178 if Is_Disabled
(N
) then
10179 Rewrite
(N
, Make_Null_Statement
(Loc
));
10185 -- Preset arguments
10193 if Present
(Pragma_Argument_Associations
(N
)) then
10194 Arg_Count
:= List_Length
(Pragma_Argument_Associations
(N
));
10195 Arg1
:= First
(Pragma_Argument_Associations
(N
));
10197 if Present
(Arg1
) then
10198 Arg2
:= Next
(Arg1
);
10200 if Present
(Arg2
) then
10201 Arg3
:= Next
(Arg2
);
10203 if Present
(Arg3
) then
10204 Arg4
:= Next
(Arg3
);
10210 -- An enumeration type defines the pragmas that are supported by the
10211 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10212 -- into the corresponding enumeration value for the following case.
10220 -- pragma Abort_Defer;
10222 when Pragma_Abort_Defer
=>
10224 Check_Arg_Count
(0);
10226 -- The only required semantic processing is to check the
10227 -- placement. This pragma must appear at the start of the
10228 -- statement sequence of a handled sequence of statements.
10230 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
10231 or else N
/= First
(Statements
(Parent
(N
)))
10236 --------------------
10237 -- Abstract_State --
10238 --------------------
10240 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10242 -- ABSTRACT_STATE_LIST ::=
10244 -- | STATE_NAME_WITH_OPTIONS
10245 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
10247 -- STATE_NAME_WITH_OPTIONS ::=
10249 -- | (STATE_NAME with OPTION_LIST)
10251 -- OPTION_LIST ::= OPTION {, OPTION}
10255 -- | NAME_VALUE_OPTION
10257 -- SIMPLE_OPTION ::= Ghost | Synchronous
10259 -- NAME_VALUE_OPTION ::=
10260 -- Part_Of => ABSTRACT_STATE
10261 -- | External [=> EXTERNAL_PROPERTY_LIST]
10263 -- EXTERNAL_PROPERTY_LIST ::=
10264 -- EXTERNAL_PROPERTY
10265 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
10267 -- EXTERNAL_PROPERTY ::=
10268 -- Async_Readers [=> boolean_EXPRESSION]
10269 -- | Async_Writers [=> boolean_EXPRESSION]
10270 -- | Effective_Reads [=> boolean_EXPRESSION]
10271 -- | Effective_Writes [=> boolean_EXPRESSION]
10272 -- others => boolean_EXPRESSION
10274 -- STATE_NAME ::= defining_identifier
10276 -- ABSTRACT_STATE ::= name
10278 -- Characteristics:
10280 -- * Analysis - The annotation is fully analyzed immediately upon
10281 -- elaboration as it cannot forward reference entities.
10283 -- * Expansion - None.
10285 -- * Template - The annotation utilizes the generic template of the
10286 -- related package declaration.
10288 -- * Globals - The annotation cannot reference global entities.
10290 -- * Instance - The annotation is instantiated automatically when
10291 -- the related generic package is instantiated.
10293 when Pragma_Abstract_State
=> Abstract_State
: declare
10294 Missing_Parentheses
: Boolean := False;
10295 -- Flag set when a state declaration with options is not properly
10298 -- Flags used to verify the consistency of states
10300 Non_Null_Seen
: Boolean := False;
10301 Null_Seen
: Boolean := False;
10303 procedure Analyze_Abstract_State
10305 Pack_Id
: Entity_Id
);
10306 -- Verify the legality of a single state declaration. Create and
10307 -- decorate a state abstraction entity and introduce it into the
10308 -- visibility chain. Pack_Id denotes the entity or the related
10309 -- package where pragma Abstract_State appears.
10311 procedure Malformed_State_Error
(State
: Node_Id
);
10312 -- Emit an error concerning the illegal declaration of abstract
10313 -- state State. This routine diagnoses syntax errors that lead to
10314 -- a different parse tree. The error is issued regardless of the
10315 -- SPARK mode in effect.
10317 ----------------------------
10318 -- Analyze_Abstract_State --
10319 ----------------------------
10321 procedure Analyze_Abstract_State
10323 Pack_Id
: Entity_Id
)
10325 -- Flags used to verify the consistency of options
10327 AR_Seen
: Boolean := False;
10328 AW_Seen
: Boolean := False;
10329 ER_Seen
: Boolean := False;
10330 EW_Seen
: Boolean := False;
10331 External_Seen
: Boolean := False;
10332 Ghost_Seen
: Boolean := False;
10333 Others_Seen
: Boolean := False;
10334 Part_Of_Seen
: Boolean := False;
10335 Synchronous_Seen
: Boolean := False;
10337 -- Flags used to store the static value of all external states'
10340 AR_Val
: Boolean := False;
10341 AW_Val
: Boolean := False;
10342 ER_Val
: Boolean := False;
10343 EW_Val
: Boolean := False;
10345 State_Id
: Entity_Id
:= Empty
;
10346 -- The entity to be generated for the current state declaration
10348 procedure Analyze_External_Option
(Opt
: Node_Id
);
10349 -- Verify the legality of option External
10351 procedure Analyze_External_Property
10353 Expr
: Node_Id
:= Empty
);
10354 -- Verify the legailty of a single external property. Prop
10355 -- denotes the external property. Expr is the expression used
10356 -- to set the property.
10358 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
);
10359 -- Verify the legality of option Part_Of
10361 procedure Check_Duplicate_Option
10363 Status
: in out Boolean);
10364 -- Flag Status denotes whether a particular option has been
10365 -- seen while processing a state. This routine verifies that
10366 -- Opt is not a duplicate option and sets the flag Status
10367 -- (SPARK RM 7.1.4(1)).
10369 procedure Check_Duplicate_Property
10371 Status
: in out Boolean);
10372 -- Flag Status denotes whether a particular property has been
10373 -- seen while processing option External. This routine verifies
10374 -- that Prop is not a duplicate property and sets flag Status.
10375 -- Opt is not a duplicate property and sets the flag Status.
10376 -- (SPARK RM 7.1.4(2))
10378 procedure Check_Ghost_Synchronous
;
10379 -- Ensure that the abstract state is not subject to both Ghost
10380 -- and Synchronous simple options. Emit an error if this is the
10383 procedure Create_Abstract_State
10387 Is_Null
: Boolean);
10388 -- Generate an abstract state entity with name Nam and enter it
10389 -- into visibility. Decl is the "declaration" of the state as
10390 -- it appears in pragma Abstract_State. Loc is the location of
10391 -- the related state "declaration". Flag Is_Null should be set
10392 -- when the associated Abstract_State pragma defines a null
10395 -----------------------------
10396 -- Analyze_External_Option --
10397 -----------------------------
10399 procedure Analyze_External_Option
(Opt
: Node_Id
) is
10400 Errors
: constant Nat
:= Serious_Errors_Detected
;
10402 Props
: Node_Id
:= Empty
;
10405 if Nkind
(Opt
) = N_Component_Association
then
10406 Props
:= Expression
(Opt
);
10409 -- External state with properties
10411 if Present
(Props
) then
10413 -- Multiple properties appear as an aggregate
10415 if Nkind
(Props
) = N_Aggregate
then
10417 -- Simple property form
10419 Prop
:= First
(Expressions
(Props
));
10420 while Present
(Prop
) loop
10421 Analyze_External_Property
(Prop
);
10425 -- Property with expression form
10427 Prop
:= First
(Component_Associations
(Props
));
10428 while Present
(Prop
) loop
10429 Analyze_External_Property
10430 (Prop
=> First
(Choices
(Prop
)),
10431 Expr
=> Expression
(Prop
));
10439 Analyze_External_Property
(Props
);
10442 -- An external state defined without any properties defaults
10443 -- all properties to True.
10452 -- Once all external properties have been processed, verify
10453 -- their mutual interaction. Do not perform the check when
10454 -- at least one of the properties is illegal as this will
10455 -- produce a bogus error.
10457 if Errors
= Serious_Errors_Detected
then
10458 Check_External_Properties
10459 (State
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
10461 end Analyze_External_Option
;
10463 -------------------------------
10464 -- Analyze_External_Property --
10465 -------------------------------
10467 procedure Analyze_External_Property
10469 Expr
: Node_Id
:= Empty
)
10471 Expr_Val
: Boolean;
10474 -- Check the placement of "others" (if available)
10476 if Nkind
(Prop
) = N_Others_Choice
then
10477 if Others_Seen
then
10479 ("only one others choice allowed in option External",
10482 Others_Seen
:= True;
10485 elsif Others_Seen
then
10487 ("others must be the last property in option External",
10490 -- The only remaining legal options are the four predefined
10491 -- external properties.
10493 elsif Nkind
(Prop
) = N_Identifier
10494 and then Nam_In
(Chars
(Prop
), Name_Async_Readers
,
10495 Name_Async_Writers
,
10496 Name_Effective_Reads
,
10497 Name_Effective_Writes
)
10501 -- Otherwise the construct is not a valid property
10504 SPARK_Msg_N
("invalid external state property", Prop
);
10508 -- Ensure that the expression of the external state property
10509 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10511 if Present
(Expr
) then
10512 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
10514 if Is_OK_Static_Expression
(Expr
) then
10515 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
10518 ("expression of external state property must be "
10522 -- The lack of expression defaults the property to True
10528 -- Named properties
10530 if Nkind
(Prop
) = N_Identifier
then
10531 if Chars
(Prop
) = Name_Async_Readers
then
10532 Check_Duplicate_Property
(Prop
, AR_Seen
);
10533 AR_Val
:= Expr_Val
;
10535 elsif Chars
(Prop
) = Name_Async_Writers
then
10536 Check_Duplicate_Property
(Prop
, AW_Seen
);
10537 AW_Val
:= Expr_Val
;
10539 elsif Chars
(Prop
) = Name_Effective_Reads
then
10540 Check_Duplicate_Property
(Prop
, ER_Seen
);
10541 ER_Val
:= Expr_Val
;
10544 Check_Duplicate_Property
(Prop
, EW_Seen
);
10545 EW_Val
:= Expr_Val
;
10548 -- The handling of property "others" must take into account
10549 -- all other named properties that have been encountered so
10550 -- far. Only those that have not been seen are affected by
10554 if not AR_Seen
then
10555 AR_Val
:= Expr_Val
;
10558 if not AW_Seen
then
10559 AW_Val
:= Expr_Val
;
10562 if not ER_Seen
then
10563 ER_Val
:= Expr_Val
;
10566 if not EW_Seen
then
10567 EW_Val
:= Expr_Val
;
10570 end Analyze_External_Property
;
10572 ----------------------------
10573 -- Analyze_Part_Of_Option --
10574 ----------------------------
10576 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
) is
10577 Encap
: constant Node_Id
:= Expression
(Opt
);
10578 Constits
: Elist_Id
;
10579 Encap_Id
: Entity_Id
;
10583 Check_Duplicate_Option
(Opt
, Part_Of_Seen
);
10586 (Indic
=> First
(Choices
(Opt
)),
10587 Item_Id
=> State_Id
,
10589 Encap_Id
=> Encap_Id
,
10592 -- The Part_Of indicator transforms the abstract state into
10593 -- a constituent of the encapsulating state or single
10594 -- concurrent type.
10597 pragma Assert
(Present
(Encap_Id
));
10598 Constits
:= Part_Of_Constituents
(Encap_Id
);
10600 if No
(Constits
) then
10601 Constits
:= New_Elmt_List
;
10602 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
10605 Append_Elmt
(State_Id
, Constits
);
10606 Set_Encapsulating_State
(State_Id
, Encap_Id
);
10608 end Analyze_Part_Of_Option
;
10610 ----------------------------
10611 -- Check_Duplicate_Option --
10612 ----------------------------
10614 procedure Check_Duplicate_Option
10616 Status
: in out Boolean)
10620 SPARK_Msg_N
("duplicate state option", Opt
);
10624 end Check_Duplicate_Option
;
10626 ------------------------------
10627 -- Check_Duplicate_Property --
10628 ------------------------------
10630 procedure Check_Duplicate_Property
10632 Status
: in out Boolean)
10636 SPARK_Msg_N
("duplicate external property", Prop
);
10640 end Check_Duplicate_Property
;
10642 -----------------------------
10643 -- Check_Ghost_Synchronous --
10644 -----------------------------
10646 procedure Check_Ghost_Synchronous
is
10648 -- A synchronized abstract state cannot be Ghost and vice
10649 -- versa (SPARK RM 6.9(19)).
10651 if Ghost_Seen
and Synchronous_Seen
then
10652 SPARK_Msg_N
("synchronized state cannot be ghost", State
);
10654 end Check_Ghost_Synchronous
;
10656 ---------------------------
10657 -- Create_Abstract_State --
10658 ---------------------------
10660 procedure Create_Abstract_State
10667 -- The abstract state may be semi-declared when the related
10668 -- package was withed through a limited with clause. In that
10669 -- case reuse the entity to fully declare the state.
10671 if Present
(Decl
) and then Present
(Entity
(Decl
)) then
10672 State_Id
:= Entity
(Decl
);
10674 -- Otherwise the elaboration of pragma Abstract_State
10675 -- declares the state.
10678 State_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
10680 if Present
(Decl
) then
10681 Set_Entity
(Decl
, State_Id
);
10685 -- Null states never come from source
10687 Set_Comes_From_Source
(State_Id
, not Is_Null
);
10688 Set_Parent
(State_Id
, State
);
10689 Set_Ekind
(State_Id
, E_Abstract_State
);
10690 Set_Etype
(State_Id
, Standard_Void_Type
);
10691 Set_Encapsulating_State
(State_Id
, Empty
);
10693 -- An abstract state declared within a Ghost region becomes
10694 -- Ghost (SPARK RM 6.9(2)).
10696 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Pack_Id
) then
10697 Set_Is_Ghost_Entity
(State_Id
);
10700 -- Establish a link between the state declaration and the
10701 -- abstract state entity. Note that a null state remains as
10702 -- N_Null and does not carry any linkages.
10704 if not Is_Null
then
10705 if Present
(Decl
) then
10706 Set_Entity
(Decl
, State_Id
);
10707 Set_Etype
(Decl
, Standard_Void_Type
);
10710 -- Every non-null state must be defined, nameable and
10713 Push_Scope
(Pack_Id
);
10714 Generate_Definition
(State_Id
);
10715 Enter_Name
(State_Id
);
10718 end Create_Abstract_State
;
10725 -- Start of processing for Analyze_Abstract_State
10728 -- A package with a null abstract state is not allowed to
10729 -- declare additional states.
10733 ("package & has null abstract state", State
, Pack_Id
);
10735 -- Null states appear as internally generated entities
10737 elsif Nkind
(State
) = N_Null
then
10738 Create_Abstract_State
10739 (Nam
=> New_Internal_Name
('S'),
10741 Loc
=> Sloc
(State
),
10745 -- Catch a case where a null state appears in a list of
10746 -- non-null states.
10748 if Non_Null_Seen
then
10750 ("package & has non-null abstract state",
10754 -- Simple state declaration
10756 elsif Nkind
(State
) = N_Identifier
then
10757 Create_Abstract_State
10758 (Nam
=> Chars
(State
),
10760 Loc
=> Sloc
(State
),
10762 Non_Null_Seen
:= True;
10764 -- State declaration with various options. This construct
10765 -- appears as an extension aggregate in the tree.
10767 elsif Nkind
(State
) = N_Extension_Aggregate
then
10768 if Nkind
(Ancestor_Part
(State
)) = N_Identifier
then
10769 Create_Abstract_State
10770 (Nam
=> Chars
(Ancestor_Part
(State
)),
10771 Decl
=> Ancestor_Part
(State
),
10772 Loc
=> Sloc
(Ancestor_Part
(State
)),
10774 Non_Null_Seen
:= True;
10777 ("state name must be an identifier",
10778 Ancestor_Part
(State
));
10781 -- Options External, Ghost and Synchronous appear as
10784 Opt
:= First
(Expressions
(State
));
10785 while Present
(Opt
) loop
10786 if Nkind
(Opt
) = N_Identifier
then
10790 if Chars
(Opt
) = Name_External
then
10791 Check_Duplicate_Option
(Opt
, External_Seen
);
10792 Analyze_External_Option
(Opt
);
10796 elsif Chars
(Opt
) = Name_Ghost
then
10797 Check_Duplicate_Option
(Opt
, Ghost_Seen
);
10798 Check_Ghost_Synchronous
;
10800 if Present
(State_Id
) then
10801 Set_Is_Ghost_Entity
(State_Id
);
10806 elsif Chars
(Opt
) = Name_Synchronous
then
10807 Check_Duplicate_Option
(Opt
, Synchronous_Seen
);
10808 Check_Ghost_Synchronous
;
10810 -- Option Part_Of without an encapsulating state is
10811 -- illegal (SPARK RM 7.1.4(9)).
10813 elsif Chars
(Opt
) = Name_Part_Of
then
10815 ("indicator Part_Of must denote abstract state, "
10816 & "single protected type or single task type",
10819 -- Do not emit an error message when a previous state
10820 -- declaration with options was not parenthesized as
10821 -- the option is actually another state declaration.
10823 -- with Abstract_State
10824 -- (State_1 with ..., -- missing parentheses
10825 -- (State_2 with ...),
10826 -- State_3) -- ok state declaration
10828 elsif Missing_Parentheses
then
10831 -- Otherwise the option is not allowed. Note that it
10832 -- is not possible to distinguish between an option
10833 -- and a state declaration when a previous state with
10834 -- options not properly parentheses.
10836 -- with Abstract_State
10837 -- (State_1 with ..., -- missing parentheses
10838 -- State_2); -- could be an option
10842 ("simple option not allowed in state declaration",
10846 -- Catch a case where missing parentheses around a state
10847 -- declaration with options cause a subsequent state
10848 -- declaration with options to be treated as an option.
10850 -- with Abstract_State
10851 -- (State_1 with ..., -- missing parentheses
10852 -- (State_2 with ...))
10854 elsif Nkind
(Opt
) = N_Extension_Aggregate
then
10855 Missing_Parentheses
:= True;
10857 ("state declaration must be parenthesized",
10858 Ancestor_Part
(State
));
10860 -- Otherwise the option is malformed
10863 SPARK_Msg_N
("malformed option", Opt
);
10869 -- Options External and Part_Of appear as component
10872 Opt
:= First
(Component_Associations
(State
));
10873 while Present
(Opt
) loop
10874 Opt_Nam
:= First
(Choices
(Opt
));
10876 if Nkind
(Opt_Nam
) = N_Identifier
then
10877 if Chars
(Opt_Nam
) = Name_External
then
10878 Analyze_External_Option
(Opt
);
10880 elsif Chars
(Opt_Nam
) = Name_Part_Of
then
10881 Analyze_Part_Of_Option
(Opt
);
10884 SPARK_Msg_N
("invalid state option", Opt
);
10887 SPARK_Msg_N
("invalid state option", Opt
);
10893 -- Any other attempt to declare a state is illegal
10896 Malformed_State_Error
(State
);
10900 -- Guard against a junk state. In such cases no entity is
10901 -- generated and the subsequent checks cannot be applied.
10903 if Present
(State_Id
) then
10905 -- Verify whether the state does not introduce an illegal
10906 -- hidden state within a package subject to a null abstract
10909 Check_No_Hidden_State
(State_Id
);
10911 -- Check whether the lack of option Part_Of agrees with the
10912 -- placement of the abstract state with respect to the state
10915 if not Part_Of_Seen
then
10916 Check_Missing_Part_Of
(State_Id
);
10919 -- Associate the state with its related package
10921 if No
(Abstract_States
(Pack_Id
)) then
10922 Set_Abstract_States
(Pack_Id
, New_Elmt_List
);
10925 Append_Elmt
(State_Id
, Abstract_States
(Pack_Id
));
10927 end Analyze_Abstract_State
;
10929 ---------------------------
10930 -- Malformed_State_Error --
10931 ---------------------------
10933 procedure Malformed_State_Error
(State
: Node_Id
) is
10935 Error_Msg_N
("malformed abstract state declaration", State
);
10937 -- An abstract state with a simple option is being declared
10938 -- with "=>" rather than the legal "with". The state appears
10939 -- as a component association.
10941 if Nkind
(State
) = N_Component_Association
then
10942 Error_Msg_N
("\use WITH to specify simple option", State
);
10944 end Malformed_State_Error
;
10948 Pack_Decl
: Node_Id
;
10949 Pack_Id
: Entity_Id
;
10953 -- Start of processing for Abstract_State
10957 Check_No_Identifiers
;
10958 Check_Arg_Count
(1);
10960 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
10962 -- Ensure the proper placement of the pragma. Abstract states must
10963 -- be associated with a package declaration.
10965 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
10966 N_Package_Declaration
)
10970 -- Otherwise the pragma is associated with an illegal construct
10977 Pack_Id
:= Defining_Entity
(Pack_Decl
);
10979 -- Chain the pragma on the contract for completeness
10981 Add_Contract_Item
(N
, Pack_Id
);
10983 -- The legality checks of pragmas Abstract_State, Initializes, and
10984 -- Initial_Condition are affected by the SPARK mode in effect. In
10985 -- addition, these three pragmas are subject to an inherent order:
10987 -- 1) Abstract_State
10989 -- 3) Initial_Condition
10991 -- Analyze all these pragmas in the order outlined above
10993 Analyze_If_Present
(Pragma_SPARK_Mode
);
10995 -- A pragma that applies to a Ghost entity becomes Ghost for the
10996 -- purposes of legality checks and removal of ignored Ghost code.
10998 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
10999 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
11001 States
:= Expression
(Get_Argument
(N
, Pack_Id
));
11003 -- Multiple non-null abstract states appear as an aggregate
11005 if Nkind
(States
) = N_Aggregate
then
11006 State
:= First
(Expressions
(States
));
11007 while Present
(State
) loop
11008 Analyze_Abstract_State
(State
, Pack_Id
);
11012 -- An abstract state with a simple option is being illegaly
11013 -- declared with "=>" rather than "with". In this case the
11014 -- state declaration appears as a component association.
11016 if Present
(Component_Associations
(States
)) then
11017 State
:= First
(Component_Associations
(States
));
11018 while Present
(State
) loop
11019 Malformed_State_Error
(State
);
11024 -- Various forms of a single abstract state. Note that these may
11025 -- include malformed state declarations.
11028 Analyze_Abstract_State
(States
, Pack_Id
);
11031 Analyze_If_Present
(Pragma_Initializes
);
11032 Analyze_If_Present
(Pragma_Initial_Condition
);
11033 end Abstract_State
;
11041 -- Note: this pragma also has some specific processing in Par.Prag
11042 -- because we want to set the Ada version mode during parsing.
11044 when Pragma_Ada_83
=>
11046 Check_Arg_Count
(0);
11048 -- We really should check unconditionally for proper configuration
11049 -- pragma placement, since we really don't want mixed Ada modes
11050 -- within a single unit, and the GNAT reference manual has always
11051 -- said this was a configuration pragma, but we did not check and
11052 -- are hesitant to add the check now.
11054 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
11055 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
11056 -- or Ada 2012 mode.
11058 if Ada_Version
>= Ada_2005
then
11059 Check_Valid_Configuration_Pragma
;
11062 -- Now set Ada 83 mode
11064 Ada_Version
:= Ada_83
;
11065 Ada_Version_Explicit
:= Ada_83
;
11066 Ada_Version_Pragma
:= N
;
11074 -- Note: this pragma also has some specific processing in Par.Prag
11075 -- because we want to set the Ada 83 version mode during parsing.
11077 when Pragma_Ada_95
=>
11079 Check_Arg_Count
(0);
11081 -- We really should check unconditionally for proper configuration
11082 -- pragma placement, since we really don't want mixed Ada modes
11083 -- within a single unit, and the GNAT reference manual has always
11084 -- said this was a configuration pragma, but we did not check and
11085 -- are hesitant to add the check now.
11087 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
11088 -- or Ada 95, so we must check if we are in Ada 2005 mode.
11090 if Ada_Version
>= Ada_2005
then
11091 Check_Valid_Configuration_Pragma
;
11094 -- Now set Ada 95 mode
11096 Ada_Version
:= Ada_95
;
11097 Ada_Version_Explicit
:= Ada_95
;
11098 Ada_Version_Pragma
:= N
;
11100 ---------------------
11101 -- Ada_05/Ada_2005 --
11102 ---------------------
11105 -- pragma Ada_05 (LOCAL_NAME);
11107 -- pragma Ada_2005;
11108 -- pragma Ada_2005 (LOCAL_NAME):
11110 -- Note: these pragmas also have some specific processing in Par.Prag
11111 -- because we want to set the Ada 2005 version mode during parsing.
11113 -- The one argument form is used for managing the transition from
11114 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
11115 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
11116 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
11117 -- mode, a preference rule is established which does not choose
11118 -- such an entity unless it is unambiguously specified. This avoids
11119 -- extra subprograms marked this way from generating ambiguities in
11120 -- otherwise legal pre-Ada_2005 programs. The one argument form is
11121 -- intended for exclusive use in the GNAT run-time library.
11123 when Pragma_Ada_05 | Pragma_Ada_2005
=> declare
11129 if Arg_Count
= 1 then
11130 Check_Arg_Is_Local_Name
(Arg1
);
11131 E_Id
:= Get_Pragma_Arg
(Arg1
);
11133 if Etype
(E_Id
) = Any_Type
then
11137 Set_Is_Ada_2005_Only
(Entity
(E_Id
));
11138 Record_Rep_Item
(Entity
(E_Id
), N
);
11141 Check_Arg_Count
(0);
11143 -- For Ada_2005 we unconditionally enforce the documented
11144 -- configuration pragma placement, since we do not want to
11145 -- tolerate mixed modes in a unit involving Ada 2005. That
11146 -- would cause real difficulties for those cases where there
11147 -- are incompatibilities between Ada 95 and Ada 2005.
11149 Check_Valid_Configuration_Pragma
;
11151 -- Now set appropriate Ada mode
11153 Ada_Version
:= Ada_2005
;
11154 Ada_Version_Explicit
:= Ada_2005
;
11155 Ada_Version_Pragma
:= N
;
11159 ---------------------
11160 -- Ada_12/Ada_2012 --
11161 ---------------------
11164 -- pragma Ada_12 (LOCAL_NAME);
11166 -- pragma Ada_2012;
11167 -- pragma Ada_2012 (LOCAL_NAME):
11169 -- Note: these pragmas also have some specific processing in Par.Prag
11170 -- because we want to set the Ada 2012 version mode during parsing.
11172 -- The one argument form is used for managing the transition from Ada
11173 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
11174 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
11175 -- mode will generate a warning. In addition, in any pre-Ada_2012
11176 -- mode, a preference rule is established which does not choose
11177 -- such an entity unless it is unambiguously specified. This avoids
11178 -- extra subprograms marked this way from generating ambiguities in
11179 -- otherwise legal pre-Ada_2012 programs. The one argument form is
11180 -- intended for exclusive use in the GNAT run-time library.
11182 when Pragma_Ada_12 | Pragma_Ada_2012
=> declare
11188 if Arg_Count
= 1 then
11189 Check_Arg_Is_Local_Name
(Arg1
);
11190 E_Id
:= Get_Pragma_Arg
(Arg1
);
11192 if Etype
(E_Id
) = Any_Type
then
11196 Set_Is_Ada_2012_Only
(Entity
(E_Id
));
11197 Record_Rep_Item
(Entity
(E_Id
), N
);
11200 Check_Arg_Count
(0);
11202 -- For Ada_2012 we unconditionally enforce the documented
11203 -- configuration pragma placement, since we do not want to
11204 -- tolerate mixed modes in a unit involving Ada 2012. That
11205 -- would cause real difficulties for those cases where there
11206 -- are incompatibilities between Ada 95 and Ada 2012. We could
11207 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
11209 Check_Valid_Configuration_Pragma
;
11211 -- Now set appropriate Ada mode
11213 Ada_Version
:= Ada_2012
;
11214 Ada_Version_Explicit
:= Ada_2012
;
11215 Ada_Version_Pragma
:= N
;
11219 ----------------------
11220 -- All_Calls_Remote --
11221 ----------------------
11223 -- pragma All_Calls_Remote [(library_package_NAME)];
11225 when Pragma_All_Calls_Remote
=> All_Calls_Remote
: declare
11226 Lib_Entity
: Entity_Id
;
11229 Check_Ada_83_Warning
;
11230 Check_Valid_Library_Unit_Pragma
;
11232 if Nkind
(N
) = N_Null_Statement
then
11236 Lib_Entity
:= Find_Lib_Unit_Name
;
11238 -- A pragma that applies to a Ghost entity becomes Ghost for the
11239 -- purposes of legality checks and removal of ignored Ghost code.
11241 Mark_Pragma_As_Ghost
(N
, Lib_Entity
);
11243 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11245 if Present
(Lib_Entity
) and then not Debug_Flag_U
then
11246 if not Is_Remote_Call_Interface
(Lib_Entity
) then
11247 Error_Pragma
("pragma% only apply to rci unit");
11249 -- Set flag for entity of the library unit
11252 Set_Has_All_Calls_Remote
(Lib_Entity
);
11255 end All_Calls_Remote
;
11257 ---------------------------
11258 -- Allow_Integer_Address --
11259 ---------------------------
11261 -- pragma Allow_Integer_Address;
11263 when Pragma_Allow_Integer_Address
=>
11265 Check_Valid_Configuration_Pragma
;
11266 Check_Arg_Count
(0);
11268 -- If Address is a private type, then set the flag to allow
11269 -- integer address values. If Address is not private, then this
11270 -- pragma has no purpose, so it is simply ignored. Not clear if
11271 -- there are any such targets now.
11273 if Opt
.Address_Is_Private
then
11274 Opt
.Allow_Integer_Address
:= True;
11282 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11283 -- ARG ::= NAME | EXPRESSION
11285 -- The first two arguments are by convention intended to refer to an
11286 -- external tool and a tool-specific function. These arguments are
11289 when Pragma_Annotate
=> Annotate
: declare
11296 Check_At_Least_N_Arguments
(1);
11298 Nam_Arg
:= Last
(Pragma_Argument_Associations
(N
));
11300 -- Determine whether the last argument is "Entity => local_NAME"
11301 -- and if it is, perform the required semantic checks. Remove the
11302 -- argument from further processing.
11304 if Nkind
(Nam_Arg
) = N_Pragma_Argument_Association
11305 and then Chars
(Nam_Arg
) = Name_Entity
11307 Check_Arg_Is_Local_Name
(Nam_Arg
);
11308 Arg_Count
:= Arg_Count
- 1;
11310 -- A pragma that applies to a Ghost entity becomes Ghost for
11311 -- the purposes of legality checks and removal of ignored Ghost
11314 if Is_Entity_Name
(Get_Pragma_Arg
(Nam_Arg
))
11315 and then Present
(Entity
(Get_Pragma_Arg
(Nam_Arg
)))
11317 Mark_Pragma_As_Ghost
(N
, Entity
(Get_Pragma_Arg
(Nam_Arg
)));
11320 -- Not allowed in compiler units (bootstrap issues)
11322 Check_Compiler_Unit
("Entity for pragma Annotate", N
);
11325 -- Continue the processing with last argument removed for now
11327 Check_Arg_Is_Identifier
(Arg1
);
11328 Check_No_Identifiers
;
11331 -- The second parameter is optional, it is never analyzed
11336 -- Otherwise there is a second parameter
11339 -- The second parameter must be an identifier
11341 Check_Arg_Is_Identifier
(Arg2
);
11343 -- Process the remaining parameters (if any)
11345 Arg
:= Next
(Arg2
);
11346 while Present
(Arg
) loop
11347 Expr
:= Get_Pragma_Arg
(Arg
);
11350 if Is_Entity_Name
(Expr
) then
11353 -- For string literals, we assume Standard_String as the
11354 -- type, unless the string contains wide or wide_wide
11357 elsif Nkind
(Expr
) = N_String_Literal
then
11358 if Has_Wide_Wide_Character
(Expr
) then
11359 Resolve
(Expr
, Standard_Wide_Wide_String
);
11360 elsif Has_Wide_Character
(Expr
) then
11361 Resolve
(Expr
, Standard_Wide_String
);
11363 Resolve
(Expr
, Standard_String
);
11366 elsif Is_Overloaded
(Expr
) then
11367 Error_Pragma_Arg
("ambiguous argument for pragma%", Expr
);
11378 -------------------------------------------------
11379 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11380 -------------------------------------------------
11383 -- ( [Check => ] Boolean_EXPRESSION
11384 -- [, [Message =>] Static_String_EXPRESSION]);
11386 -- pragma Assert_And_Cut
11387 -- ( [Check => ] Boolean_EXPRESSION
11388 -- [, [Message =>] Static_String_EXPRESSION]);
11391 -- ( [Check => ] Boolean_EXPRESSION
11392 -- [, [Message =>] Static_String_EXPRESSION]);
11394 -- pragma Loop_Invariant
11395 -- ( [Check => ] Boolean_EXPRESSION
11396 -- [, [Message =>] Static_String_EXPRESSION]);
11398 when Pragma_Assert |
11399 Pragma_Assert_And_Cut |
11401 Pragma_Loop_Invariant
=>
11403 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean;
11404 -- Determine whether expression Expr contains a Loop_Entry
11405 -- attribute reference.
11407 -------------------------
11408 -- Contains_Loop_Entry --
11409 -------------------------
11411 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean is
11412 Has_Loop_Entry
: Boolean := False;
11414 function Process
(N
: Node_Id
) return Traverse_Result
;
11415 -- Process function for traversal to look for Loop_Entry
11421 function Process
(N
: Node_Id
) return Traverse_Result
is
11423 if Nkind
(N
) = N_Attribute_Reference
11424 and then Attribute_Name
(N
) = Name_Loop_Entry
11426 Has_Loop_Entry
:= True;
11433 procedure Traverse
is new Traverse_Proc
(Process
);
11435 -- Start of processing for Contains_Loop_Entry
11439 return Has_Loop_Entry
;
11440 end Contains_Loop_Entry
;
11445 New_Args
: List_Id
;
11447 -- Start of processing for Assert
11450 -- Assert is an Ada 2005 RM-defined pragma
11452 if Prag_Id
= Pragma_Assert
then
11455 -- The remaining ones are GNAT pragmas
11461 Check_At_Least_N_Arguments
(1);
11462 Check_At_Most_N_Arguments
(2);
11463 Check_Arg_Order
((Name_Check
, Name_Message
));
11464 Check_Optional_Identifier
(Arg1
, Name_Check
);
11465 Expr
:= Get_Pragma_Arg
(Arg1
);
11467 -- Special processing for Loop_Invariant, Loop_Variant or for
11468 -- other cases where a Loop_Entry attribute is present. If the
11469 -- assertion pragma contains attribute Loop_Entry, ensure that
11470 -- the related pragma is within a loop.
11472 if Prag_Id
= Pragma_Loop_Invariant
11473 or else Prag_Id
= Pragma_Loop_Variant
11474 or else Contains_Loop_Entry
(Expr
)
11476 Check_Loop_Pragma_Placement
;
11478 -- Perform preanalysis to deal with embedded Loop_Entry
11481 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
11484 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11485 -- a corresponding Check pragma:
11487 -- pragma Check (name, condition [, msg]);
11489 -- Where name is the identifier matching the pragma name. So
11490 -- rewrite pragma in this manner, transfer the message argument
11491 -- if present, and analyze the result
11493 -- Note: When dealing with a semantically analyzed tree, the
11494 -- information that a Check node N corresponds to a source Assert,
11495 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11496 -- pragma kind of Original_Node(N).
11498 New_Args
:= New_List
(
11499 Make_Pragma_Argument_Association
(Loc
,
11500 Expression
=> Make_Identifier
(Loc
, Pname
)),
11501 Make_Pragma_Argument_Association
(Sloc
(Expr
),
11502 Expression
=> Expr
));
11504 if Arg_Count
> 1 then
11505 Check_Optional_Identifier
(Arg2
, Name_Message
);
11507 -- Provide semantic annnotations for optional argument, for
11508 -- ASIS use, before rewriting.
11510 Preanalyze_And_Resolve
(Expression
(Arg2
), Standard_String
);
11511 Append_To
(New_Args
, New_Copy_Tree
(Arg2
));
11514 -- Rewrite as Check pragma
11518 Chars
=> Name_Check
,
11519 Pragma_Argument_Associations
=> New_Args
));
11524 ----------------------
11525 -- Assertion_Policy --
11526 ----------------------
11528 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11530 -- The following form is Ada 2012 only, but we allow it in all modes
11532 -- Pragma Assertion_Policy (
11533 -- ASSERTION_KIND => POLICY_IDENTIFIER
11534 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11536 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11538 -- RM_ASSERTION_KIND ::= Assert |
11539 -- Static_Predicate |
11540 -- Dynamic_Predicate |
11545 -- Type_Invariant |
11546 -- Type_Invariant'Class
11548 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11550 -- Contract_Cases |
11552 -- Default_Initial_Condition |
11554 -- Initial_Condition |
11555 -- Loop_Invariant |
11561 -- Statement_Assertions
11563 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11564 -- ID_ASSERTION_KIND list contains implementation-defined additions
11565 -- recognized by GNAT. The effect is to control the behavior of
11566 -- identically named aspects and pragmas, depending on the specified
11567 -- policy identifier:
11569 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11571 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11572 -- implementation-defined addition that results in totally ignoring
11573 -- the corresponding assertion. If Disable is specified, then the
11574 -- argument of the assertion is not even analyzed. This is useful
11575 -- when the aspect/pragma argument references entities in a with'ed
11576 -- package that is replaced by a dummy package in the final build.
11578 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11579 -- and Type_Invariant'Class were recognized by the parser and
11580 -- transformed into references to the special internal identifiers
11581 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11582 -- processing is required here.
11584 when Pragma_Assertion_Policy
=> Assertion_Policy
: declare
11593 -- This can always appear as a configuration pragma
11595 if Is_Configuration_Pragma
then
11598 -- It can also appear in a declarative part or package spec in Ada
11599 -- 2012 mode. We allow this in other modes, but in that case we
11600 -- consider that we have an Ada 2012 pragma on our hands.
11603 Check_Is_In_Decl_Part_Or_Package_Spec
;
11607 -- One argument case with no identifier (first form above)
11610 and then (Nkind
(Arg1
) /= N_Pragma_Argument_Association
11611 or else Chars
(Arg1
) = No_Name
)
11613 Check_Arg_Is_One_Of
11614 (Arg1
, Name_Check
, Name_Disable
, Name_Ignore
);
11616 -- Treat one argument Assertion_Policy as equivalent to:
11618 -- pragma Check_Policy (Assertion, policy)
11620 -- So rewrite pragma in that manner and link on to the chain
11621 -- of Check_Policy pragmas, marking the pragma as analyzed.
11623 Policy
:= Get_Pragma_Arg
(Arg1
);
11627 Chars
=> Name_Check_Policy
,
11628 Pragma_Argument_Associations
=> New_List
(
11629 Make_Pragma_Argument_Association
(Loc
,
11630 Expression
=> Make_Identifier
(Loc
, Name_Assertion
)),
11632 Make_Pragma_Argument_Association
(Loc
,
11634 Make_Identifier
(Sloc
(Policy
), Chars
(Policy
))))));
11637 -- Here if we have two or more arguments
11640 Check_At_Least_N_Arguments
(1);
11643 -- Loop through arguments
11646 while Present
(Arg
) loop
11647 LocP
:= Sloc
(Arg
);
11649 -- Kind must be specified
11651 if Nkind
(Arg
) /= N_Pragma_Argument_Association
11652 or else Chars
(Arg
) = No_Name
11655 ("missing assertion kind for pragma%", Arg
);
11658 -- Check Kind and Policy have allowed forms
11660 Kind
:= Chars
(Arg
);
11661 Policy
:= Get_Pragma_Arg
(Arg
);
11663 if not Is_Valid_Assertion_Kind
(Kind
) then
11665 ("invalid assertion kind for pragma%", Arg
);
11668 Check_Arg_Is_One_Of
11669 (Arg
, Name_Check
, Name_Disable
, Name_Ignore
);
11671 if Kind
= Name_Ghost
then
11673 -- The Ghost policy must be either Check or Ignore
11674 -- (SPARK RM 6.9(6)).
11676 if not Nam_In
(Chars
(Policy
), Name_Check
,
11680 ("argument of pragma % Ghost must be Check or "
11681 & "Ignore", Policy
);
11684 -- Pragma Assertion_Policy specifying a Ghost policy
11685 -- cannot occur within a Ghost subprogram or package
11686 -- (SPARK RM 6.9(14)).
11688 if Ghost_Mode
> None
then
11690 ("pragma % cannot appear within ghost subprogram or "
11695 -- Rewrite the Assertion_Policy pragma as a series of
11696 -- Check_Policy pragmas of the form:
11698 -- Check_Policy (Kind, Policy);
11700 -- Note: the insertion of the pragmas cannot be done with
11701 -- Insert_Action because in the configuration case, there
11702 -- are no scopes on the scope stack and the mechanism will
11705 Insert_Before_And_Analyze
(N
,
11707 Chars
=> Name_Check_Policy
,
11708 Pragma_Argument_Associations
=> New_List
(
11709 Make_Pragma_Argument_Association
(LocP
,
11710 Expression
=> Make_Identifier
(LocP
, Kind
)),
11711 Make_Pragma_Argument_Association
(LocP
,
11712 Expression
=> Policy
))));
11717 -- Rewrite the Assertion_Policy pragma as null since we have
11718 -- now inserted all the equivalent Check pragmas.
11720 Rewrite
(N
, Make_Null_Statement
(Loc
));
11723 end Assertion_Policy
;
11725 ------------------------------
11726 -- Assume_No_Invalid_Values --
11727 ------------------------------
11729 -- pragma Assume_No_Invalid_Values (On | Off);
11731 when Pragma_Assume_No_Invalid_Values
=>
11733 Check_Valid_Configuration_Pragma
;
11734 Check_Arg_Count
(1);
11735 Check_No_Identifiers
;
11736 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
11738 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
11739 Assume_No_Invalid_Values
:= True;
11741 Assume_No_Invalid_Values
:= False;
11744 --------------------------
11745 -- Attribute_Definition --
11746 --------------------------
11748 -- pragma Attribute_Definition
11749 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11750 -- [Entity =>] LOCAL_NAME,
11751 -- [Expression =>] EXPRESSION | NAME);
11753 when Pragma_Attribute_Definition
=> Attribute_Definition
: declare
11754 Attribute_Designator
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
11759 Check_Arg_Count
(3);
11760 Check_Optional_Identifier
(Arg1
, "attribute");
11761 Check_Optional_Identifier
(Arg2
, "entity");
11762 Check_Optional_Identifier
(Arg3
, "expression");
11764 if Nkind
(Attribute_Designator
) /= N_Identifier
then
11765 Error_Msg_N
("attribute name expected", Attribute_Designator
);
11769 Check_Arg_Is_Local_Name
(Arg2
);
11771 -- If the attribute is not recognized, then issue a warning (not
11772 -- an error), and ignore the pragma.
11774 Aname
:= Chars
(Attribute_Designator
);
11776 if not Is_Attribute_Name
(Aname
) then
11777 Bad_Attribute
(Attribute_Designator
, Aname
, Warn
=> True);
11781 -- Otherwise, rewrite the pragma as an attribute definition clause
11784 Make_Attribute_Definition_Clause
(Loc
,
11785 Name
=> Get_Pragma_Arg
(Arg2
),
11787 Expression
=> Get_Pragma_Arg
(Arg3
)));
11789 end Attribute_Definition
;
11791 ------------------------------------------------------------------
11792 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11793 ------------------------------------------------------------------
11795 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
11796 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
11797 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
11798 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
11800 when Pragma_Async_Readers |
11801 Pragma_Async_Writers |
11802 Pragma_Effective_Reads |
11803 Pragma_Effective_Writes
=>
11804 Async_Effective
: declare
11805 Obj_Decl
: Node_Id
;
11806 Obj_Id
: Entity_Id
;
11810 Check_No_Identifiers
;
11811 Check_At_Most_N_Arguments
(1);
11813 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
11815 -- Object declaration
11817 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
11820 -- Otherwise the pragma is associated with an illegal construact
11827 Obj_Id
:= Defining_Entity
(Obj_Decl
);
11829 -- Perform minimal verification to ensure that the argument is at
11830 -- least a variable. Subsequent finer grained checks will be done
11831 -- at the end of the declarative region the contains the pragma.
11833 if Ekind
(Obj_Id
) = E_Variable
then
11835 -- Chain the pragma on the contract for further processing by
11836 -- Analyze_External_Property_In_Decl_Part.
11838 Add_Contract_Item
(N
, Obj_Id
);
11840 -- A pragma that applies to a Ghost entity becomes Ghost for
11841 -- the purposes of legality checks and removal of ignored Ghost
11844 Mark_Pragma_As_Ghost
(N
, Obj_Id
);
11846 -- Analyze the Boolean expression (if any)
11848 if Present
(Arg1
) then
11849 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
11852 -- Otherwise the external property applies to a constant
11855 Error_Pragma
("pragma % must apply to a volatile object");
11857 end Async_Effective
;
11863 -- pragma Asynchronous (LOCAL_NAME);
11865 when Pragma_Asynchronous
=> Asynchronous
: declare
11868 Formal
: Entity_Id
;
11873 procedure Process_Async_Pragma
;
11874 -- Common processing for procedure and access-to-procedure case
11876 --------------------------
11877 -- Process_Async_Pragma --
11878 --------------------------
11880 procedure Process_Async_Pragma
is
11883 Set_Is_Asynchronous
(Nm
);
11887 -- The formals should be of mode IN (RM E.4.1(6))
11890 while Present
(S
) loop
11891 Formal
:= Defining_Identifier
(S
);
11893 if Nkind
(Formal
) = N_Defining_Identifier
11894 and then Ekind
(Formal
) /= E_In_Parameter
11897 ("pragma% procedure can only have IN parameter",
11904 Set_Is_Asynchronous
(Nm
);
11905 end Process_Async_Pragma
;
11907 -- Start of processing for pragma Asynchronous
11910 Check_Ada_83_Warning
;
11911 Check_No_Identifiers
;
11912 Check_Arg_Count
(1);
11913 Check_Arg_Is_Local_Name
(Arg1
);
11915 if Debug_Flag_U
then
11919 C_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
11920 Analyze
(Get_Pragma_Arg
(Arg1
));
11921 Nm
:= Entity
(Get_Pragma_Arg
(Arg1
));
11923 -- A pragma that applies to a Ghost entity becomes Ghost for the
11924 -- purposes of legality checks and removal of ignored Ghost code.
11926 Mark_Pragma_As_Ghost
(N
, Nm
);
11928 if not Is_Remote_Call_Interface
(C_Ent
)
11929 and then not Is_Remote_Types
(C_Ent
)
11931 -- This pragma should only appear in an RCI or Remote Types
11932 -- unit (RM E.4.1(4)).
11935 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11938 if Ekind
(Nm
) = E_Procedure
11939 and then Nkind
(Parent
(Nm
)) = N_Procedure_Specification
11941 if not Is_Remote_Call_Interface
(Nm
) then
11943 ("pragma% cannot be applied on non-remote procedure",
11947 L
:= Parameter_Specifications
(Parent
(Nm
));
11948 Process_Async_Pragma
;
11951 elsif Ekind
(Nm
) = E_Function
then
11953 ("pragma% cannot be applied to function", Arg1
);
11955 elsif Is_Remote_Access_To_Subprogram_Type
(Nm
) then
11956 if Is_Record_Type
(Nm
) then
11958 -- A record type that is the Equivalent_Type for a remote
11959 -- access-to-subprogram type.
11961 Decl
:= Declaration_Node
(Corresponding_Remote_Type
(Nm
));
11964 -- A non-expanded RAS type (distribution is not enabled)
11966 Decl
:= Declaration_Node
(Nm
);
11969 if Nkind
(Decl
) = N_Full_Type_Declaration
11970 and then Nkind
(Type_Definition
(Decl
)) =
11971 N_Access_Procedure_Definition
11973 L
:= Parameter_Specifications
(Type_Definition
(Decl
));
11974 Process_Async_Pragma
;
11976 if Is_Asynchronous
(Nm
)
11977 and then Expander_Active
11978 and then Get_PCS_Name
/= Name_No_DSA
11980 RACW_Type_Is_Asynchronous
(Underlying_RACW_Type
(Nm
));
11985 ("pragma% cannot reference access-to-function type",
11989 -- Only other possibility is Access-to-class-wide type
11991 elsif Is_Access_Type
(Nm
)
11992 and then Is_Class_Wide_Type
(Designated_Type
(Nm
))
11994 Check_First_Subtype
(Arg1
);
11995 Set_Is_Asynchronous
(Nm
);
11996 if Expander_Active
then
11997 RACW_Type_Is_Asynchronous
(Nm
);
12001 Error_Pragma_Arg
("inappropriate argument for pragma%", Arg1
);
12009 -- pragma Atomic (LOCAL_NAME);
12011 when Pragma_Atomic
=>
12012 Process_Atomic_Independent_Shared_Volatile
;
12014 -----------------------
12015 -- Atomic_Components --
12016 -----------------------
12018 -- pragma Atomic_Components (array_LOCAL_NAME);
12020 -- This processing is shared by Volatile_Components
12022 when Pragma_Atomic_Components |
12023 Pragma_Volatile_Components
=>
12024 Atomic_Components
: declare
12031 Check_Ada_83_Warning
;
12032 Check_No_Identifiers
;
12033 Check_Arg_Count
(1);
12034 Check_Arg_Is_Local_Name
(Arg1
);
12035 E_Id
:= Get_Pragma_Arg
(Arg1
);
12037 if Etype
(E_Id
) = Any_Type
then
12041 E
:= Entity
(E_Id
);
12043 -- A pragma that applies to a Ghost entity becomes Ghost for the
12044 -- purposes of legality checks and removal of ignored Ghost code.
12046 Mark_Pragma_As_Ghost
(N
, E
);
12047 Check_Duplicate_Pragma
(E
);
12049 if Rep_Item_Too_Early
(E
, N
)
12051 Rep_Item_Too_Late
(E
, N
)
12056 D
:= Declaration_Node
(E
);
12059 if (K
= N_Full_Type_Declaration
and then Is_Array_Type
(E
))
12061 ((Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
12062 and then Nkind
(D
) = N_Object_Declaration
12063 and then Nkind
(Object_Definition
(D
)) =
12064 N_Constrained_Array_Definition
)
12066 -- The flag is set on the object, or on the base type
12068 if Nkind
(D
) /= N_Object_Declaration
then
12069 E
:= Base_Type
(E
);
12072 -- Atomic implies both Independent and Volatile
12074 if Prag_Id
= Pragma_Atomic_Components
then
12075 Set_Has_Atomic_Components
(E
);
12076 Set_Has_Independent_Components
(E
);
12079 Set_Has_Volatile_Components
(E
);
12082 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
12084 end Atomic_Components
;
12086 --------------------
12087 -- Attach_Handler --
12088 --------------------
12090 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
12092 when Pragma_Attach_Handler
=>
12093 Check_Ada_83_Warning
;
12094 Check_No_Identifiers
;
12095 Check_Arg_Count
(2);
12097 if No_Run_Time_Mode
then
12098 Error_Msg_CRT
("Attach_Handler pragma", N
);
12100 Check_Interrupt_Or_Attach_Handler
;
12102 -- The expression that designates the attribute may depend on a
12103 -- discriminant, and is therefore a per-object expression, to
12104 -- be expanded in the init proc. If expansion is enabled, then
12105 -- perform semantic checks on a copy only.
12110 Parg2
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
12113 -- In Relaxed_RM_Semantics mode, we allow any static
12114 -- integer value, for compatibility with other compilers.
12116 if Relaxed_RM_Semantics
12117 and then Nkind
(Parg2
) = N_Integer_Literal
12119 Typ
:= Standard_Integer
;
12121 Typ
:= RTE
(RE_Interrupt_ID
);
12124 if Expander_Active
then
12125 Temp
:= New_Copy_Tree
(Parg2
);
12126 Set_Parent
(Temp
, N
);
12127 Preanalyze_And_Resolve
(Temp
, Typ
);
12130 Resolve
(Parg2
, Typ
);
12134 Process_Interrupt_Or_Attach_Handler
;
12137 --------------------
12138 -- C_Pass_By_Copy --
12139 --------------------
12141 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
12143 when Pragma_C_Pass_By_Copy
=> C_Pass_By_Copy
: declare
12149 Check_Valid_Configuration_Pragma
;
12150 Check_Arg_Count
(1);
12151 Check_Optional_Identifier
(Arg1
, "max_size");
12153 Arg
:= Get_Pragma_Arg
(Arg1
);
12154 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
12156 Val
:= Expr_Value
(Arg
);
12160 ("maximum size for pragma% must be positive", Arg1
);
12162 elsif UI_Is_In_Int_Range
(Val
) then
12163 Default_C_Record_Mechanism
:= UI_To_Int
(Val
);
12165 -- If a giant value is given, Int'Last will do well enough.
12166 -- If sometime someone complains that a record larger than
12167 -- two gigabytes is not copied, we will worry about it then.
12170 Default_C_Record_Mechanism
:= Mechanism_Type
'Last;
12172 end C_Pass_By_Copy
;
12178 -- pragma Check ([Name =>] CHECK_KIND,
12179 -- [Check =>] Boolean_EXPRESSION
12180 -- [,[Message =>] String_EXPRESSION]);
12182 -- CHECK_KIND ::= IDENTIFIER |
12185 -- Invariant'Class |
12186 -- Type_Invariant'Class
12188 -- The identifiers Assertions and Statement_Assertions are not
12189 -- allowed, since they have special meaning for Check_Policy.
12191 when Pragma_Check
=> Check
: declare
12197 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
12200 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
12201 -- the mode now to ensure that any nodes generated during analysis
12202 -- and expansion are marked as Ghost.
12204 Set_Ghost_Mode
(N
);
12207 Check_At_Least_N_Arguments
(2);
12208 Check_At_Most_N_Arguments
(3);
12209 Check_Optional_Identifier
(Arg1
, Name_Name
);
12210 Check_Optional_Identifier
(Arg2
, Name_Check
);
12212 if Arg_Count
= 3 then
12213 Check_Optional_Identifier
(Arg3
, Name_Message
);
12214 Str
:= Get_Pragma_Arg
(Arg3
);
12217 Rewrite_Assertion_Kind
(Get_Pragma_Arg
(Arg1
));
12218 Check_Arg_Is_Identifier
(Arg1
);
12219 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
12221 -- Check forbidden name Assertions or Statement_Assertions
12224 when Name_Assertions
=>
12226 ("""Assertions"" is not allowed as a check kind for "
12227 & "pragma%", Arg1
);
12229 when Name_Statement_Assertions
=>
12231 ("""Statement_Assertions"" is not allowed as a check kind "
12232 & "for pragma%", Arg1
);
12238 -- Check applicable policy. We skip this if Checked/Ignored status
12239 -- is already set (e.g. in the case of a pragma from an aspect).
12241 if Is_Checked
(N
) or else Is_Ignored
(N
) then
12244 -- For a non-source pragma that is a rewriting of another pragma,
12245 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12247 elsif Is_Rewrite_Substitution
(N
)
12248 and then Nkind
(Original_Node
(N
)) = N_Pragma
12249 and then Original_Node
(N
) /= N
12251 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
12252 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
12254 -- Otherwise query the applicable policy at this point
12257 case Check_Kind
(Cname
) is
12258 when Name_Ignore
=>
12259 Set_Is_Ignored
(N
, True);
12260 Set_Is_Checked
(N
, False);
12263 Set_Is_Ignored
(N
, False);
12264 Set_Is_Checked
(N
, True);
12266 -- For disable, rewrite pragma as null statement and skip
12267 -- rest of the analysis of the pragma.
12269 when Name_Disable
=>
12270 Rewrite
(N
, Make_Null_Statement
(Loc
));
12274 -- No other possibilities
12277 raise Program_Error
;
12281 -- If check kind was not Disable, then continue pragma analysis
12283 Expr
:= Get_Pragma_Arg
(Arg2
);
12285 -- Deal with SCO generation
12289 -- Nothing to do for predicates as the checks occur in the
12290 -- client units. The SCO for the aspect in the declaration
12291 -- unit is conservatively always enabled.
12293 when Name_Predicate
=>
12296 -- Otherwise mark aspect/pragma SCO as enabled
12299 if Is_Checked
(N
) and then not Split_PPC
(N
) then
12300 Set_SCO_Pragma_Enabled
(Loc
);
12304 -- Deal with analyzing the string argument
12306 if Arg_Count
= 3 then
12308 -- If checks are not on we don't want any expansion (since
12309 -- such expansion would not get properly deleted) but
12310 -- we do want to analyze (to get proper references).
12311 -- The Preanalyze_And_Resolve routine does just what we want
12313 if Is_Ignored
(N
) then
12314 Preanalyze_And_Resolve
(Str
, Standard_String
);
12316 -- Otherwise we need a proper analysis and expansion
12319 Analyze_And_Resolve
(Str
, Standard_String
);
12323 -- Now you might think we could just do the same with the Boolean
12324 -- expression if checks are off (and expansion is on) and then
12325 -- rewrite the check as a null statement. This would work but we
12326 -- would lose the useful warnings about an assertion being bound
12327 -- to fail even if assertions are turned off.
12329 -- So instead we wrap the boolean expression in an if statement
12330 -- that looks like:
12332 -- if False and then condition then
12336 -- The reason we do this rewriting during semantic analysis rather
12337 -- than as part of normal expansion is that we cannot analyze and
12338 -- expand the code for the boolean expression directly, or it may
12339 -- cause insertion of actions that would escape the attempt to
12340 -- suppress the check code.
12342 -- Note that the Sloc for the if statement corresponds to the
12343 -- argument condition, not the pragma itself. The reason for
12344 -- this is that we may generate a warning if the condition is
12345 -- False at compile time, and we do not want to delete this
12346 -- warning when we delete the if statement.
12348 if Expander_Active
and Is_Ignored
(N
) then
12349 Eloc
:= Sloc
(Expr
);
12352 Make_If_Statement
(Eloc
,
12354 Make_And_Then
(Eloc
,
12355 Left_Opnd
=> Make_Identifier
(Eloc
, Name_False
),
12356 Right_Opnd
=> Expr
),
12357 Then_Statements
=> New_List
(
12358 Make_Null_Statement
(Eloc
))));
12360 -- Now go ahead and analyze the if statement
12362 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
12364 -- One rather special treatment. If we are now in Eliminated
12365 -- overflow mode, then suppress overflow checking since we do
12366 -- not want to drag in the bignum stuff if we are in Ignore
12367 -- mode anyway. This is particularly important if we are using
12368 -- a configurable run time that does not support bignum ops.
12370 if Scope_Suppress
.Overflow_Mode_Assertions
= Eliminated
then
12372 Svo
: constant Boolean :=
12373 Scope_Suppress
.Suppress
(Overflow_Check
);
12375 Scope_Suppress
.Overflow_Mode_Assertions
:= Strict
;
12376 Scope_Suppress
.Suppress
(Overflow_Check
) := True;
12378 Scope_Suppress
.Suppress
(Overflow_Check
) := Svo
;
12379 Scope_Suppress
.Overflow_Mode_Assertions
:= Eliminated
;
12382 -- Not that special case
12388 -- All done with this check
12390 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
12392 -- Check is active or expansion not active. In these cases we can
12393 -- just go ahead and analyze the boolean with no worries.
12396 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
12397 Analyze_And_Resolve
(Expr
, Any_Boolean
);
12398 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
12401 Ghost_Mode
:= Save_Ghost_Mode
;
12404 --------------------------
12405 -- Check_Float_Overflow --
12406 --------------------------
12408 -- pragma Check_Float_Overflow;
12410 when Pragma_Check_Float_Overflow
=>
12412 Check_Valid_Configuration_Pragma
;
12413 Check_Arg_Count
(0);
12414 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
12420 -- pragma Check_Name (check_IDENTIFIER);
12422 when Pragma_Check_Name
=>
12424 Check_No_Identifiers
;
12425 Check_Valid_Configuration_Pragma
;
12426 Check_Arg_Count
(1);
12427 Check_Arg_Is_Identifier
(Arg1
);
12430 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
12433 for J
in Check_Names
.First
.. Check_Names
.Last
loop
12434 if Check_Names
.Table
(J
) = Nam
then
12439 Check_Names
.Append
(Nam
);
12446 -- This is the old style syntax, which is still allowed in all modes:
12448 -- pragma Check_Policy ([Name =>] CHECK_KIND
12449 -- [Policy =>] POLICY_IDENTIFIER);
12451 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12453 -- CHECK_KIND ::= IDENTIFIER |
12456 -- Type_Invariant'Class |
12459 -- This is the new style syntax, compatible with Assertion_Policy
12460 -- and also allowed in all modes.
12462 -- Pragma Check_Policy (
12463 -- CHECK_KIND => POLICY_IDENTIFIER
12464 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12466 -- Note: the identifiers Name and Policy are not allowed as
12467 -- Check_Kind values. This avoids ambiguities between the old and
12468 -- new form syntax.
12470 when Pragma_Check_Policy
=> Check_Policy
: declare
12475 Check_At_Least_N_Arguments
(1);
12477 -- A Check_Policy pragma can appear either as a configuration
12478 -- pragma, or in a declarative part or a package spec (see RM
12479 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12480 -- followed for Check_Policy).
12482 if not Is_Configuration_Pragma
then
12483 Check_Is_In_Decl_Part_Or_Package_Spec
;
12486 -- Figure out if we have the old or new syntax. We have the
12487 -- old syntax if the first argument has no identifier, or the
12488 -- identifier is Name.
12490 if Nkind
(Arg1
) /= N_Pragma_Argument_Association
12491 or else Nam_In
(Chars
(Arg1
), No_Name
, Name_Name
)
12495 Check_Arg_Count
(2);
12496 Check_Optional_Identifier
(Arg1
, Name_Name
);
12497 Kind
:= Get_Pragma_Arg
(Arg1
);
12498 Rewrite_Assertion_Kind
(Kind
);
12499 Check_Arg_Is_Identifier
(Arg1
);
12501 -- Check forbidden check kind
12503 if Nam_In
(Chars
(Kind
), Name_Name
, Name_Policy
) then
12504 Error_Msg_Name_2
:= Chars
(Kind
);
12506 ("pragma% does not allow% as check name", Arg1
);
12511 Check_Optional_Identifier
(Arg2
, Name_Policy
);
12512 Check_Arg_Is_One_Of
12514 Name_On
, Name_Off
, Name_Check
, Name_Disable
, Name_Ignore
);
12516 -- And chain pragma on the Check_Policy_List for search
12518 Set_Next_Pragma
(N
, Opt
.Check_Policy_List
);
12519 Opt
.Check_Policy_List
:= N
;
12521 -- For the new syntax, what we do is to convert each argument to
12522 -- an old syntax equivalent. We do that because we want to chain
12523 -- old style Check_Policy pragmas for the search (we don't want
12524 -- to have to deal with multiple arguments in the search).
12535 while Present
(Arg
) loop
12536 LocP
:= Sloc
(Arg
);
12537 Argx
:= Get_Pragma_Arg
(Arg
);
12539 -- Kind must be specified
12541 if Nkind
(Arg
) /= N_Pragma_Argument_Association
12542 or else Chars
(Arg
) = No_Name
12545 ("missing assertion kind for pragma%", Arg
);
12548 -- Construct equivalent old form syntax Check_Policy
12549 -- pragma and insert it to get remaining checks.
12553 Chars
=> Name_Check_Policy
,
12554 Pragma_Argument_Associations
=> New_List
(
12555 Make_Pragma_Argument_Association
(LocP
,
12557 Make_Identifier
(LocP
, Chars
(Arg
))),
12558 Make_Pragma_Argument_Association
(Sloc
(Argx
),
12559 Expression
=> Argx
)));
12563 -- For a configuration pragma, insert old form in
12564 -- the corresponding file.
12566 if Is_Configuration_Pragma
then
12567 Insert_After
(N
, New_P
);
12571 Insert_Action
(N
, New_P
);
12575 -- Rewrite original Check_Policy pragma to null, since we
12576 -- have converted it into a series of old syntax pragmas.
12578 Rewrite
(N
, Make_Null_Statement
(Loc
));
12588 -- pragma Comment (static_string_EXPRESSION)
12590 -- Processing for pragma Comment shares the circuitry for pragma
12591 -- Ident. The only differences are that Ident enforces a limit of 31
12592 -- characters on its argument, and also enforces limitations on
12593 -- placement for DEC compatibility. Pragma Comment shares neither of
12594 -- these restrictions.
12596 -------------------
12597 -- Common_Object --
12598 -------------------
12600 -- pragma Common_Object (
12601 -- [Internal =>] LOCAL_NAME
12602 -- [, [External =>] EXTERNAL_SYMBOL]
12603 -- [, [Size =>] EXTERNAL_SYMBOL]);
12605 -- Processing for this pragma is shared with Psect_Object
12607 ------------------------
12608 -- Compile_Time_Error --
12609 ------------------------
12611 -- pragma Compile_Time_Error
12612 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12614 when Pragma_Compile_Time_Error
=>
12616 Process_Compile_Time_Warning_Or_Error
;
12618 --------------------------
12619 -- Compile_Time_Warning --
12620 --------------------------
12622 -- pragma Compile_Time_Warning
12623 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12625 when Pragma_Compile_Time_Warning
=>
12627 Process_Compile_Time_Warning_Or_Error
;
12629 ---------------------------
12630 -- Compiler_Unit_Warning --
12631 ---------------------------
12633 -- pragma Compiler_Unit_Warning;
12637 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12638 -- errors not warnings. This means that we had introduced a big extra
12639 -- inertia to compiler changes, since even if we implemented a new
12640 -- feature, and even if all versions to be used for bootstrapping
12641 -- implemented this new feature, we could not use it, since old
12642 -- compilers would give errors for using this feature in units
12643 -- having Compiler_Unit pragmas.
12645 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12646 -- problem. We no longer have any units mentioning Compiler_Unit,
12647 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12648 -- and thus generates a warning which can be ignored. So that deals
12649 -- with the problem of old compilers not implementing the newer form
12652 -- Newer compilers recognize the new pragma, but generate warning
12653 -- messages instead of errors, which again can be ignored in the
12654 -- case of an old compiler which implements a wanted new feature
12655 -- but at the time felt like warning about it for older compilers.
12657 -- We retain Compiler_Unit so that new compilers can be used to build
12658 -- older run-times that use this pragma. That's an unusual case, but
12659 -- it's easy enough to handle, so why not?
12661 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning
=>
12663 Check_Arg_Count
(0);
12665 -- Only recognized in main unit
12667 if Current_Sem_Unit
= Main_Unit
then
12668 Compiler_Unit
:= True;
12671 -----------------------------
12672 -- Complete_Representation --
12673 -----------------------------
12675 -- pragma Complete_Representation;
12677 when Pragma_Complete_Representation
=>
12679 Check_Arg_Count
(0);
12681 if Nkind
(Parent
(N
)) /= N_Record_Representation_Clause
then
12683 ("pragma & must appear within record representation clause");
12686 ----------------------------
12687 -- Complex_Representation --
12688 ----------------------------
12690 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12692 when Pragma_Complex_Representation
=> Complex_Representation
: declare
12699 Check_Arg_Count
(1);
12700 Check_Optional_Identifier
(Arg1
, Name_Entity
);
12701 Check_Arg_Is_Local_Name
(Arg1
);
12702 E_Id
:= Get_Pragma_Arg
(Arg1
);
12704 if Etype
(E_Id
) = Any_Type
then
12708 E
:= Entity
(E_Id
);
12710 if not Is_Record_Type
(E
) then
12712 ("argument for pragma% must be record type", Arg1
);
12715 Ent
:= First_Entity
(E
);
12718 or else No
(Next_Entity
(Ent
))
12719 or else Present
(Next_Entity
(Next_Entity
(Ent
)))
12720 or else not Is_Floating_Point_Type
(Etype
(Ent
))
12721 or else Etype
(Ent
) /= Etype
(Next_Entity
(Ent
))
12724 ("record for pragma% must have two fields of the same "
12725 & "floating-point type", Arg1
);
12728 Set_Has_Complex_Representation
(Base_Type
(E
));
12730 -- We need to treat the type has having a non-standard
12731 -- representation, for back-end purposes, even though in
12732 -- general a complex will have the default representation
12733 -- of a record with two real components.
12735 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
12737 end Complex_Representation
;
12739 -------------------------
12740 -- Component_Alignment --
12741 -------------------------
12743 -- pragma Component_Alignment (
12744 -- [Form =>] ALIGNMENT_CHOICE
12745 -- [, [Name =>] type_LOCAL_NAME]);
12747 -- ALIGNMENT_CHOICE ::=
12749 -- | Component_Size_4
12753 when Pragma_Component_Alignment
=> Component_AlignmentP
: declare
12754 Args
: Args_List
(1 .. 2);
12755 Names
: constant Name_List
(1 .. 2) := (
12759 Form
: Node_Id
renames Args
(1);
12760 Name
: Node_Id
renames Args
(2);
12762 Atype
: Component_Alignment_Kind
;
12767 Gather_Associations
(Names
, Args
);
12770 Error_Pragma
("missing Form argument for pragma%");
12773 Check_Arg_Is_Identifier
(Form
);
12775 -- Get proper alignment, note that Default = Component_Size on all
12776 -- machines we have so far, and we want to set this value rather
12777 -- than the default value to indicate that it has been explicitly
12778 -- set (and thus will not get overridden by the default component
12779 -- alignment for the current scope)
12781 if Chars
(Form
) = Name_Component_Size
then
12782 Atype
:= Calign_Component_Size
;
12784 elsif Chars
(Form
) = Name_Component_Size_4
then
12785 Atype
:= Calign_Component_Size_4
;
12787 elsif Chars
(Form
) = Name_Default
then
12788 Atype
:= Calign_Component_Size
;
12790 elsif Chars
(Form
) = Name_Storage_Unit
then
12791 Atype
:= Calign_Storage_Unit
;
12795 ("invalid Form parameter for pragma%", Form
);
12798 -- Case with no name, supplied, affects scope table entry
12802 (Scope_Stack
.Last
).Component_Alignment_Default
:= Atype
;
12804 -- Case of name supplied
12807 Check_Arg_Is_Local_Name
(Name
);
12809 Typ
:= Entity
(Name
);
12812 or else Rep_Item_Too_Early
(Typ
, N
)
12816 Typ
:= Underlying_Type
(Typ
);
12819 if not Is_Record_Type
(Typ
)
12820 and then not Is_Array_Type
(Typ
)
12823 ("Name parameter of pragma% must identify record or "
12824 & "array type", Name
);
12827 -- An explicit Component_Alignment pragma overrides an
12828 -- implicit pragma Pack, but not an explicit one.
12830 if not Has_Pragma_Pack
(Base_Type
(Typ
)) then
12831 Set_Is_Packed
(Base_Type
(Typ
), False);
12832 Set_Component_Alignment
(Base_Type
(Typ
), Atype
);
12835 end Component_AlignmentP
;
12837 --------------------------------
12838 -- Constant_After_Elaboration --
12839 --------------------------------
12841 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
12843 when Pragma_Constant_After_Elaboration
=> Constant_After_Elaboration
:
12845 Obj_Decl
: Node_Id
;
12846 Obj_Id
: Entity_Id
;
12850 Check_No_Identifiers
;
12851 Check_At_Most_N_Arguments
(1);
12853 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
12855 -- Object declaration
12857 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
12860 -- Otherwise the pragma is associated with an illegal construct
12867 Obj_Id
:= Defining_Entity
(Obj_Decl
);
12869 -- The object declaration must be a library-level variable which
12870 -- is either explicitly initialized or obtains a value during the
12871 -- elaboration of a package body (SPARK RM 3.3.1).
12873 if Ekind
(Obj_Id
) = E_Variable
then
12874 if not Is_Library_Level_Entity
(Obj_Id
) then
12876 ("pragma % must apply to a library level variable");
12880 -- Otherwise the pragma applies to a constant, which is illegal
12883 Error_Pragma
("pragma % must apply to a variable declaration");
12887 -- Chain the pragma on the contract for completeness
12889 Add_Contract_Item
(N
, Obj_Id
);
12891 -- A pragma that applies to a Ghost entity becomes Ghost for the
12892 -- purposes of legality checks and removal of ignored Ghost code.
12894 Mark_Pragma_As_Ghost
(N
, Obj_Id
);
12896 -- Analyze the Boolean expression (if any)
12898 if Present
(Arg1
) then
12899 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
12901 end Constant_After_Elaboration
;
12903 --------------------
12904 -- Contract_Cases --
12905 --------------------
12907 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12909 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12911 -- CASE_GUARD ::= boolean_EXPRESSION | others
12913 -- CONSEQUENCE ::= boolean_EXPRESSION
12915 -- Characteristics:
12917 -- * Analysis - The annotation undergoes initial checks to verify
12918 -- the legal placement and context. Secondary checks preanalyze the
12921 -- Analyze_Contract_Cases_In_Decl_Part
12923 -- * Expansion - The annotation is expanded during the expansion of
12924 -- the related subprogram [body] contract as performed in:
12926 -- Expand_Subprogram_Contract
12928 -- * Template - The annotation utilizes the generic template of the
12929 -- related subprogram [body] when it is:
12931 -- aspect on subprogram declaration
12932 -- aspect on stand alone subprogram body
12933 -- pragma on stand alone subprogram body
12935 -- The annotation must prepare its own template when it is:
12937 -- pragma on subprogram declaration
12939 -- * Globals - Capture of global references must occur after full
12942 -- * Instance - The annotation is instantiated automatically when
12943 -- the related generic subprogram [body] is instantiated except for
12944 -- the "pragma on subprogram declaration" case. In that scenario
12945 -- the annotation must instantiate itself.
12947 when Pragma_Contract_Cases
=> Contract_Cases
: declare
12948 Spec_Id
: Entity_Id
;
12949 Subp_Decl
: Node_Id
;
12953 Check_No_Identifiers
;
12954 Check_Arg_Count
(1);
12956 -- Ensure the proper placement of the pragma. Contract_Cases must
12957 -- be associated with a subprogram declaration or a body that acts
12961 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
12965 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
12968 -- Generic subprogram
12970 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
12973 -- Body acts as spec
12975 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
12976 and then No
(Corresponding_Spec
(Subp_Decl
))
12980 -- Body stub acts as spec
12982 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
12983 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
12989 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
12997 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
12999 -- Chain the pragma on the contract for further processing by
13000 -- Analyze_Contract_Cases_In_Decl_Part.
13002 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
13004 -- A pragma that applies to a Ghost entity becomes Ghost for the
13005 -- purposes of legality checks and removal of ignored Ghost code.
13007 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
13008 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
13010 -- Fully analyze the pragma when it appears inside an entry
13011 -- or subprogram body because it cannot benefit from forward
13014 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
13016 N_Subprogram_Body_Stub
)
13018 -- The legality checks of pragma Contract_Cases are affected by
13019 -- the SPARK mode in effect and the volatility of the context.
13020 -- Analyze all pragmas in a specific order.
13022 Analyze_If_Present
(Pragma_SPARK_Mode
);
13023 Analyze_If_Present
(Pragma_Volatile_Function
);
13024 Analyze_Contract_Cases_In_Decl_Part
(N
);
13026 end Contract_Cases
;
13032 -- pragma Controlled (first_subtype_LOCAL_NAME);
13034 when Pragma_Controlled
=> Controlled
: declare
13038 Check_No_Identifiers
;
13039 Check_Arg_Count
(1);
13040 Check_Arg_Is_Local_Name
(Arg1
);
13041 Arg
:= Get_Pragma_Arg
(Arg1
);
13043 if not Is_Entity_Name
(Arg
)
13044 or else not Is_Access_Type
(Entity
(Arg
))
13046 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
13048 Set_Has_Pragma_Controlled
(Base_Type
(Entity
(Arg
)));
13056 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
13057 -- [Entity =>] LOCAL_NAME);
13059 when Pragma_Convention
=> Convention
: declare
13062 pragma Warnings
(Off
, C
);
13063 pragma Warnings
(Off
, E
);
13065 Check_Arg_Order
((Name_Convention
, Name_Entity
));
13066 Check_Ada_83_Warning
;
13067 Check_Arg_Count
(2);
13068 Process_Convention
(C
, E
);
13070 -- A pragma that applies to a Ghost entity becomes Ghost for the
13071 -- purposes of legality checks and removal of ignored Ghost code.
13073 Mark_Pragma_As_Ghost
(N
, E
);
13076 ---------------------------
13077 -- Convention_Identifier --
13078 ---------------------------
13080 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
13081 -- [Convention =>] convention_IDENTIFIER);
13083 when Pragma_Convention_Identifier
=> Convention_Identifier
: declare
13089 Check_Arg_Order
((Name_Name
, Name_Convention
));
13090 Check_Arg_Count
(2);
13091 Check_Optional_Identifier
(Arg1
, Name_Name
);
13092 Check_Optional_Identifier
(Arg2
, Name_Convention
);
13093 Check_Arg_Is_Identifier
(Arg1
);
13094 Check_Arg_Is_Identifier
(Arg2
);
13095 Idnam
:= Chars
(Get_Pragma_Arg
(Arg1
));
13096 Cname
:= Chars
(Get_Pragma_Arg
(Arg2
));
13098 if Is_Convention_Name
(Cname
) then
13099 Record_Convention_Identifier
13100 (Idnam
, Get_Convention_Id
(Cname
));
13103 ("second arg for % pragma must be convention", Arg2
);
13105 end Convention_Identifier
;
13111 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
13113 when Pragma_CPP_Class
=> CPP_Class
: declare
13117 if Warn_On_Obsolescent_Feature
then
13119 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
13120 & "effect; replace it by pragma import?j?", N
);
13123 Check_Arg_Count
(1);
13127 Chars
=> Name_Import
,
13128 Pragma_Argument_Associations
=> New_List
(
13129 Make_Pragma_Argument_Association
(Loc
,
13130 Expression
=> Make_Identifier
(Loc
, Name_CPP
)),
13131 New_Copy
(First
(Pragma_Argument_Associations
(N
))))));
13135 ---------------------
13136 -- CPP_Constructor --
13137 ---------------------
13139 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
13140 -- [, [External_Name =>] static_string_EXPRESSION ]
13141 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13143 when Pragma_CPP_Constructor
=> CPP_Constructor
: declare
13146 Def_Id
: Entity_Id
;
13147 Tag_Typ
: Entity_Id
;
13151 Check_At_Least_N_Arguments
(1);
13152 Check_At_Most_N_Arguments
(3);
13153 Check_Optional_Identifier
(Arg1
, Name_Entity
);
13154 Check_Arg_Is_Local_Name
(Arg1
);
13156 Id
:= Get_Pragma_Arg
(Arg1
);
13157 Find_Program_Unit_Name
(Id
);
13159 -- If we did not find the name, we are done
13161 if Etype
(Id
) = Any_Type
then
13165 Def_Id
:= Entity
(Id
);
13167 -- Check if already defined as constructor
13169 if Is_Constructor
(Def_Id
) then
13171 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1
);
13175 if Ekind
(Def_Id
) = E_Function
13176 and then (Is_CPP_Class
(Etype
(Def_Id
))
13177 or else (Is_Class_Wide_Type
(Etype
(Def_Id
))
13179 Is_CPP_Class
(Root_Type
(Etype
(Def_Id
)))))
13181 if Scope
(Def_Id
) /= Scope
(Etype
(Def_Id
)) then
13183 ("'C'P'P constructor must be defined in the scope of "
13184 & "its returned type", Arg1
);
13187 if Arg_Count
>= 2 then
13188 Set_Imported
(Def_Id
);
13189 Set_Is_Public
(Def_Id
);
13190 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
13193 Set_Has_Completion
(Def_Id
);
13194 Set_Is_Constructor
(Def_Id
);
13195 Set_Convention
(Def_Id
, Convention_CPP
);
13197 -- Imported C++ constructors are not dispatching primitives
13198 -- because in C++ they don't have a dispatch table slot.
13199 -- However, in Ada the constructor has the profile of a
13200 -- function that returns a tagged type and therefore it has
13201 -- been treated as a primitive operation during semantic
13202 -- analysis. We now remove it from the list of primitive
13203 -- operations of the type.
13205 if Is_Tagged_Type
(Etype
(Def_Id
))
13206 and then not Is_Class_Wide_Type
(Etype
(Def_Id
))
13207 and then Is_Dispatching_Operation
(Def_Id
)
13209 Tag_Typ
:= Etype
(Def_Id
);
13211 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
13212 while Present
(Elmt
) and then Node
(Elmt
) /= Def_Id
loop
13216 Remove_Elmt
(Primitive_Operations
(Tag_Typ
), Elmt
);
13217 Set_Is_Dispatching_Operation
(Def_Id
, False);
13220 -- For backward compatibility, if the constructor returns a
13221 -- class wide type, and we internally change the return type to
13222 -- the corresponding root type.
13224 if Is_Class_Wide_Type
(Etype
(Def_Id
)) then
13225 Set_Etype
(Def_Id
, Root_Type
(Etype
(Def_Id
)));
13229 ("pragma% requires function returning a 'C'P'P_Class type",
13232 end CPP_Constructor
;
13238 when Pragma_CPP_Virtual
=> CPP_Virtual
: declare
13242 if Warn_On_Obsolescent_Feature
then
13244 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
13253 when Pragma_CPP_Vtable
=> CPP_Vtable
: declare
13257 if Warn_On_Obsolescent_Feature
then
13259 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
13268 -- pragma CPU (EXPRESSION);
13270 when Pragma_CPU
=> CPU
: declare
13271 P
: constant Node_Id
:= Parent
(N
);
13277 Check_No_Identifiers
;
13278 Check_Arg_Count
(1);
13282 if Nkind
(P
) = N_Subprogram_Body
then
13283 Check_In_Main_Program
;
13285 Arg
:= Get_Pragma_Arg
(Arg1
);
13286 Analyze_And_Resolve
(Arg
, Any_Integer
);
13288 Ent
:= Defining_Unit_Name
(Specification
(P
));
13290 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
13291 Ent
:= Defining_Identifier
(Ent
);
13296 if not Is_OK_Static_Expression
(Arg
) then
13297 Flag_Non_Static_Expr
13298 ("main subprogram affinity is not static!", Arg
);
13301 -- If constraint error, then we already signalled an error
13303 elsif Raises_Constraint_Error
(Arg
) then
13306 -- Otherwise check in range
13310 CPU_Id
: constant Entity_Id
:= RTE
(RE_CPU_Range
);
13311 -- This is the entity System.Multiprocessors.CPU_Range;
13313 Val
: constant Uint
:= Expr_Value
(Arg
);
13316 if Val
< Expr_Value
(Type_Low_Bound
(CPU_Id
))
13318 Val
> Expr_Value
(Type_High_Bound
(CPU_Id
))
13321 ("main subprogram CPU is out of range", Arg1
);
13327 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
13331 elsif Nkind
(P
) = N_Task_Definition
then
13332 Arg
:= Get_Pragma_Arg
(Arg1
);
13333 Ent
:= Defining_Identifier
(Parent
(P
));
13335 -- The expression must be analyzed in the special manner
13336 -- described in "Handling of Default and Per-Object
13337 -- Expressions" in sem.ads.
13339 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_CPU_Range
));
13341 -- Anything else is incorrect
13347 -- Check duplicate pragma before we chain the pragma in the Rep
13348 -- Item chain of Ent.
13350 Check_Duplicate_Pragma
(Ent
);
13351 Record_Rep_Item
(Ent
, N
);
13358 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
13360 when Pragma_Debug
=> Debug
: declare
13367 -- The condition for executing the call is that the expander
13368 -- is active and that we are not ignoring this debug pragma.
13373 (Expander_Active
and then not Is_Ignored
(N
)),
13376 if not Is_Ignored
(N
) then
13377 Set_SCO_Pragma_Enabled
(Loc
);
13380 if Arg_Count
= 2 then
13382 Make_And_Then
(Loc
,
13383 Left_Opnd
=> Relocate_Node
(Cond
),
13384 Right_Opnd
=> Get_Pragma_Arg
(Arg1
));
13385 Call
:= Get_Pragma_Arg
(Arg2
);
13387 Call
:= Get_Pragma_Arg
(Arg1
);
13391 N_Indexed_Component
,
13395 N_Selected_Component
)
13397 -- If this pragma Debug comes from source, its argument was
13398 -- parsed as a name form (which is syntactically identical).
13399 -- In a generic context a parameterless call will be left as
13400 -- an expanded name (if global) or selected_component if local.
13401 -- Change it to a procedure call statement now.
13403 Change_Name_To_Procedure_Call_Statement
(Call
);
13405 elsif Nkind
(Call
) = N_Procedure_Call_Statement
then
13407 -- Already in the form of a procedure call statement: nothing
13408 -- to do (could happen in case of an internally generated
13414 -- All other cases: diagnose error
13417 ("argument of pragma ""Debug"" is not procedure call",
13422 -- Rewrite into a conditional with an appropriate condition. We
13423 -- wrap the procedure call in a block so that overhead from e.g.
13424 -- use of the secondary stack does not generate execution overhead
13425 -- for suppressed conditions.
13427 -- Normally the analysis that follows will freeze the subprogram
13428 -- being called. However, if the call is to a null procedure,
13429 -- we want to freeze it before creating the block, because the
13430 -- analysis that follows may be done with expansion disabled, in
13431 -- which case the body will not be generated, leading to spurious
13434 if Nkind
(Call
) = N_Procedure_Call_Statement
13435 and then Is_Entity_Name
(Name
(Call
))
13437 Analyze
(Name
(Call
));
13438 Freeze_Before
(N
, Entity
(Name
(Call
)));
13442 Make_Implicit_If_Statement
(N
,
13444 Then_Statements
=> New_List
(
13445 Make_Block_Statement
(Loc
,
13446 Handled_Statement_Sequence
=>
13447 Make_Handled_Sequence_Of_Statements
(Loc
,
13448 Statements
=> New_List
(Relocate_Node
(Call
)))))));
13451 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13452 -- after analysis of the normally rewritten node, to capture all
13453 -- references to entities, which avoids issuing wrong warnings
13454 -- about unused entities.
13456 if GNATprove_Mode
then
13457 Rewrite
(N
, Make_Null_Statement
(Loc
));
13465 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13467 when Pragma_Debug_Policy
=>
13469 Check_Arg_Count
(1);
13470 Check_No_Identifiers
;
13471 Check_Arg_Is_Identifier
(Arg1
);
13473 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
13474 -- rewrite it that way, and let the rest of the checking come
13475 -- from analyzing the rewritten pragma.
13479 Chars
=> Name_Check_Policy
,
13480 Pragma_Argument_Associations
=> New_List
(
13481 Make_Pragma_Argument_Association
(Loc
,
13482 Expression
=> Make_Identifier
(Loc
, Name_Debug
)),
13484 Make_Pragma_Argument_Association
(Loc
,
13485 Expression
=> Get_Pragma_Arg
(Arg1
)))));
13488 -------------------------------
13489 -- Default_Initial_Condition --
13490 -------------------------------
13492 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
13494 when Pragma_Default_Initial_Condition
=> Default_Init_Cond
: declare
13501 Check_No_Identifiers
;
13502 Check_At_Most_N_Arguments
(1);
13505 while Present
(Stmt
) loop
13507 -- Skip prior pragmas, but check for duplicates
13509 if Nkind
(Stmt
) = N_Pragma
then
13510 if Pragma_Name
(Stmt
) = Pname
then
13511 Error_Msg_Name_1
:= Pname
;
13512 Error_Msg_Sloc
:= Sloc
(Stmt
);
13513 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
13516 -- Skip internally generated code
13518 elsif not Comes_From_Source
(Stmt
) then
13521 -- The associated private type [extension] has been found, stop
13524 elsif Nkind_In
(Stmt
, N_Private_Extension_Declaration
,
13525 N_Private_Type_Declaration
)
13527 Typ
:= Defining_Entity
(Stmt
);
13530 -- The pragma does not apply to a legal construct, issue an
13531 -- error and stop the analysis.
13538 Stmt
:= Prev
(Stmt
);
13541 -- A pragma that applies to a Ghost entity becomes Ghost for the
13542 -- purposes of legality checks and removal of ignored Ghost code.
13544 Mark_Pragma_As_Ghost
(N
, Typ
);
13545 Set_Has_Default_Init_Cond
(Typ
);
13546 Set_Has_Inherited_Default_Init_Cond
(Typ
, False);
13548 -- Chain the pragma on the rep item chain for further processing
13550 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
13551 end Default_Init_Cond
;
13553 ----------------------------------
13554 -- Default_Scalar_Storage_Order --
13555 ----------------------------------
13557 -- pragma Default_Scalar_Storage_Order
13558 -- (High_Order_First | Low_Order_First);
13560 when Pragma_Default_Scalar_Storage_Order
=> DSSO
: declare
13561 Default
: Character;
13565 Check_Arg_Count
(1);
13567 -- Default_Scalar_Storage_Order can appear as a configuration
13568 -- pragma, or in a declarative part of a package spec.
13570 if not Is_Configuration_Pragma
then
13571 Check_Is_In_Decl_Part_Or_Package_Spec
;
13574 Check_No_Identifiers
;
13575 Check_Arg_Is_One_Of
13576 (Arg1
, Name_High_Order_First
, Name_Low_Order_First
);
13577 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
13578 Default
:= Fold_Upper
(Name_Buffer
(1));
13580 if not Support_Nondefault_SSO_On_Target
13581 and then (Ttypes
.Bytes_Big_Endian
/= (Default
= 'H'))
13583 if Warn_On_Unrecognized_Pragma
then
13585 ("non-default Scalar_Storage_Order not supported "
13586 & "on target?g?", N
);
13588 ("\pragma Default_Scalar_Storage_Order ignored?g?", N
);
13591 -- Here set the specified default
13594 Opt
.Default_SSO
:= Default
;
13598 --------------------------
13599 -- Default_Storage_Pool --
13600 --------------------------
13602 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
13604 when Pragma_Default_Storage_Pool
=> Default_Storage_Pool
: declare
13609 Check_Arg_Count
(1);
13611 -- Default_Storage_Pool can appear as a configuration pragma, or
13612 -- in a declarative part of a package spec.
13614 if not Is_Configuration_Pragma
then
13615 Check_Is_In_Decl_Part_Or_Package_Spec
;
13618 if From_Aspect_Specification
(N
) then
13620 E
: constant Entity_Id
:= Entity
(Corresponding_Aspect
(N
));
13622 if not In_Open_Scopes
(E
) then
13624 ("aspect must apply to package or subprogram", N
);
13629 if Present
(Arg1
) then
13630 Pool
:= Get_Pragma_Arg
(Arg1
);
13632 -- Case of Default_Storage_Pool (null);
13634 if Nkind
(Pool
) = N_Null
then
13637 -- This is an odd case, this is not really an expression,
13638 -- so we don't have a type for it. So just set the type to
13641 Set_Etype
(Pool
, Empty
);
13643 -- Case of Default_Storage_Pool (storage_pool_NAME);
13646 -- If it's a configuration pragma, then the only allowed
13647 -- argument is "null".
13649 if Is_Configuration_Pragma
then
13650 Error_Pragma_Arg
("NULL expected", Arg1
);
13653 -- The expected type for a non-"null" argument is
13654 -- Root_Storage_Pool'Class, and the pool must be a variable.
13656 Analyze_And_Resolve
13657 (Pool
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
13659 if Is_Variable
(Pool
) then
13661 -- A pragma that applies to a Ghost entity becomes Ghost
13662 -- for the purposes of legality checks and removal of
13663 -- ignored Ghost code.
13665 Mark_Pragma_As_Ghost
(N
, Entity
(Pool
));
13669 ("default storage pool must be a variable", Arg1
);
13673 -- Record the pool name (or null). Freeze.Freeze_Entity for an
13674 -- access type will use this information to set the appropriate
13675 -- attributes of the access type.
13677 Default_Pool
:= Pool
;
13679 end Default_Storage_Pool
;
13685 -- pragma Depends (DEPENDENCY_RELATION);
13687 -- DEPENDENCY_RELATION ::=
13689 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
13691 -- DEPENDENCY_CLAUSE ::=
13692 -- OUTPUT_LIST =>[+] INPUT_LIST
13693 -- | NULL_DEPENDENCY_CLAUSE
13695 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13697 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13699 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13701 -- OUTPUT ::= NAME | FUNCTION_RESULT
13704 -- where FUNCTION_RESULT is a function Result attribute_reference
13706 -- Characteristics:
13708 -- * Analysis - The annotation undergoes initial checks to verify
13709 -- the legal placement and context. Secondary checks fully analyze
13710 -- the dependency clauses in:
13712 -- Analyze_Depends_In_Decl_Part
13714 -- * Expansion - None.
13716 -- * Template - The annotation utilizes the generic template of the
13717 -- related subprogram [body] when it is:
13719 -- aspect on subprogram declaration
13720 -- aspect on stand alone subprogram body
13721 -- pragma on stand alone subprogram body
13723 -- The annotation must prepare its own template when it is:
13725 -- pragma on subprogram declaration
13727 -- * Globals - Capture of global references must occur after full
13730 -- * Instance - The annotation is instantiated automatically when
13731 -- the related generic subprogram [body] is instantiated except for
13732 -- the "pragma on subprogram declaration" case. In that scenario
13733 -- the annotation must instantiate itself.
13735 when Pragma_Depends
=> Depends
: declare
13737 Spec_Id
: Entity_Id
;
13738 Subp_Decl
: Node_Id
;
13741 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
13745 -- Chain the pragma on the contract for further processing by
13746 -- Analyze_Depends_In_Decl_Part.
13748 Add_Contract_Item
(N
, Spec_Id
);
13750 -- Fully analyze the pragma when it appears inside an entry
13751 -- or subprogram body because it cannot benefit from forward
13754 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
13756 N_Subprogram_Body_Stub
)
13758 -- The legality checks of pragmas Depends and Global are
13759 -- affected by the SPARK mode in effect and the volatility
13760 -- of the context. In addition these two pragmas are subject
13761 -- to an inherent order:
13766 -- Analyze all these pragmas in the order outlined above
13768 Analyze_If_Present
(Pragma_SPARK_Mode
);
13769 Analyze_If_Present
(Pragma_Volatile_Function
);
13770 Analyze_If_Present
(Pragma_Global
);
13771 Analyze_Depends_In_Decl_Part
(N
);
13776 ---------------------
13777 -- Detect_Blocking --
13778 ---------------------
13780 -- pragma Detect_Blocking;
13782 when Pragma_Detect_Blocking
=>
13784 Check_Arg_Count
(0);
13785 Check_Valid_Configuration_Pragma
;
13786 Detect_Blocking
:= True;
13788 ------------------------------------
13789 -- Disable_Atomic_Synchronization --
13790 ------------------------------------
13792 -- pragma Disable_Atomic_Synchronization [(Entity)];
13794 when Pragma_Disable_Atomic_Synchronization
=>
13796 Process_Disable_Enable_Atomic_Sync
(Name_Suppress
);
13798 -------------------
13799 -- Discard_Names --
13800 -------------------
13802 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13804 when Pragma_Discard_Names
=> Discard_Names
: declare
13809 Check_Ada_83_Warning
;
13811 -- Deal with configuration pragma case
13813 if Arg_Count
= 0 and then Is_Configuration_Pragma
then
13814 Global_Discard_Names
:= True;
13817 -- Otherwise, check correct appropriate context
13820 Check_Is_In_Decl_Part_Or_Package_Spec
;
13822 if Arg_Count
= 0 then
13824 -- If there is no parameter, then from now on this pragma
13825 -- applies to any enumeration, exception or tagged type
13826 -- defined in the current declarative part, and recursively
13827 -- to any nested scope.
13829 Set_Discard_Names
(Current_Scope
);
13833 Check_Arg_Count
(1);
13834 Check_Optional_Identifier
(Arg1
, Name_On
);
13835 Check_Arg_Is_Local_Name
(Arg1
);
13837 E_Id
:= Get_Pragma_Arg
(Arg1
);
13839 if Etype
(E_Id
) = Any_Type
then
13842 E
:= Entity
(E_Id
);
13845 -- A pragma that applies to a Ghost entity becomes Ghost for
13846 -- the purposes of legality checks and removal of ignored
13849 Mark_Pragma_As_Ghost
(N
, E
);
13851 if (Is_First_Subtype
(E
)
13853 (Is_Enumeration_Type
(E
) or else Is_Tagged_Type
(E
)))
13854 or else Ekind
(E
) = E_Exception
13856 Set_Discard_Names
(E
);
13857 Record_Rep_Item
(E
, N
);
13861 ("inappropriate entity for pragma%", Arg1
);
13867 ------------------------
13868 -- Dispatching_Domain --
13869 ------------------------
13871 -- pragma Dispatching_Domain (EXPRESSION);
13873 when Pragma_Dispatching_Domain
=> Dispatching_Domain
: declare
13874 P
: constant Node_Id
:= Parent
(N
);
13880 Check_No_Identifiers
;
13881 Check_Arg_Count
(1);
13883 -- This pragma is born obsolete, but not the aspect
13885 if not From_Aspect_Specification
(N
) then
13887 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
13890 if Nkind
(P
) = N_Task_Definition
then
13891 Arg
:= Get_Pragma_Arg
(Arg1
);
13892 Ent
:= Defining_Identifier
(Parent
(P
));
13894 -- A pragma that applies to a Ghost entity becomes Ghost for
13895 -- the purposes of legality checks and removal of ignored Ghost
13898 Mark_Pragma_As_Ghost
(N
, Ent
);
13900 -- The expression must be analyzed in the special manner
13901 -- described in "Handling of Default and Per-Object
13902 -- Expressions" in sem.ads.
13904 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Dispatching_Domain
));
13906 -- Check duplicate pragma before we chain the pragma in the Rep
13907 -- Item chain of Ent.
13909 Check_Duplicate_Pragma
(Ent
);
13910 Record_Rep_Item
(Ent
, N
);
13912 -- Anything else is incorrect
13917 end Dispatching_Domain
;
13923 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13925 when Pragma_Elaborate
=> Elaborate
: declare
13930 -- Pragma must be in context items list of a compilation unit
13932 if not Is_In_Context_Clause
then
13936 -- Must be at least one argument
13938 if Arg_Count
= 0 then
13939 Error_Pragma
("pragma% requires at least one argument");
13942 -- In Ada 83 mode, there can be no items following it in the
13943 -- context list except other pragmas and implicit with clauses
13944 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13945 -- placement rule does not apply.
13947 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
13949 while Present
(Citem
) loop
13950 if Nkind
(Citem
) = N_Pragma
13951 or else (Nkind
(Citem
) = N_With_Clause
13952 and then Implicit_With
(Citem
))
13957 ("(Ada 83) pragma% must be at end of context clause");
13964 -- Finally, the arguments must all be units mentioned in a with
13965 -- clause in the same context clause. Note we already checked (in
13966 -- Par.Prag) that the arguments are all identifiers or selected
13970 Outer
: while Present
(Arg
) loop
13971 Citem
:= First
(List_Containing
(N
));
13972 Inner
: while Citem
/= N
loop
13973 if Nkind
(Citem
) = N_With_Clause
13974 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
13976 Set_Elaborate_Present
(Citem
, True);
13977 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
13979 -- With the pragma present, elaboration calls on
13980 -- subprograms from the named unit need no further
13981 -- checks, as long as the pragma appears in the current
13982 -- compilation unit. If the pragma appears in some unit
13983 -- in the context, there might still be a need for an
13984 -- Elaborate_All_Desirable from the current compilation
13985 -- to the named unit, so we keep the check enabled.
13987 if In_Extended_Main_Source_Unit
(N
) then
13989 -- This does not apply in SPARK mode, where we allow
13990 -- pragma Elaborate, but we don't trust it to be right
13991 -- so we will still insist on the Elaborate_All.
13993 if SPARK_Mode
/= On
then
13994 Set_Suppress_Elaboration_Warnings
13995 (Entity
(Name
(Citem
)));
14007 ("argument of pragma% is not withed unit", Arg
);
14013 -- Give a warning if operating in static mode with one of the
14014 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
14017 and not Dynamic_Elaboration_Checks
14019 -- pragma Elaborate not allowed in SPARK mode anyway. We
14020 -- already complained about it, no point in generating any
14021 -- further complaint.
14023 and SPARK_Mode
/= On
14026 ("?l?use of pragma Elaborate may not be safe", N
);
14028 ("?l?use pragma Elaborate_All instead if possible", N
);
14032 -------------------
14033 -- Elaborate_All --
14034 -------------------
14036 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
14038 when Pragma_Elaborate_All
=> Elaborate_All
: declare
14043 Check_Ada_83_Warning
;
14045 -- Pragma must be in context items list of a compilation unit
14047 if not Is_In_Context_Clause
then
14051 -- Must be at least one argument
14053 if Arg_Count
= 0 then
14054 Error_Pragma
("pragma% requires at least one argument");
14057 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
14058 -- have to appear at the end of the context clause, but may
14059 -- appear mixed in with other items, even in Ada 83 mode.
14061 -- Final check: the arguments must all be units mentioned in
14062 -- a with clause in the same context clause. Note that we
14063 -- already checked (in Par.Prag) that all the arguments are
14064 -- either identifiers or selected components.
14067 Outr
: while Present
(Arg
) loop
14068 Citem
:= First
(List_Containing
(N
));
14069 Innr
: while Citem
/= N
loop
14070 if Nkind
(Citem
) = N_With_Clause
14071 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
14073 Set_Elaborate_All_Present
(Citem
, True);
14074 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
14076 -- Suppress warnings and elaboration checks on the named
14077 -- unit if the pragma is in the current compilation, as
14078 -- for pragma Elaborate.
14080 if In_Extended_Main_Source_Unit
(N
) then
14081 Set_Suppress_Elaboration_Warnings
14082 (Entity
(Name
(Citem
)));
14091 Set_Error_Posted
(N
);
14093 ("argument of pragma% is not withed unit", Arg
);
14100 --------------------
14101 -- Elaborate_Body --
14102 --------------------
14104 -- pragma Elaborate_Body [( library_unit_NAME )];
14106 when Pragma_Elaborate_Body
=> Elaborate_Body
: declare
14107 Cunit_Node
: Node_Id
;
14108 Cunit_Ent
: Entity_Id
;
14111 Check_Ada_83_Warning
;
14112 Check_Valid_Library_Unit_Pragma
;
14114 if Nkind
(N
) = N_Null_Statement
then
14118 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
14119 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
14121 -- A pragma that applies to a Ghost entity becomes Ghost for the
14122 -- purposes of legality checks and removal of ignored Ghost code.
14124 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
14126 if Nkind_In
(Unit
(Cunit_Node
), N_Package_Body
,
14129 Error_Pragma
("pragma% must refer to a spec, not a body");
14131 Set_Body_Required
(Cunit_Node
, True);
14132 Set_Has_Pragma_Elaborate_Body
(Cunit_Ent
);
14134 -- If we are in dynamic elaboration mode, then we suppress
14135 -- elaboration warnings for the unit, since it is definitely
14136 -- fine NOT to do dynamic checks at the first level (and such
14137 -- checks will be suppressed because no elaboration boolean
14138 -- is created for Elaborate_Body packages).
14140 -- But in the static model of elaboration, Elaborate_Body is
14141 -- definitely NOT good enough to ensure elaboration safety on
14142 -- its own, since the body may WITH other units that are not
14143 -- safe from an elaboration point of view, so a client must
14144 -- still do an Elaborate_All on such units.
14146 -- Debug flag -gnatdD restores the old behavior of 3.13, where
14147 -- Elaborate_Body always suppressed elab warnings.
14149 if Dynamic_Elaboration_Checks
or Debug_Flag_DD
then
14150 Set_Suppress_Elaboration_Warnings
(Cunit_Ent
);
14153 end Elaborate_Body
;
14155 ------------------------
14156 -- Elaboration_Checks --
14157 ------------------------
14159 -- pragma Elaboration_Checks (Static | Dynamic);
14161 when Pragma_Elaboration_Checks
=>
14163 Check_Arg_Count
(1);
14164 Check_Arg_Is_One_Of
(Arg1
, Name_Static
, Name_Dynamic
);
14166 -- Set flag accordingly (ignore attempt at dynamic elaboration
14167 -- checks in SPARK mode).
14169 Dynamic_Elaboration_Checks
:=
14170 (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Dynamic
)
14171 and then SPARK_Mode
/= On
;
14177 -- pragma Eliminate (
14178 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
14179 -- [,[Entity =>] IDENTIFIER |
14180 -- SELECTED_COMPONENT |
14182 -- [, OVERLOADING_RESOLUTION]);
14184 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
14187 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
14188 -- FUNCTION_PROFILE
14190 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
14192 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
14193 -- Result_Type => result_SUBTYPE_NAME]
14195 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
14196 -- SUBTYPE_NAME ::= STRING_LITERAL
14198 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
14199 -- SOURCE_TRACE ::= STRING_LITERAL
14201 when Pragma_Eliminate
=> Eliminate
: declare
14202 Args
: Args_List
(1 .. 5);
14203 Names
: constant Name_List
(1 .. 5) := (
14206 Name_Parameter_Types
,
14208 Name_Source_Location
);
14210 Unit_Name
: Node_Id
renames Args
(1);
14211 Entity
: Node_Id
renames Args
(2);
14212 Parameter_Types
: Node_Id
renames Args
(3);
14213 Result_Type
: Node_Id
renames Args
(4);
14214 Source_Location
: Node_Id
renames Args
(5);
14218 Check_Valid_Configuration_Pragma
;
14219 Gather_Associations
(Names
, Args
);
14221 if No
(Unit_Name
) then
14222 Error_Pragma
("missing Unit_Name argument for pragma%");
14226 and then (Present
(Parameter_Types
)
14228 Present
(Result_Type
)
14230 Present
(Source_Location
))
14232 Error_Pragma
("missing Entity argument for pragma%");
14235 if (Present
(Parameter_Types
)
14237 Present
(Result_Type
))
14239 Present
(Source_Location
)
14242 ("parameter profile and source location cannot be used "
14243 & "together in pragma%");
14246 Process_Eliminate_Pragma
14255 -----------------------------------
14256 -- Enable_Atomic_Synchronization --
14257 -----------------------------------
14259 -- pragma Enable_Atomic_Synchronization [(Entity)];
14261 when Pragma_Enable_Atomic_Synchronization
=>
14263 Process_Disable_Enable_Atomic_Sync
(Name_Unsuppress
);
14270 -- [ Convention =>] convention_IDENTIFIER,
14271 -- [ Entity =>] LOCAL_NAME
14272 -- [, [External_Name =>] static_string_EXPRESSION ]
14273 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14275 when Pragma_Export
=> Export
: declare
14277 Def_Id
: Entity_Id
;
14279 pragma Warnings
(Off
, C
);
14282 Check_Ada_83_Warning
;
14286 Name_External_Name
,
14289 Check_At_Least_N_Arguments
(2);
14290 Check_At_Most_N_Arguments
(4);
14292 -- In Relaxed_RM_Semantics, support old Ada 83 style:
14293 -- pragma Export (Entity, "external name");
14295 if Relaxed_RM_Semantics
14296 and then Arg_Count
= 2
14297 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
14300 Def_Id
:= Get_Pragma_Arg
(Arg1
);
14303 if not Is_Entity_Name
(Def_Id
) then
14304 Error_Pragma_Arg
("entity name required", Arg1
);
14307 Def_Id
:= Entity
(Def_Id
);
14308 Set_Exported
(Def_Id
, Arg1
);
14311 Process_Convention
(C
, Def_Id
);
14313 -- A pragma that applies to a Ghost entity becomes Ghost for
14314 -- the purposes of legality checks and removal of ignored Ghost
14317 Mark_Pragma_As_Ghost
(N
, Def_Id
);
14319 if Ekind
(Def_Id
) /= E_Constant
then
14320 Note_Possible_Modification
14321 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
14324 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
14325 Set_Exported
(Def_Id
, Arg2
);
14328 -- If the entity is a deferred constant, propagate the information
14329 -- to the full view, because gigi elaborates the full view only.
14331 if Ekind
(Def_Id
) = E_Constant
14332 and then Present
(Full_View
(Def_Id
))
14335 Id2
: constant Entity_Id
:= Full_View
(Def_Id
);
14337 Set_Is_Exported
(Id2
, Is_Exported
(Def_Id
));
14338 Set_First_Rep_Item
(Id2
, First_Rep_Item
(Def_Id
));
14339 Set_Interface_Name
(Id2
, Einfo
.Interface_Name
(Def_Id
));
14344 ---------------------
14345 -- Export_Function --
14346 ---------------------
14348 -- pragma Export_Function (
14349 -- [Internal =>] LOCAL_NAME
14350 -- [, [External =>] EXTERNAL_SYMBOL]
14351 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14352 -- [, [Result_Type =>] TYPE_DESIGNATOR]
14353 -- [, [Mechanism =>] MECHANISM]
14354 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14356 -- EXTERNAL_SYMBOL ::=
14358 -- | static_string_EXPRESSION
14360 -- PARAMETER_TYPES ::=
14362 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14364 -- TYPE_DESIGNATOR ::=
14366 -- | subtype_Name ' Access
14370 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14372 -- MECHANISM_ASSOCIATION ::=
14373 -- [formal_parameter_NAME =>] MECHANISM_NAME
14375 -- MECHANISM_NAME ::=
14379 when Pragma_Export_Function
=> Export_Function
: declare
14380 Args
: Args_List
(1 .. 6);
14381 Names
: constant Name_List
(1 .. 6) := (
14384 Name_Parameter_Types
,
14387 Name_Result_Mechanism
);
14389 Internal
: Node_Id
renames Args
(1);
14390 External
: Node_Id
renames Args
(2);
14391 Parameter_Types
: Node_Id
renames Args
(3);
14392 Result_Type
: Node_Id
renames Args
(4);
14393 Mechanism
: Node_Id
renames Args
(5);
14394 Result_Mechanism
: Node_Id
renames Args
(6);
14398 Gather_Associations
(Names
, Args
);
14399 Process_Extended_Import_Export_Subprogram_Pragma
(
14400 Arg_Internal
=> Internal
,
14401 Arg_External
=> External
,
14402 Arg_Parameter_Types
=> Parameter_Types
,
14403 Arg_Result_Type
=> Result_Type
,
14404 Arg_Mechanism
=> Mechanism
,
14405 Arg_Result_Mechanism
=> Result_Mechanism
);
14406 end Export_Function
;
14408 -------------------
14409 -- Export_Object --
14410 -------------------
14412 -- pragma Export_Object (
14413 -- [Internal =>] LOCAL_NAME
14414 -- [, [External =>] EXTERNAL_SYMBOL]
14415 -- [, [Size =>] EXTERNAL_SYMBOL]);
14417 -- EXTERNAL_SYMBOL ::=
14419 -- | static_string_EXPRESSION
14421 -- PARAMETER_TYPES ::=
14423 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14425 -- TYPE_DESIGNATOR ::=
14427 -- | subtype_Name ' Access
14431 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14433 -- MECHANISM_ASSOCIATION ::=
14434 -- [formal_parameter_NAME =>] MECHANISM_NAME
14436 -- MECHANISM_NAME ::=
14440 when Pragma_Export_Object
=> Export_Object
: declare
14441 Args
: Args_List
(1 .. 3);
14442 Names
: constant Name_List
(1 .. 3) := (
14447 Internal
: Node_Id
renames Args
(1);
14448 External
: Node_Id
renames Args
(2);
14449 Size
: Node_Id
renames Args
(3);
14453 Gather_Associations
(Names
, Args
);
14454 Process_Extended_Import_Export_Object_Pragma
(
14455 Arg_Internal
=> Internal
,
14456 Arg_External
=> External
,
14460 ----------------------
14461 -- Export_Procedure --
14462 ----------------------
14464 -- pragma Export_Procedure (
14465 -- [Internal =>] LOCAL_NAME
14466 -- [, [External =>] EXTERNAL_SYMBOL]
14467 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14468 -- [, [Mechanism =>] MECHANISM]);
14470 -- EXTERNAL_SYMBOL ::=
14472 -- | static_string_EXPRESSION
14474 -- PARAMETER_TYPES ::=
14476 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14478 -- TYPE_DESIGNATOR ::=
14480 -- | subtype_Name ' Access
14484 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14486 -- MECHANISM_ASSOCIATION ::=
14487 -- [formal_parameter_NAME =>] MECHANISM_NAME
14489 -- MECHANISM_NAME ::=
14493 when Pragma_Export_Procedure
=> Export_Procedure
: declare
14494 Args
: Args_List
(1 .. 4);
14495 Names
: constant Name_List
(1 .. 4) := (
14498 Name_Parameter_Types
,
14501 Internal
: Node_Id
renames Args
(1);
14502 External
: Node_Id
renames Args
(2);
14503 Parameter_Types
: Node_Id
renames Args
(3);
14504 Mechanism
: Node_Id
renames Args
(4);
14508 Gather_Associations
(Names
, Args
);
14509 Process_Extended_Import_Export_Subprogram_Pragma
(
14510 Arg_Internal
=> Internal
,
14511 Arg_External
=> External
,
14512 Arg_Parameter_Types
=> Parameter_Types
,
14513 Arg_Mechanism
=> Mechanism
);
14514 end Export_Procedure
;
14520 -- pragma Export_Value (
14521 -- [Value =>] static_integer_EXPRESSION,
14522 -- [Link_Name =>] static_string_EXPRESSION);
14524 when Pragma_Export_Value
=>
14526 Check_Arg_Order
((Name_Value
, Name_Link_Name
));
14527 Check_Arg_Count
(2);
14529 Check_Optional_Identifier
(Arg1
, Name_Value
);
14530 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
14532 Check_Optional_Identifier
(Arg2
, Name_Link_Name
);
14533 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
14535 -----------------------------
14536 -- Export_Valued_Procedure --
14537 -----------------------------
14539 -- pragma Export_Valued_Procedure (
14540 -- [Internal =>] LOCAL_NAME
14541 -- [, [External =>] EXTERNAL_SYMBOL,]
14542 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14543 -- [, [Mechanism =>] MECHANISM]);
14545 -- EXTERNAL_SYMBOL ::=
14547 -- | static_string_EXPRESSION
14549 -- PARAMETER_TYPES ::=
14551 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14553 -- TYPE_DESIGNATOR ::=
14555 -- | subtype_Name ' Access
14559 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14561 -- MECHANISM_ASSOCIATION ::=
14562 -- [formal_parameter_NAME =>] MECHANISM_NAME
14564 -- MECHANISM_NAME ::=
14568 when Pragma_Export_Valued_Procedure
=>
14569 Export_Valued_Procedure
: declare
14570 Args
: Args_List
(1 .. 4);
14571 Names
: constant Name_List
(1 .. 4) := (
14574 Name_Parameter_Types
,
14577 Internal
: Node_Id
renames Args
(1);
14578 External
: Node_Id
renames Args
(2);
14579 Parameter_Types
: Node_Id
renames Args
(3);
14580 Mechanism
: Node_Id
renames Args
(4);
14584 Gather_Associations
(Names
, Args
);
14585 Process_Extended_Import_Export_Subprogram_Pragma
(
14586 Arg_Internal
=> Internal
,
14587 Arg_External
=> External
,
14588 Arg_Parameter_Types
=> Parameter_Types
,
14589 Arg_Mechanism
=> Mechanism
);
14590 end Export_Valued_Procedure
;
14592 -------------------
14593 -- Extend_System --
14594 -------------------
14596 -- pragma Extend_System ([Name =>] Identifier);
14598 when Pragma_Extend_System
=> Extend_System
: declare
14601 Check_Valid_Configuration_Pragma
;
14602 Check_Arg_Count
(1);
14603 Check_Optional_Identifier
(Arg1
, Name_Name
);
14604 Check_Arg_Is_Identifier
(Arg1
);
14606 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
14609 and then Name_Buffer
(1 .. 4) = "aux_"
14611 if Present
(System_Extend_Pragma_Arg
) then
14612 if Chars
(Get_Pragma_Arg
(Arg1
)) =
14613 Chars
(Expression
(System_Extend_Pragma_Arg
))
14617 Error_Msg_Sloc
:= Sloc
(System_Extend_Pragma_Arg
);
14618 Error_Pragma
("pragma% conflicts with that #");
14622 System_Extend_Pragma_Arg
:= Arg1
;
14624 if not GNAT_Mode
then
14625 System_Extend_Unit
:= Arg1
;
14629 Error_Pragma
("incorrect name for pragma%, must be Aux_xxx");
14633 ------------------------
14634 -- Extensions_Allowed --
14635 ------------------------
14637 -- pragma Extensions_Allowed (ON | OFF);
14639 when Pragma_Extensions_Allowed
=>
14641 Check_Arg_Count
(1);
14642 Check_No_Identifiers
;
14643 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
14645 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
14646 Extensions_Allowed
:= True;
14647 Ada_Version
:= Ada_Version_Type
'Last;
14650 Extensions_Allowed
:= False;
14651 Ada_Version
:= Ada_Version_Explicit
;
14652 Ada_Version_Pragma
:= Empty
;
14655 ------------------------
14656 -- Extensions_Visible --
14657 ------------------------
14659 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
14661 -- Characteristics:
14663 -- * Analysis - The annotation is fully analyzed immediately upon
14664 -- elaboration as its expression must be static.
14666 -- * Expansion - None.
14668 -- * Template - The annotation utilizes the generic template of the
14669 -- related subprogram [body] when it is:
14671 -- aspect on subprogram declaration
14672 -- aspect on stand alone subprogram body
14673 -- pragma on stand alone subprogram body
14675 -- The annotation must prepare its own template when it is:
14677 -- pragma on subprogram declaration
14679 -- * Globals - Capture of global references must occur after full
14682 -- * Instance - The annotation is instantiated automatically when
14683 -- the related generic subprogram [body] is instantiated except for
14684 -- the "pragma on subprogram declaration" case. In that scenario
14685 -- the annotation must instantiate itself.
14687 when Pragma_Extensions_Visible
=> Extensions_Visible
: declare
14688 Formal
: Entity_Id
;
14689 Has_OK_Formal
: Boolean := False;
14690 Spec_Id
: Entity_Id
;
14691 Subp_Decl
: Node_Id
;
14695 Check_No_Identifiers
;
14696 Check_At_Most_N_Arguments
(1);
14699 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
14701 -- Abstract subprogram declaration
14703 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
14706 -- Generic subprogram declaration
14708 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
14711 -- Body acts as spec
14713 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
14714 and then No
(Corresponding_Spec
(Subp_Decl
))
14718 -- Body stub acts as spec
14720 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
14721 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
14725 -- Subprogram declaration
14727 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
14730 -- Otherwise the pragma is associated with an illegal construct
14733 Error_Pragma
("pragma % must apply to a subprogram");
14737 -- Chain the pragma on the contract for completeness
14739 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
14741 -- The legality checks of pragma Extension_Visible are affected
14742 -- by the SPARK mode in effect. Analyze all pragmas in specific
14745 Analyze_If_Present
(Pragma_SPARK_Mode
);
14747 -- Mark the pragma as Ghost if the related subprogram is also
14748 -- Ghost. This also ensures that any expansion performed further
14749 -- below will produce Ghost nodes.
14751 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
14752 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
14754 -- Examine the formals of the related subprogram
14756 Formal
:= First_Formal
(Spec_Id
);
14757 while Present
(Formal
) loop
14759 -- At least one of the formals is of a specific tagged type,
14760 -- the pragma is legal.
14762 if Is_Specific_Tagged_Type
(Etype
(Formal
)) then
14763 Has_OK_Formal
:= True;
14766 -- A generic subprogram with at least one formal of a private
14767 -- type ensures the legality of the pragma because the actual
14768 -- may be specifically tagged. Note that this is verified by
14769 -- the check above at instantiation time.
14771 elsif Is_Private_Type
(Etype
(Formal
))
14772 and then Is_Generic_Type
(Etype
(Formal
))
14774 Has_OK_Formal
:= True;
14778 Next_Formal
(Formal
);
14781 if not Has_OK_Formal
then
14782 Error_Msg_Name_1
:= Pname
;
14783 Error_Msg_N
(Fix_Error
("incorrect placement of pragma %"), N
);
14785 ("\subprogram & lacks parameter of specific tagged or "
14786 & "generic private type", N
, Spec_Id
);
14791 -- Analyze the Boolean expression (if any)
14793 if Present
(Arg1
) then
14794 Check_Static_Boolean_Expression
14795 (Expression
(Get_Argument
(N
, Spec_Id
)));
14797 end Extensions_Visible
;
14803 -- pragma External (
14804 -- [ Convention =>] convention_IDENTIFIER,
14805 -- [ Entity =>] LOCAL_NAME
14806 -- [, [External_Name =>] static_string_EXPRESSION ]
14807 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14809 when Pragma_External
=> External
: declare
14812 pragma Warnings
(Off
, C
);
14819 Name_External_Name
,
14821 Check_At_Least_N_Arguments
(2);
14822 Check_At_Most_N_Arguments
(4);
14823 Process_Convention
(C
, E
);
14825 -- A pragma that applies to a Ghost entity becomes Ghost for the
14826 -- purposes of legality checks and removal of ignored Ghost code.
14828 Mark_Pragma_As_Ghost
(N
, E
);
14830 Note_Possible_Modification
14831 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
14832 Process_Interface_Name
(E
, Arg3
, Arg4
);
14833 Set_Exported
(E
, Arg2
);
14836 --------------------------
14837 -- External_Name_Casing --
14838 --------------------------
14840 -- pragma External_Name_Casing (
14841 -- UPPERCASE | LOWERCASE
14842 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14844 when Pragma_External_Name_Casing
=> External_Name_Casing
: declare
14847 Check_No_Identifiers
;
14849 if Arg_Count
= 2 then
14850 Check_Arg_Is_One_Of
14851 (Arg2
, Name_As_Is
, Name_Uppercase
, Name_Lowercase
);
14853 case Chars
(Get_Pragma_Arg
(Arg2
)) is
14855 Opt
.External_Name_Exp_Casing
:= As_Is
;
14857 when Name_Uppercase
=>
14858 Opt
.External_Name_Exp_Casing
:= Uppercase
;
14860 when Name_Lowercase
=>
14861 Opt
.External_Name_Exp_Casing
:= Lowercase
;
14868 Check_Arg_Count
(1);
14871 Check_Arg_Is_One_Of
(Arg1
, Name_Uppercase
, Name_Lowercase
);
14873 case Chars
(Get_Pragma_Arg
(Arg1
)) is
14874 when Name_Uppercase
=>
14875 Opt
.External_Name_Imp_Casing
:= Uppercase
;
14877 when Name_Lowercase
=>
14878 Opt
.External_Name_Imp_Casing
:= Lowercase
;
14883 end External_Name_Casing
;
14889 -- pragma Fast_Math;
14891 when Pragma_Fast_Math
=>
14893 Check_No_Identifiers
;
14894 Check_Valid_Configuration_Pragma
;
14897 --------------------------
14898 -- Favor_Top_Level --
14899 --------------------------
14901 -- pragma Favor_Top_Level (type_NAME);
14903 when Pragma_Favor_Top_Level
=> Favor_Top_Level
: declare
14908 Check_No_Identifiers
;
14909 Check_Arg_Count
(1);
14910 Check_Arg_Is_Local_Name
(Arg1
);
14911 Typ
:= Entity
(Get_Pragma_Arg
(Arg1
));
14913 -- A pragma that applies to a Ghost entity becomes Ghost for the
14914 -- purposes of legality checks and removal of ignored Ghost code.
14916 Mark_Pragma_As_Ghost
(N
, Typ
);
14918 -- If it's an access-to-subprogram type (in particular, not a
14919 -- subtype), set the flag on that type.
14921 if Is_Access_Subprogram_Type
(Typ
) then
14922 Set_Can_Use_Internal_Rep
(Typ
, False);
14924 -- Otherwise it's an error (name denotes the wrong sort of entity)
14928 ("access-to-subprogram type expected",
14929 Get_Pragma_Arg
(Arg1
));
14931 end Favor_Top_Level
;
14933 ---------------------------
14934 -- Finalize_Storage_Only --
14935 ---------------------------
14937 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14939 when Pragma_Finalize_Storage_Only
=> Finalize_Storage
: declare
14940 Assoc
: constant Node_Id
:= Arg1
;
14941 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
14946 Check_No_Identifiers
;
14947 Check_Arg_Count
(1);
14948 Check_Arg_Is_Local_Name
(Arg1
);
14950 Find_Type
(Type_Id
);
14951 Typ
:= Entity
(Type_Id
);
14954 or else Rep_Item_Too_Early
(Typ
, N
)
14958 Typ
:= Underlying_Type
(Typ
);
14961 if not Is_Controlled
(Typ
) then
14962 Error_Pragma
("pragma% must specify controlled type");
14965 Check_First_Subtype
(Arg1
);
14967 if Finalize_Storage_Only
(Typ
) then
14968 Error_Pragma
("duplicate pragma%, only one allowed");
14970 elsif not Rep_Item_Too_Late
(Typ
, N
) then
14971 Set_Finalize_Storage_Only
(Base_Type
(Typ
), True);
14973 end Finalize_Storage
;
14979 -- pragma Ghost [ (boolean_EXPRESSION) ];
14981 when Pragma_Ghost
=> Ghost
: declare
14985 Orig_Stmt
: Node_Id
;
14986 Prev_Id
: Entity_Id
;
14991 Check_No_Identifiers
;
14992 Check_At_Most_N_Arguments
(1);
14996 while Present
(Stmt
) loop
14998 -- Skip prior pragmas, but check for duplicates
15000 if Nkind
(Stmt
) = N_Pragma
then
15001 if Pragma_Name
(Stmt
) = Pname
then
15002 Error_Msg_Name_1
:= Pname
;
15003 Error_Msg_Sloc
:= Sloc
(Stmt
);
15004 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
15007 -- Task unit declared without a definition cannot be subject to
15008 -- pragma Ghost (SPARK RM 6.9(19)).
15010 elsif Nkind_In
(Stmt
, N_Single_Task_Declaration
,
15011 N_Task_Type_Declaration
)
15013 Error_Pragma
("pragma % cannot apply to a task type");
15016 -- Skip internally generated code
15018 elsif not Comes_From_Source
(Stmt
) then
15019 Orig_Stmt
:= Original_Node
(Stmt
);
15021 -- When pragma Ghost applies to an untagged derivation, the
15022 -- derivation is transformed into a [sub]type declaration.
15024 if Nkind_In
(Stmt
, N_Full_Type_Declaration
,
15025 N_Subtype_Declaration
)
15026 and then Comes_From_Source
(Orig_Stmt
)
15027 and then Nkind
(Orig_Stmt
) = N_Full_Type_Declaration
15028 and then Nkind
(Type_Definition
(Orig_Stmt
)) =
15029 N_Derived_Type_Definition
15031 Id
:= Defining_Entity
(Stmt
);
15034 -- When pragma Ghost applies to an expression function, the
15035 -- expression function is transformed into a subprogram.
15037 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
15038 and then Comes_From_Source
(Orig_Stmt
)
15039 and then Nkind
(Orig_Stmt
) = N_Expression_Function
15041 Id
:= Defining_Entity
(Stmt
);
15045 -- The pragma applies to a legal construct, stop the traversal
15047 elsif Nkind_In
(Stmt
, N_Abstract_Subprogram_Declaration
,
15048 N_Full_Type_Declaration
,
15049 N_Generic_Subprogram_Declaration
,
15050 N_Object_Declaration
,
15051 N_Private_Extension_Declaration
,
15052 N_Private_Type_Declaration
,
15053 N_Subprogram_Declaration
,
15054 N_Subtype_Declaration
)
15056 Id
:= Defining_Entity
(Stmt
);
15059 -- The pragma does not apply to a legal construct, issue an
15060 -- error and stop the analysis.
15064 ("pragma % must apply to an object, package, subprogram "
15069 Stmt
:= Prev
(Stmt
);
15072 Context
:= Parent
(N
);
15074 -- Handle compilation units
15076 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
15077 Context
:= Unit
(Parent
(Context
));
15080 -- Protected and task types cannot be subject to pragma Ghost
15081 -- (SPARK RM 6.9(19)).
15083 if Nkind_In
(Context
, N_Protected_Body
, N_Protected_Definition
)
15085 Error_Pragma
("pragma % cannot apply to a protected type");
15088 elsif Nkind_In
(Context
, N_Task_Body
, N_Task_Definition
) then
15089 Error_Pragma
("pragma % cannot apply to a task type");
15095 -- When pragma Ghost is associated with a [generic] package, it
15096 -- appears in the visible declarations.
15098 if Nkind
(Context
) = N_Package_Specification
15099 and then Present
(Visible_Declarations
(Context
))
15100 and then List_Containing
(N
) = Visible_Declarations
(Context
)
15102 Id
:= Defining_Entity
(Context
);
15104 -- Pragma Ghost applies to a stand alone subprogram body
15106 elsif Nkind
(Context
) = N_Subprogram_Body
15107 and then No
(Corresponding_Spec
(Context
))
15109 Id
:= Defining_Entity
(Context
);
15111 -- Pragma Ghost applies to a subprogram declaration that acts
15112 -- as a compilation unit.
15114 elsif Nkind
(Context
) = N_Subprogram_Declaration
then
15115 Id
:= Defining_Entity
(Context
);
15121 ("pragma % must apply to an object, package, subprogram or "
15126 -- Handle completions of types and constants that are subject to
15129 if Is_Record_Type
(Id
) or else Ekind
(Id
) = E_Constant
then
15130 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
15132 if Present
(Prev_Id
) and then not Is_Ghost_Entity
(Prev_Id
) then
15133 Error_Msg_Name_1
:= Pname
;
15135 -- The full declaration of a deferred constant cannot be
15136 -- subject to pragma Ghost unless the deferred declaration
15137 -- is also Ghost (SPARK RM 6.9(9)).
15139 if Ekind
(Prev_Id
) = E_Constant
then
15140 Error_Msg_Name_1
:= Pname
;
15141 Error_Msg_NE
(Fix_Error
15142 ("pragma % must apply to declaration of deferred "
15143 & "constant &"), N
, Id
);
15146 -- Pragma Ghost may appear on the full view of an incomplete
15147 -- type because the incomplete declaration lacks aspects and
15148 -- cannot be subject to pragma Ghost.
15150 elsif Ekind
(Prev_Id
) = E_Incomplete_Type
then
15153 -- The full declaration of a type cannot be subject to
15154 -- pragma Ghost unless the partial view is also Ghost
15155 -- (SPARK RM 6.9(9)).
15158 Error_Msg_NE
(Fix_Error
15159 ("pragma % must apply to partial view of type &"),
15165 -- A synchronized object cannot be subject to pragma Ghost
15166 -- (SPARK RM 6.9(19)).
15168 elsif Ekind
(Id
) = E_Variable
then
15169 if Is_Protected_Type
(Etype
(Id
)) then
15170 Error_Pragma
("pragma % cannot apply to a protected object");
15173 elsif Is_Task_Type
(Etype
(Id
)) then
15174 Error_Pragma
("pragma % cannot apply to a task object");
15179 -- Analyze the Boolean expression (if any)
15181 if Present
(Arg1
) then
15182 Expr
:= Get_Pragma_Arg
(Arg1
);
15184 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
15186 if Is_OK_Static_Expression
(Expr
) then
15188 -- "Ghostness" cannot be turned off once enabled within a
15189 -- region (SPARK RM 6.9(6)).
15191 if Is_False
(Expr_Value
(Expr
))
15192 and then Ghost_Mode
> None
15195 ("pragma % with value False cannot appear in enabled "
15200 -- Otherwie the expression is not static
15204 ("expression of pragma % must be static", Expr
);
15209 Set_Is_Ghost_Entity
(Id
);
15216 -- pragma Global (GLOBAL_SPECIFICATION);
15218 -- GLOBAL_SPECIFICATION ::=
15221 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
15223 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
15225 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
15226 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
15227 -- GLOBAL_ITEM ::= NAME
15229 -- Characteristics:
15231 -- * Analysis - The annotation undergoes initial checks to verify
15232 -- the legal placement and context. Secondary checks fully analyze
15233 -- the dependency clauses in:
15235 -- Analyze_Global_In_Decl_Part
15237 -- * Expansion - None.
15239 -- * Template - The annotation utilizes the generic template of the
15240 -- related subprogram [body] when it is:
15242 -- aspect on subprogram declaration
15243 -- aspect on stand alone subprogram body
15244 -- pragma on stand alone subprogram body
15246 -- The annotation must prepare its own template when it is:
15248 -- pragma on subprogram declaration
15250 -- * Globals - Capture of global references must occur after full
15253 -- * Instance - The annotation is instantiated automatically when
15254 -- the related generic subprogram [body] is instantiated except for
15255 -- the "pragma on subprogram declaration" case. In that scenario
15256 -- the annotation must instantiate itself.
15258 when Pragma_Global
=> Global
: declare
15260 Spec_Id
: Entity_Id
;
15261 Subp_Decl
: Node_Id
;
15264 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
15268 -- Chain the pragma on the contract for further processing by
15269 -- Analyze_Global_In_Decl_Part.
15271 Add_Contract_Item
(N
, Spec_Id
);
15273 -- Fully analyze the pragma when it appears inside an entry
15274 -- or subprogram body because it cannot benefit from forward
15277 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
15279 N_Subprogram_Body_Stub
)
15281 -- The legality checks of pragmas Depends and Global are
15282 -- affected by the SPARK mode in effect and the volatility
15283 -- of the context. In addition these two pragmas are subject
15284 -- to an inherent order:
15289 -- Analyze all these pragmas in the order outlined above
15291 Analyze_If_Present
(Pragma_SPARK_Mode
);
15292 Analyze_If_Present
(Pragma_Volatile_Function
);
15293 Analyze_Global_In_Decl_Part
(N
);
15294 Analyze_If_Present
(Pragma_Depends
);
15303 -- pragma Ident (static_string_EXPRESSION)
15305 -- Note: pragma Comment shares this processing. Pragma Ident is
15306 -- identical in effect to pragma Commment.
15308 when Pragma_Ident | Pragma_Comment
=> Ident
: declare
15313 Check_Arg_Count
(1);
15314 Check_No_Identifiers
;
15315 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
15318 Str
:= Expr_Value_S
(Get_Pragma_Arg
(Arg1
));
15325 GP
:= Parent
(Parent
(N
));
15327 if Nkind_In
(GP
, N_Package_Declaration
,
15328 N_Generic_Package_Declaration
)
15333 -- If we have a compilation unit, then record the ident value,
15334 -- checking for improper duplication.
15336 if Nkind
(GP
) = N_Compilation_Unit
then
15337 CS
:= Ident_String
(Current_Sem_Unit
);
15339 if Present
(CS
) then
15341 -- If we have multiple instances, concatenate them, but
15342 -- not in ASIS, where we want the original tree.
15344 if not ASIS_Mode
then
15345 Start_String
(Strval
(CS
));
15346 Store_String_Char
(' ');
15347 Store_String_Chars
(Strval
(Str
));
15348 Set_Strval
(CS
, End_String
);
15352 Set_Ident_String
(Current_Sem_Unit
, Str
);
15355 -- For subunits, we just ignore the Ident, since in GNAT these
15356 -- are not separate object files, and hence not separate units
15357 -- in the unit table.
15359 elsif Nkind
(GP
) = N_Subunit
then
15365 -------------------
15366 -- Ignore_Pragma --
15367 -------------------
15369 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
15371 -- Entirely handled in the parser, nothing to do here
15373 when Pragma_Ignore_Pragma
=>
15376 ----------------------------
15377 -- Implementation_Defined --
15378 ----------------------------
15380 -- pragma Implementation_Defined (LOCAL_NAME);
15382 -- Marks previously declared entity as implementation defined. For
15383 -- an overloaded entity, applies to the most recent homonym.
15385 -- pragma Implementation_Defined;
15387 -- The form with no arguments appears anywhere within a scope, most
15388 -- typically a package spec, and indicates that all entities that are
15389 -- defined within the package spec are Implementation_Defined.
15391 when Pragma_Implementation_Defined
=> Implementation_Defined
: declare
15396 Check_No_Identifiers
;
15398 -- Form with no arguments
15400 if Arg_Count
= 0 then
15401 Set_Is_Implementation_Defined
(Current_Scope
);
15403 -- Form with one argument
15406 Check_Arg_Count
(1);
15407 Check_Arg_Is_Local_Name
(Arg1
);
15408 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
15409 Set_Is_Implementation_Defined
(Ent
);
15411 end Implementation_Defined
;
15417 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
15419 -- IMPLEMENTATION_KIND ::=
15420 -- By_Entry | By_Protected_Procedure | By_Any | Optional
15422 -- "By_Any" and "Optional" are treated as synonyms in order to
15423 -- support Ada 2012 aspect Synchronization.
15425 when Pragma_Implemented
=> Implemented
: declare
15426 Proc_Id
: Entity_Id
;
15431 Check_Arg_Count
(2);
15432 Check_No_Identifiers
;
15433 Check_Arg_Is_Identifier
(Arg1
);
15434 Check_Arg_Is_Local_Name
(Arg1
);
15435 Check_Arg_Is_One_Of
(Arg2
,
15438 Name_By_Protected_Procedure
,
15441 -- Extract the name of the local procedure
15443 Proc_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
15445 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
15446 -- primitive procedure of a synchronized tagged type.
15448 if Ekind
(Proc_Id
) = E_Procedure
15449 and then Is_Primitive
(Proc_Id
)
15450 and then Present
(First_Formal
(Proc_Id
))
15452 Typ
:= Etype
(First_Formal
(Proc_Id
));
15454 if Is_Tagged_Type
(Typ
)
15457 -- Check for a protected, a synchronized or a task interface
15459 ((Is_Interface
(Typ
)
15460 and then Is_Synchronized_Interface
(Typ
))
15462 -- Check for a protected type or a task type that implements
15466 (Is_Concurrent_Record_Type
(Typ
)
15467 and then Present
(Interfaces
(Typ
)))
15469 -- In analysis-only mode, examine original protected type
15472 (Nkind
(Parent
(Typ
)) = N_Protected_Type_Declaration
15473 and then Present
(Interface_List
(Parent
(Typ
))))
15475 -- Check for a private record extension with keyword
15479 (Ekind_In
(Typ
, E_Record_Type_With_Private
,
15480 E_Record_Subtype_With_Private
)
15481 and then Synchronized_Present
(Parent
(Typ
))))
15486 ("controlling formal must be of synchronized tagged type",
15491 -- Procedures declared inside a protected type must be accepted
15493 elsif Ekind
(Proc_Id
) = E_Procedure
15494 and then Is_Protected_Type
(Scope
(Proc_Id
))
15498 -- The first argument is not a primitive procedure
15502 ("pragma % must be applied to a primitive procedure", Arg1
);
15506 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
15507 -- By_Protected_Procedure to the primitive procedure of a task
15510 if Chars
(Arg2
) = Name_By_Protected_Procedure
15511 and then Is_Interface
(Typ
)
15512 and then Is_Task_Interface
(Typ
)
15515 ("implementation kind By_Protected_Procedure cannot be "
15516 & "applied to a task interface primitive", Arg2
);
15520 Record_Rep_Item
(Proc_Id
, N
);
15523 ----------------------
15524 -- Implicit_Packing --
15525 ----------------------
15527 -- pragma Implicit_Packing;
15529 when Pragma_Implicit_Packing
=>
15531 Check_Arg_Count
(0);
15532 Implicit_Packing
:= True;
15539 -- [Convention =>] convention_IDENTIFIER,
15540 -- [Entity =>] LOCAL_NAME
15541 -- [, [External_Name =>] static_string_EXPRESSION ]
15542 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15544 when Pragma_Import
=>
15545 Check_Ada_83_Warning
;
15549 Name_External_Name
,
15552 Check_At_Least_N_Arguments
(2);
15553 Check_At_Most_N_Arguments
(4);
15554 Process_Import_Or_Interface
;
15556 ---------------------
15557 -- Import_Function --
15558 ---------------------
15560 -- pragma Import_Function (
15561 -- [Internal =>] LOCAL_NAME,
15562 -- [, [External =>] EXTERNAL_SYMBOL]
15563 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15564 -- [, [Result_Type =>] SUBTYPE_MARK]
15565 -- [, [Mechanism =>] MECHANISM]
15566 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15568 -- EXTERNAL_SYMBOL ::=
15570 -- | static_string_EXPRESSION
15572 -- PARAMETER_TYPES ::=
15574 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15576 -- TYPE_DESIGNATOR ::=
15578 -- | subtype_Name ' Access
15582 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15584 -- MECHANISM_ASSOCIATION ::=
15585 -- [formal_parameter_NAME =>] MECHANISM_NAME
15587 -- MECHANISM_NAME ::=
15591 when Pragma_Import_Function
=> Import_Function
: declare
15592 Args
: Args_List
(1 .. 6);
15593 Names
: constant Name_List
(1 .. 6) := (
15596 Name_Parameter_Types
,
15599 Name_Result_Mechanism
);
15601 Internal
: Node_Id
renames Args
(1);
15602 External
: Node_Id
renames Args
(2);
15603 Parameter_Types
: Node_Id
renames Args
(3);
15604 Result_Type
: Node_Id
renames Args
(4);
15605 Mechanism
: Node_Id
renames Args
(5);
15606 Result_Mechanism
: Node_Id
renames Args
(6);
15610 Gather_Associations
(Names
, Args
);
15611 Process_Extended_Import_Export_Subprogram_Pragma
(
15612 Arg_Internal
=> Internal
,
15613 Arg_External
=> External
,
15614 Arg_Parameter_Types
=> Parameter_Types
,
15615 Arg_Result_Type
=> Result_Type
,
15616 Arg_Mechanism
=> Mechanism
,
15617 Arg_Result_Mechanism
=> Result_Mechanism
);
15618 end Import_Function
;
15620 -------------------
15621 -- Import_Object --
15622 -------------------
15624 -- pragma Import_Object (
15625 -- [Internal =>] LOCAL_NAME
15626 -- [, [External =>] EXTERNAL_SYMBOL]
15627 -- [, [Size =>] EXTERNAL_SYMBOL]);
15629 -- EXTERNAL_SYMBOL ::=
15631 -- | static_string_EXPRESSION
15633 when Pragma_Import_Object
=> Import_Object
: declare
15634 Args
: Args_List
(1 .. 3);
15635 Names
: constant Name_List
(1 .. 3) := (
15640 Internal
: Node_Id
renames Args
(1);
15641 External
: Node_Id
renames Args
(2);
15642 Size
: Node_Id
renames Args
(3);
15646 Gather_Associations
(Names
, Args
);
15647 Process_Extended_Import_Export_Object_Pragma
(
15648 Arg_Internal
=> Internal
,
15649 Arg_External
=> External
,
15653 ----------------------
15654 -- Import_Procedure --
15655 ----------------------
15657 -- pragma Import_Procedure (
15658 -- [Internal =>] LOCAL_NAME
15659 -- [, [External =>] EXTERNAL_SYMBOL]
15660 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15661 -- [, [Mechanism =>] MECHANISM]);
15663 -- EXTERNAL_SYMBOL ::=
15665 -- | static_string_EXPRESSION
15667 -- PARAMETER_TYPES ::=
15669 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15671 -- TYPE_DESIGNATOR ::=
15673 -- | subtype_Name ' Access
15677 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15679 -- MECHANISM_ASSOCIATION ::=
15680 -- [formal_parameter_NAME =>] MECHANISM_NAME
15682 -- MECHANISM_NAME ::=
15686 when Pragma_Import_Procedure
=> Import_Procedure
: declare
15687 Args
: Args_List
(1 .. 4);
15688 Names
: constant Name_List
(1 .. 4) := (
15691 Name_Parameter_Types
,
15694 Internal
: Node_Id
renames Args
(1);
15695 External
: Node_Id
renames Args
(2);
15696 Parameter_Types
: Node_Id
renames Args
(3);
15697 Mechanism
: Node_Id
renames Args
(4);
15701 Gather_Associations
(Names
, Args
);
15702 Process_Extended_Import_Export_Subprogram_Pragma
(
15703 Arg_Internal
=> Internal
,
15704 Arg_External
=> External
,
15705 Arg_Parameter_Types
=> Parameter_Types
,
15706 Arg_Mechanism
=> Mechanism
);
15707 end Import_Procedure
;
15709 -----------------------------
15710 -- Import_Valued_Procedure --
15711 -----------------------------
15713 -- pragma Import_Valued_Procedure (
15714 -- [Internal =>] LOCAL_NAME
15715 -- [, [External =>] EXTERNAL_SYMBOL]
15716 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15717 -- [, [Mechanism =>] MECHANISM]);
15719 -- EXTERNAL_SYMBOL ::=
15721 -- | static_string_EXPRESSION
15723 -- PARAMETER_TYPES ::=
15725 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15727 -- TYPE_DESIGNATOR ::=
15729 -- | subtype_Name ' Access
15733 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15735 -- MECHANISM_ASSOCIATION ::=
15736 -- [formal_parameter_NAME =>] MECHANISM_NAME
15738 -- MECHANISM_NAME ::=
15742 when Pragma_Import_Valued_Procedure
=>
15743 Import_Valued_Procedure
: declare
15744 Args
: Args_List
(1 .. 4);
15745 Names
: constant Name_List
(1 .. 4) := (
15748 Name_Parameter_Types
,
15751 Internal
: Node_Id
renames Args
(1);
15752 External
: Node_Id
renames Args
(2);
15753 Parameter_Types
: Node_Id
renames Args
(3);
15754 Mechanism
: Node_Id
renames Args
(4);
15758 Gather_Associations
(Names
, Args
);
15759 Process_Extended_Import_Export_Subprogram_Pragma
(
15760 Arg_Internal
=> Internal
,
15761 Arg_External
=> External
,
15762 Arg_Parameter_Types
=> Parameter_Types
,
15763 Arg_Mechanism
=> Mechanism
);
15764 end Import_Valued_Procedure
;
15770 -- pragma Independent (LOCAL_NAME);
15772 when Pragma_Independent
=>
15773 Process_Atomic_Independent_Shared_Volatile
;
15775 ----------------------------
15776 -- Independent_Components --
15777 ----------------------------
15779 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
15781 when Pragma_Independent_Components
=> Independent_Components
: declare
15789 Check_Ada_83_Warning
;
15791 Check_No_Identifiers
;
15792 Check_Arg_Count
(1);
15793 Check_Arg_Is_Local_Name
(Arg1
);
15794 E_Id
:= Get_Pragma_Arg
(Arg1
);
15796 if Etype
(E_Id
) = Any_Type
then
15800 E
:= Entity
(E_Id
);
15802 -- A pragma that applies to a Ghost entity becomes Ghost for the
15803 -- purposes of legality checks and removal of ignored Ghost code.
15805 Mark_Pragma_As_Ghost
(N
, E
);
15807 -- Check duplicate before we chain ourselves
15809 Check_Duplicate_Pragma
(E
);
15811 -- Check appropriate entity
15813 if Rep_Item_Too_Early
(E
, N
)
15815 Rep_Item_Too_Late
(E
, N
)
15820 D
:= Declaration_Node
(E
);
15823 -- The flag is set on the base type, or on the object
15825 if K
= N_Full_Type_Declaration
15826 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
15828 Set_Has_Independent_Components
(Base_Type
(E
));
15829 Record_Independence_Check
(N
, Base_Type
(E
));
15831 -- For record type, set all components independent
15833 if Is_Record_Type
(E
) then
15834 C
:= First_Component
(E
);
15835 while Present
(C
) loop
15836 Set_Is_Independent
(C
);
15837 Next_Component
(C
);
15841 elsif (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
15842 and then Nkind
(D
) = N_Object_Declaration
15843 and then Nkind
(Object_Definition
(D
)) =
15844 N_Constrained_Array_Definition
15846 Set_Has_Independent_Components
(E
);
15847 Record_Independence_Check
(N
, E
);
15850 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
15852 end Independent_Components
;
15854 -----------------------
15855 -- Initial_Condition --
15856 -----------------------
15858 -- pragma Initial_Condition (boolean_EXPRESSION);
15860 -- Characteristics:
15862 -- * Analysis - The annotation undergoes initial checks to verify
15863 -- the legal placement and context. Secondary checks preanalyze the
15866 -- Analyze_Initial_Condition_In_Decl_Part
15868 -- * Expansion - The annotation is expanded during the expansion of
15869 -- the package body whose declaration is subject to the annotation
15872 -- Expand_Pragma_Initial_Condition
15874 -- * Template - The annotation utilizes the generic template of the
15875 -- related package declaration.
15877 -- * Globals - Capture of global references must occur after full
15880 -- * Instance - The annotation is instantiated automatically when
15881 -- the related generic package is instantiated.
15883 when Pragma_Initial_Condition
=> Initial_Condition
: declare
15884 Pack_Decl
: Node_Id
;
15885 Pack_Id
: Entity_Id
;
15889 Check_No_Identifiers
;
15890 Check_Arg_Count
(1);
15892 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
15894 -- Ensure the proper placement of the pragma. Initial_Condition
15895 -- must be associated with a package declaration.
15897 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
15898 N_Package_Declaration
)
15902 -- Otherwise the pragma is associated with an illegal context
15909 Pack_Id
:= Defining_Entity
(Pack_Decl
);
15911 -- Chain the pragma on the contract for further processing by
15912 -- Analyze_Initial_Condition_In_Decl_Part.
15914 Add_Contract_Item
(N
, Pack_Id
);
15916 -- The legality checks of pragmas Abstract_State, Initializes, and
15917 -- Initial_Condition are affected by the SPARK mode in effect. In
15918 -- addition, these three pragmas are subject to an inherent order:
15920 -- 1) Abstract_State
15922 -- 3) Initial_Condition
15924 -- Analyze all these pragmas in the order outlined above
15926 Analyze_If_Present
(Pragma_SPARK_Mode
);
15927 Analyze_If_Present
(Pragma_Abstract_State
);
15928 Analyze_If_Present
(Pragma_Initializes
);
15930 -- A pragma that applies to a Ghost entity becomes Ghost for the
15931 -- purposes of legality checks and removal of ignored Ghost code.
15933 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
15934 end Initial_Condition
;
15936 ------------------------
15937 -- Initialize_Scalars --
15938 ------------------------
15940 -- pragma Initialize_Scalars;
15942 when Pragma_Initialize_Scalars
=>
15944 Check_Arg_Count
(0);
15945 Check_Valid_Configuration_Pragma
;
15946 Check_Restriction
(No_Initialize_Scalars
, N
);
15948 -- Initialize_Scalars creates false positives in CodePeer, and
15949 -- incorrect negative results in GNATprove mode, so ignore this
15950 -- pragma in these modes.
15952 if not Restriction_Active
(No_Initialize_Scalars
)
15953 and then not (CodePeer_Mode
or GNATprove_Mode
)
15955 Init_Or_Norm_Scalars
:= True;
15956 Initialize_Scalars
:= True;
15963 -- pragma Initializes (INITIALIZATION_LIST);
15965 -- INITIALIZATION_LIST ::=
15967 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15969 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15974 -- | (INPUT {, INPUT})
15978 -- Characteristics:
15980 -- * Analysis - The annotation undergoes initial checks to verify
15981 -- the legal placement and context. Secondary checks preanalyze the
15984 -- Analyze_Initializes_In_Decl_Part
15986 -- * Expansion - None.
15988 -- * Template - The annotation utilizes the generic template of the
15989 -- related package declaration.
15991 -- * Globals - Capture of global references must occur after full
15994 -- * Instance - The annotation is instantiated automatically when
15995 -- the related generic package is instantiated.
15997 when Pragma_Initializes
=> Initializes
: declare
15998 Pack_Decl
: Node_Id
;
15999 Pack_Id
: Entity_Id
;
16003 Check_No_Identifiers
;
16004 Check_Arg_Count
(1);
16006 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
16008 -- Ensure the proper placement of the pragma. Initializes must be
16009 -- associated with a package declaration.
16011 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
16012 N_Package_Declaration
)
16016 -- Otherwise the pragma is associated with an illegal construc
16023 Pack_Id
:= Defining_Entity
(Pack_Decl
);
16025 -- Chain the pragma on the contract for further processing by
16026 -- Analyze_Initializes_In_Decl_Part.
16028 Add_Contract_Item
(N
, Pack_Id
);
16030 -- The legality checks of pragmas Abstract_State, Initializes, and
16031 -- Initial_Condition are affected by the SPARK mode in effect. In
16032 -- addition, these three pragmas are subject to an inherent order:
16034 -- 1) Abstract_State
16036 -- 3) Initial_Condition
16038 -- Analyze all these pragmas in the order outlined above
16040 Analyze_If_Present
(Pragma_SPARK_Mode
);
16041 Analyze_If_Present
(Pragma_Abstract_State
);
16043 -- A pragma that applies to a Ghost entity becomes Ghost for the
16044 -- purposes of legality checks and removal of ignored Ghost code.
16046 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
16047 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
16049 Analyze_If_Present
(Pragma_Initial_Condition
);
16056 -- pragma Inline ( NAME {, NAME} );
16058 when Pragma_Inline
=>
16060 -- Pragma always active unless in GNATprove mode. It is disabled
16061 -- in GNATprove mode because frontend inlining is applied
16062 -- independently of pragmas Inline and Inline_Always for
16063 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
16066 if not GNATprove_Mode
then
16068 -- Inline status is Enabled if inlining option is active
16070 if Inline_Active
then
16071 Process_Inline
(Enabled
);
16073 Process_Inline
(Disabled
);
16077 -------------------
16078 -- Inline_Always --
16079 -------------------
16081 -- pragma Inline_Always ( NAME {, NAME} );
16083 when Pragma_Inline_Always
=>
16086 -- Pragma always active unless in CodePeer mode or GNATprove
16087 -- mode. It is disabled in CodePeer mode because inlining is
16088 -- not helpful, and enabling it caused walk order issues. It
16089 -- is disabled in GNATprove mode because frontend inlining is
16090 -- applied independently of pragmas Inline and Inline_Always for
16091 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
16094 if not CodePeer_Mode
and not GNATprove_Mode
then
16095 Process_Inline
(Enabled
);
16098 --------------------
16099 -- Inline_Generic --
16100 --------------------
16102 -- pragma Inline_Generic (NAME {, NAME});
16104 when Pragma_Inline_Generic
=>
16106 Process_Generic_List
;
16108 ----------------------
16109 -- Inspection_Point --
16110 ----------------------
16112 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
16114 when Pragma_Inspection_Point
=> Inspection_Point
: declare
16121 if Arg_Count
> 0 then
16124 Exp
:= Get_Pragma_Arg
(Arg
);
16127 if not Is_Entity_Name
(Exp
)
16128 or else not Is_Object
(Entity
(Exp
))
16130 Error_Pragma_Arg
("object name required", Arg
);
16134 exit when No
(Arg
);
16137 end Inspection_Point
;
16143 -- pragma Interface (
16144 -- [ Convention =>] convention_IDENTIFIER,
16145 -- [ Entity =>] LOCAL_NAME
16146 -- [, [External_Name =>] static_string_EXPRESSION ]
16147 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16149 when Pragma_Interface
=>
16154 Name_External_Name
,
16156 Check_At_Least_N_Arguments
(2);
16157 Check_At_Most_N_Arguments
(4);
16158 Process_Import_Or_Interface
;
16160 -- In Ada 2005, the permission to use Interface (a reserved word)
16161 -- as a pragma name is considered an obsolescent feature, and this
16162 -- pragma was already obsolescent in Ada 95.
16164 if Ada_Version
>= Ada_95
then
16166 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
16168 if Warn_On_Obsolescent_Feature
then
16170 ("pragma Interface is an obsolescent feature?j?", N
);
16172 ("|use pragma Import instead?j?", N
);
16176 --------------------
16177 -- Interface_Name --
16178 --------------------
16180 -- pragma Interface_Name (
16181 -- [ Entity =>] LOCAL_NAME
16182 -- [,[External_Name =>] static_string_EXPRESSION ]
16183 -- [,[Link_Name =>] static_string_EXPRESSION ]);
16185 when Pragma_Interface_Name
=> Interface_Name
: declare
16187 Def_Id
: Entity_Id
;
16188 Hom_Id
: Entity_Id
;
16194 ((Name_Entity
, Name_External_Name
, Name_Link_Name
));
16195 Check_At_Least_N_Arguments
(2);
16196 Check_At_Most_N_Arguments
(3);
16197 Id
:= Get_Pragma_Arg
(Arg1
);
16200 -- This is obsolete from Ada 95 on, but it is an implementation
16201 -- defined pragma, so we do not consider that it violates the
16202 -- restriction (No_Obsolescent_Features).
16204 if Ada_Version
>= Ada_95
then
16205 if Warn_On_Obsolescent_Feature
then
16207 ("pragma Interface_Name is an obsolescent feature?j?", N
);
16209 ("|use pragma Import instead?j?", N
);
16213 if not Is_Entity_Name
(Id
) then
16215 ("first argument for pragma% must be entity name", Arg1
);
16216 elsif Etype
(Id
) = Any_Type
then
16219 Def_Id
:= Entity
(Id
);
16222 -- Special DEC-compatible processing for the object case, forces
16223 -- object to be imported.
16225 if Ekind
(Def_Id
) = E_Variable
then
16226 Kill_Size_Check_Code
(Def_Id
);
16227 Note_Possible_Modification
(Id
, Sure
=> False);
16229 -- Initialization is not allowed for imported variable
16231 if Present
(Expression
(Parent
(Def_Id
)))
16232 and then Comes_From_Source
(Expression
(Parent
(Def_Id
)))
16234 Error_Msg_Sloc
:= Sloc
(Def_Id
);
16236 ("no initialization allowed for declaration of& #",
16240 -- For compatibility, support VADS usage of providing both
16241 -- pragmas Interface and Interface_Name to obtain the effect
16242 -- of a single Import pragma.
16244 if Is_Imported
(Def_Id
)
16245 and then Present
(First_Rep_Item
(Def_Id
))
16246 and then Nkind
(First_Rep_Item
(Def_Id
)) = N_Pragma
16248 Pragma_Name
(First_Rep_Item
(Def_Id
)) = Name_Interface
16252 Set_Imported
(Def_Id
);
16255 Set_Is_Public
(Def_Id
);
16256 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
16259 -- Otherwise must be subprogram
16261 elsif not Is_Subprogram
(Def_Id
) then
16263 ("argument of pragma% is not subprogram", Arg1
);
16266 Check_At_Most_N_Arguments
(3);
16270 -- Loop through homonyms
16273 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
16275 if Is_Imported
(Def_Id
) then
16276 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
16280 exit when From_Aspect_Specification
(N
);
16281 Hom_Id
:= Homonym
(Hom_Id
);
16283 exit when No
(Hom_Id
)
16284 or else Scope
(Hom_Id
) /= Current_Scope
;
16289 ("argument of pragma% is not imported subprogram",
16293 end Interface_Name
;
16295 -----------------------
16296 -- Interrupt_Handler --
16297 -----------------------
16299 -- pragma Interrupt_Handler (handler_NAME);
16301 when Pragma_Interrupt_Handler
=>
16302 Check_Ada_83_Warning
;
16303 Check_Arg_Count
(1);
16304 Check_No_Identifiers
;
16306 if No_Run_Time_Mode
then
16307 Error_Msg_CRT
("Interrupt_Handler pragma", N
);
16309 Check_Interrupt_Or_Attach_Handler
;
16310 Process_Interrupt_Or_Attach_Handler
;
16313 ------------------------
16314 -- Interrupt_Priority --
16315 ------------------------
16317 -- pragma Interrupt_Priority [(EXPRESSION)];
16319 when Pragma_Interrupt_Priority
=> Interrupt_Priority
: declare
16320 P
: constant Node_Id
:= Parent
(N
);
16325 Check_Ada_83_Warning
;
16327 if Arg_Count
/= 0 then
16328 Arg
:= Get_Pragma_Arg
(Arg1
);
16329 Check_Arg_Count
(1);
16330 Check_No_Identifiers
;
16332 -- The expression must be analyzed in the special manner
16333 -- described in "Handling of Default and Per-Object
16334 -- Expressions" in sem.ads.
16336 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Interrupt_Priority
));
16339 if not Nkind_In
(P
, N_Task_Definition
, N_Protected_Definition
) then
16344 Ent
:= Defining_Identifier
(Parent
(P
));
16346 -- Check duplicate pragma before we chain the pragma in the Rep
16347 -- Item chain of Ent.
16349 Check_Duplicate_Pragma
(Ent
);
16350 Record_Rep_Item
(Ent
, N
);
16352 -- Check the No_Task_At_Interrupt_Priority restriction
16354 if Nkind
(P
) = N_Task_Definition
then
16355 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
16358 end Interrupt_Priority
;
16360 ---------------------
16361 -- Interrupt_State --
16362 ---------------------
16364 -- pragma Interrupt_State (
16365 -- [Name =>] INTERRUPT_ID,
16366 -- [State =>] INTERRUPT_STATE);
16368 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
16369 -- INTERRUPT_STATE => System | Runtime | User
16371 -- Note: if the interrupt id is given as an identifier, then it must
16372 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
16373 -- given as a static integer expression which must be in the range of
16374 -- Ada.Interrupts.Interrupt_ID.
16376 when Pragma_Interrupt_State
=> Interrupt_State
: declare
16377 Int_Id
: constant Entity_Id
:= RTE
(RE_Interrupt_ID
);
16378 -- This is the entity Ada.Interrupts.Interrupt_ID;
16380 State_Type
: Character;
16381 -- Set to 's'/'r'/'u' for System/Runtime/User
16384 -- Index to entry in Interrupt_States table
16387 -- Value of interrupt
16389 Arg1X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
16390 -- The first argument to the pragma
16392 Int_Ent
: Entity_Id
;
16393 -- Interrupt entity in Ada.Interrupts.Names
16397 Check_Arg_Order
((Name_Name
, Name_State
));
16398 Check_Arg_Count
(2);
16400 Check_Optional_Identifier
(Arg1
, Name_Name
);
16401 Check_Optional_Identifier
(Arg2
, Name_State
);
16402 Check_Arg_Is_Identifier
(Arg2
);
16404 -- First argument is identifier
16406 if Nkind
(Arg1X
) = N_Identifier
then
16408 -- Search list of names in Ada.Interrupts.Names
16410 Int_Ent
:= First_Entity
(RTE
(RE_Names
));
16412 if No
(Int_Ent
) then
16413 Error_Pragma_Arg
("invalid interrupt name", Arg1
);
16415 elsif Chars
(Int_Ent
) = Chars
(Arg1X
) then
16416 Int_Val
:= Expr_Value
(Constant_Value
(Int_Ent
));
16420 Next_Entity
(Int_Ent
);
16423 -- First argument is not an identifier, so it must be a static
16424 -- expression of type Ada.Interrupts.Interrupt_ID.
16427 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
16428 Int_Val
:= Expr_Value
(Arg1X
);
16430 if Int_Val
< Expr_Value
(Type_Low_Bound
(Int_Id
))
16432 Int_Val
> Expr_Value
(Type_High_Bound
(Int_Id
))
16435 ("value not in range of type "
16436 & """Ada.Interrupts.Interrupt_'I'D""", Arg1
);
16442 case Chars
(Get_Pragma_Arg
(Arg2
)) is
16443 when Name_Runtime
=> State_Type
:= 'r';
16444 when Name_System
=> State_Type
:= 's';
16445 when Name_User
=> State_Type
:= 'u';
16448 Error_Pragma_Arg
("invalid interrupt state", Arg2
);
16451 -- Check if entry is already stored
16453 IST_Num
:= Interrupt_States
.First
;
16455 -- If entry not found, add it
16457 if IST_Num
> Interrupt_States
.Last
then
16458 Interrupt_States
.Append
16459 ((Interrupt_Number
=> UI_To_Int
(Int_Val
),
16460 Interrupt_State
=> State_Type
,
16461 Pragma_Loc
=> Loc
));
16464 -- Case of entry for the same entry
16466 elsif Int_Val
= Interrupt_States
.Table
(IST_Num
).
16469 -- If state matches, done, no need to make redundant entry
16472 State_Type
= Interrupt_States
.Table
(IST_Num
).
16475 -- Otherwise if state does not match, error
16478 Interrupt_States
.Table
(IST_Num
).Pragma_Loc
;
16480 ("state conflicts with that given #", Arg2
);
16484 IST_Num
:= IST_Num
+ 1;
16486 end Interrupt_State
;
16492 -- pragma Invariant
16493 -- ([Entity =>] type_LOCAL_NAME,
16494 -- [Check =>] EXPRESSION
16495 -- [,[Message =>] String_Expression]);
16497 when Pragma_Invariant
=> Invariant
: declare
16504 Check_At_Least_N_Arguments
(2);
16505 Check_At_Most_N_Arguments
(3);
16506 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16507 Check_Optional_Identifier
(Arg2
, Name_Check
);
16509 if Arg_Count
= 3 then
16510 Check_Optional_Identifier
(Arg3
, Name_Message
);
16511 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
16514 Check_Arg_Is_Local_Name
(Arg1
);
16516 Type_Id
:= Get_Pragma_Arg
(Arg1
);
16517 Find_Type
(Type_Id
);
16518 Typ
:= Entity
(Type_Id
);
16520 if Typ
= Any_Type
then
16523 -- Invariants allowed in interface types (RM 7.3.2(3/3))
16525 elsif Is_Interface
(Typ
) then
16528 -- An invariant must apply to a private type, or appear in the
16529 -- private part of a package spec and apply to a completion.
16530 -- a class-wide invariant can only appear on a private declaration
16531 -- or private extension, not a completion.
16533 elsif Ekind_In
(Typ
, E_Private_Type
,
16534 E_Record_Type_With_Private
,
16535 E_Limited_Private_Type
)
16539 elsif In_Private_Part
(Current_Scope
)
16540 and then Has_Private_Declaration
(Typ
)
16541 and then not Class_Present
(N
)
16545 elsif In_Private_Part
(Current_Scope
) then
16547 ("pragma% only allowed for private type declared in "
16548 & "visible part", Arg1
);
16552 ("pragma% only allowed for private type", Arg1
);
16555 -- A pragma that applies to a Ghost entity becomes Ghost for the
16556 -- purposes of legality checks and removal of ignored Ghost code.
16558 Mark_Pragma_As_Ghost
(N
, Typ
);
16560 -- Not allowed for abstract type in the non-class case (it is
16561 -- allowed to use Invariant'Class for abstract types).
16563 if Is_Abstract_Type
(Typ
) and then not Class_Present
(N
) then
16565 ("pragma% not allowed for abstract type", Arg1
);
16568 -- Link the pragma on to the rep item chain, for processing when
16569 -- the type is frozen.
16571 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
16573 -- Note that the type has at least one invariant, and also that
16574 -- it has inheritable invariants if we have Invariant'Class
16575 -- or Type_Invariant'Class. Build the corresponding invariant
16576 -- procedure declaration, so that calls to it can be generated
16577 -- before the body is built (e.g. within an expression function).
16579 -- Interface types have no invariant procedure; their invariants
16580 -- are propagated to the build invariant procedure of all the
16581 -- types covering the interface type.
16583 if not Is_Interface
(Typ
) then
16584 Insert_After_And_Analyze
16585 (N
, Build_Invariant_Procedure_Declaration
(Typ
));
16588 if Class_Present
(N
) then
16589 Set_Has_Inheritable_Invariants
(Typ
);
16597 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16599 when Pragma_Keep_Names
=> Keep_Names
: declare
16604 Check_Arg_Count
(1);
16605 Check_Optional_Identifier
(Arg1
, Name_On
);
16606 Check_Arg_Is_Local_Name
(Arg1
);
16608 Arg
:= Get_Pragma_Arg
(Arg1
);
16611 if Etype
(Arg
) = Any_Type
then
16615 if not Is_Entity_Name
(Arg
)
16616 or else Ekind
(Entity
(Arg
)) /= E_Enumeration_Type
16619 ("pragma% requires a local enumeration type", Arg1
);
16622 Set_Discard_Names
(Entity
(Arg
), False);
16629 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16631 when Pragma_License
=>
16634 -- Do not analyze pragma any further in CodePeer mode, to avoid
16635 -- extraneous errors in this implementation-dependent pragma,
16636 -- which has a different profile on other compilers.
16638 if CodePeer_Mode
then
16642 Check_Arg_Count
(1);
16643 Check_No_Identifiers
;
16644 Check_Valid_Configuration_Pragma
;
16645 Check_Arg_Is_Identifier
(Arg1
);
16648 Sind
: constant Source_File_Index
:=
16649 Source_Index
(Current_Sem_Unit
);
16652 case Chars
(Get_Pragma_Arg
(Arg1
)) is
16654 Set_License
(Sind
, GPL
);
16656 when Name_Modified_GPL
=>
16657 Set_License
(Sind
, Modified_GPL
);
16659 when Name_Restricted
=>
16660 Set_License
(Sind
, Restricted
);
16662 when Name_Unrestricted
=>
16663 Set_License
(Sind
, Unrestricted
);
16666 Error_Pragma_Arg
("invalid license name", Arg1
);
16674 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16676 when Pragma_Link_With
=> Link_With
: declare
16682 if Operating_Mode
= Generate_Code
16683 and then In_Extended_Main_Source_Unit
(N
)
16685 Check_At_Least_N_Arguments
(1);
16686 Check_No_Identifiers
;
16687 Check_Is_In_Decl_Part_Or_Package_Spec
;
16688 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16692 while Present
(Arg
) loop
16693 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
16695 -- Store argument, converting sequences of spaces to a
16696 -- single null character (this is one of the differences
16697 -- in processing between Link_With and Linker_Options).
16699 Arg_Store
: declare
16700 C
: constant Char_Code
:= Get_Char_Code
(' ');
16701 S
: constant String_Id
:=
16702 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
)));
16703 L
: constant Nat
:= String_Length
(S
);
16706 procedure Skip_Spaces
;
16707 -- Advance F past any spaces
16713 procedure Skip_Spaces
is
16715 while F
<= L
and then Get_String_Char
(S
, F
) = C
loop
16720 -- Start of processing for Arg_Store
16723 Skip_Spaces
; -- skip leading spaces
16725 -- Loop through characters, changing any embedded
16726 -- sequence of spaces to a single null character (this
16727 -- is how Link_With/Linker_Options differ)
16730 if Get_String_Char
(S
, F
) = C
then
16733 Store_String_Char
(ASCII
.NUL
);
16736 Store_String_Char
(Get_String_Char
(S
, F
));
16744 if Present
(Arg
) then
16745 Store_String_Char
(ASCII
.NUL
);
16749 Store_Linker_Option_String
(End_String
);
16757 -- pragma Linker_Alias (
16758 -- [Entity =>] LOCAL_NAME
16759 -- [Target =>] static_string_EXPRESSION);
16761 when Pragma_Linker_Alias
=>
16763 Check_Arg_Order
((Name_Entity
, Name_Target
));
16764 Check_Arg_Count
(2);
16765 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16766 Check_Optional_Identifier
(Arg2
, Name_Target
);
16767 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
16768 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16770 -- The only processing required is to link this item on to the
16771 -- list of rep items for the given entity. This is accomplished
16772 -- by the call to Rep_Item_Too_Late (when no error is detected
16773 -- and False is returned).
16775 if Rep_Item_Too_Late
(Entity
(Get_Pragma_Arg
(Arg1
)), N
) then
16778 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
16781 ------------------------
16782 -- Linker_Constructor --
16783 ------------------------
16785 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16787 -- Code is shared with Linker_Destructor
16789 -----------------------
16790 -- Linker_Destructor --
16791 -----------------------
16793 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16795 when Pragma_Linker_Constructor |
16796 Pragma_Linker_Destructor
=>
16797 Linker_Constructor
: declare
16803 Check_Arg_Count
(1);
16804 Check_No_Identifiers
;
16805 Check_Arg_Is_Local_Name
(Arg1
);
16806 Arg1_X
:= Get_Pragma_Arg
(Arg1
);
16808 Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
16810 if not Is_Library_Level_Entity
(Proc
) then
16812 ("argument for pragma% must be library level entity", Arg1
);
16815 -- The only processing required is to link this item on to the
16816 -- list of rep items for the given entity. This is accomplished
16817 -- by the call to Rep_Item_Too_Late (when no error is detected
16818 -- and False is returned).
16820 if Rep_Item_Too_Late
(Proc
, N
) then
16823 Set_Has_Gigi_Rep_Item
(Proc
);
16825 end Linker_Constructor
;
16827 --------------------
16828 -- Linker_Options --
16829 --------------------
16831 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16833 when Pragma_Linker_Options
=> Linker_Options
: declare
16837 Check_Ada_83_Warning
;
16838 Check_No_Identifiers
;
16839 Check_Arg_Count
(1);
16840 Check_Is_In_Decl_Part_Or_Package_Spec
;
16841 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16842 Start_String
(Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg1
))));
16845 while Present
(Arg
) loop
16846 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
16847 Store_String_Char
(ASCII
.NUL
);
16849 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
16853 if Operating_Mode
= Generate_Code
16854 and then In_Extended_Main_Source_Unit
(N
)
16856 Store_Linker_Option_String
(End_String
);
16858 end Linker_Options
;
16860 --------------------
16861 -- Linker_Section --
16862 --------------------
16864 -- pragma Linker_Section (
16865 -- [Entity =>] LOCAL_NAME
16866 -- [Section =>] static_string_EXPRESSION);
16868 when Pragma_Linker_Section
=> Linker_Section
: declare
16873 Ghost_Error_Posted
: Boolean := False;
16874 -- Flag set when an error concerning the illegal mix of Ghost and
16875 -- non-Ghost subprograms is emitted.
16877 Ghost_Id
: Entity_Id
:= Empty
;
16878 -- The entity of the first Ghost subprogram encountered while
16879 -- processing the arguments of the pragma.
16883 Check_Arg_Order
((Name_Entity
, Name_Section
));
16884 Check_Arg_Count
(2);
16885 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16886 Check_Optional_Identifier
(Arg2
, Name_Section
);
16887 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
16888 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16890 -- Check kind of entity
16892 Arg
:= Get_Pragma_Arg
(Arg1
);
16893 Ent
:= Entity
(Arg
);
16895 case Ekind
(Ent
) is
16897 -- Objects (constants and variables) and types. For these cases
16898 -- all we need to do is to set the Linker_Section_pragma field,
16899 -- checking that we do not have a duplicate.
16901 when E_Constant | E_Variable | Type_Kind
=>
16902 LPE
:= Linker_Section_Pragma
(Ent
);
16904 if Present
(LPE
) then
16905 Error_Msg_Sloc
:= Sloc
(LPE
);
16907 ("Linker_Section already specified for &#", Arg1
, Ent
);
16910 Set_Linker_Section_Pragma
(Ent
, N
);
16912 -- A pragma that applies to a Ghost entity becomes Ghost for
16913 -- the purposes of legality checks and removal of ignored
16916 Mark_Pragma_As_Ghost
(N
, Ent
);
16920 when Subprogram_Kind
=>
16922 -- Aspect case, entity already set
16924 if From_Aspect_Specification
(N
) then
16925 Set_Linker_Section_Pragma
16926 (Entity
(Corresponding_Aspect
(N
)), N
);
16928 -- Pragma case, we must climb the homonym chain, but skip
16929 -- any for which the linker section is already set.
16933 if No
(Linker_Section_Pragma
(Ent
)) then
16934 Set_Linker_Section_Pragma
(Ent
, N
);
16936 -- A pragma that applies to a Ghost entity becomes
16937 -- Ghost for the purposes of legality checks and
16938 -- removal of ignored Ghost code.
16940 Mark_Pragma_As_Ghost
(N
, Ent
);
16942 -- Capture the entity of the first Ghost subprogram
16943 -- being processed for error detection purposes.
16945 if Is_Ghost_Entity
(Ent
) then
16946 if No
(Ghost_Id
) then
16950 -- Otherwise the subprogram is non-Ghost. It is
16951 -- illegal to mix references to Ghost and non-Ghost
16952 -- entities (SPARK RM 6.9).
16954 elsif Present
(Ghost_Id
)
16955 and then not Ghost_Error_Posted
16957 Ghost_Error_Posted
:= True;
16959 Error_Msg_Name_1
:= Pname
;
16961 ("pragma % cannot mention ghost and "
16962 & "non-ghost subprograms", N
);
16964 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
16966 ("\& # declared as ghost", N
, Ghost_Id
);
16968 Error_Msg_Sloc
:= Sloc
(Ent
);
16970 ("\& # declared as non-ghost", N
, Ent
);
16974 Ent
:= Homonym
(Ent
);
16976 or else Scope
(Ent
) /= Current_Scope
;
16980 -- All other cases are illegal
16984 ("pragma% applies only to objects, subprograms, and types",
16987 end Linker_Section
;
16993 -- pragma List (On | Off)
16995 -- There is nothing to do here, since we did all the processing for
16996 -- this pragma in Par.Prag (so that it works properly even in syntax
16999 when Pragma_List
=>
17006 -- pragma Lock_Free [(Boolean_EXPRESSION)];
17008 when Pragma_Lock_Free
=> Lock_Free
: declare
17009 P
: constant Node_Id
:= Parent
(N
);
17015 Check_No_Identifiers
;
17016 Check_At_Most_N_Arguments
(1);
17018 -- Protected definition case
17020 if Nkind
(P
) = N_Protected_Definition
then
17021 Ent
:= Defining_Identifier
(Parent
(P
));
17025 if Arg_Count
= 1 then
17026 Arg
:= Get_Pragma_Arg
(Arg1
);
17027 Val
:= Is_True
(Static_Boolean
(Arg
));
17029 -- No arguments (expression is considered to be True)
17035 -- Check duplicate pragma before we chain the pragma in the Rep
17036 -- Item chain of Ent.
17038 Check_Duplicate_Pragma
(Ent
);
17039 Record_Rep_Item
(Ent
, N
);
17040 Set_Uses_Lock_Free
(Ent
, Val
);
17042 -- Anything else is incorrect placement
17049 --------------------
17050 -- Locking_Policy --
17051 --------------------
17053 -- pragma Locking_Policy (policy_IDENTIFIER);
17055 when Pragma_Locking_Policy
=> declare
17056 subtype LP_Range
is Name_Id
17057 range First_Locking_Policy_Name
.. Last_Locking_Policy_Name
;
17062 Check_Ada_83_Warning
;
17063 Check_Arg_Count
(1);
17064 Check_No_Identifiers
;
17065 Check_Arg_Is_Locking_Policy
(Arg1
);
17066 Check_Valid_Configuration_Pragma
;
17067 LP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
17070 when Name_Ceiling_Locking
=>
17072 when Name_Inheritance_Locking
=>
17074 when Name_Concurrent_Readers_Locking
=>
17078 if Locking_Policy
/= ' '
17079 and then Locking_Policy
/= LP
17081 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
17082 Error_Pragma
("locking policy incompatible with policy#");
17084 -- Set new policy, but always preserve System_Location since we
17085 -- like the error message with the run time name.
17088 Locking_Policy
:= LP
;
17090 if Locking_Policy_Sloc
/= System_Location
then
17091 Locking_Policy_Sloc
:= Loc
;
17096 -------------------
17097 -- Loop_Optimize --
17098 -------------------
17100 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
17102 -- OPTIMIZATION_HINT ::=
17103 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
17105 when Pragma_Loop_Optimize
=> Loop_Optimize
: declare
17110 Check_At_Least_N_Arguments
(1);
17111 Check_No_Identifiers
;
17113 Hint
:= First
(Pragma_Argument_Associations
(N
));
17114 while Present
(Hint
) loop
17115 Check_Arg_Is_One_Of
(Hint
, Name_Ivdep
,
17123 Check_Loop_Pragma_Placement
;
17130 -- pragma Loop_Variant
17131 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
17133 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
17135 -- CHANGE_DIRECTION ::= Increases | Decreases
17137 when Pragma_Loop_Variant
=> Loop_Variant
: declare
17142 Check_At_Least_N_Arguments
(1);
17143 Check_Loop_Pragma_Placement
;
17145 -- Process all increasing / decreasing expressions
17147 Variant
:= First
(Pragma_Argument_Associations
(N
));
17148 while Present
(Variant
) loop
17149 if not Nam_In
(Chars
(Variant
), Name_Decreases
,
17152 Error_Pragma_Arg
("wrong change modifier", Variant
);
17155 Preanalyze_Assert_Expression
17156 (Expression
(Variant
), Any_Discrete
);
17162 -----------------------
17163 -- Machine_Attribute --
17164 -----------------------
17166 -- pragma Machine_Attribute (
17167 -- [Entity =>] LOCAL_NAME,
17168 -- [Attribute_Name =>] static_string_EXPRESSION
17169 -- [, [Info =>] static_EXPRESSION] );
17171 when Pragma_Machine_Attribute
=> Machine_Attribute
: declare
17172 Def_Id
: Entity_Id
;
17176 Check_Arg_Order
((Name_Entity
, Name_Attribute_Name
, Name_Info
));
17178 if Arg_Count
= 3 then
17179 Check_Optional_Identifier
(Arg3
, Name_Info
);
17180 Check_Arg_Is_OK_Static_Expression
(Arg3
);
17182 Check_Arg_Count
(2);
17185 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17186 Check_Optional_Identifier
(Arg2
, Name_Attribute_Name
);
17187 Check_Arg_Is_Local_Name
(Arg1
);
17188 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
17189 Def_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
17191 if Is_Access_Type
(Def_Id
) then
17192 Def_Id
:= Designated_Type
(Def_Id
);
17195 if Rep_Item_Too_Early
(Def_Id
, N
) then
17199 Def_Id
:= Underlying_Type
(Def_Id
);
17201 -- The only processing required is to link this item on to the
17202 -- list of rep items for the given entity. This is accomplished
17203 -- by the call to Rep_Item_Too_Late (when no error is detected
17204 -- and False is returned).
17206 if Rep_Item_Too_Late
(Def_Id
, N
) then
17209 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
17211 end Machine_Attribute
;
17218 -- (MAIN_OPTION [, MAIN_OPTION]);
17221 -- [STACK_SIZE =>] static_integer_EXPRESSION
17222 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
17223 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
17225 when Pragma_Main
=> Main
: declare
17226 Args
: Args_List
(1 .. 3);
17227 Names
: constant Name_List
(1 .. 3) := (
17229 Name_Task_Stack_Size_Default
,
17230 Name_Time_Slicing_Enabled
);
17236 Gather_Associations
(Names
, Args
);
17238 for J
in 1 .. 2 loop
17239 if Present
(Args
(J
)) then
17240 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
17244 if Present
(Args
(3)) then
17245 Check_Arg_Is_OK_Static_Expression
(Args
(3), Standard_Boolean
);
17249 while Present
(Nod
) loop
17250 if Nkind
(Nod
) = N_Pragma
17251 and then Pragma_Name
(Nod
) = Name_Main
17253 Error_Msg_Name_1
:= Pname
;
17254 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
17265 -- pragma Main_Storage
17266 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
17268 -- MAIN_STORAGE_OPTION ::=
17269 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
17270 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
17272 when Pragma_Main_Storage
=> Main_Storage
: declare
17273 Args
: Args_List
(1 .. 2);
17274 Names
: constant Name_List
(1 .. 2) := (
17275 Name_Working_Storage
,
17282 Gather_Associations
(Names
, Args
);
17284 for J
in 1 .. 2 loop
17285 if Present
(Args
(J
)) then
17286 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
17290 Check_In_Main_Program
;
17293 while Present
(Nod
) loop
17294 if Nkind
(Nod
) = N_Pragma
17295 and then Pragma_Name
(Nod
) = Name_Main_Storage
17297 Error_Msg_Name_1
:= Pname
;
17298 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
17309 -- pragma Memory_Size (NUMERIC_LITERAL)
17311 when Pragma_Memory_Size
=>
17314 -- Memory size is simply ignored
17316 Check_No_Identifiers
;
17317 Check_Arg_Count
(1);
17318 Check_Arg_Is_Integer_Literal
(Arg1
);
17326 -- The only correct use of this pragma is on its own in a file, in
17327 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
17328 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
17329 -- check for a file containing nothing but a No_Body pragma). If we
17330 -- attempt to process it during normal semantics processing, it means
17331 -- it was misplaced.
17333 when Pragma_No_Body
=>
17337 -----------------------------
17338 -- No_Elaboration_Code_All --
17339 -----------------------------
17341 -- pragma No_Elaboration_Code_All;
17343 when Pragma_No_Elaboration_Code_All
=>
17345 Check_Valid_Library_Unit_Pragma
;
17347 if Nkind
(N
) = N_Null_Statement
then
17351 -- Must appear for a spec or generic spec
17353 if not Nkind_In
(Unit
(Cunit
(Current_Sem_Unit
)),
17354 N_Generic_Package_Declaration
,
17355 N_Generic_Subprogram_Declaration
,
17356 N_Package_Declaration
,
17357 N_Subprogram_Declaration
)
17361 ("pragma% can only occur for package "
17362 & "or subprogram spec"));
17365 -- Set flag in unit table
17367 Set_No_Elab_Code_All
(Current_Sem_Unit
);
17369 -- Set restriction No_Elaboration_Code if this is the main unit
17371 if Current_Sem_Unit
= Main_Unit
then
17372 Set_Restriction
(No_Elaboration_Code
, N
);
17375 -- If we are in the main unit or in an extended main source unit,
17376 -- then we also add it to the configuration restrictions so that
17377 -- it will apply to all units in the extended main source.
17379 if Current_Sem_Unit
= Main_Unit
17380 or else In_Extended_Main_Source_Unit
(N
)
17382 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
17385 -- If in main extended unit, activate transitive with test
17387 if In_Extended_Main_Source_Unit
(N
) then
17388 Opt
.No_Elab_Code_All_Pragma
:= N
;
17395 -- pragma No_Inline ( NAME {, NAME} );
17397 when Pragma_No_Inline
=>
17399 Process_Inline
(Suppressed
);
17405 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
17407 when Pragma_No_Return
=> No_Return
: declare
17413 Ghost_Error_Posted
: Boolean := False;
17414 -- Flag set when an error concerning the illegal mix of Ghost and
17415 -- non-Ghost subprograms is emitted.
17417 Ghost_Id
: Entity_Id
:= Empty
;
17418 -- The entity of the first Ghost procedure encountered while
17419 -- processing the arguments of the pragma.
17423 Check_At_Least_N_Arguments
(1);
17425 -- Loop through arguments of pragma
17428 while Present
(Arg
) loop
17429 Check_Arg_Is_Local_Name
(Arg
);
17430 Id
:= Get_Pragma_Arg
(Arg
);
17433 if not Is_Entity_Name
(Id
) then
17434 Error_Pragma_Arg
("entity name required", Arg
);
17437 if Etype
(Id
) = Any_Type
then
17441 -- Loop to find matching procedures
17447 and then Scope
(E
) = Current_Scope
17449 if Ekind_In
(E
, E_Procedure
, E_Generic_Procedure
) then
17452 -- A pragma that applies to a Ghost entity becomes Ghost
17453 -- for the purposes of legality checks and removal of
17454 -- ignored Ghost code.
17456 Mark_Pragma_As_Ghost
(N
, E
);
17458 -- Capture the entity of the first Ghost procedure being
17459 -- processed for error detection purposes.
17461 if Is_Ghost_Entity
(E
) then
17462 if No
(Ghost_Id
) then
17466 -- Otherwise the subprogram is non-Ghost. It is illegal
17467 -- to mix references to Ghost and non-Ghost entities
17470 elsif Present
(Ghost_Id
)
17471 and then not Ghost_Error_Posted
17473 Ghost_Error_Posted
:= True;
17475 Error_Msg_Name_1
:= Pname
;
17477 ("pragma % cannot mention ghost and non-ghost "
17478 & "procedures", N
);
17480 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
17481 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
17483 Error_Msg_Sloc
:= Sloc
(E
);
17484 Error_Msg_NE
("\& # declared as non-ghost", N
, E
);
17487 -- Set flag on any alias as well
17489 if Is_Overloadable
(E
) and then Present
(Alias
(E
)) then
17490 Set_No_Return
(Alias
(E
));
17496 exit when From_Aspect_Specification
(N
);
17500 -- If entity in not in current scope it may be the enclosing
17501 -- suprogram body to which the aspect applies.
17504 if Entity
(Id
) = Current_Scope
17505 and then From_Aspect_Specification
(N
)
17507 Set_No_Return
(Entity
(Id
));
17509 Error_Pragma_Arg
("no procedure& found for pragma%", Arg
);
17521 -- pragma No_Run_Time;
17523 -- Note: this pragma is retained for backwards compatibility. See
17524 -- body of Rtsfind for full details on its handling.
17526 when Pragma_No_Run_Time
=>
17528 Check_Valid_Configuration_Pragma
;
17529 Check_Arg_Count
(0);
17531 No_Run_Time_Mode
:= True;
17532 Configurable_Run_Time_Mode
:= True;
17534 -- Set Duration to 32 bits if word size is 32
17536 if Ttypes
.System_Word_Size
= 32 then
17537 Duration_32_Bits_On_Target
:= True;
17540 -- Set appropriate restrictions
17542 Set_Restriction
(No_Finalization
, N
);
17543 Set_Restriction
(No_Exception_Handlers
, N
);
17544 Set_Restriction
(Max_Tasks
, N
, 0);
17545 Set_Restriction
(No_Tasking
, N
);
17547 -----------------------
17548 -- No_Tagged_Streams --
17549 -----------------------
17551 -- pragma No_Tagged_Streams;
17552 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
17554 when Pragma_No_Tagged_Streams
=> No_Tagged_Strms
: declare
17560 Check_At_Most_N_Arguments
(1);
17562 -- One argument case
17564 if Arg_Count
= 1 then
17565 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17566 Check_Arg_Is_Local_Name
(Arg1
);
17567 E_Id
:= Get_Pragma_Arg
(Arg1
);
17569 if Etype
(E_Id
) = Any_Type
then
17573 E
:= Entity
(E_Id
);
17575 Check_Duplicate_Pragma
(E
);
17577 if not Is_Tagged_Type
(E
) or else Is_Derived_Type
(E
) then
17579 ("argument for pragma% must be root tagged type", Arg1
);
17582 if Rep_Item_Too_Early
(E
, N
)
17584 Rep_Item_Too_Late
(E
, N
)
17588 Set_No_Tagged_Streams_Pragma
(E
, N
);
17591 -- Zero argument case
17594 Check_Is_In_Decl_Part_Or_Package_Spec
;
17595 No_Tagged_Streams
:= N
;
17597 end No_Tagged_Strms
;
17599 ------------------------
17600 -- No_Strict_Aliasing --
17601 ------------------------
17603 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
17605 when Pragma_No_Strict_Aliasing
=> No_Strict_Aliasing
: declare
17610 Check_At_Most_N_Arguments
(1);
17612 if Arg_Count
= 0 then
17613 Check_Valid_Configuration_Pragma
;
17614 Opt
.No_Strict_Aliasing
:= True;
17617 Check_Optional_Identifier
(Arg2
, Name_Entity
);
17618 Check_Arg_Is_Local_Name
(Arg1
);
17619 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
17621 if E_Id
= Any_Type
then
17623 elsif No
(E_Id
) or else not Is_Access_Type
(E_Id
) then
17624 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
17627 Set_No_Strict_Aliasing
(Implementation_Base_Type
(E_Id
));
17629 end No_Strict_Aliasing
;
17631 -----------------------
17632 -- Normalize_Scalars --
17633 -----------------------
17635 -- pragma Normalize_Scalars;
17637 when Pragma_Normalize_Scalars
=>
17638 Check_Ada_83_Warning
;
17639 Check_Arg_Count
(0);
17640 Check_Valid_Configuration_Pragma
;
17642 -- Normalize_Scalars creates false positives in CodePeer, and
17643 -- incorrect negative results in GNATprove mode, so ignore this
17644 -- pragma in these modes.
17646 if not (CodePeer_Mode
or GNATprove_Mode
) then
17647 Normalize_Scalars
:= True;
17648 Init_Or_Norm_Scalars
:= True;
17655 -- pragma Obsolescent;
17657 -- pragma Obsolescent (
17658 -- [Message =>] static_string_EXPRESSION
17659 -- [,[Version =>] Ada_05]]);
17661 -- pragma Obsolescent (
17662 -- [Entity =>] NAME
17663 -- [,[Message =>] static_string_EXPRESSION
17664 -- [,[Version =>] Ada_05]] );
17666 when Pragma_Obsolescent
=> Obsolescent
: declare
17670 procedure Set_Obsolescent
(E
: Entity_Id
);
17671 -- Given an entity Ent, mark it as obsolescent if appropriate
17673 ---------------------
17674 -- Set_Obsolescent --
17675 ---------------------
17677 procedure Set_Obsolescent
(E
: Entity_Id
) is
17686 -- A pragma that applies to a Ghost entity becomes Ghost for
17687 -- the purposes of legality checks and removal of ignored Ghost
17690 Mark_Pragma_As_Ghost
(N
, E
);
17692 -- Entity name was given
17694 if Present
(Ename
) then
17696 -- If entity name matches, we are fine. Save entity in
17697 -- pragma argument, for ASIS use.
17699 if Chars
(Ename
) = Chars
(Ent
) then
17700 Set_Entity
(Ename
, Ent
);
17701 Generate_Reference
(Ent
, Ename
);
17703 -- If entity name does not match, only possibility is an
17704 -- enumeration literal from an enumeration type declaration.
17706 elsif Ekind
(Ent
) /= E_Enumeration_Type
then
17708 ("pragma % entity name does not match declaration");
17711 Ent
:= First_Literal
(E
);
17715 ("pragma % entity name does not match any "
17716 & "enumeration literal");
17718 elsif Chars
(Ent
) = Chars
(Ename
) then
17719 Set_Entity
(Ename
, Ent
);
17720 Generate_Reference
(Ent
, Ename
);
17724 Ent
:= Next_Literal
(Ent
);
17730 -- Ent points to entity to be marked
17732 if Arg_Count
>= 1 then
17734 -- Deal with static string argument
17736 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
17737 S
:= Strval
(Get_Pragma_Arg
(Arg1
));
17739 for J
in 1 .. String_Length
(S
) loop
17740 if not In_Character_Range
(Get_String_Char
(S
, J
)) then
17742 ("pragma% argument does not allow wide characters",
17747 Obsolescent_Warnings
.Append
17748 ((Ent
=> Ent
, Msg
=> Strval
(Get_Pragma_Arg
(Arg1
))));
17750 -- Check for Ada_05 parameter
17752 if Arg_Count
/= 1 then
17753 Check_Arg_Count
(2);
17756 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
17759 Check_Arg_Is_Identifier
(Argx
);
17761 if Chars
(Argx
) /= Name_Ada_05
then
17762 Error_Msg_Name_2
:= Name_Ada_05
;
17764 ("only allowed argument for pragma% is %", Argx
);
17767 if Ada_Version_Explicit
< Ada_2005
17768 or else not Warn_On_Ada_2005_Compatibility
17776 -- Set flag if pragma active
17779 Set_Is_Obsolescent
(Ent
);
17783 end Set_Obsolescent
;
17785 -- Start of processing for pragma Obsolescent
17790 Check_At_Most_N_Arguments
(3);
17792 -- See if first argument specifies an entity name
17796 (Chars
(Arg1
) = Name_Entity
17798 Nkind_In
(Get_Pragma_Arg
(Arg1
), N_Character_Literal
,
17800 N_Operator_Symbol
))
17802 Ename
:= Get_Pragma_Arg
(Arg1
);
17804 -- Eliminate first argument, so we can share processing
17808 Arg_Count
:= Arg_Count
- 1;
17810 -- No Entity name argument given
17816 if Arg_Count
>= 1 then
17817 Check_Optional_Identifier
(Arg1
, Name_Message
);
17819 if Arg_Count
= 2 then
17820 Check_Optional_Identifier
(Arg2
, Name_Version
);
17824 -- Get immediately preceding declaration
17827 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
17831 -- Cases where we do not follow anything other than another pragma
17835 -- First case: library level compilation unit declaration with
17836 -- the pragma immediately following the declaration.
17838 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
17840 (Defining_Entity
(Unit
(Parent
(Parent
(N
)))));
17843 -- Case 2: library unit placement for package
17847 Ent
: constant Entity_Id
:= Find_Lib_Unit_Name
;
17849 if Is_Package_Or_Generic_Package
(Ent
) then
17850 Set_Obsolescent
(Ent
);
17856 -- Cases where we must follow a declaration, including an
17857 -- abstract subprogram declaration, which is not in the
17858 -- other node subtypes.
17861 if Nkind
(Decl
) not in N_Declaration
17862 and then Nkind
(Decl
) not in N_Later_Decl_Item
17863 and then Nkind
(Decl
) not in N_Generic_Declaration
17864 and then Nkind
(Decl
) not in N_Renaming_Declaration
17865 and then Nkind
(Decl
) /= N_Abstract_Subprogram_Declaration
17868 ("pragma% misplaced, "
17869 & "must immediately follow a declaration");
17872 Set_Obsolescent
(Defining_Entity
(Decl
));
17882 -- pragma Optimize (Time | Space | Off);
17884 -- The actual check for optimize is done in Gigi. Note that this
17885 -- pragma does not actually change the optimization setting, it
17886 -- simply checks that it is consistent with the pragma.
17888 when Pragma_Optimize
=>
17889 Check_No_Identifiers
;
17890 Check_Arg_Count
(1);
17891 Check_Arg_Is_One_Of
(Arg1
, Name_Time
, Name_Space
, Name_Off
);
17893 ------------------------
17894 -- Optimize_Alignment --
17895 ------------------------
17897 -- pragma Optimize_Alignment (Time | Space | Off);
17899 when Pragma_Optimize_Alignment
=> Optimize_Alignment
: begin
17901 Check_No_Identifiers
;
17902 Check_Arg_Count
(1);
17903 Check_Valid_Configuration_Pragma
;
17906 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
17910 Opt
.Optimize_Alignment
:= 'T';
17912 Opt
.Optimize_Alignment
:= 'S';
17914 Opt
.Optimize_Alignment
:= 'O';
17916 Error_Pragma_Arg
("invalid argument for pragma%", Arg1
);
17920 -- Set indication that mode is set locally. If we are in fact in a
17921 -- configuration pragma file, this setting is harmless since the
17922 -- switch will get reset anyway at the start of each unit.
17924 Optimize_Alignment_Local
:= True;
17925 end Optimize_Alignment
;
17931 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17933 when Pragma_Ordered
=> Ordered
: declare
17934 Assoc
: constant Node_Id
:= Arg1
;
17940 Check_No_Identifiers
;
17941 Check_Arg_Count
(1);
17942 Check_Arg_Is_Local_Name
(Arg1
);
17944 Type_Id
:= Get_Pragma_Arg
(Assoc
);
17945 Find_Type
(Type_Id
);
17946 Typ
:= Entity
(Type_Id
);
17948 if Typ
= Any_Type
then
17951 Typ
:= Underlying_Type
(Typ
);
17954 if not Is_Enumeration_Type
(Typ
) then
17955 Error_Pragma
("pragma% must specify enumeration type");
17958 Check_First_Subtype
(Arg1
);
17959 Set_Has_Pragma_Ordered
(Base_Type
(Typ
));
17962 -------------------
17963 -- Overflow_Mode --
17964 -------------------
17966 -- pragma Overflow_Mode
17967 -- ([General => ] MODE [, [Assertions => ] MODE]);
17969 -- MODE := STRICT | MINIMIZED | ELIMINATED
17971 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17972 -- since System.Bignums makes this assumption. This is true of nearly
17973 -- all (all?) targets.
17975 when Pragma_Overflow_Mode
=> Overflow_Mode
: declare
17976 function Get_Overflow_Mode
17978 Arg
: Node_Id
) return Overflow_Mode_Type
;
17979 -- Function to process one pragma argument, Arg. If an identifier
17980 -- is present, it must be Name. Mode type is returned if a valid
17981 -- argument exists, otherwise an error is signalled.
17983 -----------------------
17984 -- Get_Overflow_Mode --
17985 -----------------------
17987 function Get_Overflow_Mode
17989 Arg
: Node_Id
) return Overflow_Mode_Type
17991 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
17994 Check_Optional_Identifier
(Arg
, Name
);
17995 Check_Arg_Is_Identifier
(Argx
);
17997 if Chars
(Argx
) = Name_Strict
then
18000 elsif Chars
(Argx
) = Name_Minimized
then
18003 elsif Chars
(Argx
) = Name_Eliminated
then
18004 if Ttypes
.Standard_Long_Long_Integer_Size
/= 64 then
18006 ("Eliminated not implemented on this target", Argx
);
18012 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
18014 end Get_Overflow_Mode
;
18016 -- Start of processing for Overflow_Mode
18020 Check_At_Least_N_Arguments
(1);
18021 Check_At_Most_N_Arguments
(2);
18023 -- Process first argument
18025 Scope_Suppress
.Overflow_Mode_General
:=
18026 Get_Overflow_Mode
(Name_General
, Arg1
);
18028 -- Case of only one argument
18030 if Arg_Count
= 1 then
18031 Scope_Suppress
.Overflow_Mode_Assertions
:=
18032 Scope_Suppress
.Overflow_Mode_General
;
18034 -- Case of two arguments present
18037 Scope_Suppress
.Overflow_Mode_Assertions
:=
18038 Get_Overflow_Mode
(Name_Assertions
, Arg2
);
18042 --------------------------
18043 -- Overriding Renamings --
18044 --------------------------
18046 -- pragma Overriding_Renamings;
18048 when Pragma_Overriding_Renamings
=>
18050 Check_Arg_Count
(0);
18051 Check_Valid_Configuration_Pragma
;
18052 Overriding_Renamings
:= True;
18058 -- pragma Pack (first_subtype_LOCAL_NAME);
18060 when Pragma_Pack
=> Pack
: declare
18061 Assoc
: constant Node_Id
:= Arg1
;
18063 Ignore
: Boolean := False;
18068 Check_No_Identifiers
;
18069 Check_Arg_Count
(1);
18070 Check_Arg_Is_Local_Name
(Arg1
);
18071 Type_Id
:= Get_Pragma_Arg
(Assoc
);
18073 if not Is_Entity_Name
(Type_Id
)
18074 or else not Is_Type
(Entity
(Type_Id
))
18077 ("argument for pragma% must be type or subtype", Arg1
);
18080 Find_Type
(Type_Id
);
18081 Typ
:= Entity
(Type_Id
);
18084 or else Rep_Item_Too_Early
(Typ
, N
)
18088 Typ
:= Underlying_Type
(Typ
);
18091 -- A pragma that applies to a Ghost entity becomes Ghost for the
18092 -- purposes of legality checks and removal of ignored Ghost code.
18094 Mark_Pragma_As_Ghost
(N
, Typ
);
18096 if not Is_Array_Type
(Typ
) and then not Is_Record_Type
(Typ
) then
18097 Error_Pragma
("pragma% must specify array or record type");
18100 Check_First_Subtype
(Arg1
);
18101 Check_Duplicate_Pragma
(Typ
);
18105 if Is_Array_Type
(Typ
) then
18106 Ctyp
:= Component_Type
(Typ
);
18108 -- Ignore pack that does nothing
18110 if Known_Static_Esize
(Ctyp
)
18111 and then Known_Static_RM_Size
(Ctyp
)
18112 and then Esize
(Ctyp
) = RM_Size
(Ctyp
)
18113 and then Addressable
(Esize
(Ctyp
))
18118 -- Process OK pragma Pack. Note that if there is a separate
18119 -- component clause present, the Pack will be cancelled. This
18120 -- processing is in Freeze.
18122 if not Rep_Item_Too_Late
(Typ
, N
) then
18124 -- In CodePeer mode, we do not need complex front-end
18125 -- expansions related to pragma Pack, so disable handling
18128 if CodePeer_Mode
then
18131 -- Normal case where we do the pack action
18135 Set_Is_Packed
(Base_Type
(Typ
));
18136 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
18139 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
18143 -- For record types, the pack is always effective
18145 else pragma Assert
(Is_Record_Type
(Typ
));
18146 if not Rep_Item_Too_Late
(Typ
, N
) then
18147 Set_Is_Packed
(Base_Type
(Typ
));
18148 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
18149 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
18160 -- There is nothing to do here, since we did all the processing for
18161 -- this pragma in Par.Prag (so that it works properly even in syntax
18164 when Pragma_Page
=>
18171 -- pragma Part_Of (ABSTRACT_STATE);
18173 -- ABSTRACT_STATE ::= NAME
18175 when Pragma_Part_Of
=> Part_Of
: declare
18176 procedure Propagate_Part_Of
18177 (Pack_Id
: Entity_Id
;
18178 State_Id
: Entity_Id
;
18179 Instance
: Node_Id
);
18180 -- Propagate the Part_Of indicator to all abstract states and
18181 -- objects declared in the visible state space of a package
18182 -- denoted by Pack_Id. State_Id is the encapsulating state.
18183 -- Instance is the package instantiation node.
18185 -----------------------
18186 -- Propagate_Part_Of --
18187 -----------------------
18189 procedure Propagate_Part_Of
18190 (Pack_Id
: Entity_Id
;
18191 State_Id
: Entity_Id
;
18192 Instance
: Node_Id
)
18194 Has_Item
: Boolean := False;
18195 -- Flag set when the visible state space contains at least one
18196 -- abstract state or variable.
18198 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
);
18199 -- Propagate the Part_Of indicator to all abstract states and
18200 -- objects declared in the visible state space of a package
18201 -- denoted by Pack_Id.
18203 -----------------------
18204 -- Propagate_Part_Of --
18205 -----------------------
18207 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
) is
18208 Constits
: Elist_Id
;
18209 Item_Id
: Entity_Id
;
18212 -- Traverse the entity chain of the package and set relevant
18213 -- attributes of abstract states and objects declared in the
18214 -- visible state space of the package.
18216 Item_Id
:= First_Entity
(Pack_Id
);
18217 while Present
(Item_Id
)
18218 and then not In_Private_Part
(Item_Id
)
18220 -- Do not consider internally generated items
18222 if not Comes_From_Source
(Item_Id
) then
18225 -- The Part_Of indicator turns an abstract state or an
18226 -- object into a constituent of the encapsulating state.
18228 elsif Ekind_In
(Item_Id
, E_Abstract_State
,
18233 Constits
:= Part_Of_Constituents
(State_Id
);
18235 if No
(Constits
) then
18236 Constits
:= New_Elmt_List
;
18237 Set_Part_Of_Constituents
(State_Id
, Constits
);
18240 Append_Elmt
(Item_Id
, Constits
);
18241 Set_Encapsulating_State
(Item_Id
, State_Id
);
18243 -- Recursively handle nested packages and instantiations
18245 elsif Ekind
(Item_Id
) = E_Package
then
18246 Propagate_Part_Of
(Item_Id
);
18249 Next_Entity
(Item_Id
);
18251 end Propagate_Part_Of
;
18253 -- Start of processing for Propagate_Part_Of
18256 Propagate_Part_Of
(Pack_Id
);
18258 -- Detect a package instantiation that is subject to a Part_Of
18259 -- indicator, but has no visible state.
18261 if not Has_Item
then
18263 ("package instantiation & has Part_Of indicator but "
18264 & "lacks visible state", Instance
, Pack_Id
);
18266 end Propagate_Part_Of
;
18270 Constits
: Elist_Id
;
18272 Encap_Id
: Entity_Id
;
18273 Item_Id
: Entity_Id
;
18277 -- Start of processing for Part_Of
18281 Check_No_Identifiers
;
18282 Check_Arg_Count
(1);
18284 Stmt
:= Find_Related_Context
(N
, Do_Checks
=> True);
18286 -- Object declaration
18288 if Nkind
(Stmt
) = N_Object_Declaration
then
18291 -- Package instantiation
18293 elsif Nkind
(Stmt
) = N_Package_Instantiation
then
18296 -- Single concurrent type declaration
18298 elsif Is_Single_Concurrent_Type_Declaration
(Stmt
) then
18301 -- Otherwise the pragma is associated with an illegal construct
18308 -- Extract the entity of the related object declaration or package
18309 -- instantiation. In the case of the instantiation, use the entity
18310 -- of the instance spec.
18312 if Nkind
(Stmt
) = N_Package_Instantiation
then
18313 Stmt
:= Instance_Spec
(Stmt
);
18316 Item_Id
:= Defining_Entity
(Stmt
);
18317 Encap
:= Get_Pragma_Arg
(Arg1
);
18319 -- A pragma that applies to a Ghost entity becomes Ghost for the
18320 -- purposes of legality checks and removal of ignored Ghost code.
18322 Mark_Pragma_As_Ghost
(N
, Item_Id
);
18324 -- Chain the pragma on the contract for further processing by
18325 -- Analyze_Part_Of_In_Decl_Part or for completeness.
18327 Add_Contract_Item
(N
, Item_Id
);
18329 -- A variable may act as consituent of a single concurrent type
18330 -- which in turn could be declared after the variable. Due to this
18331 -- discrepancy, the full analysis of indicator Part_Of is delayed
18332 -- until the end of the enclosing declarative region (see routine
18333 -- Analyze_Part_Of_In_Decl_Part).
18335 if Ekind
(Item_Id
) = E_Variable
then
18338 -- Otherwise indicator Part_Of applies to a constant or a package
18342 -- Detect any discrepancies between the placement of the
18343 -- constant or package instantiation with respect to state
18344 -- space and the encapsulating state.
18348 Item_Id
=> Item_Id
,
18350 Encap_Id
=> Encap_Id
,
18354 pragma Assert
(Present
(Encap_Id
));
18356 if Ekind
(Item_Id
) = E_Constant
then
18357 Constits
:= Part_Of_Constituents
(Encap_Id
);
18359 if No
(Constits
) then
18360 Constits
:= New_Elmt_List
;
18361 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
18364 Append_Elmt
(Item_Id
, Constits
);
18365 Set_Encapsulating_State
(Item_Id
, Encap_Id
);
18367 -- Propagate the Part_Of indicator to the visible state
18368 -- space of the package instantiation.
18372 (Pack_Id
=> Item_Id
,
18373 State_Id
=> Encap_Id
,
18380 ----------------------------------
18381 -- Partition_Elaboration_Policy --
18382 ----------------------------------
18384 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
18386 when Pragma_Partition_Elaboration_Policy
=> declare
18387 subtype PEP_Range
is Name_Id
18388 range First_Partition_Elaboration_Policy_Name
18389 .. Last_Partition_Elaboration_Policy_Name
;
18390 PEP_Val
: PEP_Range
;
18395 Check_Arg_Count
(1);
18396 Check_No_Identifiers
;
18397 Check_Arg_Is_Partition_Elaboration_Policy
(Arg1
);
18398 Check_Valid_Configuration_Pragma
;
18399 PEP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
18402 when Name_Concurrent
=>
18404 when Name_Sequential
=>
18408 if Partition_Elaboration_Policy
/= ' '
18409 and then Partition_Elaboration_Policy
/= PEP
18411 Error_Msg_Sloc
:= Partition_Elaboration_Policy_Sloc
;
18413 ("partition elaboration policy incompatible with policy#");
18415 -- Set new policy, but always preserve System_Location since we
18416 -- like the error message with the run time name.
18419 Partition_Elaboration_Policy
:= PEP
;
18421 if Partition_Elaboration_Policy_Sloc
/= System_Location
then
18422 Partition_Elaboration_Policy_Sloc
:= Loc
;
18431 -- pragma Passive [(PASSIVE_FORM)];
18433 -- PASSIVE_FORM ::= Semaphore | No
18435 when Pragma_Passive
=>
18438 if Nkind
(Parent
(N
)) /= N_Task_Definition
then
18439 Error_Pragma
("pragma% must be within task definition");
18442 if Arg_Count
/= 0 then
18443 Check_Arg_Count
(1);
18444 Check_Arg_Is_One_Of
(Arg1
, Name_Semaphore
, Name_No
);
18447 ----------------------------------
18448 -- Preelaborable_Initialization --
18449 ----------------------------------
18451 -- pragma Preelaborable_Initialization (DIRECT_NAME);
18453 when Pragma_Preelaborable_Initialization
=> Preelab_Init
: declare
18458 Check_Arg_Count
(1);
18459 Check_No_Identifiers
;
18460 Check_Arg_Is_Identifier
(Arg1
);
18461 Check_Arg_Is_Local_Name
(Arg1
);
18462 Check_First_Subtype
(Arg1
);
18463 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
18465 -- A pragma that applies to a Ghost entity becomes Ghost for the
18466 -- purposes of legality checks and removal of ignored Ghost code.
18468 Mark_Pragma_As_Ghost
(N
, Ent
);
18470 -- The pragma may come from an aspect on a private declaration,
18471 -- even if the freeze point at which this is analyzed in the
18472 -- private part after the full view.
18474 if Has_Private_Declaration
(Ent
)
18475 and then From_Aspect_Specification
(N
)
18479 -- Check appropriate type argument
18481 elsif Is_Private_Type
(Ent
)
18482 or else Is_Protected_Type
(Ent
)
18483 or else (Is_Generic_Type
(Ent
) and then Is_Derived_Type
(Ent
))
18485 -- AI05-0028: The pragma applies to all composite types. Note
18486 -- that we apply this binding interpretation to earlier versions
18487 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
18488 -- choice since there are other compilers that do the same.
18490 or else Is_Composite_Type
(Ent
)
18496 ("pragma % can only be applied to private, formal derived, "
18497 & "protected, or composite type", Arg1
);
18500 -- Give an error if the pragma is applied to a protected type that
18501 -- does not qualify (due to having entries, or due to components
18502 -- that do not qualify).
18504 if Is_Protected_Type
(Ent
)
18505 and then not Has_Preelaborable_Initialization
(Ent
)
18508 ("protected type & does not have preelaborable "
18509 & "initialization", Ent
);
18511 -- Otherwise mark the type as definitely having preelaborable
18515 Set_Known_To_Have_Preelab_Init
(Ent
);
18518 if Has_Pragma_Preelab_Init
(Ent
)
18519 and then Warn_On_Redundant_Constructs
18521 Error_Pragma
("?r?duplicate pragma%!");
18523 Set_Has_Pragma_Preelab_Init
(Ent
);
18527 --------------------
18528 -- Persistent_BSS --
18529 --------------------
18531 -- pragma Persistent_BSS [(object_NAME)];
18533 when Pragma_Persistent_BSS
=> Persistent_BSS
: declare
18540 Check_At_Most_N_Arguments
(1);
18542 -- Case of application to specific object (one argument)
18544 if Arg_Count
= 1 then
18545 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
18547 if not Is_Entity_Name
(Get_Pragma_Arg
(Arg1
))
18549 Ekind_In
(Entity
(Get_Pragma_Arg
(Arg1
)), E_Variable
,
18552 Error_Pragma_Arg
("pragma% only applies to objects", Arg1
);
18555 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
18556 Decl
:= Parent
(Ent
);
18558 -- A pragma that applies to a Ghost entity becomes Ghost for
18559 -- the purposes of legality checks and removal of ignored Ghost
18562 Mark_Pragma_As_Ghost
(N
, Ent
);
18564 -- Check for duplication before inserting in list of
18565 -- representation items.
18567 Check_Duplicate_Pragma
(Ent
);
18569 if Rep_Item_Too_Late
(Ent
, N
) then
18573 if Present
(Expression
(Decl
)) then
18575 ("object for pragma% cannot have initialization", Arg1
);
18578 if not Is_Potentially_Persistent_Type
(Etype
(Ent
)) then
18580 ("object type for pragma% is not potentially persistent",
18585 Make_Linker_Section_Pragma
18586 (Ent
, Sloc
(N
), ".persistent.bss");
18587 Insert_After
(N
, Prag
);
18590 -- Case of use as configuration pragma with no arguments
18593 Check_Valid_Configuration_Pragma
;
18594 Persistent_BSS_Mode
:= True;
18596 end Persistent_BSS
;
18602 -- pragma Polling (ON | OFF);
18604 when Pragma_Polling
=>
18606 Check_Arg_Count
(1);
18607 Check_No_Identifiers
;
18608 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
18609 Polling_Required
:= (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
);
18611 -----------------------------------
18612 -- Post/Post_Class/Postcondition --
18613 -----------------------------------
18615 -- pragma Post (Boolean_EXPRESSION);
18616 -- pragma Post_Class (Boolean_EXPRESSION);
18617 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18618 -- [,[Message =>] String_EXPRESSION]);
18620 -- Characteristics:
18622 -- * Analysis - The annotation undergoes initial checks to verify
18623 -- the legal placement and context. Secondary checks preanalyze the
18626 -- Analyze_Pre_Post_Condition_In_Decl_Part
18628 -- * Expansion - The annotation is expanded during the expansion of
18629 -- the related subprogram [body] contract as performed in:
18631 -- Expand_Subprogram_Contract
18633 -- * Template - The annotation utilizes the generic template of the
18634 -- related subprogram [body] when it is:
18636 -- aspect on subprogram declaration
18637 -- aspect on stand alone subprogram body
18638 -- pragma on stand alone subprogram body
18640 -- The annotation must prepare its own template when it is:
18642 -- pragma on subprogram declaration
18644 -- * Globals - Capture of global references must occur after full
18647 -- * Instance - The annotation is instantiated automatically when
18648 -- the related generic subprogram [body] is instantiated except for
18649 -- the "pragma on subprogram declaration" case. In that scenario
18650 -- the annotation must instantiate itself.
18653 Pragma_Post_Class |
18654 Pragma_Postcondition
=>
18655 Analyze_Pre_Post_Condition
;
18657 --------------------------------
18658 -- Pre/Pre_Class/Precondition --
18659 --------------------------------
18661 -- pragma Pre (Boolean_EXPRESSION);
18662 -- pragma Pre_Class (Boolean_EXPRESSION);
18663 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18664 -- [,[Message =>] String_EXPRESSION]);
18666 -- Characteristics:
18668 -- * Analysis - The annotation undergoes initial checks to verify
18669 -- the legal placement and context. Secondary checks preanalyze the
18672 -- Analyze_Pre_Post_Condition_In_Decl_Part
18674 -- * Expansion - The annotation is expanded during the expansion of
18675 -- the related subprogram [body] contract as performed in:
18677 -- Expand_Subprogram_Contract
18679 -- * Template - The annotation utilizes the generic template of the
18680 -- related subprogram [body] when it is:
18682 -- aspect on subprogram declaration
18683 -- aspect on stand alone subprogram body
18684 -- pragma on stand alone subprogram body
18686 -- The annotation must prepare its own template when it is:
18688 -- pragma on subprogram declaration
18690 -- * Globals - Capture of global references must occur after full
18693 -- * Instance - The annotation is instantiated automatically when
18694 -- the related generic subprogram [body] is instantiated except for
18695 -- the "pragma on subprogram declaration" case. In that scenario
18696 -- the annotation must instantiate itself.
18700 Pragma_Precondition
=>
18701 Analyze_Pre_Post_Condition
;
18707 -- pragma Predicate
18708 -- ([Entity =>] type_LOCAL_NAME,
18709 -- [Check =>] boolean_EXPRESSION);
18711 when Pragma_Predicate
=> Predicate
: declare
18718 Check_Arg_Count
(2);
18719 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18720 Check_Optional_Identifier
(Arg2
, Name_Check
);
18722 Check_Arg_Is_Local_Name
(Arg1
);
18724 Type_Id
:= Get_Pragma_Arg
(Arg1
);
18725 Find_Type
(Type_Id
);
18726 Typ
:= Entity
(Type_Id
);
18728 if Typ
= Any_Type
then
18732 -- A pragma that applies to a Ghost entity becomes Ghost for the
18733 -- purposes of legality checks and removal of ignored Ghost code.
18735 Mark_Pragma_As_Ghost
(N
, Typ
);
18737 -- The remaining processing is simply to link the pragma on to
18738 -- the rep item chain, for processing when the type is frozen.
18739 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18740 -- mark the type as having predicates.
18742 Set_Has_Predicates
(Typ
);
18743 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
18746 -----------------------
18747 -- Predicate_Failure --
18748 -----------------------
18750 -- pragma Predicate_Failure
18751 -- ([Entity =>] type_LOCAL_NAME,
18752 -- [Message =>] string_EXPRESSION);
18754 when Pragma_Predicate_Failure
=> Predicate_Failure
: declare
18761 Check_Arg_Count
(2);
18762 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18763 Check_Optional_Identifier
(Arg2
, Name_Message
);
18765 Check_Arg_Is_Local_Name
(Arg1
);
18767 Type_Id
:= Get_Pragma_Arg
(Arg1
);
18768 Find_Type
(Type_Id
);
18769 Typ
:= Entity
(Type_Id
);
18771 if Typ
= Any_Type
then
18775 -- A pragma that applies to a Ghost entity becomes Ghost for the
18776 -- purposes of legality checks and removal of ignored Ghost code.
18778 Mark_Pragma_As_Ghost
(N
, Typ
);
18780 -- The remaining processing is simply to link the pragma on to
18781 -- the rep item chain, for processing when the type is frozen.
18782 -- This is accomplished by a call to Rep_Item_Too_Late.
18784 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
18785 end Predicate_Failure
;
18791 -- pragma Preelaborate [(library_unit_NAME)];
18793 -- Set the flag Is_Preelaborated of program unit name entity
18795 when Pragma_Preelaborate
=> Preelaborate
: declare
18796 Pa
: constant Node_Id
:= Parent
(N
);
18797 Pk
: constant Node_Kind
:= Nkind
(Pa
);
18801 Check_Ada_83_Warning
;
18802 Check_Valid_Library_Unit_Pragma
;
18804 if Nkind
(N
) = N_Null_Statement
then
18808 Ent
:= Find_Lib_Unit_Name
;
18810 -- A pragma that applies to a Ghost entity becomes Ghost for the
18811 -- purposes of legality checks and removal of ignored Ghost code.
18813 Mark_Pragma_As_Ghost
(N
, Ent
);
18814 Check_Duplicate_Pragma
(Ent
);
18816 -- This filters out pragmas inside generic parents that show up
18817 -- inside instantiations. Pragmas that come from aspects in the
18818 -- unit are not ignored.
18820 if Present
(Ent
) then
18821 if Pk
= N_Package_Specification
18822 and then Present
(Generic_Parent
(Pa
))
18823 and then not From_Aspect_Specification
(N
)
18828 if not Debug_Flag_U
then
18829 Set_Is_Preelaborated
(Ent
);
18830 Set_Suppress_Elaboration_Warnings
(Ent
);
18836 -------------------------------
18837 -- Prefix_Exception_Messages --
18838 -------------------------------
18840 -- pragma Prefix_Exception_Messages;
18842 when Pragma_Prefix_Exception_Messages
=>
18844 Check_Valid_Configuration_Pragma
;
18845 Check_Arg_Count
(0);
18846 Prefix_Exception_Messages
:= True;
18852 -- pragma Priority (EXPRESSION);
18854 when Pragma_Priority
=> Priority
: declare
18855 P
: constant Node_Id
:= Parent
(N
);
18860 Check_No_Identifiers
;
18861 Check_Arg_Count
(1);
18865 if Nkind
(P
) = N_Subprogram_Body
then
18866 Check_In_Main_Program
;
18868 Ent
:= Defining_Unit_Name
(Specification
(P
));
18870 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
18871 Ent
:= Defining_Identifier
(Ent
);
18874 Arg
:= Get_Pragma_Arg
(Arg1
);
18875 Analyze_And_Resolve
(Arg
, Standard_Integer
);
18879 if not Is_OK_Static_Expression
(Arg
) then
18880 Flag_Non_Static_Expr
18881 ("main subprogram priority is not static!", Arg
);
18884 -- If constraint error, then we already signalled an error
18886 elsif Raises_Constraint_Error
(Arg
) then
18889 -- Otherwise check in range except if Relaxed_RM_Semantics
18890 -- where we ignore the value if out of range.
18894 Val
: constant Uint
:= Expr_Value
(Arg
);
18896 if not Relaxed_RM_Semantics
18899 or else Val
> Expr_Value
(Expression
18900 (Parent
(RTE
(RE_Max_Priority
)))))
18903 ("main subprogram priority is out of range", Arg1
);
18906 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
18911 -- Load an arbitrary entity from System.Tasking.Stages or
18912 -- System.Tasking.Restricted.Stages (depending on the
18913 -- supported profile) to make sure that one of these packages
18914 -- is implicitly with'ed, since we need to have the tasking
18915 -- run time active for the pragma Priority to have any effect.
18916 -- Previously we with'ed the package System.Tasking, but this
18917 -- package does not trigger the required initialization of the
18918 -- run-time library.
18921 Discard
: Entity_Id
;
18922 pragma Warnings
(Off
, Discard
);
18924 if Restricted_Profile
then
18925 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
18927 Discard
:= RTE
(RE_Activate_Tasks
);
18931 -- Task or Protected, must be of type Integer
18933 elsif Nkind_In
(P
, N_Protected_Definition
, N_Task_Definition
) then
18934 Arg
:= Get_Pragma_Arg
(Arg1
);
18935 Ent
:= Defining_Identifier
(Parent
(P
));
18937 -- The expression must be analyzed in the special manner
18938 -- described in "Handling of Default and Per-Object
18939 -- Expressions" in sem.ads.
18941 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Any_Priority
));
18943 if not Is_OK_Static_Expression
(Arg
) then
18944 Check_Restriction
(Static_Priorities
, Arg
);
18947 -- Anything else is incorrect
18953 -- Check duplicate pragma before we chain the pragma in the Rep
18954 -- Item chain of Ent.
18956 Check_Duplicate_Pragma
(Ent
);
18957 Record_Rep_Item
(Ent
, N
);
18960 -----------------------------------
18961 -- Priority_Specific_Dispatching --
18962 -----------------------------------
18964 -- pragma Priority_Specific_Dispatching (
18965 -- policy_IDENTIFIER,
18966 -- first_priority_EXPRESSION,
18967 -- last_priority_EXPRESSION);
18969 when Pragma_Priority_Specific_Dispatching
=>
18970 Priority_Specific_Dispatching
: declare
18971 Prio_Id
: constant Entity_Id
:= RTE
(RE_Any_Priority
);
18972 -- This is the entity System.Any_Priority;
18975 Lower_Bound
: Node_Id
;
18976 Upper_Bound
: Node_Id
;
18982 Check_Arg_Count
(3);
18983 Check_No_Identifiers
;
18984 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
18985 Check_Valid_Configuration_Pragma
;
18986 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
18987 DP
:= Fold_Upper
(Name_Buffer
(1));
18989 Lower_Bound
:= Get_Pragma_Arg
(Arg2
);
18990 Check_Arg_Is_OK_Static_Expression
(Lower_Bound
, Standard_Integer
);
18991 Lower_Val
:= Expr_Value
(Lower_Bound
);
18993 Upper_Bound
:= Get_Pragma_Arg
(Arg3
);
18994 Check_Arg_Is_OK_Static_Expression
(Upper_Bound
, Standard_Integer
);
18995 Upper_Val
:= Expr_Value
(Upper_Bound
);
18997 -- It is not allowed to use Task_Dispatching_Policy and
18998 -- Priority_Specific_Dispatching in the same partition.
19000 if Task_Dispatching_Policy
/= ' ' then
19001 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
19003 ("pragma% incompatible with Task_Dispatching_Policy#");
19005 -- Check lower bound in range
19007 elsif Lower_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
19009 Lower_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
19012 ("first_priority is out of range", Arg2
);
19014 -- Check upper bound in range
19016 elsif Upper_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
19018 Upper_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
19021 ("last_priority is out of range", Arg3
);
19023 -- Check that the priority range is valid
19025 elsif Lower_Val
> Upper_Val
then
19027 ("last_priority_expression must be greater than or equal to "
19028 & "first_priority_expression");
19030 -- Store the new policy, but always preserve System_Location since
19031 -- we like the error message with the run-time name.
19034 -- Check overlapping in the priority ranges specified in other
19035 -- Priority_Specific_Dispatching pragmas within the same
19036 -- partition. We can only check those we know about.
19039 Specific_Dispatching
.First
.. Specific_Dispatching
.Last
19041 if Specific_Dispatching
.Table
(J
).First_Priority
in
19042 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
19043 or else Specific_Dispatching
.Table
(J
).Last_Priority
in
19044 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
19047 Specific_Dispatching
.Table
(J
).Pragma_Loc
;
19049 ("priority range overlaps with "
19050 & "Priority_Specific_Dispatching#");
19054 -- The use of Priority_Specific_Dispatching is incompatible
19055 -- with Task_Dispatching_Policy.
19057 if Task_Dispatching_Policy
/= ' ' then
19058 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
19060 ("Priority_Specific_Dispatching incompatible "
19061 & "with Task_Dispatching_Policy#");
19064 -- The use of Priority_Specific_Dispatching forces ceiling
19067 if Locking_Policy
/= ' ' and then Locking_Policy
/= 'C' then
19068 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
19070 ("Priority_Specific_Dispatching incompatible "
19071 & "with Locking_Policy#");
19073 -- Set the Ceiling_Locking policy, but preserve System_Location
19074 -- since we like the error message with the run time name.
19077 Locking_Policy
:= 'C';
19079 if Locking_Policy_Sloc
/= System_Location
then
19080 Locking_Policy_Sloc
:= Loc
;
19084 -- Add entry in the table
19086 Specific_Dispatching
.Append
19087 ((Dispatching_Policy
=> DP
,
19088 First_Priority
=> UI_To_Int
(Lower_Val
),
19089 Last_Priority
=> UI_To_Int
(Upper_Val
),
19090 Pragma_Loc
=> Loc
));
19092 end Priority_Specific_Dispatching
;
19098 -- pragma Profile (profile_IDENTIFIER);
19100 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
19102 when Pragma_Profile
=>
19104 Check_Arg_Count
(1);
19105 Check_Valid_Configuration_Pragma
;
19106 Check_No_Identifiers
;
19109 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
19112 if Chars
(Argx
) = Name_Ravenscar
then
19113 Set_Ravenscar_Profile
(Ravenscar
, N
);
19115 elsif Chars
(Argx
) = Name_Gnat_Extended_Ravenscar
then
19116 Set_Ravenscar_Profile
(GNAT_Extended_Ravenscar
, N
);
19118 elsif Chars
(Argx
) = Name_Restricted
then
19119 Set_Profile_Restrictions
19121 N
, Warn
=> Treat_Restrictions_As_Warnings
);
19123 elsif Chars
(Argx
) = Name_Rational
then
19124 Set_Rational_Profile
;
19126 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
19127 Set_Profile_Restrictions
19128 (No_Implementation_Extensions
,
19129 N
, Warn
=> Treat_Restrictions_As_Warnings
);
19132 Error_Pragma_Arg
("& is not a valid profile", Argx
);
19136 ----------------------
19137 -- Profile_Warnings --
19138 ----------------------
19140 -- pragma Profile_Warnings (profile_IDENTIFIER);
19142 -- profile_IDENTIFIER => Restricted | Ravenscar
19144 when Pragma_Profile_Warnings
=>
19146 Check_Arg_Count
(1);
19147 Check_Valid_Configuration_Pragma
;
19148 Check_No_Identifiers
;
19151 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
19154 if Chars
(Argx
) = Name_Ravenscar
then
19155 Set_Profile_Restrictions
(Ravenscar
, N
, Warn
=> True);
19157 elsif Chars
(Argx
) = Name_Restricted
then
19158 Set_Profile_Restrictions
(Restricted
, N
, Warn
=> True);
19160 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
19161 Set_Profile_Restrictions
19162 (No_Implementation_Extensions
, N
, Warn
=> True);
19165 Error_Pragma_Arg
("& is not a valid profile", Argx
);
19169 --------------------------
19170 -- Propagate_Exceptions --
19171 --------------------------
19173 -- pragma Propagate_Exceptions;
19175 -- Note: this pragma is obsolete and has no effect
19177 when Pragma_Propagate_Exceptions
=>
19179 Check_Arg_Count
(0);
19181 if Warn_On_Obsolescent_Feature
then
19183 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
19184 "and has no effect?j?", N
);
19187 -----------------------------
19188 -- Provide_Shift_Operators --
19189 -----------------------------
19191 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
19193 when Pragma_Provide_Shift_Operators
=>
19194 Provide_Shift_Operators
: declare
19197 procedure Declare_Shift_Operator
(Nam
: Name_Id
);
19198 -- Insert declaration and pragma Instrinsic for named shift op
19200 ----------------------------
19201 -- Declare_Shift_Operator --
19202 ----------------------------
19204 procedure Declare_Shift_Operator
(Nam
: Name_Id
) is
19210 Make_Subprogram_Declaration
(Loc
,
19211 Make_Function_Specification
(Loc
,
19212 Defining_Unit_Name
=>
19213 Make_Defining_Identifier
(Loc
, Chars
=> Nam
),
19215 Result_Definition
=>
19216 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
)),
19218 Parameter_Specifications
=> New_List
(
19219 Make_Parameter_Specification
(Loc
,
19220 Defining_Identifier
=>
19221 Make_Defining_Identifier
(Loc
, Name_Value
),
19223 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
))),
19225 Make_Parameter_Specification
(Loc
,
19226 Defining_Identifier
=>
19227 Make_Defining_Identifier
(Loc
, Name_Amount
),
19229 New_Occurrence_Of
(Standard_Natural
, Loc
)))));
19233 Pragma_Identifier
=> Make_Identifier
(Loc
, Name_Import
),
19234 Pragma_Argument_Associations
=> New_List
(
19235 Make_Pragma_Argument_Association
(Loc
,
19236 Expression
=> Make_Identifier
(Loc
, Name_Intrinsic
)),
19237 Make_Pragma_Argument_Association
(Loc
,
19238 Expression
=> Make_Identifier
(Loc
, Nam
))));
19240 Insert_After
(N
, Import
);
19241 Insert_After
(N
, Func
);
19242 end Declare_Shift_Operator
;
19244 -- Start of processing for Provide_Shift_Operators
19248 Check_Arg_Count
(1);
19249 Check_Arg_Is_Local_Name
(Arg1
);
19251 Arg1
:= Get_Pragma_Arg
(Arg1
);
19253 -- We must have an entity name
19255 if not Is_Entity_Name
(Arg1
) then
19257 ("pragma % must apply to integer first subtype", Arg1
);
19260 -- If no Entity, means there was a prior error so ignore
19262 if Present
(Entity
(Arg1
)) then
19263 Ent
:= Entity
(Arg1
);
19265 -- Apply error checks
19267 if not Is_First_Subtype
(Ent
) then
19269 ("cannot apply pragma %",
19270 "\& is not a first subtype",
19273 elsif not Is_Integer_Type
(Ent
) then
19275 ("cannot apply pragma %",
19276 "\& is not an integer type",
19279 elsif Has_Shift_Operator
(Ent
) then
19281 ("cannot apply pragma %",
19282 "\& already has declared shift operators",
19285 elsif Is_Frozen
(Ent
) then
19287 ("pragma % appears too late",
19288 "\& is already frozen",
19292 -- Now declare the operators. We do this during analysis rather
19293 -- than expansion, since we want the operators available if we
19294 -- are operating in -gnatc or ASIS mode.
19296 Declare_Shift_Operator
(Name_Rotate_Left
);
19297 Declare_Shift_Operator
(Name_Rotate_Right
);
19298 Declare_Shift_Operator
(Name_Shift_Left
);
19299 Declare_Shift_Operator
(Name_Shift_Right
);
19300 Declare_Shift_Operator
(Name_Shift_Right_Arithmetic
);
19302 end Provide_Shift_Operators
;
19308 -- pragma Psect_Object (
19309 -- [Internal =>] LOCAL_NAME,
19310 -- [, [External =>] EXTERNAL_SYMBOL]
19311 -- [, [Size =>] EXTERNAL_SYMBOL]);
19313 when Pragma_Psect_Object | Pragma_Common_Object
=>
19314 Psect_Object
: declare
19315 Args
: Args_List
(1 .. 3);
19316 Names
: constant Name_List
(1 .. 3) := (
19321 Internal
: Node_Id
renames Args
(1);
19322 External
: Node_Id
renames Args
(2);
19323 Size
: Node_Id
renames Args
(3);
19325 Def_Id
: Entity_Id
;
19327 procedure Check_Arg
(Arg
: Node_Id
);
19328 -- Checks that argument is either a string literal or an
19329 -- identifier, and posts error message if not.
19335 procedure Check_Arg
(Arg
: Node_Id
) is
19337 if not Nkind_In
(Original_Node
(Arg
),
19342 ("inappropriate argument for pragma %", Arg
);
19346 -- Start of processing for Common_Object/Psect_Object
19350 Gather_Associations
(Names
, Args
);
19351 Process_Extended_Import_Export_Internal_Arg
(Internal
);
19353 Def_Id
:= Entity
(Internal
);
19355 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
19357 ("pragma% must designate an object", Internal
);
19360 Check_Arg
(Internal
);
19362 if Is_Imported
(Def_Id
) or else Is_Exported
(Def_Id
) then
19364 ("cannot use pragma% for imported/exported object",
19368 if Is_Concurrent_Type
(Etype
(Internal
)) then
19370 ("cannot specify pragma % for task/protected object",
19374 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
19376 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
19378 Error_Msg_N
("??duplicate Common/Psect_Object pragma", N
);
19381 if Ekind
(Def_Id
) = E_Constant
then
19383 ("cannot specify pragma % for a constant", Internal
);
19386 if Is_Record_Type
(Etype
(Internal
)) then
19392 Ent
:= First_Entity
(Etype
(Internal
));
19393 while Present
(Ent
) loop
19394 Decl
:= Declaration_Node
(Ent
);
19396 if Ekind
(Ent
) = E_Component
19397 and then Nkind
(Decl
) = N_Component_Declaration
19398 and then Present
(Expression
(Decl
))
19399 and then Warn_On_Export_Import
19402 ("?x?object for pragma % has defaults", Internal
);
19412 if Present
(Size
) then
19416 if Present
(External
) then
19417 Check_Arg_Is_External_Name
(External
);
19420 -- If all error tests pass, link pragma on to the rep item chain
19422 Record_Rep_Item
(Def_Id
, N
);
19429 -- pragma Pure [(library_unit_NAME)];
19431 when Pragma_Pure
=> Pure
: declare
19435 Check_Ada_83_Warning
;
19437 -- If the pragma comes from a subprogram instantiation, nothing to
19438 -- check, this can happen at any level of nesting.
19440 if Is_Wrapper_Package
(Current_Scope
) then
19443 Check_Valid_Library_Unit_Pragma
;
19446 if Nkind
(N
) = N_Null_Statement
then
19450 Ent
:= Find_Lib_Unit_Name
;
19452 -- A pragma that applies to a Ghost entity becomes Ghost for the
19453 -- purposes of legality checks and removal of ignored Ghost code.
19455 Mark_Pragma_As_Ghost
(N
, Ent
);
19457 if not Debug_Flag_U
then
19459 Set_Has_Pragma_Pure
(Ent
);
19460 Set_Suppress_Elaboration_Warnings
(Ent
);
19464 -------------------
19465 -- Pure_Function --
19466 -------------------
19468 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
19470 when Pragma_Pure_Function
=> Pure_Function
: declare
19471 Def_Id
: Entity_Id
;
19474 Effective
: Boolean := False;
19478 Check_Arg_Count
(1);
19479 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19480 Check_Arg_Is_Local_Name
(Arg1
);
19481 E_Id
:= Get_Pragma_Arg
(Arg1
);
19483 if Error_Posted
(E_Id
) then
19487 -- Loop through homonyms (overloadings) of referenced entity
19489 E
:= Entity
(E_Id
);
19491 -- A pragma that applies to a Ghost entity becomes Ghost for the
19492 -- purposes of legality checks and removal of ignored Ghost code.
19494 Mark_Pragma_As_Ghost
(N
, E
);
19496 if Present
(E
) then
19498 Def_Id
:= Get_Base_Subprogram
(E
);
19500 if not Ekind_In
(Def_Id
, E_Function
,
19501 E_Generic_Function
,
19505 ("pragma% requires a function name", Arg1
);
19508 Set_Is_Pure
(Def_Id
);
19510 if not Has_Pragma_Pure_Function
(Def_Id
) then
19511 Set_Has_Pragma_Pure_Function
(Def_Id
);
19515 exit when From_Aspect_Specification
(N
);
19517 exit when No
(E
) or else Scope
(E
) /= Current_Scope
;
19521 and then Warn_On_Redundant_Constructs
19524 ("pragma Pure_Function on& is redundant?r?",
19530 --------------------
19531 -- Queuing_Policy --
19532 --------------------
19534 -- pragma Queuing_Policy (policy_IDENTIFIER);
19536 when Pragma_Queuing_Policy
=> declare
19540 Check_Ada_83_Warning
;
19541 Check_Arg_Count
(1);
19542 Check_No_Identifiers
;
19543 Check_Arg_Is_Queuing_Policy
(Arg1
);
19544 Check_Valid_Configuration_Pragma
;
19545 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
19546 QP
:= Fold_Upper
(Name_Buffer
(1));
19548 if Queuing_Policy
/= ' '
19549 and then Queuing_Policy
/= QP
19551 Error_Msg_Sloc
:= Queuing_Policy_Sloc
;
19552 Error_Pragma
("queuing policy incompatible with policy#");
19554 -- Set new policy, but always preserve System_Location since we
19555 -- like the error message with the run time name.
19558 Queuing_Policy
:= QP
;
19560 if Queuing_Policy_Sloc
/= System_Location
then
19561 Queuing_Policy_Sloc
:= Loc
;
19570 -- pragma Rational, for compatibility with foreign compiler
19572 when Pragma_Rational
=>
19573 Set_Rational_Profile
;
19575 ---------------------
19576 -- Refined_Depends --
19577 ---------------------
19579 -- pragma Refined_Depends (DEPENDENCY_RELATION);
19581 -- DEPENDENCY_RELATION ::=
19583 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
19585 -- DEPENDENCY_CLAUSE ::=
19586 -- OUTPUT_LIST =>[+] INPUT_LIST
19587 -- | NULL_DEPENDENCY_CLAUSE
19589 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
19591 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
19593 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
19595 -- OUTPUT ::= NAME | FUNCTION_RESULT
19598 -- where FUNCTION_RESULT is a function Result attribute_reference
19600 -- Characteristics:
19602 -- * Analysis - The annotation undergoes initial checks to verify
19603 -- the legal placement and context. Secondary checks fully analyze
19604 -- the dependency clauses/global list in:
19606 -- Analyze_Refined_Depends_In_Decl_Part
19608 -- * Expansion - None.
19610 -- * Template - The annotation utilizes the generic template of the
19611 -- related subprogram body.
19613 -- * Globals - Capture of global references must occur after full
19616 -- * Instance - The annotation is instantiated automatically when
19617 -- the related generic subprogram body is instantiated.
19619 when Pragma_Refined_Depends
=> Refined_Depends
: declare
19620 Body_Id
: Entity_Id
;
19622 Spec_Id
: Entity_Id
;
19625 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19629 -- Chain the pragma on the contract for further processing by
19630 -- Analyze_Refined_Depends_In_Decl_Part.
19632 Add_Contract_Item
(N
, Body_Id
);
19634 -- The legality checks of pragmas Refined_Depends and
19635 -- Refined_Global are affected by the SPARK mode in effect and
19636 -- the volatility of the context. In addition these two pragmas
19637 -- are subject to an inherent order:
19639 -- 1) Refined_Global
19640 -- 2) Refined_Depends
19642 -- Analyze all these pragmas in the order outlined above
19644 Analyze_If_Present
(Pragma_SPARK_Mode
);
19645 Analyze_If_Present
(Pragma_Volatile_Function
);
19646 Analyze_If_Present
(Pragma_Refined_Global
);
19647 Analyze_Refined_Depends_In_Decl_Part
(N
);
19649 end Refined_Depends
;
19651 --------------------
19652 -- Refined_Global --
19653 --------------------
19655 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
19657 -- GLOBAL_SPECIFICATION ::=
19660 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
19662 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
19664 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
19665 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
19666 -- GLOBAL_ITEM ::= NAME
19668 -- Characteristics:
19670 -- * Analysis - The annotation undergoes initial checks to verify
19671 -- the legal placement and context. Secondary checks fully analyze
19672 -- the dependency clauses/global list in:
19674 -- Analyze_Refined_Global_In_Decl_Part
19676 -- * Expansion - None.
19678 -- * Template - The annotation utilizes the generic template of the
19679 -- related subprogram body.
19681 -- * Globals - Capture of global references must occur after full
19684 -- * Instance - The annotation is instantiated automatically when
19685 -- the related generic subprogram body is instantiated.
19687 when Pragma_Refined_Global
=> Refined_Global
: declare
19688 Body_Id
: Entity_Id
;
19690 Spec_Id
: Entity_Id
;
19693 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19697 -- Chain the pragma on the contract for further processing by
19698 -- Analyze_Refined_Global_In_Decl_Part.
19700 Add_Contract_Item
(N
, Body_Id
);
19702 -- The legality checks of pragmas Refined_Depends and
19703 -- Refined_Global are affected by the SPARK mode in effect and
19704 -- the volatility of the context. In addition these two pragmas
19705 -- are subject to an inherent order:
19707 -- 1) Refined_Global
19708 -- 2) Refined_Depends
19710 -- Analyze all these pragmas in the order outlined above
19712 Analyze_If_Present
(Pragma_SPARK_Mode
);
19713 Analyze_If_Present
(Pragma_Volatile_Function
);
19714 Analyze_Refined_Global_In_Decl_Part
(N
);
19715 Analyze_If_Present
(Pragma_Refined_Depends
);
19717 end Refined_Global
;
19723 -- pragma Refined_Post (boolean_EXPRESSION);
19725 -- Characteristics:
19727 -- * Analysis - The annotation is fully analyzed immediately upon
19728 -- elaboration as it cannot forward reference entities.
19730 -- * Expansion - The annotation is expanded during the expansion of
19731 -- the related subprogram body contract as performed in:
19733 -- Expand_Subprogram_Contract
19735 -- * Template - The annotation utilizes the generic template of the
19736 -- related subprogram body.
19738 -- * Globals - Capture of global references must occur after full
19741 -- * Instance - The annotation is instantiated automatically when
19742 -- the related generic subprogram body is instantiated.
19744 when Pragma_Refined_Post
=> Refined_Post
: declare
19745 Body_Id
: Entity_Id
;
19747 Spec_Id
: Entity_Id
;
19750 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19752 -- Fully analyze the pragma when it appears inside a subprogram
19753 -- body because it cannot benefit from forward references.
19757 -- Chain the pragma on the contract for completeness
19759 Add_Contract_Item
(N
, Body_Id
);
19761 -- The legality checks of pragma Refined_Post are affected by
19762 -- the SPARK mode in effect and the volatility of the context.
19763 -- Analyze all pragmas in a specific order.
19765 Analyze_If_Present
(Pragma_SPARK_Mode
);
19766 Analyze_If_Present
(Pragma_Volatile_Function
);
19767 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
19769 -- Currently it is not possible to inline pre/postconditions on
19770 -- a subprogram subject to pragma Inline_Always.
19772 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
19776 -------------------
19777 -- Refined_State --
19778 -------------------
19780 -- pragma Refined_State (REFINEMENT_LIST);
19782 -- REFINEMENT_LIST ::=
19783 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19785 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19787 -- CONSTITUENT_LIST ::=
19790 -- | (CONSTITUENT {, CONSTITUENT})
19792 -- CONSTITUENT ::= object_NAME | state_NAME
19794 -- Characteristics:
19796 -- * Analysis - The annotation undergoes initial checks to verify
19797 -- the legal placement and context. Secondary checks preanalyze the
19798 -- refinement clauses in:
19800 -- Analyze_Refined_State_In_Decl_Part
19802 -- * Expansion - None.
19804 -- * Template - The annotation utilizes the template of the related
19807 -- * Globals - Capture of global references must occur after full
19810 -- * Instance - The annotation is instantiated automatically when
19811 -- the related generic package body is instantiated.
19813 when Pragma_Refined_State
=> Refined_State
: declare
19814 Pack_Decl
: Node_Id
;
19815 Spec_Id
: Entity_Id
;
19819 Check_No_Identifiers
;
19820 Check_Arg_Count
(1);
19822 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
19824 -- Ensure the proper placement of the pragma. Refined states must
19825 -- be associated with a package body.
19827 if Nkind
(Pack_Decl
) = N_Package_Body
then
19830 -- Otherwise the pragma is associated with an illegal construct
19837 Spec_Id
:= Corresponding_Spec
(Pack_Decl
);
19839 -- Chain the pragma on the contract for further processing by
19840 -- Analyze_Refined_State_In_Decl_Part.
19842 Add_Contract_Item
(N
, Defining_Entity
(Pack_Decl
));
19844 -- The legality checks of pragma Refined_State are affected by the
19845 -- SPARK mode in effect. Analyze all pragmas in a specific order.
19847 Analyze_If_Present
(Pragma_SPARK_Mode
);
19849 -- A pragma that applies to a Ghost entity becomes Ghost for the
19850 -- purposes of legality checks and removal of ignored Ghost code.
19852 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
19854 -- State refinement is allowed only when the corresponding package
19855 -- declaration has non-null pragma Abstract_State. Refinement not
19856 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19858 if SPARK_Mode
/= Off
19860 (No
(Abstract_States
(Spec_Id
))
19861 or else Has_Null_Abstract_State
(Spec_Id
))
19864 ("useless refinement, package & does not define abstract "
19865 & "states", N
, Spec_Id
);
19870 -----------------------
19871 -- Relative_Deadline --
19872 -----------------------
19874 -- pragma Relative_Deadline (time_span_EXPRESSION);
19876 when Pragma_Relative_Deadline
=> Relative_Deadline
: declare
19877 P
: constant Node_Id
:= Parent
(N
);
19882 Check_No_Identifiers
;
19883 Check_Arg_Count
(1);
19885 Arg
:= Get_Pragma_Arg
(Arg1
);
19887 -- The expression must be analyzed in the special manner described
19888 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19890 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
19894 if Nkind
(P
) = N_Subprogram_Body
then
19895 Check_In_Main_Program
;
19897 -- Only Task and subprogram cases allowed
19899 elsif Nkind
(P
) /= N_Task_Definition
then
19903 -- Check duplicate pragma before we set the corresponding flag
19905 if Has_Relative_Deadline_Pragma
(P
) then
19906 Error_Pragma
("duplicate pragma% not allowed");
19909 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19910 -- Relative_Deadline pragma node cannot be inserted in the Rep
19911 -- Item chain of Ent since it is rewritten by the expander as a
19912 -- procedure call statement that will break the chain.
19914 Set_Has_Relative_Deadline_Pragma
(P
);
19915 end Relative_Deadline
;
19917 ------------------------
19918 -- Remote_Access_Type --
19919 ------------------------
19921 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19923 when Pragma_Remote_Access_Type
=> Remote_Access_Type
: declare
19928 Check_Arg_Count
(1);
19929 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19930 Check_Arg_Is_Local_Name
(Arg1
);
19932 E
:= Entity
(Get_Pragma_Arg
(Arg1
));
19934 -- A pragma that applies to a Ghost entity becomes Ghost for the
19935 -- purposes of legality checks and removal of ignored Ghost code.
19937 Mark_Pragma_As_Ghost
(N
, E
);
19939 if Nkind
(Parent
(E
)) = N_Formal_Type_Declaration
19940 and then Ekind
(E
) = E_General_Access_Type
19941 and then Is_Class_Wide_Type
(Directly_Designated_Type
(E
))
19942 and then Scope
(Root_Type
(Directly_Designated_Type
(E
)))
19944 and then Is_Valid_Remote_Object_Type
19945 (Root_Type
(Directly_Designated_Type
(E
)))
19947 Set_Is_Remote_Types
(E
);
19951 ("pragma% applies only to formal access to classwide types",
19954 end Remote_Access_Type
;
19956 ---------------------------
19957 -- Remote_Call_Interface --
19958 ---------------------------
19960 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19962 when Pragma_Remote_Call_Interface
=> Remote_Call_Interface
: declare
19963 Cunit_Node
: Node_Id
;
19964 Cunit_Ent
: Entity_Id
;
19968 Check_Ada_83_Warning
;
19969 Check_Valid_Library_Unit_Pragma
;
19971 if Nkind
(N
) = N_Null_Statement
then
19975 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
19976 K
:= Nkind
(Unit
(Cunit_Node
));
19977 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
19979 -- A pragma that applies to a Ghost entity becomes Ghost for the
19980 -- purposes of legality checks and removal of ignored Ghost code.
19982 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
19984 if K
= N_Package_Declaration
19985 or else K
= N_Generic_Package_Declaration
19986 or else K
= N_Subprogram_Declaration
19987 or else K
= N_Generic_Subprogram_Declaration
19988 or else (K
= N_Subprogram_Body
19989 and then Acts_As_Spec
(Unit
(Cunit_Node
)))
19994 "pragma% must apply to package or subprogram declaration");
19997 Set_Is_Remote_Call_Interface
(Cunit_Ent
);
19998 end Remote_Call_Interface
;
20004 -- pragma Remote_Types [(library_unit_NAME)];
20006 when Pragma_Remote_Types
=> Remote_Types
: declare
20007 Cunit_Node
: Node_Id
;
20008 Cunit_Ent
: Entity_Id
;
20011 Check_Ada_83_Warning
;
20012 Check_Valid_Library_Unit_Pragma
;
20014 if Nkind
(N
) = N_Null_Statement
then
20018 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
20019 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
20021 -- A pragma that applies to a Ghost entity becomes Ghost for the
20022 -- purposes of legality checks and removal of ignored Ghost code.
20024 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
20026 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
20027 N_Generic_Package_Declaration
)
20030 ("pragma% can only apply to a package declaration");
20033 Set_Is_Remote_Types
(Cunit_Ent
);
20040 -- pragma Ravenscar;
20042 when Pragma_Ravenscar
=>
20044 Check_Arg_Count
(0);
20045 Check_Valid_Configuration_Pragma
;
20046 Set_Ravenscar_Profile
(Ravenscar
, N
);
20048 if Warn_On_Obsolescent_Feature
then
20050 ("pragma Ravenscar is an obsolescent feature?j?", N
);
20052 ("|use pragma Profile (Ravenscar) instead?j?", N
);
20055 -------------------------
20056 -- Restricted_Run_Time --
20057 -------------------------
20059 -- pragma Restricted_Run_Time;
20061 when Pragma_Restricted_Run_Time
=>
20063 Check_Arg_Count
(0);
20064 Check_Valid_Configuration_Pragma
;
20065 Set_Profile_Restrictions
20066 (Restricted
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
20068 if Warn_On_Obsolescent_Feature
then
20070 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
20073 ("|use pragma Profile (Restricted) instead?j?", N
);
20080 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
20083 -- restriction_IDENTIFIER
20084 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20086 when Pragma_Restrictions
=>
20087 Process_Restrictions_Or_Restriction_Warnings
20088 (Warn
=> Treat_Restrictions_As_Warnings
);
20090 --------------------------
20091 -- Restriction_Warnings --
20092 --------------------------
20094 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
20097 -- restriction_IDENTIFIER
20098 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20100 when Pragma_Restriction_Warnings
=>
20102 Process_Restrictions_Or_Restriction_Warnings
(Warn
=> True);
20108 -- pragma Reviewable;
20110 when Pragma_Reviewable
=>
20111 Check_Ada_83_Warning
;
20112 Check_Arg_Count
(0);
20114 -- Call dummy debugging function rv. This is done to assist front
20115 -- end debugging. By placing a Reviewable pragma in the source
20116 -- program, a breakpoint on rv catches this place in the source,
20117 -- allowing convenient stepping to the point of interest.
20121 --------------------------
20122 -- Short_Circuit_And_Or --
20123 --------------------------
20125 -- pragma Short_Circuit_And_Or;
20127 when Pragma_Short_Circuit_And_Or
=>
20129 Check_Arg_Count
(0);
20130 Check_Valid_Configuration_Pragma
;
20131 Short_Circuit_And_Or
:= True;
20133 -------------------
20134 -- Share_Generic --
20135 -------------------
20137 -- pragma Share_Generic (GNAME {, GNAME});
20139 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
20141 when Pragma_Share_Generic
=>
20143 Process_Generic_List
;
20149 -- pragma Shared (LOCAL_NAME);
20151 when Pragma_Shared
=>
20153 Process_Atomic_Independent_Shared_Volatile
;
20155 --------------------
20156 -- Shared_Passive --
20157 --------------------
20159 -- pragma Shared_Passive [(library_unit_NAME)];
20161 -- Set the flag Is_Shared_Passive of program unit name entity
20163 when Pragma_Shared_Passive
=> Shared_Passive
: declare
20164 Cunit_Node
: Node_Id
;
20165 Cunit_Ent
: Entity_Id
;
20168 Check_Ada_83_Warning
;
20169 Check_Valid_Library_Unit_Pragma
;
20171 if Nkind
(N
) = N_Null_Statement
then
20175 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
20176 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
20178 -- A pragma that applies to a Ghost entity becomes Ghost for the
20179 -- purposes of legality checks and removal of ignored Ghost code.
20181 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
20183 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
20184 N_Generic_Package_Declaration
)
20187 ("pragma% can only apply to a package declaration");
20190 Set_Is_Shared_Passive
(Cunit_Ent
);
20191 end Shared_Passive
;
20193 -----------------------
20194 -- Short_Descriptors --
20195 -----------------------
20197 -- pragma Short_Descriptors;
20199 -- Recognize and validate, but otherwise ignore
20201 when Pragma_Short_Descriptors
=>
20203 Check_Arg_Count
(0);
20204 Check_Valid_Configuration_Pragma
;
20206 ------------------------------
20207 -- Simple_Storage_Pool_Type --
20208 ------------------------------
20210 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
20212 when Pragma_Simple_Storage_Pool_Type
=>
20213 Simple_Storage_Pool_Type
: declare
20219 Check_Arg_Count
(1);
20220 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
20222 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20223 Find_Type
(Type_Id
);
20224 Typ
:= Entity
(Type_Id
);
20226 if Typ
= Any_Type
then
20230 -- A pragma that applies to a Ghost entity becomes Ghost for the
20231 -- purposes of legality checks and removal of ignored Ghost code.
20233 Mark_Pragma_As_Ghost
(N
, Typ
);
20235 -- We require the pragma to apply to a type declared in a package
20236 -- declaration, but not (immediately) within a package body.
20238 if Ekind
(Current_Scope
) /= E_Package
20239 or else In_Package_Body
(Current_Scope
)
20242 ("pragma% can only apply to type declared immediately "
20243 & "within a package declaration");
20246 -- A simple storage pool type must be an immutably limited record
20247 -- or private type. If the pragma is given for a private type,
20248 -- the full type is similarly restricted (which is checked later
20249 -- in Freeze_Entity).
20251 if Is_Record_Type
(Typ
)
20252 and then not Is_Limited_View
(Typ
)
20255 ("pragma% can only apply to explicitly limited record type");
20257 elsif Is_Private_Type
(Typ
) and then not Is_Limited_Type
(Typ
) then
20259 ("pragma% can only apply to a private type that is limited");
20261 elsif not Is_Record_Type
(Typ
)
20262 and then not Is_Private_Type
(Typ
)
20265 ("pragma% can only apply to limited record or private type");
20268 Record_Rep_Item
(Typ
, N
);
20269 end Simple_Storage_Pool_Type
;
20271 ----------------------
20272 -- Source_File_Name --
20273 ----------------------
20275 -- There are five forms for this pragma:
20277 -- pragma Source_File_Name (
20278 -- [UNIT_NAME =>] unit_NAME,
20279 -- BODY_FILE_NAME => STRING_LITERAL
20280 -- [, [INDEX =>] INTEGER_LITERAL]);
20282 -- pragma Source_File_Name (
20283 -- [UNIT_NAME =>] unit_NAME,
20284 -- SPEC_FILE_NAME => STRING_LITERAL
20285 -- [, [INDEX =>] INTEGER_LITERAL]);
20287 -- pragma Source_File_Name (
20288 -- BODY_FILE_NAME => STRING_LITERAL
20289 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20290 -- [, CASING => CASING_SPEC]);
20292 -- pragma Source_File_Name (
20293 -- SPEC_FILE_NAME => STRING_LITERAL
20294 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20295 -- [, CASING => CASING_SPEC]);
20297 -- pragma Source_File_Name (
20298 -- SUBUNIT_FILE_NAME => STRING_LITERAL
20299 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20300 -- [, CASING => CASING_SPEC]);
20302 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
20304 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
20305 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
20306 -- only be used when no project file is used, while SFNP can only be
20307 -- used when a project file is used.
20309 -- No processing here. Processing was completed during parsing, since
20310 -- we need to have file names set as early as possible. Units are
20311 -- loaded well before semantic processing starts.
20313 -- The only processing we defer to this point is the check for
20314 -- correct placement.
20316 when Pragma_Source_File_Name
=>
20318 Check_Valid_Configuration_Pragma
;
20320 ------------------------------
20321 -- Source_File_Name_Project --
20322 ------------------------------
20324 -- See Source_File_Name for syntax
20326 -- No processing here. Processing was completed during parsing, since
20327 -- we need to have file names set as early as possible. Units are
20328 -- loaded well before semantic processing starts.
20330 -- The only processing we defer to this point is the check for
20331 -- correct placement.
20333 when Pragma_Source_File_Name_Project
=>
20335 Check_Valid_Configuration_Pragma
;
20337 -- Check that a pragma Source_File_Name_Project is used only in a
20338 -- configuration pragmas file.
20340 -- Pragmas Source_File_Name_Project should only be generated by
20341 -- the Project Manager in configuration pragmas files.
20343 -- This is really an ugly test. It seems to depend on some
20344 -- accidental and undocumented property. At the very least it
20345 -- needs to be documented, but it would be better to have a
20346 -- clean way of testing if we are in a configuration file???
20348 if Present
(Parent
(N
)) then
20350 ("pragma% can only appear in a configuration pragmas file");
20353 ----------------------
20354 -- Source_Reference --
20355 ----------------------
20357 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
20359 -- Nothing to do, all processing completed in Par.Prag, since we need
20360 -- the information for possible parser messages that are output.
20362 when Pragma_Source_Reference
=>
20369 -- pragma SPARK_Mode [(On | Off)];
20371 when Pragma_SPARK_Mode
=> Do_SPARK_Mode
: declare
20372 Mode_Id
: SPARK_Mode_Type
;
20374 procedure Check_Pragma_Conformance
20375 (Context_Pragma
: Node_Id
;
20376 Entity
: Entity_Id
;
20377 Entity_Pragma
: Node_Id
);
20378 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
20379 -- conformance of pragma N depending the following scenarios:
20381 -- If pragma Context_Pragma is not Empty, verify that pragma N is
20382 -- compatible with the pragma Context_Pragma that was inherited
20383 -- from the context:
20384 -- * If the mode of Context_Pragma is ON, then the new mode can
20386 -- * If the mode of Context_Pragma is OFF, then the only allowed
20387 -- new mode is also OFF. Emit error if this is not the case.
20389 -- If Entity is not Empty, verify that pragma N is compatible with
20390 -- pragma Entity_Pragma that belongs to Entity.
20391 -- * If Entity_Pragma is Empty, always issue an error as this
20392 -- corresponds to the case where a previous section of Entity
20393 -- has no SPARK_Mode set.
20394 -- * If the mode of Entity_Pragma is ON, then the new mode can
20396 -- * If the mode of Entity_Pragma is OFF, then the only allowed
20397 -- new mode is also OFF. Emit error if this is not the case.
20399 procedure Check_Library_Level_Entity
(E
: Entity_Id
);
20400 -- Subsidiary to routines Process_xxx. Verify that the related
20401 -- entity E subject to pragma SPARK_Mode is library-level.
20403 procedure Process_Body
(Decl
: Node_Id
);
20404 -- Verify the legality of pragma SPARK_Mode when it appears as the
20405 -- top of the body declarations of entry, package, protected unit,
20406 -- subprogram or task unit body denoted by Decl.
20408 procedure Process_Overloadable
(Decl
: Node_Id
);
20409 -- Verify the legality of pragma SPARK_Mode when it applies to an
20410 -- entry or [generic] subprogram declaration denoted by Decl.
20412 procedure Process_Private_Part
(Decl
: Node_Id
);
20413 -- Verify the legality of pragma SPARK_Mode when it appears at the
20414 -- top of the private declarations of a package spec, protected or
20415 -- task unit declaration denoted by Decl.
20417 procedure Process_Statement_Part
(Decl
: Node_Id
);
20418 -- Verify the legality of pragma SPARK_Mode when it appears at the
20419 -- top of the statement sequence of a package body denoted by node
20422 procedure Process_Visible_Part
(Decl
: Node_Id
);
20423 -- Verify the legality of pragma SPARK_Mode when it appears at the
20424 -- top of the visible declarations of a package spec, protected or
20425 -- task unit declaration denoted by Decl. The routine is also used
20426 -- on protected or task units declared without a definition.
20428 procedure Set_SPARK_Context
;
20429 -- Subsidiary to routines Process_xxx. Set the global variables
20430 -- which represent the mode of the context from pragma N. Ensure
20431 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
20433 ------------------------------
20434 -- Check_Pragma_Conformance --
20435 ------------------------------
20437 procedure Check_Pragma_Conformance
20438 (Context_Pragma
: Node_Id
;
20439 Entity
: Entity_Id
;
20440 Entity_Pragma
: Node_Id
)
20442 Err_Id
: Entity_Id
;
20446 -- The current pragma may appear without an argument. If this
20447 -- is the case, associate all error messages with the pragma
20450 if Present
(Arg1
) then
20456 -- The mode of the current pragma is compared against that of
20457 -- an enclosing context.
20459 if Present
(Context_Pragma
) then
20460 pragma Assert
(Nkind
(Context_Pragma
) = N_Pragma
);
20462 -- Issue an error if the new mode is less restrictive than
20463 -- that of the context.
20465 if Get_SPARK_Mode_From_Annotation
(Context_Pragma
) = Off
20466 and then Get_SPARK_Mode_From_Annotation
(N
) = On
20469 ("cannot change SPARK_Mode from Off to On", Err_N
);
20470 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
20471 Error_Msg_N
("\SPARK_Mode was set to Off#", Err_N
);
20476 -- The mode of the current pragma is compared against that of
20477 -- an initial package, protected type, subprogram or task type
20480 if Present
(Entity
) then
20482 -- A simple protected or task type is transformed into an
20483 -- anonymous type whose name cannot be used to issue error
20484 -- messages. Recover the original entity of the type.
20486 if Ekind_In
(Entity
, E_Protected_Type
, E_Task_Type
) then
20489 (Original_Node
(Unit_Declaration_Node
(Entity
)));
20494 -- Both the initial declaration and the completion carry
20495 -- SPARK_Mode pragmas.
20497 if Present
(Entity_Pragma
) then
20498 pragma Assert
(Nkind
(Entity_Pragma
) = N_Pragma
);
20500 -- Issue an error if the new mode is less restrictive
20501 -- than that of the initial declaration.
20503 if Get_SPARK_Mode_From_Annotation
(Entity_Pragma
) = Off
20504 and then Get_SPARK_Mode_From_Annotation
(N
) = On
20506 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
20507 Error_Msg_Sloc
:= Sloc
(Entity_Pragma
);
20509 ("\value Off was set for SPARK_Mode on&#",
20514 -- Otherwise the initial declaration lacks a SPARK_Mode
20515 -- pragma in which case the current pragma is illegal as
20516 -- it cannot "complete".
20519 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
20520 Error_Msg_Sloc
:= Sloc
(Err_Id
);
20522 ("\no value was set for SPARK_Mode on&#",
20527 end Check_Pragma_Conformance
;
20529 --------------------------------
20530 -- Check_Library_Level_Entity --
20531 --------------------------------
20533 procedure Check_Library_Level_Entity
(E
: Entity_Id
) is
20534 procedure Add_Entity_To_Name_Buffer
;
20535 -- Add the E_Kind of entity E to the name buffer
20537 -------------------------------
20538 -- Add_Entity_To_Name_Buffer --
20539 -------------------------------
20541 procedure Add_Entity_To_Name_Buffer
is
20543 if Ekind_In
(E
, E_Entry
, E_Entry_Family
) then
20544 Add_Str_To_Name_Buffer
("entry");
20546 elsif Ekind_In
(E
, E_Generic_Package
,
20550 Add_Str_To_Name_Buffer
("package");
20552 elsif Ekind_In
(E
, E_Protected_Body
, E_Protected_Type
) then
20553 Add_Str_To_Name_Buffer
("protected type");
20555 elsif Ekind_In
(E
, E_Function
,
20556 E_Generic_Function
,
20557 E_Generic_Procedure
,
20561 Add_Str_To_Name_Buffer
("subprogram");
20564 pragma Assert
(Ekind_In
(E
, E_Task_Body
, E_Task_Type
));
20565 Add_Str_To_Name_Buffer
("task type");
20567 end Add_Entity_To_Name_Buffer
;
20571 Msg_1
: constant String := "incorrect placement of pragma%";
20574 -- Start of processing for Check_Library_Level_Entity
20577 if not Is_Library_Level_Entity
(E
) then
20578 Error_Msg_Name_1
:= Pname
;
20579 Error_Msg_N
(Fix_Error
(Msg_1
), N
);
20582 Add_Str_To_Name_Buffer
("\& is not a library-level ");
20583 Add_Entity_To_Name_Buffer
;
20585 Msg_2
:= Name_Find
;
20586 Error_Msg_NE
(Get_Name_String
(Msg_2
), N
, E
);
20590 end Check_Library_Level_Entity
;
20596 procedure Process_Body
(Decl
: Node_Id
) is
20597 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20598 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
20601 -- Ignore pragma when applied to the special body created for
20602 -- inlining, recognized by its internal name _Parent.
20604 if Chars
(Body_Id
) = Name_uParent
then
20608 Check_Library_Level_Entity
(Body_Id
);
20610 -- For entry bodies, verify the legality against:
20611 -- * The mode of the context
20612 -- * The mode of the spec (if any)
20614 if Nkind_In
(Decl
, N_Entry_Body
, N_Subprogram_Body
) then
20616 -- A stand alone subprogram body
20618 if Body_Id
= Spec_Id
then
20619 Check_Pragma_Conformance
20620 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20622 Entity_Pragma
=> Empty
);
20624 -- An entry or subprogram body that completes a previous
20628 Check_Pragma_Conformance
20629 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20631 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
20635 Set_SPARK_Pragma
(Body_Id
, N
);
20636 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20638 -- For package bodies, verify the legality against:
20639 -- * The mode of the context
20640 -- * The mode of the private part
20642 -- This case is separated from protected and task bodies
20643 -- because the statement part of the package body inherits
20644 -- the mode of the body declarations.
20646 elsif Nkind
(Decl
) = N_Package_Body
then
20647 Check_Pragma_Conformance
20648 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20650 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
20653 Set_SPARK_Pragma
(Body_Id
, N
);
20654 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20655 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
20656 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
20658 -- For protected and task bodies, verify the legality against:
20659 -- * The mode of the context
20660 -- * The mode of the private part
20664 (Nkind_In
(Decl
, N_Protected_Body
, N_Task_Body
));
20666 Check_Pragma_Conformance
20667 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20669 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
20672 Set_SPARK_Pragma
(Body_Id
, N
);
20673 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20677 --------------------------
20678 -- Process_Overloadable --
20679 --------------------------
20681 procedure Process_Overloadable
(Decl
: Node_Id
) is
20682 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20683 Spec_Typ
: constant Entity_Id
:= Etype
(Spec_Id
);
20686 Check_Library_Level_Entity
(Spec_Id
);
20688 -- Verify the legality against:
20689 -- * The mode of the context
20691 Check_Pragma_Conformance
20692 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
20694 Entity_Pragma
=> Empty
);
20696 Set_SPARK_Pragma
(Spec_Id
, N
);
20697 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
20699 -- When the pragma applies to the anonymous object created for
20700 -- a single task type, decorate the type as well. This scenario
20701 -- arises when the single task type lacks a task definition,
20702 -- therefore there is no issue with respect to a potential
20703 -- pragma SPARK_Mode in the private part.
20705 -- task type Anon_Task_Typ;
20706 -- Obj : Anon_Task_Typ;
20707 -- pragma SPARK_Mode ...;
20709 if Is_Single_Task_Object
(Spec_Id
) then
20710 Set_SPARK_Pragma
(Spec_Typ
, N
);
20711 Set_SPARK_Pragma_Inherited
(Spec_Typ
, False);
20712 Set_SPARK_Aux_Pragma
(Spec_Typ
, N
);
20713 Set_SPARK_Aux_Pragma_Inherited
(Spec_Typ
, True);
20715 end Process_Overloadable
;
20717 --------------------------
20718 -- Process_Private_Part --
20719 --------------------------
20721 procedure Process_Private_Part
(Decl
: Node_Id
) is
20722 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20725 Check_Library_Level_Entity
(Spec_Id
);
20727 -- Verify the legality against:
20728 -- * The mode of the visible declarations
20730 Check_Pragma_Conformance
20731 (Context_Pragma
=> Empty
,
20733 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
20736 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
20737 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, False);
20738 end Process_Private_Part
;
20740 ----------------------------
20741 -- Process_Statement_Part --
20742 ----------------------------
20744 procedure Process_Statement_Part
(Decl
: Node_Id
) is
20745 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20748 Check_Library_Level_Entity
(Body_Id
);
20750 -- Verify the legality against:
20751 -- * The mode of the body declarations
20753 Check_Pragma_Conformance
20754 (Context_Pragma
=> Empty
,
20756 Entity_Pragma
=> SPARK_Pragma
(Body_Id
));
20759 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
20760 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, False);
20761 end Process_Statement_Part
;
20763 --------------------------
20764 -- Process_Visible_Part --
20765 --------------------------
20767 procedure Process_Visible_Part
(Decl
: Node_Id
) is
20768 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20769 Obj_Id
: Entity_Id
;
20772 Check_Library_Level_Entity
(Spec_Id
);
20774 -- Verify the legality against:
20775 -- * The mode of the context
20777 Check_Pragma_Conformance
20778 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
20780 Entity_Pragma
=> Empty
);
20782 -- A task unit declared without a definition does not set the
20783 -- SPARK_Mode of the context because the task does not have any
20784 -- entries that could inherit the mode.
20786 if not Nkind_In
(Decl
, N_Single_Task_Declaration
,
20787 N_Task_Type_Declaration
)
20792 Set_SPARK_Pragma
(Spec_Id
, N
);
20793 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
20794 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
20795 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, True);
20797 -- When the pragma applies to a single protected or task type,
20798 -- decorate the corresponding anonymous object as well.
20800 -- protected Anon_Prot_Typ is
20801 -- pragma SPARK_Mode ...;
20803 -- end Anon_Prot_Typ;
20805 -- Obj : Anon_Prot_Typ;
20807 if Is_Single_Concurrent_Type
(Spec_Id
) then
20808 Obj_Id
:= Anonymous_Object
(Spec_Id
);
20810 Set_SPARK_Pragma
(Obj_Id
, N
);
20811 Set_SPARK_Pragma_Inherited
(Obj_Id
, False);
20813 end Process_Visible_Part
;
20815 -----------------------
20816 -- Set_SPARK_Context --
20817 -----------------------
20819 procedure Set_SPARK_Context
is
20821 SPARK_Mode
:= Mode_Id
;
20822 SPARK_Mode_Pragma
:= N
;
20824 if SPARK_Mode
= On
then
20825 Dynamic_Elaboration_Checks
:= False;
20827 end Set_SPARK_Context
;
20835 -- Start of processing for Do_SPARK_Mode
20838 -- When a SPARK_Mode pragma appears inside an instantiation whose
20839 -- enclosing context has SPARK_Mode set to "off", the pragma has
20840 -- no semantic effect.
20842 if Ignore_Pragma_SPARK_Mode
then
20843 Rewrite
(N
, Make_Null_Statement
(Loc
));
20849 Check_No_Identifiers
;
20850 Check_At_Most_N_Arguments
(1);
20852 -- Check the legality of the mode (no argument = ON)
20854 if Arg_Count
= 1 then
20855 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
20856 Mode
:= Chars
(Get_Pragma_Arg
(Arg1
));
20861 Mode_Id
:= Get_SPARK_Mode_Type
(Mode
);
20862 Context
:= Parent
(N
);
20864 -- The pragma appears in a configuration pragmas file
20866 if No
(Context
) then
20867 Check_Valid_Configuration_Pragma
;
20869 if Present
(SPARK_Mode_Pragma
) then
20870 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
20871 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
20877 -- The pragma acts as a configuration pragma in a compilation unit
20879 -- pragma SPARK_Mode ...;
20880 -- package Pack is ...;
20882 elsif Nkind
(Context
) = N_Compilation_Unit
20883 and then List_Containing
(N
) = Context_Items
(Context
)
20885 Check_Valid_Configuration_Pragma
;
20888 -- Otherwise the placement of the pragma within the tree dictates
20889 -- its associated construct. Inspect the declarative list where
20890 -- the pragma resides to find a potential construct.
20894 while Present
(Stmt
) loop
20896 -- Skip prior pragmas, but check for duplicates. Note that
20897 -- this also takes care of pragmas generated for aspects.
20899 if Nkind
(Stmt
) = N_Pragma
then
20900 if Pragma_Name
(Stmt
) = Pname
then
20901 Error_Msg_Name_1
:= Pname
;
20902 Error_Msg_Sloc
:= Sloc
(Stmt
);
20903 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
20907 -- The pragma applies to an expression function that has
20908 -- already been rewritten into a subprogram declaration.
20910 -- function Expr_Func return ... is (...);
20911 -- pragma SPARK_Mode ...;
20913 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
20914 and then Nkind
(Original_Node
(Stmt
)) =
20915 N_Expression_Function
20917 Process_Overloadable
(Stmt
);
20920 -- The pragma applies to the anonymous object created for a
20921 -- single concurrent type.
20923 -- protected type Anon_Prot_Typ ...;
20924 -- Obj : Anon_Prot_Typ;
20925 -- pragma SPARK_Mode ...;
20927 elsif Nkind
(Stmt
) = N_Object_Declaration
20928 and then Is_Single_Concurrent_Object
20929 (Defining_Entity
(Stmt
))
20931 Process_Overloadable
(Stmt
);
20934 -- Skip internally generated code
20936 elsif not Comes_From_Source
(Stmt
) then
20939 -- The pragma applies to an entry or [generic] subprogram
20943 -- pragma SPARK_Mode ...;
20946 -- procedure Proc ...;
20947 -- pragma SPARK_Mode ...;
20949 elsif Nkind_In
(Stmt
, N_Generic_Subprogram_Declaration
,
20950 N_Subprogram_Declaration
)
20951 or else (Nkind
(Stmt
) = N_Entry_Declaration
20952 and then Is_Protected_Type
20953 (Scope
(Defining_Entity
(Stmt
))))
20955 Process_Overloadable
(Stmt
);
20958 -- Otherwise the pragma does not apply to a legal construct
20959 -- or it does not appear at the top of a declarative or a
20960 -- statement list. Issue an error and stop the analysis.
20970 -- The pragma applies to a package or a subprogram that acts as
20971 -- a compilation unit.
20973 -- procedure Proc ...;
20974 -- pragma SPARK_Mode ...;
20976 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
20977 Context
:= Unit
(Parent
(Context
));
20980 -- The pragma appears at the top of entry, package, protected
20981 -- unit, subprogram or task unit body declarations.
20983 -- entry Ent when ... is
20984 -- pragma SPARK_Mode ...;
20986 -- package body Pack is
20987 -- pragma SPARK_Mode ...;
20989 -- procedure Proc ... is
20990 -- pragma SPARK_Mode;
20992 -- protected body Prot is
20993 -- pragma SPARK_Mode ...;
20995 if Nkind_In
(Context
, N_Entry_Body
,
21001 Process_Body
(Context
);
21003 -- The pragma appears at the top of the visible or private
21004 -- declaration of a package spec, protected or task unit.
21007 -- pragma SPARK_Mode ...;
21009 -- pragma SPARK_Mode ...;
21011 -- protected [type] Prot is
21012 -- pragma SPARK_Mode ...;
21014 -- pragma SPARK_Mode ...;
21016 elsif Nkind_In
(Context
, N_Package_Specification
,
21017 N_Protected_Definition
,
21020 if List_Containing
(N
) = Visible_Declarations
(Context
) then
21021 Process_Visible_Part
(Parent
(Context
));
21023 Process_Private_Part
(Parent
(Context
));
21026 -- The pragma appears at the top of package body statements
21028 -- package body Pack is
21030 -- pragma SPARK_Mode;
21032 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
21033 and then Nkind
(Parent
(Context
)) = N_Package_Body
21035 Process_Statement_Part
(Parent
(Context
));
21037 -- The pragma appeared as an aspect of a [generic] subprogram
21038 -- declaration that acts as a compilation unit.
21041 -- procedure Proc ...;
21042 -- pragma SPARK_Mode ...;
21044 elsif Nkind_In
(Context
, N_Generic_Subprogram_Declaration
,
21045 N_Subprogram_Declaration
)
21047 Process_Overloadable
(Context
);
21049 -- The pragma does not apply to a legal construct, issue error
21057 --------------------------------
21058 -- Static_Elaboration_Desired --
21059 --------------------------------
21061 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
21063 when Pragma_Static_Elaboration_Desired
=>
21065 Check_At_Most_N_Arguments
(1);
21067 if Is_Compilation_Unit
(Current_Scope
)
21068 and then Ekind
(Current_Scope
) = E_Package
21070 Set_Static_Elaboration_Desired
(Current_Scope
, True);
21072 Error_Pragma
("pragma% must apply to a library-level package");
21079 -- pragma Storage_Size (EXPRESSION);
21081 when Pragma_Storage_Size
=> Storage_Size
: declare
21082 P
: constant Node_Id
:= Parent
(N
);
21086 Check_No_Identifiers
;
21087 Check_Arg_Count
(1);
21089 -- The expression must be analyzed in the special manner described
21090 -- in "Handling of Default Expressions" in sem.ads.
21092 Arg
:= Get_Pragma_Arg
(Arg1
);
21093 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
21095 if not Is_OK_Static_Expression
(Arg
) then
21096 Check_Restriction
(Static_Storage_Size
, Arg
);
21099 if Nkind
(P
) /= N_Task_Definition
then
21104 if Has_Storage_Size_Pragma
(P
) then
21105 Error_Pragma
("duplicate pragma% not allowed");
21107 Set_Has_Storage_Size_Pragma
(P
, True);
21110 Record_Rep_Item
(Defining_Identifier
(Parent
(P
)), N
);
21118 -- pragma Storage_Unit (NUMERIC_LITERAL);
21120 -- Only permitted argument is System'Storage_Unit value
21122 when Pragma_Storage_Unit
=>
21123 Check_No_Identifiers
;
21124 Check_Arg_Count
(1);
21125 Check_Arg_Is_Integer_Literal
(Arg1
);
21127 if Intval
(Get_Pragma_Arg
(Arg1
)) /=
21128 UI_From_Int
(Ttypes
.System_Storage_Unit
)
21130 Error_Msg_Uint_1
:= UI_From_Int
(Ttypes
.System_Storage_Unit
);
21132 ("the only allowed argument for pragma% is ^", Arg1
);
21135 --------------------
21136 -- Stream_Convert --
21137 --------------------
21139 -- pragma Stream_Convert (
21140 -- [Entity =>] type_LOCAL_NAME,
21141 -- [Read =>] function_NAME,
21142 -- [Write =>] function NAME);
21144 when Pragma_Stream_Convert
=> Stream_Convert
: declare
21146 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
);
21147 -- Check that the given argument is the name of a local function
21148 -- of one argument that is not overloaded earlier in the current
21149 -- local scope. A check is also made that the argument is a
21150 -- function with one parameter.
21152 --------------------------------------
21153 -- Check_OK_Stream_Convert_Function --
21154 --------------------------------------
21156 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
) is
21160 Check_Arg_Is_Local_Name
(Arg
);
21161 Ent
:= Entity
(Get_Pragma_Arg
(Arg
));
21163 if Has_Homonym
(Ent
) then
21165 ("argument for pragma% may not be overloaded", Arg
);
21168 if Ekind
(Ent
) /= E_Function
21169 or else No
(First_Formal
(Ent
))
21170 or else Present
(Next_Formal
(First_Formal
(Ent
)))
21173 ("argument for pragma% must be function of one argument",
21176 end Check_OK_Stream_Convert_Function
;
21178 -- Start of processing for Stream_Convert
21182 Check_Arg_Order
((Name_Entity
, Name_Read
, Name_Write
));
21183 Check_Arg_Count
(3);
21184 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21185 Check_Optional_Identifier
(Arg2
, Name_Read
);
21186 Check_Optional_Identifier
(Arg3
, Name_Write
);
21187 Check_Arg_Is_Local_Name
(Arg1
);
21188 Check_OK_Stream_Convert_Function
(Arg2
);
21189 Check_OK_Stream_Convert_Function
(Arg3
);
21192 Typ
: constant Entity_Id
:=
21193 Underlying_Type
(Entity
(Get_Pragma_Arg
(Arg1
)));
21194 Read
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg2
));
21195 Write
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg3
));
21198 Check_First_Subtype
(Arg1
);
21200 -- Check for too early or too late. Note that we don't enforce
21201 -- the rule about primitive operations in this case, since, as
21202 -- is the case for explicit stream attributes themselves, these
21203 -- restrictions are not appropriate. Note that the chaining of
21204 -- the pragma by Rep_Item_Too_Late is actually the critical
21205 -- processing done for this pragma.
21207 if Rep_Item_Too_Early
(Typ
, N
)
21209 Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True)
21214 -- Return if previous error
21216 if Etype
(Typ
) = Any_Type
21218 Etype
(Read
) = Any_Type
21220 Etype
(Write
) = Any_Type
21227 if Underlying_Type
(Etype
(Read
)) /= Typ
then
21229 ("incorrect return type for function&", Arg2
);
21232 if Underlying_Type
(Etype
(First_Formal
(Write
))) /= Typ
then
21234 ("incorrect parameter type for function&", Arg3
);
21237 if Underlying_Type
(Etype
(First_Formal
(Read
))) /=
21238 Underlying_Type
(Etype
(Write
))
21241 ("result type of & does not match Read parameter type",
21245 end Stream_Convert
;
21251 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21253 -- This is processed by the parser since some of the style checks
21254 -- take place during source scanning and parsing. This means that
21255 -- we don't need to issue error messages here.
21257 when Pragma_Style_Checks
=> Style_Checks
: declare
21258 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
21264 Check_No_Identifiers
;
21266 -- Two argument form
21268 if Arg_Count
= 2 then
21269 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
21276 E_Id
:= Get_Pragma_Arg
(Arg2
);
21279 if not Is_Entity_Name
(E_Id
) then
21281 ("second argument of pragma% must be entity name",
21285 E
:= Entity
(E_Id
);
21287 if not Ignore_Style_Checks_Pragmas
then
21292 Set_Suppress_Style_Checks
21293 (E
, Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Off
);
21294 exit when No
(Homonym
(E
));
21301 -- One argument form
21304 Check_Arg_Count
(1);
21306 if Nkind
(A
) = N_String_Literal
then
21310 Slen
: constant Natural := Natural (String_Length
(S
));
21311 Options
: String (1 .. Slen
);
21317 C
:= Get_String_Char
(S
, Pos
(J
));
21318 exit when not In_Character_Range
(C
);
21319 Options
(J
) := Get_Character
(C
);
21321 -- If at end of string, set options. As per discussion
21322 -- above, no need to check for errors, since we issued
21323 -- them in the parser.
21326 if not Ignore_Style_Checks_Pragmas
then
21327 Set_Style_Check_Options
(Options
);
21337 elsif Nkind
(A
) = N_Identifier
then
21338 if Chars
(A
) = Name_All_Checks
then
21339 if not Ignore_Style_Checks_Pragmas
then
21341 Set_GNAT_Style_Check_Options
;
21343 Set_Default_Style_Check_Options
;
21347 elsif Chars
(A
) = Name_On
then
21348 if not Ignore_Style_Checks_Pragmas
then
21349 Style_Check
:= True;
21352 elsif Chars
(A
) = Name_Off
then
21353 if not Ignore_Style_Checks_Pragmas
then
21354 Style_Check
:= False;
21365 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
21367 when Pragma_Subtitle
=>
21369 Check_Arg_Count
(1);
21370 Check_Optional_Identifier
(Arg1
, Name_Subtitle
);
21371 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
21378 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
21380 when Pragma_Suppress
=>
21381 Process_Suppress_Unsuppress
(Suppress_Case
=> True);
21387 -- pragma Suppress_All;
21389 -- The only check made here is that the pragma has no arguments.
21390 -- There are no placement rules, and the processing required (setting
21391 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
21392 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
21393 -- then creates and inserts a pragma Suppress (All_Checks).
21395 when Pragma_Suppress_All
=>
21397 Check_Arg_Count
(0);
21399 -------------------------
21400 -- Suppress_Debug_Info --
21401 -------------------------
21403 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
21405 when Pragma_Suppress_Debug_Info
=> Suppress_Debug_Info
: declare
21406 Nam_Id
: Entity_Id
;
21410 Check_Arg_Count
(1);
21411 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21412 Check_Arg_Is_Local_Name
(Arg1
);
21414 Nam_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
21416 -- A pragma that applies to a Ghost entity becomes Ghost for the
21417 -- purposes of legality checks and removal of ignored Ghost code.
21419 Mark_Pragma_As_Ghost
(N
, Nam_Id
);
21420 Set_Debug_Info_Off
(Nam_Id
);
21421 end Suppress_Debug_Info
;
21423 ----------------------------------
21424 -- Suppress_Exception_Locations --
21425 ----------------------------------
21427 -- pragma Suppress_Exception_Locations;
21429 when Pragma_Suppress_Exception_Locations
=>
21431 Check_Arg_Count
(0);
21432 Check_Valid_Configuration_Pragma
;
21433 Exception_Locations_Suppressed
:= True;
21435 -----------------------------
21436 -- Suppress_Initialization --
21437 -----------------------------
21439 -- pragma Suppress_Initialization ([Entity =>] type_Name);
21441 when Pragma_Suppress_Initialization
=> Suppress_Init
: declare
21447 Check_Arg_Count
(1);
21448 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21449 Check_Arg_Is_Local_Name
(Arg1
);
21451 E_Id
:= Get_Pragma_Arg
(Arg1
);
21453 if Etype
(E_Id
) = Any_Type
then
21457 E
:= Entity
(E_Id
);
21459 -- A pragma that applies to a Ghost entity becomes Ghost for the
21460 -- purposes of legality checks and removal of ignored Ghost code.
21462 Mark_Pragma_As_Ghost
(N
, E
);
21464 if not Is_Type
(E
) and then Ekind
(E
) /= E_Variable
then
21466 ("pragma% requires variable, type or subtype", Arg1
);
21469 if Rep_Item_Too_Early
(E
, N
)
21471 Rep_Item_Too_Late
(E
, N
, FOnly
=> True)
21476 -- For incomplete/private type, set flag on full view
21478 if Is_Incomplete_Or_Private_Type
(E
) then
21479 if No
(Full_View
(Base_Type
(E
))) then
21481 ("argument of pragma% cannot be an incomplete type", Arg1
);
21483 Set_Suppress_Initialization
(Full_View
(Base_Type
(E
)));
21486 -- For first subtype, set flag on base type
21488 elsif Is_First_Subtype
(E
) then
21489 Set_Suppress_Initialization
(Base_Type
(E
));
21491 -- For other than first subtype, set flag on subtype or variable
21494 Set_Suppress_Initialization
(E
);
21502 -- pragma System_Name (DIRECT_NAME);
21504 -- Syntax check: one argument, which must be the identifier GNAT or
21505 -- the identifier GCC, no other identifiers are acceptable.
21507 when Pragma_System_Name
=>
21509 Check_No_Identifiers
;
21510 Check_Arg_Count
(1);
21511 Check_Arg_Is_One_Of
(Arg1
, Name_Gcc
, Name_Gnat
);
21513 -----------------------------
21514 -- Task_Dispatching_Policy --
21515 -----------------------------
21517 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
21519 when Pragma_Task_Dispatching_Policy
=> declare
21523 Check_Ada_83_Warning
;
21524 Check_Arg_Count
(1);
21525 Check_No_Identifiers
;
21526 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
21527 Check_Valid_Configuration_Pragma
;
21528 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
21529 DP
:= Fold_Upper
(Name_Buffer
(1));
21531 if Task_Dispatching_Policy
/= ' '
21532 and then Task_Dispatching_Policy
/= DP
21534 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
21536 ("task dispatching policy incompatible with policy#");
21538 -- Set new policy, but always preserve System_Location since we
21539 -- like the error message with the run time name.
21542 Task_Dispatching_Policy
:= DP
;
21544 if Task_Dispatching_Policy_Sloc
/= System_Location
then
21545 Task_Dispatching_Policy_Sloc
:= Loc
;
21554 -- pragma Task_Info (EXPRESSION);
21556 when Pragma_Task_Info
=> Task_Info
: declare
21557 P
: constant Node_Id
:= Parent
(N
);
21563 if Warn_On_Obsolescent_Feature
then
21565 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
21566 & "instead?j?", N
);
21569 if Nkind
(P
) /= N_Task_Definition
then
21570 Error_Pragma
("pragma% must appear in task definition");
21573 Check_No_Identifiers
;
21574 Check_Arg_Count
(1);
21576 Analyze_And_Resolve
21577 (Get_Pragma_Arg
(Arg1
), RTE
(RE_Task_Info_Type
));
21579 if Etype
(Get_Pragma_Arg
(Arg1
)) = Any_Type
then
21583 Ent
:= Defining_Identifier
(Parent
(P
));
21585 -- Check duplicate pragma before we chain the pragma in the Rep
21586 -- Item chain of Ent.
21589 (Ent
, Name_Task_Info
, Check_Parents
=> False)
21591 Error_Pragma
("duplicate pragma% not allowed");
21594 Record_Rep_Item
(Ent
, N
);
21601 -- pragma Task_Name (string_EXPRESSION);
21603 when Pragma_Task_Name
=> Task_Name
: declare
21604 P
: constant Node_Id
:= Parent
(N
);
21609 Check_No_Identifiers
;
21610 Check_Arg_Count
(1);
21612 Arg
:= Get_Pragma_Arg
(Arg1
);
21614 -- The expression is used in the call to Create_Task, and must be
21615 -- expanded there, not in the context of the current spec. It must
21616 -- however be analyzed to capture global references, in case it
21617 -- appears in a generic context.
21619 Preanalyze_And_Resolve
(Arg
, Standard_String
);
21621 if Nkind
(P
) /= N_Task_Definition
then
21625 Ent
:= Defining_Identifier
(Parent
(P
));
21627 -- Check duplicate pragma before we chain the pragma in the Rep
21628 -- Item chain of Ent.
21631 (Ent
, Name_Task_Name
, Check_Parents
=> False)
21633 Error_Pragma
("duplicate pragma% not allowed");
21636 Record_Rep_Item
(Ent
, N
);
21643 -- pragma Task_Storage (
21644 -- [Task_Type =>] LOCAL_NAME,
21645 -- [Top_Guard =>] static_integer_EXPRESSION);
21647 when Pragma_Task_Storage
=> Task_Storage
: declare
21648 Args
: Args_List
(1 .. 2);
21649 Names
: constant Name_List
(1 .. 2) := (
21653 Task_Type
: Node_Id
renames Args
(1);
21654 Top_Guard
: Node_Id
renames Args
(2);
21660 Gather_Associations
(Names
, Args
);
21662 if No
(Task_Type
) then
21664 ("missing task_type argument for pragma%");
21667 Check_Arg_Is_Local_Name
(Task_Type
);
21669 Ent
:= Entity
(Task_Type
);
21671 if not Is_Task_Type
(Ent
) then
21673 ("argument for pragma% must be task type", Task_Type
);
21676 if No
(Top_Guard
) then
21678 ("pragma% takes two arguments", Task_Type
);
21680 Check_Arg_Is_OK_Static_Expression
(Top_Guard
, Any_Integer
);
21683 Check_First_Subtype
(Task_Type
);
21685 if Rep_Item_Too_Late
(Ent
, N
) then
21694 -- pragma Test_Case
21695 -- ([Name =>] Static_String_EXPRESSION
21696 -- ,[Mode =>] MODE_TYPE
21697 -- [, Requires => Boolean_EXPRESSION]
21698 -- [, Ensures => Boolean_EXPRESSION]);
21700 -- MODE_TYPE ::= Nominal | Robustness
21702 -- Characteristics:
21704 -- * Analysis - The annotation undergoes initial checks to verify
21705 -- the legal placement and context. Secondary checks preanalyze the
21708 -- Analyze_Test_Case_In_Decl_Part
21710 -- * Expansion - None.
21712 -- * Template - The annotation utilizes the generic template of the
21713 -- related subprogram when it is:
21715 -- aspect on subprogram declaration
21717 -- The annotation must prepare its own template when it is:
21719 -- pragma on subprogram declaration
21721 -- * Globals - Capture of global references must occur after full
21724 -- * Instance - The annotation is instantiated automatically when
21725 -- the related generic subprogram is instantiated except for the
21726 -- "pragma on subprogram declaration" case. In that scenario the
21727 -- annotation must instantiate itself.
21729 when Pragma_Test_Case
=> Test_Case
: declare
21730 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
);
21731 -- Ensure that the contract of subprogram Subp_Id does not contain
21732 -- another Test_Case pragma with the same Name as the current one.
21734 -------------------------
21735 -- Check_Distinct_Name --
21736 -------------------------
21738 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
) is
21739 Items
: constant Node_Id
:= Contract
(Subp_Id
);
21740 Name
: constant String_Id
:= Get_Name_From_CTC_Pragma
(N
);
21744 -- Inspect all Test_Case pragma of the related subprogram
21745 -- looking for one with a duplicate "Name" argument.
21747 if Present
(Items
) then
21748 Prag
:= Contract_Test_Cases
(Items
);
21749 while Present
(Prag
) loop
21750 if Pragma_Name
(Prag
) = Name_Test_Case
21752 and then String_Equal
21753 (Name
, Get_Name_From_CTC_Pragma
(Prag
))
21755 Error_Msg_Sloc
:= Sloc
(Prag
);
21756 Error_Pragma
("name for pragma % is already used #");
21759 Prag
:= Next_Pragma
(Prag
);
21762 end Check_Distinct_Name
;
21766 Pack_Decl
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
21769 Subp_Decl
: Node_Id
;
21770 Subp_Id
: Entity_Id
;
21772 -- Start of processing for Test_Case
21776 Check_At_Least_N_Arguments
(2);
21777 Check_At_Most_N_Arguments
(4);
21779 ((Name_Name
, Name_Mode
, Name_Requires
, Name_Ensures
));
21783 Check_Optional_Identifier
(Arg1
, Name_Name
);
21784 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
21788 Check_Optional_Identifier
(Arg2
, Name_Mode
);
21789 Check_Arg_Is_One_Of
(Arg2
, Name_Nominal
, Name_Robustness
);
21791 -- Arguments "Requires" and "Ensures"
21793 if Present
(Arg3
) then
21794 if Present
(Arg4
) then
21795 Check_Identifier
(Arg3
, Name_Requires
);
21796 Check_Identifier
(Arg4
, Name_Ensures
);
21798 Check_Identifier_Is_One_Of
21799 (Arg3
, Name_Requires
, Name_Ensures
);
21803 -- Pragma Test_Case must be associated with a subprogram declared
21804 -- in a library-level package. First determine whether the current
21805 -- compilation unit is a legal context.
21807 if Nkind_In
(Pack_Decl
, N_Package_Declaration
,
21808 N_Generic_Package_Declaration
)
21812 -- Otherwise the placement is illegal
21816 ("pragma % must be specified within a package declaration");
21820 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
);
21822 -- Find the enclosing context
21824 Context
:= Parent
(Subp_Decl
);
21826 if Present
(Context
) then
21827 Context
:= Parent
(Context
);
21830 -- Verify the placement of the pragma
21832 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
21834 ("pragma % cannot be applied to abstract subprogram");
21837 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
21838 Error_Pragma
("pragma % cannot be applied to entry");
21841 -- The context is a [generic] subprogram declared at the top level
21842 -- of the [generic] package unit.
21844 elsif Nkind_In
(Subp_Decl
, N_Generic_Subprogram_Declaration
,
21845 N_Subprogram_Declaration
)
21846 and then Present
(Context
)
21847 and then Nkind_In
(Context
, N_Generic_Package_Declaration
,
21848 N_Package_Declaration
)
21852 -- Otherwise the placement is illegal
21856 ("pragma % must be applied to a library-level subprogram "
21861 Subp_Id
:= Defining_Entity
(Subp_Decl
);
21863 -- Chain the pragma on the contract for further processing by
21864 -- Analyze_Test_Case_In_Decl_Part.
21866 Add_Contract_Item
(N
, Subp_Id
);
21868 -- A pragma that applies to a Ghost entity becomes Ghost for the
21869 -- purposes of legality checks and removal of ignored Ghost code.
21871 Mark_Pragma_As_Ghost
(N
, Subp_Id
);
21873 -- Preanalyze the original aspect argument "Name" for ASIS or for
21874 -- a generic subprogram to properly capture global references.
21876 if ASIS_Mode
or else Is_Generic_Subprogram
(Subp_Id
) then
21877 Asp_Arg
:= Test_Case_Arg
(N
, Name_Name
, From_Aspect
=> True);
21879 if Present
(Asp_Arg
) then
21881 -- The argument appears with an identifier in association
21884 if Nkind
(Asp_Arg
) = N_Component_Association
then
21885 Asp_Arg
:= Expression
(Asp_Arg
);
21888 Check_Expr_Is_OK_Static_Expression
21889 (Asp_Arg
, Standard_String
);
21893 -- Ensure that the all Test_Case pragmas of the related subprogram
21894 -- have distinct names.
21896 Check_Distinct_Name
(Subp_Id
);
21898 -- Fully analyze the pragma when it appears inside an entry
21899 -- or subprogram body because it cannot benefit from forward
21902 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
21904 N_Subprogram_Body_Stub
)
21906 -- The legality checks of pragma Test_Case are affected by the
21907 -- SPARK mode in effect and the volatility of the context.
21908 -- Analyze all pragmas in a specific order.
21910 Analyze_If_Present
(Pragma_SPARK_Mode
);
21911 Analyze_If_Present
(Pragma_Volatile_Function
);
21912 Analyze_Test_Case_In_Decl_Part
(N
);
21916 --------------------------
21917 -- Thread_Local_Storage --
21918 --------------------------
21920 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
21922 when Pragma_Thread_Local_Storage
=> Thread_Local_Storage
: declare
21928 Check_Arg_Count
(1);
21929 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21930 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
21932 Id
:= Get_Pragma_Arg
(Arg1
);
21935 if not Is_Entity_Name
(Id
)
21936 or else Ekind
(Entity
(Id
)) /= E_Variable
21938 Error_Pragma_Arg
("local variable name required", Arg1
);
21943 -- A pragma that applies to a Ghost entity becomes Ghost for the
21944 -- purposes of legality checks and removal of ignored Ghost code.
21946 Mark_Pragma_As_Ghost
(N
, E
);
21948 if Rep_Item_Too_Early
(E
, N
)
21950 Rep_Item_Too_Late
(E
, N
)
21955 Set_Has_Pragma_Thread_Local_Storage
(E
);
21956 Set_Has_Gigi_Rep_Item
(E
);
21957 end Thread_Local_Storage
;
21963 -- pragma Time_Slice (static_duration_EXPRESSION);
21965 when Pragma_Time_Slice
=> Time_Slice
: declare
21971 Check_Arg_Count
(1);
21972 Check_No_Identifiers
;
21973 Check_In_Main_Program
;
21974 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_Duration
);
21976 if not Error_Posted
(Arg1
) then
21978 while Present
(Nod
) loop
21979 if Nkind
(Nod
) = N_Pragma
21980 and then Pragma_Name
(Nod
) = Name_Time_Slice
21982 Error_Msg_Name_1
:= Pname
;
21983 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
21990 -- Process only if in main unit
21992 if Get_Source_Unit
(Loc
) = Main_Unit
then
21993 Opt
.Time_Slice_Set
:= True;
21994 Val
:= Expr_Value_R
(Get_Pragma_Arg
(Arg1
));
21996 if Val
<= Ureal_0
then
21997 Opt
.Time_Slice_Value
:= 0;
21999 elsif Val
> UR_From_Uint
(UI_From_Int
(1000)) then
22000 Opt
.Time_Slice_Value
:= 1_000_000_000
;
22003 Opt
.Time_Slice_Value
:=
22004 UI_To_Int
(UR_To_Uint
(Val
* UI_From_Int
(1_000_000
)));
22013 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
22015 -- TITLING_OPTION ::=
22016 -- [Title =>] STRING_LITERAL
22017 -- | [Subtitle =>] STRING_LITERAL
22019 when Pragma_Title
=> Title
: declare
22020 Args
: Args_List
(1 .. 2);
22021 Names
: constant Name_List
(1 .. 2) := (
22027 Gather_Associations
(Names
, Args
);
22030 for J
in 1 .. 2 loop
22031 if Present
(Args
(J
)) then
22032 Check_Arg_Is_OK_Static_Expression
22033 (Args
(J
), Standard_String
);
22038 ----------------------------
22039 -- Type_Invariant[_Class] --
22040 ----------------------------
22042 -- pragma Type_Invariant[_Class]
22043 -- ([Entity =>] type_LOCAL_NAME,
22044 -- [Check =>] EXPRESSION);
22046 when Pragma_Type_Invariant |
22047 Pragma_Type_Invariant_Class
=>
22048 Type_Invariant
: declare
22049 I_Pragma
: Node_Id
;
22052 Check_Arg_Count
(2);
22054 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
22055 -- setting Class_Present for the Type_Invariant_Class case.
22057 Set_Class_Present
(N
, Prag_Id
= Pragma_Type_Invariant_Class
);
22058 I_Pragma
:= New_Copy
(N
);
22059 Set_Pragma_Identifier
22060 (I_Pragma
, Make_Identifier
(Loc
, Name_Invariant
));
22061 Rewrite
(N
, I_Pragma
);
22062 Set_Analyzed
(N
, False);
22064 end Type_Invariant
;
22066 ---------------------
22067 -- Unchecked_Union --
22068 ---------------------
22070 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
22072 when Pragma_Unchecked_Union
=> Unchecked_Union
: declare
22073 Assoc
: constant Node_Id
:= Arg1
;
22074 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
22084 Check_No_Identifiers
;
22085 Check_Arg_Count
(1);
22086 Check_Arg_Is_Local_Name
(Arg1
);
22088 Find_Type
(Type_Id
);
22090 Typ
:= Entity
(Type_Id
);
22092 -- A pragma that applies to a Ghost entity becomes Ghost for the
22093 -- purposes of legality checks and removal of ignored Ghost code.
22095 Mark_Pragma_As_Ghost
(N
, Typ
);
22098 or else Rep_Item_Too_Early
(Typ
, N
)
22102 Typ
:= Underlying_Type
(Typ
);
22105 if Rep_Item_Too_Late
(Typ
, N
) then
22109 Check_First_Subtype
(Arg1
);
22111 -- Note remaining cases are references to a type in the current
22112 -- declarative part. If we find an error, we post the error on
22113 -- the relevant type declaration at an appropriate point.
22115 if not Is_Record_Type
(Typ
) then
22116 Error_Msg_N
("unchecked union must be record type", Typ
);
22119 elsif Is_Tagged_Type
(Typ
) then
22120 Error_Msg_N
("unchecked union must not be tagged", Typ
);
22123 elsif not Has_Discriminants
(Typ
) then
22125 ("unchecked union must have one discriminant", Typ
);
22128 -- Note: in previous versions of GNAT we used to check for limited
22129 -- types and give an error, but in fact the standard does allow
22130 -- Unchecked_Union on limited types, so this check was removed.
22132 -- Similarly, GNAT used to require that all discriminants have
22133 -- default values, but this is not mandated by the RM.
22135 -- Proceed with basic error checks completed
22138 Tdef
:= Type_Definition
(Declaration_Node
(Typ
));
22139 Clist
:= Component_List
(Tdef
);
22141 -- Check presence of component list and variant part
22143 if No
(Clist
) or else No
(Variant_Part
(Clist
)) then
22145 ("unchecked union must have variant part", Tdef
);
22149 -- Check components
22151 Comp
:= First
(Component_Items
(Clist
));
22152 while Present
(Comp
) loop
22153 Check_Component
(Comp
, Typ
);
22157 -- Check variant part
22159 Vpart
:= Variant_Part
(Clist
);
22161 Variant
:= First
(Variants
(Vpart
));
22162 while Present
(Variant
) loop
22163 Check_Variant
(Variant
, Typ
);
22168 Set_Is_Unchecked_Union
(Typ
);
22169 Set_Convention
(Typ
, Convention_C
);
22170 Set_Has_Unchecked_Union
(Base_Type
(Typ
));
22171 Set_Is_Unchecked_Union
(Base_Type
(Typ
));
22172 end Unchecked_Union
;
22174 ------------------------
22175 -- Unimplemented_Unit --
22176 ------------------------
22178 -- pragma Unimplemented_Unit;
22180 -- Note: this only gives an error if we are generating code, or if
22181 -- we are in a generic library unit (where the pragma appears in the
22182 -- body, not in the spec).
22184 when Pragma_Unimplemented_Unit
=> Unimplemented_Unit
: declare
22185 Cunitent
: constant Entity_Id
:=
22186 Cunit_Entity
(Get_Source_Unit
(Loc
));
22187 Ent_Kind
: constant Entity_Kind
:=
22192 Check_Arg_Count
(0);
22194 if Operating_Mode
= Generate_Code
22195 or else Ent_Kind
= E_Generic_Function
22196 or else Ent_Kind
= E_Generic_Procedure
22197 or else Ent_Kind
= E_Generic_Package
22199 Get_Name_String
(Chars
(Cunitent
));
22200 Set_Casing
(Mixed_Case
);
22201 Write_Str
(Name_Buffer
(1 .. Name_Len
));
22202 Write_Str
(" is not supported in this configuration");
22204 raise Unrecoverable_Error
;
22206 end Unimplemented_Unit
;
22208 ------------------------
22209 -- Universal_Aliasing --
22210 ------------------------
22212 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
22214 when Pragma_Universal_Aliasing
=> Universal_Alias
: declare
22219 Check_Arg_Count
(1);
22220 Check_Optional_Identifier
(Arg2
, Name_Entity
);
22221 Check_Arg_Is_Local_Name
(Arg1
);
22222 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
22224 if E_Id
= Any_Type
then
22226 elsif No
(E_Id
) or else not Is_Type
(E_Id
) then
22227 Error_Pragma_Arg
("pragma% requires type", Arg1
);
22230 -- A pragma that applies to a Ghost entity becomes Ghost for the
22231 -- purposes of legality checks and removal of ignored Ghost code.
22233 Mark_Pragma_As_Ghost
(N
, E_Id
);
22234 Set_Universal_Aliasing
(Implementation_Base_Type
(E_Id
));
22235 Record_Rep_Item
(E_Id
, N
);
22236 end Universal_Alias
;
22238 --------------------
22239 -- Universal_Data --
22240 --------------------
22242 -- pragma Universal_Data [(library_unit_NAME)];
22244 when Pragma_Universal_Data
=>
22247 -- If this is a configuration pragma, then set the universal
22248 -- addressing option, otherwise confirm that the pragma satisfies
22249 -- the requirements of library unit pragma placement and leave it
22250 -- to the GNAAMP back end to detect the pragma (avoids transitive
22251 -- setting of the option due to withed units).
22253 if Is_Configuration_Pragma
then
22254 Universal_Addressing_On_AAMP
:= True;
22256 Check_Valid_Library_Unit_Pragma
;
22259 if not AAMP_On_Target
then
22260 Error_Pragma
("??pragma% ignored (applies only to AAMP)");
22267 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
22269 when Pragma_Unmodified
=> Unmodified
: declare
22271 Arg_Expr
: Node_Id
;
22272 Arg_Id
: Entity_Id
;
22274 Ghost_Error_Posted
: Boolean := False;
22275 -- Flag set when an error concerning the illegal mix of Ghost and
22276 -- non-Ghost variables is emitted.
22278 Ghost_Id
: Entity_Id
:= Empty
;
22279 -- The entity of the first Ghost variable encountered while
22280 -- processing the arguments of the pragma.
22284 Check_At_Least_N_Arguments
(1);
22286 -- Loop through arguments
22289 while Present
(Arg
) loop
22290 Check_No_Identifier
(Arg
);
22292 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
22293 -- in fact generate reference, so that the entity will have a
22294 -- reference, which will inhibit any warnings about it not
22295 -- being referenced, and also properly show up in the ali file
22296 -- as a reference. But this reference is recorded before the
22297 -- Has_Pragma_Unreferenced flag is set, so that no warning is
22298 -- generated for this reference.
22300 Check_Arg_Is_Local_Name
(Arg
);
22301 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22303 if Is_Entity_Name
(Arg_Expr
) then
22304 Arg_Id
:= Entity
(Arg_Expr
);
22306 if Is_Assignable
(Arg_Id
) then
22307 Set_Has_Pragma_Unmodified
(Arg_Id
);
22309 -- A pragma that applies to a Ghost entity becomes Ghost
22310 -- for the purposes of legality checks and removal of
22311 -- ignored Ghost code.
22313 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22315 -- Capture the entity of the first Ghost variable being
22316 -- processed for error detection purposes.
22318 if Is_Ghost_Entity
(Arg_Id
) then
22319 if No
(Ghost_Id
) then
22320 Ghost_Id
:= Arg_Id
;
22323 -- Otherwise the variable is non-Ghost. It is illegal
22324 -- to mix references to Ghost and non-Ghost entities
22327 elsif Present
(Ghost_Id
)
22328 and then not Ghost_Error_Posted
22330 Ghost_Error_Posted
:= True;
22332 Error_Msg_Name_1
:= Pname
;
22334 ("pragma % cannot mention ghost and non-ghost "
22337 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22338 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22340 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22341 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22344 -- Otherwise the pragma referenced an illegal entity
22348 ("pragma% can only be applied to a variable", Arg_Expr
);
22360 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
22362 -- or when used in a context clause:
22364 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
22366 when Pragma_Unreferenced
=> Unreferenced
: declare
22368 Arg_Expr
: Node_Id
;
22369 Arg_Id
: Entity_Id
;
22372 Ghost_Error_Posted
: Boolean := False;
22373 -- Flag set when an error concerning the illegal mix of Ghost and
22374 -- non-Ghost names is emitted.
22376 Ghost_Id
: Entity_Id
:= Empty
;
22377 -- The entity of the first Ghost name encountered while processing
22378 -- the arguments of the pragma.
22382 Check_At_Least_N_Arguments
(1);
22384 -- Check case of appearing within context clause
22386 if Is_In_Context_Clause
then
22388 -- The arguments must all be units mentioned in a with clause
22389 -- in the same context clause. Note we already checked (in
22390 -- Par.Prag) that the arguments are either identifiers or
22391 -- selected components.
22394 while Present
(Arg
) loop
22395 Citem
:= First
(List_Containing
(N
));
22396 while Citem
/= N
loop
22397 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22399 if Nkind
(Citem
) = N_With_Clause
22400 and then Same_Name
(Name
(Citem
), Arg_Expr
)
22402 Set_Has_Pragma_Unreferenced
22405 (Library_Unit
(Citem
))));
22406 Set_Elab_Unit_Name
(Arg_Expr
, Name
(Citem
));
22415 ("argument of pragma% is not withed unit", Arg
);
22421 -- Case of not in list of context items
22425 while Present
(Arg
) loop
22426 Check_No_Identifier
(Arg
);
22428 -- Note: the analyze call done by Check_Arg_Is_Local_Name
22429 -- will in fact generate reference, so that the entity will
22430 -- have a reference, which will inhibit any warnings about
22431 -- it not being referenced, and also properly show up in the
22432 -- ali file as a reference. But this reference is recorded
22433 -- before the Has_Pragma_Unreferenced flag is set, so that
22434 -- no warning is generated for this reference.
22436 Check_Arg_Is_Local_Name
(Arg
);
22437 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22439 if Is_Entity_Name
(Arg_Expr
) then
22440 Arg_Id
:= Entity
(Arg_Expr
);
22442 -- If the entity is overloaded, the pragma applies to the
22443 -- most recent overloading, as documented. In this case,
22444 -- name resolution does not generate a reference, so it
22445 -- must be done here explicitly.
22447 if Is_Overloaded
(Arg_Expr
) then
22448 Generate_Reference
(Arg_Id
, N
);
22451 Set_Has_Pragma_Unreferenced
(Arg_Id
);
22453 -- A pragma that applies to a Ghost entity becomes Ghost
22454 -- for the purposes of legality checks and removal of
22455 -- ignored Ghost code.
22457 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22459 -- Capture the entity of the first Ghost name being
22460 -- processed for error detection purposes.
22462 if Is_Ghost_Entity
(Arg_Id
) then
22463 if No
(Ghost_Id
) then
22464 Ghost_Id
:= Arg_Id
;
22467 -- Otherwise the name is non-Ghost. It is illegal to mix
22468 -- references to Ghost and non-Ghost entities
22471 elsif Present
(Ghost_Id
)
22472 and then not Ghost_Error_Posted
22474 Ghost_Error_Posted
:= True;
22476 Error_Msg_Name_1
:= Pname
;
22478 ("pragma % cannot mention ghost and non-ghost names",
22481 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22482 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22484 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22485 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22494 --------------------------
22495 -- Unreferenced_Objects --
22496 --------------------------
22498 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
22500 when Pragma_Unreferenced_Objects
=> Unreferenced_Objects
: declare
22502 Arg_Expr
: Node_Id
;
22503 Arg_Id
: Entity_Id
;
22505 Ghost_Error_Posted
: Boolean := False;
22506 -- Flag set when an error concerning the illegal mix of Ghost and
22507 -- non-Ghost types is emitted.
22509 Ghost_Id
: Entity_Id
:= Empty
;
22510 -- The entity of the first Ghost type encountered while processing
22511 -- the arguments of the pragma.
22515 Check_At_Least_N_Arguments
(1);
22518 while Present
(Arg
) loop
22519 Check_No_Identifier
(Arg
);
22520 Check_Arg_Is_Local_Name
(Arg
);
22521 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22523 if Is_Entity_Name
(Arg_Expr
) then
22524 Arg_Id
:= Entity
(Arg_Expr
);
22526 if Is_Type
(Arg_Id
) then
22527 Set_Has_Pragma_Unreferenced_Objects
(Arg_Id
);
22529 -- A pragma that applies to a Ghost entity becomes Ghost
22530 -- for the purposes of legality checks and removal of
22531 -- ignored Ghost code.
22533 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22535 -- Capture the entity of the first Ghost type being
22536 -- processed for error detection purposes.
22538 if Is_Ghost_Entity
(Arg_Id
) then
22539 if No
(Ghost_Id
) then
22540 Ghost_Id
:= Arg_Id
;
22543 -- Otherwise the type is non-Ghost. It is illegal to mix
22544 -- references to Ghost and non-Ghost entities
22547 elsif Present
(Ghost_Id
)
22548 and then not Ghost_Error_Posted
22550 Ghost_Error_Posted
:= True;
22552 Error_Msg_Name_1
:= Pname
;
22554 ("pragma % cannot mention ghost and non-ghost types",
22557 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22558 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22560 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22561 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22565 ("argument for pragma% must be type or subtype", Arg
);
22569 ("argument for pragma% must be type or subtype", Arg
);
22574 end Unreferenced_Objects
;
22576 ------------------------------
22577 -- Unreserve_All_Interrupts --
22578 ------------------------------
22580 -- pragma Unreserve_All_Interrupts;
22582 when Pragma_Unreserve_All_Interrupts
=>
22584 Check_Arg_Count
(0);
22586 if In_Extended_Main_Code_Unit
(Main_Unit_Entity
) then
22587 Unreserve_All_Interrupts
:= True;
22594 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
22596 when Pragma_Unsuppress
=>
22598 Process_Suppress_Unsuppress
(Suppress_Case
=> False);
22600 ----------------------------
22601 -- Unevaluated_Use_Of_Old --
22602 ----------------------------
22604 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
22606 when Pragma_Unevaluated_Use_Of_Old
=>
22608 Check_Arg_Count
(1);
22609 Check_No_Identifiers
;
22610 Check_Arg_Is_One_Of
(Arg1
, Name_Error
, Name_Warn
, Name_Allow
);
22612 -- Suppress/Unsuppress can appear as a configuration pragma, or in
22613 -- a declarative part or a package spec.
22615 if not Is_Configuration_Pragma
then
22616 Check_Is_In_Decl_Part_Or_Package_Spec
;
22619 -- Store proper setting of Uneval_Old
22621 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
22622 Uneval_Old
:= Fold_Upper
(Name_Buffer
(1));
22624 -------------------
22625 -- Use_VADS_Size --
22626 -------------------
22628 -- pragma Use_VADS_Size;
22630 when Pragma_Use_VADS_Size
=>
22632 Check_Arg_Count
(0);
22633 Check_Valid_Configuration_Pragma
;
22634 Use_VADS_Size
:= True;
22636 ---------------------
22637 -- Validity_Checks --
22638 ---------------------
22640 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22642 when Pragma_Validity_Checks
=> Validity_Checks
: declare
22643 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
22649 Check_Arg_Count
(1);
22650 Check_No_Identifiers
;
22652 -- Pragma always active unless in CodePeer or GNATprove modes,
22653 -- which use a fixed configuration of validity checks.
22655 if not (CodePeer_Mode
or GNATprove_Mode
) then
22656 if Nkind
(A
) = N_String_Literal
then
22660 Slen
: constant Natural := Natural (String_Length
(S
));
22661 Options
: String (1 .. Slen
);
22665 -- Couldn't we use a for loop here over Options'Range???
22669 C
:= Get_String_Char
(S
, Pos
(J
));
22671 -- This is a weird test, it skips setting validity
22672 -- checks entirely if any element of S is out of
22673 -- range of Character, what is that about ???
22675 exit when not In_Character_Range
(C
);
22676 Options
(J
) := Get_Character
(C
);
22679 Set_Validity_Check_Options
(Options
);
22687 elsif Nkind
(A
) = N_Identifier
then
22688 if Chars
(A
) = Name_All_Checks
then
22689 Set_Validity_Check_Options
("a");
22690 elsif Chars
(A
) = Name_On
then
22691 Validity_Checks_On
:= True;
22692 elsif Chars
(A
) = Name_Off
then
22693 Validity_Checks_On
:= False;
22697 end Validity_Checks
;
22703 -- pragma Volatile (LOCAL_NAME);
22705 when Pragma_Volatile
=>
22706 Process_Atomic_Independent_Shared_Volatile
;
22708 -------------------------
22709 -- Volatile_Components --
22710 -------------------------
22712 -- pragma Volatile_Components (array_LOCAL_NAME);
22714 -- Volatile is handled by the same circuit as Atomic_Components
22716 --------------------------
22717 -- Volatile_Full_Access --
22718 --------------------------
22720 -- pragma Volatile_Full_Access (LOCAL_NAME);
22722 when Pragma_Volatile_Full_Access
=>
22724 Process_Atomic_Independent_Shared_Volatile
;
22726 -----------------------
22727 -- Volatile_Function --
22728 -----------------------
22730 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
22732 when Pragma_Volatile_Function
=> Volatile_Function
: declare
22733 Over_Id
: Entity_Id
;
22734 Spec_Id
: Entity_Id
;
22735 Subp_Decl
: Node_Id
;
22739 Check_No_Identifiers
;
22740 Check_At_Most_N_Arguments
(1);
22743 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
22745 -- Generic subprogram
22747 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
22750 -- Body acts as spec
22752 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
22753 and then No
(Corresponding_Spec
(Subp_Decl
))
22757 -- Body stub acts as spec
22759 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
22760 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
22766 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
22774 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
22776 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
22781 -- Chain the pragma on the contract for completeness
22783 Add_Contract_Item
(N
, Spec_Id
);
22785 -- The legality checks of pragma Volatile_Function are affected by
22786 -- the SPARK mode in effect. Analyze all pragmas in a specific
22789 Analyze_If_Present
(Pragma_SPARK_Mode
);
22791 -- A pragma that applies to a Ghost entity becomes Ghost for the
22792 -- purposes of legality checks and removal of ignored Ghost code.
22794 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
22796 -- A volatile function cannot override a non-volatile function
22797 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
22798 -- in New_Overloaded_Entity, however at that point the pragma has
22799 -- not been processed yet.
22801 Over_Id
:= Overridden_Operation
(Spec_Id
);
22803 if Present
(Over_Id
)
22804 and then not Is_Volatile_Function
(Over_Id
)
22807 ("incompatible volatile function values in effect", Spec_Id
);
22809 Error_Msg_Sloc
:= Sloc
(Over_Id
);
22811 ("\& declared # with Volatile_Function value `False`",
22814 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
22816 ("\overridden # with Volatile_Function value `True`",
22820 -- Analyze the Boolean expression (if any)
22822 if Present
(Arg1
) then
22823 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
22825 end Volatile_Function
;
22827 ----------------------
22828 -- Warning_As_Error --
22829 ----------------------
22831 -- pragma Warning_As_Error (static_string_EXPRESSION);
22833 when Pragma_Warning_As_Error
=>
22835 Check_Arg_Count
(1);
22836 Check_No_Identifiers
;
22837 Check_Valid_Configuration_Pragma
;
22839 if not Is_Static_String_Expression
(Arg1
) then
22841 ("argument of pragma% must be static string expression",
22844 -- OK static string expression
22847 Acquire_Warning_Match_String
(Arg1
);
22848 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
22849 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
22850 new String'(Name_Buffer (1 .. Name_Len));
22857 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
22859 -- DETAILS ::= On | Off
22860 -- DETAILS ::= On | Off, local_NAME
22861 -- DETAILS ::= static_string_EXPRESSION
22862 -- DETAILS ::= On | Off, static_string_EXPRESSION
22864 -- TOOL_NAME ::= GNAT | GNATProve
22866 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
22868 -- Note: If the first argument matches an allowed tool name, it is
22869 -- always considered to be a tool name, even if there is a string
22870 -- variable of that name.
22872 -- Note if the second argument of DETAILS is a local_NAME then the
22873 -- second form is always understood. If the intention is to use
22874 -- the fourth form, then you can write NAME & "" to force the
22875 -- intepretation as a static_string_EXPRESSION.
22877 when Pragma_Warnings => Warnings : declare
22878 Reason : String_Id;
22882 Check_At_Least_N_Arguments (1);
22884 -- See if last argument is labeled Reason. If so, make sure we
22885 -- have a string literal or a concatenation of string literals,
22886 -- and acquire the REASON string. Then remove the REASON argument
22887 -- by decreasing Num_Args by one; Remaining processing looks only
22888 -- at first Num_Args arguments).
22891 Last_Arg : constant Node_Id :=
22892 Last (Pragma_Argument_Associations (N));
22895 if Nkind (Last_Arg) = N_Pragma_Argument_Association
22896 and then Chars (Last_Arg) = Name_Reason
22899 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
22900 Reason := End_String;
22901 Arg_Count := Arg_Count - 1;
22903 -- Not allowed in compiler units (bootstrap issues)
22905 Check_Compiler_Unit ("Reason for pragma Warnings", N);
22907 -- No REASON string, set null string as reason
22910 Reason := Null_String_Id;
22914 -- Now proceed with REASON taken care of and eliminated
22916 Check_No_Identifiers;
22918 -- If debug flag -gnatd.i is set, pragma is ignored
22920 if Debug_Flag_Dot_I then
22924 -- Process various forms of the pragma
22927 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22928 Shifted_Args : List_Id;
22931 -- See if first argument is a tool name, currently either
22932 -- GNAT or GNATprove. If so, either ignore the pragma if the
22933 -- tool used does not match, or continue as if no tool name
22934 -- was given otherwise, by shifting the arguments.
22936 if Nkind (Argx) = N_Identifier
22937 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
22939 if Chars (Argx) = Name_Gnat then
22940 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
22941 Rewrite (N, Make_Null_Statement (Loc));
22946 elsif Chars (Argx) = Name_Gnatprove then
22947 if not GNATprove_Mode then
22948 Rewrite (N, Make_Null_Statement (Loc));
22954 raise Program_Error;
22957 -- At this point, the pragma Warnings applies to the tool,
22958 -- so continue with shifted arguments.
22960 Arg_Count := Arg_Count - 1;
22962 if Arg_Count = 1 then
22963 Shifted_Args := New_List (New_Copy (Arg2));
22964 elsif Arg_Count = 2 then
22965 Shifted_Args := New_List (New_Copy (Arg2),
22967 elsif Arg_Count = 3 then
22968 Shifted_Args := New_List (New_Copy (Arg2),
22972 raise Program_Error;
22977 Chars => Name_Warnings,
22978 Pragma_Argument_Associations => Shifted_Args));
22983 -- One argument case
22985 if Arg_Count = 1 then
22987 -- On/Off one argument case was processed by parser
22989 if Nkind (Argx) = N_Identifier
22990 and then Nam_In (Chars (Argx), Name_On, Name_Off)
22994 -- One argument case must be ON/OFF or static string expr
22996 elsif not Is_Static_String_Expression (Arg1) then
22998 ("argument of pragma% must be On/Off or static string "
22999 & "expression", Arg1);
23001 -- One argument string expression case
23005 Lit : constant Node_Id := Expr_Value_S (Argx);
23006 Str : constant String_Id := Strval (Lit);
23007 Len : constant Nat := String_Length (Str);
23015 while J <= Len loop
23016 C := Get_String_Char (Str, J);
23017 OK := In_Character_Range (C);
23020 Chr := Get_Character (C);
23022 -- Dash case: only -Wxxx is accepted
23029 C := Get_String_Char (Str, J);
23030 Chr := Get_Character (C);
23031 exit when Chr = 'W
';
23036 elsif J < Len and then Chr = '.' then
23038 C := Get_String_Char (Str, J);
23039 Chr := Get_Character (C);
23041 if not Set_Dot_Warning_Switch (Chr) then
23043 ("invalid warning switch character "
23044 & '.' & Chr, Arg1);
23050 OK := Set_Warning_Switch (Chr);
23056 ("invalid warning switch character " & Chr,
23065 -- Two or more arguments (must be two)
23068 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23069 Check_Arg_Count (2);
23077 E_Id := Get_Pragma_Arg (Arg2);
23080 -- In the expansion of an inlined body, a reference to
23081 -- the formal may be wrapped in a conversion if the
23082 -- actual is a conversion. Retrieve the real entity name.
23084 if (In_Instance_Body or In_Inlined_Body)
23085 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
23087 E_Id := Expression (E_Id);
23090 -- Entity name case
23092 if Is_Entity_Name (E_Id) then
23093 E := Entity (E_Id);
23100 (E, (Chars (Get_Pragma_Arg (Arg1)) =
23103 -- For OFF case, make entry in warnings off
23104 -- pragma table for later processing. But we do
23105 -- not do that within an instance, since these
23106 -- warnings are about what is needed in the
23107 -- template, not an instance of it.
23109 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
23110 and then Warn_On_Warnings_Off
23111 and then not In_Instance
23113 Warnings_Off_Pragmas.Append ((N, E, Reason));
23116 if Is_Enumeration_Type (E) then
23120 Lit := First_Literal (E);
23121 while Present (Lit) loop
23122 Set_Warnings_Off (Lit);
23123 Next_Literal (Lit);
23128 exit when No (Homonym (E));
23133 -- Error if not entity or static string expression case
23135 elsif not Is_Static_String_Expression (Arg2) then
23137 ("second argument of pragma% must be entity name "
23138 & "or static string expression", Arg2);
23140 -- Static string expression case
23143 Acquire_Warning_Match_String (Arg2);
23145 -- Note on configuration pragma case: If this is a
23146 -- configuration pragma, then for an OFF pragma, we
23147 -- just set Config True in the call, which is all
23148 -- that needs to be done. For the case of ON, this
23149 -- is normally an error, unless it is canceling the
23150 -- effect of a previous OFF pragma in the same file.
23151 -- In any other case, an error will be signalled (ON
23152 -- with no matching OFF).
23154 -- Note: We set Used if we are inside a generic to
23155 -- disable the test that the non-config case actually
23156 -- cancels a warning. That's because we can't be sure
23157 -- there isn't an instantiation in some other unit
23158 -- where a warning is suppressed.
23160 -- We could do a little better here by checking if the
23161 -- generic unit we are inside is public, but for now
23162 -- we don't bother with that refinement.
23164 if Chars (Argx) = Name_Off then
23165 Set_Specific_Warning_Off
23166 (Loc, Name_Buffer (1 .. Name_Len), Reason,
23167 Config => Is_Configuration_Pragma,
23168 Used => Inside_A_Generic or else In_Instance);
23170 elsif Chars (Argx) = Name_On then
23171 Set_Specific_Warning_On
23172 (Loc, Name_Buffer (1 .. Name_Len), Err);
23176 ("??pragma Warnings On with no matching "
23177 & "Warnings Off", Loc);
23186 -------------------
23187 -- Weak_External --
23188 -------------------
23190 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
23192 when Pragma_Weak_External => Weak_External : declare
23197 Check_Arg_Count (1);
23198 Check_Optional_Identifier (Arg1, Name_Entity);
23199 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23200 Ent := Entity (Get_Pragma_Arg (Arg1));
23202 if Rep_Item_Too_Early (Ent, N) then
23205 Ent := Underlying_Type (Ent);
23208 -- The only processing required is to link this item on to the
23209 -- list of rep items for the given entity. This is accomplished
23210 -- by the call to Rep_Item_Too_Late (when no error is detected
23211 -- and False is returned).
23213 if Rep_Item_Too_Late (Ent, N) then
23216 Set_Has_Gigi_Rep_Item (Ent);
23220 -----------------------------
23221 -- Wide_Character_Encoding --
23222 -----------------------------
23224 -- pragma Wide_Character_Encoding (IDENTIFIER);
23226 when Pragma_Wide_Character_Encoding =>
23229 -- Nothing to do, handled in parser. Note that we do not enforce
23230 -- configuration pragma placement, this pragma can appear at any
23231 -- place in the source, allowing mixed encodings within a single
23236 --------------------
23237 -- Unknown_Pragma --
23238 --------------------
23240 -- Should be impossible, since the case of an unknown pragma is
23241 -- separately processed before the case statement is entered.
23243 when Unknown_Pragma =>
23244 raise Program_Error;
23247 -- AI05-0144: detect dangerous order dependence. Disabled for now,
23248 -- until AI is formally approved.
23250 -- Check_Order_Dependence;
23253 when Pragma_Exit => null;
23254 end Analyze_Pragma;
23256 ---------------------------------------------
23257 -- Analyze_Pre_Post_Condition_In_Decl_Part --
23258 ---------------------------------------------
23260 procedure Analyze_Pre_Post_Condition_In_Decl_Part
23262 Freeze_Id : Entity_Id := Empty)
23266 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
23267 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
23268 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
23270 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
23273 Disp_Typ : Entity_Id;
23274 Restore_Scope : Boolean := False;
23276 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
23279 -- Do not analyze the pragma multiple times
23281 if Is_Analyzed_Pragma (N) then
23285 -- Set the Ghost mode in effect from the pragma. Due to the delayed
23286 -- analysis of the pragma, the Ghost mode at point of declaration and
23287 -- point of analysis may not necessarely be the same. Use the mode in
23288 -- effect at the point of declaration.
23290 Set_Ghost_Mode (N);
23292 -- Ensure that the subprogram and its formals are visible when analyzing
23293 -- the expression of the pragma.
23295 if not In_Open_Scopes (Spec_Id) then
23296 Restore_Scope := True;
23297 Push_Scope (Spec_Id);
23299 if Is_Generic_Subprogram (Spec_Id) then
23300 Install_Generic_Formals (Spec_Id);
23302 Install_Formals (Spec_Id);
23306 Errors := Serious_Errors_Detected;
23307 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
23309 -- Emit a clarification message when the expression contains at least
23310 -- one undefined reference, possibly due to contract "freezing".
23312 if Errors /= Serious_Errors_Detected
23313 and then Present (Freeze_Id)
23314 and then Has_Undefined_Reference (Expr)
23316 Contract_Freeze_Error (Spec_Id, Freeze_Id);
23319 if Class_Present (N) then
23321 -- Verify that a class-wide condition is legal, i.e. the operation is
23322 -- a primitive of a tagged type.
23324 Disp_Typ := Find_Dispatching_Type (Spec_Id);
23326 if No (Disp_Typ) then
23327 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
23329 if From_Aspect_Specification (N) then
23331 ("aspect % can only be specified for a primitive operation "
23332 & "of a tagged type", Corresponding_Aspect (N));
23334 -- The pragma is a source construct
23338 ("pragma % can only be specified for a primitive operation "
23339 & "of a tagged type", N);
23344 if Restore_Scope then
23348 -- Currently it is not possible to inline pre/postconditions on a
23349 -- subprogram subject to pragma Inline_Always.
23351 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
23352 Ghost_Mode := Save_Ghost_Mode;
23354 Set_Is_Analyzed_Pragma (N);
23355 end Analyze_Pre_Post_Condition_In_Decl_Part;
23357 ------------------------------------------
23358 -- Analyze_Refined_Depends_In_Decl_Part --
23359 ------------------------------------------
23361 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
23362 Body_Inputs : Elist_Id := No_Elist;
23363 Body_Outputs : Elist_Id := No_Elist;
23364 -- The inputs and outputs of the subprogram body synthesized from pragma
23365 -- Refined_Depends.
23367 Dependencies : List_Id := No_List;
23369 -- The corresponding Depends pragma along with its clauses
23371 Matched_Items : Elist_Id := No_Elist;
23372 -- A list containing the entities of all successfully matched items
23373 -- found in pragma Depends.
23375 Refinements : List_Id := No_List;
23376 -- The clauses of pragma Refined_Depends
23378 Spec_Id : Entity_Id;
23379 -- The entity of the subprogram subject to pragma Refined_Depends
23381 Spec_Inputs : Elist_Id := No_Elist;
23382 Spec_Outputs : Elist_Id := No_Elist;
23383 -- The inputs and outputs of the subprogram spec synthesized from pragma
23386 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
23387 -- Try to match a single dependency clause Dep_Clause against one or
23388 -- more refinement clauses found in list Refinements. Each successful
23389 -- match eliminates at least one refinement clause from Refinements.
23391 procedure Check_Output_States;
23392 -- Determine whether pragma Depends contains an output state with a
23393 -- visible refinement and if so, ensure that pragma Refined_Depends
23394 -- mentions all its constituents as outputs.
23396 procedure Normalize_Clauses (Clauses : List_Id);
23397 -- Given a list of dependence or refinement clauses Clauses, normalize
23398 -- each clause by creating multiple dependencies with exactly one input
23401 procedure Report_Extra_Clauses;
23402 -- Emit an error for each extra clause found in list Refinements
23404 -----------------------------
23405 -- Check_Dependency_Clause --
23406 -----------------------------
23408 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
23409 Dep_Input : constant Node_Id := Expression (Dep_Clause);
23410 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
23412 function Is_In_Out_State_Clause return Boolean;
23413 -- Determine whether dependence clause Dep_Clause denotes an abstract
23414 -- state that depends on itself (State => State).
23416 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
23417 -- Determine whether item Item denotes an abstract state with visible
23418 -- null refinement.
23420 procedure Match_Items
23421 (Dep_Item : Node_Id;
23422 Ref_Item : Node_Id;
23423 Matched : out Boolean);
23424 -- Try to match dependence item Dep_Item against refinement item
23425 -- Ref_Item. To match against a possible null refinement (see 2, 7),
23426 -- set Ref_Item to Empty. Flag Matched is set to True when one of
23427 -- the following conformance scenarios is in effect:
23428 -- 1) Both items denote null
23429 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
23430 -- 3) Both items denote attribute 'Result
23431 -- 4) Both items denote the same object
23432 -- 5) Both items denote the same formal parameter
23433 -- 6) Both items denote the same current instance of a type
23434 -- 7) Both items denote the same discriminant
23435 -- 8) Dep_Item is an abstract state with visible null refinement
23436 -- and Ref_Item denotes null.
23437 -- 9) Dep_Item is an abstract state with visible null refinement
23438 -- and Ref_Item is Empty (special case).
23439 -- 10) Dep_Item is an abstract state with visible non-null
23440 -- refinement and Ref_Item denotes one of its constituents.
23441 -- 11) Dep_Item is an abstract state without a visible refinement
23442 -- and Ref_Item denotes the same state.
23443 -- When scenario 10 is in effect, the entity of the abstract state
23444 -- denoted by Dep_Item is added to list Refined_States.
23446 procedure Record_Item
(Item_Id
: Entity_Id
);
23447 -- Store the entity of an item denoted by Item_Id in Matched_Items
23449 ----------------------------
23450 -- Is_In_Out_State_Clause --
23451 ----------------------------
23453 function Is_In_Out_State_Clause
return Boolean is
23454 Dep_Input_Id
: Entity_Id
;
23455 Dep_Output_Id
: Entity_Id
;
23458 -- Detect the following clause:
23461 if Is_Entity_Name
(Dep_Input
)
23462 and then Is_Entity_Name
(Dep_Output
)
23464 -- Handle abstract views generated for limited with clauses
23466 Dep_Input_Id
:= Available_View
(Entity_Of
(Dep_Input
));
23467 Dep_Output_Id
:= Available_View
(Entity_Of
(Dep_Output
));
23470 Ekind
(Dep_Input_Id
) = E_Abstract_State
23471 and then Dep_Input_Id
= Dep_Output_Id
;
23475 end Is_In_Out_State_Clause
;
23477 ---------------------------
23478 -- Is_Null_Refined_State --
23479 ---------------------------
23481 function Is_Null_Refined_State
(Item
: Node_Id
) return Boolean is
23482 Item_Id
: Entity_Id
;
23485 if Is_Entity_Name
(Item
) then
23487 -- Handle abstract views generated for limited with clauses
23489 Item_Id
:= Available_View
(Entity_Of
(Item
));
23492 Ekind
(Item_Id
) = E_Abstract_State
23493 and then Has_Null_Visible_Refinement
(Item_Id
);
23497 end Is_Null_Refined_State
;
23503 procedure Match_Items
23504 (Dep_Item
: Node_Id
;
23505 Ref_Item
: Node_Id
;
23506 Matched
: out Boolean)
23508 Dep_Item_Id
: Entity_Id
;
23509 Ref_Item_Id
: Entity_Id
;
23512 -- Assume that the two items do not match
23516 -- A null matches null or Empty (special case)
23518 if Nkind
(Dep_Item
) = N_Null
23519 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
23523 -- Attribute 'Result matches attribute 'Result
23525 elsif Is_Attribute_Result
(Dep_Item
)
23526 and then Is_Attribute_Result
(Dep_Item
)
23530 -- Abstract states, current instances of concurrent types,
23531 -- discriminants, formal parameters and objects.
23533 elsif Is_Entity_Name
(Dep_Item
) then
23535 -- Handle abstract views generated for limited with clauses
23537 Dep_Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
23539 if Ekind
(Dep_Item_Id
) = E_Abstract_State
then
23541 -- An abstract state with visible null refinement matches
23542 -- null or Empty (special case).
23544 if Has_Null_Visible_Refinement
(Dep_Item_Id
)
23545 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
23547 Record_Item
(Dep_Item_Id
);
23550 -- An abstract state with visible non-null refinement
23551 -- matches one of its constituents.
23553 elsif Has_Non_Null_Visible_Refinement
(Dep_Item_Id
) then
23554 if Is_Entity_Name
(Ref_Item
) then
23555 Ref_Item_Id
:= Entity_Of
(Ref_Item
);
23557 if Ekind_In
(Ref_Item_Id
, E_Abstract_State
,
23560 and then Present
(Encapsulating_State
(Ref_Item_Id
))
23561 and then Encapsulating_State
(Ref_Item_Id
) =
23564 Record_Item
(Dep_Item_Id
);
23569 -- An abstract state without a visible refinement matches
23572 elsif Is_Entity_Name
(Ref_Item
)
23573 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
23575 Record_Item
(Dep_Item_Id
);
23579 -- A current instance of a concurrent type, discriminant,
23580 -- formal parameter or an object matches itself.
23582 elsif Is_Entity_Name
(Ref_Item
)
23583 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
23585 Record_Item
(Dep_Item_Id
);
23595 procedure Record_Item
(Item_Id
: Entity_Id
) is
23597 if not Contains
(Matched_Items
, Item_Id
) then
23598 Append_New_Elmt
(Item_Id
, Matched_Items
);
23604 Clause_Matched
: Boolean := False;
23605 Dummy
: Boolean := False;
23606 Inputs_Match
: Boolean;
23607 Next_Ref_Clause
: Node_Id
;
23608 Outputs_Match
: Boolean;
23609 Ref_Clause
: Node_Id
;
23610 Ref_Input
: Node_Id
;
23611 Ref_Output
: Node_Id
;
23613 -- Start of processing for Check_Dependency_Clause
23616 -- Do not perform this check in an instance because it was already
23617 -- performed successfully in the generic template.
23619 if Is_Generic_Instance
(Spec_Id
) then
23623 -- Examine all refinement clauses and compare them against the
23624 -- dependence clause.
23626 Ref_Clause
:= First
(Refinements
);
23627 while Present
(Ref_Clause
) loop
23628 Next_Ref_Clause
:= Next
(Ref_Clause
);
23630 -- Obtain the attributes of the current refinement clause
23632 Ref_Input
:= Expression
(Ref_Clause
);
23633 Ref_Output
:= First
(Choices
(Ref_Clause
));
23635 -- The current refinement clause matches the dependence clause
23636 -- when both outputs match and both inputs match. See routine
23637 -- Match_Items for all possible conformance scenarios.
23639 -- Depends Dep_Output => Dep_Input
23643 -- Refined_Depends Ref_Output => Ref_Input
23646 (Dep_Item
=> Dep_Input
,
23647 Ref_Item
=> Ref_Input
,
23648 Matched
=> Inputs_Match
);
23651 (Dep_Item
=> Dep_Output
,
23652 Ref_Item
=> Ref_Output
,
23653 Matched
=> Outputs_Match
);
23655 -- An In_Out state clause may be matched against a refinement with
23656 -- a null input or null output as long as the non-null side of the
23657 -- relation contains a valid constituent of the In_Out_State.
23659 if Is_In_Out_State_Clause
then
23661 -- Depends => (State => State)
23662 -- Refined_Depends => (null => Constit) -- OK
23665 and then not Outputs_Match
23666 and then Nkind
(Ref_Output
) = N_Null
23668 Outputs_Match
:= True;
23671 -- Depends => (State => State)
23672 -- Refined_Depends => (Constit => null) -- OK
23674 if not Inputs_Match
23675 and then Outputs_Match
23676 and then Nkind
(Ref_Input
) = N_Null
23678 Inputs_Match
:= True;
23682 -- The current refinement clause is legally constructed following
23683 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
23684 -- the pool of candidates. The seach continues because a single
23685 -- dependence clause may have multiple matching refinements.
23687 if Inputs_Match
and Outputs_Match
then
23688 Clause_Matched
:= True;
23689 Remove
(Ref_Clause
);
23692 Ref_Clause
:= Next_Ref_Clause
;
23695 -- Depending on the order or composition of refinement clauses, an
23696 -- In_Out state clause may not be directly refinable.
23698 -- Depends => ((Output, State) => (Input, State))
23699 -- Refined_State => (State => (Constit_1, Constit_2))
23700 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
23702 -- Matching normalized clause (State => State) fails because there is
23703 -- no direct refinement capable of satisfying this relation. Another
23704 -- similar case arises when clauses (Constit_1 => Input) and (Output
23705 -- => Constit_2) are matched first, leaving no candidates for clause
23706 -- (State => State). Both scenarios are legal as long as one of the
23707 -- previous clauses mentioned a valid constituent of State.
23709 if not Clause_Matched
23710 and then Is_In_Out_State_Clause
23712 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
23714 Clause_Matched
:= True;
23717 -- A clause where the input is an abstract state with visible null
23718 -- refinement is implicitly matched when the output has already been
23719 -- matched in a previous clause.
23721 -- Depends => (Output => State) -- implicitly OK
23722 -- Refined_State => (State => null)
23723 -- Refined_Depends => (Output => ...)
23725 if not Clause_Matched
23726 and then Is_Null_Refined_State
(Dep_Input
)
23727 and then Is_Entity_Name
(Dep_Output
)
23729 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Output
)))
23731 Clause_Matched
:= True;
23734 -- A clause where the output is an abstract state with visible null
23735 -- refinement is implicitly matched when the input has already been
23736 -- matched in a previous clause.
23738 -- Depends => (State => Input) -- implicitly OK
23739 -- Refined_State => (State => null)
23740 -- Refined_Depends => (... => Input)
23742 if not Clause_Matched
23743 and then Is_Null_Refined_State
(Dep_Output
)
23744 and then Is_Entity_Name
(Dep_Input
)
23746 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
23748 Clause_Matched
:= True;
23751 -- At this point either all refinement clauses have been examined or
23752 -- pragma Refined_Depends contains a solitary null. Only an abstract
23753 -- state with null refinement can possibly match these cases.
23755 -- Depends => (State => null)
23756 -- Refined_State => (State => null)
23757 -- Refined_Depends => null -- OK
23759 if not Clause_Matched
then
23761 (Dep_Item
=> Dep_Input
,
23763 Matched
=> Inputs_Match
);
23766 (Dep_Item
=> Dep_Output
,
23768 Matched
=> Outputs_Match
);
23770 Clause_Matched
:= Inputs_Match
and Outputs_Match
;
23773 -- If the contents of Refined_Depends are legal, then the current
23774 -- dependence clause should be satisfied either by an explicit match
23775 -- or by one of the special cases.
23777 if not Clause_Matched
then
23779 (Fix_Msg
(Spec_Id
, "dependence clause of subprogram & has no "
23780 & "matching refinement in body"), Dep_Clause
, Spec_Id
);
23782 end Check_Dependency_Clause
;
23784 -------------------------
23785 -- Check_Output_States --
23786 -------------------------
23788 procedure Check_Output_States
is
23789 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
23790 -- Determine whether all constituents of state State_Id with visible
23791 -- refinement are used as outputs in pragma Refined_Depends. Emit an
23792 -- error if this is not the case.
23794 -----------------------------
23795 -- Check_Constituent_Usage --
23796 -----------------------------
23798 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
23799 Constits
: constant Elist_Id
:=
23800 Refinement_Constituents
(State_Id
);
23801 Constit_Elmt
: Elmt_Id
;
23802 Constit_Id
: Entity_Id
;
23803 Posted
: Boolean := False;
23806 if Present
(Constits
) then
23807 Constit_Elmt
:= First_Elmt
(Constits
);
23808 while Present
(Constit_Elmt
) loop
23809 Constit_Id
:= Node
(Constit_Elmt
);
23811 -- The constituent acts as an input (SPARK RM 7.2.5(3))
23813 if Present
(Body_Inputs
)
23814 and then Appears_In
(Body_Inputs
, Constit_Id
)
23816 Error_Msg_Name_1
:= Chars
(State_Id
);
23818 ("constituent & of state % must act as output in "
23819 & "dependence refinement", N
, Constit_Id
);
23821 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
23823 elsif No
(Body_Outputs
)
23824 or else not Appears_In
(Body_Outputs
, Constit_Id
)
23829 ("output state & must be replaced by all its "
23830 & "constituents in dependence refinement",
23835 ("\constituent & is missing in output list",
23839 Next_Elmt
(Constit_Elmt
);
23842 end Check_Constituent_Usage
;
23847 Item_Elmt
: Elmt_Id
;
23848 Item_Id
: Entity_Id
;
23850 -- Start of processing for Check_Output_States
23853 -- Do not perform this check in an instance because it was already
23854 -- performed successfully in the generic template.
23856 if Is_Generic_Instance
(Spec_Id
) then
23859 -- Inspect the outputs of pragma Depends looking for a state with a
23860 -- visible refinement.
23862 elsif Present
(Spec_Outputs
) then
23863 Item_Elmt
:= First_Elmt
(Spec_Outputs
);
23864 while Present
(Item_Elmt
) loop
23865 Item
:= Node
(Item_Elmt
);
23867 -- Deal with the mixed nature of the input and output lists
23869 if Nkind
(Item
) = N_Defining_Identifier
then
23872 Item_Id
:= Available_View
(Entity_Of
(Item
));
23875 if Ekind
(Item_Id
) = E_Abstract_State
then
23877 -- The state acts as an input-output, skip it
23879 if Present
(Spec_Inputs
)
23880 and then Appears_In
(Spec_Inputs
, Item_Id
)
23884 -- Ensure that all of the constituents are utilized as
23885 -- outputs in pragma Refined_Depends.
23887 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
23888 Check_Constituent_Usage
(Item_Id
);
23892 Next_Elmt
(Item_Elmt
);
23895 end Check_Output_States
;
23897 -----------------------
23898 -- Normalize_Clauses --
23899 -----------------------
23901 procedure Normalize_Clauses
(Clauses
: List_Id
) is
23902 procedure Normalize_Inputs
(Clause
: Node_Id
);
23903 -- Normalize clause Clause by creating multiple clauses for each
23904 -- input item of Clause. It is assumed that Clause has exactly one
23905 -- output. The transformation is as follows:
23907 -- Output => (Input_1, Input_2) -- original
23909 -- Output => Input_1 -- normalizations
23910 -- Output => Input_2
23912 procedure Normalize_Outputs
(Clause
: Node_Id
);
23913 -- Normalize clause Clause by creating multiple clause for each
23914 -- output item of Clause. The transformation is as follows:
23916 -- (Output_1, Output_2) => Input -- original
23918 -- Output_1 => Input -- normalization
23919 -- Output_2 => Input
23921 ----------------------
23922 -- Normalize_Inputs --
23923 ----------------------
23925 procedure Normalize_Inputs
(Clause
: Node_Id
) is
23926 Inputs
: constant Node_Id
:= Expression
(Clause
);
23927 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
23928 Output
: constant List_Id
:= Choices
(Clause
);
23929 Last_Input
: Node_Id
;
23931 New_Clause
: Node_Id
;
23932 Next_Input
: Node_Id
;
23935 -- Normalization is performed only when the original clause has
23936 -- more than one input. Multiple inputs appear as an aggregate.
23938 if Nkind
(Inputs
) = N_Aggregate
then
23939 Last_Input
:= Last
(Expressions
(Inputs
));
23941 -- Create a new clause for each input
23943 Input
:= First
(Expressions
(Inputs
));
23944 while Present
(Input
) loop
23945 Next_Input
:= Next
(Input
);
23947 -- Unhook the current input from the original input list
23948 -- because it will be relocated to a new clause.
23952 -- Special processing for the last input. At this point the
23953 -- original aggregate has been stripped down to one element.
23954 -- Replace the aggregate by the element itself.
23956 if Input
= Last_Input
then
23957 Rewrite
(Inputs
, Input
);
23959 -- Generate a clause of the form:
23964 Make_Component_Association
(Loc
,
23965 Choices
=> New_Copy_List_Tree
(Output
),
23966 Expression
=> Input
);
23968 -- The new clause contains replicated content that has
23969 -- already been analyzed, mark the clause as analyzed.
23971 Set_Analyzed
(New_Clause
);
23972 Insert_After
(Clause
, New_Clause
);
23975 Input
:= Next_Input
;
23978 end Normalize_Inputs
;
23980 -----------------------
23981 -- Normalize_Outputs --
23982 -----------------------
23984 procedure Normalize_Outputs
(Clause
: Node_Id
) is
23985 Inputs
: constant Node_Id
:= Expression
(Clause
);
23986 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
23987 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
23988 Last_Output
: Node_Id
;
23989 New_Clause
: Node_Id
;
23990 Next_Output
: Node_Id
;
23994 -- Multiple outputs appear as an aggregate. Nothing to do when
23995 -- the clause has exactly one output.
23997 if Nkind
(Outputs
) = N_Aggregate
then
23998 Last_Output
:= Last
(Expressions
(Outputs
));
24000 -- Create a clause for each output. Note that each time a new
24001 -- clause is created, the original output list slowly shrinks
24002 -- until there is one item left.
24004 Output
:= First
(Expressions
(Outputs
));
24005 while Present
(Output
) loop
24006 Next_Output
:= Next
(Output
);
24008 -- Unhook the output from the original output list as it
24009 -- will be relocated to a new clause.
24013 -- Special processing for the last output. At this point
24014 -- the original aggregate has been stripped down to one
24015 -- element. Replace the aggregate by the element itself.
24017 if Output
= Last_Output
then
24018 Rewrite
(Outputs
, Output
);
24021 -- Generate a clause of the form:
24022 -- (Output => Inputs)
24025 Make_Component_Association
(Loc
,
24026 Choices
=> New_List
(Output
),
24027 Expression
=> New_Copy_Tree
(Inputs
));
24029 -- The new clause contains replicated content that has
24030 -- already been analyzed. There is not need to reanalyze
24033 Set_Analyzed
(New_Clause
);
24034 Insert_After
(Clause
, New_Clause
);
24037 Output
:= Next_Output
;
24040 end Normalize_Outputs
;
24046 -- Start of processing for Normalize_Clauses
24049 Clause
:= First
(Clauses
);
24050 while Present
(Clause
) loop
24051 Normalize_Outputs
(Clause
);
24055 Clause
:= First
(Clauses
);
24056 while Present
(Clause
) loop
24057 Normalize_Inputs
(Clause
);
24060 end Normalize_Clauses
;
24062 --------------------------
24063 -- Report_Extra_Clauses --
24064 --------------------------
24066 procedure Report_Extra_Clauses
is
24070 -- Do not perform this check in an instance because it was already
24071 -- performed successfully in the generic template.
24073 if Is_Generic_Instance
(Spec_Id
) then
24076 elsif Present
(Refinements
) then
24077 Clause
:= First
(Refinements
);
24078 while Present
(Clause
) loop
24080 -- Do not complain about a null input refinement, since a null
24081 -- input legitimately matches anything.
24083 if Nkind
(Clause
) = N_Component_Association
24084 and then Nkind
(Expression
(Clause
)) = N_Null
24090 ("unmatched or extra clause in dependence refinement",
24097 end Report_Extra_Clauses
;
24101 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
24102 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
24103 Errors
: constant Nat
:= Serious_Errors_Detected
;
24109 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
24112 -- Do not analyze the pragma multiple times
24114 if Is_Analyzed_Pragma
(N
) then
24118 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
24120 -- Use the anonymous object as the proper spec when Refined_Depends
24121 -- applies to the body of a single task type. The object carries the
24122 -- proper Chars as well as all non-refined versions of pragmas.
24124 if Is_Single_Concurrent_Type
(Spec_Id
) then
24125 Spec_Id
:= Anonymous_Object
(Spec_Id
);
24128 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
24130 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
24131 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
24133 if No
(Depends
) then
24135 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
24136 & "& lacks aspect or pragma Depends"), N
, Spec_Id
);
24140 Deps
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
24142 -- A null dependency relation renders the refinement useless because it
24143 -- cannot possibly mention abstract states with visible refinement. Note
24144 -- that the inverse is not true as states may be refined to null
24145 -- (SPARK RM 7.2.5(2)).
24147 if Nkind
(Deps
) = N_Null
then
24149 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
24150 & "depend on abstract state with visible refinement"), N
, Spec_Id
);
24154 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
24155 -- This ensures that the categorization of all refined dependency items
24156 -- is consistent with their role.
24158 Analyze_Depends_In_Decl_Part
(N
);
24160 -- Do not match dependencies against refinements if Refined_Depends is
24161 -- illegal to avoid emitting misleading error.
24163 if Serious_Errors_Detected
= Errors
then
24165 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
24166 -- the inputs and outputs of the subprogram spec and body to verify
24167 -- the use of states with visible refinement and their constituents.
24169 if No
(Get_Pragma
(Spec_Id
, Pragma_Global
))
24170 or else No
(Get_Pragma
(Body_Id
, Pragma_Refined_Global
))
24172 Collect_Subprogram_Inputs_Outputs
24173 (Subp_Id
=> Spec_Id
,
24174 Synthesize
=> True,
24175 Subp_Inputs
=> Spec_Inputs
,
24176 Subp_Outputs
=> Spec_Outputs
,
24177 Global_Seen
=> Dummy
);
24179 Collect_Subprogram_Inputs_Outputs
24180 (Subp_Id
=> Body_Id
,
24181 Synthesize
=> True,
24182 Subp_Inputs
=> Body_Inputs
,
24183 Subp_Outputs
=> Body_Outputs
,
24184 Global_Seen
=> Dummy
);
24186 -- For an output state with a visible refinement, ensure that all
24187 -- constituents appear as outputs in the dependency refinement.
24189 Check_Output_States
;
24192 -- Matching is disabled in ASIS because clauses are not normalized as
24193 -- this is a tree altering activity similar to expansion.
24199 -- Multiple dependency clauses appear as component associations of an
24200 -- aggregate. Note that the clauses are copied because the algorithm
24201 -- modifies them and this should not be visible in Depends.
24203 pragma Assert
(Nkind
(Deps
) = N_Aggregate
);
24204 Dependencies
:= New_Copy_List_Tree
(Component_Associations
(Deps
));
24205 Normalize_Clauses
(Dependencies
);
24207 Refs
:= Expression
(Get_Argument
(N
, Spec_Id
));
24209 if Nkind
(Refs
) = N_Null
then
24210 Refinements
:= No_List
;
24212 -- Multiple dependency clauses appear as component associations of an
24213 -- aggregate. Note that the clauses are copied because the algorithm
24214 -- modifies them and this should not be visible in Refined_Depends.
24216 else pragma Assert
(Nkind
(Refs
) = N_Aggregate
);
24217 Refinements
:= New_Copy_List_Tree
(Component_Associations
(Refs
));
24218 Normalize_Clauses
(Refinements
);
24221 -- At this point the clauses of pragmas Depends and Refined_Depends
24222 -- have been normalized into simple dependencies between one output
24223 -- and one input. Examine all clauses of pragma Depends looking for
24224 -- matching clauses in pragma Refined_Depends.
24226 Clause
:= First
(Dependencies
);
24227 while Present
(Clause
) loop
24228 Check_Dependency_Clause
(Clause
);
24232 if Serious_Errors_Detected
= Errors
then
24233 Report_Extra_Clauses
;
24238 Set_Is_Analyzed_Pragma
(N
);
24239 end Analyze_Refined_Depends_In_Decl_Part
;
24241 -----------------------------------------
24242 -- Analyze_Refined_Global_In_Decl_Part --
24243 -----------------------------------------
24245 procedure Analyze_Refined_Global_In_Decl_Part
(N
: Node_Id
) is
24247 -- The corresponding Global pragma
24249 Has_In_State
: Boolean := False;
24250 Has_In_Out_State
: Boolean := False;
24251 Has_Out_State
: Boolean := False;
24252 Has_Proof_In_State
: Boolean := False;
24253 -- These flags are set when the corresponding Global pragma has a state
24254 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
24257 Has_Null_State
: Boolean := False;
24258 -- This flag is set when the corresponding Global pragma has at least
24259 -- one state with a null refinement.
24261 In_Constits
: Elist_Id
:= No_Elist
;
24262 In_Out_Constits
: Elist_Id
:= No_Elist
;
24263 Out_Constits
: Elist_Id
:= No_Elist
;
24264 Proof_In_Constits
: Elist_Id
:= No_Elist
;
24265 -- These lists contain the entities of all Input, In_Out, Output and
24266 -- Proof_In constituents that appear in Refined_Global and participate
24267 -- in state refinement.
24269 In_Items
: Elist_Id
:= No_Elist
;
24270 In_Out_Items
: Elist_Id
:= No_Elist
;
24271 Out_Items
: Elist_Id
:= No_Elist
;
24272 Proof_In_Items
: Elist_Id
:= No_Elist
;
24273 -- These list contain the entities of all Input, In_Out, Output and
24274 -- Proof_In items defined in the corresponding Global pragma.
24276 Spec_Id
: Entity_Id
;
24277 -- The entity of the subprogram subject to pragma Refined_Global
24279 States
: Elist_Id
:= No_Elist
;
24280 -- A list of all states with visible refinement found in pragma Global
24282 procedure Check_In_Out_States
;
24283 -- Determine whether the corresponding Global pragma mentions In_Out
24284 -- states with visible refinement and if so, ensure that one of the
24285 -- following completions apply to the constituents of the state:
24286 -- 1) there is at least one constituent of mode In_Out
24287 -- 2) there is at least one Input and one Output constituent
24288 -- 3) not all constituents are present and one of them is of mode
24290 -- This routine may remove elements from In_Constits, In_Out_Constits,
24291 -- Out_Constits and Proof_In_Constits.
24293 procedure Check_Input_States
;
24294 -- Determine whether the corresponding Global pragma mentions Input
24295 -- states with visible refinement and if so, ensure that at least one of
24296 -- its constituents appears as an Input item in Refined_Global.
24297 -- This routine may remove elements from In_Constits, In_Out_Constits,
24298 -- Out_Constits and Proof_In_Constits.
24300 procedure Check_Output_States
;
24301 -- Determine whether the corresponding Global pragma mentions Output
24302 -- states with visible refinement and if so, ensure that all of its
24303 -- constituents appear as Output items in Refined_Global.
24304 -- This routine may remove elements from In_Constits, In_Out_Constits,
24305 -- Out_Constits and Proof_In_Constits.
24307 procedure Check_Proof_In_States
;
24308 -- Determine whether the corresponding Global pragma mentions Proof_In
24309 -- states with visible refinement and if so, ensure that at least one of
24310 -- its constituents appears as a Proof_In item in Refined_Global.
24311 -- This routine may remove elements from In_Constits, In_Out_Constits,
24312 -- Out_Constits and Proof_In_Constits.
24314 procedure Check_Refined_Global_List
24316 Global_Mode
: Name_Id
:= Name_Input
);
24317 -- Verify the legality of a single global list declaration. Global_Mode
24318 -- denotes the current mode in effect.
24320 procedure Collect_Global_Items
24322 Mode
: Name_Id
:= Name_Input
);
24323 -- Gather all input, in out, output and Proof_In items from node List
24324 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
24325 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
24326 -- and Has_Proof_In_State are set when there is at least one abstract
24327 -- state with visible refinement available in the corresponding mode.
24328 -- Flag Has_Null_State is set when at least state has a null refinement.
24329 -- Mode enotes the current global mode in effect.
24331 function Present_Then_Remove
24333 Item
: Entity_Id
) return Boolean;
24334 -- Search List for a particular entity Item. If Item has been found,
24335 -- remove it from List. This routine is used to strip lists In_Constits,
24336 -- In_Out_Constits and Out_Constits of valid constituents.
24338 procedure Report_Extra_Constituents
;
24339 -- Emit an error for each constituent found in lists In_Constits,
24340 -- In_Out_Constits and Out_Constits.
24342 -------------------------
24343 -- Check_In_Out_States --
24344 -------------------------
24346 procedure Check_In_Out_States
is
24347 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24348 -- Determine whether one of the following coverage scenarios is in
24350 -- 1) there is at least one constituent of mode In_Out or Output
24351 -- 2) there is at least one pair of constituents with modes Input
24352 -- and Output, or Proof_In and Output.
24353 -- 3) there is at least one constituent of mode Output and not all
24354 -- constituents are present.
24355 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
24357 -----------------------------
24358 -- Check_Constituent_Usage --
24359 -----------------------------
24361 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24362 Constits
: constant Elist_Id
:=
24363 Refinement_Constituents
(State_Id
);
24364 Constit_Elmt
: Elmt_Id
;
24365 Constit_Id
: Entity_Id
;
24366 Has_Missing
: Boolean := False;
24367 In_Out_Seen
: Boolean := False;
24368 Input_Seen
: Boolean := False;
24369 Output_Seen
: Boolean := False;
24370 Proof_In_Seen
: Boolean := False;
24373 -- Process all the constituents of the state and note their modes
24374 -- within the global refinement.
24376 if Present
(Constits
) then
24377 Constit_Elmt
:= First_Elmt
(Constits
);
24378 while Present
(Constit_Elmt
) loop
24379 Constit_Id
:= Node
(Constit_Elmt
);
24381 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
24382 Input_Seen
:= True;
24384 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
) then
24385 In_Out_Seen
:= True;
24387 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
24388 Output_Seen
:= True;
24390 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24392 Proof_In_Seen
:= True;
24395 Has_Missing
:= True;
24398 Next_Elmt
(Constit_Elmt
);
24402 -- An In_Out constituent is a valid completion
24404 if In_Out_Seen
then
24407 -- A pair of one Input/Proof_In and one Output constituent is a
24408 -- valid completion.
24410 elsif (Input_Seen
or Proof_In_Seen
) and Output_Seen
then
24413 elsif Output_Seen
then
24415 -- A single Output constituent is a valid completion only when
24416 -- some of the other constituents are missing.
24418 if Has_Missing
then
24421 -- Otherwise all constituents are of mode Output
24425 ("global refinement of state & must include at least one "
24426 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
24430 -- The state lacks a completion
24432 elsif not Input_Seen
24433 and not In_Out_Seen
24434 and not Output_Seen
24435 and not Proof_In_Seen
24438 ("missing global refinement of state &", N
, State_Id
);
24440 -- Otherwise the state has a malformed completion where at least
24441 -- one of the constituents has a different mode.
24445 ("global refinement of state & redefines the mode of its "
24446 & "constituents", N
, State_Id
);
24448 end Check_Constituent_Usage
;
24452 Item_Elmt
: Elmt_Id
;
24453 Item_Id
: Entity_Id
;
24455 -- Start of processing for Check_In_Out_States
24458 -- Do not perform this check in an instance because it was already
24459 -- performed successfully in the generic template.
24461 if Is_Generic_Instance
(Spec_Id
) then
24464 -- Inspect the In_Out items of the corresponding Global pragma
24465 -- looking for a state with a visible refinement.
24467 elsif Has_In_Out_State
and then Present
(In_Out_Items
) then
24468 Item_Elmt
:= First_Elmt
(In_Out_Items
);
24469 while Present
(Item_Elmt
) loop
24470 Item_Id
:= Node
(Item_Elmt
);
24472 -- Ensure that one of the three coverage variants is satisfied
24474 if Ekind
(Item_Id
) = E_Abstract_State
24475 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24477 Check_Constituent_Usage
(Item_Id
);
24480 Next_Elmt
(Item_Elmt
);
24483 end Check_In_Out_States
;
24485 ------------------------
24486 -- Check_Input_States --
24487 ------------------------
24489 procedure Check_Input_States
is
24490 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24491 -- Determine whether at least one constituent of state State_Id with
24492 -- visible refinement is used and has mode Input. Ensure that the
24493 -- remaining constituents do not have In_Out or Output modes. Emit an
24494 -- error if this is not the case (SPARK RM 7.2.4(5)).
24496 -----------------------------
24497 -- Check_Constituent_Usage --
24498 -----------------------------
24500 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24501 Constits
: constant Elist_Id
:=
24502 Refinement_Constituents
(State_Id
);
24503 Constit_Elmt
: Elmt_Id
;
24504 Constit_Id
: Entity_Id
;
24505 In_Seen
: Boolean := False;
24508 if Present
(Constits
) then
24509 Constit_Elmt
:= First_Elmt
(Constits
);
24510 while Present
(Constit_Elmt
) loop
24511 Constit_Id
:= Node
(Constit_Elmt
);
24513 -- At least one of the constituents appears as an Input
24515 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
24518 -- A Proof_In constituent can refine an Input state as long
24519 -- as there is at least one Input constituent present.
24521 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24525 -- The constituent appears in the global refinement, but has
24526 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
24528 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24529 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
24531 Error_Msg_Name_1
:= Chars
(State_Id
);
24533 ("constituent & of state % must have mode `Input` in "
24534 & "global refinement", N
, Constit_Id
);
24537 Next_Elmt
(Constit_Elmt
);
24541 -- Not one of the constituents appeared as Input
24543 if not In_Seen
then
24545 ("global refinement of state & must include at least one "
24546 & "constituent of mode `Input`", N
, State_Id
);
24548 end Check_Constituent_Usage
;
24552 Item_Elmt
: Elmt_Id
;
24553 Item_Id
: Entity_Id
;
24555 -- Start of processing for Check_Input_States
24558 -- Do not perform this check in an instance because it was already
24559 -- performed successfully in the generic template.
24561 if Is_Generic_Instance
(Spec_Id
) then
24564 -- Inspect the Input items of the corresponding Global pragma looking
24565 -- for a state with a visible refinement.
24567 elsif Has_In_State
and then Present
(In_Items
) then
24568 Item_Elmt
:= First_Elmt
(In_Items
);
24569 while Present
(Item_Elmt
) loop
24570 Item_Id
:= Node
(Item_Elmt
);
24572 -- Ensure that at least one of the constituents is utilized and
24573 -- is of mode Input.
24575 if Ekind
(Item_Id
) = E_Abstract_State
24576 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24578 Check_Constituent_Usage
(Item_Id
);
24581 Next_Elmt
(Item_Elmt
);
24584 end Check_Input_States
;
24586 -------------------------
24587 -- Check_Output_States --
24588 -------------------------
24590 procedure Check_Output_States
is
24591 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24592 -- Determine whether all constituents of state State_Id with visible
24593 -- refinement are used and have mode Output. Emit an error if this is
24594 -- not the case (SPARK RM 7.2.4(5)).
24596 -----------------------------
24597 -- Check_Constituent_Usage --
24598 -----------------------------
24600 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24601 Constits
: constant Elist_Id
:=
24602 Refinement_Constituents
(State_Id
);
24603 Constit_Elmt
: Elmt_Id
;
24604 Constit_Id
: Entity_Id
;
24605 Posted
: Boolean := False;
24608 if Present
(Constits
) then
24609 Constit_Elmt
:= First_Elmt
(Constits
);
24610 while Present
(Constit_Elmt
) loop
24611 Constit_Id
:= Node
(Constit_Elmt
);
24613 if Present_Then_Remove
(Out_Constits
, Constit_Id
) then
24616 -- The constituent appears in the global refinement, but has
24617 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
24619 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
24620 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24621 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24623 Error_Msg_Name_1
:= Chars
(State_Id
);
24625 ("constituent & of state % must have mode `Output` in "
24626 & "global refinement", N
, Constit_Id
);
24628 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
24634 ("`Output` state & must be replaced by all its "
24635 & "constituents in global refinement", N
, State_Id
);
24639 ("\constituent & is missing in output list",
24643 Next_Elmt
(Constit_Elmt
);
24646 end Check_Constituent_Usage
;
24650 Item_Elmt
: Elmt_Id
;
24651 Item_Id
: Entity_Id
;
24653 -- Start of processing for Check_Output_States
24656 -- Do not perform this check in an instance because it was already
24657 -- performed successfully in the generic template.
24659 if Is_Generic_Instance
(Spec_Id
) then
24662 -- Inspect the Output items of the corresponding Global pragma
24663 -- looking for a state with a visible refinement.
24665 elsif Has_Out_State
and then Present
(Out_Items
) then
24666 Item_Elmt
:= First_Elmt
(Out_Items
);
24667 while Present
(Item_Elmt
) loop
24668 Item_Id
:= Node
(Item_Elmt
);
24670 -- Ensure that all of the constituents are utilized and they
24671 -- have mode Output.
24673 if Ekind
(Item_Id
) = E_Abstract_State
24674 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24676 Check_Constituent_Usage
(Item_Id
);
24679 Next_Elmt
(Item_Elmt
);
24682 end Check_Output_States
;
24684 ---------------------------
24685 -- Check_Proof_In_States --
24686 ---------------------------
24688 procedure Check_Proof_In_States
is
24689 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24690 -- Determine whether at least one constituent of state State_Id with
24691 -- visible refinement is used and has mode Proof_In. Ensure that the
24692 -- remaining constituents do not have Input, In_Out or Output modes.
24693 -- Emit an error of this is not the case (SPARK RM 7.2.4(5)).
24695 -----------------------------
24696 -- Check_Constituent_Usage --
24697 -----------------------------
24699 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24700 Constits
: constant Elist_Id
:=
24701 Refinement_Constituents
(State_Id
);
24702 Constit_Elmt
: Elmt_Id
;
24703 Constit_Id
: Entity_Id
;
24704 Proof_In_Seen
: Boolean := False;
24707 if Present
(Constits
) then
24708 Constit_Elmt
:= First_Elmt
(Constits
);
24709 while Present
(Constit_Elmt
) loop
24710 Constit_Id
:= Node
(Constit_Elmt
);
24712 -- At least one of the constituents appears as Proof_In
24714 if Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
24715 Proof_In_Seen
:= True;
24717 -- The constituent appears in the global refinement, but has
24718 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
24720 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
24721 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24722 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
24724 Error_Msg_Name_1
:= Chars
(State_Id
);
24726 ("constituent & of state % must have mode `Proof_In` "
24727 & "in global refinement", N
, Constit_Id
);
24730 Next_Elmt
(Constit_Elmt
);
24734 -- Not one of the constituents appeared as Proof_In
24736 if not Proof_In_Seen
then
24738 ("global refinement of state & must include at least one "
24739 & "constituent of mode `Proof_In`", N
, State_Id
);
24741 end Check_Constituent_Usage
;
24745 Item_Elmt
: Elmt_Id
;
24746 Item_Id
: Entity_Id
;
24748 -- Start of processing for Check_Proof_In_States
24751 -- Do not perform this check in an instance because it was already
24752 -- performed successfully in the generic template.
24754 if Is_Generic_Instance
(Spec_Id
) then
24757 -- Inspect the Proof_In items of the corresponding Global pragma
24758 -- looking for a state with a visible refinement.
24760 elsif Has_Proof_In_State
and then Present
(Proof_In_Items
) then
24761 Item_Elmt
:= First_Elmt
(Proof_In_Items
);
24762 while Present
(Item_Elmt
) loop
24763 Item_Id
:= Node
(Item_Elmt
);
24765 -- Ensure that at least one of the constituents is utilized and
24766 -- is of mode Proof_In
24768 if Ekind
(Item_Id
) = E_Abstract_State
24769 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24771 Check_Constituent_Usage
(Item_Id
);
24774 Next_Elmt
(Item_Elmt
);
24777 end Check_Proof_In_States
;
24779 -------------------------------
24780 -- Check_Refined_Global_List --
24781 -------------------------------
24783 procedure Check_Refined_Global_List
24785 Global_Mode
: Name_Id
:= Name_Input
)
24787 procedure Check_Refined_Global_Item
24789 Global_Mode
: Name_Id
);
24790 -- Verify the legality of a single global item declaration. Parameter
24791 -- Global_Mode denotes the current mode in effect.
24793 -------------------------------
24794 -- Check_Refined_Global_Item --
24795 -------------------------------
24797 procedure Check_Refined_Global_Item
24799 Global_Mode
: Name_Id
)
24801 Item_Id
: constant Entity_Id
:= Entity_Of
(Item
);
24803 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
);
24804 -- Issue a common error message for all mode mismatches. Expect
24805 -- denotes the expected mode.
24807 -----------------------------
24808 -- Inconsistent_Mode_Error --
24809 -----------------------------
24811 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
) is
24814 ("global item & has inconsistent modes", Item
, Item_Id
);
24816 Error_Msg_Name_1
:= Global_Mode
;
24817 Error_Msg_Name_2
:= Expect
;
24818 SPARK_Msg_N
("\expected mode %, found mode %", Item
);
24819 end Inconsistent_Mode_Error
;
24821 -- Start of processing for Check_Refined_Global_Item
24824 -- When the state or object acts as a constituent of another
24825 -- state with a visible refinement, collect it for the state
24826 -- completeness checks performed later on. Note that the item
24827 -- acts as a constituent only when the encapsulating state is
24828 -- present in pragma Global.
24830 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
24831 and then Present
(Encapsulating_State
(Item_Id
))
24832 and then Has_Visible_Refinement
(Encapsulating_State
(Item_Id
))
24833 and then Contains
(States
, Encapsulating_State
(Item_Id
))
24835 if Global_Mode
= Name_Input
then
24836 Append_New_Elmt
(Item_Id
, In_Constits
);
24838 elsif Global_Mode
= Name_In_Out
then
24839 Append_New_Elmt
(Item_Id
, In_Out_Constits
);
24841 elsif Global_Mode
= Name_Output
then
24842 Append_New_Elmt
(Item_Id
, Out_Constits
);
24844 elsif Global_Mode
= Name_Proof_In
then
24845 Append_New_Elmt
(Item_Id
, Proof_In_Constits
);
24848 -- When not a constituent, ensure that both occurrences of the
24849 -- item in pragmas Global and Refined_Global match.
24851 elsif Contains
(In_Items
, Item_Id
) then
24852 if Global_Mode
/= Name_Input
then
24853 Inconsistent_Mode_Error
(Name_Input
);
24856 elsif Contains
(In_Out_Items
, Item_Id
) then
24857 if Global_Mode
/= Name_In_Out
then
24858 Inconsistent_Mode_Error
(Name_In_Out
);
24861 elsif Contains
(Out_Items
, Item_Id
) then
24862 if Global_Mode
/= Name_Output
then
24863 Inconsistent_Mode_Error
(Name_Output
);
24866 elsif Contains
(Proof_In_Items
, Item_Id
) then
24869 -- The item does not appear in the corresponding Global pragma,
24870 -- it must be an extra (SPARK RM 7.2.4(3)).
24873 SPARK_Msg_NE
("extra global item &", Item
, Item_Id
);
24875 end Check_Refined_Global_Item
;
24881 -- Start of processing for Check_Refined_Global_List
24884 -- Do not perform this check in an instance because it was already
24885 -- performed successfully in the generic template.
24887 if Is_Generic_Instance
(Spec_Id
) then
24890 elsif Nkind
(List
) = N_Null
then
24893 -- Single global item declaration
24895 elsif Nkind_In
(List
, N_Expanded_Name
,
24897 N_Selected_Component
)
24899 Check_Refined_Global_Item
(List
, Global_Mode
);
24901 -- Simple global list or moded global list declaration
24903 elsif Nkind
(List
) = N_Aggregate
then
24905 -- The declaration of a simple global list appear as a collection
24908 if Present
(Expressions
(List
)) then
24909 Item
:= First
(Expressions
(List
));
24910 while Present
(Item
) loop
24911 Check_Refined_Global_Item
(Item
, Global_Mode
);
24915 -- The declaration of a moded global list appears as a collection
24916 -- of component associations where individual choices denote
24919 elsif Present
(Component_Associations
(List
)) then
24920 Item
:= First
(Component_Associations
(List
));
24921 while Present
(Item
) loop
24922 Check_Refined_Global_List
24923 (List
=> Expression
(Item
),
24924 Global_Mode
=> Chars
(First
(Choices
(Item
))));
24932 raise Program_Error
;
24938 raise Program_Error
;
24940 end Check_Refined_Global_List
;
24942 --------------------------
24943 -- Collect_Global_Items --
24944 --------------------------
24946 procedure Collect_Global_Items
24948 Mode
: Name_Id
:= Name_Input
)
24950 procedure Collect_Global_Item
24952 Item_Mode
: Name_Id
);
24953 -- Add a single item to the appropriate list. Item_Mode denotes the
24954 -- current mode in effect.
24956 -------------------------
24957 -- Collect_Global_Item --
24958 -------------------------
24960 procedure Collect_Global_Item
24962 Item_Mode
: Name_Id
)
24964 Item_Id
: constant Entity_Id
:= Available_View
(Entity_Of
(Item
));
24965 -- The above handles abstract views of variables and states built
24966 -- for limited with clauses.
24969 -- Signal that the global list contains at least one abstract
24970 -- state with a visible refinement. Note that the refinement may
24971 -- be null in which case there are no constituents.
24973 if Ekind
(Item_Id
) = E_Abstract_State
then
24974 if Has_Null_Visible_Refinement
(Item_Id
) then
24975 Has_Null_State
:= True;
24977 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
24978 Append_New_Elmt
(Item_Id
, States
);
24980 if Item_Mode
= Name_Input
then
24981 Has_In_State
:= True;
24982 elsif Item_Mode
= Name_In_Out
then
24983 Has_In_Out_State
:= True;
24984 elsif Item_Mode
= Name_Output
then
24985 Has_Out_State
:= True;
24986 elsif Item_Mode
= Name_Proof_In
then
24987 Has_Proof_In_State
:= True;
24992 -- Add the item to the proper list
24994 if Item_Mode
= Name_Input
then
24995 Append_New_Elmt
(Item_Id
, In_Items
);
24996 elsif Item_Mode
= Name_In_Out
then
24997 Append_New_Elmt
(Item_Id
, In_Out_Items
);
24998 elsif Item_Mode
= Name_Output
then
24999 Append_New_Elmt
(Item_Id
, Out_Items
);
25000 elsif Item_Mode
= Name_Proof_In
then
25001 Append_New_Elmt
(Item_Id
, Proof_In_Items
);
25003 end Collect_Global_Item
;
25009 -- Start of processing for Collect_Global_Items
25012 if Nkind
(List
) = N_Null
then
25015 -- Single global item declaration
25017 elsif Nkind_In
(List
, N_Expanded_Name
,
25019 N_Selected_Component
)
25021 Collect_Global_Item
(List
, Mode
);
25023 -- Single global list or moded global list declaration
25025 elsif Nkind
(List
) = N_Aggregate
then
25027 -- The declaration of a simple global list appear as a collection
25030 if Present
(Expressions
(List
)) then
25031 Item
:= First
(Expressions
(List
));
25032 while Present
(Item
) loop
25033 Collect_Global_Item
(Item
, Mode
);
25037 -- The declaration of a moded global list appears as a collection
25038 -- of component associations where individual choices denote mode.
25040 elsif Present
(Component_Associations
(List
)) then
25041 Item
:= First
(Component_Associations
(List
));
25042 while Present
(Item
) loop
25043 Collect_Global_Items
25044 (List
=> Expression
(Item
),
25045 Mode
=> Chars
(First
(Choices
(Item
))));
25053 raise Program_Error
;
25056 -- To accomodate partial decoration of disabled SPARK features, this
25057 -- routine may be called with illegal input. If this is the case, do
25058 -- not raise Program_Error.
25063 end Collect_Global_Items
;
25065 -------------------------
25066 -- Present_Then_Remove --
25067 -------------------------
25069 function Present_Then_Remove
25071 Item
: Entity_Id
) return Boolean
25076 if Present
(List
) then
25077 Elmt
:= First_Elmt
(List
);
25078 while Present
(Elmt
) loop
25079 if Node
(Elmt
) = Item
then
25080 Remove_Elmt
(List
, Elmt
);
25089 end Present_Then_Remove
;
25091 -------------------------------
25092 -- Report_Extra_Constituents --
25093 -------------------------------
25095 procedure Report_Extra_Constituents
is
25096 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
);
25097 -- Emit an error for every element of List
25099 ---------------------------------------
25100 -- Report_Extra_Constituents_In_List --
25101 ---------------------------------------
25103 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
) is
25104 Constit_Elmt
: Elmt_Id
;
25107 if Present
(List
) then
25108 Constit_Elmt
:= First_Elmt
(List
);
25109 while Present
(Constit_Elmt
) loop
25110 SPARK_Msg_NE
("extra constituent &", N
, Node
(Constit_Elmt
));
25111 Next_Elmt
(Constit_Elmt
);
25114 end Report_Extra_Constituents_In_List
;
25116 -- Start of processing for Report_Extra_Constituents
25119 -- Do not perform this check in an instance because it was already
25120 -- performed successfully in the generic template.
25122 if Is_Generic_Instance
(Spec_Id
) then
25126 Report_Extra_Constituents_In_List
(In_Constits
);
25127 Report_Extra_Constituents_In_List
(In_Out_Constits
);
25128 Report_Extra_Constituents_In_List
(Out_Constits
);
25129 Report_Extra_Constituents_In_List
(Proof_In_Constits
);
25131 end Report_Extra_Constituents
;
25135 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
25136 Errors
: constant Nat
:= Serious_Errors_Detected
;
25139 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
25142 -- Do not analyze the pragma multiple times
25144 if Is_Analyzed_Pragma
(N
) then
25148 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
25150 -- Use the anonymous object as the proper spec when Refined_Global
25151 -- applies to the body of a single task type. The object carries the
25152 -- proper Chars as well as all non-refined versions of pragmas.
25154 if Is_Single_Concurrent_Type
(Spec_Id
) then
25155 Spec_Id
:= Anonymous_Object
(Spec_Id
);
25158 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
25159 Items
:= Expression
(Get_Argument
(N
, Spec_Id
));
25161 -- The subprogram declaration lacks pragma Global. This renders
25162 -- Refined_Global useless as there is nothing to refine.
25164 if No
(Global
) then
25166 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
25167 & "& lacks aspect or pragma Global"), N
, Spec_Id
);
25171 -- Extract all relevant items from the corresponding Global pragma
25173 Collect_Global_Items
(Expression
(Get_Argument
(Global
, Spec_Id
)));
25175 -- Package and subprogram bodies are instantiated individually in
25176 -- a separate compiler pass. Due to this mode of instantiation, the
25177 -- refinement of a state may no longer be visible when a subprogram
25178 -- body contract is instantiated. Since the generic template is legal,
25179 -- do not perform this check in the instance to circumvent this oddity.
25181 if Is_Generic_Instance
(Spec_Id
) then
25184 -- Non-instance case
25187 -- The corresponding Global pragma must mention at least one state
25188 -- witha visible refinement at the point Refined_Global is processed.
25189 -- States with null refinements need Refined_Global pragma
25190 -- (SPARK RM 7.2.4(2)).
25192 if not Has_In_State
25193 and then not Has_In_Out_State
25194 and then not Has_Out_State
25195 and then not Has_Proof_In_State
25196 and then not Has_Null_State
25199 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
25200 & "depend on abstract state with visible refinement"),
25204 -- The global refinement of inputs and outputs cannot be null when
25205 -- the corresponding Global pragma contains at least one item except
25206 -- in the case where we have states with null refinements.
25208 elsif Nkind
(Items
) = N_Null
25210 (Present
(In_Items
)
25211 or else Present
(In_Out_Items
)
25212 or else Present
(Out_Items
)
25213 or else Present
(Proof_In_Items
))
25214 and then not Has_Null_State
25217 (Fix_Msg
(Spec_Id
, "refinement cannot be null, subprogram & has "
25218 & "global items"), N
, Spec_Id
);
25223 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
25224 -- This ensures that the categorization of all refined global items is
25225 -- consistent with their role.
25227 Analyze_Global_In_Decl_Part
(N
);
25229 -- Perform all refinement checks with respect to completeness and mode
25232 if Serious_Errors_Detected
= Errors
then
25233 Check_Refined_Global_List
(Items
);
25236 -- For Input states with visible refinement, at least one constituent
25237 -- must be used as an Input in the global refinement.
25239 if Serious_Errors_Detected
= Errors
then
25240 Check_Input_States
;
25243 -- Verify all possible completion variants for In_Out states with
25244 -- visible refinement.
25246 if Serious_Errors_Detected
= Errors
then
25247 Check_In_Out_States
;
25250 -- For Output states with visible refinement, all constituents must be
25251 -- used as Outputs in the global refinement.
25253 if Serious_Errors_Detected
= Errors
then
25254 Check_Output_States
;
25257 -- For Proof_In states with visible refinement, at least one constituent
25258 -- must be used as Proof_In in the global refinement.
25260 if Serious_Errors_Detected
= Errors
then
25261 Check_Proof_In_States
;
25264 -- Emit errors for all constituents that belong to other states with
25265 -- visible refinement that do not appear in Global.
25267 if Serious_Errors_Detected
= Errors
then
25268 Report_Extra_Constituents
;
25272 Set_Is_Analyzed_Pragma
(N
);
25273 end Analyze_Refined_Global_In_Decl_Part
;
25275 ----------------------------------------
25276 -- Analyze_Refined_State_In_Decl_Part --
25277 ----------------------------------------
25279 procedure Analyze_Refined_State_In_Decl_Part
25281 Freeze_Id
: Entity_Id
:= Empty
)
25283 Body_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
25284 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
25285 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(Body_Decl
);
25287 Available_States
: Elist_Id
:= No_Elist
;
25288 -- A list of all abstract states defined in the package declaration that
25289 -- are available for refinement. The list is used to report unrefined
25292 Body_States
: Elist_Id
:= No_Elist
;
25293 -- A list of all hidden states that appear in the body of the related
25294 -- package. The list is used to report unused hidden states.
25296 Constituents_Seen
: Elist_Id
:= No_Elist
;
25297 -- A list that contains all constituents processed so far. The list is
25298 -- used to detect multiple uses of the same constituent.
25300 Freeze_Posted
: Boolean := False;
25301 -- A flag that controls the output of a freezing-related error (see use
25304 Refined_States_Seen
: Elist_Id
:= No_Elist
;
25305 -- A list that contains all refined states processed so far. The list is
25306 -- used to detect duplicate refinements.
25308 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
);
25309 -- Perform full analysis of a single refinement clause
25311 procedure Report_Unrefined_States
(States
: Elist_Id
);
25312 -- Emit errors for all unrefined abstract states found in list States
25314 -------------------------------
25315 -- Analyze_Refinement_Clause --
25316 -------------------------------
25318 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
) is
25319 AR_Constit
: Entity_Id
:= Empty
;
25320 AW_Constit
: Entity_Id
:= Empty
;
25321 ER_Constit
: Entity_Id
:= Empty
;
25322 EW_Constit
: Entity_Id
:= Empty
;
25323 -- The entities of external constituents that contain one of the
25324 -- following enabled properties: Async_Readers, Async_Writers,
25325 -- Effective_Reads and Effective_Writes.
25327 External_Constit_Seen
: Boolean := False;
25328 -- Flag used to mark when at least one external constituent is part
25329 -- of the state refinement.
25331 Non_Null_Seen
: Boolean := False;
25332 Null_Seen
: Boolean := False;
25333 -- Flags used to detect multiple uses of null in a single clause or a
25334 -- mixture of null and non-null constituents.
25336 Part_Of_Constits
: Elist_Id
:= No_Elist
;
25337 -- A list of all candidate constituents subject to indicator Part_Of
25338 -- where the encapsulating state is the current state.
25341 State_Id
: Entity_Id
;
25342 -- The current state being refined
25344 procedure Analyze_Constituent
(Constit
: Node_Id
);
25345 -- Perform full analysis of a single constituent
25347 procedure Check_External_Property
25348 (Prop_Nam
: Name_Id
;
25350 Constit
: Entity_Id
);
25351 -- Determine whether a property denoted by name Prop_Nam is present
25352 -- in the refined state. Emit an error if this is not the case. Flag
25353 -- Enabled should be set when the property applies to the refined
25354 -- state. Constit denotes the constituent (if any) which introduces
25355 -- the property in the refinement.
25357 procedure Match_State
;
25358 -- Determine whether the state being refined appears in list
25359 -- Available_States. Emit an error when attempting to re-refine the
25360 -- state or when the state is not defined in the package declaration,
25361 -- otherwise remove the state from Available_States.
25363 procedure Report_Unused_Constituents
(Constits
: Elist_Id
);
25364 -- Emit errors for all unused Part_Of constituents in list Constits
25366 -------------------------
25367 -- Analyze_Constituent --
25368 -------------------------
25370 procedure Analyze_Constituent
(Constit
: Node_Id
) is
25371 procedure Match_Constituent
(Constit_Id
: Entity_Id
);
25372 -- Determine whether constituent Constit denoted by its entity
25373 -- Constit_Id appears in Body_States. Emit an error when the
25374 -- constituent is not a valid hidden state of the related package
25375 -- or when it is used more than once. Otherwise remove the
25376 -- constituent from Body_States.
25378 -----------------------
25379 -- Match_Constituent --
25380 -----------------------
25382 procedure Match_Constituent
(Constit_Id
: Entity_Id
) is
25383 procedure Collect_Constituent
;
25384 -- Verify the legality of constituent Constit_Id and add it to
25385 -- the refinements of State_Id.
25387 -------------------------
25388 -- Collect_Constituent --
25389 -------------------------
25391 procedure Collect_Constituent
is
25392 Constits
: Elist_Id
;
25395 -- The Ghost policy in effect at the point of abstract state
25396 -- declaration and constituent must match (SPARK RM 6.9(15))
25398 Check_Ghost_Refinement
25399 (State
, State_Id
, Constit
, Constit_Id
);
25401 -- A synchronized state must be refined by a synchronized
25402 -- object or another synchronized state (SPARK RM 9.6).
25404 if Is_Synchronized_State
(State_Id
)
25405 and then not Is_Synchronized_Object
(Constit_Id
)
25406 and then not Is_Synchronized_State
(Constit_Id
)
25409 ("constituent of synchronized state & must be "
25410 & "synchronized", Constit
, State_Id
);
25413 -- Add the constituent to the list of processed items to aid
25414 -- with the detection of duplicates.
25416 Append_New_Elmt
(Constit_Id
, Constituents_Seen
);
25418 -- Collect the constituent in the list of refinement items
25419 -- and establish a relation between the refined state and
25422 Constits
:= Refinement_Constituents
(State_Id
);
25424 if No
(Constits
) then
25425 Constits
:= New_Elmt_List
;
25426 Set_Refinement_Constituents
(State_Id
, Constits
);
25429 Append_Elmt
(Constit_Id
, Constits
);
25430 Set_Encapsulating_State
(Constit_Id
, State_Id
);
25432 -- The state has at least one legal constituent, mark the
25433 -- start of the refinement region. The region ends when the
25434 -- body declarations end (see routine Analyze_Declarations).
25436 Set_Has_Visible_Refinement
(State_Id
);
25438 -- When the constituent is external, save its relevant
25439 -- property for further checks.
25441 if Async_Readers_Enabled
(Constit_Id
) then
25442 AR_Constit
:= Constit_Id
;
25443 External_Constit_Seen
:= True;
25446 if Async_Writers_Enabled
(Constit_Id
) then
25447 AW_Constit
:= Constit_Id
;
25448 External_Constit_Seen
:= True;
25451 if Effective_Reads_Enabled
(Constit_Id
) then
25452 ER_Constit
:= Constit_Id
;
25453 External_Constit_Seen
:= True;
25456 if Effective_Writes_Enabled
(Constit_Id
) then
25457 EW_Constit
:= Constit_Id
;
25458 External_Constit_Seen
:= True;
25460 end Collect_Constituent
;
25464 State_Elmt
: Elmt_Id
;
25466 -- Start of processing for Match_Constituent
25469 -- Detect a duplicate use of a constituent
25471 if Contains
(Constituents_Seen
, Constit_Id
) then
25473 ("duplicate use of constituent &", Constit
, Constit_Id
);
25477 -- The constituent is subject to a Part_Of indicator
25479 if Present
(Encapsulating_State
(Constit_Id
)) then
25480 if Encapsulating_State
(Constit_Id
) = State_Id
then
25481 Remove
(Part_Of_Constits
, Constit_Id
);
25482 Collect_Constituent
;
25484 -- The constituent is part of another state and is used
25485 -- incorrectly in the refinement of the current state.
25488 Error_Msg_Name_1
:= Chars
(State_Id
);
25490 ("& cannot act as constituent of state %",
25491 Constit
, Constit_Id
);
25493 ("\Part_Of indicator specifies encapsulator &",
25494 Constit
, Encapsulating_State
(Constit_Id
));
25497 -- The only other source of legal constituents is the body
25498 -- state space of the related package.
25501 if Present
(Body_States
) then
25502 State_Elmt
:= First_Elmt
(Body_States
);
25503 while Present
(State_Elmt
) loop
25505 -- Consume a valid constituent to signal that it has
25506 -- been encountered.
25508 if Node
(State_Elmt
) = Constit_Id
then
25509 Remove_Elmt
(Body_States
, State_Elmt
);
25510 Collect_Constituent
;
25514 Next_Elmt
(State_Elmt
);
25518 -- Constants are part of the hidden state of a package, but
25519 -- the compiler cannot determine whether they have variable
25520 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
25521 -- hidden state. Accept the constant quietly even if it is
25522 -- a visible state or lacks a Part_Of indicator.
25524 if Ekind
(Constit_Id
) = E_Constant
then
25525 Collect_Constituent
;
25527 -- If we get here, then the constituent is not a hidden
25528 -- state of the related package and may not be used in a
25529 -- refinement (SPARK RM 7.2.2(9)).
25532 Error_Msg_Name_1
:= Chars
(Spec_Id
);
25534 ("cannot use & in refinement, constituent is not a "
25535 & "hidden state of package %", Constit
, Constit_Id
);
25538 end Match_Constituent
;
25542 Constit_Id
: Entity_Id
;
25543 Constits
: Elist_Id
;
25545 -- Start of processing for Analyze_Constituent
25548 -- Detect multiple uses of null in a single refinement clause or a
25549 -- mixture of null and non-null constituents.
25551 if Nkind
(Constit
) = N_Null
then
25554 ("multiple null constituents not allowed", Constit
);
25556 elsif Non_Null_Seen
then
25558 ("cannot mix null and non-null constituents", Constit
);
25563 -- Collect the constituent in the list of refinement items
25565 Constits
:= Refinement_Constituents
(State_Id
);
25567 if No
(Constits
) then
25568 Constits
:= New_Elmt_List
;
25569 Set_Refinement_Constituents
(State_Id
, Constits
);
25572 Append_Elmt
(Constit
, Constits
);
25574 -- The state has at least one legal constituent, mark the
25575 -- start of the refinement region. The region ends when the
25576 -- body declarations end (see Analyze_Declarations).
25578 Set_Has_Visible_Refinement
(State_Id
);
25581 -- Non-null constituents
25584 Non_Null_Seen
:= True;
25588 ("cannot mix null and non-null constituents", Constit
);
25592 Resolve_State
(Constit
);
25594 -- Ensure that the constituent denotes a valid state or a
25595 -- whole object (SPARK RM 7.2.2(5)).
25597 if Is_Entity_Name
(Constit
) then
25598 Constit_Id
:= Entity_Of
(Constit
);
25600 -- When a constituent is declared after a subprogram body
25601 -- that caused "freezing" of the related contract where
25602 -- pragma Refined_State resides, the constituent appears
25603 -- undefined and carries Any_Id as its entity.
25605 -- package body Pack
25606 -- with Refined_State => (State => Constit)
25609 -- with Refined_Global => (Input => Constit)
25617 if Constit_Id
= Any_Id
then
25618 SPARK_Msg_NE
("& is undefined", Constit
, Constit_Id
);
25620 -- Emit a specialized info message when the contract of
25621 -- the related package body was "frozen" by another body.
25622 -- Note that it is not possible to precisely identify why
25623 -- the constituent is undefined because it is not visible
25624 -- when pragma Refined_State is analyzed. This message is
25625 -- a reasonable approximation.
25627 if Present
(Freeze_Id
) and then not Freeze_Posted
then
25628 Freeze_Posted
:= True;
25630 Error_Msg_Name_1
:= Chars
(Body_Id
);
25631 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
25633 ("body & declared # freezes the contract of %",
25636 ("\all constituents must be declared before body #",
25639 -- A misplaced constituent is a critical error because
25640 -- pragma Refined_Depends or Refined_Global depends on
25641 -- the proper link between a state and a constituent.
25642 -- Stop the compilation, as this leads to a multitude
25643 -- of misleading cascaded errors.
25645 raise Program_Error
;
25648 -- The constituent is a valid state or object
25650 elsif Ekind_In
(Constit_Id
, E_Abstract_State
,
25654 Match_Constituent
(Constit_Id
);
25656 -- The variable may eventually become a constituent of a
25657 -- single protected/task type. Record the reference now
25658 -- and verify its legality when analyzing the contract of
25659 -- the variable (SPARK RM 9.3).
25661 if Ekind
(Constit_Id
) = E_Variable
then
25662 Record_Possible_Part_Of_Reference
25663 (Var_Id
=> Constit_Id
,
25667 -- Otherwise the constituent is illegal
25671 ("constituent & must denote object or state",
25672 Constit
, Constit_Id
);
25675 -- The constituent is illegal
25678 SPARK_Msg_N
("malformed constituent", Constit
);
25681 end Analyze_Constituent
;
25683 -----------------------------
25684 -- Check_External_Property --
25685 -----------------------------
25687 procedure Check_External_Property
25688 (Prop_Nam
: Name_Id
;
25690 Constit
: Entity_Id
)
25693 -- The property is missing in the declaration of the state, but
25694 -- a constituent is introducing it in the state refinement
25695 -- (SPARK RM 7.2.8(2)).
25697 if not Enabled
and then Present
(Constit
) then
25698 Error_Msg_Name_1
:= Prop_Nam
;
25699 Error_Msg_Name_2
:= Chars
(State_Id
);
25701 ("constituent & introduces external property % in refinement "
25702 & "of state %", State
, Constit
);
25704 Error_Msg_Sloc
:= Sloc
(State_Id
);
25706 ("\property is missing in abstract state declaration #",
25709 end Check_External_Property
;
25715 procedure Match_State
is
25716 State_Elmt
: Elmt_Id
;
25719 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
25721 if Contains
(Refined_States_Seen
, State_Id
) then
25723 ("duplicate refinement of state &", State
, State_Id
);
25727 -- Inspect the abstract states defined in the package declaration
25728 -- looking for a match.
25730 State_Elmt
:= First_Elmt
(Available_States
);
25731 while Present
(State_Elmt
) loop
25733 -- A valid abstract state is being refined in the body. Add
25734 -- the state to the list of processed refined states to aid
25735 -- with the detection of duplicate refinements. Remove the
25736 -- state from Available_States to signal that it has already
25739 if Node
(State_Elmt
) = State_Id
then
25740 Append_New_Elmt
(State_Id
, Refined_States_Seen
);
25741 Remove_Elmt
(Available_States
, State_Elmt
);
25745 Next_Elmt
(State_Elmt
);
25748 -- If we get here, we are refining a state that is not defined in
25749 -- the package declaration.
25751 Error_Msg_Name_1
:= Chars
(Spec_Id
);
25753 ("cannot refine state, & is not defined in package %",
25757 --------------------------------
25758 -- Report_Unused_Constituents --
25759 --------------------------------
25761 procedure Report_Unused_Constituents
(Constits
: Elist_Id
) is
25762 Constit_Elmt
: Elmt_Id
;
25763 Constit_Id
: Entity_Id
;
25764 Posted
: Boolean := False;
25767 if Present
(Constits
) then
25768 Constit_Elmt
:= First_Elmt
(Constits
);
25769 while Present
(Constit_Elmt
) loop
25770 Constit_Id
:= Node
(Constit_Elmt
);
25772 -- Generate an error message of the form:
25774 -- state ... has unused Part_Of constituents
25775 -- abstract state ... defined at ...
25776 -- constant ... defined at ...
25777 -- variable ... defined at ...
25782 ("state & has unused Part_Of constituents",
25786 Error_Msg_Sloc
:= Sloc
(Constit_Id
);
25788 if Ekind
(Constit_Id
) = E_Abstract_State
then
25790 ("\abstract state & defined #", State
, Constit_Id
);
25792 elsif Ekind
(Constit_Id
) = E_Constant
then
25794 ("\constant & defined #", State
, Constit_Id
);
25797 pragma Assert
(Ekind
(Constit_Id
) = E_Variable
);
25798 SPARK_Msg_NE
("\variable & defined #", State
, Constit_Id
);
25801 Next_Elmt
(Constit_Elmt
);
25804 end Report_Unused_Constituents
;
25806 -- Local declarations
25808 Body_Ref
: Node_Id
;
25809 Body_Ref_Elmt
: Elmt_Id
;
25811 Extra_State
: Node_Id
;
25813 -- Start of processing for Analyze_Refinement_Clause
25816 -- A refinement clause appears as a component association where the
25817 -- sole choice is the state and the expressions are the constituents.
25818 -- This is a syntax error, always report.
25820 if Nkind
(Clause
) /= N_Component_Association
then
25821 Error_Msg_N
("malformed state refinement clause", Clause
);
25825 -- Analyze the state name of a refinement clause
25827 State
:= First
(Choices
(Clause
));
25830 Resolve_State
(State
);
25832 -- Ensure that the state name denotes a valid abstract state that is
25833 -- defined in the spec of the related package.
25835 if Is_Entity_Name
(State
) then
25836 State_Id
:= Entity_Of
(State
);
25838 -- When the abstract state is undefined, it appears as Any_Id. Do
25839 -- not continue with the analysis of the clause.
25841 if State_Id
= Any_Id
then
25844 -- Catch any attempts to re-refine a state or refine a state that
25845 -- is not defined in the package declaration.
25847 elsif Ekind
(State_Id
) = E_Abstract_State
then
25851 SPARK_Msg_NE
("& must denote abstract state", State
, State_Id
);
25855 -- References to a state with visible refinement are illegal.
25856 -- When nested packages are involved, detecting such references is
25857 -- tricky because pragma Refined_State is analyzed later than the
25858 -- offending pragma Depends or Global. References that occur in
25859 -- such nested context are stored in a list. Emit errors for all
25860 -- references found in Body_References (SPARK RM 6.1.4(8)).
25862 if Present
(Body_References
(State_Id
)) then
25863 Body_Ref_Elmt
:= First_Elmt
(Body_References
(State_Id
));
25864 while Present
(Body_Ref_Elmt
) loop
25865 Body_Ref
:= Node
(Body_Ref_Elmt
);
25867 SPARK_Msg_N
("reference to & not allowed", Body_Ref
);
25868 Error_Msg_Sloc
:= Sloc
(State
);
25869 SPARK_Msg_N
("\refinement of & is visible#", Body_Ref
);
25871 Next_Elmt
(Body_Ref_Elmt
);
25875 -- The state name is illegal. This is a syntax error, always report.
25878 Error_Msg_N
("malformed state name in refinement clause", State
);
25882 -- A refinement clause may only refine one state at a time
25884 Extra_State
:= Next
(State
);
25886 if Present
(Extra_State
) then
25888 ("refinement clause cannot cover multiple states", Extra_State
);
25891 -- Replicate the Part_Of constituents of the refined state because
25892 -- the algorithm will consume items.
25894 Part_Of_Constits
:= New_Copy_Elist
(Part_Of_Constituents
(State_Id
));
25896 -- Analyze all constituents of the refinement. Multiple constituents
25897 -- appear as an aggregate.
25899 Constit
:= Expression
(Clause
);
25901 if Nkind
(Constit
) = N_Aggregate
then
25902 if Present
(Component_Associations
(Constit
)) then
25904 ("constituents of refinement clause must appear in "
25905 & "positional form", Constit
);
25907 else pragma Assert
(Present
(Expressions
(Constit
)));
25908 Constit
:= First
(Expressions
(Constit
));
25909 while Present
(Constit
) loop
25910 Analyze_Constituent
(Constit
);
25915 -- Various forms of a single constituent. Note that these may include
25916 -- malformed constituents.
25919 Analyze_Constituent
(Constit
);
25922 -- Verify that external constituents do not introduce new external
25923 -- property in the state refinement (SPARK RM 7.2.8(2)).
25925 if Is_External_State
(State_Id
) then
25926 Check_External_Property
25927 (Prop_Nam
=> Name_Async_Readers
,
25928 Enabled
=> Async_Readers_Enabled
(State_Id
),
25929 Constit
=> AR_Constit
);
25931 Check_External_Property
25932 (Prop_Nam
=> Name_Async_Writers
,
25933 Enabled
=> Async_Writers_Enabled
(State_Id
),
25934 Constit
=> AW_Constit
);
25936 Check_External_Property
25937 (Prop_Nam
=> Name_Effective_Reads
,
25938 Enabled
=> Effective_Reads_Enabled
(State_Id
),
25939 Constit
=> ER_Constit
);
25941 Check_External_Property
25942 (Prop_Nam
=> Name_Effective_Writes
,
25943 Enabled
=> Effective_Writes_Enabled
(State_Id
),
25944 Constit
=> EW_Constit
);
25946 -- When a refined state is not external, it should not have external
25947 -- constituents (SPARK RM 7.2.8(1)).
25949 elsif External_Constit_Seen
then
25951 ("non-external state & cannot contain external constituents in "
25952 & "refinement", State
, State_Id
);
25955 -- Ensure that all Part_Of candidate constituents have been mentioned
25956 -- in the refinement clause.
25958 Report_Unused_Constituents
(Part_Of_Constits
);
25959 end Analyze_Refinement_Clause
;
25961 -----------------------------
25962 -- Report_Unrefined_States --
25963 -----------------------------
25965 procedure Report_Unrefined_States
(States
: Elist_Id
) is
25966 State_Elmt
: Elmt_Id
;
25969 if Present
(States
) then
25970 State_Elmt
:= First_Elmt
(States
);
25971 while Present
(State_Elmt
) loop
25973 ("abstract state & must be refined", Node
(State_Elmt
));
25975 Next_Elmt
(State_Elmt
);
25978 end Report_Unrefined_States
;
25980 -- Local declarations
25982 Clauses
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
25985 -- Start of processing for Analyze_Refined_State_In_Decl_Part
25988 -- Do not analyze the pragma multiple times
25990 if Is_Analyzed_Pragma
(N
) then
25994 -- Replicate the abstract states declared by the package because the
25995 -- matching algorithm will consume states.
25997 Available_States
:= New_Copy_Elist
(Abstract_States
(Spec_Id
));
25999 -- Gather all abstract states and objects declared in the visible
26000 -- state space of the package body. These items must be utilized as
26001 -- constituents in a state refinement.
26003 Body_States
:= Collect_Body_States
(Body_Id
);
26005 -- Multiple non-null state refinements appear as an aggregate
26007 if Nkind
(Clauses
) = N_Aggregate
then
26008 if Present
(Expressions
(Clauses
)) then
26010 ("state refinements must appear as component associations",
26013 else pragma Assert
(Present
(Component_Associations
(Clauses
)));
26014 Clause
:= First
(Component_Associations
(Clauses
));
26015 while Present
(Clause
) loop
26016 Analyze_Refinement_Clause
(Clause
);
26021 -- Various forms of a single state refinement. Note that these may
26022 -- include malformed refinements.
26025 Analyze_Refinement_Clause
(Clauses
);
26028 -- List all abstract states that were left unrefined
26030 Report_Unrefined_States
(Available_States
);
26032 Set_Is_Analyzed_Pragma
(N
);
26033 end Analyze_Refined_State_In_Decl_Part
;
26035 ------------------------------------
26036 -- Analyze_Test_Case_In_Decl_Part --
26037 ------------------------------------
26039 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
) is
26040 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
26041 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
26043 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
);
26044 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
26045 -- denoted by Arg_Nam.
26047 ------------------------------
26048 -- Preanalyze_Test_Case_Arg --
26049 ------------------------------
26051 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
) is
26055 -- Preanalyze the original aspect argument for ASIS or for a generic
26056 -- subprogram to properly capture global references.
26058 if ASIS_Mode
or else Is_Generic_Subprogram
(Spec_Id
) then
26062 Arg_Nam
=> Arg_Nam
,
26063 From_Aspect
=> True);
26065 if Present
(Arg
) then
26066 Preanalyze_Assert_Expression
26067 (Expression
(Arg
), Standard_Boolean
);
26071 Arg
:= Test_Case_Arg
(N
, Arg_Nam
);
26073 if Present
(Arg
) then
26074 Preanalyze_Assert_Expression
(Expression
(Arg
), Standard_Boolean
);
26076 end Preanalyze_Test_Case_Arg
;
26080 Restore_Scope
: Boolean := False;
26082 -- Start of processing for Analyze_Test_Case_In_Decl_Part
26085 -- Do not analyze the pragma multiple times
26087 if Is_Analyzed_Pragma
(N
) then
26091 -- Ensure that the formal parameters are visible when analyzing all
26092 -- clauses. This falls out of the general rule of aspects pertaining
26093 -- to subprogram declarations.
26095 if not In_Open_Scopes
(Spec_Id
) then
26096 Restore_Scope
:= True;
26097 Push_Scope
(Spec_Id
);
26099 if Is_Generic_Subprogram
(Spec_Id
) then
26100 Install_Generic_Formals
(Spec_Id
);
26102 Install_Formals
(Spec_Id
);
26106 Preanalyze_Test_Case_Arg
(Name_Requires
);
26107 Preanalyze_Test_Case_Arg
(Name_Ensures
);
26109 if Restore_Scope
then
26113 -- Currently it is not possible to inline pre/postconditions on a
26114 -- subprogram subject to pragma Inline_Always.
26116 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
26118 Set_Is_Analyzed_Pragma
(N
);
26119 end Analyze_Test_Case_In_Decl_Part
;
26125 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean is
26130 if Present
(List
) then
26131 Elmt
:= First_Elmt
(List
);
26132 while Present
(Elmt
) loop
26133 if Nkind
(Node
(Elmt
)) = N_Defining_Identifier
then
26136 Id
:= Entity_Of
(Node
(Elmt
));
26139 if Id
= Item_Id
then
26150 -----------------------------------
26151 -- Build_Pragma_Check_Equivalent --
26152 -----------------------------------
26154 function Build_Pragma_Check_Equivalent
26156 Subp_Id
: Entity_Id
:= Empty
;
26157 Inher_Id
: Entity_Id
:= Empty
) return Node_Id
26160 -- List containing the following mappings
26161 -- * Formal parameters of inherited subprogram Inher_Id and subprogram
26164 -- * The dispatching type of Inher_Id and the dispatching type of
26167 -- * Primitives of the dispatching type of Inher_Id and primitives of
26168 -- the dispatching type of Subp_Id.
26170 function Replace_Entity
(N
: Node_Id
) return Traverse_Result
;
26171 -- Replace reference to formal of inherited operation or to primitive
26172 -- operation of root type, with corresponding entity for derived type.
26174 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
;
26175 -- Detect whether node N references a formal parameter subject to
26176 -- pragma Unreferenced. If this is the case, set Comes_From_Source
26177 -- to False to suppress the generation of a reference when analyzing
26180 --------------------
26181 -- Replace_Entity --
26182 --------------------
26184 function Replace_Entity
(N
: Node_Id
) return Traverse_Result
is
26189 if Nkind
(N
) = N_Identifier
26190 and then Present
(Entity
(N
))
26192 (Is_Formal
(Entity
(N
)) or else Is_Subprogram
(Entity
(N
)))
26194 (Nkind
(Parent
(N
)) /= N_Attribute_Reference
26195 or else Attribute_Name
(Parent
(N
)) /= Name_Class
)
26197 -- The replacement does not apply to dispatching calls within the
26198 -- condition, but only to calls whose static tag is that of the
26201 if Is_Subprogram
(Entity
(N
))
26202 and then Nkind
(Parent
(N
)) = N_Function_Call
26203 and then Present
(Controlling_Argument
(Parent
(N
)))
26208 -- Loop to find out if entity has a renaming
26211 Elmt
:= First_Elmt
(Map
);
26212 while Present
(Elmt
) loop
26213 if Node
(Elmt
) = Entity
(N
) then
26214 New_E
:= Node
(Next_Elmt
(Elmt
));
26221 if Present
(New_E
) then
26222 Rewrite
(N
, New_Occurrence_Of
(New_E
, Sloc
(N
)));
26225 -- Check that there are no calls left to abstract operations
26226 -- if the current subprogram is not abstract.
26228 if Nkind
(Parent
(N
)) = N_Function_Call
26229 and then N
= Name
(Parent
(N
))
26230 and then not Is_Abstract_Subprogram
(Subp_Id
)
26231 and then Is_Abstract_Subprogram
(Entity
(N
))
26233 Error_Msg_Sloc
:= Sloc
(Current_Scope
);
26235 ("cannot call abstract subprogram in inherited condition "
26236 & "for&#", N
, Current_Scope
);
26239 -- The whole expression will be reanalyzed
26241 elsif Nkind
(N
) in N_Has_Etype
then
26242 Set_Analyzed
(N
, False);
26246 end Replace_Entity
;
26248 ------------------------
26249 -- Suppress_Reference --
26250 ------------------------
26252 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
is
26253 Formal
: Entity_Id
;
26256 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
26257 Formal
:= Entity
(N
);
26259 -- The formal parameter is subject to pragma Unreferenced.
26260 -- Prevent the generation of a reference by resetting the
26261 -- Comes_From_Source flag.
26263 if Is_Formal
(Formal
)
26264 and then Has_Pragma_Unreferenced
(Formal
)
26266 Set_Comes_From_Source
(N
, False);
26271 end Suppress_Reference
;
26273 procedure Replace_Condition_Entities
is
26274 new Traverse_Proc
(Replace_Entity
);
26276 procedure Suppress_References
is
26277 new Traverse_Proc
(Suppress_Reference
);
26281 Loc
: constant Source_Ptr
:= Sloc
(Prag
);
26282 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
26283 Check_Prag
: Node_Id
;
26284 Inher_Formal
: Entity_Id
;
26287 Subp_Formal
: Entity_Id
;
26289 -- Start of processing for Build_Pragma_Check_Equivalent
26294 -- When the pre- or postcondition is inherited, map the formals of the
26295 -- inherited subprogram to those of the current subprogram. In addition,
26296 -- map primitive operations of the parent type into the corresponding
26297 -- primitive operations of the descendant.
26299 if Present
(Inher_Id
) then
26300 pragma Assert
(Present
(Subp_Id
));
26302 Map
:= New_Elmt_List
;
26304 -- Create a mapping <inherited formal> => <subprogram formal>
26306 Inher_Formal
:= First_Formal
(Inher_Id
);
26307 Subp_Formal
:= First_Formal
(Subp_Id
);
26308 while Present
(Inher_Formal
) and then Present
(Subp_Formal
) loop
26309 Append_Elmt
(Inher_Formal
, Map
);
26310 Append_Elmt
(Subp_Formal
, Map
);
26312 Next_Formal
(Inher_Formal
);
26313 Next_Formal
(Subp_Formal
);
26316 -- Map primitive operations of the parent type to the corresponding
26317 -- operations of the descendant. Note that the descendant type may
26318 -- not be frozen yet, so we cannot use the dispatch table directly.
26320 -- Note : the construction of the map involves a full traversal of
26321 -- the list of primitive operations, as well as a scan of the
26322 -- declarations in the scope of the operation. Given that class-wide
26323 -- conditions are typically short expressions, it might be much more
26324 -- efficient to collect the identifiers in the expression first, and
26325 -- then determine the ones that have to be mapped. Optimization ???
26327 Primitive_Mapping
: declare
26328 function Overridden_Ancestor
(S
: Entity_Id
) return Entity_Id
;
26329 -- Given the controlling type of the overridden operation and a
26330 -- primitive of the current type, find the corresponding operation
26331 -- of the parent type.
26333 -------------------------
26334 -- Overridden_Ancestor --
26335 -------------------------
26337 function Overridden_Ancestor
(S
: Entity_Id
) return Entity_Id
is
26342 while Present
(Overridden_Operation
(Anc
)) loop
26343 exit when Scope
(Anc
) = Scope
(Inher_Id
);
26344 Anc
:= Overridden_Operation
(Anc
);
26348 end Overridden_Ancestor
;
26352 Old_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Inher_Id
);
26353 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Subp_Id
);
26355 Old_Elmt
: Elmt_Id
;
26356 Old_Prim
: Entity_Id
;
26359 -- Start of processing for Primitive_Mapping
26362 Decl
:= First
(List_Containing
(Unit_Declaration_Node
(Subp_Id
)));
26364 -- Look for primitive operations of the current type that have
26365 -- overridden an operation of the type related to the original
26366 -- class-wide precondition. There may be several intermediate
26367 -- overridings between them.
26369 while Present
(Decl
) loop
26370 if Nkind
(Decl
) = N_Subprogram_Declaration
then
26371 Prim
:= Defining_Entity
(Decl
);
26373 if Is_Subprogram
(Prim
)
26374 and then Present
(Overridden_Operation
(Prim
))
26375 and then Find_Dispatching_Type
(Prim
) = Typ
26377 Old_Prim
:= Overridden_Ancestor
(Prim
);
26379 Append_Elmt
(Old_Prim
, Map
);
26380 Append_Elmt
(Prim
, Map
);
26387 -- Now examine inherited operations. These do not override, but
26388 -- have an alias, which is the entity used in a call. In turn
26389 -- that alias may be inherited or comes from source, in which
26390 -- case it may override an earlier operation. We only need to
26391 -- examine inherited functions, that may appear within the
26392 -- inherited expression.
26394 Prim
:= First_Entity
(Scope
(Subp_Id
));
26395 while Present
(Prim
) loop
26396 if not Comes_From_Source
(Prim
)
26397 and then Ekind
(Prim
) = E_Function
26398 and then Present
(Alias
(Prim
))
26400 Old_Prim
:= Alias
(Prim
);
26402 if Comes_From_Source
(Old_Prim
) then
26403 Old_Prim
:= Overridden_Ancestor
(Old_Prim
);
26406 while Present
(Alias
(Old_Prim
))
26407 and then Scope
(Old_Prim
) /= Scope
(Inher_Id
)
26409 Old_Prim
:= Alias
(Old_Prim
);
26411 if Comes_From_Source
(Old_Prim
) then
26412 Old_Prim
:= Overridden_Ancestor
(Old_Prim
);
26418 Append_Elmt
(Old_Prim
, Map
);
26419 Append_Elmt
(Prim
, Map
);
26422 Next_Entity
(Prim
);
26425 -- If the parent operation is an interface operation, the
26426 -- overriding indicator is not present. Instead, we get from
26427 -- the interface operation the primitive of the current type
26428 -- that implements it.
26430 if Is_Interface
(Old_Typ
) then
26431 Old_Elmt
:= First_Elmt
(Collect_Primitive_Operations
(Old_Typ
));
26432 while Present
(Old_Elmt
) loop
26433 Old_Prim
:= Node
(Old_Elmt
);
26434 Prim
:= Find_Primitive_Covering_Interface
(Typ
, Old_Prim
);
26436 if Present
(Prim
) then
26437 Append_Elmt
(Old_Prim
, Map
);
26438 Append_Elmt
(Prim
, Map
);
26441 Next_Elmt
(Old_Elmt
);
26445 if Map
/= No_Elist
then
26446 Append_Elmt
(Old_Typ
, Map
);
26447 Append_Elmt
(Typ
, Map
);
26449 end Primitive_Mapping
;
26452 -- Copy the original pragma while performing substitutions (if
26455 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
26457 if Map
/= No_Elist
then
26458 Replace_Condition_Entities
(Check_Prag
);
26461 -- Mark the pragma as being internally generated and reset the Analyzed
26464 Set_Analyzed
(Check_Prag
, False);
26465 Set_Comes_From_Source
(Check_Prag
, False);
26466 Set_Class_Present
(Check_Prag
, False);
26468 -- The tree of the original pragma may contain references to the
26469 -- formal parameters of the related subprogram. At the same time
26470 -- the corresponding body may mark the formals as unreferenced:
26472 -- procedure Proc (Formal : ...)
26473 -- with Pre => Formal ...;
26475 -- procedure Proc (Formal : ...) is
26476 -- pragma Unreferenced (Formal);
26479 -- This creates problems because all pragma Check equivalents are
26480 -- analyzed at the end of the body declarations. Since all source
26481 -- references have already been accounted for, reset any references
26482 -- to such formals in the generated pragma Check equivalent.
26484 Suppress_References
(Check_Prag
);
26486 if Present
(Corresponding_Aspect
(Prag
)) then
26487 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Prag
)));
26492 -- Convert the copy into pragma Check by correcting the name and adding
26493 -- a check_kind argument.
26495 Set_Pragma_Identifier
26496 (Check_Prag
, Make_Identifier
(Loc
, Name_Check
));
26498 Prepend_To
(Pragma_Argument_Associations
(Check_Prag
),
26499 Make_Pragma_Argument_Association
(Loc
,
26500 Expression
=> Make_Identifier
(Loc
, Nam
)));
26502 -- Update the error message when the pragma is inherited
26504 if Present
(Inher_Id
) then
26505 Msg_Arg
:= Last
(Pragma_Argument_Associations
(Check_Prag
));
26507 if Chars
(Msg_Arg
) = Name_Message
then
26508 String_To_Name_Buffer
(Strval
(Expression
(Msg_Arg
)));
26510 -- Insert "inherited" to improve the error message
26512 if Name_Buffer
(1 .. 8) = "failed p" then
26513 Insert_Str_In_Name_Buffer
("inherited ", 8);
26514 Set_Strval
(Expression
(Msg_Arg
), String_From_Name_Buffer
);
26520 end Build_Pragma_Check_Equivalent
;
26522 -----------------------------
26523 -- Check_Applicable_Policy --
26524 -----------------------------
26526 procedure Check_Applicable_Policy
(N
: Node_Id
) is
26530 Ename
: constant Name_Id
:= Original_Aspect_Pragma_Name
(N
);
26533 -- No effect if not valid assertion kind name
26535 if not Is_Valid_Assertion_Kind
(Ename
) then
26539 -- Loop through entries in check policy list
26541 PP
:= Opt
.Check_Policy_List
;
26542 while Present
(PP
) loop
26544 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
26545 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
26549 or else Pnm
= Name_Assertion
26550 or else (Pnm
= Name_Statement_Assertions
26551 and then Nam_In
(Ename
, Name_Assert
,
26552 Name_Assert_And_Cut
,
26554 Name_Loop_Invariant
,
26555 Name_Loop_Variant
))
26557 Policy
:= Chars
(Get_Pragma_Arg
(Last
(PPA
)));
26560 when Name_Off | Name_Ignore
=>
26561 Set_Is_Ignored
(N
, True);
26562 Set_Is_Checked
(N
, False);
26564 when Name_On | Name_Check
=>
26565 Set_Is_Checked
(N
, True);
26566 Set_Is_Ignored
(N
, False);
26568 when Name_Disable
=>
26569 Set_Is_Ignored
(N
, True);
26570 Set_Is_Checked
(N
, False);
26571 Set_Is_Disabled
(N
, True);
26573 -- That should be exhaustive, the null here is a defence
26574 -- against a malformed tree from previous errors.
26583 PP
:= Next_Pragma
(PP
);
26587 -- If there are no specific entries that matched, then we let the
26588 -- setting of assertions govern. Note that this provides the needed
26589 -- compatibility with the RM for the cases of assertion, invariant,
26590 -- precondition, predicate, and postcondition.
26592 if Assertions_Enabled
then
26593 Set_Is_Checked
(N
, True);
26594 Set_Is_Ignored
(N
, False);
26596 Set_Is_Checked
(N
, False);
26597 Set_Is_Ignored
(N
, True);
26599 end Check_Applicable_Policy
;
26601 -------------------------------
26602 -- Check_External_Properties --
26603 -------------------------------
26605 procedure Check_External_Properties
26613 -- All properties enabled
26615 if AR
and AW
and ER
and EW
then
26618 -- Async_Readers + Effective_Writes
26619 -- Async_Readers + Async_Writers + Effective_Writes
26621 elsif AR
and EW
and not ER
then
26624 -- Async_Writers + Effective_Reads
26625 -- Async_Readers + Async_Writers + Effective_Reads
26627 elsif AW
and ER
and not EW
then
26630 -- Async_Readers + Async_Writers
26632 elsif AR
and AW
and not ER
and not EW
then
26637 elsif AR
and not AW
and not ER
and not EW
then
26642 elsif AW
and not AR
and not ER
and not EW
then
26647 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
26650 end Check_External_Properties
;
26656 function Check_Kind
(Nam
: Name_Id
) return Name_Id
is
26660 -- Loop through entries in check policy list
26662 PP
:= Opt
.Check_Policy_List
;
26663 while Present
(PP
) loop
26665 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
26666 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
26670 or else (Pnm
= Name_Assertion
26671 and then Is_Valid_Assertion_Kind
(Nam
))
26672 or else (Pnm
= Name_Statement_Assertions
26673 and then Nam_In
(Nam
, Name_Assert
,
26674 Name_Assert_And_Cut
,
26676 Name_Loop_Invariant
,
26677 Name_Loop_Variant
))
26679 case (Chars
(Get_Pragma_Arg
(Last
(PPA
)))) is
26680 when Name_On | Name_Check
=>
26682 when Name_Off | Name_Ignore
=>
26683 return Name_Ignore
;
26684 when Name_Disable
=>
26685 return Name_Disable
;
26687 raise Program_Error
;
26691 PP
:= Next_Pragma
(PP
);
26696 -- If there are no specific entries that matched, then we let the
26697 -- setting of assertions govern. Note that this provides the needed
26698 -- compatibility with the RM for the cases of assertion, invariant,
26699 -- precondition, predicate, and postcondition.
26701 if Assertions_Enabled
then
26704 return Name_Ignore
;
26708 ---------------------------
26709 -- Check_Missing_Part_Of --
26710 ---------------------------
26712 procedure Check_Missing_Part_Of
(Item_Id
: Entity_Id
) is
26713 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean;
26714 -- Determine whether a package denoted by Pack_Id declares at least one
26717 -----------------------
26718 -- Has_Visible_State --
26719 -----------------------
26721 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean is
26722 Item_Id
: Entity_Id
;
26725 -- Traverse the entity chain of the package trying to find at least
26726 -- one visible abstract state, variable or a package [instantiation]
26727 -- that declares a visible state.
26729 Item_Id
:= First_Entity
(Pack_Id
);
26730 while Present
(Item_Id
)
26731 and then not In_Private_Part
(Item_Id
)
26733 -- Do not consider internally generated items
26735 if not Comes_From_Source
(Item_Id
) then
26738 -- A visible state has been found
26740 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
26743 -- Recursively peek into nested packages and instantiations
26745 elsif Ekind
(Item_Id
) = E_Package
26746 and then Has_Visible_State
(Item_Id
)
26751 Next_Entity
(Item_Id
);
26755 end Has_Visible_State
;
26759 Pack_Id
: Entity_Id
;
26760 Placement
: State_Space_Kind
;
26762 -- Start of processing for Check_Missing_Part_Of
26765 -- Do not consider abstract states, variables or package instantiations
26766 -- coming from an instance as those always inherit the Part_Of indicator
26767 -- of the instance itself.
26769 if In_Instance
then
26772 -- Do not consider internally generated entities as these can never
26773 -- have a Part_Of indicator.
26775 elsif not Comes_From_Source
(Item_Id
) then
26778 -- Perform these checks only when SPARK_Mode is enabled as they will
26779 -- interfere with standard Ada rules and produce false positives.
26781 elsif SPARK_Mode
/= On
then
26784 -- Do not consider constants, because the compiler cannot accurately
26785 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
26786 -- act as a hidden state of a package.
26788 elsif Ekind
(Item_Id
) = E_Constant
then
26792 -- Find where the abstract state, variable or package instantiation
26793 -- lives with respect to the state space.
26795 Find_Placement_In_State_Space
26796 (Item_Id
=> Item_Id
,
26797 Placement
=> Placement
,
26798 Pack_Id
=> Pack_Id
);
26800 -- Items that appear in a non-package construct (subprogram, block, etc)
26801 -- do not require a Part_Of indicator because they can never act as a
26804 if Placement
= Not_In_Package
then
26807 -- An item declared in the body state space of a package always act as a
26808 -- constituent and does not need explicit Part_Of indicator.
26810 elsif Placement
= Body_State_Space
then
26813 -- In general an item declared in the visible state space of a package
26814 -- does not require a Part_Of indicator. The only exception is when the
26815 -- related package is a private child unit in which case Part_Of must
26816 -- denote a state in the parent unit or in one of its descendants.
26818 elsif Placement
= Visible_State_Space
then
26819 if Is_Child_Unit
(Pack_Id
)
26820 and then Is_Private_Descendant
(Pack_Id
)
26822 -- A package instantiation does not need a Part_Of indicator when
26823 -- the related generic template has no visible state.
26825 if Ekind
(Item_Id
) = E_Package
26826 and then Is_Generic_Instance
(Item_Id
)
26827 and then not Has_Visible_State
(Item_Id
)
26831 -- All other cases require Part_Of
26835 ("indicator Part_Of is required in this context "
26836 & "(SPARK RM 7.2.6(3))", Item_Id
);
26837 Error_Msg_Name_1
:= Chars
(Pack_Id
);
26839 ("\& is declared in the visible part of private child "
26840 & "unit %", Item_Id
);
26844 -- When the item appears in the private state space of a packge, it must
26845 -- be a part of some state declared by the said package.
26847 else pragma Assert
(Placement
= Private_State_Space
);
26849 -- The related package does not declare a state, the item cannot act
26850 -- as a Part_Of constituent.
26852 if No
(Get_Pragma
(Pack_Id
, Pragma_Abstract_State
)) then
26855 -- A package instantiation does not need a Part_Of indicator when the
26856 -- related generic template has no visible state.
26858 elsif Ekind
(Pack_Id
) = E_Package
26859 and then Is_Generic_Instance
(Pack_Id
)
26860 and then not Has_Visible_State
(Pack_Id
)
26864 -- All other cases require Part_Of
26868 ("indicator Part_Of is required in this context "
26869 & "(SPARK RM 7.2.6(2))", Item_Id
);
26870 Error_Msg_Name_1
:= Chars
(Pack_Id
);
26872 ("\& is declared in the private part of package %", Item_Id
);
26875 end Check_Missing_Part_Of
;
26877 ---------------------------------------------------
26878 -- Check_Postcondition_Use_In_Inlined_Subprogram --
26879 ---------------------------------------------------
26881 procedure Check_Postcondition_Use_In_Inlined_Subprogram
26883 Spec_Id
: Entity_Id
)
26886 if Warn_On_Redundant_Constructs
26887 and then Has_Pragma_Inline_Always
(Spec_Id
)
26889 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
26891 if From_Aspect_Specification
(Prag
) then
26893 ("aspect % not enforced on inlined subprogram &?r?",
26894 Corresponding_Aspect
(Prag
), Spec_Id
);
26897 ("pragma % not enforced on inlined subprogram &?r?",
26901 end Check_Postcondition_Use_In_Inlined_Subprogram
;
26903 -------------------------------------
26904 -- Check_State_And_Constituent_Use --
26905 -------------------------------------
26907 procedure Check_State_And_Constituent_Use
26908 (States
: Elist_Id
;
26909 Constits
: Elist_Id
;
26912 function Find_Encapsulating_State
26913 (Constit_Id
: Entity_Id
) return Entity_Id
;
26914 -- Given the entity of a constituent, try to find a corresponding
26915 -- encapsulating state that appears in the same context. The routine
26916 -- returns Empty is no such state is found.
26918 ------------------------------
26919 -- Find_Encapsulating_State --
26920 ------------------------------
26922 function Find_Encapsulating_State
26923 (Constit_Id
: Entity_Id
) return Entity_Id
26925 State_Id
: Entity_Id
;
26928 -- Since a constituent may be part of a larger constituent set, climb
26929 -- the encapsulating state chain looking for a state that appears in
26930 -- the same context.
26932 State_Id
:= Encapsulating_State
(Constit_Id
);
26933 while Present
(State_Id
) loop
26934 if Contains
(States
, State_Id
) then
26938 State_Id
:= Encapsulating_State
(State_Id
);
26942 end Find_Encapsulating_State
;
26946 Constit_Elmt
: Elmt_Id
;
26947 Constit_Id
: Entity_Id
;
26948 State_Id
: Entity_Id
;
26950 -- Start of processing for Check_State_And_Constituent_Use
26953 -- Nothing to do if there are no states or constituents
26955 if No
(States
) or else No
(Constits
) then
26959 -- Inspect the list of constituents and try to determine whether its
26960 -- encapsulating state is in list States.
26962 Constit_Elmt
:= First_Elmt
(Constits
);
26963 while Present
(Constit_Elmt
) loop
26964 Constit_Id
:= Node
(Constit_Elmt
);
26966 -- Determine whether the constituent is part of an encapsulating
26967 -- state that appears in the same context and if this is the case,
26968 -- emit an error (SPARK RM 7.2.6(7)).
26970 State_Id
:= Find_Encapsulating_State
(Constit_Id
);
26972 if Present
(State_Id
) then
26973 Error_Msg_Name_1
:= Chars
(Constit_Id
);
26975 ("cannot mention state & and its constituent % in the same "
26976 & "context", Context
, State_Id
);
26980 Next_Elmt
(Constit_Elmt
);
26982 end Check_State_And_Constituent_Use
;
26984 ---------------------------------------------
26985 -- Collect_Inherited_Class_Wide_Conditions --
26986 ---------------------------------------------
26988 procedure Collect_Inherited_Class_Wide_Conditions
(Subp
: Entity_Id
) is
26989 Parent_Subp
: constant Entity_Id
:= Overridden_Operation
(Subp
);
26990 Prags
: constant Node_Id
:= Contract
(Parent_Subp
);
26991 In_Spec_Expr
: Boolean;
26992 Installed
: Boolean;
26994 New_Prag
: Node_Id
;
26997 Installed
:= False;
26999 -- Iterate over the contract of the overridden subprogram to find all
27000 -- inherited class-wide pre- and postconditions.
27002 if Present
(Prags
) then
27003 Prag
:= Pre_Post_Conditions
(Prags
);
27005 while Present
(Prag
) loop
27006 if Nam_In
(Pragma_Name
(Prag
), Name_Precondition
,
27007 Name_Postcondition
)
27008 and then Class_Present
(Prag
)
27010 -- The generated pragma must be analyzed in the context of
27011 -- the subprogram, to make its formals visible. In addition,
27012 -- we must inhibit freezing and full analysis because the
27013 -- controlling type of the subprogram is not frozen yet, and
27014 -- may have further primitives.
27016 if not Installed
then
27019 Install_Formals
(Subp
);
27020 In_Spec_Expr
:= In_Spec_Expression
;
27021 In_Spec_Expression
:= True;
27025 Build_Pragma_Check_Equivalent
(Prag
, Subp
, Parent_Subp
);
27026 Insert_After
(Unit_Declaration_Node
(Subp
), New_Prag
);
27027 Preanalyze
(New_Prag
);
27029 -- Prevent further analysis in subsequent processing of the
27030 -- current list of declarations
27032 Set_Analyzed
(New_Prag
);
27035 Prag
:= Next_Pragma
(Prag
);
27039 In_Spec_Expression
:= In_Spec_Expr
;
27043 end Collect_Inherited_Class_Wide_Conditions
;
27045 ---------------------------------------
27046 -- Collect_Subprogram_Inputs_Outputs --
27047 ---------------------------------------
27049 procedure Collect_Subprogram_Inputs_Outputs
27050 (Subp_Id
: Entity_Id
;
27051 Synthesize
: Boolean := False;
27052 Subp_Inputs
: in out Elist_Id
;
27053 Subp_Outputs
: in out Elist_Id
;
27054 Global_Seen
: out Boolean)
27056 procedure Collect_Dependency_Clause
(Clause
: Node_Id
);
27057 -- Collect all relevant items from a dependency clause
27059 procedure Collect_Global_List
27061 Mode
: Name_Id
:= Name_Input
);
27062 -- Collect all relevant items from a global list
27064 -------------------------------
27065 -- Collect_Dependency_Clause --
27066 -------------------------------
27068 procedure Collect_Dependency_Clause
(Clause
: Node_Id
) is
27069 procedure Collect_Dependency_Item
27071 Is_Input
: Boolean);
27072 -- Add an item to the proper subprogram input or output collection
27074 -----------------------------
27075 -- Collect_Dependency_Item --
27076 -----------------------------
27078 procedure Collect_Dependency_Item
27080 Is_Input
: Boolean)
27085 -- Nothing to collect when the item is null
27087 if Nkind
(Item
) = N_Null
then
27090 -- Ditto for attribute 'Result
27092 elsif Is_Attribute_Result
(Item
) then
27095 -- Multiple items appear as an aggregate
27097 elsif Nkind
(Item
) = N_Aggregate
then
27098 Extra
:= First
(Expressions
(Item
));
27099 while Present
(Extra
) loop
27100 Collect_Dependency_Item
(Extra
, Is_Input
);
27104 -- Otherwise this is a solitary item
27108 Append_New_Elmt
(Item
, Subp_Inputs
);
27110 Append_New_Elmt
(Item
, Subp_Outputs
);
27113 end Collect_Dependency_Item
;
27115 -- Start of processing for Collect_Dependency_Clause
27118 if Nkind
(Clause
) = N_Null
then
27121 -- A dependency cause appears as component association
27123 elsif Nkind
(Clause
) = N_Component_Association
then
27124 Collect_Dependency_Item
27125 (Item
=> Expression
(Clause
),
27128 Collect_Dependency_Item
27129 (Item
=> First
(Choices
(Clause
)),
27130 Is_Input
=> False);
27132 -- To accomodate partial decoration of disabled SPARK features, this
27133 -- routine may be called with illegal input. If this is the case, do
27134 -- not raise Program_Error.
27139 end Collect_Dependency_Clause
;
27141 -------------------------
27142 -- Collect_Global_List --
27143 -------------------------
27145 procedure Collect_Global_List
27147 Mode
: Name_Id
:= Name_Input
)
27149 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
27150 -- Add an item to the proper subprogram input or output collection
27152 -------------------------
27153 -- Collect_Global_Item --
27154 -------------------------
27156 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
27158 if Nam_In
(Mode
, Name_In_Out
, Name_Input
) then
27159 Append_New_Elmt
(Item
, Subp_Inputs
);
27162 if Nam_In
(Mode
, Name_In_Out
, Name_Output
) then
27163 Append_New_Elmt
(Item
, Subp_Outputs
);
27165 end Collect_Global_Item
;
27172 -- Start of processing for Collect_Global_List
27175 if Nkind
(List
) = N_Null
then
27178 -- Single global item declaration
27180 elsif Nkind_In
(List
, N_Expanded_Name
,
27182 N_Selected_Component
)
27184 Collect_Global_Item
(List
, Mode
);
27186 -- Simple global list or moded global list declaration
27188 elsif Nkind
(List
) = N_Aggregate
then
27189 if Present
(Expressions
(List
)) then
27190 Item
:= First
(Expressions
(List
));
27191 while Present
(Item
) loop
27192 Collect_Global_Item
(Item
, Mode
);
27197 Assoc
:= First
(Component_Associations
(List
));
27198 while Present
(Assoc
) loop
27199 Collect_Global_List
27200 (List
=> Expression
(Assoc
),
27201 Mode
=> Chars
(First
(Choices
(Assoc
))));
27206 -- To accomodate partial decoration of disabled SPARK features, this
27207 -- routine may be called with illegal input. If this is the case, do
27208 -- not raise Program_Error.
27213 end Collect_Global_List
;
27220 Formal
: Entity_Id
;
27222 Spec_Id
: Entity_Id
;
27223 Subp_Decl
: Node_Id
;
27226 -- Start of processing for Collect_Subprogram_Inputs_Outputs
27229 Global_Seen
:= False;
27231 -- Process all formal parameters of entries, [generic] subprograms, and
27234 if Ekind_In
(Subp_Id
, E_Entry
,
27237 E_Generic_Function
,
27238 E_Generic_Procedure
,
27242 Subp_Decl
:= Unit_Declaration_Node
(Subp_Id
);
27243 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
27245 -- Process all [generic] formal parameters
27247 Formal
:= First_Entity
(Spec_Id
);
27248 while Present
(Formal
) loop
27249 if Ekind_In
(Formal
, E_Generic_In_Parameter
,
27250 E_In_Out_Parameter
,
27253 Append_New_Elmt
(Formal
, Subp_Inputs
);
27256 if Ekind_In
(Formal
, E_Generic_In_Out_Parameter
,
27257 E_In_Out_Parameter
,
27260 Append_New_Elmt
(Formal
, Subp_Outputs
);
27262 -- Out parameters can act as inputs when the related type is
27263 -- tagged, unconstrained array, unconstrained record, or record
27264 -- with unconstrained components.
27266 if Ekind
(Formal
) = E_Out_Parameter
27267 and then Is_Unconstrained_Or_Tagged_Item
(Formal
)
27269 Append_New_Elmt
(Formal
, Subp_Inputs
);
27273 Next_Entity
(Formal
);
27276 -- Otherwise the input denotes a task type, a task body, or the
27277 -- anonymous object created for a single task type.
27279 elsif Ekind_In
(Subp_Id
, E_Task_Type
, E_Task_Body
)
27280 or else Is_Single_Task_Object
(Subp_Id
)
27282 Subp_Decl
:= Declaration_Node
(Subp_Id
);
27283 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
27286 -- When processing an entry, subprogram or task body, look for pragmas
27287 -- Refined_Depends and Refined_Global as they specify the inputs and
27290 if Is_Entry_Body
(Subp_Id
)
27291 or else Ekind_In
(Subp_Id
, E_Subprogram_Body
, E_Task_Body
)
27293 Depends
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Depends
);
27294 Global
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Global
);
27296 -- Subprogram declaration or stand alone body case, look for pragmas
27297 -- Depends and Global
27300 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
27301 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
27304 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
27305 -- because it provides finer granularity of inputs and outputs.
27307 if Present
(Global
) then
27308 Global_Seen
:= True;
27309 Collect_Global_List
(Expression
(Get_Argument
(Global
, Spec_Id
)));
27311 -- When the related subprogram lacks pragma [Refined_]Global, fall back
27312 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
27313 -- the inputs and outputs from [Refined_]Depends.
27315 elsif Synthesize
and then Present
(Depends
) then
27316 Clauses
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
27318 -- Multiple dependency clauses appear as an aggregate
27320 if Nkind
(Clauses
) = N_Aggregate
then
27321 Clause
:= First
(Component_Associations
(Clauses
));
27322 while Present
(Clause
) loop
27323 Collect_Dependency_Clause
(Clause
);
27327 -- Otherwise this is a single dependency clause
27330 Collect_Dependency_Clause
(Clauses
);
27334 -- The current instance of a protected type acts as a formal parameter
27335 -- of mode IN for functions and IN OUT for entries and procedures
27336 -- (SPARK RM 6.1.4).
27338 if Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
27339 Typ
:= Scope
(Spec_Id
);
27341 -- Use the anonymous object when the type is single protected
27343 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
27344 Typ
:= Anonymous_Object
(Typ
);
27347 Append_New_Elmt
(Typ
, Subp_Inputs
);
27349 if Ekind_In
(Spec_Id
, E_Entry
, E_Entry_Family
, E_Procedure
) then
27350 Append_New_Elmt
(Typ
, Subp_Outputs
);
27353 -- The current instance of a task type acts as a formal parameter of
27354 -- mode IN OUT (SPARK RM 6.1.4).
27356 elsif Ekind
(Spec_Id
) = E_Task_Type
then
27359 -- Use the anonymous object when the type is single task
27361 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
27362 Typ
:= Anonymous_Object
(Typ
);
27365 Append_New_Elmt
(Typ
, Subp_Inputs
);
27366 Append_New_Elmt
(Typ
, Subp_Outputs
);
27368 elsif Is_Single_Task_Object
(Spec_Id
) then
27369 Append_New_Elmt
(Spec_Id
, Subp_Inputs
);
27370 Append_New_Elmt
(Spec_Id
, Subp_Outputs
);
27372 end Collect_Subprogram_Inputs_Outputs
;
27374 ---------------------------
27375 -- Contract_Freeze_Error --
27376 ---------------------------
27378 procedure Contract_Freeze_Error
27379 (Contract_Id
: Entity_Id
;
27380 Freeze_Id
: Entity_Id
)
27383 Error_Msg_Name_1
:= Chars
(Contract_Id
);
27384 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
27387 ("body & declared # freezes the contract of%", Contract_Id
, Freeze_Id
);
27389 ("\all contractual items must be declared before body #", Contract_Id
);
27390 end Contract_Freeze_Error
;
27392 ---------------------------------
27393 -- Delay_Config_Pragma_Analyze --
27394 ---------------------------------
27396 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean is
27398 return Nam_In
(Pragma_Name
(N
), Name_Interrupt_State
,
27399 Name_Priority_Specific_Dispatching
);
27400 end Delay_Config_Pragma_Analyze
;
27402 -----------------------
27403 -- Duplication_Error --
27404 -----------------------
27406 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
) is
27407 Prag_From_Asp
: constant Boolean := From_Aspect_Specification
(Prag
);
27408 Prev_From_Asp
: constant Boolean := From_Aspect_Specification
(Prev
);
27411 Error_Msg_Sloc
:= Sloc
(Prev
);
27412 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
27414 -- Emit a precise message to distinguish between source pragmas and
27415 -- pragmas generated from aspects. The ordering of the two pragmas is
27419 -- Prag -- duplicate
27421 -- No error is emitted when both pragmas come from aspects because this
27422 -- is already detected by the general aspect analysis mechanism.
27424 if Prag_From_Asp
and Prev_From_Asp
then
27426 elsif Prag_From_Asp
then
27427 Error_Msg_N
("aspect % duplicates pragma declared #", Prag
);
27428 elsif Prev_From_Asp
then
27429 Error_Msg_N
("pragma % duplicates aspect declared #", Prag
);
27431 Error_Msg_N
("pragma % duplicates pragma declared #", Prag
);
27433 end Duplication_Error
;
27435 --------------------------
27436 -- Find_Related_Context --
27437 --------------------------
27439 function Find_Related_Context
27441 Do_Checks
: Boolean := False) return Node_Id
27446 Stmt
:= Prev
(Prag
);
27447 while Present
(Stmt
) loop
27449 -- Skip prior pragmas, but check for duplicates
27451 if Nkind
(Stmt
) = N_Pragma
then
27452 if Do_Checks
and then Pragma_Name
(Stmt
) = Pragma_Name
(Prag
) then
27458 -- Skip internally generated code
27460 elsif not Comes_From_Source
(Stmt
) then
27462 -- The anonymous object created for a single concurrent type is a
27463 -- suitable context.
27465 if Nkind
(Stmt
) = N_Object_Declaration
27466 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
27471 -- Return the current source construct
27481 end Find_Related_Context
;
27483 --------------------------------------
27484 -- Find_Related_Declaration_Or_Body --
27485 --------------------------------------
27487 function Find_Related_Declaration_Or_Body
27489 Do_Checks
: Boolean := False) return Node_Id
27491 Prag_Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
27493 procedure Expression_Function_Error
;
27494 -- Emit an error concerning pragma Prag that illegaly applies to an
27495 -- expression function.
27497 -------------------------------
27498 -- Expression_Function_Error --
27499 -------------------------------
27501 procedure Expression_Function_Error
is
27503 Error_Msg_Name_1
:= Prag_Nam
;
27505 -- Emit a precise message to distinguish between source pragmas and
27506 -- pragmas generated from aspects.
27508 if From_Aspect_Specification
(Prag
) then
27510 ("aspect % cannot apply to a stand alone expression function",
27514 ("pragma % cannot apply to a stand alone expression function",
27517 end Expression_Function_Error
;
27521 Context
: constant Node_Id
:= Parent
(Prag
);
27524 Look_For_Body
: constant Boolean :=
27525 Nam_In
(Prag_Nam
, Name_Refined_Depends
,
27526 Name_Refined_Global
,
27527 Name_Refined_Post
);
27528 -- Refinement pragmas must be associated with a subprogram body [stub]
27530 -- Start of processing for Find_Related_Declaration_Or_Body
27533 Stmt
:= Prev
(Prag
);
27534 while Present
(Stmt
) loop
27536 -- Skip prior pragmas, but check for duplicates. Pragmas produced
27537 -- by splitting a complex pre/postcondition are not considered to
27540 if Nkind
(Stmt
) = N_Pragma
then
27542 and then not Split_PPC
(Stmt
)
27543 and then Original_Aspect_Pragma_Name
(Stmt
) = Prag_Nam
27550 -- Emit an error when a refinement pragma appears on an expression
27551 -- function without a completion.
27554 and then Look_For_Body
27555 and then Nkind
(Stmt
) = N_Subprogram_Declaration
27556 and then Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
27557 and then not Has_Completion
(Defining_Entity
(Stmt
))
27559 Expression_Function_Error
;
27562 -- The refinement pragma applies to a subprogram body stub
27564 elsif Look_For_Body
27565 and then Nkind
(Stmt
) = N_Subprogram_Body_Stub
27569 -- Skip internally generated code
27571 elsif not Comes_From_Source
(Stmt
) then
27573 -- The anonymous object created for a single concurrent type is a
27574 -- suitable context.
27576 if Nkind
(Stmt
) = N_Object_Declaration
27577 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
27581 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
then
27583 -- The subprogram declaration is an internally generated spec
27584 -- for an expression function.
27586 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
27589 -- The subprogram is actually an instance housed within an
27590 -- anonymous wrapper package.
27592 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
27597 -- Return the current construct which is either a subprogram body,
27598 -- a subprogram declaration or is illegal.
27607 -- If we fall through, then the pragma was either the first declaration
27608 -- or it was preceded by other pragmas and no source constructs.
27610 -- The pragma is associated with a library-level subprogram
27612 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
27613 return Unit
(Parent
(Context
));
27615 -- The pragma appears inside the declarations of an entry body
27617 elsif Nkind
(Context
) = N_Entry_Body
then
27620 -- The pragma appears inside the statements of a subprogram body. This
27621 -- placement is the result of subprogram contract expansion.
27623 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
then
27624 return Parent
(Context
);
27626 -- The pragma appears inside the declarative part of a subprogram body
27628 elsif Nkind
(Context
) = N_Subprogram_Body
then
27631 -- The pragma appears inside the declarative part of a task body
27633 elsif Nkind
(Context
) = N_Task_Body
then
27636 -- The pragma is a byproduct of aspect expansion, return the related
27637 -- context of the original aspect. This case has a lower priority as
27638 -- the above circuitry pinpoints precisely the related context.
27640 elsif Present
(Corresponding_Aspect
(Prag
)) then
27641 return Parent
(Corresponding_Aspect
(Prag
));
27643 -- No candidate subprogram [body] found
27648 end Find_Related_Declaration_Or_Body
;
27650 ----------------------------------
27651 -- Find_Related_Package_Or_Body --
27652 ----------------------------------
27654 function Find_Related_Package_Or_Body
27656 Do_Checks
: Boolean := False) return Node_Id
27658 Context
: constant Node_Id
:= Parent
(Prag
);
27659 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
27663 Stmt
:= Prev
(Prag
);
27664 while Present
(Stmt
) loop
27666 -- Skip prior pragmas, but check for duplicates
27668 if Nkind
(Stmt
) = N_Pragma
then
27669 if Do_Checks
and then Pragma_Name
(Stmt
) = Prag_Nam
then
27675 -- Skip internally generated code
27677 elsif not Comes_From_Source
(Stmt
) then
27678 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
27680 -- The subprogram declaration is an internally generated spec
27681 -- for an expression function.
27683 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
27686 -- The subprogram is actually an instance housed within an
27687 -- anonymous wrapper package.
27689 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
27694 -- Return the current source construct which is illegal
27703 -- If we fall through, then the pragma was either the first declaration
27704 -- or it was preceded by other pragmas and no source constructs.
27706 -- The pragma is associated with a package. The immediate context in
27707 -- this case is the specification of the package.
27709 if Nkind
(Context
) = N_Package_Specification
then
27710 return Parent
(Context
);
27712 -- The pragma appears in the declarations of a package body
27714 elsif Nkind
(Context
) = N_Package_Body
then
27717 -- The pragma appears in the statements of a package body
27719 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
27720 and then Nkind
(Parent
(Context
)) = N_Package_Body
27722 return Parent
(Context
);
27724 -- The pragma is a byproduct of aspect expansion, return the related
27725 -- context of the original aspect. This case has a lower priority as
27726 -- the above circuitry pinpoints precisely the related context.
27728 elsif Present
(Corresponding_Aspect
(Prag
)) then
27729 return Parent
(Corresponding_Aspect
(Prag
));
27731 -- No candidate packge [body] found
27736 end Find_Related_Package_Or_Body
;
27742 function Get_Argument
27744 Context_Id
: Entity_Id
:= Empty
) return Node_Id
27746 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
27749 -- Use the expression of the original aspect when compiling for ASIS or
27750 -- when analyzing the template of a generic unit. In both cases the
27751 -- aspect's tree must be decorated to allow for ASIS queries or to save
27752 -- the global references in the generic context.
27754 if From_Aspect_Specification
(Prag
)
27755 and then (ASIS_Mode
or else (Present
(Context_Id
)
27756 and then Is_Generic_Unit
(Context_Id
)))
27758 return Corresponding_Aspect
(Prag
);
27760 -- Otherwise use the expression of the pragma
27762 elsif Present
(Args
) then
27763 return First
(Args
);
27770 -------------------------
27771 -- Get_Base_Subprogram --
27772 -------------------------
27774 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
is
27775 Result
: Entity_Id
;
27778 -- Follow subprogram renaming chain
27782 if Is_Subprogram
(Result
)
27784 Nkind
(Parent
(Declaration_Node
(Result
))) =
27785 N_Subprogram_Renaming_Declaration
27786 and then Present
(Alias
(Result
))
27788 Result
:= Alias
(Result
);
27792 end Get_Base_Subprogram
;
27794 -----------------------
27795 -- Get_SPARK_Mode_Type --
27796 -----------------------
27798 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
is
27800 if N
= Name_On
then
27802 elsif N
= Name_Off
then
27805 -- Any other argument is illegal
27808 raise Program_Error
;
27810 end Get_SPARK_Mode_Type
;
27812 ------------------------------------
27813 -- Get_SPARK_Mode_From_Annotation --
27814 ------------------------------------
27816 function Get_SPARK_Mode_From_Annotation
27817 (N
: Node_Id
) return SPARK_Mode_Type
27822 if Nkind
(N
) = N_Aspect_Specification
then
27823 Mode
:= Expression
(N
);
27825 else pragma Assert
(Nkind
(N
) = N_Pragma
);
27826 Mode
:= First
(Pragma_Argument_Associations
(N
));
27828 if Present
(Mode
) then
27829 Mode
:= Get_Pragma_Arg
(Mode
);
27833 -- Aspect or pragma SPARK_Mode specifies an explicit mode
27835 if Present
(Mode
) then
27836 if Nkind
(Mode
) = N_Identifier
then
27837 return Get_SPARK_Mode_Type
(Chars
(Mode
));
27839 -- In case of a malformed aspect or pragma, return the default None
27845 -- Otherwise the lack of an expression defaults SPARK_Mode to On
27850 end Get_SPARK_Mode_From_Annotation
;
27852 ---------------------------
27853 -- Has_Extra_Parentheses --
27854 ---------------------------
27856 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean is
27860 -- The aggregate should not have an expression list because a clause
27861 -- is always interpreted as a component association. The only way an
27862 -- expression list can sneak in is by adding extra parentheses around
27863 -- the individual clauses:
27865 -- Depends (Output => Input) -- proper form
27866 -- Depends ((Output => Input)) -- extra parentheses
27868 -- Since the extra parentheses are not allowed by the syntax of the
27869 -- pragma, flag them now to avoid emitting misleading errors down the
27872 if Nkind
(Clause
) = N_Aggregate
27873 and then Present
(Expressions
(Clause
))
27875 Expr
:= First
(Expressions
(Clause
));
27876 while Present
(Expr
) loop
27878 -- A dependency clause surrounded by extra parentheses appears
27879 -- as an aggregate of component associations with an optional
27880 -- Paren_Count set.
27882 if Nkind
(Expr
) = N_Aggregate
27883 and then Present
(Component_Associations
(Expr
))
27886 ("dependency clause contains extra parentheses", Expr
);
27888 -- Otherwise the expression is a malformed construct
27891 SPARK_Msg_N
("malformed dependency clause", Expr
);
27901 end Has_Extra_Parentheses
;
27907 procedure Initialize
is
27918 Dummy
:= Dummy
+ 1;
27921 -----------------------------
27922 -- Is_Config_Static_String --
27923 -----------------------------
27925 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean is
27927 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean;
27928 -- This is an internal recursive function that is just like the outer
27929 -- function except that it adds the string to the name buffer rather
27930 -- than placing the string in the name buffer.
27932 ------------------------------
27933 -- Add_Config_Static_String --
27934 ------------------------------
27936 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean is
27943 if Nkind
(N
) = N_Op_Concat
then
27944 if Add_Config_Static_String
(Left_Opnd
(N
)) then
27945 N
:= Right_Opnd
(N
);
27951 if Nkind
(N
) /= N_String_Literal
then
27952 Error_Msg_N
("string literal expected for pragma argument", N
);
27956 for J
in 1 .. String_Length
(Strval
(N
)) loop
27957 C
:= Get_String_Char
(Strval
(N
), J
);
27959 if not In_Character_Range
(C
) then
27961 ("string literal contains invalid wide character",
27962 Sloc
(N
) + 1 + Source_Ptr
(J
));
27966 Add_Char_To_Name_Buffer
(Get_Character
(C
));
27971 end Add_Config_Static_String
;
27973 -- Start of processing for Is_Config_Static_String
27978 return Add_Config_Static_String
(Arg
);
27979 end Is_Config_Static_String
;
27981 ---------------------
27982 -- Is_CCT_Instance --
27983 ---------------------
27985 function Is_CCT_Instance
27986 (Ref_Id
: Entity_Id
;
27987 Context_Id
: Entity_Id
) return Boolean
27993 -- When the reference denotes a single protected type, the context is
27994 -- either a protected subprogram or its body.
27996 if Is_Single_Protected_Object
(Ref_Id
) then
27997 Typ
:= Scope
(Context_Id
);
28000 Ekind
(Typ
) = E_Protected_Type
28001 and then Present
(Anonymous_Object
(Typ
))
28002 and then Anonymous_Object
(Typ
) = Ref_Id
;
28004 -- When the reference denotes a single task type, the context is either
28005 -- the same type or if inside the body, the anonymous task type.
28007 elsif Is_Single_Task_Object
(Ref_Id
) then
28008 if Ekind
(Context_Id
) = E_Task_Type
then
28010 Present
(Anonymous_Object
(Context_Id
))
28011 and then Anonymous_Object
(Context_Id
) = Ref_Id
;
28013 return Ref_Id
= Context_Id
;
28016 -- Otherwise the reference denotes a protected or a task type. Climb the
28017 -- scope chain looking for an enclosing concurrent type that matches the
28018 -- referenced entity.
28021 pragma Assert
(Ekind_In
(Ref_Id
, E_Protected_Type
, E_Task_Type
));
28023 S
:= Current_Scope
;
28024 while Present
(S
) and then S
/= Standard_Standard
loop
28025 if Ekind_In
(S
, E_Protected_Type
, E_Task_Type
)
28026 and then S
= Ref_Id
28036 end Is_CCT_Instance
;
28038 -------------------------------
28039 -- Is_Elaboration_SPARK_Mode --
28040 -------------------------------
28042 function Is_Elaboration_SPARK_Mode
(N
: Node_Id
) return Boolean is
28045 (Nkind
(N
) = N_Pragma
28046 and then Pragma_Name
(N
) = Name_SPARK_Mode
28047 and then Is_List_Member
(N
));
28049 -- Pragma SPARK_Mode affects the elaboration of a package body when it
28050 -- appears in the statement part of the body.
28053 Present
(Parent
(N
))
28054 and then Nkind
(Parent
(N
)) = N_Handled_Sequence_Of_Statements
28055 and then List_Containing
(N
) = Statements
(Parent
(N
))
28056 and then Present
(Parent
(Parent
(N
)))
28057 and then Nkind
(Parent
(Parent
(N
))) = N_Package_Body
;
28058 end Is_Elaboration_SPARK_Mode
;
28060 -----------------------
28061 -- Is_Enabled_Pragma --
28062 -----------------------
28064 function Is_Enabled_Pragma
(Prag
: Node_Id
) return Boolean is
28068 if Present
(Prag
) then
28069 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
28071 if Present
(Arg
) then
28072 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg
)));
28074 -- The lack of a Boolean argument automatically enables the pragma
28080 -- The pragma is missing, therefore it is not enabled
28085 end Is_Enabled_Pragma
;
28087 -----------------------------------------
28088 -- Is_Non_Significant_Pragma_Reference --
28089 -----------------------------------------
28091 -- This function makes use of the following static table which indicates
28092 -- whether appearance of some name in a given pragma is to be considered
28093 -- as a reference for the purposes of warnings about unreferenced objects.
28095 -- -1 indicates that appearence in any argument is significant
28096 -- 0 indicates that appearance in any argument is not significant
28097 -- +n indicates that appearance as argument n is significant, but all
28098 -- other arguments are not significant
28099 -- 9n arguments from n on are significant, before n insignificant
28101 Sig_Flags
: constant array (Pragma_Id
) of Int
:=
28102 (Pragma_Abort_Defer
=> -1,
28103 Pragma_Abstract_State
=> -1,
28104 Pragma_Ada_83
=> -1,
28105 Pragma_Ada_95
=> -1,
28106 Pragma_Ada_05
=> -1,
28107 Pragma_Ada_2005
=> -1,
28108 Pragma_Ada_12
=> -1,
28109 Pragma_Ada_2012
=> -1,
28110 Pragma_All_Calls_Remote
=> -1,
28111 Pragma_Allow_Integer_Address
=> -1,
28112 Pragma_Annotate
=> 93,
28113 Pragma_Assert
=> -1,
28114 Pragma_Assert_And_Cut
=> -1,
28115 Pragma_Assertion_Policy
=> 0,
28116 Pragma_Assume
=> -1,
28117 Pragma_Assume_No_Invalid_Values
=> 0,
28118 Pragma_Async_Readers
=> 0,
28119 Pragma_Async_Writers
=> 0,
28120 Pragma_Asynchronous
=> 0,
28121 Pragma_Atomic
=> 0,
28122 Pragma_Atomic_Components
=> 0,
28123 Pragma_Attach_Handler
=> -1,
28124 Pragma_Attribute_Definition
=> 92,
28125 Pragma_Check
=> -1,
28126 Pragma_Check_Float_Overflow
=> 0,
28127 Pragma_Check_Name
=> 0,
28128 Pragma_Check_Policy
=> 0,
28129 Pragma_CPP_Class
=> 0,
28130 Pragma_CPP_Constructor
=> 0,
28131 Pragma_CPP_Virtual
=> 0,
28132 Pragma_CPP_Vtable
=> 0,
28134 Pragma_C_Pass_By_Copy
=> 0,
28135 Pragma_Comment
=> -1,
28136 Pragma_Common_Object
=> 0,
28137 Pragma_Compile_Time_Error
=> -1,
28138 Pragma_Compile_Time_Warning
=> -1,
28139 Pragma_Compiler_Unit
=> -1,
28140 Pragma_Compiler_Unit_Warning
=> -1,
28141 Pragma_Complete_Representation
=> 0,
28142 Pragma_Complex_Representation
=> 0,
28143 Pragma_Component_Alignment
=> 0,
28144 Pragma_Constant_After_Elaboration
=> 0,
28145 Pragma_Contract_Cases
=> -1,
28146 Pragma_Controlled
=> 0,
28147 Pragma_Convention
=> 0,
28148 Pragma_Convention_Identifier
=> 0,
28149 Pragma_Debug
=> -1,
28150 Pragma_Debug_Policy
=> 0,
28151 Pragma_Detect_Blocking
=> 0,
28152 Pragma_Default_Initial_Condition
=> -1,
28153 Pragma_Default_Scalar_Storage_Order
=> 0,
28154 Pragma_Default_Storage_Pool
=> 0,
28155 Pragma_Depends
=> -1,
28156 Pragma_Disable_Atomic_Synchronization
=> 0,
28157 Pragma_Discard_Names
=> 0,
28158 Pragma_Dispatching_Domain
=> -1,
28159 Pragma_Effective_Reads
=> 0,
28160 Pragma_Effective_Writes
=> 0,
28161 Pragma_Elaborate
=> 0,
28162 Pragma_Elaborate_All
=> 0,
28163 Pragma_Elaborate_Body
=> 0,
28164 Pragma_Elaboration_Checks
=> 0,
28165 Pragma_Eliminate
=> 0,
28166 Pragma_Enable_Atomic_Synchronization
=> 0,
28167 Pragma_Export
=> -1,
28168 Pragma_Export_Function
=> -1,
28169 Pragma_Export_Object
=> -1,
28170 Pragma_Export_Procedure
=> -1,
28171 Pragma_Export_Value
=> -1,
28172 Pragma_Export_Valued_Procedure
=> -1,
28173 Pragma_Extend_System
=> -1,
28174 Pragma_Extensions_Allowed
=> 0,
28175 Pragma_Extensions_Visible
=> 0,
28176 Pragma_External
=> -1,
28177 Pragma_Favor_Top_Level
=> 0,
28178 Pragma_External_Name_Casing
=> 0,
28179 Pragma_Fast_Math
=> 0,
28180 Pragma_Finalize_Storage_Only
=> 0,
28182 Pragma_Global
=> -1,
28183 Pragma_Ident
=> -1,
28184 Pragma_Ignore_Pragma
=> 0,
28185 Pragma_Implementation_Defined
=> -1,
28186 Pragma_Implemented
=> -1,
28187 Pragma_Implicit_Packing
=> 0,
28188 Pragma_Import
=> 93,
28189 Pragma_Import_Function
=> 0,
28190 Pragma_Import_Object
=> 0,
28191 Pragma_Import_Procedure
=> 0,
28192 Pragma_Import_Valued_Procedure
=> 0,
28193 Pragma_Independent
=> 0,
28194 Pragma_Independent_Components
=> 0,
28195 Pragma_Initial_Condition
=> -1,
28196 Pragma_Initialize_Scalars
=> 0,
28197 Pragma_Initializes
=> -1,
28198 Pragma_Inline
=> 0,
28199 Pragma_Inline_Always
=> 0,
28200 Pragma_Inline_Generic
=> 0,
28201 Pragma_Inspection_Point
=> -1,
28202 Pragma_Interface
=> 92,
28203 Pragma_Interface_Name
=> 0,
28204 Pragma_Interrupt_Handler
=> -1,
28205 Pragma_Interrupt_Priority
=> -1,
28206 Pragma_Interrupt_State
=> -1,
28207 Pragma_Invariant
=> -1,
28208 Pragma_Keep_Names
=> 0,
28209 Pragma_License
=> 0,
28210 Pragma_Link_With
=> -1,
28211 Pragma_Linker_Alias
=> -1,
28212 Pragma_Linker_Constructor
=> -1,
28213 Pragma_Linker_Destructor
=> -1,
28214 Pragma_Linker_Options
=> -1,
28215 Pragma_Linker_Section
=> 0,
28217 Pragma_Lock_Free
=> 0,
28218 Pragma_Locking_Policy
=> 0,
28219 Pragma_Loop_Invariant
=> -1,
28220 Pragma_Loop_Optimize
=> 0,
28221 Pragma_Loop_Variant
=> -1,
28222 Pragma_Machine_Attribute
=> -1,
28224 Pragma_Main_Storage
=> -1,
28225 Pragma_Memory_Size
=> 0,
28226 Pragma_No_Return
=> 0,
28227 Pragma_No_Body
=> 0,
28228 Pragma_No_Elaboration_Code_All
=> 0,
28229 Pragma_No_Inline
=> 0,
28230 Pragma_No_Run_Time
=> -1,
28231 Pragma_No_Strict_Aliasing
=> -1,
28232 Pragma_No_Tagged_Streams
=> 0,
28233 Pragma_Normalize_Scalars
=> 0,
28234 Pragma_Obsolescent
=> 0,
28235 Pragma_Optimize
=> 0,
28236 Pragma_Optimize_Alignment
=> 0,
28237 Pragma_Overflow_Mode
=> 0,
28238 Pragma_Overriding_Renamings
=> 0,
28239 Pragma_Ordered
=> 0,
28242 Pragma_Part_Of
=> 0,
28243 Pragma_Partition_Elaboration_Policy
=> 0,
28244 Pragma_Passive
=> 0,
28245 Pragma_Persistent_BSS
=> 0,
28246 Pragma_Polling
=> 0,
28247 Pragma_Prefix_Exception_Messages
=> 0,
28249 Pragma_Postcondition
=> -1,
28250 Pragma_Post_Class
=> -1,
28252 Pragma_Precondition
=> -1,
28253 Pragma_Predicate
=> -1,
28254 Pragma_Predicate_Failure
=> -1,
28255 Pragma_Preelaborable_Initialization
=> -1,
28256 Pragma_Preelaborate
=> 0,
28257 Pragma_Pre_Class
=> -1,
28258 Pragma_Priority
=> -1,
28259 Pragma_Priority_Specific_Dispatching
=> 0,
28260 Pragma_Profile
=> 0,
28261 Pragma_Profile_Warnings
=> 0,
28262 Pragma_Propagate_Exceptions
=> 0,
28263 Pragma_Provide_Shift_Operators
=> 0,
28264 Pragma_Psect_Object
=> 0,
28266 Pragma_Pure_Function
=> 0,
28267 Pragma_Queuing_Policy
=> 0,
28268 Pragma_Rational
=> 0,
28269 Pragma_Ravenscar
=> 0,
28270 Pragma_Refined_Depends
=> -1,
28271 Pragma_Refined_Global
=> -1,
28272 Pragma_Refined_Post
=> -1,
28273 Pragma_Refined_State
=> -1,
28274 Pragma_Relative_Deadline
=> 0,
28275 Pragma_Remote_Access_Type
=> -1,
28276 Pragma_Remote_Call_Interface
=> -1,
28277 Pragma_Remote_Types
=> -1,
28278 Pragma_Restricted_Run_Time
=> 0,
28279 Pragma_Restriction_Warnings
=> 0,
28280 Pragma_Restrictions
=> 0,
28281 Pragma_Reviewable
=> -1,
28282 Pragma_Short_Circuit_And_Or
=> 0,
28283 Pragma_Share_Generic
=> 0,
28284 Pragma_Shared
=> 0,
28285 Pragma_Shared_Passive
=> 0,
28286 Pragma_Short_Descriptors
=> 0,
28287 Pragma_Simple_Storage_Pool_Type
=> 0,
28288 Pragma_Source_File_Name
=> 0,
28289 Pragma_Source_File_Name_Project
=> 0,
28290 Pragma_Source_Reference
=> 0,
28291 Pragma_SPARK_Mode
=> 0,
28292 Pragma_Storage_Size
=> -1,
28293 Pragma_Storage_Unit
=> 0,
28294 Pragma_Static_Elaboration_Desired
=> 0,
28295 Pragma_Stream_Convert
=> 0,
28296 Pragma_Style_Checks
=> 0,
28297 Pragma_Subtitle
=> 0,
28298 Pragma_Suppress
=> 0,
28299 Pragma_Suppress_Exception_Locations
=> 0,
28300 Pragma_Suppress_All
=> 0,
28301 Pragma_Suppress_Debug_Info
=> 0,
28302 Pragma_Suppress_Initialization
=> 0,
28303 Pragma_System_Name
=> 0,
28304 Pragma_Task_Dispatching_Policy
=> 0,
28305 Pragma_Task_Info
=> -1,
28306 Pragma_Task_Name
=> -1,
28307 Pragma_Task_Storage
=> -1,
28308 Pragma_Test_Case
=> -1,
28309 Pragma_Thread_Local_Storage
=> -1,
28310 Pragma_Time_Slice
=> -1,
28312 Pragma_Type_Invariant
=> -1,
28313 Pragma_Type_Invariant_Class
=> -1,
28314 Pragma_Unchecked_Union
=> 0,
28315 Pragma_Unimplemented_Unit
=> 0,
28316 Pragma_Universal_Aliasing
=> 0,
28317 Pragma_Universal_Data
=> 0,
28318 Pragma_Unmodified
=> 0,
28319 Pragma_Unreferenced
=> 0,
28320 Pragma_Unreferenced_Objects
=> 0,
28321 Pragma_Unreserve_All_Interrupts
=> 0,
28322 Pragma_Unsuppress
=> 0,
28323 Pragma_Unevaluated_Use_Of_Old
=> 0,
28324 Pragma_Use_VADS_Size
=> 0,
28325 Pragma_Validity_Checks
=> 0,
28326 Pragma_Volatile
=> 0,
28327 Pragma_Volatile_Components
=> 0,
28328 Pragma_Volatile_Full_Access
=> 0,
28329 Pragma_Volatile_Function
=> 0,
28330 Pragma_Warning_As_Error
=> 0,
28331 Pragma_Warnings
=> 0,
28332 Pragma_Weak_External
=> 0,
28333 Pragma_Wide_Character_Encoding
=> 0,
28334 Unknown_Pragma
=> 0);
28336 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean is
28342 function Arg_No
return Nat
;
28343 -- Returns an integer showing what argument we are in. A value of
28344 -- zero means we are not in any of the arguments.
28350 function Arg_No
return Nat
is
28355 A
:= First
(Pragma_Argument_Associations
(Parent
(P
)));
28369 -- Start of processing for Non_Significant_Pragma_Reference
28374 if Nkind
(P
) /= N_Pragma_Argument_Association
then
28378 Id
:= Get_Pragma_Id
(Parent
(P
));
28379 C
:= Sig_Flags
(Id
);
28394 return AN
< (C
- 90);
28400 end Is_Non_Significant_Pragma_Reference
;
28402 ------------------------------
28403 -- Is_Pragma_String_Literal --
28404 ------------------------------
28406 -- This function returns true if the corresponding pragma argument is a
28407 -- static string expression. These are the only cases in which string
28408 -- literals can appear as pragma arguments. We also allow a string literal
28409 -- as the first argument to pragma Assert (although it will of course
28410 -- always generate a type error).
28412 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean is
28413 Pragn
: constant Node_Id
:= Parent
(Par
);
28414 Assoc
: constant List_Id
:= Pragma_Argument_Associations
(Pragn
);
28415 Pname
: constant Name_Id
:= Pragma_Name
(Pragn
);
28421 N
:= First
(Assoc
);
28428 if Pname
= Name_Assert
then
28431 elsif Pname
= Name_Export
then
28434 elsif Pname
= Name_Ident
then
28437 elsif Pname
= Name_Import
then
28440 elsif Pname
= Name_Interface_Name
then
28443 elsif Pname
= Name_Linker_Alias
then
28446 elsif Pname
= Name_Linker_Section
then
28449 elsif Pname
= Name_Machine_Attribute
then
28452 elsif Pname
= Name_Source_File_Name
then
28455 elsif Pname
= Name_Source_Reference
then
28458 elsif Pname
= Name_Title
then
28461 elsif Pname
= Name_Subtitle
then
28467 end Is_Pragma_String_Literal
;
28469 ---------------------------
28470 -- Is_Private_SPARK_Mode --
28471 ---------------------------
28473 function Is_Private_SPARK_Mode
(N
: Node_Id
) return Boolean is
28476 (Nkind
(N
) = N_Pragma
28477 and then Pragma_Name
(N
) = Name_SPARK_Mode
28478 and then Is_List_Member
(N
));
28480 -- For pragma SPARK_Mode to be private, it has to appear in the private
28481 -- declarations of a package.
28484 Present
(Parent
(N
))
28485 and then Nkind
(Parent
(N
)) = N_Package_Specification
28486 and then List_Containing
(N
) = Private_Declarations
(Parent
(N
));
28487 end Is_Private_SPARK_Mode
;
28489 -------------------------------------
28490 -- Is_Unconstrained_Or_Tagged_Item --
28491 -------------------------------------
28493 function Is_Unconstrained_Or_Tagged_Item
28494 (Item
: Entity_Id
) return Boolean
28496 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean;
28497 -- Determine whether record type Typ has at least one unconstrained
28500 ---------------------------------
28501 -- Has_Unconstrained_Component --
28502 ---------------------------------
28504 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean is
28508 Comp
:= First_Component
(Typ
);
28509 while Present
(Comp
) loop
28510 if Is_Unconstrained_Or_Tagged_Item
(Comp
) then
28514 Next_Component
(Comp
);
28518 end Has_Unconstrained_Component
;
28522 Typ
: constant Entity_Id
:= Etype
(Item
);
28524 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
28527 if Is_Tagged_Type
(Typ
) then
28530 elsif Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
28533 elsif Is_Record_Type
(Typ
) then
28534 if Has_Discriminants
(Typ
) and then not Is_Constrained
(Typ
) then
28537 return Has_Unconstrained_Component
(Typ
);
28540 elsif Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
) then
28546 end Is_Unconstrained_Or_Tagged_Item
;
28548 -----------------------------
28549 -- Is_Valid_Assertion_Kind --
28550 -----------------------------
28552 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean is
28559 Name_Static_Predicate |
28560 Name_Dynamic_Predicate |
28565 Name_Type_Invariant |
28566 Name_uType_Invariant |
28570 Name_Assert_And_Cut |
28572 Name_Contract_Cases |
28574 Name_Default_Initial_Condition |
28576 Name_Initial_Condition |
28579 Name_Loop_Invariant |
28580 Name_Loop_Variant |
28581 Name_Postcondition |
28582 Name_Precondition |
28584 Name_Refined_Post |
28585 Name_Statement_Assertions
=> return True;
28587 when others => return False;
28589 end Is_Valid_Assertion_Kind
;
28591 --------------------------------------
28592 -- Process_Compilation_Unit_Pragmas --
28593 --------------------------------------
28595 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
) is
28597 -- A special check for pragma Suppress_All, a very strange DEC pragma,
28598 -- strange because it comes at the end of the unit. Rational has the
28599 -- same name for a pragma, but treats it as a program unit pragma, In
28600 -- GNAT we just decide to allow it anywhere at all. If it appeared then
28601 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
28602 -- node, and we insert a pragma Suppress (All_Checks) at the start of
28603 -- the context clause to ensure the correct processing.
28605 if Has_Pragma_Suppress_All
(N
) then
28606 Prepend_To
(Context_Items
(N
),
28607 Make_Pragma
(Sloc
(N
),
28608 Chars
=> Name_Suppress
,
28609 Pragma_Argument_Associations
=> New_List
(
28610 Make_Pragma_Argument_Association
(Sloc
(N
),
28611 Expression
=> Make_Identifier
(Sloc
(N
), Name_All_Checks
)))));
28614 -- Nothing else to do at the current time
28616 end Process_Compilation_Unit_Pragmas
;
28618 ------------------------------------
28619 -- Record_Possible_Body_Reference --
28620 ------------------------------------
28622 procedure Record_Possible_Body_Reference
28623 (State_Id
: Entity_Id
;
28627 Spec_Id
: Entity_Id
;
28630 -- Ensure that we are dealing with a reference to a state
28632 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
28634 -- Climb the tree starting from the reference looking for a package body
28635 -- whose spec declares the referenced state. This criteria automatically
28636 -- excludes references in package specs which are legal. Note that it is
28637 -- not wise to emit an error now as the package body may lack pragma
28638 -- Refined_State or the referenced state may not be mentioned in the
28639 -- refinement. This approach avoids the generation of misleading errors.
28642 while Present
(Context
) loop
28643 if Nkind
(Context
) = N_Package_Body
then
28644 Spec_Id
:= Corresponding_Spec
(Context
);
28646 if Present
(Abstract_States
(Spec_Id
))
28647 and then Contains
(Abstract_States
(Spec_Id
), State_Id
)
28649 if No
(Body_References
(State_Id
)) then
28650 Set_Body_References
(State_Id
, New_Elmt_List
);
28653 Append_Elmt
(Ref
, To
=> Body_References
(State_Id
));
28658 Context
:= Parent
(Context
);
28660 end Record_Possible_Body_Reference
;
28662 ------------------------------------------
28663 -- Relocate_Pragmas_To_Anonymous_Object --
28664 ------------------------------------------
28666 procedure Relocate_Pragmas_To_Anonymous_Object
28667 (Typ_Decl
: Node_Id
;
28668 Obj_Decl
: Node_Id
)
28672 Next_Decl
: Node_Id
;
28675 if Nkind
(Typ_Decl
) = N_Protected_Type_Declaration
then
28676 Def
:= Protected_Definition
(Typ_Decl
);
28678 pragma Assert
(Nkind
(Typ_Decl
) = N_Task_Type_Declaration
);
28679 Def
:= Task_Definition
(Typ_Decl
);
28682 -- The concurrent definition has a visible declaration list. Inspect it
28683 -- and relocate all canidate pragmas.
28685 if Present
(Def
) and then Present
(Visible_Declarations
(Def
)) then
28686 Decl
:= First
(Visible_Declarations
(Def
));
28687 while Present
(Decl
) loop
28689 -- Preserve the following declaration for iteration purposes due
28690 -- to possible relocation of a pragma.
28692 Next_Decl
:= Next
(Decl
);
28694 if Nkind
(Decl
) = N_Pragma
28695 and then Pragma_On_Anonymous_Object_OK
(Get_Pragma_Id
(Decl
))
28698 Insert_After
(Obj_Decl
, Decl
);
28700 -- Skip internally generated code
28702 elsif not Comes_From_Source
(Decl
) then
28705 -- No candidate pragmas are available for relocation
28714 end Relocate_Pragmas_To_Anonymous_Object
;
28716 ------------------------------
28717 -- Relocate_Pragmas_To_Body --
28718 ------------------------------
28720 procedure Relocate_Pragmas_To_Body
28721 (Subp_Body
: Node_Id
;
28722 Target_Body
: Node_Id
:= Empty
)
28724 procedure Relocate_Pragma
(Prag
: Node_Id
);
28725 -- Remove a single pragma from its current list and add it to the
28726 -- declarations of the proper body (either Subp_Body or Target_Body).
28728 ---------------------
28729 -- Relocate_Pragma --
28730 ---------------------
28732 procedure Relocate_Pragma
(Prag
: Node_Id
) is
28737 -- When subprogram stubs or expression functions are involves, the
28738 -- destination declaration list belongs to the proper body.
28740 if Present
(Target_Body
) then
28741 Target
:= Target_Body
;
28743 Target
:= Subp_Body
;
28746 Decls
:= Declarations
(Target
);
28750 Set_Declarations
(Target
, Decls
);
28753 -- Unhook the pragma from its current list
28756 Prepend
(Prag
, Decls
);
28757 end Relocate_Pragma
;
28761 Body_Id
: constant Entity_Id
:=
28762 Defining_Unit_Name
(Specification
(Subp_Body
));
28763 Next_Stmt
: Node_Id
;
28766 -- Start of processing for Relocate_Pragmas_To_Body
28769 -- Do not process a body that comes from a separate unit as no construct
28770 -- can possibly follow it.
28772 if not Is_List_Member
(Subp_Body
) then
28775 -- Do not relocate pragmas that follow a stub if the stub does not have
28778 elsif Nkind
(Subp_Body
) = N_Subprogram_Body_Stub
28779 and then No
(Target_Body
)
28783 -- Do not process internally generated routine _Postconditions
28785 elsif Ekind
(Body_Id
) = E_Procedure
28786 and then Chars
(Body_Id
) = Name_uPostconditions
28791 -- Look at what is following the body. We are interested in certain kind
28792 -- of pragmas (either from source or byproducts of expansion) that can
28793 -- apply to a body [stub].
28795 Stmt
:= Next
(Subp_Body
);
28796 while Present
(Stmt
) loop
28798 -- Preserve the following statement for iteration purposes due to a
28799 -- possible relocation of a pragma.
28801 Next_Stmt
:= Next
(Stmt
);
28803 -- Move a candidate pragma following the body to the declarations of
28806 if Nkind
(Stmt
) = N_Pragma
28807 and then Pragma_On_Body_Or_Stub_OK
(Get_Pragma_Id
(Stmt
))
28809 Relocate_Pragma
(Stmt
);
28811 -- Skip internally generated code
28813 elsif not Comes_From_Source
(Stmt
) then
28816 -- No candidate pragmas are available for relocation
28824 end Relocate_Pragmas_To_Body
;
28826 -------------------
28827 -- Resolve_State --
28828 -------------------
28830 procedure Resolve_State
(N
: Node_Id
) is
28835 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
28836 Func
:= Entity
(N
);
28838 -- Handle overloading of state names by functions. Traverse the
28839 -- homonym chain looking for an abstract state.
28841 if Ekind
(Func
) = E_Function
and then Has_Homonym
(Func
) then
28842 State
:= Homonym
(Func
);
28843 while Present
(State
) loop
28845 -- Resolve the overloading by setting the proper entity of the
28846 -- reference to that of the state.
28848 if Ekind
(State
) = E_Abstract_State
then
28849 Set_Etype
(N
, Standard_Void_Type
);
28850 Set_Entity
(N
, State
);
28851 Set_Associated_Node
(N
, State
);
28855 State
:= Homonym
(State
);
28858 -- A function can never act as a state. If the homonym chain does
28859 -- not contain a corresponding state, then something went wrong in
28860 -- the overloading mechanism.
28862 raise Program_Error
;
28867 ----------------------------
28868 -- Rewrite_Assertion_Kind --
28869 ----------------------------
28871 procedure Rewrite_Assertion_Kind
(N
: Node_Id
) is
28875 if Nkind
(N
) = N_Attribute_Reference
28876 and then Attribute_Name
(N
) = Name_Class
28877 and then Nkind
(Prefix
(N
)) = N_Identifier
28879 case Chars
(Prefix
(N
)) is
28884 when Name_Type_Invariant
=>
28885 Nam
:= Name_uType_Invariant
;
28886 when Name_Invariant
=>
28887 Nam
:= Name_uInvariant
;
28892 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
=> Nam
));
28894 end Rewrite_Assertion_Kind
;
28902 Dummy
:= Dummy
+ 1;
28905 --------------------------------
28906 -- Set_Encoded_Interface_Name --
28907 --------------------------------
28909 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
) is
28910 Str
: constant String_Id
:= Strval
(S
);
28911 Len
: constant Nat
:= String_Length
(Str
);
28916 Hex
: constant array (0 .. 15) of Character := "0123456789abcdef";
28919 -- Stores encoded value of character code CC. The encoding we use an
28920 -- underscore followed by four lower case hex digits.
28926 procedure Encode
is
28928 Store_String_Char
(Get_Char_Code
('_'));
28930 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 12))));
28932 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 8 and 16#
0F#
))));
28934 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 4 and 16#
0F#
))));
28936 (Get_Char_Code
(Hex
(Integer (CC
and 16#
0F#
))));
28939 -- Start of processing for Set_Encoded_Interface_Name
28942 -- If first character is asterisk, this is a link name, and we leave it
28943 -- completely unmodified. We also ignore null strings (the latter case
28944 -- happens only in error cases) and no encoding should occur for AAMP
28945 -- interface names.
28948 or else Get_String_Char
(Str
, 1) = Get_Char_Code
('*')
28949 or else AAMP_On_Target
28951 Set_Interface_Name
(E
, S
);
28956 CC
:= Get_String_Char
(Str
, J
);
28958 exit when not In_Character_Range
(CC
);
28960 C
:= Get_Character
(CC
);
28962 exit when C
/= '_' and then C
/= '$'
28963 and then C
not in '0' .. '9'
28964 and then C
not in 'a' .. 'z'
28965 and then C
not in 'A' .. 'Z';
28968 Set_Interface_Name
(E
, S
);
28976 -- Here we need to encode. The encoding we use as follows:
28977 -- three underscores + four hex digits (lower case)
28981 for J
in 1 .. String_Length
(Str
) loop
28982 CC
:= Get_String_Char
(Str
, J
);
28984 if not In_Character_Range
(CC
) then
28987 C
:= Get_Character
(CC
);
28989 if C
= '_' or else C
= '$'
28990 or else C
in '0' .. '9'
28991 or else C
in 'a' .. 'z'
28992 or else C
in 'A' .. 'Z'
28994 Store_String_Char
(CC
);
29001 Set_Interface_Name
(E
,
29002 Make_String_Literal
(Sloc
(S
),
29003 Strval
=> End_String
));
29005 end Set_Encoded_Interface_Name
;
29007 ------------------------
29008 -- Set_Elab_Unit_Name --
29009 ------------------------
29011 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
) is
29016 if Nkind
(N
) = N_Identifier
29017 and then Nkind
(With_Item
) = N_Identifier
29019 Set_Entity
(N
, Entity
(With_Item
));
29021 elsif Nkind
(N
) = N_Selected_Component
then
29022 Change_Selected_Component_To_Expanded_Name
(N
);
29023 Set_Entity
(N
, Entity
(With_Item
));
29024 Set_Entity
(Selector_Name
(N
), Entity
(N
));
29026 Pref
:= Prefix
(N
);
29027 Scop
:= Scope
(Entity
(N
));
29028 while Nkind
(Pref
) = N_Selected_Component
loop
29029 Change_Selected_Component_To_Expanded_Name
(Pref
);
29030 Set_Entity
(Selector_Name
(Pref
), Scop
);
29031 Set_Entity
(Pref
, Scop
);
29032 Pref
:= Prefix
(Pref
);
29033 Scop
:= Scope
(Scop
);
29036 Set_Entity
(Pref
, Scop
);
29039 Generate_Reference
(Entity
(With_Item
), N
, Set_Ref
=> False);
29040 end Set_Elab_Unit_Name
;
29042 -------------------
29043 -- Test_Case_Arg --
29044 -------------------
29046 function Test_Case_Arg
29049 From_Aspect
: Boolean := False) return Node_Id
29051 Aspect
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
29056 pragma Assert
(Nam_In
(Arg_Nam
, Name_Ensures
,
29061 -- The caller requests the aspect argument
29063 if From_Aspect
then
29064 if Present
(Aspect
)
29065 and then Nkind
(Expression
(Aspect
)) = N_Aggregate
29067 Args
:= Expression
(Aspect
);
29069 -- "Name" and "Mode" may appear without an identifier as a
29070 -- positional association.
29072 if Present
(Expressions
(Args
)) then
29073 Arg
:= First
(Expressions
(Args
));
29075 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
29083 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
29088 -- Some or all arguments may appear as component associatons
29090 if Present
(Component_Associations
(Args
)) then
29091 Arg
:= First
(Component_Associations
(Args
));
29092 while Present
(Arg
) loop
29093 if Chars
(First
(Choices
(Arg
))) = Arg_Nam
then
29102 -- Otherwise retrieve the argument directly from the pragma
29105 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
29107 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
29111 -- Skip argument "Name"
29115 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
29119 -- Skip argument "Mode"
29123 -- Arguments "Requires" and "Ensures" are optional and may not be
29126 while Present
(Arg
) loop
29127 if Chars
(Arg
) = Arg_Nam
then