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
6470 procedure Set_Atomic_VFA
(E
: Entity_Id
);
6471 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6472 -- no explicit alignment was given, set alignment to unknown, since
6473 -- back end knows what the alignment requirements are for atomic and
6474 -- full access arrays. Note: this is necessary for derived types.
6476 --------------------
6477 -- Set_Atomic_VFA --
6478 --------------------
6480 procedure Set_Atomic_VFA
(E
: Entity_Id
) is
6482 if Prag_Id
= Pragma_Volatile_Full_Access
then
6483 Set_Is_Volatile_Full_Access
(E
);
6488 if not Has_Alignment_Clause
(E
) then
6489 Set_Alignment
(E
, Uint_0
);
6499 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6502 Check_Ada_83_Warning
;
6503 Check_No_Identifiers
;
6504 Check_Arg_Count
(1);
6505 Check_Arg_Is_Local_Name
(Arg1
);
6506 E_Arg
:= Get_Pragma_Arg
(Arg1
);
6508 if Etype
(E_Arg
) = Any_Type
then
6512 E
:= Entity
(E_Arg
);
6513 Decl
:= 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 Nkind
(Decl
) = N_Object_Declaration
6623 or else (Nkind
(Decl
) = 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)). Original_Node is necessary to account for
6678 -- untagged derived types that are rewritten as subtypes of their
6679 -- respective root types.
6682 and then Prag_Id
= Pragma_Volatile
6684 not Nkind_In
(Original_Node
(Decl
), N_Full_Type_Declaration
,
6685 N_Object_Declaration
)
6688 ("argument of pragma % must denote a full type or object "
6689 & "declaration", Arg1
);
6691 end Process_Atomic_Independent_Shared_Volatile
;
6693 -------------------------------------------
6694 -- Process_Compile_Time_Warning_Or_Error --
6695 -------------------------------------------
6697 procedure Process_Compile_Time_Warning_Or_Error
is
6698 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
6701 Check_Arg_Count
(2);
6702 Check_No_Identifiers
;
6703 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
6704 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
6706 if Compile_Time_Known_Value
(Arg1x
) then
6707 if Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
))) then
6709 Str
: constant String_Id
:=
6710 Strval
(Get_Pragma_Arg
(Arg2
));
6711 Len
: constant Nat
:= String_Length
(Str
);
6716 Cent
: constant Entity_Id
:=
6717 Cunit_Entity
(Current_Sem_Unit
);
6719 Force
: constant Boolean :=
6720 Prag_Id
= Pragma_Compile_Time_Warning
6722 Is_Spec_Name
(Unit_Name
(Current_Sem_Unit
))
6723 and then (Ekind
(Cent
) /= E_Package
6724 or else not In_Private_Part
(Cent
));
6725 -- Set True if this is the warning case, and we are in the
6726 -- visible part of a package spec, or in a subprogram spec,
6727 -- in which case we want to force the client to see the
6728 -- warning, even though it is not in the main unit.
6731 -- Loop through segments of message separated by line feeds.
6732 -- We output these segments as separate messages with
6733 -- continuation marks for all but the first.
6738 Error_Msg_Strlen
:= 0;
6740 -- Loop to copy characters from argument to error message
6744 exit when Ptr
> Len
;
6745 CC
:= Get_String_Char
(Str
, Ptr
);
6748 -- Ignore wide chars ??? else store character
6750 if In_Character_Range
(CC
) then
6751 C
:= Get_Character
(CC
);
6752 exit when C
= ASCII
.LF
;
6753 Error_Msg_Strlen
:= Error_Msg_Strlen
+ 1;
6754 Error_Msg_String
(Error_Msg_Strlen
) := C
;
6758 -- Here with one line ready to go
6760 Error_Msg_Warn
:= Prag_Id
= Pragma_Compile_Time_Warning
;
6762 -- If this is a warning in a spec, then we want clients
6763 -- to see the warning, so mark the message with the
6764 -- special sequence !! to force the warning. In the case
6765 -- of a package spec, we do not force this if we are in
6766 -- the private part of the spec.
6769 if Cont
= False then
6770 Error_Msg_N
("<<~!!", Arg1
);
6773 Error_Msg_N
("\<<~!!", Arg1
);
6776 -- Error, rather than warning, or in a body, so we do not
6777 -- need to force visibility for client (error will be
6778 -- output in any case, and this is the situation in which
6779 -- we do not want a client to get a warning, since the
6780 -- warning is in the body or the spec private part).
6783 if Cont
= False then
6784 Error_Msg_N
("<<~", Arg1
);
6787 Error_Msg_N
("\<<~", Arg1
);
6791 exit when Ptr
> Len
;
6796 end Process_Compile_Time_Warning_Or_Error
;
6798 ------------------------
6799 -- Process_Convention --
6800 ------------------------
6802 procedure Process_Convention
6803 (C
: out Convention_Id
;
6804 Ent
: out Entity_Id
)
6808 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
);
6809 -- Called if we have more than one Export/Import/Convention pragma.
6810 -- This is generally illegal, but we have a special case of allowing
6811 -- Import and Interface to coexist if they specify the convention in
6812 -- a consistent manner. We are allowed to do this, since Interface is
6813 -- an implementation defined pragma, and we choose to do it since we
6814 -- know Rational allows this combination. S is the entity id of the
6815 -- subprogram in question. This procedure also sets the special flag
6816 -- Import_Interface_Present in both pragmas in the case where we do
6817 -- have matching Import and Interface pragmas.
6819 procedure Set_Convention_From_Pragma
(E
: Entity_Id
);
6820 -- Set convention in entity E, and also flag that the entity has a
6821 -- convention pragma. If entity is for a private or incomplete type,
6822 -- also set convention and flag on underlying type. This procedure
6823 -- also deals with the special case of C_Pass_By_Copy convention,
6824 -- and error checks for inappropriate convention specification.
6826 -------------------------------
6827 -- Diagnose_Multiple_Pragmas --
6828 -------------------------------
6830 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
) is
6831 Pdec
: constant Node_Id
:= Declaration_Node
(S
);
6835 function Same_Convention
(Decl
: Node_Id
) return Boolean;
6836 -- Decl is a pragma node. This function returns True if this
6837 -- pragma has a first argument that is an identifier with a
6838 -- Chars field corresponding to the Convention_Id C.
6840 function Same_Name
(Decl
: Node_Id
) return Boolean;
6841 -- Decl is a pragma node. This function returns True if this
6842 -- pragma has a second argument that is an identifier with a
6843 -- Chars field that matches the Chars of the current subprogram.
6845 ---------------------
6846 -- Same_Convention --
6847 ---------------------
6849 function Same_Convention
(Decl
: Node_Id
) return Boolean is
6850 Arg1
: constant Node_Id
:=
6851 First
(Pragma_Argument_Associations
(Decl
));
6854 if Present
(Arg1
) then
6856 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
6858 if Nkind
(Arg
) = N_Identifier
6859 and then Is_Convention_Name
(Chars
(Arg
))
6860 and then Get_Convention_Id
(Chars
(Arg
)) = C
6868 end Same_Convention
;
6874 function Same_Name
(Decl
: Node_Id
) return Boolean is
6875 Arg1
: constant Node_Id
:=
6876 First
(Pragma_Argument_Associations
(Decl
));
6884 Arg2
:= Next
(Arg1
);
6891 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
6893 if Nkind
(Arg
) = N_Identifier
6894 and then Chars
(Arg
) = Chars
(S
)
6903 -- Start of processing for Diagnose_Multiple_Pragmas
6908 -- Definitely give message if we have Convention/Export here
6910 if Prag_Id
= Pragma_Convention
or else Prag_Id
= Pragma_Export
then
6913 -- If we have an Import or Export, scan back from pragma to
6914 -- find any previous pragma applying to the same procedure.
6915 -- The scan will be terminated by the start of the list, or
6916 -- hitting the subprogram declaration. This won't allow one
6917 -- pragma to appear in the public part and one in the private
6918 -- part, but that seems very unlikely in practice.
6922 while Present
(Decl
) and then Decl
/= Pdec
loop
6924 -- Look for pragma with same name as us
6926 if Nkind
(Decl
) = N_Pragma
6927 and then Same_Name
(Decl
)
6929 -- Give error if same as our pragma or Export/Convention
6931 if Nam_In
(Pragma_Name
(Decl
), Name_Export
,
6937 -- Case of Import/Interface or the other way round
6939 elsif Nam_In
(Pragma_Name
(Decl
), Name_Interface
,
6942 -- Here we know that we have Import and Interface. It
6943 -- doesn't matter which way round they are. See if
6944 -- they specify the same convention. If so, all OK,
6945 -- and set special flags to stop other messages
6947 if Same_Convention
(Decl
) then
6948 Set_Import_Interface_Present
(N
);
6949 Set_Import_Interface_Present
(Decl
);
6952 -- If different conventions, special message
6955 Error_Msg_Sloc
:= Sloc
(Decl
);
6957 ("convention differs from that given#", Arg1
);
6967 -- Give message if needed if we fall through those tests
6968 -- except on Relaxed_RM_Semantics where we let go: either this
6969 -- is a case accepted/ignored by other Ada compilers (e.g.
6970 -- a mix of Convention and Import), or another error will be
6971 -- generated later (e.g. using both Import and Export).
6973 if Err
and not Relaxed_RM_Semantics
then
6975 ("at most one Convention/Export/Import pragma is allowed",
6978 end Diagnose_Multiple_Pragmas
;
6980 --------------------------------
6981 -- Set_Convention_From_Pragma --
6982 --------------------------------
6984 procedure Set_Convention_From_Pragma
(E
: Entity_Id
) is
6986 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6987 -- for an overridden dispatching operation. Technically this is
6988 -- an amendment and should only be done in Ada 2005 mode. However,
6989 -- this is clearly a mistake, since the problem that is addressed
6990 -- by this AI is that there is a clear gap in the RM.
6992 if Is_Dispatching_Operation
(E
)
6993 and then Present
(Overridden_Operation
(E
))
6994 and then C
/= Convention
(Overridden_Operation
(E
))
6997 ("cannot change convention for overridden dispatching "
6998 & "operation", Arg1
);
7001 -- Special checks for Convention_Stdcall
7003 if C
= Convention_Stdcall
then
7005 -- A dispatching call is not allowed. A dispatching subprogram
7006 -- cannot be used to interface to the Win32 API, so in fact
7007 -- this check does not impose any effective restriction.
7009 if Is_Dispatching_Operation
(E
) then
7010 Error_Msg_Sloc
:= Sloc
(E
);
7012 -- Note: make this unconditional so that if there is more
7013 -- than one call to which the pragma applies, we get a
7014 -- message for each call. Also don't use Error_Pragma,
7015 -- so that we get multiple messages.
7018 ("dispatching subprogram# cannot use Stdcall convention!",
7021 -- Subprograms are not allowed
7023 elsif not Is_Subprogram_Or_Generic_Subprogram
(E
)
7027 and then Ekind
(E
) /= E_Variable
7029 -- An access to subprogram is also allowed
7033 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
)
7035 -- Allow internal call to set convention of subprogram type
7037 and then not (Ekind
(E
) = E_Subprogram_Type
)
7040 ("second argument of pragma% must be subprogram (type)",
7045 -- Set the convention
7047 Set_Convention
(E
, C
);
7048 Set_Has_Convention_Pragma
(E
);
7050 -- For the case of a record base type, also set the convention of
7051 -- any anonymous access types declared in the record which do not
7052 -- currently have a specified convention.
7054 if Is_Record_Type
(E
) and then Is_Base_Type
(E
) then
7059 Comp
:= First_Component
(E
);
7060 while Present
(Comp
) loop
7061 if Present
(Etype
(Comp
))
7062 and then Ekind_In
(Etype
(Comp
),
7063 E_Anonymous_Access_Type
,
7064 E_Anonymous_Access_Subprogram_Type
)
7065 and then not Has_Convention_Pragma
(Comp
)
7067 Set_Convention
(Comp
, C
);
7070 Next_Component
(Comp
);
7075 -- Deal with incomplete/private type case, where underlying type
7076 -- is available, so set convention of that underlying type.
7078 if Is_Incomplete_Or_Private_Type
(E
)
7079 and then Present
(Underlying_Type
(E
))
7081 Set_Convention
(Underlying_Type
(E
), C
);
7082 Set_Has_Convention_Pragma
(Underlying_Type
(E
), True);
7085 -- A class-wide type should inherit the convention of the specific
7086 -- root type (although this isn't specified clearly by the RM).
7088 if Is_Type
(E
) and then Present
(Class_Wide_Type
(E
)) then
7089 Set_Convention
(Class_Wide_Type
(E
), C
);
7092 -- If the entity is a record type, then check for special case of
7093 -- C_Pass_By_Copy, which is treated the same as C except that the
7094 -- special record flag is set. This convention is only permitted
7095 -- on record types (see AI95-00131).
7097 if Cname
= Name_C_Pass_By_Copy
then
7098 if Is_Record_Type
(E
) then
7099 Set_C_Pass_By_Copy
(Base_Type
(E
));
7100 elsif Is_Incomplete_Or_Private_Type
(E
)
7101 and then Is_Record_Type
(Underlying_Type
(E
))
7103 Set_C_Pass_By_Copy
(Base_Type
(Underlying_Type
(E
)));
7106 ("C_Pass_By_Copy convention allowed only for record type",
7111 -- If the entity is a derived boolean type, check for the special
7112 -- case of convention C, C++, or Fortran, where we consider any
7113 -- nonzero value to represent true.
7115 if Is_Discrete_Type
(E
)
7116 and then Root_Type
(Etype
(E
)) = Standard_Boolean
7122 C
= Convention_Fortran
)
7124 Set_Nonzero_Is_True
(Base_Type
(E
));
7126 end Set_Convention_From_Pragma
;
7130 Comp_Unit
: Unit_Number_Type
;
7135 -- Start of processing for Process_Convention
7138 Check_At_Least_N_Arguments
(2);
7139 Check_Optional_Identifier
(Arg1
, Name_Convention
);
7140 Check_Arg_Is_Identifier
(Arg1
);
7141 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
7143 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
7144 -- tested again below to set the critical flag).
7146 if Cname
= Name_C_Pass_By_Copy
then
7149 -- Otherwise we must have something in the standard convention list
7151 elsif Is_Convention_Name
(Cname
) then
7152 C
:= Get_Convention_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
7154 -- Otherwise warn on unrecognized convention
7157 if Warn_On_Export_Import
then
7159 ("??unrecognized convention name, C assumed",
7160 Get_Pragma_Arg
(Arg1
));
7166 Check_Optional_Identifier
(Arg2
, Name_Entity
);
7167 Check_Arg_Is_Local_Name
(Arg2
);
7169 Id
:= Get_Pragma_Arg
(Arg2
);
7172 if not Is_Entity_Name
(Id
) then
7173 Error_Pragma_Arg
("entity name required", Arg2
);
7178 -- Set entity to return
7182 -- Ada_Pass_By_Copy special checking
7184 if C
= Convention_Ada_Pass_By_Copy
then
7185 if not Is_First_Subtype
(E
) then
7187 ("convention `Ada_Pass_By_Copy` only allowed for types",
7191 if Is_By_Reference_Type
(E
) then
7193 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7197 -- Ada_Pass_By_Reference special checking
7199 elsif C
= Convention_Ada_Pass_By_Reference
then
7200 if not Is_First_Subtype
(E
) then
7202 ("convention `Ada_Pass_By_Reference` only allowed for types",
7206 if Is_By_Copy_Type
(E
) then
7208 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7213 -- Go to renamed subprogram if present, since convention applies to
7214 -- the actual renamed entity, not to the renaming entity. If the
7215 -- subprogram is inherited, go to parent subprogram.
7217 if Is_Subprogram
(E
)
7218 and then Present
(Alias
(E
))
7220 if Nkind
(Parent
(Declaration_Node
(E
))) =
7221 N_Subprogram_Renaming_Declaration
7223 if Scope
(E
) /= Scope
(Alias
(E
)) then
7225 ("cannot apply pragma% to non-local entity&#", E
);
7230 elsif Nkind_In
(Parent
(E
), N_Full_Type_Declaration
,
7231 N_Private_Extension_Declaration
)
7232 and then Scope
(E
) = Scope
(Alias
(E
))
7236 -- Return the parent subprogram the entity was inherited from
7242 -- Check that we are not applying this to a specless body. Relax this
7243 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
7245 if Is_Subprogram
(E
)
7246 and then Nkind
(Parent
(Declaration_Node
(E
))) = N_Subprogram_Body
7247 and then not Relaxed_RM_Semantics
7250 ("pragma% requires separate spec and must come before body");
7253 -- Check that we are not applying this to a named constant
7255 if Ekind_In
(E
, E_Named_Integer
, E_Named_Real
) then
7256 Error_Msg_Name_1
:= Pname
;
7258 ("cannot apply pragma% to named constant!",
7259 Get_Pragma_Arg
(Arg2
));
7261 ("\supply appropriate type for&!", Arg2
);
7264 if Ekind
(E
) = E_Enumeration_Literal
then
7265 Error_Pragma
("enumeration literal not allowed for pragma%");
7268 -- Check for rep item appearing too early or too late
7270 if Etype
(E
) = Any_Type
7271 or else Rep_Item_Too_Early
(E
, N
)
7275 elsif Present
(Underlying_Type
(E
)) then
7276 E
:= Underlying_Type
(E
);
7279 if Rep_Item_Too_Late
(E
, N
) then
7283 if Has_Convention_Pragma
(E
) then
7284 Diagnose_Multiple_Pragmas
(E
);
7286 elsif Convention
(E
) = Convention_Protected
7287 or else Ekind
(Scope
(E
)) = E_Protected_Type
7290 ("a protected operation cannot be given a different convention",
7294 -- For Intrinsic, a subprogram is required
7296 if C
= Convention_Intrinsic
7297 and then not Is_Subprogram_Or_Generic_Subprogram
(E
)
7299 -- Accept Intrinsic Export on types if Relaxed_RM_Semantics
7301 if not (Is_Type
(E
) and then Relaxed_RM_Semantics
) then
7303 ("second argument of pragma% must be a subprogram", Arg2
);
7307 -- Deal with non-subprogram cases
7309 if not Is_Subprogram_Or_Generic_Subprogram
(E
) then
7310 Set_Convention_From_Pragma
(E
);
7314 -- The pragma must apply to a first subtype, but it can also
7315 -- apply to a generic type in a generic formal part, in which
7316 -- case it will also appear in the corresponding instance.
7318 if Is_Generic_Type
(E
) or else In_Instance
then
7321 Check_First_Subtype
(Arg2
);
7324 Set_Convention_From_Pragma
(Base_Type
(E
));
7326 -- For access subprograms, we must set the convention on the
7327 -- internally generated directly designated type as well.
7329 if Ekind
(E
) = E_Access_Subprogram_Type
then
7330 Set_Convention_From_Pragma
(Directly_Designated_Type
(E
));
7334 -- For the subprogram case, set proper convention for all homonyms
7335 -- in same scope and the same declarative part, i.e. the same
7336 -- compilation unit.
7339 Comp_Unit
:= Get_Source_Unit
(E
);
7340 Set_Convention_From_Pragma
(E
);
7342 -- Treat a pragma Import as an implicit body, and pragma import
7343 -- as implicit reference (for navigation in GPS).
7345 if Prag_Id
= Pragma_Import
then
7346 Generate_Reference
(E
, Id
, 'b');
7348 -- For exported entities we restrict the generation of references
7349 -- to entities exported to foreign languages since entities
7350 -- exported to Ada do not provide further information to GPS and
7351 -- add undesired references to the output of the gnatxref tool.
7353 elsif Prag_Id
= Pragma_Export
7354 and then Convention
(E
) /= Convention_Ada
7356 Generate_Reference
(E
, Id
, 'i');
7359 -- If the pragma comes from an aspect, it only applies to the
7360 -- given entity, not its homonyms.
7362 if From_Aspect_Specification
(N
) then
7366 -- Otherwise Loop through the homonyms of the pragma argument's
7367 -- entity, an apply convention to those in the current scope.
7373 exit when No
(E1
) or else Scope
(E1
) /= Current_Scope
;
7375 -- Ignore entry for which convention is already set
7377 if Has_Convention_Pragma
(E1
) then
7381 -- Do not set the pragma on inherited operations or on formal
7384 if Comes_From_Source
(E1
)
7385 and then Comp_Unit
= Get_Source_Unit
(E1
)
7386 and then not Is_Formal_Subprogram
(E1
)
7387 and then Nkind
(Original_Node
(Parent
(E1
))) /=
7388 N_Full_Type_Declaration
7390 if Present
(Alias
(E1
))
7391 and then Scope
(E1
) /= Scope
(Alias
(E1
))
7394 ("cannot apply pragma% to non-local entity& declared#",
7398 Set_Convention_From_Pragma
(E1
);
7400 if Prag_Id
= Pragma_Import
then
7401 Generate_Reference
(E1
, Id
, 'b');
7409 end Process_Convention
;
7411 ----------------------------------------
7412 -- Process_Disable_Enable_Atomic_Sync --
7413 ----------------------------------------
7415 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
) is
7417 Check_No_Identifiers
;
7418 Check_At_Most_N_Arguments
(1);
7420 -- Modeled internally as
7421 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7425 Pragma_Identifier
=>
7426 Make_Identifier
(Loc
, Nam
),
7427 Pragma_Argument_Associations
=> New_List
(
7428 Make_Pragma_Argument_Association
(Loc
,
7430 Make_Identifier
(Loc
, Name_Atomic_Synchronization
)))));
7432 if Present
(Arg1
) then
7433 Append_To
(Pragma_Argument_Associations
(N
), New_Copy
(Arg1
));
7437 end Process_Disable_Enable_Atomic_Sync
;
7439 -------------------------------------------------
7440 -- Process_Extended_Import_Export_Internal_Arg --
7441 -------------------------------------------------
7443 procedure Process_Extended_Import_Export_Internal_Arg
7444 (Arg_Internal
: Node_Id
:= Empty
)
7447 if No
(Arg_Internal
) then
7448 Error_Pragma
("Internal parameter required for pragma%");
7451 if Nkind
(Arg_Internal
) = N_Identifier
then
7454 elsif Nkind
(Arg_Internal
) = N_Operator_Symbol
7455 and then (Prag_Id
= Pragma_Import_Function
7457 Prag_Id
= Pragma_Export_Function
)
7463 ("wrong form for Internal parameter for pragma%", Arg_Internal
);
7466 Check_Arg_Is_Local_Name
(Arg_Internal
);
7467 end Process_Extended_Import_Export_Internal_Arg
;
7469 --------------------------------------------------
7470 -- Process_Extended_Import_Export_Object_Pragma --
7471 --------------------------------------------------
7473 procedure Process_Extended_Import_Export_Object_Pragma
7474 (Arg_Internal
: Node_Id
;
7475 Arg_External
: Node_Id
;
7481 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
7482 Def_Id
:= Entity
(Arg_Internal
);
7484 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
7486 ("pragma% must designate an object", Arg_Internal
);
7489 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
7491 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
7494 ("previous Common/Psect_Object applies, pragma % not permitted",
7498 if Rep_Item_Too_Late
(Def_Id
, N
) then
7502 Set_Extended_Import_Export_External_Name
(Def_Id
, Arg_External
);
7504 if Present
(Arg_Size
) then
7505 Check_Arg_Is_External_Name
(Arg_Size
);
7508 -- Export_Object case
7510 if Prag_Id
= Pragma_Export_Object
then
7511 if not Is_Library_Level_Entity
(Def_Id
) then
7513 ("argument for pragma% must be library level entity",
7517 if Ekind
(Current_Scope
) = E_Generic_Package
then
7518 Error_Pragma
("pragma& cannot appear in a generic unit");
7521 if not Size_Known_At_Compile_Time
(Etype
(Def_Id
)) then
7523 ("exported object must have compile time known size",
7527 if Warn_On_Export_Import
and then Is_Exported
(Def_Id
) then
7528 Error_Msg_N
("??duplicate Export_Object pragma", N
);
7530 Set_Exported
(Def_Id
, Arg_Internal
);
7533 -- Import_Object case
7536 if Is_Concurrent_Type
(Etype
(Def_Id
)) then
7538 ("cannot use pragma% for task/protected object",
7542 if Ekind
(Def_Id
) = E_Constant
then
7544 ("cannot import a constant", Arg_Internal
);
7547 if Warn_On_Export_Import
7548 and then Has_Discriminants
(Etype
(Def_Id
))
7551 ("imported value must be initialized??", Arg_Internal
);
7554 if Warn_On_Export_Import
7555 and then Is_Access_Type
(Etype
(Def_Id
))
7558 ("cannot import object of an access type??", Arg_Internal
);
7561 if Warn_On_Export_Import
7562 and then Is_Imported
(Def_Id
)
7564 Error_Msg_N
("??duplicate Import_Object pragma", N
);
7566 -- Check for explicit initialization present. Note that an
7567 -- initialization generated by the code generator, e.g. for an
7568 -- access type, does not count here.
7570 elsif Present
(Expression
(Parent
(Def_Id
)))
7573 (Original_Node
(Expression
(Parent
(Def_Id
))))
7575 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7577 ("imported entities cannot be initialized (RM B.1(24))",
7578 "\no initialization allowed for & declared#", Arg1
);
7580 Set_Imported
(Def_Id
);
7581 Note_Possible_Modification
(Arg_Internal
, Sure
=> False);
7584 end Process_Extended_Import_Export_Object_Pragma
;
7586 ------------------------------------------------------
7587 -- Process_Extended_Import_Export_Subprogram_Pragma --
7588 ------------------------------------------------------
7590 procedure Process_Extended_Import_Export_Subprogram_Pragma
7591 (Arg_Internal
: Node_Id
;
7592 Arg_External
: Node_Id
;
7593 Arg_Parameter_Types
: Node_Id
;
7594 Arg_Result_Type
: Node_Id
:= Empty
;
7595 Arg_Mechanism
: Node_Id
;
7596 Arg_Result_Mechanism
: Node_Id
:= Empty
)
7602 Ambiguous
: Boolean;
7605 function Same_Base_Type
7607 Formal
: Entity_Id
) return Boolean;
7608 -- Determines if Ptype references the type of Formal. Note that only
7609 -- the base types need to match according to the spec. Ptype here is
7610 -- the argument from the pragma, which is either a type name, or an
7611 -- access attribute.
7613 --------------------
7614 -- Same_Base_Type --
7615 --------------------
7617 function Same_Base_Type
7619 Formal
: Entity_Id
) return Boolean
7621 Ftyp
: constant Entity_Id
:= Base_Type
(Etype
(Formal
));
7625 -- Case where pragma argument is typ'Access
7627 if Nkind
(Ptype
) = N_Attribute_Reference
7628 and then Attribute_Name
(Ptype
) = Name_Access
7630 Pref
:= Prefix
(Ptype
);
7633 if not Is_Entity_Name
(Pref
)
7634 or else Entity
(Pref
) = Any_Type
7639 -- We have a match if the corresponding argument is of an
7640 -- anonymous access type, and its designated type matches the
7641 -- type of the prefix of the access attribute
7643 return Ekind
(Ftyp
) = E_Anonymous_Access_Type
7644 and then Base_Type
(Entity
(Pref
)) =
7645 Base_Type
(Etype
(Designated_Type
(Ftyp
)));
7647 -- Case where pragma argument is a type name
7652 if not Is_Entity_Name
(Ptype
)
7653 or else Entity
(Ptype
) = Any_Type
7658 -- We have a match if the corresponding argument is of the type
7659 -- given in the pragma (comparing base types)
7661 return Base_Type
(Entity
(Ptype
)) = Ftyp
;
7665 -- Start of processing for
7666 -- Process_Extended_Import_Export_Subprogram_Pragma
7669 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
7673 -- Loop through homonyms (overloadings) of the entity
7675 Hom_Id
:= Entity
(Arg_Internal
);
7676 while Present
(Hom_Id
) loop
7677 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
7679 -- We need a subprogram in the current scope
7681 if not Is_Subprogram
(Def_Id
)
7682 or else Scope
(Def_Id
) /= Current_Scope
7689 -- Pragma cannot apply to subprogram body
7691 if Is_Subprogram
(Def_Id
)
7692 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
7696 ("pragma% requires separate spec"
7697 & " and must come before body");
7700 -- Test result type if given, note that the result type
7701 -- parameter can only be present for the function cases.
7703 if Present
(Arg_Result_Type
)
7704 and then not Same_Base_Type
(Arg_Result_Type
, Def_Id
)
7708 elsif Etype
(Def_Id
) /= Standard_Void_Type
7710 Nam_In
(Pname
, Name_Export_Procedure
, Name_Import_Procedure
)
7714 -- Test parameter types if given. Note that this parameter
7715 -- has not been analyzed (and must not be, since it is
7716 -- semantic nonsense), so we get it as the parser left it.
7718 elsif Present
(Arg_Parameter_Types
) then
7719 Check_Matching_Types
: declare
7724 Formal
:= First_Formal
(Def_Id
);
7726 if Nkind
(Arg_Parameter_Types
) = N_Null
then
7727 if Present
(Formal
) then
7731 -- A list of one type, e.g. (List) is parsed as
7732 -- a parenthesized expression.
7734 elsif Nkind
(Arg_Parameter_Types
) /= N_Aggregate
7735 and then Paren_Count
(Arg_Parameter_Types
) = 1
7738 or else Present
(Next_Formal
(Formal
))
7743 Same_Base_Type
(Arg_Parameter_Types
, Formal
);
7746 -- A list of more than one type is parsed as a aggregate
7748 elsif Nkind
(Arg_Parameter_Types
) = N_Aggregate
7749 and then Paren_Count
(Arg_Parameter_Types
) = 0
7751 Ptype
:= First
(Expressions
(Arg_Parameter_Types
));
7752 while Present
(Ptype
) or else Present
(Formal
) loop
7755 or else not Same_Base_Type
(Ptype
, Formal
)
7760 Next_Formal
(Formal
);
7765 -- Anything else is of the wrong form
7769 ("wrong form for Parameter_Types parameter",
7770 Arg_Parameter_Types
);
7772 end Check_Matching_Types
;
7775 -- Match is now False if the entry we found did not match
7776 -- either a supplied Parameter_Types or Result_Types argument
7782 -- Ambiguous case, the flag Ambiguous shows if we already
7783 -- detected this and output the initial messages.
7786 if not Ambiguous
then
7788 Error_Msg_Name_1
:= Pname
;
7790 ("pragma% does not uniquely identify subprogram!",
7792 Error_Msg_Sloc
:= Sloc
(Ent
);
7793 Error_Msg_N
("matching subprogram #!", N
);
7797 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7798 Error_Msg_N
("matching subprogram #!", N
);
7803 Hom_Id
:= Homonym
(Hom_Id
);
7806 -- See if we found an entry
7809 if not Ambiguous
then
7810 if Is_Generic_Subprogram
(Entity
(Arg_Internal
)) then
7812 ("pragma% cannot be given for generic subprogram");
7815 ("pragma% does not identify local subprogram");
7822 -- Import pragmas must be for imported entities
7824 if Prag_Id
= Pragma_Import_Function
7826 Prag_Id
= Pragma_Import_Procedure
7828 Prag_Id
= Pragma_Import_Valued_Procedure
7830 if not Is_Imported
(Ent
) then
7832 ("pragma Import or Interface must precede pragma%");
7835 -- Here we have the Export case which can set the entity as exported
7837 -- But does not do so if the specified external name is null, since
7838 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7839 -- compatible) to request no external name.
7841 elsif Nkind
(Arg_External
) = N_String_Literal
7842 and then String_Length
(Strval
(Arg_External
)) = 0
7846 -- In all other cases, set entity as exported
7849 Set_Exported
(Ent
, Arg_Internal
);
7852 -- Special processing for Valued_Procedure cases
7854 if Prag_Id
= Pragma_Import_Valued_Procedure
7856 Prag_Id
= Pragma_Export_Valued_Procedure
7858 Formal
:= First_Formal
(Ent
);
7861 Error_Pragma
("at least one parameter required for pragma%");
7863 elsif Ekind
(Formal
) /= E_Out_Parameter
then
7864 Error_Pragma
("first parameter must have mode out for pragma%");
7867 Set_Is_Valued_Procedure
(Ent
);
7871 Set_Extended_Import_Export_External_Name
(Ent
, Arg_External
);
7873 -- Process Result_Mechanism argument if present. We have already
7874 -- checked that this is only allowed for the function case.
7876 if Present
(Arg_Result_Mechanism
) then
7877 Set_Mechanism_Value
(Ent
, Arg_Result_Mechanism
);
7880 -- Process Mechanism parameter if present. Note that this parameter
7881 -- is not analyzed, and must not be analyzed since it is semantic
7882 -- nonsense, so we get it in exactly as the parser left it.
7884 if Present
(Arg_Mechanism
) then
7892 -- A single mechanism association without a formal parameter
7893 -- name is parsed as a parenthesized expression. All other
7894 -- cases are parsed as aggregates, so we rewrite the single
7895 -- parameter case as an aggregate for consistency.
7897 if Nkind
(Arg_Mechanism
) /= N_Aggregate
7898 and then Paren_Count
(Arg_Mechanism
) = 1
7900 Rewrite
(Arg_Mechanism
,
7901 Make_Aggregate
(Sloc
(Arg_Mechanism
),
7902 Expressions
=> New_List
(
7903 Relocate_Node
(Arg_Mechanism
))));
7906 -- Case of only mechanism name given, applies to all formals
7908 if Nkind
(Arg_Mechanism
) /= N_Aggregate
then
7909 Formal
:= First_Formal
(Ent
);
7910 while Present
(Formal
) loop
7911 Set_Mechanism_Value
(Formal
, Arg_Mechanism
);
7912 Next_Formal
(Formal
);
7915 -- Case of list of mechanism associations given
7918 if Null_Record_Present
(Arg_Mechanism
) then
7920 ("inappropriate form for Mechanism parameter",
7924 -- Deal with positional ones first
7926 Formal
:= First_Formal
(Ent
);
7928 if Present
(Expressions
(Arg_Mechanism
)) then
7929 Mname
:= First
(Expressions
(Arg_Mechanism
));
7930 while Present
(Mname
) loop
7933 ("too many mechanism associations", Mname
);
7936 Set_Mechanism_Value
(Formal
, Mname
);
7937 Next_Formal
(Formal
);
7942 -- Deal with named entries
7944 if Present
(Component_Associations
(Arg_Mechanism
)) then
7945 Massoc
:= First
(Component_Associations
(Arg_Mechanism
));
7946 while Present
(Massoc
) loop
7947 Choice
:= First
(Choices
(Massoc
));
7949 if Nkind
(Choice
) /= N_Identifier
7950 or else Present
(Next
(Choice
))
7953 ("incorrect form for mechanism association",
7957 Formal
:= First_Formal
(Ent
);
7961 ("parameter name & not present", Choice
);
7964 if Chars
(Choice
) = Chars
(Formal
) then
7966 (Formal
, Expression
(Massoc
));
7968 -- Set entity on identifier (needed by ASIS)
7970 Set_Entity
(Choice
, Formal
);
7975 Next_Formal
(Formal
);
7984 end Process_Extended_Import_Export_Subprogram_Pragma
;
7986 --------------------------
7987 -- Process_Generic_List --
7988 --------------------------
7990 procedure Process_Generic_List
is
7995 Check_No_Identifiers
;
7996 Check_At_Least_N_Arguments
(1);
7998 -- Check all arguments are names of generic units or instances
8001 while Present
(Arg
) loop
8002 Exp
:= Get_Pragma_Arg
(Arg
);
8005 if not Is_Entity_Name
(Exp
)
8007 (not Is_Generic_Instance
(Entity
(Exp
))
8009 not Is_Generic_Unit
(Entity
(Exp
)))
8012 ("pragma% argument must be name of generic unit/instance",
8018 end Process_Generic_List
;
8020 ------------------------------------
8021 -- Process_Import_Predefined_Type --
8022 ------------------------------------
8024 procedure Process_Import_Predefined_Type
is
8025 Loc
: constant Source_Ptr
:= Sloc
(N
);
8027 Ftyp
: Node_Id
:= Empty
;
8033 String_To_Name_Buffer
(Strval
(Expression
(Arg3
)));
8036 Elmt
:= First_Elmt
(Predefined_Float_Types
);
8037 while Present
(Elmt
) and then Chars
(Node
(Elmt
)) /= Nam
loop
8041 Ftyp
:= Node
(Elmt
);
8043 if Present
(Ftyp
) then
8045 -- Don't build a derived type declaration, because predefined C
8046 -- types have no declaration anywhere, so cannot really be named.
8047 -- Instead build a full type declaration, starting with an
8048 -- appropriate type definition is built
8050 if Is_Floating_Point_Type
(Ftyp
) then
8051 Def
:= Make_Floating_Point_Definition
(Loc
,
8052 Make_Integer_Literal
(Loc
, Digits_Value
(Ftyp
)),
8053 Make_Real_Range_Specification
(Loc
,
8054 Make_Real_Literal
(Loc
, Realval
(Type_Low_Bound
(Ftyp
))),
8055 Make_Real_Literal
(Loc
, Realval
(Type_High_Bound
(Ftyp
)))));
8057 -- Should never have a predefined type we cannot handle
8060 raise Program_Error
;
8063 -- Build and insert a Full_Type_Declaration, which will be
8064 -- analyzed as soon as this list entry has been analyzed.
8066 Decl
:= Make_Full_Type_Declaration
(Loc
,
8067 Make_Defining_Identifier
(Loc
, Chars
(Expression
(Arg2
))),
8068 Type_Definition
=> Def
);
8070 Insert_After
(N
, Decl
);
8071 Mark_Rewrite_Insertion
(Decl
);
8074 Error_Pragma_Arg
("no matching type found for pragma%",
8077 end Process_Import_Predefined_Type
;
8079 ---------------------------------
8080 -- Process_Import_Or_Interface --
8081 ---------------------------------
8083 procedure Process_Import_Or_Interface
is
8089 -- In Relaxed_RM_Semantics, support old Ada 83 style:
8090 -- pragma Import (Entity, "external name");
8092 if Relaxed_RM_Semantics
8093 and then Arg_Count
= 2
8094 and then Prag_Id
= Pragma_Import
8095 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
8098 Def_Id
:= Get_Pragma_Arg
(Arg1
);
8101 if not Is_Entity_Name
(Def_Id
) then
8102 Error_Pragma_Arg
("entity name required", Arg1
);
8105 Def_Id
:= Entity
(Def_Id
);
8106 Kill_Size_Check_Code
(Def_Id
);
8107 Note_Possible_Modification
(Get_Pragma_Arg
(Arg1
), Sure
=> False);
8110 Process_Convention
(C
, Def_Id
);
8112 -- A pragma that applies to a Ghost entity becomes Ghost for the
8113 -- purposes of legality checks and removal of ignored Ghost code.
8115 Mark_Pragma_As_Ghost
(N
, Def_Id
);
8116 Kill_Size_Check_Code
(Def_Id
);
8117 Note_Possible_Modification
(Get_Pragma_Arg
(Arg2
), Sure
=> False);
8120 -- Various error checks
8122 if Ekind_In
(Def_Id
, E_Variable
, E_Constant
) then
8124 -- We do not permit Import to apply to a renaming declaration
8126 if Present
(Renamed_Object
(Def_Id
)) then
8128 ("pragma% not allowed for object renaming", Arg2
);
8130 -- User initialization is not allowed for imported object, but
8131 -- the object declaration may contain a default initialization,
8132 -- that will be discarded. Note that an explicit initialization
8133 -- only counts if it comes from source, otherwise it is simply
8134 -- the code generator making an implicit initialization explicit.
8136 elsif Present
(Expression
(Parent
(Def_Id
)))
8137 and then Comes_From_Source
8138 (Original_Node
(Expression
(Parent
(Def_Id
))))
8140 -- Set imported flag to prevent cascaded errors
8142 Set_Is_Imported
(Def_Id
);
8144 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8146 ("no initialization allowed for declaration of& #",
8147 "\imported entities cannot be initialized (RM B.1(24))",
8151 -- If the pragma comes from an aspect specification the
8152 -- Is_Imported flag has already been set.
8154 if not From_Aspect_Specification
(N
) then
8155 Set_Imported
(Def_Id
);
8158 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
8160 -- Note that we do not set Is_Public here. That's because we
8161 -- only want to set it if there is no address clause, and we
8162 -- don't know that yet, so we delay that processing till
8165 -- pragma Import completes deferred constants
8167 if Ekind
(Def_Id
) = E_Constant
then
8168 Set_Has_Completion
(Def_Id
);
8171 -- It is not possible to import a constant of an unconstrained
8172 -- array type (e.g. string) because there is no simple way to
8173 -- write a meaningful subtype for it.
8175 if Is_Array_Type
(Etype
(Def_Id
))
8176 and then not Is_Constrained
(Etype
(Def_Id
))
8179 ("imported constant& must have a constrained subtype",
8184 elsif Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8186 -- If the name is overloaded, pragma applies to all of the denoted
8187 -- entities in the same declarative part, unless the pragma comes
8188 -- from an aspect specification or was generated by the compiler
8189 -- (such as for pragma Provide_Shift_Operators).
8192 while Present
(Hom_Id
) loop
8194 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8196 -- Ignore inherited subprograms because the pragma will apply
8197 -- to the parent operation, which is the one called.
8199 if Is_Overloadable
(Def_Id
)
8200 and then Present
(Alias
(Def_Id
))
8204 -- If it is not a subprogram, it must be in an outer scope and
8205 -- pragma does not apply.
8207 elsif not Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8210 -- The pragma does not apply to primitives of interfaces
8212 elsif Is_Dispatching_Operation
(Def_Id
)
8213 and then Present
(Find_Dispatching_Type
(Def_Id
))
8214 and then Is_Interface
(Find_Dispatching_Type
(Def_Id
))
8218 -- Verify that the homonym is in the same declarative part (not
8219 -- just the same scope). If the pragma comes from an aspect
8220 -- specification we know that it is part of the declaration.
8222 elsif Parent
(Unit_Declaration_Node
(Def_Id
)) /= Parent
(N
)
8223 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit_Aux
8224 and then not From_Aspect_Specification
(N
)
8229 -- If the pragma comes from an aspect specification the
8230 -- Is_Imported flag has already been set.
8232 if not From_Aspect_Specification
(N
) then
8233 Set_Imported
(Def_Id
);
8236 -- Reject an Import applied to an abstract subprogram
8238 if Is_Subprogram
(Def_Id
)
8239 and then Is_Abstract_Subprogram
(Def_Id
)
8241 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8243 ("cannot import abstract subprogram& declared#",
8247 -- Special processing for Convention_Intrinsic
8249 if C
= Convention_Intrinsic
then
8251 -- Link_Name argument not allowed for intrinsic
8255 Set_Is_Intrinsic_Subprogram
(Def_Id
);
8257 -- If no external name is present, then check that this
8258 -- is a valid intrinsic subprogram. If an external name
8259 -- is present, then this is handled by the back end.
8262 Check_Intrinsic_Subprogram
8263 (Def_Id
, Get_Pragma_Arg
(Arg2
));
8267 -- Verify that the subprogram does not have a completion
8268 -- through a renaming declaration. For other completions the
8269 -- pragma appears as a too late representation.
8272 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Def_Id
);
8276 and then Nkind
(Decl
) = N_Subprogram_Declaration
8277 and then Present
(Corresponding_Body
(Decl
))
8278 and then Nkind
(Unit_Declaration_Node
8279 (Corresponding_Body
(Decl
))) =
8280 N_Subprogram_Renaming_Declaration
8282 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8284 ("cannot import&, renaming already provided for "
8285 & "declaration #", N
, Def_Id
);
8289 -- If the pragma comes from an aspect specification, there
8290 -- must be an Import aspect specified as well. In the rare
8291 -- case where Import is set to False, the suprogram needs to
8292 -- have a local completion.
8295 Imp_Aspect
: constant Node_Id
:=
8296 Find_Aspect
(Def_Id
, Aspect_Import
);
8300 if Present
(Imp_Aspect
)
8301 and then Present
(Expression
(Imp_Aspect
))
8303 Expr
:= Expression
(Imp_Aspect
);
8304 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8306 if Is_Entity_Name
(Expr
)
8307 and then Entity
(Expr
) = Standard_True
8309 Set_Has_Completion
(Def_Id
);
8312 -- If there is no expression, the default is True, as for
8313 -- all boolean aspects. Same for the older pragma.
8316 Set_Has_Completion
(Def_Id
);
8320 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
8323 if Is_Compilation_Unit
(Hom_Id
) then
8325 -- Its possible homonyms are not affected by the pragma.
8326 -- Such homonyms might be present in the context of other
8327 -- units being compiled.
8331 elsif From_Aspect_Specification
(N
) then
8334 -- If the pragma was created by the compiler, then we don't
8335 -- want it to apply to other homonyms. This kind of case can
8336 -- occur when using pragma Provide_Shift_Operators, which
8337 -- generates implicit shift and rotate operators with Import
8338 -- pragmas that might apply to earlier explicit or implicit
8339 -- declarations marked with Import (for example, coming from
8340 -- an earlier pragma Provide_Shift_Operators for another type),
8341 -- and we don't generally want other homonyms being treated
8342 -- as imported or the pragma flagged as an illegal duplicate.
8344 elsif not Comes_From_Source
(N
) then
8348 Hom_Id
:= Homonym
(Hom_Id
);
8352 -- Import a CPP class
8354 elsif C
= Convention_CPP
8355 and then (Is_Record_Type
(Def_Id
)
8356 or else Ekind
(Def_Id
) = E_Incomplete_Type
)
8358 if Ekind
(Def_Id
) = E_Incomplete_Type
then
8359 if Present
(Full_View
(Def_Id
)) then
8360 Def_Id
:= Full_View
(Def_Id
);
8364 ("cannot import 'C'P'P type before full declaration seen",
8365 Get_Pragma_Arg
(Arg2
));
8367 -- Although we have reported the error we decorate it as
8368 -- CPP_Class to avoid reporting spurious errors
8370 Set_Is_CPP_Class
(Def_Id
);
8375 -- Types treated as CPP classes must be declared limited (note:
8376 -- this used to be a warning but there is no real benefit to it
8377 -- since we did effectively intend to treat the type as limited
8380 if not Is_Limited_Type
(Def_Id
) then
8382 ("imported 'C'P'P type must be limited",
8383 Get_Pragma_Arg
(Arg2
));
8386 if Etype
(Def_Id
) /= Def_Id
8387 and then not Is_CPP_Class
(Root_Type
(Def_Id
))
8389 Error_Msg_N
("root type must be a 'C'P'P type", Arg1
);
8392 Set_Is_CPP_Class
(Def_Id
);
8394 -- Imported CPP types must not have discriminants (because C++
8395 -- classes do not have discriminants).
8397 if Has_Discriminants
(Def_Id
) then
8399 ("imported 'C'P'P type cannot have discriminants",
8400 First
(Discriminant_Specifications
8401 (Declaration_Node
(Def_Id
))));
8404 -- Check that components of imported CPP types do not have default
8405 -- expressions. For private types this check is performed when the
8406 -- full view is analyzed (see Process_Full_View).
8408 if not Is_Private_Type
(Def_Id
) then
8409 Check_CPP_Type_Has_No_Defaults
(Def_Id
);
8412 -- Import a CPP exception
8414 elsif C
= Convention_CPP
8415 and then Ekind
(Def_Id
) = E_Exception
8419 ("'External_'Name arguments is required for 'Cpp exception",
8422 -- As only a string is allowed, Check_Arg_Is_External_Name
8425 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
8428 if Present
(Arg4
) then
8430 ("Link_Name argument not allowed for imported Cpp exception",
8434 -- Do not call Set_Interface_Name as the name of the exception
8435 -- shouldn't be modified (and in particular it shouldn't be
8436 -- the External_Name). For exceptions, the External_Name is the
8437 -- name of the RTTI structure.
8439 -- ??? Emit an error if pragma Import/Export_Exception is present
8441 elsif Nkind
(Parent
(Def_Id
)) = N_Incomplete_Type_Declaration
then
8443 Check_Arg_Count
(3);
8444 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
8446 Process_Import_Predefined_Type
;
8450 ("second argument of pragma% must be object, subprogram "
8451 & "or incomplete type",
8455 -- If this pragma applies to a compilation unit, then the unit, which
8456 -- is a subprogram, does not require (or allow) a body. We also do
8457 -- not need to elaborate imported procedures.
8459 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
8461 Cunit
: constant Node_Id
:= Parent
(Parent
(N
));
8463 Set_Body_Required
(Cunit
, False);
8466 end Process_Import_Or_Interface
;
8468 --------------------
8469 -- Process_Inline --
8470 --------------------
8472 procedure Process_Inline
(Status
: Inline_Status
) is
8479 Ghost_Error_Posted
: Boolean := False;
8480 -- Flag set when an error concerning the illegal mix of Ghost and
8481 -- non-Ghost subprograms is emitted.
8483 Ghost_Id
: Entity_Id
:= Empty
;
8484 -- The entity of the first Ghost subprogram encountered while
8485 -- processing the arguments of the pragma.
8487 procedure Make_Inline
(Subp
: Entity_Id
);
8488 -- Subp is the defining unit name of the subprogram declaration. Set
8489 -- the flag, as well as the flag in the corresponding body, if there
8492 procedure Set_Inline_Flags
(Subp
: Entity_Id
);
8493 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8494 -- Has_Pragma_Inline_Always for the Inline_Always case.
8496 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean;
8497 -- Returns True if it can be determined at this stage that inlining
8498 -- is not possible, for example if the body is available and contains
8499 -- exception handlers, we prevent inlining, since otherwise we can
8500 -- get undefined symbols at link time. This function also emits a
8501 -- warning if front-end inlining is enabled and the pragma appears
8504 -- ??? is business with link symbols still valid, or does it relate
8505 -- to front end ZCX which is being phased out ???
8507 ---------------------------
8508 -- Inlining_Not_Possible --
8509 ---------------------------
8511 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean is
8512 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
8516 if Nkind
(Decl
) = N_Subprogram_Body
then
8517 Stats
:= Handled_Statement_Sequence
(Decl
);
8518 return Present
(Exception_Handlers
(Stats
))
8519 or else Present
(At_End_Proc
(Stats
));
8521 elsif Nkind
(Decl
) = N_Subprogram_Declaration
8522 and then Present
(Corresponding_Body
(Decl
))
8524 if Front_End_Inlining
8525 and then Analyzed
(Corresponding_Body
(Decl
))
8527 Error_Msg_N
("pragma appears too late, ignored??", N
);
8530 -- If the subprogram is a renaming as body, the body is just a
8531 -- call to the renamed subprogram, and inlining is trivially
8535 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
8536 N_Subprogram_Renaming_Declaration
8542 Handled_Statement_Sequence
8543 (Unit_Declaration_Node
(Corresponding_Body
(Decl
)));
8546 Present
(Exception_Handlers
(Stats
))
8547 or else Present
(At_End_Proc
(Stats
));
8551 -- If body is not available, assume the best, the check is
8552 -- performed again when compiling enclosing package bodies.
8556 end Inlining_Not_Possible
;
8562 procedure Make_Inline
(Subp
: Entity_Id
) is
8563 Kind
: constant Entity_Kind
:= Ekind
(Subp
);
8564 Inner_Subp
: Entity_Id
:= Subp
;
8567 -- Ignore if bad type, avoid cascaded error
8569 if Etype
(Subp
) = Any_Type
then
8573 -- If inlining is not possible, for now do not treat as an error
8575 elsif Status
/= Suppressed
8576 and then Inlining_Not_Possible
(Subp
)
8581 -- Here we have a candidate for inlining, but we must exclude
8582 -- derived operations. Otherwise we would end up trying to inline
8583 -- a phantom declaration, and the result would be to drag in a
8584 -- body which has no direct inlining associated with it. That
8585 -- would not only be inefficient but would also result in the
8586 -- backend doing cross-unit inlining in cases where it was
8587 -- definitely inappropriate to do so.
8589 -- However, a simple Comes_From_Source test is insufficient, since
8590 -- we do want to allow inlining of generic instances which also do
8591 -- not come from source. We also need to recognize specs generated
8592 -- by the front-end for bodies that carry the pragma. Finally,
8593 -- predefined operators do not come from source but are not
8594 -- inlineable either.
8596 elsif Is_Generic_Instance
(Subp
)
8597 or else Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Declaration
8601 elsif not Comes_From_Source
(Subp
)
8602 and then Scope
(Subp
) /= Standard_Standard
8608 -- The referenced entity must either be the enclosing entity, or
8609 -- an entity declared within the current open scope.
8611 if Present
(Scope
(Subp
))
8612 and then Scope
(Subp
) /= Current_Scope
8613 and then Subp
/= Current_Scope
8616 ("argument of% must be entity in current scope", Assoc
);
8620 -- Processing for procedure, operator or function. If subprogram
8621 -- is aliased (as for an instance) indicate that the renamed
8622 -- entity (if declared in the same unit) is inlined.
8623 -- If this is the anonymous subprogram created for a subprogram
8624 -- instance, the inlining applies to it directly. Otherwise we
8625 -- retrieve it as the alias of the visible subprogram instance.
8627 if Is_Subprogram
(Subp
) then
8628 if Is_Wrapper_Package
(Scope
(Subp
)) then
8631 Inner_Subp
:= Ultimate_Alias
(Inner_Subp
);
8634 if In_Same_Source_Unit
(Subp
, Inner_Subp
) then
8635 Set_Inline_Flags
(Inner_Subp
);
8637 Decl
:= Parent
(Parent
(Inner_Subp
));
8639 if Nkind
(Decl
) = N_Subprogram_Declaration
8640 and then Present
(Corresponding_Body
(Decl
))
8642 Set_Inline_Flags
(Corresponding_Body
(Decl
));
8644 elsif Is_Generic_Instance
(Subp
)
8645 and then Comes_From_Source
(Subp
)
8647 -- Indicate that the body needs to be created for
8648 -- inlining subsequent calls. The instantiation node
8649 -- follows the declaration of the wrapper package
8650 -- created for it. The subprogram that requires the
8651 -- body is the anonymous one in the wrapper package.
8653 if Scope
(Subp
) /= Standard_Standard
8655 Need_Subprogram_Instance_Body
8656 (Next
(Unit_Declaration_Node
8657 (Scope
(Alias
(Subp
)))), Subp
)
8662 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8663 -- appear in a formal part to apply to a formal subprogram.
8664 -- Do not apply check within an instance or a formal package
8665 -- the test will have been applied to the original generic.
8667 elsif Nkind
(Decl
) in N_Formal_Subprogram_Declaration
8668 and then List_Containing
(Decl
) = List_Containing
(N
)
8669 and then not In_Instance
8672 ("Inline cannot apply to a formal subprogram", N
);
8674 -- If Subp is a renaming, it is the renamed entity that
8675 -- will appear in any call, and be inlined. However, for
8676 -- ASIS uses it is convenient to indicate that the renaming
8677 -- itself is an inlined subprogram, so that some gnatcheck
8678 -- rules can be applied in the absence of expansion.
8680 elsif Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
8681 Set_Inline_Flags
(Subp
);
8687 -- For a generic subprogram set flag as well, for use at the point
8688 -- of instantiation, to determine whether the body should be
8691 elsif Is_Generic_Subprogram
(Subp
) then
8692 Set_Inline_Flags
(Subp
);
8695 -- Literals are by definition inlined
8697 elsif Kind
= E_Enumeration_Literal
then
8700 -- Anything else is an error
8704 ("expect subprogram name for pragma%", Assoc
);
8708 ----------------------
8709 -- Set_Inline_Flags --
8710 ----------------------
8712 procedure Set_Inline_Flags
(Subp
: Entity_Id
) is
8714 -- First set the Has_Pragma_XXX flags and issue the appropriate
8715 -- errors and warnings for suspicious combinations.
8717 if Prag_Id
= Pragma_No_Inline
then
8718 if Has_Pragma_Inline_Always
(Subp
) then
8720 ("Inline_Always and No_Inline are mutually exclusive", N
);
8721 elsif Has_Pragma_Inline
(Subp
) then
8723 ("Inline and No_Inline both specified for& ??",
8724 N
, Entity
(Subp_Id
));
8727 Set_Has_Pragma_No_Inline
(Subp
);
8729 if Prag_Id
= Pragma_Inline_Always
then
8730 if Has_Pragma_No_Inline
(Subp
) then
8732 ("Inline_Always and No_Inline are mutually exclusive",
8736 Set_Has_Pragma_Inline_Always
(Subp
);
8738 if Has_Pragma_No_Inline
(Subp
) then
8740 ("Inline and No_Inline both specified for& ??",
8741 N
, Entity
(Subp_Id
));
8745 if not Has_Pragma_Inline
(Subp
) then
8746 Set_Has_Pragma_Inline
(Subp
);
8750 -- Then adjust the Is_Inlined flag. It can never be set if the
8751 -- subprogram is subject to pragma No_Inline.
8755 Set_Is_Inlined
(Subp
, False);
8759 if not Has_Pragma_No_Inline
(Subp
) then
8760 Set_Is_Inlined
(Subp
, True);
8764 -- A pragma that applies to a Ghost entity becomes Ghost for the
8765 -- purposes of legality checks and removal of ignored Ghost code.
8767 Mark_Pragma_As_Ghost
(N
, Subp
);
8769 -- Capture the entity of the first Ghost subprogram being
8770 -- processed for error detection purposes.
8772 if Is_Ghost_Entity
(Subp
) then
8773 if No
(Ghost_Id
) then
8777 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
8778 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
8780 elsif Present
(Ghost_Id
) and then not Ghost_Error_Posted
then
8781 Ghost_Error_Posted
:= True;
8783 Error_Msg_Name_1
:= Pname
;
8785 ("pragma % cannot mention ghost and non-ghost subprograms",
8788 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
8789 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
8791 Error_Msg_Sloc
:= Sloc
(Subp
);
8792 Error_Msg_NE
("\& # declared as non-ghost", N
, Subp
);
8794 end Set_Inline_Flags
;
8796 -- Start of processing for Process_Inline
8799 Check_No_Identifiers
;
8800 Check_At_Least_N_Arguments
(1);
8802 if Status
= Enabled
then
8803 Inline_Processing_Required
:= True;
8807 while Present
(Assoc
) loop
8808 Subp_Id
:= Get_Pragma_Arg
(Assoc
);
8812 if Is_Entity_Name
(Subp_Id
) then
8813 Subp
:= Entity
(Subp_Id
);
8815 if Subp
= Any_Id
then
8817 -- If previous error, avoid cascaded errors
8819 Check_Error_Detected
;
8825 -- For the pragma case, climb homonym chain. This is
8826 -- what implements allowing the pragma in the renaming
8827 -- case, with the result applying to the ancestors, and
8828 -- also allows Inline to apply to all previous homonyms.
8830 if not From_Aspect_Specification
(N
) then
8831 while Present
(Homonym
(Subp
))
8832 and then Scope
(Homonym
(Subp
)) = Current_Scope
8834 Make_Inline
(Homonym
(Subp
));
8835 Subp
:= Homonym
(Subp
);
8842 Error_Pragma_Arg
("inappropriate argument for pragma%", Assoc
);
8849 ----------------------------
8850 -- Process_Interface_Name --
8851 ----------------------------
8853 procedure Process_Interface_Name
8854 (Subprogram_Def
: Entity_Id
;
8860 String_Val
: String_Id
;
8862 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
);
8863 -- SN is a string literal node for an interface name. This routine
8864 -- performs some minimal checks that the name is reasonable. In
8865 -- particular that no spaces or other obviously incorrect characters
8866 -- appear. This is only a warning, since any characters are allowed.
8868 ----------------------------------
8869 -- Check_Form_Of_Interface_Name --
8870 ----------------------------------
8872 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
) is
8873 S
: constant String_Id
:= Strval
(Expr_Value_S
(SN
));
8874 SL
: constant Nat
:= String_Length
(S
);
8879 Error_Msg_N
("interface name cannot be null string", SN
);
8882 for J
in 1 .. SL
loop
8883 C
:= Get_String_Char
(S
, J
);
8885 -- Look for dubious character and issue unconditional warning.
8886 -- Definitely dubious if not in character range.
8888 if not In_Character_Range
(C
)
8890 -- Commas, spaces and (back)slashes are dubious
8892 or else Get_Character
(C
) = ','
8893 or else Get_Character
(C
) = '\'
8894 or else Get_Character
(C
) = ' '
8895 or else Get_Character
(C
) = '/'
8898 ("??interface name contains illegal character",
8899 Sloc
(SN
) + Source_Ptr
(J
));
8902 end Check_Form_Of_Interface_Name
;
8904 -- Start of processing for Process_Interface_Name
8907 if No
(Link_Arg
) then
8908 if No
(Ext_Arg
) then
8911 elsif Chars
(Ext_Arg
) = Name_Link_Name
then
8913 Link_Nam
:= Expression
(Ext_Arg
);
8916 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8917 Ext_Nam
:= Expression
(Ext_Arg
);
8922 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8923 Check_Optional_Identifier
(Link_Arg
, Name_Link_Name
);
8924 Ext_Nam
:= Expression
(Ext_Arg
);
8925 Link_Nam
:= Expression
(Link_Arg
);
8928 -- Check expressions for external name and link name are static
8930 if Present
(Ext_Nam
) then
8931 Check_Arg_Is_OK_Static_Expression
(Ext_Nam
, Standard_String
);
8932 Check_Form_Of_Interface_Name
(Ext_Nam
);
8934 -- Verify that external name is not the name of a local entity,
8935 -- which would hide the imported one and could lead to run-time
8936 -- surprises. The problem can only arise for entities declared in
8937 -- a package body (otherwise the external name is fully qualified
8938 -- and will not conflict).
8946 if Prag_Id
= Pragma_Import
then
8947 String_To_Name_Buffer
(Strval
(Expr_Value_S
(Ext_Nam
)));
8949 E
:= Entity_Id
(Get_Name_Table_Int
(Nam
));
8951 if Nam
/= Chars
(Subprogram_Def
)
8952 and then Present
(E
)
8953 and then not Is_Overloadable
(E
)
8954 and then Is_Immediately_Visible
(E
)
8955 and then not Is_Imported
(E
)
8956 and then Ekind
(Scope
(E
)) = E_Package
8959 while Present
(Par
) loop
8960 if Nkind
(Par
) = N_Package_Body
then
8961 Error_Msg_Sloc
:= Sloc
(E
);
8963 ("imported entity is hidden by & declared#",
8968 Par
:= Parent
(Par
);
8975 if Present
(Link_Nam
) then
8976 Check_Arg_Is_OK_Static_Expression
(Link_Nam
, Standard_String
);
8977 Check_Form_Of_Interface_Name
(Link_Nam
);
8980 -- If there is no link name, just set the external name
8982 if No
(Link_Nam
) then
8983 Link_Nam
:= Adjust_External_Name_Case
(Expr_Value_S
(Ext_Nam
));
8985 -- For the Link_Name case, the given literal is preceded by an
8986 -- asterisk, which indicates to GCC that the given name should be
8987 -- taken literally, and in particular that no prepending of
8988 -- underlines should occur, even in systems where this is the
8993 Store_String_Char
(Get_Char_Code
('*'));
8994 String_Val
:= Strval
(Expr_Value_S
(Link_Nam
));
8995 Store_String_Chars
(String_Val
);
8997 Make_String_Literal
(Sloc
(Link_Nam
),
8998 Strval
=> End_String
);
9001 -- Set the interface name. If the entity is a generic instance, use
9002 -- its alias, which is the callable entity.
9004 if Is_Generic_Instance
(Subprogram_Def
) then
9005 Set_Encoded_Interface_Name
9006 (Alias
(Get_Base_Subprogram
(Subprogram_Def
)), Link_Nam
);
9008 Set_Encoded_Interface_Name
9009 (Get_Base_Subprogram
(Subprogram_Def
), Link_Nam
);
9012 Check_Duplicated_Export_Name
(Link_Nam
);
9013 end Process_Interface_Name
;
9015 -----------------------------------------
9016 -- Process_Interrupt_Or_Attach_Handler --
9017 -----------------------------------------
9019 procedure Process_Interrupt_Or_Attach_Handler
is
9020 Handler
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
9021 Prot_Typ
: constant Entity_Id
:= Scope
(Handler
);
9024 -- A pragma that applies to a Ghost entity becomes Ghost for the
9025 -- purposes of legality checks and removal of ignored Ghost code.
9027 Mark_Pragma_As_Ghost
(N
, Handler
);
9028 Set_Is_Interrupt_Handler
(Handler
);
9030 -- If the pragma is not associated with a handler procedure within a
9031 -- protected type, then it must be for a nonprotected procedure for
9032 -- the AAMP target, in which case we don't associate a representation
9033 -- item with the procedure's scope.
9035 if Ekind
(Prot_Typ
) = E_Protected_Type
then
9036 Record_Rep_Item
(Prot_Typ
, N
);
9039 -- Chain the pragma on the contract for completeness
9041 Add_Contract_Item
(N
, Handler
);
9042 end Process_Interrupt_Or_Attach_Handler
;
9044 --------------------------------------------------
9045 -- Process_Restrictions_Or_Restriction_Warnings --
9046 --------------------------------------------------
9048 -- Note: some of the simple identifier cases were handled in par-prag,
9049 -- but it is harmless (and more straightforward) to simply handle all
9050 -- cases here, even if it means we repeat a bit of work in some cases.
9052 procedure Process_Restrictions_Or_Restriction_Warnings
9056 R_Id
: Restriction_Id
;
9062 -- Ignore all Restrictions pragmas in CodePeer mode
9064 if CodePeer_Mode
then
9068 Check_Ada_83_Warning
;
9069 Check_At_Least_N_Arguments
(1);
9070 Check_Valid_Configuration_Pragma
;
9073 while Present
(Arg
) loop
9075 Expr
:= Get_Pragma_Arg
(Arg
);
9077 -- Case of no restriction identifier present
9079 if Id
= No_Name
then
9080 if Nkind
(Expr
) /= N_Identifier
then
9082 ("invalid form for restriction", Arg
);
9087 (Process_Restriction_Synonyms
(Expr
));
9089 if R_Id
not in All_Boolean_Restrictions
then
9090 Error_Msg_Name_1
:= Pname
;
9092 ("invalid restriction identifier&", Get_Pragma_Arg
(Arg
));
9094 -- Check for possible misspelling
9096 for J
in Restriction_Id
loop
9098 Rnm
: constant String := Restriction_Id
'Image (J
);
9101 Name_Buffer
(1 .. Rnm
'Length) := Rnm
;
9102 Name_Len
:= Rnm
'Length;
9103 Set_Casing
(All_Lower_Case
);
9105 if Is_Bad_Spelling_Of
(Chars
(Expr
), Name_Enter
) then
9107 (Identifier_Casing
(Current_Source_File
));
9108 Error_Msg_String
(1 .. Rnm
'Length) :=
9109 Name_Buffer
(1 .. Name_Len
);
9110 Error_Msg_Strlen
:= Rnm
'Length;
9111 Error_Msg_N
-- CODEFIX
9112 ("\possible misspelling of ""~""",
9113 Get_Pragma_Arg
(Arg
));
9122 if Implementation_Restriction
(R_Id
) then
9123 Check_Restriction
(No_Implementation_Restrictions
, Arg
);
9126 -- Special processing for No_Elaboration_Code restriction
9128 if R_Id
= No_Elaboration_Code
then
9130 -- Restriction is only recognized within a configuration
9131 -- pragma file, or within a unit of the main extended
9132 -- program. Note: the test for Main_Unit is needed to
9133 -- properly include the case of configuration pragma files.
9135 if not (Current_Sem_Unit
= Main_Unit
9136 or else In_Extended_Main_Source_Unit
(N
))
9140 -- Don't allow in a subunit unless already specified in
9143 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
9144 and then Nkind
(Unit
(Parent
(N
))) = N_Subunit
9145 and then not Restriction_Active
(No_Elaboration_Code
)
9148 ("invalid specification of ""No_Elaboration_Code""",
9151 ("\restriction cannot be specified in a subunit", N
);
9153 ("\unless also specified in body or spec", N
);
9156 -- If we accept a No_Elaboration_Code restriction, then it
9157 -- needs to be added to the configuration restriction set so
9158 -- that we get proper application to other units in the main
9159 -- extended source as required.
9162 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
9166 -- If this is a warning, then set the warning unless we already
9167 -- have a real restriction active (we never want a warning to
9168 -- override a real restriction).
9171 if not Restriction_Active
(R_Id
) then
9172 Set_Restriction
(R_Id
, N
);
9173 Restriction_Warnings
(R_Id
) := True;
9176 -- If real restriction case, then set it and make sure that the
9177 -- restriction warning flag is off, since a real restriction
9178 -- always overrides a warning.
9181 Set_Restriction
(R_Id
, N
);
9182 Restriction_Warnings
(R_Id
) := False;
9185 -- Check for obsolescent restrictions in Ada 2005 mode
9188 and then Ada_Version
>= Ada_2005
9189 and then (R_Id
= No_Asynchronous_Control
9191 R_Id
= No_Unchecked_Deallocation
9193 R_Id
= No_Unchecked_Conversion
)
9195 Check_Restriction
(No_Obsolescent_Features
, N
);
9198 -- A very special case that must be processed here: pragma
9199 -- Restrictions (No_Exceptions) turns off all run-time
9200 -- checking. This is a bit dubious in terms of the formal
9201 -- language definition, but it is what is intended by RM
9202 -- H.4(12). Restriction_Warnings never affects generated code
9203 -- so this is done only in the real restriction case.
9205 -- Atomic_Synchronization is not a real check, so it is not
9206 -- affected by this processing).
9208 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
9209 -- run-time checks in CodePeer and GNATprove modes: we want to
9210 -- generate checks for analysis purposes, as set respectively
9211 -- by -gnatC and -gnatd.F
9214 and then not (CodePeer_Mode
or GNATprove_Mode
)
9215 and then R_Id
= No_Exceptions
9217 for J
in Scope_Suppress
.Suppress
'Range loop
9218 if J
/= Atomic_Synchronization
then
9219 Scope_Suppress
.Suppress
(J
) := True;
9224 -- Case of No_Dependence => unit-name. Note that the parser
9225 -- already made the necessary entry in the No_Dependence table.
9227 elsif Id
= Name_No_Dependence
then
9228 if not OK_No_Dependence_Unit_Name
(Expr
) then
9232 -- Case of No_Specification_Of_Aspect => aspect-identifier
9234 elsif Id
= Name_No_Specification_Of_Aspect
then
9239 if Nkind
(Expr
) /= N_Identifier
then
9242 A_Id
:= Get_Aspect_Id
(Chars
(Expr
));
9245 if A_Id
= No_Aspect
then
9246 Error_Pragma_Arg
("invalid restriction name", Arg
);
9248 Set_Restriction_No_Specification_Of_Aspect
(Expr
, Warn
);
9252 -- Case of No_Use_Of_Attribute => attribute-identifier
9254 elsif Id
= Name_No_Use_Of_Attribute
then
9255 if Nkind
(Expr
) /= N_Identifier
9256 or else not Is_Attribute_Name
(Chars
(Expr
))
9258 Error_Msg_N
("unknown attribute name??", Expr
);
9261 Set_Restriction_No_Use_Of_Attribute
(Expr
, Warn
);
9264 -- Case of No_Use_Of_Entity => fully-qualified-name
9266 elsif Id
= Name_No_Use_Of_Entity
then
9268 -- Restriction is only recognized within a configuration
9269 -- pragma file, or within a unit of the main extended
9270 -- program. Note: the test for Main_Unit is needed to
9271 -- properly include the case of configuration pragma files.
9273 if Current_Sem_Unit
= Main_Unit
9274 or else In_Extended_Main_Source_Unit
(N
)
9276 if not OK_No_Dependence_Unit_Name
(Expr
) then
9277 Error_Msg_N
("wrong form for entity name", Expr
);
9279 Set_Restriction_No_Use_Of_Entity
9280 (Expr
, Warn
, No_Profile
);
9284 -- Case of No_Use_Of_Pragma => pragma-identifier
9286 elsif Id
= Name_No_Use_Of_Pragma
then
9287 if Nkind
(Expr
) /= N_Identifier
9288 or else not Is_Pragma_Name
(Chars
(Expr
))
9290 Error_Msg_N
("unknown pragma name??", Expr
);
9292 Set_Restriction_No_Use_Of_Pragma
(Expr
, Warn
);
9295 -- All other cases of restriction identifier present
9298 R_Id
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(Arg
));
9299 Analyze_And_Resolve
(Expr
, Any_Integer
);
9301 if R_Id
not in All_Parameter_Restrictions
then
9303 ("invalid restriction parameter identifier", Arg
);
9305 elsif not Is_OK_Static_Expression
(Expr
) then
9306 Flag_Non_Static_Expr
9307 ("value must be static expression!", Expr
);
9310 elsif not Is_Integer_Type
(Etype
(Expr
))
9311 or else Expr_Value
(Expr
) < 0
9314 ("value must be non-negative integer", Arg
);
9317 -- Restriction pragma is active
9319 Val
:= Expr_Value
(Expr
);
9321 if not UI_Is_In_Int_Range
(Val
) then
9323 ("pragma ignored, value too large??", Arg
);
9326 -- Warning case. If the real restriction is active, then we
9327 -- ignore the request, since warning never overrides a real
9328 -- restriction. Otherwise we set the proper warning. Note that
9329 -- this circuit sets the warning again if it is already set,
9330 -- which is what we want, since the constant may have changed.
9333 if not Restriction_Active
(R_Id
) then
9335 (R_Id
, N
, Integer (UI_To_Int
(Val
)));
9336 Restriction_Warnings
(R_Id
) := True;
9339 -- Real restriction case, set restriction and make sure warning
9340 -- flag is off since real restriction always overrides warning.
9343 Set_Restriction
(R_Id
, N
, Integer (UI_To_Int
(Val
)));
9344 Restriction_Warnings
(R_Id
) := False;
9350 end Process_Restrictions_Or_Restriction_Warnings
;
9352 ---------------------------------
9353 -- Process_Suppress_Unsuppress --
9354 ---------------------------------
9356 -- Note: this procedure makes entries in the check suppress data
9357 -- structures managed by Sem. See spec of package Sem for full
9358 -- details on how we handle recording of check suppression.
9360 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean) is
9365 In_Package_Spec
: constant Boolean :=
9366 Is_Package_Or_Generic_Package
(Current_Scope
)
9367 and then not In_Package_Body
(Current_Scope
);
9369 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
);
9370 -- Used to suppress a single check on the given entity
9372 --------------------------------
9373 -- Suppress_Unsuppress_Echeck --
9374 --------------------------------
9376 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
) is
9378 -- Check for error of trying to set atomic synchronization for
9379 -- a non-atomic variable.
9381 if C
= Atomic_Synchronization
9382 and then not (Is_Atomic
(E
) or else Has_Atomic_Components
(E
))
9385 ("pragma & requires atomic type or variable",
9386 Pragma_Identifier
(Original_Node
(N
)));
9389 Set_Checks_May_Be_Suppressed
(E
);
9391 if In_Package_Spec
then
9392 Push_Global_Suppress_Stack_Entry
9395 Suppress
=> Suppress_Case
);
9397 Push_Local_Suppress_Stack_Entry
9400 Suppress
=> Suppress_Case
);
9403 -- If this is a first subtype, and the base type is distinct,
9404 -- then also set the suppress flags on the base type.
9406 if Is_First_Subtype
(E
) and then Etype
(E
) /= E
then
9407 Suppress_Unsuppress_Echeck
(Etype
(E
), C
);
9409 end Suppress_Unsuppress_Echeck
;
9411 -- Start of processing for Process_Suppress_Unsuppress
9414 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9415 -- on user code: we want to generate checks for analysis purposes, as
9416 -- set respectively by -gnatC and -gnatd.F
9418 if Comes_From_Source
(N
)
9419 and then (CodePeer_Mode
or GNATprove_Mode
)
9424 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9425 -- declarative part or a package spec (RM 11.5(5)).
9427 if not Is_Configuration_Pragma
then
9428 Check_Is_In_Decl_Part_Or_Package_Spec
;
9431 Check_At_Least_N_Arguments
(1);
9432 Check_At_Most_N_Arguments
(2);
9433 Check_No_Identifier
(Arg1
);
9434 Check_Arg_Is_Identifier
(Arg1
);
9436 C
:= Get_Check_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
9438 if C
= No_Check_Id
then
9440 ("argument of pragma% is not valid check name", Arg1
);
9443 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9445 if C
= Elaboration_Check
and then SPARK_Mode
= On
then
9447 ("Suppress of Elaboration_Check ignored in SPARK??",
9448 "\elaboration checking rules are statically enforced "
9449 & "(SPARK RM 7.7)", Arg1
);
9452 -- One-argument case
9454 if Arg_Count
= 1 then
9456 -- Make an entry in the local scope suppress table. This is the
9457 -- table that directly shows the current value of the scope
9458 -- suppress check for any check id value.
9460 if C
= All_Checks
then
9462 -- For All_Checks, we set all specific predefined checks with
9463 -- the exception of Elaboration_Check, which is handled
9464 -- specially because of not wanting All_Checks to have the
9465 -- effect of deactivating static elaboration order processing.
9466 -- Atomic_Synchronization is also not affected, since this is
9467 -- not a real check.
9469 for J
in Scope_Suppress
.Suppress
'Range loop
9470 if J
/= Elaboration_Check
9472 J
/= Atomic_Synchronization
9474 Scope_Suppress
.Suppress
(J
) := Suppress_Case
;
9478 -- If not All_Checks, and predefined check, then set appropriate
9479 -- scope entry. Note that we will set Elaboration_Check if this
9480 -- is explicitly specified. Atomic_Synchronization is allowed
9481 -- only if internally generated and entity is atomic.
9483 elsif C
in Predefined_Check_Id
9484 and then (not Comes_From_Source
(N
)
9485 or else C
/= Atomic_Synchronization
)
9487 Scope_Suppress
.Suppress
(C
) := Suppress_Case
;
9490 -- Also make an entry in the Local_Entity_Suppress table
9492 Push_Local_Suppress_Stack_Entry
9495 Suppress
=> Suppress_Case
);
9497 -- Case of two arguments present, where the check is suppressed for
9498 -- a specified entity (given as the second argument of the pragma)
9501 -- This is obsolescent in Ada 2005 mode
9503 if Ada_Version
>= Ada_2005
then
9504 Check_Restriction
(No_Obsolescent_Features
, Arg2
);
9507 Check_Optional_Identifier
(Arg2
, Name_On
);
9508 E_Id
:= Get_Pragma_Arg
(Arg2
);
9511 if not Is_Entity_Name
(E_Id
) then
9513 ("second argument of pragma% must be entity name", Arg2
);
9522 -- A pragma that applies to a Ghost entity becomes Ghost for the
9523 -- purposes of legality checks and removal of ignored Ghost code.
9525 Mark_Pragma_As_Ghost
(N
, E
);
9527 -- Enforce RM 11.5(7) which requires that for a pragma that
9528 -- appears within a package spec, the named entity must be
9529 -- within the package spec. We allow the package name itself
9530 -- to be mentioned since that makes sense, although it is not
9531 -- strictly allowed by 11.5(7).
9534 and then E
/= Current_Scope
9535 and then Scope
(E
) /= Current_Scope
9538 ("entity in pragma% is not in package spec (RM 11.5(7))",
9542 -- Loop through homonyms. As noted below, in the case of a package
9543 -- spec, only homonyms within the package spec are considered.
9546 Suppress_Unsuppress_Echeck
(E
, C
);
9548 if Is_Generic_Instance
(E
)
9549 and then Is_Subprogram
(E
)
9550 and then Present
(Alias
(E
))
9552 Suppress_Unsuppress_Echeck
(Alias
(E
), C
);
9555 -- Move to next homonym if not aspect spec case
9557 exit when From_Aspect_Specification
(N
);
9561 -- If we are within a package specification, the pragma only
9562 -- applies to homonyms in the same scope.
9564 exit when In_Package_Spec
9565 and then Scope
(E
) /= Current_Scope
;
9568 end Process_Suppress_Unsuppress
;
9570 -------------------------------
9571 -- Record_Independence_Check --
9572 -------------------------------
9574 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
) is
9576 -- For GCC back ends the validation is done a priori
9578 if not AAMP_On_Target
then
9582 Independence_Checks
.Append
((N
, E
));
9583 end Record_Independence_Check
;
9589 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
) is
9591 if Is_Imported
(E
) then
9593 ("cannot export entity& that was previously imported", Arg
);
9595 elsif Present
(Address_Clause
(E
))
9596 and then not Relaxed_RM_Semantics
9599 ("cannot export entity& that has an address clause", Arg
);
9602 Set_Is_Exported
(E
);
9604 -- Generate a reference for entity explicitly, because the
9605 -- identifier may be overloaded and name resolution will not
9608 Generate_Reference
(E
, Arg
);
9610 -- Deal with exporting non-library level entity
9612 if not Is_Library_Level_Entity
(E
) then
9614 -- Not allowed at all for subprograms
9616 if Is_Subprogram
(E
) then
9617 Error_Pragma_Arg
("local subprogram& cannot be exported", Arg
);
9619 -- Otherwise set public and statically allocated
9623 Set_Is_Statically_Allocated
(E
);
9625 -- Warn if the corresponding W flag is set
9627 if Warn_On_Export_Import
9629 -- Only do this for something that was in the source. Not
9630 -- clear if this can be False now (there used for sure to be
9631 -- cases on some systems where it was False), but anyway the
9632 -- test is harmless if not needed, so it is retained.
9634 and then Comes_From_Source
(Arg
)
9637 ("?x?& has been made static as a result of Export",
9640 ("\?x?this usage is non-standard and non-portable",
9646 if Warn_On_Export_Import
and then Is_Type
(E
) then
9647 Error_Msg_NE
("exporting a type has no effect?x?", Arg
, E
);
9650 if Warn_On_Export_Import
and Inside_A_Generic
then
9652 ("all instances of& will have the same external name?x?",
9657 ----------------------------------------------
9658 -- Set_Extended_Import_Export_External_Name --
9659 ----------------------------------------------
9661 procedure Set_Extended_Import_Export_External_Name
9662 (Internal_Ent
: Entity_Id
;
9663 Arg_External
: Node_Id
)
9665 Old_Name
: constant Node_Id
:= Interface_Name
(Internal_Ent
);
9669 if No
(Arg_External
) then
9673 Check_Arg_Is_External_Name
(Arg_External
);
9675 if Nkind
(Arg_External
) = N_String_Literal
then
9676 if String_Length
(Strval
(Arg_External
)) = 0 then
9679 New_Name
:= Adjust_External_Name_Case
(Arg_External
);
9682 elsif Nkind
(Arg_External
) = N_Identifier
then
9683 New_Name
:= Get_Default_External_Name
(Arg_External
);
9685 -- Check_Arg_Is_External_Name should let through only identifiers and
9686 -- string literals or static string expressions (which are folded to
9687 -- string literals).
9690 raise Program_Error
;
9693 -- If we already have an external name set (by a prior normal Import
9694 -- or Export pragma), then the external names must match
9696 if Present
(Interface_Name
(Internal_Ent
)) then
9698 -- Ignore mismatching names in CodePeer mode, to support some
9699 -- old compilers which would export the same procedure under
9700 -- different names, e.g:
9702 -- pragma Export_Procedure (P, "a");
9703 -- pragma Export_Procedure (P, "b");
9705 if CodePeer_Mode
then
9709 Check_Matching_Internal_Names
: declare
9710 S1
: constant String_Id
:= Strval
(Old_Name
);
9711 S2
: constant String_Id
:= Strval
(New_Name
);
9714 pragma No_Return
(Mismatch
);
9715 -- Called if names do not match
9721 procedure Mismatch
is
9723 Error_Msg_Sloc
:= Sloc
(Old_Name
);
9725 ("external name does not match that given #",
9729 -- Start of processing for Check_Matching_Internal_Names
9732 if String_Length
(S1
) /= String_Length
(S2
) then
9736 for J
in 1 .. String_Length
(S1
) loop
9737 if Get_String_Char
(S1
, J
) /= Get_String_Char
(S2
, J
) then
9742 end Check_Matching_Internal_Names
;
9744 -- Otherwise set the given name
9747 Set_Encoded_Interface_Name
(Internal_Ent
, New_Name
);
9748 Check_Duplicated_Export_Name
(New_Name
);
9750 end Set_Extended_Import_Export_External_Name
;
9756 procedure Set_Imported
(E
: Entity_Id
) is
9758 -- Error message if already imported or exported
9760 if Is_Exported
(E
) or else Is_Imported
(E
) then
9762 -- Error if being set Exported twice
9764 if Is_Exported
(E
) then
9765 Error_Msg_NE
("entity& was previously exported", N
, E
);
9767 -- Ignore error in CodePeer mode where we treat all imported
9768 -- subprograms as unknown.
9770 elsif CodePeer_Mode
then
9773 -- OK if Import/Interface case
9775 elsif Import_Interface_Present
(N
) then
9778 -- Error if being set Imported twice
9781 Error_Msg_NE
("entity& was previously imported", N
, E
);
9784 Error_Msg_Name_1
:= Pname
;
9786 ("\(pragma% applies to all previous entities)", N
);
9788 Error_Msg_Sloc
:= Sloc
(E
);
9789 Error_Msg_NE
("\import not allowed for& declared#", N
, E
);
9791 -- Here if not previously imported or exported, OK to import
9794 Set_Is_Imported
(E
);
9796 -- For subprogram, set Import_Pragma field
9798 if Is_Subprogram
(E
) then
9799 Set_Import_Pragma
(E
, N
);
9802 -- If the entity is an object that is not at the library level,
9803 -- then it is statically allocated. We do not worry about objects
9804 -- with address clauses in this context since they are not really
9805 -- imported in the linker sense.
9808 and then not Is_Library_Level_Entity
(E
)
9809 and then No
(Address_Clause
(E
))
9811 Set_Is_Statically_Allocated
(E
);
9818 -------------------------
9819 -- Set_Mechanism_Value --
9820 -------------------------
9822 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9823 -- analyzed, since it is semantic nonsense), so we get it in the exact
9824 -- form created by the parser.
9826 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
) is
9827 procedure Bad_Mechanism
;
9828 pragma No_Return
(Bad_Mechanism
);
9829 -- Signal bad mechanism name
9831 -------------------------
9832 -- Bad_Mechanism_Value --
9833 -------------------------
9835 procedure Bad_Mechanism
is
9837 Error_Pragma_Arg
("unrecognized mechanism name", Mech_Name
);
9840 -- Start of processing for Set_Mechanism_Value
9843 if Mechanism
(Ent
) /= Default_Mechanism
then
9845 ("mechanism for & has already been set", Mech_Name
, Ent
);
9848 -- MECHANISM_NAME ::= value | reference
9850 if Nkind
(Mech_Name
) = N_Identifier
then
9851 if Chars
(Mech_Name
) = Name_Value
then
9852 Set_Mechanism
(Ent
, By_Copy
);
9855 elsif Chars
(Mech_Name
) = Name_Reference
then
9856 Set_Mechanism
(Ent
, By_Reference
);
9859 elsif Chars
(Mech_Name
) = Name_Copy
then
9861 ("bad mechanism name, Value assumed", Mech_Name
);
9870 end Set_Mechanism_Value
;
9872 --------------------------
9873 -- Set_Rational_Profile --
9874 --------------------------
9876 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9877 -- extension to the semantics of renaming declarations.
9879 procedure Set_Rational_Profile
is
9881 Implicit_Packing
:= True;
9882 Overriding_Renamings
:= True;
9883 Use_VADS_Size
:= True;
9884 end Set_Rational_Profile
;
9886 ---------------------------
9887 -- Set_Ravenscar_Profile --
9888 ---------------------------
9890 -- The tasks to be done here are
9892 -- Set required policies
9894 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9895 -- pragma Locking_Policy (Ceiling_Locking)
9897 -- Set Detect_Blocking mode
9899 -- Set required restrictions (see System.Rident for detailed list)
9901 -- Set the No_Dependence rules
9902 -- No_Dependence => Ada.Asynchronous_Task_Control
9903 -- No_Dependence => Ada.Calendar
9904 -- No_Dependence => Ada.Execution_Time.Group_Budget
9905 -- No_Dependence => Ada.Execution_Time.Timers
9906 -- No_Dependence => Ada.Task_Attributes
9907 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9909 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
) is
9910 procedure Set_Error_Msg_To_Profile_Name
;
9911 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
9914 -----------------------------------
9915 -- Set_Error_Msg_To_Profile_Name --
9916 -----------------------------------
9918 procedure Set_Error_Msg_To_Profile_Name
is
9919 Prof_Nam
: constant Node_Id
:=
9921 (First
(Pragma_Argument_Associations
(N
)));
9924 Get_Name_String
(Chars
(Prof_Nam
));
9925 Adjust_Name_Case
(Global_Name_Buffer
, Sloc
(Prof_Nam
));
9926 Error_Msg_Strlen
:= Name_Len
;
9927 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
9928 end Set_Error_Msg_To_Profile_Name
;
9937 -- Start of processing for Set_Ravenscar_Profile
9940 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9942 if Task_Dispatching_Policy
/= ' '
9943 and then Task_Dispatching_Policy
/= 'F'
9945 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
9946 Set_Error_Msg_To_Profile_Name
;
9947 Error_Pragma
("Profile (~) incompatible with policy#");
9949 -- Set the FIFO_Within_Priorities policy, but always preserve
9950 -- System_Location since we like the error message with the run time
9954 Task_Dispatching_Policy
:= 'F';
9956 if Task_Dispatching_Policy_Sloc
/= System_Location
then
9957 Task_Dispatching_Policy_Sloc
:= Loc
;
9961 -- pragma Locking_Policy (Ceiling_Locking)
9963 if Locking_Policy
/= ' '
9964 and then Locking_Policy
/= 'C'
9966 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
9967 Set_Error_Msg_To_Profile_Name
;
9968 Error_Pragma
("Profile (~) incompatible with policy#");
9970 -- Set the Ceiling_Locking policy, but preserve System_Location since
9971 -- we like the error message with the run time name.
9974 Locking_Policy
:= 'C';
9976 if Locking_Policy_Sloc
/= System_Location
then
9977 Locking_Policy_Sloc
:= Loc
;
9981 -- pragma Detect_Blocking
9983 Detect_Blocking
:= True;
9985 -- Set the corresponding restrictions
9987 Set_Profile_Restrictions
9988 (Profile
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
9990 -- Set the No_Dependence restrictions
9992 -- The following No_Dependence restrictions:
9993 -- No_Dependence => Ada.Asynchronous_Task_Control
9994 -- No_Dependence => Ada.Calendar
9995 -- No_Dependence => Ada.Task_Attributes
9996 -- are already set by previous call to Set_Profile_Restrictions.
9998 -- Set the following restrictions which were added to Ada 2005:
9999 -- No_Dependence => Ada.Execution_Time.Group_Budget
10000 -- No_Dependence => Ada.Execution_Time.Timers
10002 -- ??? The use of Name_Buffer here is suspicious. The names should
10003 -- be registered in snames.ads-tmpl and used to build the qualified
10006 if Ada_Version
>= Ada_2005
then
10007 Name_Buffer
(1 .. 3) := "ada";
10010 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
);
10012 Name_Buffer
(1 .. 14) := "execution_time";
10015 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10018 Make_Selected_Component
10021 Selector_Name
=> Sel_Id
);
10023 Name_Buffer
(1 .. 13) := "group_budgets";
10026 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10029 Make_Selected_Component
10032 Selector_Name
=> Sel_Id
);
10034 Set_Restriction_No_Dependence
10036 Warn
=> Treat_Restrictions_As_Warnings
,
10037 Profile
=> Ravenscar
);
10039 Name_Buffer
(1 .. 6) := "timers";
10042 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10045 Make_Selected_Component
10048 Selector_Name
=> Sel_Id
);
10050 Set_Restriction_No_Dependence
10052 Warn
=> Treat_Restrictions_As_Warnings
,
10053 Profile
=> Ravenscar
);
10056 -- Set the following restriction which was added to Ada 2012 (see
10058 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
10060 if Ada_Version
>= Ada_2012
then
10061 Name_Buffer
(1 .. 6) := "system";
10064 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
);
10066 Name_Buffer
(1 .. 15) := "multiprocessors";
10069 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10072 Make_Selected_Component
10075 Selector_Name
=> Sel_Id
);
10077 Name_Buffer
(1 .. 19) := "dispatching_domains";
10080 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
10083 Make_Selected_Component
10086 Selector_Name
=> Sel_Id
);
10088 Set_Restriction_No_Dependence
10090 Warn
=> Treat_Restrictions_As_Warnings
,
10091 Profile
=> Ravenscar
);
10093 end Set_Ravenscar_Profile
;
10095 -- Start of processing for Analyze_Pragma
10098 -- The following code is a defense against recursion. Not clear that
10099 -- this can happen legitimately, but perhaps some error situations can
10100 -- cause it, and we did see this recursion during testing.
10102 if Analyzed
(N
) then
10108 Check_Restriction_No_Use_Of_Pragma
(N
);
10110 -- Deal with unrecognized pragma
10112 Pname
:= Pragma_Name
(N
);
10114 if not Is_Pragma_Name
(Pname
) then
10115 if Warn_On_Unrecognized_Pragma
then
10116 Error_Msg_Name_1
:= Pname
;
10117 Error_Msg_N
("?g?unrecognized pragma%!", Pragma_Identifier
(N
));
10119 for PN
in First_Pragma_Name
.. Last_Pragma_Name
loop
10120 if Is_Bad_Spelling_Of
(Pname
, PN
) then
10121 Error_Msg_Name_1
:= PN
;
10122 Error_Msg_N
-- CODEFIX
10123 ("\?g?possible misspelling of %!", Pragma_Identifier
(N
));
10132 -- Ignore pragma if Ignore_Pragma applies
10134 if Get_Name_Table_Boolean3
(Pname
) then
10138 -- Here to start processing for recognized pragma
10140 Prag_Id
:= Get_Pragma_Id
(Pname
);
10141 Pname
:= Original_Aspect_Pragma_Name
(N
);
10143 -- Capture setting of Opt.Uneval_Old
10145 case Opt
.Uneval_Old
is
10147 Set_Uneval_Old_Accept
(N
);
10151 Set_Uneval_Old_Warn
(N
);
10153 raise Program_Error
;
10156 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
10157 -- is already set, indicating that we have already checked the policy
10158 -- at the right point. This happens for example in the case of a pragma
10159 -- that is derived from an Aspect.
10161 if Is_Ignored
(N
) or else Is_Checked
(N
) then
10164 -- For a pragma that is a rewriting of another pragma, copy the
10165 -- Is_Checked/Is_Ignored status from the rewritten pragma.
10167 elsif Is_Rewrite_Substitution
(N
)
10168 and then Nkind
(Original_Node
(N
)) = N_Pragma
10169 and then Original_Node
(N
) /= N
10171 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
10172 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
10174 -- Otherwise query the applicable policy at this point
10177 Check_Applicable_Policy
(N
);
10179 -- If pragma is disabled, rewrite as NULL and skip analysis
10181 if Is_Disabled
(N
) then
10182 Rewrite
(N
, Make_Null_Statement
(Loc
));
10188 -- Preset arguments
10196 if Present
(Pragma_Argument_Associations
(N
)) then
10197 Arg_Count
:= List_Length
(Pragma_Argument_Associations
(N
));
10198 Arg1
:= First
(Pragma_Argument_Associations
(N
));
10200 if Present
(Arg1
) then
10201 Arg2
:= Next
(Arg1
);
10203 if Present
(Arg2
) then
10204 Arg3
:= Next
(Arg2
);
10206 if Present
(Arg3
) then
10207 Arg4
:= Next
(Arg3
);
10213 -- An enumeration type defines the pragmas that are supported by the
10214 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10215 -- into the corresponding enumeration value for the following case.
10223 -- pragma Abort_Defer;
10225 when Pragma_Abort_Defer
=>
10227 Check_Arg_Count
(0);
10229 -- The only required semantic processing is to check the
10230 -- placement. This pragma must appear at the start of the
10231 -- statement sequence of a handled sequence of statements.
10233 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
10234 or else N
/= First
(Statements
(Parent
(N
)))
10239 --------------------
10240 -- Abstract_State --
10241 --------------------
10243 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10245 -- ABSTRACT_STATE_LIST ::=
10247 -- | STATE_NAME_WITH_OPTIONS
10248 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
10250 -- STATE_NAME_WITH_OPTIONS ::=
10252 -- | (STATE_NAME with OPTION_LIST)
10254 -- OPTION_LIST ::= OPTION {, OPTION}
10258 -- | NAME_VALUE_OPTION
10260 -- SIMPLE_OPTION ::= Ghost | Synchronous
10262 -- NAME_VALUE_OPTION ::=
10263 -- Part_Of => ABSTRACT_STATE
10264 -- | External [=> EXTERNAL_PROPERTY_LIST]
10266 -- EXTERNAL_PROPERTY_LIST ::=
10267 -- EXTERNAL_PROPERTY
10268 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
10270 -- EXTERNAL_PROPERTY ::=
10271 -- Async_Readers [=> boolean_EXPRESSION]
10272 -- | Async_Writers [=> boolean_EXPRESSION]
10273 -- | Effective_Reads [=> boolean_EXPRESSION]
10274 -- | Effective_Writes [=> boolean_EXPRESSION]
10275 -- others => boolean_EXPRESSION
10277 -- STATE_NAME ::= defining_identifier
10279 -- ABSTRACT_STATE ::= name
10281 -- Characteristics:
10283 -- * Analysis - The annotation is fully analyzed immediately upon
10284 -- elaboration as it cannot forward reference entities.
10286 -- * Expansion - None.
10288 -- * Template - The annotation utilizes the generic template of the
10289 -- related package declaration.
10291 -- * Globals - The annotation cannot reference global entities.
10293 -- * Instance - The annotation is instantiated automatically when
10294 -- the related generic package is instantiated.
10296 when Pragma_Abstract_State
=> Abstract_State
: declare
10297 Missing_Parentheses
: Boolean := False;
10298 -- Flag set when a state declaration with options is not properly
10301 -- Flags used to verify the consistency of states
10303 Non_Null_Seen
: Boolean := False;
10304 Null_Seen
: Boolean := False;
10306 procedure Analyze_Abstract_State
10308 Pack_Id
: Entity_Id
);
10309 -- Verify the legality of a single state declaration. Create and
10310 -- decorate a state abstraction entity and introduce it into the
10311 -- visibility chain. Pack_Id denotes the entity or the related
10312 -- package where pragma Abstract_State appears.
10314 procedure Malformed_State_Error
(State
: Node_Id
);
10315 -- Emit an error concerning the illegal declaration of abstract
10316 -- state State. This routine diagnoses syntax errors that lead to
10317 -- a different parse tree. The error is issued regardless of the
10318 -- SPARK mode in effect.
10320 ----------------------------
10321 -- Analyze_Abstract_State --
10322 ----------------------------
10324 procedure Analyze_Abstract_State
10326 Pack_Id
: Entity_Id
)
10328 -- Flags used to verify the consistency of options
10330 AR_Seen
: Boolean := False;
10331 AW_Seen
: Boolean := False;
10332 ER_Seen
: Boolean := False;
10333 EW_Seen
: Boolean := False;
10334 External_Seen
: Boolean := False;
10335 Ghost_Seen
: Boolean := False;
10336 Others_Seen
: Boolean := False;
10337 Part_Of_Seen
: Boolean := False;
10338 Synchronous_Seen
: Boolean := False;
10340 -- Flags used to store the static value of all external states'
10343 AR_Val
: Boolean := False;
10344 AW_Val
: Boolean := False;
10345 ER_Val
: Boolean := False;
10346 EW_Val
: Boolean := False;
10348 State_Id
: Entity_Id
:= Empty
;
10349 -- The entity to be generated for the current state declaration
10351 procedure Analyze_External_Option
(Opt
: Node_Id
);
10352 -- Verify the legality of option External
10354 procedure Analyze_External_Property
10356 Expr
: Node_Id
:= Empty
);
10357 -- Verify the legailty of a single external property. Prop
10358 -- denotes the external property. Expr is the expression used
10359 -- to set the property.
10361 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
);
10362 -- Verify the legality of option Part_Of
10364 procedure Check_Duplicate_Option
10366 Status
: in out Boolean);
10367 -- Flag Status denotes whether a particular option has been
10368 -- seen while processing a state. This routine verifies that
10369 -- Opt is not a duplicate option and sets the flag Status
10370 -- (SPARK RM 7.1.4(1)).
10372 procedure Check_Duplicate_Property
10374 Status
: in out Boolean);
10375 -- Flag Status denotes whether a particular property has been
10376 -- seen while processing option External. This routine verifies
10377 -- that Prop is not a duplicate property and sets flag Status.
10378 -- Opt is not a duplicate property and sets the flag Status.
10379 -- (SPARK RM 7.1.4(2))
10381 procedure Check_Ghost_Synchronous
;
10382 -- Ensure that the abstract state is not subject to both Ghost
10383 -- and Synchronous simple options. Emit an error if this is the
10386 procedure Create_Abstract_State
10390 Is_Null
: Boolean);
10391 -- Generate an abstract state entity with name Nam and enter it
10392 -- into visibility. Decl is the "declaration" of the state as
10393 -- it appears in pragma Abstract_State. Loc is the location of
10394 -- the related state "declaration". Flag Is_Null should be set
10395 -- when the associated Abstract_State pragma defines a null
10398 -----------------------------
10399 -- Analyze_External_Option --
10400 -----------------------------
10402 procedure Analyze_External_Option
(Opt
: Node_Id
) is
10403 Errors
: constant Nat
:= Serious_Errors_Detected
;
10405 Props
: Node_Id
:= Empty
;
10408 if Nkind
(Opt
) = N_Component_Association
then
10409 Props
:= Expression
(Opt
);
10412 -- External state with properties
10414 if Present
(Props
) then
10416 -- Multiple properties appear as an aggregate
10418 if Nkind
(Props
) = N_Aggregate
then
10420 -- Simple property form
10422 Prop
:= First
(Expressions
(Props
));
10423 while Present
(Prop
) loop
10424 Analyze_External_Property
(Prop
);
10428 -- Property with expression form
10430 Prop
:= First
(Component_Associations
(Props
));
10431 while Present
(Prop
) loop
10432 Analyze_External_Property
10433 (Prop
=> First
(Choices
(Prop
)),
10434 Expr
=> Expression
(Prop
));
10442 Analyze_External_Property
(Props
);
10445 -- An external state defined without any properties defaults
10446 -- all properties to True.
10455 -- Once all external properties have been processed, verify
10456 -- their mutual interaction. Do not perform the check when
10457 -- at least one of the properties is illegal as this will
10458 -- produce a bogus error.
10460 if Errors
= Serious_Errors_Detected
then
10461 Check_External_Properties
10462 (State
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
10464 end Analyze_External_Option
;
10466 -------------------------------
10467 -- Analyze_External_Property --
10468 -------------------------------
10470 procedure Analyze_External_Property
10472 Expr
: Node_Id
:= Empty
)
10474 Expr_Val
: Boolean;
10477 -- Check the placement of "others" (if available)
10479 if Nkind
(Prop
) = N_Others_Choice
then
10480 if Others_Seen
then
10482 ("only one others choice allowed in option External",
10485 Others_Seen
:= True;
10488 elsif Others_Seen
then
10490 ("others must be the last property in option External",
10493 -- The only remaining legal options are the four predefined
10494 -- external properties.
10496 elsif Nkind
(Prop
) = N_Identifier
10497 and then Nam_In
(Chars
(Prop
), Name_Async_Readers
,
10498 Name_Async_Writers
,
10499 Name_Effective_Reads
,
10500 Name_Effective_Writes
)
10504 -- Otherwise the construct is not a valid property
10507 SPARK_Msg_N
("invalid external state property", Prop
);
10511 -- Ensure that the expression of the external state property
10512 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10514 if Present
(Expr
) then
10515 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
10517 if Is_OK_Static_Expression
(Expr
) then
10518 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
10521 ("expression of external state property must be "
10525 -- The lack of expression defaults the property to True
10531 -- Named properties
10533 if Nkind
(Prop
) = N_Identifier
then
10534 if Chars
(Prop
) = Name_Async_Readers
then
10535 Check_Duplicate_Property
(Prop
, AR_Seen
);
10536 AR_Val
:= Expr_Val
;
10538 elsif Chars
(Prop
) = Name_Async_Writers
then
10539 Check_Duplicate_Property
(Prop
, AW_Seen
);
10540 AW_Val
:= Expr_Val
;
10542 elsif Chars
(Prop
) = Name_Effective_Reads
then
10543 Check_Duplicate_Property
(Prop
, ER_Seen
);
10544 ER_Val
:= Expr_Val
;
10547 Check_Duplicate_Property
(Prop
, EW_Seen
);
10548 EW_Val
:= Expr_Val
;
10551 -- The handling of property "others" must take into account
10552 -- all other named properties that have been encountered so
10553 -- far. Only those that have not been seen are affected by
10557 if not AR_Seen
then
10558 AR_Val
:= Expr_Val
;
10561 if not AW_Seen
then
10562 AW_Val
:= Expr_Val
;
10565 if not ER_Seen
then
10566 ER_Val
:= Expr_Val
;
10569 if not EW_Seen
then
10570 EW_Val
:= Expr_Val
;
10573 end Analyze_External_Property
;
10575 ----------------------------
10576 -- Analyze_Part_Of_Option --
10577 ----------------------------
10579 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
) is
10580 Encap
: constant Node_Id
:= Expression
(Opt
);
10581 Constits
: Elist_Id
;
10582 Encap_Id
: Entity_Id
;
10586 Check_Duplicate_Option
(Opt
, Part_Of_Seen
);
10589 (Indic
=> First
(Choices
(Opt
)),
10590 Item_Id
=> State_Id
,
10592 Encap_Id
=> Encap_Id
,
10595 -- The Part_Of indicator transforms the abstract state into
10596 -- a constituent of the encapsulating state or single
10597 -- concurrent type.
10600 pragma Assert
(Present
(Encap_Id
));
10601 Constits
:= Part_Of_Constituents
(Encap_Id
);
10603 if No
(Constits
) then
10604 Constits
:= New_Elmt_List
;
10605 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
10608 Append_Elmt
(State_Id
, Constits
);
10609 Set_Encapsulating_State
(State_Id
, Encap_Id
);
10611 end Analyze_Part_Of_Option
;
10613 ----------------------------
10614 -- Check_Duplicate_Option --
10615 ----------------------------
10617 procedure Check_Duplicate_Option
10619 Status
: in out Boolean)
10623 SPARK_Msg_N
("duplicate state option", Opt
);
10627 end Check_Duplicate_Option
;
10629 ------------------------------
10630 -- Check_Duplicate_Property --
10631 ------------------------------
10633 procedure Check_Duplicate_Property
10635 Status
: in out Boolean)
10639 SPARK_Msg_N
("duplicate external property", Prop
);
10643 end Check_Duplicate_Property
;
10645 -----------------------------
10646 -- Check_Ghost_Synchronous --
10647 -----------------------------
10649 procedure Check_Ghost_Synchronous
is
10651 -- A synchronized abstract state cannot be Ghost and vice
10652 -- versa (SPARK RM 6.9(19)).
10654 if Ghost_Seen
and Synchronous_Seen
then
10655 SPARK_Msg_N
("synchronized state cannot be ghost", State
);
10657 end Check_Ghost_Synchronous
;
10659 ---------------------------
10660 -- Create_Abstract_State --
10661 ---------------------------
10663 procedure Create_Abstract_State
10670 -- The abstract state may be semi-declared when the related
10671 -- package was withed through a limited with clause. In that
10672 -- case reuse the entity to fully declare the state.
10674 if Present
(Decl
) and then Present
(Entity
(Decl
)) then
10675 State_Id
:= Entity
(Decl
);
10677 -- Otherwise the elaboration of pragma Abstract_State
10678 -- declares the state.
10681 State_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
10683 if Present
(Decl
) then
10684 Set_Entity
(Decl
, State_Id
);
10688 -- Null states never come from source
10690 Set_Comes_From_Source
(State_Id
, not Is_Null
);
10691 Set_Parent
(State_Id
, State
);
10692 Set_Ekind
(State_Id
, E_Abstract_State
);
10693 Set_Etype
(State_Id
, Standard_Void_Type
);
10694 Set_Encapsulating_State
(State_Id
, Empty
);
10696 -- An abstract state declared within a Ghost region becomes
10697 -- Ghost (SPARK RM 6.9(2)).
10699 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Pack_Id
) then
10700 Set_Is_Ghost_Entity
(State_Id
);
10703 -- Establish a link between the state declaration and the
10704 -- abstract state entity. Note that a null state remains as
10705 -- N_Null and does not carry any linkages.
10707 if not Is_Null
then
10708 if Present
(Decl
) then
10709 Set_Entity
(Decl
, State_Id
);
10710 Set_Etype
(Decl
, Standard_Void_Type
);
10713 -- Every non-null state must be defined, nameable and
10716 Push_Scope
(Pack_Id
);
10717 Generate_Definition
(State_Id
);
10718 Enter_Name
(State_Id
);
10721 end Create_Abstract_State
;
10728 -- Start of processing for Analyze_Abstract_State
10731 -- A package with a null abstract state is not allowed to
10732 -- declare additional states.
10736 ("package & has null abstract state", State
, Pack_Id
);
10738 -- Null states appear as internally generated entities
10740 elsif Nkind
(State
) = N_Null
then
10741 Create_Abstract_State
10742 (Nam
=> New_Internal_Name
('S'),
10744 Loc
=> Sloc
(State
),
10748 -- Catch a case where a null state appears in a list of
10749 -- non-null states.
10751 if Non_Null_Seen
then
10753 ("package & has non-null abstract state",
10757 -- Simple state declaration
10759 elsif Nkind
(State
) = N_Identifier
then
10760 Create_Abstract_State
10761 (Nam
=> Chars
(State
),
10763 Loc
=> Sloc
(State
),
10765 Non_Null_Seen
:= True;
10767 -- State declaration with various options. This construct
10768 -- appears as an extension aggregate in the tree.
10770 elsif Nkind
(State
) = N_Extension_Aggregate
then
10771 if Nkind
(Ancestor_Part
(State
)) = N_Identifier
then
10772 Create_Abstract_State
10773 (Nam
=> Chars
(Ancestor_Part
(State
)),
10774 Decl
=> Ancestor_Part
(State
),
10775 Loc
=> Sloc
(Ancestor_Part
(State
)),
10777 Non_Null_Seen
:= True;
10780 ("state name must be an identifier",
10781 Ancestor_Part
(State
));
10784 -- Options External, Ghost and Synchronous appear as
10787 Opt
:= First
(Expressions
(State
));
10788 while Present
(Opt
) loop
10789 if Nkind
(Opt
) = N_Identifier
then
10793 if Chars
(Opt
) = Name_External
then
10794 Check_Duplicate_Option
(Opt
, External_Seen
);
10795 Analyze_External_Option
(Opt
);
10799 elsif Chars
(Opt
) = Name_Ghost
then
10800 Check_Duplicate_Option
(Opt
, Ghost_Seen
);
10801 Check_Ghost_Synchronous
;
10803 if Present
(State_Id
) then
10804 Set_Is_Ghost_Entity
(State_Id
);
10809 elsif Chars
(Opt
) = Name_Synchronous
then
10810 Check_Duplicate_Option
(Opt
, Synchronous_Seen
);
10811 Check_Ghost_Synchronous
;
10813 -- Option Part_Of without an encapsulating state is
10814 -- illegal (SPARK RM 7.1.4(9)).
10816 elsif Chars
(Opt
) = Name_Part_Of
then
10818 ("indicator Part_Of must denote abstract state, "
10819 & "single protected type or single task type",
10822 -- Do not emit an error message when a previous state
10823 -- declaration with options was not parenthesized as
10824 -- the option is actually another state declaration.
10826 -- with Abstract_State
10827 -- (State_1 with ..., -- missing parentheses
10828 -- (State_2 with ...),
10829 -- State_3) -- ok state declaration
10831 elsif Missing_Parentheses
then
10834 -- Otherwise the option is not allowed. Note that it
10835 -- is not possible to distinguish between an option
10836 -- and a state declaration when a previous state with
10837 -- options not properly parentheses.
10839 -- with Abstract_State
10840 -- (State_1 with ..., -- missing parentheses
10841 -- State_2); -- could be an option
10845 ("simple option not allowed in state declaration",
10849 -- Catch a case where missing parentheses around a state
10850 -- declaration with options cause a subsequent state
10851 -- declaration with options to be treated as an option.
10853 -- with Abstract_State
10854 -- (State_1 with ..., -- missing parentheses
10855 -- (State_2 with ...))
10857 elsif Nkind
(Opt
) = N_Extension_Aggregate
then
10858 Missing_Parentheses
:= True;
10860 ("state declaration must be parenthesized",
10861 Ancestor_Part
(State
));
10863 -- Otherwise the option is malformed
10866 SPARK_Msg_N
("malformed option", Opt
);
10872 -- Options External and Part_Of appear as component
10875 Opt
:= First
(Component_Associations
(State
));
10876 while Present
(Opt
) loop
10877 Opt_Nam
:= First
(Choices
(Opt
));
10879 if Nkind
(Opt_Nam
) = N_Identifier
then
10880 if Chars
(Opt_Nam
) = Name_External
then
10881 Analyze_External_Option
(Opt
);
10883 elsif Chars
(Opt_Nam
) = Name_Part_Of
then
10884 Analyze_Part_Of_Option
(Opt
);
10887 SPARK_Msg_N
("invalid state option", Opt
);
10890 SPARK_Msg_N
("invalid state option", Opt
);
10896 -- Any other attempt to declare a state is illegal
10899 Malformed_State_Error
(State
);
10903 -- Guard against a junk state. In such cases no entity is
10904 -- generated and the subsequent checks cannot be applied.
10906 if Present
(State_Id
) then
10908 -- Verify whether the state does not introduce an illegal
10909 -- hidden state within a package subject to a null abstract
10912 Check_No_Hidden_State
(State_Id
);
10914 -- Check whether the lack of option Part_Of agrees with the
10915 -- placement of the abstract state with respect to the state
10918 if not Part_Of_Seen
then
10919 Check_Missing_Part_Of
(State_Id
);
10922 -- Associate the state with its related package
10924 if No
(Abstract_States
(Pack_Id
)) then
10925 Set_Abstract_States
(Pack_Id
, New_Elmt_List
);
10928 Append_Elmt
(State_Id
, Abstract_States
(Pack_Id
));
10930 end Analyze_Abstract_State
;
10932 ---------------------------
10933 -- Malformed_State_Error --
10934 ---------------------------
10936 procedure Malformed_State_Error
(State
: Node_Id
) is
10938 Error_Msg_N
("malformed abstract state declaration", State
);
10940 -- An abstract state with a simple option is being declared
10941 -- with "=>" rather than the legal "with". The state appears
10942 -- as a component association.
10944 if Nkind
(State
) = N_Component_Association
then
10945 Error_Msg_N
("\use WITH to specify simple option", State
);
10947 end Malformed_State_Error
;
10951 Pack_Decl
: Node_Id
;
10952 Pack_Id
: Entity_Id
;
10956 -- Start of processing for Abstract_State
10960 Check_No_Identifiers
;
10961 Check_Arg_Count
(1);
10963 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
10965 -- Ensure the proper placement of the pragma. Abstract states must
10966 -- be associated with a package declaration.
10968 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
10969 N_Package_Declaration
)
10973 -- Otherwise the pragma is associated with an illegal construct
10980 Pack_Id
:= Defining_Entity
(Pack_Decl
);
10982 -- Chain the pragma on the contract for completeness
10984 Add_Contract_Item
(N
, Pack_Id
);
10986 -- The legality checks of pragmas Abstract_State, Initializes, and
10987 -- Initial_Condition are affected by the SPARK mode in effect. In
10988 -- addition, these three pragmas are subject to an inherent order:
10990 -- 1) Abstract_State
10992 -- 3) Initial_Condition
10994 -- Analyze all these pragmas in the order outlined above
10996 Analyze_If_Present
(Pragma_SPARK_Mode
);
10998 -- A pragma that applies to a Ghost entity becomes Ghost for the
10999 -- purposes of legality checks and removal of ignored Ghost code.
11001 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
11002 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
11004 States
:= Expression
(Get_Argument
(N
, Pack_Id
));
11006 -- Multiple non-null abstract states appear as an aggregate
11008 if Nkind
(States
) = N_Aggregate
then
11009 State
:= First
(Expressions
(States
));
11010 while Present
(State
) loop
11011 Analyze_Abstract_State
(State
, Pack_Id
);
11015 -- An abstract state with a simple option is being illegaly
11016 -- declared with "=>" rather than "with". In this case the
11017 -- state declaration appears as a component association.
11019 if Present
(Component_Associations
(States
)) then
11020 State
:= First
(Component_Associations
(States
));
11021 while Present
(State
) loop
11022 Malformed_State_Error
(State
);
11027 -- Various forms of a single abstract state. Note that these may
11028 -- include malformed state declarations.
11031 Analyze_Abstract_State
(States
, Pack_Id
);
11034 Analyze_If_Present
(Pragma_Initializes
);
11035 Analyze_If_Present
(Pragma_Initial_Condition
);
11036 end Abstract_State
;
11044 -- Note: this pragma also has some specific processing in Par.Prag
11045 -- because we want to set the Ada version mode during parsing.
11047 when Pragma_Ada_83
=>
11049 Check_Arg_Count
(0);
11051 -- We really should check unconditionally for proper configuration
11052 -- pragma placement, since we really don't want mixed Ada modes
11053 -- within a single unit, and the GNAT reference manual has always
11054 -- said this was a configuration pragma, but we did not check and
11055 -- are hesitant to add the check now.
11057 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
11058 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
11059 -- or Ada 2012 mode.
11061 if Ada_Version
>= Ada_2005
then
11062 Check_Valid_Configuration_Pragma
;
11065 -- Now set Ada 83 mode
11067 Ada_Version
:= Ada_83
;
11068 Ada_Version_Explicit
:= Ada_83
;
11069 Ada_Version_Pragma
:= N
;
11077 -- Note: this pragma also has some specific processing in Par.Prag
11078 -- because we want to set the Ada 83 version mode during parsing.
11080 when Pragma_Ada_95
=>
11082 Check_Arg_Count
(0);
11084 -- We really should check unconditionally for proper configuration
11085 -- pragma placement, since we really don't want mixed Ada modes
11086 -- within a single unit, and the GNAT reference manual has always
11087 -- said this was a configuration pragma, but we did not check and
11088 -- are hesitant to add the check now.
11090 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
11091 -- or Ada 95, so we must check if we are in Ada 2005 mode.
11093 if Ada_Version
>= Ada_2005
then
11094 Check_Valid_Configuration_Pragma
;
11097 -- Now set Ada 95 mode
11099 Ada_Version
:= Ada_95
;
11100 Ada_Version_Explicit
:= Ada_95
;
11101 Ada_Version_Pragma
:= N
;
11103 ---------------------
11104 -- Ada_05/Ada_2005 --
11105 ---------------------
11108 -- pragma Ada_05 (LOCAL_NAME);
11110 -- pragma Ada_2005;
11111 -- pragma Ada_2005 (LOCAL_NAME):
11113 -- Note: these pragmas also have some specific processing in Par.Prag
11114 -- because we want to set the Ada 2005 version mode during parsing.
11116 -- The one argument form is used for managing the transition from
11117 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
11118 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
11119 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
11120 -- mode, a preference rule is established which does not choose
11121 -- such an entity unless it is unambiguously specified. This avoids
11122 -- extra subprograms marked this way from generating ambiguities in
11123 -- otherwise legal pre-Ada_2005 programs. The one argument form is
11124 -- intended for exclusive use in the GNAT run-time library.
11126 when Pragma_Ada_05 | Pragma_Ada_2005
=> declare
11132 if Arg_Count
= 1 then
11133 Check_Arg_Is_Local_Name
(Arg1
);
11134 E_Id
:= Get_Pragma_Arg
(Arg1
);
11136 if Etype
(E_Id
) = Any_Type
then
11140 Set_Is_Ada_2005_Only
(Entity
(E_Id
));
11141 Record_Rep_Item
(Entity
(E_Id
), N
);
11144 Check_Arg_Count
(0);
11146 -- For Ada_2005 we unconditionally enforce the documented
11147 -- configuration pragma placement, since we do not want to
11148 -- tolerate mixed modes in a unit involving Ada 2005. That
11149 -- would cause real difficulties for those cases where there
11150 -- are incompatibilities between Ada 95 and Ada 2005.
11152 Check_Valid_Configuration_Pragma
;
11154 -- Now set appropriate Ada mode
11156 Ada_Version
:= Ada_2005
;
11157 Ada_Version_Explicit
:= Ada_2005
;
11158 Ada_Version_Pragma
:= N
;
11162 ---------------------
11163 -- Ada_12/Ada_2012 --
11164 ---------------------
11167 -- pragma Ada_12 (LOCAL_NAME);
11169 -- pragma Ada_2012;
11170 -- pragma Ada_2012 (LOCAL_NAME):
11172 -- Note: these pragmas also have some specific processing in Par.Prag
11173 -- because we want to set the Ada 2012 version mode during parsing.
11175 -- The one argument form is used for managing the transition from Ada
11176 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
11177 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
11178 -- mode will generate a warning. In addition, in any pre-Ada_2012
11179 -- mode, a preference rule is established which does not choose
11180 -- such an entity unless it is unambiguously specified. This avoids
11181 -- extra subprograms marked this way from generating ambiguities in
11182 -- otherwise legal pre-Ada_2012 programs. The one argument form is
11183 -- intended for exclusive use in the GNAT run-time library.
11185 when Pragma_Ada_12 | Pragma_Ada_2012
=> declare
11191 if Arg_Count
= 1 then
11192 Check_Arg_Is_Local_Name
(Arg1
);
11193 E_Id
:= Get_Pragma_Arg
(Arg1
);
11195 if Etype
(E_Id
) = Any_Type
then
11199 Set_Is_Ada_2012_Only
(Entity
(E_Id
));
11200 Record_Rep_Item
(Entity
(E_Id
), N
);
11203 Check_Arg_Count
(0);
11205 -- For Ada_2012 we unconditionally enforce the documented
11206 -- configuration pragma placement, since we do not want to
11207 -- tolerate mixed modes in a unit involving Ada 2012. That
11208 -- would cause real difficulties for those cases where there
11209 -- are incompatibilities between Ada 95 and Ada 2012. We could
11210 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
11212 Check_Valid_Configuration_Pragma
;
11214 -- Now set appropriate Ada mode
11216 Ada_Version
:= Ada_2012
;
11217 Ada_Version_Explicit
:= Ada_2012
;
11218 Ada_Version_Pragma
:= N
;
11222 ----------------------
11223 -- All_Calls_Remote --
11224 ----------------------
11226 -- pragma All_Calls_Remote [(library_package_NAME)];
11228 when Pragma_All_Calls_Remote
=> All_Calls_Remote
: declare
11229 Lib_Entity
: Entity_Id
;
11232 Check_Ada_83_Warning
;
11233 Check_Valid_Library_Unit_Pragma
;
11235 if Nkind
(N
) = N_Null_Statement
then
11239 Lib_Entity
:= Find_Lib_Unit_Name
;
11241 -- A pragma that applies to a Ghost entity becomes Ghost for the
11242 -- purposes of legality checks and removal of ignored Ghost code.
11244 Mark_Pragma_As_Ghost
(N
, Lib_Entity
);
11246 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11248 if Present
(Lib_Entity
) and then not Debug_Flag_U
then
11249 if not Is_Remote_Call_Interface
(Lib_Entity
) then
11250 Error_Pragma
("pragma% only apply to rci unit");
11252 -- Set flag for entity of the library unit
11255 Set_Has_All_Calls_Remote
(Lib_Entity
);
11258 end All_Calls_Remote
;
11260 ---------------------------
11261 -- Allow_Integer_Address --
11262 ---------------------------
11264 -- pragma Allow_Integer_Address;
11266 when Pragma_Allow_Integer_Address
=>
11268 Check_Valid_Configuration_Pragma
;
11269 Check_Arg_Count
(0);
11271 -- If Address is a private type, then set the flag to allow
11272 -- integer address values. If Address is not private, then this
11273 -- pragma has no purpose, so it is simply ignored. Not clear if
11274 -- there are any such targets now.
11276 if Opt
.Address_Is_Private
then
11277 Opt
.Allow_Integer_Address
:= True;
11285 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11286 -- ARG ::= NAME | EXPRESSION
11288 -- The first two arguments are by convention intended to refer to an
11289 -- external tool and a tool-specific function. These arguments are
11292 when Pragma_Annotate
=> Annotate
: declare
11299 Check_At_Least_N_Arguments
(1);
11301 Nam_Arg
:= Last
(Pragma_Argument_Associations
(N
));
11303 -- Determine whether the last argument is "Entity => local_NAME"
11304 -- and if it is, perform the required semantic checks. Remove the
11305 -- argument from further processing.
11307 if Nkind
(Nam_Arg
) = N_Pragma_Argument_Association
11308 and then Chars
(Nam_Arg
) = Name_Entity
11310 Check_Arg_Is_Local_Name
(Nam_Arg
);
11311 Arg_Count
:= Arg_Count
- 1;
11313 -- A pragma that applies to a Ghost entity becomes Ghost for
11314 -- the purposes of legality checks and removal of ignored Ghost
11317 if Is_Entity_Name
(Get_Pragma_Arg
(Nam_Arg
))
11318 and then Present
(Entity
(Get_Pragma_Arg
(Nam_Arg
)))
11320 Mark_Pragma_As_Ghost
(N
, Entity
(Get_Pragma_Arg
(Nam_Arg
)));
11323 -- Not allowed in compiler units (bootstrap issues)
11325 Check_Compiler_Unit
("Entity for pragma Annotate", N
);
11328 -- Continue the processing with last argument removed for now
11330 Check_Arg_Is_Identifier
(Arg1
);
11331 Check_No_Identifiers
;
11334 -- The second parameter is optional, it is never analyzed
11339 -- Otherwise there is a second parameter
11342 -- The second parameter must be an identifier
11344 Check_Arg_Is_Identifier
(Arg2
);
11346 -- Process the remaining parameters (if any)
11348 Arg
:= Next
(Arg2
);
11349 while Present
(Arg
) loop
11350 Expr
:= Get_Pragma_Arg
(Arg
);
11353 if Is_Entity_Name
(Expr
) then
11356 -- For string literals, we assume Standard_String as the
11357 -- type, unless the string contains wide or wide_wide
11360 elsif Nkind
(Expr
) = N_String_Literal
then
11361 if Has_Wide_Wide_Character
(Expr
) then
11362 Resolve
(Expr
, Standard_Wide_Wide_String
);
11363 elsif Has_Wide_Character
(Expr
) then
11364 Resolve
(Expr
, Standard_Wide_String
);
11366 Resolve
(Expr
, Standard_String
);
11369 elsif Is_Overloaded
(Expr
) then
11370 Error_Pragma_Arg
("ambiguous argument for pragma%", Expr
);
11381 -------------------------------------------------
11382 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11383 -------------------------------------------------
11386 -- ( [Check => ] Boolean_EXPRESSION
11387 -- [, [Message =>] Static_String_EXPRESSION]);
11389 -- pragma Assert_And_Cut
11390 -- ( [Check => ] Boolean_EXPRESSION
11391 -- [, [Message =>] Static_String_EXPRESSION]);
11394 -- ( [Check => ] Boolean_EXPRESSION
11395 -- [, [Message =>] Static_String_EXPRESSION]);
11397 -- pragma Loop_Invariant
11398 -- ( [Check => ] Boolean_EXPRESSION
11399 -- [, [Message =>] Static_String_EXPRESSION]);
11401 when Pragma_Assert |
11402 Pragma_Assert_And_Cut |
11404 Pragma_Loop_Invariant
=>
11406 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean;
11407 -- Determine whether expression Expr contains a Loop_Entry
11408 -- attribute reference.
11410 -------------------------
11411 -- Contains_Loop_Entry --
11412 -------------------------
11414 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean is
11415 Has_Loop_Entry
: Boolean := False;
11417 function Process
(N
: Node_Id
) return Traverse_Result
;
11418 -- Process function for traversal to look for Loop_Entry
11424 function Process
(N
: Node_Id
) return Traverse_Result
is
11426 if Nkind
(N
) = N_Attribute_Reference
11427 and then Attribute_Name
(N
) = Name_Loop_Entry
11429 Has_Loop_Entry
:= True;
11436 procedure Traverse
is new Traverse_Proc
(Process
);
11438 -- Start of processing for Contains_Loop_Entry
11442 return Has_Loop_Entry
;
11443 end Contains_Loop_Entry
;
11448 New_Args
: List_Id
;
11450 -- Start of processing for Assert
11453 -- Assert is an Ada 2005 RM-defined pragma
11455 if Prag_Id
= Pragma_Assert
then
11458 -- The remaining ones are GNAT pragmas
11464 Check_At_Least_N_Arguments
(1);
11465 Check_At_Most_N_Arguments
(2);
11466 Check_Arg_Order
((Name_Check
, Name_Message
));
11467 Check_Optional_Identifier
(Arg1
, Name_Check
);
11468 Expr
:= Get_Pragma_Arg
(Arg1
);
11470 -- Special processing for Loop_Invariant, Loop_Variant or for
11471 -- other cases where a Loop_Entry attribute is present. If the
11472 -- assertion pragma contains attribute Loop_Entry, ensure that
11473 -- the related pragma is within a loop.
11475 if Prag_Id
= Pragma_Loop_Invariant
11476 or else Prag_Id
= Pragma_Loop_Variant
11477 or else Contains_Loop_Entry
(Expr
)
11479 Check_Loop_Pragma_Placement
;
11481 -- Perform preanalysis to deal with embedded Loop_Entry
11484 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
11487 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11488 -- a corresponding Check pragma:
11490 -- pragma Check (name, condition [, msg]);
11492 -- Where name is the identifier matching the pragma name. So
11493 -- rewrite pragma in this manner, transfer the message argument
11494 -- if present, and analyze the result
11496 -- Note: When dealing with a semantically analyzed tree, the
11497 -- information that a Check node N corresponds to a source Assert,
11498 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11499 -- pragma kind of Original_Node(N).
11501 New_Args
:= New_List
(
11502 Make_Pragma_Argument_Association
(Loc
,
11503 Expression
=> Make_Identifier
(Loc
, Pname
)),
11504 Make_Pragma_Argument_Association
(Sloc
(Expr
),
11505 Expression
=> Expr
));
11507 if Arg_Count
> 1 then
11508 Check_Optional_Identifier
(Arg2
, Name_Message
);
11510 -- Provide semantic annnotations for optional argument, for
11511 -- ASIS use, before rewriting.
11513 Preanalyze_And_Resolve
(Expression
(Arg2
), Standard_String
);
11514 Append_To
(New_Args
, New_Copy_Tree
(Arg2
));
11517 -- Rewrite as Check pragma
11521 Chars
=> Name_Check
,
11522 Pragma_Argument_Associations
=> New_Args
));
11527 ----------------------
11528 -- Assertion_Policy --
11529 ----------------------
11531 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11533 -- The following form is Ada 2012 only, but we allow it in all modes
11535 -- Pragma Assertion_Policy (
11536 -- ASSERTION_KIND => POLICY_IDENTIFIER
11537 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11539 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11541 -- RM_ASSERTION_KIND ::= Assert |
11542 -- Static_Predicate |
11543 -- Dynamic_Predicate |
11548 -- Type_Invariant |
11549 -- Type_Invariant'Class
11551 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11553 -- Contract_Cases |
11555 -- Default_Initial_Condition |
11557 -- Initial_Condition |
11558 -- Loop_Invariant |
11564 -- Statement_Assertions
11566 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11567 -- ID_ASSERTION_KIND list contains implementation-defined additions
11568 -- recognized by GNAT. The effect is to control the behavior of
11569 -- identically named aspects and pragmas, depending on the specified
11570 -- policy identifier:
11572 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11574 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11575 -- implementation-defined addition that results in totally ignoring
11576 -- the corresponding assertion. If Disable is specified, then the
11577 -- argument of the assertion is not even analyzed. This is useful
11578 -- when the aspect/pragma argument references entities in a with'ed
11579 -- package that is replaced by a dummy package in the final build.
11581 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11582 -- and Type_Invariant'Class were recognized by the parser and
11583 -- transformed into references to the special internal identifiers
11584 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11585 -- processing is required here.
11587 when Pragma_Assertion_Policy
=> Assertion_Policy
: declare
11596 -- This can always appear as a configuration pragma
11598 if Is_Configuration_Pragma
then
11601 -- It can also appear in a declarative part or package spec in Ada
11602 -- 2012 mode. We allow this in other modes, but in that case we
11603 -- consider that we have an Ada 2012 pragma on our hands.
11606 Check_Is_In_Decl_Part_Or_Package_Spec
;
11610 -- One argument case with no identifier (first form above)
11613 and then (Nkind
(Arg1
) /= N_Pragma_Argument_Association
11614 or else Chars
(Arg1
) = No_Name
)
11616 Check_Arg_Is_One_Of
11617 (Arg1
, Name_Check
, Name_Disable
, Name_Ignore
);
11619 -- Treat one argument Assertion_Policy as equivalent to:
11621 -- pragma Check_Policy (Assertion, policy)
11623 -- So rewrite pragma in that manner and link on to the chain
11624 -- of Check_Policy pragmas, marking the pragma as analyzed.
11626 Policy
:= Get_Pragma_Arg
(Arg1
);
11630 Chars
=> Name_Check_Policy
,
11631 Pragma_Argument_Associations
=> New_List
(
11632 Make_Pragma_Argument_Association
(Loc
,
11633 Expression
=> Make_Identifier
(Loc
, Name_Assertion
)),
11635 Make_Pragma_Argument_Association
(Loc
,
11637 Make_Identifier
(Sloc
(Policy
), Chars
(Policy
))))));
11640 -- Here if we have two or more arguments
11643 Check_At_Least_N_Arguments
(1);
11646 -- Loop through arguments
11649 while Present
(Arg
) loop
11650 LocP
:= Sloc
(Arg
);
11652 -- Kind must be specified
11654 if Nkind
(Arg
) /= N_Pragma_Argument_Association
11655 or else Chars
(Arg
) = No_Name
11658 ("missing assertion kind for pragma%", Arg
);
11661 -- Check Kind and Policy have allowed forms
11663 Kind
:= Chars
(Arg
);
11664 Policy
:= Get_Pragma_Arg
(Arg
);
11666 if not Is_Valid_Assertion_Kind
(Kind
) then
11668 ("invalid assertion kind for pragma%", Arg
);
11671 Check_Arg_Is_One_Of
11672 (Arg
, Name_Check
, Name_Disable
, Name_Ignore
);
11674 if Kind
= Name_Ghost
then
11676 -- The Ghost policy must be either Check or Ignore
11677 -- (SPARK RM 6.9(6)).
11679 if not Nam_In
(Chars
(Policy
), Name_Check
,
11683 ("argument of pragma % Ghost must be Check or "
11684 & "Ignore", Policy
);
11687 -- Pragma Assertion_Policy specifying a Ghost policy
11688 -- cannot occur within a Ghost subprogram or package
11689 -- (SPARK RM 6.9(14)).
11691 if Ghost_Mode
> None
then
11693 ("pragma % cannot appear within ghost subprogram or "
11698 -- Rewrite the Assertion_Policy pragma as a series of
11699 -- Check_Policy pragmas of the form:
11701 -- Check_Policy (Kind, Policy);
11703 -- Note: the insertion of the pragmas cannot be done with
11704 -- Insert_Action because in the configuration case, there
11705 -- are no scopes on the scope stack and the mechanism will
11708 Insert_Before_And_Analyze
(N
,
11710 Chars
=> Name_Check_Policy
,
11711 Pragma_Argument_Associations
=> New_List
(
11712 Make_Pragma_Argument_Association
(LocP
,
11713 Expression
=> Make_Identifier
(LocP
, Kind
)),
11714 Make_Pragma_Argument_Association
(LocP
,
11715 Expression
=> Policy
))));
11720 -- Rewrite the Assertion_Policy pragma as null since we have
11721 -- now inserted all the equivalent Check pragmas.
11723 Rewrite
(N
, Make_Null_Statement
(Loc
));
11726 end Assertion_Policy
;
11728 ------------------------------
11729 -- Assume_No_Invalid_Values --
11730 ------------------------------
11732 -- pragma Assume_No_Invalid_Values (On | Off);
11734 when Pragma_Assume_No_Invalid_Values
=>
11736 Check_Valid_Configuration_Pragma
;
11737 Check_Arg_Count
(1);
11738 Check_No_Identifiers
;
11739 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
11741 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
11742 Assume_No_Invalid_Values
:= True;
11744 Assume_No_Invalid_Values
:= False;
11747 --------------------------
11748 -- Attribute_Definition --
11749 --------------------------
11751 -- pragma Attribute_Definition
11752 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11753 -- [Entity =>] LOCAL_NAME,
11754 -- [Expression =>] EXPRESSION | NAME);
11756 when Pragma_Attribute_Definition
=> Attribute_Definition
: declare
11757 Attribute_Designator
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
11762 Check_Arg_Count
(3);
11763 Check_Optional_Identifier
(Arg1
, "attribute");
11764 Check_Optional_Identifier
(Arg2
, "entity");
11765 Check_Optional_Identifier
(Arg3
, "expression");
11767 if Nkind
(Attribute_Designator
) /= N_Identifier
then
11768 Error_Msg_N
("attribute name expected", Attribute_Designator
);
11772 Check_Arg_Is_Local_Name
(Arg2
);
11774 -- If the attribute is not recognized, then issue a warning (not
11775 -- an error), and ignore the pragma.
11777 Aname
:= Chars
(Attribute_Designator
);
11779 if not Is_Attribute_Name
(Aname
) then
11780 Bad_Attribute
(Attribute_Designator
, Aname
, Warn
=> True);
11784 -- Otherwise, rewrite the pragma as an attribute definition clause
11787 Make_Attribute_Definition_Clause
(Loc
,
11788 Name
=> Get_Pragma_Arg
(Arg2
),
11790 Expression
=> Get_Pragma_Arg
(Arg3
)));
11792 end Attribute_Definition
;
11794 ------------------------------------------------------------------
11795 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11796 ------------------------------------------------------------------
11798 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
11799 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
11800 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
11801 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
11803 when Pragma_Async_Readers |
11804 Pragma_Async_Writers |
11805 Pragma_Effective_Reads |
11806 Pragma_Effective_Writes
=>
11807 Async_Effective
: declare
11808 Obj_Decl
: Node_Id
;
11809 Obj_Id
: Entity_Id
;
11813 Check_No_Identifiers
;
11814 Check_At_Most_N_Arguments
(1);
11816 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
11818 -- Object declaration
11820 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
11823 -- Otherwise the pragma is associated with an illegal construact
11830 Obj_Id
:= Defining_Entity
(Obj_Decl
);
11832 -- Perform minimal verification to ensure that the argument is at
11833 -- least a variable. Subsequent finer grained checks will be done
11834 -- at the end of the declarative region the contains the pragma.
11836 if Ekind
(Obj_Id
) = E_Variable
then
11838 -- Chain the pragma on the contract for further processing by
11839 -- Analyze_External_Property_In_Decl_Part.
11841 Add_Contract_Item
(N
, Obj_Id
);
11843 -- A pragma that applies to a Ghost entity becomes Ghost for
11844 -- the purposes of legality checks and removal of ignored Ghost
11847 Mark_Pragma_As_Ghost
(N
, Obj_Id
);
11849 -- Analyze the Boolean expression (if any)
11851 if Present
(Arg1
) then
11852 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
11855 -- Otherwise the external property applies to a constant
11858 Error_Pragma
("pragma % must apply to a volatile object");
11860 end Async_Effective
;
11866 -- pragma Asynchronous (LOCAL_NAME);
11868 when Pragma_Asynchronous
=> Asynchronous
: declare
11871 Formal
: Entity_Id
;
11876 procedure Process_Async_Pragma
;
11877 -- Common processing for procedure and access-to-procedure case
11879 --------------------------
11880 -- Process_Async_Pragma --
11881 --------------------------
11883 procedure Process_Async_Pragma
is
11886 Set_Is_Asynchronous
(Nm
);
11890 -- The formals should be of mode IN (RM E.4.1(6))
11893 while Present
(S
) loop
11894 Formal
:= Defining_Identifier
(S
);
11896 if Nkind
(Formal
) = N_Defining_Identifier
11897 and then Ekind
(Formal
) /= E_In_Parameter
11900 ("pragma% procedure can only have IN parameter",
11907 Set_Is_Asynchronous
(Nm
);
11908 end Process_Async_Pragma
;
11910 -- Start of processing for pragma Asynchronous
11913 Check_Ada_83_Warning
;
11914 Check_No_Identifiers
;
11915 Check_Arg_Count
(1);
11916 Check_Arg_Is_Local_Name
(Arg1
);
11918 if Debug_Flag_U
then
11922 C_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
11923 Analyze
(Get_Pragma_Arg
(Arg1
));
11924 Nm
:= Entity
(Get_Pragma_Arg
(Arg1
));
11926 -- A pragma that applies to a Ghost entity becomes Ghost for the
11927 -- purposes of legality checks and removal of ignored Ghost code.
11929 Mark_Pragma_As_Ghost
(N
, Nm
);
11931 if not Is_Remote_Call_Interface
(C_Ent
)
11932 and then not Is_Remote_Types
(C_Ent
)
11934 -- This pragma should only appear in an RCI or Remote Types
11935 -- unit (RM E.4.1(4)).
11938 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11941 if Ekind
(Nm
) = E_Procedure
11942 and then Nkind
(Parent
(Nm
)) = N_Procedure_Specification
11944 if not Is_Remote_Call_Interface
(Nm
) then
11946 ("pragma% cannot be applied on non-remote procedure",
11950 L
:= Parameter_Specifications
(Parent
(Nm
));
11951 Process_Async_Pragma
;
11954 elsif Ekind
(Nm
) = E_Function
then
11956 ("pragma% cannot be applied to function", Arg1
);
11958 elsif Is_Remote_Access_To_Subprogram_Type
(Nm
) then
11959 if Is_Record_Type
(Nm
) then
11961 -- A record type that is the Equivalent_Type for a remote
11962 -- access-to-subprogram type.
11964 Decl
:= Declaration_Node
(Corresponding_Remote_Type
(Nm
));
11967 -- A non-expanded RAS type (distribution is not enabled)
11969 Decl
:= Declaration_Node
(Nm
);
11972 if Nkind
(Decl
) = N_Full_Type_Declaration
11973 and then Nkind
(Type_Definition
(Decl
)) =
11974 N_Access_Procedure_Definition
11976 L
:= Parameter_Specifications
(Type_Definition
(Decl
));
11977 Process_Async_Pragma
;
11979 if Is_Asynchronous
(Nm
)
11980 and then Expander_Active
11981 and then Get_PCS_Name
/= Name_No_DSA
11983 RACW_Type_Is_Asynchronous
(Underlying_RACW_Type
(Nm
));
11988 ("pragma% cannot reference access-to-function type",
11992 -- Only other possibility is Access-to-class-wide type
11994 elsif Is_Access_Type
(Nm
)
11995 and then Is_Class_Wide_Type
(Designated_Type
(Nm
))
11997 Check_First_Subtype
(Arg1
);
11998 Set_Is_Asynchronous
(Nm
);
11999 if Expander_Active
then
12000 RACW_Type_Is_Asynchronous
(Nm
);
12004 Error_Pragma_Arg
("inappropriate argument for pragma%", Arg1
);
12012 -- pragma Atomic (LOCAL_NAME);
12014 when Pragma_Atomic
=>
12015 Process_Atomic_Independent_Shared_Volatile
;
12017 -----------------------
12018 -- Atomic_Components --
12019 -----------------------
12021 -- pragma Atomic_Components (array_LOCAL_NAME);
12023 -- This processing is shared by Volatile_Components
12025 when Pragma_Atomic_Components |
12026 Pragma_Volatile_Components
=>
12027 Atomic_Components
: declare
12034 Check_Ada_83_Warning
;
12035 Check_No_Identifiers
;
12036 Check_Arg_Count
(1);
12037 Check_Arg_Is_Local_Name
(Arg1
);
12038 E_Id
:= Get_Pragma_Arg
(Arg1
);
12040 if Etype
(E_Id
) = Any_Type
then
12044 E
:= Entity
(E_Id
);
12046 -- A pragma that applies to a Ghost entity becomes Ghost for the
12047 -- purposes of legality checks and removal of ignored Ghost code.
12049 Mark_Pragma_As_Ghost
(N
, E
);
12050 Check_Duplicate_Pragma
(E
);
12052 if Rep_Item_Too_Early
(E
, N
)
12054 Rep_Item_Too_Late
(E
, N
)
12059 D
:= Declaration_Node
(E
);
12062 if (K
= N_Full_Type_Declaration
and then Is_Array_Type
(E
))
12064 ((Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
12065 and then Nkind
(D
) = N_Object_Declaration
12066 and then Nkind
(Object_Definition
(D
)) =
12067 N_Constrained_Array_Definition
)
12069 -- The flag is set on the object, or on the base type
12071 if Nkind
(D
) /= N_Object_Declaration
then
12072 E
:= Base_Type
(E
);
12075 -- Atomic implies both Independent and Volatile
12077 if Prag_Id
= Pragma_Atomic_Components
then
12078 Set_Has_Atomic_Components
(E
);
12079 Set_Has_Independent_Components
(E
);
12082 Set_Has_Volatile_Components
(E
);
12085 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
12087 end Atomic_Components
;
12089 --------------------
12090 -- Attach_Handler --
12091 --------------------
12093 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
12095 when Pragma_Attach_Handler
=>
12096 Check_Ada_83_Warning
;
12097 Check_No_Identifiers
;
12098 Check_Arg_Count
(2);
12100 if No_Run_Time_Mode
then
12101 Error_Msg_CRT
("Attach_Handler pragma", N
);
12103 Check_Interrupt_Or_Attach_Handler
;
12105 -- The expression that designates the attribute may depend on a
12106 -- discriminant, and is therefore a per-object expression, to
12107 -- be expanded in the init proc. If expansion is enabled, then
12108 -- perform semantic checks on a copy only.
12113 Parg2
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
12116 -- In Relaxed_RM_Semantics mode, we allow any static
12117 -- integer value, for compatibility with other compilers.
12119 if Relaxed_RM_Semantics
12120 and then Nkind
(Parg2
) = N_Integer_Literal
12122 Typ
:= Standard_Integer
;
12124 Typ
:= RTE
(RE_Interrupt_ID
);
12127 if Expander_Active
then
12128 Temp
:= New_Copy_Tree
(Parg2
);
12129 Set_Parent
(Temp
, N
);
12130 Preanalyze_And_Resolve
(Temp
, Typ
);
12133 Resolve
(Parg2
, Typ
);
12137 Process_Interrupt_Or_Attach_Handler
;
12140 --------------------
12141 -- C_Pass_By_Copy --
12142 --------------------
12144 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
12146 when Pragma_C_Pass_By_Copy
=> C_Pass_By_Copy
: declare
12152 Check_Valid_Configuration_Pragma
;
12153 Check_Arg_Count
(1);
12154 Check_Optional_Identifier
(Arg1
, "max_size");
12156 Arg
:= Get_Pragma_Arg
(Arg1
);
12157 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
12159 Val
:= Expr_Value
(Arg
);
12163 ("maximum size for pragma% must be positive", Arg1
);
12165 elsif UI_Is_In_Int_Range
(Val
) then
12166 Default_C_Record_Mechanism
:= UI_To_Int
(Val
);
12168 -- If a giant value is given, Int'Last will do well enough.
12169 -- If sometime someone complains that a record larger than
12170 -- two gigabytes is not copied, we will worry about it then.
12173 Default_C_Record_Mechanism
:= Mechanism_Type
'Last;
12175 end C_Pass_By_Copy
;
12181 -- pragma Check ([Name =>] CHECK_KIND,
12182 -- [Check =>] Boolean_EXPRESSION
12183 -- [,[Message =>] String_EXPRESSION]);
12185 -- CHECK_KIND ::= IDENTIFIER |
12188 -- Invariant'Class |
12189 -- Type_Invariant'Class
12191 -- The identifiers Assertions and Statement_Assertions are not
12192 -- allowed, since they have special meaning for Check_Policy.
12194 when Pragma_Check
=> Check
: declare
12200 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
12203 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
12204 -- the mode now to ensure that any nodes generated during analysis
12205 -- and expansion are marked as Ghost.
12207 Set_Ghost_Mode
(N
);
12210 Check_At_Least_N_Arguments
(2);
12211 Check_At_Most_N_Arguments
(3);
12212 Check_Optional_Identifier
(Arg1
, Name_Name
);
12213 Check_Optional_Identifier
(Arg2
, Name_Check
);
12215 if Arg_Count
= 3 then
12216 Check_Optional_Identifier
(Arg3
, Name_Message
);
12217 Str
:= Get_Pragma_Arg
(Arg3
);
12220 Rewrite_Assertion_Kind
(Get_Pragma_Arg
(Arg1
));
12221 Check_Arg_Is_Identifier
(Arg1
);
12222 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
12224 -- Check forbidden name Assertions or Statement_Assertions
12227 when Name_Assertions
=>
12229 ("""Assertions"" is not allowed as a check kind for "
12230 & "pragma%", Arg1
);
12232 when Name_Statement_Assertions
=>
12234 ("""Statement_Assertions"" is not allowed as a check kind "
12235 & "for pragma%", Arg1
);
12241 -- Check applicable policy. We skip this if Checked/Ignored status
12242 -- is already set (e.g. in the case of a pragma from an aspect).
12244 if Is_Checked
(N
) or else Is_Ignored
(N
) then
12247 -- For a non-source pragma that is a rewriting of another pragma,
12248 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12250 elsif Is_Rewrite_Substitution
(N
)
12251 and then Nkind
(Original_Node
(N
)) = N_Pragma
12252 and then Original_Node
(N
) /= N
12254 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
12255 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
12257 -- Otherwise query the applicable policy at this point
12260 case Check_Kind
(Cname
) is
12261 when Name_Ignore
=>
12262 Set_Is_Ignored
(N
, True);
12263 Set_Is_Checked
(N
, False);
12266 Set_Is_Ignored
(N
, False);
12267 Set_Is_Checked
(N
, True);
12269 -- For disable, rewrite pragma as null statement and skip
12270 -- rest of the analysis of the pragma.
12272 when Name_Disable
=>
12273 Rewrite
(N
, Make_Null_Statement
(Loc
));
12277 -- No other possibilities
12280 raise Program_Error
;
12284 -- If check kind was not Disable, then continue pragma analysis
12286 Expr
:= Get_Pragma_Arg
(Arg2
);
12288 -- Deal with SCO generation
12292 -- Nothing to do for predicates as the checks occur in the
12293 -- client units. The SCO for the aspect in the declaration
12294 -- unit is conservatively always enabled.
12296 when Name_Predicate
=>
12299 -- Otherwise mark aspect/pragma SCO as enabled
12302 if Is_Checked
(N
) and then not Split_PPC
(N
) then
12303 Set_SCO_Pragma_Enabled
(Loc
);
12307 -- Deal with analyzing the string argument
12309 if Arg_Count
= 3 then
12311 -- If checks are not on we don't want any expansion (since
12312 -- such expansion would not get properly deleted) but
12313 -- we do want to analyze (to get proper references).
12314 -- The Preanalyze_And_Resolve routine does just what we want
12316 if Is_Ignored
(N
) then
12317 Preanalyze_And_Resolve
(Str
, Standard_String
);
12319 -- Otherwise we need a proper analysis and expansion
12322 Analyze_And_Resolve
(Str
, Standard_String
);
12326 -- Now you might think we could just do the same with the Boolean
12327 -- expression if checks are off (and expansion is on) and then
12328 -- rewrite the check as a null statement. This would work but we
12329 -- would lose the useful warnings about an assertion being bound
12330 -- to fail even if assertions are turned off.
12332 -- So instead we wrap the boolean expression in an if statement
12333 -- that looks like:
12335 -- if False and then condition then
12339 -- The reason we do this rewriting during semantic analysis rather
12340 -- than as part of normal expansion is that we cannot analyze and
12341 -- expand the code for the boolean expression directly, or it may
12342 -- cause insertion of actions that would escape the attempt to
12343 -- suppress the check code.
12345 -- Note that the Sloc for the if statement corresponds to the
12346 -- argument condition, not the pragma itself. The reason for
12347 -- this is that we may generate a warning if the condition is
12348 -- False at compile time, and we do not want to delete this
12349 -- warning when we delete the if statement.
12351 if Expander_Active
and Is_Ignored
(N
) then
12352 Eloc
:= Sloc
(Expr
);
12355 Make_If_Statement
(Eloc
,
12357 Make_And_Then
(Eloc
,
12358 Left_Opnd
=> Make_Identifier
(Eloc
, Name_False
),
12359 Right_Opnd
=> Expr
),
12360 Then_Statements
=> New_List
(
12361 Make_Null_Statement
(Eloc
))));
12363 -- Now go ahead and analyze the if statement
12365 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
12367 -- One rather special treatment. If we are now in Eliminated
12368 -- overflow mode, then suppress overflow checking since we do
12369 -- not want to drag in the bignum stuff if we are in Ignore
12370 -- mode anyway. This is particularly important if we are using
12371 -- a configurable run time that does not support bignum ops.
12373 if Scope_Suppress
.Overflow_Mode_Assertions
= Eliminated
then
12375 Svo
: constant Boolean :=
12376 Scope_Suppress
.Suppress
(Overflow_Check
);
12378 Scope_Suppress
.Overflow_Mode_Assertions
:= Strict
;
12379 Scope_Suppress
.Suppress
(Overflow_Check
) := True;
12381 Scope_Suppress
.Suppress
(Overflow_Check
) := Svo
;
12382 Scope_Suppress
.Overflow_Mode_Assertions
:= Eliminated
;
12385 -- Not that special case
12391 -- All done with this check
12393 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
12395 -- Check is active or expansion not active. In these cases we can
12396 -- just go ahead and analyze the boolean with no worries.
12399 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
12400 Analyze_And_Resolve
(Expr
, Any_Boolean
);
12401 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
12404 Ghost_Mode
:= Save_Ghost_Mode
;
12407 --------------------------
12408 -- Check_Float_Overflow --
12409 --------------------------
12411 -- pragma Check_Float_Overflow;
12413 when Pragma_Check_Float_Overflow
=>
12415 Check_Valid_Configuration_Pragma
;
12416 Check_Arg_Count
(0);
12417 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
12423 -- pragma Check_Name (check_IDENTIFIER);
12425 when Pragma_Check_Name
=>
12427 Check_No_Identifiers
;
12428 Check_Valid_Configuration_Pragma
;
12429 Check_Arg_Count
(1);
12430 Check_Arg_Is_Identifier
(Arg1
);
12433 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
12436 for J
in Check_Names
.First
.. Check_Names
.Last
loop
12437 if Check_Names
.Table
(J
) = Nam
then
12442 Check_Names
.Append
(Nam
);
12449 -- This is the old style syntax, which is still allowed in all modes:
12451 -- pragma Check_Policy ([Name =>] CHECK_KIND
12452 -- [Policy =>] POLICY_IDENTIFIER);
12454 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12456 -- CHECK_KIND ::= IDENTIFIER |
12459 -- Type_Invariant'Class |
12462 -- This is the new style syntax, compatible with Assertion_Policy
12463 -- and also allowed in all modes.
12465 -- Pragma Check_Policy (
12466 -- CHECK_KIND => POLICY_IDENTIFIER
12467 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12469 -- Note: the identifiers Name and Policy are not allowed as
12470 -- Check_Kind values. This avoids ambiguities between the old and
12471 -- new form syntax.
12473 when Pragma_Check_Policy
=> Check_Policy
: declare
12478 Check_At_Least_N_Arguments
(1);
12480 -- A Check_Policy pragma can appear either as a configuration
12481 -- pragma, or in a declarative part or a package spec (see RM
12482 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12483 -- followed for Check_Policy).
12485 if not Is_Configuration_Pragma
then
12486 Check_Is_In_Decl_Part_Or_Package_Spec
;
12489 -- Figure out if we have the old or new syntax. We have the
12490 -- old syntax if the first argument has no identifier, or the
12491 -- identifier is Name.
12493 if Nkind
(Arg1
) /= N_Pragma_Argument_Association
12494 or else Nam_In
(Chars
(Arg1
), No_Name
, Name_Name
)
12498 Check_Arg_Count
(2);
12499 Check_Optional_Identifier
(Arg1
, Name_Name
);
12500 Kind
:= Get_Pragma_Arg
(Arg1
);
12501 Rewrite_Assertion_Kind
(Kind
);
12502 Check_Arg_Is_Identifier
(Arg1
);
12504 -- Check forbidden check kind
12506 if Nam_In
(Chars
(Kind
), Name_Name
, Name_Policy
) then
12507 Error_Msg_Name_2
:= Chars
(Kind
);
12509 ("pragma% does not allow% as check name", Arg1
);
12514 Check_Optional_Identifier
(Arg2
, Name_Policy
);
12515 Check_Arg_Is_One_Of
12517 Name_On
, Name_Off
, Name_Check
, Name_Disable
, Name_Ignore
);
12519 -- And chain pragma on the Check_Policy_List for search
12521 Set_Next_Pragma
(N
, Opt
.Check_Policy_List
);
12522 Opt
.Check_Policy_List
:= N
;
12524 -- For the new syntax, what we do is to convert each argument to
12525 -- an old syntax equivalent. We do that because we want to chain
12526 -- old style Check_Policy pragmas for the search (we don't want
12527 -- to have to deal with multiple arguments in the search).
12538 while Present
(Arg
) loop
12539 LocP
:= Sloc
(Arg
);
12540 Argx
:= Get_Pragma_Arg
(Arg
);
12542 -- Kind must be specified
12544 if Nkind
(Arg
) /= N_Pragma_Argument_Association
12545 or else Chars
(Arg
) = No_Name
12548 ("missing assertion kind for pragma%", Arg
);
12551 -- Construct equivalent old form syntax Check_Policy
12552 -- pragma and insert it to get remaining checks.
12556 Chars
=> Name_Check_Policy
,
12557 Pragma_Argument_Associations
=> New_List
(
12558 Make_Pragma_Argument_Association
(LocP
,
12560 Make_Identifier
(LocP
, Chars
(Arg
))),
12561 Make_Pragma_Argument_Association
(Sloc
(Argx
),
12562 Expression
=> Argx
)));
12566 -- For a configuration pragma, insert old form in
12567 -- the corresponding file.
12569 if Is_Configuration_Pragma
then
12570 Insert_After
(N
, New_P
);
12574 Insert_Action
(N
, New_P
);
12578 -- Rewrite original Check_Policy pragma to null, since we
12579 -- have converted it into a series of old syntax pragmas.
12581 Rewrite
(N
, Make_Null_Statement
(Loc
));
12591 -- pragma Comment (static_string_EXPRESSION)
12593 -- Processing for pragma Comment shares the circuitry for pragma
12594 -- Ident. The only differences are that Ident enforces a limit of 31
12595 -- characters on its argument, and also enforces limitations on
12596 -- placement for DEC compatibility. Pragma Comment shares neither of
12597 -- these restrictions.
12599 -------------------
12600 -- Common_Object --
12601 -------------------
12603 -- pragma Common_Object (
12604 -- [Internal =>] LOCAL_NAME
12605 -- [, [External =>] EXTERNAL_SYMBOL]
12606 -- [, [Size =>] EXTERNAL_SYMBOL]);
12608 -- Processing for this pragma is shared with Psect_Object
12610 ------------------------
12611 -- Compile_Time_Error --
12612 ------------------------
12614 -- pragma Compile_Time_Error
12615 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12617 when Pragma_Compile_Time_Error
=>
12619 Process_Compile_Time_Warning_Or_Error
;
12621 --------------------------
12622 -- Compile_Time_Warning --
12623 --------------------------
12625 -- pragma Compile_Time_Warning
12626 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12628 when Pragma_Compile_Time_Warning
=>
12630 Process_Compile_Time_Warning_Or_Error
;
12632 ---------------------------
12633 -- Compiler_Unit_Warning --
12634 ---------------------------
12636 -- pragma Compiler_Unit_Warning;
12640 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12641 -- errors not warnings. This means that we had introduced a big extra
12642 -- inertia to compiler changes, since even if we implemented a new
12643 -- feature, and even if all versions to be used for bootstrapping
12644 -- implemented this new feature, we could not use it, since old
12645 -- compilers would give errors for using this feature in units
12646 -- having Compiler_Unit pragmas.
12648 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12649 -- problem. We no longer have any units mentioning Compiler_Unit,
12650 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12651 -- and thus generates a warning which can be ignored. So that deals
12652 -- with the problem of old compilers not implementing the newer form
12655 -- Newer compilers recognize the new pragma, but generate warning
12656 -- messages instead of errors, which again can be ignored in the
12657 -- case of an old compiler which implements a wanted new feature
12658 -- but at the time felt like warning about it for older compilers.
12660 -- We retain Compiler_Unit so that new compilers can be used to build
12661 -- older run-times that use this pragma. That's an unusual case, but
12662 -- it's easy enough to handle, so why not?
12664 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning
=>
12666 Check_Arg_Count
(0);
12668 -- Only recognized in main unit
12670 if Current_Sem_Unit
= Main_Unit
then
12671 Compiler_Unit
:= True;
12674 -----------------------------
12675 -- Complete_Representation --
12676 -----------------------------
12678 -- pragma Complete_Representation;
12680 when Pragma_Complete_Representation
=>
12682 Check_Arg_Count
(0);
12684 if Nkind
(Parent
(N
)) /= N_Record_Representation_Clause
then
12686 ("pragma & must appear within record representation clause");
12689 ----------------------------
12690 -- Complex_Representation --
12691 ----------------------------
12693 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12695 when Pragma_Complex_Representation
=> Complex_Representation
: declare
12702 Check_Arg_Count
(1);
12703 Check_Optional_Identifier
(Arg1
, Name_Entity
);
12704 Check_Arg_Is_Local_Name
(Arg1
);
12705 E_Id
:= Get_Pragma_Arg
(Arg1
);
12707 if Etype
(E_Id
) = Any_Type
then
12711 E
:= Entity
(E_Id
);
12713 if not Is_Record_Type
(E
) then
12715 ("argument for pragma% must be record type", Arg1
);
12718 Ent
:= First_Entity
(E
);
12721 or else No
(Next_Entity
(Ent
))
12722 or else Present
(Next_Entity
(Next_Entity
(Ent
)))
12723 or else not Is_Floating_Point_Type
(Etype
(Ent
))
12724 or else Etype
(Ent
) /= Etype
(Next_Entity
(Ent
))
12727 ("record for pragma% must have two fields of the same "
12728 & "floating-point type", Arg1
);
12731 Set_Has_Complex_Representation
(Base_Type
(E
));
12733 -- We need to treat the type has having a non-standard
12734 -- representation, for back-end purposes, even though in
12735 -- general a complex will have the default representation
12736 -- of a record with two real components.
12738 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
12740 end Complex_Representation
;
12742 -------------------------
12743 -- Component_Alignment --
12744 -------------------------
12746 -- pragma Component_Alignment (
12747 -- [Form =>] ALIGNMENT_CHOICE
12748 -- [, [Name =>] type_LOCAL_NAME]);
12750 -- ALIGNMENT_CHOICE ::=
12752 -- | Component_Size_4
12756 when Pragma_Component_Alignment
=> Component_AlignmentP
: declare
12757 Args
: Args_List
(1 .. 2);
12758 Names
: constant Name_List
(1 .. 2) := (
12762 Form
: Node_Id
renames Args
(1);
12763 Name
: Node_Id
renames Args
(2);
12765 Atype
: Component_Alignment_Kind
;
12770 Gather_Associations
(Names
, Args
);
12773 Error_Pragma
("missing Form argument for pragma%");
12776 Check_Arg_Is_Identifier
(Form
);
12778 -- Get proper alignment, note that Default = Component_Size on all
12779 -- machines we have so far, and we want to set this value rather
12780 -- than the default value to indicate that it has been explicitly
12781 -- set (and thus will not get overridden by the default component
12782 -- alignment for the current scope)
12784 if Chars
(Form
) = Name_Component_Size
then
12785 Atype
:= Calign_Component_Size
;
12787 elsif Chars
(Form
) = Name_Component_Size_4
then
12788 Atype
:= Calign_Component_Size_4
;
12790 elsif Chars
(Form
) = Name_Default
then
12791 Atype
:= Calign_Component_Size
;
12793 elsif Chars
(Form
) = Name_Storage_Unit
then
12794 Atype
:= Calign_Storage_Unit
;
12798 ("invalid Form parameter for pragma%", Form
);
12801 -- Case with no name, supplied, affects scope table entry
12805 (Scope_Stack
.Last
).Component_Alignment_Default
:= Atype
;
12807 -- Case of name supplied
12810 Check_Arg_Is_Local_Name
(Name
);
12812 Typ
:= Entity
(Name
);
12815 or else Rep_Item_Too_Early
(Typ
, N
)
12819 Typ
:= Underlying_Type
(Typ
);
12822 if not Is_Record_Type
(Typ
)
12823 and then not Is_Array_Type
(Typ
)
12826 ("Name parameter of pragma% must identify record or "
12827 & "array type", Name
);
12830 -- An explicit Component_Alignment pragma overrides an
12831 -- implicit pragma Pack, but not an explicit one.
12833 if not Has_Pragma_Pack
(Base_Type
(Typ
)) then
12834 Set_Is_Packed
(Base_Type
(Typ
), False);
12835 Set_Component_Alignment
(Base_Type
(Typ
), Atype
);
12838 end Component_AlignmentP
;
12840 --------------------------------
12841 -- Constant_After_Elaboration --
12842 --------------------------------
12844 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
12846 when Pragma_Constant_After_Elaboration
=> Constant_After_Elaboration
:
12848 Obj_Decl
: Node_Id
;
12849 Obj_Id
: Entity_Id
;
12853 Check_No_Identifiers
;
12854 Check_At_Most_N_Arguments
(1);
12856 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
12858 -- Object declaration
12860 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
12863 -- Otherwise the pragma is associated with an illegal construct
12870 Obj_Id
:= Defining_Entity
(Obj_Decl
);
12872 -- The object declaration must be a library-level variable which
12873 -- is either explicitly initialized or obtains a value during the
12874 -- elaboration of a package body (SPARK RM 3.3.1).
12876 if Ekind
(Obj_Id
) = E_Variable
then
12877 if not Is_Library_Level_Entity
(Obj_Id
) then
12879 ("pragma % must apply to a library level variable");
12883 -- Otherwise the pragma applies to a constant, which is illegal
12886 Error_Pragma
("pragma % must apply to a variable declaration");
12890 -- Chain the pragma on the contract for completeness
12892 Add_Contract_Item
(N
, Obj_Id
);
12894 -- A pragma that applies to a Ghost entity becomes Ghost for the
12895 -- purposes of legality checks and removal of ignored Ghost code.
12897 Mark_Pragma_As_Ghost
(N
, Obj_Id
);
12899 -- Analyze the Boolean expression (if any)
12901 if Present
(Arg1
) then
12902 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
12904 end Constant_After_Elaboration
;
12906 --------------------
12907 -- Contract_Cases --
12908 --------------------
12910 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12912 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12914 -- CASE_GUARD ::= boolean_EXPRESSION | others
12916 -- CONSEQUENCE ::= boolean_EXPRESSION
12918 -- Characteristics:
12920 -- * Analysis - The annotation undergoes initial checks to verify
12921 -- the legal placement and context. Secondary checks preanalyze the
12924 -- Analyze_Contract_Cases_In_Decl_Part
12926 -- * Expansion - The annotation is expanded during the expansion of
12927 -- the related subprogram [body] contract as performed in:
12929 -- Expand_Subprogram_Contract
12931 -- * Template - The annotation utilizes the generic template of the
12932 -- related subprogram [body] when it is:
12934 -- aspect on subprogram declaration
12935 -- aspect on stand alone subprogram body
12936 -- pragma on stand alone subprogram body
12938 -- The annotation must prepare its own template when it is:
12940 -- pragma on subprogram declaration
12942 -- * Globals - Capture of global references must occur after full
12945 -- * Instance - The annotation is instantiated automatically when
12946 -- the related generic subprogram [body] is instantiated except for
12947 -- the "pragma on subprogram declaration" case. In that scenario
12948 -- the annotation must instantiate itself.
12950 when Pragma_Contract_Cases
=> Contract_Cases
: declare
12951 Spec_Id
: Entity_Id
;
12952 Subp_Decl
: Node_Id
;
12956 Check_No_Identifiers
;
12957 Check_Arg_Count
(1);
12959 -- Ensure the proper placement of the pragma. Contract_Cases must
12960 -- be associated with a subprogram declaration or a body that acts
12964 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
12968 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
12971 -- Generic subprogram
12973 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
12976 -- Body acts as spec
12978 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
12979 and then No
(Corresponding_Spec
(Subp_Decl
))
12983 -- Body stub acts as spec
12985 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
12986 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
12992 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
13000 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
13002 -- Chain the pragma on the contract for further processing by
13003 -- Analyze_Contract_Cases_In_Decl_Part.
13005 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
13007 -- A pragma that applies to a Ghost entity becomes Ghost for the
13008 -- purposes of legality checks and removal of ignored Ghost code.
13010 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
13011 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
13013 -- Fully analyze the pragma when it appears inside an entry
13014 -- or subprogram body because it cannot benefit from forward
13017 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
13019 N_Subprogram_Body_Stub
)
13021 -- The legality checks of pragma Contract_Cases are affected by
13022 -- the SPARK mode in effect and the volatility of the context.
13023 -- Analyze all pragmas in a specific order.
13025 Analyze_If_Present
(Pragma_SPARK_Mode
);
13026 Analyze_If_Present
(Pragma_Volatile_Function
);
13027 Analyze_Contract_Cases_In_Decl_Part
(N
);
13029 end Contract_Cases
;
13035 -- pragma Controlled (first_subtype_LOCAL_NAME);
13037 when Pragma_Controlled
=> Controlled
: declare
13041 Check_No_Identifiers
;
13042 Check_Arg_Count
(1);
13043 Check_Arg_Is_Local_Name
(Arg1
);
13044 Arg
:= Get_Pragma_Arg
(Arg1
);
13046 if not Is_Entity_Name
(Arg
)
13047 or else not Is_Access_Type
(Entity
(Arg
))
13049 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
13051 Set_Has_Pragma_Controlled
(Base_Type
(Entity
(Arg
)));
13059 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
13060 -- [Entity =>] LOCAL_NAME);
13062 when Pragma_Convention
=> Convention
: declare
13065 pragma Warnings
(Off
, C
);
13066 pragma Warnings
(Off
, E
);
13068 Check_Arg_Order
((Name_Convention
, Name_Entity
));
13069 Check_Ada_83_Warning
;
13070 Check_Arg_Count
(2);
13071 Process_Convention
(C
, E
);
13073 -- A pragma that applies to a Ghost entity becomes Ghost for the
13074 -- purposes of legality checks and removal of ignored Ghost code.
13076 Mark_Pragma_As_Ghost
(N
, E
);
13079 ---------------------------
13080 -- Convention_Identifier --
13081 ---------------------------
13083 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
13084 -- [Convention =>] convention_IDENTIFIER);
13086 when Pragma_Convention_Identifier
=> Convention_Identifier
: declare
13092 Check_Arg_Order
((Name_Name
, Name_Convention
));
13093 Check_Arg_Count
(2);
13094 Check_Optional_Identifier
(Arg1
, Name_Name
);
13095 Check_Optional_Identifier
(Arg2
, Name_Convention
);
13096 Check_Arg_Is_Identifier
(Arg1
);
13097 Check_Arg_Is_Identifier
(Arg2
);
13098 Idnam
:= Chars
(Get_Pragma_Arg
(Arg1
));
13099 Cname
:= Chars
(Get_Pragma_Arg
(Arg2
));
13101 if Is_Convention_Name
(Cname
) then
13102 Record_Convention_Identifier
13103 (Idnam
, Get_Convention_Id
(Cname
));
13106 ("second arg for % pragma must be convention", Arg2
);
13108 end Convention_Identifier
;
13114 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
13116 when Pragma_CPP_Class
=> CPP_Class
: declare
13120 if Warn_On_Obsolescent_Feature
then
13122 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
13123 & "effect; replace it by pragma import?j?", N
);
13126 Check_Arg_Count
(1);
13130 Chars
=> Name_Import
,
13131 Pragma_Argument_Associations
=> New_List
(
13132 Make_Pragma_Argument_Association
(Loc
,
13133 Expression
=> Make_Identifier
(Loc
, Name_CPP
)),
13134 New_Copy
(First
(Pragma_Argument_Associations
(N
))))));
13138 ---------------------
13139 -- CPP_Constructor --
13140 ---------------------
13142 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
13143 -- [, [External_Name =>] static_string_EXPRESSION ]
13144 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13146 when Pragma_CPP_Constructor
=> CPP_Constructor
: declare
13149 Def_Id
: Entity_Id
;
13150 Tag_Typ
: Entity_Id
;
13154 Check_At_Least_N_Arguments
(1);
13155 Check_At_Most_N_Arguments
(3);
13156 Check_Optional_Identifier
(Arg1
, Name_Entity
);
13157 Check_Arg_Is_Local_Name
(Arg1
);
13159 Id
:= Get_Pragma_Arg
(Arg1
);
13160 Find_Program_Unit_Name
(Id
);
13162 -- If we did not find the name, we are done
13164 if Etype
(Id
) = Any_Type
then
13168 Def_Id
:= Entity
(Id
);
13170 -- Check if already defined as constructor
13172 if Is_Constructor
(Def_Id
) then
13174 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1
);
13178 if Ekind
(Def_Id
) = E_Function
13179 and then (Is_CPP_Class
(Etype
(Def_Id
))
13180 or else (Is_Class_Wide_Type
(Etype
(Def_Id
))
13182 Is_CPP_Class
(Root_Type
(Etype
(Def_Id
)))))
13184 if Scope
(Def_Id
) /= Scope
(Etype
(Def_Id
)) then
13186 ("'C'P'P constructor must be defined in the scope of "
13187 & "its returned type", Arg1
);
13190 if Arg_Count
>= 2 then
13191 Set_Imported
(Def_Id
);
13192 Set_Is_Public
(Def_Id
);
13193 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
13196 Set_Has_Completion
(Def_Id
);
13197 Set_Is_Constructor
(Def_Id
);
13198 Set_Convention
(Def_Id
, Convention_CPP
);
13200 -- Imported C++ constructors are not dispatching primitives
13201 -- because in C++ they don't have a dispatch table slot.
13202 -- However, in Ada the constructor has the profile of a
13203 -- function that returns a tagged type and therefore it has
13204 -- been treated as a primitive operation during semantic
13205 -- analysis. We now remove it from the list of primitive
13206 -- operations of the type.
13208 if Is_Tagged_Type
(Etype
(Def_Id
))
13209 and then not Is_Class_Wide_Type
(Etype
(Def_Id
))
13210 and then Is_Dispatching_Operation
(Def_Id
)
13212 Tag_Typ
:= Etype
(Def_Id
);
13214 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
13215 while Present
(Elmt
) and then Node
(Elmt
) /= Def_Id
loop
13219 Remove_Elmt
(Primitive_Operations
(Tag_Typ
), Elmt
);
13220 Set_Is_Dispatching_Operation
(Def_Id
, False);
13223 -- For backward compatibility, if the constructor returns a
13224 -- class wide type, and we internally change the return type to
13225 -- the corresponding root type.
13227 if Is_Class_Wide_Type
(Etype
(Def_Id
)) then
13228 Set_Etype
(Def_Id
, Root_Type
(Etype
(Def_Id
)));
13232 ("pragma% requires function returning a 'C'P'P_Class type",
13235 end CPP_Constructor
;
13241 when Pragma_CPP_Virtual
=> CPP_Virtual
: declare
13245 if Warn_On_Obsolescent_Feature
then
13247 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
13256 when Pragma_CPP_Vtable
=> CPP_Vtable
: declare
13260 if Warn_On_Obsolescent_Feature
then
13262 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
13271 -- pragma CPU (EXPRESSION);
13273 when Pragma_CPU
=> CPU
: declare
13274 P
: constant Node_Id
:= Parent
(N
);
13280 Check_No_Identifiers
;
13281 Check_Arg_Count
(1);
13285 if Nkind
(P
) = N_Subprogram_Body
then
13286 Check_In_Main_Program
;
13288 Arg
:= Get_Pragma_Arg
(Arg1
);
13289 Analyze_And_Resolve
(Arg
, Any_Integer
);
13291 Ent
:= Defining_Unit_Name
(Specification
(P
));
13293 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
13294 Ent
:= Defining_Identifier
(Ent
);
13299 if not Is_OK_Static_Expression
(Arg
) then
13300 Flag_Non_Static_Expr
13301 ("main subprogram affinity is not static!", Arg
);
13304 -- If constraint error, then we already signalled an error
13306 elsif Raises_Constraint_Error
(Arg
) then
13309 -- Otherwise check in range
13313 CPU_Id
: constant Entity_Id
:= RTE
(RE_CPU_Range
);
13314 -- This is the entity System.Multiprocessors.CPU_Range;
13316 Val
: constant Uint
:= Expr_Value
(Arg
);
13319 if Val
< Expr_Value
(Type_Low_Bound
(CPU_Id
))
13321 Val
> Expr_Value
(Type_High_Bound
(CPU_Id
))
13324 ("main subprogram CPU is out of range", Arg1
);
13330 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
13334 elsif Nkind
(P
) = N_Task_Definition
then
13335 Arg
:= Get_Pragma_Arg
(Arg1
);
13336 Ent
:= Defining_Identifier
(Parent
(P
));
13338 -- The expression must be analyzed in the special manner
13339 -- described in "Handling of Default and Per-Object
13340 -- Expressions" in sem.ads.
13342 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_CPU_Range
));
13344 -- Anything else is incorrect
13350 -- Check duplicate pragma before we chain the pragma in the Rep
13351 -- Item chain of Ent.
13353 Check_Duplicate_Pragma
(Ent
);
13354 Record_Rep_Item
(Ent
, N
);
13361 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
13363 when Pragma_Debug
=> Debug
: declare
13370 -- The condition for executing the call is that the expander
13371 -- is active and that we are not ignoring this debug pragma.
13376 (Expander_Active
and then not Is_Ignored
(N
)),
13379 if not Is_Ignored
(N
) then
13380 Set_SCO_Pragma_Enabled
(Loc
);
13383 if Arg_Count
= 2 then
13385 Make_And_Then
(Loc
,
13386 Left_Opnd
=> Relocate_Node
(Cond
),
13387 Right_Opnd
=> Get_Pragma_Arg
(Arg1
));
13388 Call
:= Get_Pragma_Arg
(Arg2
);
13390 Call
:= Get_Pragma_Arg
(Arg1
);
13394 N_Indexed_Component
,
13398 N_Selected_Component
)
13400 -- If this pragma Debug comes from source, its argument was
13401 -- parsed as a name form (which is syntactically identical).
13402 -- In a generic context a parameterless call will be left as
13403 -- an expanded name (if global) or selected_component if local.
13404 -- Change it to a procedure call statement now.
13406 Change_Name_To_Procedure_Call_Statement
(Call
);
13408 elsif Nkind
(Call
) = N_Procedure_Call_Statement
then
13410 -- Already in the form of a procedure call statement: nothing
13411 -- to do (could happen in case of an internally generated
13417 -- All other cases: diagnose error
13420 ("argument of pragma ""Debug"" is not procedure call",
13425 -- Rewrite into a conditional with an appropriate condition. We
13426 -- wrap the procedure call in a block so that overhead from e.g.
13427 -- use of the secondary stack does not generate execution overhead
13428 -- for suppressed conditions.
13430 -- Normally the analysis that follows will freeze the subprogram
13431 -- being called. However, if the call is to a null procedure,
13432 -- we want to freeze it before creating the block, because the
13433 -- analysis that follows may be done with expansion disabled, in
13434 -- which case the body will not be generated, leading to spurious
13437 if Nkind
(Call
) = N_Procedure_Call_Statement
13438 and then Is_Entity_Name
(Name
(Call
))
13440 Analyze
(Name
(Call
));
13441 Freeze_Before
(N
, Entity
(Name
(Call
)));
13445 Make_Implicit_If_Statement
(N
,
13447 Then_Statements
=> New_List
(
13448 Make_Block_Statement
(Loc
,
13449 Handled_Statement_Sequence
=>
13450 Make_Handled_Sequence_Of_Statements
(Loc
,
13451 Statements
=> New_List
(Relocate_Node
(Call
)))))));
13454 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13455 -- after analysis of the normally rewritten node, to capture all
13456 -- references to entities, which avoids issuing wrong warnings
13457 -- about unused entities.
13459 if GNATprove_Mode
then
13460 Rewrite
(N
, Make_Null_Statement
(Loc
));
13468 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13470 when Pragma_Debug_Policy
=>
13472 Check_Arg_Count
(1);
13473 Check_No_Identifiers
;
13474 Check_Arg_Is_Identifier
(Arg1
);
13476 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
13477 -- rewrite it that way, and let the rest of the checking come
13478 -- from analyzing the rewritten pragma.
13482 Chars
=> Name_Check_Policy
,
13483 Pragma_Argument_Associations
=> New_List
(
13484 Make_Pragma_Argument_Association
(Loc
,
13485 Expression
=> Make_Identifier
(Loc
, Name_Debug
)),
13487 Make_Pragma_Argument_Association
(Loc
,
13488 Expression
=> Get_Pragma_Arg
(Arg1
)))));
13491 -------------------------------
13492 -- Default_Initial_Condition --
13493 -------------------------------
13495 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
13497 when Pragma_Default_Initial_Condition
=> Default_Init_Cond
: declare
13504 Check_No_Identifiers
;
13505 Check_At_Most_N_Arguments
(1);
13508 while Present
(Stmt
) loop
13510 -- Skip prior pragmas, but check for duplicates
13512 if Nkind
(Stmt
) = N_Pragma
then
13513 if Pragma_Name
(Stmt
) = Pname
then
13514 Error_Msg_Name_1
:= Pname
;
13515 Error_Msg_Sloc
:= Sloc
(Stmt
);
13516 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
13519 -- Skip internally generated code
13521 elsif not Comes_From_Source
(Stmt
) then
13524 -- The associated private type [extension] has been found, stop
13527 elsif Nkind_In
(Stmt
, N_Private_Extension_Declaration
,
13528 N_Private_Type_Declaration
)
13530 Typ
:= Defining_Entity
(Stmt
);
13533 -- The pragma does not apply to a legal construct, issue an
13534 -- error and stop the analysis.
13541 Stmt
:= Prev
(Stmt
);
13544 -- A pragma that applies to a Ghost entity becomes Ghost for the
13545 -- purposes of legality checks and removal of ignored Ghost code.
13547 Mark_Pragma_As_Ghost
(N
, Typ
);
13548 Set_Has_Default_Init_Cond
(Typ
);
13549 Set_Has_Inherited_Default_Init_Cond
(Typ
, False);
13551 -- Chain the pragma on the rep item chain for further processing
13553 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
13554 end Default_Init_Cond
;
13556 ----------------------------------
13557 -- Default_Scalar_Storage_Order --
13558 ----------------------------------
13560 -- pragma Default_Scalar_Storage_Order
13561 -- (High_Order_First | Low_Order_First);
13563 when Pragma_Default_Scalar_Storage_Order
=> DSSO
: declare
13564 Default
: Character;
13568 Check_Arg_Count
(1);
13570 -- Default_Scalar_Storage_Order can appear as a configuration
13571 -- pragma, or in a declarative part of a package spec.
13573 if not Is_Configuration_Pragma
then
13574 Check_Is_In_Decl_Part_Or_Package_Spec
;
13577 Check_No_Identifiers
;
13578 Check_Arg_Is_One_Of
13579 (Arg1
, Name_High_Order_First
, Name_Low_Order_First
);
13580 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
13581 Default
:= Fold_Upper
(Name_Buffer
(1));
13583 if not Support_Nondefault_SSO_On_Target
13584 and then (Ttypes
.Bytes_Big_Endian
/= (Default
= 'H'))
13586 if Warn_On_Unrecognized_Pragma
then
13588 ("non-default Scalar_Storage_Order not supported "
13589 & "on target?g?", N
);
13591 ("\pragma Default_Scalar_Storage_Order ignored?g?", N
);
13594 -- Here set the specified default
13597 Opt
.Default_SSO
:= Default
;
13601 --------------------------
13602 -- Default_Storage_Pool --
13603 --------------------------
13605 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
13607 when Pragma_Default_Storage_Pool
=> Default_Storage_Pool
: declare
13612 Check_Arg_Count
(1);
13614 -- Default_Storage_Pool can appear as a configuration pragma, or
13615 -- in a declarative part of a package spec.
13617 if not Is_Configuration_Pragma
then
13618 Check_Is_In_Decl_Part_Or_Package_Spec
;
13621 if From_Aspect_Specification
(N
) then
13623 E
: constant Entity_Id
:= Entity
(Corresponding_Aspect
(N
));
13625 if not In_Open_Scopes
(E
) then
13627 ("aspect must apply to package or subprogram", N
);
13632 if Present
(Arg1
) then
13633 Pool
:= Get_Pragma_Arg
(Arg1
);
13635 -- Case of Default_Storage_Pool (null);
13637 if Nkind
(Pool
) = N_Null
then
13640 -- This is an odd case, this is not really an expression,
13641 -- so we don't have a type for it. So just set the type to
13644 Set_Etype
(Pool
, Empty
);
13646 -- Case of Default_Storage_Pool (storage_pool_NAME);
13649 -- If it's a configuration pragma, then the only allowed
13650 -- argument is "null".
13652 if Is_Configuration_Pragma
then
13653 Error_Pragma_Arg
("NULL expected", Arg1
);
13656 -- The expected type for a non-"null" argument is
13657 -- Root_Storage_Pool'Class, and the pool must be a variable.
13659 Analyze_And_Resolve
13660 (Pool
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
13662 if Is_Variable
(Pool
) then
13664 -- A pragma that applies to a Ghost entity becomes Ghost
13665 -- for the purposes of legality checks and removal of
13666 -- ignored Ghost code.
13668 Mark_Pragma_As_Ghost
(N
, Entity
(Pool
));
13672 ("default storage pool must be a variable", Arg1
);
13676 -- Record the pool name (or null). Freeze.Freeze_Entity for an
13677 -- access type will use this information to set the appropriate
13678 -- attributes of the access type.
13680 Default_Pool
:= Pool
;
13682 end Default_Storage_Pool
;
13688 -- pragma Depends (DEPENDENCY_RELATION);
13690 -- DEPENDENCY_RELATION ::=
13692 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
13694 -- DEPENDENCY_CLAUSE ::=
13695 -- OUTPUT_LIST =>[+] INPUT_LIST
13696 -- | NULL_DEPENDENCY_CLAUSE
13698 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13700 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13702 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13704 -- OUTPUT ::= NAME | FUNCTION_RESULT
13707 -- where FUNCTION_RESULT is a function Result attribute_reference
13709 -- Characteristics:
13711 -- * Analysis - The annotation undergoes initial checks to verify
13712 -- the legal placement and context. Secondary checks fully analyze
13713 -- the dependency clauses in:
13715 -- Analyze_Depends_In_Decl_Part
13717 -- * Expansion - None.
13719 -- * Template - The annotation utilizes the generic template of the
13720 -- related subprogram [body] when it is:
13722 -- aspect on subprogram declaration
13723 -- aspect on stand alone subprogram body
13724 -- pragma on stand alone subprogram body
13726 -- The annotation must prepare its own template when it is:
13728 -- pragma on subprogram declaration
13730 -- * Globals - Capture of global references must occur after full
13733 -- * Instance - The annotation is instantiated automatically when
13734 -- the related generic subprogram [body] is instantiated except for
13735 -- the "pragma on subprogram declaration" case. In that scenario
13736 -- the annotation must instantiate itself.
13738 when Pragma_Depends
=> Depends
: declare
13740 Spec_Id
: Entity_Id
;
13741 Subp_Decl
: Node_Id
;
13744 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
13748 -- Chain the pragma on the contract for further processing by
13749 -- Analyze_Depends_In_Decl_Part.
13751 Add_Contract_Item
(N
, Spec_Id
);
13753 -- Fully analyze the pragma when it appears inside an entry
13754 -- or subprogram body because it cannot benefit from forward
13757 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
13759 N_Subprogram_Body_Stub
)
13761 -- The legality checks of pragmas Depends and Global are
13762 -- affected by the SPARK mode in effect and the volatility
13763 -- of the context. In addition these two pragmas are subject
13764 -- to an inherent order:
13769 -- Analyze all these pragmas in the order outlined above
13771 Analyze_If_Present
(Pragma_SPARK_Mode
);
13772 Analyze_If_Present
(Pragma_Volatile_Function
);
13773 Analyze_If_Present
(Pragma_Global
);
13774 Analyze_Depends_In_Decl_Part
(N
);
13779 ---------------------
13780 -- Detect_Blocking --
13781 ---------------------
13783 -- pragma Detect_Blocking;
13785 when Pragma_Detect_Blocking
=>
13787 Check_Arg_Count
(0);
13788 Check_Valid_Configuration_Pragma
;
13789 Detect_Blocking
:= True;
13791 ------------------------------------
13792 -- Disable_Atomic_Synchronization --
13793 ------------------------------------
13795 -- pragma Disable_Atomic_Synchronization [(Entity)];
13797 when Pragma_Disable_Atomic_Synchronization
=>
13799 Process_Disable_Enable_Atomic_Sync
(Name_Suppress
);
13801 -------------------
13802 -- Discard_Names --
13803 -------------------
13805 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13807 when Pragma_Discard_Names
=> Discard_Names
: declare
13812 Check_Ada_83_Warning
;
13814 -- Deal with configuration pragma case
13816 if Arg_Count
= 0 and then Is_Configuration_Pragma
then
13817 Global_Discard_Names
:= True;
13820 -- Otherwise, check correct appropriate context
13823 Check_Is_In_Decl_Part_Or_Package_Spec
;
13825 if Arg_Count
= 0 then
13827 -- If there is no parameter, then from now on this pragma
13828 -- applies to any enumeration, exception or tagged type
13829 -- defined in the current declarative part, and recursively
13830 -- to any nested scope.
13832 Set_Discard_Names
(Current_Scope
);
13836 Check_Arg_Count
(1);
13837 Check_Optional_Identifier
(Arg1
, Name_On
);
13838 Check_Arg_Is_Local_Name
(Arg1
);
13840 E_Id
:= Get_Pragma_Arg
(Arg1
);
13842 if Etype
(E_Id
) = Any_Type
then
13845 E
:= Entity
(E_Id
);
13848 -- A pragma that applies to a Ghost entity becomes Ghost for
13849 -- the purposes of legality checks and removal of ignored
13852 Mark_Pragma_As_Ghost
(N
, E
);
13854 if (Is_First_Subtype
(E
)
13856 (Is_Enumeration_Type
(E
) or else Is_Tagged_Type
(E
)))
13857 or else Ekind
(E
) = E_Exception
13859 Set_Discard_Names
(E
);
13860 Record_Rep_Item
(E
, N
);
13864 ("inappropriate entity for pragma%", Arg1
);
13870 ------------------------
13871 -- Dispatching_Domain --
13872 ------------------------
13874 -- pragma Dispatching_Domain (EXPRESSION);
13876 when Pragma_Dispatching_Domain
=> Dispatching_Domain
: declare
13877 P
: constant Node_Id
:= Parent
(N
);
13883 Check_No_Identifiers
;
13884 Check_Arg_Count
(1);
13886 -- This pragma is born obsolete, but not the aspect
13888 if not From_Aspect_Specification
(N
) then
13890 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
13893 if Nkind
(P
) = N_Task_Definition
then
13894 Arg
:= Get_Pragma_Arg
(Arg1
);
13895 Ent
:= Defining_Identifier
(Parent
(P
));
13897 -- A pragma that applies to a Ghost entity becomes Ghost for
13898 -- the purposes of legality checks and removal of ignored Ghost
13901 Mark_Pragma_As_Ghost
(N
, Ent
);
13903 -- The expression must be analyzed in the special manner
13904 -- described in "Handling of Default and Per-Object
13905 -- Expressions" in sem.ads.
13907 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Dispatching_Domain
));
13909 -- Check duplicate pragma before we chain the pragma in the Rep
13910 -- Item chain of Ent.
13912 Check_Duplicate_Pragma
(Ent
);
13913 Record_Rep_Item
(Ent
, N
);
13915 -- Anything else is incorrect
13920 end Dispatching_Domain
;
13926 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13928 when Pragma_Elaborate
=> Elaborate
: declare
13933 -- Pragma must be in context items list of a compilation unit
13935 if not Is_In_Context_Clause
then
13939 -- Must be at least one argument
13941 if Arg_Count
= 0 then
13942 Error_Pragma
("pragma% requires at least one argument");
13945 -- In Ada 83 mode, there can be no items following it in the
13946 -- context list except other pragmas and implicit with clauses
13947 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13948 -- placement rule does not apply.
13950 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
13952 while Present
(Citem
) loop
13953 if Nkind
(Citem
) = N_Pragma
13954 or else (Nkind
(Citem
) = N_With_Clause
13955 and then Implicit_With
(Citem
))
13960 ("(Ada 83) pragma% must be at end of context clause");
13967 -- Finally, the arguments must all be units mentioned in a with
13968 -- clause in the same context clause. Note we already checked (in
13969 -- Par.Prag) that the arguments are all identifiers or selected
13973 Outer
: while Present
(Arg
) loop
13974 Citem
:= First
(List_Containing
(N
));
13975 Inner
: while Citem
/= N
loop
13976 if Nkind
(Citem
) = N_With_Clause
13977 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
13979 Set_Elaborate_Present
(Citem
, True);
13980 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
13982 -- With the pragma present, elaboration calls on
13983 -- subprograms from the named unit need no further
13984 -- checks, as long as the pragma appears in the current
13985 -- compilation unit. If the pragma appears in some unit
13986 -- in the context, there might still be a need for an
13987 -- Elaborate_All_Desirable from the current compilation
13988 -- to the named unit, so we keep the check enabled.
13990 if In_Extended_Main_Source_Unit
(N
) then
13992 -- This does not apply in SPARK mode, where we allow
13993 -- pragma Elaborate, but we don't trust it to be right
13994 -- so we will still insist on the Elaborate_All.
13996 if SPARK_Mode
/= On
then
13997 Set_Suppress_Elaboration_Warnings
13998 (Entity
(Name
(Citem
)));
14010 ("argument of pragma% is not withed unit", Arg
);
14016 -- Give a warning if operating in static mode with one of the
14017 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
14020 and not Dynamic_Elaboration_Checks
14022 -- pragma Elaborate not allowed in SPARK mode anyway. We
14023 -- already complained about it, no point in generating any
14024 -- further complaint.
14026 and SPARK_Mode
/= On
14029 ("?l?use of pragma Elaborate may not be safe", N
);
14031 ("?l?use pragma Elaborate_All instead if possible", N
);
14035 -------------------
14036 -- Elaborate_All --
14037 -------------------
14039 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
14041 when Pragma_Elaborate_All
=> Elaborate_All
: declare
14046 Check_Ada_83_Warning
;
14048 -- Pragma must be in context items list of a compilation unit
14050 if not Is_In_Context_Clause
then
14054 -- Must be at least one argument
14056 if Arg_Count
= 0 then
14057 Error_Pragma
("pragma% requires at least one argument");
14060 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
14061 -- have to appear at the end of the context clause, but may
14062 -- appear mixed in with other items, even in Ada 83 mode.
14064 -- Final check: the arguments must all be units mentioned in
14065 -- a with clause in the same context clause. Note that we
14066 -- already checked (in Par.Prag) that all the arguments are
14067 -- either identifiers or selected components.
14070 Outr
: while Present
(Arg
) loop
14071 Citem
:= First
(List_Containing
(N
));
14072 Innr
: while Citem
/= N
loop
14073 if Nkind
(Citem
) = N_With_Clause
14074 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
14076 Set_Elaborate_All_Present
(Citem
, True);
14077 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
14079 -- Suppress warnings and elaboration checks on the named
14080 -- unit if the pragma is in the current compilation, as
14081 -- for pragma Elaborate.
14083 if In_Extended_Main_Source_Unit
(N
) then
14084 Set_Suppress_Elaboration_Warnings
14085 (Entity
(Name
(Citem
)));
14094 Set_Error_Posted
(N
);
14096 ("argument of pragma% is not withed unit", Arg
);
14103 --------------------
14104 -- Elaborate_Body --
14105 --------------------
14107 -- pragma Elaborate_Body [( library_unit_NAME )];
14109 when Pragma_Elaborate_Body
=> Elaborate_Body
: declare
14110 Cunit_Node
: Node_Id
;
14111 Cunit_Ent
: Entity_Id
;
14114 Check_Ada_83_Warning
;
14115 Check_Valid_Library_Unit_Pragma
;
14117 if Nkind
(N
) = N_Null_Statement
then
14121 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
14122 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
14124 -- A pragma that applies to a Ghost entity becomes Ghost for the
14125 -- purposes of legality checks and removal of ignored Ghost code.
14127 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
14129 if Nkind_In
(Unit
(Cunit_Node
), N_Package_Body
,
14132 Error_Pragma
("pragma% must refer to a spec, not a body");
14134 Set_Body_Required
(Cunit_Node
, True);
14135 Set_Has_Pragma_Elaborate_Body
(Cunit_Ent
);
14137 -- If we are in dynamic elaboration mode, then we suppress
14138 -- elaboration warnings for the unit, since it is definitely
14139 -- fine NOT to do dynamic checks at the first level (and such
14140 -- checks will be suppressed because no elaboration boolean
14141 -- is created for Elaborate_Body packages).
14143 -- But in the static model of elaboration, Elaborate_Body is
14144 -- definitely NOT good enough to ensure elaboration safety on
14145 -- its own, since the body may WITH other units that are not
14146 -- safe from an elaboration point of view, so a client must
14147 -- still do an Elaborate_All on such units.
14149 -- Debug flag -gnatdD restores the old behavior of 3.13, where
14150 -- Elaborate_Body always suppressed elab warnings.
14152 if Dynamic_Elaboration_Checks
or Debug_Flag_DD
then
14153 Set_Suppress_Elaboration_Warnings
(Cunit_Ent
);
14156 end Elaborate_Body
;
14158 ------------------------
14159 -- Elaboration_Checks --
14160 ------------------------
14162 -- pragma Elaboration_Checks (Static | Dynamic);
14164 when Pragma_Elaboration_Checks
=>
14166 Check_Arg_Count
(1);
14167 Check_Arg_Is_One_Of
(Arg1
, Name_Static
, Name_Dynamic
);
14169 -- Set flag accordingly (ignore attempt at dynamic elaboration
14170 -- checks in SPARK mode).
14172 Dynamic_Elaboration_Checks
:=
14173 (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Dynamic
)
14174 and then SPARK_Mode
/= On
;
14180 -- pragma Eliminate (
14181 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
14182 -- [,[Entity =>] IDENTIFIER |
14183 -- SELECTED_COMPONENT |
14185 -- [, OVERLOADING_RESOLUTION]);
14187 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
14190 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
14191 -- FUNCTION_PROFILE
14193 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
14195 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
14196 -- Result_Type => result_SUBTYPE_NAME]
14198 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
14199 -- SUBTYPE_NAME ::= STRING_LITERAL
14201 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
14202 -- SOURCE_TRACE ::= STRING_LITERAL
14204 when Pragma_Eliminate
=> Eliminate
: declare
14205 Args
: Args_List
(1 .. 5);
14206 Names
: constant Name_List
(1 .. 5) := (
14209 Name_Parameter_Types
,
14211 Name_Source_Location
);
14213 Unit_Name
: Node_Id
renames Args
(1);
14214 Entity
: Node_Id
renames Args
(2);
14215 Parameter_Types
: Node_Id
renames Args
(3);
14216 Result_Type
: Node_Id
renames Args
(4);
14217 Source_Location
: Node_Id
renames Args
(5);
14221 Check_Valid_Configuration_Pragma
;
14222 Gather_Associations
(Names
, Args
);
14224 if No
(Unit_Name
) then
14225 Error_Pragma
("missing Unit_Name argument for pragma%");
14229 and then (Present
(Parameter_Types
)
14231 Present
(Result_Type
)
14233 Present
(Source_Location
))
14235 Error_Pragma
("missing Entity argument for pragma%");
14238 if (Present
(Parameter_Types
)
14240 Present
(Result_Type
))
14242 Present
(Source_Location
)
14245 ("parameter profile and source location cannot be used "
14246 & "together in pragma%");
14249 Process_Eliminate_Pragma
14258 -----------------------------------
14259 -- Enable_Atomic_Synchronization --
14260 -----------------------------------
14262 -- pragma Enable_Atomic_Synchronization [(Entity)];
14264 when Pragma_Enable_Atomic_Synchronization
=>
14266 Process_Disable_Enable_Atomic_Sync
(Name_Unsuppress
);
14273 -- [ Convention =>] convention_IDENTIFIER,
14274 -- [ Entity =>] LOCAL_NAME
14275 -- [, [External_Name =>] static_string_EXPRESSION ]
14276 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14278 when Pragma_Export
=> Export
: declare
14280 Def_Id
: Entity_Id
;
14282 pragma Warnings
(Off
, C
);
14285 Check_Ada_83_Warning
;
14289 Name_External_Name
,
14292 Check_At_Least_N_Arguments
(2);
14293 Check_At_Most_N_Arguments
(4);
14295 -- In Relaxed_RM_Semantics, support old Ada 83 style:
14296 -- pragma Export (Entity, "external name");
14298 if Relaxed_RM_Semantics
14299 and then Arg_Count
= 2
14300 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
14303 Def_Id
:= Get_Pragma_Arg
(Arg1
);
14306 if not Is_Entity_Name
(Def_Id
) then
14307 Error_Pragma_Arg
("entity name required", Arg1
);
14310 Def_Id
:= Entity
(Def_Id
);
14311 Set_Exported
(Def_Id
, Arg1
);
14314 Process_Convention
(C
, Def_Id
);
14316 -- A pragma that applies to a Ghost entity becomes Ghost for
14317 -- the purposes of legality checks and removal of ignored Ghost
14320 Mark_Pragma_As_Ghost
(N
, Def_Id
);
14322 if Ekind
(Def_Id
) /= E_Constant
then
14323 Note_Possible_Modification
14324 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
14327 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
14328 Set_Exported
(Def_Id
, Arg2
);
14331 -- If the entity is a deferred constant, propagate the information
14332 -- to the full view, because gigi elaborates the full view only.
14334 if Ekind
(Def_Id
) = E_Constant
14335 and then Present
(Full_View
(Def_Id
))
14338 Id2
: constant Entity_Id
:= Full_View
(Def_Id
);
14340 Set_Is_Exported
(Id2
, Is_Exported
(Def_Id
));
14341 Set_First_Rep_Item
(Id2
, First_Rep_Item
(Def_Id
));
14342 Set_Interface_Name
(Id2
, Einfo
.Interface_Name
(Def_Id
));
14347 ---------------------
14348 -- Export_Function --
14349 ---------------------
14351 -- pragma Export_Function (
14352 -- [Internal =>] LOCAL_NAME
14353 -- [, [External =>] EXTERNAL_SYMBOL]
14354 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14355 -- [, [Result_Type =>] TYPE_DESIGNATOR]
14356 -- [, [Mechanism =>] MECHANISM]
14357 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14359 -- EXTERNAL_SYMBOL ::=
14361 -- | static_string_EXPRESSION
14363 -- PARAMETER_TYPES ::=
14365 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14367 -- TYPE_DESIGNATOR ::=
14369 -- | subtype_Name ' Access
14373 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14375 -- MECHANISM_ASSOCIATION ::=
14376 -- [formal_parameter_NAME =>] MECHANISM_NAME
14378 -- MECHANISM_NAME ::=
14382 when Pragma_Export_Function
=> Export_Function
: declare
14383 Args
: Args_List
(1 .. 6);
14384 Names
: constant Name_List
(1 .. 6) := (
14387 Name_Parameter_Types
,
14390 Name_Result_Mechanism
);
14392 Internal
: Node_Id
renames Args
(1);
14393 External
: Node_Id
renames Args
(2);
14394 Parameter_Types
: Node_Id
renames Args
(3);
14395 Result_Type
: Node_Id
renames Args
(4);
14396 Mechanism
: Node_Id
renames Args
(5);
14397 Result_Mechanism
: Node_Id
renames Args
(6);
14401 Gather_Associations
(Names
, Args
);
14402 Process_Extended_Import_Export_Subprogram_Pragma
(
14403 Arg_Internal
=> Internal
,
14404 Arg_External
=> External
,
14405 Arg_Parameter_Types
=> Parameter_Types
,
14406 Arg_Result_Type
=> Result_Type
,
14407 Arg_Mechanism
=> Mechanism
,
14408 Arg_Result_Mechanism
=> Result_Mechanism
);
14409 end Export_Function
;
14411 -------------------
14412 -- Export_Object --
14413 -------------------
14415 -- pragma Export_Object (
14416 -- [Internal =>] LOCAL_NAME
14417 -- [, [External =>] EXTERNAL_SYMBOL]
14418 -- [, [Size =>] EXTERNAL_SYMBOL]);
14420 -- EXTERNAL_SYMBOL ::=
14422 -- | static_string_EXPRESSION
14424 -- PARAMETER_TYPES ::=
14426 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14428 -- TYPE_DESIGNATOR ::=
14430 -- | subtype_Name ' Access
14434 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14436 -- MECHANISM_ASSOCIATION ::=
14437 -- [formal_parameter_NAME =>] MECHANISM_NAME
14439 -- MECHANISM_NAME ::=
14443 when Pragma_Export_Object
=> Export_Object
: declare
14444 Args
: Args_List
(1 .. 3);
14445 Names
: constant Name_List
(1 .. 3) := (
14450 Internal
: Node_Id
renames Args
(1);
14451 External
: Node_Id
renames Args
(2);
14452 Size
: Node_Id
renames Args
(3);
14456 Gather_Associations
(Names
, Args
);
14457 Process_Extended_Import_Export_Object_Pragma
(
14458 Arg_Internal
=> Internal
,
14459 Arg_External
=> External
,
14463 ----------------------
14464 -- Export_Procedure --
14465 ----------------------
14467 -- pragma Export_Procedure (
14468 -- [Internal =>] LOCAL_NAME
14469 -- [, [External =>] EXTERNAL_SYMBOL]
14470 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14471 -- [, [Mechanism =>] MECHANISM]);
14473 -- EXTERNAL_SYMBOL ::=
14475 -- | static_string_EXPRESSION
14477 -- PARAMETER_TYPES ::=
14479 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14481 -- TYPE_DESIGNATOR ::=
14483 -- | subtype_Name ' Access
14487 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14489 -- MECHANISM_ASSOCIATION ::=
14490 -- [formal_parameter_NAME =>] MECHANISM_NAME
14492 -- MECHANISM_NAME ::=
14496 when Pragma_Export_Procedure
=> Export_Procedure
: declare
14497 Args
: Args_List
(1 .. 4);
14498 Names
: constant Name_List
(1 .. 4) := (
14501 Name_Parameter_Types
,
14504 Internal
: Node_Id
renames Args
(1);
14505 External
: Node_Id
renames Args
(2);
14506 Parameter_Types
: Node_Id
renames Args
(3);
14507 Mechanism
: Node_Id
renames Args
(4);
14511 Gather_Associations
(Names
, Args
);
14512 Process_Extended_Import_Export_Subprogram_Pragma
(
14513 Arg_Internal
=> Internal
,
14514 Arg_External
=> External
,
14515 Arg_Parameter_Types
=> Parameter_Types
,
14516 Arg_Mechanism
=> Mechanism
);
14517 end Export_Procedure
;
14523 -- pragma Export_Value (
14524 -- [Value =>] static_integer_EXPRESSION,
14525 -- [Link_Name =>] static_string_EXPRESSION);
14527 when Pragma_Export_Value
=>
14529 Check_Arg_Order
((Name_Value
, Name_Link_Name
));
14530 Check_Arg_Count
(2);
14532 Check_Optional_Identifier
(Arg1
, Name_Value
);
14533 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
14535 Check_Optional_Identifier
(Arg2
, Name_Link_Name
);
14536 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
14538 -----------------------------
14539 -- Export_Valued_Procedure --
14540 -----------------------------
14542 -- pragma Export_Valued_Procedure (
14543 -- [Internal =>] LOCAL_NAME
14544 -- [, [External =>] EXTERNAL_SYMBOL,]
14545 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14546 -- [, [Mechanism =>] MECHANISM]);
14548 -- EXTERNAL_SYMBOL ::=
14550 -- | static_string_EXPRESSION
14552 -- PARAMETER_TYPES ::=
14554 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14556 -- TYPE_DESIGNATOR ::=
14558 -- | subtype_Name ' Access
14562 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14564 -- MECHANISM_ASSOCIATION ::=
14565 -- [formal_parameter_NAME =>] MECHANISM_NAME
14567 -- MECHANISM_NAME ::=
14571 when Pragma_Export_Valued_Procedure
=>
14572 Export_Valued_Procedure
: declare
14573 Args
: Args_List
(1 .. 4);
14574 Names
: constant Name_List
(1 .. 4) := (
14577 Name_Parameter_Types
,
14580 Internal
: Node_Id
renames Args
(1);
14581 External
: Node_Id
renames Args
(2);
14582 Parameter_Types
: Node_Id
renames Args
(3);
14583 Mechanism
: Node_Id
renames Args
(4);
14587 Gather_Associations
(Names
, Args
);
14588 Process_Extended_Import_Export_Subprogram_Pragma
(
14589 Arg_Internal
=> Internal
,
14590 Arg_External
=> External
,
14591 Arg_Parameter_Types
=> Parameter_Types
,
14592 Arg_Mechanism
=> Mechanism
);
14593 end Export_Valued_Procedure
;
14595 -------------------
14596 -- Extend_System --
14597 -------------------
14599 -- pragma Extend_System ([Name =>] Identifier);
14601 when Pragma_Extend_System
=> Extend_System
: declare
14604 Check_Valid_Configuration_Pragma
;
14605 Check_Arg_Count
(1);
14606 Check_Optional_Identifier
(Arg1
, Name_Name
);
14607 Check_Arg_Is_Identifier
(Arg1
);
14609 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
14612 and then Name_Buffer
(1 .. 4) = "aux_"
14614 if Present
(System_Extend_Pragma_Arg
) then
14615 if Chars
(Get_Pragma_Arg
(Arg1
)) =
14616 Chars
(Expression
(System_Extend_Pragma_Arg
))
14620 Error_Msg_Sloc
:= Sloc
(System_Extend_Pragma_Arg
);
14621 Error_Pragma
("pragma% conflicts with that #");
14625 System_Extend_Pragma_Arg
:= Arg1
;
14627 if not GNAT_Mode
then
14628 System_Extend_Unit
:= Arg1
;
14632 Error_Pragma
("incorrect name for pragma%, must be Aux_xxx");
14636 ------------------------
14637 -- Extensions_Allowed --
14638 ------------------------
14640 -- pragma Extensions_Allowed (ON | OFF);
14642 when Pragma_Extensions_Allowed
=>
14644 Check_Arg_Count
(1);
14645 Check_No_Identifiers
;
14646 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
14648 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
14649 Extensions_Allowed
:= True;
14650 Ada_Version
:= Ada_Version_Type
'Last;
14653 Extensions_Allowed
:= False;
14654 Ada_Version
:= Ada_Version_Explicit
;
14655 Ada_Version_Pragma
:= Empty
;
14658 ------------------------
14659 -- Extensions_Visible --
14660 ------------------------
14662 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
14664 -- Characteristics:
14666 -- * Analysis - The annotation is fully analyzed immediately upon
14667 -- elaboration as its expression must be static.
14669 -- * Expansion - None.
14671 -- * Template - The annotation utilizes the generic template of the
14672 -- related subprogram [body] when it is:
14674 -- aspect on subprogram declaration
14675 -- aspect on stand alone subprogram body
14676 -- pragma on stand alone subprogram body
14678 -- The annotation must prepare its own template when it is:
14680 -- pragma on subprogram declaration
14682 -- * Globals - Capture of global references must occur after full
14685 -- * Instance - The annotation is instantiated automatically when
14686 -- the related generic subprogram [body] is instantiated except for
14687 -- the "pragma on subprogram declaration" case. In that scenario
14688 -- the annotation must instantiate itself.
14690 when Pragma_Extensions_Visible
=> Extensions_Visible
: declare
14691 Formal
: Entity_Id
;
14692 Has_OK_Formal
: Boolean := False;
14693 Spec_Id
: Entity_Id
;
14694 Subp_Decl
: Node_Id
;
14698 Check_No_Identifiers
;
14699 Check_At_Most_N_Arguments
(1);
14702 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
14704 -- Abstract subprogram declaration
14706 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
14709 -- Generic subprogram declaration
14711 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
14714 -- Body acts as spec
14716 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
14717 and then No
(Corresponding_Spec
(Subp_Decl
))
14721 -- Body stub acts as spec
14723 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
14724 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
14728 -- Subprogram declaration
14730 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
14733 -- Otherwise the pragma is associated with an illegal construct
14736 Error_Pragma
("pragma % must apply to a subprogram");
14740 -- Chain the pragma on the contract for completeness
14742 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
14744 -- The legality checks of pragma Extension_Visible are affected
14745 -- by the SPARK mode in effect. Analyze all pragmas in specific
14748 Analyze_If_Present
(Pragma_SPARK_Mode
);
14750 -- Mark the pragma as Ghost if the related subprogram is also
14751 -- Ghost. This also ensures that any expansion performed further
14752 -- below will produce Ghost nodes.
14754 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
14755 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
14757 -- Examine the formals of the related subprogram
14759 Formal
:= First_Formal
(Spec_Id
);
14760 while Present
(Formal
) loop
14762 -- At least one of the formals is of a specific tagged type,
14763 -- the pragma is legal.
14765 if Is_Specific_Tagged_Type
(Etype
(Formal
)) then
14766 Has_OK_Formal
:= True;
14769 -- A generic subprogram with at least one formal of a private
14770 -- type ensures the legality of the pragma because the actual
14771 -- may be specifically tagged. Note that this is verified by
14772 -- the check above at instantiation time.
14774 elsif Is_Private_Type
(Etype
(Formal
))
14775 and then Is_Generic_Type
(Etype
(Formal
))
14777 Has_OK_Formal
:= True;
14781 Next_Formal
(Formal
);
14784 if not Has_OK_Formal
then
14785 Error_Msg_Name_1
:= Pname
;
14786 Error_Msg_N
(Fix_Error
("incorrect placement of pragma %"), N
);
14788 ("\subprogram & lacks parameter of specific tagged or "
14789 & "generic private type", N
, Spec_Id
);
14794 -- Analyze the Boolean expression (if any)
14796 if Present
(Arg1
) then
14797 Check_Static_Boolean_Expression
14798 (Expression
(Get_Argument
(N
, Spec_Id
)));
14800 end Extensions_Visible
;
14806 -- pragma External (
14807 -- [ Convention =>] convention_IDENTIFIER,
14808 -- [ Entity =>] LOCAL_NAME
14809 -- [, [External_Name =>] static_string_EXPRESSION ]
14810 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14812 when Pragma_External
=> External
: declare
14815 pragma Warnings
(Off
, C
);
14822 Name_External_Name
,
14824 Check_At_Least_N_Arguments
(2);
14825 Check_At_Most_N_Arguments
(4);
14826 Process_Convention
(C
, E
);
14828 -- A pragma that applies to a Ghost entity becomes Ghost for the
14829 -- purposes of legality checks and removal of ignored Ghost code.
14831 Mark_Pragma_As_Ghost
(N
, E
);
14833 Note_Possible_Modification
14834 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
14835 Process_Interface_Name
(E
, Arg3
, Arg4
);
14836 Set_Exported
(E
, Arg2
);
14839 --------------------------
14840 -- External_Name_Casing --
14841 --------------------------
14843 -- pragma External_Name_Casing (
14844 -- UPPERCASE | LOWERCASE
14845 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14847 when Pragma_External_Name_Casing
=> External_Name_Casing
: declare
14850 Check_No_Identifiers
;
14852 if Arg_Count
= 2 then
14853 Check_Arg_Is_One_Of
14854 (Arg2
, Name_As_Is
, Name_Uppercase
, Name_Lowercase
);
14856 case Chars
(Get_Pragma_Arg
(Arg2
)) is
14858 Opt
.External_Name_Exp_Casing
:= As_Is
;
14860 when Name_Uppercase
=>
14861 Opt
.External_Name_Exp_Casing
:= Uppercase
;
14863 when Name_Lowercase
=>
14864 Opt
.External_Name_Exp_Casing
:= Lowercase
;
14871 Check_Arg_Count
(1);
14874 Check_Arg_Is_One_Of
(Arg1
, Name_Uppercase
, Name_Lowercase
);
14876 case Chars
(Get_Pragma_Arg
(Arg1
)) is
14877 when Name_Uppercase
=>
14878 Opt
.External_Name_Imp_Casing
:= Uppercase
;
14880 when Name_Lowercase
=>
14881 Opt
.External_Name_Imp_Casing
:= Lowercase
;
14886 end External_Name_Casing
;
14892 -- pragma Fast_Math;
14894 when Pragma_Fast_Math
=>
14896 Check_No_Identifiers
;
14897 Check_Valid_Configuration_Pragma
;
14900 --------------------------
14901 -- Favor_Top_Level --
14902 --------------------------
14904 -- pragma Favor_Top_Level (type_NAME);
14906 when Pragma_Favor_Top_Level
=> Favor_Top_Level
: declare
14911 Check_No_Identifiers
;
14912 Check_Arg_Count
(1);
14913 Check_Arg_Is_Local_Name
(Arg1
);
14914 Typ
:= Entity
(Get_Pragma_Arg
(Arg1
));
14916 -- A pragma that applies to a Ghost entity becomes Ghost for the
14917 -- purposes of legality checks and removal of ignored Ghost code.
14919 Mark_Pragma_As_Ghost
(N
, Typ
);
14921 -- If it's an access-to-subprogram type (in particular, not a
14922 -- subtype), set the flag on that type.
14924 if Is_Access_Subprogram_Type
(Typ
) then
14925 Set_Can_Use_Internal_Rep
(Typ
, False);
14927 -- Otherwise it's an error (name denotes the wrong sort of entity)
14931 ("access-to-subprogram type expected",
14932 Get_Pragma_Arg
(Arg1
));
14934 end Favor_Top_Level
;
14936 ---------------------------
14937 -- Finalize_Storage_Only --
14938 ---------------------------
14940 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14942 when Pragma_Finalize_Storage_Only
=> Finalize_Storage
: declare
14943 Assoc
: constant Node_Id
:= Arg1
;
14944 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
14949 Check_No_Identifiers
;
14950 Check_Arg_Count
(1);
14951 Check_Arg_Is_Local_Name
(Arg1
);
14953 Find_Type
(Type_Id
);
14954 Typ
:= Entity
(Type_Id
);
14957 or else Rep_Item_Too_Early
(Typ
, N
)
14961 Typ
:= Underlying_Type
(Typ
);
14964 if not Is_Controlled
(Typ
) then
14965 Error_Pragma
("pragma% must specify controlled type");
14968 Check_First_Subtype
(Arg1
);
14970 if Finalize_Storage_Only
(Typ
) then
14971 Error_Pragma
("duplicate pragma%, only one allowed");
14973 elsif not Rep_Item_Too_Late
(Typ
, N
) then
14974 Set_Finalize_Storage_Only
(Base_Type
(Typ
), True);
14976 end Finalize_Storage
;
14982 -- pragma Ghost [ (boolean_EXPRESSION) ];
14984 when Pragma_Ghost
=> Ghost
: declare
14988 Orig_Stmt
: Node_Id
;
14989 Prev_Id
: Entity_Id
;
14994 Check_No_Identifiers
;
14995 Check_At_Most_N_Arguments
(1);
14999 while Present
(Stmt
) loop
15001 -- Skip prior pragmas, but check for duplicates
15003 if Nkind
(Stmt
) = N_Pragma
then
15004 if Pragma_Name
(Stmt
) = Pname
then
15005 Error_Msg_Name_1
:= Pname
;
15006 Error_Msg_Sloc
:= Sloc
(Stmt
);
15007 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
15010 -- Task unit declared without a definition cannot be subject to
15011 -- pragma Ghost (SPARK RM 6.9(19)).
15013 elsif Nkind_In
(Stmt
, N_Single_Task_Declaration
,
15014 N_Task_Type_Declaration
)
15016 Error_Pragma
("pragma % cannot apply to a task type");
15019 -- Skip internally generated code
15021 elsif not Comes_From_Source
(Stmt
) then
15022 Orig_Stmt
:= Original_Node
(Stmt
);
15024 -- When pragma Ghost applies to an untagged derivation, the
15025 -- derivation is transformed into a [sub]type declaration.
15027 if Nkind_In
(Stmt
, N_Full_Type_Declaration
,
15028 N_Subtype_Declaration
)
15029 and then Comes_From_Source
(Orig_Stmt
)
15030 and then Nkind
(Orig_Stmt
) = N_Full_Type_Declaration
15031 and then Nkind
(Type_Definition
(Orig_Stmt
)) =
15032 N_Derived_Type_Definition
15034 Id
:= Defining_Entity
(Stmt
);
15037 -- When pragma Ghost applies to an expression function, the
15038 -- expression function is transformed into a subprogram.
15040 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
15041 and then Comes_From_Source
(Orig_Stmt
)
15042 and then Nkind
(Orig_Stmt
) = N_Expression_Function
15044 Id
:= Defining_Entity
(Stmt
);
15048 -- The pragma applies to a legal construct, stop the traversal
15050 elsif Nkind_In
(Stmt
, N_Abstract_Subprogram_Declaration
,
15051 N_Full_Type_Declaration
,
15052 N_Generic_Subprogram_Declaration
,
15053 N_Object_Declaration
,
15054 N_Private_Extension_Declaration
,
15055 N_Private_Type_Declaration
,
15056 N_Subprogram_Declaration
,
15057 N_Subtype_Declaration
)
15059 Id
:= Defining_Entity
(Stmt
);
15062 -- The pragma does not apply to a legal construct, issue an
15063 -- error and stop the analysis.
15067 ("pragma % must apply to an object, package, subprogram "
15072 Stmt
:= Prev
(Stmt
);
15075 Context
:= Parent
(N
);
15077 -- Handle compilation units
15079 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
15080 Context
:= Unit
(Parent
(Context
));
15083 -- Protected and task types cannot be subject to pragma Ghost
15084 -- (SPARK RM 6.9(19)).
15086 if Nkind_In
(Context
, N_Protected_Body
, N_Protected_Definition
)
15088 Error_Pragma
("pragma % cannot apply to a protected type");
15091 elsif Nkind_In
(Context
, N_Task_Body
, N_Task_Definition
) then
15092 Error_Pragma
("pragma % cannot apply to a task type");
15098 -- When pragma Ghost is associated with a [generic] package, it
15099 -- appears in the visible declarations.
15101 if Nkind
(Context
) = N_Package_Specification
15102 and then Present
(Visible_Declarations
(Context
))
15103 and then List_Containing
(N
) = Visible_Declarations
(Context
)
15105 Id
:= Defining_Entity
(Context
);
15107 -- Pragma Ghost applies to a stand alone subprogram body
15109 elsif Nkind
(Context
) = N_Subprogram_Body
15110 and then No
(Corresponding_Spec
(Context
))
15112 Id
:= Defining_Entity
(Context
);
15114 -- Pragma Ghost applies to a subprogram declaration that acts
15115 -- as a compilation unit.
15117 elsif Nkind
(Context
) = N_Subprogram_Declaration
then
15118 Id
:= Defining_Entity
(Context
);
15124 ("pragma % must apply to an object, package, subprogram or "
15129 -- Handle completions of types and constants that are subject to
15132 if Is_Record_Type
(Id
) or else Ekind
(Id
) = E_Constant
then
15133 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
15135 if Present
(Prev_Id
) and then not Is_Ghost_Entity
(Prev_Id
) then
15136 Error_Msg_Name_1
:= Pname
;
15138 -- The full declaration of a deferred constant cannot be
15139 -- subject to pragma Ghost unless the deferred declaration
15140 -- is also Ghost (SPARK RM 6.9(9)).
15142 if Ekind
(Prev_Id
) = E_Constant
then
15143 Error_Msg_Name_1
:= Pname
;
15144 Error_Msg_NE
(Fix_Error
15145 ("pragma % must apply to declaration of deferred "
15146 & "constant &"), N
, Id
);
15149 -- Pragma Ghost may appear on the full view of an incomplete
15150 -- type because the incomplete declaration lacks aspects and
15151 -- cannot be subject to pragma Ghost.
15153 elsif Ekind
(Prev_Id
) = E_Incomplete_Type
then
15156 -- The full declaration of a type cannot be subject to
15157 -- pragma Ghost unless the partial view is also Ghost
15158 -- (SPARK RM 6.9(9)).
15161 Error_Msg_NE
(Fix_Error
15162 ("pragma % must apply to partial view of type &"),
15168 -- A synchronized object cannot be subject to pragma Ghost
15169 -- (SPARK RM 6.9(19)).
15171 elsif Ekind
(Id
) = E_Variable
then
15172 if Is_Protected_Type
(Etype
(Id
)) then
15173 Error_Pragma
("pragma % cannot apply to a protected object");
15176 elsif Is_Task_Type
(Etype
(Id
)) then
15177 Error_Pragma
("pragma % cannot apply to a task object");
15182 -- Analyze the Boolean expression (if any)
15184 if Present
(Arg1
) then
15185 Expr
:= Get_Pragma_Arg
(Arg1
);
15187 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
15189 if Is_OK_Static_Expression
(Expr
) then
15191 -- "Ghostness" cannot be turned off once enabled within a
15192 -- region (SPARK RM 6.9(6)).
15194 if Is_False
(Expr_Value
(Expr
))
15195 and then Ghost_Mode
> None
15198 ("pragma % with value False cannot appear in enabled "
15203 -- Otherwie the expression is not static
15207 ("expression of pragma % must be static", Expr
);
15212 Set_Is_Ghost_Entity
(Id
);
15219 -- pragma Global (GLOBAL_SPECIFICATION);
15221 -- GLOBAL_SPECIFICATION ::=
15224 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
15226 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
15228 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
15229 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
15230 -- GLOBAL_ITEM ::= NAME
15232 -- Characteristics:
15234 -- * Analysis - The annotation undergoes initial checks to verify
15235 -- the legal placement and context. Secondary checks fully analyze
15236 -- the dependency clauses in:
15238 -- Analyze_Global_In_Decl_Part
15240 -- * Expansion - None.
15242 -- * Template - The annotation utilizes the generic template of the
15243 -- related subprogram [body] when it is:
15245 -- aspect on subprogram declaration
15246 -- aspect on stand alone subprogram body
15247 -- pragma on stand alone subprogram body
15249 -- The annotation must prepare its own template when it is:
15251 -- pragma on subprogram declaration
15253 -- * Globals - Capture of global references must occur after full
15256 -- * Instance - The annotation is instantiated automatically when
15257 -- the related generic subprogram [body] is instantiated except for
15258 -- the "pragma on subprogram declaration" case. In that scenario
15259 -- the annotation must instantiate itself.
15261 when Pragma_Global
=> Global
: declare
15263 Spec_Id
: Entity_Id
;
15264 Subp_Decl
: Node_Id
;
15267 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
15271 -- Chain the pragma on the contract for further processing by
15272 -- Analyze_Global_In_Decl_Part.
15274 Add_Contract_Item
(N
, Spec_Id
);
15276 -- Fully analyze the pragma when it appears inside an entry
15277 -- or subprogram body because it cannot benefit from forward
15280 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
15282 N_Subprogram_Body_Stub
)
15284 -- The legality checks of pragmas Depends and Global are
15285 -- affected by the SPARK mode in effect and the volatility
15286 -- of the context. In addition these two pragmas are subject
15287 -- to an inherent order:
15292 -- Analyze all these pragmas in the order outlined above
15294 Analyze_If_Present
(Pragma_SPARK_Mode
);
15295 Analyze_If_Present
(Pragma_Volatile_Function
);
15296 Analyze_Global_In_Decl_Part
(N
);
15297 Analyze_If_Present
(Pragma_Depends
);
15306 -- pragma Ident (static_string_EXPRESSION)
15308 -- Note: pragma Comment shares this processing. Pragma Ident is
15309 -- identical in effect to pragma Commment.
15311 when Pragma_Ident | Pragma_Comment
=> Ident
: declare
15316 Check_Arg_Count
(1);
15317 Check_No_Identifiers
;
15318 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
15321 Str
:= Expr_Value_S
(Get_Pragma_Arg
(Arg1
));
15328 GP
:= Parent
(Parent
(N
));
15330 if Nkind_In
(GP
, N_Package_Declaration
,
15331 N_Generic_Package_Declaration
)
15336 -- If we have a compilation unit, then record the ident value,
15337 -- checking for improper duplication.
15339 if Nkind
(GP
) = N_Compilation_Unit
then
15340 CS
:= Ident_String
(Current_Sem_Unit
);
15342 if Present
(CS
) then
15344 -- If we have multiple instances, concatenate them, but
15345 -- not in ASIS, where we want the original tree.
15347 if not ASIS_Mode
then
15348 Start_String
(Strval
(CS
));
15349 Store_String_Char
(' ');
15350 Store_String_Chars
(Strval
(Str
));
15351 Set_Strval
(CS
, End_String
);
15355 Set_Ident_String
(Current_Sem_Unit
, Str
);
15358 -- For subunits, we just ignore the Ident, since in GNAT these
15359 -- are not separate object files, and hence not separate units
15360 -- in the unit table.
15362 elsif Nkind
(GP
) = N_Subunit
then
15368 -------------------
15369 -- Ignore_Pragma --
15370 -------------------
15372 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
15374 -- Entirely handled in the parser, nothing to do here
15376 when Pragma_Ignore_Pragma
=>
15379 ----------------------------
15380 -- Implementation_Defined --
15381 ----------------------------
15383 -- pragma Implementation_Defined (LOCAL_NAME);
15385 -- Marks previously declared entity as implementation defined. For
15386 -- an overloaded entity, applies to the most recent homonym.
15388 -- pragma Implementation_Defined;
15390 -- The form with no arguments appears anywhere within a scope, most
15391 -- typically a package spec, and indicates that all entities that are
15392 -- defined within the package spec are Implementation_Defined.
15394 when Pragma_Implementation_Defined
=> Implementation_Defined
: declare
15399 Check_No_Identifiers
;
15401 -- Form with no arguments
15403 if Arg_Count
= 0 then
15404 Set_Is_Implementation_Defined
(Current_Scope
);
15406 -- Form with one argument
15409 Check_Arg_Count
(1);
15410 Check_Arg_Is_Local_Name
(Arg1
);
15411 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
15412 Set_Is_Implementation_Defined
(Ent
);
15414 end Implementation_Defined
;
15420 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
15422 -- IMPLEMENTATION_KIND ::=
15423 -- By_Entry | By_Protected_Procedure | By_Any | Optional
15425 -- "By_Any" and "Optional" are treated as synonyms in order to
15426 -- support Ada 2012 aspect Synchronization.
15428 when Pragma_Implemented
=> Implemented
: declare
15429 Proc_Id
: Entity_Id
;
15434 Check_Arg_Count
(2);
15435 Check_No_Identifiers
;
15436 Check_Arg_Is_Identifier
(Arg1
);
15437 Check_Arg_Is_Local_Name
(Arg1
);
15438 Check_Arg_Is_One_Of
(Arg2
,
15441 Name_By_Protected_Procedure
,
15444 -- Extract the name of the local procedure
15446 Proc_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
15448 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
15449 -- primitive procedure of a synchronized tagged type.
15451 if Ekind
(Proc_Id
) = E_Procedure
15452 and then Is_Primitive
(Proc_Id
)
15453 and then Present
(First_Formal
(Proc_Id
))
15455 Typ
:= Etype
(First_Formal
(Proc_Id
));
15457 if Is_Tagged_Type
(Typ
)
15460 -- Check for a protected, a synchronized or a task interface
15462 ((Is_Interface
(Typ
)
15463 and then Is_Synchronized_Interface
(Typ
))
15465 -- Check for a protected type or a task type that implements
15469 (Is_Concurrent_Record_Type
(Typ
)
15470 and then Present
(Interfaces
(Typ
)))
15472 -- In analysis-only mode, examine original protected type
15475 (Nkind
(Parent
(Typ
)) = N_Protected_Type_Declaration
15476 and then Present
(Interface_List
(Parent
(Typ
))))
15478 -- Check for a private record extension with keyword
15482 (Ekind_In
(Typ
, E_Record_Type_With_Private
,
15483 E_Record_Subtype_With_Private
)
15484 and then Synchronized_Present
(Parent
(Typ
))))
15489 ("controlling formal must be of synchronized tagged type",
15494 -- Procedures declared inside a protected type must be accepted
15496 elsif Ekind
(Proc_Id
) = E_Procedure
15497 and then Is_Protected_Type
(Scope
(Proc_Id
))
15501 -- The first argument is not a primitive procedure
15505 ("pragma % must be applied to a primitive procedure", Arg1
);
15509 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
15510 -- By_Protected_Procedure to the primitive procedure of a task
15513 if Chars
(Arg2
) = Name_By_Protected_Procedure
15514 and then Is_Interface
(Typ
)
15515 and then Is_Task_Interface
(Typ
)
15518 ("implementation kind By_Protected_Procedure cannot be "
15519 & "applied to a task interface primitive", Arg2
);
15523 Record_Rep_Item
(Proc_Id
, N
);
15526 ----------------------
15527 -- Implicit_Packing --
15528 ----------------------
15530 -- pragma Implicit_Packing;
15532 when Pragma_Implicit_Packing
=>
15534 Check_Arg_Count
(0);
15535 Implicit_Packing
:= True;
15542 -- [Convention =>] convention_IDENTIFIER,
15543 -- [Entity =>] LOCAL_NAME
15544 -- [, [External_Name =>] static_string_EXPRESSION ]
15545 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15547 when Pragma_Import
=>
15548 Check_Ada_83_Warning
;
15552 Name_External_Name
,
15555 Check_At_Least_N_Arguments
(2);
15556 Check_At_Most_N_Arguments
(4);
15557 Process_Import_Or_Interface
;
15559 ---------------------
15560 -- Import_Function --
15561 ---------------------
15563 -- pragma Import_Function (
15564 -- [Internal =>] LOCAL_NAME,
15565 -- [, [External =>] EXTERNAL_SYMBOL]
15566 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15567 -- [, [Result_Type =>] SUBTYPE_MARK]
15568 -- [, [Mechanism =>] MECHANISM]
15569 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15571 -- EXTERNAL_SYMBOL ::=
15573 -- | static_string_EXPRESSION
15575 -- PARAMETER_TYPES ::=
15577 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15579 -- TYPE_DESIGNATOR ::=
15581 -- | subtype_Name ' Access
15585 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15587 -- MECHANISM_ASSOCIATION ::=
15588 -- [formal_parameter_NAME =>] MECHANISM_NAME
15590 -- MECHANISM_NAME ::=
15594 when Pragma_Import_Function
=> Import_Function
: declare
15595 Args
: Args_List
(1 .. 6);
15596 Names
: constant Name_List
(1 .. 6) := (
15599 Name_Parameter_Types
,
15602 Name_Result_Mechanism
);
15604 Internal
: Node_Id
renames Args
(1);
15605 External
: Node_Id
renames Args
(2);
15606 Parameter_Types
: Node_Id
renames Args
(3);
15607 Result_Type
: Node_Id
renames Args
(4);
15608 Mechanism
: Node_Id
renames Args
(5);
15609 Result_Mechanism
: Node_Id
renames Args
(6);
15613 Gather_Associations
(Names
, Args
);
15614 Process_Extended_Import_Export_Subprogram_Pragma
(
15615 Arg_Internal
=> Internal
,
15616 Arg_External
=> External
,
15617 Arg_Parameter_Types
=> Parameter_Types
,
15618 Arg_Result_Type
=> Result_Type
,
15619 Arg_Mechanism
=> Mechanism
,
15620 Arg_Result_Mechanism
=> Result_Mechanism
);
15621 end Import_Function
;
15623 -------------------
15624 -- Import_Object --
15625 -------------------
15627 -- pragma Import_Object (
15628 -- [Internal =>] LOCAL_NAME
15629 -- [, [External =>] EXTERNAL_SYMBOL]
15630 -- [, [Size =>] EXTERNAL_SYMBOL]);
15632 -- EXTERNAL_SYMBOL ::=
15634 -- | static_string_EXPRESSION
15636 when Pragma_Import_Object
=> Import_Object
: declare
15637 Args
: Args_List
(1 .. 3);
15638 Names
: constant Name_List
(1 .. 3) := (
15643 Internal
: Node_Id
renames Args
(1);
15644 External
: Node_Id
renames Args
(2);
15645 Size
: Node_Id
renames Args
(3);
15649 Gather_Associations
(Names
, Args
);
15650 Process_Extended_Import_Export_Object_Pragma
(
15651 Arg_Internal
=> Internal
,
15652 Arg_External
=> External
,
15656 ----------------------
15657 -- Import_Procedure --
15658 ----------------------
15660 -- pragma Import_Procedure (
15661 -- [Internal =>] LOCAL_NAME
15662 -- [, [External =>] EXTERNAL_SYMBOL]
15663 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15664 -- [, [Mechanism =>] MECHANISM]);
15666 -- EXTERNAL_SYMBOL ::=
15668 -- | static_string_EXPRESSION
15670 -- PARAMETER_TYPES ::=
15672 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15674 -- TYPE_DESIGNATOR ::=
15676 -- | subtype_Name ' Access
15680 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15682 -- MECHANISM_ASSOCIATION ::=
15683 -- [formal_parameter_NAME =>] MECHANISM_NAME
15685 -- MECHANISM_NAME ::=
15689 when Pragma_Import_Procedure
=> Import_Procedure
: declare
15690 Args
: Args_List
(1 .. 4);
15691 Names
: constant Name_List
(1 .. 4) := (
15694 Name_Parameter_Types
,
15697 Internal
: Node_Id
renames Args
(1);
15698 External
: Node_Id
renames Args
(2);
15699 Parameter_Types
: Node_Id
renames Args
(3);
15700 Mechanism
: Node_Id
renames Args
(4);
15704 Gather_Associations
(Names
, Args
);
15705 Process_Extended_Import_Export_Subprogram_Pragma
(
15706 Arg_Internal
=> Internal
,
15707 Arg_External
=> External
,
15708 Arg_Parameter_Types
=> Parameter_Types
,
15709 Arg_Mechanism
=> Mechanism
);
15710 end Import_Procedure
;
15712 -----------------------------
15713 -- Import_Valued_Procedure --
15714 -----------------------------
15716 -- pragma Import_Valued_Procedure (
15717 -- [Internal =>] LOCAL_NAME
15718 -- [, [External =>] EXTERNAL_SYMBOL]
15719 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15720 -- [, [Mechanism =>] MECHANISM]);
15722 -- EXTERNAL_SYMBOL ::=
15724 -- | static_string_EXPRESSION
15726 -- PARAMETER_TYPES ::=
15728 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15730 -- TYPE_DESIGNATOR ::=
15732 -- | subtype_Name ' Access
15736 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15738 -- MECHANISM_ASSOCIATION ::=
15739 -- [formal_parameter_NAME =>] MECHANISM_NAME
15741 -- MECHANISM_NAME ::=
15745 when Pragma_Import_Valued_Procedure
=>
15746 Import_Valued_Procedure
: declare
15747 Args
: Args_List
(1 .. 4);
15748 Names
: constant Name_List
(1 .. 4) := (
15751 Name_Parameter_Types
,
15754 Internal
: Node_Id
renames Args
(1);
15755 External
: Node_Id
renames Args
(2);
15756 Parameter_Types
: Node_Id
renames Args
(3);
15757 Mechanism
: Node_Id
renames Args
(4);
15761 Gather_Associations
(Names
, Args
);
15762 Process_Extended_Import_Export_Subprogram_Pragma
(
15763 Arg_Internal
=> Internal
,
15764 Arg_External
=> External
,
15765 Arg_Parameter_Types
=> Parameter_Types
,
15766 Arg_Mechanism
=> Mechanism
);
15767 end Import_Valued_Procedure
;
15773 -- pragma Independent (LOCAL_NAME);
15775 when Pragma_Independent
=>
15776 Process_Atomic_Independent_Shared_Volatile
;
15778 ----------------------------
15779 -- Independent_Components --
15780 ----------------------------
15782 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
15784 when Pragma_Independent_Components
=> Independent_Components
: declare
15792 Check_Ada_83_Warning
;
15794 Check_No_Identifiers
;
15795 Check_Arg_Count
(1);
15796 Check_Arg_Is_Local_Name
(Arg1
);
15797 E_Id
:= Get_Pragma_Arg
(Arg1
);
15799 if Etype
(E_Id
) = Any_Type
then
15803 E
:= Entity
(E_Id
);
15805 -- A pragma that applies to a Ghost entity becomes Ghost for the
15806 -- purposes of legality checks and removal of ignored Ghost code.
15808 Mark_Pragma_As_Ghost
(N
, E
);
15810 -- Check duplicate before we chain ourselves
15812 Check_Duplicate_Pragma
(E
);
15814 -- Check appropriate entity
15816 if Rep_Item_Too_Early
(E
, N
)
15818 Rep_Item_Too_Late
(E
, N
)
15823 D
:= Declaration_Node
(E
);
15826 -- The flag is set on the base type, or on the object
15828 if K
= N_Full_Type_Declaration
15829 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
15831 Set_Has_Independent_Components
(Base_Type
(E
));
15832 Record_Independence_Check
(N
, Base_Type
(E
));
15834 -- For record type, set all components independent
15836 if Is_Record_Type
(E
) then
15837 C
:= First_Component
(E
);
15838 while Present
(C
) loop
15839 Set_Is_Independent
(C
);
15840 Next_Component
(C
);
15844 elsif (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
15845 and then Nkind
(D
) = N_Object_Declaration
15846 and then Nkind
(Object_Definition
(D
)) =
15847 N_Constrained_Array_Definition
15849 Set_Has_Independent_Components
(E
);
15850 Record_Independence_Check
(N
, E
);
15853 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
15855 end Independent_Components
;
15857 -----------------------
15858 -- Initial_Condition --
15859 -----------------------
15861 -- pragma Initial_Condition (boolean_EXPRESSION);
15863 -- Characteristics:
15865 -- * Analysis - The annotation undergoes initial checks to verify
15866 -- the legal placement and context. Secondary checks preanalyze the
15869 -- Analyze_Initial_Condition_In_Decl_Part
15871 -- * Expansion - The annotation is expanded during the expansion of
15872 -- the package body whose declaration is subject to the annotation
15875 -- Expand_Pragma_Initial_Condition
15877 -- * Template - The annotation utilizes the generic template of the
15878 -- related package declaration.
15880 -- * Globals - Capture of global references must occur after full
15883 -- * Instance - The annotation is instantiated automatically when
15884 -- the related generic package is instantiated.
15886 when Pragma_Initial_Condition
=> Initial_Condition
: declare
15887 Pack_Decl
: Node_Id
;
15888 Pack_Id
: Entity_Id
;
15892 Check_No_Identifiers
;
15893 Check_Arg_Count
(1);
15895 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
15897 -- Ensure the proper placement of the pragma. Initial_Condition
15898 -- must be associated with a package declaration.
15900 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
15901 N_Package_Declaration
)
15905 -- Otherwise the pragma is associated with an illegal context
15912 Pack_Id
:= Defining_Entity
(Pack_Decl
);
15914 -- Chain the pragma on the contract for further processing by
15915 -- Analyze_Initial_Condition_In_Decl_Part.
15917 Add_Contract_Item
(N
, Pack_Id
);
15919 -- The legality checks of pragmas Abstract_State, Initializes, and
15920 -- Initial_Condition are affected by the SPARK mode in effect. In
15921 -- addition, these three pragmas are subject to an inherent order:
15923 -- 1) Abstract_State
15925 -- 3) Initial_Condition
15927 -- Analyze all these pragmas in the order outlined above
15929 Analyze_If_Present
(Pragma_SPARK_Mode
);
15930 Analyze_If_Present
(Pragma_Abstract_State
);
15931 Analyze_If_Present
(Pragma_Initializes
);
15933 -- A pragma that applies to a Ghost entity becomes Ghost for the
15934 -- purposes of legality checks and removal of ignored Ghost code.
15936 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
15937 end Initial_Condition
;
15939 ------------------------
15940 -- Initialize_Scalars --
15941 ------------------------
15943 -- pragma Initialize_Scalars;
15945 when Pragma_Initialize_Scalars
=>
15947 Check_Arg_Count
(0);
15948 Check_Valid_Configuration_Pragma
;
15949 Check_Restriction
(No_Initialize_Scalars
, N
);
15951 -- Initialize_Scalars creates false positives in CodePeer, and
15952 -- incorrect negative results in GNATprove mode, so ignore this
15953 -- pragma in these modes.
15955 if not Restriction_Active
(No_Initialize_Scalars
)
15956 and then not (CodePeer_Mode
or GNATprove_Mode
)
15958 Init_Or_Norm_Scalars
:= True;
15959 Initialize_Scalars
:= True;
15966 -- pragma Initializes (INITIALIZATION_LIST);
15968 -- INITIALIZATION_LIST ::=
15970 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15972 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15977 -- | (INPUT {, INPUT})
15981 -- Characteristics:
15983 -- * Analysis - The annotation undergoes initial checks to verify
15984 -- the legal placement and context. Secondary checks preanalyze the
15987 -- Analyze_Initializes_In_Decl_Part
15989 -- * Expansion - None.
15991 -- * Template - The annotation utilizes the generic template of the
15992 -- related package declaration.
15994 -- * Globals - Capture of global references must occur after full
15997 -- * Instance - The annotation is instantiated automatically when
15998 -- the related generic package is instantiated.
16000 when Pragma_Initializes
=> Initializes
: declare
16001 Pack_Decl
: Node_Id
;
16002 Pack_Id
: Entity_Id
;
16006 Check_No_Identifiers
;
16007 Check_Arg_Count
(1);
16009 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
16011 -- Ensure the proper placement of the pragma. Initializes must be
16012 -- associated with a package declaration.
16014 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
16015 N_Package_Declaration
)
16019 -- Otherwise the pragma is associated with an illegal construc
16026 Pack_Id
:= Defining_Entity
(Pack_Decl
);
16028 -- Chain the pragma on the contract for further processing by
16029 -- Analyze_Initializes_In_Decl_Part.
16031 Add_Contract_Item
(N
, Pack_Id
);
16033 -- The legality checks of pragmas Abstract_State, Initializes, and
16034 -- Initial_Condition are affected by the SPARK mode in effect. In
16035 -- addition, these three pragmas are subject to an inherent order:
16037 -- 1) Abstract_State
16039 -- 3) Initial_Condition
16041 -- Analyze all these pragmas in the order outlined above
16043 Analyze_If_Present
(Pragma_SPARK_Mode
);
16044 Analyze_If_Present
(Pragma_Abstract_State
);
16046 -- A pragma that applies to a Ghost entity becomes Ghost for the
16047 -- purposes of legality checks and removal of ignored Ghost code.
16049 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
16050 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
16052 Analyze_If_Present
(Pragma_Initial_Condition
);
16059 -- pragma Inline ( NAME {, NAME} );
16061 when Pragma_Inline
=>
16063 -- Pragma always active unless in GNATprove mode. It is disabled
16064 -- in GNATprove mode because frontend inlining is applied
16065 -- independently of pragmas Inline and Inline_Always for
16066 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
16069 if not GNATprove_Mode
then
16071 -- Inline status is Enabled if inlining option is active
16073 if Inline_Active
then
16074 Process_Inline
(Enabled
);
16076 Process_Inline
(Disabled
);
16080 -------------------
16081 -- Inline_Always --
16082 -------------------
16084 -- pragma Inline_Always ( NAME {, NAME} );
16086 when Pragma_Inline_Always
=>
16089 -- Pragma always active unless in CodePeer mode or GNATprove
16090 -- mode. It is disabled in CodePeer mode because inlining is
16091 -- not helpful, and enabling it caused walk order issues. It
16092 -- is disabled in GNATprove mode because frontend inlining is
16093 -- applied independently of pragmas Inline and Inline_Always for
16094 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
16097 if not CodePeer_Mode
and not GNATprove_Mode
then
16098 Process_Inline
(Enabled
);
16101 --------------------
16102 -- Inline_Generic --
16103 --------------------
16105 -- pragma Inline_Generic (NAME {, NAME});
16107 when Pragma_Inline_Generic
=>
16109 Process_Generic_List
;
16111 ----------------------
16112 -- Inspection_Point --
16113 ----------------------
16115 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
16117 when Pragma_Inspection_Point
=> Inspection_Point
: declare
16124 if Arg_Count
> 0 then
16127 Exp
:= Get_Pragma_Arg
(Arg
);
16130 if not Is_Entity_Name
(Exp
)
16131 or else not Is_Object
(Entity
(Exp
))
16133 Error_Pragma_Arg
("object name required", Arg
);
16137 exit when No
(Arg
);
16140 end Inspection_Point
;
16146 -- pragma Interface (
16147 -- [ Convention =>] convention_IDENTIFIER,
16148 -- [ Entity =>] LOCAL_NAME
16149 -- [, [External_Name =>] static_string_EXPRESSION ]
16150 -- [, [Link_Name =>] static_string_EXPRESSION ]);
16152 when Pragma_Interface
=>
16157 Name_External_Name
,
16159 Check_At_Least_N_Arguments
(2);
16160 Check_At_Most_N_Arguments
(4);
16161 Process_Import_Or_Interface
;
16163 -- In Ada 2005, the permission to use Interface (a reserved word)
16164 -- as a pragma name is considered an obsolescent feature, and this
16165 -- pragma was already obsolescent in Ada 95.
16167 if Ada_Version
>= Ada_95
then
16169 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
16171 if Warn_On_Obsolescent_Feature
then
16173 ("pragma Interface is an obsolescent feature?j?", N
);
16175 ("|use pragma Import instead?j?", N
);
16179 --------------------
16180 -- Interface_Name --
16181 --------------------
16183 -- pragma Interface_Name (
16184 -- [ Entity =>] LOCAL_NAME
16185 -- [,[External_Name =>] static_string_EXPRESSION ]
16186 -- [,[Link_Name =>] static_string_EXPRESSION ]);
16188 when Pragma_Interface_Name
=> Interface_Name
: declare
16190 Def_Id
: Entity_Id
;
16191 Hom_Id
: Entity_Id
;
16197 ((Name_Entity
, Name_External_Name
, Name_Link_Name
));
16198 Check_At_Least_N_Arguments
(2);
16199 Check_At_Most_N_Arguments
(3);
16200 Id
:= Get_Pragma_Arg
(Arg1
);
16203 -- This is obsolete from Ada 95 on, but it is an implementation
16204 -- defined pragma, so we do not consider that it violates the
16205 -- restriction (No_Obsolescent_Features).
16207 if Ada_Version
>= Ada_95
then
16208 if Warn_On_Obsolescent_Feature
then
16210 ("pragma Interface_Name is an obsolescent feature?j?", N
);
16212 ("|use pragma Import instead?j?", N
);
16216 if not Is_Entity_Name
(Id
) then
16218 ("first argument for pragma% must be entity name", Arg1
);
16219 elsif Etype
(Id
) = Any_Type
then
16222 Def_Id
:= Entity
(Id
);
16225 -- Special DEC-compatible processing for the object case, forces
16226 -- object to be imported.
16228 if Ekind
(Def_Id
) = E_Variable
then
16229 Kill_Size_Check_Code
(Def_Id
);
16230 Note_Possible_Modification
(Id
, Sure
=> False);
16232 -- Initialization is not allowed for imported variable
16234 if Present
(Expression
(Parent
(Def_Id
)))
16235 and then Comes_From_Source
(Expression
(Parent
(Def_Id
)))
16237 Error_Msg_Sloc
:= Sloc
(Def_Id
);
16239 ("no initialization allowed for declaration of& #",
16243 -- For compatibility, support VADS usage of providing both
16244 -- pragmas Interface and Interface_Name to obtain the effect
16245 -- of a single Import pragma.
16247 if Is_Imported
(Def_Id
)
16248 and then Present
(First_Rep_Item
(Def_Id
))
16249 and then Nkind
(First_Rep_Item
(Def_Id
)) = N_Pragma
16251 Pragma_Name
(First_Rep_Item
(Def_Id
)) = Name_Interface
16255 Set_Imported
(Def_Id
);
16258 Set_Is_Public
(Def_Id
);
16259 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
16262 -- Otherwise must be subprogram
16264 elsif not Is_Subprogram
(Def_Id
) then
16266 ("argument of pragma% is not subprogram", Arg1
);
16269 Check_At_Most_N_Arguments
(3);
16273 -- Loop through homonyms
16276 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
16278 if Is_Imported
(Def_Id
) then
16279 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
16283 exit when From_Aspect_Specification
(N
);
16284 Hom_Id
:= Homonym
(Hom_Id
);
16286 exit when No
(Hom_Id
)
16287 or else Scope
(Hom_Id
) /= Current_Scope
;
16292 ("argument of pragma% is not imported subprogram",
16296 end Interface_Name
;
16298 -----------------------
16299 -- Interrupt_Handler --
16300 -----------------------
16302 -- pragma Interrupt_Handler (handler_NAME);
16304 when Pragma_Interrupt_Handler
=>
16305 Check_Ada_83_Warning
;
16306 Check_Arg_Count
(1);
16307 Check_No_Identifiers
;
16309 if No_Run_Time_Mode
then
16310 Error_Msg_CRT
("Interrupt_Handler pragma", N
);
16312 Check_Interrupt_Or_Attach_Handler
;
16313 Process_Interrupt_Or_Attach_Handler
;
16316 ------------------------
16317 -- Interrupt_Priority --
16318 ------------------------
16320 -- pragma Interrupt_Priority [(EXPRESSION)];
16322 when Pragma_Interrupt_Priority
=> Interrupt_Priority
: declare
16323 P
: constant Node_Id
:= Parent
(N
);
16328 Check_Ada_83_Warning
;
16330 if Arg_Count
/= 0 then
16331 Arg
:= Get_Pragma_Arg
(Arg1
);
16332 Check_Arg_Count
(1);
16333 Check_No_Identifiers
;
16335 -- The expression must be analyzed in the special manner
16336 -- described in "Handling of Default and Per-Object
16337 -- Expressions" in sem.ads.
16339 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Interrupt_Priority
));
16342 if not Nkind_In
(P
, N_Task_Definition
, N_Protected_Definition
) then
16347 Ent
:= Defining_Identifier
(Parent
(P
));
16349 -- Check duplicate pragma before we chain the pragma in the Rep
16350 -- Item chain of Ent.
16352 Check_Duplicate_Pragma
(Ent
);
16353 Record_Rep_Item
(Ent
, N
);
16355 -- Check the No_Task_At_Interrupt_Priority restriction
16357 if Nkind
(P
) = N_Task_Definition
then
16358 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
16361 end Interrupt_Priority
;
16363 ---------------------
16364 -- Interrupt_State --
16365 ---------------------
16367 -- pragma Interrupt_State (
16368 -- [Name =>] INTERRUPT_ID,
16369 -- [State =>] INTERRUPT_STATE);
16371 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
16372 -- INTERRUPT_STATE => System | Runtime | User
16374 -- Note: if the interrupt id is given as an identifier, then it must
16375 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
16376 -- given as a static integer expression which must be in the range of
16377 -- Ada.Interrupts.Interrupt_ID.
16379 when Pragma_Interrupt_State
=> Interrupt_State
: declare
16380 Int_Id
: constant Entity_Id
:= RTE
(RE_Interrupt_ID
);
16381 -- This is the entity Ada.Interrupts.Interrupt_ID;
16383 State_Type
: Character;
16384 -- Set to 's'/'r'/'u' for System/Runtime/User
16387 -- Index to entry in Interrupt_States table
16390 -- Value of interrupt
16392 Arg1X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
16393 -- The first argument to the pragma
16395 Int_Ent
: Entity_Id
;
16396 -- Interrupt entity in Ada.Interrupts.Names
16400 Check_Arg_Order
((Name_Name
, Name_State
));
16401 Check_Arg_Count
(2);
16403 Check_Optional_Identifier
(Arg1
, Name_Name
);
16404 Check_Optional_Identifier
(Arg2
, Name_State
);
16405 Check_Arg_Is_Identifier
(Arg2
);
16407 -- First argument is identifier
16409 if Nkind
(Arg1X
) = N_Identifier
then
16411 -- Search list of names in Ada.Interrupts.Names
16413 Int_Ent
:= First_Entity
(RTE
(RE_Names
));
16415 if No
(Int_Ent
) then
16416 Error_Pragma_Arg
("invalid interrupt name", Arg1
);
16418 elsif Chars
(Int_Ent
) = Chars
(Arg1X
) then
16419 Int_Val
:= Expr_Value
(Constant_Value
(Int_Ent
));
16423 Next_Entity
(Int_Ent
);
16426 -- First argument is not an identifier, so it must be a static
16427 -- expression of type Ada.Interrupts.Interrupt_ID.
16430 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
16431 Int_Val
:= Expr_Value
(Arg1X
);
16433 if Int_Val
< Expr_Value
(Type_Low_Bound
(Int_Id
))
16435 Int_Val
> Expr_Value
(Type_High_Bound
(Int_Id
))
16438 ("value not in range of type "
16439 & """Ada.Interrupts.Interrupt_'I'D""", Arg1
);
16445 case Chars
(Get_Pragma_Arg
(Arg2
)) is
16446 when Name_Runtime
=> State_Type
:= 'r';
16447 when Name_System
=> State_Type
:= 's';
16448 when Name_User
=> State_Type
:= 'u';
16451 Error_Pragma_Arg
("invalid interrupt state", Arg2
);
16454 -- Check if entry is already stored
16456 IST_Num
:= Interrupt_States
.First
;
16458 -- If entry not found, add it
16460 if IST_Num
> Interrupt_States
.Last
then
16461 Interrupt_States
.Append
16462 ((Interrupt_Number
=> UI_To_Int
(Int_Val
),
16463 Interrupt_State
=> State_Type
,
16464 Pragma_Loc
=> Loc
));
16467 -- Case of entry for the same entry
16469 elsif Int_Val
= Interrupt_States
.Table
(IST_Num
).
16472 -- If state matches, done, no need to make redundant entry
16475 State_Type
= Interrupt_States
.Table
(IST_Num
).
16478 -- Otherwise if state does not match, error
16481 Interrupt_States
.Table
(IST_Num
).Pragma_Loc
;
16483 ("state conflicts with that given #", Arg2
);
16487 IST_Num
:= IST_Num
+ 1;
16489 end Interrupt_State
;
16495 -- pragma Invariant
16496 -- ([Entity =>] type_LOCAL_NAME,
16497 -- [Check =>] EXPRESSION
16498 -- [,[Message =>] String_Expression]);
16500 when Pragma_Invariant
=> Invariant
: declare
16507 Check_At_Least_N_Arguments
(2);
16508 Check_At_Most_N_Arguments
(3);
16509 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16510 Check_Optional_Identifier
(Arg2
, Name_Check
);
16512 if Arg_Count
= 3 then
16513 Check_Optional_Identifier
(Arg3
, Name_Message
);
16514 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
16517 Check_Arg_Is_Local_Name
(Arg1
);
16519 Type_Id
:= Get_Pragma_Arg
(Arg1
);
16520 Find_Type
(Type_Id
);
16521 Typ
:= Entity
(Type_Id
);
16523 if Typ
= Any_Type
then
16526 -- Invariants allowed in interface types (RM 7.3.2(3/3))
16528 elsif Is_Interface
(Typ
) then
16531 -- An invariant must apply to a private type, or appear in the
16532 -- private part of a package spec and apply to a completion.
16533 -- a class-wide invariant can only appear on a private declaration
16534 -- or private extension, not a completion.
16536 elsif Ekind_In
(Typ
, E_Private_Type
,
16537 E_Record_Type_With_Private
,
16538 E_Limited_Private_Type
)
16542 elsif In_Private_Part
(Current_Scope
)
16543 and then Has_Private_Declaration
(Typ
)
16544 and then not Class_Present
(N
)
16548 elsif In_Private_Part
(Current_Scope
) then
16550 ("pragma% only allowed for private type declared in "
16551 & "visible part", Arg1
);
16555 ("pragma% only allowed for private type", Arg1
);
16558 -- A pragma that applies to a Ghost entity becomes Ghost for the
16559 -- purposes of legality checks and removal of ignored Ghost code.
16561 Mark_Pragma_As_Ghost
(N
, Typ
);
16563 -- Not allowed for abstract type in the non-class case (it is
16564 -- allowed to use Invariant'Class for abstract types).
16566 if Is_Abstract_Type
(Typ
) and then not Class_Present
(N
) then
16568 ("pragma% not allowed for abstract type", Arg1
);
16571 -- Link the pragma on to the rep item chain, for processing when
16572 -- the type is frozen.
16574 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
16576 -- Note that the type has at least one invariant, and also that
16577 -- it has inheritable invariants if we have Invariant'Class
16578 -- or Type_Invariant'Class. Build the corresponding invariant
16579 -- procedure declaration, so that calls to it can be generated
16580 -- before the body is built (e.g. within an expression function).
16582 -- Interface types have no invariant procedure; their invariants
16583 -- are propagated to the build invariant procedure of all the
16584 -- types covering the interface type.
16586 if not Is_Interface
(Typ
) then
16587 Insert_After_And_Analyze
16588 (N
, Build_Invariant_Procedure_Declaration
(Typ
));
16591 if Class_Present
(N
) then
16592 Set_Has_Inheritable_Invariants
(Typ
);
16600 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16602 when Pragma_Keep_Names
=> Keep_Names
: declare
16607 Check_Arg_Count
(1);
16608 Check_Optional_Identifier
(Arg1
, Name_On
);
16609 Check_Arg_Is_Local_Name
(Arg1
);
16611 Arg
:= Get_Pragma_Arg
(Arg1
);
16614 if Etype
(Arg
) = Any_Type
then
16618 if not Is_Entity_Name
(Arg
)
16619 or else Ekind
(Entity
(Arg
)) /= E_Enumeration_Type
16622 ("pragma% requires a local enumeration type", Arg1
);
16625 Set_Discard_Names
(Entity
(Arg
), False);
16632 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16634 when Pragma_License
=>
16637 -- Do not analyze pragma any further in CodePeer mode, to avoid
16638 -- extraneous errors in this implementation-dependent pragma,
16639 -- which has a different profile on other compilers.
16641 if CodePeer_Mode
then
16645 Check_Arg_Count
(1);
16646 Check_No_Identifiers
;
16647 Check_Valid_Configuration_Pragma
;
16648 Check_Arg_Is_Identifier
(Arg1
);
16651 Sind
: constant Source_File_Index
:=
16652 Source_Index
(Current_Sem_Unit
);
16655 case Chars
(Get_Pragma_Arg
(Arg1
)) is
16657 Set_License
(Sind
, GPL
);
16659 when Name_Modified_GPL
=>
16660 Set_License
(Sind
, Modified_GPL
);
16662 when Name_Restricted
=>
16663 Set_License
(Sind
, Restricted
);
16665 when Name_Unrestricted
=>
16666 Set_License
(Sind
, Unrestricted
);
16669 Error_Pragma_Arg
("invalid license name", Arg1
);
16677 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16679 when Pragma_Link_With
=> Link_With
: declare
16685 if Operating_Mode
= Generate_Code
16686 and then In_Extended_Main_Source_Unit
(N
)
16688 Check_At_Least_N_Arguments
(1);
16689 Check_No_Identifiers
;
16690 Check_Is_In_Decl_Part_Or_Package_Spec
;
16691 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16695 while Present
(Arg
) loop
16696 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
16698 -- Store argument, converting sequences of spaces to a
16699 -- single null character (this is one of the differences
16700 -- in processing between Link_With and Linker_Options).
16702 Arg_Store
: declare
16703 C
: constant Char_Code
:= Get_Char_Code
(' ');
16704 S
: constant String_Id
:=
16705 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
)));
16706 L
: constant Nat
:= String_Length
(S
);
16709 procedure Skip_Spaces
;
16710 -- Advance F past any spaces
16716 procedure Skip_Spaces
is
16718 while F
<= L
and then Get_String_Char
(S
, F
) = C
loop
16723 -- Start of processing for Arg_Store
16726 Skip_Spaces
; -- skip leading spaces
16728 -- Loop through characters, changing any embedded
16729 -- sequence of spaces to a single null character (this
16730 -- is how Link_With/Linker_Options differ)
16733 if Get_String_Char
(S
, F
) = C
then
16736 Store_String_Char
(ASCII
.NUL
);
16739 Store_String_Char
(Get_String_Char
(S
, F
));
16747 if Present
(Arg
) then
16748 Store_String_Char
(ASCII
.NUL
);
16752 Store_Linker_Option_String
(End_String
);
16760 -- pragma Linker_Alias (
16761 -- [Entity =>] LOCAL_NAME
16762 -- [Target =>] static_string_EXPRESSION);
16764 when Pragma_Linker_Alias
=>
16766 Check_Arg_Order
((Name_Entity
, Name_Target
));
16767 Check_Arg_Count
(2);
16768 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16769 Check_Optional_Identifier
(Arg2
, Name_Target
);
16770 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
16771 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16773 -- The only processing required is to link this item on to the
16774 -- list of rep items for the given entity. This is accomplished
16775 -- by the call to Rep_Item_Too_Late (when no error is detected
16776 -- and False is returned).
16778 if Rep_Item_Too_Late
(Entity
(Get_Pragma_Arg
(Arg1
)), N
) then
16781 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
16784 ------------------------
16785 -- Linker_Constructor --
16786 ------------------------
16788 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16790 -- Code is shared with Linker_Destructor
16792 -----------------------
16793 -- Linker_Destructor --
16794 -----------------------
16796 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16798 when Pragma_Linker_Constructor |
16799 Pragma_Linker_Destructor
=>
16800 Linker_Constructor
: declare
16806 Check_Arg_Count
(1);
16807 Check_No_Identifiers
;
16808 Check_Arg_Is_Local_Name
(Arg1
);
16809 Arg1_X
:= Get_Pragma_Arg
(Arg1
);
16811 Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
16813 if not Is_Library_Level_Entity
(Proc
) then
16815 ("argument for pragma% must be library level entity", Arg1
);
16818 -- The only processing required is to link this item on to the
16819 -- list of rep items for the given entity. This is accomplished
16820 -- by the call to Rep_Item_Too_Late (when no error is detected
16821 -- and False is returned).
16823 if Rep_Item_Too_Late
(Proc
, N
) then
16826 Set_Has_Gigi_Rep_Item
(Proc
);
16828 end Linker_Constructor
;
16830 --------------------
16831 -- Linker_Options --
16832 --------------------
16834 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16836 when Pragma_Linker_Options
=> Linker_Options
: declare
16840 Check_Ada_83_Warning
;
16841 Check_No_Identifiers
;
16842 Check_Arg_Count
(1);
16843 Check_Is_In_Decl_Part_Or_Package_Spec
;
16844 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16845 Start_String
(Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg1
))));
16848 while Present
(Arg
) loop
16849 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
16850 Store_String_Char
(ASCII
.NUL
);
16852 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
16856 if Operating_Mode
= Generate_Code
16857 and then In_Extended_Main_Source_Unit
(N
)
16859 Store_Linker_Option_String
(End_String
);
16861 end Linker_Options
;
16863 --------------------
16864 -- Linker_Section --
16865 --------------------
16867 -- pragma Linker_Section (
16868 -- [Entity =>] LOCAL_NAME
16869 -- [Section =>] static_string_EXPRESSION);
16871 when Pragma_Linker_Section
=> Linker_Section
: declare
16876 Ghost_Error_Posted
: Boolean := False;
16877 -- Flag set when an error concerning the illegal mix of Ghost and
16878 -- non-Ghost subprograms is emitted.
16880 Ghost_Id
: Entity_Id
:= Empty
;
16881 -- The entity of the first Ghost subprogram encountered while
16882 -- processing the arguments of the pragma.
16886 Check_Arg_Order
((Name_Entity
, Name_Section
));
16887 Check_Arg_Count
(2);
16888 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16889 Check_Optional_Identifier
(Arg2
, Name_Section
);
16890 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
16891 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16893 -- Check kind of entity
16895 Arg
:= Get_Pragma_Arg
(Arg1
);
16896 Ent
:= Entity
(Arg
);
16898 case Ekind
(Ent
) is
16900 -- Objects (constants and variables) and types. For these cases
16901 -- all we need to do is to set the Linker_Section_pragma field,
16902 -- checking that we do not have a duplicate.
16904 when E_Constant | E_Variable | Type_Kind
=>
16905 LPE
:= Linker_Section_Pragma
(Ent
);
16907 if Present
(LPE
) then
16908 Error_Msg_Sloc
:= Sloc
(LPE
);
16910 ("Linker_Section already specified for &#", Arg1
, Ent
);
16913 Set_Linker_Section_Pragma
(Ent
, N
);
16915 -- A pragma that applies to a Ghost entity becomes Ghost for
16916 -- the purposes of legality checks and removal of ignored
16919 Mark_Pragma_As_Ghost
(N
, Ent
);
16923 when Subprogram_Kind
=>
16925 -- Aspect case, entity already set
16927 if From_Aspect_Specification
(N
) then
16928 Set_Linker_Section_Pragma
16929 (Entity
(Corresponding_Aspect
(N
)), N
);
16931 -- Pragma case, we must climb the homonym chain, but skip
16932 -- any for which the linker section is already set.
16936 if No
(Linker_Section_Pragma
(Ent
)) then
16937 Set_Linker_Section_Pragma
(Ent
, N
);
16939 -- A pragma that applies to a Ghost entity becomes
16940 -- Ghost for the purposes of legality checks and
16941 -- removal of ignored Ghost code.
16943 Mark_Pragma_As_Ghost
(N
, Ent
);
16945 -- Capture the entity of the first Ghost subprogram
16946 -- being processed for error detection purposes.
16948 if Is_Ghost_Entity
(Ent
) then
16949 if No
(Ghost_Id
) then
16953 -- Otherwise the subprogram is non-Ghost. It is
16954 -- illegal to mix references to Ghost and non-Ghost
16955 -- entities (SPARK RM 6.9).
16957 elsif Present
(Ghost_Id
)
16958 and then not Ghost_Error_Posted
16960 Ghost_Error_Posted
:= True;
16962 Error_Msg_Name_1
:= Pname
;
16964 ("pragma % cannot mention ghost and "
16965 & "non-ghost subprograms", N
);
16967 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
16969 ("\& # declared as ghost", N
, Ghost_Id
);
16971 Error_Msg_Sloc
:= Sloc
(Ent
);
16973 ("\& # declared as non-ghost", N
, Ent
);
16977 Ent
:= Homonym
(Ent
);
16979 or else Scope
(Ent
) /= Current_Scope
;
16983 -- All other cases are illegal
16987 ("pragma% applies only to objects, subprograms, and types",
16990 end Linker_Section
;
16996 -- pragma List (On | Off)
16998 -- There is nothing to do here, since we did all the processing for
16999 -- this pragma in Par.Prag (so that it works properly even in syntax
17002 when Pragma_List
=>
17009 -- pragma Lock_Free [(Boolean_EXPRESSION)];
17011 when Pragma_Lock_Free
=> Lock_Free
: declare
17012 P
: constant Node_Id
:= Parent
(N
);
17018 Check_No_Identifiers
;
17019 Check_At_Most_N_Arguments
(1);
17021 -- Protected definition case
17023 if Nkind
(P
) = N_Protected_Definition
then
17024 Ent
:= Defining_Identifier
(Parent
(P
));
17028 if Arg_Count
= 1 then
17029 Arg
:= Get_Pragma_Arg
(Arg1
);
17030 Val
:= Is_True
(Static_Boolean
(Arg
));
17032 -- No arguments (expression is considered to be True)
17038 -- Check duplicate pragma before we chain the pragma in the Rep
17039 -- Item chain of Ent.
17041 Check_Duplicate_Pragma
(Ent
);
17042 Record_Rep_Item
(Ent
, N
);
17043 Set_Uses_Lock_Free
(Ent
, Val
);
17045 -- Anything else is incorrect placement
17052 --------------------
17053 -- Locking_Policy --
17054 --------------------
17056 -- pragma Locking_Policy (policy_IDENTIFIER);
17058 when Pragma_Locking_Policy
=> declare
17059 subtype LP_Range
is Name_Id
17060 range First_Locking_Policy_Name
.. Last_Locking_Policy_Name
;
17065 Check_Ada_83_Warning
;
17066 Check_Arg_Count
(1);
17067 Check_No_Identifiers
;
17068 Check_Arg_Is_Locking_Policy
(Arg1
);
17069 Check_Valid_Configuration_Pragma
;
17070 LP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
17073 when Name_Ceiling_Locking
=>
17075 when Name_Inheritance_Locking
=>
17077 when Name_Concurrent_Readers_Locking
=>
17081 if Locking_Policy
/= ' '
17082 and then Locking_Policy
/= LP
17084 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
17085 Error_Pragma
("locking policy incompatible with policy#");
17087 -- Set new policy, but always preserve System_Location since we
17088 -- like the error message with the run time name.
17091 Locking_Policy
:= LP
;
17093 if Locking_Policy_Sloc
/= System_Location
then
17094 Locking_Policy_Sloc
:= Loc
;
17099 -------------------
17100 -- Loop_Optimize --
17101 -------------------
17103 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
17105 -- OPTIMIZATION_HINT ::=
17106 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
17108 when Pragma_Loop_Optimize
=> Loop_Optimize
: declare
17113 Check_At_Least_N_Arguments
(1);
17114 Check_No_Identifiers
;
17116 Hint
:= First
(Pragma_Argument_Associations
(N
));
17117 while Present
(Hint
) loop
17118 Check_Arg_Is_One_Of
(Hint
, Name_Ivdep
,
17126 Check_Loop_Pragma_Placement
;
17133 -- pragma Loop_Variant
17134 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
17136 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
17138 -- CHANGE_DIRECTION ::= Increases | Decreases
17140 when Pragma_Loop_Variant
=> Loop_Variant
: declare
17145 Check_At_Least_N_Arguments
(1);
17146 Check_Loop_Pragma_Placement
;
17148 -- Process all increasing / decreasing expressions
17150 Variant
:= First
(Pragma_Argument_Associations
(N
));
17151 while Present
(Variant
) loop
17152 if not Nam_In
(Chars
(Variant
), Name_Decreases
,
17155 Error_Pragma_Arg
("wrong change modifier", Variant
);
17158 Preanalyze_Assert_Expression
17159 (Expression
(Variant
), Any_Discrete
);
17165 -----------------------
17166 -- Machine_Attribute --
17167 -----------------------
17169 -- pragma Machine_Attribute (
17170 -- [Entity =>] LOCAL_NAME,
17171 -- [Attribute_Name =>] static_string_EXPRESSION
17172 -- [, [Info =>] static_EXPRESSION] );
17174 when Pragma_Machine_Attribute
=> Machine_Attribute
: declare
17175 Def_Id
: Entity_Id
;
17179 Check_Arg_Order
((Name_Entity
, Name_Attribute_Name
, Name_Info
));
17181 if Arg_Count
= 3 then
17182 Check_Optional_Identifier
(Arg3
, Name_Info
);
17183 Check_Arg_Is_OK_Static_Expression
(Arg3
);
17185 Check_Arg_Count
(2);
17188 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17189 Check_Optional_Identifier
(Arg2
, Name_Attribute_Name
);
17190 Check_Arg_Is_Local_Name
(Arg1
);
17191 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
17192 Def_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
17194 if Is_Access_Type
(Def_Id
) then
17195 Def_Id
:= Designated_Type
(Def_Id
);
17198 if Rep_Item_Too_Early
(Def_Id
, N
) then
17202 Def_Id
:= Underlying_Type
(Def_Id
);
17204 -- The only processing required is to link this item on to the
17205 -- list of rep items for the given entity. This is accomplished
17206 -- by the call to Rep_Item_Too_Late (when no error is detected
17207 -- and False is returned).
17209 if Rep_Item_Too_Late
(Def_Id
, N
) then
17212 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
17214 end Machine_Attribute
;
17221 -- (MAIN_OPTION [, MAIN_OPTION]);
17224 -- [STACK_SIZE =>] static_integer_EXPRESSION
17225 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
17226 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
17228 when Pragma_Main
=> Main
: declare
17229 Args
: Args_List
(1 .. 3);
17230 Names
: constant Name_List
(1 .. 3) := (
17232 Name_Task_Stack_Size_Default
,
17233 Name_Time_Slicing_Enabled
);
17239 Gather_Associations
(Names
, Args
);
17241 for J
in 1 .. 2 loop
17242 if Present
(Args
(J
)) then
17243 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
17247 if Present
(Args
(3)) then
17248 Check_Arg_Is_OK_Static_Expression
(Args
(3), Standard_Boolean
);
17252 while Present
(Nod
) loop
17253 if Nkind
(Nod
) = N_Pragma
17254 and then Pragma_Name
(Nod
) = Name_Main
17256 Error_Msg_Name_1
:= Pname
;
17257 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
17268 -- pragma Main_Storage
17269 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
17271 -- MAIN_STORAGE_OPTION ::=
17272 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
17273 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
17275 when Pragma_Main_Storage
=> Main_Storage
: declare
17276 Args
: Args_List
(1 .. 2);
17277 Names
: constant Name_List
(1 .. 2) := (
17278 Name_Working_Storage
,
17285 Gather_Associations
(Names
, Args
);
17287 for J
in 1 .. 2 loop
17288 if Present
(Args
(J
)) then
17289 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
17293 Check_In_Main_Program
;
17296 while Present
(Nod
) loop
17297 if Nkind
(Nod
) = N_Pragma
17298 and then Pragma_Name
(Nod
) = Name_Main_Storage
17300 Error_Msg_Name_1
:= Pname
;
17301 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
17312 -- pragma Memory_Size (NUMERIC_LITERAL)
17314 when Pragma_Memory_Size
=>
17317 -- Memory size is simply ignored
17319 Check_No_Identifiers
;
17320 Check_Arg_Count
(1);
17321 Check_Arg_Is_Integer_Literal
(Arg1
);
17329 -- The only correct use of this pragma is on its own in a file, in
17330 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
17331 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
17332 -- check for a file containing nothing but a No_Body pragma). If we
17333 -- attempt to process it during normal semantics processing, it means
17334 -- it was misplaced.
17336 when Pragma_No_Body
=>
17340 -----------------------------
17341 -- No_Elaboration_Code_All --
17342 -----------------------------
17344 -- pragma No_Elaboration_Code_All;
17346 when Pragma_No_Elaboration_Code_All
=>
17348 Check_Valid_Library_Unit_Pragma
;
17350 if Nkind
(N
) = N_Null_Statement
then
17354 -- Must appear for a spec or generic spec
17356 if not Nkind_In
(Unit
(Cunit
(Current_Sem_Unit
)),
17357 N_Generic_Package_Declaration
,
17358 N_Generic_Subprogram_Declaration
,
17359 N_Package_Declaration
,
17360 N_Subprogram_Declaration
)
17364 ("pragma% can only occur for package "
17365 & "or subprogram spec"));
17368 -- Set flag in unit table
17370 Set_No_Elab_Code_All
(Current_Sem_Unit
);
17372 -- Set restriction No_Elaboration_Code if this is the main unit
17374 if Current_Sem_Unit
= Main_Unit
then
17375 Set_Restriction
(No_Elaboration_Code
, N
);
17378 -- If we are in the main unit or in an extended main source unit,
17379 -- then we also add it to the configuration restrictions so that
17380 -- it will apply to all units in the extended main source.
17382 if Current_Sem_Unit
= Main_Unit
17383 or else In_Extended_Main_Source_Unit
(N
)
17385 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
17388 -- If in main extended unit, activate transitive with test
17390 if In_Extended_Main_Source_Unit
(N
) then
17391 Opt
.No_Elab_Code_All_Pragma
:= N
;
17398 -- pragma No_Inline ( NAME {, NAME} );
17400 when Pragma_No_Inline
=>
17402 Process_Inline
(Suppressed
);
17408 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
17410 when Pragma_No_Return
=> No_Return
: declare
17416 Ghost_Error_Posted
: Boolean := False;
17417 -- Flag set when an error concerning the illegal mix of Ghost and
17418 -- non-Ghost subprograms is emitted.
17420 Ghost_Id
: Entity_Id
:= Empty
;
17421 -- The entity of the first Ghost procedure encountered while
17422 -- processing the arguments of the pragma.
17426 Check_At_Least_N_Arguments
(1);
17428 -- Loop through arguments of pragma
17431 while Present
(Arg
) loop
17432 Check_Arg_Is_Local_Name
(Arg
);
17433 Id
:= Get_Pragma_Arg
(Arg
);
17436 if not Is_Entity_Name
(Id
) then
17437 Error_Pragma_Arg
("entity name required", Arg
);
17440 if Etype
(Id
) = Any_Type
then
17444 -- Loop to find matching procedures
17450 and then Scope
(E
) = Current_Scope
17452 if Ekind_In
(E
, E_Procedure
, E_Generic_Procedure
) then
17455 -- A pragma that applies to a Ghost entity becomes Ghost
17456 -- for the purposes of legality checks and removal of
17457 -- ignored Ghost code.
17459 Mark_Pragma_As_Ghost
(N
, E
);
17461 -- Capture the entity of the first Ghost procedure being
17462 -- processed for error detection purposes.
17464 if Is_Ghost_Entity
(E
) then
17465 if No
(Ghost_Id
) then
17469 -- Otherwise the subprogram is non-Ghost. It is illegal
17470 -- to mix references to Ghost and non-Ghost entities
17473 elsif Present
(Ghost_Id
)
17474 and then not Ghost_Error_Posted
17476 Ghost_Error_Posted
:= True;
17478 Error_Msg_Name_1
:= Pname
;
17480 ("pragma % cannot mention ghost and non-ghost "
17481 & "procedures", N
);
17483 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
17484 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
17486 Error_Msg_Sloc
:= Sloc
(E
);
17487 Error_Msg_NE
("\& # declared as non-ghost", N
, E
);
17490 -- Set flag on any alias as well
17492 if Is_Overloadable
(E
) and then Present
(Alias
(E
)) then
17493 Set_No_Return
(Alias
(E
));
17499 exit when From_Aspect_Specification
(N
);
17503 -- If entity in not in current scope it may be the enclosing
17504 -- suprogram body to which the aspect applies.
17507 if Entity
(Id
) = Current_Scope
17508 and then From_Aspect_Specification
(N
)
17510 Set_No_Return
(Entity
(Id
));
17512 Error_Pragma_Arg
("no procedure& found for pragma%", Arg
);
17524 -- pragma No_Run_Time;
17526 -- Note: this pragma is retained for backwards compatibility. See
17527 -- body of Rtsfind for full details on its handling.
17529 when Pragma_No_Run_Time
=>
17531 Check_Valid_Configuration_Pragma
;
17532 Check_Arg_Count
(0);
17534 No_Run_Time_Mode
:= True;
17535 Configurable_Run_Time_Mode
:= True;
17537 -- Set Duration to 32 bits if word size is 32
17539 if Ttypes
.System_Word_Size
= 32 then
17540 Duration_32_Bits_On_Target
:= True;
17543 -- Set appropriate restrictions
17545 Set_Restriction
(No_Finalization
, N
);
17546 Set_Restriction
(No_Exception_Handlers
, N
);
17547 Set_Restriction
(Max_Tasks
, N
, 0);
17548 Set_Restriction
(No_Tasking
, N
);
17550 -----------------------
17551 -- No_Tagged_Streams --
17552 -----------------------
17554 -- pragma No_Tagged_Streams;
17555 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
17557 when Pragma_No_Tagged_Streams
=> No_Tagged_Strms
: declare
17563 Check_At_Most_N_Arguments
(1);
17565 -- One argument case
17567 if Arg_Count
= 1 then
17568 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17569 Check_Arg_Is_Local_Name
(Arg1
);
17570 E_Id
:= Get_Pragma_Arg
(Arg1
);
17572 if Etype
(E_Id
) = Any_Type
then
17576 E
:= Entity
(E_Id
);
17578 Check_Duplicate_Pragma
(E
);
17580 if not Is_Tagged_Type
(E
) or else Is_Derived_Type
(E
) then
17582 ("argument for pragma% must be root tagged type", Arg1
);
17585 if Rep_Item_Too_Early
(E
, N
)
17587 Rep_Item_Too_Late
(E
, N
)
17591 Set_No_Tagged_Streams_Pragma
(E
, N
);
17594 -- Zero argument case
17597 Check_Is_In_Decl_Part_Or_Package_Spec
;
17598 No_Tagged_Streams
:= N
;
17600 end No_Tagged_Strms
;
17602 ------------------------
17603 -- No_Strict_Aliasing --
17604 ------------------------
17606 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
17608 when Pragma_No_Strict_Aliasing
=> No_Strict_Aliasing
: declare
17613 Check_At_Most_N_Arguments
(1);
17615 if Arg_Count
= 0 then
17616 Check_Valid_Configuration_Pragma
;
17617 Opt
.No_Strict_Aliasing
:= True;
17620 Check_Optional_Identifier
(Arg2
, Name_Entity
);
17621 Check_Arg_Is_Local_Name
(Arg1
);
17622 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
17624 if E_Id
= Any_Type
then
17626 elsif No
(E_Id
) or else not Is_Access_Type
(E_Id
) then
17627 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
17630 Set_No_Strict_Aliasing
(Implementation_Base_Type
(E_Id
));
17632 end No_Strict_Aliasing
;
17634 -----------------------
17635 -- Normalize_Scalars --
17636 -----------------------
17638 -- pragma Normalize_Scalars;
17640 when Pragma_Normalize_Scalars
=>
17641 Check_Ada_83_Warning
;
17642 Check_Arg_Count
(0);
17643 Check_Valid_Configuration_Pragma
;
17645 -- Normalize_Scalars creates false positives in CodePeer, and
17646 -- incorrect negative results in GNATprove mode, so ignore this
17647 -- pragma in these modes.
17649 if not (CodePeer_Mode
or GNATprove_Mode
) then
17650 Normalize_Scalars
:= True;
17651 Init_Or_Norm_Scalars
:= True;
17658 -- pragma Obsolescent;
17660 -- pragma Obsolescent (
17661 -- [Message =>] static_string_EXPRESSION
17662 -- [,[Version =>] Ada_05]]);
17664 -- pragma Obsolescent (
17665 -- [Entity =>] NAME
17666 -- [,[Message =>] static_string_EXPRESSION
17667 -- [,[Version =>] Ada_05]] );
17669 when Pragma_Obsolescent
=> Obsolescent
: declare
17673 procedure Set_Obsolescent
(E
: Entity_Id
);
17674 -- Given an entity Ent, mark it as obsolescent if appropriate
17676 ---------------------
17677 -- Set_Obsolescent --
17678 ---------------------
17680 procedure Set_Obsolescent
(E
: Entity_Id
) is
17689 -- A pragma that applies to a Ghost entity becomes Ghost for
17690 -- the purposes of legality checks and removal of ignored Ghost
17693 Mark_Pragma_As_Ghost
(N
, E
);
17695 -- Entity name was given
17697 if Present
(Ename
) then
17699 -- If entity name matches, we are fine. Save entity in
17700 -- pragma argument, for ASIS use.
17702 if Chars
(Ename
) = Chars
(Ent
) then
17703 Set_Entity
(Ename
, Ent
);
17704 Generate_Reference
(Ent
, Ename
);
17706 -- If entity name does not match, only possibility is an
17707 -- enumeration literal from an enumeration type declaration.
17709 elsif Ekind
(Ent
) /= E_Enumeration_Type
then
17711 ("pragma % entity name does not match declaration");
17714 Ent
:= First_Literal
(E
);
17718 ("pragma % entity name does not match any "
17719 & "enumeration literal");
17721 elsif Chars
(Ent
) = Chars
(Ename
) then
17722 Set_Entity
(Ename
, Ent
);
17723 Generate_Reference
(Ent
, Ename
);
17727 Ent
:= Next_Literal
(Ent
);
17733 -- Ent points to entity to be marked
17735 if Arg_Count
>= 1 then
17737 -- Deal with static string argument
17739 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
17740 S
:= Strval
(Get_Pragma_Arg
(Arg1
));
17742 for J
in 1 .. String_Length
(S
) loop
17743 if not In_Character_Range
(Get_String_Char
(S
, J
)) then
17745 ("pragma% argument does not allow wide characters",
17750 Obsolescent_Warnings
.Append
17751 ((Ent
=> Ent
, Msg
=> Strval
(Get_Pragma_Arg
(Arg1
))));
17753 -- Check for Ada_05 parameter
17755 if Arg_Count
/= 1 then
17756 Check_Arg_Count
(2);
17759 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
17762 Check_Arg_Is_Identifier
(Argx
);
17764 if Chars
(Argx
) /= Name_Ada_05
then
17765 Error_Msg_Name_2
:= Name_Ada_05
;
17767 ("only allowed argument for pragma% is %", Argx
);
17770 if Ada_Version_Explicit
< Ada_2005
17771 or else not Warn_On_Ada_2005_Compatibility
17779 -- Set flag if pragma active
17782 Set_Is_Obsolescent
(Ent
);
17786 end Set_Obsolescent
;
17788 -- Start of processing for pragma Obsolescent
17793 Check_At_Most_N_Arguments
(3);
17795 -- See if first argument specifies an entity name
17799 (Chars
(Arg1
) = Name_Entity
17801 Nkind_In
(Get_Pragma_Arg
(Arg1
), N_Character_Literal
,
17803 N_Operator_Symbol
))
17805 Ename
:= Get_Pragma_Arg
(Arg1
);
17807 -- Eliminate first argument, so we can share processing
17811 Arg_Count
:= Arg_Count
- 1;
17813 -- No Entity name argument given
17819 if Arg_Count
>= 1 then
17820 Check_Optional_Identifier
(Arg1
, Name_Message
);
17822 if Arg_Count
= 2 then
17823 Check_Optional_Identifier
(Arg2
, Name_Version
);
17827 -- Get immediately preceding declaration
17830 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
17834 -- Cases where we do not follow anything other than another pragma
17838 -- First case: library level compilation unit declaration with
17839 -- the pragma immediately following the declaration.
17841 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
17843 (Defining_Entity
(Unit
(Parent
(Parent
(N
)))));
17846 -- Case 2: library unit placement for package
17850 Ent
: constant Entity_Id
:= Find_Lib_Unit_Name
;
17852 if Is_Package_Or_Generic_Package
(Ent
) then
17853 Set_Obsolescent
(Ent
);
17859 -- Cases where we must follow a declaration, including an
17860 -- abstract subprogram declaration, which is not in the
17861 -- other node subtypes.
17864 if Nkind
(Decl
) not in N_Declaration
17865 and then Nkind
(Decl
) not in N_Later_Decl_Item
17866 and then Nkind
(Decl
) not in N_Generic_Declaration
17867 and then Nkind
(Decl
) not in N_Renaming_Declaration
17868 and then Nkind
(Decl
) /= N_Abstract_Subprogram_Declaration
17871 ("pragma% misplaced, "
17872 & "must immediately follow a declaration");
17875 Set_Obsolescent
(Defining_Entity
(Decl
));
17885 -- pragma Optimize (Time | Space | Off);
17887 -- The actual check for optimize is done in Gigi. Note that this
17888 -- pragma does not actually change the optimization setting, it
17889 -- simply checks that it is consistent with the pragma.
17891 when Pragma_Optimize
=>
17892 Check_No_Identifiers
;
17893 Check_Arg_Count
(1);
17894 Check_Arg_Is_One_Of
(Arg1
, Name_Time
, Name_Space
, Name_Off
);
17896 ------------------------
17897 -- Optimize_Alignment --
17898 ------------------------
17900 -- pragma Optimize_Alignment (Time | Space | Off);
17902 when Pragma_Optimize_Alignment
=> Optimize_Alignment
: begin
17904 Check_No_Identifiers
;
17905 Check_Arg_Count
(1);
17906 Check_Valid_Configuration_Pragma
;
17909 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
17913 Opt
.Optimize_Alignment
:= 'T';
17915 Opt
.Optimize_Alignment
:= 'S';
17917 Opt
.Optimize_Alignment
:= 'O';
17919 Error_Pragma_Arg
("invalid argument for pragma%", Arg1
);
17923 -- Set indication that mode is set locally. If we are in fact in a
17924 -- configuration pragma file, this setting is harmless since the
17925 -- switch will get reset anyway at the start of each unit.
17927 Optimize_Alignment_Local
:= True;
17928 end Optimize_Alignment
;
17934 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17936 when Pragma_Ordered
=> Ordered
: declare
17937 Assoc
: constant Node_Id
:= Arg1
;
17943 Check_No_Identifiers
;
17944 Check_Arg_Count
(1);
17945 Check_Arg_Is_Local_Name
(Arg1
);
17947 Type_Id
:= Get_Pragma_Arg
(Assoc
);
17948 Find_Type
(Type_Id
);
17949 Typ
:= Entity
(Type_Id
);
17951 if Typ
= Any_Type
then
17954 Typ
:= Underlying_Type
(Typ
);
17957 if not Is_Enumeration_Type
(Typ
) then
17958 Error_Pragma
("pragma% must specify enumeration type");
17961 Check_First_Subtype
(Arg1
);
17962 Set_Has_Pragma_Ordered
(Base_Type
(Typ
));
17965 -------------------
17966 -- Overflow_Mode --
17967 -------------------
17969 -- pragma Overflow_Mode
17970 -- ([General => ] MODE [, [Assertions => ] MODE]);
17972 -- MODE := STRICT | MINIMIZED | ELIMINATED
17974 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17975 -- since System.Bignums makes this assumption. This is true of nearly
17976 -- all (all?) targets.
17978 when Pragma_Overflow_Mode
=> Overflow_Mode
: declare
17979 function Get_Overflow_Mode
17981 Arg
: Node_Id
) return Overflow_Mode_Type
;
17982 -- Function to process one pragma argument, Arg. If an identifier
17983 -- is present, it must be Name. Mode type is returned if a valid
17984 -- argument exists, otherwise an error is signalled.
17986 -----------------------
17987 -- Get_Overflow_Mode --
17988 -----------------------
17990 function Get_Overflow_Mode
17992 Arg
: Node_Id
) return Overflow_Mode_Type
17994 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
17997 Check_Optional_Identifier
(Arg
, Name
);
17998 Check_Arg_Is_Identifier
(Argx
);
18000 if Chars
(Argx
) = Name_Strict
then
18003 elsif Chars
(Argx
) = Name_Minimized
then
18006 elsif Chars
(Argx
) = Name_Eliminated
then
18007 if Ttypes
.Standard_Long_Long_Integer_Size
/= 64 then
18009 ("Eliminated not implemented on this target", Argx
);
18015 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
18017 end Get_Overflow_Mode
;
18019 -- Start of processing for Overflow_Mode
18023 Check_At_Least_N_Arguments
(1);
18024 Check_At_Most_N_Arguments
(2);
18026 -- Process first argument
18028 Scope_Suppress
.Overflow_Mode_General
:=
18029 Get_Overflow_Mode
(Name_General
, Arg1
);
18031 -- Case of only one argument
18033 if Arg_Count
= 1 then
18034 Scope_Suppress
.Overflow_Mode_Assertions
:=
18035 Scope_Suppress
.Overflow_Mode_General
;
18037 -- Case of two arguments present
18040 Scope_Suppress
.Overflow_Mode_Assertions
:=
18041 Get_Overflow_Mode
(Name_Assertions
, Arg2
);
18045 --------------------------
18046 -- Overriding Renamings --
18047 --------------------------
18049 -- pragma Overriding_Renamings;
18051 when Pragma_Overriding_Renamings
=>
18053 Check_Arg_Count
(0);
18054 Check_Valid_Configuration_Pragma
;
18055 Overriding_Renamings
:= True;
18061 -- pragma Pack (first_subtype_LOCAL_NAME);
18063 when Pragma_Pack
=> Pack
: declare
18064 Assoc
: constant Node_Id
:= Arg1
;
18066 Ignore
: Boolean := False;
18071 Check_No_Identifiers
;
18072 Check_Arg_Count
(1);
18073 Check_Arg_Is_Local_Name
(Arg1
);
18074 Type_Id
:= Get_Pragma_Arg
(Assoc
);
18076 if not Is_Entity_Name
(Type_Id
)
18077 or else not Is_Type
(Entity
(Type_Id
))
18080 ("argument for pragma% must be type or subtype", Arg1
);
18083 Find_Type
(Type_Id
);
18084 Typ
:= Entity
(Type_Id
);
18087 or else Rep_Item_Too_Early
(Typ
, N
)
18091 Typ
:= Underlying_Type
(Typ
);
18094 -- A pragma that applies to a Ghost entity becomes Ghost for the
18095 -- purposes of legality checks and removal of ignored Ghost code.
18097 Mark_Pragma_As_Ghost
(N
, Typ
);
18099 if not Is_Array_Type
(Typ
) and then not Is_Record_Type
(Typ
) then
18100 Error_Pragma
("pragma% must specify array or record type");
18103 Check_First_Subtype
(Arg1
);
18104 Check_Duplicate_Pragma
(Typ
);
18108 if Is_Array_Type
(Typ
) then
18109 Ctyp
:= Component_Type
(Typ
);
18111 -- Ignore pack that does nothing
18113 if Known_Static_Esize
(Ctyp
)
18114 and then Known_Static_RM_Size
(Ctyp
)
18115 and then Esize
(Ctyp
) = RM_Size
(Ctyp
)
18116 and then Addressable
(Esize
(Ctyp
))
18121 -- Process OK pragma Pack. Note that if there is a separate
18122 -- component clause present, the Pack will be cancelled. This
18123 -- processing is in Freeze.
18125 if not Rep_Item_Too_Late
(Typ
, N
) then
18127 -- In CodePeer mode, we do not need complex front-end
18128 -- expansions related to pragma Pack, so disable handling
18131 if CodePeer_Mode
then
18134 -- Normal case where we do the pack action
18138 Set_Is_Packed
(Base_Type
(Typ
));
18139 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
18142 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
18146 -- For record types, the pack is always effective
18148 else pragma Assert
(Is_Record_Type
(Typ
));
18149 if not Rep_Item_Too_Late
(Typ
, N
) then
18150 Set_Is_Packed
(Base_Type
(Typ
));
18151 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
18152 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
18163 -- There is nothing to do here, since we did all the processing for
18164 -- this pragma in Par.Prag (so that it works properly even in syntax
18167 when Pragma_Page
=>
18174 -- pragma Part_Of (ABSTRACT_STATE);
18176 -- ABSTRACT_STATE ::= NAME
18178 when Pragma_Part_Of
=> Part_Of
: declare
18179 procedure Propagate_Part_Of
18180 (Pack_Id
: Entity_Id
;
18181 State_Id
: Entity_Id
;
18182 Instance
: Node_Id
);
18183 -- Propagate the Part_Of indicator to all abstract states and
18184 -- objects declared in the visible state space of a package
18185 -- denoted by Pack_Id. State_Id is the encapsulating state.
18186 -- Instance is the package instantiation node.
18188 -----------------------
18189 -- Propagate_Part_Of --
18190 -----------------------
18192 procedure Propagate_Part_Of
18193 (Pack_Id
: Entity_Id
;
18194 State_Id
: Entity_Id
;
18195 Instance
: Node_Id
)
18197 Has_Item
: Boolean := False;
18198 -- Flag set when the visible state space contains at least one
18199 -- abstract state or variable.
18201 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
);
18202 -- Propagate the Part_Of indicator to all abstract states and
18203 -- objects declared in the visible state space of a package
18204 -- denoted by Pack_Id.
18206 -----------------------
18207 -- Propagate_Part_Of --
18208 -----------------------
18210 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
) is
18211 Constits
: Elist_Id
;
18212 Item_Id
: Entity_Id
;
18215 -- Traverse the entity chain of the package and set relevant
18216 -- attributes of abstract states and objects declared in the
18217 -- visible state space of the package.
18219 Item_Id
:= First_Entity
(Pack_Id
);
18220 while Present
(Item_Id
)
18221 and then not In_Private_Part
(Item_Id
)
18223 -- Do not consider internally generated items
18225 if not Comes_From_Source
(Item_Id
) then
18228 -- The Part_Of indicator turns an abstract state or an
18229 -- object into a constituent of the encapsulating state.
18231 elsif Ekind_In
(Item_Id
, E_Abstract_State
,
18236 Constits
:= Part_Of_Constituents
(State_Id
);
18238 if No
(Constits
) then
18239 Constits
:= New_Elmt_List
;
18240 Set_Part_Of_Constituents
(State_Id
, Constits
);
18243 Append_Elmt
(Item_Id
, Constits
);
18244 Set_Encapsulating_State
(Item_Id
, State_Id
);
18246 -- Recursively handle nested packages and instantiations
18248 elsif Ekind
(Item_Id
) = E_Package
then
18249 Propagate_Part_Of
(Item_Id
);
18252 Next_Entity
(Item_Id
);
18254 end Propagate_Part_Of
;
18256 -- Start of processing for Propagate_Part_Of
18259 Propagate_Part_Of
(Pack_Id
);
18261 -- Detect a package instantiation that is subject to a Part_Of
18262 -- indicator, but has no visible state.
18264 if not Has_Item
then
18266 ("package instantiation & has Part_Of indicator but "
18267 & "lacks visible state", Instance
, Pack_Id
);
18269 end Propagate_Part_Of
;
18273 Constits
: Elist_Id
;
18275 Encap_Id
: Entity_Id
;
18276 Item_Id
: Entity_Id
;
18280 -- Start of processing for Part_Of
18284 Check_No_Identifiers
;
18285 Check_Arg_Count
(1);
18287 Stmt
:= Find_Related_Context
(N
, Do_Checks
=> True);
18289 -- Object declaration
18291 if Nkind
(Stmt
) = N_Object_Declaration
then
18294 -- Package instantiation
18296 elsif Nkind
(Stmt
) = N_Package_Instantiation
then
18299 -- Single concurrent type declaration
18301 elsif Is_Single_Concurrent_Type_Declaration
(Stmt
) then
18304 -- Otherwise the pragma is associated with an illegal construct
18311 -- Extract the entity of the related object declaration or package
18312 -- instantiation. In the case of the instantiation, use the entity
18313 -- of the instance spec.
18315 if Nkind
(Stmt
) = N_Package_Instantiation
then
18316 Stmt
:= Instance_Spec
(Stmt
);
18319 Item_Id
:= Defining_Entity
(Stmt
);
18320 Encap
:= Get_Pragma_Arg
(Arg1
);
18322 -- A pragma that applies to a Ghost entity becomes Ghost for the
18323 -- purposes of legality checks and removal of ignored Ghost code.
18325 Mark_Pragma_As_Ghost
(N
, Item_Id
);
18327 -- Chain the pragma on the contract for further processing by
18328 -- Analyze_Part_Of_In_Decl_Part or for completeness.
18330 Add_Contract_Item
(N
, Item_Id
);
18332 -- A variable may act as consituent of a single concurrent type
18333 -- which in turn could be declared after the variable. Due to this
18334 -- discrepancy, the full analysis of indicator Part_Of is delayed
18335 -- until the end of the enclosing declarative region (see routine
18336 -- Analyze_Part_Of_In_Decl_Part).
18338 if Ekind
(Item_Id
) = E_Variable
then
18341 -- Otherwise indicator Part_Of applies to a constant or a package
18345 -- Detect any discrepancies between the placement of the
18346 -- constant or package instantiation with respect to state
18347 -- space and the encapsulating state.
18351 Item_Id
=> Item_Id
,
18353 Encap_Id
=> Encap_Id
,
18357 pragma Assert
(Present
(Encap_Id
));
18359 if Ekind
(Item_Id
) = E_Constant
then
18360 Constits
:= Part_Of_Constituents
(Encap_Id
);
18362 if No
(Constits
) then
18363 Constits
:= New_Elmt_List
;
18364 Set_Part_Of_Constituents
(Encap_Id
, Constits
);
18367 Append_Elmt
(Item_Id
, Constits
);
18368 Set_Encapsulating_State
(Item_Id
, Encap_Id
);
18370 -- Propagate the Part_Of indicator to the visible state
18371 -- space of the package instantiation.
18375 (Pack_Id
=> Item_Id
,
18376 State_Id
=> Encap_Id
,
18383 ----------------------------------
18384 -- Partition_Elaboration_Policy --
18385 ----------------------------------
18387 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
18389 when Pragma_Partition_Elaboration_Policy
=> declare
18390 subtype PEP_Range
is Name_Id
18391 range First_Partition_Elaboration_Policy_Name
18392 .. Last_Partition_Elaboration_Policy_Name
;
18393 PEP_Val
: PEP_Range
;
18398 Check_Arg_Count
(1);
18399 Check_No_Identifiers
;
18400 Check_Arg_Is_Partition_Elaboration_Policy
(Arg1
);
18401 Check_Valid_Configuration_Pragma
;
18402 PEP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
18405 when Name_Concurrent
=>
18407 when Name_Sequential
=>
18411 if Partition_Elaboration_Policy
/= ' '
18412 and then Partition_Elaboration_Policy
/= PEP
18414 Error_Msg_Sloc
:= Partition_Elaboration_Policy_Sloc
;
18416 ("partition elaboration policy incompatible with policy#");
18418 -- Set new policy, but always preserve System_Location since we
18419 -- like the error message with the run time name.
18422 Partition_Elaboration_Policy
:= PEP
;
18424 if Partition_Elaboration_Policy_Sloc
/= System_Location
then
18425 Partition_Elaboration_Policy_Sloc
:= Loc
;
18434 -- pragma Passive [(PASSIVE_FORM)];
18436 -- PASSIVE_FORM ::= Semaphore | No
18438 when Pragma_Passive
=>
18441 if Nkind
(Parent
(N
)) /= N_Task_Definition
then
18442 Error_Pragma
("pragma% must be within task definition");
18445 if Arg_Count
/= 0 then
18446 Check_Arg_Count
(1);
18447 Check_Arg_Is_One_Of
(Arg1
, Name_Semaphore
, Name_No
);
18450 ----------------------------------
18451 -- Preelaborable_Initialization --
18452 ----------------------------------
18454 -- pragma Preelaborable_Initialization (DIRECT_NAME);
18456 when Pragma_Preelaborable_Initialization
=> Preelab_Init
: declare
18461 Check_Arg_Count
(1);
18462 Check_No_Identifiers
;
18463 Check_Arg_Is_Identifier
(Arg1
);
18464 Check_Arg_Is_Local_Name
(Arg1
);
18465 Check_First_Subtype
(Arg1
);
18466 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
18468 -- A pragma that applies to a Ghost entity becomes Ghost for the
18469 -- purposes of legality checks and removal of ignored Ghost code.
18471 Mark_Pragma_As_Ghost
(N
, Ent
);
18473 -- The pragma may come from an aspect on a private declaration,
18474 -- even if the freeze point at which this is analyzed in the
18475 -- private part after the full view.
18477 if Has_Private_Declaration
(Ent
)
18478 and then From_Aspect_Specification
(N
)
18482 -- Check appropriate type argument
18484 elsif Is_Private_Type
(Ent
)
18485 or else Is_Protected_Type
(Ent
)
18486 or else (Is_Generic_Type
(Ent
) and then Is_Derived_Type
(Ent
))
18488 -- AI05-0028: The pragma applies to all composite types. Note
18489 -- that we apply this binding interpretation to earlier versions
18490 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
18491 -- choice since there are other compilers that do the same.
18493 or else Is_Composite_Type
(Ent
)
18499 ("pragma % can only be applied to private, formal derived, "
18500 & "protected, or composite type", Arg1
);
18503 -- Give an error if the pragma is applied to a protected type that
18504 -- does not qualify (due to having entries, or due to components
18505 -- that do not qualify).
18507 if Is_Protected_Type
(Ent
)
18508 and then not Has_Preelaborable_Initialization
(Ent
)
18511 ("protected type & does not have preelaborable "
18512 & "initialization", Ent
);
18514 -- Otherwise mark the type as definitely having preelaborable
18518 Set_Known_To_Have_Preelab_Init
(Ent
);
18521 if Has_Pragma_Preelab_Init
(Ent
)
18522 and then Warn_On_Redundant_Constructs
18524 Error_Pragma
("?r?duplicate pragma%!");
18526 Set_Has_Pragma_Preelab_Init
(Ent
);
18530 --------------------
18531 -- Persistent_BSS --
18532 --------------------
18534 -- pragma Persistent_BSS [(object_NAME)];
18536 when Pragma_Persistent_BSS
=> Persistent_BSS
: declare
18543 Check_At_Most_N_Arguments
(1);
18545 -- Case of application to specific object (one argument)
18547 if Arg_Count
= 1 then
18548 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
18550 if not Is_Entity_Name
(Get_Pragma_Arg
(Arg1
))
18552 Ekind_In
(Entity
(Get_Pragma_Arg
(Arg1
)), E_Variable
,
18555 Error_Pragma_Arg
("pragma% only applies to objects", Arg1
);
18558 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
18559 Decl
:= Parent
(Ent
);
18561 -- A pragma that applies to a Ghost entity becomes Ghost for
18562 -- the purposes of legality checks and removal of ignored Ghost
18565 Mark_Pragma_As_Ghost
(N
, Ent
);
18567 -- Check for duplication before inserting in list of
18568 -- representation items.
18570 Check_Duplicate_Pragma
(Ent
);
18572 if Rep_Item_Too_Late
(Ent
, N
) then
18576 if Present
(Expression
(Decl
)) then
18578 ("object for pragma% cannot have initialization", Arg1
);
18581 if not Is_Potentially_Persistent_Type
(Etype
(Ent
)) then
18583 ("object type for pragma% is not potentially persistent",
18588 Make_Linker_Section_Pragma
18589 (Ent
, Sloc
(N
), ".persistent.bss");
18590 Insert_After
(N
, Prag
);
18593 -- Case of use as configuration pragma with no arguments
18596 Check_Valid_Configuration_Pragma
;
18597 Persistent_BSS_Mode
:= True;
18599 end Persistent_BSS
;
18605 -- pragma Polling (ON | OFF);
18607 when Pragma_Polling
=>
18609 Check_Arg_Count
(1);
18610 Check_No_Identifiers
;
18611 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
18612 Polling_Required
:= (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
);
18614 -----------------------------------
18615 -- Post/Post_Class/Postcondition --
18616 -----------------------------------
18618 -- pragma Post (Boolean_EXPRESSION);
18619 -- pragma Post_Class (Boolean_EXPRESSION);
18620 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18621 -- [,[Message =>] String_EXPRESSION]);
18623 -- Characteristics:
18625 -- * Analysis - The annotation undergoes initial checks to verify
18626 -- the legal placement and context. Secondary checks preanalyze the
18629 -- Analyze_Pre_Post_Condition_In_Decl_Part
18631 -- * Expansion - The annotation is expanded during the expansion of
18632 -- the related subprogram [body] contract as performed in:
18634 -- Expand_Subprogram_Contract
18636 -- * Template - The annotation utilizes the generic template of the
18637 -- related subprogram [body] when it is:
18639 -- aspect on subprogram declaration
18640 -- aspect on stand alone subprogram body
18641 -- pragma on stand alone subprogram body
18643 -- The annotation must prepare its own template when it is:
18645 -- pragma on subprogram declaration
18647 -- * Globals - Capture of global references must occur after full
18650 -- * Instance - The annotation is instantiated automatically when
18651 -- the related generic subprogram [body] is instantiated except for
18652 -- the "pragma on subprogram declaration" case. In that scenario
18653 -- the annotation must instantiate itself.
18656 Pragma_Post_Class |
18657 Pragma_Postcondition
=>
18658 Analyze_Pre_Post_Condition
;
18660 --------------------------------
18661 -- Pre/Pre_Class/Precondition --
18662 --------------------------------
18664 -- pragma Pre (Boolean_EXPRESSION);
18665 -- pragma Pre_Class (Boolean_EXPRESSION);
18666 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18667 -- [,[Message =>] String_EXPRESSION]);
18669 -- Characteristics:
18671 -- * Analysis - The annotation undergoes initial checks to verify
18672 -- the legal placement and context. Secondary checks preanalyze the
18675 -- Analyze_Pre_Post_Condition_In_Decl_Part
18677 -- * Expansion - The annotation is expanded during the expansion of
18678 -- the related subprogram [body] contract as performed in:
18680 -- Expand_Subprogram_Contract
18682 -- * Template - The annotation utilizes the generic template of the
18683 -- related subprogram [body] when it is:
18685 -- aspect on subprogram declaration
18686 -- aspect on stand alone subprogram body
18687 -- pragma on stand alone subprogram body
18689 -- The annotation must prepare its own template when it is:
18691 -- pragma on subprogram declaration
18693 -- * Globals - Capture of global references must occur after full
18696 -- * Instance - The annotation is instantiated automatically when
18697 -- the related generic subprogram [body] is instantiated except for
18698 -- the "pragma on subprogram declaration" case. In that scenario
18699 -- the annotation must instantiate itself.
18703 Pragma_Precondition
=>
18704 Analyze_Pre_Post_Condition
;
18710 -- pragma Predicate
18711 -- ([Entity =>] type_LOCAL_NAME,
18712 -- [Check =>] boolean_EXPRESSION);
18714 when Pragma_Predicate
=> Predicate
: declare
18721 Check_Arg_Count
(2);
18722 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18723 Check_Optional_Identifier
(Arg2
, Name_Check
);
18725 Check_Arg_Is_Local_Name
(Arg1
);
18727 Type_Id
:= Get_Pragma_Arg
(Arg1
);
18728 Find_Type
(Type_Id
);
18729 Typ
:= Entity
(Type_Id
);
18731 if Typ
= Any_Type
then
18735 -- A pragma that applies to a Ghost entity becomes Ghost for the
18736 -- purposes of legality checks and removal of ignored Ghost code.
18738 Mark_Pragma_As_Ghost
(N
, Typ
);
18740 -- The remaining processing is simply to link the pragma on to
18741 -- the rep item chain, for processing when the type is frozen.
18742 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18743 -- mark the type as having predicates.
18745 Set_Has_Predicates
(Typ
);
18746 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
18749 -----------------------
18750 -- Predicate_Failure --
18751 -----------------------
18753 -- pragma Predicate_Failure
18754 -- ([Entity =>] type_LOCAL_NAME,
18755 -- [Message =>] string_EXPRESSION);
18757 when Pragma_Predicate_Failure
=> Predicate_Failure
: declare
18764 Check_Arg_Count
(2);
18765 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18766 Check_Optional_Identifier
(Arg2
, Name_Message
);
18768 Check_Arg_Is_Local_Name
(Arg1
);
18770 Type_Id
:= Get_Pragma_Arg
(Arg1
);
18771 Find_Type
(Type_Id
);
18772 Typ
:= Entity
(Type_Id
);
18774 if Typ
= Any_Type
then
18778 -- A pragma that applies to a Ghost entity becomes Ghost for the
18779 -- purposes of legality checks and removal of ignored Ghost code.
18781 Mark_Pragma_As_Ghost
(N
, Typ
);
18783 -- The remaining processing is simply to link the pragma on to
18784 -- the rep item chain, for processing when the type is frozen.
18785 -- This is accomplished by a call to Rep_Item_Too_Late.
18787 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
18788 end Predicate_Failure
;
18794 -- pragma Preelaborate [(library_unit_NAME)];
18796 -- Set the flag Is_Preelaborated of program unit name entity
18798 when Pragma_Preelaborate
=> Preelaborate
: declare
18799 Pa
: constant Node_Id
:= Parent
(N
);
18800 Pk
: constant Node_Kind
:= Nkind
(Pa
);
18804 Check_Ada_83_Warning
;
18805 Check_Valid_Library_Unit_Pragma
;
18807 if Nkind
(N
) = N_Null_Statement
then
18811 Ent
:= Find_Lib_Unit_Name
;
18813 -- A pragma that applies to a Ghost entity becomes Ghost for the
18814 -- purposes of legality checks and removal of ignored Ghost code.
18816 Mark_Pragma_As_Ghost
(N
, Ent
);
18817 Check_Duplicate_Pragma
(Ent
);
18819 -- This filters out pragmas inside generic parents that show up
18820 -- inside instantiations. Pragmas that come from aspects in the
18821 -- unit are not ignored.
18823 if Present
(Ent
) then
18824 if Pk
= N_Package_Specification
18825 and then Present
(Generic_Parent
(Pa
))
18826 and then not From_Aspect_Specification
(N
)
18831 if not Debug_Flag_U
then
18832 Set_Is_Preelaborated
(Ent
);
18833 Set_Suppress_Elaboration_Warnings
(Ent
);
18839 -------------------------------
18840 -- Prefix_Exception_Messages --
18841 -------------------------------
18843 -- pragma Prefix_Exception_Messages;
18845 when Pragma_Prefix_Exception_Messages
=>
18847 Check_Valid_Configuration_Pragma
;
18848 Check_Arg_Count
(0);
18849 Prefix_Exception_Messages
:= True;
18855 -- pragma Priority (EXPRESSION);
18857 when Pragma_Priority
=> Priority
: declare
18858 P
: constant Node_Id
:= Parent
(N
);
18863 Check_No_Identifiers
;
18864 Check_Arg_Count
(1);
18868 if Nkind
(P
) = N_Subprogram_Body
then
18869 Check_In_Main_Program
;
18871 Ent
:= Defining_Unit_Name
(Specification
(P
));
18873 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
18874 Ent
:= Defining_Identifier
(Ent
);
18877 Arg
:= Get_Pragma_Arg
(Arg1
);
18878 Analyze_And_Resolve
(Arg
, Standard_Integer
);
18882 if not Is_OK_Static_Expression
(Arg
) then
18883 Flag_Non_Static_Expr
18884 ("main subprogram priority is not static!", Arg
);
18887 -- If constraint error, then we already signalled an error
18889 elsif Raises_Constraint_Error
(Arg
) then
18892 -- Otherwise check in range except if Relaxed_RM_Semantics
18893 -- where we ignore the value if out of range.
18897 Val
: constant Uint
:= Expr_Value
(Arg
);
18899 if not Relaxed_RM_Semantics
18902 or else Val
> Expr_Value
(Expression
18903 (Parent
(RTE
(RE_Max_Priority
)))))
18906 ("main subprogram priority is out of range", Arg1
);
18909 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
18914 -- Load an arbitrary entity from System.Tasking.Stages or
18915 -- System.Tasking.Restricted.Stages (depending on the
18916 -- supported profile) to make sure that one of these packages
18917 -- is implicitly with'ed, since we need to have the tasking
18918 -- run time active for the pragma Priority to have any effect.
18919 -- Previously we with'ed the package System.Tasking, but this
18920 -- package does not trigger the required initialization of the
18921 -- run-time library.
18924 Discard
: Entity_Id
;
18925 pragma Warnings
(Off
, Discard
);
18927 if Restricted_Profile
then
18928 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
18930 Discard
:= RTE
(RE_Activate_Tasks
);
18934 -- Task or Protected, must be of type Integer
18936 elsif Nkind_In
(P
, N_Protected_Definition
, N_Task_Definition
) then
18937 Arg
:= Get_Pragma_Arg
(Arg1
);
18938 Ent
:= Defining_Identifier
(Parent
(P
));
18940 -- The expression must be analyzed in the special manner
18941 -- described in "Handling of Default and Per-Object
18942 -- Expressions" in sem.ads.
18944 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Any_Priority
));
18946 if not Is_OK_Static_Expression
(Arg
) then
18947 Check_Restriction
(Static_Priorities
, Arg
);
18950 -- Anything else is incorrect
18956 -- Check duplicate pragma before we chain the pragma in the Rep
18957 -- Item chain of Ent.
18959 Check_Duplicate_Pragma
(Ent
);
18960 Record_Rep_Item
(Ent
, N
);
18963 -----------------------------------
18964 -- Priority_Specific_Dispatching --
18965 -----------------------------------
18967 -- pragma Priority_Specific_Dispatching (
18968 -- policy_IDENTIFIER,
18969 -- first_priority_EXPRESSION,
18970 -- last_priority_EXPRESSION);
18972 when Pragma_Priority_Specific_Dispatching
=>
18973 Priority_Specific_Dispatching
: declare
18974 Prio_Id
: constant Entity_Id
:= RTE
(RE_Any_Priority
);
18975 -- This is the entity System.Any_Priority;
18978 Lower_Bound
: Node_Id
;
18979 Upper_Bound
: Node_Id
;
18985 Check_Arg_Count
(3);
18986 Check_No_Identifiers
;
18987 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
18988 Check_Valid_Configuration_Pragma
;
18989 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
18990 DP
:= Fold_Upper
(Name_Buffer
(1));
18992 Lower_Bound
:= Get_Pragma_Arg
(Arg2
);
18993 Check_Arg_Is_OK_Static_Expression
(Lower_Bound
, Standard_Integer
);
18994 Lower_Val
:= Expr_Value
(Lower_Bound
);
18996 Upper_Bound
:= Get_Pragma_Arg
(Arg3
);
18997 Check_Arg_Is_OK_Static_Expression
(Upper_Bound
, Standard_Integer
);
18998 Upper_Val
:= Expr_Value
(Upper_Bound
);
19000 -- It is not allowed to use Task_Dispatching_Policy and
19001 -- Priority_Specific_Dispatching in the same partition.
19003 if Task_Dispatching_Policy
/= ' ' then
19004 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
19006 ("pragma% incompatible with Task_Dispatching_Policy#");
19008 -- Check lower bound in range
19010 elsif Lower_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
19012 Lower_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
19015 ("first_priority is out of range", Arg2
);
19017 -- Check upper bound in range
19019 elsif Upper_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
19021 Upper_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
19024 ("last_priority is out of range", Arg3
);
19026 -- Check that the priority range is valid
19028 elsif Lower_Val
> Upper_Val
then
19030 ("last_priority_expression must be greater than or equal to "
19031 & "first_priority_expression");
19033 -- Store the new policy, but always preserve System_Location since
19034 -- we like the error message with the run-time name.
19037 -- Check overlapping in the priority ranges specified in other
19038 -- Priority_Specific_Dispatching pragmas within the same
19039 -- partition. We can only check those we know about.
19042 Specific_Dispatching
.First
.. Specific_Dispatching
.Last
19044 if Specific_Dispatching
.Table
(J
).First_Priority
in
19045 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
19046 or else Specific_Dispatching
.Table
(J
).Last_Priority
in
19047 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
19050 Specific_Dispatching
.Table
(J
).Pragma_Loc
;
19052 ("priority range overlaps with "
19053 & "Priority_Specific_Dispatching#");
19057 -- The use of Priority_Specific_Dispatching is incompatible
19058 -- with Task_Dispatching_Policy.
19060 if Task_Dispatching_Policy
/= ' ' then
19061 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
19063 ("Priority_Specific_Dispatching incompatible "
19064 & "with Task_Dispatching_Policy#");
19067 -- The use of Priority_Specific_Dispatching forces ceiling
19070 if Locking_Policy
/= ' ' and then Locking_Policy
/= 'C' then
19071 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
19073 ("Priority_Specific_Dispatching incompatible "
19074 & "with Locking_Policy#");
19076 -- Set the Ceiling_Locking policy, but preserve System_Location
19077 -- since we like the error message with the run time name.
19080 Locking_Policy
:= 'C';
19082 if Locking_Policy_Sloc
/= System_Location
then
19083 Locking_Policy_Sloc
:= Loc
;
19087 -- Add entry in the table
19089 Specific_Dispatching
.Append
19090 ((Dispatching_Policy
=> DP
,
19091 First_Priority
=> UI_To_Int
(Lower_Val
),
19092 Last_Priority
=> UI_To_Int
(Upper_Val
),
19093 Pragma_Loc
=> Loc
));
19095 end Priority_Specific_Dispatching
;
19101 -- pragma Profile (profile_IDENTIFIER);
19103 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
19105 when Pragma_Profile
=>
19107 Check_Arg_Count
(1);
19108 Check_Valid_Configuration_Pragma
;
19109 Check_No_Identifiers
;
19112 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
19115 if Chars
(Argx
) = Name_Ravenscar
then
19116 Set_Ravenscar_Profile
(Ravenscar
, N
);
19118 elsif Chars
(Argx
) = Name_Gnat_Extended_Ravenscar
then
19119 Set_Ravenscar_Profile
(GNAT_Extended_Ravenscar
, N
);
19121 elsif Chars
(Argx
) = Name_Restricted
then
19122 Set_Profile_Restrictions
19124 N
, Warn
=> Treat_Restrictions_As_Warnings
);
19126 elsif Chars
(Argx
) = Name_Rational
then
19127 Set_Rational_Profile
;
19129 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
19130 Set_Profile_Restrictions
19131 (No_Implementation_Extensions
,
19132 N
, Warn
=> Treat_Restrictions_As_Warnings
);
19135 Error_Pragma_Arg
("& is not a valid profile", Argx
);
19139 ----------------------
19140 -- Profile_Warnings --
19141 ----------------------
19143 -- pragma Profile_Warnings (profile_IDENTIFIER);
19145 -- profile_IDENTIFIER => Restricted | Ravenscar
19147 when Pragma_Profile_Warnings
=>
19149 Check_Arg_Count
(1);
19150 Check_Valid_Configuration_Pragma
;
19151 Check_No_Identifiers
;
19154 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
19157 if Chars
(Argx
) = Name_Ravenscar
then
19158 Set_Profile_Restrictions
(Ravenscar
, N
, Warn
=> True);
19160 elsif Chars
(Argx
) = Name_Restricted
then
19161 Set_Profile_Restrictions
(Restricted
, N
, Warn
=> True);
19163 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
19164 Set_Profile_Restrictions
19165 (No_Implementation_Extensions
, N
, Warn
=> True);
19168 Error_Pragma_Arg
("& is not a valid profile", Argx
);
19172 --------------------------
19173 -- Propagate_Exceptions --
19174 --------------------------
19176 -- pragma Propagate_Exceptions;
19178 -- Note: this pragma is obsolete and has no effect
19180 when Pragma_Propagate_Exceptions
=>
19182 Check_Arg_Count
(0);
19184 if Warn_On_Obsolescent_Feature
then
19186 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
19187 "and has no effect?j?", N
);
19190 -----------------------------
19191 -- Provide_Shift_Operators --
19192 -----------------------------
19194 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
19196 when Pragma_Provide_Shift_Operators
=>
19197 Provide_Shift_Operators
: declare
19200 procedure Declare_Shift_Operator
(Nam
: Name_Id
);
19201 -- Insert declaration and pragma Instrinsic for named shift op
19203 ----------------------------
19204 -- Declare_Shift_Operator --
19205 ----------------------------
19207 procedure Declare_Shift_Operator
(Nam
: Name_Id
) is
19213 Make_Subprogram_Declaration
(Loc
,
19214 Make_Function_Specification
(Loc
,
19215 Defining_Unit_Name
=>
19216 Make_Defining_Identifier
(Loc
, Chars
=> Nam
),
19218 Result_Definition
=>
19219 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
)),
19221 Parameter_Specifications
=> New_List
(
19222 Make_Parameter_Specification
(Loc
,
19223 Defining_Identifier
=>
19224 Make_Defining_Identifier
(Loc
, Name_Value
),
19226 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
))),
19228 Make_Parameter_Specification
(Loc
,
19229 Defining_Identifier
=>
19230 Make_Defining_Identifier
(Loc
, Name_Amount
),
19232 New_Occurrence_Of
(Standard_Natural
, Loc
)))));
19236 Pragma_Identifier
=> Make_Identifier
(Loc
, Name_Import
),
19237 Pragma_Argument_Associations
=> New_List
(
19238 Make_Pragma_Argument_Association
(Loc
,
19239 Expression
=> Make_Identifier
(Loc
, Name_Intrinsic
)),
19240 Make_Pragma_Argument_Association
(Loc
,
19241 Expression
=> Make_Identifier
(Loc
, Nam
))));
19243 Insert_After
(N
, Import
);
19244 Insert_After
(N
, Func
);
19245 end Declare_Shift_Operator
;
19247 -- Start of processing for Provide_Shift_Operators
19251 Check_Arg_Count
(1);
19252 Check_Arg_Is_Local_Name
(Arg1
);
19254 Arg1
:= Get_Pragma_Arg
(Arg1
);
19256 -- We must have an entity name
19258 if not Is_Entity_Name
(Arg1
) then
19260 ("pragma % must apply to integer first subtype", Arg1
);
19263 -- If no Entity, means there was a prior error so ignore
19265 if Present
(Entity
(Arg1
)) then
19266 Ent
:= Entity
(Arg1
);
19268 -- Apply error checks
19270 if not Is_First_Subtype
(Ent
) then
19272 ("cannot apply pragma %",
19273 "\& is not a first subtype",
19276 elsif not Is_Integer_Type
(Ent
) then
19278 ("cannot apply pragma %",
19279 "\& is not an integer type",
19282 elsif Has_Shift_Operator
(Ent
) then
19284 ("cannot apply pragma %",
19285 "\& already has declared shift operators",
19288 elsif Is_Frozen
(Ent
) then
19290 ("pragma % appears too late",
19291 "\& is already frozen",
19295 -- Now declare the operators. We do this during analysis rather
19296 -- than expansion, since we want the operators available if we
19297 -- are operating in -gnatc or ASIS mode.
19299 Declare_Shift_Operator
(Name_Rotate_Left
);
19300 Declare_Shift_Operator
(Name_Rotate_Right
);
19301 Declare_Shift_Operator
(Name_Shift_Left
);
19302 Declare_Shift_Operator
(Name_Shift_Right
);
19303 Declare_Shift_Operator
(Name_Shift_Right_Arithmetic
);
19305 end Provide_Shift_Operators
;
19311 -- pragma Psect_Object (
19312 -- [Internal =>] LOCAL_NAME,
19313 -- [, [External =>] EXTERNAL_SYMBOL]
19314 -- [, [Size =>] EXTERNAL_SYMBOL]);
19316 when Pragma_Psect_Object | Pragma_Common_Object
=>
19317 Psect_Object
: declare
19318 Args
: Args_List
(1 .. 3);
19319 Names
: constant Name_List
(1 .. 3) := (
19324 Internal
: Node_Id
renames Args
(1);
19325 External
: Node_Id
renames Args
(2);
19326 Size
: Node_Id
renames Args
(3);
19328 Def_Id
: Entity_Id
;
19330 procedure Check_Arg
(Arg
: Node_Id
);
19331 -- Checks that argument is either a string literal or an
19332 -- identifier, and posts error message if not.
19338 procedure Check_Arg
(Arg
: Node_Id
) is
19340 if not Nkind_In
(Original_Node
(Arg
),
19345 ("inappropriate argument for pragma %", Arg
);
19349 -- Start of processing for Common_Object/Psect_Object
19353 Gather_Associations
(Names
, Args
);
19354 Process_Extended_Import_Export_Internal_Arg
(Internal
);
19356 Def_Id
:= Entity
(Internal
);
19358 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
19360 ("pragma% must designate an object", Internal
);
19363 Check_Arg
(Internal
);
19365 if Is_Imported
(Def_Id
) or else Is_Exported
(Def_Id
) then
19367 ("cannot use pragma% for imported/exported object",
19371 if Is_Concurrent_Type
(Etype
(Internal
)) then
19373 ("cannot specify pragma % for task/protected object",
19377 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
19379 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
19381 Error_Msg_N
("??duplicate Common/Psect_Object pragma", N
);
19384 if Ekind
(Def_Id
) = E_Constant
then
19386 ("cannot specify pragma % for a constant", Internal
);
19389 if Is_Record_Type
(Etype
(Internal
)) then
19395 Ent
:= First_Entity
(Etype
(Internal
));
19396 while Present
(Ent
) loop
19397 Decl
:= Declaration_Node
(Ent
);
19399 if Ekind
(Ent
) = E_Component
19400 and then Nkind
(Decl
) = N_Component_Declaration
19401 and then Present
(Expression
(Decl
))
19402 and then Warn_On_Export_Import
19405 ("?x?object for pragma % has defaults", Internal
);
19415 if Present
(Size
) then
19419 if Present
(External
) then
19420 Check_Arg_Is_External_Name
(External
);
19423 -- If all error tests pass, link pragma on to the rep item chain
19425 Record_Rep_Item
(Def_Id
, N
);
19432 -- pragma Pure [(library_unit_NAME)];
19434 when Pragma_Pure
=> Pure
: declare
19438 Check_Ada_83_Warning
;
19440 -- If the pragma comes from a subprogram instantiation, nothing to
19441 -- check, this can happen at any level of nesting.
19443 if Is_Wrapper_Package
(Current_Scope
) then
19446 Check_Valid_Library_Unit_Pragma
;
19449 if Nkind
(N
) = N_Null_Statement
then
19453 Ent
:= Find_Lib_Unit_Name
;
19455 -- A pragma that applies to a Ghost entity becomes Ghost for the
19456 -- purposes of legality checks and removal of ignored Ghost code.
19458 Mark_Pragma_As_Ghost
(N
, Ent
);
19460 if not Debug_Flag_U
then
19462 Set_Has_Pragma_Pure
(Ent
);
19463 Set_Suppress_Elaboration_Warnings
(Ent
);
19467 -------------------
19468 -- Pure_Function --
19469 -------------------
19471 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
19473 when Pragma_Pure_Function
=> Pure_Function
: declare
19474 Def_Id
: Entity_Id
;
19477 Effective
: Boolean := False;
19481 Check_Arg_Count
(1);
19482 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19483 Check_Arg_Is_Local_Name
(Arg1
);
19484 E_Id
:= Get_Pragma_Arg
(Arg1
);
19486 if Error_Posted
(E_Id
) then
19490 -- Loop through homonyms (overloadings) of referenced entity
19492 E
:= Entity
(E_Id
);
19494 -- A pragma that applies to a Ghost entity becomes Ghost for the
19495 -- purposes of legality checks and removal of ignored Ghost code.
19497 Mark_Pragma_As_Ghost
(N
, E
);
19499 if Present
(E
) then
19501 Def_Id
:= Get_Base_Subprogram
(E
);
19503 if not Ekind_In
(Def_Id
, E_Function
,
19504 E_Generic_Function
,
19508 ("pragma% requires a function name", Arg1
);
19511 Set_Is_Pure
(Def_Id
);
19513 if not Has_Pragma_Pure_Function
(Def_Id
) then
19514 Set_Has_Pragma_Pure_Function
(Def_Id
);
19518 exit when From_Aspect_Specification
(N
);
19520 exit when No
(E
) or else Scope
(E
) /= Current_Scope
;
19524 and then Warn_On_Redundant_Constructs
19527 ("pragma Pure_Function on& is redundant?r?",
19533 --------------------
19534 -- Queuing_Policy --
19535 --------------------
19537 -- pragma Queuing_Policy (policy_IDENTIFIER);
19539 when Pragma_Queuing_Policy
=> declare
19543 Check_Ada_83_Warning
;
19544 Check_Arg_Count
(1);
19545 Check_No_Identifiers
;
19546 Check_Arg_Is_Queuing_Policy
(Arg1
);
19547 Check_Valid_Configuration_Pragma
;
19548 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
19549 QP
:= Fold_Upper
(Name_Buffer
(1));
19551 if Queuing_Policy
/= ' '
19552 and then Queuing_Policy
/= QP
19554 Error_Msg_Sloc
:= Queuing_Policy_Sloc
;
19555 Error_Pragma
("queuing policy incompatible with policy#");
19557 -- Set new policy, but always preserve System_Location since we
19558 -- like the error message with the run time name.
19561 Queuing_Policy
:= QP
;
19563 if Queuing_Policy_Sloc
/= System_Location
then
19564 Queuing_Policy_Sloc
:= Loc
;
19573 -- pragma Rational, for compatibility with foreign compiler
19575 when Pragma_Rational
=>
19576 Set_Rational_Profile
;
19578 ---------------------
19579 -- Refined_Depends --
19580 ---------------------
19582 -- pragma Refined_Depends (DEPENDENCY_RELATION);
19584 -- DEPENDENCY_RELATION ::=
19586 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
19588 -- DEPENDENCY_CLAUSE ::=
19589 -- OUTPUT_LIST =>[+] INPUT_LIST
19590 -- | NULL_DEPENDENCY_CLAUSE
19592 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
19594 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
19596 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
19598 -- OUTPUT ::= NAME | FUNCTION_RESULT
19601 -- where FUNCTION_RESULT is a function Result attribute_reference
19603 -- Characteristics:
19605 -- * Analysis - The annotation undergoes initial checks to verify
19606 -- the legal placement and context. Secondary checks fully analyze
19607 -- the dependency clauses/global list in:
19609 -- Analyze_Refined_Depends_In_Decl_Part
19611 -- * Expansion - None.
19613 -- * Template - The annotation utilizes the generic template of the
19614 -- related subprogram body.
19616 -- * Globals - Capture of global references must occur after full
19619 -- * Instance - The annotation is instantiated automatically when
19620 -- the related generic subprogram body is instantiated.
19622 when Pragma_Refined_Depends
=> Refined_Depends
: declare
19623 Body_Id
: Entity_Id
;
19625 Spec_Id
: Entity_Id
;
19628 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19632 -- Chain the pragma on the contract for further processing by
19633 -- Analyze_Refined_Depends_In_Decl_Part.
19635 Add_Contract_Item
(N
, Body_Id
);
19637 -- The legality checks of pragmas Refined_Depends and
19638 -- Refined_Global are affected by the SPARK mode in effect and
19639 -- the volatility of the context. In addition these two pragmas
19640 -- are subject to an inherent order:
19642 -- 1) Refined_Global
19643 -- 2) Refined_Depends
19645 -- Analyze all these pragmas in the order outlined above
19647 Analyze_If_Present
(Pragma_SPARK_Mode
);
19648 Analyze_If_Present
(Pragma_Volatile_Function
);
19649 Analyze_If_Present
(Pragma_Refined_Global
);
19650 Analyze_Refined_Depends_In_Decl_Part
(N
);
19652 end Refined_Depends
;
19654 --------------------
19655 -- Refined_Global --
19656 --------------------
19658 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
19660 -- GLOBAL_SPECIFICATION ::=
19663 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
19665 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
19667 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
19668 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
19669 -- GLOBAL_ITEM ::= NAME
19671 -- Characteristics:
19673 -- * Analysis - The annotation undergoes initial checks to verify
19674 -- the legal placement and context. Secondary checks fully analyze
19675 -- the dependency clauses/global list in:
19677 -- Analyze_Refined_Global_In_Decl_Part
19679 -- * Expansion - None.
19681 -- * Template - The annotation utilizes the generic template of the
19682 -- related subprogram body.
19684 -- * Globals - Capture of global references must occur after full
19687 -- * Instance - The annotation is instantiated automatically when
19688 -- the related generic subprogram body is instantiated.
19690 when Pragma_Refined_Global
=> Refined_Global
: declare
19691 Body_Id
: Entity_Id
;
19693 Spec_Id
: Entity_Id
;
19696 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19700 -- Chain the pragma on the contract for further processing by
19701 -- Analyze_Refined_Global_In_Decl_Part.
19703 Add_Contract_Item
(N
, Body_Id
);
19705 -- The legality checks of pragmas Refined_Depends and
19706 -- Refined_Global are affected by the SPARK mode in effect and
19707 -- the volatility of the context. In addition these two pragmas
19708 -- are subject to an inherent order:
19710 -- 1) Refined_Global
19711 -- 2) Refined_Depends
19713 -- Analyze all these pragmas in the order outlined above
19715 Analyze_If_Present
(Pragma_SPARK_Mode
);
19716 Analyze_If_Present
(Pragma_Volatile_Function
);
19717 Analyze_Refined_Global_In_Decl_Part
(N
);
19718 Analyze_If_Present
(Pragma_Refined_Depends
);
19720 end Refined_Global
;
19726 -- pragma Refined_Post (boolean_EXPRESSION);
19728 -- Characteristics:
19730 -- * Analysis - The annotation is fully analyzed immediately upon
19731 -- elaboration as it cannot forward reference entities.
19733 -- * Expansion - The annotation is expanded during the expansion of
19734 -- the related subprogram body contract as performed in:
19736 -- Expand_Subprogram_Contract
19738 -- * Template - The annotation utilizes the generic template of the
19739 -- related subprogram body.
19741 -- * Globals - Capture of global references must occur after full
19744 -- * Instance - The annotation is instantiated automatically when
19745 -- the related generic subprogram body is instantiated.
19747 when Pragma_Refined_Post
=> Refined_Post
: declare
19748 Body_Id
: Entity_Id
;
19750 Spec_Id
: Entity_Id
;
19753 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19755 -- Fully analyze the pragma when it appears inside a subprogram
19756 -- body because it cannot benefit from forward references.
19760 -- Chain the pragma on the contract for completeness
19762 Add_Contract_Item
(N
, Body_Id
);
19764 -- The legality checks of pragma Refined_Post are affected by
19765 -- the SPARK mode in effect and the volatility of the context.
19766 -- Analyze all pragmas in a specific order.
19768 Analyze_If_Present
(Pragma_SPARK_Mode
);
19769 Analyze_If_Present
(Pragma_Volatile_Function
);
19770 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
19772 -- Currently it is not possible to inline pre/postconditions on
19773 -- a subprogram subject to pragma Inline_Always.
19775 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
19779 -------------------
19780 -- Refined_State --
19781 -------------------
19783 -- pragma Refined_State (REFINEMENT_LIST);
19785 -- REFINEMENT_LIST ::=
19786 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19788 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19790 -- CONSTITUENT_LIST ::=
19793 -- | (CONSTITUENT {, CONSTITUENT})
19795 -- CONSTITUENT ::= object_NAME | state_NAME
19797 -- Characteristics:
19799 -- * Analysis - The annotation undergoes initial checks to verify
19800 -- the legal placement and context. Secondary checks preanalyze the
19801 -- refinement clauses in:
19803 -- Analyze_Refined_State_In_Decl_Part
19805 -- * Expansion - None.
19807 -- * Template - The annotation utilizes the template of the related
19810 -- * Globals - Capture of global references must occur after full
19813 -- * Instance - The annotation is instantiated automatically when
19814 -- the related generic package body is instantiated.
19816 when Pragma_Refined_State
=> Refined_State
: declare
19817 Pack_Decl
: Node_Id
;
19818 Spec_Id
: Entity_Id
;
19822 Check_No_Identifiers
;
19823 Check_Arg_Count
(1);
19825 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
19827 -- Ensure the proper placement of the pragma. Refined states must
19828 -- be associated with a package body.
19830 if Nkind
(Pack_Decl
) = N_Package_Body
then
19833 -- Otherwise the pragma is associated with an illegal construct
19840 Spec_Id
:= Corresponding_Spec
(Pack_Decl
);
19842 -- Chain the pragma on the contract for further processing by
19843 -- Analyze_Refined_State_In_Decl_Part.
19845 Add_Contract_Item
(N
, Defining_Entity
(Pack_Decl
));
19847 -- The legality checks of pragma Refined_State are affected by the
19848 -- SPARK mode in effect. Analyze all pragmas in a specific order.
19850 Analyze_If_Present
(Pragma_SPARK_Mode
);
19852 -- A pragma that applies to a Ghost entity becomes Ghost for the
19853 -- purposes of legality checks and removal of ignored Ghost code.
19855 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
19857 -- State refinement is allowed only when the corresponding package
19858 -- declaration has non-null pragma Abstract_State. Refinement not
19859 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19861 if SPARK_Mode
/= Off
19863 (No
(Abstract_States
(Spec_Id
))
19864 or else Has_Null_Abstract_State
(Spec_Id
))
19867 ("useless refinement, package & does not define abstract "
19868 & "states", N
, Spec_Id
);
19873 -----------------------
19874 -- Relative_Deadline --
19875 -----------------------
19877 -- pragma Relative_Deadline (time_span_EXPRESSION);
19879 when Pragma_Relative_Deadline
=> Relative_Deadline
: declare
19880 P
: constant Node_Id
:= Parent
(N
);
19885 Check_No_Identifiers
;
19886 Check_Arg_Count
(1);
19888 Arg
:= Get_Pragma_Arg
(Arg1
);
19890 -- The expression must be analyzed in the special manner described
19891 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19893 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
19897 if Nkind
(P
) = N_Subprogram_Body
then
19898 Check_In_Main_Program
;
19900 -- Only Task and subprogram cases allowed
19902 elsif Nkind
(P
) /= N_Task_Definition
then
19906 -- Check duplicate pragma before we set the corresponding flag
19908 if Has_Relative_Deadline_Pragma
(P
) then
19909 Error_Pragma
("duplicate pragma% not allowed");
19912 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19913 -- Relative_Deadline pragma node cannot be inserted in the Rep
19914 -- Item chain of Ent since it is rewritten by the expander as a
19915 -- procedure call statement that will break the chain.
19917 Set_Has_Relative_Deadline_Pragma
(P
);
19918 end Relative_Deadline
;
19920 ------------------------
19921 -- Remote_Access_Type --
19922 ------------------------
19924 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19926 when Pragma_Remote_Access_Type
=> Remote_Access_Type
: declare
19931 Check_Arg_Count
(1);
19932 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19933 Check_Arg_Is_Local_Name
(Arg1
);
19935 E
:= Entity
(Get_Pragma_Arg
(Arg1
));
19937 -- A pragma that applies to a Ghost entity becomes Ghost for the
19938 -- purposes of legality checks and removal of ignored Ghost code.
19940 Mark_Pragma_As_Ghost
(N
, E
);
19942 if Nkind
(Parent
(E
)) = N_Formal_Type_Declaration
19943 and then Ekind
(E
) = E_General_Access_Type
19944 and then Is_Class_Wide_Type
(Directly_Designated_Type
(E
))
19945 and then Scope
(Root_Type
(Directly_Designated_Type
(E
)))
19947 and then Is_Valid_Remote_Object_Type
19948 (Root_Type
(Directly_Designated_Type
(E
)))
19950 Set_Is_Remote_Types
(E
);
19954 ("pragma% applies only to formal access to classwide types",
19957 end Remote_Access_Type
;
19959 ---------------------------
19960 -- Remote_Call_Interface --
19961 ---------------------------
19963 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19965 when Pragma_Remote_Call_Interface
=> Remote_Call_Interface
: declare
19966 Cunit_Node
: Node_Id
;
19967 Cunit_Ent
: Entity_Id
;
19971 Check_Ada_83_Warning
;
19972 Check_Valid_Library_Unit_Pragma
;
19974 if Nkind
(N
) = N_Null_Statement
then
19978 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
19979 K
:= Nkind
(Unit
(Cunit_Node
));
19980 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
19982 -- A pragma that applies to a Ghost entity becomes Ghost for the
19983 -- purposes of legality checks and removal of ignored Ghost code.
19985 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
19987 if K
= N_Package_Declaration
19988 or else K
= N_Generic_Package_Declaration
19989 or else K
= N_Subprogram_Declaration
19990 or else K
= N_Generic_Subprogram_Declaration
19991 or else (K
= N_Subprogram_Body
19992 and then Acts_As_Spec
(Unit
(Cunit_Node
)))
19997 "pragma% must apply to package or subprogram declaration");
20000 Set_Is_Remote_Call_Interface
(Cunit_Ent
);
20001 end Remote_Call_Interface
;
20007 -- pragma Remote_Types [(library_unit_NAME)];
20009 when Pragma_Remote_Types
=> Remote_Types
: declare
20010 Cunit_Node
: Node_Id
;
20011 Cunit_Ent
: Entity_Id
;
20014 Check_Ada_83_Warning
;
20015 Check_Valid_Library_Unit_Pragma
;
20017 if Nkind
(N
) = N_Null_Statement
then
20021 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
20022 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
20024 -- A pragma that applies to a Ghost entity becomes Ghost for the
20025 -- purposes of legality checks and removal of ignored Ghost code.
20027 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
20029 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
20030 N_Generic_Package_Declaration
)
20033 ("pragma% can only apply to a package declaration");
20036 Set_Is_Remote_Types
(Cunit_Ent
);
20043 -- pragma Ravenscar;
20045 when Pragma_Ravenscar
=>
20047 Check_Arg_Count
(0);
20048 Check_Valid_Configuration_Pragma
;
20049 Set_Ravenscar_Profile
(Ravenscar
, N
);
20051 if Warn_On_Obsolescent_Feature
then
20053 ("pragma Ravenscar is an obsolescent feature?j?", N
);
20055 ("|use pragma Profile (Ravenscar) instead?j?", N
);
20058 -------------------------
20059 -- Restricted_Run_Time --
20060 -------------------------
20062 -- pragma Restricted_Run_Time;
20064 when Pragma_Restricted_Run_Time
=>
20066 Check_Arg_Count
(0);
20067 Check_Valid_Configuration_Pragma
;
20068 Set_Profile_Restrictions
20069 (Restricted
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
20071 if Warn_On_Obsolescent_Feature
then
20073 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
20076 ("|use pragma Profile (Restricted) instead?j?", N
);
20083 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
20086 -- restriction_IDENTIFIER
20087 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20089 when Pragma_Restrictions
=>
20090 Process_Restrictions_Or_Restriction_Warnings
20091 (Warn
=> Treat_Restrictions_As_Warnings
);
20093 --------------------------
20094 -- Restriction_Warnings --
20095 --------------------------
20097 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
20100 -- restriction_IDENTIFIER
20101 -- | restriction_parameter_IDENTIFIER => EXPRESSION
20103 when Pragma_Restriction_Warnings
=>
20105 Process_Restrictions_Or_Restriction_Warnings
(Warn
=> True);
20111 -- pragma Reviewable;
20113 when Pragma_Reviewable
=>
20114 Check_Ada_83_Warning
;
20115 Check_Arg_Count
(0);
20117 -- Call dummy debugging function rv. This is done to assist front
20118 -- end debugging. By placing a Reviewable pragma in the source
20119 -- program, a breakpoint on rv catches this place in the source,
20120 -- allowing convenient stepping to the point of interest.
20124 --------------------------
20125 -- Short_Circuit_And_Or --
20126 --------------------------
20128 -- pragma Short_Circuit_And_Or;
20130 when Pragma_Short_Circuit_And_Or
=>
20132 Check_Arg_Count
(0);
20133 Check_Valid_Configuration_Pragma
;
20134 Short_Circuit_And_Or
:= True;
20136 -------------------
20137 -- Share_Generic --
20138 -------------------
20140 -- pragma Share_Generic (GNAME {, GNAME});
20142 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
20144 when Pragma_Share_Generic
=>
20146 Process_Generic_List
;
20152 -- pragma Shared (LOCAL_NAME);
20154 when Pragma_Shared
=>
20156 Process_Atomic_Independent_Shared_Volatile
;
20158 --------------------
20159 -- Shared_Passive --
20160 --------------------
20162 -- pragma Shared_Passive [(library_unit_NAME)];
20164 -- Set the flag Is_Shared_Passive of program unit name entity
20166 when Pragma_Shared_Passive
=> Shared_Passive
: declare
20167 Cunit_Node
: Node_Id
;
20168 Cunit_Ent
: Entity_Id
;
20171 Check_Ada_83_Warning
;
20172 Check_Valid_Library_Unit_Pragma
;
20174 if Nkind
(N
) = N_Null_Statement
then
20178 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
20179 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
20181 -- A pragma that applies to a Ghost entity becomes Ghost for the
20182 -- purposes of legality checks and removal of ignored Ghost code.
20184 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
20186 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
20187 N_Generic_Package_Declaration
)
20190 ("pragma% can only apply to a package declaration");
20193 Set_Is_Shared_Passive
(Cunit_Ent
);
20194 end Shared_Passive
;
20196 -----------------------
20197 -- Short_Descriptors --
20198 -----------------------
20200 -- pragma Short_Descriptors;
20202 -- Recognize and validate, but otherwise ignore
20204 when Pragma_Short_Descriptors
=>
20206 Check_Arg_Count
(0);
20207 Check_Valid_Configuration_Pragma
;
20209 ------------------------------
20210 -- Simple_Storage_Pool_Type --
20211 ------------------------------
20213 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
20215 when Pragma_Simple_Storage_Pool_Type
=>
20216 Simple_Storage_Pool_Type
: declare
20222 Check_Arg_Count
(1);
20223 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
20225 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20226 Find_Type
(Type_Id
);
20227 Typ
:= Entity
(Type_Id
);
20229 if Typ
= Any_Type
then
20233 -- A pragma that applies to a Ghost entity becomes Ghost for the
20234 -- purposes of legality checks and removal of ignored Ghost code.
20236 Mark_Pragma_As_Ghost
(N
, Typ
);
20238 -- We require the pragma to apply to a type declared in a package
20239 -- declaration, but not (immediately) within a package body.
20241 if Ekind
(Current_Scope
) /= E_Package
20242 or else In_Package_Body
(Current_Scope
)
20245 ("pragma% can only apply to type declared immediately "
20246 & "within a package declaration");
20249 -- A simple storage pool type must be an immutably limited record
20250 -- or private type. If the pragma is given for a private type,
20251 -- the full type is similarly restricted (which is checked later
20252 -- in Freeze_Entity).
20254 if Is_Record_Type
(Typ
)
20255 and then not Is_Limited_View
(Typ
)
20258 ("pragma% can only apply to explicitly limited record type");
20260 elsif Is_Private_Type
(Typ
) and then not Is_Limited_Type
(Typ
) then
20262 ("pragma% can only apply to a private type that is limited");
20264 elsif not Is_Record_Type
(Typ
)
20265 and then not Is_Private_Type
(Typ
)
20268 ("pragma% can only apply to limited record or private type");
20271 Record_Rep_Item
(Typ
, N
);
20272 end Simple_Storage_Pool_Type
;
20274 ----------------------
20275 -- Source_File_Name --
20276 ----------------------
20278 -- There are five forms for this pragma:
20280 -- pragma Source_File_Name (
20281 -- [UNIT_NAME =>] unit_NAME,
20282 -- BODY_FILE_NAME => STRING_LITERAL
20283 -- [, [INDEX =>] INTEGER_LITERAL]);
20285 -- pragma Source_File_Name (
20286 -- [UNIT_NAME =>] unit_NAME,
20287 -- SPEC_FILE_NAME => STRING_LITERAL
20288 -- [, [INDEX =>] INTEGER_LITERAL]);
20290 -- pragma Source_File_Name (
20291 -- BODY_FILE_NAME => STRING_LITERAL
20292 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20293 -- [, CASING => CASING_SPEC]);
20295 -- pragma Source_File_Name (
20296 -- SPEC_FILE_NAME => STRING_LITERAL
20297 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20298 -- [, CASING => CASING_SPEC]);
20300 -- pragma Source_File_Name (
20301 -- SUBUNIT_FILE_NAME => STRING_LITERAL
20302 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20303 -- [, CASING => CASING_SPEC]);
20305 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
20307 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
20308 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
20309 -- only be used when no project file is used, while SFNP can only be
20310 -- used when a project file is used.
20312 -- No processing here. Processing was completed during parsing, since
20313 -- we need to have file names set as early as possible. Units are
20314 -- loaded well before semantic processing starts.
20316 -- The only processing we defer to this point is the check for
20317 -- correct placement.
20319 when Pragma_Source_File_Name
=>
20321 Check_Valid_Configuration_Pragma
;
20323 ------------------------------
20324 -- Source_File_Name_Project --
20325 ------------------------------
20327 -- See Source_File_Name for syntax
20329 -- No processing here. Processing was completed during parsing, since
20330 -- we need to have file names set as early as possible. Units are
20331 -- loaded well before semantic processing starts.
20333 -- The only processing we defer to this point is the check for
20334 -- correct placement.
20336 when Pragma_Source_File_Name_Project
=>
20338 Check_Valid_Configuration_Pragma
;
20340 -- Check that a pragma Source_File_Name_Project is used only in a
20341 -- configuration pragmas file.
20343 -- Pragmas Source_File_Name_Project should only be generated by
20344 -- the Project Manager in configuration pragmas files.
20346 -- This is really an ugly test. It seems to depend on some
20347 -- accidental and undocumented property. At the very least it
20348 -- needs to be documented, but it would be better to have a
20349 -- clean way of testing if we are in a configuration file???
20351 if Present
(Parent
(N
)) then
20353 ("pragma% can only appear in a configuration pragmas file");
20356 ----------------------
20357 -- Source_Reference --
20358 ----------------------
20360 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
20362 -- Nothing to do, all processing completed in Par.Prag, since we need
20363 -- the information for possible parser messages that are output.
20365 when Pragma_Source_Reference
=>
20372 -- pragma SPARK_Mode [(On | Off)];
20374 when Pragma_SPARK_Mode
=> Do_SPARK_Mode
: declare
20375 Mode_Id
: SPARK_Mode_Type
;
20377 procedure Check_Pragma_Conformance
20378 (Context_Pragma
: Node_Id
;
20379 Entity
: Entity_Id
;
20380 Entity_Pragma
: Node_Id
);
20381 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
20382 -- conformance of pragma N depending the following scenarios:
20384 -- If pragma Context_Pragma is not Empty, verify that pragma N is
20385 -- compatible with the pragma Context_Pragma that was inherited
20386 -- from the context:
20387 -- * If the mode of Context_Pragma is ON, then the new mode can
20389 -- * If the mode of Context_Pragma is OFF, then the only allowed
20390 -- new mode is also OFF. Emit error if this is not the case.
20392 -- If Entity is not Empty, verify that pragma N is compatible with
20393 -- pragma Entity_Pragma that belongs to Entity.
20394 -- * If Entity_Pragma is Empty, always issue an error as this
20395 -- corresponds to the case where a previous section of Entity
20396 -- has no SPARK_Mode set.
20397 -- * If the mode of Entity_Pragma is ON, then the new mode can
20399 -- * If the mode of Entity_Pragma is OFF, then the only allowed
20400 -- new mode is also OFF. Emit error if this is not the case.
20402 procedure Check_Library_Level_Entity
(E
: Entity_Id
);
20403 -- Subsidiary to routines Process_xxx. Verify that the related
20404 -- entity E subject to pragma SPARK_Mode is library-level.
20406 procedure Process_Body
(Decl
: Node_Id
);
20407 -- Verify the legality of pragma SPARK_Mode when it appears as the
20408 -- top of the body declarations of entry, package, protected unit,
20409 -- subprogram or task unit body denoted by Decl.
20411 procedure Process_Overloadable
(Decl
: Node_Id
);
20412 -- Verify the legality of pragma SPARK_Mode when it applies to an
20413 -- entry or [generic] subprogram declaration denoted by Decl.
20415 procedure Process_Private_Part
(Decl
: Node_Id
);
20416 -- Verify the legality of pragma SPARK_Mode when it appears at the
20417 -- top of the private declarations of a package spec, protected or
20418 -- task unit declaration denoted by Decl.
20420 procedure Process_Statement_Part
(Decl
: Node_Id
);
20421 -- Verify the legality of pragma SPARK_Mode when it appears at the
20422 -- top of the statement sequence of a package body denoted by node
20425 procedure Process_Visible_Part
(Decl
: Node_Id
);
20426 -- Verify the legality of pragma SPARK_Mode when it appears at the
20427 -- top of the visible declarations of a package spec, protected or
20428 -- task unit declaration denoted by Decl. The routine is also used
20429 -- on protected or task units declared without a definition.
20431 procedure Set_SPARK_Context
;
20432 -- Subsidiary to routines Process_xxx. Set the global variables
20433 -- which represent the mode of the context from pragma N. Ensure
20434 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
20436 ------------------------------
20437 -- Check_Pragma_Conformance --
20438 ------------------------------
20440 procedure Check_Pragma_Conformance
20441 (Context_Pragma
: Node_Id
;
20442 Entity
: Entity_Id
;
20443 Entity_Pragma
: Node_Id
)
20445 Err_Id
: Entity_Id
;
20449 -- The current pragma may appear without an argument. If this
20450 -- is the case, associate all error messages with the pragma
20453 if Present
(Arg1
) then
20459 -- The mode of the current pragma is compared against that of
20460 -- an enclosing context.
20462 if Present
(Context_Pragma
) then
20463 pragma Assert
(Nkind
(Context_Pragma
) = N_Pragma
);
20465 -- Issue an error if the new mode is less restrictive than
20466 -- that of the context.
20468 if Get_SPARK_Mode_From_Annotation
(Context_Pragma
) = Off
20469 and then Get_SPARK_Mode_From_Annotation
(N
) = On
20472 ("cannot change SPARK_Mode from Off to On", Err_N
);
20473 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
20474 Error_Msg_N
("\SPARK_Mode was set to Off#", Err_N
);
20479 -- The mode of the current pragma is compared against that of
20480 -- an initial package, protected type, subprogram or task type
20483 if Present
(Entity
) then
20485 -- A simple protected or task type is transformed into an
20486 -- anonymous type whose name cannot be used to issue error
20487 -- messages. Recover the original entity of the type.
20489 if Ekind_In
(Entity
, E_Protected_Type
, E_Task_Type
) then
20492 (Original_Node
(Unit_Declaration_Node
(Entity
)));
20497 -- Both the initial declaration and the completion carry
20498 -- SPARK_Mode pragmas.
20500 if Present
(Entity_Pragma
) then
20501 pragma Assert
(Nkind
(Entity_Pragma
) = N_Pragma
);
20503 -- Issue an error if the new mode is less restrictive
20504 -- than that of the initial declaration.
20506 if Get_SPARK_Mode_From_Annotation
(Entity_Pragma
) = Off
20507 and then Get_SPARK_Mode_From_Annotation
(N
) = On
20509 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
20510 Error_Msg_Sloc
:= Sloc
(Entity_Pragma
);
20512 ("\value Off was set for SPARK_Mode on&#",
20517 -- Otherwise the initial declaration lacks a SPARK_Mode
20518 -- pragma in which case the current pragma is illegal as
20519 -- it cannot "complete".
20522 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
20523 Error_Msg_Sloc
:= Sloc
(Err_Id
);
20525 ("\no value was set for SPARK_Mode on&#",
20530 end Check_Pragma_Conformance
;
20532 --------------------------------
20533 -- Check_Library_Level_Entity --
20534 --------------------------------
20536 procedure Check_Library_Level_Entity
(E
: Entity_Id
) is
20537 procedure Add_Entity_To_Name_Buffer
;
20538 -- Add the E_Kind of entity E to the name buffer
20540 -------------------------------
20541 -- Add_Entity_To_Name_Buffer --
20542 -------------------------------
20544 procedure Add_Entity_To_Name_Buffer
is
20546 if Ekind_In
(E
, E_Entry
, E_Entry_Family
) then
20547 Add_Str_To_Name_Buffer
("entry");
20549 elsif Ekind_In
(E
, E_Generic_Package
,
20553 Add_Str_To_Name_Buffer
("package");
20555 elsif Ekind_In
(E
, E_Protected_Body
, E_Protected_Type
) then
20556 Add_Str_To_Name_Buffer
("protected type");
20558 elsif Ekind_In
(E
, E_Function
,
20559 E_Generic_Function
,
20560 E_Generic_Procedure
,
20564 Add_Str_To_Name_Buffer
("subprogram");
20567 pragma Assert
(Ekind_In
(E
, E_Task_Body
, E_Task_Type
));
20568 Add_Str_To_Name_Buffer
("task type");
20570 end Add_Entity_To_Name_Buffer
;
20574 Msg_1
: constant String := "incorrect placement of pragma%";
20577 -- Start of processing for Check_Library_Level_Entity
20580 if not Is_Library_Level_Entity
(E
) then
20581 Error_Msg_Name_1
:= Pname
;
20582 Error_Msg_N
(Fix_Error
(Msg_1
), N
);
20585 Add_Str_To_Name_Buffer
("\& is not a library-level ");
20586 Add_Entity_To_Name_Buffer
;
20588 Msg_2
:= Name_Find
;
20589 Error_Msg_NE
(Get_Name_String
(Msg_2
), N
, E
);
20593 end Check_Library_Level_Entity
;
20599 procedure Process_Body
(Decl
: Node_Id
) is
20600 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20601 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
20604 -- Ignore pragma when applied to the special body created for
20605 -- inlining, recognized by its internal name _Parent.
20607 if Chars
(Body_Id
) = Name_uParent
then
20611 Check_Library_Level_Entity
(Body_Id
);
20613 -- For entry bodies, verify the legality against:
20614 -- * The mode of the context
20615 -- * The mode of the spec (if any)
20617 if Nkind_In
(Decl
, N_Entry_Body
, N_Subprogram_Body
) then
20619 -- A stand alone subprogram body
20621 if Body_Id
= Spec_Id
then
20622 Check_Pragma_Conformance
20623 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20625 Entity_Pragma
=> Empty
);
20627 -- An entry or subprogram body that completes a previous
20631 Check_Pragma_Conformance
20632 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20634 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
20638 Set_SPARK_Pragma
(Body_Id
, N
);
20639 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20641 -- For package bodies, verify the legality against:
20642 -- * The mode of the context
20643 -- * The mode of the private part
20645 -- This case is separated from protected and task bodies
20646 -- because the statement part of the package body inherits
20647 -- the mode of the body declarations.
20649 elsif Nkind
(Decl
) = N_Package_Body
then
20650 Check_Pragma_Conformance
20651 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20653 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
20656 Set_SPARK_Pragma
(Body_Id
, N
);
20657 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20658 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
20659 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
20661 -- For protected and task bodies, verify the legality against:
20662 -- * The mode of the context
20663 -- * The mode of the private part
20667 (Nkind_In
(Decl
, N_Protected_Body
, N_Task_Body
));
20669 Check_Pragma_Conformance
20670 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20672 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
20675 Set_SPARK_Pragma
(Body_Id
, N
);
20676 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20680 --------------------------
20681 -- Process_Overloadable --
20682 --------------------------
20684 procedure Process_Overloadable
(Decl
: Node_Id
) is
20685 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20686 Spec_Typ
: constant Entity_Id
:= Etype
(Spec_Id
);
20689 Check_Library_Level_Entity
(Spec_Id
);
20691 -- Verify the legality against:
20692 -- * The mode of the context
20694 Check_Pragma_Conformance
20695 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
20697 Entity_Pragma
=> Empty
);
20699 Set_SPARK_Pragma
(Spec_Id
, N
);
20700 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
20702 -- When the pragma applies to the anonymous object created for
20703 -- a single task type, decorate the type as well. This scenario
20704 -- arises when the single task type lacks a task definition,
20705 -- therefore there is no issue with respect to a potential
20706 -- pragma SPARK_Mode in the private part.
20708 -- task type Anon_Task_Typ;
20709 -- Obj : Anon_Task_Typ;
20710 -- pragma SPARK_Mode ...;
20712 if Is_Single_Task_Object
(Spec_Id
) then
20713 Set_SPARK_Pragma
(Spec_Typ
, N
);
20714 Set_SPARK_Pragma_Inherited
(Spec_Typ
, False);
20715 Set_SPARK_Aux_Pragma
(Spec_Typ
, N
);
20716 Set_SPARK_Aux_Pragma_Inherited
(Spec_Typ
, True);
20718 end Process_Overloadable
;
20720 --------------------------
20721 -- Process_Private_Part --
20722 --------------------------
20724 procedure Process_Private_Part
(Decl
: Node_Id
) is
20725 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20728 Check_Library_Level_Entity
(Spec_Id
);
20730 -- Verify the legality against:
20731 -- * The mode of the visible declarations
20733 Check_Pragma_Conformance
20734 (Context_Pragma
=> Empty
,
20736 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
20739 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
20740 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, False);
20741 end Process_Private_Part
;
20743 ----------------------------
20744 -- Process_Statement_Part --
20745 ----------------------------
20747 procedure Process_Statement_Part
(Decl
: Node_Id
) is
20748 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20751 Check_Library_Level_Entity
(Body_Id
);
20753 -- Verify the legality against:
20754 -- * The mode of the body declarations
20756 Check_Pragma_Conformance
20757 (Context_Pragma
=> Empty
,
20759 Entity_Pragma
=> SPARK_Pragma
(Body_Id
));
20762 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
20763 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, False);
20764 end Process_Statement_Part
;
20766 --------------------------
20767 -- Process_Visible_Part --
20768 --------------------------
20770 procedure Process_Visible_Part
(Decl
: Node_Id
) is
20771 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20772 Obj_Id
: Entity_Id
;
20775 Check_Library_Level_Entity
(Spec_Id
);
20777 -- Verify the legality against:
20778 -- * The mode of the context
20780 Check_Pragma_Conformance
20781 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
20783 Entity_Pragma
=> Empty
);
20785 -- A task unit declared without a definition does not set the
20786 -- SPARK_Mode of the context because the task does not have any
20787 -- entries that could inherit the mode.
20789 if not Nkind_In
(Decl
, N_Single_Task_Declaration
,
20790 N_Task_Type_Declaration
)
20795 Set_SPARK_Pragma
(Spec_Id
, N
);
20796 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
20797 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
20798 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, True);
20800 -- When the pragma applies to a single protected or task type,
20801 -- decorate the corresponding anonymous object as well.
20803 -- protected Anon_Prot_Typ is
20804 -- pragma SPARK_Mode ...;
20806 -- end Anon_Prot_Typ;
20808 -- Obj : Anon_Prot_Typ;
20810 if Is_Single_Concurrent_Type
(Spec_Id
) then
20811 Obj_Id
:= Anonymous_Object
(Spec_Id
);
20813 Set_SPARK_Pragma
(Obj_Id
, N
);
20814 Set_SPARK_Pragma_Inherited
(Obj_Id
, False);
20816 end Process_Visible_Part
;
20818 -----------------------
20819 -- Set_SPARK_Context --
20820 -----------------------
20822 procedure Set_SPARK_Context
is
20824 SPARK_Mode
:= Mode_Id
;
20825 SPARK_Mode_Pragma
:= N
;
20827 if SPARK_Mode
= On
then
20828 Dynamic_Elaboration_Checks
:= False;
20830 end Set_SPARK_Context
;
20838 -- Start of processing for Do_SPARK_Mode
20841 -- When a SPARK_Mode pragma appears inside an instantiation whose
20842 -- enclosing context has SPARK_Mode set to "off", the pragma has
20843 -- no semantic effect.
20845 if Ignore_Pragma_SPARK_Mode
then
20846 Rewrite
(N
, Make_Null_Statement
(Loc
));
20852 Check_No_Identifiers
;
20853 Check_At_Most_N_Arguments
(1);
20855 -- Check the legality of the mode (no argument = ON)
20857 if Arg_Count
= 1 then
20858 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
20859 Mode
:= Chars
(Get_Pragma_Arg
(Arg1
));
20864 Mode_Id
:= Get_SPARK_Mode_Type
(Mode
);
20865 Context
:= Parent
(N
);
20867 -- The pragma appears in a configuration pragmas file
20869 if No
(Context
) then
20870 Check_Valid_Configuration_Pragma
;
20872 if Present
(SPARK_Mode_Pragma
) then
20873 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
20874 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
20880 -- The pragma acts as a configuration pragma in a compilation unit
20882 -- pragma SPARK_Mode ...;
20883 -- package Pack is ...;
20885 elsif Nkind
(Context
) = N_Compilation_Unit
20886 and then List_Containing
(N
) = Context_Items
(Context
)
20888 Check_Valid_Configuration_Pragma
;
20891 -- Otherwise the placement of the pragma within the tree dictates
20892 -- its associated construct. Inspect the declarative list where
20893 -- the pragma resides to find a potential construct.
20897 while Present
(Stmt
) loop
20899 -- Skip prior pragmas, but check for duplicates. Note that
20900 -- this also takes care of pragmas generated for aspects.
20902 if Nkind
(Stmt
) = N_Pragma
then
20903 if Pragma_Name
(Stmt
) = Pname
then
20904 Error_Msg_Name_1
:= Pname
;
20905 Error_Msg_Sloc
:= Sloc
(Stmt
);
20906 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
20910 -- The pragma applies to an expression function that has
20911 -- already been rewritten into a subprogram declaration.
20913 -- function Expr_Func return ... is (...);
20914 -- pragma SPARK_Mode ...;
20916 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
20917 and then Nkind
(Original_Node
(Stmt
)) =
20918 N_Expression_Function
20920 Process_Overloadable
(Stmt
);
20923 -- The pragma applies to the anonymous object created for a
20924 -- single concurrent type.
20926 -- protected type Anon_Prot_Typ ...;
20927 -- Obj : Anon_Prot_Typ;
20928 -- pragma SPARK_Mode ...;
20930 elsif Nkind
(Stmt
) = N_Object_Declaration
20931 and then Is_Single_Concurrent_Object
20932 (Defining_Entity
(Stmt
))
20934 Process_Overloadable
(Stmt
);
20937 -- Skip internally generated code
20939 elsif not Comes_From_Source
(Stmt
) then
20942 -- The pragma applies to an entry or [generic] subprogram
20946 -- pragma SPARK_Mode ...;
20949 -- procedure Proc ...;
20950 -- pragma SPARK_Mode ...;
20952 elsif Nkind_In
(Stmt
, N_Generic_Subprogram_Declaration
,
20953 N_Subprogram_Declaration
)
20954 or else (Nkind
(Stmt
) = N_Entry_Declaration
20955 and then Is_Protected_Type
20956 (Scope
(Defining_Entity
(Stmt
))))
20958 Process_Overloadable
(Stmt
);
20961 -- Otherwise the pragma does not apply to a legal construct
20962 -- or it does not appear at the top of a declarative or a
20963 -- statement list. Issue an error and stop the analysis.
20973 -- The pragma applies to a package or a subprogram that acts as
20974 -- a compilation unit.
20976 -- procedure Proc ...;
20977 -- pragma SPARK_Mode ...;
20979 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
20980 Context
:= Unit
(Parent
(Context
));
20983 -- The pragma appears at the top of entry, package, protected
20984 -- unit, subprogram or task unit body declarations.
20986 -- entry Ent when ... is
20987 -- pragma SPARK_Mode ...;
20989 -- package body Pack is
20990 -- pragma SPARK_Mode ...;
20992 -- procedure Proc ... is
20993 -- pragma SPARK_Mode;
20995 -- protected body Prot is
20996 -- pragma SPARK_Mode ...;
20998 if Nkind_In
(Context
, N_Entry_Body
,
21004 Process_Body
(Context
);
21006 -- The pragma appears at the top of the visible or private
21007 -- declaration of a package spec, protected or task unit.
21010 -- pragma SPARK_Mode ...;
21012 -- pragma SPARK_Mode ...;
21014 -- protected [type] Prot is
21015 -- pragma SPARK_Mode ...;
21017 -- pragma SPARK_Mode ...;
21019 elsif Nkind_In
(Context
, N_Package_Specification
,
21020 N_Protected_Definition
,
21023 if List_Containing
(N
) = Visible_Declarations
(Context
) then
21024 Process_Visible_Part
(Parent
(Context
));
21026 Process_Private_Part
(Parent
(Context
));
21029 -- The pragma appears at the top of package body statements
21031 -- package body Pack is
21033 -- pragma SPARK_Mode;
21035 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
21036 and then Nkind
(Parent
(Context
)) = N_Package_Body
21038 Process_Statement_Part
(Parent
(Context
));
21040 -- The pragma appeared as an aspect of a [generic] subprogram
21041 -- declaration that acts as a compilation unit.
21044 -- procedure Proc ...;
21045 -- pragma SPARK_Mode ...;
21047 elsif Nkind_In
(Context
, N_Generic_Subprogram_Declaration
,
21048 N_Subprogram_Declaration
)
21050 Process_Overloadable
(Context
);
21052 -- The pragma does not apply to a legal construct, issue error
21060 --------------------------------
21061 -- Static_Elaboration_Desired --
21062 --------------------------------
21064 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
21066 when Pragma_Static_Elaboration_Desired
=>
21068 Check_At_Most_N_Arguments
(1);
21070 if Is_Compilation_Unit
(Current_Scope
)
21071 and then Ekind
(Current_Scope
) = E_Package
21073 Set_Static_Elaboration_Desired
(Current_Scope
, True);
21075 Error_Pragma
("pragma% must apply to a library-level package");
21082 -- pragma Storage_Size (EXPRESSION);
21084 when Pragma_Storage_Size
=> Storage_Size
: declare
21085 P
: constant Node_Id
:= Parent
(N
);
21089 Check_No_Identifiers
;
21090 Check_Arg_Count
(1);
21092 -- The expression must be analyzed in the special manner described
21093 -- in "Handling of Default Expressions" in sem.ads.
21095 Arg
:= Get_Pragma_Arg
(Arg1
);
21096 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
21098 if not Is_OK_Static_Expression
(Arg
) then
21099 Check_Restriction
(Static_Storage_Size
, Arg
);
21102 if Nkind
(P
) /= N_Task_Definition
then
21107 if Has_Storage_Size_Pragma
(P
) then
21108 Error_Pragma
("duplicate pragma% not allowed");
21110 Set_Has_Storage_Size_Pragma
(P
, True);
21113 Record_Rep_Item
(Defining_Identifier
(Parent
(P
)), N
);
21121 -- pragma Storage_Unit (NUMERIC_LITERAL);
21123 -- Only permitted argument is System'Storage_Unit value
21125 when Pragma_Storage_Unit
=>
21126 Check_No_Identifiers
;
21127 Check_Arg_Count
(1);
21128 Check_Arg_Is_Integer_Literal
(Arg1
);
21130 if Intval
(Get_Pragma_Arg
(Arg1
)) /=
21131 UI_From_Int
(Ttypes
.System_Storage_Unit
)
21133 Error_Msg_Uint_1
:= UI_From_Int
(Ttypes
.System_Storage_Unit
);
21135 ("the only allowed argument for pragma% is ^", Arg1
);
21138 --------------------
21139 -- Stream_Convert --
21140 --------------------
21142 -- pragma Stream_Convert (
21143 -- [Entity =>] type_LOCAL_NAME,
21144 -- [Read =>] function_NAME,
21145 -- [Write =>] function NAME);
21147 when Pragma_Stream_Convert
=> Stream_Convert
: declare
21149 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
);
21150 -- Check that the given argument is the name of a local function
21151 -- of one argument that is not overloaded earlier in the current
21152 -- local scope. A check is also made that the argument is a
21153 -- function with one parameter.
21155 --------------------------------------
21156 -- Check_OK_Stream_Convert_Function --
21157 --------------------------------------
21159 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
) is
21163 Check_Arg_Is_Local_Name
(Arg
);
21164 Ent
:= Entity
(Get_Pragma_Arg
(Arg
));
21166 if Has_Homonym
(Ent
) then
21168 ("argument for pragma% may not be overloaded", Arg
);
21171 if Ekind
(Ent
) /= E_Function
21172 or else No
(First_Formal
(Ent
))
21173 or else Present
(Next_Formal
(First_Formal
(Ent
)))
21176 ("argument for pragma% must be function of one argument",
21179 end Check_OK_Stream_Convert_Function
;
21181 -- Start of processing for Stream_Convert
21185 Check_Arg_Order
((Name_Entity
, Name_Read
, Name_Write
));
21186 Check_Arg_Count
(3);
21187 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21188 Check_Optional_Identifier
(Arg2
, Name_Read
);
21189 Check_Optional_Identifier
(Arg3
, Name_Write
);
21190 Check_Arg_Is_Local_Name
(Arg1
);
21191 Check_OK_Stream_Convert_Function
(Arg2
);
21192 Check_OK_Stream_Convert_Function
(Arg3
);
21195 Typ
: constant Entity_Id
:=
21196 Underlying_Type
(Entity
(Get_Pragma_Arg
(Arg1
)));
21197 Read
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg2
));
21198 Write
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg3
));
21201 Check_First_Subtype
(Arg1
);
21203 -- Check for too early or too late. Note that we don't enforce
21204 -- the rule about primitive operations in this case, since, as
21205 -- is the case for explicit stream attributes themselves, these
21206 -- restrictions are not appropriate. Note that the chaining of
21207 -- the pragma by Rep_Item_Too_Late is actually the critical
21208 -- processing done for this pragma.
21210 if Rep_Item_Too_Early
(Typ
, N
)
21212 Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True)
21217 -- Return if previous error
21219 if Etype
(Typ
) = Any_Type
21221 Etype
(Read
) = Any_Type
21223 Etype
(Write
) = Any_Type
21230 if Underlying_Type
(Etype
(Read
)) /= Typ
then
21232 ("incorrect return type for function&", Arg2
);
21235 if Underlying_Type
(Etype
(First_Formal
(Write
))) /= Typ
then
21237 ("incorrect parameter type for function&", Arg3
);
21240 if Underlying_Type
(Etype
(First_Formal
(Read
))) /=
21241 Underlying_Type
(Etype
(Write
))
21244 ("result type of & does not match Read parameter type",
21248 end Stream_Convert
;
21254 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21256 -- This is processed by the parser since some of the style checks
21257 -- take place during source scanning and parsing. This means that
21258 -- we don't need to issue error messages here.
21260 when Pragma_Style_Checks
=> Style_Checks
: declare
21261 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
21267 Check_No_Identifiers
;
21269 -- Two argument form
21271 if Arg_Count
= 2 then
21272 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
21279 E_Id
:= Get_Pragma_Arg
(Arg2
);
21282 if not Is_Entity_Name
(E_Id
) then
21284 ("second argument of pragma% must be entity name",
21288 E
:= Entity
(E_Id
);
21290 if not Ignore_Style_Checks_Pragmas
then
21295 Set_Suppress_Style_Checks
21296 (E
, Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Off
);
21297 exit when No
(Homonym
(E
));
21304 -- One argument form
21307 Check_Arg_Count
(1);
21309 if Nkind
(A
) = N_String_Literal
then
21313 Slen
: constant Natural := Natural (String_Length
(S
));
21314 Options
: String (1 .. Slen
);
21320 C
:= Get_String_Char
(S
, Pos
(J
));
21321 exit when not In_Character_Range
(C
);
21322 Options
(J
) := Get_Character
(C
);
21324 -- If at end of string, set options. As per discussion
21325 -- above, no need to check for errors, since we issued
21326 -- them in the parser.
21329 if not Ignore_Style_Checks_Pragmas
then
21330 Set_Style_Check_Options
(Options
);
21340 elsif Nkind
(A
) = N_Identifier
then
21341 if Chars
(A
) = Name_All_Checks
then
21342 if not Ignore_Style_Checks_Pragmas
then
21344 Set_GNAT_Style_Check_Options
;
21346 Set_Default_Style_Check_Options
;
21350 elsif Chars
(A
) = Name_On
then
21351 if not Ignore_Style_Checks_Pragmas
then
21352 Style_Check
:= True;
21355 elsif Chars
(A
) = Name_Off
then
21356 if not Ignore_Style_Checks_Pragmas
then
21357 Style_Check
:= False;
21368 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
21370 when Pragma_Subtitle
=>
21372 Check_Arg_Count
(1);
21373 Check_Optional_Identifier
(Arg1
, Name_Subtitle
);
21374 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
21381 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
21383 when Pragma_Suppress
=>
21384 Process_Suppress_Unsuppress
(Suppress_Case
=> True);
21390 -- pragma Suppress_All;
21392 -- The only check made here is that the pragma has no arguments.
21393 -- There are no placement rules, and the processing required (setting
21394 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
21395 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
21396 -- then creates and inserts a pragma Suppress (All_Checks).
21398 when Pragma_Suppress_All
=>
21400 Check_Arg_Count
(0);
21402 -------------------------
21403 -- Suppress_Debug_Info --
21404 -------------------------
21406 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
21408 when Pragma_Suppress_Debug_Info
=> Suppress_Debug_Info
: declare
21409 Nam_Id
: Entity_Id
;
21413 Check_Arg_Count
(1);
21414 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21415 Check_Arg_Is_Local_Name
(Arg1
);
21417 Nam_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
21419 -- A pragma that applies to a Ghost entity becomes Ghost for the
21420 -- purposes of legality checks and removal of ignored Ghost code.
21422 Mark_Pragma_As_Ghost
(N
, Nam_Id
);
21423 Set_Debug_Info_Off
(Nam_Id
);
21424 end Suppress_Debug_Info
;
21426 ----------------------------------
21427 -- Suppress_Exception_Locations --
21428 ----------------------------------
21430 -- pragma Suppress_Exception_Locations;
21432 when Pragma_Suppress_Exception_Locations
=>
21434 Check_Arg_Count
(0);
21435 Check_Valid_Configuration_Pragma
;
21436 Exception_Locations_Suppressed
:= True;
21438 -----------------------------
21439 -- Suppress_Initialization --
21440 -----------------------------
21442 -- pragma Suppress_Initialization ([Entity =>] type_Name);
21444 when Pragma_Suppress_Initialization
=> Suppress_Init
: declare
21450 Check_Arg_Count
(1);
21451 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21452 Check_Arg_Is_Local_Name
(Arg1
);
21454 E_Id
:= Get_Pragma_Arg
(Arg1
);
21456 if Etype
(E_Id
) = Any_Type
then
21460 E
:= Entity
(E_Id
);
21462 -- A pragma that applies to a Ghost entity becomes Ghost for the
21463 -- purposes of legality checks and removal of ignored Ghost code.
21465 Mark_Pragma_As_Ghost
(N
, E
);
21467 if not Is_Type
(E
) and then Ekind
(E
) /= E_Variable
then
21469 ("pragma% requires variable, type or subtype", Arg1
);
21472 if Rep_Item_Too_Early
(E
, N
)
21474 Rep_Item_Too_Late
(E
, N
, FOnly
=> True)
21479 -- For incomplete/private type, set flag on full view
21481 if Is_Incomplete_Or_Private_Type
(E
) then
21482 if No
(Full_View
(Base_Type
(E
))) then
21484 ("argument of pragma% cannot be an incomplete type", Arg1
);
21486 Set_Suppress_Initialization
(Full_View
(Base_Type
(E
)));
21489 -- For first subtype, set flag on base type
21491 elsif Is_First_Subtype
(E
) then
21492 Set_Suppress_Initialization
(Base_Type
(E
));
21494 -- For other than first subtype, set flag on subtype or variable
21497 Set_Suppress_Initialization
(E
);
21505 -- pragma System_Name (DIRECT_NAME);
21507 -- Syntax check: one argument, which must be the identifier GNAT or
21508 -- the identifier GCC, no other identifiers are acceptable.
21510 when Pragma_System_Name
=>
21512 Check_No_Identifiers
;
21513 Check_Arg_Count
(1);
21514 Check_Arg_Is_One_Of
(Arg1
, Name_Gcc
, Name_Gnat
);
21516 -----------------------------
21517 -- Task_Dispatching_Policy --
21518 -----------------------------
21520 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
21522 when Pragma_Task_Dispatching_Policy
=> declare
21526 Check_Ada_83_Warning
;
21527 Check_Arg_Count
(1);
21528 Check_No_Identifiers
;
21529 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
21530 Check_Valid_Configuration_Pragma
;
21531 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
21532 DP
:= Fold_Upper
(Name_Buffer
(1));
21534 if Task_Dispatching_Policy
/= ' '
21535 and then Task_Dispatching_Policy
/= DP
21537 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
21539 ("task dispatching policy incompatible with policy#");
21541 -- Set new policy, but always preserve System_Location since we
21542 -- like the error message with the run time name.
21545 Task_Dispatching_Policy
:= DP
;
21547 if Task_Dispatching_Policy_Sloc
/= System_Location
then
21548 Task_Dispatching_Policy_Sloc
:= Loc
;
21557 -- pragma Task_Info (EXPRESSION);
21559 when Pragma_Task_Info
=> Task_Info
: declare
21560 P
: constant Node_Id
:= Parent
(N
);
21566 if Warn_On_Obsolescent_Feature
then
21568 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
21569 & "instead?j?", N
);
21572 if Nkind
(P
) /= N_Task_Definition
then
21573 Error_Pragma
("pragma% must appear in task definition");
21576 Check_No_Identifiers
;
21577 Check_Arg_Count
(1);
21579 Analyze_And_Resolve
21580 (Get_Pragma_Arg
(Arg1
), RTE
(RE_Task_Info_Type
));
21582 if Etype
(Get_Pragma_Arg
(Arg1
)) = Any_Type
then
21586 Ent
:= Defining_Identifier
(Parent
(P
));
21588 -- Check duplicate pragma before we chain the pragma in the Rep
21589 -- Item chain of Ent.
21592 (Ent
, Name_Task_Info
, Check_Parents
=> False)
21594 Error_Pragma
("duplicate pragma% not allowed");
21597 Record_Rep_Item
(Ent
, N
);
21604 -- pragma Task_Name (string_EXPRESSION);
21606 when Pragma_Task_Name
=> Task_Name
: declare
21607 P
: constant Node_Id
:= Parent
(N
);
21612 Check_No_Identifiers
;
21613 Check_Arg_Count
(1);
21615 Arg
:= Get_Pragma_Arg
(Arg1
);
21617 -- The expression is used in the call to Create_Task, and must be
21618 -- expanded there, not in the context of the current spec. It must
21619 -- however be analyzed to capture global references, in case it
21620 -- appears in a generic context.
21622 Preanalyze_And_Resolve
(Arg
, Standard_String
);
21624 if Nkind
(P
) /= N_Task_Definition
then
21628 Ent
:= Defining_Identifier
(Parent
(P
));
21630 -- Check duplicate pragma before we chain the pragma in the Rep
21631 -- Item chain of Ent.
21634 (Ent
, Name_Task_Name
, Check_Parents
=> False)
21636 Error_Pragma
("duplicate pragma% not allowed");
21639 Record_Rep_Item
(Ent
, N
);
21646 -- pragma Task_Storage (
21647 -- [Task_Type =>] LOCAL_NAME,
21648 -- [Top_Guard =>] static_integer_EXPRESSION);
21650 when Pragma_Task_Storage
=> Task_Storage
: declare
21651 Args
: Args_List
(1 .. 2);
21652 Names
: constant Name_List
(1 .. 2) := (
21656 Task_Type
: Node_Id
renames Args
(1);
21657 Top_Guard
: Node_Id
renames Args
(2);
21663 Gather_Associations
(Names
, Args
);
21665 if No
(Task_Type
) then
21667 ("missing task_type argument for pragma%");
21670 Check_Arg_Is_Local_Name
(Task_Type
);
21672 Ent
:= Entity
(Task_Type
);
21674 if not Is_Task_Type
(Ent
) then
21676 ("argument for pragma% must be task type", Task_Type
);
21679 if No
(Top_Guard
) then
21681 ("pragma% takes two arguments", Task_Type
);
21683 Check_Arg_Is_OK_Static_Expression
(Top_Guard
, Any_Integer
);
21686 Check_First_Subtype
(Task_Type
);
21688 if Rep_Item_Too_Late
(Ent
, N
) then
21697 -- pragma Test_Case
21698 -- ([Name =>] Static_String_EXPRESSION
21699 -- ,[Mode =>] MODE_TYPE
21700 -- [, Requires => Boolean_EXPRESSION]
21701 -- [, Ensures => Boolean_EXPRESSION]);
21703 -- MODE_TYPE ::= Nominal | Robustness
21705 -- Characteristics:
21707 -- * Analysis - The annotation undergoes initial checks to verify
21708 -- the legal placement and context. Secondary checks preanalyze the
21711 -- Analyze_Test_Case_In_Decl_Part
21713 -- * Expansion - None.
21715 -- * Template - The annotation utilizes the generic template of the
21716 -- related subprogram when it is:
21718 -- aspect on subprogram declaration
21720 -- The annotation must prepare its own template when it is:
21722 -- pragma on subprogram declaration
21724 -- * Globals - Capture of global references must occur after full
21727 -- * Instance - The annotation is instantiated automatically when
21728 -- the related generic subprogram is instantiated except for the
21729 -- "pragma on subprogram declaration" case. In that scenario the
21730 -- annotation must instantiate itself.
21732 when Pragma_Test_Case
=> Test_Case
: declare
21733 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
);
21734 -- Ensure that the contract of subprogram Subp_Id does not contain
21735 -- another Test_Case pragma with the same Name as the current one.
21737 -------------------------
21738 -- Check_Distinct_Name --
21739 -------------------------
21741 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
) is
21742 Items
: constant Node_Id
:= Contract
(Subp_Id
);
21743 Name
: constant String_Id
:= Get_Name_From_CTC_Pragma
(N
);
21747 -- Inspect all Test_Case pragma of the related subprogram
21748 -- looking for one with a duplicate "Name" argument.
21750 if Present
(Items
) then
21751 Prag
:= Contract_Test_Cases
(Items
);
21752 while Present
(Prag
) loop
21753 if Pragma_Name
(Prag
) = Name_Test_Case
21755 and then String_Equal
21756 (Name
, Get_Name_From_CTC_Pragma
(Prag
))
21758 Error_Msg_Sloc
:= Sloc
(Prag
);
21759 Error_Pragma
("name for pragma % is already used #");
21762 Prag
:= Next_Pragma
(Prag
);
21765 end Check_Distinct_Name
;
21769 Pack_Decl
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
21772 Subp_Decl
: Node_Id
;
21773 Subp_Id
: Entity_Id
;
21775 -- Start of processing for Test_Case
21779 Check_At_Least_N_Arguments
(2);
21780 Check_At_Most_N_Arguments
(4);
21782 ((Name_Name
, Name_Mode
, Name_Requires
, Name_Ensures
));
21786 Check_Optional_Identifier
(Arg1
, Name_Name
);
21787 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
21791 Check_Optional_Identifier
(Arg2
, Name_Mode
);
21792 Check_Arg_Is_One_Of
(Arg2
, Name_Nominal
, Name_Robustness
);
21794 -- Arguments "Requires" and "Ensures"
21796 if Present
(Arg3
) then
21797 if Present
(Arg4
) then
21798 Check_Identifier
(Arg3
, Name_Requires
);
21799 Check_Identifier
(Arg4
, Name_Ensures
);
21801 Check_Identifier_Is_One_Of
21802 (Arg3
, Name_Requires
, Name_Ensures
);
21806 -- Pragma Test_Case must be associated with a subprogram declared
21807 -- in a library-level package. First determine whether the current
21808 -- compilation unit is a legal context.
21810 if Nkind_In
(Pack_Decl
, N_Package_Declaration
,
21811 N_Generic_Package_Declaration
)
21815 -- Otherwise the placement is illegal
21819 ("pragma % must be specified within a package declaration");
21823 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
);
21825 -- Find the enclosing context
21827 Context
:= Parent
(Subp_Decl
);
21829 if Present
(Context
) then
21830 Context
:= Parent
(Context
);
21833 -- Verify the placement of the pragma
21835 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
21837 ("pragma % cannot be applied to abstract subprogram");
21840 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
21841 Error_Pragma
("pragma % cannot be applied to entry");
21844 -- The context is a [generic] subprogram declared at the top level
21845 -- of the [generic] package unit.
21847 elsif Nkind_In
(Subp_Decl
, N_Generic_Subprogram_Declaration
,
21848 N_Subprogram_Declaration
)
21849 and then Present
(Context
)
21850 and then Nkind_In
(Context
, N_Generic_Package_Declaration
,
21851 N_Package_Declaration
)
21855 -- Otherwise the placement is illegal
21859 ("pragma % must be applied to a library-level subprogram "
21864 Subp_Id
:= Defining_Entity
(Subp_Decl
);
21866 -- Chain the pragma on the contract for further processing by
21867 -- Analyze_Test_Case_In_Decl_Part.
21869 Add_Contract_Item
(N
, Subp_Id
);
21871 -- A pragma that applies to a Ghost entity becomes Ghost for the
21872 -- purposes of legality checks and removal of ignored Ghost code.
21874 Mark_Pragma_As_Ghost
(N
, Subp_Id
);
21876 -- Preanalyze the original aspect argument "Name" for ASIS or for
21877 -- a generic subprogram to properly capture global references.
21879 if ASIS_Mode
or else Is_Generic_Subprogram
(Subp_Id
) then
21880 Asp_Arg
:= Test_Case_Arg
(N
, Name_Name
, From_Aspect
=> True);
21882 if Present
(Asp_Arg
) then
21884 -- The argument appears with an identifier in association
21887 if Nkind
(Asp_Arg
) = N_Component_Association
then
21888 Asp_Arg
:= Expression
(Asp_Arg
);
21891 Check_Expr_Is_OK_Static_Expression
21892 (Asp_Arg
, Standard_String
);
21896 -- Ensure that the all Test_Case pragmas of the related subprogram
21897 -- have distinct names.
21899 Check_Distinct_Name
(Subp_Id
);
21901 -- Fully analyze the pragma when it appears inside an entry
21902 -- or subprogram body because it cannot benefit from forward
21905 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
21907 N_Subprogram_Body_Stub
)
21909 -- The legality checks of pragma Test_Case are affected by the
21910 -- SPARK mode in effect and the volatility of the context.
21911 -- Analyze all pragmas in a specific order.
21913 Analyze_If_Present
(Pragma_SPARK_Mode
);
21914 Analyze_If_Present
(Pragma_Volatile_Function
);
21915 Analyze_Test_Case_In_Decl_Part
(N
);
21919 --------------------------
21920 -- Thread_Local_Storage --
21921 --------------------------
21923 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
21925 when Pragma_Thread_Local_Storage
=> Thread_Local_Storage
: declare
21931 Check_Arg_Count
(1);
21932 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21933 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
21935 Id
:= Get_Pragma_Arg
(Arg1
);
21938 if not Is_Entity_Name
(Id
)
21939 or else Ekind
(Entity
(Id
)) /= E_Variable
21941 Error_Pragma_Arg
("local variable name required", Arg1
);
21946 -- A pragma that applies to a Ghost entity becomes Ghost for the
21947 -- purposes of legality checks and removal of ignored Ghost code.
21949 Mark_Pragma_As_Ghost
(N
, E
);
21951 if Rep_Item_Too_Early
(E
, N
)
21953 Rep_Item_Too_Late
(E
, N
)
21958 Set_Has_Pragma_Thread_Local_Storage
(E
);
21959 Set_Has_Gigi_Rep_Item
(E
);
21960 end Thread_Local_Storage
;
21966 -- pragma Time_Slice (static_duration_EXPRESSION);
21968 when Pragma_Time_Slice
=> Time_Slice
: declare
21974 Check_Arg_Count
(1);
21975 Check_No_Identifiers
;
21976 Check_In_Main_Program
;
21977 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_Duration
);
21979 if not Error_Posted
(Arg1
) then
21981 while Present
(Nod
) loop
21982 if Nkind
(Nod
) = N_Pragma
21983 and then Pragma_Name
(Nod
) = Name_Time_Slice
21985 Error_Msg_Name_1
:= Pname
;
21986 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
21993 -- Process only if in main unit
21995 if Get_Source_Unit
(Loc
) = Main_Unit
then
21996 Opt
.Time_Slice_Set
:= True;
21997 Val
:= Expr_Value_R
(Get_Pragma_Arg
(Arg1
));
21999 if Val
<= Ureal_0
then
22000 Opt
.Time_Slice_Value
:= 0;
22002 elsif Val
> UR_From_Uint
(UI_From_Int
(1000)) then
22003 Opt
.Time_Slice_Value
:= 1_000_000_000
;
22006 Opt
.Time_Slice_Value
:=
22007 UI_To_Int
(UR_To_Uint
(Val
* UI_From_Int
(1_000_000
)));
22016 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
22018 -- TITLING_OPTION ::=
22019 -- [Title =>] STRING_LITERAL
22020 -- | [Subtitle =>] STRING_LITERAL
22022 when Pragma_Title
=> Title
: declare
22023 Args
: Args_List
(1 .. 2);
22024 Names
: constant Name_List
(1 .. 2) := (
22030 Gather_Associations
(Names
, Args
);
22033 for J
in 1 .. 2 loop
22034 if Present
(Args
(J
)) then
22035 Check_Arg_Is_OK_Static_Expression
22036 (Args
(J
), Standard_String
);
22041 ----------------------------
22042 -- Type_Invariant[_Class] --
22043 ----------------------------
22045 -- pragma Type_Invariant[_Class]
22046 -- ([Entity =>] type_LOCAL_NAME,
22047 -- [Check =>] EXPRESSION);
22049 when Pragma_Type_Invariant |
22050 Pragma_Type_Invariant_Class
=>
22051 Type_Invariant
: declare
22052 I_Pragma
: Node_Id
;
22055 Check_Arg_Count
(2);
22057 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
22058 -- setting Class_Present for the Type_Invariant_Class case.
22060 Set_Class_Present
(N
, Prag_Id
= Pragma_Type_Invariant_Class
);
22061 I_Pragma
:= New_Copy
(N
);
22062 Set_Pragma_Identifier
22063 (I_Pragma
, Make_Identifier
(Loc
, Name_Invariant
));
22064 Rewrite
(N
, I_Pragma
);
22065 Set_Analyzed
(N
, False);
22067 end Type_Invariant
;
22069 ---------------------
22070 -- Unchecked_Union --
22071 ---------------------
22073 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
22075 when Pragma_Unchecked_Union
=> Unchecked_Union
: declare
22076 Assoc
: constant Node_Id
:= Arg1
;
22077 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
22087 Check_No_Identifiers
;
22088 Check_Arg_Count
(1);
22089 Check_Arg_Is_Local_Name
(Arg1
);
22091 Find_Type
(Type_Id
);
22093 Typ
:= Entity
(Type_Id
);
22095 -- A pragma that applies to a Ghost entity becomes Ghost for the
22096 -- purposes of legality checks and removal of ignored Ghost code.
22098 Mark_Pragma_As_Ghost
(N
, Typ
);
22101 or else Rep_Item_Too_Early
(Typ
, N
)
22105 Typ
:= Underlying_Type
(Typ
);
22108 if Rep_Item_Too_Late
(Typ
, N
) then
22112 Check_First_Subtype
(Arg1
);
22114 -- Note remaining cases are references to a type in the current
22115 -- declarative part. If we find an error, we post the error on
22116 -- the relevant type declaration at an appropriate point.
22118 if not Is_Record_Type
(Typ
) then
22119 Error_Msg_N
("unchecked union must be record type", Typ
);
22122 elsif Is_Tagged_Type
(Typ
) then
22123 Error_Msg_N
("unchecked union must not be tagged", Typ
);
22126 elsif not Has_Discriminants
(Typ
) then
22128 ("unchecked union must have one discriminant", Typ
);
22131 -- Note: in previous versions of GNAT we used to check for limited
22132 -- types and give an error, but in fact the standard does allow
22133 -- Unchecked_Union on limited types, so this check was removed.
22135 -- Similarly, GNAT used to require that all discriminants have
22136 -- default values, but this is not mandated by the RM.
22138 -- Proceed with basic error checks completed
22141 Tdef
:= Type_Definition
(Declaration_Node
(Typ
));
22142 Clist
:= Component_List
(Tdef
);
22144 -- Check presence of component list and variant part
22146 if No
(Clist
) or else No
(Variant_Part
(Clist
)) then
22148 ("unchecked union must have variant part", Tdef
);
22152 -- Check components
22154 Comp
:= First
(Component_Items
(Clist
));
22155 while Present
(Comp
) loop
22156 Check_Component
(Comp
, Typ
);
22160 -- Check variant part
22162 Vpart
:= Variant_Part
(Clist
);
22164 Variant
:= First
(Variants
(Vpart
));
22165 while Present
(Variant
) loop
22166 Check_Variant
(Variant
, Typ
);
22171 Set_Is_Unchecked_Union
(Typ
);
22172 Set_Convention
(Typ
, Convention_C
);
22173 Set_Has_Unchecked_Union
(Base_Type
(Typ
));
22174 Set_Is_Unchecked_Union
(Base_Type
(Typ
));
22175 end Unchecked_Union
;
22177 ------------------------
22178 -- Unimplemented_Unit --
22179 ------------------------
22181 -- pragma Unimplemented_Unit;
22183 -- Note: this only gives an error if we are generating code, or if
22184 -- we are in a generic library unit (where the pragma appears in the
22185 -- body, not in the spec).
22187 when Pragma_Unimplemented_Unit
=> Unimplemented_Unit
: declare
22188 Cunitent
: constant Entity_Id
:=
22189 Cunit_Entity
(Get_Source_Unit
(Loc
));
22190 Ent_Kind
: constant Entity_Kind
:=
22195 Check_Arg_Count
(0);
22197 if Operating_Mode
= Generate_Code
22198 or else Ent_Kind
= E_Generic_Function
22199 or else Ent_Kind
= E_Generic_Procedure
22200 or else Ent_Kind
= E_Generic_Package
22202 Get_Name_String
(Chars
(Cunitent
));
22203 Set_Casing
(Mixed_Case
);
22204 Write_Str
(Name_Buffer
(1 .. Name_Len
));
22205 Write_Str
(" is not supported in this configuration");
22207 raise Unrecoverable_Error
;
22209 end Unimplemented_Unit
;
22211 ------------------------
22212 -- Universal_Aliasing --
22213 ------------------------
22215 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
22217 when Pragma_Universal_Aliasing
=> Universal_Alias
: declare
22222 Check_Arg_Count
(1);
22223 Check_Optional_Identifier
(Arg2
, Name_Entity
);
22224 Check_Arg_Is_Local_Name
(Arg1
);
22225 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
22227 if E_Id
= Any_Type
then
22229 elsif No
(E_Id
) or else not Is_Type
(E_Id
) then
22230 Error_Pragma_Arg
("pragma% requires type", Arg1
);
22233 -- A pragma that applies to a Ghost entity becomes Ghost for the
22234 -- purposes of legality checks and removal of ignored Ghost code.
22236 Mark_Pragma_As_Ghost
(N
, E_Id
);
22237 Set_Universal_Aliasing
(Implementation_Base_Type
(E_Id
));
22238 Record_Rep_Item
(E_Id
, N
);
22239 end Universal_Alias
;
22241 --------------------
22242 -- Universal_Data --
22243 --------------------
22245 -- pragma Universal_Data [(library_unit_NAME)];
22247 when Pragma_Universal_Data
=>
22250 -- If this is a configuration pragma, then set the universal
22251 -- addressing option, otherwise confirm that the pragma satisfies
22252 -- the requirements of library unit pragma placement and leave it
22253 -- to the GNAAMP back end to detect the pragma (avoids transitive
22254 -- setting of the option due to withed units).
22256 if Is_Configuration_Pragma
then
22257 Universal_Addressing_On_AAMP
:= True;
22259 Check_Valid_Library_Unit_Pragma
;
22262 if not AAMP_On_Target
then
22263 Error_Pragma
("??pragma% ignored (applies only to AAMP)");
22270 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
22272 when Pragma_Unmodified
=> Unmodified
: declare
22274 Arg_Expr
: Node_Id
;
22275 Arg_Id
: Entity_Id
;
22277 Ghost_Error_Posted
: Boolean := False;
22278 -- Flag set when an error concerning the illegal mix of Ghost and
22279 -- non-Ghost variables is emitted.
22281 Ghost_Id
: Entity_Id
:= Empty
;
22282 -- The entity of the first Ghost variable encountered while
22283 -- processing the arguments of the pragma.
22287 Check_At_Least_N_Arguments
(1);
22289 -- Loop through arguments
22292 while Present
(Arg
) loop
22293 Check_No_Identifier
(Arg
);
22295 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
22296 -- in fact generate reference, so that the entity will have a
22297 -- reference, which will inhibit any warnings about it not
22298 -- being referenced, and also properly show up in the ali file
22299 -- as a reference. But this reference is recorded before the
22300 -- Has_Pragma_Unreferenced flag is set, so that no warning is
22301 -- generated for this reference.
22303 Check_Arg_Is_Local_Name
(Arg
);
22304 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22306 if Is_Entity_Name
(Arg_Expr
) then
22307 Arg_Id
:= Entity
(Arg_Expr
);
22309 if Is_Assignable
(Arg_Id
) then
22310 Set_Has_Pragma_Unmodified
(Arg_Id
);
22312 -- A pragma that applies to a Ghost entity becomes Ghost
22313 -- for the purposes of legality checks and removal of
22314 -- ignored Ghost code.
22316 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22318 -- Capture the entity of the first Ghost variable being
22319 -- processed for error detection purposes.
22321 if Is_Ghost_Entity
(Arg_Id
) then
22322 if No
(Ghost_Id
) then
22323 Ghost_Id
:= Arg_Id
;
22326 -- Otherwise the variable is non-Ghost. It is illegal
22327 -- to mix references to Ghost and non-Ghost entities
22330 elsif Present
(Ghost_Id
)
22331 and then not Ghost_Error_Posted
22333 Ghost_Error_Posted
:= True;
22335 Error_Msg_Name_1
:= Pname
;
22337 ("pragma % cannot mention ghost and non-ghost "
22340 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22341 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22343 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22344 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22347 -- Otherwise the pragma referenced an illegal entity
22351 ("pragma% can only be applied to a variable", Arg_Expr
);
22363 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
22365 -- or when used in a context clause:
22367 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
22369 when Pragma_Unreferenced
=> Unreferenced
: declare
22371 Arg_Expr
: Node_Id
;
22372 Arg_Id
: Entity_Id
;
22375 Ghost_Error_Posted
: Boolean := False;
22376 -- Flag set when an error concerning the illegal mix of Ghost and
22377 -- non-Ghost names is emitted.
22379 Ghost_Id
: Entity_Id
:= Empty
;
22380 -- The entity of the first Ghost name encountered while processing
22381 -- the arguments of the pragma.
22385 Check_At_Least_N_Arguments
(1);
22387 -- Check case of appearing within context clause
22389 if Is_In_Context_Clause
then
22391 -- The arguments must all be units mentioned in a with clause
22392 -- in the same context clause. Note we already checked (in
22393 -- Par.Prag) that the arguments are either identifiers or
22394 -- selected components.
22397 while Present
(Arg
) loop
22398 Citem
:= First
(List_Containing
(N
));
22399 while Citem
/= N
loop
22400 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22402 if Nkind
(Citem
) = N_With_Clause
22403 and then Same_Name
(Name
(Citem
), Arg_Expr
)
22405 Set_Has_Pragma_Unreferenced
22408 (Library_Unit
(Citem
))));
22409 Set_Elab_Unit_Name
(Arg_Expr
, Name
(Citem
));
22418 ("argument of pragma% is not withed unit", Arg
);
22424 -- Case of not in list of context items
22428 while Present
(Arg
) loop
22429 Check_No_Identifier
(Arg
);
22431 -- Note: the analyze call done by Check_Arg_Is_Local_Name
22432 -- will in fact generate reference, so that the entity will
22433 -- have a reference, which will inhibit any warnings about
22434 -- it not being referenced, and also properly show up in the
22435 -- ali file as a reference. But this reference is recorded
22436 -- before the Has_Pragma_Unreferenced flag is set, so that
22437 -- no warning is generated for this reference.
22439 Check_Arg_Is_Local_Name
(Arg
);
22440 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22442 if Is_Entity_Name
(Arg_Expr
) then
22443 Arg_Id
:= Entity
(Arg_Expr
);
22445 -- If the entity is overloaded, the pragma applies to the
22446 -- most recent overloading, as documented. In this case,
22447 -- name resolution does not generate a reference, so it
22448 -- must be done here explicitly.
22450 if Is_Overloaded
(Arg_Expr
) then
22451 Generate_Reference
(Arg_Id
, N
);
22454 Set_Has_Pragma_Unreferenced
(Arg_Id
);
22456 -- A pragma that applies to a Ghost entity becomes Ghost
22457 -- for the purposes of legality checks and removal of
22458 -- ignored Ghost code.
22460 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22462 -- Capture the entity of the first Ghost name being
22463 -- processed for error detection purposes.
22465 if Is_Ghost_Entity
(Arg_Id
) then
22466 if No
(Ghost_Id
) then
22467 Ghost_Id
:= Arg_Id
;
22470 -- Otherwise the name is non-Ghost. It is illegal to mix
22471 -- references to Ghost and non-Ghost entities
22474 elsif Present
(Ghost_Id
)
22475 and then not Ghost_Error_Posted
22477 Ghost_Error_Posted
:= True;
22479 Error_Msg_Name_1
:= Pname
;
22481 ("pragma % cannot mention ghost and non-ghost names",
22484 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22485 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22487 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22488 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22497 --------------------------
22498 -- Unreferenced_Objects --
22499 --------------------------
22501 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
22503 when Pragma_Unreferenced_Objects
=> Unreferenced_Objects
: declare
22505 Arg_Expr
: Node_Id
;
22506 Arg_Id
: Entity_Id
;
22508 Ghost_Error_Posted
: Boolean := False;
22509 -- Flag set when an error concerning the illegal mix of Ghost and
22510 -- non-Ghost types is emitted.
22512 Ghost_Id
: Entity_Id
:= Empty
;
22513 -- The entity of the first Ghost type encountered while processing
22514 -- the arguments of the pragma.
22518 Check_At_Least_N_Arguments
(1);
22521 while Present
(Arg
) loop
22522 Check_No_Identifier
(Arg
);
22523 Check_Arg_Is_Local_Name
(Arg
);
22524 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22526 if Is_Entity_Name
(Arg_Expr
) then
22527 Arg_Id
:= Entity
(Arg_Expr
);
22529 if Is_Type
(Arg_Id
) then
22530 Set_Has_Pragma_Unreferenced_Objects
(Arg_Id
);
22532 -- A pragma that applies to a Ghost entity becomes Ghost
22533 -- for the purposes of legality checks and removal of
22534 -- ignored Ghost code.
22536 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22538 -- Capture the entity of the first Ghost type being
22539 -- processed for error detection purposes.
22541 if Is_Ghost_Entity
(Arg_Id
) then
22542 if No
(Ghost_Id
) then
22543 Ghost_Id
:= Arg_Id
;
22546 -- Otherwise the type is non-Ghost. It is illegal to mix
22547 -- references to Ghost and non-Ghost entities
22550 elsif Present
(Ghost_Id
)
22551 and then not Ghost_Error_Posted
22553 Ghost_Error_Posted
:= True;
22555 Error_Msg_Name_1
:= Pname
;
22557 ("pragma % cannot mention ghost and non-ghost types",
22560 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22561 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22563 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22564 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22568 ("argument for pragma% must be type or subtype", Arg
);
22572 ("argument for pragma% must be type or subtype", Arg
);
22577 end Unreferenced_Objects
;
22579 ------------------------------
22580 -- Unreserve_All_Interrupts --
22581 ------------------------------
22583 -- pragma Unreserve_All_Interrupts;
22585 when Pragma_Unreserve_All_Interrupts
=>
22587 Check_Arg_Count
(0);
22589 if In_Extended_Main_Code_Unit
(Main_Unit_Entity
) then
22590 Unreserve_All_Interrupts
:= True;
22597 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
22599 when Pragma_Unsuppress
=>
22601 Process_Suppress_Unsuppress
(Suppress_Case
=> False);
22603 ----------------------------
22604 -- Unevaluated_Use_Of_Old --
22605 ----------------------------
22607 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
22609 when Pragma_Unevaluated_Use_Of_Old
=>
22611 Check_Arg_Count
(1);
22612 Check_No_Identifiers
;
22613 Check_Arg_Is_One_Of
(Arg1
, Name_Error
, Name_Warn
, Name_Allow
);
22615 -- Suppress/Unsuppress can appear as a configuration pragma, or in
22616 -- a declarative part or a package spec.
22618 if not Is_Configuration_Pragma
then
22619 Check_Is_In_Decl_Part_Or_Package_Spec
;
22622 -- Store proper setting of Uneval_Old
22624 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
22625 Uneval_Old
:= Fold_Upper
(Name_Buffer
(1));
22627 -------------------
22628 -- Use_VADS_Size --
22629 -------------------
22631 -- pragma Use_VADS_Size;
22633 when Pragma_Use_VADS_Size
=>
22635 Check_Arg_Count
(0);
22636 Check_Valid_Configuration_Pragma
;
22637 Use_VADS_Size
:= True;
22639 ---------------------
22640 -- Validity_Checks --
22641 ---------------------
22643 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22645 when Pragma_Validity_Checks
=> Validity_Checks
: declare
22646 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
22652 Check_Arg_Count
(1);
22653 Check_No_Identifiers
;
22655 -- Pragma always active unless in CodePeer or GNATprove modes,
22656 -- which use a fixed configuration of validity checks.
22658 if not (CodePeer_Mode
or GNATprove_Mode
) then
22659 if Nkind
(A
) = N_String_Literal
then
22663 Slen
: constant Natural := Natural (String_Length
(S
));
22664 Options
: String (1 .. Slen
);
22668 -- Couldn't we use a for loop here over Options'Range???
22672 C
:= Get_String_Char
(S
, Pos
(J
));
22674 -- This is a weird test, it skips setting validity
22675 -- checks entirely if any element of S is out of
22676 -- range of Character, what is that about ???
22678 exit when not In_Character_Range
(C
);
22679 Options
(J
) := Get_Character
(C
);
22682 Set_Validity_Check_Options
(Options
);
22690 elsif Nkind
(A
) = N_Identifier
then
22691 if Chars
(A
) = Name_All_Checks
then
22692 Set_Validity_Check_Options
("a");
22693 elsif Chars
(A
) = Name_On
then
22694 Validity_Checks_On
:= True;
22695 elsif Chars
(A
) = Name_Off
then
22696 Validity_Checks_On
:= False;
22700 end Validity_Checks
;
22706 -- pragma Volatile (LOCAL_NAME);
22708 when Pragma_Volatile
=>
22709 Process_Atomic_Independent_Shared_Volatile
;
22711 -------------------------
22712 -- Volatile_Components --
22713 -------------------------
22715 -- pragma Volatile_Components (array_LOCAL_NAME);
22717 -- Volatile is handled by the same circuit as Atomic_Components
22719 --------------------------
22720 -- Volatile_Full_Access --
22721 --------------------------
22723 -- pragma Volatile_Full_Access (LOCAL_NAME);
22725 when Pragma_Volatile_Full_Access
=>
22727 Process_Atomic_Independent_Shared_Volatile
;
22729 -----------------------
22730 -- Volatile_Function --
22731 -----------------------
22733 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
22735 when Pragma_Volatile_Function
=> Volatile_Function
: declare
22736 Over_Id
: Entity_Id
;
22737 Spec_Id
: Entity_Id
;
22738 Subp_Decl
: Node_Id
;
22742 Check_No_Identifiers
;
22743 Check_At_Most_N_Arguments
(1);
22746 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
22748 -- Generic subprogram
22750 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
22753 -- Body acts as spec
22755 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
22756 and then No
(Corresponding_Spec
(Subp_Decl
))
22760 -- Body stub acts as spec
22762 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
22763 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
22769 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
22777 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
22779 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
22784 -- Chain the pragma on the contract for completeness
22786 Add_Contract_Item
(N
, Spec_Id
);
22788 -- The legality checks of pragma Volatile_Function are affected by
22789 -- the SPARK mode in effect. Analyze all pragmas in a specific
22792 Analyze_If_Present
(Pragma_SPARK_Mode
);
22794 -- A pragma that applies to a Ghost entity becomes Ghost for the
22795 -- purposes of legality checks and removal of ignored Ghost code.
22797 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
22799 -- A volatile function cannot override a non-volatile function
22800 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
22801 -- in New_Overloaded_Entity, however at that point the pragma has
22802 -- not been processed yet.
22804 Over_Id
:= Overridden_Operation
(Spec_Id
);
22806 if Present
(Over_Id
)
22807 and then not Is_Volatile_Function
(Over_Id
)
22810 ("incompatible volatile function values in effect", Spec_Id
);
22812 Error_Msg_Sloc
:= Sloc
(Over_Id
);
22814 ("\& declared # with Volatile_Function value `False`",
22817 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
22819 ("\overridden # with Volatile_Function value `True`",
22823 -- Analyze the Boolean expression (if any)
22825 if Present
(Arg1
) then
22826 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
22828 end Volatile_Function
;
22830 ----------------------
22831 -- Warning_As_Error --
22832 ----------------------
22834 -- pragma Warning_As_Error (static_string_EXPRESSION);
22836 when Pragma_Warning_As_Error
=>
22838 Check_Arg_Count
(1);
22839 Check_No_Identifiers
;
22840 Check_Valid_Configuration_Pragma
;
22842 if not Is_Static_String_Expression
(Arg1
) then
22844 ("argument of pragma% must be static string expression",
22847 -- OK static string expression
22850 Acquire_Warning_Match_String
(Arg1
);
22851 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
22852 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
22853 new String'(Name_Buffer (1 .. Name_Len));
22860 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
22862 -- DETAILS ::= On | Off
22863 -- DETAILS ::= On | Off, local_NAME
22864 -- DETAILS ::= static_string_EXPRESSION
22865 -- DETAILS ::= On | Off, static_string_EXPRESSION
22867 -- TOOL_NAME ::= GNAT | GNATProve
22869 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
22871 -- Note: If the first argument matches an allowed tool name, it is
22872 -- always considered to be a tool name, even if there is a string
22873 -- variable of that name.
22875 -- Note if the second argument of DETAILS is a local_NAME then the
22876 -- second form is always understood. If the intention is to use
22877 -- the fourth form, then you can write NAME & "" to force the
22878 -- intepretation as a static_string_EXPRESSION.
22880 when Pragma_Warnings => Warnings : declare
22881 Reason : String_Id;
22885 Check_At_Least_N_Arguments (1);
22887 -- See if last argument is labeled Reason. If so, make sure we
22888 -- have a string literal or a concatenation of string literals,
22889 -- and acquire the REASON string. Then remove the REASON argument
22890 -- by decreasing Num_Args by one; Remaining processing looks only
22891 -- at first Num_Args arguments).
22894 Last_Arg : constant Node_Id :=
22895 Last (Pragma_Argument_Associations (N));
22898 if Nkind (Last_Arg) = N_Pragma_Argument_Association
22899 and then Chars (Last_Arg) = Name_Reason
22902 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
22903 Reason := End_String;
22904 Arg_Count := Arg_Count - 1;
22906 -- Not allowed in compiler units (bootstrap issues)
22908 Check_Compiler_Unit ("Reason for pragma Warnings", N);
22910 -- No REASON string, set null string as reason
22913 Reason := Null_String_Id;
22917 -- Now proceed with REASON taken care of and eliminated
22919 Check_No_Identifiers;
22921 -- If debug flag -gnatd.i is set, pragma is ignored
22923 if Debug_Flag_Dot_I then
22927 -- Process various forms of the pragma
22930 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22931 Shifted_Args : List_Id;
22934 -- See if first argument is a tool name, currently either
22935 -- GNAT or GNATprove. If so, either ignore the pragma if the
22936 -- tool used does not match, or continue as if no tool name
22937 -- was given otherwise, by shifting the arguments.
22939 if Nkind (Argx) = N_Identifier
22940 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
22942 if Chars (Argx) = Name_Gnat then
22943 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
22944 Rewrite (N, Make_Null_Statement (Loc));
22949 elsif Chars (Argx) = Name_Gnatprove then
22950 if not GNATprove_Mode then
22951 Rewrite (N, Make_Null_Statement (Loc));
22957 raise Program_Error;
22960 -- At this point, the pragma Warnings applies to the tool,
22961 -- so continue with shifted arguments.
22963 Arg_Count := Arg_Count - 1;
22965 if Arg_Count = 1 then
22966 Shifted_Args := New_List (New_Copy (Arg2));
22967 elsif Arg_Count = 2 then
22968 Shifted_Args := New_List (New_Copy (Arg2),
22970 elsif Arg_Count = 3 then
22971 Shifted_Args := New_List (New_Copy (Arg2),
22975 raise Program_Error;
22980 Chars => Name_Warnings,
22981 Pragma_Argument_Associations => Shifted_Args));
22986 -- One argument case
22988 if Arg_Count = 1 then
22990 -- On/Off one argument case was processed by parser
22992 if Nkind (Argx) = N_Identifier
22993 and then Nam_In (Chars (Argx), Name_On, Name_Off)
22997 -- One argument case must be ON/OFF or static string expr
22999 elsif not Is_Static_String_Expression (Arg1) then
23001 ("argument of pragma% must be On/Off or static string "
23002 & "expression", Arg1);
23004 -- One argument string expression case
23008 Lit : constant Node_Id := Expr_Value_S (Argx);
23009 Str : constant String_Id := Strval (Lit);
23010 Len : constant Nat := String_Length (Str);
23018 while J <= Len loop
23019 C := Get_String_Char (Str, J);
23020 OK := In_Character_Range (C);
23023 Chr := Get_Character (C);
23025 -- Dash case: only -Wxxx is accepted
23032 C := Get_String_Char (Str, J);
23033 Chr := Get_Character (C);
23034 exit when Chr = 'W
';
23039 elsif J < Len and then Chr = '.' then
23041 C := Get_String_Char (Str, J);
23042 Chr := Get_Character (C);
23044 if not Set_Dot_Warning_Switch (Chr) then
23046 ("invalid warning switch character "
23047 & '.' & Chr, Arg1);
23053 OK := Set_Warning_Switch (Chr);
23059 ("invalid warning switch character " & Chr,
23068 -- Two or more arguments (must be two)
23071 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
23072 Check_Arg_Count (2);
23080 E_Id := Get_Pragma_Arg (Arg2);
23083 -- In the expansion of an inlined body, a reference to
23084 -- the formal may be wrapped in a conversion if the
23085 -- actual is a conversion. Retrieve the real entity name.
23087 if (In_Instance_Body or In_Inlined_Body)
23088 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
23090 E_Id := Expression (E_Id);
23093 -- Entity name case
23095 if Is_Entity_Name (E_Id) then
23096 E := Entity (E_Id);
23103 (E, (Chars (Get_Pragma_Arg (Arg1)) =
23106 -- For OFF case, make entry in warnings off
23107 -- pragma table for later processing. But we do
23108 -- not do that within an instance, since these
23109 -- warnings are about what is needed in the
23110 -- template, not an instance of it.
23112 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
23113 and then Warn_On_Warnings_Off
23114 and then not In_Instance
23116 Warnings_Off_Pragmas.Append ((N, E, Reason));
23119 if Is_Enumeration_Type (E) then
23123 Lit := First_Literal (E);
23124 while Present (Lit) loop
23125 Set_Warnings_Off (Lit);
23126 Next_Literal (Lit);
23131 exit when No (Homonym (E));
23136 -- Error if not entity or static string expression case
23138 elsif not Is_Static_String_Expression (Arg2) then
23140 ("second argument of pragma% must be entity name "
23141 & "or static string expression", Arg2);
23143 -- Static string expression case
23146 Acquire_Warning_Match_String (Arg2);
23148 -- Note on configuration pragma case: If this is a
23149 -- configuration pragma, then for an OFF pragma, we
23150 -- just set Config True in the call, which is all
23151 -- that needs to be done. For the case of ON, this
23152 -- is normally an error, unless it is canceling the
23153 -- effect of a previous OFF pragma in the same file.
23154 -- In any other case, an error will be signalled (ON
23155 -- with no matching OFF).
23157 -- Note: We set Used if we are inside a generic to
23158 -- disable the test that the non-config case actually
23159 -- cancels a warning. That's because we can't be sure
23160 -- there isn't an instantiation in some other unit
23161 -- where a warning is suppressed.
23163 -- We could do a little better here by checking if the
23164 -- generic unit we are inside is public, but for now
23165 -- we don't bother with that refinement.
23167 if Chars (Argx) = Name_Off then
23168 Set_Specific_Warning_Off
23169 (Loc, Name_Buffer (1 .. Name_Len), Reason,
23170 Config => Is_Configuration_Pragma,
23171 Used => Inside_A_Generic or else In_Instance);
23173 elsif Chars (Argx) = Name_On then
23174 Set_Specific_Warning_On
23175 (Loc, Name_Buffer (1 .. Name_Len), Err);
23179 ("??pragma Warnings On with no matching "
23180 & "Warnings Off", Loc);
23189 -------------------
23190 -- Weak_External --
23191 -------------------
23193 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
23195 when Pragma_Weak_External => Weak_External : declare
23200 Check_Arg_Count (1);
23201 Check_Optional_Identifier (Arg1, Name_Entity);
23202 Check_Arg_Is_Library_Level_Local_Name (Arg1);
23203 Ent := Entity (Get_Pragma_Arg (Arg1));
23205 if Rep_Item_Too_Early (Ent, N) then
23208 Ent := Underlying_Type (Ent);
23211 -- The only processing required is to link this item on to the
23212 -- list of rep items for the given entity. This is accomplished
23213 -- by the call to Rep_Item_Too_Late (when no error is detected
23214 -- and False is returned).
23216 if Rep_Item_Too_Late (Ent, N) then
23219 Set_Has_Gigi_Rep_Item (Ent);
23223 -----------------------------
23224 -- Wide_Character_Encoding --
23225 -----------------------------
23227 -- pragma Wide_Character_Encoding (IDENTIFIER);
23229 when Pragma_Wide_Character_Encoding =>
23232 -- Nothing to do, handled in parser. Note that we do not enforce
23233 -- configuration pragma placement, this pragma can appear at any
23234 -- place in the source, allowing mixed encodings within a single
23239 --------------------
23240 -- Unknown_Pragma --
23241 --------------------
23243 -- Should be impossible, since the case of an unknown pragma is
23244 -- separately processed before the case statement is entered.
23246 when Unknown_Pragma =>
23247 raise Program_Error;
23250 -- AI05-0144: detect dangerous order dependence. Disabled for now,
23251 -- until AI is formally approved.
23253 -- Check_Order_Dependence;
23256 when Pragma_Exit => null;
23257 end Analyze_Pragma;
23259 ---------------------------------------------
23260 -- Analyze_Pre_Post_Condition_In_Decl_Part --
23261 ---------------------------------------------
23263 procedure Analyze_Pre_Post_Condition_In_Decl_Part
23265 Freeze_Id : Entity_Id := Empty)
23269 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
23270 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
23271 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
23273 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
23276 Disp_Typ : Entity_Id;
23277 Restore_Scope : Boolean := False;
23279 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
23282 -- Do not analyze the pragma multiple times
23284 if Is_Analyzed_Pragma (N) then
23288 -- Set the Ghost mode in effect from the pragma. Due to the delayed
23289 -- analysis of the pragma, the Ghost mode at point of declaration and
23290 -- point of analysis may not necessarely be the same. Use the mode in
23291 -- effect at the point of declaration.
23293 Set_Ghost_Mode (N);
23295 -- Ensure that the subprogram and its formals are visible when analyzing
23296 -- the expression of the pragma.
23298 if not In_Open_Scopes (Spec_Id) then
23299 Restore_Scope := True;
23300 Push_Scope (Spec_Id);
23302 if Is_Generic_Subprogram (Spec_Id) then
23303 Install_Generic_Formals (Spec_Id);
23305 Install_Formals (Spec_Id);
23309 Errors := Serious_Errors_Detected;
23310 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
23312 -- Emit a clarification message when the expression contains at least
23313 -- one undefined reference, possibly due to contract "freezing".
23315 if Errors /= Serious_Errors_Detected
23316 and then Present (Freeze_Id)
23317 and then Has_Undefined_Reference (Expr)
23319 Contract_Freeze_Error (Spec_Id, Freeze_Id);
23322 if Class_Present (N) then
23324 -- Verify that a class-wide condition is legal, i.e. the operation is
23325 -- a primitive of a tagged type. Note that a generic subprogram is
23326 -- not a primitive operation.
23328 Disp_Typ := Find_Dispatching_Type (Spec_Id);
23330 if No (Disp_Typ) or else Is_Generic_Subprogram (Spec_Id) then
23331 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
23333 if From_Aspect_Specification (N) then
23335 ("aspect % can only be specified for a primitive operation "
23336 & "of a tagged type", Corresponding_Aspect (N));
23338 -- The pragma is a source construct
23342 ("pragma % can only be specified for a primitive operation "
23343 & "of a tagged type", N);
23348 if Restore_Scope then
23352 -- Currently it is not possible to inline pre/postconditions on a
23353 -- subprogram subject to pragma Inline_Always.
23355 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
23356 Ghost_Mode := Save_Ghost_Mode;
23358 Set_Is_Analyzed_Pragma (N);
23359 end Analyze_Pre_Post_Condition_In_Decl_Part;
23361 ------------------------------------------
23362 -- Analyze_Refined_Depends_In_Decl_Part --
23363 ------------------------------------------
23365 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
23366 Body_Inputs : Elist_Id := No_Elist;
23367 Body_Outputs : Elist_Id := No_Elist;
23368 -- The inputs and outputs of the subprogram body synthesized from pragma
23369 -- Refined_Depends.
23371 Dependencies : List_Id := No_List;
23373 -- The corresponding Depends pragma along with its clauses
23375 Matched_Items : Elist_Id := No_Elist;
23376 -- A list containing the entities of all successfully matched items
23377 -- found in pragma Depends.
23379 Refinements : List_Id := No_List;
23380 -- The clauses of pragma Refined_Depends
23382 Spec_Id : Entity_Id;
23383 -- The entity of the subprogram subject to pragma Refined_Depends
23385 Spec_Inputs : Elist_Id := No_Elist;
23386 Spec_Outputs : Elist_Id := No_Elist;
23387 -- The inputs and outputs of the subprogram spec synthesized from pragma
23390 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
23391 -- Try to match a single dependency clause Dep_Clause against one or
23392 -- more refinement clauses found in list Refinements. Each successful
23393 -- match eliminates at least one refinement clause from Refinements.
23395 procedure Check_Output_States;
23396 -- Determine whether pragma Depends contains an output state with a
23397 -- visible refinement and if so, ensure that pragma Refined_Depends
23398 -- mentions all its constituents as outputs.
23400 procedure Normalize_Clauses (Clauses : List_Id);
23401 -- Given a list of dependence or refinement clauses Clauses, normalize
23402 -- each clause by creating multiple dependencies with exactly one input
23405 procedure Report_Extra_Clauses;
23406 -- Emit an error for each extra clause found in list Refinements
23408 -----------------------------
23409 -- Check_Dependency_Clause --
23410 -----------------------------
23412 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
23413 Dep_Input : constant Node_Id := Expression (Dep_Clause);
23414 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
23416 function Is_In_Out_State_Clause return Boolean;
23417 -- Determine whether dependence clause Dep_Clause denotes an abstract
23418 -- state that depends on itself (State => State).
23420 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
23421 -- Determine whether item Item denotes an abstract state with visible
23422 -- null refinement.
23424 procedure Match_Items
23425 (Dep_Item : Node_Id;
23426 Ref_Item : Node_Id;
23427 Matched : out Boolean);
23428 -- Try to match dependence item Dep_Item against refinement item
23429 -- Ref_Item. To match against a possible null refinement (see 2, 7),
23430 -- set Ref_Item to Empty. Flag Matched is set to True when one of
23431 -- the following conformance scenarios is in effect:
23432 -- 1) Both items denote null
23433 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
23434 -- 3) Both items denote attribute 'Result
23435 -- 4) Both items denote the same object
23436 -- 5) Both items denote the same formal parameter
23437 -- 6) Both items denote the same current instance of a type
23438 -- 7) Both items denote the same discriminant
23439 -- 8) Dep_Item is an abstract state with visible null refinement
23440 -- and Ref_Item denotes null.
23441 -- 9) Dep_Item is an abstract state with visible null refinement
23442 -- and Ref_Item is Empty (special case).
23443 -- 10) Dep_Item is an abstract state with visible non-null
23444 -- refinement and Ref_Item denotes one of its constituents.
23445 -- 11) Dep_Item is an abstract state without a visible refinement
23446 -- and Ref_Item denotes the same state.
23447 -- When scenario 10 is in effect, the entity of the abstract state
23448 -- denoted by Dep_Item is added to list Refined_States.
23450 procedure Record_Item
(Item_Id
: Entity_Id
);
23451 -- Store the entity of an item denoted by Item_Id in Matched_Items
23453 ----------------------------
23454 -- Is_In_Out_State_Clause --
23455 ----------------------------
23457 function Is_In_Out_State_Clause
return Boolean is
23458 Dep_Input_Id
: Entity_Id
;
23459 Dep_Output_Id
: Entity_Id
;
23462 -- Detect the following clause:
23465 if Is_Entity_Name
(Dep_Input
)
23466 and then Is_Entity_Name
(Dep_Output
)
23468 -- Handle abstract views generated for limited with clauses
23470 Dep_Input_Id
:= Available_View
(Entity_Of
(Dep_Input
));
23471 Dep_Output_Id
:= Available_View
(Entity_Of
(Dep_Output
));
23474 Ekind
(Dep_Input_Id
) = E_Abstract_State
23475 and then Dep_Input_Id
= Dep_Output_Id
;
23479 end Is_In_Out_State_Clause
;
23481 ---------------------------
23482 -- Is_Null_Refined_State --
23483 ---------------------------
23485 function Is_Null_Refined_State
(Item
: Node_Id
) return Boolean is
23486 Item_Id
: Entity_Id
;
23489 if Is_Entity_Name
(Item
) then
23491 -- Handle abstract views generated for limited with clauses
23493 Item_Id
:= Available_View
(Entity_Of
(Item
));
23496 Ekind
(Item_Id
) = E_Abstract_State
23497 and then Has_Null_Visible_Refinement
(Item_Id
);
23501 end Is_Null_Refined_State
;
23507 procedure Match_Items
23508 (Dep_Item
: Node_Id
;
23509 Ref_Item
: Node_Id
;
23510 Matched
: out Boolean)
23512 Dep_Item_Id
: Entity_Id
;
23513 Ref_Item_Id
: Entity_Id
;
23516 -- Assume that the two items do not match
23520 -- A null matches null or Empty (special case)
23522 if Nkind
(Dep_Item
) = N_Null
23523 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
23527 -- Attribute 'Result matches attribute 'Result
23529 elsif Is_Attribute_Result
(Dep_Item
)
23530 and then Is_Attribute_Result
(Dep_Item
)
23534 -- Abstract states, current instances of concurrent types,
23535 -- discriminants, formal parameters and objects.
23537 elsif Is_Entity_Name
(Dep_Item
) then
23539 -- Handle abstract views generated for limited with clauses
23541 Dep_Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
23543 if Ekind
(Dep_Item_Id
) = E_Abstract_State
then
23545 -- An abstract state with visible null refinement matches
23546 -- null or Empty (special case).
23548 if Has_Null_Visible_Refinement
(Dep_Item_Id
)
23549 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
23551 Record_Item
(Dep_Item_Id
);
23554 -- An abstract state with visible non-null refinement
23555 -- matches one of its constituents.
23557 elsif Has_Non_Null_Visible_Refinement
(Dep_Item_Id
) then
23558 if Is_Entity_Name
(Ref_Item
) then
23559 Ref_Item_Id
:= Entity_Of
(Ref_Item
);
23561 if Ekind_In
(Ref_Item_Id
, E_Abstract_State
,
23564 and then Present
(Encapsulating_State
(Ref_Item_Id
))
23565 and then Encapsulating_State
(Ref_Item_Id
) =
23568 Record_Item
(Dep_Item_Id
);
23573 -- An abstract state without a visible refinement matches
23576 elsif Is_Entity_Name
(Ref_Item
)
23577 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
23579 Record_Item
(Dep_Item_Id
);
23583 -- A current instance of a concurrent type, discriminant,
23584 -- formal parameter or an object matches itself.
23586 elsif Is_Entity_Name
(Ref_Item
)
23587 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
23589 Record_Item
(Dep_Item_Id
);
23599 procedure Record_Item
(Item_Id
: Entity_Id
) is
23601 if not Contains
(Matched_Items
, Item_Id
) then
23602 Append_New_Elmt
(Item_Id
, Matched_Items
);
23608 Clause_Matched
: Boolean := False;
23609 Dummy
: Boolean := False;
23610 Inputs_Match
: Boolean;
23611 Next_Ref_Clause
: Node_Id
;
23612 Outputs_Match
: Boolean;
23613 Ref_Clause
: Node_Id
;
23614 Ref_Input
: Node_Id
;
23615 Ref_Output
: Node_Id
;
23617 -- Start of processing for Check_Dependency_Clause
23620 -- Do not perform this check in an instance because it was already
23621 -- performed successfully in the generic template.
23623 if Is_Generic_Instance
(Spec_Id
) then
23627 -- Examine all refinement clauses and compare them against the
23628 -- dependence clause.
23630 Ref_Clause
:= First
(Refinements
);
23631 while Present
(Ref_Clause
) loop
23632 Next_Ref_Clause
:= Next
(Ref_Clause
);
23634 -- Obtain the attributes of the current refinement clause
23636 Ref_Input
:= Expression
(Ref_Clause
);
23637 Ref_Output
:= First
(Choices
(Ref_Clause
));
23639 -- The current refinement clause matches the dependence clause
23640 -- when both outputs match and both inputs match. See routine
23641 -- Match_Items for all possible conformance scenarios.
23643 -- Depends Dep_Output => Dep_Input
23647 -- Refined_Depends Ref_Output => Ref_Input
23650 (Dep_Item
=> Dep_Input
,
23651 Ref_Item
=> Ref_Input
,
23652 Matched
=> Inputs_Match
);
23655 (Dep_Item
=> Dep_Output
,
23656 Ref_Item
=> Ref_Output
,
23657 Matched
=> Outputs_Match
);
23659 -- An In_Out state clause may be matched against a refinement with
23660 -- a null input or null output as long as the non-null side of the
23661 -- relation contains a valid constituent of the In_Out_State.
23663 if Is_In_Out_State_Clause
then
23665 -- Depends => (State => State)
23666 -- Refined_Depends => (null => Constit) -- OK
23669 and then not Outputs_Match
23670 and then Nkind
(Ref_Output
) = N_Null
23672 Outputs_Match
:= True;
23675 -- Depends => (State => State)
23676 -- Refined_Depends => (Constit => null) -- OK
23678 if not Inputs_Match
23679 and then Outputs_Match
23680 and then Nkind
(Ref_Input
) = N_Null
23682 Inputs_Match
:= True;
23686 -- The current refinement clause is legally constructed following
23687 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
23688 -- the pool of candidates. The seach continues because a single
23689 -- dependence clause may have multiple matching refinements.
23691 if Inputs_Match
and Outputs_Match
then
23692 Clause_Matched
:= True;
23693 Remove
(Ref_Clause
);
23696 Ref_Clause
:= Next_Ref_Clause
;
23699 -- Depending on the order or composition of refinement clauses, an
23700 -- In_Out state clause may not be directly refinable.
23702 -- Depends => ((Output, State) => (Input, State))
23703 -- Refined_State => (State => (Constit_1, Constit_2))
23704 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
23706 -- Matching normalized clause (State => State) fails because there is
23707 -- no direct refinement capable of satisfying this relation. Another
23708 -- similar case arises when clauses (Constit_1 => Input) and (Output
23709 -- => Constit_2) are matched first, leaving no candidates for clause
23710 -- (State => State). Both scenarios are legal as long as one of the
23711 -- previous clauses mentioned a valid constituent of State.
23713 if not Clause_Matched
23714 and then Is_In_Out_State_Clause
23716 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
23718 Clause_Matched
:= True;
23721 -- A clause where the input is an abstract state with visible null
23722 -- refinement is implicitly matched when the output has already been
23723 -- matched in a previous clause.
23725 -- Depends => (Output => State) -- implicitly OK
23726 -- Refined_State => (State => null)
23727 -- Refined_Depends => (Output => ...)
23729 if not Clause_Matched
23730 and then Is_Null_Refined_State
(Dep_Input
)
23731 and then Is_Entity_Name
(Dep_Output
)
23733 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Output
)))
23735 Clause_Matched
:= True;
23738 -- A clause where the output is an abstract state with visible null
23739 -- refinement is implicitly matched when the input has already been
23740 -- matched in a previous clause.
23742 -- Depends => (State => Input) -- implicitly OK
23743 -- Refined_State => (State => null)
23744 -- Refined_Depends => (... => Input)
23746 if not Clause_Matched
23747 and then Is_Null_Refined_State
(Dep_Output
)
23748 and then Is_Entity_Name
(Dep_Input
)
23750 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
23752 Clause_Matched
:= True;
23755 -- At this point either all refinement clauses have been examined or
23756 -- pragma Refined_Depends contains a solitary null. Only an abstract
23757 -- state with null refinement can possibly match these cases.
23759 -- Depends => (State => null)
23760 -- Refined_State => (State => null)
23761 -- Refined_Depends => null -- OK
23763 if not Clause_Matched
then
23765 (Dep_Item
=> Dep_Input
,
23767 Matched
=> Inputs_Match
);
23770 (Dep_Item
=> Dep_Output
,
23772 Matched
=> Outputs_Match
);
23774 Clause_Matched
:= Inputs_Match
and Outputs_Match
;
23777 -- If the contents of Refined_Depends are legal, then the current
23778 -- dependence clause should be satisfied either by an explicit match
23779 -- or by one of the special cases.
23781 if not Clause_Matched
then
23783 (Fix_Msg
(Spec_Id
, "dependence clause of subprogram & has no "
23784 & "matching refinement in body"), Dep_Clause
, Spec_Id
);
23786 end Check_Dependency_Clause
;
23788 -------------------------
23789 -- Check_Output_States --
23790 -------------------------
23792 procedure Check_Output_States
is
23793 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
23794 -- Determine whether all constituents of state State_Id with visible
23795 -- refinement are used as outputs in pragma Refined_Depends. Emit an
23796 -- error if this is not the case.
23798 -----------------------------
23799 -- Check_Constituent_Usage --
23800 -----------------------------
23802 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
23803 Constits
: constant Elist_Id
:=
23804 Refinement_Constituents
(State_Id
);
23805 Constit_Elmt
: Elmt_Id
;
23806 Constit_Id
: Entity_Id
;
23807 Posted
: Boolean := False;
23810 if Present
(Constits
) then
23811 Constit_Elmt
:= First_Elmt
(Constits
);
23812 while Present
(Constit_Elmt
) loop
23813 Constit_Id
:= Node
(Constit_Elmt
);
23815 -- The constituent acts as an input (SPARK RM 7.2.5(3))
23817 if Present
(Body_Inputs
)
23818 and then Appears_In
(Body_Inputs
, Constit_Id
)
23820 Error_Msg_Name_1
:= Chars
(State_Id
);
23822 ("constituent & of state % must act as output in "
23823 & "dependence refinement", N
, Constit_Id
);
23825 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
23827 elsif No
(Body_Outputs
)
23828 or else not Appears_In
(Body_Outputs
, Constit_Id
)
23833 ("output state & must be replaced by all its "
23834 & "constituents in dependence refinement",
23839 ("\constituent & is missing in output list",
23843 Next_Elmt
(Constit_Elmt
);
23846 end Check_Constituent_Usage
;
23851 Item_Elmt
: Elmt_Id
;
23852 Item_Id
: Entity_Id
;
23854 -- Start of processing for Check_Output_States
23857 -- Do not perform this check in an instance because it was already
23858 -- performed successfully in the generic template.
23860 if Is_Generic_Instance
(Spec_Id
) then
23863 -- Inspect the outputs of pragma Depends looking for a state with a
23864 -- visible refinement.
23866 elsif Present
(Spec_Outputs
) then
23867 Item_Elmt
:= First_Elmt
(Spec_Outputs
);
23868 while Present
(Item_Elmt
) loop
23869 Item
:= Node
(Item_Elmt
);
23871 -- Deal with the mixed nature of the input and output lists
23873 if Nkind
(Item
) = N_Defining_Identifier
then
23876 Item_Id
:= Available_View
(Entity_Of
(Item
));
23879 if Ekind
(Item_Id
) = E_Abstract_State
then
23881 -- The state acts as an input-output, skip it
23883 if Present
(Spec_Inputs
)
23884 and then Appears_In
(Spec_Inputs
, Item_Id
)
23888 -- Ensure that all of the constituents are utilized as
23889 -- outputs in pragma Refined_Depends.
23891 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
23892 Check_Constituent_Usage
(Item_Id
);
23896 Next_Elmt
(Item_Elmt
);
23899 end Check_Output_States
;
23901 -----------------------
23902 -- Normalize_Clauses --
23903 -----------------------
23905 procedure Normalize_Clauses
(Clauses
: List_Id
) is
23906 procedure Normalize_Inputs
(Clause
: Node_Id
);
23907 -- Normalize clause Clause by creating multiple clauses for each
23908 -- input item of Clause. It is assumed that Clause has exactly one
23909 -- output. The transformation is as follows:
23911 -- Output => (Input_1, Input_2) -- original
23913 -- Output => Input_1 -- normalizations
23914 -- Output => Input_2
23916 procedure Normalize_Outputs
(Clause
: Node_Id
);
23917 -- Normalize clause Clause by creating multiple clause for each
23918 -- output item of Clause. The transformation is as follows:
23920 -- (Output_1, Output_2) => Input -- original
23922 -- Output_1 => Input -- normalization
23923 -- Output_2 => Input
23925 ----------------------
23926 -- Normalize_Inputs --
23927 ----------------------
23929 procedure Normalize_Inputs
(Clause
: Node_Id
) is
23930 Inputs
: constant Node_Id
:= Expression
(Clause
);
23931 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
23932 Output
: constant List_Id
:= Choices
(Clause
);
23933 Last_Input
: Node_Id
;
23935 New_Clause
: Node_Id
;
23936 Next_Input
: Node_Id
;
23939 -- Normalization is performed only when the original clause has
23940 -- more than one input. Multiple inputs appear as an aggregate.
23942 if Nkind
(Inputs
) = N_Aggregate
then
23943 Last_Input
:= Last
(Expressions
(Inputs
));
23945 -- Create a new clause for each input
23947 Input
:= First
(Expressions
(Inputs
));
23948 while Present
(Input
) loop
23949 Next_Input
:= Next
(Input
);
23951 -- Unhook the current input from the original input list
23952 -- because it will be relocated to a new clause.
23956 -- Special processing for the last input. At this point the
23957 -- original aggregate has been stripped down to one element.
23958 -- Replace the aggregate by the element itself.
23960 if Input
= Last_Input
then
23961 Rewrite
(Inputs
, Input
);
23963 -- Generate a clause of the form:
23968 Make_Component_Association
(Loc
,
23969 Choices
=> New_Copy_List_Tree
(Output
),
23970 Expression
=> Input
);
23972 -- The new clause contains replicated content that has
23973 -- already been analyzed, mark the clause as analyzed.
23975 Set_Analyzed
(New_Clause
);
23976 Insert_After
(Clause
, New_Clause
);
23979 Input
:= Next_Input
;
23982 end Normalize_Inputs
;
23984 -----------------------
23985 -- Normalize_Outputs --
23986 -----------------------
23988 procedure Normalize_Outputs
(Clause
: Node_Id
) is
23989 Inputs
: constant Node_Id
:= Expression
(Clause
);
23990 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
23991 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
23992 Last_Output
: Node_Id
;
23993 New_Clause
: Node_Id
;
23994 Next_Output
: Node_Id
;
23998 -- Multiple outputs appear as an aggregate. Nothing to do when
23999 -- the clause has exactly one output.
24001 if Nkind
(Outputs
) = N_Aggregate
then
24002 Last_Output
:= Last
(Expressions
(Outputs
));
24004 -- Create a clause for each output. Note that each time a new
24005 -- clause is created, the original output list slowly shrinks
24006 -- until there is one item left.
24008 Output
:= First
(Expressions
(Outputs
));
24009 while Present
(Output
) loop
24010 Next_Output
:= Next
(Output
);
24012 -- Unhook the output from the original output list as it
24013 -- will be relocated to a new clause.
24017 -- Special processing for the last output. At this point
24018 -- the original aggregate has been stripped down to one
24019 -- element. Replace the aggregate by the element itself.
24021 if Output
= Last_Output
then
24022 Rewrite
(Outputs
, Output
);
24025 -- Generate a clause of the form:
24026 -- (Output => Inputs)
24029 Make_Component_Association
(Loc
,
24030 Choices
=> New_List
(Output
),
24031 Expression
=> New_Copy_Tree
(Inputs
));
24033 -- The new clause contains replicated content that has
24034 -- already been analyzed. There is not need to reanalyze
24037 Set_Analyzed
(New_Clause
);
24038 Insert_After
(Clause
, New_Clause
);
24041 Output
:= Next_Output
;
24044 end Normalize_Outputs
;
24050 -- Start of processing for Normalize_Clauses
24053 Clause
:= First
(Clauses
);
24054 while Present
(Clause
) loop
24055 Normalize_Outputs
(Clause
);
24059 Clause
:= First
(Clauses
);
24060 while Present
(Clause
) loop
24061 Normalize_Inputs
(Clause
);
24064 end Normalize_Clauses
;
24066 --------------------------
24067 -- Report_Extra_Clauses --
24068 --------------------------
24070 procedure Report_Extra_Clauses
is
24074 -- Do not perform this check in an instance because it was already
24075 -- performed successfully in the generic template.
24077 if Is_Generic_Instance
(Spec_Id
) then
24080 elsif Present
(Refinements
) then
24081 Clause
:= First
(Refinements
);
24082 while Present
(Clause
) loop
24084 -- Do not complain about a null input refinement, since a null
24085 -- input legitimately matches anything.
24087 if Nkind
(Clause
) = N_Component_Association
24088 and then Nkind
(Expression
(Clause
)) = N_Null
24094 ("unmatched or extra clause in dependence refinement",
24101 end Report_Extra_Clauses
;
24105 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
24106 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
24107 Errors
: constant Nat
:= Serious_Errors_Detected
;
24113 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
24116 -- Do not analyze the pragma multiple times
24118 if Is_Analyzed_Pragma
(N
) then
24122 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
24124 -- Use the anonymous object as the proper spec when Refined_Depends
24125 -- applies to the body of a single task type. The object carries the
24126 -- proper Chars as well as all non-refined versions of pragmas.
24128 if Is_Single_Concurrent_Type
(Spec_Id
) then
24129 Spec_Id
:= Anonymous_Object
(Spec_Id
);
24132 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
24134 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
24135 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
24137 if No
(Depends
) then
24139 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
24140 & "& lacks aspect or pragma Depends"), N
, Spec_Id
);
24144 Deps
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
24146 -- A null dependency relation renders the refinement useless because it
24147 -- cannot possibly mention abstract states with visible refinement. Note
24148 -- that the inverse is not true as states may be refined to null
24149 -- (SPARK RM 7.2.5(2)).
24151 if Nkind
(Deps
) = N_Null
then
24153 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
24154 & "depend on abstract state with visible refinement"), N
, Spec_Id
);
24158 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
24159 -- This ensures that the categorization of all refined dependency items
24160 -- is consistent with their role.
24162 Analyze_Depends_In_Decl_Part
(N
);
24164 -- Do not match dependencies against refinements if Refined_Depends is
24165 -- illegal to avoid emitting misleading error.
24167 if Serious_Errors_Detected
= Errors
then
24169 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
24170 -- the inputs and outputs of the subprogram spec and body to verify
24171 -- the use of states with visible refinement and their constituents.
24173 if No
(Get_Pragma
(Spec_Id
, Pragma_Global
))
24174 or else No
(Get_Pragma
(Body_Id
, Pragma_Refined_Global
))
24176 Collect_Subprogram_Inputs_Outputs
24177 (Subp_Id
=> Spec_Id
,
24178 Synthesize
=> True,
24179 Subp_Inputs
=> Spec_Inputs
,
24180 Subp_Outputs
=> Spec_Outputs
,
24181 Global_Seen
=> Dummy
);
24183 Collect_Subprogram_Inputs_Outputs
24184 (Subp_Id
=> Body_Id
,
24185 Synthesize
=> True,
24186 Subp_Inputs
=> Body_Inputs
,
24187 Subp_Outputs
=> Body_Outputs
,
24188 Global_Seen
=> Dummy
);
24190 -- For an output state with a visible refinement, ensure that all
24191 -- constituents appear as outputs in the dependency refinement.
24193 Check_Output_States
;
24196 -- Matching is disabled in ASIS because clauses are not normalized as
24197 -- this is a tree altering activity similar to expansion.
24203 -- Multiple dependency clauses appear as component associations of an
24204 -- aggregate. Note that the clauses are copied because the algorithm
24205 -- modifies them and this should not be visible in Depends.
24207 pragma Assert
(Nkind
(Deps
) = N_Aggregate
);
24208 Dependencies
:= New_Copy_List_Tree
(Component_Associations
(Deps
));
24209 Normalize_Clauses
(Dependencies
);
24211 Refs
:= Expression
(Get_Argument
(N
, Spec_Id
));
24213 if Nkind
(Refs
) = N_Null
then
24214 Refinements
:= No_List
;
24216 -- Multiple dependency clauses appear as component associations of an
24217 -- aggregate. Note that the clauses are copied because the algorithm
24218 -- modifies them and this should not be visible in Refined_Depends.
24220 else pragma Assert
(Nkind
(Refs
) = N_Aggregate
);
24221 Refinements
:= New_Copy_List_Tree
(Component_Associations
(Refs
));
24222 Normalize_Clauses
(Refinements
);
24225 -- At this point the clauses of pragmas Depends and Refined_Depends
24226 -- have been normalized into simple dependencies between one output
24227 -- and one input. Examine all clauses of pragma Depends looking for
24228 -- matching clauses in pragma Refined_Depends.
24230 Clause
:= First
(Dependencies
);
24231 while Present
(Clause
) loop
24232 Check_Dependency_Clause
(Clause
);
24236 if Serious_Errors_Detected
= Errors
then
24237 Report_Extra_Clauses
;
24242 Set_Is_Analyzed_Pragma
(N
);
24243 end Analyze_Refined_Depends_In_Decl_Part
;
24245 -----------------------------------------
24246 -- Analyze_Refined_Global_In_Decl_Part --
24247 -----------------------------------------
24249 procedure Analyze_Refined_Global_In_Decl_Part
(N
: Node_Id
) is
24251 -- The corresponding Global pragma
24253 Has_In_State
: Boolean := False;
24254 Has_In_Out_State
: Boolean := False;
24255 Has_Out_State
: Boolean := False;
24256 Has_Proof_In_State
: Boolean := False;
24257 -- These flags are set when the corresponding Global pragma has a state
24258 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
24261 Has_Null_State
: Boolean := False;
24262 -- This flag is set when the corresponding Global pragma has at least
24263 -- one state with a null refinement.
24265 In_Constits
: Elist_Id
:= No_Elist
;
24266 In_Out_Constits
: Elist_Id
:= No_Elist
;
24267 Out_Constits
: Elist_Id
:= No_Elist
;
24268 Proof_In_Constits
: Elist_Id
:= No_Elist
;
24269 -- These lists contain the entities of all Input, In_Out, Output and
24270 -- Proof_In constituents that appear in Refined_Global and participate
24271 -- in state refinement.
24273 In_Items
: Elist_Id
:= No_Elist
;
24274 In_Out_Items
: Elist_Id
:= No_Elist
;
24275 Out_Items
: Elist_Id
:= No_Elist
;
24276 Proof_In_Items
: Elist_Id
:= No_Elist
;
24277 -- These list contain the entities of all Input, In_Out, Output and
24278 -- Proof_In items defined in the corresponding Global pragma.
24280 Spec_Id
: Entity_Id
;
24281 -- The entity of the subprogram subject to pragma Refined_Global
24283 States
: Elist_Id
:= No_Elist
;
24284 -- A list of all states with visible refinement found in pragma Global
24286 procedure Check_In_Out_States
;
24287 -- Determine whether the corresponding Global pragma mentions In_Out
24288 -- states with visible refinement and if so, ensure that one of the
24289 -- following completions apply to the constituents of the state:
24290 -- 1) there is at least one constituent of mode In_Out
24291 -- 2) there is at least one Input and one Output constituent
24292 -- 3) not all constituents are present and one of them is of mode
24294 -- This routine may remove elements from In_Constits, In_Out_Constits,
24295 -- Out_Constits and Proof_In_Constits.
24297 procedure Check_Input_States
;
24298 -- Determine whether the corresponding Global pragma mentions Input
24299 -- states with visible refinement and if so, ensure that at least one of
24300 -- its constituents appears as an Input item in Refined_Global.
24301 -- This routine may remove elements from In_Constits, In_Out_Constits,
24302 -- Out_Constits and Proof_In_Constits.
24304 procedure Check_Output_States
;
24305 -- Determine whether the corresponding Global pragma mentions Output
24306 -- states with visible refinement and if so, ensure that all of its
24307 -- constituents appear as Output items in Refined_Global.
24308 -- This routine may remove elements from In_Constits, In_Out_Constits,
24309 -- Out_Constits and Proof_In_Constits.
24311 procedure Check_Proof_In_States
;
24312 -- Determine whether the corresponding Global pragma mentions Proof_In
24313 -- states with visible refinement and if so, ensure that at least one of
24314 -- its constituents appears as a Proof_In item in Refined_Global.
24315 -- This routine may remove elements from In_Constits, In_Out_Constits,
24316 -- Out_Constits and Proof_In_Constits.
24318 procedure Check_Refined_Global_List
24320 Global_Mode
: Name_Id
:= Name_Input
);
24321 -- Verify the legality of a single global list declaration. Global_Mode
24322 -- denotes the current mode in effect.
24324 procedure Collect_Global_Items
24326 Mode
: Name_Id
:= Name_Input
);
24327 -- Gather all input, in out, output and Proof_In items from node List
24328 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
24329 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
24330 -- and Has_Proof_In_State are set when there is at least one abstract
24331 -- state with visible refinement available in the corresponding mode.
24332 -- Flag Has_Null_State is set when at least state has a null refinement.
24333 -- Mode enotes the current global mode in effect.
24335 function Present_Then_Remove
24337 Item
: Entity_Id
) return Boolean;
24338 -- Search List for a particular entity Item. If Item has been found,
24339 -- remove it from List. This routine is used to strip lists In_Constits,
24340 -- In_Out_Constits and Out_Constits of valid constituents.
24342 procedure Report_Extra_Constituents
;
24343 -- Emit an error for each constituent found in lists In_Constits,
24344 -- In_Out_Constits and Out_Constits.
24346 -------------------------
24347 -- Check_In_Out_States --
24348 -------------------------
24350 procedure Check_In_Out_States
is
24351 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24352 -- Determine whether one of the following coverage scenarios is in
24354 -- 1) there is at least one constituent of mode In_Out or Output
24355 -- 2) there is at least one pair of constituents with modes Input
24356 -- and Output, or Proof_In and Output.
24357 -- 3) there is at least one constituent of mode Output and not all
24358 -- constituents are present.
24359 -- If this is not the case, emit an error (SPARK RM 7.2.4(5)).
24361 -----------------------------
24362 -- Check_Constituent_Usage --
24363 -----------------------------
24365 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24366 Constits
: constant Elist_Id
:=
24367 Refinement_Constituents
(State_Id
);
24368 Constit_Elmt
: Elmt_Id
;
24369 Constit_Id
: Entity_Id
;
24370 Has_Missing
: Boolean := False;
24371 In_Out_Seen
: Boolean := False;
24372 Input_Seen
: Boolean := False;
24373 Output_Seen
: Boolean := False;
24374 Proof_In_Seen
: Boolean := False;
24377 -- Process all the constituents of the state and note their modes
24378 -- within the global refinement.
24380 if Present
(Constits
) then
24381 Constit_Elmt
:= First_Elmt
(Constits
);
24382 while Present
(Constit_Elmt
) loop
24383 Constit_Id
:= Node
(Constit_Elmt
);
24385 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
24386 Input_Seen
:= True;
24388 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
) then
24389 In_Out_Seen
:= True;
24391 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
24392 Output_Seen
:= True;
24394 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24396 Proof_In_Seen
:= True;
24399 Has_Missing
:= True;
24402 Next_Elmt
(Constit_Elmt
);
24406 -- An In_Out constituent is a valid completion
24408 if In_Out_Seen
then
24411 -- A pair of one Input/Proof_In and one Output constituent is a
24412 -- valid completion.
24414 elsif (Input_Seen
or Proof_In_Seen
) and Output_Seen
then
24417 elsif Output_Seen
then
24419 -- A single Output constituent is a valid completion only when
24420 -- some of the other constituents are missing.
24422 if Has_Missing
then
24425 -- Otherwise all constituents are of mode Output
24429 ("global refinement of state & must include at least one "
24430 & "constituent of mode `In_Out`, `Input`, or `Proof_In`",
24434 -- The state lacks a completion
24436 elsif not Input_Seen
24437 and not In_Out_Seen
24438 and not Output_Seen
24439 and not Proof_In_Seen
24442 ("missing global refinement of state &", N
, State_Id
);
24444 -- Otherwise the state has a malformed completion where at least
24445 -- one of the constituents has a different mode.
24449 ("global refinement of state & redefines the mode of its "
24450 & "constituents", N
, State_Id
);
24452 end Check_Constituent_Usage
;
24456 Item_Elmt
: Elmt_Id
;
24457 Item_Id
: Entity_Id
;
24459 -- Start of processing for Check_In_Out_States
24462 -- Do not perform this check in an instance because it was already
24463 -- performed successfully in the generic template.
24465 if Is_Generic_Instance
(Spec_Id
) then
24468 -- Inspect the In_Out items of the corresponding Global pragma
24469 -- looking for a state with a visible refinement.
24471 elsif Has_In_Out_State
and then Present
(In_Out_Items
) then
24472 Item_Elmt
:= First_Elmt
(In_Out_Items
);
24473 while Present
(Item_Elmt
) loop
24474 Item_Id
:= Node
(Item_Elmt
);
24476 -- Ensure that one of the three coverage variants is satisfied
24478 if Ekind
(Item_Id
) = E_Abstract_State
24479 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24481 Check_Constituent_Usage
(Item_Id
);
24484 Next_Elmt
(Item_Elmt
);
24487 end Check_In_Out_States
;
24489 ------------------------
24490 -- Check_Input_States --
24491 ------------------------
24493 procedure Check_Input_States
is
24494 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24495 -- Determine whether at least one constituent of state State_Id with
24496 -- visible refinement is used and has mode Input. Ensure that the
24497 -- remaining constituents do not have In_Out or Output modes. Emit an
24498 -- error if this is not the case (SPARK RM 7.2.4(5)).
24500 -----------------------------
24501 -- Check_Constituent_Usage --
24502 -----------------------------
24504 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24505 Constits
: constant Elist_Id
:=
24506 Refinement_Constituents
(State_Id
);
24507 Constit_Elmt
: Elmt_Id
;
24508 Constit_Id
: Entity_Id
;
24509 In_Seen
: Boolean := False;
24512 if Present
(Constits
) then
24513 Constit_Elmt
:= First_Elmt
(Constits
);
24514 while Present
(Constit_Elmt
) loop
24515 Constit_Id
:= Node
(Constit_Elmt
);
24517 -- At least one of the constituents appears as an Input
24519 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
24522 -- A Proof_In constituent can refine an Input state as long
24523 -- as there is at least one Input constituent present.
24525 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24529 -- The constituent appears in the global refinement, but has
24530 -- mode In_Out or Output (SPARK RM 7.2.4(5)).
24532 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24533 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
24535 Error_Msg_Name_1
:= Chars
(State_Id
);
24537 ("constituent & of state % must have mode `Input` in "
24538 & "global refinement", N
, Constit_Id
);
24541 Next_Elmt
(Constit_Elmt
);
24545 -- Not one of the constituents appeared as Input
24547 if not In_Seen
then
24549 ("global refinement of state & must include at least one "
24550 & "constituent of mode `Input`", N
, State_Id
);
24552 end Check_Constituent_Usage
;
24556 Item_Elmt
: Elmt_Id
;
24557 Item_Id
: Entity_Id
;
24559 -- Start of processing for Check_Input_States
24562 -- Do not perform this check in an instance because it was already
24563 -- performed successfully in the generic template.
24565 if Is_Generic_Instance
(Spec_Id
) then
24568 -- Inspect the Input items of the corresponding Global pragma looking
24569 -- for a state with a visible refinement.
24571 elsif Has_In_State
and then Present
(In_Items
) then
24572 Item_Elmt
:= First_Elmt
(In_Items
);
24573 while Present
(Item_Elmt
) loop
24574 Item_Id
:= Node
(Item_Elmt
);
24576 -- Ensure that at least one of the constituents is utilized and
24577 -- is of mode Input.
24579 if Ekind
(Item_Id
) = E_Abstract_State
24580 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24582 Check_Constituent_Usage
(Item_Id
);
24585 Next_Elmt
(Item_Elmt
);
24588 end Check_Input_States
;
24590 -------------------------
24591 -- Check_Output_States --
24592 -------------------------
24594 procedure Check_Output_States
is
24595 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24596 -- Determine whether all constituents of state State_Id with visible
24597 -- refinement are used and have mode Output. Emit an error if this is
24598 -- not the case (SPARK RM 7.2.4(5)).
24600 -----------------------------
24601 -- Check_Constituent_Usage --
24602 -----------------------------
24604 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24605 Constits
: constant Elist_Id
:=
24606 Refinement_Constituents
(State_Id
);
24607 Constit_Elmt
: Elmt_Id
;
24608 Constit_Id
: Entity_Id
;
24609 Posted
: Boolean := False;
24612 if Present
(Constits
) then
24613 Constit_Elmt
:= First_Elmt
(Constits
);
24614 while Present
(Constit_Elmt
) loop
24615 Constit_Id
:= Node
(Constit_Elmt
);
24617 if Present_Then_Remove
(Out_Constits
, Constit_Id
) then
24620 -- The constituent appears in the global refinement, but has
24621 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
24623 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
24624 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24625 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24627 Error_Msg_Name_1
:= Chars
(State_Id
);
24629 ("constituent & of state % must have mode `Output` in "
24630 & "global refinement", N
, Constit_Id
);
24632 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
24638 ("`Output` state & must be replaced by all its "
24639 & "constituents in global refinement", N
, State_Id
);
24643 ("\constituent & is missing in output list",
24647 Next_Elmt
(Constit_Elmt
);
24650 end Check_Constituent_Usage
;
24654 Item_Elmt
: Elmt_Id
;
24655 Item_Id
: Entity_Id
;
24657 -- Start of processing for Check_Output_States
24660 -- Do not perform this check in an instance because it was already
24661 -- performed successfully in the generic template.
24663 if Is_Generic_Instance
(Spec_Id
) then
24666 -- Inspect the Output items of the corresponding Global pragma
24667 -- looking for a state with a visible refinement.
24669 elsif Has_Out_State
and then Present
(Out_Items
) then
24670 Item_Elmt
:= First_Elmt
(Out_Items
);
24671 while Present
(Item_Elmt
) loop
24672 Item_Id
:= Node
(Item_Elmt
);
24674 -- Ensure that all of the constituents are utilized and they
24675 -- have mode Output.
24677 if Ekind
(Item_Id
) = E_Abstract_State
24678 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24680 Check_Constituent_Usage
(Item_Id
);
24683 Next_Elmt
(Item_Elmt
);
24686 end Check_Output_States
;
24688 ---------------------------
24689 -- Check_Proof_In_States --
24690 ---------------------------
24692 procedure Check_Proof_In_States
is
24693 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24694 -- Determine whether at least one constituent of state State_Id with
24695 -- visible refinement is used and has mode Proof_In. Ensure that the
24696 -- remaining constituents do not have Input, In_Out or Output modes.
24697 -- Emit an error of this is not the case (SPARK RM 7.2.4(5)).
24699 -----------------------------
24700 -- Check_Constituent_Usage --
24701 -----------------------------
24703 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24704 Constits
: constant Elist_Id
:=
24705 Refinement_Constituents
(State_Id
);
24706 Constit_Elmt
: Elmt_Id
;
24707 Constit_Id
: Entity_Id
;
24708 Proof_In_Seen
: Boolean := False;
24711 if Present
(Constits
) then
24712 Constit_Elmt
:= First_Elmt
(Constits
);
24713 while Present
(Constit_Elmt
) loop
24714 Constit_Id
:= Node
(Constit_Elmt
);
24716 -- At least one of the constituents appears as Proof_In
24718 if Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
24719 Proof_In_Seen
:= True;
24721 -- The constituent appears in the global refinement, but has
24722 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
24724 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
24725 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24726 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
24728 Error_Msg_Name_1
:= Chars
(State_Id
);
24730 ("constituent & of state % must have mode `Proof_In` "
24731 & "in global refinement", N
, Constit_Id
);
24734 Next_Elmt
(Constit_Elmt
);
24738 -- Not one of the constituents appeared as Proof_In
24740 if not Proof_In_Seen
then
24742 ("global refinement of state & must include at least one "
24743 & "constituent of mode `Proof_In`", N
, State_Id
);
24745 end Check_Constituent_Usage
;
24749 Item_Elmt
: Elmt_Id
;
24750 Item_Id
: Entity_Id
;
24752 -- Start of processing for Check_Proof_In_States
24755 -- Do not perform this check in an instance because it was already
24756 -- performed successfully in the generic template.
24758 if Is_Generic_Instance
(Spec_Id
) then
24761 -- Inspect the Proof_In items of the corresponding Global pragma
24762 -- looking for a state with a visible refinement.
24764 elsif Has_Proof_In_State
and then Present
(Proof_In_Items
) then
24765 Item_Elmt
:= First_Elmt
(Proof_In_Items
);
24766 while Present
(Item_Elmt
) loop
24767 Item_Id
:= Node
(Item_Elmt
);
24769 -- Ensure that at least one of the constituents is utilized and
24770 -- is of mode Proof_In
24772 if Ekind
(Item_Id
) = E_Abstract_State
24773 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24775 Check_Constituent_Usage
(Item_Id
);
24778 Next_Elmt
(Item_Elmt
);
24781 end Check_Proof_In_States
;
24783 -------------------------------
24784 -- Check_Refined_Global_List --
24785 -------------------------------
24787 procedure Check_Refined_Global_List
24789 Global_Mode
: Name_Id
:= Name_Input
)
24791 procedure Check_Refined_Global_Item
24793 Global_Mode
: Name_Id
);
24794 -- Verify the legality of a single global item declaration. Parameter
24795 -- Global_Mode denotes the current mode in effect.
24797 -------------------------------
24798 -- Check_Refined_Global_Item --
24799 -------------------------------
24801 procedure Check_Refined_Global_Item
24803 Global_Mode
: Name_Id
)
24805 Item_Id
: constant Entity_Id
:= Entity_Of
(Item
);
24807 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
);
24808 -- Issue a common error message for all mode mismatches. Expect
24809 -- denotes the expected mode.
24811 -----------------------------
24812 -- Inconsistent_Mode_Error --
24813 -----------------------------
24815 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
) is
24818 ("global item & has inconsistent modes", Item
, Item_Id
);
24820 Error_Msg_Name_1
:= Global_Mode
;
24821 Error_Msg_Name_2
:= Expect
;
24822 SPARK_Msg_N
("\expected mode %, found mode %", Item
);
24823 end Inconsistent_Mode_Error
;
24825 -- Start of processing for Check_Refined_Global_Item
24828 -- When the state or object acts as a constituent of another
24829 -- state with a visible refinement, collect it for the state
24830 -- completeness checks performed later on. Note that the item
24831 -- acts as a constituent only when the encapsulating state is
24832 -- present in pragma Global.
24834 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
24835 and then Present
(Encapsulating_State
(Item_Id
))
24836 and then Has_Visible_Refinement
(Encapsulating_State
(Item_Id
))
24837 and then Contains
(States
, Encapsulating_State
(Item_Id
))
24839 if Global_Mode
= Name_Input
then
24840 Append_New_Elmt
(Item_Id
, In_Constits
);
24842 elsif Global_Mode
= Name_In_Out
then
24843 Append_New_Elmt
(Item_Id
, In_Out_Constits
);
24845 elsif Global_Mode
= Name_Output
then
24846 Append_New_Elmt
(Item_Id
, Out_Constits
);
24848 elsif Global_Mode
= Name_Proof_In
then
24849 Append_New_Elmt
(Item_Id
, Proof_In_Constits
);
24852 -- When not a constituent, ensure that both occurrences of the
24853 -- item in pragmas Global and Refined_Global match.
24855 elsif Contains
(In_Items
, Item_Id
) then
24856 if Global_Mode
/= Name_Input
then
24857 Inconsistent_Mode_Error
(Name_Input
);
24860 elsif Contains
(In_Out_Items
, Item_Id
) then
24861 if Global_Mode
/= Name_In_Out
then
24862 Inconsistent_Mode_Error
(Name_In_Out
);
24865 elsif Contains
(Out_Items
, Item_Id
) then
24866 if Global_Mode
/= Name_Output
then
24867 Inconsistent_Mode_Error
(Name_Output
);
24870 elsif Contains
(Proof_In_Items
, Item_Id
) then
24873 -- The item does not appear in the corresponding Global pragma,
24874 -- it must be an extra (SPARK RM 7.2.4(3)).
24877 SPARK_Msg_NE
("extra global item &", Item
, Item_Id
);
24879 end Check_Refined_Global_Item
;
24885 -- Start of processing for Check_Refined_Global_List
24888 -- Do not perform this check in an instance because it was already
24889 -- performed successfully in the generic template.
24891 if Is_Generic_Instance
(Spec_Id
) then
24894 elsif Nkind
(List
) = N_Null
then
24897 -- Single global item declaration
24899 elsif Nkind_In
(List
, N_Expanded_Name
,
24901 N_Selected_Component
)
24903 Check_Refined_Global_Item
(List
, Global_Mode
);
24905 -- Simple global list or moded global list declaration
24907 elsif Nkind
(List
) = N_Aggregate
then
24909 -- The declaration of a simple global list appear as a collection
24912 if Present
(Expressions
(List
)) then
24913 Item
:= First
(Expressions
(List
));
24914 while Present
(Item
) loop
24915 Check_Refined_Global_Item
(Item
, Global_Mode
);
24919 -- The declaration of a moded global list appears as a collection
24920 -- of component associations where individual choices denote
24923 elsif Present
(Component_Associations
(List
)) then
24924 Item
:= First
(Component_Associations
(List
));
24925 while Present
(Item
) loop
24926 Check_Refined_Global_List
24927 (List
=> Expression
(Item
),
24928 Global_Mode
=> Chars
(First
(Choices
(Item
))));
24936 raise Program_Error
;
24942 raise Program_Error
;
24944 end Check_Refined_Global_List
;
24946 --------------------------
24947 -- Collect_Global_Items --
24948 --------------------------
24950 procedure Collect_Global_Items
24952 Mode
: Name_Id
:= Name_Input
)
24954 procedure Collect_Global_Item
24956 Item_Mode
: Name_Id
);
24957 -- Add a single item to the appropriate list. Item_Mode denotes the
24958 -- current mode in effect.
24960 -------------------------
24961 -- Collect_Global_Item --
24962 -------------------------
24964 procedure Collect_Global_Item
24966 Item_Mode
: Name_Id
)
24968 Item_Id
: constant Entity_Id
:= Available_View
(Entity_Of
(Item
));
24969 -- The above handles abstract views of variables and states built
24970 -- for limited with clauses.
24973 -- Signal that the global list contains at least one abstract
24974 -- state with a visible refinement. Note that the refinement may
24975 -- be null in which case there are no constituents.
24977 if Ekind
(Item_Id
) = E_Abstract_State
then
24978 if Has_Null_Visible_Refinement
(Item_Id
) then
24979 Has_Null_State
:= True;
24981 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
24982 Append_New_Elmt
(Item_Id
, States
);
24984 if Item_Mode
= Name_Input
then
24985 Has_In_State
:= True;
24986 elsif Item_Mode
= Name_In_Out
then
24987 Has_In_Out_State
:= True;
24988 elsif Item_Mode
= Name_Output
then
24989 Has_Out_State
:= True;
24990 elsif Item_Mode
= Name_Proof_In
then
24991 Has_Proof_In_State
:= True;
24996 -- Add the item to the proper list
24998 if Item_Mode
= Name_Input
then
24999 Append_New_Elmt
(Item_Id
, In_Items
);
25000 elsif Item_Mode
= Name_In_Out
then
25001 Append_New_Elmt
(Item_Id
, In_Out_Items
);
25002 elsif Item_Mode
= Name_Output
then
25003 Append_New_Elmt
(Item_Id
, Out_Items
);
25004 elsif Item_Mode
= Name_Proof_In
then
25005 Append_New_Elmt
(Item_Id
, Proof_In_Items
);
25007 end Collect_Global_Item
;
25013 -- Start of processing for Collect_Global_Items
25016 if Nkind
(List
) = N_Null
then
25019 -- Single global item declaration
25021 elsif Nkind_In
(List
, N_Expanded_Name
,
25023 N_Selected_Component
)
25025 Collect_Global_Item
(List
, Mode
);
25027 -- Single global list or moded global list declaration
25029 elsif Nkind
(List
) = N_Aggregate
then
25031 -- The declaration of a simple global list appear as a collection
25034 if Present
(Expressions
(List
)) then
25035 Item
:= First
(Expressions
(List
));
25036 while Present
(Item
) loop
25037 Collect_Global_Item
(Item
, Mode
);
25041 -- The declaration of a moded global list appears as a collection
25042 -- of component associations where individual choices denote mode.
25044 elsif Present
(Component_Associations
(List
)) then
25045 Item
:= First
(Component_Associations
(List
));
25046 while Present
(Item
) loop
25047 Collect_Global_Items
25048 (List
=> Expression
(Item
),
25049 Mode
=> Chars
(First
(Choices
(Item
))));
25057 raise Program_Error
;
25060 -- To accomodate partial decoration of disabled SPARK features, this
25061 -- routine may be called with illegal input. If this is the case, do
25062 -- not raise Program_Error.
25067 end Collect_Global_Items
;
25069 -------------------------
25070 -- Present_Then_Remove --
25071 -------------------------
25073 function Present_Then_Remove
25075 Item
: Entity_Id
) return Boolean
25080 if Present
(List
) then
25081 Elmt
:= First_Elmt
(List
);
25082 while Present
(Elmt
) loop
25083 if Node
(Elmt
) = Item
then
25084 Remove_Elmt
(List
, Elmt
);
25093 end Present_Then_Remove
;
25095 -------------------------------
25096 -- Report_Extra_Constituents --
25097 -------------------------------
25099 procedure Report_Extra_Constituents
is
25100 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
);
25101 -- Emit an error for every element of List
25103 ---------------------------------------
25104 -- Report_Extra_Constituents_In_List --
25105 ---------------------------------------
25107 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
) is
25108 Constit_Elmt
: Elmt_Id
;
25111 if Present
(List
) then
25112 Constit_Elmt
:= First_Elmt
(List
);
25113 while Present
(Constit_Elmt
) loop
25114 SPARK_Msg_NE
("extra constituent &", N
, Node
(Constit_Elmt
));
25115 Next_Elmt
(Constit_Elmt
);
25118 end Report_Extra_Constituents_In_List
;
25120 -- Start of processing for Report_Extra_Constituents
25123 -- Do not perform this check in an instance because it was already
25124 -- performed successfully in the generic template.
25126 if Is_Generic_Instance
(Spec_Id
) then
25130 Report_Extra_Constituents_In_List
(In_Constits
);
25131 Report_Extra_Constituents_In_List
(In_Out_Constits
);
25132 Report_Extra_Constituents_In_List
(Out_Constits
);
25133 Report_Extra_Constituents_In_List
(Proof_In_Constits
);
25135 end Report_Extra_Constituents
;
25139 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
25140 Errors
: constant Nat
:= Serious_Errors_Detected
;
25143 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
25146 -- Do not analyze the pragma multiple times
25148 if Is_Analyzed_Pragma
(N
) then
25152 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
25154 -- Use the anonymous object as the proper spec when Refined_Global
25155 -- applies to the body of a single task type. The object carries the
25156 -- proper Chars as well as all non-refined versions of pragmas.
25158 if Is_Single_Concurrent_Type
(Spec_Id
) then
25159 Spec_Id
:= Anonymous_Object
(Spec_Id
);
25162 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
25163 Items
:= Expression
(Get_Argument
(N
, Spec_Id
));
25165 -- The subprogram declaration lacks pragma Global. This renders
25166 -- Refined_Global useless as there is nothing to refine.
25168 if No
(Global
) then
25170 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
25171 & "& lacks aspect or pragma Global"), N
, Spec_Id
);
25175 -- Extract all relevant items from the corresponding Global pragma
25177 Collect_Global_Items
(Expression
(Get_Argument
(Global
, Spec_Id
)));
25179 -- Package and subprogram bodies are instantiated individually in
25180 -- a separate compiler pass. Due to this mode of instantiation, the
25181 -- refinement of a state may no longer be visible when a subprogram
25182 -- body contract is instantiated. Since the generic template is legal,
25183 -- do not perform this check in the instance to circumvent this oddity.
25185 if Is_Generic_Instance
(Spec_Id
) then
25188 -- Non-instance case
25191 -- The corresponding Global pragma must mention at least one state
25192 -- witha visible refinement at the point Refined_Global is processed.
25193 -- States with null refinements need Refined_Global pragma
25194 -- (SPARK RM 7.2.4(2)).
25196 if not Has_In_State
25197 and then not Has_In_Out_State
25198 and then not Has_Out_State
25199 and then not Has_Proof_In_State
25200 and then not Has_Null_State
25203 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
25204 & "depend on abstract state with visible refinement"),
25208 -- The global refinement of inputs and outputs cannot be null when
25209 -- the corresponding Global pragma contains at least one item except
25210 -- in the case where we have states with null refinements.
25212 elsif Nkind
(Items
) = N_Null
25214 (Present
(In_Items
)
25215 or else Present
(In_Out_Items
)
25216 or else Present
(Out_Items
)
25217 or else Present
(Proof_In_Items
))
25218 and then not Has_Null_State
25221 (Fix_Msg
(Spec_Id
, "refinement cannot be null, subprogram & has "
25222 & "global items"), N
, Spec_Id
);
25227 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
25228 -- This ensures that the categorization of all refined global items is
25229 -- consistent with their role.
25231 Analyze_Global_In_Decl_Part
(N
);
25233 -- Perform all refinement checks with respect to completeness and mode
25236 if Serious_Errors_Detected
= Errors
then
25237 Check_Refined_Global_List
(Items
);
25240 -- For Input states with visible refinement, at least one constituent
25241 -- must be used as an Input in the global refinement.
25243 if Serious_Errors_Detected
= Errors
then
25244 Check_Input_States
;
25247 -- Verify all possible completion variants for In_Out states with
25248 -- visible refinement.
25250 if Serious_Errors_Detected
= Errors
then
25251 Check_In_Out_States
;
25254 -- For Output states with visible refinement, all constituents must be
25255 -- used as Outputs in the global refinement.
25257 if Serious_Errors_Detected
= Errors
then
25258 Check_Output_States
;
25261 -- For Proof_In states with visible refinement, at least one constituent
25262 -- must be used as Proof_In in the global refinement.
25264 if Serious_Errors_Detected
= Errors
then
25265 Check_Proof_In_States
;
25268 -- Emit errors for all constituents that belong to other states with
25269 -- visible refinement that do not appear in Global.
25271 if Serious_Errors_Detected
= Errors
then
25272 Report_Extra_Constituents
;
25276 Set_Is_Analyzed_Pragma
(N
);
25277 end Analyze_Refined_Global_In_Decl_Part
;
25279 ----------------------------------------
25280 -- Analyze_Refined_State_In_Decl_Part --
25281 ----------------------------------------
25283 procedure Analyze_Refined_State_In_Decl_Part
25285 Freeze_Id
: Entity_Id
:= Empty
)
25287 Body_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
25288 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
25289 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(Body_Decl
);
25291 Available_States
: Elist_Id
:= No_Elist
;
25292 -- A list of all abstract states defined in the package declaration that
25293 -- are available for refinement. The list is used to report unrefined
25296 Body_States
: Elist_Id
:= No_Elist
;
25297 -- A list of all hidden states that appear in the body of the related
25298 -- package. The list is used to report unused hidden states.
25300 Constituents_Seen
: Elist_Id
:= No_Elist
;
25301 -- A list that contains all constituents processed so far. The list is
25302 -- used to detect multiple uses of the same constituent.
25304 Freeze_Posted
: Boolean := False;
25305 -- A flag that controls the output of a freezing-related error (see use
25308 Refined_States_Seen
: Elist_Id
:= No_Elist
;
25309 -- A list that contains all refined states processed so far. The list is
25310 -- used to detect duplicate refinements.
25312 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
);
25313 -- Perform full analysis of a single refinement clause
25315 procedure Report_Unrefined_States
(States
: Elist_Id
);
25316 -- Emit errors for all unrefined abstract states found in list States
25318 -------------------------------
25319 -- Analyze_Refinement_Clause --
25320 -------------------------------
25322 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
) is
25323 AR_Constit
: Entity_Id
:= Empty
;
25324 AW_Constit
: Entity_Id
:= Empty
;
25325 ER_Constit
: Entity_Id
:= Empty
;
25326 EW_Constit
: Entity_Id
:= Empty
;
25327 -- The entities of external constituents that contain one of the
25328 -- following enabled properties: Async_Readers, Async_Writers,
25329 -- Effective_Reads and Effective_Writes.
25331 External_Constit_Seen
: Boolean := False;
25332 -- Flag used to mark when at least one external constituent is part
25333 -- of the state refinement.
25335 Non_Null_Seen
: Boolean := False;
25336 Null_Seen
: Boolean := False;
25337 -- Flags used to detect multiple uses of null in a single clause or a
25338 -- mixture of null and non-null constituents.
25340 Part_Of_Constits
: Elist_Id
:= No_Elist
;
25341 -- A list of all candidate constituents subject to indicator Part_Of
25342 -- where the encapsulating state is the current state.
25345 State_Id
: Entity_Id
;
25346 -- The current state being refined
25348 procedure Analyze_Constituent
(Constit
: Node_Id
);
25349 -- Perform full analysis of a single constituent
25351 procedure Check_External_Property
25352 (Prop_Nam
: Name_Id
;
25354 Constit
: Entity_Id
);
25355 -- Determine whether a property denoted by name Prop_Nam is present
25356 -- in the refined state. Emit an error if this is not the case. Flag
25357 -- Enabled should be set when the property applies to the refined
25358 -- state. Constit denotes the constituent (if any) which introduces
25359 -- the property in the refinement.
25361 procedure Match_State
;
25362 -- Determine whether the state being refined appears in list
25363 -- Available_States. Emit an error when attempting to re-refine the
25364 -- state or when the state is not defined in the package declaration,
25365 -- otherwise remove the state from Available_States.
25367 procedure Report_Unused_Constituents
(Constits
: Elist_Id
);
25368 -- Emit errors for all unused Part_Of constituents in list Constits
25370 -------------------------
25371 -- Analyze_Constituent --
25372 -------------------------
25374 procedure Analyze_Constituent
(Constit
: Node_Id
) is
25375 procedure Match_Constituent
(Constit_Id
: Entity_Id
);
25376 -- Determine whether constituent Constit denoted by its entity
25377 -- Constit_Id appears in Body_States. Emit an error when the
25378 -- constituent is not a valid hidden state of the related package
25379 -- or when it is used more than once. Otherwise remove the
25380 -- constituent from Body_States.
25382 -----------------------
25383 -- Match_Constituent --
25384 -----------------------
25386 procedure Match_Constituent
(Constit_Id
: Entity_Id
) is
25387 procedure Collect_Constituent
;
25388 -- Verify the legality of constituent Constit_Id and add it to
25389 -- the refinements of State_Id.
25391 -------------------------
25392 -- Collect_Constituent --
25393 -------------------------
25395 procedure Collect_Constituent
is
25396 Constits
: Elist_Id
;
25399 -- The Ghost policy in effect at the point of abstract state
25400 -- declaration and constituent must match (SPARK RM 6.9(15))
25402 Check_Ghost_Refinement
25403 (State
, State_Id
, Constit
, Constit_Id
);
25405 -- A synchronized state must be refined by a synchronized
25406 -- object or another synchronized state (SPARK RM 9.6).
25408 if Is_Synchronized_State
(State_Id
)
25409 and then not Is_Synchronized_Object
(Constit_Id
)
25410 and then not Is_Synchronized_State
(Constit_Id
)
25413 ("constituent of synchronized state & must be "
25414 & "synchronized", Constit
, State_Id
);
25417 -- Add the constituent to the list of processed items to aid
25418 -- with the detection of duplicates.
25420 Append_New_Elmt
(Constit_Id
, Constituents_Seen
);
25422 -- Collect the constituent in the list of refinement items
25423 -- and establish a relation between the refined state and
25426 Constits
:= Refinement_Constituents
(State_Id
);
25428 if No
(Constits
) then
25429 Constits
:= New_Elmt_List
;
25430 Set_Refinement_Constituents
(State_Id
, Constits
);
25433 Append_Elmt
(Constit_Id
, Constits
);
25434 Set_Encapsulating_State
(Constit_Id
, State_Id
);
25436 -- The state has at least one legal constituent, mark the
25437 -- start of the refinement region. The region ends when the
25438 -- body declarations end (see routine Analyze_Declarations).
25440 Set_Has_Visible_Refinement
(State_Id
);
25442 -- When the constituent is external, save its relevant
25443 -- property for further checks.
25445 if Async_Readers_Enabled
(Constit_Id
) then
25446 AR_Constit
:= Constit_Id
;
25447 External_Constit_Seen
:= True;
25450 if Async_Writers_Enabled
(Constit_Id
) then
25451 AW_Constit
:= Constit_Id
;
25452 External_Constit_Seen
:= True;
25455 if Effective_Reads_Enabled
(Constit_Id
) then
25456 ER_Constit
:= Constit_Id
;
25457 External_Constit_Seen
:= True;
25460 if Effective_Writes_Enabled
(Constit_Id
) then
25461 EW_Constit
:= Constit_Id
;
25462 External_Constit_Seen
:= True;
25464 end Collect_Constituent
;
25468 State_Elmt
: Elmt_Id
;
25470 -- Start of processing for Match_Constituent
25473 -- Detect a duplicate use of a constituent
25475 if Contains
(Constituents_Seen
, Constit_Id
) then
25477 ("duplicate use of constituent &", Constit
, Constit_Id
);
25481 -- The constituent is subject to a Part_Of indicator
25483 if Present
(Encapsulating_State
(Constit_Id
)) then
25484 if Encapsulating_State
(Constit_Id
) = State_Id
then
25485 Remove
(Part_Of_Constits
, Constit_Id
);
25486 Collect_Constituent
;
25488 -- The constituent is part of another state and is used
25489 -- incorrectly in the refinement of the current state.
25492 Error_Msg_Name_1
:= Chars
(State_Id
);
25494 ("& cannot act as constituent of state %",
25495 Constit
, Constit_Id
);
25497 ("\Part_Of indicator specifies encapsulator &",
25498 Constit
, Encapsulating_State
(Constit_Id
));
25501 -- The only other source of legal constituents is the body
25502 -- state space of the related package.
25505 if Present
(Body_States
) then
25506 State_Elmt
:= First_Elmt
(Body_States
);
25507 while Present
(State_Elmt
) loop
25509 -- Consume a valid constituent to signal that it has
25510 -- been encountered.
25512 if Node
(State_Elmt
) = Constit_Id
then
25513 Remove_Elmt
(Body_States
, State_Elmt
);
25514 Collect_Constituent
;
25518 Next_Elmt
(State_Elmt
);
25522 -- Constants are part of the hidden state of a package, but
25523 -- the compiler cannot determine whether they have variable
25524 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
25525 -- hidden state. Accept the constant quietly even if it is
25526 -- a visible state or lacks a Part_Of indicator.
25528 if Ekind
(Constit_Id
) = E_Constant
then
25529 Collect_Constituent
;
25531 -- If we get here, then the constituent is not a hidden
25532 -- state of the related package and may not be used in a
25533 -- refinement (SPARK RM 7.2.2(9)).
25536 Error_Msg_Name_1
:= Chars
(Spec_Id
);
25538 ("cannot use & in refinement, constituent is not a "
25539 & "hidden state of package %", Constit
, Constit_Id
);
25542 end Match_Constituent
;
25546 Constit_Id
: Entity_Id
;
25547 Constits
: Elist_Id
;
25549 -- Start of processing for Analyze_Constituent
25552 -- Detect multiple uses of null in a single refinement clause or a
25553 -- mixture of null and non-null constituents.
25555 if Nkind
(Constit
) = N_Null
then
25558 ("multiple null constituents not allowed", Constit
);
25560 elsif Non_Null_Seen
then
25562 ("cannot mix null and non-null constituents", Constit
);
25567 -- Collect the constituent in the list of refinement items
25569 Constits
:= Refinement_Constituents
(State_Id
);
25571 if No
(Constits
) then
25572 Constits
:= New_Elmt_List
;
25573 Set_Refinement_Constituents
(State_Id
, Constits
);
25576 Append_Elmt
(Constit
, Constits
);
25578 -- The state has at least one legal constituent, mark the
25579 -- start of the refinement region. The region ends when the
25580 -- body declarations end (see Analyze_Declarations).
25582 Set_Has_Visible_Refinement
(State_Id
);
25585 -- Non-null constituents
25588 Non_Null_Seen
:= True;
25592 ("cannot mix null and non-null constituents", Constit
);
25596 Resolve_State
(Constit
);
25598 -- Ensure that the constituent denotes a valid state or a
25599 -- whole object (SPARK RM 7.2.2(5)).
25601 if Is_Entity_Name
(Constit
) then
25602 Constit_Id
:= Entity_Of
(Constit
);
25604 -- When a constituent is declared after a subprogram body
25605 -- that caused "freezing" of the related contract where
25606 -- pragma Refined_State resides, the constituent appears
25607 -- undefined and carries Any_Id as its entity.
25609 -- package body Pack
25610 -- with Refined_State => (State => Constit)
25613 -- with Refined_Global => (Input => Constit)
25621 if Constit_Id
= Any_Id
then
25622 SPARK_Msg_NE
("& is undefined", Constit
, Constit_Id
);
25624 -- Emit a specialized info message when the contract of
25625 -- the related package body was "frozen" by another body.
25626 -- Note that it is not possible to precisely identify why
25627 -- the constituent is undefined because it is not visible
25628 -- when pragma Refined_State is analyzed. This message is
25629 -- a reasonable approximation.
25631 if Present
(Freeze_Id
) and then not Freeze_Posted
then
25632 Freeze_Posted
:= True;
25634 Error_Msg_Name_1
:= Chars
(Body_Id
);
25635 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
25637 ("body & declared # freezes the contract of %",
25640 ("\all constituents must be declared before body #",
25643 -- A misplaced constituent is a critical error because
25644 -- pragma Refined_Depends or Refined_Global depends on
25645 -- the proper link between a state and a constituent.
25646 -- Stop the compilation, as this leads to a multitude
25647 -- of misleading cascaded errors.
25649 raise Program_Error
;
25652 -- The constituent is a valid state or object
25654 elsif Ekind_In
(Constit_Id
, E_Abstract_State
,
25658 Match_Constituent
(Constit_Id
);
25660 -- The variable may eventually become a constituent of a
25661 -- single protected/task type. Record the reference now
25662 -- and verify its legality when analyzing the contract of
25663 -- the variable (SPARK RM 9.3).
25665 if Ekind
(Constit_Id
) = E_Variable
then
25666 Record_Possible_Part_Of_Reference
25667 (Var_Id
=> Constit_Id
,
25671 -- Otherwise the constituent is illegal
25675 ("constituent & must denote object or state",
25676 Constit
, Constit_Id
);
25679 -- The constituent is illegal
25682 SPARK_Msg_N
("malformed constituent", Constit
);
25685 end Analyze_Constituent
;
25687 -----------------------------
25688 -- Check_External_Property --
25689 -----------------------------
25691 procedure Check_External_Property
25692 (Prop_Nam
: Name_Id
;
25694 Constit
: Entity_Id
)
25697 -- The property is missing in the declaration of the state, but
25698 -- a constituent is introducing it in the state refinement
25699 -- (SPARK RM 7.2.8(2)).
25701 if not Enabled
and then Present
(Constit
) then
25702 Error_Msg_Name_1
:= Prop_Nam
;
25703 Error_Msg_Name_2
:= Chars
(State_Id
);
25705 ("constituent & introduces external property % in refinement "
25706 & "of state %", State
, Constit
);
25708 Error_Msg_Sloc
:= Sloc
(State_Id
);
25710 ("\property is missing in abstract state declaration #",
25713 end Check_External_Property
;
25719 procedure Match_State
is
25720 State_Elmt
: Elmt_Id
;
25723 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
25725 if Contains
(Refined_States_Seen
, State_Id
) then
25727 ("duplicate refinement of state &", State
, State_Id
);
25731 -- Inspect the abstract states defined in the package declaration
25732 -- looking for a match.
25734 State_Elmt
:= First_Elmt
(Available_States
);
25735 while Present
(State_Elmt
) loop
25737 -- A valid abstract state is being refined in the body. Add
25738 -- the state to the list of processed refined states to aid
25739 -- with the detection of duplicate refinements. Remove the
25740 -- state from Available_States to signal that it has already
25743 if Node
(State_Elmt
) = State_Id
then
25744 Append_New_Elmt
(State_Id
, Refined_States_Seen
);
25745 Remove_Elmt
(Available_States
, State_Elmt
);
25749 Next_Elmt
(State_Elmt
);
25752 -- If we get here, we are refining a state that is not defined in
25753 -- the package declaration.
25755 Error_Msg_Name_1
:= Chars
(Spec_Id
);
25757 ("cannot refine state, & is not defined in package %",
25761 --------------------------------
25762 -- Report_Unused_Constituents --
25763 --------------------------------
25765 procedure Report_Unused_Constituents
(Constits
: Elist_Id
) is
25766 Constit_Elmt
: Elmt_Id
;
25767 Constit_Id
: Entity_Id
;
25768 Posted
: Boolean := False;
25771 if Present
(Constits
) then
25772 Constit_Elmt
:= First_Elmt
(Constits
);
25773 while Present
(Constit_Elmt
) loop
25774 Constit_Id
:= Node
(Constit_Elmt
);
25776 -- Generate an error message of the form:
25778 -- state ... has unused Part_Of constituents
25779 -- abstract state ... defined at ...
25780 -- constant ... defined at ...
25781 -- variable ... defined at ...
25786 ("state & has unused Part_Of constituents",
25790 Error_Msg_Sloc
:= Sloc
(Constit_Id
);
25792 if Ekind
(Constit_Id
) = E_Abstract_State
then
25794 ("\abstract state & defined #", State
, Constit_Id
);
25796 elsif Ekind
(Constit_Id
) = E_Constant
then
25798 ("\constant & defined #", State
, Constit_Id
);
25801 pragma Assert
(Ekind
(Constit_Id
) = E_Variable
);
25802 SPARK_Msg_NE
("\variable & defined #", State
, Constit_Id
);
25805 Next_Elmt
(Constit_Elmt
);
25808 end Report_Unused_Constituents
;
25810 -- Local declarations
25812 Body_Ref
: Node_Id
;
25813 Body_Ref_Elmt
: Elmt_Id
;
25815 Extra_State
: Node_Id
;
25817 -- Start of processing for Analyze_Refinement_Clause
25820 -- A refinement clause appears as a component association where the
25821 -- sole choice is the state and the expressions are the constituents.
25822 -- This is a syntax error, always report.
25824 if Nkind
(Clause
) /= N_Component_Association
then
25825 Error_Msg_N
("malformed state refinement clause", Clause
);
25829 -- Analyze the state name of a refinement clause
25831 State
:= First
(Choices
(Clause
));
25834 Resolve_State
(State
);
25836 -- Ensure that the state name denotes a valid abstract state that is
25837 -- defined in the spec of the related package.
25839 if Is_Entity_Name
(State
) then
25840 State_Id
:= Entity_Of
(State
);
25842 -- When the abstract state is undefined, it appears as Any_Id. Do
25843 -- not continue with the analysis of the clause.
25845 if State_Id
= Any_Id
then
25848 -- Catch any attempts to re-refine a state or refine a state that
25849 -- is not defined in the package declaration.
25851 elsif Ekind
(State_Id
) = E_Abstract_State
then
25855 SPARK_Msg_NE
("& must denote abstract state", State
, State_Id
);
25859 -- References to a state with visible refinement are illegal.
25860 -- When nested packages are involved, detecting such references is
25861 -- tricky because pragma Refined_State is analyzed later than the
25862 -- offending pragma Depends or Global. References that occur in
25863 -- such nested context are stored in a list. Emit errors for all
25864 -- references found in Body_References (SPARK RM 6.1.4(8)).
25866 if Present
(Body_References
(State_Id
)) then
25867 Body_Ref_Elmt
:= First_Elmt
(Body_References
(State_Id
));
25868 while Present
(Body_Ref_Elmt
) loop
25869 Body_Ref
:= Node
(Body_Ref_Elmt
);
25871 SPARK_Msg_N
("reference to & not allowed", Body_Ref
);
25872 Error_Msg_Sloc
:= Sloc
(State
);
25873 SPARK_Msg_N
("\refinement of & is visible#", Body_Ref
);
25875 Next_Elmt
(Body_Ref_Elmt
);
25879 -- The state name is illegal. This is a syntax error, always report.
25882 Error_Msg_N
("malformed state name in refinement clause", State
);
25886 -- A refinement clause may only refine one state at a time
25888 Extra_State
:= Next
(State
);
25890 if Present
(Extra_State
) then
25892 ("refinement clause cannot cover multiple states", Extra_State
);
25895 -- Replicate the Part_Of constituents of the refined state because
25896 -- the algorithm will consume items.
25898 Part_Of_Constits
:= New_Copy_Elist
(Part_Of_Constituents
(State_Id
));
25900 -- Analyze all constituents of the refinement. Multiple constituents
25901 -- appear as an aggregate.
25903 Constit
:= Expression
(Clause
);
25905 if Nkind
(Constit
) = N_Aggregate
then
25906 if Present
(Component_Associations
(Constit
)) then
25908 ("constituents of refinement clause must appear in "
25909 & "positional form", Constit
);
25911 else pragma Assert
(Present
(Expressions
(Constit
)));
25912 Constit
:= First
(Expressions
(Constit
));
25913 while Present
(Constit
) loop
25914 Analyze_Constituent
(Constit
);
25919 -- Various forms of a single constituent. Note that these may include
25920 -- malformed constituents.
25923 Analyze_Constituent
(Constit
);
25926 -- Verify that external constituents do not introduce new external
25927 -- property in the state refinement (SPARK RM 7.2.8(2)).
25929 if Is_External_State
(State_Id
) then
25930 Check_External_Property
25931 (Prop_Nam
=> Name_Async_Readers
,
25932 Enabled
=> Async_Readers_Enabled
(State_Id
),
25933 Constit
=> AR_Constit
);
25935 Check_External_Property
25936 (Prop_Nam
=> Name_Async_Writers
,
25937 Enabled
=> Async_Writers_Enabled
(State_Id
),
25938 Constit
=> AW_Constit
);
25940 Check_External_Property
25941 (Prop_Nam
=> Name_Effective_Reads
,
25942 Enabled
=> Effective_Reads_Enabled
(State_Id
),
25943 Constit
=> ER_Constit
);
25945 Check_External_Property
25946 (Prop_Nam
=> Name_Effective_Writes
,
25947 Enabled
=> Effective_Writes_Enabled
(State_Id
),
25948 Constit
=> EW_Constit
);
25950 -- When a refined state is not external, it should not have external
25951 -- constituents (SPARK RM 7.2.8(1)).
25953 elsif External_Constit_Seen
then
25955 ("non-external state & cannot contain external constituents in "
25956 & "refinement", State
, State_Id
);
25959 -- Ensure that all Part_Of candidate constituents have been mentioned
25960 -- in the refinement clause.
25962 Report_Unused_Constituents
(Part_Of_Constits
);
25963 end Analyze_Refinement_Clause
;
25965 -----------------------------
25966 -- Report_Unrefined_States --
25967 -----------------------------
25969 procedure Report_Unrefined_States
(States
: Elist_Id
) is
25970 State_Elmt
: Elmt_Id
;
25973 if Present
(States
) then
25974 State_Elmt
:= First_Elmt
(States
);
25975 while Present
(State_Elmt
) loop
25977 ("abstract state & must be refined", Node
(State_Elmt
));
25979 Next_Elmt
(State_Elmt
);
25982 end Report_Unrefined_States
;
25984 -- Local declarations
25986 Clauses
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
25989 -- Start of processing for Analyze_Refined_State_In_Decl_Part
25992 -- Do not analyze the pragma multiple times
25994 if Is_Analyzed_Pragma
(N
) then
25998 -- Replicate the abstract states declared by the package because the
25999 -- matching algorithm will consume states.
26001 Available_States
:= New_Copy_Elist
(Abstract_States
(Spec_Id
));
26003 -- Gather all abstract states and objects declared in the visible
26004 -- state space of the package body. These items must be utilized as
26005 -- constituents in a state refinement.
26007 Body_States
:= Collect_Body_States
(Body_Id
);
26009 -- Multiple non-null state refinements appear as an aggregate
26011 if Nkind
(Clauses
) = N_Aggregate
then
26012 if Present
(Expressions
(Clauses
)) then
26014 ("state refinements must appear as component associations",
26017 else pragma Assert
(Present
(Component_Associations
(Clauses
)));
26018 Clause
:= First
(Component_Associations
(Clauses
));
26019 while Present
(Clause
) loop
26020 Analyze_Refinement_Clause
(Clause
);
26025 -- Various forms of a single state refinement. Note that these may
26026 -- include malformed refinements.
26029 Analyze_Refinement_Clause
(Clauses
);
26032 -- List all abstract states that were left unrefined
26034 Report_Unrefined_States
(Available_States
);
26036 Set_Is_Analyzed_Pragma
(N
);
26037 end Analyze_Refined_State_In_Decl_Part
;
26039 ------------------------------------
26040 -- Analyze_Test_Case_In_Decl_Part --
26041 ------------------------------------
26043 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
) is
26044 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
26045 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
26047 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
);
26048 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
26049 -- denoted by Arg_Nam.
26051 ------------------------------
26052 -- Preanalyze_Test_Case_Arg --
26053 ------------------------------
26055 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
) is
26059 -- Preanalyze the original aspect argument for ASIS or for a generic
26060 -- subprogram to properly capture global references.
26062 if ASIS_Mode
or else Is_Generic_Subprogram
(Spec_Id
) then
26066 Arg_Nam
=> Arg_Nam
,
26067 From_Aspect
=> True);
26069 if Present
(Arg
) then
26070 Preanalyze_Assert_Expression
26071 (Expression
(Arg
), Standard_Boolean
);
26075 Arg
:= Test_Case_Arg
(N
, Arg_Nam
);
26077 if Present
(Arg
) then
26078 Preanalyze_Assert_Expression
(Expression
(Arg
), Standard_Boolean
);
26080 end Preanalyze_Test_Case_Arg
;
26084 Restore_Scope
: Boolean := False;
26086 -- Start of processing for Analyze_Test_Case_In_Decl_Part
26089 -- Do not analyze the pragma multiple times
26091 if Is_Analyzed_Pragma
(N
) then
26095 -- Ensure that the formal parameters are visible when analyzing all
26096 -- clauses. This falls out of the general rule of aspects pertaining
26097 -- to subprogram declarations.
26099 if not In_Open_Scopes
(Spec_Id
) then
26100 Restore_Scope
:= True;
26101 Push_Scope
(Spec_Id
);
26103 if Is_Generic_Subprogram
(Spec_Id
) then
26104 Install_Generic_Formals
(Spec_Id
);
26106 Install_Formals
(Spec_Id
);
26110 Preanalyze_Test_Case_Arg
(Name_Requires
);
26111 Preanalyze_Test_Case_Arg
(Name_Ensures
);
26113 if Restore_Scope
then
26117 -- Currently it is not possible to inline pre/postconditions on a
26118 -- subprogram subject to pragma Inline_Always.
26120 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
26122 Set_Is_Analyzed_Pragma
(N
);
26123 end Analyze_Test_Case_In_Decl_Part
;
26129 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean is
26134 if Present
(List
) then
26135 Elmt
:= First_Elmt
(List
);
26136 while Present
(Elmt
) loop
26137 if Nkind
(Node
(Elmt
)) = N_Defining_Identifier
then
26140 Id
:= Entity_Of
(Node
(Elmt
));
26143 if Id
= Item_Id
then
26154 -----------------------------------
26155 -- Build_Pragma_Check_Equivalent --
26156 -----------------------------------
26158 function Build_Pragma_Check_Equivalent
26160 Subp_Id
: Entity_Id
:= Empty
;
26161 Inher_Id
: Entity_Id
:= Empty
) return Node_Id
26164 -- List containing the following mappings
26165 -- * Formal parameters of inherited subprogram Inher_Id and subprogram
26168 -- * The dispatching type of Inher_Id and the dispatching type of
26171 -- * Primitives of the dispatching type of Inher_Id and primitives of
26172 -- the dispatching type of Subp_Id.
26174 function Replace_Entity
(N
: Node_Id
) return Traverse_Result
;
26175 -- Replace reference to formal of inherited operation or to primitive
26176 -- operation of root type, with corresponding entity for derived type.
26178 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
;
26179 -- Detect whether node N references a formal parameter subject to
26180 -- pragma Unreferenced. If this is the case, set Comes_From_Source
26181 -- to False to suppress the generation of a reference when analyzing
26184 --------------------
26185 -- Replace_Entity --
26186 --------------------
26188 function Replace_Entity
(N
: Node_Id
) return Traverse_Result
is
26193 if Nkind
(N
) = N_Identifier
26194 and then Present
(Entity
(N
))
26196 (Is_Formal
(Entity
(N
)) or else Is_Subprogram
(Entity
(N
)))
26198 (Nkind
(Parent
(N
)) /= N_Attribute_Reference
26199 or else Attribute_Name
(Parent
(N
)) /= Name_Class
)
26201 -- The replacement does not apply to dispatching calls within the
26202 -- condition, but only to calls whose static tag is that of the
26205 if Is_Subprogram
(Entity
(N
))
26206 and then Nkind
(Parent
(N
)) = N_Function_Call
26207 and then Present
(Controlling_Argument
(Parent
(N
)))
26212 -- Loop to find out if entity has a renaming
26215 Elmt
:= First_Elmt
(Map
);
26216 while Present
(Elmt
) loop
26217 if Node
(Elmt
) = Entity
(N
) then
26218 New_E
:= Node
(Next_Elmt
(Elmt
));
26225 if Present
(New_E
) then
26226 Rewrite
(N
, New_Occurrence_Of
(New_E
, Sloc
(N
)));
26229 -- Check that there are no calls left to abstract operations
26230 -- if the current subprogram is not abstract.
26232 if Nkind
(Parent
(N
)) = N_Function_Call
26233 and then N
= Name
(Parent
(N
))
26234 and then not Is_Abstract_Subprogram
(Subp_Id
)
26235 and then Is_Abstract_Subprogram
(Entity
(N
))
26237 Error_Msg_Sloc
:= Sloc
(Current_Scope
);
26239 ("cannot call abstract subprogram in inherited condition "
26240 & "for&#", N
, Current_Scope
);
26243 -- The whole expression will be reanalyzed
26245 elsif Nkind
(N
) in N_Has_Etype
then
26246 Set_Analyzed
(N
, False);
26250 end Replace_Entity
;
26252 ------------------------
26253 -- Suppress_Reference --
26254 ------------------------
26256 function Suppress_Reference
(N
: Node_Id
) return Traverse_Result
is
26257 Formal
: Entity_Id
;
26260 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
26261 Formal
:= Entity
(N
);
26263 -- The formal parameter is subject to pragma Unreferenced.
26264 -- Prevent the generation of a reference by resetting the
26265 -- Comes_From_Source flag.
26267 if Is_Formal
(Formal
)
26268 and then Has_Pragma_Unreferenced
(Formal
)
26270 Set_Comes_From_Source
(N
, False);
26275 end Suppress_Reference
;
26277 procedure Replace_Condition_Entities
is
26278 new Traverse_Proc
(Replace_Entity
);
26280 procedure Suppress_References
is
26281 new Traverse_Proc
(Suppress_Reference
);
26285 Loc
: constant Source_Ptr
:= Sloc
(Prag
);
26286 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
26287 Check_Prag
: Node_Id
;
26288 Inher_Formal
: Entity_Id
;
26291 Subp_Formal
: Entity_Id
;
26293 -- Start of processing for Build_Pragma_Check_Equivalent
26298 -- When the pre- or postcondition is inherited, map the formals of the
26299 -- inherited subprogram to those of the current subprogram. In addition,
26300 -- map primitive operations of the parent type into the corresponding
26301 -- primitive operations of the descendant.
26303 if Present
(Inher_Id
) then
26304 pragma Assert
(Present
(Subp_Id
));
26306 Map
:= New_Elmt_List
;
26308 -- Create a mapping <inherited formal> => <subprogram formal>
26310 Inher_Formal
:= First_Formal
(Inher_Id
);
26311 Subp_Formal
:= First_Formal
(Subp_Id
);
26312 while Present
(Inher_Formal
) and then Present
(Subp_Formal
) loop
26313 Append_Elmt
(Inher_Formal
, Map
);
26314 Append_Elmt
(Subp_Formal
, Map
);
26316 Next_Formal
(Inher_Formal
);
26317 Next_Formal
(Subp_Formal
);
26320 -- Map primitive operations of the parent type to the corresponding
26321 -- operations of the descendant. Note that the descendant type may
26322 -- not be frozen yet, so we cannot use the dispatch table directly.
26324 -- Note : the construction of the map involves a full traversal of
26325 -- the list of primitive operations, as well as a scan of the
26326 -- declarations in the scope of the operation. Given that class-wide
26327 -- conditions are typically short expressions, it might be much more
26328 -- efficient to collect the identifiers in the expression first, and
26329 -- then determine the ones that have to be mapped. Optimization ???
26331 Primitive_Mapping
: declare
26332 function Overridden_Ancestor
(S
: Entity_Id
) return Entity_Id
;
26333 -- Given the controlling type of the overridden operation and a
26334 -- primitive of the current type, find the corresponding operation
26335 -- of the parent type.
26337 -------------------------
26338 -- Overridden_Ancestor --
26339 -------------------------
26341 function Overridden_Ancestor
(S
: Entity_Id
) return Entity_Id
is
26346 while Present
(Overridden_Operation
(Anc
)) loop
26347 exit when Scope
(Anc
) = Scope
(Inher_Id
);
26348 Anc
:= Overridden_Operation
(Anc
);
26352 end Overridden_Ancestor
;
26356 Old_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Inher_Id
);
26357 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Subp_Id
);
26359 Old_Elmt
: Elmt_Id
;
26360 Old_Prim
: Entity_Id
;
26363 -- Start of processing for Primitive_Mapping
26366 Decl
:= First
(List_Containing
(Unit_Declaration_Node
(Subp_Id
)));
26368 -- Look for primitive operations of the current type that have
26369 -- overridden an operation of the type related to the original
26370 -- class-wide precondition. There may be several intermediate
26371 -- overridings between them.
26373 while Present
(Decl
) loop
26374 if Nkind
(Decl
) = N_Subprogram_Declaration
then
26375 Prim
:= Defining_Entity
(Decl
);
26377 if Is_Subprogram
(Prim
)
26378 and then Present
(Overridden_Operation
(Prim
))
26379 and then Find_Dispatching_Type
(Prim
) = Typ
26381 Old_Prim
:= Overridden_Ancestor
(Prim
);
26383 Append_Elmt
(Old_Prim
, Map
);
26384 Append_Elmt
(Prim
, Map
);
26391 -- Now examine inherited operations. These do not override, but
26392 -- have an alias, which is the entity used in a call. In turn
26393 -- that alias may be inherited or comes from source, in which
26394 -- case it may override an earlier operation. We only need to
26395 -- examine inherited functions, that may appear within the
26396 -- inherited expression.
26398 Prim
:= First_Entity
(Scope
(Subp_Id
));
26399 while Present
(Prim
) loop
26400 if not Comes_From_Source
(Prim
)
26401 and then Ekind
(Prim
) = E_Function
26402 and then Present
(Alias
(Prim
))
26404 Old_Prim
:= Alias
(Prim
);
26406 if Comes_From_Source
(Old_Prim
) then
26407 Old_Prim
:= Overridden_Ancestor
(Old_Prim
);
26410 while Present
(Alias
(Old_Prim
))
26411 and then Scope
(Old_Prim
) /= Scope
(Inher_Id
)
26413 Old_Prim
:= Alias
(Old_Prim
);
26415 if Comes_From_Source
(Old_Prim
) then
26416 Old_Prim
:= Overridden_Ancestor
(Old_Prim
);
26422 Append_Elmt
(Old_Prim
, Map
);
26423 Append_Elmt
(Prim
, Map
);
26426 Next_Entity
(Prim
);
26429 -- If the parent operation is an interface operation, the
26430 -- overriding indicator is not present. Instead, we get from
26431 -- the interface operation the primitive of the current type
26432 -- that implements it.
26434 if Is_Interface
(Old_Typ
) then
26435 Old_Elmt
:= First_Elmt
(Collect_Primitive_Operations
(Old_Typ
));
26436 while Present
(Old_Elmt
) loop
26437 Old_Prim
:= Node
(Old_Elmt
);
26438 Prim
:= Find_Primitive_Covering_Interface
(Typ
, Old_Prim
);
26440 if Present
(Prim
) then
26441 Append_Elmt
(Old_Prim
, Map
);
26442 Append_Elmt
(Prim
, Map
);
26445 Next_Elmt
(Old_Elmt
);
26449 if Map
/= No_Elist
then
26450 Append_Elmt
(Old_Typ
, Map
);
26451 Append_Elmt
(Typ
, Map
);
26453 end Primitive_Mapping
;
26456 -- Copy the original pragma while performing substitutions (if
26459 Check_Prag
:= New_Copy_Tree
(Source
=> Prag
);
26461 if Map
/= No_Elist
then
26462 Replace_Condition_Entities
(Check_Prag
);
26465 -- Mark the pragma as being internally generated and reset the Analyzed
26468 Set_Analyzed
(Check_Prag
, False);
26469 Set_Comes_From_Source
(Check_Prag
, False);
26470 Set_Class_Present
(Check_Prag
, False);
26472 -- The tree of the original pragma may contain references to the
26473 -- formal parameters of the related subprogram. At the same time
26474 -- the corresponding body may mark the formals as unreferenced:
26476 -- procedure Proc (Formal : ...)
26477 -- with Pre => Formal ...;
26479 -- procedure Proc (Formal : ...) is
26480 -- pragma Unreferenced (Formal);
26483 -- This creates problems because all pragma Check equivalents are
26484 -- analyzed at the end of the body declarations. Since all source
26485 -- references have already been accounted for, reset any references
26486 -- to such formals in the generated pragma Check equivalent.
26488 Suppress_References
(Check_Prag
);
26490 if Present
(Corresponding_Aspect
(Prag
)) then
26491 Nam
:= Chars
(Identifier
(Corresponding_Aspect
(Prag
)));
26496 -- Convert the copy into pragma Check by correcting the name and adding
26497 -- a check_kind argument.
26499 Set_Pragma_Identifier
26500 (Check_Prag
, Make_Identifier
(Loc
, Name_Check
));
26502 Prepend_To
(Pragma_Argument_Associations
(Check_Prag
),
26503 Make_Pragma_Argument_Association
(Loc
,
26504 Expression
=> Make_Identifier
(Loc
, Nam
)));
26506 -- Update the error message when the pragma is inherited
26508 if Present
(Inher_Id
) then
26509 Msg_Arg
:= Last
(Pragma_Argument_Associations
(Check_Prag
));
26511 if Chars
(Msg_Arg
) = Name_Message
then
26512 String_To_Name_Buffer
(Strval
(Expression
(Msg_Arg
)));
26514 -- Insert "inherited" to improve the error message
26516 if Name_Buffer
(1 .. 8) = "failed p" then
26517 Insert_Str_In_Name_Buffer
("inherited ", 8);
26518 Set_Strval
(Expression
(Msg_Arg
), String_From_Name_Buffer
);
26524 end Build_Pragma_Check_Equivalent
;
26526 -----------------------------
26527 -- Check_Applicable_Policy --
26528 -----------------------------
26530 procedure Check_Applicable_Policy
(N
: Node_Id
) is
26534 Ename
: constant Name_Id
:= Original_Aspect_Pragma_Name
(N
);
26537 -- No effect if not valid assertion kind name
26539 if not Is_Valid_Assertion_Kind
(Ename
) then
26543 -- Loop through entries in check policy list
26545 PP
:= Opt
.Check_Policy_List
;
26546 while Present
(PP
) loop
26548 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
26549 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
26553 or else Pnm
= Name_Assertion
26554 or else (Pnm
= Name_Statement_Assertions
26555 and then Nam_In
(Ename
, Name_Assert
,
26556 Name_Assert_And_Cut
,
26558 Name_Loop_Invariant
,
26559 Name_Loop_Variant
))
26561 Policy
:= Chars
(Get_Pragma_Arg
(Last
(PPA
)));
26564 when Name_Off | Name_Ignore
=>
26565 Set_Is_Ignored
(N
, True);
26566 Set_Is_Checked
(N
, False);
26568 when Name_On | Name_Check
=>
26569 Set_Is_Checked
(N
, True);
26570 Set_Is_Ignored
(N
, False);
26572 when Name_Disable
=>
26573 Set_Is_Ignored
(N
, True);
26574 Set_Is_Checked
(N
, False);
26575 Set_Is_Disabled
(N
, True);
26577 -- That should be exhaustive, the null here is a defence
26578 -- against a malformed tree from previous errors.
26587 PP
:= Next_Pragma
(PP
);
26591 -- If there are no specific entries that matched, then we let the
26592 -- setting of assertions govern. Note that this provides the needed
26593 -- compatibility with the RM for the cases of assertion, invariant,
26594 -- precondition, predicate, and postcondition.
26596 if Assertions_Enabled
then
26597 Set_Is_Checked
(N
, True);
26598 Set_Is_Ignored
(N
, False);
26600 Set_Is_Checked
(N
, False);
26601 Set_Is_Ignored
(N
, True);
26603 end Check_Applicable_Policy
;
26605 -------------------------------
26606 -- Check_External_Properties --
26607 -------------------------------
26609 procedure Check_External_Properties
26617 -- All properties enabled
26619 if AR
and AW
and ER
and EW
then
26622 -- Async_Readers + Effective_Writes
26623 -- Async_Readers + Async_Writers + Effective_Writes
26625 elsif AR
and EW
and not ER
then
26628 -- Async_Writers + Effective_Reads
26629 -- Async_Readers + Async_Writers + Effective_Reads
26631 elsif AW
and ER
and not EW
then
26634 -- Async_Readers + Async_Writers
26636 elsif AR
and AW
and not ER
and not EW
then
26641 elsif AR
and not AW
and not ER
and not EW
then
26646 elsif AW
and not AR
and not ER
and not EW
then
26651 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
26654 end Check_External_Properties
;
26660 function Check_Kind
(Nam
: Name_Id
) return Name_Id
is
26664 -- Loop through entries in check policy list
26666 PP
:= Opt
.Check_Policy_List
;
26667 while Present
(PP
) loop
26669 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
26670 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
26674 or else (Pnm
= Name_Assertion
26675 and then Is_Valid_Assertion_Kind
(Nam
))
26676 or else (Pnm
= Name_Statement_Assertions
26677 and then Nam_In
(Nam
, Name_Assert
,
26678 Name_Assert_And_Cut
,
26680 Name_Loop_Invariant
,
26681 Name_Loop_Variant
))
26683 case (Chars
(Get_Pragma_Arg
(Last
(PPA
)))) is
26684 when Name_On | Name_Check
=>
26686 when Name_Off | Name_Ignore
=>
26687 return Name_Ignore
;
26688 when Name_Disable
=>
26689 return Name_Disable
;
26691 raise Program_Error
;
26695 PP
:= Next_Pragma
(PP
);
26700 -- If there are no specific entries that matched, then we let the
26701 -- setting of assertions govern. Note that this provides the needed
26702 -- compatibility with the RM for the cases of assertion, invariant,
26703 -- precondition, predicate, and postcondition.
26705 if Assertions_Enabled
then
26708 return Name_Ignore
;
26712 ---------------------------
26713 -- Check_Missing_Part_Of --
26714 ---------------------------
26716 procedure Check_Missing_Part_Of
(Item_Id
: Entity_Id
) is
26717 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean;
26718 -- Determine whether a package denoted by Pack_Id declares at least one
26721 -----------------------
26722 -- Has_Visible_State --
26723 -----------------------
26725 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean is
26726 Item_Id
: Entity_Id
;
26729 -- Traverse the entity chain of the package trying to find at least
26730 -- one visible abstract state, variable or a package [instantiation]
26731 -- that declares a visible state.
26733 Item_Id
:= First_Entity
(Pack_Id
);
26734 while Present
(Item_Id
)
26735 and then not In_Private_Part
(Item_Id
)
26737 -- Do not consider internally generated items
26739 if not Comes_From_Source
(Item_Id
) then
26742 -- A visible state has been found
26744 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
26747 -- Recursively peek into nested packages and instantiations
26749 elsif Ekind
(Item_Id
) = E_Package
26750 and then Has_Visible_State
(Item_Id
)
26755 Next_Entity
(Item_Id
);
26759 end Has_Visible_State
;
26763 Pack_Id
: Entity_Id
;
26764 Placement
: State_Space_Kind
;
26766 -- Start of processing for Check_Missing_Part_Of
26769 -- Do not consider abstract states, variables or package instantiations
26770 -- coming from an instance as those always inherit the Part_Of indicator
26771 -- of the instance itself.
26773 if In_Instance
then
26776 -- Do not consider internally generated entities as these can never
26777 -- have a Part_Of indicator.
26779 elsif not Comes_From_Source
(Item_Id
) then
26782 -- Perform these checks only when SPARK_Mode is enabled as they will
26783 -- interfere with standard Ada rules and produce false positives.
26785 elsif SPARK_Mode
/= On
then
26788 -- Do not consider constants, because the compiler cannot accurately
26789 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
26790 -- act as a hidden state of a package.
26792 elsif Ekind
(Item_Id
) = E_Constant
then
26796 -- Find where the abstract state, variable or package instantiation
26797 -- lives with respect to the state space.
26799 Find_Placement_In_State_Space
26800 (Item_Id
=> Item_Id
,
26801 Placement
=> Placement
,
26802 Pack_Id
=> Pack_Id
);
26804 -- Items that appear in a non-package construct (subprogram, block, etc)
26805 -- do not require a Part_Of indicator because they can never act as a
26808 if Placement
= Not_In_Package
then
26811 -- An item declared in the body state space of a package always act as a
26812 -- constituent and does not need explicit Part_Of indicator.
26814 elsif Placement
= Body_State_Space
then
26817 -- In general an item declared in the visible state space of a package
26818 -- does not require a Part_Of indicator. The only exception is when the
26819 -- related package is a private child unit in which case Part_Of must
26820 -- denote a state in the parent unit or in one of its descendants.
26822 elsif Placement
= Visible_State_Space
then
26823 if Is_Child_Unit
(Pack_Id
)
26824 and then Is_Private_Descendant
(Pack_Id
)
26826 -- A package instantiation does not need a Part_Of indicator when
26827 -- the related generic template has no visible state.
26829 if Ekind
(Item_Id
) = E_Package
26830 and then Is_Generic_Instance
(Item_Id
)
26831 and then not Has_Visible_State
(Item_Id
)
26835 -- All other cases require Part_Of
26839 ("indicator Part_Of is required in this context "
26840 & "(SPARK RM 7.2.6(3))", Item_Id
);
26841 Error_Msg_Name_1
:= Chars
(Pack_Id
);
26843 ("\& is declared in the visible part of private child "
26844 & "unit %", Item_Id
);
26848 -- When the item appears in the private state space of a packge, it must
26849 -- be a part of some state declared by the said package.
26851 else pragma Assert
(Placement
= Private_State_Space
);
26853 -- The related package does not declare a state, the item cannot act
26854 -- as a Part_Of constituent.
26856 if No
(Get_Pragma
(Pack_Id
, Pragma_Abstract_State
)) then
26859 -- A package instantiation does not need a Part_Of indicator when the
26860 -- related generic template has no visible state.
26862 elsif Ekind
(Pack_Id
) = E_Package
26863 and then Is_Generic_Instance
(Pack_Id
)
26864 and then not Has_Visible_State
(Pack_Id
)
26868 -- All other cases require Part_Of
26872 ("indicator Part_Of is required in this context "
26873 & "(SPARK RM 7.2.6(2))", Item_Id
);
26874 Error_Msg_Name_1
:= Chars
(Pack_Id
);
26876 ("\& is declared in the private part of package %", Item_Id
);
26879 end Check_Missing_Part_Of
;
26881 ---------------------------------------------------
26882 -- Check_Postcondition_Use_In_Inlined_Subprogram --
26883 ---------------------------------------------------
26885 procedure Check_Postcondition_Use_In_Inlined_Subprogram
26887 Spec_Id
: Entity_Id
)
26890 if Warn_On_Redundant_Constructs
26891 and then Has_Pragma_Inline_Always
(Spec_Id
)
26893 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
26895 if From_Aspect_Specification
(Prag
) then
26897 ("aspect % not enforced on inlined subprogram &?r?",
26898 Corresponding_Aspect
(Prag
), Spec_Id
);
26901 ("pragma % not enforced on inlined subprogram &?r?",
26905 end Check_Postcondition_Use_In_Inlined_Subprogram
;
26907 -------------------------------------
26908 -- Check_State_And_Constituent_Use --
26909 -------------------------------------
26911 procedure Check_State_And_Constituent_Use
26912 (States
: Elist_Id
;
26913 Constits
: Elist_Id
;
26916 function Find_Encapsulating_State
26917 (Constit_Id
: Entity_Id
) return Entity_Id
;
26918 -- Given the entity of a constituent, try to find a corresponding
26919 -- encapsulating state that appears in the same context. The routine
26920 -- returns Empty is no such state is found.
26922 ------------------------------
26923 -- Find_Encapsulating_State --
26924 ------------------------------
26926 function Find_Encapsulating_State
26927 (Constit_Id
: Entity_Id
) return Entity_Id
26929 State_Id
: Entity_Id
;
26932 -- Since a constituent may be part of a larger constituent set, climb
26933 -- the encapsulating state chain looking for a state that appears in
26934 -- the same context.
26936 State_Id
:= Encapsulating_State
(Constit_Id
);
26937 while Present
(State_Id
) loop
26938 if Contains
(States
, State_Id
) then
26942 State_Id
:= Encapsulating_State
(State_Id
);
26946 end Find_Encapsulating_State
;
26950 Constit_Elmt
: Elmt_Id
;
26951 Constit_Id
: Entity_Id
;
26952 State_Id
: Entity_Id
;
26954 -- Start of processing for Check_State_And_Constituent_Use
26957 -- Nothing to do if there are no states or constituents
26959 if No
(States
) or else No
(Constits
) then
26963 -- Inspect the list of constituents and try to determine whether its
26964 -- encapsulating state is in list States.
26966 Constit_Elmt
:= First_Elmt
(Constits
);
26967 while Present
(Constit_Elmt
) loop
26968 Constit_Id
:= Node
(Constit_Elmt
);
26970 -- Determine whether the constituent is part of an encapsulating
26971 -- state that appears in the same context and if this is the case,
26972 -- emit an error (SPARK RM 7.2.6(7)).
26974 State_Id
:= Find_Encapsulating_State
(Constit_Id
);
26976 if Present
(State_Id
) then
26977 Error_Msg_Name_1
:= Chars
(Constit_Id
);
26979 ("cannot mention state & and its constituent % in the same "
26980 & "context", Context
, State_Id
);
26984 Next_Elmt
(Constit_Elmt
);
26986 end Check_State_And_Constituent_Use
;
26988 ---------------------------------------------
26989 -- Collect_Inherited_Class_Wide_Conditions --
26990 ---------------------------------------------
26992 procedure Collect_Inherited_Class_Wide_Conditions
(Subp
: Entity_Id
) is
26993 Parent_Subp
: constant Entity_Id
:= Overridden_Operation
(Subp
);
26994 Prags
: constant Node_Id
:= Contract
(Parent_Subp
);
26995 In_Spec_Expr
: Boolean;
26996 Installed
: Boolean;
26998 New_Prag
: Node_Id
;
27001 Installed
:= False;
27003 -- Iterate over the contract of the overridden subprogram to find all
27004 -- inherited class-wide pre- and postconditions.
27006 if Present
(Prags
) then
27007 Prag
:= Pre_Post_Conditions
(Prags
);
27009 while Present
(Prag
) loop
27010 if Nam_In
(Pragma_Name
(Prag
), Name_Precondition
,
27011 Name_Postcondition
)
27012 and then Class_Present
(Prag
)
27014 -- The generated pragma must be analyzed in the context of
27015 -- the subprogram, to make its formals visible. In addition,
27016 -- we must inhibit freezing and full analysis because the
27017 -- controlling type of the subprogram is not frozen yet, and
27018 -- may have further primitives.
27020 if not Installed
then
27023 Install_Formals
(Subp
);
27024 In_Spec_Expr
:= In_Spec_Expression
;
27025 In_Spec_Expression
:= True;
27029 Build_Pragma_Check_Equivalent
(Prag
, Subp
, Parent_Subp
);
27030 Insert_After
(Unit_Declaration_Node
(Subp
), New_Prag
);
27031 Preanalyze
(New_Prag
);
27033 -- Prevent further analysis in subsequent processing of the
27034 -- current list of declarations
27036 Set_Analyzed
(New_Prag
);
27039 Prag
:= Next_Pragma
(Prag
);
27043 In_Spec_Expression
:= In_Spec_Expr
;
27047 end Collect_Inherited_Class_Wide_Conditions
;
27049 ---------------------------------------
27050 -- Collect_Subprogram_Inputs_Outputs --
27051 ---------------------------------------
27053 procedure Collect_Subprogram_Inputs_Outputs
27054 (Subp_Id
: Entity_Id
;
27055 Synthesize
: Boolean := False;
27056 Subp_Inputs
: in out Elist_Id
;
27057 Subp_Outputs
: in out Elist_Id
;
27058 Global_Seen
: out Boolean)
27060 procedure Collect_Dependency_Clause
(Clause
: Node_Id
);
27061 -- Collect all relevant items from a dependency clause
27063 procedure Collect_Global_List
27065 Mode
: Name_Id
:= Name_Input
);
27066 -- Collect all relevant items from a global list
27068 -------------------------------
27069 -- Collect_Dependency_Clause --
27070 -------------------------------
27072 procedure Collect_Dependency_Clause
(Clause
: Node_Id
) is
27073 procedure Collect_Dependency_Item
27075 Is_Input
: Boolean);
27076 -- Add an item to the proper subprogram input or output collection
27078 -----------------------------
27079 -- Collect_Dependency_Item --
27080 -----------------------------
27082 procedure Collect_Dependency_Item
27084 Is_Input
: Boolean)
27089 -- Nothing to collect when the item is null
27091 if Nkind
(Item
) = N_Null
then
27094 -- Ditto for attribute 'Result
27096 elsif Is_Attribute_Result
(Item
) then
27099 -- Multiple items appear as an aggregate
27101 elsif Nkind
(Item
) = N_Aggregate
then
27102 Extra
:= First
(Expressions
(Item
));
27103 while Present
(Extra
) loop
27104 Collect_Dependency_Item
(Extra
, Is_Input
);
27108 -- Otherwise this is a solitary item
27112 Append_New_Elmt
(Item
, Subp_Inputs
);
27114 Append_New_Elmt
(Item
, Subp_Outputs
);
27117 end Collect_Dependency_Item
;
27119 -- Start of processing for Collect_Dependency_Clause
27122 if Nkind
(Clause
) = N_Null
then
27125 -- A dependency cause appears as component association
27127 elsif Nkind
(Clause
) = N_Component_Association
then
27128 Collect_Dependency_Item
27129 (Item
=> Expression
(Clause
),
27132 Collect_Dependency_Item
27133 (Item
=> First
(Choices
(Clause
)),
27134 Is_Input
=> False);
27136 -- To accomodate partial decoration of disabled SPARK features, this
27137 -- routine may be called with illegal input. If this is the case, do
27138 -- not raise Program_Error.
27143 end Collect_Dependency_Clause
;
27145 -------------------------
27146 -- Collect_Global_List --
27147 -------------------------
27149 procedure Collect_Global_List
27151 Mode
: Name_Id
:= Name_Input
)
27153 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
27154 -- Add an item to the proper subprogram input or output collection
27156 -------------------------
27157 -- Collect_Global_Item --
27158 -------------------------
27160 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
27162 if Nam_In
(Mode
, Name_In_Out
, Name_Input
) then
27163 Append_New_Elmt
(Item
, Subp_Inputs
);
27166 if Nam_In
(Mode
, Name_In_Out
, Name_Output
) then
27167 Append_New_Elmt
(Item
, Subp_Outputs
);
27169 end Collect_Global_Item
;
27176 -- Start of processing for Collect_Global_List
27179 if Nkind
(List
) = N_Null
then
27182 -- Single global item declaration
27184 elsif Nkind_In
(List
, N_Expanded_Name
,
27186 N_Selected_Component
)
27188 Collect_Global_Item
(List
, Mode
);
27190 -- Simple global list or moded global list declaration
27192 elsif Nkind
(List
) = N_Aggregate
then
27193 if Present
(Expressions
(List
)) then
27194 Item
:= First
(Expressions
(List
));
27195 while Present
(Item
) loop
27196 Collect_Global_Item
(Item
, Mode
);
27201 Assoc
:= First
(Component_Associations
(List
));
27202 while Present
(Assoc
) loop
27203 Collect_Global_List
27204 (List
=> Expression
(Assoc
),
27205 Mode
=> Chars
(First
(Choices
(Assoc
))));
27210 -- To accomodate partial decoration of disabled SPARK features, this
27211 -- routine may be called with illegal input. If this is the case, do
27212 -- not raise Program_Error.
27217 end Collect_Global_List
;
27224 Formal
: Entity_Id
;
27226 Spec_Id
: Entity_Id
;
27227 Subp_Decl
: Node_Id
;
27230 -- Start of processing for Collect_Subprogram_Inputs_Outputs
27233 Global_Seen
:= False;
27235 -- Process all formal parameters of entries, [generic] subprograms, and
27238 if Ekind_In
(Subp_Id
, E_Entry
,
27241 E_Generic_Function
,
27242 E_Generic_Procedure
,
27246 Subp_Decl
:= Unit_Declaration_Node
(Subp_Id
);
27247 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
27249 -- Process all [generic] formal parameters
27251 Formal
:= First_Entity
(Spec_Id
);
27252 while Present
(Formal
) loop
27253 if Ekind_In
(Formal
, E_Generic_In_Parameter
,
27254 E_In_Out_Parameter
,
27257 Append_New_Elmt
(Formal
, Subp_Inputs
);
27260 if Ekind_In
(Formal
, E_Generic_In_Out_Parameter
,
27261 E_In_Out_Parameter
,
27264 Append_New_Elmt
(Formal
, Subp_Outputs
);
27266 -- Out parameters can act as inputs when the related type is
27267 -- tagged, unconstrained array, unconstrained record, or record
27268 -- with unconstrained components.
27270 if Ekind
(Formal
) = E_Out_Parameter
27271 and then Is_Unconstrained_Or_Tagged_Item
(Formal
)
27273 Append_New_Elmt
(Formal
, Subp_Inputs
);
27277 Next_Entity
(Formal
);
27280 -- Otherwise the input denotes a task type, a task body, or the
27281 -- anonymous object created for a single task type.
27283 elsif Ekind_In
(Subp_Id
, E_Task_Type
, E_Task_Body
)
27284 or else Is_Single_Task_Object
(Subp_Id
)
27286 Subp_Decl
:= Declaration_Node
(Subp_Id
);
27287 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
27290 -- When processing an entry, subprogram or task body, look for pragmas
27291 -- Refined_Depends and Refined_Global as they specify the inputs and
27294 if Is_Entry_Body
(Subp_Id
)
27295 or else Ekind_In
(Subp_Id
, E_Subprogram_Body
, E_Task_Body
)
27297 Depends
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Depends
);
27298 Global
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Global
);
27300 -- Subprogram declaration or stand alone body case, look for pragmas
27301 -- Depends and Global
27304 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
27305 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
27308 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
27309 -- because it provides finer granularity of inputs and outputs.
27311 if Present
(Global
) then
27312 Global_Seen
:= True;
27313 Collect_Global_List
(Expression
(Get_Argument
(Global
, Spec_Id
)));
27315 -- When the related subprogram lacks pragma [Refined_]Global, fall back
27316 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
27317 -- the inputs and outputs from [Refined_]Depends.
27319 elsif Synthesize
and then Present
(Depends
) then
27320 Clauses
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
27322 -- Multiple dependency clauses appear as an aggregate
27324 if Nkind
(Clauses
) = N_Aggregate
then
27325 Clause
:= First
(Component_Associations
(Clauses
));
27326 while Present
(Clause
) loop
27327 Collect_Dependency_Clause
(Clause
);
27331 -- Otherwise this is a single dependency clause
27334 Collect_Dependency_Clause
(Clauses
);
27338 -- The current instance of a protected type acts as a formal parameter
27339 -- of mode IN for functions and IN OUT for entries and procedures
27340 -- (SPARK RM 6.1.4).
27342 if Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
27343 Typ
:= Scope
(Spec_Id
);
27345 -- Use the anonymous object when the type is single protected
27347 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
27348 Typ
:= Anonymous_Object
(Typ
);
27351 Append_New_Elmt
(Typ
, Subp_Inputs
);
27353 if Ekind_In
(Spec_Id
, E_Entry
, E_Entry_Family
, E_Procedure
) then
27354 Append_New_Elmt
(Typ
, Subp_Outputs
);
27357 -- The current instance of a task type acts as a formal parameter of
27358 -- mode IN OUT (SPARK RM 6.1.4).
27360 elsif Ekind
(Spec_Id
) = E_Task_Type
then
27363 -- Use the anonymous object when the type is single task
27365 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
27366 Typ
:= Anonymous_Object
(Typ
);
27369 Append_New_Elmt
(Typ
, Subp_Inputs
);
27370 Append_New_Elmt
(Typ
, Subp_Outputs
);
27372 elsif Is_Single_Task_Object
(Spec_Id
) then
27373 Append_New_Elmt
(Spec_Id
, Subp_Inputs
);
27374 Append_New_Elmt
(Spec_Id
, Subp_Outputs
);
27376 end Collect_Subprogram_Inputs_Outputs
;
27378 ---------------------------
27379 -- Contract_Freeze_Error --
27380 ---------------------------
27382 procedure Contract_Freeze_Error
27383 (Contract_Id
: Entity_Id
;
27384 Freeze_Id
: Entity_Id
)
27387 Error_Msg_Name_1
:= Chars
(Contract_Id
);
27388 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
27391 ("body & declared # freezes the contract of%", Contract_Id
, Freeze_Id
);
27393 ("\all contractual items must be declared before body #", Contract_Id
);
27394 end Contract_Freeze_Error
;
27396 ---------------------------------
27397 -- Delay_Config_Pragma_Analyze --
27398 ---------------------------------
27400 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean is
27402 return Nam_In
(Pragma_Name
(N
), Name_Interrupt_State
,
27403 Name_Priority_Specific_Dispatching
);
27404 end Delay_Config_Pragma_Analyze
;
27406 -----------------------
27407 -- Duplication_Error --
27408 -----------------------
27410 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
) is
27411 Prag_From_Asp
: constant Boolean := From_Aspect_Specification
(Prag
);
27412 Prev_From_Asp
: constant Boolean := From_Aspect_Specification
(Prev
);
27415 Error_Msg_Sloc
:= Sloc
(Prev
);
27416 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
27418 -- Emit a precise message to distinguish between source pragmas and
27419 -- pragmas generated from aspects. The ordering of the two pragmas is
27423 -- Prag -- duplicate
27425 -- No error is emitted when both pragmas come from aspects because this
27426 -- is already detected by the general aspect analysis mechanism.
27428 if Prag_From_Asp
and Prev_From_Asp
then
27430 elsif Prag_From_Asp
then
27431 Error_Msg_N
("aspect % duplicates pragma declared #", Prag
);
27432 elsif Prev_From_Asp
then
27433 Error_Msg_N
("pragma % duplicates aspect declared #", Prag
);
27435 Error_Msg_N
("pragma % duplicates pragma declared #", Prag
);
27437 end Duplication_Error
;
27439 --------------------------
27440 -- Find_Related_Context --
27441 --------------------------
27443 function Find_Related_Context
27445 Do_Checks
: Boolean := False) return Node_Id
27450 Stmt
:= Prev
(Prag
);
27451 while Present
(Stmt
) loop
27453 -- Skip prior pragmas, but check for duplicates
27455 if Nkind
(Stmt
) = N_Pragma
then
27456 if Do_Checks
and then Pragma_Name
(Stmt
) = Pragma_Name
(Prag
) then
27462 -- Skip internally generated code
27464 elsif not Comes_From_Source
(Stmt
) then
27466 -- The anonymous object created for a single concurrent type is a
27467 -- suitable context.
27469 if Nkind
(Stmt
) = N_Object_Declaration
27470 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
27475 -- Return the current source construct
27485 end Find_Related_Context
;
27487 --------------------------------------
27488 -- Find_Related_Declaration_Or_Body --
27489 --------------------------------------
27491 function Find_Related_Declaration_Or_Body
27493 Do_Checks
: Boolean := False) return Node_Id
27495 Prag_Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
27497 procedure Expression_Function_Error
;
27498 -- Emit an error concerning pragma Prag that illegaly applies to an
27499 -- expression function.
27501 -------------------------------
27502 -- Expression_Function_Error --
27503 -------------------------------
27505 procedure Expression_Function_Error
is
27507 Error_Msg_Name_1
:= Prag_Nam
;
27509 -- Emit a precise message to distinguish between source pragmas and
27510 -- pragmas generated from aspects.
27512 if From_Aspect_Specification
(Prag
) then
27514 ("aspect % cannot apply to a stand alone expression function",
27518 ("pragma % cannot apply to a stand alone expression function",
27521 end Expression_Function_Error
;
27525 Context
: constant Node_Id
:= Parent
(Prag
);
27528 Look_For_Body
: constant Boolean :=
27529 Nam_In
(Prag_Nam
, Name_Refined_Depends
,
27530 Name_Refined_Global
,
27531 Name_Refined_Post
);
27532 -- Refinement pragmas must be associated with a subprogram body [stub]
27534 -- Start of processing for Find_Related_Declaration_Or_Body
27537 Stmt
:= Prev
(Prag
);
27538 while Present
(Stmt
) loop
27540 -- Skip prior pragmas, but check for duplicates. Pragmas produced
27541 -- by splitting a complex pre/postcondition are not considered to
27544 if Nkind
(Stmt
) = N_Pragma
then
27546 and then not Split_PPC
(Stmt
)
27547 and then Original_Aspect_Pragma_Name
(Stmt
) = Prag_Nam
27554 -- Emit an error when a refinement pragma appears on an expression
27555 -- function without a completion.
27558 and then Look_For_Body
27559 and then Nkind
(Stmt
) = N_Subprogram_Declaration
27560 and then Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
27561 and then not Has_Completion
(Defining_Entity
(Stmt
))
27563 Expression_Function_Error
;
27566 -- The refinement pragma applies to a subprogram body stub
27568 elsif Look_For_Body
27569 and then Nkind
(Stmt
) = N_Subprogram_Body_Stub
27573 -- Skip internally generated code
27575 elsif not Comes_From_Source
(Stmt
) then
27577 -- The anonymous object created for a single concurrent type is a
27578 -- suitable context.
27580 if Nkind
(Stmt
) = N_Object_Declaration
27581 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
27585 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
then
27587 -- The subprogram declaration is an internally generated spec
27588 -- for an expression function.
27590 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
27593 -- The subprogram is actually an instance housed within an
27594 -- anonymous wrapper package.
27596 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
27601 -- Return the current construct which is either a subprogram body,
27602 -- a subprogram declaration or is illegal.
27611 -- If we fall through, then the pragma was either the first declaration
27612 -- or it was preceded by other pragmas and no source constructs.
27614 -- The pragma is associated with a library-level subprogram
27616 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
27617 return Unit
(Parent
(Context
));
27619 -- The pragma appears inside the declarations of an entry body
27621 elsif Nkind
(Context
) = N_Entry_Body
then
27624 -- The pragma appears inside the statements of a subprogram body. This
27625 -- placement is the result of subprogram contract expansion.
27627 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
then
27628 return Parent
(Context
);
27630 -- The pragma appears inside the declarative part of a subprogram body
27632 elsif Nkind
(Context
) = N_Subprogram_Body
then
27635 -- The pragma appears inside the declarative part of a task body
27637 elsif Nkind
(Context
) = N_Task_Body
then
27640 -- The pragma is a byproduct of aspect expansion, return the related
27641 -- context of the original aspect. This case has a lower priority as
27642 -- the above circuitry pinpoints precisely the related context.
27644 elsif Present
(Corresponding_Aspect
(Prag
)) then
27645 return Parent
(Corresponding_Aspect
(Prag
));
27647 -- No candidate subprogram [body] found
27652 end Find_Related_Declaration_Or_Body
;
27654 ----------------------------------
27655 -- Find_Related_Package_Or_Body --
27656 ----------------------------------
27658 function Find_Related_Package_Or_Body
27660 Do_Checks
: Boolean := False) return Node_Id
27662 Context
: constant Node_Id
:= Parent
(Prag
);
27663 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
27667 Stmt
:= Prev
(Prag
);
27668 while Present
(Stmt
) loop
27670 -- Skip prior pragmas, but check for duplicates
27672 if Nkind
(Stmt
) = N_Pragma
then
27673 if Do_Checks
and then Pragma_Name
(Stmt
) = Prag_Nam
then
27679 -- Skip internally generated code
27681 elsif not Comes_From_Source
(Stmt
) then
27682 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
27684 -- The subprogram declaration is an internally generated spec
27685 -- for an expression function.
27687 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
27690 -- The subprogram is actually an instance housed within an
27691 -- anonymous wrapper package.
27693 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
27698 -- Return the current source construct which is illegal
27707 -- If we fall through, then the pragma was either the first declaration
27708 -- or it was preceded by other pragmas and no source constructs.
27710 -- The pragma is associated with a package. The immediate context in
27711 -- this case is the specification of the package.
27713 if Nkind
(Context
) = N_Package_Specification
then
27714 return Parent
(Context
);
27716 -- The pragma appears in the declarations of a package body
27718 elsif Nkind
(Context
) = N_Package_Body
then
27721 -- The pragma appears in the statements of a package body
27723 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
27724 and then Nkind
(Parent
(Context
)) = N_Package_Body
27726 return Parent
(Context
);
27728 -- The pragma is a byproduct of aspect expansion, return the related
27729 -- context of the original aspect. This case has a lower priority as
27730 -- the above circuitry pinpoints precisely the related context.
27732 elsif Present
(Corresponding_Aspect
(Prag
)) then
27733 return Parent
(Corresponding_Aspect
(Prag
));
27735 -- No candidate packge [body] found
27740 end Find_Related_Package_Or_Body
;
27746 function Get_Argument
27748 Context_Id
: Entity_Id
:= Empty
) return Node_Id
27750 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
27753 -- Use the expression of the original aspect when compiling for ASIS or
27754 -- when analyzing the template of a generic unit. In both cases the
27755 -- aspect's tree must be decorated to allow for ASIS queries or to save
27756 -- the global references in the generic context.
27758 if From_Aspect_Specification
(Prag
)
27759 and then (ASIS_Mode
or else (Present
(Context_Id
)
27760 and then Is_Generic_Unit
(Context_Id
)))
27762 return Corresponding_Aspect
(Prag
);
27764 -- Otherwise use the expression of the pragma
27766 elsif Present
(Args
) then
27767 return First
(Args
);
27774 -------------------------
27775 -- Get_Base_Subprogram --
27776 -------------------------
27778 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
is
27779 Result
: Entity_Id
;
27782 -- Follow subprogram renaming chain
27786 if Is_Subprogram
(Result
)
27788 Nkind
(Parent
(Declaration_Node
(Result
))) =
27789 N_Subprogram_Renaming_Declaration
27790 and then Present
(Alias
(Result
))
27792 Result
:= Alias
(Result
);
27796 end Get_Base_Subprogram
;
27798 -----------------------
27799 -- Get_SPARK_Mode_Type --
27800 -----------------------
27802 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
is
27804 if N
= Name_On
then
27806 elsif N
= Name_Off
then
27809 -- Any other argument is illegal
27812 raise Program_Error
;
27814 end Get_SPARK_Mode_Type
;
27816 ------------------------------------
27817 -- Get_SPARK_Mode_From_Annotation --
27818 ------------------------------------
27820 function Get_SPARK_Mode_From_Annotation
27821 (N
: Node_Id
) return SPARK_Mode_Type
27826 if Nkind
(N
) = N_Aspect_Specification
then
27827 Mode
:= Expression
(N
);
27829 else pragma Assert
(Nkind
(N
) = N_Pragma
);
27830 Mode
:= First
(Pragma_Argument_Associations
(N
));
27832 if Present
(Mode
) then
27833 Mode
:= Get_Pragma_Arg
(Mode
);
27837 -- Aspect or pragma SPARK_Mode specifies an explicit mode
27839 if Present
(Mode
) then
27840 if Nkind
(Mode
) = N_Identifier
then
27841 return Get_SPARK_Mode_Type
(Chars
(Mode
));
27843 -- In case of a malformed aspect or pragma, return the default None
27849 -- Otherwise the lack of an expression defaults SPARK_Mode to On
27854 end Get_SPARK_Mode_From_Annotation
;
27856 ---------------------------
27857 -- Has_Extra_Parentheses --
27858 ---------------------------
27860 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean is
27864 -- The aggregate should not have an expression list because a clause
27865 -- is always interpreted as a component association. The only way an
27866 -- expression list can sneak in is by adding extra parentheses around
27867 -- the individual clauses:
27869 -- Depends (Output => Input) -- proper form
27870 -- Depends ((Output => Input)) -- extra parentheses
27872 -- Since the extra parentheses are not allowed by the syntax of the
27873 -- pragma, flag them now to avoid emitting misleading errors down the
27876 if Nkind
(Clause
) = N_Aggregate
27877 and then Present
(Expressions
(Clause
))
27879 Expr
:= First
(Expressions
(Clause
));
27880 while Present
(Expr
) loop
27882 -- A dependency clause surrounded by extra parentheses appears
27883 -- as an aggregate of component associations with an optional
27884 -- Paren_Count set.
27886 if Nkind
(Expr
) = N_Aggregate
27887 and then Present
(Component_Associations
(Expr
))
27890 ("dependency clause contains extra parentheses", Expr
);
27892 -- Otherwise the expression is a malformed construct
27895 SPARK_Msg_N
("malformed dependency clause", Expr
);
27905 end Has_Extra_Parentheses
;
27911 procedure Initialize
is
27922 Dummy
:= Dummy
+ 1;
27925 -----------------------------
27926 -- Is_Config_Static_String --
27927 -----------------------------
27929 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean is
27931 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean;
27932 -- This is an internal recursive function that is just like the outer
27933 -- function except that it adds the string to the name buffer rather
27934 -- than placing the string in the name buffer.
27936 ------------------------------
27937 -- Add_Config_Static_String --
27938 ------------------------------
27940 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean is
27947 if Nkind
(N
) = N_Op_Concat
then
27948 if Add_Config_Static_String
(Left_Opnd
(N
)) then
27949 N
:= Right_Opnd
(N
);
27955 if Nkind
(N
) /= N_String_Literal
then
27956 Error_Msg_N
("string literal expected for pragma argument", N
);
27960 for J
in 1 .. String_Length
(Strval
(N
)) loop
27961 C
:= Get_String_Char
(Strval
(N
), J
);
27963 if not In_Character_Range
(C
) then
27965 ("string literal contains invalid wide character",
27966 Sloc
(N
) + 1 + Source_Ptr
(J
));
27970 Add_Char_To_Name_Buffer
(Get_Character
(C
));
27975 end Add_Config_Static_String
;
27977 -- Start of processing for Is_Config_Static_String
27982 return Add_Config_Static_String
(Arg
);
27983 end Is_Config_Static_String
;
27985 ---------------------
27986 -- Is_CCT_Instance --
27987 ---------------------
27989 function Is_CCT_Instance
27990 (Ref_Id
: Entity_Id
;
27991 Context_Id
: Entity_Id
) return Boolean
27997 -- When the reference denotes a single protected type, the context is
27998 -- either a protected subprogram or its body.
28000 if Is_Single_Protected_Object
(Ref_Id
) then
28001 Typ
:= Scope
(Context_Id
);
28004 Ekind
(Typ
) = E_Protected_Type
28005 and then Present
(Anonymous_Object
(Typ
))
28006 and then Anonymous_Object
(Typ
) = Ref_Id
;
28008 -- When the reference denotes a single task type, the context is either
28009 -- the same type or if inside the body, the anonymous task type.
28011 elsif Is_Single_Task_Object
(Ref_Id
) then
28012 if Ekind
(Context_Id
) = E_Task_Type
then
28014 Present
(Anonymous_Object
(Context_Id
))
28015 and then Anonymous_Object
(Context_Id
) = Ref_Id
;
28017 return Ref_Id
= Context_Id
;
28020 -- Otherwise the reference denotes a protected or a task type. Climb the
28021 -- scope chain looking for an enclosing concurrent type that matches the
28022 -- referenced entity.
28025 pragma Assert
(Ekind_In
(Ref_Id
, E_Protected_Type
, E_Task_Type
));
28027 S
:= Current_Scope
;
28028 while Present
(S
) and then S
/= Standard_Standard
loop
28029 if Ekind_In
(S
, E_Protected_Type
, E_Task_Type
)
28030 and then S
= Ref_Id
28040 end Is_CCT_Instance
;
28042 -------------------------------
28043 -- Is_Elaboration_SPARK_Mode --
28044 -------------------------------
28046 function Is_Elaboration_SPARK_Mode
(N
: Node_Id
) return Boolean is
28049 (Nkind
(N
) = N_Pragma
28050 and then Pragma_Name
(N
) = Name_SPARK_Mode
28051 and then Is_List_Member
(N
));
28053 -- Pragma SPARK_Mode affects the elaboration of a package body when it
28054 -- appears in the statement part of the body.
28057 Present
(Parent
(N
))
28058 and then Nkind
(Parent
(N
)) = N_Handled_Sequence_Of_Statements
28059 and then List_Containing
(N
) = Statements
(Parent
(N
))
28060 and then Present
(Parent
(Parent
(N
)))
28061 and then Nkind
(Parent
(Parent
(N
))) = N_Package_Body
;
28062 end Is_Elaboration_SPARK_Mode
;
28064 -----------------------
28065 -- Is_Enabled_Pragma --
28066 -----------------------
28068 function Is_Enabled_Pragma
(Prag
: Node_Id
) return Boolean is
28072 if Present
(Prag
) then
28073 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
28075 if Present
(Arg
) then
28076 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg
)));
28078 -- The lack of a Boolean argument automatically enables the pragma
28084 -- The pragma is missing, therefore it is not enabled
28089 end Is_Enabled_Pragma
;
28091 -----------------------------------------
28092 -- Is_Non_Significant_Pragma_Reference --
28093 -----------------------------------------
28095 -- This function makes use of the following static table which indicates
28096 -- whether appearance of some name in a given pragma is to be considered
28097 -- as a reference for the purposes of warnings about unreferenced objects.
28099 -- -1 indicates that appearence in any argument is significant
28100 -- 0 indicates that appearance in any argument is not significant
28101 -- +n indicates that appearance as argument n is significant, but all
28102 -- other arguments are not significant
28103 -- 9n arguments from n on are significant, before n insignificant
28105 Sig_Flags
: constant array (Pragma_Id
) of Int
:=
28106 (Pragma_Abort_Defer
=> -1,
28107 Pragma_Abstract_State
=> -1,
28108 Pragma_Ada_83
=> -1,
28109 Pragma_Ada_95
=> -1,
28110 Pragma_Ada_05
=> -1,
28111 Pragma_Ada_2005
=> -1,
28112 Pragma_Ada_12
=> -1,
28113 Pragma_Ada_2012
=> -1,
28114 Pragma_All_Calls_Remote
=> -1,
28115 Pragma_Allow_Integer_Address
=> -1,
28116 Pragma_Annotate
=> 93,
28117 Pragma_Assert
=> -1,
28118 Pragma_Assert_And_Cut
=> -1,
28119 Pragma_Assertion_Policy
=> 0,
28120 Pragma_Assume
=> -1,
28121 Pragma_Assume_No_Invalid_Values
=> 0,
28122 Pragma_Async_Readers
=> 0,
28123 Pragma_Async_Writers
=> 0,
28124 Pragma_Asynchronous
=> 0,
28125 Pragma_Atomic
=> 0,
28126 Pragma_Atomic_Components
=> 0,
28127 Pragma_Attach_Handler
=> -1,
28128 Pragma_Attribute_Definition
=> 92,
28129 Pragma_Check
=> -1,
28130 Pragma_Check_Float_Overflow
=> 0,
28131 Pragma_Check_Name
=> 0,
28132 Pragma_Check_Policy
=> 0,
28133 Pragma_CPP_Class
=> 0,
28134 Pragma_CPP_Constructor
=> 0,
28135 Pragma_CPP_Virtual
=> 0,
28136 Pragma_CPP_Vtable
=> 0,
28138 Pragma_C_Pass_By_Copy
=> 0,
28139 Pragma_Comment
=> -1,
28140 Pragma_Common_Object
=> 0,
28141 Pragma_Compile_Time_Error
=> -1,
28142 Pragma_Compile_Time_Warning
=> -1,
28143 Pragma_Compiler_Unit
=> -1,
28144 Pragma_Compiler_Unit_Warning
=> -1,
28145 Pragma_Complete_Representation
=> 0,
28146 Pragma_Complex_Representation
=> 0,
28147 Pragma_Component_Alignment
=> 0,
28148 Pragma_Constant_After_Elaboration
=> 0,
28149 Pragma_Contract_Cases
=> -1,
28150 Pragma_Controlled
=> 0,
28151 Pragma_Convention
=> 0,
28152 Pragma_Convention_Identifier
=> 0,
28153 Pragma_Debug
=> -1,
28154 Pragma_Debug_Policy
=> 0,
28155 Pragma_Detect_Blocking
=> 0,
28156 Pragma_Default_Initial_Condition
=> -1,
28157 Pragma_Default_Scalar_Storage_Order
=> 0,
28158 Pragma_Default_Storage_Pool
=> 0,
28159 Pragma_Depends
=> -1,
28160 Pragma_Disable_Atomic_Synchronization
=> 0,
28161 Pragma_Discard_Names
=> 0,
28162 Pragma_Dispatching_Domain
=> -1,
28163 Pragma_Effective_Reads
=> 0,
28164 Pragma_Effective_Writes
=> 0,
28165 Pragma_Elaborate
=> 0,
28166 Pragma_Elaborate_All
=> 0,
28167 Pragma_Elaborate_Body
=> 0,
28168 Pragma_Elaboration_Checks
=> 0,
28169 Pragma_Eliminate
=> 0,
28170 Pragma_Enable_Atomic_Synchronization
=> 0,
28171 Pragma_Export
=> -1,
28172 Pragma_Export_Function
=> -1,
28173 Pragma_Export_Object
=> -1,
28174 Pragma_Export_Procedure
=> -1,
28175 Pragma_Export_Value
=> -1,
28176 Pragma_Export_Valued_Procedure
=> -1,
28177 Pragma_Extend_System
=> -1,
28178 Pragma_Extensions_Allowed
=> 0,
28179 Pragma_Extensions_Visible
=> 0,
28180 Pragma_External
=> -1,
28181 Pragma_Favor_Top_Level
=> 0,
28182 Pragma_External_Name_Casing
=> 0,
28183 Pragma_Fast_Math
=> 0,
28184 Pragma_Finalize_Storage_Only
=> 0,
28186 Pragma_Global
=> -1,
28187 Pragma_Ident
=> -1,
28188 Pragma_Ignore_Pragma
=> 0,
28189 Pragma_Implementation_Defined
=> -1,
28190 Pragma_Implemented
=> -1,
28191 Pragma_Implicit_Packing
=> 0,
28192 Pragma_Import
=> 93,
28193 Pragma_Import_Function
=> 0,
28194 Pragma_Import_Object
=> 0,
28195 Pragma_Import_Procedure
=> 0,
28196 Pragma_Import_Valued_Procedure
=> 0,
28197 Pragma_Independent
=> 0,
28198 Pragma_Independent_Components
=> 0,
28199 Pragma_Initial_Condition
=> -1,
28200 Pragma_Initialize_Scalars
=> 0,
28201 Pragma_Initializes
=> -1,
28202 Pragma_Inline
=> 0,
28203 Pragma_Inline_Always
=> 0,
28204 Pragma_Inline_Generic
=> 0,
28205 Pragma_Inspection_Point
=> -1,
28206 Pragma_Interface
=> 92,
28207 Pragma_Interface_Name
=> 0,
28208 Pragma_Interrupt_Handler
=> -1,
28209 Pragma_Interrupt_Priority
=> -1,
28210 Pragma_Interrupt_State
=> -1,
28211 Pragma_Invariant
=> -1,
28212 Pragma_Keep_Names
=> 0,
28213 Pragma_License
=> 0,
28214 Pragma_Link_With
=> -1,
28215 Pragma_Linker_Alias
=> -1,
28216 Pragma_Linker_Constructor
=> -1,
28217 Pragma_Linker_Destructor
=> -1,
28218 Pragma_Linker_Options
=> -1,
28219 Pragma_Linker_Section
=> 0,
28221 Pragma_Lock_Free
=> 0,
28222 Pragma_Locking_Policy
=> 0,
28223 Pragma_Loop_Invariant
=> -1,
28224 Pragma_Loop_Optimize
=> 0,
28225 Pragma_Loop_Variant
=> -1,
28226 Pragma_Machine_Attribute
=> -1,
28228 Pragma_Main_Storage
=> -1,
28229 Pragma_Memory_Size
=> 0,
28230 Pragma_No_Return
=> 0,
28231 Pragma_No_Body
=> 0,
28232 Pragma_No_Elaboration_Code_All
=> 0,
28233 Pragma_No_Inline
=> 0,
28234 Pragma_No_Run_Time
=> -1,
28235 Pragma_No_Strict_Aliasing
=> -1,
28236 Pragma_No_Tagged_Streams
=> 0,
28237 Pragma_Normalize_Scalars
=> 0,
28238 Pragma_Obsolescent
=> 0,
28239 Pragma_Optimize
=> 0,
28240 Pragma_Optimize_Alignment
=> 0,
28241 Pragma_Overflow_Mode
=> 0,
28242 Pragma_Overriding_Renamings
=> 0,
28243 Pragma_Ordered
=> 0,
28246 Pragma_Part_Of
=> 0,
28247 Pragma_Partition_Elaboration_Policy
=> 0,
28248 Pragma_Passive
=> 0,
28249 Pragma_Persistent_BSS
=> 0,
28250 Pragma_Polling
=> 0,
28251 Pragma_Prefix_Exception_Messages
=> 0,
28253 Pragma_Postcondition
=> -1,
28254 Pragma_Post_Class
=> -1,
28256 Pragma_Precondition
=> -1,
28257 Pragma_Predicate
=> -1,
28258 Pragma_Predicate_Failure
=> -1,
28259 Pragma_Preelaborable_Initialization
=> -1,
28260 Pragma_Preelaborate
=> 0,
28261 Pragma_Pre_Class
=> -1,
28262 Pragma_Priority
=> -1,
28263 Pragma_Priority_Specific_Dispatching
=> 0,
28264 Pragma_Profile
=> 0,
28265 Pragma_Profile_Warnings
=> 0,
28266 Pragma_Propagate_Exceptions
=> 0,
28267 Pragma_Provide_Shift_Operators
=> 0,
28268 Pragma_Psect_Object
=> 0,
28270 Pragma_Pure_Function
=> 0,
28271 Pragma_Queuing_Policy
=> 0,
28272 Pragma_Rational
=> 0,
28273 Pragma_Ravenscar
=> 0,
28274 Pragma_Refined_Depends
=> -1,
28275 Pragma_Refined_Global
=> -1,
28276 Pragma_Refined_Post
=> -1,
28277 Pragma_Refined_State
=> -1,
28278 Pragma_Relative_Deadline
=> 0,
28279 Pragma_Remote_Access_Type
=> -1,
28280 Pragma_Remote_Call_Interface
=> -1,
28281 Pragma_Remote_Types
=> -1,
28282 Pragma_Restricted_Run_Time
=> 0,
28283 Pragma_Restriction_Warnings
=> 0,
28284 Pragma_Restrictions
=> 0,
28285 Pragma_Reviewable
=> -1,
28286 Pragma_Short_Circuit_And_Or
=> 0,
28287 Pragma_Share_Generic
=> 0,
28288 Pragma_Shared
=> 0,
28289 Pragma_Shared_Passive
=> 0,
28290 Pragma_Short_Descriptors
=> 0,
28291 Pragma_Simple_Storage_Pool_Type
=> 0,
28292 Pragma_Source_File_Name
=> 0,
28293 Pragma_Source_File_Name_Project
=> 0,
28294 Pragma_Source_Reference
=> 0,
28295 Pragma_SPARK_Mode
=> 0,
28296 Pragma_Storage_Size
=> -1,
28297 Pragma_Storage_Unit
=> 0,
28298 Pragma_Static_Elaboration_Desired
=> 0,
28299 Pragma_Stream_Convert
=> 0,
28300 Pragma_Style_Checks
=> 0,
28301 Pragma_Subtitle
=> 0,
28302 Pragma_Suppress
=> 0,
28303 Pragma_Suppress_Exception_Locations
=> 0,
28304 Pragma_Suppress_All
=> 0,
28305 Pragma_Suppress_Debug_Info
=> 0,
28306 Pragma_Suppress_Initialization
=> 0,
28307 Pragma_System_Name
=> 0,
28308 Pragma_Task_Dispatching_Policy
=> 0,
28309 Pragma_Task_Info
=> -1,
28310 Pragma_Task_Name
=> -1,
28311 Pragma_Task_Storage
=> -1,
28312 Pragma_Test_Case
=> -1,
28313 Pragma_Thread_Local_Storage
=> -1,
28314 Pragma_Time_Slice
=> -1,
28316 Pragma_Type_Invariant
=> -1,
28317 Pragma_Type_Invariant_Class
=> -1,
28318 Pragma_Unchecked_Union
=> 0,
28319 Pragma_Unimplemented_Unit
=> 0,
28320 Pragma_Universal_Aliasing
=> 0,
28321 Pragma_Universal_Data
=> 0,
28322 Pragma_Unmodified
=> 0,
28323 Pragma_Unreferenced
=> 0,
28324 Pragma_Unreferenced_Objects
=> 0,
28325 Pragma_Unreserve_All_Interrupts
=> 0,
28326 Pragma_Unsuppress
=> 0,
28327 Pragma_Unevaluated_Use_Of_Old
=> 0,
28328 Pragma_Use_VADS_Size
=> 0,
28329 Pragma_Validity_Checks
=> 0,
28330 Pragma_Volatile
=> 0,
28331 Pragma_Volatile_Components
=> 0,
28332 Pragma_Volatile_Full_Access
=> 0,
28333 Pragma_Volatile_Function
=> 0,
28334 Pragma_Warning_As_Error
=> 0,
28335 Pragma_Warnings
=> 0,
28336 Pragma_Weak_External
=> 0,
28337 Pragma_Wide_Character_Encoding
=> 0,
28338 Unknown_Pragma
=> 0);
28340 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean is
28346 function Arg_No
return Nat
;
28347 -- Returns an integer showing what argument we are in. A value of
28348 -- zero means we are not in any of the arguments.
28354 function Arg_No
return Nat
is
28359 A
:= First
(Pragma_Argument_Associations
(Parent
(P
)));
28373 -- Start of processing for Non_Significant_Pragma_Reference
28378 if Nkind
(P
) /= N_Pragma_Argument_Association
then
28382 Id
:= Get_Pragma_Id
(Parent
(P
));
28383 C
:= Sig_Flags
(Id
);
28398 return AN
< (C
- 90);
28404 end Is_Non_Significant_Pragma_Reference
;
28406 ------------------------------
28407 -- Is_Pragma_String_Literal --
28408 ------------------------------
28410 -- This function returns true if the corresponding pragma argument is a
28411 -- static string expression. These are the only cases in which string
28412 -- literals can appear as pragma arguments. We also allow a string literal
28413 -- as the first argument to pragma Assert (although it will of course
28414 -- always generate a type error).
28416 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean is
28417 Pragn
: constant Node_Id
:= Parent
(Par
);
28418 Assoc
: constant List_Id
:= Pragma_Argument_Associations
(Pragn
);
28419 Pname
: constant Name_Id
:= Pragma_Name
(Pragn
);
28425 N
:= First
(Assoc
);
28432 if Pname
= Name_Assert
then
28435 elsif Pname
= Name_Export
then
28438 elsif Pname
= Name_Ident
then
28441 elsif Pname
= Name_Import
then
28444 elsif Pname
= Name_Interface_Name
then
28447 elsif Pname
= Name_Linker_Alias
then
28450 elsif Pname
= Name_Linker_Section
then
28453 elsif Pname
= Name_Machine_Attribute
then
28456 elsif Pname
= Name_Source_File_Name
then
28459 elsif Pname
= Name_Source_Reference
then
28462 elsif Pname
= Name_Title
then
28465 elsif Pname
= Name_Subtitle
then
28471 end Is_Pragma_String_Literal
;
28473 ---------------------------
28474 -- Is_Private_SPARK_Mode --
28475 ---------------------------
28477 function Is_Private_SPARK_Mode
(N
: Node_Id
) return Boolean is
28480 (Nkind
(N
) = N_Pragma
28481 and then Pragma_Name
(N
) = Name_SPARK_Mode
28482 and then Is_List_Member
(N
));
28484 -- For pragma SPARK_Mode to be private, it has to appear in the private
28485 -- declarations of a package.
28488 Present
(Parent
(N
))
28489 and then Nkind
(Parent
(N
)) = N_Package_Specification
28490 and then List_Containing
(N
) = Private_Declarations
(Parent
(N
));
28491 end Is_Private_SPARK_Mode
;
28493 -------------------------------------
28494 -- Is_Unconstrained_Or_Tagged_Item --
28495 -------------------------------------
28497 function Is_Unconstrained_Or_Tagged_Item
28498 (Item
: Entity_Id
) return Boolean
28500 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean;
28501 -- Determine whether record type Typ has at least one unconstrained
28504 ---------------------------------
28505 -- Has_Unconstrained_Component --
28506 ---------------------------------
28508 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean is
28512 Comp
:= First_Component
(Typ
);
28513 while Present
(Comp
) loop
28514 if Is_Unconstrained_Or_Tagged_Item
(Comp
) then
28518 Next_Component
(Comp
);
28522 end Has_Unconstrained_Component
;
28526 Typ
: constant Entity_Id
:= Etype
(Item
);
28528 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
28531 if Is_Tagged_Type
(Typ
) then
28534 elsif Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
28537 elsif Is_Record_Type
(Typ
) then
28538 if Has_Discriminants
(Typ
) and then not Is_Constrained
(Typ
) then
28541 return Has_Unconstrained_Component
(Typ
);
28544 elsif Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
) then
28550 end Is_Unconstrained_Or_Tagged_Item
;
28552 -----------------------------
28553 -- Is_Valid_Assertion_Kind --
28554 -----------------------------
28556 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean is
28563 Name_Static_Predicate |
28564 Name_Dynamic_Predicate |
28569 Name_Type_Invariant |
28570 Name_uType_Invariant |
28574 Name_Assert_And_Cut |
28576 Name_Contract_Cases |
28578 Name_Default_Initial_Condition |
28580 Name_Initial_Condition |
28583 Name_Loop_Invariant |
28584 Name_Loop_Variant |
28585 Name_Postcondition |
28586 Name_Precondition |
28588 Name_Refined_Post |
28589 Name_Statement_Assertions
=> return True;
28591 when others => return False;
28593 end Is_Valid_Assertion_Kind
;
28595 --------------------------------------
28596 -- Process_Compilation_Unit_Pragmas --
28597 --------------------------------------
28599 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
) is
28601 -- A special check for pragma Suppress_All, a very strange DEC pragma,
28602 -- strange because it comes at the end of the unit. Rational has the
28603 -- same name for a pragma, but treats it as a program unit pragma, In
28604 -- GNAT we just decide to allow it anywhere at all. If it appeared then
28605 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
28606 -- node, and we insert a pragma Suppress (All_Checks) at the start of
28607 -- the context clause to ensure the correct processing.
28609 if Has_Pragma_Suppress_All
(N
) then
28610 Prepend_To
(Context_Items
(N
),
28611 Make_Pragma
(Sloc
(N
),
28612 Chars
=> Name_Suppress
,
28613 Pragma_Argument_Associations
=> New_List
(
28614 Make_Pragma_Argument_Association
(Sloc
(N
),
28615 Expression
=> Make_Identifier
(Sloc
(N
), Name_All_Checks
)))));
28618 -- Nothing else to do at the current time
28620 end Process_Compilation_Unit_Pragmas
;
28622 ------------------------------------
28623 -- Record_Possible_Body_Reference --
28624 ------------------------------------
28626 procedure Record_Possible_Body_Reference
28627 (State_Id
: Entity_Id
;
28631 Spec_Id
: Entity_Id
;
28634 -- Ensure that we are dealing with a reference to a state
28636 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
28638 -- Climb the tree starting from the reference looking for a package body
28639 -- whose spec declares the referenced state. This criteria automatically
28640 -- excludes references in package specs which are legal. Note that it is
28641 -- not wise to emit an error now as the package body may lack pragma
28642 -- Refined_State or the referenced state may not be mentioned in the
28643 -- refinement. This approach avoids the generation of misleading errors.
28646 while Present
(Context
) loop
28647 if Nkind
(Context
) = N_Package_Body
then
28648 Spec_Id
:= Corresponding_Spec
(Context
);
28650 if Present
(Abstract_States
(Spec_Id
))
28651 and then Contains
(Abstract_States
(Spec_Id
), State_Id
)
28653 if No
(Body_References
(State_Id
)) then
28654 Set_Body_References
(State_Id
, New_Elmt_List
);
28657 Append_Elmt
(Ref
, To
=> Body_References
(State_Id
));
28662 Context
:= Parent
(Context
);
28664 end Record_Possible_Body_Reference
;
28666 ------------------------------------------
28667 -- Relocate_Pragmas_To_Anonymous_Object --
28668 ------------------------------------------
28670 procedure Relocate_Pragmas_To_Anonymous_Object
28671 (Typ_Decl
: Node_Id
;
28672 Obj_Decl
: Node_Id
)
28676 Next_Decl
: Node_Id
;
28679 if Nkind
(Typ_Decl
) = N_Protected_Type_Declaration
then
28680 Def
:= Protected_Definition
(Typ_Decl
);
28682 pragma Assert
(Nkind
(Typ_Decl
) = N_Task_Type_Declaration
);
28683 Def
:= Task_Definition
(Typ_Decl
);
28686 -- The concurrent definition has a visible declaration list. Inspect it
28687 -- and relocate all canidate pragmas.
28689 if Present
(Def
) and then Present
(Visible_Declarations
(Def
)) then
28690 Decl
:= First
(Visible_Declarations
(Def
));
28691 while Present
(Decl
) loop
28693 -- Preserve the following declaration for iteration purposes due
28694 -- to possible relocation of a pragma.
28696 Next_Decl
:= Next
(Decl
);
28698 if Nkind
(Decl
) = N_Pragma
28699 and then Pragma_On_Anonymous_Object_OK
(Get_Pragma_Id
(Decl
))
28702 Insert_After
(Obj_Decl
, Decl
);
28704 -- Skip internally generated code
28706 elsif not Comes_From_Source
(Decl
) then
28709 -- No candidate pragmas are available for relocation
28718 end Relocate_Pragmas_To_Anonymous_Object
;
28720 ------------------------------
28721 -- Relocate_Pragmas_To_Body --
28722 ------------------------------
28724 procedure Relocate_Pragmas_To_Body
28725 (Subp_Body
: Node_Id
;
28726 Target_Body
: Node_Id
:= Empty
)
28728 procedure Relocate_Pragma
(Prag
: Node_Id
);
28729 -- Remove a single pragma from its current list and add it to the
28730 -- declarations of the proper body (either Subp_Body or Target_Body).
28732 ---------------------
28733 -- Relocate_Pragma --
28734 ---------------------
28736 procedure Relocate_Pragma
(Prag
: Node_Id
) is
28741 -- When subprogram stubs or expression functions are involves, the
28742 -- destination declaration list belongs to the proper body.
28744 if Present
(Target_Body
) then
28745 Target
:= Target_Body
;
28747 Target
:= Subp_Body
;
28750 Decls
:= Declarations
(Target
);
28754 Set_Declarations
(Target
, Decls
);
28757 -- Unhook the pragma from its current list
28760 Prepend
(Prag
, Decls
);
28761 end Relocate_Pragma
;
28765 Body_Id
: constant Entity_Id
:=
28766 Defining_Unit_Name
(Specification
(Subp_Body
));
28767 Next_Stmt
: Node_Id
;
28770 -- Start of processing for Relocate_Pragmas_To_Body
28773 -- Do not process a body that comes from a separate unit as no construct
28774 -- can possibly follow it.
28776 if not Is_List_Member
(Subp_Body
) then
28779 -- Do not relocate pragmas that follow a stub if the stub does not have
28782 elsif Nkind
(Subp_Body
) = N_Subprogram_Body_Stub
28783 and then No
(Target_Body
)
28787 -- Do not process internally generated routine _Postconditions
28789 elsif Ekind
(Body_Id
) = E_Procedure
28790 and then Chars
(Body_Id
) = Name_uPostconditions
28795 -- Look at what is following the body. We are interested in certain kind
28796 -- of pragmas (either from source or byproducts of expansion) that can
28797 -- apply to a body [stub].
28799 Stmt
:= Next
(Subp_Body
);
28800 while Present
(Stmt
) loop
28802 -- Preserve the following statement for iteration purposes due to a
28803 -- possible relocation of a pragma.
28805 Next_Stmt
:= Next
(Stmt
);
28807 -- Move a candidate pragma following the body to the declarations of
28810 if Nkind
(Stmt
) = N_Pragma
28811 and then Pragma_On_Body_Or_Stub_OK
(Get_Pragma_Id
(Stmt
))
28813 Relocate_Pragma
(Stmt
);
28815 -- Skip internally generated code
28817 elsif not Comes_From_Source
(Stmt
) then
28820 -- No candidate pragmas are available for relocation
28828 end Relocate_Pragmas_To_Body
;
28830 -------------------
28831 -- Resolve_State --
28832 -------------------
28834 procedure Resolve_State
(N
: Node_Id
) is
28839 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
28840 Func
:= Entity
(N
);
28842 -- Handle overloading of state names by functions. Traverse the
28843 -- homonym chain looking for an abstract state.
28845 if Ekind
(Func
) = E_Function
and then Has_Homonym
(Func
) then
28846 State
:= Homonym
(Func
);
28847 while Present
(State
) loop
28849 -- Resolve the overloading by setting the proper entity of the
28850 -- reference to that of the state.
28852 if Ekind
(State
) = E_Abstract_State
then
28853 Set_Etype
(N
, Standard_Void_Type
);
28854 Set_Entity
(N
, State
);
28855 Set_Associated_Node
(N
, State
);
28859 State
:= Homonym
(State
);
28862 -- A function can never act as a state. If the homonym chain does
28863 -- not contain a corresponding state, then something went wrong in
28864 -- the overloading mechanism.
28866 raise Program_Error
;
28871 ----------------------------
28872 -- Rewrite_Assertion_Kind --
28873 ----------------------------
28875 procedure Rewrite_Assertion_Kind
(N
: Node_Id
) is
28879 if Nkind
(N
) = N_Attribute_Reference
28880 and then Attribute_Name
(N
) = Name_Class
28881 and then Nkind
(Prefix
(N
)) = N_Identifier
28883 case Chars
(Prefix
(N
)) is
28888 when Name_Type_Invariant
=>
28889 Nam
:= Name_uType_Invariant
;
28890 when Name_Invariant
=>
28891 Nam
:= Name_uInvariant
;
28896 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
=> Nam
));
28898 end Rewrite_Assertion_Kind
;
28906 Dummy
:= Dummy
+ 1;
28909 --------------------------------
28910 -- Set_Encoded_Interface_Name --
28911 --------------------------------
28913 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
) is
28914 Str
: constant String_Id
:= Strval
(S
);
28915 Len
: constant Nat
:= String_Length
(Str
);
28920 Hex
: constant array (0 .. 15) of Character := "0123456789abcdef";
28923 -- Stores encoded value of character code CC. The encoding we use an
28924 -- underscore followed by four lower case hex digits.
28930 procedure Encode
is
28932 Store_String_Char
(Get_Char_Code
('_'));
28934 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 12))));
28936 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 8 and 16#
0F#
))));
28938 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 4 and 16#
0F#
))));
28940 (Get_Char_Code
(Hex
(Integer (CC
and 16#
0F#
))));
28943 -- Start of processing for Set_Encoded_Interface_Name
28946 -- If first character is asterisk, this is a link name, and we leave it
28947 -- completely unmodified. We also ignore null strings (the latter case
28948 -- happens only in error cases) and no encoding should occur for AAMP
28949 -- interface names.
28952 or else Get_String_Char
(Str
, 1) = Get_Char_Code
('*')
28953 or else AAMP_On_Target
28955 Set_Interface_Name
(E
, S
);
28960 CC
:= Get_String_Char
(Str
, J
);
28962 exit when not In_Character_Range
(CC
);
28964 C
:= Get_Character
(CC
);
28966 exit when C
/= '_' and then C
/= '$'
28967 and then C
not in '0' .. '9'
28968 and then C
not in 'a' .. 'z'
28969 and then C
not in 'A' .. 'Z';
28972 Set_Interface_Name
(E
, S
);
28980 -- Here we need to encode. The encoding we use as follows:
28981 -- three underscores + four hex digits (lower case)
28985 for J
in 1 .. String_Length
(Str
) loop
28986 CC
:= Get_String_Char
(Str
, J
);
28988 if not In_Character_Range
(CC
) then
28991 C
:= Get_Character
(CC
);
28993 if C
= '_' or else C
= '$'
28994 or else C
in '0' .. '9'
28995 or else C
in 'a' .. 'z'
28996 or else C
in 'A' .. 'Z'
28998 Store_String_Char
(CC
);
29005 Set_Interface_Name
(E
,
29006 Make_String_Literal
(Sloc
(S
),
29007 Strval
=> End_String
));
29009 end Set_Encoded_Interface_Name
;
29011 ------------------------
29012 -- Set_Elab_Unit_Name --
29013 ------------------------
29015 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
) is
29020 if Nkind
(N
) = N_Identifier
29021 and then Nkind
(With_Item
) = N_Identifier
29023 Set_Entity
(N
, Entity
(With_Item
));
29025 elsif Nkind
(N
) = N_Selected_Component
then
29026 Change_Selected_Component_To_Expanded_Name
(N
);
29027 Set_Entity
(N
, Entity
(With_Item
));
29028 Set_Entity
(Selector_Name
(N
), Entity
(N
));
29030 Pref
:= Prefix
(N
);
29031 Scop
:= Scope
(Entity
(N
));
29032 while Nkind
(Pref
) = N_Selected_Component
loop
29033 Change_Selected_Component_To_Expanded_Name
(Pref
);
29034 Set_Entity
(Selector_Name
(Pref
), Scop
);
29035 Set_Entity
(Pref
, Scop
);
29036 Pref
:= Prefix
(Pref
);
29037 Scop
:= Scope
(Scop
);
29040 Set_Entity
(Pref
, Scop
);
29043 Generate_Reference
(Entity
(With_Item
), N
, Set_Ref
=> False);
29044 end Set_Elab_Unit_Name
;
29046 -------------------
29047 -- Test_Case_Arg --
29048 -------------------
29050 function Test_Case_Arg
29053 From_Aspect
: Boolean := False) return Node_Id
29055 Aspect
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
29060 pragma Assert
(Nam_In
(Arg_Nam
, Name_Ensures
,
29065 -- The caller requests the aspect argument
29067 if From_Aspect
then
29068 if Present
(Aspect
)
29069 and then Nkind
(Expression
(Aspect
)) = N_Aggregate
29071 Args
:= Expression
(Aspect
);
29073 -- "Name" and "Mode" may appear without an identifier as a
29074 -- positional association.
29076 if Present
(Expressions
(Args
)) then
29077 Arg
:= First
(Expressions
(Args
));
29079 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
29087 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
29092 -- Some or all arguments may appear as component associatons
29094 if Present
(Component_Associations
(Args
)) then
29095 Arg
:= First
(Component_Associations
(Args
));
29096 while Present
(Arg
) loop
29097 if Chars
(First
(Choices
(Arg
))) = Arg_Nam
then
29106 -- Otherwise retrieve the argument directly from the pragma
29109 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
29111 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
29115 -- Skip argument "Name"
29119 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
29123 -- Skip argument "Mode"
29127 -- Arguments "Requires" and "Ensures" are optional and may not be
29130 while Present
(Arg
) loop
29131 if Chars
(Arg
) = Arg_Nam
then