1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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_Type. Convert a name into a corresponding value of 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
(Ref
: Node_Id
) return Boolean;
249 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
250 -- Global. Determine whether reference Ref denotes the current instance of
251 -- a concurrent type.
253 function Is_Unconstrained_Or_Tagged_Item
(Item
: Entity_Id
) return Boolean;
254 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
255 -- pragma Depends. Determine whether the type of dependency item Item is
256 -- tagged, unconstrained array, unconstrained record or a record with at
257 -- least one unconstrained component.
259 procedure Record_Possible_Body_Reference
260 (State_Id
: Entity_Id
;
262 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
263 -- Global. Given an abstract state denoted by State_Id and a reference Ref
264 -- to it, determine whether the reference appears in a package body that
265 -- will eventually refine the state. If this is the case, record the
266 -- reference for future checks (see Analyze_Refined_State_In_Decls).
268 procedure Resolve_State
(N
: Node_Id
);
269 -- Handle the overloading of state names by functions. When N denotes a
270 -- function, this routine finds the corresponding state and sets the entity
271 -- of N to that of the state.
273 procedure Rewrite_Assertion_Kind
(N
: Node_Id
);
274 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
275 -- then it is rewritten as an identifier with the corresponding special
276 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
279 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
);
280 -- Place semantic information on the argument of an Elaborate/Elaborate_All
281 -- pragma. Entity name for unit and its parents is taken from item in
282 -- previous with_clause that mentions the unit.
284 Dummy
: Integer := 0;
285 pragma Volatile
(Dummy
);
286 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
289 pragma No_Inline
(ip
);
290 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
291 -- is just to help debugging the front end. If a pragma Inspection_Point
292 -- is added to a source program, then breaking on ip will get you to that
293 -- point in the program.
296 pragma No_Inline
(rv
);
297 -- This is a dummy function called by the processing for pragma Reviewable.
298 -- It is there for assisting front end debugging. By placing a Reviewable
299 -- pragma in the source program, a breakpoint on rv catches this place in
300 -- the source, allowing convenient stepping to the point of interest.
302 -------------------------------
303 -- Adjust_External_Name_Case --
304 -------------------------------
306 function Adjust_External_Name_Case
(N
: Node_Id
) return Node_Id
is
310 -- Adjust case of literal if required
312 if Opt
.External_Name_Exp_Casing
= As_Is
then
316 -- Copy existing string
322 for J
in 1 .. String_Length
(Strval
(N
)) loop
323 CC
:= Get_String_Char
(Strval
(N
), J
);
325 if Opt
.External_Name_Exp_Casing
= Uppercase
326 and then CC
>= Get_Char_Code
('a')
327 and then CC
<= Get_Char_Code
('z')
329 Store_String_Char
(CC
- 32);
331 elsif Opt
.External_Name_Exp_Casing
= Lowercase
332 and then CC
>= Get_Char_Code
('A')
333 and then CC
<= Get_Char_Code
('Z')
335 Store_String_Char
(CC
+ 32);
338 Store_String_Char
(CC
);
343 Make_String_Literal
(Sloc
(N
),
344 Strval
=> End_String
);
346 end Adjust_External_Name_Case
;
348 -----------------------------------------
349 -- Analyze_Contract_Cases_In_Decl_Part --
350 -----------------------------------------
352 procedure Analyze_Contract_Cases_In_Decl_Part
354 Freeze_Id
: Entity_Id
:= Empty
)
356 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
357 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
359 Others_Seen
: Boolean := False;
360 -- This flag is set when an "others" choice is encountered. It is used
361 -- to detect multiple illegal occurrences of "others".
363 procedure Analyze_Contract_Case
(CCase
: Node_Id
);
364 -- Verify the legality of a single contract case
366 ---------------------------
367 -- Analyze_Contract_Case --
368 ---------------------------
370 procedure Analyze_Contract_Case
(CCase
: Node_Id
) is
371 Case_Guard
: Node_Id
;
374 Extra_Guard
: Node_Id
;
377 if Nkind
(CCase
) = N_Component_Association
then
378 Case_Guard
:= First
(Choices
(CCase
));
379 Conseq
:= Expression
(CCase
);
381 -- Each contract case must have exactly one case guard
383 Extra_Guard
:= Next
(Case_Guard
);
385 if Present
(Extra_Guard
) then
387 ("contract case must have exactly one case guard",
391 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
393 if Nkind
(Case_Guard
) = N_Others_Choice
then
396 ("only one others choice allowed in contract cases",
402 elsif Others_Seen
then
404 ("others must be the last choice in contract cases", N
);
407 -- Preanalyze the case guard and consequence
409 if Nkind
(Case_Guard
) /= N_Others_Choice
then
410 Errors
:= Serious_Errors_Detected
;
411 Preanalyze_Assert_Expression
(Case_Guard
, Standard_Boolean
);
413 -- Emit a clarification message when the case guard contains
414 -- at least one undefined reference, possibly due to contract
417 if Errors
/= Serious_Errors_Detected
418 and then Present
(Freeze_Id
)
419 and then Has_Undefined_Reference
(Case_Guard
)
421 Contract_Freeze_Error
(Spec_Id
, Freeze_Id
);
425 Errors
:= Serious_Errors_Detected
;
426 Preanalyze_Assert_Expression
(Conseq
, Standard_Boolean
);
428 -- Emit a clarification message when the consequence contains
429 -- at least one undefined reference, possibly due to contract
432 if Errors
/= Serious_Errors_Detected
433 and then Present
(Freeze_Id
)
434 and then Has_Undefined_Reference
(Conseq
)
436 Contract_Freeze_Error
(Spec_Id
, Freeze_Id
);
439 -- The contract case is malformed
442 Error_Msg_N
("wrong syntax in contract case", CCase
);
444 end Analyze_Contract_Case
;
448 CCases
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
450 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
453 Restore_Scope
: Boolean := False;
455 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
458 -- Do not analyze the pragma multiple times
460 if Is_Analyzed_Pragma
(N
) then
464 -- Set the Ghost mode in effect from the pragma. Due to the delayed
465 -- analysis of the pragma, the Ghost mode at point of declaration and
466 -- point of analysis may not necessarely be the same. Use the mode in
467 -- effect at the point of declaration.
471 -- Single and multiple contract cases must appear in aggregate form. If
472 -- this is not the case, then either the parser of the analysis of the
473 -- pragma failed to produce an aggregate.
475 pragma Assert
(Nkind
(CCases
) = N_Aggregate
);
477 if Present
(Component_Associations
(CCases
)) then
479 -- Ensure that the formal parameters are visible when analyzing all
480 -- clauses. This falls out of the general rule of aspects pertaining
481 -- to subprogram declarations.
483 if not In_Open_Scopes
(Spec_Id
) then
484 Restore_Scope
:= True;
485 Push_Scope
(Spec_Id
);
487 if Is_Generic_Subprogram
(Spec_Id
) then
488 Install_Generic_Formals
(Spec_Id
);
490 Install_Formals
(Spec_Id
);
494 CCase
:= First
(Component_Associations
(CCases
));
495 while Present
(CCase
) loop
496 Analyze_Contract_Case
(CCase
);
500 if Restore_Scope
then
504 -- Currently it is not possible to inline pre/postconditions on a
505 -- subprogram subject to pragma Inline_Always.
507 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
509 -- Otherwise the pragma is illegal
512 Error_Msg_N
("wrong syntax for constract cases", N
);
515 Ghost_Mode
:= Save_Ghost_Mode
;
516 Set_Is_Analyzed_Pragma
(N
);
517 end Analyze_Contract_Cases_In_Decl_Part
;
519 ----------------------------------
520 -- Analyze_Depends_In_Decl_Part --
521 ----------------------------------
523 procedure Analyze_Depends_In_Decl_Part
(N
: Node_Id
) is
524 Loc
: constant Source_Ptr
:= Sloc
(N
);
525 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
526 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
528 All_Inputs_Seen
: Elist_Id
:= No_Elist
;
529 -- A list containing the entities of all the inputs processed so far.
530 -- The list is populated with unique entities because the same input
531 -- may appear in multiple input lists.
533 All_Outputs_Seen
: Elist_Id
:= No_Elist
;
534 -- A list containing the entities of all the outputs processed so far.
535 -- The list is populated with unique entities because output items are
536 -- unique in a dependence relation.
538 Constits_Seen
: Elist_Id
:= No_Elist
;
539 -- A list containing the entities of all constituents processed so far.
540 -- It aids in detecting illegal usage of a state and a corresponding
541 -- constituent in pragma [Refinde_]Depends.
543 Global_Seen
: Boolean := False;
544 -- A flag set when pragma Global has been processed
546 Null_Output_Seen
: Boolean := False;
547 -- A flag used to track the legality of a null output
549 Result_Seen
: Boolean := False;
550 -- A flag set when Spec_Id'Result is processed
552 States_Seen
: Elist_Id
:= No_Elist
;
553 -- A list containing the entities of all states processed so far. It
554 -- helps in detecting illegal usage of a state and a corresponding
555 -- constituent in pragma [Refined_]Depends.
557 Subp_Inputs
: Elist_Id
:= No_Elist
;
558 Subp_Outputs
: Elist_Id
:= No_Elist
;
559 -- Two lists containing the full set of inputs and output of the related
560 -- subprograms. Note that these lists contain both nodes and entities.
562 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
);
563 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
564 -- to the name buffer. The individual kinds are as follows:
565 -- E_Abstract_State - "state"
566 -- E_Constant - "constant"
567 -- E_Discriminant - "discriminant"
568 -- E_Generic_In_Out_Parameter - "generic parameter"
569 -- E_Generic_In_Parameter - "generic parameter"
570 -- E_In_Parameter - "parameter"
571 -- E_In_Out_Parameter - "parameter"
572 -- E_Loop_Parameter - "loop parameter"
573 -- E_Out_Parameter - "parameter"
574 -- E_Protected_Type - "current instance of protected type"
575 -- E_Task_Type - "current instance of task type"
576 -- E_Variable - "global"
578 procedure Analyze_Dependency_Clause
581 -- Verify the legality of a single dependency clause. Flag Is_Last
582 -- denotes whether Clause is the last clause in the relation.
584 procedure Check_Function_Return
;
585 -- Verify that Funtion'Result appears as one of the outputs
586 -- (SPARK RM 6.1.5(10)).
593 -- Ensure that an item fulfils its designated input and/or output role
594 -- as specified by pragma Global (if any) or the enclosing context. If
595 -- this is not the case, emit an error. Item and Item_Id denote the
596 -- attributes of an item. Flag Is_Input should be set when item comes
597 -- from an input list. Flag Self_Ref should be set when the item is an
598 -- output and the dependency clause has operator "+".
600 procedure Check_Usage
601 (Subp_Items
: Elist_Id
;
602 Used_Items
: Elist_Id
;
604 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
605 -- error if this is not the case.
607 procedure Normalize_Clause
(Clause
: Node_Id
);
608 -- Remove a self-dependency "+" from the input list of a clause
610 -----------------------------
611 -- Add_Item_To_Name_Buffer --
612 -----------------------------
614 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
) is
616 if Ekind
(Item_Id
) = E_Abstract_State
then
617 Add_Str_To_Name_Buffer
("state");
619 elsif Ekind
(Item_Id
) = E_Constant
then
620 Add_Str_To_Name_Buffer
("constant");
622 elsif Ekind
(Item_Id
) = E_Discriminant
then
623 Add_Str_To_Name_Buffer
("discriminant");
625 elsif Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
626 E_Generic_In_Parameter
)
628 Add_Str_To_Name_Buffer
("generic parameter");
630 elsif Is_Formal
(Item_Id
) then
631 Add_Str_To_Name_Buffer
("parameter");
633 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
634 Add_Str_To_Name_Buffer
("loop parameter");
636 elsif Ekind
(Item_Id
) = E_Protected_Type
637 or else Is_Single_Protected_Object
(Item_Id
)
639 Add_Str_To_Name_Buffer
("current instance of protected type");
641 elsif Ekind
(Item_Id
) = E_Task_Type
642 or else Is_Single_Task_Object
(Item_Id
)
644 Add_Str_To_Name_Buffer
("current instance of task type");
646 elsif Ekind
(Item_Id
) = E_Variable
then
647 Add_Str_To_Name_Buffer
("global");
649 -- The routine should not be called with non-SPARK items
654 end Add_Item_To_Name_Buffer
;
656 -------------------------------
657 -- Analyze_Dependency_Clause --
658 -------------------------------
660 procedure Analyze_Dependency_Clause
664 procedure Analyze_Input_List
(Inputs
: Node_Id
);
665 -- Verify the legality of a single input list
667 procedure Analyze_Input_Output
672 Seen
: in out Elist_Id
;
673 Null_Seen
: in out Boolean;
674 Non_Null_Seen
: in out Boolean);
675 -- Verify the legality of a single input or output item. Flag
676 -- Is_Input should be set whenever Item is an input, False when it
677 -- denotes an output. Flag Self_Ref should be set when the item is an
678 -- output and the dependency clause has a "+". Flag Top_Level should
679 -- be set whenever Item appears immediately within an input or output
680 -- list. Seen is a collection of all abstract states, objects and
681 -- formals processed so far. Flag Null_Seen denotes whether a null
682 -- input or output has been encountered. Flag Non_Null_Seen denotes
683 -- whether a non-null input or output has been encountered.
685 ------------------------
686 -- Analyze_Input_List --
687 ------------------------
689 procedure Analyze_Input_List
(Inputs
: Node_Id
) is
690 Inputs_Seen
: Elist_Id
:= No_Elist
;
691 -- A list containing the entities of all inputs that appear in the
692 -- current input list.
694 Non_Null_Input_Seen
: Boolean := False;
695 Null_Input_Seen
: Boolean := False;
696 -- Flags used to check the legality of an input list
701 -- Multiple inputs appear as an aggregate
703 if Nkind
(Inputs
) = N_Aggregate
then
704 if Present
(Component_Associations
(Inputs
)) then
706 ("nested dependency relations not allowed", Inputs
);
708 elsif Present
(Expressions
(Inputs
)) then
709 Input
:= First
(Expressions
(Inputs
));
710 while Present
(Input
) loop
717 Null_Seen
=> Null_Input_Seen
,
718 Non_Null_Seen
=> Non_Null_Input_Seen
);
723 -- Syntax error, always report
726 Error_Msg_N
("malformed input dependency list", Inputs
);
729 -- Process a solitary input
738 Null_Seen
=> Null_Input_Seen
,
739 Non_Null_Seen
=> Non_Null_Input_Seen
);
742 -- Detect an illegal dependency clause of the form
746 if Null_Output_Seen
and then Null_Input_Seen
then
748 ("null dependency clause cannot have a null input list",
751 end Analyze_Input_List
;
753 --------------------------
754 -- Analyze_Input_Output --
755 --------------------------
757 procedure Analyze_Input_Output
762 Seen
: in out Elist_Id
;
763 Null_Seen
: in out Boolean;
764 Non_Null_Seen
: in out Boolean)
766 Is_Output
: constant Boolean := not Is_Input
;
771 -- Multiple input or output items appear as an aggregate
773 if Nkind
(Item
) = N_Aggregate
then
774 if not Top_Level
then
775 SPARK_Msg_N
("nested grouping of items not allowed", Item
);
777 elsif Present
(Component_Associations
(Item
)) then
779 ("nested dependency relations not allowed", Item
);
781 -- Recursively analyze the grouped items
783 elsif Present
(Expressions
(Item
)) then
784 Grouped
:= First
(Expressions
(Item
));
785 while Present
(Grouped
) loop
788 Is_Input
=> Is_Input
,
789 Self_Ref
=> Self_Ref
,
792 Null_Seen
=> Null_Seen
,
793 Non_Null_Seen
=> Non_Null_Seen
);
798 -- Syntax error, always report
801 Error_Msg_N
("malformed dependency list", Item
);
804 -- Process attribute 'Result in the context of a dependency clause
806 elsif Is_Attribute_Result
(Item
) then
807 Non_Null_Seen
:= True;
811 -- Attribute 'Result is allowed to appear on the output side of
812 -- a dependency clause (SPARK RM 6.1.5(6)).
815 SPARK_Msg_N
("function result cannot act as input", Item
);
819 ("cannot mix null and non-null dependency items", Item
);
825 -- Detect multiple uses of null in a single dependency list or
826 -- throughout the whole relation. Verify the placement of a null
827 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
829 elsif Nkind
(Item
) = N_Null
then
832 ("multiple null dependency relations not allowed", Item
);
834 elsif Non_Null_Seen
then
836 ("cannot mix null and non-null dependency items", Item
);
844 ("null output list must be the last clause in a "
845 & "dependency relation", Item
);
847 -- Catch a useless dependence of the form:
852 ("useless dependence, null depends on itself", Item
);
860 Non_Null_Seen
:= True;
863 SPARK_Msg_N
("cannot mix null and non-null items", Item
);
867 Resolve_State
(Item
);
869 -- Find the entity of the item. If this is a renaming, climb
870 -- the renaming chain to reach the root object. Renamings of
871 -- non-entire objects do not yield an entity (Empty).
873 Item_Id
:= Entity_Of
(Item
);
875 if Present
(Item_Id
) then
879 if Ekind_In
(Item_Id
, E_Constant
,
884 -- Current instances of concurrent types
886 Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
)
891 Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
892 E_Generic_In_Parameter
,
900 Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
)
902 -- The item denotes a concurrent type, but it is not the
903 -- current instance of an enclosing concurrent type.
905 if Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
)
906 and then not Is_CCT_Instance
(Item
)
909 ("invalid use of subtype mark in dependency "
913 -- Ensure that the item fulfils its role as input and/or
914 -- output as specified by pragma Global or the enclosing
917 Check_Role
(Item
, Item_Id
, Is_Input
, Self_Ref
);
919 -- Detect multiple uses of the same state, variable or
920 -- formal parameter. If this is not the case, add the
921 -- item to the list of processed relations.
923 if Contains
(Seen
, Item_Id
) then
925 ("duplicate use of item &", Item
, Item_Id
);
927 Append_New_Elmt
(Item_Id
, Seen
);
930 -- Detect illegal use of an input related to a null
931 -- output. Such input items cannot appear in other
932 -- input lists (SPARK RM 6.1.5(13)).
935 and then Null_Output_Seen
936 and then Contains
(All_Inputs_Seen
, Item_Id
)
939 ("input of a null output list cannot appear in "
940 & "multiple input lists", Item
);
943 -- Add an input or a self-referential output to the list
944 -- of all processed inputs.
946 if Is_Input
or else Self_Ref
then
947 Append_New_Elmt
(Item_Id
, All_Inputs_Seen
);
950 -- State related checks (SPARK RM 6.1.5(3))
952 if Ekind
(Item_Id
) = E_Abstract_State
then
954 -- Package and subprogram bodies are instantiated
955 -- individually in a separate compiler pass. Due to
956 -- this mode of instantiation, the refinement of a
957 -- state may no longer be visible when a subprogram
958 -- body contract is instantiated. Since the generic
959 -- template is legal, do not perform this check in
960 -- the instance to circumvent this oddity.
962 if Is_Generic_Instance
(Spec_Id
) then
965 -- An abstract state with visible refinement cannot
966 -- appear in pragma [Refined_]Depends as its place
967 -- must be taken by some of its constituents
968 -- (SPARK RM 6.1.4(7)).
970 elsif Has_Visible_Refinement
(Item_Id
) then
972 ("cannot mention state & in dependence relation",
974 SPARK_Msg_N
("\use its constituents instead", Item
);
977 -- If the reference to the abstract state appears in
978 -- an enclosing package body that will eventually
979 -- refine the state, record the reference for future
983 Record_Possible_Body_Reference
984 (State_Id
=> Item_Id
,
989 -- When the item renames an entire object, replace the
990 -- item with a reference to the object.
992 if Entity
(Item
) /= Item_Id
then
994 New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
998 -- Add the entity of the current item to the list of
1001 if Ekind
(Item_Id
) = E_Abstract_State
then
1002 Append_New_Elmt
(Item_Id
, States_Seen
);
1004 -- The variable may eventually become a constituent of a
1005 -- single protected/task type. Record the reference now
1006 -- and verify its legality when analyzing the contract of
1007 -- the variable (SPARK RM 9.3).
1009 elsif Ekind
(Item_Id
) = E_Variable
then
1010 Record_Possible_Part_Of_Reference
1015 if Ekind_In
(Item_Id
, E_Abstract_State
,
1018 and then Present
(Encapsulating_State
(Item_Id
))
1020 Append_New_Elmt
(Item_Id
, Constits_Seen
);
1023 -- All other input/output items are illegal
1024 -- (SPARK RM 6.1.5(1)).
1028 ("item must denote parameter, variable, state or "
1029 & "current instance of concurren type", Item
);
1032 -- All other input/output items are illegal
1033 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
1037 ("item must denote parameter, variable, state or current "
1038 & "instance of concurrent type", Item
);
1041 end Analyze_Input_Output
;
1049 Non_Null_Output_Seen
: Boolean := False;
1050 -- Flag used to check the legality of an output list
1052 -- Start of processing for Analyze_Dependency_Clause
1055 Inputs
:= Expression
(Clause
);
1058 -- An input list with a self-dependency appears as operator "+" where
1059 -- the actuals inputs are the right operand.
1061 if Nkind
(Inputs
) = N_Op_Plus
then
1062 Inputs
:= Right_Opnd
(Inputs
);
1066 -- Process the output_list of a dependency_clause
1068 Output
:= First
(Choices
(Clause
));
1069 while Present
(Output
) loop
1070 Analyze_Input_Output
1073 Self_Ref
=> Self_Ref
,
1075 Seen
=> All_Outputs_Seen
,
1076 Null_Seen
=> Null_Output_Seen
,
1077 Non_Null_Seen
=> Non_Null_Output_Seen
);
1082 -- Process the input_list of a dependency_clause
1084 Analyze_Input_List
(Inputs
);
1085 end Analyze_Dependency_Clause
;
1087 ---------------------------
1088 -- Check_Function_Return --
1089 ---------------------------
1091 procedure Check_Function_Return
is
1093 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
1094 and then not Result_Seen
1097 ("result of & must appear in exactly one output list",
1100 end Check_Function_Return
;
1106 procedure Check_Role
1108 Item_Id
: Entity_Id
;
1113 (Item_Is_Input
: out Boolean;
1114 Item_Is_Output
: out Boolean);
1115 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1116 -- Item_Is_Output are set depending on the role.
1118 procedure Role_Error
1119 (Item_Is_Input
: Boolean;
1120 Item_Is_Output
: Boolean);
1121 -- Emit an error message concerning the incorrect use of Item in
1122 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1123 -- denote whether the item is an input and/or an output.
1130 (Item_Is_Input
: out Boolean;
1131 Item_Is_Output
: out Boolean)
1134 Item_Is_Input
:= False;
1135 Item_Is_Output
:= False;
1139 if Ekind
(Item_Id
) = E_Abstract_State
then
1141 -- When pragma Global is present, the mode of the state may be
1142 -- further constrained by setting a more restrictive mode.
1145 if Appears_In
(Subp_Inputs
, Item_Id
) then
1146 Item_Is_Input
:= True;
1149 if Appears_In
(Subp_Outputs
, Item_Id
) then
1150 Item_Is_Output
:= True;
1153 -- Otherwise the state has a default IN OUT mode
1156 Item_Is_Input
:= True;
1157 Item_Is_Output
:= True;
1162 elsif Ekind_In
(Item_Id
, E_Constant
,
1166 Item_Is_Input
:= True;
1170 elsif Ekind_In
(Item_Id
, E_Generic_In_Parameter
,
1173 Item_Is_Input
:= True;
1175 elsif Ekind_In
(Item_Id
, E_Generic_In_Out_Parameter
,
1178 Item_Is_Input
:= True;
1179 Item_Is_Output
:= True;
1181 elsif Ekind
(Item_Id
) = E_Out_Parameter
then
1182 if Scope
(Item_Id
) = Spec_Id
then
1184 -- An OUT parameter of the related subprogram has mode IN
1185 -- if its type is unconstrained or tagged because array
1186 -- bounds, discriminants or tags can be read.
1188 if Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1189 Item_Is_Input
:= True;
1192 Item_Is_Output
:= True;
1194 -- An OUT parameter of an enclosing subprogram behaves as a
1195 -- read-write variable in which case the mode is IN OUT.
1198 Item_Is_Input
:= True;
1199 Item_Is_Output
:= True;
1204 elsif Ekind
(Item_Id
) = E_Protected_Type
then
1206 -- A protected type acts as a formal parameter of mode IN when
1207 -- it applies to a protected function.
1209 if Ekind
(Spec_Id
) = E_Function
then
1210 Item_Is_Input
:= True;
1212 -- Otherwise the protected type acts as a formal of mode IN OUT
1215 Item_Is_Input
:= True;
1216 Item_Is_Output
:= True;
1221 elsif Ekind
(Item_Id
) = E_Task_Type
then
1222 Item_Is_Input
:= True;
1223 Item_Is_Output
:= True;
1227 else pragma Assert
(Ekind
(Item_Id
) = E_Variable
);
1229 -- When pragma Global is present, the mode of the variable may
1230 -- be further constrained by setting a more restrictive mode.
1234 -- A variable has mode IN when its type is unconstrained or
1235 -- tagged because array bounds, discriminants or tags can be
1238 if Appears_In
(Subp_Inputs
, Item_Id
)
1239 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
)
1241 Item_Is_Input
:= True;
1244 if Appears_In
(Subp_Outputs
, Item_Id
) then
1245 Item_Is_Output
:= True;
1248 -- Otherwise the variable has a default IN OUT mode
1251 Item_Is_Input
:= True;
1252 Item_Is_Output
:= True;
1261 procedure Role_Error
1262 (Item_Is_Input
: Boolean;
1263 Item_Is_Output
: Boolean)
1265 Error_Msg
: Name_Id
;
1270 -- When the item is not part of the input and the output set of
1271 -- the related subprogram, then it appears as extra in pragma
1272 -- [Refined_]Depends.
1274 if not Item_Is_Input
and then not Item_Is_Output
then
1275 Add_Item_To_Name_Buffer
(Item_Id
);
1276 Add_Str_To_Name_Buffer
1277 (" & cannot appear in dependence relation");
1279 Error_Msg
:= Name_Find
;
1280 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1282 Error_Msg_Name_1
:= Chars
(Spec_Id
);
1284 (Fix_Msg
(Spec_Id
, "\& is not part of the input or output "
1285 & "set of subprogram %"), Item
, Item_Id
);
1287 -- The mode of the item and its role in pragma [Refined_]Depends
1288 -- are in conflict. Construct a detailed message explaining the
1289 -- illegality (SPARK RM 6.1.5(5-6)).
1292 if Item_Is_Input
then
1293 Add_Str_To_Name_Buffer
("read-only");
1295 Add_Str_To_Name_Buffer
("write-only");
1298 Add_Char_To_Name_Buffer
(' ');
1299 Add_Item_To_Name_Buffer
(Item_Id
);
1300 Add_Str_To_Name_Buffer
(" & cannot appear as ");
1302 if Item_Is_Input
then
1303 Add_Str_To_Name_Buffer
("output");
1305 Add_Str_To_Name_Buffer
("input");
1308 Add_Str_To_Name_Buffer
(" in dependence relation");
1309 Error_Msg
:= Name_Find
;
1310 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1316 Item_Is_Input
: Boolean;
1317 Item_Is_Output
: Boolean;
1319 -- Start of processing for Check_Role
1322 Find_Role
(Item_Is_Input
, Item_Is_Output
);
1327 if not Item_Is_Input
then
1328 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1331 -- Self-referential item
1334 if not Item_Is_Input
or else not Item_Is_Output
then
1335 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1340 elsif not Item_Is_Output
then
1341 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1349 procedure Check_Usage
1350 (Subp_Items
: Elist_Id
;
1351 Used_Items
: Elist_Id
;
1354 procedure Usage_Error
(Item_Id
: Entity_Id
);
1355 -- Emit an error concerning the illegal usage of an item
1361 procedure Usage_Error
(Item_Id
: Entity_Id
) is
1362 Error_Msg
: Name_Id
;
1369 -- Unconstrained and tagged items are not part of the explicit
1370 -- input set of the related subprogram, they do not have to be
1371 -- present in a dependence relation and should not be flagged
1372 -- (SPARK RM 6.1.5(8)).
1374 if not Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1377 Add_Item_To_Name_Buffer
(Item_Id
);
1378 Add_Str_To_Name_Buffer
1379 (" & is missing from input dependence list");
1381 Error_Msg
:= Name_Find
;
1382 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1385 -- Output case (SPARK RM 6.1.5(10))
1390 Add_Item_To_Name_Buffer
(Item_Id
);
1391 Add_Str_To_Name_Buffer
1392 (" & is missing from output dependence list");
1394 Error_Msg
:= Name_Find
;
1395 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), N
, Item_Id
);
1403 Item_Id
: Entity_Id
;
1405 -- Start of processing for Check_Usage
1408 if No
(Subp_Items
) then
1412 -- Each input or output of the subprogram must appear in a dependency
1415 Elmt
:= First_Elmt
(Subp_Items
);
1416 while Present
(Elmt
) loop
1417 Item
:= Node
(Elmt
);
1419 if Nkind
(Item
) = N_Defining_Identifier
then
1422 Item_Id
:= Entity_Of
(Item
);
1425 -- The item does not appear in a dependency
1427 if Present
(Item_Id
)
1428 and then not Contains
(Used_Items
, Item_Id
)
1430 -- The current instance of a concurrent type behaves as a
1431 -- formal parameter (SPARK RM 6.1.4).
1433 if Is_Formal
(Item_Id
)
1434 or else Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
)
1436 Usage_Error
(Item_Id
);
1438 -- States and global objects are not used properly only when
1439 -- the subprogram is subject to pragma Global.
1441 elsif Global_Seen
then
1442 Usage_Error
(Item_Id
);
1450 ----------------------
1451 -- Normalize_Clause --
1452 ----------------------
1454 procedure Normalize_Clause
(Clause
: Node_Id
) is
1455 procedure Create_Or_Modify_Clause
1461 Multiple
: Boolean);
1462 -- Create a brand new clause to represent the self-reference or
1463 -- modify the input and/or output lists of an existing clause. Output
1464 -- denotes a self-referencial output. Outputs is the output list of a
1465 -- clause. Inputs is the input list of a clause. After denotes the
1466 -- clause after which the new clause is to be inserted. Flag In_Place
1467 -- should be set when normalizing the last output of an output list.
1468 -- Flag Multiple should be set when Output comes from a list with
1471 -----------------------------
1472 -- Create_Or_Modify_Clause --
1473 -----------------------------
1475 procedure Create_Or_Modify_Clause
1483 procedure Propagate_Output
1486 -- Handle the various cases of output propagation to the input
1487 -- list. Output denotes a self-referencial output item. Inputs
1488 -- is the input list of a clause.
1490 ----------------------
1491 -- Propagate_Output --
1492 ----------------------
1494 procedure Propagate_Output
1498 function In_Input_List
1500 Inputs
: List_Id
) return Boolean;
1501 -- Determine whether a particulat item appears in the input
1502 -- list of a clause.
1508 function In_Input_List
1510 Inputs
: List_Id
) return Boolean
1515 Elmt
:= First
(Inputs
);
1516 while Present
(Elmt
) loop
1517 if Entity_Of
(Elmt
) = Item
then
1529 Output_Id
: constant Entity_Id
:= Entity_Of
(Output
);
1532 -- Start of processing for Propagate_Output
1535 -- The clause is of the form:
1537 -- (Output =>+ null)
1539 -- Remove null input and replace it with a copy of the output:
1541 -- (Output => Output)
1543 if Nkind
(Inputs
) = N_Null
then
1544 Rewrite
(Inputs
, New_Copy_Tree
(Output
));
1546 -- The clause is of the form:
1548 -- (Output =>+ (Input1, ..., InputN))
1550 -- Determine whether the output is not already mentioned in the
1551 -- input list and if not, add it to the list of inputs:
1553 -- (Output => (Output, Input1, ..., InputN))
1555 elsif Nkind
(Inputs
) = N_Aggregate
then
1556 Grouped
:= Expressions
(Inputs
);
1558 if not In_Input_List
1562 Prepend_To
(Grouped
, New_Copy_Tree
(Output
));
1565 -- The clause is of the form:
1567 -- (Output =>+ Input)
1569 -- If the input does not mention the output, group the two
1572 -- (Output => (Output, Input))
1574 elsif Entity_Of
(Inputs
) /= Output_Id
then
1576 Make_Aggregate
(Loc
,
1577 Expressions
=> New_List
(
1578 New_Copy_Tree
(Output
),
1579 New_Copy_Tree
(Inputs
))));
1581 end Propagate_Output
;
1585 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
1586 New_Clause
: Node_Id
;
1588 -- Start of processing for Create_Or_Modify_Clause
1591 -- A null output depending on itself does not require any
1594 if Nkind
(Output
) = N_Null
then
1597 -- A function result cannot depend on itself because it cannot
1598 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1600 elsif Is_Attribute_Result
(Output
) then
1601 SPARK_Msg_N
("function result cannot depend on itself", Output
);
1605 -- When performing the transformation in place, simply add the
1606 -- output to the list of inputs (if not already there). This
1607 -- case arises when dealing with the last output of an output
1608 -- list. Perform the normalization in place to avoid generating
1609 -- a malformed tree.
1612 Propagate_Output
(Output
, Inputs
);
1614 -- A list with multiple outputs is slowly trimmed until only
1615 -- one element remains. When this happens, replace aggregate
1616 -- with the element itself.
1620 Rewrite
(Outputs
, Output
);
1626 -- Unchain the output from its output list as it will appear in
1627 -- a new clause. Note that we cannot simply rewrite the output
1628 -- as null because this will violate the semantics of pragma
1633 -- Generate a new clause of the form:
1634 -- (Output => Inputs)
1637 Make_Component_Association
(Loc
,
1638 Choices
=> New_List
(Output
),
1639 Expression
=> New_Copy_Tree
(Inputs
));
1641 -- The new clause contains replicated content that has already
1642 -- been analyzed. There is not need to reanalyze or renormalize
1645 Set_Analyzed
(New_Clause
);
1648 (Output
=> First
(Choices
(New_Clause
)),
1649 Inputs
=> Expression
(New_Clause
));
1651 Insert_After
(After
, New_Clause
);
1653 end Create_Or_Modify_Clause
;
1657 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
1659 Last_Output
: Node_Id
;
1660 Next_Output
: Node_Id
;
1663 -- Start of processing for Normalize_Clause
1666 -- A self-dependency appears as operator "+". Remove the "+" from the
1667 -- tree by moving the real inputs to their proper place.
1669 if Nkind
(Expression
(Clause
)) = N_Op_Plus
then
1670 Rewrite
(Expression
(Clause
), Right_Opnd
(Expression
(Clause
)));
1671 Inputs
:= Expression
(Clause
);
1673 -- Multiple outputs appear as an aggregate
1675 if Nkind
(Outputs
) = N_Aggregate
then
1676 Last_Output
:= Last
(Expressions
(Outputs
));
1678 Output
:= First
(Expressions
(Outputs
));
1679 while Present
(Output
) loop
1681 -- Normalization may remove an output from its list,
1682 -- preserve the subsequent output now.
1684 Next_Output
:= Next
(Output
);
1686 Create_Or_Modify_Clause
1691 In_Place
=> Output
= Last_Output
,
1694 Output
:= Next_Output
;
1700 Create_Or_Modify_Clause
1709 end Normalize_Clause
;
1713 Deps
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
1714 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
1718 Last_Clause
: Node_Id
;
1719 Restore_Scope
: Boolean := False;
1721 -- Start of processing for Analyze_Depends_In_Decl_Part
1724 -- Do not analyze the pragma multiple times
1726 if Is_Analyzed_Pragma
(N
) then
1730 -- Empty dependency list
1732 if Nkind
(Deps
) = N_Null
then
1734 -- Gather all states, objects and formal parameters that the
1735 -- subprogram may depend on. These items are obtained from the
1736 -- parameter profile or pragma [Refined_]Global (if available).
1738 Collect_Subprogram_Inputs_Outputs
1739 (Subp_Id
=> Subp_Id
,
1740 Subp_Inputs
=> Subp_Inputs
,
1741 Subp_Outputs
=> Subp_Outputs
,
1742 Global_Seen
=> Global_Seen
);
1744 -- Verify that every input or output of the subprogram appear in a
1747 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1748 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1749 Check_Function_Return
;
1751 -- Dependency clauses appear as component associations of an aggregate
1753 elsif Nkind
(Deps
) = N_Aggregate
then
1755 -- Do not attempt to perform analysis of a syntactically illegal
1756 -- clause as this will lead to misleading errors.
1758 if Has_Extra_Parentheses
(Deps
) then
1762 if Present
(Component_Associations
(Deps
)) then
1763 Last_Clause
:= Last
(Component_Associations
(Deps
));
1765 -- Gather all states, objects and formal parameters that the
1766 -- subprogram may depend on. These items are obtained from the
1767 -- parameter profile or pragma [Refined_]Global (if available).
1769 Collect_Subprogram_Inputs_Outputs
1770 (Subp_Id
=> Subp_Id
,
1771 Subp_Inputs
=> Subp_Inputs
,
1772 Subp_Outputs
=> Subp_Outputs
,
1773 Global_Seen
=> Global_Seen
);
1775 -- When pragma [Refined_]Depends appears on a single concurrent
1776 -- type, it is relocated to the anonymous object.
1778 if Is_Single_Concurrent_Object
(Spec_Id
) then
1781 -- Ensure that the formal parameters are visible when analyzing
1782 -- all clauses. This falls out of the general rule of aspects
1783 -- pertaining to subprogram declarations.
1785 elsif not In_Open_Scopes
(Spec_Id
) then
1786 Restore_Scope
:= True;
1787 Push_Scope
(Spec_Id
);
1789 if Ekind
(Spec_Id
) = E_Task_Type
then
1790 if Has_Discriminants
(Spec_Id
) then
1791 Install_Discriminants
(Spec_Id
);
1794 elsif Is_Generic_Subprogram
(Spec_Id
) then
1795 Install_Generic_Formals
(Spec_Id
);
1798 Install_Formals
(Spec_Id
);
1802 Clause
:= First
(Component_Associations
(Deps
));
1803 while Present
(Clause
) loop
1804 Errors
:= Serious_Errors_Detected
;
1806 -- The normalization mechanism may create extra clauses that
1807 -- contain replicated input and output names. There is no need
1808 -- to reanalyze them.
1810 if not Analyzed
(Clause
) then
1811 Set_Analyzed
(Clause
);
1813 Analyze_Dependency_Clause
1815 Is_Last
=> Clause
= Last_Clause
);
1818 -- Do not normalize a clause if errors were detected (count
1819 -- of Serious_Errors has increased) because the inputs and/or
1820 -- outputs may denote illegal items. Normalization is disabled
1821 -- in ASIS mode as it alters the tree by introducing new nodes
1822 -- similar to expansion.
1824 if Serious_Errors_Detected
= Errors
and then not ASIS_Mode
then
1825 Normalize_Clause
(Clause
);
1831 if Restore_Scope
then
1835 -- Verify that every input or output of the subprogram appear in a
1838 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1839 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1840 Check_Function_Return
;
1842 -- The dependency list is malformed. This is a syntax error, always
1846 Error_Msg_N
("malformed dependency relation", Deps
);
1850 -- The top level dependency relation is malformed. This is a syntax
1851 -- error, always report.
1854 Error_Msg_N
("malformed dependency relation", Deps
);
1858 -- Ensure that a state and a corresponding constituent do not appear
1859 -- together in pragma [Refined_]Depends.
1861 Check_State_And_Constituent_Use
1862 (States
=> States_Seen
,
1863 Constits
=> Constits_Seen
,
1867 Set_Is_Analyzed_Pragma
(N
);
1868 end Analyze_Depends_In_Decl_Part
;
1870 --------------------------------------------
1871 -- Analyze_External_Property_In_Decl_Part --
1872 --------------------------------------------
1874 procedure Analyze_External_Property_In_Decl_Part
1876 Expr_Val
: out Boolean)
1878 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
1879 Obj_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
1880 Obj_Id
: constant Entity_Id
:= Defining_Entity
(Obj_Decl
);
1886 -- Do not analyze the pragma multiple times
1888 if Is_Analyzed_Pragma
(N
) then
1892 Error_Msg_Name_1
:= Pragma_Name
(N
);
1894 -- An external property pragma must apply to an effectively volatile
1895 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1896 -- The check is performed at the end of the declarative region due to a
1897 -- possible out-of-order arrangement of pragmas:
1900 -- pragma Async_Readers (Obj);
1901 -- pragma Volatile (Obj);
1903 if not Is_Effectively_Volatile
(Obj_Id
) then
1905 ("external property % must apply to a volatile object", N
);
1908 -- Ensure that the Boolean expression (if present) is static. A missing
1909 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1913 if Present
(Arg1
) then
1914 Expr
:= Get_Pragma_Arg
(Arg1
);
1916 if Is_OK_Static_Expression
(Expr
) then
1917 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
1921 Set_Is_Analyzed_Pragma
(N
);
1922 end Analyze_External_Property_In_Decl_Part
;
1924 ---------------------------------
1925 -- Analyze_Global_In_Decl_Part --
1926 ---------------------------------
1928 procedure Analyze_Global_In_Decl_Part
(N
: Node_Id
) is
1929 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
1930 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
1931 Subp_Id
: constant Entity_Id
:= Defining_Entity
(Subp_Decl
);
1933 Constits_Seen
: Elist_Id
:= No_Elist
;
1934 -- A list containing the entities of all constituents processed so far.
1935 -- It aids in detecting illegal usage of a state and a corresponding
1936 -- constituent in pragma [Refinde_]Global.
1938 Seen
: Elist_Id
:= No_Elist
;
1939 -- A list containing the entities of all the items processed so far. It
1940 -- plays a role in detecting distinct entities.
1942 States_Seen
: Elist_Id
:= No_Elist
;
1943 -- A list containing the entities of all states processed so far. It
1944 -- helps in detecting illegal usage of a state and a corresponding
1945 -- constituent in pragma [Refined_]Global.
1947 In_Out_Seen
: Boolean := False;
1948 Input_Seen
: Boolean := False;
1949 Output_Seen
: Boolean := False;
1950 Proof_Seen
: Boolean := False;
1951 -- Flags used to verify the consistency of modes
1953 procedure Analyze_Global_List
1955 Global_Mode
: Name_Id
:= Name_Input
);
1956 -- Verify the legality of a single global list declaration. Global_Mode
1957 -- denotes the current mode in effect.
1959 -------------------------
1960 -- Analyze_Global_List --
1961 -------------------------
1963 procedure Analyze_Global_List
1965 Global_Mode
: Name_Id
:= Name_Input
)
1967 procedure Analyze_Global_Item
1969 Global_Mode
: Name_Id
);
1970 -- Verify the legality of a single global item declaration denoted by
1971 -- Item. Global_Mode denotes the current mode in effect.
1973 procedure Check_Duplicate_Mode
1975 Status
: in out Boolean);
1976 -- Flag Status denotes whether a particular mode has been seen while
1977 -- processing a global list. This routine verifies that Mode is not a
1978 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
1980 procedure Check_Mode_Restriction_In_Enclosing_Context
1982 Item_Id
: Entity_Id
);
1983 -- Verify that an item of mode In_Out or Output does not appear as an
1984 -- input in the Global aspect of an enclosing subprogram. If this is
1985 -- the case, emit an error. Item and Item_Id are respectively the
1986 -- item and its entity.
1988 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
);
1989 -- Mode denotes either In_Out or Output. Depending on the kind of the
1990 -- related subprogram, emit an error if those two modes apply to a
1991 -- function (SPARK RM 6.1.4(10)).
1993 -------------------------
1994 -- Analyze_Global_Item --
1995 -------------------------
1997 procedure Analyze_Global_Item
1999 Global_Mode
: Name_Id
)
2001 Item_Id
: Entity_Id
;
2004 -- Detect one of the following cases
2006 -- with Global => (null, Name)
2007 -- with Global => (Name_1, null, Name_2)
2008 -- with Global => (Name, null)
2010 if Nkind
(Item
) = N_Null
then
2011 SPARK_Msg_N
("cannot mix null and non-null global items", Item
);
2016 Resolve_State
(Item
);
2018 -- Find the entity of the item. If this is a renaming, climb the
2019 -- renaming chain to reach the root object. Renamings of non-
2020 -- entire objects do not yield an entity (Empty).
2022 Item_Id
:= Entity_Of
(Item
);
2024 if Present
(Item_Id
) then
2026 -- A global item may denote a formal parameter of an enclosing
2027 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
2028 -- provide a better error diagnostic.
2030 if Is_Formal
(Item_Id
) then
2031 if Scope
(Item_Id
) = Spec_Id
then
2033 (Fix_Msg
(Spec_Id
, "global item cannot reference "
2034 & "parameter of subprogram &"), Item
, Spec_Id
);
2038 -- A global item may denote a concurrent type as long as it is
2039 -- the current instance of an enclosing concurrent type
2040 -- (SPARK RM 6.1.4).
2042 elsif Ekind_In
(Item_Id
, E_Protected_Type
, E_Task_Type
) then
2043 if Is_CCT_Instance
(Item
) then
2045 -- Pragma [Refined_]Global associated with a protected
2046 -- subprogram cannot mention the current instance of a
2047 -- protected type because the instance behaves as a
2048 -- formal parameter.
2050 if Ekind
(Item_Id
) = E_Protected_Type
2051 and then Scope
(Spec_Id
) = Item_Id
2053 Error_Msg_Name_1
:= Chars
(Item_Id
);
2055 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2056 & "cannot reference current instance of protected "
2057 & "type %"), Item
, Spec_Id
);
2060 -- Pragma [Refined_]Global associated with a task type
2061 -- cannot mention the current instance of a task type
2062 -- because the instance behaves as a formal parameter.
2064 elsif Ekind
(Item_Id
) = E_Task_Type
2065 and then Spec_Id
= Item_Id
2067 Error_Msg_Name_1
:= Chars
(Item_Id
);
2069 (Fix_Msg
(Spec_Id
, "global item of subprogram & "
2070 & "cannot reference current instance of task type "
2071 & "%"), Item
, Spec_Id
);
2075 -- Otherwise the global item denotes a subtype mark that is
2076 -- not a current instance.
2080 ("invalid use of subtype mark in global list", Item
);
2084 -- A formal object may act as a global item inside a generic
2086 elsif Is_Formal_Object
(Item_Id
) then
2089 -- The only legal references are those to abstract states,
2090 -- objects and various kinds of constants (SPARK RM 6.1.4(4)).
2092 elsif not Ekind_In
(Item_Id
, E_Abstract_State
,
2099 ("global item must denote object, state or current "
2100 & "instance of concurrent type", Item
);
2104 -- State related checks
2106 if Ekind
(Item_Id
) = E_Abstract_State
then
2108 -- Package and subprogram bodies are instantiated
2109 -- individually in a separate compiler pass. Due to this
2110 -- mode of instantiation, the refinement of a state may
2111 -- no longer be visible when a subprogram body contract
2112 -- is instantiated. Since the generic template is legal,
2113 -- do not perform this check in the instance to circumvent
2116 if Is_Generic_Instance
(Spec_Id
) then
2119 -- An abstract state with visible refinement cannot appear
2120 -- in pragma [Refined_]Global as its place must be taken by
2121 -- some of its constituents (SPARK RM 6.1.4(7)).
2123 elsif Has_Visible_Refinement
(Item_Id
) then
2125 ("cannot mention state & in global refinement",
2127 SPARK_Msg_N
("\use its constituents instead", Item
);
2130 -- An external state cannot appear as a global item of a
2131 -- nonvolatile function (SPARK RM 7.1.3(8)).
2133 elsif Is_External_State
(Item_Id
)
2134 and then Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2135 and then not Is_Volatile_Function
(Spec_Id
)
2138 ("external state & cannot act as global item of "
2139 & "nonvolatile function", Item
, Item_Id
);
2142 -- If the reference to the abstract state appears in an
2143 -- enclosing package body that will eventually refine the
2144 -- state, record the reference for future checks.
2147 Record_Possible_Body_Reference
2148 (State_Id
=> Item_Id
,
2152 -- Constant related checks
2154 elsif Ekind
(Item_Id
) = E_Constant
then
2156 -- A constant is a read-only item, therefore it cannot act
2159 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2161 ("constant & cannot act as output", Item
, Item_Id
);
2165 -- Discriminant related checks
2167 elsif Ekind
(Item_Id
) = E_Discriminant
then
2169 -- A discriminant is a read-only item, therefore it cannot
2170 -- act as an output.
2172 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2174 ("discriminant & cannot act as output", Item
, Item_Id
);
2178 -- Loop parameter related checks
2180 elsif Ekind
(Item_Id
) = E_Loop_Parameter
then
2182 -- A loop parameter is a read-only item, therefore it cannot
2183 -- act as an output.
2185 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2187 ("loop parameter & cannot act as output",
2192 -- Variable related checks. These are only relevant when
2193 -- SPARK_Mode is on as they are not standard Ada legality
2196 elsif SPARK_Mode
= On
2197 and then Ekind
(Item_Id
) = E_Variable
2198 and then Is_Effectively_Volatile
(Item_Id
)
2200 -- An effectively volatile object cannot appear as a global
2201 -- item of a nonvolatile function (SPARK RM 7.1.3(8)).
2203 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
)
2204 and then not Is_Volatile_Function
(Spec_Id
)
2207 ("volatile object & cannot act as global item of a "
2208 & "function", Item
, Item_Id
);
2211 -- An effectively volatile object with external property
2212 -- Effective_Reads set to True must have mode Output or
2213 -- In_Out (SPARK RM 7.1.3(11)).
2215 elsif Effective_Reads_Enabled
(Item_Id
)
2216 and then Global_Mode
= Name_Input
2219 ("volatile object & with property Effective_Reads must "
2220 & "have mode In_Out or Output", Item
, Item_Id
);
2225 -- When the item renames an entire object, replace the item
2226 -- with a reference to the object.
2228 if Entity
(Item
) /= Item_Id
then
2229 Rewrite
(Item
, New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
2233 -- Some form of illegal construct masquerading as a name
2234 -- (SPARK RM 6.1.4(4)).
2238 ("global item must denote object, state or current instance "
2239 & "of concurrent type", Item
);
2243 -- Verify that an output does not appear as an input in an
2244 -- enclosing subprogram.
2246 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
2247 Check_Mode_Restriction_In_Enclosing_Context
(Item
, Item_Id
);
2250 -- The same entity might be referenced through various way.
2251 -- Check the entity of the item rather than the item itself
2252 -- (SPARK RM 6.1.4(10)).
2254 if Contains
(Seen
, Item_Id
) then
2255 SPARK_Msg_N
("duplicate global item", Item
);
2257 -- Add the entity of the current item to the list of processed
2261 Append_New_Elmt
(Item_Id
, Seen
);
2263 if Ekind
(Item_Id
) = E_Abstract_State
then
2264 Append_New_Elmt
(Item_Id
, States_Seen
);
2266 -- The variable may eventually become a constituent of a single
2267 -- protected/task type. Record the reference now and verify its
2268 -- legality when analyzing the contract of the variable
2271 elsif Ekind
(Item_Id
) = E_Variable
then
2272 Record_Possible_Part_Of_Reference
2277 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
2278 and then Present
(Encapsulating_State
(Item_Id
))
2280 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2283 end Analyze_Global_Item
;
2285 --------------------------
2286 -- Check_Duplicate_Mode --
2287 --------------------------
2289 procedure Check_Duplicate_Mode
2291 Status
: in out Boolean)
2295 SPARK_Msg_N
("duplicate global mode", Mode
);
2299 end Check_Duplicate_Mode
;
2301 -------------------------------------------------
2302 -- Check_Mode_Restriction_In_Enclosing_Context --
2303 -------------------------------------------------
2305 procedure Check_Mode_Restriction_In_Enclosing_Context
2307 Item_Id
: Entity_Id
)
2309 Context
: Entity_Id
;
2311 Inputs
: Elist_Id
:= No_Elist
;
2312 Outputs
: Elist_Id
:= No_Elist
;
2315 -- Traverse the scope stack looking for enclosing subprograms
2316 -- subject to pragma [Refined_]Global.
2318 Context
:= Scope
(Subp_Id
);
2319 while Present
(Context
) and then Context
/= Standard_Standard
loop
2320 if Is_Subprogram
(Context
)
2322 (Present
(Get_Pragma
(Context
, Pragma_Global
))
2324 Present
(Get_Pragma
(Context
, Pragma_Refined_Global
)))
2326 Collect_Subprogram_Inputs_Outputs
2327 (Subp_Id
=> Context
,
2328 Subp_Inputs
=> Inputs
,
2329 Subp_Outputs
=> Outputs
,
2330 Global_Seen
=> Dummy
);
2332 -- The item is classified as In_Out or Output but appears as
2333 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(11)).
2335 if Appears_In
(Inputs
, Item_Id
)
2336 and then not Appears_In
(Outputs
, Item_Id
)
2339 ("global item & cannot have mode In_Out or Output",
2343 (Fix_Msg
(Subp_Id
, "\item already appears as input of "
2344 & "subprogram &"), Item
, Context
);
2346 -- Stop the traversal once an error has been detected
2352 Context
:= Scope
(Context
);
2354 end Check_Mode_Restriction_In_Enclosing_Context
;
2356 ----------------------------------------
2357 -- Check_Mode_Restriction_In_Function --
2358 ----------------------------------------
2360 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
) is
2362 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
2364 ("global mode & is not applicable to functions", Mode
);
2366 end Check_Mode_Restriction_In_Function
;
2374 -- Start of processing for Analyze_Global_List
2377 if Nkind
(List
) = N_Null
then
2378 Set_Analyzed
(List
);
2380 -- Single global item declaration
2382 elsif Nkind_In
(List
, N_Expanded_Name
,
2384 N_Selected_Component
)
2386 Analyze_Global_Item
(List
, Global_Mode
);
2388 -- Simple global list or moded global list declaration
2390 elsif Nkind
(List
) = N_Aggregate
then
2391 Set_Analyzed
(List
);
2393 -- The declaration of a simple global list appear as a collection
2396 if Present
(Expressions
(List
)) then
2397 if Present
(Component_Associations
(List
)) then
2399 ("cannot mix moded and non-moded global lists", List
);
2402 Item
:= First
(Expressions
(List
));
2403 while Present
(Item
) loop
2404 Analyze_Global_Item
(Item
, Global_Mode
);
2408 -- The declaration of a moded global list appears as a collection
2409 -- of component associations where individual choices denote
2412 elsif Present
(Component_Associations
(List
)) then
2413 if Present
(Expressions
(List
)) then
2415 ("cannot mix moded and non-moded global lists", List
);
2418 Assoc
:= First
(Component_Associations
(List
));
2419 while Present
(Assoc
) loop
2420 Mode
:= First
(Choices
(Assoc
));
2422 if Nkind
(Mode
) = N_Identifier
then
2423 if Chars
(Mode
) = Name_In_Out
then
2424 Check_Duplicate_Mode
(Mode
, In_Out_Seen
);
2425 Check_Mode_Restriction_In_Function
(Mode
);
2427 elsif Chars
(Mode
) = Name_Input
then
2428 Check_Duplicate_Mode
(Mode
, Input_Seen
);
2430 elsif Chars
(Mode
) = Name_Output
then
2431 Check_Duplicate_Mode
(Mode
, Output_Seen
);
2432 Check_Mode_Restriction_In_Function
(Mode
);
2434 elsif Chars
(Mode
) = Name_Proof_In
then
2435 Check_Duplicate_Mode
(Mode
, Proof_Seen
);
2438 SPARK_Msg_N
("invalid mode selector", Mode
);
2442 SPARK_Msg_N
("invalid mode selector", Mode
);
2445 -- Items in a moded list appear as a collection of
2446 -- expressions. Reuse the existing machinery to analyze
2450 (List
=> Expression
(Assoc
),
2451 Global_Mode
=> Chars
(Mode
));
2459 raise Program_Error
;
2462 -- Any other attempt to declare a global item is illegal. This is a
2463 -- syntax error, always report.
2466 Error_Msg_N
("malformed global list", List
);
2468 end Analyze_Global_List
;
2472 Items
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
2474 Restore_Scope
: Boolean := False;
2476 -- Start of processing for Analyze_Global_In_Decl_Part
2479 -- Do not analyze the pragma multiple times
2481 if Is_Analyzed_Pragma
(N
) then
2485 -- There is nothing to be done for a null global list
2487 if Nkind
(Items
) = N_Null
then
2488 Set_Analyzed
(Items
);
2490 -- Analyze the various forms of global lists and items. Note that some
2491 -- of these may be malformed in which case the analysis emits error
2495 -- When pragma [Refined_]Global appears on a single concurrent type,
2496 -- it is relocated to the anonymous object.
2498 if Is_Single_Concurrent_Object
(Spec_Id
) then
2501 -- Ensure that the formal parameters are visible when processing an
2502 -- item. This falls out of the general rule of aspects pertaining to
2503 -- subprogram declarations.
2505 elsif not In_Open_Scopes
(Spec_Id
) then
2506 Restore_Scope
:= True;
2507 Push_Scope
(Spec_Id
);
2509 if Ekind
(Spec_Id
) = E_Task_Type
then
2510 if Has_Discriminants
(Spec_Id
) then
2511 Install_Discriminants
(Spec_Id
);
2514 elsif Is_Generic_Subprogram
(Spec_Id
) then
2515 Install_Generic_Formals
(Spec_Id
);
2518 Install_Formals
(Spec_Id
);
2522 Analyze_Global_List
(Items
);
2524 if Restore_Scope
then
2529 -- Ensure that a state and a corresponding constituent do not appear
2530 -- together in pragma [Refined_]Global.
2532 Check_State_And_Constituent_Use
2533 (States
=> States_Seen
,
2534 Constits
=> Constits_Seen
,
2537 Set_Is_Analyzed_Pragma
(N
);
2538 end Analyze_Global_In_Decl_Part
;
2540 --------------------------------------------
2541 -- Analyze_Initial_Condition_In_Decl_Part --
2542 --------------------------------------------
2544 procedure Analyze_Initial_Condition_In_Decl_Part
(N
: Node_Id
) is
2545 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2546 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2547 Expr
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
2549 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
2552 -- Do not analyze the pragma multiple times
2554 if Is_Analyzed_Pragma
(N
) then
2558 -- Set the Ghost mode in effect from the pragma. Due to the delayed
2559 -- analysis of the pragma, the Ghost mode at point of declaration and
2560 -- point of analysis may not necessarely be the same. Use the mode in
2561 -- effect at the point of declaration.
2565 -- The expression is preanalyzed because it has not been moved to its
2566 -- final place yet. A direct analysis may generate side effects and this
2567 -- is not desired at this point.
2569 Preanalyze_Assert_Expression
(Expr
, Standard_Boolean
);
2570 Ghost_Mode
:= Save_Ghost_Mode
;
2572 Set_Is_Analyzed_Pragma
(N
);
2573 end Analyze_Initial_Condition_In_Decl_Part
;
2575 --------------------------------------
2576 -- Analyze_Initializes_In_Decl_Part --
2577 --------------------------------------
2579 procedure Analyze_Initializes_In_Decl_Part
(N
: Node_Id
) is
2580 Pack_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2581 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
2583 Constits_Seen
: Elist_Id
:= No_Elist
;
2584 -- A list containing the entities of all constituents processed so far.
2585 -- It aids in detecting illegal usage of a state and a corresponding
2586 -- constituent in pragma Initializes.
2588 Items_Seen
: Elist_Id
:= No_Elist
;
2589 -- A list of all initialization items processed so far. This list is
2590 -- used to detect duplicate items.
2592 Non_Null_Seen
: Boolean := False;
2593 Null_Seen
: Boolean := False;
2594 -- Flags used to check the legality of a null initialization list
2596 States_And_Objs
: Elist_Id
:= No_Elist
;
2597 -- A list of all abstract states and objects declared in the visible
2598 -- declarations of the related package. This list is used to detect the
2599 -- legality of initialization items.
2601 States_Seen
: Elist_Id
:= No_Elist
;
2602 -- A list containing the entities of all states processed so far. It
2603 -- helps in detecting illegal usage of a state and a corresponding
2604 -- constituent in pragma Initializes.
2606 procedure Analyze_Initialization_Item
(Item
: Node_Id
);
2607 -- Verify the legality of a single initialization item
2609 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
);
2610 -- Verify the legality of a single initialization item followed by a
2611 -- list of input items.
2613 procedure Collect_States_And_Objects
;
2614 -- Inspect the visible declarations of the related package and gather
2615 -- the entities of all abstract states and objects in States_And_Objs.
2617 ---------------------------------
2618 -- Analyze_Initialization_Item --
2619 ---------------------------------
2621 procedure Analyze_Initialization_Item
(Item
: Node_Id
) is
2622 Item_Id
: Entity_Id
;
2625 -- Null initialization list
2627 if Nkind
(Item
) = N_Null
then
2629 SPARK_Msg_N
("multiple null initializations not allowed", Item
);
2631 elsif Non_Null_Seen
then
2633 ("cannot mix null and non-null initialization items", Item
);
2638 -- Initialization item
2641 Non_Null_Seen
:= True;
2645 ("cannot mix null and non-null initialization items", Item
);
2649 Resolve_State
(Item
);
2651 if Is_Entity_Name
(Item
) then
2652 Item_Id
:= Entity_Of
(Item
);
2654 if Ekind_In
(Item_Id
, E_Abstract_State
,
2658 -- The state or variable must be declared in the visible
2659 -- declarations of the package (SPARK RM 7.1.5(7)).
2661 if not Contains
(States_And_Objs
, Item_Id
) then
2662 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2664 ("initialization item & must appear in the visible "
2665 & "declarations of package %", Item
, Item_Id
);
2667 -- Detect a duplicate use of the same initialization item
2668 -- (SPARK RM 7.1.5(5)).
2670 elsif Contains
(Items_Seen
, Item_Id
) then
2671 SPARK_Msg_N
("duplicate initialization item", Item
);
2673 -- The item is legal, add it to the list of processed states
2677 Append_New_Elmt
(Item_Id
, Items_Seen
);
2679 if Ekind
(Item_Id
) = E_Abstract_State
then
2680 Append_New_Elmt
(Item_Id
, States_Seen
);
2683 if Present
(Encapsulating_State
(Item_Id
)) then
2684 Append_New_Elmt
(Item_Id
, Constits_Seen
);
2688 -- The item references something that is not a state or object
2689 -- (SPARK RM 7.1.5(3)).
2693 ("initialization item must denote object or state", Item
);
2696 -- Some form of illegal construct masquerading as a name
2697 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2701 ("initialization item must denote object or state", Item
);
2704 end Analyze_Initialization_Item
;
2706 ---------------------------------------------
2707 -- Analyze_Initialization_Item_With_Inputs --
2708 ---------------------------------------------
2710 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
) is
2711 Inputs_Seen
: Elist_Id
:= No_Elist
;
2712 -- A list of all inputs processed so far. This list is used to detect
2713 -- duplicate uses of an input.
2715 Non_Null_Seen
: Boolean := False;
2716 Null_Seen
: Boolean := False;
2717 -- Flags used to check the legality of an input list
2719 procedure Analyze_Input_Item
(Input
: Node_Id
);
2720 -- Verify the legality of a single input item
2722 ------------------------
2723 -- Analyze_Input_Item --
2724 ------------------------
2726 procedure Analyze_Input_Item
(Input
: Node_Id
) is
2727 Input_Id
: Entity_Id
;
2732 if Nkind
(Input
) = N_Null
then
2735 ("multiple null initializations not allowed", Item
);
2737 elsif Non_Null_Seen
then
2739 ("cannot mix null and non-null initialization item", Item
);
2747 Non_Null_Seen
:= True;
2751 ("cannot mix null and non-null initialization item", Item
);
2755 Resolve_State
(Input
);
2757 if Is_Entity_Name
(Input
) then
2758 Input_Id
:= Entity_Of
(Input
);
2760 if Ekind_In
(Input_Id
, E_Abstract_State
,
2767 -- The input cannot denote states or objects declared
2768 -- within the related package (SPARK RM 7.1.5(4)).
2770 if Within_Scope
(Input_Id
, Current_Scope
) then
2771 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2773 ("input item & cannot denote a visible object or "
2774 & "state of package %", Input
, Input_Id
);
2776 -- Detect a duplicate use of the same input item
2777 -- (SPARK RM 7.1.5(5)).
2779 elsif Contains
(Inputs_Seen
, Input_Id
) then
2780 SPARK_Msg_N
("duplicate input item", Input
);
2782 -- Input is legal, add it to the list of processed inputs
2785 Append_New_Elmt
(Input_Id
, Inputs_Seen
);
2787 if Ekind
(Input_Id
) = E_Abstract_State
then
2788 Append_New_Elmt
(Input_Id
, States_Seen
);
2791 if Ekind_In
(Input_Id
, E_Abstract_State
,
2794 and then Present
(Encapsulating_State
(Input_Id
))
2796 Append_New_Elmt
(Input_Id
, Constits_Seen
);
2800 -- The input references something that is not a state or an
2801 -- object (SPARK RM 7.1.5(3)).
2805 ("input item must denote object or state", Input
);
2808 -- Some form of illegal construct masquerading as a name
2809 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2813 ("input item must denote object or state", Input
);
2816 end Analyze_Input_Item
;
2820 Inputs
: constant Node_Id
:= Expression
(Item
);
2824 Name_Seen
: Boolean := False;
2825 -- A flag used to detect multiple item names
2827 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2830 -- Inspect the name of an item with inputs
2832 Elmt
:= First
(Choices
(Item
));
2833 while Present
(Elmt
) loop
2835 SPARK_Msg_N
("only one item allowed in initialization", Elmt
);
2838 Analyze_Initialization_Item
(Elmt
);
2844 -- Multiple input items appear as an aggregate
2846 if Nkind
(Inputs
) = N_Aggregate
then
2847 if Present
(Expressions
(Inputs
)) then
2848 Input
:= First
(Expressions
(Inputs
));
2849 while Present
(Input
) loop
2850 Analyze_Input_Item
(Input
);
2855 if Present
(Component_Associations
(Inputs
)) then
2857 ("inputs must appear in named association form", Inputs
);
2860 -- Single input item
2863 Analyze_Input_Item
(Inputs
);
2865 end Analyze_Initialization_Item_With_Inputs
;
2867 --------------------------------
2868 -- Collect_States_And_Objects --
2869 --------------------------------
2871 procedure Collect_States_And_Objects
is
2872 Pack_Spec
: constant Node_Id
:= Specification
(Pack_Decl
);
2876 -- Collect the abstract states defined in the package (if any)
2878 if Present
(Abstract_States
(Pack_Id
)) then
2879 States_And_Objs
:= New_Copy_Elist
(Abstract_States
(Pack_Id
));
2882 -- Collect all objects the appear in the visible declarations of the
2885 if Present
(Visible_Declarations
(Pack_Spec
)) then
2886 Decl
:= First
(Visible_Declarations
(Pack_Spec
));
2887 while Present
(Decl
) loop
2888 if Comes_From_Source
(Decl
)
2889 and then Nkind
(Decl
) = N_Object_Declaration
2891 Append_New_Elmt
(Defining_Entity
(Decl
), States_And_Objs
);
2897 end Collect_States_And_Objects
;
2901 Inits
: constant Node_Id
:= Expression
(Get_Argument
(N
, Pack_Id
));
2904 -- Start of processing for Analyze_Initializes_In_Decl_Part
2907 -- Do not analyze the pragma multiple times
2909 if Is_Analyzed_Pragma
(N
) then
2913 -- Nothing to do when the initialization list is empty
2915 if Nkind
(Inits
) = N_Null
then
2919 -- Single and multiple initialization clauses appear as an aggregate. If
2920 -- this is not the case, then either the parser or the analysis of the
2921 -- pragma failed to produce an aggregate.
2923 pragma Assert
(Nkind
(Inits
) = N_Aggregate
);
2925 -- Initialize the various lists used during analysis
2927 Collect_States_And_Objects
;
2929 if Present
(Expressions
(Inits
)) then
2930 Init
:= First
(Expressions
(Inits
));
2931 while Present
(Init
) loop
2932 Analyze_Initialization_Item
(Init
);
2937 if Present
(Component_Associations
(Inits
)) then
2938 Init
:= First
(Component_Associations
(Inits
));
2939 while Present
(Init
) loop
2940 Analyze_Initialization_Item_With_Inputs
(Init
);
2945 -- Ensure that a state and a corresponding constituent do not appear
2946 -- together in pragma Initializes.
2948 Check_State_And_Constituent_Use
2949 (States
=> States_Seen
,
2950 Constits
=> Constits_Seen
,
2953 Set_Is_Analyzed_Pragma
(N
);
2954 end Analyze_Initializes_In_Decl_Part
;
2956 ---------------------
2957 -- Analyze_Part_Of --
2958 ---------------------
2960 procedure Analyze_Part_Of
2962 Item_Id
: Entity_Id
;
2964 Encap_Id
: out Entity_Id
;
2965 Legal
: out Boolean)
2967 Encap_Typ
: Entity_Id
;
2968 Item_Decl
: Node_Id
;
2969 Pack_Id
: Entity_Id
;
2970 Placement
: State_Space_Kind
;
2971 Parent_Unit
: Entity_Id
;
2974 -- Assume that the indicator is illegal
2979 if Nkind_In
(Encap
, N_Expanded_Name
,
2981 N_Selected_Component
)
2984 Resolve_State
(Encap
);
2986 Encap_Id
:= Entity
(Encap
);
2988 -- The encapsulator is an abstract state
2990 if Ekind
(Encap_Id
) = E_Abstract_State
then
2993 -- The encapsulator is a single concurrent type (SPARK RM 9.3)
2995 elsif Is_Single_Concurrent_Object
(Encap_Id
) then
2998 -- Otherwise the encapsulator is not a legal choice
3002 ("indicator Part_Of must denote abstract state, single "
3003 & "protected type or single task type", Encap
);
3007 -- This is a syntax error, always report
3011 ("indicator Part_Of must denote abstract state, single protected "
3012 & "type or single task type", Encap
);
3016 -- Catch a case where indicator Part_Of denotes the abstract view of a
3017 -- variable which appears as an abstract state (SPARK RM 10.1.2 2).
3019 if From_Limited_With
(Encap_Id
)
3020 and then Present
(Non_Limited_View
(Encap_Id
))
3021 and then Ekind
(Non_Limited_View
(Encap_Id
)) = E_Variable
3023 SPARK_Msg_N
("indicator Part_Of must denote abstract state", Encap
);
3024 SPARK_Msg_N
("\& denotes abstract view of object", Encap
);
3028 -- The encapsulator is an abstract state
3030 if Ekind
(Encap_Id
) = E_Abstract_State
then
3032 -- Determine where the object, package instantiation or state lives
3033 -- with respect to the enclosing packages or package bodies.
3035 Find_Placement_In_State_Space
3036 (Item_Id
=> Item_Id
,
3037 Placement
=> Placement
,
3038 Pack_Id
=> Pack_Id
);
3040 -- The item appears in a non-package construct with a declarative
3041 -- part (subprogram, block, etc). As such, the item is not allowed
3042 -- to be a part of an encapsulating state because the item is not
3045 if Placement
= Not_In_Package
then
3047 ("indicator Part_Of cannot appear in this context "
3048 & "(SPARK RM 7.2.6(5))", Indic
);
3049 Error_Msg_Name_1
:= Chars
(Scope
(Encap_Id
));
3051 ("\& is not part of the hidden state of package %",
3054 -- The item appears in the visible state space of some package. In
3055 -- general this scenario does not warrant Part_Of except when the
3056 -- package is a private child unit and the encapsulating state is
3057 -- declared in a parent unit or a public descendant of that parent
3060 elsif Placement
= Visible_State_Space
then
3061 if Is_Child_Unit
(Pack_Id
)
3062 and then Is_Private_Descendant
(Pack_Id
)
3064 -- A variable or state abstraction which is part of the visible
3065 -- state of a private child unit (or one of its public
3066 -- descendants) must have its Part_Of indicator specified. The
3067 -- Part_Of indicator must denote a state abstraction declared
3068 -- by either the parent unit of the private unit or by a public
3069 -- descendant of that parent unit.
3071 -- Find nearest private ancestor (which can be the current unit
3074 Parent_Unit
:= Pack_Id
;
3075 while Present
(Parent_Unit
) loop
3078 (Parent
(Unit_Declaration_Node
(Parent_Unit
)));
3079 Parent_Unit
:= Scope
(Parent_Unit
);
3082 Parent_Unit
:= Scope
(Parent_Unit
);
3084 if not Is_Child_Or_Sibling
(Pack_Id
, Scope
(Encap_Id
)) then
3086 ("indicator Part_Of must denote abstract state or public "
3087 & "descendant of & (SPARK RM 7.2.6(3))",
3088 Indic
, Parent_Unit
);
3090 elsif Scope
(Encap_Id
) = Parent_Unit
3092 (Is_Ancestor_Package
(Parent_Unit
, Scope
(Encap_Id
))
3093 and then not Is_Private_Descendant
(Scope
(Encap_Id
)))
3099 ("indicator Part_Of must denote abstract state or public "
3100 & "descendant of & (SPARK RM 7.2.6(3))",
3101 Indic
, Parent_Unit
);
3104 -- Indicator Part_Of is not needed when the related package is not
3105 -- a private child unit or a public descendant thereof.
3109 ("indicator Part_Of cannot appear in this context "
3110 & "(SPARK RM 7.2.6(5))", Indic
);
3111 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3113 ("\& is declared in the visible part of package %",
3117 -- When the item appears in the private state space of a package, the
3118 -- encapsulating state must be declared in the same package.
3120 elsif Placement
= Private_State_Space
then
3121 if Scope
(Encap_Id
) /= Pack_Id
then
3123 ("indicator Part_Of must designate an abstract state of "
3124 & "package & (SPARK RM 7.2.6(2))", Indic
, Pack_Id
);
3125 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3127 ("\& is declared in the private part of package %",
3131 -- Items declared in the body state space of a package do not need
3132 -- Part_Of indicators as the refinement has already been seen.
3136 ("indicator Part_Of cannot appear in this context "
3137 & "(SPARK RM 7.2.6(5))", Indic
);
3139 if Scope
(Encap_Id
) = Pack_Id
then
3140 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3142 ("\& is declared in the body of package %", Indic
, Item_Id
);
3146 -- The encapsulator is a single concurrent type
3149 Encap_Typ
:= Etype
(Encap_Id
);
3151 -- Only abstract states and variables can act as constituents of an
3152 -- encapsulating single concurrent type.
3154 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
3157 -- The constituent is a constant
3159 elsif Ekind
(Item_Id
) = E_Constant
then
3160 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3162 (Fix_Msg
(Encap_Typ
, "consant & cannot act as constituent of "
3163 & "single protected type %"), Indic
, Item_Id
);
3165 -- The constituent is a package instantiation
3168 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3170 (Fix_Msg
(Encap_Typ
, "package instantiation & cannot act as "
3171 & "constituent of single protected type %"), Indic
, Item_Id
);
3174 -- When the item denotes an abstract state of a nested package, use
3175 -- the declaration of the package to detect proper placement.
3180 -- with Abstract_State => (State with Part_Of => T)
3182 if Ekind
(Item_Id
) = E_Abstract_State
then
3183 Item_Decl
:= Unit_Declaration_Node
(Scope
(Item_Id
));
3185 Item_Decl
:= Declaration_Node
(Item_Id
);
3188 -- Both the item and its encapsulating single concurrent type must
3189 -- appear in the same declarative region (SPARK RM 9.3). Note that
3190 -- privacy is ignored.
3192 if Parent
(Item_Decl
) /= Parent
(Declaration_Node
(Encap_Id
)) then
3193 Error_Msg_Name_1
:= Chars
(Encap_Id
);
3195 (Fix_Msg
(Encap_Typ
, "constituent & must be declared "
3196 & "immediately within the same region as single protected "
3197 & "type %"), Indic
, Item_Id
);
3202 end Analyze_Part_Of
;
3204 ----------------------------------
3205 -- Analyze_Part_Of_In_Decl_Part --
3206 ----------------------------------
3208 procedure Analyze_Part_Of_In_Decl_Part
3210 Freeze_Id
: Entity_Id
:= Empty
)
3212 Encap
: constant Node_Id
:=
3213 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
3214 Errors
: constant Nat
:= Serious_Errors_Detected
;
3215 Var_Decl
: constant Node_Id
:= Find_Related_Context
(N
);
3216 Var_Id
: constant Entity_Id
:= Defining_Entity
(Var_Decl
);
3217 Encap_Id
: Entity_Id
;
3221 -- Detect any discrepancies between the placement of the variable with
3222 -- respect to general state space and the encapsulating state or single
3229 Encap_Id
=> Encap_Id
,
3232 -- The Part_Of indicator turns the variable into a constituent of the
3233 -- encapsulating state or single concurrent type.
3236 pragma Assert
(Present
(Encap_Id
));
3238 Append_Elmt
(Var_Id
, Part_Of_Constituents
(Encap_Id
));
3239 Set_Encapsulating_State
(Var_Id
, Encap_Id
);
3242 -- Emit a clarification message when the encapsulator is undefined,
3243 -- possibly due to contract "freezing".
3245 if Errors
/= Serious_Errors_Detected
3246 and then Present
(Freeze_Id
)
3247 and then Has_Undefined_Reference
(Encap
)
3249 Contract_Freeze_Error
(Var_Id
, Freeze_Id
);
3251 end Analyze_Part_Of_In_Decl_Part
;
3253 --------------------
3254 -- Analyze_Pragma --
3255 --------------------
3257 procedure Analyze_Pragma
(N
: Node_Id
) is
3258 Loc
: constant Source_Ptr
:= Sloc
(N
);
3259 Prag_Id
: Pragma_Id
;
3262 -- Name of the source pragma, or name of the corresponding aspect for
3263 -- pragmas which originate in a source aspect. In the latter case, the
3264 -- name may be different from the pragma name.
3266 Pragma_Exit
: exception;
3267 -- This exception is used to exit pragma processing completely. It
3268 -- is used when an error is detected, and no further processing is
3269 -- required. It is also used if an earlier error has left the tree in
3270 -- a state where the pragma should not be processed.
3273 -- Number of pragma argument associations
3279 -- First four pragma arguments (pragma argument association nodes, or
3280 -- Empty if the corresponding argument does not exist).
3282 type Name_List
is array (Natural range <>) of Name_Id
;
3283 type Args_List
is array (Natural range <>) of Node_Id
;
3284 -- Types used for arguments to Check_Arg_Order and Gather_Associations
3286 -----------------------
3287 -- Local Subprograms --
3288 -----------------------
3290 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
);
3291 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
3292 -- get the given string argument, and place it in Name_Buffer, adding
3293 -- leading and trailing asterisks if they are not already present. The
3294 -- caller has already checked that Arg is a static string expression.
3296 procedure Ada_2005_Pragma
;
3297 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
3298 -- Ada 95 mode, these are implementation defined pragmas, so should be
3299 -- caught by the No_Implementation_Pragmas restriction.
3301 procedure Ada_2012_Pragma
;
3302 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
3303 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
3304 -- should be caught by the No_Implementation_Pragmas restriction.
3306 procedure Analyze_Depends_Global
3307 (Spec_Id
: out Entity_Id
;
3308 Subp_Decl
: out Node_Id
;
3309 Legal
: out Boolean);
3310 -- Subsidiary to the analysis of pragmas Depends and Global. Verify the
3311 -- legality of the placement and related context of the pragma. Spec_Id
3312 -- is the entity of the related subprogram. Subp_Decl is the declaration
3313 -- of the related subprogram. Sets flag Legal when the pragma is legal.
3315 procedure Analyze_If_Present
(Id
: Pragma_Id
);
3316 -- Inspect the remainder of the list containing pragma N and look for
3317 -- a pragma that matches Id. If found, analyze the pragma.
3319 procedure Analyze_Pre_Post_Condition
;
3320 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
3322 procedure Analyze_Refined_Depends_Global_Post
3323 (Spec_Id
: out Entity_Id
;
3324 Body_Id
: out Entity_Id
;
3325 Legal
: out Boolean);
3326 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
3327 -- Refined_Global and Refined_Post. Verify the legality of the placement
3328 -- and related context of the pragma. Spec_Id is the entity of the
3329 -- related subprogram. Body_Id is the entity of the subprogram body.
3330 -- Flag Legal is set when the pragma is legal.
3332 procedure Check_Ada_83_Warning
;
3333 -- Issues a warning message for the current pragma if operating in Ada
3334 -- 83 mode (used for language pragmas that are not a standard part of
3335 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
3338 procedure Check_Arg_Count
(Required
: Nat
);
3339 -- Check argument count for pragma is equal to given parameter. If not,
3340 -- then issue an error message and raise Pragma_Exit.
3342 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
3343 -- Arg which can either be a pragma argument association, in which case
3344 -- the check is applied to the expression of the association or an
3345 -- expression directly.
3347 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
);
3348 -- Check that an argument has the right form for an EXTERNAL_NAME
3349 -- parameter of an extended import/export pragma. The rule is that the
3350 -- name must be an identifier or string literal (in Ada 83 mode) or a
3351 -- static string expression (in Ada 95 mode).
3353 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
);
3354 -- Check the specified argument Arg to make sure that it is an
3355 -- identifier. If not give error and raise Pragma_Exit.
3357 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
);
3358 -- Check the specified argument Arg to make sure that it is an integer
3359 -- literal. If not give error and raise Pragma_Exit.
3361 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
);
3362 -- Check the specified argument Arg to make sure that it has the proper
3363 -- syntactic form for a local name and meets the semantic requirements
3364 -- for a local name. The local name is analyzed as part of the
3365 -- processing for this call. In addition, the local name is required
3366 -- to represent an entity at the library level.
3368 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
);
3369 -- Check the specified argument Arg to make sure that it has the proper
3370 -- syntactic form for a local name and meets the semantic requirements
3371 -- for a local name. The local name is analyzed as part of the
3372 -- processing for this call.
3374 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
);
3375 -- Check the specified argument Arg to make sure that it is a valid
3376 -- locking policy name. If not give error and raise Pragma_Exit.
3378 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
);
3379 -- Check the specified argument Arg to make sure that it is a valid
3380 -- elaboration policy name. If not give error and raise Pragma_Exit.
3382 procedure Check_Arg_Is_One_Of
3385 procedure Check_Arg_Is_One_Of
3387 N1
, N2
, N3
: Name_Id
);
3388 procedure Check_Arg_Is_One_Of
3390 N1
, N2
, N3
, N4
: Name_Id
);
3391 procedure Check_Arg_Is_One_Of
3393 N1
, N2
, N3
, N4
, N5
: Name_Id
);
3394 -- Check the specified argument Arg to make sure that it is an
3395 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
3396 -- present). If not then give error and raise Pragma_Exit.
3398 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
);
3399 -- Check the specified argument Arg to make sure that it is a valid
3400 -- queuing policy name. If not give error and raise Pragma_Exit.
3402 procedure Check_Arg_Is_OK_Static_Expression
3404 Typ
: Entity_Id
:= Empty
);
3405 -- Check the specified argument Arg to make sure that it is a static
3406 -- expression of the given type (i.e. it will be analyzed and resolved
3407 -- using this type, which can be any valid argument to Resolve, e.g.
3408 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3409 -- Typ is left Empty, then any static expression is allowed. Includes
3410 -- checking that the argument does not raise Constraint_Error.
3412 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
);
3413 -- Check the specified argument Arg to make sure that it is a valid task
3414 -- dispatching policy name. If not give error and raise Pragma_Exit.
3416 procedure Check_Arg_Order
(Names
: Name_List
);
3417 -- Checks for an instance of two arguments with identifiers for the
3418 -- current pragma which are not in the sequence indicated by Names,
3419 -- and if so, generates a fatal message about bad order of arguments.
3421 procedure Check_At_Least_N_Arguments
(N
: Nat
);
3422 -- Check there are at least N arguments present
3424 procedure Check_At_Most_N_Arguments
(N
: Nat
);
3425 -- Check there are no more than N arguments present
3427 procedure Check_Component
3430 In_Variant_Part
: Boolean := False);
3431 -- Examine an Unchecked_Union component for correct use of per-object
3432 -- constrained subtypes, and for restrictions on finalizable components.
3433 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
3434 -- should be set when Comp comes from a record variant.
3436 procedure Check_Duplicate_Pragma
(E
: Entity_Id
);
3437 -- Check if a rep item of the same name as the current pragma is already
3438 -- chained as a rep pragma to the given entity. If so give a message
3439 -- about the duplicate, and then raise Pragma_Exit so does not return.
3440 -- Note that if E is a type, then this routine avoids flagging a pragma
3441 -- which applies to a parent type from which E is derived.
3443 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
);
3444 -- Nam is an N_String_Literal node containing the external name set by
3445 -- an Import or Export pragma (or extended Import or Export pragma).
3446 -- This procedure checks for possible duplications if this is the export
3447 -- case, and if found, issues an appropriate error message.
3449 procedure Check_Expr_Is_OK_Static_Expression
3451 Typ
: Entity_Id
:= Empty
);
3452 -- Check the specified expression Expr to make sure that it is a static
3453 -- expression of the given type (i.e. it will be analyzed and resolved
3454 -- using this type, which can be any valid argument to Resolve, e.g.
3455 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
3456 -- Typ is left Empty, then any static expression is allowed. Includes
3457 -- checking that the expression does not raise Constraint_Error.
3459 procedure Check_First_Subtype
(Arg
: Node_Id
);
3460 -- Checks that Arg, whose expression is an entity name, references a
3463 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3464 -- Checks that the given argument has an identifier, and if so, requires
3465 -- it to match the given identifier name. If there is no identifier, or
3466 -- a non-matching identifier, then an error message is given and
3467 -- Pragma_Exit is raised.
3469 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
);
3470 -- Checks that the given argument has an identifier, and if so, requires
3471 -- it to match one of the given identifier names. If there is no
3472 -- identifier, or a non-matching identifier, then an error message is
3473 -- given and Pragma_Exit is raised.
3475 procedure Check_In_Main_Program
;
3476 -- Common checks for pragmas that appear within a main program
3477 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
3479 procedure Check_Interrupt_Or_Attach_Handler
;
3480 -- Common processing for first argument of pragma Interrupt_Handler or
3481 -- pragma Attach_Handler.
3483 procedure Check_Loop_Pragma_Placement
;
3484 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
3485 -- appear immediately within a construct restricted to loops, and that
3486 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
3488 procedure Check_Is_In_Decl_Part_Or_Package_Spec
;
3489 -- Check that pragma appears in a declarative part, or in a package
3490 -- specification, i.e. that it does not occur in a statement sequence
3493 procedure Check_No_Identifier
(Arg
: Node_Id
);
3494 -- Checks that the given argument does not have an identifier. If
3495 -- an identifier is present, then an error message is issued, and
3496 -- Pragma_Exit is raised.
3498 procedure Check_No_Identifiers
;
3499 -- Checks that none of the arguments to the pragma has an identifier.
3500 -- If any argument has an identifier, then an error message is issued,
3501 -- and Pragma_Exit is raised.
3503 procedure Check_No_Link_Name
;
3504 -- Checks that no link name is specified
3506 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
3507 -- Checks if the given argument has an identifier, and if so, requires
3508 -- it to match the given identifier name. If there is a non-matching
3509 -- identifier, then an error message is given and Pragma_Exit is raised.
3511 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String);
3512 -- Checks if the given argument has an identifier, and if so, requires
3513 -- it to match the given identifier name. If there is a non-matching
3514 -- identifier, then an error message is given and Pragma_Exit is raised.
3515 -- In this version of the procedure, the identifier name is given as
3516 -- a string with lower case letters.
3518 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
);
3519 -- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers,
3520 -- Constant_After_Elaboration, Effective_Reads, Effective_Writes,
3521 -- Extensions_Visible and Volatile_Function. Ensure that expression Expr
3522 -- is an OK static boolean expression. Emit an error if this is not the
3525 procedure Check_Static_Constraint
(Constr
: Node_Id
);
3526 -- Constr is a constraint from an N_Subtype_Indication node from a
3527 -- component constraint in an Unchecked_Union type. This routine checks
3528 -- that the constraint is static as required by the restrictions for
3531 procedure Check_Valid_Configuration_Pragma
;
3532 -- Legality checks for placement of a configuration pragma
3534 procedure Check_Valid_Library_Unit_Pragma
;
3535 -- Legality checks for library unit pragmas. A special case arises for
3536 -- pragmas in generic instances that come from copies of the original
3537 -- library unit pragmas in the generic templates. In the case of other
3538 -- than library level instantiations these can appear in contexts which
3539 -- would normally be invalid (they only apply to the original template
3540 -- and to library level instantiations), and they are simply ignored,
3541 -- which is implemented by rewriting them as null statements.
3543 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
);
3544 -- Check an Unchecked_Union variant for lack of nested variants and
3545 -- presence of at least one component. UU_Typ is the related Unchecked_
3548 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
);
3549 -- Subsidiary routine to the processing of pragmas Abstract_State,
3550 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
3551 -- Refined_Global and Refined_State. Transform argument Arg into
3552 -- an aggregate if not one already. N_Null is never transformed.
3553 -- Arg may denote an aspect specification or a pragma argument
3556 procedure Error_Pragma
(Msg
: String);
3557 pragma No_Return
(Error_Pragma
);
3558 -- Outputs error message for current pragma. The message contains a %
3559 -- that will be replaced with the pragma name, and the flag is placed
3560 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
3561 -- calls Fix_Error (see spec of that procedure for details).
3563 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
);
3564 pragma No_Return
(Error_Pragma_Arg
);
3565 -- Outputs error message for current pragma. The message may contain
3566 -- a % that will be replaced with the pragma name. The parameter Arg
3567 -- may either be a pragma argument association, in which case the flag
3568 -- is placed on the expression of this association, or an expression,
3569 -- in which case the flag is placed directly on the expression. The
3570 -- message is placed using Error_Msg_N, so the message may also contain
3571 -- an & insertion character which will reference the given Arg value.
3572 -- After placing the message, Pragma_Exit is raised. Note: this routine
3573 -- calls Fix_Error (see spec of that procedure for details).
3575 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
);
3576 pragma No_Return
(Error_Pragma_Arg
);
3577 -- Similar to above form of Error_Pragma_Arg except that two messages
3578 -- are provided, the second is a continuation comment starting with \.
3580 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
);
3581 pragma No_Return
(Error_Pragma_Arg_Ident
);
3582 -- Outputs error message for current pragma. The message may contain a %
3583 -- that will be replaced with the pragma name. The parameter Arg must be
3584 -- a pragma argument association with a non-empty identifier (i.e. its
3585 -- Chars field must be set), and the error message is placed on the
3586 -- identifier. The message is placed using Error_Msg_N so the message
3587 -- may also contain an & insertion character which will reference
3588 -- the identifier. After placing the message, Pragma_Exit is raised.
3589 -- Note: this routine calls Fix_Error (see spec of that procedure for
3592 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
);
3593 pragma No_Return
(Error_Pragma_Ref
);
3594 -- Outputs error message for current pragma. The message may contain
3595 -- a % that will be replaced with the pragma name. The parameter Ref
3596 -- must be an entity whose name can be referenced by & and sloc by #.
3597 -- After placing the message, Pragma_Exit is raised. Note: this routine
3598 -- calls Fix_Error (see spec of that procedure for details).
3600 function Find_Lib_Unit_Name
return Entity_Id
;
3601 -- Used for a library unit pragma to find the entity to which the
3602 -- library unit pragma applies, returns the entity found.
3604 procedure Find_Program_Unit_Name
(Id
: Node_Id
);
3605 -- If the pragma is a compilation unit pragma, the id must denote the
3606 -- compilation unit in the same compilation, and the pragma must appear
3607 -- in the list of preceding or trailing pragmas. If it is a program
3608 -- unit pragma that is not a compilation unit pragma, then the
3609 -- identifier must be visible.
3611 function Find_Unique_Parameterless_Procedure
3613 Arg
: Node_Id
) return Entity_Id
;
3614 -- Used for a procedure pragma to find the unique parameterless
3615 -- procedure identified by Name, returns it if it exists, otherwise
3616 -- errors out and uses Arg as the pragma argument for the message.
3618 function Fix_Error
(Msg
: String) return String;
3619 -- This is called prior to issuing an error message. Msg is the normal
3620 -- error message issued in the pragma case. This routine checks for the
3621 -- case of a pragma coming from an aspect in the source, and returns a
3622 -- message suitable for the aspect case as follows:
3624 -- Each substring "pragma" is replaced by "aspect"
3626 -- If "argument of" is at the start of the error message text, it is
3627 -- replaced by "entity for".
3629 -- If "argument" is at the start of the error message text, it is
3630 -- replaced by "entity".
3632 -- So for example, "argument of pragma X must be discrete type"
3633 -- returns "entity for aspect X must be a discrete type".
3635 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3636 -- be different from the pragma name). If the current pragma results
3637 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3638 -- original pragma name.
3640 procedure Gather_Associations
3642 Args
: out Args_List
);
3643 -- This procedure is used to gather the arguments for a pragma that
3644 -- permits arbitrary ordering of parameters using the normal rules
3645 -- for named and positional parameters. The Names argument is a list
3646 -- of Name_Id values that corresponds to the allowed pragma argument
3647 -- association identifiers in order. The result returned in Args is
3648 -- a list of corresponding expressions that are the pragma arguments.
3649 -- Note that this is a list of expressions, not of pragma argument
3650 -- associations (Gather_Associations has completely checked all the
3651 -- optional identifiers when it returns). An entry in Args is Empty
3652 -- on return if the corresponding argument is not present.
3654 procedure GNAT_Pragma
;
3655 -- Called for all GNAT defined pragmas to check the relevant restriction
3656 -- (No_Implementation_Pragmas).
3658 function Is_Before_First_Decl
3659 (Pragma_Node
: Node_Id
;
3660 Decls
: List_Id
) return Boolean;
3661 -- Return True if Pragma_Node is before the first declarative item in
3662 -- Decls where Decls is the list of declarative items.
3664 function Is_Configuration_Pragma
return Boolean;
3665 -- Determines if the placement of the current pragma is appropriate
3666 -- for a configuration pragma.
3668 function Is_In_Context_Clause
return Boolean;
3669 -- Returns True if pragma appears within the context clause of a unit,
3670 -- and False for any other placement (does not generate any messages).
3672 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean;
3673 -- Analyzes the argument, and determines if it is a static string
3674 -- expression, returns True if so, False if non-static or not String.
3675 -- A special case is that a string literal returns True in Ada 83 mode
3676 -- (which has no such thing as static string expressions). Note that
3677 -- the call analyzes its argument, so this cannot be used for the case
3678 -- where an identifier might not be declared.
3680 procedure Pragma_Misplaced
;
3681 pragma No_Return
(Pragma_Misplaced
);
3682 -- Issue fatal error message for misplaced pragma
3684 procedure Process_Atomic_Independent_Shared_Volatile
;
3685 -- Common processing for pragmas Atomic, Independent, Shared, Volatile,
3686 -- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma
3687 -- and treated as being identical in effect to pragma Atomic.
3689 procedure Process_Compile_Time_Warning_Or_Error
;
3690 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3692 procedure Process_Convention
3693 (C
: out Convention_Id
;
3694 Ent
: out Entity_Id
);
3695 -- Common processing for Convention, Interface, Import and Export.
3696 -- Checks first two arguments of pragma, and sets the appropriate
3697 -- convention value in the specified entity or entities. On return
3698 -- C is the convention, Ent is the referenced entity.
3700 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
);
3701 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3702 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3704 procedure Process_Extended_Import_Export_Object_Pragma
3705 (Arg_Internal
: Node_Id
;
3706 Arg_External
: Node_Id
;
3707 Arg_Size
: Node_Id
);
3708 -- Common processing for the pragmas Import/Export_Object. The three
3709 -- arguments correspond to the three named parameters of the pragmas. An
3710 -- argument is empty if the corresponding parameter is not present in
3713 procedure Process_Extended_Import_Export_Internal_Arg
3714 (Arg_Internal
: Node_Id
:= Empty
);
3715 -- Common processing for all extended Import and Export pragmas. The
3716 -- argument is the pragma parameter for the Internal argument. If
3717 -- Arg_Internal is empty or inappropriate, an error message is posted.
3718 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3719 -- set to identify the referenced entity.
3721 procedure Process_Extended_Import_Export_Subprogram_Pragma
3722 (Arg_Internal
: Node_Id
;
3723 Arg_External
: Node_Id
;
3724 Arg_Parameter_Types
: Node_Id
;
3725 Arg_Result_Type
: Node_Id
:= Empty
;
3726 Arg_Mechanism
: Node_Id
;
3727 Arg_Result_Mechanism
: Node_Id
:= Empty
);
3728 -- Common processing for all extended Import and Export pragmas applying
3729 -- to subprograms. The caller omits any arguments that do not apply to
3730 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3731 -- only in the Import_Function and Export_Function cases). The argument
3732 -- names correspond to the allowed pragma association identifiers.
3734 procedure Process_Generic_List
;
3735 -- Common processing for Share_Generic and Inline_Generic
3737 procedure Process_Import_Or_Interface
;
3738 -- Common processing for Import or Interface
3740 procedure Process_Import_Predefined_Type
;
3741 -- Processing for completing a type with pragma Import. This is used
3742 -- to declare types that match predefined C types, especially for cases
3743 -- without corresponding Ada predefined type.
3745 type Inline_Status
is (Suppressed
, Disabled
, Enabled
);
3746 -- Inline status of a subprogram, indicated as follows:
3747 -- Suppressed: inlining is suppressed for the subprogram
3748 -- Disabled: no inlining is requested for the subprogram
3749 -- Enabled: inlining is requested/required for the subprogram
3751 procedure Process_Inline
(Status
: Inline_Status
);
3752 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3753 -- indicates the inline status specified by the pragma.
3755 procedure Process_Interface_Name
3756 (Subprogram_Def
: Entity_Id
;
3758 Link_Arg
: Node_Id
);
3759 -- Given the last two arguments of pragma Import, pragma Export, or
3760 -- pragma Interface_Name, performs validity checks and sets the
3761 -- Interface_Name field of the given subprogram entity to the
3762 -- appropriate external or link name, depending on the arguments given.
3763 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3764 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3765 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3766 -- nor Link_Arg is present, the interface name is set to the default
3767 -- from the subprogram name.
3769 procedure Process_Interrupt_Or_Attach_Handler
;
3770 -- Common processing for Interrupt and Attach_Handler pragmas
3772 procedure Process_Restrictions_Or_Restriction_Warnings
(Warn
: Boolean);
3773 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3774 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3775 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3776 -- is not set in the Restrictions case.
3778 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean);
3779 -- Common processing for Suppress and Unsuppress. The boolean parameter
3780 -- Suppress_Case is True for the Suppress case, and False for the
3783 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
);
3784 -- Subsidiary to the analysis of pragmas Independent[_Components].
3785 -- Record such a pragma N applied to entity E for future checks.
3787 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
);
3788 -- This procedure sets the Is_Exported flag for the given entity,
3789 -- checking that the entity was not previously imported. Arg is
3790 -- the argument that specified the entity. A check is also made
3791 -- for exporting inappropriate entities.
3793 procedure Set_Extended_Import_Export_External_Name
3794 (Internal_Ent
: Entity_Id
;
3795 Arg_External
: Node_Id
);
3796 -- Common processing for all extended import export pragmas. The first
3797 -- argument, Internal_Ent, is the internal entity, which has already
3798 -- been checked for validity by the caller. Arg_External is from the
3799 -- Import or Export pragma, and may be null if no External parameter
3800 -- was present. If Arg_External is present and is a non-null string
3801 -- (a null string is treated as the default), then the Interface_Name
3802 -- field of Internal_Ent is set appropriately.
3804 procedure Set_Imported
(E
: Entity_Id
);
3805 -- This procedure sets the Is_Imported flag for the given entity,
3806 -- checking that it is not previously exported or imported.
3808 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
);
3809 -- Mech is a parameter passing mechanism (see Import_Function syntax
3810 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3811 -- has the right form, and if not issues an error message. If the
3812 -- argument has the right form then the Mechanism field of Ent is
3813 -- set appropriately.
3815 procedure Set_Rational_Profile
;
3816 -- Activate the set of configuration pragmas and permissions that make
3817 -- up the Rational profile.
3819 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
);
3820 -- Activate the set of configuration pragmas and restrictions that make
3821 -- up the Profile. Profile must be either GNAT_Extended_Ravencar or
3822 -- Ravenscar. N is the corresponding pragma node, which is used for
3823 -- error messages on any constructs violating the profile.
3825 ----------------------------------
3826 -- Acquire_Warning_Match_String --
3827 ----------------------------------
3829 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
) is
3831 String_To_Name_Buffer
3832 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
3834 -- Add asterisk at start if not already there
3836 if Name_Len
> 0 and then Name_Buffer
(1) /= '*' then
3837 Name_Buffer
(2 .. Name_Len
+ 1) :=
3838 Name_Buffer
(1 .. Name_Len
);
3839 Name_Buffer
(1) := '*';
3840 Name_Len
:= Name_Len
+ 1;
3843 -- Add asterisk at end if not already there
3845 if Name_Buffer
(Name_Len
) /= '*' then
3846 Name_Len
:= Name_Len
+ 1;
3847 Name_Buffer
(Name_Len
) := '*';
3849 end Acquire_Warning_Match_String
;
3851 ---------------------
3852 -- Ada_2005_Pragma --
3853 ---------------------
3855 procedure Ada_2005_Pragma
is
3857 if Ada_Version
<= Ada_95
then
3858 Check_Restriction
(No_Implementation_Pragmas
, N
);
3860 end Ada_2005_Pragma
;
3862 ---------------------
3863 -- Ada_2012_Pragma --
3864 ---------------------
3866 procedure Ada_2012_Pragma
is
3868 if Ada_Version
<= Ada_2005
then
3869 Check_Restriction
(No_Implementation_Pragmas
, N
);
3871 end Ada_2012_Pragma
;
3873 ----------------------------
3874 -- Analyze_Depends_Global --
3875 ----------------------------
3877 procedure Analyze_Depends_Global
3878 (Spec_Id
: out Entity_Id
;
3879 Subp_Decl
: out Node_Id
;
3880 Legal
: out Boolean)
3883 -- Assume that the pragma is illegal
3890 Check_Arg_Count
(1);
3892 -- Ensure the proper placement of the pragma. Depends/Global must be
3893 -- associated with a subprogram declaration or a body that acts as a
3896 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
3900 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
3903 -- Generic subprogram
3905 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
3908 -- Object declaration of a single concurrent type
3910 elsif Nkind
(Subp_Decl
) = N_Object_Declaration
then
3915 elsif Nkind
(Subp_Decl
) = N_Single_Task_Declaration
then
3918 -- Subprogram body acts as spec
3920 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
3921 and then No
(Corresponding_Spec
(Subp_Decl
))
3925 -- Subprogram body stub acts as spec
3927 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
3928 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
3932 -- Subprogram declaration
3934 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
3939 elsif Nkind
(Subp_Decl
) = N_Task_Type_Declaration
then
3947 -- If we get here, then the pragma is legal
3950 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
3952 -- When the related context is an entry, the entry must belong to a
3953 -- protected unit (SPARK RM 6.1.4(6)).
3955 if Is_Entry_Declaration
(Spec_Id
)
3956 and then Ekind
(Scope
(Spec_Id
)) /= E_Protected_Type
3961 -- When the related context is an anonymous object created for a
3962 -- simple concurrent type, the type must be a task
3963 -- (SPARK RM 6.1.4(6)).
3965 elsif Is_Single_Concurrent_Object
(Spec_Id
)
3966 and then Ekind
(Etype
(Spec_Id
)) /= E_Task_Type
3972 -- A pragma that applies to a Ghost entity becomes Ghost for the
3973 -- purposes of legality checks and removal of ignored Ghost code.
3975 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
3976 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
3977 end Analyze_Depends_Global
;
3979 ------------------------
3980 -- Analyze_If_Present --
3981 ------------------------
3983 procedure Analyze_If_Present
(Id
: Pragma_Id
) is
3987 pragma Assert
(Is_List_Member
(N
));
3989 -- Inspect the declarations or statements following pragma N looking
3990 -- for another pragma whose Id matches the caller's request. If it is
3991 -- available, analyze it.
3994 while Present
(Stmt
) loop
3995 if Nkind
(Stmt
) = N_Pragma
and then Get_Pragma_Id
(Stmt
) = Id
then
3996 Analyze_Pragma
(Stmt
);
3999 -- The first source declaration or statement immediately following
4000 -- N ends the region where a pragma may appear.
4002 elsif Comes_From_Source
(Stmt
) then
4008 end Analyze_If_Present
;
4010 --------------------------------
4011 -- Analyze_Pre_Post_Condition --
4012 --------------------------------
4014 procedure Analyze_Pre_Post_Condition
is
4015 Prag_Iden
: constant Node_Id
:= Pragma_Identifier
(N
);
4016 Subp_Decl
: Node_Id
;
4017 Subp_Id
: Entity_Id
;
4019 Duplicates_OK
: Boolean := False;
4020 -- Flag set when a pre/postcondition allows multiple pragmas of the
4023 In_Body_OK
: Boolean := False;
4024 -- Flag set when a pre/postcondition is allowed to appear on a body
4025 -- even though the subprogram may have a spec.
4027 Is_Pre_Post
: Boolean := False;
4028 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
4032 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
4033 -- offer uniformity among the various kinds of pre/postconditions by
4034 -- rewriting the pragma identifier. This allows the retrieval of the
4035 -- original pragma name by routine Original_Aspect_Pragma_Name.
4037 if Comes_From_Source
(N
) then
4038 if Nam_In
(Pname
, Name_Pre
, Name_Pre_Class
) then
4039 Is_Pre_Post
:= True;
4040 Set_Class_Present
(N
, Pname
= Name_Pre_Class
);
4041 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Precondition
));
4043 elsif Nam_In
(Pname
, Name_Post
, Name_Post_Class
) then
4044 Is_Pre_Post
:= True;
4045 Set_Class_Present
(N
, Pname
= Name_Post_Class
);
4046 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Postcondition
));
4050 -- Determine the semantics with respect to duplicates and placement
4051 -- in a body. Pragmas Precondition and Postcondition were introduced
4052 -- before aspects and are not subject to the same aspect-like rules.
4054 if Nam_In
(Pname
, Name_Precondition
, Name_Postcondition
) then
4055 Duplicates_OK
:= True;
4061 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
4062 -- argument without an identifier.
4065 Check_Arg_Count
(1);
4066 Check_No_Identifiers
;
4068 -- Pragmas Precondition and Postcondition have complex argument
4072 Check_At_Least_N_Arguments
(1);
4073 Check_At_Most_N_Arguments
(2);
4074 Check_Optional_Identifier
(Arg1
, Name_Check
);
4076 if Present
(Arg2
) then
4077 Check_Optional_Identifier
(Arg2
, Name_Message
);
4078 Preanalyze_Spec_Expression
4079 (Get_Pragma_Arg
(Arg2
), Standard_String
);
4083 -- For a pragma PPC in the extended main source unit, record enabled
4085 -- ??? nothing checks that the pragma is in the main source unit
4087 if Is_Checked
(N
) and then not Split_PPC
(N
) then
4088 Set_SCO_Pragma_Enabled
(Loc
);
4091 -- Ensure the proper placement of the pragma
4094 Find_Related_Declaration_Or_Body
4095 (N
, Do_Checks
=> not Duplicates_OK
);
4097 -- When a pre/postcondition pragma applies to an abstract subprogram,
4098 -- its original form must be an aspect with 'Class.
4100 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
4101 if not From_Aspect_Specification
(N
) then
4103 ("pragma % cannot be applied to abstract subprogram");
4105 elsif not Class_Present
(N
) then
4107 ("aspect % requires ''Class for abstract subprogram");
4110 -- Entry declaration
4112 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
4115 -- Generic subprogram declaration
4117 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
4122 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
4123 and then (No
(Corresponding_Spec
(Subp_Decl
)) or In_Body_OK
)
4127 -- Subprogram body stub
4129 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4130 and then (No
(Corresponding_Spec_Of_Stub
(Subp_Decl
)) or In_Body_OK
)
4134 -- Subprogram declaration
4136 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
4138 -- AI05-0230: When a pre/postcondition pragma applies to a null
4139 -- procedure, its original form must be an aspect with 'Class.
4141 if Nkind
(Specification
(Subp_Decl
)) = N_Procedure_Specification
4142 and then Null_Present
(Specification
(Subp_Decl
))
4143 and then From_Aspect_Specification
(N
)
4144 and then not Class_Present
(N
)
4146 Error_Pragma
("aspect % requires ''Class for null procedure");
4149 -- Otherwise the placement is illegal
4156 Subp_Id
:= Defining_Entity
(Subp_Decl
);
4158 -- Chain the pragma on the contract for further processing by
4159 -- Analyze_Pre_Post_Condition_In_Decl_Part.
4161 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
4163 -- A pragma that applies to a Ghost entity becomes Ghost for the
4164 -- purposes of legality checks and removal of ignored Ghost code.
4166 Mark_Pragma_As_Ghost
(N
, Subp_Id
);
4168 -- Fully analyze the pragma when it appears inside an entry or
4169 -- subprogram body because it cannot benefit from forward references.
4171 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
4173 N_Subprogram_Body_Stub
)
4175 -- The legality checks of pragmas Precondition and Postcondition
4176 -- are affected by the SPARK mode in effect and the volatility of
4177 -- the context. Analyze all pragmas in a specific order.
4179 Analyze_If_Present
(Pragma_SPARK_Mode
);
4180 Analyze_If_Present
(Pragma_Volatile_Function
);
4181 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
4183 end Analyze_Pre_Post_Condition
;
4185 -----------------------------------------
4186 -- Analyze_Refined_Depends_Global_Post --
4187 -----------------------------------------
4189 procedure Analyze_Refined_Depends_Global_Post
4190 (Spec_Id
: out Entity_Id
;
4191 Body_Id
: out Entity_Id
;
4192 Legal
: out Boolean)
4194 Body_Decl
: Node_Id
;
4195 Spec_Decl
: Node_Id
;
4198 -- Assume that the pragma is illegal
4205 Check_Arg_Count
(1);
4206 Check_No_Identifiers
;
4208 -- Verify the placement of the pragma and check for duplicates. The
4209 -- pragma must apply to a subprogram body [stub].
4211 Body_Decl
:= Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
4215 if Nkind
(Body_Decl
) = N_Entry_Body
then
4220 elsif Nkind
(Body_Decl
) = N_Subprogram_Body
then
4223 -- Subprogram body stub
4225 elsif Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
4230 elsif Nkind
(Body_Decl
) = N_Task_Body
then
4238 Body_Id
:= Defining_Entity
(Body_Decl
);
4239 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
4241 -- The pragma must apply to the second declaration of a subprogram.
4242 -- In other words, the body [stub] cannot acts as a spec.
4244 if No
(Spec_Id
) then
4245 Error_Pragma
("pragma % cannot apply to a stand alone body");
4248 -- Catch the case where the subprogram body is a subunit and acts as
4249 -- the third declaration of the subprogram.
4251 elsif Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
4252 Error_Pragma
("pragma % cannot apply to a subunit");
4256 -- A refined pragma can only apply to the body [stub] of a subprogram
4257 -- declared in the visible part of a package. Retrieve the context of
4258 -- the subprogram declaration.
4260 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
4262 -- When dealing with protected entries or protected subprograms, use
4263 -- the enclosing protected type as the proper context.
4265 if Ekind_In
(Spec_Id
, E_Entry
,
4269 and then Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
4271 Spec_Decl
:= Declaration_Node
(Scope
(Spec_Id
));
4274 if Nkind
(Parent
(Spec_Decl
)) /= N_Package_Specification
then
4276 (Fix_Msg
(Spec_Id
, "pragma % must apply to the body of "
4277 & "subprogram declared in a package specification"));
4281 -- If we get here, then the pragma is legal
4285 -- A pragma that applies to a Ghost entity becomes Ghost for the
4286 -- purposes of legality checks and removal of ignored Ghost code.
4288 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
4290 if Nam_In
(Pname
, Name_Refined_Depends
, Name_Refined_Global
) then
4291 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
4293 end Analyze_Refined_Depends_Global_Post
;
4295 --------------------------
4296 -- Check_Ada_83_Warning --
4297 --------------------------
4299 procedure Check_Ada_83_Warning
is
4301 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
4302 Error_Msg_N
("(Ada 83) pragma& is non-standard??", N
);
4304 end Check_Ada_83_Warning
;
4306 ---------------------
4307 -- Check_Arg_Count --
4308 ---------------------
4310 procedure Check_Arg_Count
(Required
: Nat
) is
4312 if Arg_Count
/= Required
then
4313 Error_Pragma
("wrong number of arguments for pragma%");
4315 end Check_Arg_Count
;
4317 --------------------------------
4318 -- Check_Arg_Is_External_Name --
4319 --------------------------------
4321 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
) is
4322 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4325 if Nkind
(Argx
) = N_Identifier
then
4329 Analyze_And_Resolve
(Argx
, Standard_String
);
4331 if Is_OK_Static_Expression
(Argx
) then
4334 elsif Etype
(Argx
) = Any_Type
then
4337 -- An interesting special case, if we have a string literal and
4338 -- we are in Ada 83 mode, then we allow it even though it will
4339 -- not be flagged as static. This allows expected Ada 83 mode
4340 -- use of external names which are string literals, even though
4341 -- technically these are not static in Ada 83.
4343 elsif Ada_Version
= Ada_83
4344 and then Nkind
(Argx
) = N_String_Literal
4348 -- Static expression that raises Constraint_Error. This has
4349 -- already been flagged, so just exit from pragma processing.
4351 elsif Is_OK_Static_Expression
(Argx
) then
4354 -- Here we have a real error (non-static expression)
4357 Error_Msg_Name_1
:= Pname
;
4360 Msg
: constant String :=
4361 "argument for pragma% must be a identifier or "
4362 & "static string expression!";
4364 Flag_Non_Static_Expr
(Fix_Error
(Msg
), Argx
);
4369 end Check_Arg_Is_External_Name
;
4371 -----------------------------
4372 -- Check_Arg_Is_Identifier --
4373 -----------------------------
4375 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
) is
4376 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4378 if Nkind
(Argx
) /= N_Identifier
then
4380 ("argument for pragma% must be identifier", Argx
);
4382 end Check_Arg_Is_Identifier
;
4384 ----------------------------------
4385 -- Check_Arg_Is_Integer_Literal --
4386 ----------------------------------
4388 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
) is
4389 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4391 if Nkind
(Argx
) /= N_Integer_Literal
then
4393 ("argument for pragma% must be integer literal", Argx
);
4395 end Check_Arg_Is_Integer_Literal
;
4397 -------------------------------------------
4398 -- Check_Arg_Is_Library_Level_Local_Name --
4399 -------------------------------------------
4403 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4404 -- | library_unit_NAME
4406 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
) is
4408 Check_Arg_Is_Local_Name
(Arg
);
4410 -- If it came from an aspect, we want to give the error just as if it
4411 -- came from source.
4413 if not Is_Library_Level_Entity
(Entity
(Get_Pragma_Arg
(Arg
)))
4414 and then (Comes_From_Source
(N
)
4415 or else Present
(Corresponding_Aspect
(Parent
(Arg
))))
4418 ("argument for pragma% must be library level entity", Arg
);
4420 end Check_Arg_Is_Library_Level_Local_Name
;
4422 -----------------------------
4423 -- Check_Arg_Is_Local_Name --
4424 -----------------------------
4428 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
4429 -- | library_unit_NAME
4431 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
) is
4432 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4437 if Nkind
(Argx
) not in N_Direct_Name
4438 and then (Nkind
(Argx
) /= N_Attribute_Reference
4439 or else Present
(Expressions
(Argx
))
4440 or else Nkind
(Prefix
(Argx
)) /= N_Identifier
)
4441 and then (not Is_Entity_Name
(Argx
)
4442 or else not Is_Compilation_Unit
(Entity
(Argx
)))
4444 Error_Pragma_Arg
("argument for pragma% must be local name", Argx
);
4447 -- No further check required if not an entity name
4449 if not Is_Entity_Name
(Argx
) then
4455 Ent
: constant Entity_Id
:= Entity
(Argx
);
4456 Scop
: constant Entity_Id
:= Scope
(Ent
);
4459 -- Case of a pragma applied to a compilation unit: pragma must
4460 -- occur immediately after the program unit in the compilation.
4462 if Is_Compilation_Unit
(Ent
) then
4464 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
4467 -- Case of pragma placed immediately after spec
4469 if Parent
(N
) = Aux_Decls_Node
(Parent
(Decl
)) then
4472 -- Case of pragma placed immediately after body
4474 elsif Nkind
(Decl
) = N_Subprogram_Declaration
4475 and then Present
(Corresponding_Body
(Decl
))
4479 (Parent
(Unit_Declaration_Node
4480 (Corresponding_Body
(Decl
))));
4482 -- All other cases are illegal
4489 -- Special restricted placement rule from 10.2.1(11.8/2)
4491 elsif Is_Generic_Formal
(Ent
)
4492 and then Prag_Id
= Pragma_Preelaborable_Initialization
4494 OK
:= List_Containing
(N
) =
4495 Generic_Formal_Declarations
4496 (Unit_Declaration_Node
(Scop
));
4498 -- If this is an aspect applied to a subprogram body, the
4499 -- pragma is inserted in its declarative part.
4501 elsif From_Aspect_Specification
(N
)
4502 and then Ent
= Current_Scope
4504 Nkind
(Unit_Declaration_Node
(Ent
)) = N_Subprogram_Body
4508 -- If the aspect is a predicate (possibly others ???) and the
4509 -- context is a record type, this is a discriminant expression
4510 -- within a type declaration, that freezes the predicated
4513 elsif From_Aspect_Specification
(N
)
4514 and then Prag_Id
= Pragma_Predicate
4515 and then Ekind
(Current_Scope
) = E_Record_Type
4516 and then Scop
= Scope
(Current_Scope
)
4520 -- Default case, just check that the pragma occurs in the scope
4521 -- of the entity denoted by the name.
4524 OK
:= Current_Scope
= Scop
;
4529 ("pragma% argument must be in same declarative part", Arg
);
4533 end Check_Arg_Is_Local_Name
;
4535 ---------------------------------
4536 -- Check_Arg_Is_Locking_Policy --
4537 ---------------------------------
4539 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
) is
4540 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4543 Check_Arg_Is_Identifier
(Argx
);
4545 if not Is_Locking_Policy_Name
(Chars
(Argx
)) then
4546 Error_Pragma_Arg
("& is not a valid locking policy name", Argx
);
4548 end Check_Arg_Is_Locking_Policy
;
4550 -----------------------------------------------
4551 -- Check_Arg_Is_Partition_Elaboration_Policy --
4552 -----------------------------------------------
4554 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
) is
4555 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4558 Check_Arg_Is_Identifier
(Argx
);
4560 if not Is_Partition_Elaboration_Policy_Name
(Chars
(Argx
)) then
4562 ("& is not a valid partition elaboration policy name", Argx
);
4564 end Check_Arg_Is_Partition_Elaboration_Policy
;
4566 -------------------------
4567 -- Check_Arg_Is_One_Of --
4568 -------------------------
4570 procedure Check_Arg_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
4571 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4574 Check_Arg_Is_Identifier
(Argx
);
4576 if not Nam_In
(Chars
(Argx
), N1
, N2
) then
4577 Error_Msg_Name_2
:= N1
;
4578 Error_Msg_Name_3
:= N2
;
4579 Error_Pragma_Arg
("argument for pragma% must be% or%", Argx
);
4581 end Check_Arg_Is_One_Of
;
4583 procedure Check_Arg_Is_One_Of
4585 N1
, N2
, N3
: Name_Id
)
4587 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4590 Check_Arg_Is_Identifier
(Argx
);
4592 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
) then
4593 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
4595 end Check_Arg_Is_One_Of
;
4597 procedure Check_Arg_Is_One_Of
4599 N1
, N2
, N3
, N4
: Name_Id
)
4601 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4604 Check_Arg_Is_Identifier
(Argx
);
4606 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
) then
4607 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
4609 end Check_Arg_Is_One_Of
;
4611 procedure Check_Arg_Is_One_Of
4613 N1
, N2
, N3
, N4
, N5
: Name_Id
)
4615 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4618 Check_Arg_Is_Identifier
(Argx
);
4620 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
, N5
) then
4621 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
4623 end Check_Arg_Is_One_Of
;
4625 ---------------------------------
4626 -- Check_Arg_Is_Queuing_Policy --
4627 ---------------------------------
4629 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
) is
4630 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4633 Check_Arg_Is_Identifier
(Argx
);
4635 if not Is_Queuing_Policy_Name
(Chars
(Argx
)) then
4636 Error_Pragma_Arg
("& is not a valid queuing policy name", Argx
);
4638 end Check_Arg_Is_Queuing_Policy
;
4640 ---------------------------------------
4641 -- Check_Arg_Is_OK_Static_Expression --
4642 ---------------------------------------
4644 procedure Check_Arg_Is_OK_Static_Expression
4646 Typ
: Entity_Id
:= Empty
)
4649 Check_Expr_Is_OK_Static_Expression
(Get_Pragma_Arg
(Arg
), Typ
);
4650 end Check_Arg_Is_OK_Static_Expression
;
4652 ------------------------------------------
4653 -- Check_Arg_Is_Task_Dispatching_Policy --
4654 ------------------------------------------
4656 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
) is
4657 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4660 Check_Arg_Is_Identifier
(Argx
);
4662 if not Is_Task_Dispatching_Policy_Name
(Chars
(Argx
)) then
4664 ("& is not an allowed task dispatching policy name", Argx
);
4666 end Check_Arg_Is_Task_Dispatching_Policy
;
4668 ---------------------
4669 -- Check_Arg_Order --
4670 ---------------------
4672 procedure Check_Arg_Order
(Names
: Name_List
) is
4675 Highest_So_Far
: Natural := 0;
4676 -- Highest index in Names seen do far
4680 for J
in 1 .. Arg_Count
loop
4681 if Chars
(Arg
) /= No_Name
then
4682 for K
in Names
'Range loop
4683 if Chars
(Arg
) = Names
(K
) then
4684 if K
< Highest_So_Far
then
4685 Error_Msg_Name_1
:= Pname
;
4687 ("parameters out of order for pragma%", Arg
);
4688 Error_Msg_Name_1
:= Names
(K
);
4689 Error_Msg_Name_2
:= Names
(Highest_So_Far
);
4690 Error_Msg_N
("\% must appear before %", Arg
);
4694 Highest_So_Far
:= K
;
4702 end Check_Arg_Order
;
4704 --------------------------------
4705 -- Check_At_Least_N_Arguments --
4706 --------------------------------
4708 procedure Check_At_Least_N_Arguments
(N
: Nat
) is
4710 if Arg_Count
< N
then
4711 Error_Pragma
("too few arguments for pragma%");
4713 end Check_At_Least_N_Arguments
;
4715 -------------------------------
4716 -- Check_At_Most_N_Arguments --
4717 -------------------------------
4719 procedure Check_At_Most_N_Arguments
(N
: Nat
) is
4722 if Arg_Count
> N
then
4724 for J
in 1 .. N
loop
4726 Error_Pragma_Arg
("too many arguments for pragma%", Arg
);
4729 end Check_At_Most_N_Arguments
;
4731 ---------------------
4732 -- Check_Component --
4733 ---------------------
4735 procedure Check_Component
4738 In_Variant_Part
: Boolean := False)
4740 Comp_Id
: constant Entity_Id
:= Defining_Identifier
(Comp
);
4741 Sindic
: constant Node_Id
:=
4742 Subtype_Indication
(Component_Definition
(Comp
));
4743 Typ
: constant Entity_Id
:= Etype
(Comp_Id
);
4746 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4747 -- object constraint, then the component type shall be an Unchecked_
4750 if Nkind
(Sindic
) = N_Subtype_Indication
4751 and then Has_Per_Object_Constraint
(Comp_Id
)
4752 and then not Is_Unchecked_Union
(Etype
(Subtype_Mark
(Sindic
)))
4755 ("component subtype subject to per-object constraint "
4756 & "must be an Unchecked_Union", Comp
);
4758 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4759 -- the body of a generic unit, or within the body of any of its
4760 -- descendant library units, no part of the type of a component
4761 -- declared in a variant_part of the unchecked union type shall be of
4762 -- a formal private type or formal private extension declared within
4763 -- the formal part of the generic unit.
4765 elsif Ada_Version
>= Ada_2012
4766 and then In_Generic_Body
(UU_Typ
)
4767 and then In_Variant_Part
4768 and then Is_Private_Type
(Typ
)
4769 and then Is_Generic_Type
(Typ
)
4772 ("component of unchecked union cannot be of generic type", Comp
);
4774 elsif Needs_Finalization
(Typ
) then
4776 ("component of unchecked union cannot be controlled", Comp
);
4778 elsif Has_Task
(Typ
) then
4780 ("component of unchecked union cannot have tasks", Comp
);
4782 end Check_Component
;
4784 ----------------------------
4785 -- Check_Duplicate_Pragma --
4786 ----------------------------
4788 procedure Check_Duplicate_Pragma
(E
: Entity_Id
) is
4789 Id
: Entity_Id
:= E
;
4793 -- Nothing to do if this pragma comes from an aspect specification,
4794 -- since we could not be duplicating a pragma, and we dealt with the
4795 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4797 if From_Aspect_Specification
(N
) then
4801 -- Otherwise current pragma may duplicate previous pragma or a
4802 -- previously given aspect specification or attribute definition
4803 -- clause for the same pragma.
4805 P
:= Get_Rep_Item
(E
, Pragma_Name
(N
), Check_Parents
=> False);
4809 -- If the entity is a type, then we have to make sure that the
4810 -- ostensible duplicate is not for a parent type from which this
4814 if Nkind
(P
) = N_Pragma
then
4816 Args
: constant List_Id
:=
4817 Pragma_Argument_Associations
(P
);
4820 and then Is_Entity_Name
(Expression
(First
(Args
)))
4821 and then Is_Type
(Entity
(Expression
(First
(Args
))))
4822 and then Entity
(Expression
(First
(Args
))) /= E
4828 elsif Nkind
(P
) = N_Aspect_Specification
4829 and then Is_Type
(Entity
(P
))
4830 and then Entity
(P
) /= E
4836 -- Here we have a definite duplicate
4838 Error_Msg_Name_1
:= Pragma_Name
(N
);
4839 Error_Msg_Sloc
:= Sloc
(P
);
4841 -- For a single protected or a single task object, the error is
4842 -- issued on the original entity.
4844 if Ekind_In
(Id
, E_Task_Type
, E_Protected_Type
) then
4845 Id
:= Defining_Identifier
(Original_Node
(Parent
(Id
)));
4848 if Nkind
(P
) = N_Aspect_Specification
4849 or else From_Aspect_Specification
(P
)
4851 Error_Msg_NE
("aspect% for & previously given#", N
, Id
);
4853 Error_Msg_NE
("pragma% for & duplicates pragma#", N
, Id
);
4858 end Check_Duplicate_Pragma
;
4860 ----------------------------------
4861 -- Check_Duplicated_Export_Name --
4862 ----------------------------------
4864 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
) is
4865 String_Val
: constant String_Id
:= Strval
(Nam
);
4868 -- We are only interested in the export case, and in the case of
4869 -- generics, it is the instance, not the template, that is the
4870 -- problem (the template will generate a warning in any case).
4872 if not Inside_A_Generic
4873 and then (Prag_Id
= Pragma_Export
4875 Prag_Id
= Pragma_Export_Procedure
4877 Prag_Id
= Pragma_Export_Valued_Procedure
4879 Prag_Id
= Pragma_Export_Function
)
4881 for J
in Externals
.First
.. Externals
.Last
loop
4882 if String_Equal
(String_Val
, Strval
(Externals
.Table
(J
))) then
4883 Error_Msg_Sloc
:= Sloc
(Externals
.Table
(J
));
4884 Error_Msg_N
("external name duplicates name given#", Nam
);
4889 Externals
.Append
(Nam
);
4891 end Check_Duplicated_Export_Name
;
4893 ----------------------------------------
4894 -- Check_Expr_Is_OK_Static_Expression --
4895 ----------------------------------------
4897 procedure Check_Expr_Is_OK_Static_Expression
4899 Typ
: Entity_Id
:= Empty
)
4902 if Present
(Typ
) then
4903 Analyze_And_Resolve
(Expr
, Typ
);
4905 Analyze_And_Resolve
(Expr
);
4908 if Is_OK_Static_Expression
(Expr
) then
4911 elsif Etype
(Expr
) = Any_Type
then
4914 -- An interesting special case, if we have a string literal and we
4915 -- are in Ada 83 mode, then we allow it even though it will not be
4916 -- flagged as static. This allows the use of Ada 95 pragmas like
4917 -- Import in Ada 83 mode. They will of course be flagged with
4918 -- warnings as usual, but will not cause errors.
4920 elsif Ada_Version
= Ada_83
4921 and then Nkind
(Expr
) = N_String_Literal
4925 -- Static expression that raises Constraint_Error. This has already
4926 -- been flagged, so just exit from pragma processing.
4928 elsif Is_OK_Static_Expression
(Expr
) then
4931 -- Finally, we have a real error
4934 Error_Msg_Name_1
:= Pname
;
4935 Flag_Non_Static_Expr
4936 (Fix_Error
("argument for pragma% must be a static expression!"),
4940 end Check_Expr_Is_OK_Static_Expression
;
4942 -------------------------
4943 -- Check_First_Subtype --
4944 -------------------------
4946 procedure Check_First_Subtype
(Arg
: Node_Id
) is
4947 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4948 Ent
: constant Entity_Id
:= Entity
(Argx
);
4951 if Is_First_Subtype
(Ent
) then
4954 elsif Is_Type
(Ent
) then
4956 ("pragma% cannot apply to subtype", Argx
);
4958 elsif Is_Object
(Ent
) then
4960 ("pragma% cannot apply to object, requires a type", Argx
);
4964 ("pragma% cannot apply to&, requires a type", Argx
);
4966 end Check_First_Subtype
;
4968 ----------------------
4969 -- Check_Identifier --
4970 ----------------------
4972 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
4975 and then Nkind
(Arg
) = N_Pragma_Argument_Association
4977 if Chars
(Arg
) = No_Name
or else Chars
(Arg
) /= Id
then
4978 Error_Msg_Name_1
:= Pname
;
4979 Error_Msg_Name_2
:= Id
;
4980 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
4984 end Check_Identifier
;
4986 --------------------------------
4987 -- Check_Identifier_Is_One_Of --
4988 --------------------------------
4990 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
4993 and then Nkind
(Arg
) = N_Pragma_Argument_Association
4995 if Chars
(Arg
) = No_Name
then
4996 Error_Msg_Name_1
:= Pname
;
4997 Error_Msg_N
("pragma% argument expects an identifier", Arg
);
5000 elsif Chars
(Arg
) /= N1
5001 and then Chars
(Arg
) /= N2
5003 Error_Msg_Name_1
:= Pname
;
5004 Error_Msg_N
("invalid identifier for pragma% argument", Arg
);
5008 end Check_Identifier_Is_One_Of
;
5010 ---------------------------
5011 -- Check_In_Main_Program --
5012 ---------------------------
5014 procedure Check_In_Main_Program
is
5015 P
: constant Node_Id
:= Parent
(N
);
5018 -- Must be in subprogram body
5020 if Nkind
(P
) /= N_Subprogram_Body
then
5021 Error_Pragma
("% pragma allowed only in subprogram");
5023 -- Otherwise warn if obviously not main program
5025 elsif Present
(Parameter_Specifications
(Specification
(P
)))
5026 or else not Is_Compilation_Unit
(Defining_Entity
(P
))
5028 Error_Msg_Name_1
:= Pname
;
5030 ("??pragma% is only effective in main program", N
);
5032 end Check_In_Main_Program
;
5034 ---------------------------------------
5035 -- Check_Interrupt_Or_Attach_Handler --
5036 ---------------------------------------
5038 procedure Check_Interrupt_Or_Attach_Handler
is
5039 Arg1_X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
5040 Handler_Proc
, Proc_Scope
: Entity_Id
;
5045 if Prag_Id
= Pragma_Interrupt_Handler
then
5046 Check_Restriction
(No_Dynamic_Attachment
, N
);
5049 Handler_Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
5050 Proc_Scope
:= Scope
(Handler_Proc
);
5052 -- On AAMP only, a pragma Interrupt_Handler is supported for
5053 -- nonprotected parameterless procedures.
5055 if not AAMP_On_Target
5056 or else Prag_Id
= Pragma_Attach_Handler
5058 if Ekind
(Proc_Scope
) /= E_Protected_Type
then
5060 ("argument of pragma% must be protected procedure", Arg1
);
5063 -- For pragma case (as opposed to access case), check placement.
5064 -- We don't need to do that for aspects, because we have the
5065 -- check that they aspect applies an appropriate procedure.
5067 if not From_Aspect_Specification
(N
)
5068 and then Parent
(N
) /= Protected_Definition
(Parent
(Proc_Scope
))
5070 Error_Pragma
("pragma% must be in protected definition");
5074 if not Is_Library_Level_Entity
(Proc_Scope
)
5075 or else (AAMP_On_Target
5076 and then not Is_Library_Level_Entity
(Handler_Proc
))
5079 ("argument for pragma% must be library level entity", Arg1
);
5082 -- AI05-0033: A pragma cannot appear within a generic body, because
5083 -- instance can be in a nested scope. The check that protected type
5084 -- is itself a library-level declaration is done elsewhere.
5086 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
5087 -- handle code prior to AI-0033. Analysis tools typically are not
5088 -- interested in this pragma in any case, so no need to worry too
5089 -- much about its placement.
5091 if Inside_A_Generic
then
5092 if Ekind
(Scope
(Current_Scope
)) = E_Generic_Package
5093 and then In_Package_Body
(Scope
(Current_Scope
))
5094 and then not Relaxed_RM_Semantics
5096 Error_Pragma
("pragma% cannot be used inside a generic");
5099 end Check_Interrupt_Or_Attach_Handler
;
5101 ---------------------------------
5102 -- Check_Loop_Pragma_Placement --
5103 ---------------------------------
5105 procedure Check_Loop_Pragma_Placement
is
5106 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
);
5107 -- Verify whether the current pragma is properly grouped with other
5108 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
5109 -- related loop where the pragma appears.
5111 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean;
5112 -- Determine whether an arbitrary statement Stmt denotes pragma
5113 -- Loop_Invariant or Loop_Variant.
5115 procedure Placement_Error
(Constr
: Node_Id
);
5116 pragma No_Return
(Placement_Error
);
5117 -- Node Constr denotes the last loop restricted construct before we
5118 -- encountered an illegal relation between enclosing constructs. Emit
5119 -- an error depending on what Constr was.
5121 --------------------------------
5122 -- Check_Loop_Pragma_Grouping --
5123 --------------------------------
5125 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
) is
5126 Stop_Search
: exception;
5127 -- This exception is used to terminate the recursive descent of
5128 -- routine Check_Grouping.
5130 procedure Check_Grouping
(L
: List_Id
);
5131 -- Find the first group of pragmas in list L and if successful,
5132 -- ensure that the current pragma is part of that group. The
5133 -- routine raises Stop_Search once such a check is performed to
5134 -- halt the recursive descent.
5136 procedure Grouping_Error
(Prag
: Node_Id
);
5137 pragma No_Return
(Grouping_Error
);
5138 -- Emit an error concerning the current pragma indicating that it
5139 -- should be placed after pragma Prag.
5141 --------------------
5142 -- Check_Grouping --
5143 --------------------
5145 procedure Check_Grouping
(L
: List_Id
) is
5151 -- Inspect the list of declarations or statements looking for
5152 -- the first grouping of pragmas:
5155 -- pragma Loop_Invariant ...;
5156 -- pragma Loop_Variant ...;
5158 -- pragma Loop_Variant ...; -- current pragma
5160 -- If the current pragma is not in the grouping, then it must
5161 -- either appear in a different declarative or statement list
5162 -- or the construct at (1) is separating the pragma from the
5166 while Present
(Stmt
) loop
5168 -- Pragmas Loop_Invariant and Loop_Variant may only appear
5169 -- inside a loop or a block housed inside a loop. Inspect
5170 -- the declarations and statements of the block as they may
5171 -- contain the first grouping.
5173 if Nkind
(Stmt
) = N_Block_Statement
then
5174 HSS
:= Handled_Statement_Sequence
(Stmt
);
5176 Check_Grouping
(Declarations
(Stmt
));
5178 if Present
(HSS
) then
5179 Check_Grouping
(Statements
(HSS
));
5182 -- First pragma of the first topmost grouping has been found
5184 elsif Is_Loop_Pragma
(Stmt
) then
5186 -- The group and the current pragma are not in the same
5187 -- declarative or statement list.
5189 if List_Containing
(Stmt
) /= List_Containing
(N
) then
5190 Grouping_Error
(Stmt
);
5192 -- Try to reach the current pragma from the first pragma
5193 -- of the grouping while skipping other members:
5195 -- pragma Loop_Invariant ...; -- first pragma
5196 -- pragma Loop_Variant ...; -- member
5198 -- pragma Loop_Variant ...; -- current pragma
5201 while Present
(Stmt
) loop
5203 -- The current pragma is either the first pragma
5204 -- of the group or is a member of the group. Stop
5205 -- the search as the placement is legal.
5210 -- Skip group members, but keep track of the last
5211 -- pragma in the group.
5213 elsif Is_Loop_Pragma
(Stmt
) then
5216 -- Skip declarations and statements generated by
5217 -- the compiler during expansion.
5219 elsif not Comes_From_Source
(Stmt
) then
5222 -- A non-pragma is separating the group from the
5223 -- current pragma, the placement is illegal.
5226 Grouping_Error
(Prag
);
5232 -- If the traversal did not reach the current pragma,
5233 -- then the list must be malformed.
5235 raise Program_Error
;
5243 --------------------
5244 -- Grouping_Error --
5245 --------------------
5247 procedure Grouping_Error
(Prag
: Node_Id
) is
5249 Error_Msg_Sloc
:= Sloc
(Prag
);
5250 Error_Pragma
("pragma% must appear next to pragma#");
5253 -- Start of processing for Check_Loop_Pragma_Grouping
5256 -- Inspect the statements of the loop or nested blocks housed
5257 -- within to determine whether the current pragma is part of the
5258 -- first topmost grouping of Loop_Invariant and Loop_Variant.
5260 Check_Grouping
(Statements
(Loop_Stmt
));
5263 when Stop_Search
=> null;
5264 end Check_Loop_Pragma_Grouping
;
5266 --------------------
5267 -- Is_Loop_Pragma --
5268 --------------------
5270 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean is
5272 -- Inspect the original node as Loop_Invariant and Loop_Variant
5273 -- pragmas are rewritten to null when assertions are disabled.
5275 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
then
5277 Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
5278 Name_Loop_Invariant
,
5285 ---------------------
5286 -- Placement_Error --
5287 ---------------------
5289 procedure Placement_Error
(Constr
: Node_Id
) is
5290 LA
: constant String := " with Loop_Entry";
5293 if Prag_Id
= Pragma_Assert
then
5294 Error_Msg_String
(1 .. LA
'Length) := LA
;
5295 Error_Msg_Strlen
:= LA
'Length;
5297 Error_Msg_Strlen
:= 0;
5300 if Nkind
(Constr
) = N_Pragma
then
5302 ("pragma %~ must appear immediately within the statements "
5306 ("block containing pragma %~ must appear immediately within "
5307 & "the statements of a loop", Constr
);
5309 end Placement_Error
;
5311 -- Local declarations
5316 -- Start of processing for Check_Loop_Pragma_Placement
5319 -- Check that pragma appears immediately within a loop statement,
5320 -- ignoring intervening block statements.
5324 while Present
(Stmt
) loop
5326 -- The pragma or previous block must appear immediately within the
5327 -- current block's declarative or statement part.
5329 if Nkind
(Stmt
) = N_Block_Statement
then
5330 if (No
(Declarations
(Stmt
))
5331 or else List_Containing
(Prev
) /= Declarations
(Stmt
))
5333 List_Containing
(Prev
) /=
5334 Statements
(Handled_Statement_Sequence
(Stmt
))
5336 Placement_Error
(Prev
);
5339 -- Keep inspecting the parents because we are now within a
5340 -- chain of nested blocks.
5344 Stmt
:= Parent
(Stmt
);
5347 -- The pragma or previous block must appear immediately within the
5348 -- statements of the loop.
5350 elsif Nkind
(Stmt
) = N_Loop_Statement
then
5351 if List_Containing
(Prev
) /= Statements
(Stmt
) then
5352 Placement_Error
(Prev
);
5355 -- Stop the traversal because we reached the innermost loop
5356 -- regardless of whether we encountered an error or not.
5360 -- Ignore a handled statement sequence. Note that this node may
5361 -- be related to a subprogram body in which case we will emit an
5362 -- error on the next iteration of the search.
5364 elsif Nkind
(Stmt
) = N_Handled_Sequence_Of_Statements
then
5365 Stmt
:= Parent
(Stmt
);
5367 -- Any other statement breaks the chain from the pragma to the
5371 Placement_Error
(Prev
);
5376 -- Check that the current pragma Loop_Invariant or Loop_Variant is
5377 -- grouped together with other such pragmas.
5379 if Is_Loop_Pragma
(N
) then
5381 -- The previous check should have located the related loop
5383 pragma Assert
(Nkind
(Stmt
) = N_Loop_Statement
);
5384 Check_Loop_Pragma_Grouping
(Stmt
);
5386 end Check_Loop_Pragma_Placement
;
5388 -------------------------------------------
5389 -- Check_Is_In_Decl_Part_Or_Package_Spec --
5390 -------------------------------------------
5392 procedure Check_Is_In_Decl_Part_Or_Package_Spec
is
5401 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
then
5404 elsif Nkind_In
(P
, N_Package_Specification
,
5409 -- Note: the following tests seem a little peculiar, because
5410 -- they test for bodies, but if we were in the statement part
5411 -- of the body, we would already have hit the handled statement
5412 -- sequence, so the only way we get here is by being in the
5413 -- declarative part of the body.
5415 elsif Nkind_In
(P
, N_Subprogram_Body
,
5426 Error_Pragma
("pragma% is not in declarative part or package spec");
5427 end Check_Is_In_Decl_Part_Or_Package_Spec
;
5429 -------------------------
5430 -- Check_No_Identifier --
5431 -------------------------
5433 procedure Check_No_Identifier
(Arg
: Node_Id
) is
5435 if Nkind
(Arg
) = N_Pragma_Argument_Association
5436 and then Chars
(Arg
) /= No_Name
5438 Error_Pragma_Arg_Ident
5439 ("pragma% does not permit identifier& here", Arg
);
5441 end Check_No_Identifier
;
5443 --------------------------
5444 -- Check_No_Identifiers --
5445 --------------------------
5447 procedure Check_No_Identifiers
is
5451 for J
in 1 .. Arg_Count
loop
5452 Check_No_Identifier
(Arg_Node
);
5455 end Check_No_Identifiers
;
5457 ------------------------
5458 -- Check_No_Link_Name --
5459 ------------------------
5461 procedure Check_No_Link_Name
is
5463 if Present
(Arg3
) and then Chars
(Arg3
) = Name_Link_Name
then
5467 if Present
(Arg4
) then
5469 ("Link_Name argument not allowed for Import Intrinsic", Arg4
);
5471 end Check_No_Link_Name
;
5473 -------------------------------
5474 -- Check_Optional_Identifier --
5475 -------------------------------
5477 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
5480 and then Nkind
(Arg
) = N_Pragma_Argument_Association
5481 and then Chars
(Arg
) /= No_Name
5483 if Chars
(Arg
) /= Id
then
5484 Error_Msg_Name_1
:= Pname
;
5485 Error_Msg_Name_2
:= Id
;
5486 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
5490 end Check_Optional_Identifier
;
5492 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String) is
5494 Name_Buffer
(1 .. Id
'Length) := Id
;
5495 Name_Len
:= Id
'Length;
5496 Check_Optional_Identifier
(Arg
, Name_Find
);
5497 end Check_Optional_Identifier
;
5499 -------------------------------------
5500 -- Check_Static_Boolean_Expression --
5501 -------------------------------------
5503 procedure Check_Static_Boolean_Expression
(Expr
: Node_Id
) is
5505 if Present
(Expr
) then
5506 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
5508 if not Is_OK_Static_Expression
(Expr
) then
5510 ("expression of pragma % must be static", Expr
);
5513 end Check_Static_Boolean_Expression
;
5515 -----------------------------
5516 -- Check_Static_Constraint --
5517 -----------------------------
5519 -- Note: for convenience in writing this procedure, in addition to
5520 -- the officially (i.e. by spec) allowed argument which is always a
5521 -- constraint, it also allows ranges and discriminant associations.
5522 -- Above is not clear ???
5524 procedure Check_Static_Constraint
(Constr
: Node_Id
) is
5526 procedure Require_Static
(E
: Node_Id
);
5527 -- Require given expression to be static expression
5529 --------------------
5530 -- Require_Static --
5531 --------------------
5533 procedure Require_Static
(E
: Node_Id
) is
5535 if not Is_OK_Static_Expression
(E
) then
5536 Flag_Non_Static_Expr
5537 ("non-static constraint not allowed in Unchecked_Union!", E
);
5542 -- Start of processing for Check_Static_Constraint
5545 case Nkind
(Constr
) is
5546 when N_Discriminant_Association
=>
5547 Require_Static
(Expression
(Constr
));
5550 Require_Static
(Low_Bound
(Constr
));
5551 Require_Static
(High_Bound
(Constr
));
5553 when N_Attribute_Reference
=>
5554 Require_Static
(Type_Low_Bound
(Etype
(Prefix
(Constr
))));
5555 Require_Static
(Type_High_Bound
(Etype
(Prefix
(Constr
))));
5557 when N_Range_Constraint
=>
5558 Check_Static_Constraint
(Range_Expression
(Constr
));
5560 when N_Index_Or_Discriminant_Constraint
=>
5564 IDC
:= First
(Constraints
(Constr
));
5565 while Present
(IDC
) loop
5566 Check_Static_Constraint
(IDC
);
5574 end Check_Static_Constraint
;
5576 --------------------------------------
5577 -- Check_Valid_Configuration_Pragma --
5578 --------------------------------------
5580 -- A configuration pragma must appear in the context clause of a
5581 -- compilation unit, and only other pragmas may precede it. Note that
5582 -- the test also allows use in a configuration pragma file.
5584 procedure Check_Valid_Configuration_Pragma
is
5586 if not Is_Configuration_Pragma
then
5587 Error_Pragma
("incorrect placement for configuration pragma%");
5589 end Check_Valid_Configuration_Pragma
;
5591 -------------------------------------
5592 -- Check_Valid_Library_Unit_Pragma --
5593 -------------------------------------
5595 procedure Check_Valid_Library_Unit_Pragma
is
5597 Parent_Node
: Node_Id
;
5598 Unit_Name
: Entity_Id
;
5599 Unit_Kind
: Node_Kind
;
5600 Unit_Node
: Node_Id
;
5601 Sindex
: Source_File_Index
;
5604 if not Is_List_Member
(N
) then
5608 Plist
:= List_Containing
(N
);
5609 Parent_Node
:= Parent
(Plist
);
5611 if Parent_Node
= Empty
then
5614 -- Case of pragma appearing after a compilation unit. In this case
5615 -- it must have an argument with the corresponding name and must
5616 -- be part of the following pragmas of its parent.
5618 elsif Nkind
(Parent_Node
) = N_Compilation_Unit_Aux
then
5619 if Plist
/= Pragmas_After
(Parent_Node
) then
5622 elsif Arg_Count
= 0 then
5624 ("argument required if outside compilation unit");
5627 Check_No_Identifiers
;
5628 Check_Arg_Count
(1);
5629 Unit_Node
:= Unit
(Parent
(Parent_Node
));
5630 Unit_Kind
:= Nkind
(Unit_Node
);
5632 Analyze
(Get_Pragma_Arg
(Arg1
));
5634 if Unit_Kind
= N_Generic_Subprogram_Declaration
5635 or else Unit_Kind
= N_Subprogram_Declaration
5637 Unit_Name
:= Defining_Entity
(Unit_Node
);
5639 elsif Unit_Kind
in N_Generic_Instantiation
then
5640 Unit_Name
:= Defining_Entity
(Unit_Node
);
5643 Unit_Name
:= Cunit_Entity
(Current_Sem_Unit
);
5646 if Chars
(Unit_Name
) /=
5647 Chars
(Entity
(Get_Pragma_Arg
(Arg1
)))
5650 ("pragma% argument is not current unit name", Arg1
);
5653 if Ekind
(Unit_Name
) = E_Package
5654 and then Present
(Renamed_Entity
(Unit_Name
))
5656 Error_Pragma
("pragma% not allowed for renamed package");
5660 -- Pragma appears other than after a compilation unit
5663 -- Here we check for the generic instantiation case and also
5664 -- for the case of processing a generic formal package. We
5665 -- detect these cases by noting that the Sloc on the node
5666 -- does not belong to the current compilation unit.
5668 Sindex
:= Source_Index
(Current_Sem_Unit
);
5670 if Loc
not in Source_First
(Sindex
) .. Source_Last
(Sindex
) then
5671 Rewrite
(N
, Make_Null_Statement
(Loc
));
5674 -- If before first declaration, the pragma applies to the
5675 -- enclosing unit, and the name if present must be this name.
5677 elsif Is_Before_First_Decl
(N
, Plist
) then
5678 Unit_Node
:= Unit_Declaration_Node
(Current_Scope
);
5679 Unit_Kind
:= Nkind
(Unit_Node
);
5681 if Nkind
(Parent
(Unit_Node
)) /= N_Compilation_Unit
then
5684 elsif Unit_Kind
= N_Subprogram_Body
5685 and then not Acts_As_Spec
(Unit_Node
)
5689 elsif Nkind
(Parent_Node
) = N_Package_Body
then
5692 elsif Nkind
(Parent_Node
) = N_Package_Specification
5693 and then Plist
= Private_Declarations
(Parent_Node
)
5697 elsif (Nkind
(Parent_Node
) = N_Generic_Package_Declaration
5698 or else Nkind
(Parent_Node
) =
5699 N_Generic_Subprogram_Declaration
)
5700 and then Plist
= Generic_Formal_Declarations
(Parent_Node
)
5704 elsif Arg_Count
> 0 then
5705 Analyze
(Get_Pragma_Arg
(Arg1
));
5707 if Entity
(Get_Pragma_Arg
(Arg1
)) /= Current_Scope
then
5709 ("name in pragma% must be enclosing unit", Arg1
);
5712 -- It is legal to have no argument in this context
5718 -- Error if not before first declaration. This is because a
5719 -- library unit pragma argument must be the name of a library
5720 -- unit (RM 10.1.5(7)), but the only names permitted in this
5721 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5722 -- generic subprogram declarations or generic instantiations.
5726 ("pragma% misplaced, must be before first declaration");
5730 end Check_Valid_Library_Unit_Pragma
;
5736 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
) is
5737 Clist
: constant Node_Id
:= Component_List
(Variant
);
5741 Comp
:= First
(Component_Items
(Clist
));
5742 while Present
(Comp
) loop
5743 Check_Component
(Comp
, UU_Typ
, In_Variant_Part
=> True);
5748 ---------------------------
5749 -- Ensure_Aggregate_Form --
5750 ---------------------------
5752 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
) is
5753 CFSD
: constant Boolean := Get_Comes_From_Source_Default
;
5754 Expr
: constant Node_Id
:= Expression
(Arg
);
5755 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5756 Comps
: List_Id
:= No_List
;
5757 Exprs
: List_Id
:= No_List
;
5758 Nam
: Name_Id
:= No_Name
;
5759 Nam_Loc
: Source_Ptr
;
5762 -- The pragma argument is in positional form:
5764 -- pragma Depends (Nam => ...)
5768 -- Note that the Sloc of the Chars field is the Sloc of the pragma
5769 -- argument association.
5771 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
5773 Nam_Loc
:= Sloc
(Arg
);
5775 -- Remove the pragma argument name as this will be captured in the
5778 Set_Chars
(Arg
, No_Name
);
5781 -- The argument is already in aggregate form, but the presence of a
5782 -- name causes this to be interpreted as named association which in
5783 -- turn must be converted into an aggregate.
5785 -- pragma Global (In_Out => (A, B, C))
5789 -- pragma Global ((In_Out => (A, B, C)))
5791 -- aggregate aggregate
5793 if Nkind
(Expr
) = N_Aggregate
then
5794 if Nam
= No_Name
then
5798 -- Do not transform a null argument into an aggregate as N_Null has
5799 -- special meaning in formal verification pragmas.
5801 elsif Nkind
(Expr
) = N_Null
then
5805 -- Everything comes from source if the original comes from source
5807 Set_Comes_From_Source_Default
(Comes_From_Source
(Arg
));
5809 -- Positional argument is transformed into an aggregate with an
5810 -- Expressions list.
5812 if Nam
= No_Name
then
5813 Exprs
:= New_List
(Relocate_Node
(Expr
));
5815 -- An associative argument is transformed into an aggregate with
5816 -- Component_Associations.
5820 Make_Component_Association
(Loc
,
5821 Choices
=> New_List
(Make_Identifier
(Nam_Loc
, Nam
)),
5822 Expression
=> Relocate_Node
(Expr
)));
5825 Set_Expression
(Arg
,
5826 Make_Aggregate
(Loc
,
5827 Component_Associations
=> Comps
,
5828 Expressions
=> Exprs
));
5830 -- Restore Comes_From_Source default
5832 Set_Comes_From_Source_Default
(CFSD
);
5833 end Ensure_Aggregate_Form
;
5839 procedure Error_Pragma
(Msg
: String) is
5841 Error_Msg_Name_1
:= Pname
;
5842 Error_Msg_N
(Fix_Error
(Msg
), N
);
5846 ----------------------
5847 -- Error_Pragma_Arg --
5848 ----------------------
5850 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
) is
5852 Error_Msg_Name_1
:= Pname
;
5853 Error_Msg_N
(Fix_Error
(Msg
), Get_Pragma_Arg
(Arg
));
5855 end Error_Pragma_Arg
;
5857 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
) is
5859 Error_Msg_Name_1
:= Pname
;
5860 Error_Msg_N
(Fix_Error
(Msg1
), Get_Pragma_Arg
(Arg
));
5861 Error_Pragma_Arg
(Msg2
, Arg
);
5862 end Error_Pragma_Arg
;
5864 ----------------------------
5865 -- Error_Pragma_Arg_Ident --
5866 ----------------------------
5868 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
) is
5870 Error_Msg_Name_1
:= Pname
;
5871 Error_Msg_N
(Fix_Error
(Msg
), Arg
);
5873 end Error_Pragma_Arg_Ident
;
5875 ----------------------
5876 -- Error_Pragma_Ref --
5877 ----------------------
5879 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
) is
5881 Error_Msg_Name_1
:= Pname
;
5882 Error_Msg_Sloc
:= Sloc
(Ref
);
5883 Error_Msg_NE
(Fix_Error
(Msg
), N
, Ref
);
5885 end Error_Pragma_Ref
;
5887 ------------------------
5888 -- Find_Lib_Unit_Name --
5889 ------------------------
5891 function Find_Lib_Unit_Name
return Entity_Id
is
5893 -- Return inner compilation unit entity, for case of nested
5894 -- categorization pragmas. This happens in generic unit.
5896 if Nkind
(Parent
(N
)) = N_Package_Specification
5897 and then Defining_Entity
(Parent
(N
)) /= Current_Scope
5899 return Defining_Entity
(Parent
(N
));
5901 return Current_Scope
;
5903 end Find_Lib_Unit_Name
;
5905 ----------------------------
5906 -- Find_Program_Unit_Name --
5907 ----------------------------
5909 procedure Find_Program_Unit_Name
(Id
: Node_Id
) is
5910 Unit_Name
: Entity_Id
;
5911 Unit_Kind
: Node_Kind
;
5912 P
: constant Node_Id
:= Parent
(N
);
5915 if Nkind
(P
) = N_Compilation_Unit
then
5916 Unit_Kind
:= Nkind
(Unit
(P
));
5918 if Nkind_In
(Unit_Kind
, N_Subprogram_Declaration
,
5919 N_Package_Declaration
)
5920 or else Unit_Kind
in N_Generic_Declaration
5922 Unit_Name
:= Defining_Entity
(Unit
(P
));
5924 if Chars
(Id
) = Chars
(Unit_Name
) then
5925 Set_Entity
(Id
, Unit_Name
);
5926 Set_Etype
(Id
, Etype
(Unit_Name
));
5928 Set_Etype
(Id
, Any_Type
);
5930 ("cannot find program unit referenced by pragma%");
5934 Set_Etype
(Id
, Any_Type
);
5935 Error_Pragma
("pragma% inapplicable to this unit");
5941 end Find_Program_Unit_Name
;
5943 -----------------------------------------
5944 -- Find_Unique_Parameterless_Procedure --
5945 -----------------------------------------
5947 function Find_Unique_Parameterless_Procedure
5949 Arg
: Node_Id
) return Entity_Id
5951 Proc
: Entity_Id
:= Empty
;
5954 -- The body of this procedure needs some comments ???
5956 if not Is_Entity_Name
(Name
) then
5958 ("argument of pragma% must be entity name", Arg
);
5960 elsif not Is_Overloaded
(Name
) then
5961 Proc
:= Entity
(Name
);
5963 if Ekind
(Proc
) /= E_Procedure
5964 or else Present
(First_Formal
(Proc
))
5967 ("argument of pragma% must be parameterless procedure", Arg
);
5972 Found
: Boolean := False;
5974 Index
: Interp_Index
;
5977 Get_First_Interp
(Name
, Index
, It
);
5978 while Present
(It
.Nam
) loop
5981 if Ekind
(Proc
) = E_Procedure
5982 and then No
(First_Formal
(Proc
))
5986 Set_Entity
(Name
, Proc
);
5987 Set_Is_Overloaded
(Name
, False);
5990 ("ambiguous handler name for pragma% ", Arg
);
5994 Get_Next_Interp
(Index
, It
);
5999 ("argument of pragma% must be parameterless procedure",
6002 Proc
:= Entity
(Name
);
6008 end Find_Unique_Parameterless_Procedure
;
6014 function Fix_Error
(Msg
: String) return String is
6015 Res
: String (Msg
'Range) := Msg
;
6016 Res_Last
: Natural := Msg
'Last;
6020 -- If we have a rewriting of another pragma, go to that pragma
6022 if Is_Rewrite_Substitution
(N
)
6023 and then Nkind
(Original_Node
(N
)) = N_Pragma
6025 Error_Msg_Name_1
:= Pragma_Name
(Original_Node
(N
));
6028 -- Case where pragma comes from an aspect specification
6030 if From_Aspect_Specification
(N
) then
6032 -- Change appearence of "pragma" in message to "aspect"
6035 while J
<= Res_Last
- 5 loop
6036 if Res
(J
.. J
+ 5) = "pragma" then
6037 Res
(J
.. J
+ 5) := "aspect";
6045 -- Change "argument of" at start of message to "entity for"
6048 and then Res
(Res
'First .. Res
'First + 10) = "argument of"
6050 Res
(Res
'First .. Res
'First + 9) := "entity for";
6051 Res
(Res
'First + 10 .. Res_Last
- 1) :=
6052 Res
(Res
'First + 11 .. Res_Last
);
6053 Res_Last
:= Res_Last
- 1;
6056 -- Change "argument" at start of message to "entity"
6059 and then Res
(Res
'First .. Res
'First + 7) = "argument"
6061 Res
(Res
'First .. Res
'First + 5) := "entity";
6062 Res
(Res
'First + 6 .. Res_Last
- 2) :=
6063 Res
(Res
'First + 8 .. Res_Last
);
6064 Res_Last
:= Res_Last
- 2;
6067 -- Get name from corresponding aspect
6069 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(N
);
6072 -- Return possibly modified message
6074 return Res
(Res
'First .. Res_Last
);
6077 -------------------------
6078 -- Gather_Associations --
6079 -------------------------
6081 procedure Gather_Associations
6083 Args
: out Args_List
)
6088 -- Initialize all parameters to Empty
6090 for J
in Args
'Range loop
6094 -- That's all we have to do if there are no argument associations
6096 if No
(Pragma_Argument_Associations
(N
)) then
6100 -- Otherwise first deal with any positional parameters present
6102 Arg
:= First
(Pragma_Argument_Associations
(N
));
6103 for Index
in Args
'Range loop
6104 exit when No
(Arg
) or else Chars
(Arg
) /= No_Name
;
6105 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6109 -- Positional parameters all processed, if any left, then we
6110 -- have too many positional parameters.
6112 if Present
(Arg
) and then Chars
(Arg
) = No_Name
then
6114 ("too many positional associations for pragma%", Arg
);
6117 -- Process named parameters if any are present
6119 while Present
(Arg
) loop
6120 if Chars
(Arg
) = No_Name
then
6122 ("positional association cannot follow named association",
6126 for Index
in Names
'Range loop
6127 if Names
(Index
) = Chars
(Arg
) then
6128 if Present
(Args
(Index
)) then
6130 ("duplicate argument association for pragma%", Arg
);
6132 Args
(Index
) := Get_Pragma_Arg
(Arg
);
6137 if Index
= Names
'Last then
6138 Error_Msg_Name_1
:= Pname
;
6139 Error_Msg_N
("pragma% does not allow & argument", Arg
);
6141 -- Check for possible misspelling
6143 for Index1
in Names
'Range loop
6144 if Is_Bad_Spelling_Of
6145 (Chars
(Arg
), Names
(Index1
))
6147 Error_Msg_Name_1
:= Names
(Index1
);
6148 Error_Msg_N
-- CODEFIX
6149 ("\possible misspelling of%", Arg
);
6161 end Gather_Associations
;
6167 procedure GNAT_Pragma
is
6169 -- We need to check the No_Implementation_Pragmas restriction for
6170 -- the case of a pragma from source. Note that the case of aspects
6171 -- generating corresponding pragmas marks these pragmas as not being
6172 -- from source, so this test also catches that case.
6174 if Comes_From_Source
(N
) then
6175 Check_Restriction
(No_Implementation_Pragmas
, N
);
6179 --------------------------
6180 -- Is_Before_First_Decl --
6181 --------------------------
6183 function Is_Before_First_Decl
6184 (Pragma_Node
: Node_Id
;
6185 Decls
: List_Id
) return Boolean
6187 Item
: Node_Id
:= First
(Decls
);
6190 -- Only other pragmas can come before this pragma
6193 if No
(Item
) or else Nkind
(Item
) /= N_Pragma
then
6196 elsif Item
= Pragma_Node
then
6202 end Is_Before_First_Decl
;
6204 -----------------------------
6205 -- Is_Configuration_Pragma --
6206 -----------------------------
6208 -- A configuration pragma must appear in the context clause of a
6209 -- compilation unit, and only other pragmas may precede it. Note that
6210 -- the test below also permits use in a configuration pragma file.
6212 function Is_Configuration_Pragma
return Boolean is
6213 Lis
: constant List_Id
:= List_Containing
(N
);
6214 Par
: constant Node_Id
:= Parent
(N
);
6218 -- If no parent, then we are in the configuration pragma file,
6219 -- so the placement is definitely appropriate.
6224 -- Otherwise we must be in the context clause of a compilation unit
6225 -- and the only thing allowed before us in the context list is more
6226 -- configuration pragmas.
6228 elsif Nkind
(Par
) = N_Compilation_Unit
6229 and then Context_Items
(Par
) = Lis
6236 elsif Nkind
(Prg
) /= N_Pragma
then
6246 end Is_Configuration_Pragma
;
6248 --------------------------
6249 -- Is_In_Context_Clause --
6250 --------------------------
6252 function Is_In_Context_Clause
return Boolean is
6254 Parent_Node
: Node_Id
;
6257 if not Is_List_Member
(N
) then
6261 Plist
:= List_Containing
(N
);
6262 Parent_Node
:= Parent
(Plist
);
6264 if Parent_Node
= Empty
6265 or else Nkind
(Parent_Node
) /= N_Compilation_Unit
6266 or else Context_Items
(Parent_Node
) /= Plist
6273 end Is_In_Context_Clause
;
6275 ---------------------------------
6276 -- Is_Static_String_Expression --
6277 ---------------------------------
6279 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean is
6280 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
6281 Lit
: constant Boolean := Nkind
(Argx
) = N_String_Literal
;
6284 Analyze_And_Resolve
(Argx
);
6286 -- Special case Ada 83, where the expression will never be static,
6287 -- but we will return true if we had a string literal to start with.
6289 if Ada_Version
= Ada_83
then
6292 -- Normal case, true only if we end up with a string literal that
6293 -- is marked as being the result of evaluating a static expression.
6296 return Is_OK_Static_Expression
(Argx
)
6297 and then Nkind
(Argx
) = N_String_Literal
;
6300 end Is_Static_String_Expression
;
6302 ----------------------
6303 -- Pragma_Misplaced --
6304 ----------------------
6306 procedure Pragma_Misplaced
is
6308 Error_Pragma
("incorrect placement of pragma%");
6309 end Pragma_Misplaced
;
6311 ------------------------------------------------
6312 -- Process_Atomic_Independent_Shared_Volatile --
6313 ------------------------------------------------
6315 procedure Process_Atomic_Independent_Shared_Volatile
is
6321 procedure Set_Atomic_VFA
(E
: Entity_Id
);
6322 -- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if
6323 -- no explicit alignment was given, set alignment to unknown, since
6324 -- back end knows what the alignment requirements are for atomic and
6325 -- full access arrays. Note: this is necessary for derived types.
6327 --------------------
6328 -- Set_Atomic_VFA --
6329 --------------------
6331 procedure Set_Atomic_VFA
(E
: Entity_Id
) is
6333 if Prag_Id
= Pragma_Volatile_Full_Access
then
6334 Set_Is_Volatile_Full_Access
(E
);
6339 if not Has_Alignment_Clause
(E
) then
6340 Set_Alignment
(E
, Uint_0
);
6344 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
6347 Check_Ada_83_Warning
;
6348 Check_No_Identifiers
;
6349 Check_Arg_Count
(1);
6350 Check_Arg_Is_Local_Name
(Arg1
);
6351 E_Id
:= Get_Pragma_Arg
(Arg1
);
6353 if Etype
(E_Id
) = Any_Type
then
6358 D
:= Declaration_Node
(E
);
6361 -- A pragma that applies to a Ghost entity becomes Ghost for the
6362 -- purposes of legality checks and removal of ignored Ghost code.
6364 Mark_Pragma_As_Ghost
(N
, E
);
6366 -- Check duplicate before we chain ourselves
6368 Check_Duplicate_Pragma
(E
);
6370 -- Check Atomic and VFA used together
6372 if (Is_Atomic
(E
) and then Prag_Id
= Pragma_Volatile_Full_Access
)
6373 or else (Is_Volatile_Full_Access
(E
)
6374 and then (Prag_Id
= Pragma_Atomic
6376 Prag_Id
= Pragma_Shared
))
6379 ("cannot have Volatile_Full_Access and Atomic for same entity");
6382 -- Check for applying VFA to an entity which has aliased component
6384 if Prag_Id
= Pragma_Volatile_Full_Access
then
6387 Aliased_Comp
: Boolean := False;
6388 -- Set True if aliased component present
6391 if Is_Array_Type
(Etype
(E
)) then
6392 Aliased_Comp
:= Has_Aliased_Components
(Etype
(E
));
6394 -- Record case, too bad Has_Aliased_Components is not also
6395 -- set for records, should it be ???
6397 elsif Is_Record_Type
(Etype
(E
)) then
6398 Comp
:= First_Component_Or_Discriminant
(Etype
(E
));
6399 while Present
(Comp
) loop
6400 if Is_Aliased
(Comp
)
6401 or else Is_Aliased
(Etype
(Comp
))
6403 Aliased_Comp
:= True;
6407 Next_Component_Or_Discriminant
(Comp
);
6411 if Aliased_Comp
then
6413 ("cannot apply Volatile_Full_Access (aliased component "
6419 -- Now check appropriateness of the entity
6422 if Rep_Item_Too_Early
(E
, N
)
6424 Rep_Item_Too_Late
(E
, N
)
6428 Check_First_Subtype
(Arg1
);
6431 -- Attribute belongs on the base type. If the view of the type is
6432 -- currently private, it also belongs on the underlying type.
6434 if Prag_Id
= Pragma_Atomic
6436 Prag_Id
= Pragma_Shared
6438 Prag_Id
= Pragma_Volatile_Full_Access
6441 Set_Atomic_VFA
(Base_Type
(E
));
6442 Set_Atomic_VFA
(Underlying_Type
(E
));
6445 -- Atomic/Shared/Volatile_Full_Access imply Independent
6447 if Prag_Id
/= Pragma_Volatile
then
6448 Set_Is_Independent
(E
);
6449 Set_Is_Independent
(Base_Type
(E
));
6450 Set_Is_Independent
(Underlying_Type
(E
));
6452 if Prag_Id
= Pragma_Independent
then
6453 Record_Independence_Check
(N
, Base_Type
(E
));
6457 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6459 if Prag_Id
/= Pragma_Independent
then
6460 Set_Is_Volatile
(E
);
6461 Set_Is_Volatile
(Base_Type
(E
));
6462 Set_Is_Volatile
(Underlying_Type
(E
));
6464 Set_Treat_As_Volatile
(E
);
6465 Set_Treat_As_Volatile
(Underlying_Type
(E
));
6468 elsif K
= N_Object_Declaration
6469 or else (K
= N_Component_Declaration
6470 and then Original_Record_Component
(E
) = E
)
6472 if Rep_Item_Too_Late
(E
, N
) then
6476 if Prag_Id
= Pragma_Atomic
6478 Prag_Id
= Pragma_Shared
6480 Prag_Id
= Pragma_Volatile_Full_Access
6482 if Prag_Id
= Pragma_Volatile_Full_Access
then
6483 Set_Is_Volatile_Full_Access
(E
);
6488 -- If the object declaration has an explicit initialization, a
6489 -- temporary may have to be created to hold the expression, to
6490 -- ensure that access to the object remain atomic.
6492 if Nkind
(Parent
(E
)) = N_Object_Declaration
6493 and then Present
(Expression
(Parent
(E
)))
6495 Set_Has_Delayed_Freeze
(E
);
6499 -- Atomic/Shared/Volatile_Full_Access imply Independent
6501 if Prag_Id
/= Pragma_Volatile
then
6502 Set_Is_Independent
(E
);
6504 if Prag_Id
= Pragma_Independent
then
6505 Record_Independence_Check
(N
, E
);
6509 -- Atomic/Shared/Volatile_Full_Access imply Volatile
6511 if Prag_Id
/= Pragma_Independent
then
6512 Set_Is_Volatile
(E
);
6513 Set_Treat_As_Volatile
(E
);
6517 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
6520 -- The following check is only relevant when SPARK_Mode is on as
6521 -- this is not a standard Ada legality rule. Pragma Volatile can
6522 -- only apply to a full type declaration or an object declaration
6523 -- (SPARK RM C.6(1)).
6526 and then Prag_Id
= Pragma_Volatile
6527 and then not Nkind_In
(K
, N_Full_Type_Declaration
,
6528 N_Object_Declaration
)
6531 ("argument of pragma % must denote a full type or object "
6532 & "declaration", Arg1
);
6534 end Process_Atomic_Independent_Shared_Volatile
;
6536 -------------------------------------------
6537 -- Process_Compile_Time_Warning_Or_Error --
6538 -------------------------------------------
6540 procedure Process_Compile_Time_Warning_Or_Error
is
6541 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
6544 Check_Arg_Count
(2);
6545 Check_No_Identifiers
;
6546 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
6547 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
6549 if Compile_Time_Known_Value
(Arg1x
) then
6550 if Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
))) then
6552 Str
: constant String_Id
:=
6553 Strval
(Get_Pragma_Arg
(Arg2
));
6554 Len
: constant Int
:= String_Length
(Str
);
6559 Cent
: constant Entity_Id
:=
6560 Cunit_Entity
(Current_Sem_Unit
);
6562 Force
: constant Boolean :=
6563 Prag_Id
= Pragma_Compile_Time_Warning
6565 Is_Spec_Name
(Unit_Name
(Current_Sem_Unit
))
6566 and then (Ekind
(Cent
) /= E_Package
6567 or else not In_Private_Part
(Cent
));
6568 -- Set True if this is the warning case, and we are in the
6569 -- visible part of a package spec, or in a subprogram spec,
6570 -- in which case we want to force the client to see the
6571 -- warning, even though it is not in the main unit.
6574 -- Loop through segments of message separated by line feeds.
6575 -- We output these segments as separate messages with
6576 -- continuation marks for all but the first.
6581 Error_Msg_Strlen
:= 0;
6583 -- Loop to copy characters from argument to error message
6587 exit when Ptr
> Len
;
6588 CC
:= Get_String_Char
(Str
, Ptr
);
6591 -- Ignore wide chars ??? else store character
6593 if In_Character_Range
(CC
) then
6594 C
:= Get_Character
(CC
);
6595 exit when C
= ASCII
.LF
;
6596 Error_Msg_Strlen
:= Error_Msg_Strlen
+ 1;
6597 Error_Msg_String
(Error_Msg_Strlen
) := C
;
6601 -- Here with one line ready to go
6603 Error_Msg_Warn
:= Prag_Id
= Pragma_Compile_Time_Warning
;
6605 -- If this is a warning in a spec, then we want clients
6606 -- to see the warning, so mark the message with the
6607 -- special sequence !! to force the warning. In the case
6608 -- of a package spec, we do not force this if we are in
6609 -- the private part of the spec.
6612 if Cont
= False then
6613 Error_Msg_N
("<<~!!", Arg1
);
6616 Error_Msg_N
("\<<~!!", Arg1
);
6619 -- Error, rather than warning, or in a body, so we do not
6620 -- need to force visibility for client (error will be
6621 -- output in any case, and this is the situation in which
6622 -- we do not want a client to get a warning, since the
6623 -- warning is in the body or the spec private part).
6626 if Cont
= False then
6627 Error_Msg_N
("<<~", Arg1
);
6630 Error_Msg_N
("\<<~", Arg1
);
6634 exit when Ptr
> Len
;
6639 end Process_Compile_Time_Warning_Or_Error
;
6641 ------------------------
6642 -- Process_Convention --
6643 ------------------------
6645 procedure Process_Convention
6646 (C
: out Convention_Id
;
6647 Ent
: out Entity_Id
)
6651 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
);
6652 -- Called if we have more than one Export/Import/Convention pragma.
6653 -- This is generally illegal, but we have a special case of allowing
6654 -- Import and Interface to coexist if they specify the convention in
6655 -- a consistent manner. We are allowed to do this, since Interface is
6656 -- an implementation defined pragma, and we choose to do it since we
6657 -- know Rational allows this combination. S is the entity id of the
6658 -- subprogram in question. This procedure also sets the special flag
6659 -- Import_Interface_Present in both pragmas in the case where we do
6660 -- have matching Import and Interface pragmas.
6662 procedure Set_Convention_From_Pragma
(E
: Entity_Id
);
6663 -- Set convention in entity E, and also flag that the entity has a
6664 -- convention pragma. If entity is for a private or incomplete type,
6665 -- also set convention and flag on underlying type. This procedure
6666 -- also deals with the special case of C_Pass_By_Copy convention,
6667 -- and error checks for inappropriate convention specification.
6669 -------------------------------
6670 -- Diagnose_Multiple_Pragmas --
6671 -------------------------------
6673 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
) is
6674 Pdec
: constant Node_Id
:= Declaration_Node
(S
);
6678 function Same_Convention
(Decl
: Node_Id
) return Boolean;
6679 -- Decl is a pragma node. This function returns True if this
6680 -- pragma has a first argument that is an identifier with a
6681 -- Chars field corresponding to the Convention_Id C.
6683 function Same_Name
(Decl
: Node_Id
) return Boolean;
6684 -- Decl is a pragma node. This function returns True if this
6685 -- pragma has a second argument that is an identifier with a
6686 -- Chars field that matches the Chars of the current subprogram.
6688 ---------------------
6689 -- Same_Convention --
6690 ---------------------
6692 function Same_Convention
(Decl
: Node_Id
) return Boolean is
6693 Arg1
: constant Node_Id
:=
6694 First
(Pragma_Argument_Associations
(Decl
));
6697 if Present
(Arg1
) then
6699 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
6701 if Nkind
(Arg
) = N_Identifier
6702 and then Is_Convention_Name
(Chars
(Arg
))
6703 and then Get_Convention_Id
(Chars
(Arg
)) = C
6711 end Same_Convention
;
6717 function Same_Name
(Decl
: Node_Id
) return Boolean is
6718 Arg1
: constant Node_Id
:=
6719 First
(Pragma_Argument_Associations
(Decl
));
6727 Arg2
:= Next
(Arg1
);
6734 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
6736 if Nkind
(Arg
) = N_Identifier
6737 and then Chars
(Arg
) = Chars
(S
)
6746 -- Start of processing for Diagnose_Multiple_Pragmas
6751 -- Definitely give message if we have Convention/Export here
6753 if Prag_Id
= Pragma_Convention
or else Prag_Id
= Pragma_Export
then
6756 -- If we have an Import or Export, scan back from pragma to
6757 -- find any previous pragma applying to the same procedure.
6758 -- The scan will be terminated by the start of the list, or
6759 -- hitting the subprogram declaration. This won't allow one
6760 -- pragma to appear in the public part and one in the private
6761 -- part, but that seems very unlikely in practice.
6765 while Present
(Decl
) and then Decl
/= Pdec
loop
6767 -- Look for pragma with same name as us
6769 if Nkind
(Decl
) = N_Pragma
6770 and then Same_Name
(Decl
)
6772 -- Give error if same as our pragma or Export/Convention
6774 if Nam_In
(Pragma_Name
(Decl
), Name_Export
,
6780 -- Case of Import/Interface or the other way round
6782 elsif Nam_In
(Pragma_Name
(Decl
), Name_Interface
,
6785 -- Here we know that we have Import and Interface. It
6786 -- doesn't matter which way round they are. See if
6787 -- they specify the same convention. If so, all OK,
6788 -- and set special flags to stop other messages
6790 if Same_Convention
(Decl
) then
6791 Set_Import_Interface_Present
(N
);
6792 Set_Import_Interface_Present
(Decl
);
6795 -- If different conventions, special message
6798 Error_Msg_Sloc
:= Sloc
(Decl
);
6800 ("convention differs from that given#", Arg1
);
6810 -- Give message if needed if we fall through those tests
6811 -- except on Relaxed_RM_Semantics where we let go: either this
6812 -- is a case accepted/ignored by other Ada compilers (e.g.
6813 -- a mix of Convention and Import), or another error will be
6814 -- generated later (e.g. using both Import and Export).
6816 if Err
and not Relaxed_RM_Semantics
then
6818 ("at most one Convention/Export/Import pragma is allowed",
6821 end Diagnose_Multiple_Pragmas
;
6823 --------------------------------
6824 -- Set_Convention_From_Pragma --
6825 --------------------------------
6827 procedure Set_Convention_From_Pragma
(E
: Entity_Id
) is
6829 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6830 -- for an overridden dispatching operation. Technically this is
6831 -- an amendment and should only be done in Ada 2005 mode. However,
6832 -- this is clearly a mistake, since the problem that is addressed
6833 -- by this AI is that there is a clear gap in the RM.
6835 if Is_Dispatching_Operation
(E
)
6836 and then Present
(Overridden_Operation
(E
))
6837 and then C
/= Convention
(Overridden_Operation
(E
))
6840 ("cannot change convention for overridden dispatching "
6841 & "operation", Arg1
);
6844 -- Special checks for Convention_Stdcall
6846 if C
= Convention_Stdcall
then
6848 -- A dispatching call is not allowed. A dispatching subprogram
6849 -- cannot be used to interface to the Win32 API, so in fact
6850 -- this check does not impose any effective restriction.
6852 if Is_Dispatching_Operation
(E
) then
6853 Error_Msg_Sloc
:= Sloc
(E
);
6855 -- Note: make this unconditional so that if there is more
6856 -- than one call to which the pragma applies, we get a
6857 -- message for each call. Also don't use Error_Pragma,
6858 -- so that we get multiple messages.
6861 ("dispatching subprogram# cannot use Stdcall convention!",
6864 -- Subprograms are not allowed
6866 elsif not Is_Subprogram_Or_Generic_Subprogram
(E
)
6870 and then Ekind
(E
) /= E_Variable
6872 -- An access to subprogram is also allowed
6876 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
)
6878 -- Allow internal call to set convention of subprogram type
6880 and then not (Ekind
(E
) = E_Subprogram_Type
)
6883 ("second argument of pragma% must be subprogram (type)",
6888 -- Set the convention
6890 Set_Convention
(E
, C
);
6891 Set_Has_Convention_Pragma
(E
);
6893 -- For the case of a record base type, also set the convention of
6894 -- any anonymous access types declared in the record which do not
6895 -- currently have a specified convention.
6897 if Is_Record_Type
(E
) and then Is_Base_Type
(E
) then
6902 Comp
:= First_Component
(E
);
6903 while Present
(Comp
) loop
6904 if Present
(Etype
(Comp
))
6905 and then Ekind_In
(Etype
(Comp
),
6906 E_Anonymous_Access_Type
,
6907 E_Anonymous_Access_Subprogram_Type
)
6908 and then not Has_Convention_Pragma
(Comp
)
6910 Set_Convention
(Comp
, C
);
6913 Next_Component
(Comp
);
6918 -- Deal with incomplete/private type case, where underlying type
6919 -- is available, so set convention of that underlying type.
6921 if Is_Incomplete_Or_Private_Type
(E
)
6922 and then Present
(Underlying_Type
(E
))
6924 Set_Convention
(Underlying_Type
(E
), C
);
6925 Set_Has_Convention_Pragma
(Underlying_Type
(E
), True);
6928 -- A class-wide type should inherit the convention of the specific
6929 -- root type (although this isn't specified clearly by the RM).
6931 if Is_Type
(E
) and then Present
(Class_Wide_Type
(E
)) then
6932 Set_Convention
(Class_Wide_Type
(E
), C
);
6935 -- If the entity is a record type, then check for special case of
6936 -- C_Pass_By_Copy, which is treated the same as C except that the
6937 -- special record flag is set. This convention is only permitted
6938 -- on record types (see AI95-00131).
6940 if Cname
= Name_C_Pass_By_Copy
then
6941 if Is_Record_Type
(E
) then
6942 Set_C_Pass_By_Copy
(Base_Type
(E
));
6943 elsif Is_Incomplete_Or_Private_Type
(E
)
6944 and then Is_Record_Type
(Underlying_Type
(E
))
6946 Set_C_Pass_By_Copy
(Base_Type
(Underlying_Type
(E
)));
6949 ("C_Pass_By_Copy convention allowed only for record type",
6954 -- If the entity is a derived boolean type, check for the special
6955 -- case of convention C, C++, or Fortran, where we consider any
6956 -- nonzero value to represent true.
6958 if Is_Discrete_Type
(E
)
6959 and then Root_Type
(Etype
(E
)) = Standard_Boolean
6965 C
= Convention_Fortran
)
6967 Set_Nonzero_Is_True
(Base_Type
(E
));
6969 end Set_Convention_From_Pragma
;
6973 Comp_Unit
: Unit_Number_Type
;
6978 -- Start of processing for Process_Convention
6981 Check_At_Least_N_Arguments
(2);
6982 Check_Optional_Identifier
(Arg1
, Name_Convention
);
6983 Check_Arg_Is_Identifier
(Arg1
);
6984 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
6986 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6987 -- tested again below to set the critical flag).
6989 if Cname
= Name_C_Pass_By_Copy
then
6992 -- Otherwise we must have something in the standard convention list
6994 elsif Is_Convention_Name
(Cname
) then
6995 C
:= Get_Convention_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
6997 -- Otherwise warn on unrecognized convention
7000 if Warn_On_Export_Import
then
7002 ("??unrecognized convention name, C assumed",
7003 Get_Pragma_Arg
(Arg1
));
7009 Check_Optional_Identifier
(Arg2
, Name_Entity
);
7010 Check_Arg_Is_Local_Name
(Arg2
);
7012 Id
:= Get_Pragma_Arg
(Arg2
);
7015 if not Is_Entity_Name
(Id
) then
7016 Error_Pragma_Arg
("entity name required", Arg2
);
7021 -- Set entity to return
7025 -- Ada_Pass_By_Copy special checking
7027 if C
= Convention_Ada_Pass_By_Copy
then
7028 if not Is_First_Subtype
(E
) then
7030 ("convention `Ada_Pass_By_Copy` only allowed for types",
7034 if Is_By_Reference_Type
(E
) then
7036 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
7040 -- Ada_Pass_By_Reference special checking
7042 elsif C
= Convention_Ada_Pass_By_Reference
then
7043 if not Is_First_Subtype
(E
) then
7045 ("convention `Ada_Pass_By_Reference` only allowed for types",
7049 if Is_By_Copy_Type
(E
) then
7051 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
7056 -- Go to renamed subprogram if present, since convention applies to
7057 -- the actual renamed entity, not to the renaming entity. If the
7058 -- subprogram is inherited, go to parent subprogram.
7060 if Is_Subprogram
(E
)
7061 and then Present
(Alias
(E
))
7063 if Nkind
(Parent
(Declaration_Node
(E
))) =
7064 N_Subprogram_Renaming_Declaration
7066 if Scope
(E
) /= Scope
(Alias
(E
)) then
7068 ("cannot apply pragma% to non-local entity&#", E
);
7073 elsif Nkind_In
(Parent
(E
), N_Full_Type_Declaration
,
7074 N_Private_Extension_Declaration
)
7075 and then Scope
(E
) = Scope
(Alias
(E
))
7079 -- Return the parent subprogram the entity was inherited from
7085 -- Check that we are not applying this to a specless body. Relax this
7086 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
7088 if Is_Subprogram
(E
)
7089 and then Nkind
(Parent
(Declaration_Node
(E
))) = N_Subprogram_Body
7090 and then not Relaxed_RM_Semantics
7093 ("pragma% requires separate spec and must come before body");
7096 -- Check that we are not applying this to a named constant
7098 if Ekind_In
(E
, E_Named_Integer
, E_Named_Real
) then
7099 Error_Msg_Name_1
:= Pname
;
7101 ("cannot apply pragma% to named constant!",
7102 Get_Pragma_Arg
(Arg2
));
7104 ("\supply appropriate type for&!", Arg2
);
7107 if Ekind
(E
) = E_Enumeration_Literal
then
7108 Error_Pragma
("enumeration literal not allowed for pragma%");
7111 -- Check for rep item appearing too early or too late
7113 if Etype
(E
) = Any_Type
7114 or else Rep_Item_Too_Early
(E
, N
)
7118 elsif Present
(Underlying_Type
(E
)) then
7119 E
:= Underlying_Type
(E
);
7122 if Rep_Item_Too_Late
(E
, N
) then
7126 if Has_Convention_Pragma
(E
) then
7127 Diagnose_Multiple_Pragmas
(E
);
7129 elsif Convention
(E
) = Convention_Protected
7130 or else Ekind
(Scope
(E
)) = E_Protected_Type
7133 ("a protected operation cannot be given a different convention",
7137 -- For Intrinsic, a subprogram is required
7139 if C
= Convention_Intrinsic
7140 and then not Is_Subprogram_Or_Generic_Subprogram
(E
)
7143 ("second argument of pragma% must be a subprogram", Arg2
);
7146 -- Deal with non-subprogram cases
7148 if not Is_Subprogram_Or_Generic_Subprogram
(E
) then
7149 Set_Convention_From_Pragma
(E
);
7153 -- The pragma must apply to a first subtype, but it can also
7154 -- apply to a generic type in a generic formal part, in which
7155 -- case it will also appear in the corresponding instance.
7157 if Is_Generic_Type
(E
) or else In_Instance
then
7160 Check_First_Subtype
(Arg2
);
7163 Set_Convention_From_Pragma
(Base_Type
(E
));
7165 -- For access subprograms, we must set the convention on the
7166 -- internally generated directly designated type as well.
7168 if Ekind
(E
) = E_Access_Subprogram_Type
then
7169 Set_Convention_From_Pragma
(Directly_Designated_Type
(E
));
7173 -- For the subprogram case, set proper convention for all homonyms
7174 -- in same scope and the same declarative part, i.e. the same
7175 -- compilation unit.
7178 Comp_Unit
:= Get_Source_Unit
(E
);
7179 Set_Convention_From_Pragma
(E
);
7181 -- Treat a pragma Import as an implicit body, and pragma import
7182 -- as implicit reference (for navigation in GPS).
7184 if Prag_Id
= Pragma_Import
then
7185 Generate_Reference
(E
, Id
, 'b');
7187 -- For exported entities we restrict the generation of references
7188 -- to entities exported to foreign languages since entities
7189 -- exported to Ada do not provide further information to GPS and
7190 -- add undesired references to the output of the gnatxref tool.
7192 elsif Prag_Id
= Pragma_Export
7193 and then Convention
(E
) /= Convention_Ada
7195 Generate_Reference
(E
, Id
, 'i');
7198 -- If the pragma comes from an aspect, it only applies to the
7199 -- given entity, not its homonyms.
7201 if From_Aspect_Specification
(N
) then
7205 -- Otherwise Loop through the homonyms of the pragma argument's
7206 -- entity, an apply convention to those in the current scope.
7212 exit when No
(E1
) or else Scope
(E1
) /= Current_Scope
;
7214 -- Ignore entry for which convention is already set
7216 if Has_Convention_Pragma
(E1
) then
7220 -- Do not set the pragma on inherited operations or on formal
7223 if Comes_From_Source
(E1
)
7224 and then Comp_Unit
= Get_Source_Unit
(E1
)
7225 and then not Is_Formal_Subprogram
(E1
)
7226 and then Nkind
(Original_Node
(Parent
(E1
))) /=
7227 N_Full_Type_Declaration
7229 if Present
(Alias
(E1
))
7230 and then Scope
(E1
) /= Scope
(Alias
(E1
))
7233 ("cannot apply pragma% to non-local entity& declared#",
7237 Set_Convention_From_Pragma
(E1
);
7239 if Prag_Id
= Pragma_Import
then
7240 Generate_Reference
(E1
, Id
, 'b');
7248 end Process_Convention
;
7250 ----------------------------------------
7251 -- Process_Disable_Enable_Atomic_Sync --
7252 ----------------------------------------
7254 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
) is
7256 Check_No_Identifiers
;
7257 Check_At_Most_N_Arguments
(1);
7259 -- Modeled internally as
7260 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
7264 Pragma_Identifier
=>
7265 Make_Identifier
(Loc
, Nam
),
7266 Pragma_Argument_Associations
=> New_List
(
7267 Make_Pragma_Argument_Association
(Loc
,
7269 Make_Identifier
(Loc
, Name_Atomic_Synchronization
)))));
7271 if Present
(Arg1
) then
7272 Append_To
(Pragma_Argument_Associations
(N
), New_Copy
(Arg1
));
7276 end Process_Disable_Enable_Atomic_Sync
;
7278 -------------------------------------------------
7279 -- Process_Extended_Import_Export_Internal_Arg --
7280 -------------------------------------------------
7282 procedure Process_Extended_Import_Export_Internal_Arg
7283 (Arg_Internal
: Node_Id
:= Empty
)
7286 if No
(Arg_Internal
) then
7287 Error_Pragma
("Internal parameter required for pragma%");
7290 if Nkind
(Arg_Internal
) = N_Identifier
then
7293 elsif Nkind
(Arg_Internal
) = N_Operator_Symbol
7294 and then (Prag_Id
= Pragma_Import_Function
7296 Prag_Id
= Pragma_Export_Function
)
7302 ("wrong form for Internal parameter for pragma%", Arg_Internal
);
7305 Check_Arg_Is_Local_Name
(Arg_Internal
);
7306 end Process_Extended_Import_Export_Internal_Arg
;
7308 --------------------------------------------------
7309 -- Process_Extended_Import_Export_Object_Pragma --
7310 --------------------------------------------------
7312 procedure Process_Extended_Import_Export_Object_Pragma
7313 (Arg_Internal
: Node_Id
;
7314 Arg_External
: Node_Id
;
7320 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
7321 Def_Id
:= Entity
(Arg_Internal
);
7323 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
7325 ("pragma% must designate an object", Arg_Internal
);
7328 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
7330 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
7333 ("previous Common/Psect_Object applies, pragma % not permitted",
7337 if Rep_Item_Too_Late
(Def_Id
, N
) then
7341 Set_Extended_Import_Export_External_Name
(Def_Id
, Arg_External
);
7343 if Present
(Arg_Size
) then
7344 Check_Arg_Is_External_Name
(Arg_Size
);
7347 -- Export_Object case
7349 if Prag_Id
= Pragma_Export_Object
then
7350 if not Is_Library_Level_Entity
(Def_Id
) then
7352 ("argument for pragma% must be library level entity",
7356 if Ekind
(Current_Scope
) = E_Generic_Package
then
7357 Error_Pragma
("pragma& cannot appear in a generic unit");
7360 if not Size_Known_At_Compile_Time
(Etype
(Def_Id
)) then
7362 ("exported object must have compile time known size",
7366 if Warn_On_Export_Import
and then Is_Exported
(Def_Id
) then
7367 Error_Msg_N
("??duplicate Export_Object pragma", N
);
7369 Set_Exported
(Def_Id
, Arg_Internal
);
7372 -- Import_Object case
7375 if Is_Concurrent_Type
(Etype
(Def_Id
)) then
7377 ("cannot use pragma% for task/protected object",
7381 if Ekind
(Def_Id
) = E_Constant
then
7383 ("cannot import a constant", Arg_Internal
);
7386 if Warn_On_Export_Import
7387 and then Has_Discriminants
(Etype
(Def_Id
))
7390 ("imported value must be initialized??", Arg_Internal
);
7393 if Warn_On_Export_Import
7394 and then Is_Access_Type
(Etype
(Def_Id
))
7397 ("cannot import object of an access type??", Arg_Internal
);
7400 if Warn_On_Export_Import
7401 and then Is_Imported
(Def_Id
)
7403 Error_Msg_N
("??duplicate Import_Object pragma", N
);
7405 -- Check for explicit initialization present. Note that an
7406 -- initialization generated by the code generator, e.g. for an
7407 -- access type, does not count here.
7409 elsif Present
(Expression
(Parent
(Def_Id
)))
7412 (Original_Node
(Expression
(Parent
(Def_Id
))))
7414 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7416 ("imported entities cannot be initialized (RM B.1(24))",
7417 "\no initialization allowed for & declared#", Arg1
);
7419 Set_Imported
(Def_Id
);
7420 Note_Possible_Modification
(Arg_Internal
, Sure
=> False);
7423 end Process_Extended_Import_Export_Object_Pragma
;
7425 ------------------------------------------------------
7426 -- Process_Extended_Import_Export_Subprogram_Pragma --
7427 ------------------------------------------------------
7429 procedure Process_Extended_Import_Export_Subprogram_Pragma
7430 (Arg_Internal
: Node_Id
;
7431 Arg_External
: Node_Id
;
7432 Arg_Parameter_Types
: Node_Id
;
7433 Arg_Result_Type
: Node_Id
:= Empty
;
7434 Arg_Mechanism
: Node_Id
;
7435 Arg_Result_Mechanism
: Node_Id
:= Empty
)
7441 Ambiguous
: Boolean;
7444 function Same_Base_Type
7446 Formal
: Entity_Id
) return Boolean;
7447 -- Determines if Ptype references the type of Formal. Note that only
7448 -- the base types need to match according to the spec. Ptype here is
7449 -- the argument from the pragma, which is either a type name, or an
7450 -- access attribute.
7452 --------------------
7453 -- Same_Base_Type --
7454 --------------------
7456 function Same_Base_Type
7458 Formal
: Entity_Id
) return Boolean
7460 Ftyp
: constant Entity_Id
:= Base_Type
(Etype
(Formal
));
7464 -- Case where pragma argument is typ'Access
7466 if Nkind
(Ptype
) = N_Attribute_Reference
7467 and then Attribute_Name
(Ptype
) = Name_Access
7469 Pref
:= Prefix
(Ptype
);
7472 if not Is_Entity_Name
(Pref
)
7473 or else Entity
(Pref
) = Any_Type
7478 -- We have a match if the corresponding argument is of an
7479 -- anonymous access type, and its designated type matches the
7480 -- type of the prefix of the access attribute
7482 return Ekind
(Ftyp
) = E_Anonymous_Access_Type
7483 and then Base_Type
(Entity
(Pref
)) =
7484 Base_Type
(Etype
(Designated_Type
(Ftyp
)));
7486 -- Case where pragma argument is a type name
7491 if not Is_Entity_Name
(Ptype
)
7492 or else Entity
(Ptype
) = Any_Type
7497 -- We have a match if the corresponding argument is of the type
7498 -- given in the pragma (comparing base types)
7500 return Base_Type
(Entity
(Ptype
)) = Ftyp
;
7504 -- Start of processing for
7505 -- Process_Extended_Import_Export_Subprogram_Pragma
7508 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
7512 -- Loop through homonyms (overloadings) of the entity
7514 Hom_Id
:= Entity
(Arg_Internal
);
7515 while Present
(Hom_Id
) loop
7516 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
7518 -- We need a subprogram in the current scope
7520 if not Is_Subprogram
(Def_Id
)
7521 or else Scope
(Def_Id
) /= Current_Scope
7528 -- Pragma cannot apply to subprogram body
7530 if Is_Subprogram
(Def_Id
)
7531 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
7535 ("pragma% requires separate spec"
7536 & " and must come before body");
7539 -- Test result type if given, note that the result type
7540 -- parameter can only be present for the function cases.
7542 if Present
(Arg_Result_Type
)
7543 and then not Same_Base_Type
(Arg_Result_Type
, Def_Id
)
7547 elsif Etype
(Def_Id
) /= Standard_Void_Type
7549 Nam_In
(Pname
, Name_Export_Procedure
, Name_Import_Procedure
)
7553 -- Test parameter types if given. Note that this parameter
7554 -- has not been analyzed (and must not be, since it is
7555 -- semantic nonsense), so we get it as the parser left it.
7557 elsif Present
(Arg_Parameter_Types
) then
7558 Check_Matching_Types
: declare
7563 Formal
:= First_Formal
(Def_Id
);
7565 if Nkind
(Arg_Parameter_Types
) = N_Null
then
7566 if Present
(Formal
) then
7570 -- A list of one type, e.g. (List) is parsed as
7571 -- a parenthesized expression.
7573 elsif Nkind
(Arg_Parameter_Types
) /= N_Aggregate
7574 and then Paren_Count
(Arg_Parameter_Types
) = 1
7577 or else Present
(Next_Formal
(Formal
))
7582 Same_Base_Type
(Arg_Parameter_Types
, Formal
);
7585 -- A list of more than one type is parsed as a aggregate
7587 elsif Nkind
(Arg_Parameter_Types
) = N_Aggregate
7588 and then Paren_Count
(Arg_Parameter_Types
) = 0
7590 Ptype
:= First
(Expressions
(Arg_Parameter_Types
));
7591 while Present
(Ptype
) or else Present
(Formal
) loop
7594 or else not Same_Base_Type
(Ptype
, Formal
)
7599 Next_Formal
(Formal
);
7604 -- Anything else is of the wrong form
7608 ("wrong form for Parameter_Types parameter",
7609 Arg_Parameter_Types
);
7611 end Check_Matching_Types
;
7614 -- Match is now False if the entry we found did not match
7615 -- either a supplied Parameter_Types or Result_Types argument
7621 -- Ambiguous case, the flag Ambiguous shows if we already
7622 -- detected this and output the initial messages.
7625 if not Ambiguous
then
7627 Error_Msg_Name_1
:= Pname
;
7629 ("pragma% does not uniquely identify subprogram!",
7631 Error_Msg_Sloc
:= Sloc
(Ent
);
7632 Error_Msg_N
("matching subprogram #!", N
);
7636 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7637 Error_Msg_N
("matching subprogram #!", N
);
7642 Hom_Id
:= Homonym
(Hom_Id
);
7645 -- See if we found an entry
7648 if not Ambiguous
then
7649 if Is_Generic_Subprogram
(Entity
(Arg_Internal
)) then
7651 ("pragma% cannot be given for generic subprogram");
7654 ("pragma% does not identify local subprogram");
7661 -- Import pragmas must be for imported entities
7663 if Prag_Id
= Pragma_Import_Function
7665 Prag_Id
= Pragma_Import_Procedure
7667 Prag_Id
= Pragma_Import_Valued_Procedure
7669 if not Is_Imported
(Ent
) then
7671 ("pragma Import or Interface must precede pragma%");
7674 -- Here we have the Export case which can set the entity as exported
7676 -- But does not do so if the specified external name is null, since
7677 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7678 -- compatible) to request no external name.
7680 elsif Nkind
(Arg_External
) = N_String_Literal
7681 and then String_Length
(Strval
(Arg_External
)) = 0
7685 -- In all other cases, set entity as exported
7688 Set_Exported
(Ent
, Arg_Internal
);
7691 -- Special processing for Valued_Procedure cases
7693 if Prag_Id
= Pragma_Import_Valued_Procedure
7695 Prag_Id
= Pragma_Export_Valued_Procedure
7697 Formal
:= First_Formal
(Ent
);
7700 Error_Pragma
("at least one parameter required for pragma%");
7702 elsif Ekind
(Formal
) /= E_Out_Parameter
then
7703 Error_Pragma
("first parameter must have mode out for pragma%");
7706 Set_Is_Valued_Procedure
(Ent
);
7710 Set_Extended_Import_Export_External_Name
(Ent
, Arg_External
);
7712 -- Process Result_Mechanism argument if present. We have already
7713 -- checked that this is only allowed for the function case.
7715 if Present
(Arg_Result_Mechanism
) then
7716 Set_Mechanism_Value
(Ent
, Arg_Result_Mechanism
);
7719 -- Process Mechanism parameter if present. Note that this parameter
7720 -- is not analyzed, and must not be analyzed since it is semantic
7721 -- nonsense, so we get it in exactly as the parser left it.
7723 if Present
(Arg_Mechanism
) then
7731 -- A single mechanism association without a formal parameter
7732 -- name is parsed as a parenthesized expression. All other
7733 -- cases are parsed as aggregates, so we rewrite the single
7734 -- parameter case as an aggregate for consistency.
7736 if Nkind
(Arg_Mechanism
) /= N_Aggregate
7737 and then Paren_Count
(Arg_Mechanism
) = 1
7739 Rewrite
(Arg_Mechanism
,
7740 Make_Aggregate
(Sloc
(Arg_Mechanism
),
7741 Expressions
=> New_List
(
7742 Relocate_Node
(Arg_Mechanism
))));
7745 -- Case of only mechanism name given, applies to all formals
7747 if Nkind
(Arg_Mechanism
) /= N_Aggregate
then
7748 Formal
:= First_Formal
(Ent
);
7749 while Present
(Formal
) loop
7750 Set_Mechanism_Value
(Formal
, Arg_Mechanism
);
7751 Next_Formal
(Formal
);
7754 -- Case of list of mechanism associations given
7757 if Null_Record_Present
(Arg_Mechanism
) then
7759 ("inappropriate form for Mechanism parameter",
7763 -- Deal with positional ones first
7765 Formal
:= First_Formal
(Ent
);
7767 if Present
(Expressions
(Arg_Mechanism
)) then
7768 Mname
:= First
(Expressions
(Arg_Mechanism
));
7769 while Present
(Mname
) loop
7772 ("too many mechanism associations", Mname
);
7775 Set_Mechanism_Value
(Formal
, Mname
);
7776 Next_Formal
(Formal
);
7781 -- Deal with named entries
7783 if Present
(Component_Associations
(Arg_Mechanism
)) then
7784 Massoc
:= First
(Component_Associations
(Arg_Mechanism
));
7785 while Present
(Massoc
) loop
7786 Choice
:= First
(Choices
(Massoc
));
7788 if Nkind
(Choice
) /= N_Identifier
7789 or else Present
(Next
(Choice
))
7792 ("incorrect form for mechanism association",
7796 Formal
:= First_Formal
(Ent
);
7800 ("parameter name & not present", Choice
);
7803 if Chars
(Choice
) = Chars
(Formal
) then
7805 (Formal
, Expression
(Massoc
));
7807 -- Set entity on identifier (needed by ASIS)
7809 Set_Entity
(Choice
, Formal
);
7814 Next_Formal
(Formal
);
7823 end Process_Extended_Import_Export_Subprogram_Pragma
;
7825 --------------------------
7826 -- Process_Generic_List --
7827 --------------------------
7829 procedure Process_Generic_List
is
7834 Check_No_Identifiers
;
7835 Check_At_Least_N_Arguments
(1);
7837 -- Check all arguments are names of generic units or instances
7840 while Present
(Arg
) loop
7841 Exp
:= Get_Pragma_Arg
(Arg
);
7844 if not Is_Entity_Name
(Exp
)
7846 (not Is_Generic_Instance
(Entity
(Exp
))
7848 not Is_Generic_Unit
(Entity
(Exp
)))
7851 ("pragma% argument must be name of generic unit/instance",
7857 end Process_Generic_List
;
7859 ------------------------------------
7860 -- Process_Import_Predefined_Type --
7861 ------------------------------------
7863 procedure Process_Import_Predefined_Type
is
7864 Loc
: constant Source_Ptr
:= Sloc
(N
);
7866 Ftyp
: Node_Id
:= Empty
;
7872 String_To_Name_Buffer
(Strval
(Expression
(Arg3
)));
7875 Elmt
:= First_Elmt
(Predefined_Float_Types
);
7876 while Present
(Elmt
) and then Chars
(Node
(Elmt
)) /= Nam
loop
7880 Ftyp
:= Node
(Elmt
);
7882 if Present
(Ftyp
) then
7884 -- Don't build a derived type declaration, because predefined C
7885 -- types have no declaration anywhere, so cannot really be named.
7886 -- Instead build a full type declaration, starting with an
7887 -- appropriate type definition is built
7889 if Is_Floating_Point_Type
(Ftyp
) then
7890 Def
:= Make_Floating_Point_Definition
(Loc
,
7891 Make_Integer_Literal
(Loc
, Digits_Value
(Ftyp
)),
7892 Make_Real_Range_Specification
(Loc
,
7893 Make_Real_Literal
(Loc
, Realval
(Type_Low_Bound
(Ftyp
))),
7894 Make_Real_Literal
(Loc
, Realval
(Type_High_Bound
(Ftyp
)))));
7896 -- Should never have a predefined type we cannot handle
7899 raise Program_Error
;
7902 -- Build and insert a Full_Type_Declaration, which will be
7903 -- analyzed as soon as this list entry has been analyzed.
7905 Decl
:= Make_Full_Type_Declaration
(Loc
,
7906 Make_Defining_Identifier
(Loc
, Chars
(Expression
(Arg2
))),
7907 Type_Definition
=> Def
);
7909 Insert_After
(N
, Decl
);
7910 Mark_Rewrite_Insertion
(Decl
);
7913 Error_Pragma_Arg
("no matching type found for pragma%",
7916 end Process_Import_Predefined_Type
;
7918 ---------------------------------
7919 -- Process_Import_Or_Interface --
7920 ---------------------------------
7922 procedure Process_Import_Or_Interface
is
7928 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7929 -- pragma Import (Entity, "external name");
7931 if Relaxed_RM_Semantics
7932 and then Arg_Count
= 2
7933 and then Prag_Id
= Pragma_Import
7934 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
7937 Def_Id
:= Get_Pragma_Arg
(Arg1
);
7940 if not Is_Entity_Name
(Def_Id
) then
7941 Error_Pragma_Arg
("entity name required", Arg1
);
7944 Def_Id
:= Entity
(Def_Id
);
7945 Kill_Size_Check_Code
(Def_Id
);
7946 Note_Possible_Modification
(Get_Pragma_Arg
(Arg1
), Sure
=> False);
7949 Process_Convention
(C
, Def_Id
);
7951 -- A pragma that applies to a Ghost entity becomes Ghost for the
7952 -- purposes of legality checks and removal of ignored Ghost code.
7954 Mark_Pragma_As_Ghost
(N
, Def_Id
);
7955 Kill_Size_Check_Code
(Def_Id
);
7956 Note_Possible_Modification
(Get_Pragma_Arg
(Arg2
), Sure
=> False);
7959 -- Various error checks
7961 if Ekind_In
(Def_Id
, E_Variable
, E_Constant
) then
7963 -- We do not permit Import to apply to a renaming declaration
7965 if Present
(Renamed_Object
(Def_Id
)) then
7967 ("pragma% not allowed for object renaming", Arg2
);
7969 -- User initialization is not allowed for imported object, but
7970 -- the object declaration may contain a default initialization,
7971 -- that will be discarded. Note that an explicit initialization
7972 -- only counts if it comes from source, otherwise it is simply
7973 -- the code generator making an implicit initialization explicit.
7975 elsif Present
(Expression
(Parent
(Def_Id
)))
7976 and then Comes_From_Source
7977 (Original_Node
(Expression
(Parent
(Def_Id
))))
7979 -- Set imported flag to prevent cascaded errors
7981 Set_Is_Imported
(Def_Id
);
7983 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7985 ("no initialization allowed for declaration of& #",
7986 "\imported entities cannot be initialized (RM B.1(24))",
7990 -- If the pragma comes from an aspect specification the
7991 -- Is_Imported flag has already been set.
7993 if not From_Aspect_Specification
(N
) then
7994 Set_Imported
(Def_Id
);
7997 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
7999 -- Note that we do not set Is_Public here. That's because we
8000 -- only want to set it if there is no address clause, and we
8001 -- don't know that yet, so we delay that processing till
8004 -- pragma Import completes deferred constants
8006 if Ekind
(Def_Id
) = E_Constant
then
8007 Set_Has_Completion
(Def_Id
);
8010 -- It is not possible to import a constant of an unconstrained
8011 -- array type (e.g. string) because there is no simple way to
8012 -- write a meaningful subtype for it.
8014 if Is_Array_Type
(Etype
(Def_Id
))
8015 and then not Is_Constrained
(Etype
(Def_Id
))
8018 ("imported constant& must have a constrained subtype",
8023 elsif Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8025 -- If the name is overloaded, pragma applies to all of the denoted
8026 -- entities in the same declarative part, unless the pragma comes
8027 -- from an aspect specification or was generated by the compiler
8028 -- (such as for pragma Provide_Shift_Operators).
8031 while Present
(Hom_Id
) loop
8033 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
8035 -- Ignore inherited subprograms because the pragma will apply
8036 -- to the parent operation, which is the one called.
8038 if Is_Overloadable
(Def_Id
)
8039 and then Present
(Alias
(Def_Id
))
8043 -- If it is not a subprogram, it must be in an outer scope and
8044 -- pragma does not apply.
8046 elsif not Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
8049 -- The pragma does not apply to primitives of interfaces
8051 elsif Is_Dispatching_Operation
(Def_Id
)
8052 and then Present
(Find_Dispatching_Type
(Def_Id
))
8053 and then Is_Interface
(Find_Dispatching_Type
(Def_Id
))
8057 -- Verify that the homonym is in the same declarative part (not
8058 -- just the same scope). If the pragma comes from an aspect
8059 -- specification we know that it is part of the declaration.
8061 elsif Parent
(Unit_Declaration_Node
(Def_Id
)) /= Parent
(N
)
8062 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit_Aux
8063 and then not From_Aspect_Specification
(N
)
8068 -- If the pragma comes from an aspect specification the
8069 -- Is_Imported flag has already been set.
8071 if not From_Aspect_Specification
(N
) then
8072 Set_Imported
(Def_Id
);
8075 -- Reject an Import applied to an abstract subprogram
8077 if Is_Subprogram
(Def_Id
)
8078 and then Is_Abstract_Subprogram
(Def_Id
)
8080 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8082 ("cannot import abstract subprogram& declared#",
8086 -- Special processing for Convention_Intrinsic
8088 if C
= Convention_Intrinsic
then
8090 -- Link_Name argument not allowed for intrinsic
8094 Set_Is_Intrinsic_Subprogram
(Def_Id
);
8096 -- If no external name is present, then check that this
8097 -- is a valid intrinsic subprogram. If an external name
8098 -- is present, then this is handled by the back end.
8101 Check_Intrinsic_Subprogram
8102 (Def_Id
, Get_Pragma_Arg
(Arg2
));
8106 -- Verify that the subprogram does not have a completion
8107 -- through a renaming declaration. For other completions the
8108 -- pragma appears as a too late representation.
8111 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Def_Id
);
8115 and then Nkind
(Decl
) = N_Subprogram_Declaration
8116 and then Present
(Corresponding_Body
(Decl
))
8117 and then Nkind
(Unit_Declaration_Node
8118 (Corresponding_Body
(Decl
))) =
8119 N_Subprogram_Renaming_Declaration
8121 Error_Msg_Sloc
:= Sloc
(Def_Id
);
8123 ("cannot import&, renaming already provided for "
8124 & "declaration #", N
, Def_Id
);
8128 -- If the pragma comes from an aspect specification, there
8129 -- must be an Import aspect specified as well. In the rare
8130 -- case where Import is set to False, the suprogram needs to
8131 -- have a local completion.
8134 Imp_Aspect
: constant Node_Id
:=
8135 Find_Aspect
(Def_Id
, Aspect_Import
);
8139 if Present
(Imp_Aspect
)
8140 and then Present
(Expression
(Imp_Aspect
))
8142 Expr
:= Expression
(Imp_Aspect
);
8143 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
8145 if Is_Entity_Name
(Expr
)
8146 and then Entity
(Expr
) = Standard_True
8148 Set_Has_Completion
(Def_Id
);
8151 -- If there is no expression, the default is True, as for
8152 -- all boolean aspects. Same for the older pragma.
8155 Set_Has_Completion
(Def_Id
);
8159 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
8162 if Is_Compilation_Unit
(Hom_Id
) then
8164 -- Its possible homonyms are not affected by the pragma.
8165 -- Such homonyms might be present in the context of other
8166 -- units being compiled.
8170 elsif From_Aspect_Specification
(N
) then
8173 -- If the pragma was created by the compiler, then we don't
8174 -- want it to apply to other homonyms. This kind of case can
8175 -- occur when using pragma Provide_Shift_Operators, which
8176 -- generates implicit shift and rotate operators with Import
8177 -- pragmas that might apply to earlier explicit or implicit
8178 -- declarations marked with Import (for example, coming from
8179 -- an earlier pragma Provide_Shift_Operators for another type),
8180 -- and we don't generally want other homonyms being treated
8181 -- as imported or the pragma flagged as an illegal duplicate.
8183 elsif not Comes_From_Source
(N
) then
8187 Hom_Id
:= Homonym
(Hom_Id
);
8191 -- Import a CPP class
8193 elsif C
= Convention_CPP
8194 and then (Is_Record_Type
(Def_Id
)
8195 or else Ekind
(Def_Id
) = E_Incomplete_Type
)
8197 if Ekind
(Def_Id
) = E_Incomplete_Type
then
8198 if Present
(Full_View
(Def_Id
)) then
8199 Def_Id
:= Full_View
(Def_Id
);
8203 ("cannot import 'C'P'P type before full declaration seen",
8204 Get_Pragma_Arg
(Arg2
));
8206 -- Although we have reported the error we decorate it as
8207 -- CPP_Class to avoid reporting spurious errors
8209 Set_Is_CPP_Class
(Def_Id
);
8214 -- Types treated as CPP classes must be declared limited (note:
8215 -- this used to be a warning but there is no real benefit to it
8216 -- since we did effectively intend to treat the type as limited
8219 if not Is_Limited_Type
(Def_Id
) then
8221 ("imported 'C'P'P type must be limited",
8222 Get_Pragma_Arg
(Arg2
));
8225 if Etype
(Def_Id
) /= Def_Id
8226 and then not Is_CPP_Class
(Root_Type
(Def_Id
))
8228 Error_Msg_N
("root type must be a 'C'P'P type", Arg1
);
8231 Set_Is_CPP_Class
(Def_Id
);
8233 -- Imported CPP types must not have discriminants (because C++
8234 -- classes do not have discriminants).
8236 if Has_Discriminants
(Def_Id
) then
8238 ("imported 'C'P'P type cannot have discriminants",
8239 First
(Discriminant_Specifications
8240 (Declaration_Node
(Def_Id
))));
8243 -- Check that components of imported CPP types do not have default
8244 -- expressions. For private types this check is performed when the
8245 -- full view is analyzed (see Process_Full_View).
8247 if not Is_Private_Type
(Def_Id
) then
8248 Check_CPP_Type_Has_No_Defaults
(Def_Id
);
8251 -- Import a CPP exception
8253 elsif C
= Convention_CPP
8254 and then Ekind
(Def_Id
) = E_Exception
8258 ("'External_'Name arguments is required for 'Cpp exception",
8261 -- As only a string is allowed, Check_Arg_Is_External_Name
8264 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
8267 if Present
(Arg4
) then
8269 ("Link_Name argument not allowed for imported Cpp exception",
8273 -- Do not call Set_Interface_Name as the name of the exception
8274 -- shouldn't be modified (and in particular it shouldn't be
8275 -- the External_Name). For exceptions, the External_Name is the
8276 -- name of the RTTI structure.
8278 -- ??? Emit an error if pragma Import/Export_Exception is present
8280 elsif Nkind
(Parent
(Def_Id
)) = N_Incomplete_Type_Declaration
then
8282 Check_Arg_Count
(3);
8283 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
8285 Process_Import_Predefined_Type
;
8289 ("second argument of pragma% must be object, subprogram "
8290 & "or incomplete type",
8294 -- If this pragma applies to a compilation unit, then the unit, which
8295 -- is a subprogram, does not require (or allow) a body. We also do
8296 -- not need to elaborate imported procedures.
8298 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
8300 Cunit
: constant Node_Id
:= Parent
(Parent
(N
));
8302 Set_Body_Required
(Cunit
, False);
8305 end Process_Import_Or_Interface
;
8307 --------------------
8308 -- Process_Inline --
8309 --------------------
8311 procedure Process_Inline
(Status
: Inline_Status
) is
8318 Ghost_Error_Posted
: Boolean := False;
8319 -- Flag set when an error concerning the illegal mix of Ghost and
8320 -- non-Ghost subprograms is emitted.
8322 Ghost_Id
: Entity_Id
:= Empty
;
8323 -- The entity of the first Ghost subprogram encountered while
8324 -- processing the arguments of the pragma.
8326 procedure Make_Inline
(Subp
: Entity_Id
);
8327 -- Subp is the defining unit name of the subprogram declaration. Set
8328 -- the flag, as well as the flag in the corresponding body, if there
8331 procedure Set_Inline_Flags
(Subp
: Entity_Id
);
8332 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
8333 -- Has_Pragma_Inline_Always for the Inline_Always case.
8335 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean;
8336 -- Returns True if it can be determined at this stage that inlining
8337 -- is not possible, for example if the body is available and contains
8338 -- exception handlers, we prevent inlining, since otherwise we can
8339 -- get undefined symbols at link time. This function also emits a
8340 -- warning if front-end inlining is enabled and the pragma appears
8343 -- ??? is business with link symbols still valid, or does it relate
8344 -- to front end ZCX which is being phased out ???
8346 ---------------------------
8347 -- Inlining_Not_Possible --
8348 ---------------------------
8350 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean is
8351 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
8355 if Nkind
(Decl
) = N_Subprogram_Body
then
8356 Stats
:= Handled_Statement_Sequence
(Decl
);
8357 return Present
(Exception_Handlers
(Stats
))
8358 or else Present
(At_End_Proc
(Stats
));
8360 elsif Nkind
(Decl
) = N_Subprogram_Declaration
8361 and then Present
(Corresponding_Body
(Decl
))
8363 if Front_End_Inlining
8364 and then Analyzed
(Corresponding_Body
(Decl
))
8366 Error_Msg_N
("pragma appears too late, ignored??", N
);
8369 -- If the subprogram is a renaming as body, the body is just a
8370 -- call to the renamed subprogram, and inlining is trivially
8374 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
8375 N_Subprogram_Renaming_Declaration
8381 Handled_Statement_Sequence
8382 (Unit_Declaration_Node
(Corresponding_Body
(Decl
)));
8385 Present
(Exception_Handlers
(Stats
))
8386 or else Present
(At_End_Proc
(Stats
));
8390 -- If body is not available, assume the best, the check is
8391 -- performed again when compiling enclosing package bodies.
8395 end Inlining_Not_Possible
;
8401 procedure Make_Inline
(Subp
: Entity_Id
) is
8402 Kind
: constant Entity_Kind
:= Ekind
(Subp
);
8403 Inner_Subp
: Entity_Id
:= Subp
;
8406 -- Ignore if bad type, avoid cascaded error
8408 if Etype
(Subp
) = Any_Type
then
8412 -- If inlining is not possible, for now do not treat as an error
8414 elsif Status
/= Suppressed
8415 and then Inlining_Not_Possible
(Subp
)
8420 -- Here we have a candidate for inlining, but we must exclude
8421 -- derived operations. Otherwise we would end up trying to inline
8422 -- a phantom declaration, and the result would be to drag in a
8423 -- body which has no direct inlining associated with it. That
8424 -- would not only be inefficient but would also result in the
8425 -- backend doing cross-unit inlining in cases where it was
8426 -- definitely inappropriate to do so.
8428 -- However, a simple Comes_From_Source test is insufficient, since
8429 -- we do want to allow inlining of generic instances which also do
8430 -- not come from source. We also need to recognize specs generated
8431 -- by the front-end for bodies that carry the pragma. Finally,
8432 -- predefined operators do not come from source but are not
8433 -- inlineable either.
8435 elsif Is_Generic_Instance
(Subp
)
8436 or else Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Declaration
8440 elsif not Comes_From_Source
(Subp
)
8441 and then Scope
(Subp
) /= Standard_Standard
8447 -- The referenced entity must either be the enclosing entity, or
8448 -- an entity declared within the current open scope.
8450 if Present
(Scope
(Subp
))
8451 and then Scope
(Subp
) /= Current_Scope
8452 and then Subp
/= Current_Scope
8455 ("argument of% must be entity in current scope", Assoc
);
8459 -- Processing for procedure, operator or function. If subprogram
8460 -- is aliased (as for an instance) indicate that the renamed
8461 -- entity (if declared in the same unit) is inlined.
8463 if Is_Subprogram
(Subp
) then
8464 Inner_Subp
:= Ultimate_Alias
(Inner_Subp
);
8466 if In_Same_Source_Unit
(Subp
, Inner_Subp
) then
8467 Set_Inline_Flags
(Inner_Subp
);
8469 Decl
:= Parent
(Parent
(Inner_Subp
));
8471 if Nkind
(Decl
) = N_Subprogram_Declaration
8472 and then Present
(Corresponding_Body
(Decl
))
8474 Set_Inline_Flags
(Corresponding_Body
(Decl
));
8476 elsif Is_Generic_Instance
(Subp
) then
8478 -- Indicate that the body needs to be created for
8479 -- inlining subsequent calls. The instantiation node
8480 -- follows the declaration of the wrapper package
8483 if Scope
(Subp
) /= Standard_Standard
8485 Need_Subprogram_Instance_Body
8486 (Next
(Unit_Declaration_Node
(Scope
(Alias
(Subp
)))),
8492 -- Inline is a program unit pragma (RM 10.1.5) and cannot
8493 -- appear in a formal part to apply to a formal subprogram.
8494 -- Do not apply check within an instance or a formal package
8495 -- the test will have been applied to the original generic.
8497 elsif Nkind
(Decl
) in N_Formal_Subprogram_Declaration
8498 and then List_Containing
(Decl
) = List_Containing
(N
)
8499 and then not In_Instance
8502 ("Inline cannot apply to a formal subprogram", N
);
8504 -- If Subp is a renaming, it is the renamed entity that
8505 -- will appear in any call, and be inlined. However, for
8506 -- ASIS uses it is convenient to indicate that the renaming
8507 -- itself is an inlined subprogram, so that some gnatcheck
8508 -- rules can be applied in the absence of expansion.
8510 elsif Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
8511 Set_Inline_Flags
(Subp
);
8517 -- For a generic subprogram set flag as well, for use at the point
8518 -- of instantiation, to determine whether the body should be
8521 elsif Is_Generic_Subprogram
(Subp
) then
8522 Set_Inline_Flags
(Subp
);
8525 -- Literals are by definition inlined
8527 elsif Kind
= E_Enumeration_Literal
then
8530 -- Anything else is an error
8534 ("expect subprogram name for pragma%", Assoc
);
8538 ----------------------
8539 -- Set_Inline_Flags --
8540 ----------------------
8542 procedure Set_Inline_Flags
(Subp
: Entity_Id
) is
8544 -- First set the Has_Pragma_XXX flags and issue the appropriate
8545 -- errors and warnings for suspicious combinations.
8547 if Prag_Id
= Pragma_No_Inline
then
8548 if Has_Pragma_Inline_Always
(Subp
) then
8550 ("Inline_Always and No_Inline are mutually exclusive", N
);
8551 elsif Has_Pragma_Inline
(Subp
) then
8553 ("Inline and No_Inline both specified for& ??",
8554 N
, Entity
(Subp_Id
));
8557 Set_Has_Pragma_No_Inline
(Subp
);
8559 if Prag_Id
= Pragma_Inline_Always
then
8560 if Has_Pragma_No_Inline
(Subp
) then
8562 ("Inline_Always and No_Inline are mutually exclusive",
8566 Set_Has_Pragma_Inline_Always
(Subp
);
8568 if Has_Pragma_No_Inline
(Subp
) then
8570 ("Inline and No_Inline both specified for& ??",
8571 N
, Entity
(Subp_Id
));
8575 if not Has_Pragma_Inline
(Subp
) then
8576 Set_Has_Pragma_Inline
(Subp
);
8580 -- Then adjust the Is_Inlined flag. It can never be set if the
8581 -- subprogram is subject to pragma No_Inline.
8585 Set_Is_Inlined
(Subp
, False);
8589 if not Has_Pragma_No_Inline
(Subp
) then
8590 Set_Is_Inlined
(Subp
, True);
8594 -- A pragma that applies to a Ghost entity becomes Ghost for the
8595 -- purposes of legality checks and removal of ignored Ghost code.
8597 Mark_Pragma_As_Ghost
(N
, Subp
);
8599 -- Capture the entity of the first Ghost subprogram being
8600 -- processed for error detection purposes.
8602 if Is_Ghost_Entity
(Subp
) then
8603 if No
(Ghost_Id
) then
8607 -- Otherwise the subprogram is non-Ghost. It is illegal to mix
8608 -- references to Ghost and non-Ghost entities (SPARK RM 6.9).
8610 elsif Present
(Ghost_Id
) and then not Ghost_Error_Posted
then
8611 Ghost_Error_Posted
:= True;
8613 Error_Msg_Name_1
:= Pname
;
8615 ("pragma % cannot mention ghost and non-ghost subprograms",
8618 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
8619 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
8621 Error_Msg_Sloc
:= Sloc
(Subp
);
8622 Error_Msg_NE
("\& # declared as non-ghost", N
, Subp
);
8624 end Set_Inline_Flags
;
8626 -- Start of processing for Process_Inline
8629 Check_No_Identifiers
;
8630 Check_At_Least_N_Arguments
(1);
8632 if Status
= Enabled
then
8633 Inline_Processing_Required
:= True;
8637 while Present
(Assoc
) loop
8638 Subp_Id
:= Get_Pragma_Arg
(Assoc
);
8642 if Is_Entity_Name
(Subp_Id
) then
8643 Subp
:= Entity
(Subp_Id
);
8645 if Subp
= Any_Id
then
8647 -- If previous error, avoid cascaded errors
8649 Check_Error_Detected
;
8655 -- For the pragma case, climb homonym chain. This is
8656 -- what implements allowing the pragma in the renaming
8657 -- case, with the result applying to the ancestors, and
8658 -- also allows Inline to apply to all previous homonyms.
8660 if not From_Aspect_Specification
(N
) then
8661 while Present
(Homonym
(Subp
))
8662 and then Scope
(Homonym
(Subp
)) = Current_Scope
8664 Make_Inline
(Homonym
(Subp
));
8665 Subp
:= Homonym
(Subp
);
8672 Error_Pragma_Arg
("inappropriate argument for pragma%", Assoc
);
8679 ----------------------------
8680 -- Process_Interface_Name --
8681 ----------------------------
8683 procedure Process_Interface_Name
8684 (Subprogram_Def
: Entity_Id
;
8690 String_Val
: String_Id
;
8692 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
);
8693 -- SN is a string literal node for an interface name. This routine
8694 -- performs some minimal checks that the name is reasonable. In
8695 -- particular that no spaces or other obviously incorrect characters
8696 -- appear. This is only a warning, since any characters are allowed.
8698 ----------------------------------
8699 -- Check_Form_Of_Interface_Name --
8700 ----------------------------------
8702 procedure Check_Form_Of_Interface_Name
(SN
: Node_Id
) is
8703 S
: constant String_Id
:= Strval
(Expr_Value_S
(SN
));
8704 SL
: constant Nat
:= String_Length
(S
);
8709 Error_Msg_N
("interface name cannot be null string", SN
);
8712 for J
in 1 .. SL
loop
8713 C
:= Get_String_Char
(S
, J
);
8715 -- Look for dubious character and issue unconditional warning.
8716 -- Definitely dubious if not in character range.
8718 if not In_Character_Range
(C
)
8720 -- Commas, spaces and (back)slashes are dubious
8722 or else Get_Character
(C
) = ','
8723 or else Get_Character
(C
) = '\'
8724 or else Get_Character
(C
) = ' '
8725 or else Get_Character
(C
) = '/'
8728 ("??interface name contains illegal character",
8729 Sloc
(SN
) + Source_Ptr
(J
));
8732 end Check_Form_Of_Interface_Name
;
8734 -- Start of processing for Process_Interface_Name
8737 if No
(Link_Arg
) then
8738 if No
(Ext_Arg
) then
8741 elsif Chars
(Ext_Arg
) = Name_Link_Name
then
8743 Link_Nam
:= Expression
(Ext_Arg
);
8746 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8747 Ext_Nam
:= Expression
(Ext_Arg
);
8752 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8753 Check_Optional_Identifier
(Link_Arg
, Name_Link_Name
);
8754 Ext_Nam
:= Expression
(Ext_Arg
);
8755 Link_Nam
:= Expression
(Link_Arg
);
8758 -- Check expressions for external name and link name are static
8760 if Present
(Ext_Nam
) then
8761 Check_Arg_Is_OK_Static_Expression
(Ext_Nam
, Standard_String
);
8762 Check_Form_Of_Interface_Name
(Ext_Nam
);
8764 -- Verify that external name is not the name of a local entity,
8765 -- which would hide the imported one and could lead to run-time
8766 -- surprises. The problem can only arise for entities declared in
8767 -- a package body (otherwise the external name is fully qualified
8768 -- and will not conflict).
8776 if Prag_Id
= Pragma_Import
then
8777 String_To_Name_Buffer
(Strval
(Expr_Value_S
(Ext_Nam
)));
8779 E
:= Entity_Id
(Get_Name_Table_Int
(Nam
));
8781 if Nam
/= Chars
(Subprogram_Def
)
8782 and then Present
(E
)
8783 and then not Is_Overloadable
(E
)
8784 and then Is_Immediately_Visible
(E
)
8785 and then not Is_Imported
(E
)
8786 and then Ekind
(Scope
(E
)) = E_Package
8789 while Present
(Par
) loop
8790 if Nkind
(Par
) = N_Package_Body
then
8791 Error_Msg_Sloc
:= Sloc
(E
);
8793 ("imported entity is hidden by & declared#",
8798 Par
:= Parent
(Par
);
8805 if Present
(Link_Nam
) then
8806 Check_Arg_Is_OK_Static_Expression
(Link_Nam
, Standard_String
);
8807 Check_Form_Of_Interface_Name
(Link_Nam
);
8810 -- If there is no link name, just set the external name
8812 if No
(Link_Nam
) then
8813 Link_Nam
:= Adjust_External_Name_Case
(Expr_Value_S
(Ext_Nam
));
8815 -- For the Link_Name case, the given literal is preceded by an
8816 -- asterisk, which indicates to GCC that the given name should be
8817 -- taken literally, and in particular that no prepending of
8818 -- underlines should occur, even in systems where this is the
8823 Store_String_Char
(Get_Char_Code
('*'));
8824 String_Val
:= Strval
(Expr_Value_S
(Link_Nam
));
8825 Store_String_Chars
(String_Val
);
8827 Make_String_Literal
(Sloc
(Link_Nam
),
8828 Strval
=> End_String
);
8831 -- Set the interface name. If the entity is a generic instance, use
8832 -- its alias, which is the callable entity.
8834 if Is_Generic_Instance
(Subprogram_Def
) then
8835 Set_Encoded_Interface_Name
8836 (Alias
(Get_Base_Subprogram
(Subprogram_Def
)), Link_Nam
);
8838 Set_Encoded_Interface_Name
8839 (Get_Base_Subprogram
(Subprogram_Def
), Link_Nam
);
8842 Check_Duplicated_Export_Name
(Link_Nam
);
8843 end Process_Interface_Name
;
8845 -----------------------------------------
8846 -- Process_Interrupt_Or_Attach_Handler --
8847 -----------------------------------------
8849 procedure Process_Interrupt_Or_Attach_Handler
is
8850 Handler
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
8851 Prot_Typ
: constant Entity_Id
:= Scope
(Handler
);
8854 -- A pragma that applies to a Ghost entity becomes Ghost for the
8855 -- purposes of legality checks and removal of ignored Ghost code.
8857 Mark_Pragma_As_Ghost
(N
, Handler
);
8858 Set_Is_Interrupt_Handler
(Handler
);
8860 -- If the pragma is not associated with a handler procedure within a
8861 -- protected type, then it must be for a nonprotected procedure for
8862 -- the AAMP target, in which case we don't associate a representation
8863 -- item with the procedure's scope.
8865 if Ekind
(Prot_Typ
) = E_Protected_Type
then
8866 Record_Rep_Item
(Prot_Typ
, N
);
8869 -- Chain the pragma on the contract for completeness
8871 Add_Contract_Item
(N
, Handler
);
8872 end Process_Interrupt_Or_Attach_Handler
;
8874 --------------------------------------------------
8875 -- Process_Restrictions_Or_Restriction_Warnings --
8876 --------------------------------------------------
8878 -- Note: some of the simple identifier cases were handled in par-prag,
8879 -- but it is harmless (and more straightforward) to simply handle all
8880 -- cases here, even if it means we repeat a bit of work in some cases.
8882 procedure Process_Restrictions_Or_Restriction_Warnings
8886 R_Id
: Restriction_Id
;
8892 -- Ignore all Restrictions pragmas in CodePeer mode
8894 if CodePeer_Mode
then
8898 Check_Ada_83_Warning
;
8899 Check_At_Least_N_Arguments
(1);
8900 Check_Valid_Configuration_Pragma
;
8903 while Present
(Arg
) loop
8905 Expr
:= Get_Pragma_Arg
(Arg
);
8907 -- Case of no restriction identifier present
8909 if Id
= No_Name
then
8910 if Nkind
(Expr
) /= N_Identifier
then
8912 ("invalid form for restriction", Arg
);
8917 (Process_Restriction_Synonyms
(Expr
));
8919 if R_Id
not in All_Boolean_Restrictions
then
8920 Error_Msg_Name_1
:= Pname
;
8922 ("invalid restriction identifier&", Get_Pragma_Arg
(Arg
));
8924 -- Check for possible misspelling
8926 for J
in Restriction_Id
loop
8928 Rnm
: constant String := Restriction_Id
'Image (J
);
8931 Name_Buffer
(1 .. Rnm
'Length) := Rnm
;
8932 Name_Len
:= Rnm
'Length;
8933 Set_Casing
(All_Lower_Case
);
8935 if Is_Bad_Spelling_Of
(Chars
(Expr
), Name_Enter
) then
8937 (Identifier_Casing
(Current_Source_File
));
8938 Error_Msg_String
(1 .. Rnm
'Length) :=
8939 Name_Buffer
(1 .. Name_Len
);
8940 Error_Msg_Strlen
:= Rnm
'Length;
8941 Error_Msg_N
-- CODEFIX
8942 ("\possible misspelling of ""~""",
8943 Get_Pragma_Arg
(Arg
));
8952 if Implementation_Restriction
(R_Id
) then
8953 Check_Restriction
(No_Implementation_Restrictions
, Arg
);
8956 -- Special processing for No_Elaboration_Code restriction
8958 if R_Id
= No_Elaboration_Code
then
8960 -- Restriction is only recognized within a configuration
8961 -- pragma file, or within a unit of the main extended
8962 -- program. Note: the test for Main_Unit is needed to
8963 -- properly include the case of configuration pragma files.
8965 if not (Current_Sem_Unit
= Main_Unit
8966 or else In_Extended_Main_Source_Unit
(N
))
8970 -- Don't allow in a subunit unless already specified in
8973 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
8974 and then Nkind
(Unit
(Parent
(N
))) = N_Subunit
8975 and then not Restriction_Active
(No_Elaboration_Code
)
8978 ("invalid specification of ""No_Elaboration_Code""",
8981 ("\restriction cannot be specified in a subunit", N
);
8983 ("\unless also specified in body or spec", N
);
8986 -- If we accept a No_Elaboration_Code restriction, then it
8987 -- needs to be added to the configuration restriction set so
8988 -- that we get proper application to other units in the main
8989 -- extended source as required.
8992 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
8996 -- If this is a warning, then set the warning unless we already
8997 -- have a real restriction active (we never want a warning to
8998 -- override a real restriction).
9001 if not Restriction_Active
(R_Id
) then
9002 Set_Restriction
(R_Id
, N
);
9003 Restriction_Warnings
(R_Id
) := True;
9006 -- If real restriction case, then set it and make sure that the
9007 -- restriction warning flag is off, since a real restriction
9008 -- always overrides a warning.
9011 Set_Restriction
(R_Id
, N
);
9012 Restriction_Warnings
(R_Id
) := False;
9015 -- Check for obsolescent restrictions in Ada 2005 mode
9018 and then Ada_Version
>= Ada_2005
9019 and then (R_Id
= No_Asynchronous_Control
9021 R_Id
= No_Unchecked_Deallocation
9023 R_Id
= No_Unchecked_Conversion
)
9025 Check_Restriction
(No_Obsolescent_Features
, N
);
9028 -- A very special case that must be processed here: pragma
9029 -- Restrictions (No_Exceptions) turns off all run-time
9030 -- checking. This is a bit dubious in terms of the formal
9031 -- language definition, but it is what is intended by RM
9032 -- H.4(12). Restriction_Warnings never affects generated code
9033 -- so this is done only in the real restriction case.
9035 -- Atomic_Synchronization is not a real check, so it is not
9036 -- affected by this processing).
9038 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
9039 -- run-time checks in CodePeer and GNATprove modes: we want to
9040 -- generate checks for analysis purposes, as set respectively
9041 -- by -gnatC and -gnatd.F
9044 and then not (CodePeer_Mode
or GNATprove_Mode
)
9045 and then R_Id
= No_Exceptions
9047 for J
in Scope_Suppress
.Suppress
'Range loop
9048 if J
/= Atomic_Synchronization
then
9049 Scope_Suppress
.Suppress
(J
) := True;
9054 -- Case of No_Dependence => unit-name. Note that the parser
9055 -- already made the necessary entry in the No_Dependence table.
9057 elsif Id
= Name_No_Dependence
then
9058 if not OK_No_Dependence_Unit_Name
(Expr
) then
9062 -- Case of No_Specification_Of_Aspect => aspect-identifier
9064 elsif Id
= Name_No_Specification_Of_Aspect
then
9069 if Nkind
(Expr
) /= N_Identifier
then
9072 A_Id
:= Get_Aspect_Id
(Chars
(Expr
));
9075 if A_Id
= No_Aspect
then
9076 Error_Pragma_Arg
("invalid restriction name", Arg
);
9078 Set_Restriction_No_Specification_Of_Aspect
(Expr
, Warn
);
9082 -- Case of No_Use_Of_Attribute => attribute-identifier
9084 elsif Id
= Name_No_Use_Of_Attribute
then
9085 if Nkind
(Expr
) /= N_Identifier
9086 or else not Is_Attribute_Name
(Chars
(Expr
))
9088 Error_Msg_N
("unknown attribute name??", Expr
);
9091 Set_Restriction_No_Use_Of_Attribute
(Expr
, Warn
);
9094 -- Case of No_Use_Of_Entity => fully-qualified-name
9096 elsif Id
= Name_No_Use_Of_Entity
then
9098 -- Restriction is only recognized within a configuration
9099 -- pragma file, or within a unit of the main extended
9100 -- program. Note: the test for Main_Unit is needed to
9101 -- properly include the case of configuration pragma files.
9103 if Current_Sem_Unit
= Main_Unit
9104 or else In_Extended_Main_Source_Unit
(N
)
9106 if not OK_No_Dependence_Unit_Name
(Expr
) then
9107 Error_Msg_N
("wrong form for entity name", Expr
);
9109 Set_Restriction_No_Use_Of_Entity
9110 (Expr
, Warn
, No_Profile
);
9114 -- Case of No_Use_Of_Pragma => pragma-identifier
9116 elsif Id
= Name_No_Use_Of_Pragma
then
9117 if Nkind
(Expr
) /= N_Identifier
9118 or else not Is_Pragma_Name
(Chars
(Expr
))
9120 Error_Msg_N
("unknown pragma name??", Expr
);
9122 Set_Restriction_No_Use_Of_Pragma
(Expr
, Warn
);
9125 -- All other cases of restriction identifier present
9128 R_Id
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(Arg
));
9129 Analyze_And_Resolve
(Expr
, Any_Integer
);
9131 if R_Id
not in All_Parameter_Restrictions
then
9133 ("invalid restriction parameter identifier", Arg
);
9135 elsif not Is_OK_Static_Expression
(Expr
) then
9136 Flag_Non_Static_Expr
9137 ("value must be static expression!", Expr
);
9140 elsif not Is_Integer_Type
(Etype
(Expr
))
9141 or else Expr_Value
(Expr
) < 0
9144 ("value must be non-negative integer", Arg
);
9147 -- Restriction pragma is active
9149 Val
:= Expr_Value
(Expr
);
9151 if not UI_Is_In_Int_Range
(Val
) then
9153 ("pragma ignored, value too large??", Arg
);
9156 -- Warning case. If the real restriction is active, then we
9157 -- ignore the request, since warning never overrides a real
9158 -- restriction. Otherwise we set the proper warning. Note that
9159 -- this circuit sets the warning again if it is already set,
9160 -- which is what we want, since the constant may have changed.
9163 if not Restriction_Active
(R_Id
) then
9165 (R_Id
, N
, Integer (UI_To_Int
(Val
)));
9166 Restriction_Warnings
(R_Id
) := True;
9169 -- Real restriction case, set restriction and make sure warning
9170 -- flag is off since real restriction always overrides warning.
9173 Set_Restriction
(R_Id
, N
, Integer (UI_To_Int
(Val
)));
9174 Restriction_Warnings
(R_Id
) := False;
9180 end Process_Restrictions_Or_Restriction_Warnings
;
9182 ---------------------------------
9183 -- Process_Suppress_Unsuppress --
9184 ---------------------------------
9186 -- Note: this procedure makes entries in the check suppress data
9187 -- structures managed by Sem. See spec of package Sem for full
9188 -- details on how we handle recording of check suppression.
9190 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean) is
9195 In_Package_Spec
: constant Boolean :=
9196 Is_Package_Or_Generic_Package
(Current_Scope
)
9197 and then not In_Package_Body
(Current_Scope
);
9199 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
);
9200 -- Used to suppress a single check on the given entity
9202 --------------------------------
9203 -- Suppress_Unsuppress_Echeck --
9204 --------------------------------
9206 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
) is
9208 -- Check for error of trying to set atomic synchronization for
9209 -- a non-atomic variable.
9211 if C
= Atomic_Synchronization
9212 and then not (Is_Atomic
(E
) or else Has_Atomic_Components
(E
))
9215 ("pragma & requires atomic type or variable",
9216 Pragma_Identifier
(Original_Node
(N
)));
9219 Set_Checks_May_Be_Suppressed
(E
);
9221 if In_Package_Spec
then
9222 Push_Global_Suppress_Stack_Entry
9225 Suppress
=> Suppress_Case
);
9227 Push_Local_Suppress_Stack_Entry
9230 Suppress
=> Suppress_Case
);
9233 -- If this is a first subtype, and the base type is distinct,
9234 -- then also set the suppress flags on the base type.
9236 if Is_First_Subtype
(E
) and then Etype
(E
) /= E
then
9237 Suppress_Unsuppress_Echeck
(Etype
(E
), C
);
9239 end Suppress_Unsuppress_Echeck
;
9241 -- Start of processing for Process_Suppress_Unsuppress
9244 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
9245 -- on user code: we want to generate checks for analysis purposes, as
9246 -- set respectively by -gnatC and -gnatd.F
9248 if Comes_From_Source
(N
)
9249 and then (CodePeer_Mode
or GNATprove_Mode
)
9254 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
9255 -- declarative part or a package spec (RM 11.5(5)).
9257 if not Is_Configuration_Pragma
then
9258 Check_Is_In_Decl_Part_Or_Package_Spec
;
9261 Check_At_Least_N_Arguments
(1);
9262 Check_At_Most_N_Arguments
(2);
9263 Check_No_Identifier
(Arg1
);
9264 Check_Arg_Is_Identifier
(Arg1
);
9266 C
:= Get_Check_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
9268 if C
= No_Check_Id
then
9270 ("argument of pragma% is not valid check name", Arg1
);
9273 -- Warn that suppress of Elaboration_Check has no effect in SPARK
9275 if C
= Elaboration_Check
and then SPARK_Mode
= On
then
9277 ("Suppress of Elaboration_Check ignored in SPARK??",
9278 "\elaboration checking rules are statically enforced "
9279 & "(SPARK RM 7.7)", Arg1
);
9282 -- One-argument case
9284 if Arg_Count
= 1 then
9286 -- Make an entry in the local scope suppress table. This is the
9287 -- table that directly shows the current value of the scope
9288 -- suppress check for any check id value.
9290 if C
= All_Checks
then
9292 -- For All_Checks, we set all specific predefined checks with
9293 -- the exception of Elaboration_Check, which is handled
9294 -- specially because of not wanting All_Checks to have the
9295 -- effect of deactivating static elaboration order processing.
9296 -- Atomic_Synchronization is also not affected, since this is
9297 -- not a real check.
9299 for J
in Scope_Suppress
.Suppress
'Range loop
9300 if J
/= Elaboration_Check
9302 J
/= Atomic_Synchronization
9304 Scope_Suppress
.Suppress
(J
) := Suppress_Case
;
9308 -- If not All_Checks, and predefined check, then set appropriate
9309 -- scope entry. Note that we will set Elaboration_Check if this
9310 -- is explicitly specified. Atomic_Synchronization is allowed
9311 -- only if internally generated and entity is atomic.
9313 elsif C
in Predefined_Check_Id
9314 and then (not Comes_From_Source
(N
)
9315 or else C
/= Atomic_Synchronization
)
9317 Scope_Suppress
.Suppress
(C
) := Suppress_Case
;
9320 -- Also make an entry in the Local_Entity_Suppress table
9322 Push_Local_Suppress_Stack_Entry
9325 Suppress
=> Suppress_Case
);
9327 -- Case of two arguments present, where the check is suppressed for
9328 -- a specified entity (given as the second argument of the pragma)
9331 -- This is obsolescent in Ada 2005 mode
9333 if Ada_Version
>= Ada_2005
then
9334 Check_Restriction
(No_Obsolescent_Features
, Arg2
);
9337 Check_Optional_Identifier
(Arg2
, Name_On
);
9338 E_Id
:= Get_Pragma_Arg
(Arg2
);
9341 if not Is_Entity_Name
(E_Id
) then
9343 ("second argument of pragma% must be entity name", Arg2
);
9352 -- A pragma that applies to a Ghost entity becomes Ghost for the
9353 -- purposes of legality checks and removal of ignored Ghost code.
9355 Mark_Pragma_As_Ghost
(N
, E
);
9357 -- Enforce RM 11.5(7) which requires that for a pragma that
9358 -- appears within a package spec, the named entity must be
9359 -- within the package spec. We allow the package name itself
9360 -- to be mentioned since that makes sense, although it is not
9361 -- strictly allowed by 11.5(7).
9364 and then E
/= Current_Scope
9365 and then Scope
(E
) /= Current_Scope
9368 ("entity in pragma% is not in package spec (RM 11.5(7))",
9372 -- Loop through homonyms. As noted below, in the case of a package
9373 -- spec, only homonyms within the package spec are considered.
9376 Suppress_Unsuppress_Echeck
(E
, C
);
9378 if Is_Generic_Instance
(E
)
9379 and then Is_Subprogram
(E
)
9380 and then Present
(Alias
(E
))
9382 Suppress_Unsuppress_Echeck
(Alias
(E
), C
);
9385 -- Move to next homonym if not aspect spec case
9387 exit when From_Aspect_Specification
(N
);
9391 -- If we are within a package specification, the pragma only
9392 -- applies to homonyms in the same scope.
9394 exit when In_Package_Spec
9395 and then Scope
(E
) /= Current_Scope
;
9398 end Process_Suppress_Unsuppress
;
9400 -------------------------------
9401 -- Record_Independence_Check --
9402 -------------------------------
9404 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
) is
9406 -- For GCC back ends the validation is done a priori
9408 if not AAMP_On_Target
then
9412 Independence_Checks
.Append
((N
, E
));
9413 end Record_Independence_Check
;
9419 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
) is
9421 if Is_Imported
(E
) then
9423 ("cannot export entity& that was previously imported", Arg
);
9425 elsif Present
(Address_Clause
(E
))
9426 and then not Relaxed_RM_Semantics
9429 ("cannot export entity& that has an address clause", Arg
);
9432 Set_Is_Exported
(E
);
9434 -- Generate a reference for entity explicitly, because the
9435 -- identifier may be overloaded and name resolution will not
9438 Generate_Reference
(E
, Arg
);
9440 -- Deal with exporting non-library level entity
9442 if not Is_Library_Level_Entity
(E
) then
9444 -- Not allowed at all for subprograms
9446 if Is_Subprogram
(E
) then
9447 Error_Pragma_Arg
("local subprogram& cannot be exported", Arg
);
9449 -- Otherwise set public and statically allocated
9453 Set_Is_Statically_Allocated
(E
);
9455 -- Warn if the corresponding W flag is set
9457 if Warn_On_Export_Import
9459 -- Only do this for something that was in the source. Not
9460 -- clear if this can be False now (there used for sure to be
9461 -- cases on some systems where it was False), but anyway the
9462 -- test is harmless if not needed, so it is retained.
9464 and then Comes_From_Source
(Arg
)
9467 ("?x?& has been made static as a result of Export",
9470 ("\?x?this usage is non-standard and non-portable",
9476 if Warn_On_Export_Import
and then Is_Type
(E
) then
9477 Error_Msg_NE
("exporting a type has no effect?x?", Arg
, E
);
9480 if Warn_On_Export_Import
and Inside_A_Generic
then
9482 ("all instances of& will have the same external name?x?",
9487 ----------------------------------------------
9488 -- Set_Extended_Import_Export_External_Name --
9489 ----------------------------------------------
9491 procedure Set_Extended_Import_Export_External_Name
9492 (Internal_Ent
: Entity_Id
;
9493 Arg_External
: Node_Id
)
9495 Old_Name
: constant Node_Id
:= Interface_Name
(Internal_Ent
);
9499 if No
(Arg_External
) then
9503 Check_Arg_Is_External_Name
(Arg_External
);
9505 if Nkind
(Arg_External
) = N_String_Literal
then
9506 if String_Length
(Strval
(Arg_External
)) = 0 then
9509 New_Name
:= Adjust_External_Name_Case
(Arg_External
);
9512 elsif Nkind
(Arg_External
) = N_Identifier
then
9513 New_Name
:= Get_Default_External_Name
(Arg_External
);
9515 -- Check_Arg_Is_External_Name should let through only identifiers and
9516 -- string literals or static string expressions (which are folded to
9517 -- string literals).
9520 raise Program_Error
;
9523 -- If we already have an external name set (by a prior normal Import
9524 -- or Export pragma), then the external names must match
9526 if Present
(Interface_Name
(Internal_Ent
)) then
9528 -- Ignore mismatching names in CodePeer mode, to support some
9529 -- old compilers which would export the same procedure under
9530 -- different names, e.g:
9532 -- pragma Export_Procedure (P, "a");
9533 -- pragma Export_Procedure (P, "b");
9535 if CodePeer_Mode
then
9539 Check_Matching_Internal_Names
: declare
9540 S1
: constant String_Id
:= Strval
(Old_Name
);
9541 S2
: constant String_Id
:= Strval
(New_Name
);
9544 pragma No_Return
(Mismatch
);
9545 -- Called if names do not match
9551 procedure Mismatch
is
9553 Error_Msg_Sloc
:= Sloc
(Old_Name
);
9555 ("external name does not match that given #",
9559 -- Start of processing for Check_Matching_Internal_Names
9562 if String_Length
(S1
) /= String_Length
(S2
) then
9566 for J
in 1 .. String_Length
(S1
) loop
9567 if Get_String_Char
(S1
, J
) /= Get_String_Char
(S2
, J
) then
9572 end Check_Matching_Internal_Names
;
9574 -- Otherwise set the given name
9577 Set_Encoded_Interface_Name
(Internal_Ent
, New_Name
);
9578 Check_Duplicated_Export_Name
(New_Name
);
9580 end Set_Extended_Import_Export_External_Name
;
9586 procedure Set_Imported
(E
: Entity_Id
) is
9588 -- Error message if already imported or exported
9590 if Is_Exported
(E
) or else Is_Imported
(E
) then
9592 -- Error if being set Exported twice
9594 if Is_Exported
(E
) then
9595 Error_Msg_NE
("entity& was previously exported", N
, E
);
9597 -- Ignore error in CodePeer mode where we treat all imported
9598 -- subprograms as unknown.
9600 elsif CodePeer_Mode
then
9603 -- OK if Import/Interface case
9605 elsif Import_Interface_Present
(N
) then
9608 -- Error if being set Imported twice
9611 Error_Msg_NE
("entity& was previously imported", N
, E
);
9614 Error_Msg_Name_1
:= Pname
;
9616 ("\(pragma% applies to all previous entities)", N
);
9618 Error_Msg_Sloc
:= Sloc
(E
);
9619 Error_Msg_NE
("\import not allowed for& declared#", N
, E
);
9621 -- Here if not previously imported or exported, OK to import
9624 Set_Is_Imported
(E
);
9626 -- For subprogram, set Import_Pragma field
9628 if Is_Subprogram
(E
) then
9629 Set_Import_Pragma
(E
, N
);
9632 -- If the entity is an object that is not at the library level,
9633 -- then it is statically allocated. We do not worry about objects
9634 -- with address clauses in this context since they are not really
9635 -- imported in the linker sense.
9638 and then not Is_Library_Level_Entity
(E
)
9639 and then No
(Address_Clause
(E
))
9641 Set_Is_Statically_Allocated
(E
);
9648 -------------------------
9649 -- Set_Mechanism_Value --
9650 -------------------------
9652 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9653 -- analyzed, since it is semantic nonsense), so we get it in the exact
9654 -- form created by the parser.
9656 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
) is
9657 procedure Bad_Mechanism
;
9658 pragma No_Return
(Bad_Mechanism
);
9659 -- Signal bad mechanism name
9661 -------------------------
9662 -- Bad_Mechanism_Value --
9663 -------------------------
9665 procedure Bad_Mechanism
is
9667 Error_Pragma_Arg
("unrecognized mechanism name", Mech_Name
);
9670 -- Start of processing for Set_Mechanism_Value
9673 if Mechanism
(Ent
) /= Default_Mechanism
then
9675 ("mechanism for & has already been set", Mech_Name
, Ent
);
9678 -- MECHANISM_NAME ::= value | reference
9680 if Nkind
(Mech_Name
) = N_Identifier
then
9681 if Chars
(Mech_Name
) = Name_Value
then
9682 Set_Mechanism
(Ent
, By_Copy
);
9685 elsif Chars
(Mech_Name
) = Name_Reference
then
9686 Set_Mechanism
(Ent
, By_Reference
);
9689 elsif Chars
(Mech_Name
) = Name_Copy
then
9691 ("bad mechanism name, Value assumed", Mech_Name
);
9700 end Set_Mechanism_Value
;
9702 --------------------------
9703 -- Set_Rational_Profile --
9704 --------------------------
9706 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9707 -- extension to the semantics of renaming declarations.
9709 procedure Set_Rational_Profile
is
9711 Implicit_Packing
:= True;
9712 Overriding_Renamings
:= True;
9713 Use_VADS_Size
:= True;
9714 end Set_Rational_Profile
;
9716 ---------------------------
9717 -- Set_Ravenscar_Profile --
9718 ---------------------------
9720 -- The tasks to be done here are
9722 -- Set required policies
9724 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9725 -- pragma Locking_Policy (Ceiling_Locking)
9727 -- Set Detect_Blocking mode
9729 -- Set required restrictions (see System.Rident for detailed list)
9731 -- Set the No_Dependence rules
9732 -- No_Dependence => Ada.Asynchronous_Task_Control
9733 -- No_Dependence => Ada.Calendar
9734 -- No_Dependence => Ada.Execution_Time.Group_Budget
9735 -- No_Dependence => Ada.Execution_Time.Timers
9736 -- No_Dependence => Ada.Task_Attributes
9737 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9739 procedure Set_Ravenscar_Profile
(Profile
: Profile_Name
; N
: Node_Id
) is
9740 procedure Set_Error_Msg_To_Profile_Name
;
9741 -- Set Error_Msg_String and Error_Msg_Strlen to the name of the
9744 -----------------------------------
9745 -- Set_Error_Msg_To_Profile_Name --
9746 -----------------------------------
9748 procedure Set_Error_Msg_To_Profile_Name
is
9749 Prof_Nam
: constant Node_Id
:=
9751 (First
(Pragma_Argument_Associations
(N
)));
9754 Get_Name_String
(Chars
(Prof_Nam
));
9755 Adjust_Name_Case
(Sloc
(Prof_Nam
));
9756 Error_Msg_Strlen
:= Name_Len
;
9757 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
9758 end Set_Error_Msg_To_Profile_Name
;
9767 -- Start of processing for Set_Ravenscar_Profile
9770 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9772 if Task_Dispatching_Policy
/= ' '
9773 and then Task_Dispatching_Policy
/= 'F'
9775 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
9776 Set_Error_Msg_To_Profile_Name
;
9777 Error_Pragma
("Profile (~) incompatible with policy#");
9779 -- Set the FIFO_Within_Priorities policy, but always preserve
9780 -- System_Location since we like the error message with the run time
9784 Task_Dispatching_Policy
:= 'F';
9786 if Task_Dispatching_Policy_Sloc
/= System_Location
then
9787 Task_Dispatching_Policy_Sloc
:= Loc
;
9791 -- pragma Locking_Policy (Ceiling_Locking)
9793 if Locking_Policy
/= ' '
9794 and then Locking_Policy
/= 'C'
9796 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
9797 Set_Error_Msg_To_Profile_Name
;
9798 Error_Pragma
("Profile (~) incompatible with policy#");
9800 -- Set the Ceiling_Locking policy, but preserve System_Location since
9801 -- we like the error message with the run time name.
9804 Locking_Policy
:= 'C';
9806 if Locking_Policy_Sloc
/= System_Location
then
9807 Locking_Policy_Sloc
:= Loc
;
9811 -- pragma Detect_Blocking
9813 Detect_Blocking
:= True;
9815 -- Set the corresponding restrictions
9817 Set_Profile_Restrictions
9818 (Profile
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
9820 -- Set the No_Dependence restrictions
9822 -- The following No_Dependence restrictions:
9823 -- No_Dependence => Ada.Asynchronous_Task_Control
9824 -- No_Dependence => Ada.Calendar
9825 -- No_Dependence => Ada.Task_Attributes
9826 -- are already set by previous call to Set_Profile_Restrictions.
9828 -- Set the following restrictions which were added to Ada 2005:
9829 -- No_Dependence => Ada.Execution_Time.Group_Budget
9830 -- No_Dependence => Ada.Execution_Time.Timers
9832 -- ??? The use of Name_Buffer here is suspicious. The names should
9833 -- be registered in snames.ads-tmpl and used to build the qualified
9836 if Ada_Version
>= Ada_2005
then
9837 Name_Buffer
(1 .. 3) := "ada";
9840 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
);
9842 Name_Buffer
(1 .. 14) := "execution_time";
9845 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
9848 Make_Selected_Component
9851 Selector_Name
=> Sel_Id
);
9853 Name_Buffer
(1 .. 13) := "group_budgets";
9856 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
9859 Make_Selected_Component
9862 Selector_Name
=> Sel_Id
);
9864 Set_Restriction_No_Dependence
9866 Warn
=> Treat_Restrictions_As_Warnings
,
9867 Profile
=> Ravenscar
);
9869 Name_Buffer
(1 .. 6) := "timers";
9872 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
9875 Make_Selected_Component
9878 Selector_Name
=> Sel_Id
);
9880 Set_Restriction_No_Dependence
9882 Warn
=> Treat_Restrictions_As_Warnings
,
9883 Profile
=> Ravenscar
);
9886 -- Set the following restriction which was added to Ada 2012 (see
9888 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9890 if Ada_Version
>= Ada_2012
then
9891 Name_Buffer
(1 .. 6) := "system";
9894 Pref_Id
:= Make_Identifier
(Loc
, Name_Find
);
9896 Name_Buffer
(1 .. 15) := "multiprocessors";
9899 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
9902 Make_Selected_Component
9905 Selector_Name
=> Sel_Id
);
9907 Name_Buffer
(1 .. 19) := "dispatching_domains";
9910 Sel_Id
:= Make_Identifier
(Loc
, Name_Find
);
9913 Make_Selected_Component
9916 Selector_Name
=> Sel_Id
);
9918 Set_Restriction_No_Dependence
9920 Warn
=> Treat_Restrictions_As_Warnings
,
9921 Profile
=> Ravenscar
);
9923 end Set_Ravenscar_Profile
;
9925 -- Start of processing for Analyze_Pragma
9928 -- The following code is a defense against recursion. Not clear that
9929 -- this can happen legitimately, but perhaps some error situations can
9930 -- cause it, and we did see this recursion during testing.
9932 if Analyzed
(N
) then
9938 -- Deal with unrecognized pragma
9940 Pname
:= Pragma_Name
(N
);
9942 if not Is_Pragma_Name
(Pname
) then
9943 if Warn_On_Unrecognized_Pragma
then
9944 Error_Msg_Name_1
:= Pname
;
9945 Error_Msg_N
("?g?unrecognized pragma%!", Pragma_Identifier
(N
));
9947 for PN
in First_Pragma_Name
.. Last_Pragma_Name
loop
9948 if Is_Bad_Spelling_Of
(Pname
, PN
) then
9949 Error_Msg_Name_1
:= PN
;
9950 Error_Msg_N
-- CODEFIX
9951 ("\?g?possible misspelling of %!", Pragma_Identifier
(N
));
9960 -- Ignore pragma if Ignore_Pragma applies
9962 if Get_Name_Table_Boolean3
(Pname
) then
9966 -- Here to start processing for recognized pragma
9968 Prag_Id
:= Get_Pragma_Id
(Pname
);
9969 Pname
:= Original_Aspect_Pragma_Name
(N
);
9971 -- Capture setting of Opt.Uneval_Old
9973 case Opt
.Uneval_Old
is
9975 Set_Uneval_Old_Accept
(N
);
9979 Set_Uneval_Old_Warn
(N
);
9981 raise Program_Error
;
9984 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
9985 -- is already set, indicating that we have already checked the policy
9986 -- at the right point. This happens for example in the case of a pragma
9987 -- that is derived from an Aspect.
9989 if Is_Ignored
(N
) or else Is_Checked
(N
) then
9992 -- For a pragma that is a rewriting of another pragma, copy the
9993 -- Is_Checked/Is_Ignored status from the rewritten pragma.
9995 elsif Is_Rewrite_Substitution
(N
)
9996 and then Nkind
(Original_Node
(N
)) = N_Pragma
9997 and then Original_Node
(N
) /= N
9999 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
10000 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
10002 -- Otherwise query the applicable policy at this point
10005 Check_Applicable_Policy
(N
);
10007 -- If pragma is disabled, rewrite as NULL and skip analysis
10009 if Is_Disabled
(N
) then
10010 Rewrite
(N
, Make_Null_Statement
(Loc
));
10016 -- Preset arguments
10024 if Present
(Pragma_Argument_Associations
(N
)) then
10025 Arg_Count
:= List_Length
(Pragma_Argument_Associations
(N
));
10026 Arg1
:= First
(Pragma_Argument_Associations
(N
));
10028 if Present
(Arg1
) then
10029 Arg2
:= Next
(Arg1
);
10031 if Present
(Arg2
) then
10032 Arg3
:= Next
(Arg2
);
10034 if Present
(Arg3
) then
10035 Arg4
:= Next
(Arg3
);
10041 Check_Restriction_No_Use_Of_Pragma
(N
);
10043 -- An enumeration type defines the pragmas that are supported by the
10044 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
10045 -- into the corresponding enumeration value for the following case.
10053 -- pragma Abort_Defer;
10055 when Pragma_Abort_Defer
=>
10057 Check_Arg_Count
(0);
10059 -- The only required semantic processing is to check the
10060 -- placement. This pragma must appear at the start of the
10061 -- statement sequence of a handled sequence of statements.
10063 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
10064 or else N
/= First
(Statements
(Parent
(N
)))
10069 --------------------
10070 -- Abstract_State --
10071 --------------------
10073 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
10075 -- ABSTRACT_STATE_LIST ::=
10077 -- | STATE_NAME_WITH_OPTIONS
10078 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS})
10080 -- STATE_NAME_WITH_OPTIONS ::=
10082 -- | (STATE_NAME with OPTION_LIST)
10084 -- OPTION_LIST ::= OPTION {, OPTION}
10088 -- | NAME_VALUE_OPTION
10090 -- SIMPLE_OPTION ::= Ghost | Synchronous
10092 -- NAME_VALUE_OPTION ::=
10093 -- Part_Of => ABSTRACT_STATE
10094 -- | External [=> EXTERNAL_PROPERTY_LIST]
10096 -- EXTERNAL_PROPERTY_LIST ::=
10097 -- EXTERNAL_PROPERTY
10098 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY})
10100 -- EXTERNAL_PROPERTY ::=
10101 -- Async_Readers [=> boolean_EXPRESSION]
10102 -- | Async_Writers [=> boolean_EXPRESSION]
10103 -- | Effective_Reads [=> boolean_EXPRESSION]
10104 -- | Effective_Writes [=> boolean_EXPRESSION]
10105 -- others => boolean_EXPRESSION
10107 -- STATE_NAME ::= defining_identifier
10109 -- ABSTRACT_STATE ::= name
10111 -- Characteristics:
10113 -- * Analysis - The annotation is fully analyzed immediately upon
10114 -- elaboration as it cannot forward reference entities.
10116 -- * Expansion - None.
10118 -- * Template - The annotation utilizes the generic template of the
10119 -- related package declaration.
10121 -- * Globals - The annotation cannot reference global entities.
10123 -- * Instance - The annotation is instantiated automatically when
10124 -- the related generic package is instantiated.
10126 when Pragma_Abstract_State
=> Abstract_State
: declare
10127 Missing_Parentheses
: Boolean := False;
10128 -- Flag set when a state declaration with options is not properly
10131 -- Flags used to verify the consistency of states
10133 Non_Null_Seen
: Boolean := False;
10134 Null_Seen
: Boolean := False;
10136 procedure Analyze_Abstract_State
10138 Pack_Id
: Entity_Id
);
10139 -- Verify the legality of a single state declaration. Create and
10140 -- decorate a state abstraction entity and introduce it into the
10141 -- visibility chain. Pack_Id denotes the entity or the related
10142 -- package where pragma Abstract_State appears.
10144 procedure Malformed_State_Error
(State
: Node_Id
);
10145 -- Emit an error concerning the illegal declaration of abstract
10146 -- state State. This routine diagnoses syntax errors that lead to
10147 -- a different parse tree. The error is issued regardless of the
10148 -- SPARK mode in effect.
10150 ----------------------------
10151 -- Analyze_Abstract_State --
10152 ----------------------------
10154 procedure Analyze_Abstract_State
10156 Pack_Id
: Entity_Id
)
10158 -- Flags used to verify the consistency of options
10160 AR_Seen
: Boolean := False;
10161 AW_Seen
: Boolean := False;
10162 ER_Seen
: Boolean := False;
10163 EW_Seen
: Boolean := False;
10164 External_Seen
: Boolean := False;
10165 Ghost_Seen
: Boolean := False;
10166 Others_Seen
: Boolean := False;
10167 Part_Of_Seen
: Boolean := False;
10168 Synchronous_Seen
: Boolean := False;
10170 -- Flags used to store the static value of all external states'
10173 AR_Val
: Boolean := False;
10174 AW_Val
: Boolean := False;
10175 ER_Val
: Boolean := False;
10176 EW_Val
: Boolean := False;
10178 State_Id
: Entity_Id
:= Empty
;
10179 -- The entity to be generated for the current state declaration
10181 procedure Analyze_External_Option
(Opt
: Node_Id
);
10182 -- Verify the legality of option External
10184 procedure Analyze_External_Property
10186 Expr
: Node_Id
:= Empty
);
10187 -- Verify the legailty of a single external property. Prop
10188 -- denotes the external property. Expr is the expression used
10189 -- to set the property.
10191 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
);
10192 -- Verify the legality of option Part_Of
10194 procedure Check_Duplicate_Option
10196 Status
: in out Boolean);
10197 -- Flag Status denotes whether a particular option has been
10198 -- seen while processing a state. This routine verifies that
10199 -- Opt is not a duplicate option and sets the flag Status
10200 -- (SPARK RM 7.1.4(1)).
10202 procedure Check_Duplicate_Property
10204 Status
: in out Boolean);
10205 -- Flag Status denotes whether a particular property has been
10206 -- seen while processing option External. This routine verifies
10207 -- that Prop is not a duplicate property and sets flag Status.
10208 -- Opt is not a duplicate property and sets the flag Status.
10209 -- (SPARK RM 7.1.4(2))
10211 procedure Check_Ghost_Synchronous
;
10212 -- Ensure that the abstract state is not subject to both Ghost
10213 -- and Synchronous simple options. Emit an error if this is the
10216 procedure Create_Abstract_State
10220 Is_Null
: Boolean);
10221 -- Generate an abstract state entity with name Nam and enter it
10222 -- into visibility. Decl is the "declaration" of the state as
10223 -- it appears in pragma Abstract_State. Loc is the location of
10224 -- the related state "declaration". Flag Is_Null should be set
10225 -- when the associated Abstract_State pragma defines a null
10228 -----------------------------
10229 -- Analyze_External_Option --
10230 -----------------------------
10232 procedure Analyze_External_Option
(Opt
: Node_Id
) is
10233 Errors
: constant Nat
:= Serious_Errors_Detected
;
10235 Props
: Node_Id
:= Empty
;
10238 if Nkind
(Opt
) = N_Component_Association
then
10239 Props
:= Expression
(Opt
);
10242 -- External state with properties
10244 if Present
(Props
) then
10246 -- Multiple properties appear as an aggregate
10248 if Nkind
(Props
) = N_Aggregate
then
10250 -- Simple property form
10252 Prop
:= First
(Expressions
(Props
));
10253 while Present
(Prop
) loop
10254 Analyze_External_Property
(Prop
);
10258 -- Property with expression form
10260 Prop
:= First
(Component_Associations
(Props
));
10261 while Present
(Prop
) loop
10262 Analyze_External_Property
10263 (Prop
=> First
(Choices
(Prop
)),
10264 Expr
=> Expression
(Prop
));
10272 Analyze_External_Property
(Props
);
10275 -- An external state defined without any properties defaults
10276 -- all properties to True.
10285 -- Once all external properties have been processed, verify
10286 -- their mutual interaction. Do not perform the check when
10287 -- at least one of the properties is illegal as this will
10288 -- produce a bogus error.
10290 if Errors
= Serious_Errors_Detected
then
10291 Check_External_Properties
10292 (State
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
10294 end Analyze_External_Option
;
10296 -------------------------------
10297 -- Analyze_External_Property --
10298 -------------------------------
10300 procedure Analyze_External_Property
10302 Expr
: Node_Id
:= Empty
)
10304 Expr_Val
: Boolean;
10307 -- Check the placement of "others" (if available)
10309 if Nkind
(Prop
) = N_Others_Choice
then
10310 if Others_Seen
then
10312 ("only one others choice allowed in option External",
10315 Others_Seen
:= True;
10318 elsif Others_Seen
then
10320 ("others must be the last property in option External",
10323 -- The only remaining legal options are the four predefined
10324 -- external properties.
10326 elsif Nkind
(Prop
) = N_Identifier
10327 and then Nam_In
(Chars
(Prop
), Name_Async_Readers
,
10328 Name_Async_Writers
,
10329 Name_Effective_Reads
,
10330 Name_Effective_Writes
)
10334 -- Otherwise the construct is not a valid property
10337 SPARK_Msg_N
("invalid external state property", Prop
);
10341 -- Ensure that the expression of the external state property
10342 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
10344 if Present
(Expr
) then
10345 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
10347 if Is_OK_Static_Expression
(Expr
) then
10348 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
10351 ("expression of external state property must be "
10355 -- The lack of expression defaults the property to True
10361 -- Named properties
10363 if Nkind
(Prop
) = N_Identifier
then
10364 if Chars
(Prop
) = Name_Async_Readers
then
10365 Check_Duplicate_Property
(Prop
, AR_Seen
);
10366 AR_Val
:= Expr_Val
;
10368 elsif Chars
(Prop
) = Name_Async_Writers
then
10369 Check_Duplicate_Property
(Prop
, AW_Seen
);
10370 AW_Val
:= Expr_Val
;
10372 elsif Chars
(Prop
) = Name_Effective_Reads
then
10373 Check_Duplicate_Property
(Prop
, ER_Seen
);
10374 ER_Val
:= Expr_Val
;
10377 Check_Duplicate_Property
(Prop
, EW_Seen
);
10378 EW_Val
:= Expr_Val
;
10381 -- The handling of property "others" must take into account
10382 -- all other named properties that have been encountered so
10383 -- far. Only those that have not been seen are affected by
10387 if not AR_Seen
then
10388 AR_Val
:= Expr_Val
;
10391 if not AW_Seen
then
10392 AW_Val
:= Expr_Val
;
10395 if not ER_Seen
then
10396 ER_Val
:= Expr_Val
;
10399 if not EW_Seen
then
10400 EW_Val
:= Expr_Val
;
10403 end Analyze_External_Property
;
10405 ----------------------------
10406 -- Analyze_Part_Of_Option --
10407 ----------------------------
10409 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
) is
10410 Encap
: constant Node_Id
:= Expression
(Opt
);
10411 Encap_Id
: Entity_Id
;
10415 Check_Duplicate_Option
(Opt
, Part_Of_Seen
);
10418 (Indic
=> First
(Choices
(Opt
)),
10419 Item_Id
=> State_Id
,
10421 Encap_Id
=> Encap_Id
,
10424 -- The Part_Of indicator transforms the abstract state into
10425 -- a constituent of the encapsulating state or single
10426 -- concurrent type.
10429 pragma Assert
(Present
(Encap_Id
));
10431 Append_Elmt
(State_Id
, Part_Of_Constituents
(Encap_Id
));
10432 Set_Encapsulating_State
(State_Id
, Encap_Id
);
10434 end Analyze_Part_Of_Option
;
10436 ----------------------------
10437 -- Check_Duplicate_Option --
10438 ----------------------------
10440 procedure Check_Duplicate_Option
10442 Status
: in out Boolean)
10446 SPARK_Msg_N
("duplicate state option", Opt
);
10450 end Check_Duplicate_Option
;
10452 ------------------------------
10453 -- Check_Duplicate_Property --
10454 ------------------------------
10456 procedure Check_Duplicate_Property
10458 Status
: in out Boolean)
10462 SPARK_Msg_N
("duplicate external property", Prop
);
10466 end Check_Duplicate_Property
;
10468 -----------------------------
10469 -- Check_Ghost_Synchronous --
10470 -----------------------------
10472 procedure Check_Ghost_Synchronous
is
10474 -- A synchronized abstract state cannot be Ghost and vice
10475 -- versa (SPARK RM 6.9(19)).
10477 if Ghost_Seen
and Synchronous_Seen
then
10478 SPARK_Msg_N
("synchronized state cannot be ghost", State
);
10480 end Check_Ghost_Synchronous
;
10482 ---------------------------
10483 -- Create_Abstract_State --
10484 ---------------------------
10486 procedure Create_Abstract_State
10493 -- The abstract state may be semi-declared when the related
10494 -- package was withed through a limited with clause. In that
10495 -- case reuse the entity to fully declare the state.
10497 if Present
(Decl
) and then Present
(Entity
(Decl
)) then
10498 State_Id
:= Entity
(Decl
);
10500 -- Otherwise the elaboration of pragma Abstract_State
10501 -- declares the state.
10504 State_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
10506 if Present
(Decl
) then
10507 Set_Entity
(Decl
, State_Id
);
10511 -- Null states never come from source
10513 Set_Comes_From_Source
(State_Id
, not Is_Null
);
10514 Set_Parent
(State_Id
, State
);
10515 Set_Ekind
(State_Id
, E_Abstract_State
);
10516 Set_Etype
(State_Id
, Standard_Void_Type
);
10517 Set_Encapsulating_State
(State_Id
, Empty
);
10518 Set_Refinement_Constituents
(State_Id
, New_Elmt_List
);
10519 Set_Part_Of_Constituents
(State_Id
, New_Elmt_List
);
10521 -- An abstract state declared within a Ghost region becomes
10522 -- Ghost (SPARK RM 6.9(2)).
10524 if Ghost_Mode
> None
or else Is_Ghost_Entity
(Pack_Id
) then
10525 Set_Is_Ghost_Entity
(State_Id
);
10528 -- Establish a link between the state declaration and the
10529 -- abstract state entity. Note that a null state remains as
10530 -- N_Null and does not carry any linkages.
10532 if not Is_Null
then
10533 if Present
(Decl
) then
10534 Set_Entity
(Decl
, State_Id
);
10535 Set_Etype
(Decl
, Standard_Void_Type
);
10538 -- Every non-null state must be defined, nameable and
10541 Push_Scope
(Pack_Id
);
10542 Generate_Definition
(State_Id
);
10543 Enter_Name
(State_Id
);
10546 end Create_Abstract_State
;
10553 -- Start of processing for Analyze_Abstract_State
10556 -- A package with a null abstract state is not allowed to
10557 -- declare additional states.
10561 ("package & has null abstract state", State
, Pack_Id
);
10563 -- Null states appear as internally generated entities
10565 elsif Nkind
(State
) = N_Null
then
10566 Create_Abstract_State
10567 (Nam
=> New_Internal_Name
('S'),
10569 Loc
=> Sloc
(State
),
10573 -- Catch a case where a null state appears in a list of
10574 -- non-null states.
10576 if Non_Null_Seen
then
10578 ("package & has non-null abstract state",
10582 -- Simple state declaration
10584 elsif Nkind
(State
) = N_Identifier
then
10585 Create_Abstract_State
10586 (Nam
=> Chars
(State
),
10588 Loc
=> Sloc
(State
),
10590 Non_Null_Seen
:= True;
10592 -- State declaration with various options. This construct
10593 -- appears as an extension aggregate in the tree.
10595 elsif Nkind
(State
) = N_Extension_Aggregate
then
10596 if Nkind
(Ancestor_Part
(State
)) = N_Identifier
then
10597 Create_Abstract_State
10598 (Nam
=> Chars
(Ancestor_Part
(State
)),
10599 Decl
=> Ancestor_Part
(State
),
10600 Loc
=> Sloc
(Ancestor_Part
(State
)),
10602 Non_Null_Seen
:= True;
10605 ("state name must be an identifier",
10606 Ancestor_Part
(State
));
10609 -- Options External, Ghost and Synchronous appear as
10612 Opt
:= First
(Expressions
(State
));
10613 while Present
(Opt
) loop
10614 if Nkind
(Opt
) = N_Identifier
then
10618 if Chars
(Opt
) = Name_External
then
10619 Check_Duplicate_Option
(Opt
, External_Seen
);
10620 Analyze_External_Option
(Opt
);
10624 elsif Chars
(Opt
) = Name_Ghost
then
10625 Check_Duplicate_Option
(Opt
, Ghost_Seen
);
10626 Check_Ghost_Synchronous
;
10628 if Present
(State_Id
) then
10629 Set_Is_Ghost_Entity
(State_Id
);
10634 elsif Chars
(Opt
) = Name_Synchronous
then
10635 Check_Duplicate_Option
(Opt
, Synchronous_Seen
);
10636 Check_Ghost_Synchronous
;
10638 -- Option Part_Of without an encapsulating state is
10639 -- illegal (SPARK RM 7.1.4(9)).
10641 elsif Chars
(Opt
) = Name_Part_Of
then
10643 ("indicator Part_Of must denote abstract state, "
10644 & "single protected type or single task type",
10647 -- Do not emit an error message when a previous state
10648 -- declaration with options was not parenthesized as
10649 -- the option is actually another state declaration.
10651 -- with Abstract_State
10652 -- (State_1 with ..., -- missing parentheses
10653 -- (State_2 with ...),
10654 -- State_3) -- ok state declaration
10656 elsif Missing_Parentheses
then
10659 -- Otherwise the option is not allowed. Note that it
10660 -- is not possible to distinguish between an option
10661 -- and a state declaration when a previous state with
10662 -- options not properly parentheses.
10664 -- with Abstract_State
10665 -- (State_1 with ..., -- missing parentheses
10666 -- State_2); -- could be an option
10670 ("simple option not allowed in state declaration",
10674 -- Catch a case where missing parentheses around a state
10675 -- declaration with options cause a subsequent state
10676 -- declaration with options to be treated as an option.
10678 -- with Abstract_State
10679 -- (State_1 with ..., -- missing parentheses
10680 -- (State_2 with ...))
10682 elsif Nkind
(Opt
) = N_Extension_Aggregate
then
10683 Missing_Parentheses
:= True;
10685 ("state declaration must be parenthesized",
10686 Ancestor_Part
(State
));
10688 -- Otherwise the option is malformed
10691 SPARK_Msg_N
("malformed option", Opt
);
10697 -- Options External and Part_Of appear as component
10700 Opt
:= First
(Component_Associations
(State
));
10701 while Present
(Opt
) loop
10702 Opt_Nam
:= First
(Choices
(Opt
));
10704 if Nkind
(Opt_Nam
) = N_Identifier
then
10705 if Chars
(Opt_Nam
) = Name_External
then
10706 Analyze_External_Option
(Opt
);
10708 elsif Chars
(Opt_Nam
) = Name_Part_Of
then
10709 Analyze_Part_Of_Option
(Opt
);
10712 SPARK_Msg_N
("invalid state option", Opt
);
10715 SPARK_Msg_N
("invalid state option", Opt
);
10721 -- Any other attempt to declare a state is illegal
10724 Malformed_State_Error
(State
);
10728 -- Guard against a junk state. In such cases no entity is
10729 -- generated and the subsequent checks cannot be applied.
10731 if Present
(State_Id
) then
10733 -- Verify whether the state does not introduce an illegal
10734 -- hidden state within a package subject to a null abstract
10737 Check_No_Hidden_State
(State_Id
);
10739 -- Check whether the lack of option Part_Of agrees with the
10740 -- placement of the abstract state with respect to the state
10743 if not Part_Of_Seen
then
10744 Check_Missing_Part_Of
(State_Id
);
10747 -- Associate the state with its related package
10749 if No
(Abstract_States
(Pack_Id
)) then
10750 Set_Abstract_States
(Pack_Id
, New_Elmt_List
);
10753 Append_Elmt
(State_Id
, Abstract_States
(Pack_Id
));
10755 end Analyze_Abstract_State
;
10757 ---------------------------
10758 -- Malformed_State_Error --
10759 ---------------------------
10761 procedure Malformed_State_Error
(State
: Node_Id
) is
10763 Error_Msg_N
("malformed abstract state declaration", State
);
10765 -- An abstract state with a simple option is being declared
10766 -- with "=>" rather than the legal "with". The state appears
10767 -- as a component association.
10769 if Nkind
(State
) = N_Component_Association
then
10770 Error_Msg_N
("\use WITH to specify simple option", State
);
10772 end Malformed_State_Error
;
10776 Pack_Decl
: Node_Id
;
10777 Pack_Id
: Entity_Id
;
10781 -- Start of processing for Abstract_State
10785 Check_No_Identifiers
;
10786 Check_Arg_Count
(1);
10788 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
10790 -- Ensure the proper placement of the pragma. Abstract states must
10791 -- be associated with a package declaration.
10793 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
10794 N_Package_Declaration
)
10798 -- Otherwise the pragma is associated with an illegal construct
10805 Pack_Id
:= Defining_Entity
(Pack_Decl
);
10807 -- Chain the pragma on the contract for completeness
10809 Add_Contract_Item
(N
, Pack_Id
);
10811 -- The legality checks of pragmas Abstract_State, Initializes, and
10812 -- Initial_Condition are affected by the SPARK mode in effect. In
10813 -- addition, these three pragmas are subject to an inherent order:
10815 -- 1) Abstract_State
10817 -- 3) Initial_Condition
10819 -- Analyze all these pragmas in the order outlined above
10821 Analyze_If_Present
(Pragma_SPARK_Mode
);
10823 -- A pragma that applies to a Ghost entity becomes Ghost for the
10824 -- purposes of legality checks and removal of ignored Ghost code.
10826 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
10827 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
10829 States
:= Expression
(Get_Argument
(N
, Pack_Id
));
10831 -- Multiple non-null abstract states appear as an aggregate
10833 if Nkind
(States
) = N_Aggregate
then
10834 State
:= First
(Expressions
(States
));
10835 while Present
(State
) loop
10836 Analyze_Abstract_State
(State
, Pack_Id
);
10840 -- An abstract state with a simple option is being illegaly
10841 -- declared with "=>" rather than "with". In this case the
10842 -- state declaration appears as a component association.
10844 if Present
(Component_Associations
(States
)) then
10845 State
:= First
(Component_Associations
(States
));
10846 while Present
(State
) loop
10847 Malformed_State_Error
(State
);
10852 -- Various forms of a single abstract state. Note that these may
10853 -- include malformed state declarations.
10856 Analyze_Abstract_State
(States
, Pack_Id
);
10859 Analyze_If_Present
(Pragma_Initializes
);
10860 Analyze_If_Present
(Pragma_Initial_Condition
);
10861 end Abstract_State
;
10869 -- Note: this pragma also has some specific processing in Par.Prag
10870 -- because we want to set the Ada version mode during parsing.
10872 when Pragma_Ada_83
=>
10874 Check_Arg_Count
(0);
10876 -- We really should check unconditionally for proper configuration
10877 -- pragma placement, since we really don't want mixed Ada modes
10878 -- within a single unit, and the GNAT reference manual has always
10879 -- said this was a configuration pragma, but we did not check and
10880 -- are hesitant to add the check now.
10882 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
10883 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
10884 -- or Ada 2012 mode.
10886 if Ada_Version
>= Ada_2005
then
10887 Check_Valid_Configuration_Pragma
;
10890 -- Now set Ada 83 mode
10892 Ada_Version
:= Ada_83
;
10893 Ada_Version_Explicit
:= Ada_83
;
10894 Ada_Version_Pragma
:= N
;
10902 -- Note: this pragma also has some specific processing in Par.Prag
10903 -- because we want to set the Ada 83 version mode during parsing.
10905 when Pragma_Ada_95
=>
10907 Check_Arg_Count
(0);
10909 -- We really should check unconditionally for proper configuration
10910 -- pragma placement, since we really don't want mixed Ada modes
10911 -- within a single unit, and the GNAT reference manual has always
10912 -- said this was a configuration pragma, but we did not check and
10913 -- are hesitant to add the check now.
10915 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
10916 -- or Ada 95, so we must check if we are in Ada 2005 mode.
10918 if Ada_Version
>= Ada_2005
then
10919 Check_Valid_Configuration_Pragma
;
10922 -- Now set Ada 95 mode
10924 Ada_Version
:= Ada_95
;
10925 Ada_Version_Explicit
:= Ada_95
;
10926 Ada_Version_Pragma
:= N
;
10928 ---------------------
10929 -- Ada_05/Ada_2005 --
10930 ---------------------
10933 -- pragma Ada_05 (LOCAL_NAME);
10935 -- pragma Ada_2005;
10936 -- pragma Ada_2005 (LOCAL_NAME):
10938 -- Note: these pragmas also have some specific processing in Par.Prag
10939 -- because we want to set the Ada 2005 version mode during parsing.
10941 -- The one argument form is used for managing the transition from
10942 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
10943 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
10944 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
10945 -- mode, a preference rule is established which does not choose
10946 -- such an entity unless it is unambiguously specified. This avoids
10947 -- extra subprograms marked this way from generating ambiguities in
10948 -- otherwise legal pre-Ada_2005 programs. The one argument form is
10949 -- intended for exclusive use in the GNAT run-time library.
10951 when Pragma_Ada_05 | Pragma_Ada_2005
=> declare
10957 if Arg_Count
= 1 then
10958 Check_Arg_Is_Local_Name
(Arg1
);
10959 E_Id
:= Get_Pragma_Arg
(Arg1
);
10961 if Etype
(E_Id
) = Any_Type
then
10965 Set_Is_Ada_2005_Only
(Entity
(E_Id
));
10966 Record_Rep_Item
(Entity
(E_Id
), N
);
10969 Check_Arg_Count
(0);
10971 -- For Ada_2005 we unconditionally enforce the documented
10972 -- configuration pragma placement, since we do not want to
10973 -- tolerate mixed modes in a unit involving Ada 2005. That
10974 -- would cause real difficulties for those cases where there
10975 -- are incompatibilities between Ada 95 and Ada 2005.
10977 Check_Valid_Configuration_Pragma
;
10979 -- Now set appropriate Ada mode
10981 Ada_Version
:= Ada_2005
;
10982 Ada_Version_Explicit
:= Ada_2005
;
10983 Ada_Version_Pragma
:= N
;
10987 ---------------------
10988 -- Ada_12/Ada_2012 --
10989 ---------------------
10992 -- pragma Ada_12 (LOCAL_NAME);
10994 -- pragma Ada_2012;
10995 -- pragma Ada_2012 (LOCAL_NAME):
10997 -- Note: these pragmas also have some specific processing in Par.Prag
10998 -- because we want to set the Ada 2012 version mode during parsing.
11000 -- The one argument form is used for managing the transition from Ada
11001 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
11002 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
11003 -- mode will generate a warning. In addition, in any pre-Ada_2012
11004 -- mode, a preference rule is established which does not choose
11005 -- such an entity unless it is unambiguously specified. This avoids
11006 -- extra subprograms marked this way from generating ambiguities in
11007 -- otherwise legal pre-Ada_2012 programs. The one argument form is
11008 -- intended for exclusive use in the GNAT run-time library.
11010 when Pragma_Ada_12 | Pragma_Ada_2012
=> declare
11016 if Arg_Count
= 1 then
11017 Check_Arg_Is_Local_Name
(Arg1
);
11018 E_Id
:= Get_Pragma_Arg
(Arg1
);
11020 if Etype
(E_Id
) = Any_Type
then
11024 Set_Is_Ada_2012_Only
(Entity
(E_Id
));
11025 Record_Rep_Item
(Entity
(E_Id
), N
);
11028 Check_Arg_Count
(0);
11030 -- For Ada_2012 we unconditionally enforce the documented
11031 -- configuration pragma placement, since we do not want to
11032 -- tolerate mixed modes in a unit involving Ada 2012. That
11033 -- would cause real difficulties for those cases where there
11034 -- are incompatibilities between Ada 95 and Ada 2012. We could
11035 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
11037 Check_Valid_Configuration_Pragma
;
11039 -- Now set appropriate Ada mode
11041 Ada_Version
:= Ada_2012
;
11042 Ada_Version_Explicit
:= Ada_2012
;
11043 Ada_Version_Pragma
:= N
;
11047 ----------------------
11048 -- All_Calls_Remote --
11049 ----------------------
11051 -- pragma All_Calls_Remote [(library_package_NAME)];
11053 when Pragma_All_Calls_Remote
=> All_Calls_Remote
: declare
11054 Lib_Entity
: Entity_Id
;
11057 Check_Ada_83_Warning
;
11058 Check_Valid_Library_Unit_Pragma
;
11060 if Nkind
(N
) = N_Null_Statement
then
11064 Lib_Entity
:= Find_Lib_Unit_Name
;
11066 -- A pragma that applies to a Ghost entity becomes Ghost for the
11067 -- purposes of legality checks and removal of ignored Ghost code.
11069 Mark_Pragma_As_Ghost
(N
, Lib_Entity
);
11071 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
11073 if Present
(Lib_Entity
) and then not Debug_Flag_U
then
11074 if not Is_Remote_Call_Interface
(Lib_Entity
) then
11075 Error_Pragma
("pragma% only apply to rci unit");
11077 -- Set flag for entity of the library unit
11080 Set_Has_All_Calls_Remote
(Lib_Entity
);
11083 end All_Calls_Remote
;
11085 ---------------------------
11086 -- Allow_Integer_Address --
11087 ---------------------------
11089 -- pragma Allow_Integer_Address;
11091 when Pragma_Allow_Integer_Address
=>
11093 Check_Valid_Configuration_Pragma
;
11094 Check_Arg_Count
(0);
11096 -- If Address is a private type, then set the flag to allow
11097 -- integer address values. If Address is not private, then this
11098 -- pragma has no purpose, so it is simply ignored. Not clear if
11099 -- there are any such targets now.
11101 if Opt
.Address_Is_Private
then
11102 Opt
.Allow_Integer_Address
:= True;
11110 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
11111 -- ARG ::= NAME | EXPRESSION
11113 -- The first two arguments are by convention intended to refer to an
11114 -- external tool and a tool-specific function. These arguments are
11117 when Pragma_Annotate
=> Annotate
: declare
11124 Check_At_Least_N_Arguments
(1);
11126 Nam_Arg
:= Last
(Pragma_Argument_Associations
(N
));
11128 -- Determine whether the last argument is "Entity => local_NAME"
11129 -- and if it is, perform the required semantic checks. Remove the
11130 -- argument from further processing.
11132 if Nkind
(Nam_Arg
) = N_Pragma_Argument_Association
11133 and then Chars
(Nam_Arg
) = Name_Entity
11135 Check_Arg_Is_Local_Name
(Nam_Arg
);
11136 Arg_Count
:= Arg_Count
- 1;
11138 -- A pragma that applies to a Ghost entity becomes Ghost for
11139 -- the purposes of legality checks and removal of ignored Ghost
11142 if Is_Entity_Name
(Get_Pragma_Arg
(Nam_Arg
))
11143 and then Present
(Entity
(Get_Pragma_Arg
(Nam_Arg
)))
11145 Mark_Pragma_As_Ghost
(N
, Entity
(Get_Pragma_Arg
(Nam_Arg
)));
11148 -- Not allowed in compiler units (bootstrap issues)
11150 Check_Compiler_Unit
("Entity for pragma Annotate", N
);
11153 -- Continue the processing with last argument removed for now
11155 Check_Arg_Is_Identifier
(Arg1
);
11156 Check_No_Identifiers
;
11159 -- The second parameter is optional, it is never analyzed
11164 -- Otherwise there is a second parameter
11167 -- The second parameter must be an identifier
11169 Check_Arg_Is_Identifier
(Arg2
);
11171 -- Process the remaining parameters (if any)
11173 Arg
:= Next
(Arg2
);
11174 while Present
(Arg
) loop
11175 Expr
:= Get_Pragma_Arg
(Arg
);
11178 if Is_Entity_Name
(Expr
) then
11181 -- For string literals, we assume Standard_String as the
11182 -- type, unless the string contains wide or wide_wide
11185 elsif Nkind
(Expr
) = N_String_Literal
then
11186 if Has_Wide_Wide_Character
(Expr
) then
11187 Resolve
(Expr
, Standard_Wide_Wide_String
);
11188 elsif Has_Wide_Character
(Expr
) then
11189 Resolve
(Expr
, Standard_Wide_String
);
11191 Resolve
(Expr
, Standard_String
);
11194 elsif Is_Overloaded
(Expr
) then
11195 Error_Pragma_Arg
("ambiguous argument for pragma%", Expr
);
11206 -------------------------------------------------
11207 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
11208 -------------------------------------------------
11211 -- ( [Check => ] Boolean_EXPRESSION
11212 -- [, [Message =>] Static_String_EXPRESSION]);
11214 -- pragma Assert_And_Cut
11215 -- ( [Check => ] Boolean_EXPRESSION
11216 -- [, [Message =>] Static_String_EXPRESSION]);
11219 -- ( [Check => ] Boolean_EXPRESSION
11220 -- [, [Message =>] Static_String_EXPRESSION]);
11222 -- pragma Loop_Invariant
11223 -- ( [Check => ] Boolean_EXPRESSION
11224 -- [, [Message =>] Static_String_EXPRESSION]);
11226 when Pragma_Assert |
11227 Pragma_Assert_And_Cut |
11229 Pragma_Loop_Invariant
=>
11231 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean;
11232 -- Determine whether expression Expr contains a Loop_Entry
11233 -- attribute reference.
11235 -------------------------
11236 -- Contains_Loop_Entry --
11237 -------------------------
11239 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean is
11240 Has_Loop_Entry
: Boolean := False;
11242 function Process
(N
: Node_Id
) return Traverse_Result
;
11243 -- Process function for traversal to look for Loop_Entry
11249 function Process
(N
: Node_Id
) return Traverse_Result
is
11251 if Nkind
(N
) = N_Attribute_Reference
11252 and then Attribute_Name
(N
) = Name_Loop_Entry
11254 Has_Loop_Entry
:= True;
11261 procedure Traverse
is new Traverse_Proc
(Process
);
11263 -- Start of processing for Contains_Loop_Entry
11267 return Has_Loop_Entry
;
11268 end Contains_Loop_Entry
;
11273 New_Args
: List_Id
;
11275 -- Start of processing for Assert
11278 -- Assert is an Ada 2005 RM-defined pragma
11280 if Prag_Id
= Pragma_Assert
then
11283 -- The remaining ones are GNAT pragmas
11289 Check_At_Least_N_Arguments
(1);
11290 Check_At_Most_N_Arguments
(2);
11291 Check_Arg_Order
((Name_Check
, Name_Message
));
11292 Check_Optional_Identifier
(Arg1
, Name_Check
);
11293 Expr
:= Get_Pragma_Arg
(Arg1
);
11295 -- Special processing for Loop_Invariant, Loop_Variant or for
11296 -- other cases where a Loop_Entry attribute is present. If the
11297 -- assertion pragma contains attribute Loop_Entry, ensure that
11298 -- the related pragma is within a loop.
11300 if Prag_Id
= Pragma_Loop_Invariant
11301 or else Prag_Id
= Pragma_Loop_Variant
11302 or else Contains_Loop_Entry
(Expr
)
11304 Check_Loop_Pragma_Placement
;
11306 -- Perform preanalysis to deal with embedded Loop_Entry
11309 Preanalyze_Assert_Expression
(Expr
, Any_Boolean
);
11312 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
11313 -- a corresponding Check pragma:
11315 -- pragma Check (name, condition [, msg]);
11317 -- Where name is the identifier matching the pragma name. So
11318 -- rewrite pragma in this manner, transfer the message argument
11319 -- if present, and analyze the result
11321 -- Note: When dealing with a semantically analyzed tree, the
11322 -- information that a Check node N corresponds to a source Assert,
11323 -- Assume, or Assert_And_Cut pragma can be retrieved from the
11324 -- pragma kind of Original_Node(N).
11326 New_Args
:= New_List
(
11327 Make_Pragma_Argument_Association
(Loc
,
11328 Expression
=> Make_Identifier
(Loc
, Pname
)),
11329 Make_Pragma_Argument_Association
(Sloc
(Expr
),
11330 Expression
=> Expr
));
11332 if Arg_Count
> 1 then
11333 Check_Optional_Identifier
(Arg2
, Name_Message
);
11335 -- Provide semantic annnotations for optional argument, for
11336 -- ASIS use, before rewriting.
11338 Preanalyze_And_Resolve
(Expression
(Arg2
), Standard_String
);
11339 Append_To
(New_Args
, New_Copy_Tree
(Arg2
));
11342 -- Rewrite as Check pragma
11346 Chars
=> Name_Check
,
11347 Pragma_Argument_Associations
=> New_Args
));
11352 ----------------------
11353 -- Assertion_Policy --
11354 ----------------------
11356 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
11358 -- The following form is Ada 2012 only, but we allow it in all modes
11360 -- Pragma Assertion_Policy (
11361 -- ASSERTION_KIND => POLICY_IDENTIFIER
11362 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
11364 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
11366 -- RM_ASSERTION_KIND ::= Assert |
11367 -- Static_Predicate |
11368 -- Dynamic_Predicate |
11373 -- Type_Invariant |
11374 -- Type_Invariant'Class
11376 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
11378 -- Contract_Cases |
11380 -- Default_Initial_Condition |
11382 -- Initial_Condition |
11383 -- Loop_Invariant |
11389 -- Statement_Assertions
11391 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
11392 -- ID_ASSERTION_KIND list contains implementation-defined additions
11393 -- recognized by GNAT. The effect is to control the behavior of
11394 -- identically named aspects and pragmas, depending on the specified
11395 -- policy identifier:
11397 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
11399 -- Note: Check and Ignore are language-defined. Disable is a GNAT
11400 -- implementation-defined addition that results in totally ignoring
11401 -- the corresponding assertion. If Disable is specified, then the
11402 -- argument of the assertion is not even analyzed. This is useful
11403 -- when the aspect/pragma argument references entities in a with'ed
11404 -- package that is replaced by a dummy package in the final build.
11406 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
11407 -- and Type_Invariant'Class were recognized by the parser and
11408 -- transformed into references to the special internal identifiers
11409 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
11410 -- processing is required here.
11412 when Pragma_Assertion_Policy
=> Assertion_Policy
: declare
11421 -- This can always appear as a configuration pragma
11423 if Is_Configuration_Pragma
then
11426 -- It can also appear in a declarative part or package spec in Ada
11427 -- 2012 mode. We allow this in other modes, but in that case we
11428 -- consider that we have an Ada 2012 pragma on our hands.
11431 Check_Is_In_Decl_Part_Or_Package_Spec
;
11435 -- One argument case with no identifier (first form above)
11438 and then (Nkind
(Arg1
) /= N_Pragma_Argument_Association
11439 or else Chars
(Arg1
) = No_Name
)
11441 Check_Arg_Is_One_Of
11442 (Arg1
, Name_Check
, Name_Disable
, Name_Ignore
);
11444 -- Treat one argument Assertion_Policy as equivalent to:
11446 -- pragma Check_Policy (Assertion, policy)
11448 -- So rewrite pragma in that manner and link on to the chain
11449 -- of Check_Policy pragmas, marking the pragma as analyzed.
11451 Policy
:= Get_Pragma_Arg
(Arg1
);
11455 Chars
=> Name_Check_Policy
,
11456 Pragma_Argument_Associations
=> New_List
(
11457 Make_Pragma_Argument_Association
(Loc
,
11458 Expression
=> Make_Identifier
(Loc
, Name_Assertion
)),
11460 Make_Pragma_Argument_Association
(Loc
,
11462 Make_Identifier
(Sloc
(Policy
), Chars
(Policy
))))));
11465 -- Here if we have two or more arguments
11468 Check_At_Least_N_Arguments
(1);
11471 -- Loop through arguments
11474 while Present
(Arg
) loop
11475 LocP
:= Sloc
(Arg
);
11477 -- Kind must be specified
11479 if Nkind
(Arg
) /= N_Pragma_Argument_Association
11480 or else Chars
(Arg
) = No_Name
11483 ("missing assertion kind for pragma%", Arg
);
11486 -- Check Kind and Policy have allowed forms
11488 Kind
:= Chars
(Arg
);
11490 if not Is_Valid_Assertion_Kind
(Kind
) then
11492 ("invalid assertion kind for pragma%", Arg
);
11495 Check_Arg_Is_One_Of
11496 (Arg
, Name_Check
, Name_Disable
, Name_Ignore
);
11498 -- Rewrite the Assertion_Policy pragma as a series of
11499 -- Check_Policy pragmas of the form:
11501 -- Check_Policy (Kind, Policy);
11503 -- Note: the insertion of the pragmas cannot be done with
11504 -- Insert_Action because in the configuration case, there
11505 -- are no scopes on the scope stack and the mechanism will
11508 Insert_Before_And_Analyze
(N
,
11510 Chars
=> Name_Check_Policy
,
11511 Pragma_Argument_Associations
=> New_List
(
11512 Make_Pragma_Argument_Association
(LocP
,
11513 Expression
=> Make_Identifier
(LocP
, Kind
)),
11514 Make_Pragma_Argument_Association
(LocP
,
11515 Expression
=> Get_Pragma_Arg
(Arg
)))));
11520 -- Rewrite the Assertion_Policy pragma as null since we have
11521 -- now inserted all the equivalent Check pragmas.
11523 Rewrite
(N
, Make_Null_Statement
(Loc
));
11526 end Assertion_Policy
;
11528 ------------------------------
11529 -- Assume_No_Invalid_Values --
11530 ------------------------------
11532 -- pragma Assume_No_Invalid_Values (On | Off);
11534 when Pragma_Assume_No_Invalid_Values
=>
11536 Check_Valid_Configuration_Pragma
;
11537 Check_Arg_Count
(1);
11538 Check_No_Identifiers
;
11539 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
11541 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
11542 Assume_No_Invalid_Values
:= True;
11544 Assume_No_Invalid_Values
:= False;
11547 --------------------------
11548 -- Attribute_Definition --
11549 --------------------------
11551 -- pragma Attribute_Definition
11552 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
11553 -- [Entity =>] LOCAL_NAME,
11554 -- [Expression =>] EXPRESSION | NAME);
11556 when Pragma_Attribute_Definition
=> Attribute_Definition
: declare
11557 Attribute_Designator
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
11562 Check_Arg_Count
(3);
11563 Check_Optional_Identifier
(Arg1
, "attribute");
11564 Check_Optional_Identifier
(Arg2
, "entity");
11565 Check_Optional_Identifier
(Arg3
, "expression");
11567 if Nkind
(Attribute_Designator
) /= N_Identifier
then
11568 Error_Msg_N
("attribute name expected", Attribute_Designator
);
11572 Check_Arg_Is_Local_Name
(Arg2
);
11574 -- If the attribute is not recognized, then issue a warning (not
11575 -- an error), and ignore the pragma.
11577 Aname
:= Chars
(Attribute_Designator
);
11579 if not Is_Attribute_Name
(Aname
) then
11580 Bad_Attribute
(Attribute_Designator
, Aname
, Warn
=> True);
11584 -- Otherwise, rewrite the pragma as an attribute definition clause
11587 Make_Attribute_Definition_Clause
(Loc
,
11588 Name
=> Get_Pragma_Arg
(Arg2
),
11590 Expression
=> Get_Pragma_Arg
(Arg3
)));
11592 end Attribute_Definition
;
11594 ------------------------------------------------------------------
11595 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
11596 ------------------------------------------------------------------
11598 -- pragma Asynch_Readers [ (boolean_EXPRESSION) ];
11599 -- pragma Asynch_Writers [ (boolean_EXPRESSION) ];
11600 -- pragma Effective_Reads [ (boolean_EXPRESSION) ];
11601 -- pragma Effective_Writes [ (boolean_EXPRESSION) ];
11603 when Pragma_Async_Readers |
11604 Pragma_Async_Writers |
11605 Pragma_Effective_Reads |
11606 Pragma_Effective_Writes
=>
11607 Async_Effective
: declare
11608 Obj_Decl
: Node_Id
;
11609 Obj_Id
: Entity_Id
;
11613 Check_No_Identifiers
;
11614 Check_At_Most_N_Arguments
(1);
11616 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
11618 -- Object declaration
11620 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
11623 -- Otherwise the pragma is associated with an illegal construact
11630 Obj_Id
:= Defining_Entity
(Obj_Decl
);
11632 -- Perform minimal verification to ensure that the argument is at
11633 -- least a variable. Subsequent finer grained checks will be done
11634 -- at the end of the declarative region the contains the pragma.
11636 if Ekind
(Obj_Id
) = E_Variable
then
11638 -- Chain the pragma on the contract for further processing by
11639 -- Analyze_External_Property_In_Decl_Part.
11641 Add_Contract_Item
(N
, Obj_Id
);
11643 -- A pragma that applies to a Ghost entity becomes Ghost for
11644 -- the purposes of legality checks and removal of ignored Ghost
11647 Mark_Pragma_As_Ghost
(N
, Obj_Id
);
11649 -- Analyze the Boolean expression (if any)
11651 if Present
(Arg1
) then
11652 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
11655 -- Otherwise the external property applies to a constant
11658 Error_Pragma
("pragma % must apply to a volatile object");
11660 end Async_Effective
;
11666 -- pragma Asynchronous (LOCAL_NAME);
11668 when Pragma_Asynchronous
=> Asynchronous
: declare
11671 Formal
: Entity_Id
;
11676 procedure Process_Async_Pragma
;
11677 -- Common processing for procedure and access-to-procedure case
11679 --------------------------
11680 -- Process_Async_Pragma --
11681 --------------------------
11683 procedure Process_Async_Pragma
is
11686 Set_Is_Asynchronous
(Nm
);
11690 -- The formals should be of mode IN (RM E.4.1(6))
11693 while Present
(S
) loop
11694 Formal
:= Defining_Identifier
(S
);
11696 if Nkind
(Formal
) = N_Defining_Identifier
11697 and then Ekind
(Formal
) /= E_In_Parameter
11700 ("pragma% procedure can only have IN parameter",
11707 Set_Is_Asynchronous
(Nm
);
11708 end Process_Async_Pragma
;
11710 -- Start of processing for pragma Asynchronous
11713 Check_Ada_83_Warning
;
11714 Check_No_Identifiers
;
11715 Check_Arg_Count
(1);
11716 Check_Arg_Is_Local_Name
(Arg1
);
11718 if Debug_Flag_U
then
11722 C_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
11723 Analyze
(Get_Pragma_Arg
(Arg1
));
11724 Nm
:= Entity
(Get_Pragma_Arg
(Arg1
));
11726 -- A pragma that applies to a Ghost entity becomes Ghost for the
11727 -- purposes of legality checks and removal of ignored Ghost code.
11729 Mark_Pragma_As_Ghost
(N
, Nm
);
11731 if not Is_Remote_Call_Interface
(C_Ent
)
11732 and then not Is_Remote_Types
(C_Ent
)
11734 -- This pragma should only appear in an RCI or Remote Types
11735 -- unit (RM E.4.1(4)).
11738 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11741 if Ekind
(Nm
) = E_Procedure
11742 and then Nkind
(Parent
(Nm
)) = N_Procedure_Specification
11744 if not Is_Remote_Call_Interface
(Nm
) then
11746 ("pragma% cannot be applied on non-remote procedure",
11750 L
:= Parameter_Specifications
(Parent
(Nm
));
11751 Process_Async_Pragma
;
11754 elsif Ekind
(Nm
) = E_Function
then
11756 ("pragma% cannot be applied to function", Arg1
);
11758 elsif Is_Remote_Access_To_Subprogram_Type
(Nm
) then
11759 if Is_Record_Type
(Nm
) then
11761 -- A record type that is the Equivalent_Type for a remote
11762 -- access-to-subprogram type.
11764 Decl
:= Declaration_Node
(Corresponding_Remote_Type
(Nm
));
11767 -- A non-expanded RAS type (distribution is not enabled)
11769 Decl
:= Declaration_Node
(Nm
);
11772 if Nkind
(Decl
) = N_Full_Type_Declaration
11773 and then Nkind
(Type_Definition
(Decl
)) =
11774 N_Access_Procedure_Definition
11776 L
:= Parameter_Specifications
(Type_Definition
(Decl
));
11777 Process_Async_Pragma
;
11779 if Is_Asynchronous
(Nm
)
11780 and then Expander_Active
11781 and then Get_PCS_Name
/= Name_No_DSA
11783 RACW_Type_Is_Asynchronous
(Underlying_RACW_Type
(Nm
));
11788 ("pragma% cannot reference access-to-function type",
11792 -- Only other possibility is Access-to-class-wide type
11794 elsif Is_Access_Type
(Nm
)
11795 and then Is_Class_Wide_Type
(Designated_Type
(Nm
))
11797 Check_First_Subtype
(Arg1
);
11798 Set_Is_Asynchronous
(Nm
);
11799 if Expander_Active
then
11800 RACW_Type_Is_Asynchronous
(Nm
);
11804 Error_Pragma_Arg
("inappropriate argument for pragma%", Arg1
);
11812 -- pragma Atomic (LOCAL_NAME);
11814 when Pragma_Atomic
=>
11815 Process_Atomic_Independent_Shared_Volatile
;
11817 -----------------------
11818 -- Atomic_Components --
11819 -----------------------
11821 -- pragma Atomic_Components (array_LOCAL_NAME);
11823 -- This processing is shared by Volatile_Components
11825 when Pragma_Atomic_Components |
11826 Pragma_Volatile_Components
=>
11827 Atomic_Components
: declare
11834 Check_Ada_83_Warning
;
11835 Check_No_Identifiers
;
11836 Check_Arg_Count
(1);
11837 Check_Arg_Is_Local_Name
(Arg1
);
11838 E_Id
:= Get_Pragma_Arg
(Arg1
);
11840 if Etype
(E_Id
) = Any_Type
then
11844 E
:= Entity
(E_Id
);
11846 -- A pragma that applies to a Ghost entity becomes Ghost for the
11847 -- purposes of legality checks and removal of ignored Ghost code.
11849 Mark_Pragma_As_Ghost
(N
, E
);
11850 Check_Duplicate_Pragma
(E
);
11852 if Rep_Item_Too_Early
(E
, N
)
11854 Rep_Item_Too_Late
(E
, N
)
11859 D
:= Declaration_Node
(E
);
11862 if (K
= N_Full_Type_Declaration
and then Is_Array_Type
(E
))
11864 ((Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
11865 and then Nkind
(D
) = N_Object_Declaration
11866 and then Nkind
(Object_Definition
(D
)) =
11867 N_Constrained_Array_Definition
)
11869 -- The flag is set on the object, or on the base type
11871 if Nkind
(D
) /= N_Object_Declaration
then
11872 E
:= Base_Type
(E
);
11875 -- Atomic implies both Independent and Volatile
11877 if Prag_Id
= Pragma_Atomic_Components
then
11878 Set_Has_Atomic_Components
(E
);
11879 Set_Has_Independent_Components
(E
);
11882 Set_Has_Volatile_Components
(E
);
11885 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
11887 end Atomic_Components
;
11889 --------------------
11890 -- Attach_Handler --
11891 --------------------
11893 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11895 when Pragma_Attach_Handler
=>
11896 Check_Ada_83_Warning
;
11897 Check_No_Identifiers
;
11898 Check_Arg_Count
(2);
11900 if No_Run_Time_Mode
then
11901 Error_Msg_CRT
("Attach_Handler pragma", N
);
11903 Check_Interrupt_Or_Attach_Handler
;
11905 -- The expression that designates the attribute may depend on a
11906 -- discriminant, and is therefore a per-object expression, to
11907 -- be expanded in the init proc. If expansion is enabled, then
11908 -- perform semantic checks on a copy only.
11913 Parg2
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
11916 -- In Relaxed_RM_Semantics mode, we allow any static
11917 -- integer value, for compatibility with other compilers.
11919 if Relaxed_RM_Semantics
11920 and then Nkind
(Parg2
) = N_Integer_Literal
11922 Typ
:= Standard_Integer
;
11924 Typ
:= RTE
(RE_Interrupt_ID
);
11927 if Expander_Active
then
11928 Temp
:= New_Copy_Tree
(Parg2
);
11929 Set_Parent
(Temp
, N
);
11930 Preanalyze_And_Resolve
(Temp
, Typ
);
11933 Resolve
(Parg2
, Typ
);
11937 Process_Interrupt_Or_Attach_Handler
;
11940 --------------------
11941 -- C_Pass_By_Copy --
11942 --------------------
11944 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11946 when Pragma_C_Pass_By_Copy
=> C_Pass_By_Copy
: declare
11952 Check_Valid_Configuration_Pragma
;
11953 Check_Arg_Count
(1);
11954 Check_Optional_Identifier
(Arg1
, "max_size");
11956 Arg
:= Get_Pragma_Arg
(Arg1
);
11957 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
11959 Val
:= Expr_Value
(Arg
);
11963 ("maximum size for pragma% must be positive", Arg1
);
11965 elsif UI_Is_In_Int_Range
(Val
) then
11966 Default_C_Record_Mechanism
:= UI_To_Int
(Val
);
11968 -- If a giant value is given, Int'Last will do well enough.
11969 -- If sometime someone complains that a record larger than
11970 -- two gigabytes is not copied, we will worry about it then.
11973 Default_C_Record_Mechanism
:= Mechanism_Type
'Last;
11975 end C_Pass_By_Copy
;
11981 -- pragma Check ([Name =>] CHECK_KIND,
11982 -- [Check =>] Boolean_EXPRESSION
11983 -- [,[Message =>] String_EXPRESSION]);
11985 -- CHECK_KIND ::= IDENTIFIER |
11988 -- Invariant'Class |
11989 -- Type_Invariant'Class
11991 -- The identifiers Assertions and Statement_Assertions are not
11992 -- allowed, since they have special meaning for Check_Policy.
11994 when Pragma_Check
=> Check
: declare
12000 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
12003 -- Pragma Check is Ghost when it applies to a Ghost entity. Set
12004 -- the mode now to ensure that any nodes generated during analysis
12005 -- and expansion are marked as Ghost.
12007 Set_Ghost_Mode
(N
);
12010 Check_At_Least_N_Arguments
(2);
12011 Check_At_Most_N_Arguments
(3);
12012 Check_Optional_Identifier
(Arg1
, Name_Name
);
12013 Check_Optional_Identifier
(Arg2
, Name_Check
);
12015 if Arg_Count
= 3 then
12016 Check_Optional_Identifier
(Arg3
, Name_Message
);
12017 Str
:= Get_Pragma_Arg
(Arg3
);
12020 Rewrite_Assertion_Kind
(Get_Pragma_Arg
(Arg1
));
12021 Check_Arg_Is_Identifier
(Arg1
);
12022 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
12024 -- Check forbidden name Assertions or Statement_Assertions
12027 when Name_Assertions
=>
12029 ("""Assertions"" is not allowed as a check kind for "
12030 & "pragma%", Arg1
);
12032 when Name_Statement_Assertions
=>
12034 ("""Statement_Assertions"" is not allowed as a check kind "
12035 & "for pragma%", Arg1
);
12041 -- Check applicable policy. We skip this if Checked/Ignored status
12042 -- is already set (e.g. in the case of a pragma from an aspect).
12044 if Is_Checked
(N
) or else Is_Ignored
(N
) then
12047 -- For a non-source pragma that is a rewriting of another pragma,
12048 -- copy the Is_Checked/Ignored status from the rewritten pragma.
12050 elsif Is_Rewrite_Substitution
(N
)
12051 and then Nkind
(Original_Node
(N
)) = N_Pragma
12052 and then Original_Node
(N
) /= N
12054 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
12055 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
12057 -- Otherwise query the applicable policy at this point
12060 case Check_Kind
(Cname
) is
12061 when Name_Ignore
=>
12062 Set_Is_Ignored
(N
, True);
12063 Set_Is_Checked
(N
, False);
12066 Set_Is_Ignored
(N
, False);
12067 Set_Is_Checked
(N
, True);
12069 -- For disable, rewrite pragma as null statement and skip
12070 -- rest of the analysis of the pragma.
12072 when Name_Disable
=>
12073 Rewrite
(N
, Make_Null_Statement
(Loc
));
12077 -- No other possibilities
12080 raise Program_Error
;
12084 -- If check kind was not Disable, then continue pragma analysis
12086 Expr
:= Get_Pragma_Arg
(Arg2
);
12088 -- Deal with SCO generation
12092 -- Nothing to do for invariants and predicates as the checks
12093 -- occur in the client units. The SCO for the aspect in the
12094 -- declaration unit is conservatively always enabled.
12096 when Name_Invariant | Name_Predicate
=>
12099 -- Otherwise mark aspect/pragma SCO as enabled
12102 if Is_Checked
(N
) and then not Split_PPC
(N
) then
12103 Set_SCO_Pragma_Enabled
(Loc
);
12107 -- Deal with analyzing the string argument
12109 if Arg_Count
= 3 then
12111 -- If checks are not on we don't want any expansion (since
12112 -- such expansion would not get properly deleted) but
12113 -- we do want to analyze (to get proper references).
12114 -- The Preanalyze_And_Resolve routine does just what we want
12116 if Is_Ignored
(N
) then
12117 Preanalyze_And_Resolve
(Str
, Standard_String
);
12119 -- Otherwise we need a proper analysis and expansion
12122 Analyze_And_Resolve
(Str
, Standard_String
);
12126 -- Now you might think we could just do the same with the Boolean
12127 -- expression if checks are off (and expansion is on) and then
12128 -- rewrite the check as a null statement. This would work but we
12129 -- would lose the useful warnings about an assertion being bound
12130 -- to fail even if assertions are turned off.
12132 -- So instead we wrap the boolean expression in an if statement
12133 -- that looks like:
12135 -- if False and then condition then
12139 -- The reason we do this rewriting during semantic analysis rather
12140 -- than as part of normal expansion is that we cannot analyze and
12141 -- expand the code for the boolean expression directly, or it may
12142 -- cause insertion of actions that would escape the attempt to
12143 -- suppress the check code.
12145 -- Note that the Sloc for the if statement corresponds to the
12146 -- argument condition, not the pragma itself. The reason for
12147 -- this is that we may generate a warning if the condition is
12148 -- False at compile time, and we do not want to delete this
12149 -- warning when we delete the if statement.
12151 if Expander_Active
and Is_Ignored
(N
) then
12152 Eloc
:= Sloc
(Expr
);
12155 Make_If_Statement
(Eloc
,
12157 Make_And_Then
(Eloc
,
12158 Left_Opnd
=> Make_Identifier
(Eloc
, Name_False
),
12159 Right_Opnd
=> Expr
),
12160 Then_Statements
=> New_List
(
12161 Make_Null_Statement
(Eloc
))));
12163 -- Now go ahead and analyze the if statement
12165 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
12167 -- One rather special treatment. If we are now in Eliminated
12168 -- overflow mode, then suppress overflow checking since we do
12169 -- not want to drag in the bignum stuff if we are in Ignore
12170 -- mode anyway. This is particularly important if we are using
12171 -- a configurable run time that does not support bignum ops.
12173 if Scope_Suppress
.Overflow_Mode_Assertions
= Eliminated
then
12175 Svo
: constant Boolean :=
12176 Scope_Suppress
.Suppress
(Overflow_Check
);
12178 Scope_Suppress
.Overflow_Mode_Assertions
:= Strict
;
12179 Scope_Suppress
.Suppress
(Overflow_Check
) := True;
12181 Scope_Suppress
.Suppress
(Overflow_Check
) := Svo
;
12182 Scope_Suppress
.Overflow_Mode_Assertions
:= Eliminated
;
12185 -- Not that special case
12191 -- All done with this check
12193 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
12195 -- Check is active or expansion not active. In these cases we can
12196 -- just go ahead and analyze the boolean with no worries.
12199 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
12200 Analyze_And_Resolve
(Expr
, Any_Boolean
);
12201 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
12204 Ghost_Mode
:= Save_Ghost_Mode
;
12207 --------------------------
12208 -- Check_Float_Overflow --
12209 --------------------------
12211 -- pragma Check_Float_Overflow;
12213 when Pragma_Check_Float_Overflow
=>
12215 Check_Valid_Configuration_Pragma
;
12216 Check_Arg_Count
(0);
12217 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
12223 -- pragma Check_Name (check_IDENTIFIER);
12225 when Pragma_Check_Name
=>
12227 Check_No_Identifiers
;
12228 Check_Valid_Configuration_Pragma
;
12229 Check_Arg_Count
(1);
12230 Check_Arg_Is_Identifier
(Arg1
);
12233 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
12236 for J
in Check_Names
.First
.. Check_Names
.Last
loop
12237 if Check_Names
.Table
(J
) = Nam
then
12242 Check_Names
.Append
(Nam
);
12249 -- This is the old style syntax, which is still allowed in all modes:
12251 -- pragma Check_Policy ([Name =>] CHECK_KIND
12252 -- [Policy =>] POLICY_IDENTIFIER);
12254 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
12256 -- CHECK_KIND ::= IDENTIFIER |
12259 -- Type_Invariant'Class |
12262 -- This is the new style syntax, compatible with Assertion_Policy
12263 -- and also allowed in all modes.
12265 -- Pragma Check_Policy (
12266 -- CHECK_KIND => POLICY_IDENTIFIER
12267 -- {, CHECK_KIND => POLICY_IDENTIFIER});
12269 -- Note: the identifiers Name and Policy are not allowed as
12270 -- Check_Kind values. This avoids ambiguities between the old and
12271 -- new form syntax.
12273 when Pragma_Check_Policy
=> Check_Policy
: declare
12279 Check_At_Least_N_Arguments
(1);
12281 -- A Check_Policy pragma can appear either as a configuration
12282 -- pragma, or in a declarative part or a package spec (see RM
12283 -- 11.5(5) for rules for Suppress/Unsuppress which are also
12284 -- followed for Check_Policy).
12286 if not Is_Configuration_Pragma
then
12287 Check_Is_In_Decl_Part_Or_Package_Spec
;
12290 -- Figure out if we have the old or new syntax. We have the
12291 -- old syntax if the first argument has no identifier, or the
12292 -- identifier is Name.
12294 if Nkind
(Arg1
) /= N_Pragma_Argument_Association
12295 or else Nam_In
(Chars
(Arg1
), No_Name
, Name_Name
)
12299 Check_Arg_Count
(2);
12300 Check_Optional_Identifier
(Arg1
, Name_Name
);
12301 Kind
:= Get_Pragma_Arg
(Arg1
);
12302 Rewrite_Assertion_Kind
(Kind
);
12303 Check_Arg_Is_Identifier
(Arg1
);
12305 -- Check forbidden check kind
12307 if Nam_In
(Chars
(Kind
), Name_Name
, Name_Policy
) then
12308 Error_Msg_Name_2
:= Chars
(Kind
);
12310 ("pragma% does not allow% as check name", Arg1
);
12315 Check_Optional_Identifier
(Arg2
, Name_Policy
);
12316 Check_Arg_Is_One_Of
12318 Name_On
, Name_Off
, Name_Check
, Name_Disable
, Name_Ignore
);
12319 Ident
:= Get_Pragma_Arg
(Arg2
);
12321 if Chars
(Kind
) = Name_Ghost
then
12323 -- Pragma Check_Policy specifying a Ghost policy cannot
12324 -- occur within a ghost subprogram or package.
12326 if Ghost_Mode
> None
then
12328 ("pragma % cannot appear within ghost subprogram or "
12331 -- The policy identifier of pragma Ghost must be either
12332 -- Check or Ignore (SPARK RM 6.9(7)).
12334 elsif not Nam_In
(Chars
(Ident
), Name_Check
,
12338 ("argument of pragma % Ghost must be Check or Ignore",
12343 -- And chain pragma on the Check_Policy_List for search
12345 Set_Next_Pragma
(N
, Opt
.Check_Policy_List
);
12346 Opt
.Check_Policy_List
:= N
;
12348 -- For the new syntax, what we do is to convert each argument to
12349 -- an old syntax equivalent. We do that because we want to chain
12350 -- old style Check_Policy pragmas for the search (we don't want
12351 -- to have to deal with multiple arguments in the search).
12361 while Present
(Arg
) loop
12362 LocP
:= Sloc
(Arg
);
12363 Argx
:= Get_Pragma_Arg
(Arg
);
12365 -- Kind must be specified
12367 if Nkind
(Arg
) /= N_Pragma_Argument_Association
12368 or else Chars
(Arg
) = No_Name
12371 ("missing assertion kind for pragma%", Arg
);
12374 -- Construct equivalent old form syntax Check_Policy
12375 -- pragma and insert it to get remaining checks.
12379 Chars
=> Name_Check_Policy
,
12380 Pragma_Argument_Associations
=> New_List
(
12381 Make_Pragma_Argument_Association
(LocP
,
12383 Make_Identifier
(LocP
, Chars
(Arg
))),
12384 Make_Pragma_Argument_Association
(Sloc
(Argx
),
12385 Expression
=> Argx
))));
12390 -- Rewrite original Check_Policy pragma to null, since we
12391 -- have converted it into a series of old syntax pragmas.
12393 Rewrite
(N
, Make_Null_Statement
(Loc
));
12403 -- pragma Comment (static_string_EXPRESSION)
12405 -- Processing for pragma Comment shares the circuitry for pragma
12406 -- Ident. The only differences are that Ident enforces a limit of 31
12407 -- characters on its argument, and also enforces limitations on
12408 -- placement for DEC compatibility. Pragma Comment shares neither of
12409 -- these restrictions.
12411 -------------------
12412 -- Common_Object --
12413 -------------------
12415 -- pragma Common_Object (
12416 -- [Internal =>] LOCAL_NAME
12417 -- [, [External =>] EXTERNAL_SYMBOL]
12418 -- [, [Size =>] EXTERNAL_SYMBOL]);
12420 -- Processing for this pragma is shared with Psect_Object
12422 ------------------------
12423 -- Compile_Time_Error --
12424 ------------------------
12426 -- pragma Compile_Time_Error
12427 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12429 when Pragma_Compile_Time_Error
=>
12431 Process_Compile_Time_Warning_Or_Error
;
12433 --------------------------
12434 -- Compile_Time_Warning --
12435 --------------------------
12437 -- pragma Compile_Time_Warning
12438 -- (boolean_EXPRESSION, static_string_EXPRESSION);
12440 when Pragma_Compile_Time_Warning
=>
12442 Process_Compile_Time_Warning_Or_Error
;
12444 ---------------------------
12445 -- Compiler_Unit_Warning --
12446 ---------------------------
12448 -- pragma Compiler_Unit_Warning;
12452 -- Originally, we had only pragma Compiler_Unit, and it resulted in
12453 -- errors not warnings. This means that we had introduced a big extra
12454 -- inertia to compiler changes, since even if we implemented a new
12455 -- feature, and even if all versions to be used for bootstrapping
12456 -- implemented this new feature, we could not use it, since old
12457 -- compilers would give errors for using this feature in units
12458 -- having Compiler_Unit pragmas.
12460 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
12461 -- problem. We no longer have any units mentioning Compiler_Unit,
12462 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
12463 -- and thus generates a warning which can be ignored. So that deals
12464 -- with the problem of old compilers not implementing the newer form
12467 -- Newer compilers recognize the new pragma, but generate warning
12468 -- messages instead of errors, which again can be ignored in the
12469 -- case of an old compiler which implements a wanted new feature
12470 -- but at the time felt like warning about it for older compilers.
12472 -- We retain Compiler_Unit so that new compilers can be used to build
12473 -- older run-times that use this pragma. That's an unusual case, but
12474 -- it's easy enough to handle, so why not?
12476 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning
=>
12478 Check_Arg_Count
(0);
12480 -- Only recognized in main unit
12482 if Current_Sem_Unit
= Main_Unit
then
12483 Compiler_Unit
:= True;
12486 -----------------------------
12487 -- Complete_Representation --
12488 -----------------------------
12490 -- pragma Complete_Representation;
12492 when Pragma_Complete_Representation
=>
12494 Check_Arg_Count
(0);
12496 if Nkind
(Parent
(N
)) /= N_Record_Representation_Clause
then
12498 ("pragma & must appear within record representation clause");
12501 ----------------------------
12502 -- Complex_Representation --
12503 ----------------------------
12505 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
12507 when Pragma_Complex_Representation
=> Complex_Representation
: declare
12514 Check_Arg_Count
(1);
12515 Check_Optional_Identifier
(Arg1
, Name_Entity
);
12516 Check_Arg_Is_Local_Name
(Arg1
);
12517 E_Id
:= Get_Pragma_Arg
(Arg1
);
12519 if Etype
(E_Id
) = Any_Type
then
12523 E
:= Entity
(E_Id
);
12525 if not Is_Record_Type
(E
) then
12527 ("argument for pragma% must be record type", Arg1
);
12530 Ent
:= First_Entity
(E
);
12533 or else No
(Next_Entity
(Ent
))
12534 or else Present
(Next_Entity
(Next_Entity
(Ent
)))
12535 or else not Is_Floating_Point_Type
(Etype
(Ent
))
12536 or else Etype
(Ent
) /= Etype
(Next_Entity
(Ent
))
12539 ("record for pragma% must have two fields of the same "
12540 & "floating-point type", Arg1
);
12543 Set_Has_Complex_Representation
(Base_Type
(E
));
12545 -- We need to treat the type has having a non-standard
12546 -- representation, for back-end purposes, even though in
12547 -- general a complex will have the default representation
12548 -- of a record with two real components.
12550 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
12552 end Complex_Representation
;
12554 -------------------------
12555 -- Component_Alignment --
12556 -------------------------
12558 -- pragma Component_Alignment (
12559 -- [Form =>] ALIGNMENT_CHOICE
12560 -- [, [Name =>] type_LOCAL_NAME]);
12562 -- ALIGNMENT_CHOICE ::=
12564 -- | Component_Size_4
12568 when Pragma_Component_Alignment
=> Component_AlignmentP
: declare
12569 Args
: Args_List
(1 .. 2);
12570 Names
: constant Name_List
(1 .. 2) := (
12574 Form
: Node_Id
renames Args
(1);
12575 Name
: Node_Id
renames Args
(2);
12577 Atype
: Component_Alignment_Kind
;
12582 Gather_Associations
(Names
, Args
);
12585 Error_Pragma
("missing Form argument for pragma%");
12588 Check_Arg_Is_Identifier
(Form
);
12590 -- Get proper alignment, note that Default = Component_Size on all
12591 -- machines we have so far, and we want to set this value rather
12592 -- than the default value to indicate that it has been explicitly
12593 -- set (and thus will not get overridden by the default component
12594 -- alignment for the current scope)
12596 if Chars
(Form
) = Name_Component_Size
then
12597 Atype
:= Calign_Component_Size
;
12599 elsif Chars
(Form
) = Name_Component_Size_4
then
12600 Atype
:= Calign_Component_Size_4
;
12602 elsif Chars
(Form
) = Name_Default
then
12603 Atype
:= Calign_Component_Size
;
12605 elsif Chars
(Form
) = Name_Storage_Unit
then
12606 Atype
:= Calign_Storage_Unit
;
12610 ("invalid Form parameter for pragma%", Form
);
12613 -- Case with no name, supplied, affects scope table entry
12617 (Scope_Stack
.Last
).Component_Alignment_Default
:= Atype
;
12619 -- Case of name supplied
12622 Check_Arg_Is_Local_Name
(Name
);
12624 Typ
:= Entity
(Name
);
12627 or else Rep_Item_Too_Early
(Typ
, N
)
12631 Typ
:= Underlying_Type
(Typ
);
12634 if not Is_Record_Type
(Typ
)
12635 and then not Is_Array_Type
(Typ
)
12638 ("Name parameter of pragma% must identify record or "
12639 & "array type", Name
);
12642 -- An explicit Component_Alignment pragma overrides an
12643 -- implicit pragma Pack, but not an explicit one.
12645 if not Has_Pragma_Pack
(Base_Type
(Typ
)) then
12646 Set_Is_Packed
(Base_Type
(Typ
), False);
12647 Set_Component_Alignment
(Base_Type
(Typ
), Atype
);
12650 end Component_AlignmentP
;
12652 --------------------------------
12653 -- Constant_After_Elaboration --
12654 --------------------------------
12656 -- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ];
12658 when Pragma_Constant_After_Elaboration
=> Constant_After_Elaboration
:
12660 Obj_Decl
: Node_Id
;
12661 Obj_Id
: Entity_Id
;
12665 Check_No_Identifiers
;
12666 Check_At_Most_N_Arguments
(1);
12668 Obj_Decl
:= Find_Related_Context
(N
, Do_Checks
=> True);
12670 -- Object declaration
12672 if Nkind
(Obj_Decl
) = N_Object_Declaration
then
12675 -- Otherwise the pragma is associated with an illegal construct
12682 Obj_Id
:= Defining_Entity
(Obj_Decl
);
12684 -- The object declaration must be a library-level variable which
12685 -- is either explicitly initialized or obtains a value during the
12686 -- elaboration of a package body (SPARK RM 3.3.1).
12688 if Ekind
(Obj_Id
) = E_Variable
then
12689 if not Is_Library_Level_Entity
(Obj_Id
) then
12691 ("pragma % must apply to a library level variable");
12695 -- Otherwise the pragma applies to a constant, which is illegal
12698 Error_Pragma
("pragma % must apply to a variable declaration");
12702 -- Chain the pragma on the contract for completeness
12704 Add_Contract_Item
(N
, Obj_Id
);
12706 -- A pragma that applies to a Ghost entity becomes Ghost for the
12707 -- purposes of legality checks and removal of ignored Ghost code.
12709 Mark_Pragma_As_Ghost
(N
, Obj_Id
);
12711 -- Analyze the Boolean expression (if any)
12713 if Present
(Arg1
) then
12714 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
12716 end Constant_After_Elaboration
;
12718 --------------------
12719 -- Contract_Cases --
12720 --------------------
12722 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
12724 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
12726 -- CASE_GUARD ::= boolean_EXPRESSION | others
12728 -- CONSEQUENCE ::= boolean_EXPRESSION
12730 -- Characteristics:
12732 -- * Analysis - The annotation undergoes initial checks to verify
12733 -- the legal placement and context. Secondary checks preanalyze the
12736 -- Analyze_Contract_Cases_In_Decl_Part
12738 -- * Expansion - The annotation is expanded during the expansion of
12739 -- the related subprogram [body] contract as performed in:
12741 -- Expand_Subprogram_Contract
12743 -- * Template - The annotation utilizes the generic template of the
12744 -- related subprogram [body] when it is:
12746 -- aspect on subprogram declaration
12747 -- aspect on stand alone subprogram body
12748 -- pragma on stand alone subprogram body
12750 -- The annotation must prepare its own template when it is:
12752 -- pragma on subprogram declaration
12754 -- * Globals - Capture of global references must occur after full
12757 -- * Instance - The annotation is instantiated automatically when
12758 -- the related generic subprogram [body] is instantiated except for
12759 -- the "pragma on subprogram declaration" case. In that scenario
12760 -- the annotation must instantiate itself.
12762 when Pragma_Contract_Cases
=> Contract_Cases
: declare
12763 Spec_Id
: Entity_Id
;
12764 Subp_Decl
: Node_Id
;
12768 Check_No_Identifiers
;
12769 Check_Arg_Count
(1);
12771 -- Ensure the proper placement of the pragma. Contract_Cases must
12772 -- be associated with a subprogram declaration or a body that acts
12776 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
12780 if Nkind
(Subp_Decl
) = N_Entry_Declaration
then
12783 -- Generic subprogram
12785 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
12788 -- Body acts as spec
12790 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
12791 and then No
(Corresponding_Spec
(Subp_Decl
))
12795 -- Body stub acts as spec
12797 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
12798 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
12804 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
12812 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
12814 -- Chain the pragma on the contract for further processing by
12815 -- Analyze_Contract_Cases_In_Decl_Part.
12817 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
12819 -- A pragma that applies to a Ghost entity becomes Ghost for the
12820 -- purposes of legality checks and removal of ignored Ghost code.
12822 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
12823 Ensure_Aggregate_Form
(Get_Argument
(N
, Spec_Id
));
12825 -- Fully analyze the pragma when it appears inside an entry
12826 -- or subprogram body because it cannot benefit from forward
12829 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
12831 N_Subprogram_Body_Stub
)
12833 -- The legality checks of pragma Contract_Cases are affected by
12834 -- the SPARK mode in effect and the volatility of the context.
12835 -- Analyze all pragmas in a specific order.
12837 Analyze_If_Present
(Pragma_SPARK_Mode
);
12838 Analyze_If_Present
(Pragma_Volatile_Function
);
12839 Analyze_Contract_Cases_In_Decl_Part
(N
);
12841 end Contract_Cases
;
12847 -- pragma Controlled (first_subtype_LOCAL_NAME);
12849 when Pragma_Controlled
=> Controlled
: declare
12853 Check_No_Identifiers
;
12854 Check_Arg_Count
(1);
12855 Check_Arg_Is_Local_Name
(Arg1
);
12856 Arg
:= Get_Pragma_Arg
(Arg1
);
12858 if not Is_Entity_Name
(Arg
)
12859 or else not Is_Access_Type
(Entity
(Arg
))
12861 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
12863 Set_Has_Pragma_Controlled
(Base_Type
(Entity
(Arg
)));
12871 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12872 -- [Entity =>] LOCAL_NAME);
12874 when Pragma_Convention
=> Convention
: declare
12877 pragma Warnings
(Off
, C
);
12878 pragma Warnings
(Off
, E
);
12880 Check_Arg_Order
((Name_Convention
, Name_Entity
));
12881 Check_Ada_83_Warning
;
12882 Check_Arg_Count
(2);
12883 Process_Convention
(C
, E
);
12885 -- A pragma that applies to a Ghost entity becomes Ghost for the
12886 -- purposes of legality checks and removal of ignored Ghost code.
12888 Mark_Pragma_As_Ghost
(N
, E
);
12891 ---------------------------
12892 -- Convention_Identifier --
12893 ---------------------------
12895 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12896 -- [Convention =>] convention_IDENTIFIER);
12898 when Pragma_Convention_Identifier
=> Convention_Identifier
: declare
12904 Check_Arg_Order
((Name_Name
, Name_Convention
));
12905 Check_Arg_Count
(2);
12906 Check_Optional_Identifier
(Arg1
, Name_Name
);
12907 Check_Optional_Identifier
(Arg2
, Name_Convention
);
12908 Check_Arg_Is_Identifier
(Arg1
);
12909 Check_Arg_Is_Identifier
(Arg2
);
12910 Idnam
:= Chars
(Get_Pragma_Arg
(Arg1
));
12911 Cname
:= Chars
(Get_Pragma_Arg
(Arg2
));
12913 if Is_Convention_Name
(Cname
) then
12914 Record_Convention_Identifier
12915 (Idnam
, Get_Convention_Id
(Cname
));
12918 ("second arg for % pragma must be convention", Arg2
);
12920 end Convention_Identifier
;
12926 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12928 when Pragma_CPP_Class
=> CPP_Class
: declare
12932 if Warn_On_Obsolescent_Feature
then
12934 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12935 & "effect; replace it by pragma import?j?", N
);
12938 Check_Arg_Count
(1);
12942 Chars
=> Name_Import
,
12943 Pragma_Argument_Associations
=> New_List
(
12944 Make_Pragma_Argument_Association
(Loc
,
12945 Expression
=> Make_Identifier
(Loc
, Name_CPP
)),
12946 New_Copy
(First
(Pragma_Argument_Associations
(N
))))));
12950 ---------------------
12951 -- CPP_Constructor --
12952 ---------------------
12954 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12955 -- [, [External_Name =>] static_string_EXPRESSION ]
12956 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12958 when Pragma_CPP_Constructor
=> CPP_Constructor
: declare
12961 Def_Id
: Entity_Id
;
12962 Tag_Typ
: Entity_Id
;
12966 Check_At_Least_N_Arguments
(1);
12967 Check_At_Most_N_Arguments
(3);
12968 Check_Optional_Identifier
(Arg1
, Name_Entity
);
12969 Check_Arg_Is_Local_Name
(Arg1
);
12971 Id
:= Get_Pragma_Arg
(Arg1
);
12972 Find_Program_Unit_Name
(Id
);
12974 -- If we did not find the name, we are done
12976 if Etype
(Id
) = Any_Type
then
12980 Def_Id
:= Entity
(Id
);
12982 -- Check if already defined as constructor
12984 if Is_Constructor
(Def_Id
) then
12986 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1
);
12990 if Ekind
(Def_Id
) = E_Function
12991 and then (Is_CPP_Class
(Etype
(Def_Id
))
12992 or else (Is_Class_Wide_Type
(Etype
(Def_Id
))
12994 Is_CPP_Class
(Root_Type
(Etype
(Def_Id
)))))
12996 if Scope
(Def_Id
) /= Scope
(Etype
(Def_Id
)) then
12998 ("'C'P'P constructor must be defined in the scope of "
12999 & "its returned type", Arg1
);
13002 if Arg_Count
>= 2 then
13003 Set_Imported
(Def_Id
);
13004 Set_Is_Public
(Def_Id
);
13005 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
13008 Set_Has_Completion
(Def_Id
);
13009 Set_Is_Constructor
(Def_Id
);
13010 Set_Convention
(Def_Id
, Convention_CPP
);
13012 -- Imported C++ constructors are not dispatching primitives
13013 -- because in C++ they don't have a dispatch table slot.
13014 -- However, in Ada the constructor has the profile of a
13015 -- function that returns a tagged type and therefore it has
13016 -- been treated as a primitive operation during semantic
13017 -- analysis. We now remove it from the list of primitive
13018 -- operations of the type.
13020 if Is_Tagged_Type
(Etype
(Def_Id
))
13021 and then not Is_Class_Wide_Type
(Etype
(Def_Id
))
13022 and then Is_Dispatching_Operation
(Def_Id
)
13024 Tag_Typ
:= Etype
(Def_Id
);
13026 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
13027 while Present
(Elmt
) and then Node
(Elmt
) /= Def_Id
loop
13031 Remove_Elmt
(Primitive_Operations
(Tag_Typ
), Elmt
);
13032 Set_Is_Dispatching_Operation
(Def_Id
, False);
13035 -- For backward compatibility, if the constructor returns a
13036 -- class wide type, and we internally change the return type to
13037 -- the corresponding root type.
13039 if Is_Class_Wide_Type
(Etype
(Def_Id
)) then
13040 Set_Etype
(Def_Id
, Root_Type
(Etype
(Def_Id
)));
13044 ("pragma% requires function returning a 'C'P'P_Class type",
13047 end CPP_Constructor
;
13053 when Pragma_CPP_Virtual
=> CPP_Virtual
: declare
13057 if Warn_On_Obsolescent_Feature
then
13059 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
13068 when Pragma_CPP_Vtable
=> CPP_Vtable
: declare
13072 if Warn_On_Obsolescent_Feature
then
13074 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
13083 -- pragma CPU (EXPRESSION);
13085 when Pragma_CPU
=> CPU
: declare
13086 P
: constant Node_Id
:= Parent
(N
);
13092 Check_No_Identifiers
;
13093 Check_Arg_Count
(1);
13097 if Nkind
(P
) = N_Subprogram_Body
then
13098 Check_In_Main_Program
;
13100 Arg
:= Get_Pragma_Arg
(Arg1
);
13101 Analyze_And_Resolve
(Arg
, Any_Integer
);
13103 Ent
:= Defining_Unit_Name
(Specification
(P
));
13105 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
13106 Ent
:= Defining_Identifier
(Ent
);
13111 if not Is_OK_Static_Expression
(Arg
) then
13112 Flag_Non_Static_Expr
13113 ("main subprogram affinity is not static!", Arg
);
13116 -- If constraint error, then we already signalled an error
13118 elsif Raises_Constraint_Error
(Arg
) then
13121 -- Otherwise check in range
13125 CPU_Id
: constant Entity_Id
:= RTE
(RE_CPU_Range
);
13126 -- This is the entity System.Multiprocessors.CPU_Range;
13128 Val
: constant Uint
:= Expr_Value
(Arg
);
13131 if Val
< Expr_Value
(Type_Low_Bound
(CPU_Id
))
13133 Val
> Expr_Value
(Type_High_Bound
(CPU_Id
))
13136 ("main subprogram CPU is out of range", Arg1
);
13142 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
13146 elsif Nkind
(P
) = N_Task_Definition
then
13147 Arg
:= Get_Pragma_Arg
(Arg1
);
13148 Ent
:= Defining_Identifier
(Parent
(P
));
13150 -- The expression must be analyzed in the special manner
13151 -- described in "Handling of Default and Per-Object
13152 -- Expressions" in sem.ads.
13154 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_CPU_Range
));
13156 -- Anything else is incorrect
13162 -- Check duplicate pragma before we chain the pragma in the Rep
13163 -- Item chain of Ent.
13165 Check_Duplicate_Pragma
(Ent
);
13166 Record_Rep_Item
(Ent
, N
);
13173 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
13175 when Pragma_Debug
=> Debug
: declare
13182 -- The condition for executing the call is that the expander
13183 -- is active and that we are not ignoring this debug pragma.
13188 (Expander_Active
and then not Is_Ignored
(N
)),
13191 if not Is_Ignored
(N
) then
13192 Set_SCO_Pragma_Enabled
(Loc
);
13195 if Arg_Count
= 2 then
13197 Make_And_Then
(Loc
,
13198 Left_Opnd
=> Relocate_Node
(Cond
),
13199 Right_Opnd
=> Get_Pragma_Arg
(Arg1
));
13200 Call
:= Get_Pragma_Arg
(Arg2
);
13202 Call
:= Get_Pragma_Arg
(Arg1
);
13206 N_Indexed_Component
,
13210 N_Selected_Component
)
13212 -- If this pragma Debug comes from source, its argument was
13213 -- parsed as a name form (which is syntactically identical).
13214 -- In a generic context a parameterless call will be left as
13215 -- an expanded name (if global) or selected_component if local.
13216 -- Change it to a procedure call statement now.
13218 Change_Name_To_Procedure_Call_Statement
(Call
);
13220 elsif Nkind
(Call
) = N_Procedure_Call_Statement
then
13222 -- Already in the form of a procedure call statement: nothing
13223 -- to do (could happen in case of an internally generated
13229 -- All other cases: diagnose error
13232 ("argument of pragma ""Debug"" is not procedure call",
13237 -- Rewrite into a conditional with an appropriate condition. We
13238 -- wrap the procedure call in a block so that overhead from e.g.
13239 -- use of the secondary stack does not generate execution overhead
13240 -- for suppressed conditions.
13242 -- Normally the analysis that follows will freeze the subprogram
13243 -- being called. However, if the call is to a null procedure,
13244 -- we want to freeze it before creating the block, because the
13245 -- analysis that follows may be done with expansion disabled, in
13246 -- which case the body will not be generated, leading to spurious
13249 if Nkind
(Call
) = N_Procedure_Call_Statement
13250 and then Is_Entity_Name
(Name
(Call
))
13252 Analyze
(Name
(Call
));
13253 Freeze_Before
(N
, Entity
(Name
(Call
)));
13257 Make_Implicit_If_Statement
(N
,
13259 Then_Statements
=> New_List
(
13260 Make_Block_Statement
(Loc
,
13261 Handled_Statement_Sequence
=>
13262 Make_Handled_Sequence_Of_Statements
(Loc
,
13263 Statements
=> New_List
(Relocate_Node
(Call
)))))));
13266 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
13267 -- after analysis of the normally rewritten node, to capture all
13268 -- references to entities, which avoids issuing wrong warnings
13269 -- about unused entities.
13271 if GNATprove_Mode
then
13272 Rewrite
(N
, Make_Null_Statement
(Loc
));
13280 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
13282 when Pragma_Debug_Policy
=>
13284 Check_Arg_Count
(1);
13285 Check_No_Identifiers
;
13286 Check_Arg_Is_Identifier
(Arg1
);
13288 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
13289 -- rewrite it that way, and let the rest of the checking come
13290 -- from analyzing the rewritten pragma.
13294 Chars
=> Name_Check_Policy
,
13295 Pragma_Argument_Associations
=> New_List
(
13296 Make_Pragma_Argument_Association
(Loc
,
13297 Expression
=> Make_Identifier
(Loc
, Name_Debug
)),
13299 Make_Pragma_Argument_Association
(Loc
,
13300 Expression
=> Get_Pragma_Arg
(Arg1
)))));
13303 -------------------------------
13304 -- Default_Initial_Condition --
13305 -------------------------------
13307 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
13309 when Pragma_Default_Initial_Condition
=> Default_Init_Cond
: declare
13316 Check_No_Identifiers
;
13317 Check_At_Most_N_Arguments
(1);
13320 while Present
(Stmt
) loop
13322 -- Skip prior pragmas, but check for duplicates
13324 if Nkind
(Stmt
) = N_Pragma
then
13325 if Pragma_Name
(Stmt
) = Pname
then
13326 Error_Msg_Name_1
:= Pname
;
13327 Error_Msg_Sloc
:= Sloc
(Stmt
);
13328 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
13331 -- Skip internally generated code
13333 elsif not Comes_From_Source
(Stmt
) then
13336 -- The associated private type [extension] has been found, stop
13339 elsif Nkind_In
(Stmt
, N_Private_Extension_Declaration
,
13340 N_Private_Type_Declaration
)
13342 Typ
:= Defining_Entity
(Stmt
);
13345 -- The pragma does not apply to a legal construct, issue an
13346 -- error and stop the analysis.
13353 Stmt
:= Prev
(Stmt
);
13356 -- A pragma that applies to a Ghost entity becomes Ghost for the
13357 -- purposes of legality checks and removal of ignored Ghost code.
13359 Mark_Pragma_As_Ghost
(N
, Typ
);
13360 Set_Has_Default_Init_Cond
(Typ
);
13361 Set_Has_Inherited_Default_Init_Cond
(Typ
, False);
13363 -- Chain the pragma on the rep item chain for further processing
13365 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
13366 end Default_Init_Cond
;
13368 ----------------------------------
13369 -- Default_Scalar_Storage_Order --
13370 ----------------------------------
13372 -- pragma Default_Scalar_Storage_Order
13373 -- (High_Order_First | Low_Order_First);
13375 when Pragma_Default_Scalar_Storage_Order
=> DSSO
: declare
13376 Default
: Character;
13380 Check_Arg_Count
(1);
13382 -- Default_Scalar_Storage_Order can appear as a configuration
13383 -- pragma, or in a declarative part of a package spec.
13385 if not Is_Configuration_Pragma
then
13386 Check_Is_In_Decl_Part_Or_Package_Spec
;
13389 Check_No_Identifiers
;
13390 Check_Arg_Is_One_Of
13391 (Arg1
, Name_High_Order_First
, Name_Low_Order_First
);
13392 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
13393 Default
:= Fold_Upper
(Name_Buffer
(1));
13395 if not Support_Nondefault_SSO_On_Target
13396 and then (Ttypes
.Bytes_Big_Endian
/= (Default
= 'H'))
13398 if Warn_On_Unrecognized_Pragma
then
13400 ("non-default Scalar_Storage_Order not supported "
13401 & "on target?g?", N
);
13403 ("\pragma Default_Scalar_Storage_Order ignored?g?", N
);
13406 -- Here set the specified default
13409 Opt
.Default_SSO
:= Default
;
13413 --------------------------
13414 -- Default_Storage_Pool --
13415 --------------------------
13417 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
13419 when Pragma_Default_Storage_Pool
=> Default_Storage_Pool
: declare
13424 Check_Arg_Count
(1);
13426 -- Default_Storage_Pool can appear as a configuration pragma, or
13427 -- in a declarative part of a package spec.
13429 if not Is_Configuration_Pragma
then
13430 Check_Is_In_Decl_Part_Or_Package_Spec
;
13433 if Present
(Arg1
) then
13434 Pool
:= Get_Pragma_Arg
(Arg1
);
13436 -- Case of Default_Storage_Pool (null);
13438 if Nkind
(Pool
) = N_Null
then
13441 -- This is an odd case, this is not really an expression,
13442 -- so we don't have a type for it. So just set the type to
13445 Set_Etype
(Pool
, Empty
);
13447 -- Case of Default_Storage_Pool (storage_pool_NAME);
13450 -- If it's a configuration pragma, then the only allowed
13451 -- argument is "null".
13453 if Is_Configuration_Pragma
then
13454 Error_Pragma_Arg
("NULL expected", Arg1
);
13457 -- The expected type for a non-"null" argument is
13458 -- Root_Storage_Pool'Class, and the pool must be a variable.
13460 Analyze_And_Resolve
13461 (Pool
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
13463 if Is_Variable
(Pool
) then
13465 -- A pragma that applies to a Ghost entity becomes Ghost
13466 -- for the purposes of legality checks and removal of
13467 -- ignored Ghost code.
13469 Mark_Pragma_As_Ghost
(N
, Entity
(Pool
));
13473 ("default storage pool must be a variable", Arg1
);
13477 -- Record the pool name (or null). Freeze.Freeze_Entity for an
13478 -- access type will use this information to set the appropriate
13479 -- attributes of the access type.
13481 Default_Pool
:= Pool
;
13483 end Default_Storage_Pool
;
13489 -- pragma Depends (DEPENDENCY_RELATION);
13491 -- DEPENDENCY_RELATION ::=
13493 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
13495 -- DEPENDENCY_CLAUSE ::=
13496 -- OUTPUT_LIST =>[+] INPUT_LIST
13497 -- | NULL_DEPENDENCY_CLAUSE
13499 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
13501 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
13503 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
13505 -- OUTPUT ::= NAME | FUNCTION_RESULT
13508 -- where FUNCTION_RESULT is a function Result attribute_reference
13510 -- Characteristics:
13512 -- * Analysis - The annotation undergoes initial checks to verify
13513 -- the legal placement and context. Secondary checks fully analyze
13514 -- the dependency clauses in:
13516 -- Analyze_Depends_In_Decl_Part
13518 -- * Expansion - None.
13520 -- * Template - The annotation utilizes the generic template of the
13521 -- related subprogram [body] when it is:
13523 -- aspect on subprogram declaration
13524 -- aspect on stand alone subprogram body
13525 -- pragma on stand alone subprogram body
13527 -- The annotation must prepare its own template when it is:
13529 -- pragma on subprogram declaration
13531 -- * Globals - Capture of global references must occur after full
13534 -- * Instance - The annotation is instantiated automatically when
13535 -- the related generic subprogram [body] is instantiated except for
13536 -- the "pragma on subprogram declaration" case. In that scenario
13537 -- the annotation must instantiate itself.
13539 when Pragma_Depends
=> Depends
: declare
13541 Spec_Id
: Entity_Id
;
13542 Subp_Decl
: Node_Id
;
13545 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
13549 -- Chain the pragma on the contract for further processing by
13550 -- Analyze_Depends_In_Decl_Part.
13552 Add_Contract_Item
(N
, Spec_Id
);
13554 -- Fully analyze the pragma when it appears inside an entry
13555 -- or subprogram body because it cannot benefit from forward
13558 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
13560 N_Subprogram_Body_Stub
)
13562 -- The legality checks of pragmas Depends and Global are
13563 -- affected by the SPARK mode in effect and the volatility
13564 -- of the context. In addition these two pragmas are subject
13565 -- to an inherent order:
13570 -- Analyze all these pragmas in the order outlined above
13572 Analyze_If_Present
(Pragma_SPARK_Mode
);
13573 Analyze_If_Present
(Pragma_Volatile_Function
);
13574 Analyze_If_Present
(Pragma_Global
);
13575 Analyze_Depends_In_Decl_Part
(N
);
13580 ---------------------
13581 -- Detect_Blocking --
13582 ---------------------
13584 -- pragma Detect_Blocking;
13586 when Pragma_Detect_Blocking
=>
13588 Check_Arg_Count
(0);
13589 Check_Valid_Configuration_Pragma
;
13590 Detect_Blocking
:= True;
13592 ------------------------------------
13593 -- Disable_Atomic_Synchronization --
13594 ------------------------------------
13596 -- pragma Disable_Atomic_Synchronization [(Entity)];
13598 when Pragma_Disable_Atomic_Synchronization
=>
13600 Process_Disable_Enable_Atomic_Sync
(Name_Suppress
);
13602 -------------------
13603 -- Discard_Names --
13604 -------------------
13606 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
13608 when Pragma_Discard_Names
=> Discard_Names
: declare
13613 Check_Ada_83_Warning
;
13615 -- Deal with configuration pragma case
13617 if Arg_Count
= 0 and then Is_Configuration_Pragma
then
13618 Global_Discard_Names
:= True;
13621 -- Otherwise, check correct appropriate context
13624 Check_Is_In_Decl_Part_Or_Package_Spec
;
13626 if Arg_Count
= 0 then
13628 -- If there is no parameter, then from now on this pragma
13629 -- applies to any enumeration, exception or tagged type
13630 -- defined in the current declarative part, and recursively
13631 -- to any nested scope.
13633 Set_Discard_Names
(Current_Scope
);
13637 Check_Arg_Count
(1);
13638 Check_Optional_Identifier
(Arg1
, Name_On
);
13639 Check_Arg_Is_Local_Name
(Arg1
);
13641 E_Id
:= Get_Pragma_Arg
(Arg1
);
13643 if Etype
(E_Id
) = Any_Type
then
13646 E
:= Entity
(E_Id
);
13649 -- A pragma that applies to a Ghost entity becomes Ghost for
13650 -- the purposes of legality checks and removal of ignored
13653 Mark_Pragma_As_Ghost
(N
, E
);
13655 if (Is_First_Subtype
(E
)
13657 (Is_Enumeration_Type
(E
) or else Is_Tagged_Type
(E
)))
13658 or else Ekind
(E
) = E_Exception
13660 Set_Discard_Names
(E
);
13661 Record_Rep_Item
(E
, N
);
13665 ("inappropriate entity for pragma%", Arg1
);
13671 ------------------------
13672 -- Dispatching_Domain --
13673 ------------------------
13675 -- pragma Dispatching_Domain (EXPRESSION);
13677 when Pragma_Dispatching_Domain
=> Dispatching_Domain
: declare
13678 P
: constant Node_Id
:= Parent
(N
);
13684 Check_No_Identifiers
;
13685 Check_Arg_Count
(1);
13687 -- This pragma is born obsolete, but not the aspect
13689 if not From_Aspect_Specification
(N
) then
13691 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
13694 if Nkind
(P
) = N_Task_Definition
then
13695 Arg
:= Get_Pragma_Arg
(Arg1
);
13696 Ent
:= Defining_Identifier
(Parent
(P
));
13698 -- A pragma that applies to a Ghost entity becomes Ghost for
13699 -- the purposes of legality checks and removal of ignored Ghost
13702 Mark_Pragma_As_Ghost
(N
, Ent
);
13704 -- The expression must be analyzed in the special manner
13705 -- described in "Handling of Default and Per-Object
13706 -- Expressions" in sem.ads.
13708 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Dispatching_Domain
));
13710 -- Check duplicate pragma before we chain the pragma in the Rep
13711 -- Item chain of Ent.
13713 Check_Duplicate_Pragma
(Ent
);
13714 Record_Rep_Item
(Ent
, N
);
13716 -- Anything else is incorrect
13721 end Dispatching_Domain
;
13727 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
13729 when Pragma_Elaborate
=> Elaborate
: declare
13734 -- Pragma must be in context items list of a compilation unit
13736 if not Is_In_Context_Clause
then
13740 -- Must be at least one argument
13742 if Arg_Count
= 0 then
13743 Error_Pragma
("pragma% requires at least one argument");
13746 -- In Ada 83 mode, there can be no items following it in the
13747 -- context list except other pragmas and implicit with clauses
13748 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
13749 -- placement rule does not apply.
13751 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
13753 while Present
(Citem
) loop
13754 if Nkind
(Citem
) = N_Pragma
13755 or else (Nkind
(Citem
) = N_With_Clause
13756 and then Implicit_With
(Citem
))
13761 ("(Ada 83) pragma% must be at end of context clause");
13768 -- Finally, the arguments must all be units mentioned in a with
13769 -- clause in the same context clause. Note we already checked (in
13770 -- Par.Prag) that the arguments are all identifiers or selected
13774 Outer
: while Present
(Arg
) loop
13775 Citem
:= First
(List_Containing
(N
));
13776 Inner
: while Citem
/= N
loop
13777 if Nkind
(Citem
) = N_With_Clause
13778 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
13780 Set_Elaborate_Present
(Citem
, True);
13781 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
13783 -- With the pragma present, elaboration calls on
13784 -- subprograms from the named unit need no further
13785 -- checks, as long as the pragma appears in the current
13786 -- compilation unit. If the pragma appears in some unit
13787 -- in the context, there might still be a need for an
13788 -- Elaborate_All_Desirable from the current compilation
13789 -- to the named unit, so we keep the check enabled.
13791 if In_Extended_Main_Source_Unit
(N
) then
13793 -- This does not apply in SPARK mode, where we allow
13794 -- pragma Elaborate, but we don't trust it to be right
13795 -- so we will still insist on the Elaborate_All.
13797 if SPARK_Mode
/= On
then
13798 Set_Suppress_Elaboration_Warnings
13799 (Entity
(Name
(Citem
)));
13811 ("argument of pragma% is not withed unit", Arg
);
13817 -- Give a warning if operating in static mode with one of the
13818 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
13821 and not Dynamic_Elaboration_Checks
13823 -- pragma Elaborate not allowed in SPARK mode anyway. We
13824 -- already complained about it, no point in generating any
13825 -- further complaint.
13827 and SPARK_Mode
/= On
13830 ("?l?use of pragma Elaborate may not be safe", N
);
13832 ("?l?use pragma Elaborate_All instead if possible", N
);
13836 -------------------
13837 -- Elaborate_All --
13838 -------------------
13840 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
13842 when Pragma_Elaborate_All
=> Elaborate_All
: declare
13847 Check_Ada_83_Warning
;
13849 -- Pragma must be in context items list of a compilation unit
13851 if not Is_In_Context_Clause
then
13855 -- Must be at least one argument
13857 if Arg_Count
= 0 then
13858 Error_Pragma
("pragma% requires at least one argument");
13861 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
13862 -- have to appear at the end of the context clause, but may
13863 -- appear mixed in with other items, even in Ada 83 mode.
13865 -- Final check: the arguments must all be units mentioned in
13866 -- a with clause in the same context clause. Note that we
13867 -- already checked (in Par.Prag) that all the arguments are
13868 -- either identifiers or selected components.
13871 Outr
: while Present
(Arg
) loop
13872 Citem
:= First
(List_Containing
(N
));
13873 Innr
: while Citem
/= N
loop
13874 if Nkind
(Citem
) = N_With_Clause
13875 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
13877 Set_Elaborate_All_Present
(Citem
, True);
13878 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
13880 -- Suppress warnings and elaboration checks on the named
13881 -- unit if the pragma is in the current compilation, as
13882 -- for pragma Elaborate.
13884 if In_Extended_Main_Source_Unit
(N
) then
13885 Set_Suppress_Elaboration_Warnings
13886 (Entity
(Name
(Citem
)));
13895 Set_Error_Posted
(N
);
13897 ("argument of pragma% is not withed unit", Arg
);
13904 --------------------
13905 -- Elaborate_Body --
13906 --------------------
13908 -- pragma Elaborate_Body [( library_unit_NAME )];
13910 when Pragma_Elaborate_Body
=> Elaborate_Body
: declare
13911 Cunit_Node
: Node_Id
;
13912 Cunit_Ent
: Entity_Id
;
13915 Check_Ada_83_Warning
;
13916 Check_Valid_Library_Unit_Pragma
;
13918 if Nkind
(N
) = N_Null_Statement
then
13922 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
13923 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
13925 -- A pragma that applies to a Ghost entity becomes Ghost for the
13926 -- purposes of legality checks and removal of ignored Ghost code.
13928 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
13930 if Nkind_In
(Unit
(Cunit_Node
), N_Package_Body
,
13933 Error_Pragma
("pragma% must refer to a spec, not a body");
13935 Set_Body_Required
(Cunit_Node
, True);
13936 Set_Has_Pragma_Elaborate_Body
(Cunit_Ent
);
13938 -- If we are in dynamic elaboration mode, then we suppress
13939 -- elaboration warnings for the unit, since it is definitely
13940 -- fine NOT to do dynamic checks at the first level (and such
13941 -- checks will be suppressed because no elaboration boolean
13942 -- is created for Elaborate_Body packages).
13944 -- But in the static model of elaboration, Elaborate_Body is
13945 -- definitely NOT good enough to ensure elaboration safety on
13946 -- its own, since the body may WITH other units that are not
13947 -- safe from an elaboration point of view, so a client must
13948 -- still do an Elaborate_All on such units.
13950 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13951 -- Elaborate_Body always suppressed elab warnings.
13953 if Dynamic_Elaboration_Checks
or Debug_Flag_DD
then
13954 Set_Suppress_Elaboration_Warnings
(Cunit_Ent
);
13957 end Elaborate_Body
;
13959 ------------------------
13960 -- Elaboration_Checks --
13961 ------------------------
13963 -- pragma Elaboration_Checks (Static | Dynamic);
13965 when Pragma_Elaboration_Checks
=>
13967 Check_Arg_Count
(1);
13968 Check_Arg_Is_One_Of
(Arg1
, Name_Static
, Name_Dynamic
);
13970 -- Set flag accordingly (ignore attempt at dynamic elaboration
13971 -- checks in SPARK mode).
13973 Dynamic_Elaboration_Checks
:=
13974 (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Dynamic
)
13975 and then SPARK_Mode
/= On
;
13981 -- pragma Eliminate (
13982 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13983 -- [,[Entity =>] IDENTIFIER |
13984 -- SELECTED_COMPONENT |
13986 -- [, OVERLOADING_RESOLUTION]);
13988 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13991 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13992 -- FUNCTION_PROFILE
13994 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13996 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13997 -- Result_Type => result_SUBTYPE_NAME]
13999 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
14000 -- SUBTYPE_NAME ::= STRING_LITERAL
14002 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
14003 -- SOURCE_TRACE ::= STRING_LITERAL
14005 when Pragma_Eliminate
=> Eliminate
: declare
14006 Args
: Args_List
(1 .. 5);
14007 Names
: constant Name_List
(1 .. 5) := (
14010 Name_Parameter_Types
,
14012 Name_Source_Location
);
14014 Unit_Name
: Node_Id
renames Args
(1);
14015 Entity
: Node_Id
renames Args
(2);
14016 Parameter_Types
: Node_Id
renames Args
(3);
14017 Result_Type
: Node_Id
renames Args
(4);
14018 Source_Location
: Node_Id
renames Args
(5);
14022 Check_Valid_Configuration_Pragma
;
14023 Gather_Associations
(Names
, Args
);
14025 if No
(Unit_Name
) then
14026 Error_Pragma
("missing Unit_Name argument for pragma%");
14030 and then (Present
(Parameter_Types
)
14032 Present
(Result_Type
)
14034 Present
(Source_Location
))
14036 Error_Pragma
("missing Entity argument for pragma%");
14039 if (Present
(Parameter_Types
)
14041 Present
(Result_Type
))
14043 Present
(Source_Location
)
14046 ("parameter profile and source location cannot be used "
14047 & "together in pragma%");
14050 Process_Eliminate_Pragma
14059 -----------------------------------
14060 -- Enable_Atomic_Synchronization --
14061 -----------------------------------
14063 -- pragma Enable_Atomic_Synchronization [(Entity)];
14065 when Pragma_Enable_Atomic_Synchronization
=>
14067 Process_Disable_Enable_Atomic_Sync
(Name_Unsuppress
);
14074 -- [ Convention =>] convention_IDENTIFIER,
14075 -- [ Entity =>] LOCAL_NAME
14076 -- [, [External_Name =>] static_string_EXPRESSION ]
14077 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14079 when Pragma_Export
=> Export
: declare
14081 Def_Id
: Entity_Id
;
14083 pragma Warnings
(Off
, C
);
14086 Check_Ada_83_Warning
;
14090 Name_External_Name
,
14093 Check_At_Least_N_Arguments
(2);
14094 Check_At_Most_N_Arguments
(4);
14096 -- In Relaxed_RM_Semantics, support old Ada 83 style:
14097 -- pragma Export (Entity, "external name");
14099 if Relaxed_RM_Semantics
14100 and then Arg_Count
= 2
14101 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
14104 Def_Id
:= Get_Pragma_Arg
(Arg1
);
14107 if not Is_Entity_Name
(Def_Id
) then
14108 Error_Pragma_Arg
("entity name required", Arg1
);
14111 Def_Id
:= Entity
(Def_Id
);
14112 Set_Exported
(Def_Id
, Arg1
);
14115 Process_Convention
(C
, Def_Id
);
14117 -- A pragma that applies to a Ghost entity becomes Ghost for
14118 -- the purposes of legality checks and removal of ignored Ghost
14121 Mark_Pragma_As_Ghost
(N
, Def_Id
);
14123 if Ekind
(Def_Id
) /= E_Constant
then
14124 Note_Possible_Modification
14125 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
14128 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
14129 Set_Exported
(Def_Id
, Arg2
);
14132 -- If the entity is a deferred constant, propagate the information
14133 -- to the full view, because gigi elaborates the full view only.
14135 if Ekind
(Def_Id
) = E_Constant
14136 and then Present
(Full_View
(Def_Id
))
14139 Id2
: constant Entity_Id
:= Full_View
(Def_Id
);
14141 Set_Is_Exported
(Id2
, Is_Exported
(Def_Id
));
14142 Set_First_Rep_Item
(Id2
, First_Rep_Item
(Def_Id
));
14143 Set_Interface_Name
(Id2
, Einfo
.Interface_Name
(Def_Id
));
14148 ---------------------
14149 -- Export_Function --
14150 ---------------------
14152 -- pragma Export_Function (
14153 -- [Internal =>] LOCAL_NAME
14154 -- [, [External =>] EXTERNAL_SYMBOL]
14155 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14156 -- [, [Result_Type =>] TYPE_DESIGNATOR]
14157 -- [, [Mechanism =>] MECHANISM]
14158 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14160 -- EXTERNAL_SYMBOL ::=
14162 -- | static_string_EXPRESSION
14164 -- PARAMETER_TYPES ::=
14166 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14168 -- TYPE_DESIGNATOR ::=
14170 -- | subtype_Name ' Access
14174 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14176 -- MECHANISM_ASSOCIATION ::=
14177 -- [formal_parameter_NAME =>] MECHANISM_NAME
14179 -- MECHANISM_NAME ::=
14183 when Pragma_Export_Function
=> Export_Function
: declare
14184 Args
: Args_List
(1 .. 6);
14185 Names
: constant Name_List
(1 .. 6) := (
14188 Name_Parameter_Types
,
14191 Name_Result_Mechanism
);
14193 Internal
: Node_Id
renames Args
(1);
14194 External
: Node_Id
renames Args
(2);
14195 Parameter_Types
: Node_Id
renames Args
(3);
14196 Result_Type
: Node_Id
renames Args
(4);
14197 Mechanism
: Node_Id
renames Args
(5);
14198 Result_Mechanism
: Node_Id
renames Args
(6);
14202 Gather_Associations
(Names
, Args
);
14203 Process_Extended_Import_Export_Subprogram_Pragma
(
14204 Arg_Internal
=> Internal
,
14205 Arg_External
=> External
,
14206 Arg_Parameter_Types
=> Parameter_Types
,
14207 Arg_Result_Type
=> Result_Type
,
14208 Arg_Mechanism
=> Mechanism
,
14209 Arg_Result_Mechanism
=> Result_Mechanism
);
14210 end Export_Function
;
14212 -------------------
14213 -- Export_Object --
14214 -------------------
14216 -- pragma Export_Object (
14217 -- [Internal =>] LOCAL_NAME
14218 -- [, [External =>] EXTERNAL_SYMBOL]
14219 -- [, [Size =>] EXTERNAL_SYMBOL]);
14221 -- EXTERNAL_SYMBOL ::=
14223 -- | static_string_EXPRESSION
14225 -- PARAMETER_TYPES ::=
14227 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14229 -- TYPE_DESIGNATOR ::=
14231 -- | subtype_Name ' Access
14235 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14237 -- MECHANISM_ASSOCIATION ::=
14238 -- [formal_parameter_NAME =>] MECHANISM_NAME
14240 -- MECHANISM_NAME ::=
14244 when Pragma_Export_Object
=> Export_Object
: declare
14245 Args
: Args_List
(1 .. 3);
14246 Names
: constant Name_List
(1 .. 3) := (
14251 Internal
: Node_Id
renames Args
(1);
14252 External
: Node_Id
renames Args
(2);
14253 Size
: Node_Id
renames Args
(3);
14257 Gather_Associations
(Names
, Args
);
14258 Process_Extended_Import_Export_Object_Pragma
(
14259 Arg_Internal
=> Internal
,
14260 Arg_External
=> External
,
14264 ----------------------
14265 -- Export_Procedure --
14266 ----------------------
14268 -- pragma Export_Procedure (
14269 -- [Internal =>] LOCAL_NAME
14270 -- [, [External =>] EXTERNAL_SYMBOL]
14271 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14272 -- [, [Mechanism =>] MECHANISM]);
14274 -- EXTERNAL_SYMBOL ::=
14276 -- | static_string_EXPRESSION
14278 -- PARAMETER_TYPES ::=
14280 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14282 -- TYPE_DESIGNATOR ::=
14284 -- | subtype_Name ' Access
14288 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14290 -- MECHANISM_ASSOCIATION ::=
14291 -- [formal_parameter_NAME =>] MECHANISM_NAME
14293 -- MECHANISM_NAME ::=
14297 when Pragma_Export_Procedure
=> Export_Procedure
: declare
14298 Args
: Args_List
(1 .. 4);
14299 Names
: constant Name_List
(1 .. 4) := (
14302 Name_Parameter_Types
,
14305 Internal
: Node_Id
renames Args
(1);
14306 External
: Node_Id
renames Args
(2);
14307 Parameter_Types
: Node_Id
renames Args
(3);
14308 Mechanism
: Node_Id
renames Args
(4);
14312 Gather_Associations
(Names
, Args
);
14313 Process_Extended_Import_Export_Subprogram_Pragma
(
14314 Arg_Internal
=> Internal
,
14315 Arg_External
=> External
,
14316 Arg_Parameter_Types
=> Parameter_Types
,
14317 Arg_Mechanism
=> Mechanism
);
14318 end Export_Procedure
;
14324 -- pragma Export_Value (
14325 -- [Value =>] static_integer_EXPRESSION,
14326 -- [Link_Name =>] static_string_EXPRESSION);
14328 when Pragma_Export_Value
=>
14330 Check_Arg_Order
((Name_Value
, Name_Link_Name
));
14331 Check_Arg_Count
(2);
14333 Check_Optional_Identifier
(Arg1
, Name_Value
);
14334 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
14336 Check_Optional_Identifier
(Arg2
, Name_Link_Name
);
14337 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
14339 -----------------------------
14340 -- Export_Valued_Procedure --
14341 -----------------------------
14343 -- pragma Export_Valued_Procedure (
14344 -- [Internal =>] LOCAL_NAME
14345 -- [, [External =>] EXTERNAL_SYMBOL,]
14346 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14347 -- [, [Mechanism =>] MECHANISM]);
14349 -- EXTERNAL_SYMBOL ::=
14351 -- | static_string_EXPRESSION
14353 -- PARAMETER_TYPES ::=
14355 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14357 -- TYPE_DESIGNATOR ::=
14359 -- | subtype_Name ' Access
14363 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14365 -- MECHANISM_ASSOCIATION ::=
14366 -- [formal_parameter_NAME =>] MECHANISM_NAME
14368 -- MECHANISM_NAME ::=
14372 when Pragma_Export_Valued_Procedure
=>
14373 Export_Valued_Procedure
: declare
14374 Args
: Args_List
(1 .. 4);
14375 Names
: constant Name_List
(1 .. 4) := (
14378 Name_Parameter_Types
,
14381 Internal
: Node_Id
renames Args
(1);
14382 External
: Node_Id
renames Args
(2);
14383 Parameter_Types
: Node_Id
renames Args
(3);
14384 Mechanism
: Node_Id
renames Args
(4);
14388 Gather_Associations
(Names
, Args
);
14389 Process_Extended_Import_Export_Subprogram_Pragma
(
14390 Arg_Internal
=> Internal
,
14391 Arg_External
=> External
,
14392 Arg_Parameter_Types
=> Parameter_Types
,
14393 Arg_Mechanism
=> Mechanism
);
14394 end Export_Valued_Procedure
;
14396 -------------------
14397 -- Extend_System --
14398 -------------------
14400 -- pragma Extend_System ([Name =>] Identifier);
14402 when Pragma_Extend_System
=> Extend_System
: declare
14405 Check_Valid_Configuration_Pragma
;
14406 Check_Arg_Count
(1);
14407 Check_Optional_Identifier
(Arg1
, Name_Name
);
14408 Check_Arg_Is_Identifier
(Arg1
);
14410 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
14413 and then Name_Buffer
(1 .. 4) = "aux_"
14415 if Present
(System_Extend_Pragma_Arg
) then
14416 if Chars
(Get_Pragma_Arg
(Arg1
)) =
14417 Chars
(Expression
(System_Extend_Pragma_Arg
))
14421 Error_Msg_Sloc
:= Sloc
(System_Extend_Pragma_Arg
);
14422 Error_Pragma
("pragma% conflicts with that #");
14426 System_Extend_Pragma_Arg
:= Arg1
;
14428 if not GNAT_Mode
then
14429 System_Extend_Unit
:= Arg1
;
14433 Error_Pragma
("incorrect name for pragma%, must be Aux_xxx");
14437 ------------------------
14438 -- Extensions_Allowed --
14439 ------------------------
14441 -- pragma Extensions_Allowed (ON | OFF);
14443 when Pragma_Extensions_Allowed
=>
14445 Check_Arg_Count
(1);
14446 Check_No_Identifiers
;
14447 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
14449 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
14450 Extensions_Allowed
:= True;
14451 Ada_Version
:= Ada_Version_Type
'Last;
14454 Extensions_Allowed
:= False;
14455 Ada_Version
:= Ada_Version_Explicit
;
14456 Ada_Version_Pragma
:= Empty
;
14459 ------------------------
14460 -- Extensions_Visible --
14461 ------------------------
14463 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
14465 -- Characteristics:
14467 -- * Analysis - The annotation is fully analyzed immediately upon
14468 -- elaboration as its expression must be static.
14470 -- * Expansion - None.
14472 -- * Template - The annotation utilizes the generic template of the
14473 -- related subprogram [body] when it is:
14475 -- aspect on subprogram declaration
14476 -- aspect on stand alone subprogram body
14477 -- pragma on stand alone subprogram body
14479 -- The annotation must prepare its own template when it is:
14481 -- pragma on subprogram declaration
14483 -- * Globals - Capture of global references must occur after full
14486 -- * Instance - The annotation is instantiated automatically when
14487 -- the related generic subprogram [body] is instantiated except for
14488 -- the "pragma on subprogram declaration" case. In that scenario
14489 -- the annotation must instantiate itself.
14491 when Pragma_Extensions_Visible
=> Extensions_Visible
: declare
14492 Formal
: Entity_Id
;
14493 Has_OK_Formal
: Boolean := False;
14494 Spec_Id
: Entity_Id
;
14495 Subp_Decl
: Node_Id
;
14499 Check_No_Identifiers
;
14500 Check_At_Most_N_Arguments
(1);
14503 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
14505 -- Abstract subprogram declaration
14507 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
14510 -- Generic subprogram declaration
14512 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
14515 -- Body acts as spec
14517 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
14518 and then No
(Corresponding_Spec
(Subp_Decl
))
14522 -- Body stub acts as spec
14524 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
14525 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
14529 -- Subprogram declaration
14531 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
14534 -- Otherwise the pragma is associated with an illegal construct
14537 Error_Pragma
("pragma % must apply to a subprogram");
14541 -- Chain the pragma on the contract for completeness
14543 Add_Contract_Item
(N
, Defining_Entity
(Subp_Decl
));
14545 -- The legality checks of pragma Extension_Visible are affected
14546 -- by the SPARK mode in effect. Analyze all pragmas in specific
14549 Analyze_If_Present
(Pragma_SPARK_Mode
);
14551 -- Mark the pragma as Ghost if the related subprogram is also
14552 -- Ghost. This also ensures that any expansion performed further
14553 -- below will produce Ghost nodes.
14555 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
14556 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
14558 -- Examine the formals of the related subprogram
14560 Formal
:= First_Formal
(Spec_Id
);
14561 while Present
(Formal
) loop
14563 -- At least one of the formals is of a specific tagged type,
14564 -- the pragma is legal.
14566 if Is_Specific_Tagged_Type
(Etype
(Formal
)) then
14567 Has_OK_Formal
:= True;
14570 -- A generic subprogram with at least one formal of a private
14571 -- type ensures the legality of the pragma because the actual
14572 -- may be specifically tagged. Note that this is verified by
14573 -- the check above at instantiation time.
14575 elsif Is_Private_Type
(Etype
(Formal
))
14576 and then Is_Generic_Type
(Etype
(Formal
))
14578 Has_OK_Formal
:= True;
14582 Next_Formal
(Formal
);
14585 if not Has_OK_Formal
then
14586 Error_Msg_Name_1
:= Pname
;
14587 Error_Msg_N
(Fix_Error
("incorrect placement of pragma %"), N
);
14589 ("\subprogram & lacks parameter of specific tagged or "
14590 & "generic private type", N
, Spec_Id
);
14595 -- Analyze the Boolean expression (if any)
14597 if Present
(Arg1
) then
14598 Check_Static_Boolean_Expression
14599 (Expression
(Get_Argument
(N
, Spec_Id
)));
14601 end Extensions_Visible
;
14607 -- pragma External (
14608 -- [ Convention =>] convention_IDENTIFIER,
14609 -- [ Entity =>] LOCAL_NAME
14610 -- [, [External_Name =>] static_string_EXPRESSION ]
14611 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14613 when Pragma_External
=> External
: declare
14616 pragma Warnings
(Off
, C
);
14623 Name_External_Name
,
14625 Check_At_Least_N_Arguments
(2);
14626 Check_At_Most_N_Arguments
(4);
14627 Process_Convention
(C
, E
);
14629 -- A pragma that applies to a Ghost entity becomes Ghost for the
14630 -- purposes of legality checks and removal of ignored Ghost code.
14632 Mark_Pragma_As_Ghost
(N
, E
);
14634 Note_Possible_Modification
14635 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
14636 Process_Interface_Name
(E
, Arg3
, Arg4
);
14637 Set_Exported
(E
, Arg2
);
14640 --------------------------
14641 -- External_Name_Casing --
14642 --------------------------
14644 -- pragma External_Name_Casing (
14645 -- UPPERCASE | LOWERCASE
14646 -- [, AS_IS | UPPERCASE | LOWERCASE]);
14648 when Pragma_External_Name_Casing
=> External_Name_Casing
: declare
14651 Check_No_Identifiers
;
14653 if Arg_Count
= 2 then
14654 Check_Arg_Is_One_Of
14655 (Arg2
, Name_As_Is
, Name_Uppercase
, Name_Lowercase
);
14657 case Chars
(Get_Pragma_Arg
(Arg2
)) is
14659 Opt
.External_Name_Exp_Casing
:= As_Is
;
14661 when Name_Uppercase
=>
14662 Opt
.External_Name_Exp_Casing
:= Uppercase
;
14664 when Name_Lowercase
=>
14665 Opt
.External_Name_Exp_Casing
:= Lowercase
;
14672 Check_Arg_Count
(1);
14675 Check_Arg_Is_One_Of
(Arg1
, Name_Uppercase
, Name_Lowercase
);
14677 case Chars
(Get_Pragma_Arg
(Arg1
)) is
14678 when Name_Uppercase
=>
14679 Opt
.External_Name_Imp_Casing
:= Uppercase
;
14681 when Name_Lowercase
=>
14682 Opt
.External_Name_Imp_Casing
:= Lowercase
;
14687 end External_Name_Casing
;
14693 -- pragma Fast_Math;
14695 when Pragma_Fast_Math
=>
14697 Check_No_Identifiers
;
14698 Check_Valid_Configuration_Pragma
;
14701 --------------------------
14702 -- Favor_Top_Level --
14703 --------------------------
14705 -- pragma Favor_Top_Level (type_NAME);
14707 when Pragma_Favor_Top_Level
=> Favor_Top_Level
: declare
14712 Check_No_Identifiers
;
14713 Check_Arg_Count
(1);
14714 Check_Arg_Is_Local_Name
(Arg1
);
14715 Typ
:= Entity
(Get_Pragma_Arg
(Arg1
));
14717 -- A pragma that applies to a Ghost entity becomes Ghost for the
14718 -- purposes of legality checks and removal of ignored Ghost code.
14720 Mark_Pragma_As_Ghost
(N
, Typ
);
14722 -- If it's an access-to-subprogram type (in particular, not a
14723 -- subtype), set the flag on that type.
14725 if Is_Access_Subprogram_Type
(Typ
) then
14726 Set_Can_Use_Internal_Rep
(Typ
, False);
14728 -- Otherwise it's an error (name denotes the wrong sort of entity)
14732 ("access-to-subprogram type expected",
14733 Get_Pragma_Arg
(Arg1
));
14735 end Favor_Top_Level
;
14737 ---------------------------
14738 -- Finalize_Storage_Only --
14739 ---------------------------
14741 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
14743 when Pragma_Finalize_Storage_Only
=> Finalize_Storage
: declare
14744 Assoc
: constant Node_Id
:= Arg1
;
14745 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
14750 Check_No_Identifiers
;
14751 Check_Arg_Count
(1);
14752 Check_Arg_Is_Local_Name
(Arg1
);
14754 Find_Type
(Type_Id
);
14755 Typ
:= Entity
(Type_Id
);
14758 or else Rep_Item_Too_Early
(Typ
, N
)
14762 Typ
:= Underlying_Type
(Typ
);
14765 if not Is_Controlled
(Typ
) then
14766 Error_Pragma
("pragma% must specify controlled type");
14769 Check_First_Subtype
(Arg1
);
14771 if Finalize_Storage_Only
(Typ
) then
14772 Error_Pragma
("duplicate pragma%, only one allowed");
14774 elsif not Rep_Item_Too_Late
(Typ
, N
) then
14775 Set_Finalize_Storage_Only
(Base_Type
(Typ
), True);
14777 end Finalize_Storage
;
14783 -- pragma Ghost [ (boolean_EXPRESSION) ];
14785 when Pragma_Ghost
=> Ghost
: declare
14789 Orig_Stmt
: Node_Id
;
14790 Prev_Id
: Entity_Id
;
14795 Check_No_Identifiers
;
14796 Check_At_Most_N_Arguments
(1);
14800 while Present
(Stmt
) loop
14802 -- Skip prior pragmas, but check for duplicates
14804 if Nkind
(Stmt
) = N_Pragma
then
14805 if Pragma_Name
(Stmt
) = Pname
then
14806 Error_Msg_Name_1
:= Pname
;
14807 Error_Msg_Sloc
:= Sloc
(Stmt
);
14808 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
14811 -- Task unit declared without a definition cannot be subject to
14812 -- pragma Ghost (SPARK RM 6.9(19)).
14814 elsif Nkind_In
(Stmt
, N_Single_Task_Declaration
,
14815 N_Task_Type_Declaration
)
14817 Error_Pragma
("pragma % cannot apply to a task type");
14820 -- Skip internally generated code
14822 elsif not Comes_From_Source
(Stmt
) then
14823 Orig_Stmt
:= Original_Node
(Stmt
);
14825 -- When pragma Ghost applies to an untagged derivation, the
14826 -- derivation is transformed into a [sub]type declaration.
14828 if Nkind_In
(Stmt
, N_Full_Type_Declaration
,
14829 N_Subtype_Declaration
)
14830 and then Comes_From_Source
(Orig_Stmt
)
14831 and then Nkind
(Orig_Stmt
) = N_Full_Type_Declaration
14832 and then Nkind
(Type_Definition
(Orig_Stmt
)) =
14833 N_Derived_Type_Definition
14835 Id
:= Defining_Entity
(Stmt
);
14838 -- When pragma Ghost applies to an expression function, the
14839 -- expression function is transformed into a subprogram.
14841 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
14842 and then Comes_From_Source
(Orig_Stmt
)
14843 and then Nkind
(Orig_Stmt
) = N_Expression_Function
14845 Id
:= Defining_Entity
(Stmt
);
14849 -- The pragma applies to a legal construct, stop the traversal
14851 elsif Nkind_In
(Stmt
, N_Abstract_Subprogram_Declaration
,
14852 N_Full_Type_Declaration
,
14853 N_Generic_Subprogram_Declaration
,
14854 N_Object_Declaration
,
14855 N_Private_Extension_Declaration
,
14856 N_Private_Type_Declaration
,
14857 N_Subprogram_Declaration
,
14858 N_Subtype_Declaration
)
14860 Id
:= Defining_Entity
(Stmt
);
14863 -- The pragma does not apply to a legal construct, issue an
14864 -- error and stop the analysis.
14868 ("pragma % must apply to an object, package, subprogram "
14873 Stmt
:= Prev
(Stmt
);
14876 Context
:= Parent
(N
);
14878 -- Handle compilation units
14880 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
14881 Context
:= Unit
(Parent
(Context
));
14884 -- Protected and task types cannot be subject to pragma Ghost
14885 -- (SPARK RM 6.9(19)).
14887 if Nkind_In
(Context
, N_Protected_Body
, N_Protected_Definition
)
14889 Error_Pragma
("pragma % cannot apply to a protected type");
14892 elsif Nkind_In
(Context
, N_Task_Body
, N_Task_Definition
) then
14893 Error_Pragma
("pragma % cannot apply to a task type");
14899 -- When pragma Ghost is associated with a [generic] package, it
14900 -- appears in the visible declarations.
14902 if Nkind
(Context
) = N_Package_Specification
14903 and then Present
(Visible_Declarations
(Context
))
14904 and then List_Containing
(N
) = Visible_Declarations
(Context
)
14906 Id
:= Defining_Entity
(Context
);
14908 -- Pragma Ghost applies to a stand alone subprogram body
14910 elsif Nkind
(Context
) = N_Subprogram_Body
14911 and then No
(Corresponding_Spec
(Context
))
14913 Id
:= Defining_Entity
(Context
);
14919 ("pragma % must apply to an object, package, subprogram or "
14924 -- A derived type or type extension cannot be subject to pragma
14925 -- Ghost if either the parent type or one of the progenitor types
14926 -- is not Ghost (SPARK RM 6.9(9)).
14928 if Is_Derived_Type
(Id
) then
14929 Check_Ghost_Derivation
(Id
);
14932 -- Handle completions of types and constants that are subject to
14935 if Is_Record_Type
(Id
) or else Ekind
(Id
) = E_Constant
then
14936 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
14938 if Present
(Prev_Id
) and then not Is_Ghost_Entity
(Prev_Id
) then
14939 Error_Msg_Name_1
:= Pname
;
14941 -- The full declaration of a deferred constant cannot be
14942 -- subject to pragma Ghost unless the deferred declaration
14943 -- is also Ghost (SPARK RM 6.9(10)).
14945 if Ekind
(Prev_Id
) = E_Constant
then
14946 Error_Msg_Name_1
:= Pname
;
14947 Error_Msg_NE
(Fix_Error
14948 ("pragma % must apply to declaration of deferred "
14949 & "constant &"), N
, Id
);
14952 -- Pragma Ghost may appear on the full view of an incomplete
14953 -- type because the incomplete declaration lacks aspects and
14954 -- cannot be subject to pragma Ghost.
14956 elsif Ekind
(Prev_Id
) = E_Incomplete_Type
then
14959 -- The full declaration of a type cannot be subject to
14960 -- pragma Ghost unless the partial view is also Ghost
14961 -- (SPARK RM 6.9(10)).
14964 Error_Msg_NE
(Fix_Error
14965 ("pragma % must apply to partial view of type &"),
14971 -- A synchronized object cannot be subject to pragma Ghost
14972 -- (SPARK RM 6.9(19)).
14974 elsif Ekind
(Id
) = E_Variable
then
14975 if Is_Protected_Type
(Etype
(Id
)) then
14976 Error_Pragma
("pragma % cannot apply to a protected object");
14979 elsif Is_Task_Type
(Etype
(Id
)) then
14980 Error_Pragma
("pragma % cannot apply to a task object");
14985 -- Analyze the Boolean expression (if any)
14987 if Present
(Arg1
) then
14988 Expr
:= Get_Pragma_Arg
(Arg1
);
14990 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
14992 if Is_OK_Static_Expression
(Expr
) then
14994 -- "Ghostness" cannot be turned off once enabled within a
14995 -- region (SPARK RM 6.9(7)).
14997 if Is_False
(Expr_Value
(Expr
))
14998 and then Ghost_Mode
> None
15001 ("pragma % with value False cannot appear in enabled "
15006 -- Otherwie the expression is not static
15010 ("expression of pragma % must be static", Expr
);
15015 Set_Is_Ghost_Entity
(Id
);
15022 -- pragma Global (GLOBAL_SPECIFICATION);
15024 -- GLOBAL_SPECIFICATION ::=
15027 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
15029 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
15031 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
15032 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
15033 -- GLOBAL_ITEM ::= NAME
15035 -- Characteristics:
15037 -- * Analysis - The annotation undergoes initial checks to verify
15038 -- the legal placement and context. Secondary checks fully analyze
15039 -- the dependency clauses in:
15041 -- Analyze_Global_In_Decl_Part
15043 -- * Expansion - None.
15045 -- * Template - The annotation utilizes the generic template of the
15046 -- related subprogram [body] when it is:
15048 -- aspect on subprogram declaration
15049 -- aspect on stand alone subprogram body
15050 -- pragma on stand alone subprogram body
15052 -- The annotation must prepare its own template when it is:
15054 -- pragma on subprogram declaration
15056 -- * Globals - Capture of global references must occur after full
15059 -- * Instance - The annotation is instantiated automatically when
15060 -- the related generic subprogram [body] is instantiated except for
15061 -- the "pragma on subprogram declaration" case. In that scenario
15062 -- the annotation must instantiate itself.
15064 when Pragma_Global
=> Global
: declare
15066 Spec_Id
: Entity_Id
;
15067 Subp_Decl
: Node_Id
;
15070 Analyze_Depends_Global
(Spec_Id
, Subp_Decl
, Legal
);
15074 -- Chain the pragma on the contract for further processing by
15075 -- Analyze_Global_In_Decl_Part.
15077 Add_Contract_Item
(N
, Spec_Id
);
15079 -- Fully analyze the pragma when it appears inside an entry
15080 -- or subprogram body because it cannot benefit from forward
15083 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
15085 N_Subprogram_Body_Stub
)
15087 -- The legality checks of pragmas Depends and Global are
15088 -- affected by the SPARK mode in effect and the volatility
15089 -- of the context. In addition these two pragmas are subject
15090 -- to an inherent order:
15095 -- Analyze all these pragmas in the order outlined above
15097 Analyze_If_Present
(Pragma_SPARK_Mode
);
15098 Analyze_If_Present
(Pragma_Volatile_Function
);
15099 Analyze_Global_In_Decl_Part
(N
);
15100 Analyze_If_Present
(Pragma_Depends
);
15109 -- pragma Ident (static_string_EXPRESSION)
15111 -- Note: pragma Comment shares this processing. Pragma Ident is
15112 -- identical in effect to pragma Commment.
15114 when Pragma_Ident | Pragma_Comment
=> Ident
: declare
15119 Check_Arg_Count
(1);
15120 Check_No_Identifiers
;
15121 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
15124 Str
:= Expr_Value_S
(Get_Pragma_Arg
(Arg1
));
15131 GP
:= Parent
(Parent
(N
));
15133 if Nkind_In
(GP
, N_Package_Declaration
,
15134 N_Generic_Package_Declaration
)
15139 -- If we have a compilation unit, then record the ident value,
15140 -- checking for improper duplication.
15142 if Nkind
(GP
) = N_Compilation_Unit
then
15143 CS
:= Ident_String
(Current_Sem_Unit
);
15145 if Present
(CS
) then
15147 -- If we have multiple instances, concatenate them, but
15148 -- not in ASIS, where we want the original tree.
15150 if not ASIS_Mode
then
15151 Start_String
(Strval
(CS
));
15152 Store_String_Char
(' ');
15153 Store_String_Chars
(Strval
(Str
));
15154 Set_Strval
(CS
, End_String
);
15158 Set_Ident_String
(Current_Sem_Unit
, Str
);
15161 -- For subunits, we just ignore the Ident, since in GNAT these
15162 -- are not separate object files, and hence not separate units
15163 -- in the unit table.
15165 elsif Nkind
(GP
) = N_Subunit
then
15171 -------------------
15172 -- Ignore_Pragma --
15173 -------------------
15175 -- pragma Ignore_Pragma (pragma_IDENTIFIER);
15177 -- Entirely handled in the parser, nothing to do here
15179 when Pragma_Ignore_Pragma
=>
15182 ----------------------------
15183 -- Implementation_Defined --
15184 ----------------------------
15186 -- pragma Implementation_Defined (LOCAL_NAME);
15188 -- Marks previously declared entity as implementation defined. For
15189 -- an overloaded entity, applies to the most recent homonym.
15191 -- pragma Implementation_Defined;
15193 -- The form with no arguments appears anywhere within a scope, most
15194 -- typically a package spec, and indicates that all entities that are
15195 -- defined within the package spec are Implementation_Defined.
15197 when Pragma_Implementation_Defined
=> Implementation_Defined
: declare
15202 Check_No_Identifiers
;
15204 -- Form with no arguments
15206 if Arg_Count
= 0 then
15207 Set_Is_Implementation_Defined
(Current_Scope
);
15209 -- Form with one argument
15212 Check_Arg_Count
(1);
15213 Check_Arg_Is_Local_Name
(Arg1
);
15214 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
15215 Set_Is_Implementation_Defined
(Ent
);
15217 end Implementation_Defined
;
15223 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
15225 -- IMPLEMENTATION_KIND ::=
15226 -- By_Entry | By_Protected_Procedure | By_Any | Optional
15228 -- "By_Any" and "Optional" are treated as synonyms in order to
15229 -- support Ada 2012 aspect Synchronization.
15231 when Pragma_Implemented
=> Implemented
: declare
15232 Proc_Id
: Entity_Id
;
15237 Check_Arg_Count
(2);
15238 Check_No_Identifiers
;
15239 Check_Arg_Is_Identifier
(Arg1
);
15240 Check_Arg_Is_Local_Name
(Arg1
);
15241 Check_Arg_Is_One_Of
(Arg2
,
15244 Name_By_Protected_Procedure
,
15247 -- Extract the name of the local procedure
15249 Proc_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
15251 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
15252 -- primitive procedure of a synchronized tagged type.
15254 if Ekind
(Proc_Id
) = E_Procedure
15255 and then Is_Primitive
(Proc_Id
)
15256 and then Present
(First_Formal
(Proc_Id
))
15258 Typ
:= Etype
(First_Formal
(Proc_Id
));
15260 if Is_Tagged_Type
(Typ
)
15263 -- Check for a protected, a synchronized or a task interface
15265 ((Is_Interface
(Typ
)
15266 and then Is_Synchronized_Interface
(Typ
))
15268 -- Check for a protected type or a task type that implements
15272 (Is_Concurrent_Record_Type
(Typ
)
15273 and then Present
(Interfaces
(Typ
)))
15275 -- In analysis-only mode, examine original protected type
15278 (Nkind
(Parent
(Typ
)) = N_Protected_Type_Declaration
15279 and then Present
(Interface_List
(Parent
(Typ
))))
15281 -- Check for a private record extension with keyword
15285 (Ekind_In
(Typ
, E_Record_Type_With_Private
,
15286 E_Record_Subtype_With_Private
)
15287 and then Synchronized_Present
(Parent
(Typ
))))
15292 ("controlling formal must be of synchronized tagged type",
15297 -- Procedures declared inside a protected type must be accepted
15299 elsif Ekind
(Proc_Id
) = E_Procedure
15300 and then Is_Protected_Type
(Scope
(Proc_Id
))
15304 -- The first argument is not a primitive procedure
15308 ("pragma % must be applied to a primitive procedure", Arg1
);
15312 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
15313 -- By_Protected_Procedure to the primitive procedure of a task
15316 if Chars
(Arg2
) = Name_By_Protected_Procedure
15317 and then Is_Interface
(Typ
)
15318 and then Is_Task_Interface
(Typ
)
15321 ("implementation kind By_Protected_Procedure cannot be "
15322 & "applied to a task interface primitive", Arg2
);
15326 Record_Rep_Item
(Proc_Id
, N
);
15329 ----------------------
15330 -- Implicit_Packing --
15331 ----------------------
15333 -- pragma Implicit_Packing;
15335 when Pragma_Implicit_Packing
=>
15337 Check_Arg_Count
(0);
15338 Implicit_Packing
:= True;
15345 -- [Convention =>] convention_IDENTIFIER,
15346 -- [Entity =>] LOCAL_NAME
15347 -- [, [External_Name =>] static_string_EXPRESSION ]
15348 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15350 when Pragma_Import
=>
15351 Check_Ada_83_Warning
;
15355 Name_External_Name
,
15358 Check_At_Least_N_Arguments
(2);
15359 Check_At_Most_N_Arguments
(4);
15360 Process_Import_Or_Interface
;
15362 ---------------------
15363 -- Import_Function --
15364 ---------------------
15366 -- pragma Import_Function (
15367 -- [Internal =>] LOCAL_NAME,
15368 -- [, [External =>] EXTERNAL_SYMBOL]
15369 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15370 -- [, [Result_Type =>] SUBTYPE_MARK]
15371 -- [, [Mechanism =>] MECHANISM]
15372 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
15374 -- EXTERNAL_SYMBOL ::=
15376 -- | static_string_EXPRESSION
15378 -- PARAMETER_TYPES ::=
15380 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15382 -- TYPE_DESIGNATOR ::=
15384 -- | subtype_Name ' Access
15388 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15390 -- MECHANISM_ASSOCIATION ::=
15391 -- [formal_parameter_NAME =>] MECHANISM_NAME
15393 -- MECHANISM_NAME ::=
15397 when Pragma_Import_Function
=> Import_Function
: declare
15398 Args
: Args_List
(1 .. 6);
15399 Names
: constant Name_List
(1 .. 6) := (
15402 Name_Parameter_Types
,
15405 Name_Result_Mechanism
);
15407 Internal
: Node_Id
renames Args
(1);
15408 External
: Node_Id
renames Args
(2);
15409 Parameter_Types
: Node_Id
renames Args
(3);
15410 Result_Type
: Node_Id
renames Args
(4);
15411 Mechanism
: Node_Id
renames Args
(5);
15412 Result_Mechanism
: Node_Id
renames Args
(6);
15416 Gather_Associations
(Names
, Args
);
15417 Process_Extended_Import_Export_Subprogram_Pragma
(
15418 Arg_Internal
=> Internal
,
15419 Arg_External
=> External
,
15420 Arg_Parameter_Types
=> Parameter_Types
,
15421 Arg_Result_Type
=> Result_Type
,
15422 Arg_Mechanism
=> Mechanism
,
15423 Arg_Result_Mechanism
=> Result_Mechanism
);
15424 end Import_Function
;
15426 -------------------
15427 -- Import_Object --
15428 -------------------
15430 -- pragma Import_Object (
15431 -- [Internal =>] LOCAL_NAME
15432 -- [, [External =>] EXTERNAL_SYMBOL]
15433 -- [, [Size =>] EXTERNAL_SYMBOL]);
15435 -- EXTERNAL_SYMBOL ::=
15437 -- | static_string_EXPRESSION
15439 when Pragma_Import_Object
=> Import_Object
: declare
15440 Args
: Args_List
(1 .. 3);
15441 Names
: constant Name_List
(1 .. 3) := (
15446 Internal
: Node_Id
renames Args
(1);
15447 External
: Node_Id
renames Args
(2);
15448 Size
: Node_Id
renames Args
(3);
15452 Gather_Associations
(Names
, Args
);
15453 Process_Extended_Import_Export_Object_Pragma
(
15454 Arg_Internal
=> Internal
,
15455 Arg_External
=> External
,
15459 ----------------------
15460 -- Import_Procedure --
15461 ----------------------
15463 -- pragma Import_Procedure (
15464 -- [Internal =>] LOCAL_NAME
15465 -- [, [External =>] EXTERNAL_SYMBOL]
15466 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15467 -- [, [Mechanism =>] MECHANISM]);
15469 -- EXTERNAL_SYMBOL ::=
15471 -- | static_string_EXPRESSION
15473 -- PARAMETER_TYPES ::=
15475 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15477 -- TYPE_DESIGNATOR ::=
15479 -- | subtype_Name ' Access
15483 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15485 -- MECHANISM_ASSOCIATION ::=
15486 -- [formal_parameter_NAME =>] MECHANISM_NAME
15488 -- MECHANISM_NAME ::=
15492 when Pragma_Import_Procedure
=> Import_Procedure
: declare
15493 Args
: Args_List
(1 .. 4);
15494 Names
: constant Name_List
(1 .. 4) := (
15497 Name_Parameter_Types
,
15500 Internal
: Node_Id
renames Args
(1);
15501 External
: Node_Id
renames Args
(2);
15502 Parameter_Types
: Node_Id
renames Args
(3);
15503 Mechanism
: Node_Id
renames Args
(4);
15507 Gather_Associations
(Names
, Args
);
15508 Process_Extended_Import_Export_Subprogram_Pragma
(
15509 Arg_Internal
=> Internal
,
15510 Arg_External
=> External
,
15511 Arg_Parameter_Types
=> Parameter_Types
,
15512 Arg_Mechanism
=> Mechanism
);
15513 end Import_Procedure
;
15515 -----------------------------
15516 -- Import_Valued_Procedure --
15517 -----------------------------
15519 -- pragma Import_Valued_Procedure (
15520 -- [Internal =>] LOCAL_NAME
15521 -- [, [External =>] EXTERNAL_SYMBOL]
15522 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
15523 -- [, [Mechanism =>] MECHANISM]);
15525 -- EXTERNAL_SYMBOL ::=
15527 -- | static_string_EXPRESSION
15529 -- PARAMETER_TYPES ::=
15531 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
15533 -- TYPE_DESIGNATOR ::=
15535 -- | subtype_Name ' Access
15539 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
15541 -- MECHANISM_ASSOCIATION ::=
15542 -- [formal_parameter_NAME =>] MECHANISM_NAME
15544 -- MECHANISM_NAME ::=
15548 when Pragma_Import_Valued_Procedure
=>
15549 Import_Valued_Procedure
: declare
15550 Args
: Args_List
(1 .. 4);
15551 Names
: constant Name_List
(1 .. 4) := (
15554 Name_Parameter_Types
,
15557 Internal
: Node_Id
renames Args
(1);
15558 External
: Node_Id
renames Args
(2);
15559 Parameter_Types
: Node_Id
renames Args
(3);
15560 Mechanism
: Node_Id
renames Args
(4);
15564 Gather_Associations
(Names
, Args
);
15565 Process_Extended_Import_Export_Subprogram_Pragma
(
15566 Arg_Internal
=> Internal
,
15567 Arg_External
=> External
,
15568 Arg_Parameter_Types
=> Parameter_Types
,
15569 Arg_Mechanism
=> Mechanism
);
15570 end Import_Valued_Procedure
;
15576 -- pragma Independent (LOCAL_NAME);
15578 when Pragma_Independent
=>
15579 Process_Atomic_Independent_Shared_Volatile
;
15581 ----------------------------
15582 -- Independent_Components --
15583 ----------------------------
15585 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
15587 when Pragma_Independent_Components
=> Independent_Components
: declare
15595 Check_Ada_83_Warning
;
15597 Check_No_Identifiers
;
15598 Check_Arg_Count
(1);
15599 Check_Arg_Is_Local_Name
(Arg1
);
15600 E_Id
:= Get_Pragma_Arg
(Arg1
);
15602 if Etype
(E_Id
) = Any_Type
then
15606 E
:= Entity
(E_Id
);
15608 -- A pragma that applies to a Ghost entity becomes Ghost for the
15609 -- purposes of legality checks and removal of ignored Ghost code.
15611 Mark_Pragma_As_Ghost
(N
, E
);
15613 -- Check duplicate before we chain ourselves
15615 Check_Duplicate_Pragma
(E
);
15617 -- Check appropriate entity
15619 if Rep_Item_Too_Early
(E
, N
)
15621 Rep_Item_Too_Late
(E
, N
)
15626 D
:= Declaration_Node
(E
);
15629 -- The flag is set on the base type, or on the object
15631 if K
= N_Full_Type_Declaration
15632 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
15634 Set_Has_Independent_Components
(Base_Type
(E
));
15635 Record_Independence_Check
(N
, Base_Type
(E
));
15637 -- For record type, set all components independent
15639 if Is_Record_Type
(E
) then
15640 C
:= First_Component
(E
);
15641 while Present
(C
) loop
15642 Set_Is_Independent
(C
);
15643 Next_Component
(C
);
15647 elsif (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
15648 and then Nkind
(D
) = N_Object_Declaration
15649 and then Nkind
(Object_Definition
(D
)) =
15650 N_Constrained_Array_Definition
15652 Set_Has_Independent_Components
(E
);
15653 Record_Independence_Check
(N
, E
);
15656 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
15658 end Independent_Components
;
15660 -----------------------
15661 -- Initial_Condition --
15662 -----------------------
15664 -- pragma Initial_Condition (boolean_EXPRESSION);
15666 -- Characteristics:
15668 -- * Analysis - The annotation undergoes initial checks to verify
15669 -- the legal placement and context. Secondary checks preanalyze the
15672 -- Analyze_Initial_Condition_In_Decl_Part
15674 -- * Expansion - The annotation is expanded during the expansion of
15675 -- the package body whose declaration is subject to the annotation
15678 -- Expand_Pragma_Initial_Condition
15680 -- * Template - The annotation utilizes the generic template of the
15681 -- related package declaration.
15683 -- * Globals - Capture of global references must occur after full
15686 -- * Instance - The annotation is instantiated automatically when
15687 -- the related generic package is instantiated.
15689 when Pragma_Initial_Condition
=> Initial_Condition
: declare
15690 Pack_Decl
: Node_Id
;
15691 Pack_Id
: Entity_Id
;
15695 Check_No_Identifiers
;
15696 Check_Arg_Count
(1);
15698 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
15700 -- Ensure the proper placement of the pragma. Initial_Condition
15701 -- must be associated with a package declaration.
15703 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
15704 N_Package_Declaration
)
15708 -- Otherwise the pragma is associated with an illegal context
15715 Pack_Id
:= Defining_Entity
(Pack_Decl
);
15717 -- Chain the pragma on the contract for further processing by
15718 -- Analyze_Initial_Condition_In_Decl_Part.
15720 Add_Contract_Item
(N
, Pack_Id
);
15722 -- The legality checks of pragmas Abstract_State, Initializes, and
15723 -- Initial_Condition are affected by the SPARK mode in effect. In
15724 -- addition, these three pragmas are subject to an inherent order:
15726 -- 1) Abstract_State
15728 -- 3) Initial_Condition
15730 -- Analyze all these pragmas in the order outlined above
15732 Analyze_If_Present
(Pragma_SPARK_Mode
);
15733 Analyze_If_Present
(Pragma_Abstract_State
);
15734 Analyze_If_Present
(Pragma_Initializes
);
15736 -- A pragma that applies to a Ghost entity becomes Ghost for the
15737 -- purposes of legality checks and removal of ignored Ghost code.
15739 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
15740 end Initial_Condition
;
15742 ------------------------
15743 -- Initialize_Scalars --
15744 ------------------------
15746 -- pragma Initialize_Scalars;
15748 when Pragma_Initialize_Scalars
=>
15750 Check_Arg_Count
(0);
15751 Check_Valid_Configuration_Pragma
;
15752 Check_Restriction
(No_Initialize_Scalars
, N
);
15754 -- Initialize_Scalars creates false positives in CodePeer, and
15755 -- incorrect negative results in GNATprove mode, so ignore this
15756 -- pragma in these modes.
15758 if not Restriction_Active
(No_Initialize_Scalars
)
15759 and then not (CodePeer_Mode
or GNATprove_Mode
)
15761 Init_Or_Norm_Scalars
:= True;
15762 Initialize_Scalars
:= True;
15769 -- pragma Initializes (INITIALIZATION_LIST);
15771 -- INITIALIZATION_LIST ::=
15773 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
15775 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
15780 -- | (INPUT {, INPUT})
15784 -- Characteristics:
15786 -- * Analysis - The annotation undergoes initial checks to verify
15787 -- the legal placement and context. Secondary checks preanalyze the
15790 -- Analyze_Initializes_In_Decl_Part
15792 -- * Expansion - None.
15794 -- * Template - The annotation utilizes the generic template of the
15795 -- related package declaration.
15797 -- * Globals - Capture of global references must occur after full
15800 -- * Instance - The annotation is instantiated automatically when
15801 -- the related generic package is instantiated.
15803 when Pragma_Initializes
=> Initializes
: declare
15804 Pack_Decl
: Node_Id
;
15805 Pack_Id
: Entity_Id
;
15809 Check_No_Identifiers
;
15810 Check_Arg_Count
(1);
15812 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
15814 -- Ensure the proper placement of the pragma. Initializes must be
15815 -- associated with a package declaration.
15817 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
15818 N_Package_Declaration
)
15822 -- Otherwise the pragma is associated with an illegal construc
15829 Pack_Id
:= Defining_Entity
(Pack_Decl
);
15831 -- Chain the pragma on the contract for further processing by
15832 -- Analyze_Initializes_In_Decl_Part.
15834 Add_Contract_Item
(N
, Pack_Id
);
15836 -- The legality checks of pragmas Abstract_State, Initializes, and
15837 -- Initial_Condition are affected by the SPARK mode in effect. In
15838 -- addition, these three pragmas are subject to an inherent order:
15840 -- 1) Abstract_State
15842 -- 3) Initial_Condition
15844 -- Analyze all these pragmas in the order outlined above
15846 Analyze_If_Present
(Pragma_SPARK_Mode
);
15847 Analyze_If_Present
(Pragma_Abstract_State
);
15849 -- A pragma that applies to a Ghost entity becomes Ghost for the
15850 -- purposes of legality checks and removal of ignored Ghost code.
15852 Mark_Pragma_As_Ghost
(N
, Pack_Id
);
15853 Ensure_Aggregate_Form
(Get_Argument
(N
, Pack_Id
));
15855 Analyze_If_Present
(Pragma_Initial_Condition
);
15862 -- pragma Inline ( NAME {, NAME} );
15864 when Pragma_Inline
=>
15866 -- Pragma always active unless in GNATprove mode. It is disabled
15867 -- in GNATprove mode because frontend inlining is applied
15868 -- independently of pragmas Inline and Inline_Always for
15869 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
15872 if not GNATprove_Mode
then
15874 -- Inline status is Enabled if inlining option is active
15876 if Inline_Active
then
15877 Process_Inline
(Enabled
);
15879 Process_Inline
(Disabled
);
15883 -------------------
15884 -- Inline_Always --
15885 -------------------
15887 -- pragma Inline_Always ( NAME {, NAME} );
15889 when Pragma_Inline_Always
=>
15892 -- Pragma always active unless in CodePeer mode or GNATprove
15893 -- mode. It is disabled in CodePeer mode because inlining is
15894 -- not helpful, and enabling it caused walk order issues. It
15895 -- is disabled in GNATprove mode because frontend inlining is
15896 -- applied independently of pragmas Inline and Inline_Always for
15897 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
15900 if not CodePeer_Mode
and not GNATprove_Mode
then
15901 Process_Inline
(Enabled
);
15904 --------------------
15905 -- Inline_Generic --
15906 --------------------
15908 -- pragma Inline_Generic (NAME {, NAME});
15910 when Pragma_Inline_Generic
=>
15912 Process_Generic_List
;
15914 ----------------------
15915 -- Inspection_Point --
15916 ----------------------
15918 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
15920 when Pragma_Inspection_Point
=> Inspection_Point
: declare
15927 if Arg_Count
> 0 then
15930 Exp
:= Get_Pragma_Arg
(Arg
);
15933 if not Is_Entity_Name
(Exp
)
15934 or else not Is_Object
(Entity
(Exp
))
15936 Error_Pragma_Arg
("object name required", Arg
);
15940 exit when No
(Arg
);
15943 end Inspection_Point
;
15949 -- pragma Interface (
15950 -- [ Convention =>] convention_IDENTIFIER,
15951 -- [ Entity =>] LOCAL_NAME
15952 -- [, [External_Name =>] static_string_EXPRESSION ]
15953 -- [, [Link_Name =>] static_string_EXPRESSION ]);
15955 when Pragma_Interface
=>
15960 Name_External_Name
,
15962 Check_At_Least_N_Arguments
(2);
15963 Check_At_Most_N_Arguments
(4);
15964 Process_Import_Or_Interface
;
15966 -- In Ada 2005, the permission to use Interface (a reserved word)
15967 -- as a pragma name is considered an obsolescent feature, and this
15968 -- pragma was already obsolescent in Ada 95.
15970 if Ada_Version
>= Ada_95
then
15972 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
15974 if Warn_On_Obsolescent_Feature
then
15976 ("pragma Interface is an obsolescent feature?j?", N
);
15978 ("|use pragma Import instead?j?", N
);
15982 --------------------
15983 -- Interface_Name --
15984 --------------------
15986 -- pragma Interface_Name (
15987 -- [ Entity =>] LOCAL_NAME
15988 -- [,[External_Name =>] static_string_EXPRESSION ]
15989 -- [,[Link_Name =>] static_string_EXPRESSION ]);
15991 when Pragma_Interface_Name
=> Interface_Name
: declare
15993 Def_Id
: Entity_Id
;
15994 Hom_Id
: Entity_Id
;
16000 ((Name_Entity
, Name_External_Name
, Name_Link_Name
));
16001 Check_At_Least_N_Arguments
(2);
16002 Check_At_Most_N_Arguments
(3);
16003 Id
:= Get_Pragma_Arg
(Arg1
);
16006 -- This is obsolete from Ada 95 on, but it is an implementation
16007 -- defined pragma, so we do not consider that it violates the
16008 -- restriction (No_Obsolescent_Features).
16010 if Ada_Version
>= Ada_95
then
16011 if Warn_On_Obsolescent_Feature
then
16013 ("pragma Interface_Name is an obsolescent feature?j?", N
);
16015 ("|use pragma Import instead?j?", N
);
16019 if not Is_Entity_Name
(Id
) then
16021 ("first argument for pragma% must be entity name", Arg1
);
16022 elsif Etype
(Id
) = Any_Type
then
16025 Def_Id
:= Entity
(Id
);
16028 -- Special DEC-compatible processing for the object case, forces
16029 -- object to be imported.
16031 if Ekind
(Def_Id
) = E_Variable
then
16032 Kill_Size_Check_Code
(Def_Id
);
16033 Note_Possible_Modification
(Id
, Sure
=> False);
16035 -- Initialization is not allowed for imported variable
16037 if Present
(Expression
(Parent
(Def_Id
)))
16038 and then Comes_From_Source
(Expression
(Parent
(Def_Id
)))
16040 Error_Msg_Sloc
:= Sloc
(Def_Id
);
16042 ("no initialization allowed for declaration of& #",
16046 -- For compatibility, support VADS usage of providing both
16047 -- pragmas Interface and Interface_Name to obtain the effect
16048 -- of a single Import pragma.
16050 if Is_Imported
(Def_Id
)
16051 and then Present
(First_Rep_Item
(Def_Id
))
16052 and then Nkind
(First_Rep_Item
(Def_Id
)) = N_Pragma
16054 Pragma_Name
(First_Rep_Item
(Def_Id
)) = Name_Interface
16058 Set_Imported
(Def_Id
);
16061 Set_Is_Public
(Def_Id
);
16062 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
16065 -- Otherwise must be subprogram
16067 elsif not Is_Subprogram
(Def_Id
) then
16069 ("argument of pragma% is not subprogram", Arg1
);
16072 Check_At_Most_N_Arguments
(3);
16076 -- Loop through homonyms
16079 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
16081 if Is_Imported
(Def_Id
) then
16082 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
16086 exit when From_Aspect_Specification
(N
);
16087 Hom_Id
:= Homonym
(Hom_Id
);
16089 exit when No
(Hom_Id
)
16090 or else Scope
(Hom_Id
) /= Current_Scope
;
16095 ("argument of pragma% is not imported subprogram",
16099 end Interface_Name
;
16101 -----------------------
16102 -- Interrupt_Handler --
16103 -----------------------
16105 -- pragma Interrupt_Handler (handler_NAME);
16107 when Pragma_Interrupt_Handler
=>
16108 Check_Ada_83_Warning
;
16109 Check_Arg_Count
(1);
16110 Check_No_Identifiers
;
16112 if No_Run_Time_Mode
then
16113 Error_Msg_CRT
("Interrupt_Handler pragma", N
);
16115 Check_Interrupt_Or_Attach_Handler
;
16116 Process_Interrupt_Or_Attach_Handler
;
16119 ------------------------
16120 -- Interrupt_Priority --
16121 ------------------------
16123 -- pragma Interrupt_Priority [(EXPRESSION)];
16125 when Pragma_Interrupt_Priority
=> Interrupt_Priority
: declare
16126 P
: constant Node_Id
:= Parent
(N
);
16131 Check_Ada_83_Warning
;
16133 if Arg_Count
/= 0 then
16134 Arg
:= Get_Pragma_Arg
(Arg1
);
16135 Check_Arg_Count
(1);
16136 Check_No_Identifiers
;
16138 -- The expression must be analyzed in the special manner
16139 -- described in "Handling of Default and Per-Object
16140 -- Expressions" in sem.ads.
16142 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Interrupt_Priority
));
16145 if not Nkind_In
(P
, N_Task_Definition
, N_Protected_Definition
) then
16150 Ent
:= Defining_Identifier
(Parent
(P
));
16152 -- Check duplicate pragma before we chain the pragma in the Rep
16153 -- Item chain of Ent.
16155 Check_Duplicate_Pragma
(Ent
);
16156 Record_Rep_Item
(Ent
, N
);
16158 -- Check the No_Task_At_Interrupt_Priority restriction
16160 if Nkind
(P
) = N_Task_Definition
then
16161 Check_Restriction
(No_Task_At_Interrupt_Priority
, N
);
16164 end Interrupt_Priority
;
16166 ---------------------
16167 -- Interrupt_State --
16168 ---------------------
16170 -- pragma Interrupt_State (
16171 -- [Name =>] INTERRUPT_ID,
16172 -- [State =>] INTERRUPT_STATE);
16174 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
16175 -- INTERRUPT_STATE => System | Runtime | User
16177 -- Note: if the interrupt id is given as an identifier, then it must
16178 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
16179 -- given as a static integer expression which must be in the range of
16180 -- Ada.Interrupts.Interrupt_ID.
16182 when Pragma_Interrupt_State
=> Interrupt_State
: declare
16183 Int_Id
: constant Entity_Id
:= RTE
(RE_Interrupt_ID
);
16184 -- This is the entity Ada.Interrupts.Interrupt_ID;
16186 State_Type
: Character;
16187 -- Set to 's'/'r'/'u' for System/Runtime/User
16190 -- Index to entry in Interrupt_States table
16193 -- Value of interrupt
16195 Arg1X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
16196 -- The first argument to the pragma
16198 Int_Ent
: Entity_Id
;
16199 -- Interrupt entity in Ada.Interrupts.Names
16203 Check_Arg_Order
((Name_Name
, Name_State
));
16204 Check_Arg_Count
(2);
16206 Check_Optional_Identifier
(Arg1
, Name_Name
);
16207 Check_Optional_Identifier
(Arg2
, Name_State
);
16208 Check_Arg_Is_Identifier
(Arg2
);
16210 -- First argument is identifier
16212 if Nkind
(Arg1X
) = N_Identifier
then
16214 -- Search list of names in Ada.Interrupts.Names
16216 Int_Ent
:= First_Entity
(RTE
(RE_Names
));
16218 if No
(Int_Ent
) then
16219 Error_Pragma_Arg
("invalid interrupt name", Arg1
);
16221 elsif Chars
(Int_Ent
) = Chars
(Arg1X
) then
16222 Int_Val
:= Expr_Value
(Constant_Value
(Int_Ent
));
16226 Next_Entity
(Int_Ent
);
16229 -- First argument is not an identifier, so it must be a static
16230 -- expression of type Ada.Interrupts.Interrupt_ID.
16233 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
16234 Int_Val
:= Expr_Value
(Arg1X
);
16236 if Int_Val
< Expr_Value
(Type_Low_Bound
(Int_Id
))
16238 Int_Val
> Expr_Value
(Type_High_Bound
(Int_Id
))
16241 ("value not in range of type "
16242 & """Ada.Interrupts.Interrupt_'I'D""", Arg1
);
16248 case Chars
(Get_Pragma_Arg
(Arg2
)) is
16249 when Name_Runtime
=> State_Type
:= 'r';
16250 when Name_System
=> State_Type
:= 's';
16251 when Name_User
=> State_Type
:= 'u';
16254 Error_Pragma_Arg
("invalid interrupt state", Arg2
);
16257 -- Check if entry is already stored
16259 IST_Num
:= Interrupt_States
.First
;
16261 -- If entry not found, add it
16263 if IST_Num
> Interrupt_States
.Last
then
16264 Interrupt_States
.Append
16265 ((Interrupt_Number
=> UI_To_Int
(Int_Val
),
16266 Interrupt_State
=> State_Type
,
16267 Pragma_Loc
=> Loc
));
16270 -- Case of entry for the same entry
16272 elsif Int_Val
= Interrupt_States
.Table
(IST_Num
).
16275 -- If state matches, done, no need to make redundant entry
16278 State_Type
= Interrupt_States
.Table
(IST_Num
).
16281 -- Otherwise if state does not match, error
16284 Interrupt_States
.Table
(IST_Num
).Pragma_Loc
;
16286 ("state conflicts with that given #", Arg2
);
16290 IST_Num
:= IST_Num
+ 1;
16292 end Interrupt_State
;
16298 -- pragma Invariant
16299 -- ([Entity =>] type_LOCAL_NAME,
16300 -- [Check =>] EXPRESSION
16301 -- [,[Message =>] String_Expression]);
16303 when Pragma_Invariant
=> Invariant
: declare
16310 Check_At_Least_N_Arguments
(2);
16311 Check_At_Most_N_Arguments
(3);
16312 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16313 Check_Optional_Identifier
(Arg2
, Name_Check
);
16315 if Arg_Count
= 3 then
16316 Check_Optional_Identifier
(Arg3
, Name_Message
);
16317 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
16320 Check_Arg_Is_Local_Name
(Arg1
);
16322 Type_Id
:= Get_Pragma_Arg
(Arg1
);
16323 Find_Type
(Type_Id
);
16324 Typ
:= Entity
(Type_Id
);
16326 if Typ
= Any_Type
then
16329 -- Invariants allowed in interface types (RM 7.3.2(3/3))
16331 elsif Is_Interface
(Typ
) then
16334 -- An invariant must apply to a private type, or appear in the
16335 -- private part of a package spec and apply to a completion.
16336 -- a class-wide invariant can only appear on a private declaration
16337 -- or private extension, not a completion.
16339 elsif Ekind_In
(Typ
, E_Private_Type
,
16340 E_Record_Type_With_Private
,
16341 E_Limited_Private_Type
)
16345 elsif In_Private_Part
(Current_Scope
)
16346 and then Has_Private_Declaration
(Typ
)
16347 and then not Class_Present
(N
)
16351 elsif In_Private_Part
(Current_Scope
) then
16353 ("pragma% only allowed for private type declared in "
16354 & "visible part", Arg1
);
16358 ("pragma% only allowed for private type", Arg1
);
16361 -- A pragma that applies to a Ghost entity becomes Ghost for the
16362 -- purposes of legality checks and removal of ignored Ghost code.
16364 Mark_Pragma_As_Ghost
(N
, Typ
);
16366 -- Not allowed for abstract type in the non-class case (it is
16367 -- allowed to use Invariant'Class for abstract types).
16369 if Is_Abstract_Type
(Typ
) and then not Class_Present
(N
) then
16371 ("pragma% not allowed for abstract type", Arg1
);
16374 -- Link the pragma on to the rep item chain, for processing when
16375 -- the type is frozen.
16377 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
16379 -- Note that the type has at least one invariant, and also that
16380 -- it has inheritable invariants if we have Invariant'Class
16381 -- or Type_Invariant'Class. Build the corresponding invariant
16382 -- procedure declaration, so that calls to it can be generated
16383 -- before the body is built (e.g. within an expression function).
16385 -- Interface types have no invariant procedure; their invariants
16386 -- are propagated to the build invariant procedure of all the
16387 -- types covering the interface type.
16389 if not Is_Interface
(Typ
) then
16390 Insert_After_And_Analyze
16391 (N
, Build_Invariant_Procedure_Declaration
(Typ
));
16394 if Class_Present
(N
) then
16395 Set_Has_Inheritable_Invariants
(Typ
);
16403 -- pragma Keep_Names ([On => ] LOCAL_NAME);
16405 when Pragma_Keep_Names
=> Keep_Names
: declare
16410 Check_Arg_Count
(1);
16411 Check_Optional_Identifier
(Arg1
, Name_On
);
16412 Check_Arg_Is_Local_Name
(Arg1
);
16414 Arg
:= Get_Pragma_Arg
(Arg1
);
16417 if Etype
(Arg
) = Any_Type
then
16421 if not Is_Entity_Name
(Arg
)
16422 or else Ekind
(Entity
(Arg
)) /= E_Enumeration_Type
16425 ("pragma% requires a local enumeration type", Arg1
);
16428 Set_Discard_Names
(Entity
(Arg
), False);
16435 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
16437 when Pragma_License
=>
16440 -- Do not analyze pragma any further in CodePeer mode, to avoid
16441 -- extraneous errors in this implementation-dependent pragma,
16442 -- which has a different profile on other compilers.
16444 if CodePeer_Mode
then
16448 Check_Arg_Count
(1);
16449 Check_No_Identifiers
;
16450 Check_Valid_Configuration_Pragma
;
16451 Check_Arg_Is_Identifier
(Arg1
);
16454 Sind
: constant Source_File_Index
:=
16455 Source_Index
(Current_Sem_Unit
);
16458 case Chars
(Get_Pragma_Arg
(Arg1
)) is
16460 Set_License
(Sind
, GPL
);
16462 when Name_Modified_GPL
=>
16463 Set_License
(Sind
, Modified_GPL
);
16465 when Name_Restricted
=>
16466 Set_License
(Sind
, Restricted
);
16468 when Name_Unrestricted
=>
16469 Set_License
(Sind
, Unrestricted
);
16472 Error_Pragma_Arg
("invalid license name", Arg1
);
16480 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
16482 when Pragma_Link_With
=> Link_With
: declare
16488 if Operating_Mode
= Generate_Code
16489 and then In_Extended_Main_Source_Unit
(N
)
16491 Check_At_Least_N_Arguments
(1);
16492 Check_No_Identifiers
;
16493 Check_Is_In_Decl_Part_Or_Package_Spec
;
16494 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16498 while Present
(Arg
) loop
16499 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
16501 -- Store argument, converting sequences of spaces to a
16502 -- single null character (this is one of the differences
16503 -- in processing between Link_With and Linker_Options).
16505 Arg_Store
: declare
16506 C
: constant Char_Code
:= Get_Char_Code
(' ');
16507 S
: constant String_Id
:=
16508 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
)));
16509 L
: constant Nat
:= String_Length
(S
);
16512 procedure Skip_Spaces
;
16513 -- Advance F past any spaces
16519 procedure Skip_Spaces
is
16521 while F
<= L
and then Get_String_Char
(S
, F
) = C
loop
16526 -- Start of processing for Arg_Store
16529 Skip_Spaces
; -- skip leading spaces
16531 -- Loop through characters, changing any embedded
16532 -- sequence of spaces to a single null character (this
16533 -- is how Link_With/Linker_Options differ)
16536 if Get_String_Char
(S
, F
) = C
then
16539 Store_String_Char
(ASCII
.NUL
);
16542 Store_String_Char
(Get_String_Char
(S
, F
));
16550 if Present
(Arg
) then
16551 Store_String_Char
(ASCII
.NUL
);
16555 Store_Linker_Option_String
(End_String
);
16563 -- pragma Linker_Alias (
16564 -- [Entity =>] LOCAL_NAME
16565 -- [Target =>] static_string_EXPRESSION);
16567 when Pragma_Linker_Alias
=>
16569 Check_Arg_Order
((Name_Entity
, Name_Target
));
16570 Check_Arg_Count
(2);
16571 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16572 Check_Optional_Identifier
(Arg2
, Name_Target
);
16573 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
16574 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16576 -- The only processing required is to link this item on to the
16577 -- list of rep items for the given entity. This is accomplished
16578 -- by the call to Rep_Item_Too_Late (when no error is detected
16579 -- and False is returned).
16581 if Rep_Item_Too_Late
(Entity
(Get_Pragma_Arg
(Arg1
)), N
) then
16584 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
16587 ------------------------
16588 -- Linker_Constructor --
16589 ------------------------
16591 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
16593 -- Code is shared with Linker_Destructor
16595 -----------------------
16596 -- Linker_Destructor --
16597 -----------------------
16599 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
16601 when Pragma_Linker_Constructor |
16602 Pragma_Linker_Destructor
=>
16603 Linker_Constructor
: declare
16609 Check_Arg_Count
(1);
16610 Check_No_Identifiers
;
16611 Check_Arg_Is_Local_Name
(Arg1
);
16612 Arg1_X
:= Get_Pragma_Arg
(Arg1
);
16614 Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
16616 if not Is_Library_Level_Entity
(Proc
) then
16618 ("argument for pragma% must be library level entity", Arg1
);
16621 -- The only processing required is to link this item on to the
16622 -- list of rep items for the given entity. This is accomplished
16623 -- by the call to Rep_Item_Too_Late (when no error is detected
16624 -- and False is returned).
16626 if Rep_Item_Too_Late
(Proc
, N
) then
16629 Set_Has_Gigi_Rep_Item
(Proc
);
16631 end Linker_Constructor
;
16633 --------------------
16634 -- Linker_Options --
16635 --------------------
16637 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
16639 when Pragma_Linker_Options
=> Linker_Options
: declare
16643 Check_Ada_83_Warning
;
16644 Check_No_Identifiers
;
16645 Check_Arg_Count
(1);
16646 Check_Is_In_Decl_Part_Or_Package_Spec
;
16647 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16648 Start_String
(Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg1
))));
16651 while Present
(Arg
) loop
16652 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
16653 Store_String_Char
(ASCII
.NUL
);
16655 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
16659 if Operating_Mode
= Generate_Code
16660 and then In_Extended_Main_Source_Unit
(N
)
16662 Store_Linker_Option_String
(End_String
);
16664 end Linker_Options
;
16666 --------------------
16667 -- Linker_Section --
16668 --------------------
16670 -- pragma Linker_Section (
16671 -- [Entity =>] LOCAL_NAME
16672 -- [Section =>] static_string_EXPRESSION);
16674 when Pragma_Linker_Section
=> Linker_Section
: declare
16679 Ghost_Error_Posted
: Boolean := False;
16680 -- Flag set when an error concerning the illegal mix of Ghost and
16681 -- non-Ghost subprograms is emitted.
16683 Ghost_Id
: Entity_Id
:= Empty
;
16684 -- The entity of the first Ghost subprogram encountered while
16685 -- processing the arguments of the pragma.
16689 Check_Arg_Order
((Name_Entity
, Name_Section
));
16690 Check_Arg_Count
(2);
16691 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16692 Check_Optional_Identifier
(Arg2
, Name_Section
);
16693 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
16694 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16696 -- Check kind of entity
16698 Arg
:= Get_Pragma_Arg
(Arg1
);
16699 Ent
:= Entity
(Arg
);
16701 case Ekind
(Ent
) is
16703 -- Objects (constants and variables) and types. For these cases
16704 -- all we need to do is to set the Linker_Section_pragma field,
16705 -- checking that we do not have a duplicate.
16707 when E_Constant | E_Variable | Type_Kind
=>
16708 LPE
:= Linker_Section_Pragma
(Ent
);
16710 if Present
(LPE
) then
16711 Error_Msg_Sloc
:= Sloc
(LPE
);
16713 ("Linker_Section already specified for &#", Arg1
, Ent
);
16716 Set_Linker_Section_Pragma
(Ent
, N
);
16718 -- A pragma that applies to a Ghost entity becomes Ghost for
16719 -- the purposes of legality checks and removal of ignored
16722 Mark_Pragma_As_Ghost
(N
, Ent
);
16726 when Subprogram_Kind
=>
16728 -- Aspect case, entity already set
16730 if From_Aspect_Specification
(N
) then
16731 Set_Linker_Section_Pragma
16732 (Entity
(Corresponding_Aspect
(N
)), N
);
16734 -- Pragma case, we must climb the homonym chain, but skip
16735 -- any for which the linker section is already set.
16739 if No
(Linker_Section_Pragma
(Ent
)) then
16740 Set_Linker_Section_Pragma
(Ent
, N
);
16742 -- A pragma that applies to a Ghost entity becomes
16743 -- Ghost for the purposes of legality checks and
16744 -- removal of ignored Ghost code.
16746 Mark_Pragma_As_Ghost
(N
, Ent
);
16748 -- Capture the entity of the first Ghost subprogram
16749 -- being processed for error detection purposes.
16751 if Is_Ghost_Entity
(Ent
) then
16752 if No
(Ghost_Id
) then
16756 -- Otherwise the subprogram is non-Ghost. It is
16757 -- illegal to mix references to Ghost and non-Ghost
16758 -- entities (SPARK RM 6.9).
16760 elsif Present
(Ghost_Id
)
16761 and then not Ghost_Error_Posted
16763 Ghost_Error_Posted
:= True;
16765 Error_Msg_Name_1
:= Pname
;
16767 ("pragma % cannot mention ghost and "
16768 & "non-ghost subprograms", N
);
16770 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
16772 ("\& # declared as ghost", N
, Ghost_Id
);
16774 Error_Msg_Sloc
:= Sloc
(Ent
);
16776 ("\& # declared as non-ghost", N
, Ent
);
16780 Ent
:= Homonym
(Ent
);
16782 or else Scope
(Ent
) /= Current_Scope
;
16786 -- All other cases are illegal
16790 ("pragma% applies only to objects, subprograms, and types",
16793 end Linker_Section
;
16799 -- pragma List (On | Off)
16801 -- There is nothing to do here, since we did all the processing for
16802 -- this pragma in Par.Prag (so that it works properly even in syntax
16805 when Pragma_List
=>
16812 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16814 when Pragma_Lock_Free
=> Lock_Free
: declare
16815 P
: constant Node_Id
:= Parent
(N
);
16821 Check_No_Identifiers
;
16822 Check_At_Most_N_Arguments
(1);
16824 -- Protected definition case
16826 if Nkind
(P
) = N_Protected_Definition
then
16827 Ent
:= Defining_Identifier
(Parent
(P
));
16831 if Arg_Count
= 1 then
16832 Arg
:= Get_Pragma_Arg
(Arg1
);
16833 Val
:= Is_True
(Static_Boolean
(Arg
));
16835 -- No arguments (expression is considered to be True)
16841 -- Check duplicate pragma before we chain the pragma in the Rep
16842 -- Item chain of Ent.
16844 Check_Duplicate_Pragma
(Ent
);
16845 Record_Rep_Item
(Ent
, N
);
16846 Set_Uses_Lock_Free
(Ent
, Val
);
16848 -- Anything else is incorrect placement
16855 --------------------
16856 -- Locking_Policy --
16857 --------------------
16859 -- pragma Locking_Policy (policy_IDENTIFIER);
16861 when Pragma_Locking_Policy
=> declare
16862 subtype LP_Range
is Name_Id
16863 range First_Locking_Policy_Name
.. Last_Locking_Policy_Name
;
16868 Check_Ada_83_Warning
;
16869 Check_Arg_Count
(1);
16870 Check_No_Identifiers
;
16871 Check_Arg_Is_Locking_Policy
(Arg1
);
16872 Check_Valid_Configuration_Pragma
;
16873 LP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
16876 when Name_Ceiling_Locking
=>
16878 when Name_Inheritance_Locking
=>
16880 when Name_Concurrent_Readers_Locking
=>
16884 if Locking_Policy
/= ' '
16885 and then Locking_Policy
/= LP
16887 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
16888 Error_Pragma
("locking policy incompatible with policy#");
16890 -- Set new policy, but always preserve System_Location since we
16891 -- like the error message with the run time name.
16894 Locking_Policy
:= LP
;
16896 if Locking_Policy_Sloc
/= System_Location
then
16897 Locking_Policy_Sloc
:= Loc
;
16902 -------------------
16903 -- Loop_Optimize --
16904 -------------------
16906 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16908 -- OPTIMIZATION_HINT ::=
16909 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16911 when Pragma_Loop_Optimize
=> Loop_Optimize
: declare
16916 Check_At_Least_N_Arguments
(1);
16917 Check_No_Identifiers
;
16919 Hint
:= First
(Pragma_Argument_Associations
(N
));
16920 while Present
(Hint
) loop
16921 Check_Arg_Is_One_Of
(Hint
, Name_Ivdep
,
16929 Check_Loop_Pragma_Placement
;
16936 -- pragma Loop_Variant
16937 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16939 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16941 -- CHANGE_DIRECTION ::= Increases | Decreases
16943 when Pragma_Loop_Variant
=> Loop_Variant
: declare
16948 Check_At_Least_N_Arguments
(1);
16949 Check_Loop_Pragma_Placement
;
16951 -- Process all increasing / decreasing expressions
16953 Variant
:= First
(Pragma_Argument_Associations
(N
));
16954 while Present
(Variant
) loop
16955 if not Nam_In
(Chars
(Variant
), Name_Decreases
,
16958 Error_Pragma_Arg
("wrong change modifier", Variant
);
16961 Preanalyze_Assert_Expression
16962 (Expression
(Variant
), Any_Discrete
);
16968 -----------------------
16969 -- Machine_Attribute --
16970 -----------------------
16972 -- pragma Machine_Attribute (
16973 -- [Entity =>] LOCAL_NAME,
16974 -- [Attribute_Name =>] static_string_EXPRESSION
16975 -- [, [Info =>] static_EXPRESSION] );
16977 when Pragma_Machine_Attribute
=> Machine_Attribute
: declare
16978 Def_Id
: Entity_Id
;
16982 Check_Arg_Order
((Name_Entity
, Name_Attribute_Name
, Name_Info
));
16984 if Arg_Count
= 3 then
16985 Check_Optional_Identifier
(Arg3
, Name_Info
);
16986 Check_Arg_Is_OK_Static_Expression
(Arg3
);
16988 Check_Arg_Count
(2);
16991 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16992 Check_Optional_Identifier
(Arg2
, Name_Attribute_Name
);
16993 Check_Arg_Is_Local_Name
(Arg1
);
16994 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16995 Def_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
16997 if Is_Access_Type
(Def_Id
) then
16998 Def_Id
:= Designated_Type
(Def_Id
);
17001 if Rep_Item_Too_Early
(Def_Id
, N
) then
17005 Def_Id
:= Underlying_Type
(Def_Id
);
17007 -- The only processing required is to link this item on to the
17008 -- list of rep items for the given entity. This is accomplished
17009 -- by the call to Rep_Item_Too_Late (when no error is detected
17010 -- and False is returned).
17012 if Rep_Item_Too_Late
(Def_Id
, N
) then
17015 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
17017 end Machine_Attribute
;
17024 -- (MAIN_OPTION [, MAIN_OPTION]);
17027 -- [STACK_SIZE =>] static_integer_EXPRESSION
17028 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
17029 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
17031 when Pragma_Main
=> Main
: declare
17032 Args
: Args_List
(1 .. 3);
17033 Names
: constant Name_List
(1 .. 3) := (
17035 Name_Task_Stack_Size_Default
,
17036 Name_Time_Slicing_Enabled
);
17042 Gather_Associations
(Names
, Args
);
17044 for J
in 1 .. 2 loop
17045 if Present
(Args
(J
)) then
17046 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
17050 if Present
(Args
(3)) then
17051 Check_Arg_Is_OK_Static_Expression
(Args
(3), Standard_Boolean
);
17055 while Present
(Nod
) loop
17056 if Nkind
(Nod
) = N_Pragma
17057 and then Pragma_Name
(Nod
) = Name_Main
17059 Error_Msg_Name_1
:= Pname
;
17060 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
17071 -- pragma Main_Storage
17072 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
17074 -- MAIN_STORAGE_OPTION ::=
17075 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
17076 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
17078 when Pragma_Main_Storage
=> Main_Storage
: declare
17079 Args
: Args_List
(1 .. 2);
17080 Names
: constant Name_List
(1 .. 2) := (
17081 Name_Working_Storage
,
17088 Gather_Associations
(Names
, Args
);
17090 for J
in 1 .. 2 loop
17091 if Present
(Args
(J
)) then
17092 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
17096 Check_In_Main_Program
;
17099 while Present
(Nod
) loop
17100 if Nkind
(Nod
) = N_Pragma
17101 and then Pragma_Name
(Nod
) = Name_Main_Storage
17103 Error_Msg_Name_1
:= Pname
;
17104 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
17115 -- pragma Memory_Size (NUMERIC_LITERAL)
17117 when Pragma_Memory_Size
=>
17120 -- Memory size is simply ignored
17122 Check_No_Identifiers
;
17123 Check_Arg_Count
(1);
17124 Check_Arg_Is_Integer_Literal
(Arg1
);
17132 -- The only correct use of this pragma is on its own in a file, in
17133 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
17134 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
17135 -- check for a file containing nothing but a No_Body pragma). If we
17136 -- attempt to process it during normal semantics processing, it means
17137 -- it was misplaced.
17139 when Pragma_No_Body
=>
17143 -----------------------------
17144 -- No_Elaboration_Code_All --
17145 -----------------------------
17147 -- pragma No_Elaboration_Code_All;
17149 when Pragma_No_Elaboration_Code_All
=>
17151 Check_Valid_Library_Unit_Pragma
;
17153 if Nkind
(N
) = N_Null_Statement
then
17157 -- Must appear for a spec or generic spec
17159 if not Nkind_In
(Unit
(Cunit
(Current_Sem_Unit
)),
17160 N_Generic_Package_Declaration
,
17161 N_Generic_Subprogram_Declaration
,
17162 N_Package_Declaration
,
17163 N_Subprogram_Declaration
)
17167 ("pragma% can only occur for package "
17168 & "or subprogram spec"));
17171 -- Set flag in unit table
17173 Set_No_Elab_Code_All
(Current_Sem_Unit
);
17175 -- Set restriction No_Elaboration_Code if this is the main unit
17177 if Current_Sem_Unit
= Main_Unit
then
17178 Set_Restriction
(No_Elaboration_Code
, N
);
17181 -- If we are in the main unit or in an extended main source unit,
17182 -- then we also add it to the configuration restrictions so that
17183 -- it will apply to all units in the extended main source.
17185 if Current_Sem_Unit
= Main_Unit
17186 or else In_Extended_Main_Source_Unit
(N
)
17188 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
17191 -- If in main extended unit, activate transitive with test
17193 if In_Extended_Main_Source_Unit
(N
) then
17194 Opt
.No_Elab_Code_All_Pragma
:= N
;
17201 -- pragma No_Inline ( NAME {, NAME} );
17203 when Pragma_No_Inline
=>
17205 Process_Inline
(Suppressed
);
17211 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
17213 when Pragma_No_Return
=> No_Return
: declare
17219 Ghost_Error_Posted
: Boolean := False;
17220 -- Flag set when an error concerning the illegal mix of Ghost and
17221 -- non-Ghost subprograms is emitted.
17223 Ghost_Id
: Entity_Id
:= Empty
;
17224 -- The entity of the first Ghost procedure encountered while
17225 -- processing the arguments of the pragma.
17229 Check_At_Least_N_Arguments
(1);
17231 -- Loop through arguments of pragma
17234 while Present
(Arg
) loop
17235 Check_Arg_Is_Local_Name
(Arg
);
17236 Id
:= Get_Pragma_Arg
(Arg
);
17239 if not Is_Entity_Name
(Id
) then
17240 Error_Pragma_Arg
("entity name required", Arg
);
17243 if Etype
(Id
) = Any_Type
then
17247 -- Loop to find matching procedures
17253 and then Scope
(E
) = Current_Scope
17255 if Ekind_In
(E
, E_Procedure
, E_Generic_Procedure
) then
17258 -- A pragma that applies to a Ghost entity becomes Ghost
17259 -- for the purposes of legality checks and removal of
17260 -- ignored Ghost code.
17262 Mark_Pragma_As_Ghost
(N
, E
);
17264 -- Capture the entity of the first Ghost procedure being
17265 -- processed for error detection purposes.
17267 if Is_Ghost_Entity
(E
) then
17268 if No
(Ghost_Id
) then
17272 -- Otherwise the subprogram is non-Ghost. It is illegal
17273 -- to mix references to Ghost and non-Ghost entities
17276 elsif Present
(Ghost_Id
)
17277 and then not Ghost_Error_Posted
17279 Ghost_Error_Posted
:= True;
17281 Error_Msg_Name_1
:= Pname
;
17283 ("pragma % cannot mention ghost and non-ghost "
17284 & "procedures", N
);
17286 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
17287 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
17289 Error_Msg_Sloc
:= Sloc
(E
);
17290 Error_Msg_NE
("\& # declared as non-ghost", N
, E
);
17293 -- Set flag on any alias as well
17295 if Is_Overloadable
(E
) and then Present
(Alias
(E
)) then
17296 Set_No_Return
(Alias
(E
));
17302 exit when From_Aspect_Specification
(N
);
17306 -- If entity in not in current scope it may be the enclosing
17307 -- suprogram body to which the aspect applies.
17310 if Entity
(Id
) = Current_Scope
17311 and then From_Aspect_Specification
(N
)
17313 Set_No_Return
(Entity
(Id
));
17315 Error_Pragma_Arg
("no procedure& found for pragma%", Arg
);
17327 -- pragma No_Run_Time;
17329 -- Note: this pragma is retained for backwards compatibility. See
17330 -- body of Rtsfind for full details on its handling.
17332 when Pragma_No_Run_Time
=>
17334 Check_Valid_Configuration_Pragma
;
17335 Check_Arg_Count
(0);
17337 No_Run_Time_Mode
:= True;
17338 Configurable_Run_Time_Mode
:= True;
17340 -- Set Duration to 32 bits if word size is 32
17342 if Ttypes
.System_Word_Size
= 32 then
17343 Duration_32_Bits_On_Target
:= True;
17346 -- Set appropriate restrictions
17348 Set_Restriction
(No_Finalization
, N
);
17349 Set_Restriction
(No_Exception_Handlers
, N
);
17350 Set_Restriction
(Max_Tasks
, N
, 0);
17351 Set_Restriction
(No_Tasking
, N
);
17353 -----------------------
17354 -- No_Tagged_Streams --
17355 -----------------------
17357 -- pragma No_Tagged_Streams;
17358 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
17360 when Pragma_No_Tagged_Streams
=> No_Tagged_Strms
: declare
17366 Check_At_Most_N_Arguments
(1);
17368 -- One argument case
17370 if Arg_Count
= 1 then
17371 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17372 Check_Arg_Is_Local_Name
(Arg1
);
17373 E_Id
:= Get_Pragma_Arg
(Arg1
);
17375 if Etype
(E_Id
) = Any_Type
then
17379 E
:= Entity
(E_Id
);
17381 Check_Duplicate_Pragma
(E
);
17383 if not Is_Tagged_Type
(E
) or else Is_Derived_Type
(E
) then
17385 ("argument for pragma% must be root tagged type", Arg1
);
17388 if Rep_Item_Too_Early
(E
, N
)
17390 Rep_Item_Too_Late
(E
, N
)
17394 Set_No_Tagged_Streams_Pragma
(E
, N
);
17397 -- Zero argument case
17400 Check_Is_In_Decl_Part_Or_Package_Spec
;
17401 No_Tagged_Streams
:= N
;
17403 end No_Tagged_Strms
;
17405 ------------------------
17406 -- No_Strict_Aliasing --
17407 ------------------------
17409 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
17411 when Pragma_No_Strict_Aliasing
=> No_Strict_Aliasing
: declare
17416 Check_At_Most_N_Arguments
(1);
17418 if Arg_Count
= 0 then
17419 Check_Valid_Configuration_Pragma
;
17420 Opt
.No_Strict_Aliasing
:= True;
17423 Check_Optional_Identifier
(Arg2
, Name_Entity
);
17424 Check_Arg_Is_Local_Name
(Arg1
);
17425 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
17427 if E_Id
= Any_Type
then
17429 elsif No
(E_Id
) or else not Is_Access_Type
(E_Id
) then
17430 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
17433 Set_No_Strict_Aliasing
(Implementation_Base_Type
(E_Id
));
17435 end No_Strict_Aliasing
;
17437 -----------------------
17438 -- Normalize_Scalars --
17439 -----------------------
17441 -- pragma Normalize_Scalars;
17443 when Pragma_Normalize_Scalars
=>
17444 Check_Ada_83_Warning
;
17445 Check_Arg_Count
(0);
17446 Check_Valid_Configuration_Pragma
;
17448 -- Normalize_Scalars creates false positives in CodePeer, and
17449 -- incorrect negative results in GNATprove mode, so ignore this
17450 -- pragma in these modes.
17452 if not (CodePeer_Mode
or GNATprove_Mode
) then
17453 Normalize_Scalars
:= True;
17454 Init_Or_Norm_Scalars
:= True;
17461 -- pragma Obsolescent;
17463 -- pragma Obsolescent (
17464 -- [Message =>] static_string_EXPRESSION
17465 -- [,[Version =>] Ada_05]]);
17467 -- pragma Obsolescent (
17468 -- [Entity =>] NAME
17469 -- [,[Message =>] static_string_EXPRESSION
17470 -- [,[Version =>] Ada_05]] );
17472 when Pragma_Obsolescent
=> Obsolescent
: declare
17476 procedure Set_Obsolescent
(E
: Entity_Id
);
17477 -- Given an entity Ent, mark it as obsolescent if appropriate
17479 ---------------------
17480 -- Set_Obsolescent --
17481 ---------------------
17483 procedure Set_Obsolescent
(E
: Entity_Id
) is
17492 -- A pragma that applies to a Ghost entity becomes Ghost for
17493 -- the purposes of legality checks and removal of ignored Ghost
17496 Mark_Pragma_As_Ghost
(N
, E
);
17498 -- Entity name was given
17500 if Present
(Ename
) then
17502 -- If entity name matches, we are fine. Save entity in
17503 -- pragma argument, for ASIS use.
17505 if Chars
(Ename
) = Chars
(Ent
) then
17506 Set_Entity
(Ename
, Ent
);
17507 Generate_Reference
(Ent
, Ename
);
17509 -- If entity name does not match, only possibility is an
17510 -- enumeration literal from an enumeration type declaration.
17512 elsif Ekind
(Ent
) /= E_Enumeration_Type
then
17514 ("pragma % entity name does not match declaration");
17517 Ent
:= First_Literal
(E
);
17521 ("pragma % entity name does not match any "
17522 & "enumeration literal");
17524 elsif Chars
(Ent
) = Chars
(Ename
) then
17525 Set_Entity
(Ename
, Ent
);
17526 Generate_Reference
(Ent
, Ename
);
17530 Ent
:= Next_Literal
(Ent
);
17536 -- Ent points to entity to be marked
17538 if Arg_Count
>= 1 then
17540 -- Deal with static string argument
17542 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
17543 S
:= Strval
(Get_Pragma_Arg
(Arg1
));
17545 for J
in 1 .. String_Length
(S
) loop
17546 if not In_Character_Range
(Get_String_Char
(S
, J
)) then
17548 ("pragma% argument does not allow wide characters",
17553 Obsolescent_Warnings
.Append
17554 ((Ent
=> Ent
, Msg
=> Strval
(Get_Pragma_Arg
(Arg1
))));
17556 -- Check for Ada_05 parameter
17558 if Arg_Count
/= 1 then
17559 Check_Arg_Count
(2);
17562 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
17565 Check_Arg_Is_Identifier
(Argx
);
17567 if Chars
(Argx
) /= Name_Ada_05
then
17568 Error_Msg_Name_2
:= Name_Ada_05
;
17570 ("only allowed argument for pragma% is %", Argx
);
17573 if Ada_Version_Explicit
< Ada_2005
17574 or else not Warn_On_Ada_2005_Compatibility
17582 -- Set flag if pragma active
17585 Set_Is_Obsolescent
(Ent
);
17589 end Set_Obsolescent
;
17591 -- Start of processing for pragma Obsolescent
17596 Check_At_Most_N_Arguments
(3);
17598 -- See if first argument specifies an entity name
17602 (Chars
(Arg1
) = Name_Entity
17604 Nkind_In
(Get_Pragma_Arg
(Arg1
), N_Character_Literal
,
17606 N_Operator_Symbol
))
17608 Ename
:= Get_Pragma_Arg
(Arg1
);
17610 -- Eliminate first argument, so we can share processing
17614 Arg_Count
:= Arg_Count
- 1;
17616 -- No Entity name argument given
17622 if Arg_Count
>= 1 then
17623 Check_Optional_Identifier
(Arg1
, Name_Message
);
17625 if Arg_Count
= 2 then
17626 Check_Optional_Identifier
(Arg2
, Name_Version
);
17630 -- Get immediately preceding declaration
17633 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
17637 -- Cases where we do not follow anything other than another pragma
17641 -- First case: library level compilation unit declaration with
17642 -- the pragma immediately following the declaration.
17644 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
17646 (Defining_Entity
(Unit
(Parent
(Parent
(N
)))));
17649 -- Case 2: library unit placement for package
17653 Ent
: constant Entity_Id
:= Find_Lib_Unit_Name
;
17655 if Is_Package_Or_Generic_Package
(Ent
) then
17656 Set_Obsolescent
(Ent
);
17662 -- Cases where we must follow a declaration, including an
17663 -- abstract subprogram declaration, which is not in the
17664 -- other node subtypes.
17667 if Nkind
(Decl
) not in N_Declaration
17668 and then Nkind
(Decl
) not in N_Later_Decl_Item
17669 and then Nkind
(Decl
) not in N_Generic_Declaration
17670 and then Nkind
(Decl
) not in N_Renaming_Declaration
17671 and then Nkind
(Decl
) /= N_Abstract_Subprogram_Declaration
17674 ("pragma% misplaced, "
17675 & "must immediately follow a declaration");
17678 Set_Obsolescent
(Defining_Entity
(Decl
));
17688 -- pragma Optimize (Time | Space | Off);
17690 -- The actual check for optimize is done in Gigi. Note that this
17691 -- pragma does not actually change the optimization setting, it
17692 -- simply checks that it is consistent with the pragma.
17694 when Pragma_Optimize
=>
17695 Check_No_Identifiers
;
17696 Check_Arg_Count
(1);
17697 Check_Arg_Is_One_Of
(Arg1
, Name_Time
, Name_Space
, Name_Off
);
17699 ------------------------
17700 -- Optimize_Alignment --
17701 ------------------------
17703 -- pragma Optimize_Alignment (Time | Space | Off);
17705 when Pragma_Optimize_Alignment
=> Optimize_Alignment
: begin
17707 Check_No_Identifiers
;
17708 Check_Arg_Count
(1);
17709 Check_Valid_Configuration_Pragma
;
17712 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
17716 Opt
.Optimize_Alignment
:= 'T';
17718 Opt
.Optimize_Alignment
:= 'S';
17720 Opt
.Optimize_Alignment
:= 'O';
17722 Error_Pragma_Arg
("invalid argument for pragma%", Arg1
);
17726 -- Set indication that mode is set locally. If we are in fact in a
17727 -- configuration pragma file, this setting is harmless since the
17728 -- switch will get reset anyway at the start of each unit.
17730 Optimize_Alignment_Local
:= True;
17731 end Optimize_Alignment
;
17737 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
17739 when Pragma_Ordered
=> Ordered
: declare
17740 Assoc
: constant Node_Id
:= Arg1
;
17746 Check_No_Identifiers
;
17747 Check_Arg_Count
(1);
17748 Check_Arg_Is_Local_Name
(Arg1
);
17750 Type_Id
:= Get_Pragma_Arg
(Assoc
);
17751 Find_Type
(Type_Id
);
17752 Typ
:= Entity
(Type_Id
);
17754 if Typ
= Any_Type
then
17757 Typ
:= Underlying_Type
(Typ
);
17760 if not Is_Enumeration_Type
(Typ
) then
17761 Error_Pragma
("pragma% must specify enumeration type");
17764 Check_First_Subtype
(Arg1
);
17765 Set_Has_Pragma_Ordered
(Base_Type
(Typ
));
17768 -------------------
17769 -- Overflow_Mode --
17770 -------------------
17772 -- pragma Overflow_Mode
17773 -- ([General => ] MODE [, [Assertions => ] MODE]);
17775 -- MODE := STRICT | MINIMIZED | ELIMINATED
17777 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
17778 -- since System.Bignums makes this assumption. This is true of nearly
17779 -- all (all?) targets.
17781 when Pragma_Overflow_Mode
=> Overflow_Mode
: declare
17782 function Get_Overflow_Mode
17784 Arg
: Node_Id
) return Overflow_Mode_Type
;
17785 -- Function to process one pragma argument, Arg. If an identifier
17786 -- is present, it must be Name. Mode type is returned if a valid
17787 -- argument exists, otherwise an error is signalled.
17789 -----------------------
17790 -- Get_Overflow_Mode --
17791 -----------------------
17793 function Get_Overflow_Mode
17795 Arg
: Node_Id
) return Overflow_Mode_Type
17797 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
17800 Check_Optional_Identifier
(Arg
, Name
);
17801 Check_Arg_Is_Identifier
(Argx
);
17803 if Chars
(Argx
) = Name_Strict
then
17806 elsif Chars
(Argx
) = Name_Minimized
then
17809 elsif Chars
(Argx
) = Name_Eliminated
then
17810 if Ttypes
.Standard_Long_Long_Integer_Size
/= 64 then
17812 ("Eliminated not implemented on this target", Argx
);
17818 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
17820 end Get_Overflow_Mode
;
17822 -- Start of processing for Overflow_Mode
17826 Check_At_Least_N_Arguments
(1);
17827 Check_At_Most_N_Arguments
(2);
17829 -- Process first argument
17831 Scope_Suppress
.Overflow_Mode_General
:=
17832 Get_Overflow_Mode
(Name_General
, Arg1
);
17834 -- Case of only one argument
17836 if Arg_Count
= 1 then
17837 Scope_Suppress
.Overflow_Mode_Assertions
:=
17838 Scope_Suppress
.Overflow_Mode_General
;
17840 -- Case of two arguments present
17843 Scope_Suppress
.Overflow_Mode_Assertions
:=
17844 Get_Overflow_Mode
(Name_Assertions
, Arg2
);
17848 --------------------------
17849 -- Overriding Renamings --
17850 --------------------------
17852 -- pragma Overriding_Renamings;
17854 when Pragma_Overriding_Renamings
=>
17856 Check_Arg_Count
(0);
17857 Check_Valid_Configuration_Pragma
;
17858 Overriding_Renamings
:= True;
17864 -- pragma Pack (first_subtype_LOCAL_NAME);
17866 when Pragma_Pack
=> Pack
: declare
17867 Assoc
: constant Node_Id
:= Arg1
;
17869 Ignore
: Boolean := False;
17874 Check_No_Identifiers
;
17875 Check_Arg_Count
(1);
17876 Check_Arg_Is_Local_Name
(Arg1
);
17877 Type_Id
:= Get_Pragma_Arg
(Assoc
);
17879 if not Is_Entity_Name
(Type_Id
)
17880 or else not Is_Type
(Entity
(Type_Id
))
17883 ("argument for pragma% must be type or subtype", Arg1
);
17886 Find_Type
(Type_Id
);
17887 Typ
:= Entity
(Type_Id
);
17890 or else Rep_Item_Too_Early
(Typ
, N
)
17894 Typ
:= Underlying_Type
(Typ
);
17897 -- A pragma that applies to a Ghost entity becomes Ghost for the
17898 -- purposes of legality checks and removal of ignored Ghost code.
17900 Mark_Pragma_As_Ghost
(N
, Typ
);
17902 if not Is_Array_Type
(Typ
) and then not Is_Record_Type
(Typ
) then
17903 Error_Pragma
("pragma% must specify array or record type");
17906 Check_First_Subtype
(Arg1
);
17907 Check_Duplicate_Pragma
(Typ
);
17911 if Is_Array_Type
(Typ
) then
17912 Ctyp
:= Component_Type
(Typ
);
17914 -- Ignore pack that does nothing
17916 if Known_Static_Esize
(Ctyp
)
17917 and then Known_Static_RM_Size
(Ctyp
)
17918 and then Esize
(Ctyp
) = RM_Size
(Ctyp
)
17919 and then Addressable
(Esize
(Ctyp
))
17924 -- Process OK pragma Pack. Note that if there is a separate
17925 -- component clause present, the Pack will be cancelled. This
17926 -- processing is in Freeze.
17928 if not Rep_Item_Too_Late
(Typ
, N
) then
17930 -- In CodePeer mode, we do not need complex front-end
17931 -- expansions related to pragma Pack, so disable handling
17934 if CodePeer_Mode
then
17937 -- Normal case where we do the pack action
17941 Set_Is_Packed
(Base_Type
(Typ
));
17942 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
17945 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
17949 -- For record types, the pack is always effective
17951 else pragma Assert
(Is_Record_Type
(Typ
));
17952 if not Rep_Item_Too_Late
(Typ
, N
) then
17953 Set_Is_Packed
(Base_Type
(Typ
));
17954 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
17955 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
17966 -- There is nothing to do here, since we did all the processing for
17967 -- this pragma in Par.Prag (so that it works properly even in syntax
17970 when Pragma_Page
=>
17977 -- pragma Part_Of (ABSTRACT_STATE);
17979 -- ABSTRACT_STATE ::= NAME
17981 when Pragma_Part_Of
=> Part_Of
: declare
17982 procedure Propagate_Part_Of
17983 (Pack_Id
: Entity_Id
;
17984 State_Id
: Entity_Id
;
17985 Instance
: Node_Id
);
17986 -- Propagate the Part_Of indicator to all abstract states and
17987 -- objects declared in the visible state space of a package
17988 -- denoted by Pack_Id. State_Id is the encapsulating state.
17989 -- Instance is the package instantiation node.
17991 -----------------------
17992 -- Propagate_Part_Of --
17993 -----------------------
17995 procedure Propagate_Part_Of
17996 (Pack_Id
: Entity_Id
;
17997 State_Id
: Entity_Id
;
17998 Instance
: Node_Id
)
18000 Has_Item
: Boolean := False;
18001 -- Flag set when the visible state space contains at least one
18002 -- abstract state or variable.
18004 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
);
18005 -- Propagate the Part_Of indicator to all abstract states and
18006 -- objects declared in the visible state space of a package
18007 -- denoted by Pack_Id.
18009 -----------------------
18010 -- Propagate_Part_Of --
18011 -----------------------
18013 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
) is
18014 Item_Id
: Entity_Id
;
18017 -- Traverse the entity chain of the package and set relevant
18018 -- attributes of abstract states and objects declared in the
18019 -- visible state space of the package.
18021 Item_Id
:= First_Entity
(Pack_Id
);
18022 while Present
(Item_Id
)
18023 and then not In_Private_Part
(Item_Id
)
18025 -- Do not consider internally generated items
18027 if not Comes_From_Source
(Item_Id
) then
18030 -- The Part_Of indicator turns an abstract state or an
18031 -- object into a constituent of the encapsulating state.
18033 elsif Ekind_In
(Item_Id
, E_Abstract_State
,
18039 Append_Elmt
(Item_Id
, Part_Of_Constituents
(State_Id
));
18040 Set_Encapsulating_State
(Item_Id
, State_Id
);
18042 -- Recursively handle nested packages and instantiations
18044 elsif Ekind
(Item_Id
) = E_Package
then
18045 Propagate_Part_Of
(Item_Id
);
18048 Next_Entity
(Item_Id
);
18050 end Propagate_Part_Of
;
18052 -- Start of processing for Propagate_Part_Of
18055 Propagate_Part_Of
(Pack_Id
);
18057 -- Detect a package instantiation that is subject to a Part_Of
18058 -- indicator, but has no visible state.
18060 if not Has_Item
then
18062 ("package instantiation & has Part_Of indicator but "
18063 & "lacks visible state", Instance
, Pack_Id
);
18065 end Propagate_Part_Of
;
18070 Encap_Id
: Entity_Id
;
18071 Item_Id
: Entity_Id
;
18075 -- Start of processing for Part_Of
18079 Check_No_Identifiers
;
18080 Check_Arg_Count
(1);
18082 Stmt
:= Find_Related_Context
(N
, Do_Checks
=> True);
18084 -- Object declaration
18086 if Nkind
(Stmt
) = N_Object_Declaration
then
18089 -- Package instantiation
18091 elsif Nkind
(Stmt
) = N_Package_Instantiation
then
18094 -- Single concurrent type declaration
18096 elsif Is_Single_Concurrent_Type_Declaration
(Stmt
) then
18099 -- Otherwise the pragma is associated with an illegal construct
18106 -- Extract the entity of the related object declaration or package
18107 -- instantiation. In the case of the instantiation, use the entity
18108 -- of the instance spec.
18110 if Nkind
(Stmt
) = N_Package_Instantiation
then
18111 Stmt
:= Instance_Spec
(Stmt
);
18114 Item_Id
:= Defining_Entity
(Stmt
);
18115 Encap
:= Get_Pragma_Arg
(Arg1
);
18117 -- A pragma that applies to a Ghost entity becomes Ghost for the
18118 -- purposes of legality checks and removal of ignored Ghost code.
18120 Mark_Pragma_As_Ghost
(N
, Item_Id
);
18122 -- Chain the pragma on the contract for further processing by
18123 -- Analyze_Part_Of_In_Decl_Part or for completeness.
18125 Add_Contract_Item
(N
, Item_Id
);
18127 -- A variable may act as consituent of a single concurrent type
18128 -- which in turn could be declared after the variable. Due to this
18129 -- discrepancy, the full analysis of indicator Part_Of is delayed
18130 -- until the end of the enclosing declarative region (see routine
18131 -- Analyze_Part_Of_In_Decl_Part).
18133 if Ekind
(Item_Id
) = E_Variable
then
18136 -- Otherwise indicator Part_Of applies to a constant or a package
18140 -- Detect any discrepancies between the placement of the
18141 -- constant or package instantiation with respect to state
18142 -- space and the encapsulating state.
18146 Item_Id
=> Item_Id
,
18148 Encap_Id
=> Encap_Id
,
18152 pragma Assert
(Present
(Encap_Id
));
18154 if Ekind
(Item_Id
) = E_Constant
then
18155 Append_Elmt
(Item_Id
, Part_Of_Constituents
(Encap_Id
));
18156 Set_Encapsulating_State
(Item_Id
, Encap_Id
);
18158 -- Propagate the Part_Of indicator to the visible state
18159 -- space of the package instantiation.
18163 (Pack_Id
=> Item_Id
,
18164 State_Id
=> Encap_Id
,
18171 ----------------------------------
18172 -- Partition_Elaboration_Policy --
18173 ----------------------------------
18175 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
18177 when Pragma_Partition_Elaboration_Policy
=> declare
18178 subtype PEP_Range
is Name_Id
18179 range First_Partition_Elaboration_Policy_Name
18180 .. Last_Partition_Elaboration_Policy_Name
;
18181 PEP_Val
: PEP_Range
;
18186 Check_Arg_Count
(1);
18187 Check_No_Identifiers
;
18188 Check_Arg_Is_Partition_Elaboration_Policy
(Arg1
);
18189 Check_Valid_Configuration_Pragma
;
18190 PEP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
18193 when Name_Concurrent
=>
18195 when Name_Sequential
=>
18199 if Partition_Elaboration_Policy
/= ' '
18200 and then Partition_Elaboration_Policy
/= PEP
18202 Error_Msg_Sloc
:= Partition_Elaboration_Policy_Sloc
;
18204 ("partition elaboration policy incompatible with policy#");
18206 -- Set new policy, but always preserve System_Location since we
18207 -- like the error message with the run time name.
18210 Partition_Elaboration_Policy
:= PEP
;
18212 if Partition_Elaboration_Policy_Sloc
/= System_Location
then
18213 Partition_Elaboration_Policy_Sloc
:= Loc
;
18222 -- pragma Passive [(PASSIVE_FORM)];
18224 -- PASSIVE_FORM ::= Semaphore | No
18226 when Pragma_Passive
=>
18229 if Nkind
(Parent
(N
)) /= N_Task_Definition
then
18230 Error_Pragma
("pragma% must be within task definition");
18233 if Arg_Count
/= 0 then
18234 Check_Arg_Count
(1);
18235 Check_Arg_Is_One_Of
(Arg1
, Name_Semaphore
, Name_No
);
18238 ----------------------------------
18239 -- Preelaborable_Initialization --
18240 ----------------------------------
18242 -- pragma Preelaborable_Initialization (DIRECT_NAME);
18244 when Pragma_Preelaborable_Initialization
=> Preelab_Init
: declare
18249 Check_Arg_Count
(1);
18250 Check_No_Identifiers
;
18251 Check_Arg_Is_Identifier
(Arg1
);
18252 Check_Arg_Is_Local_Name
(Arg1
);
18253 Check_First_Subtype
(Arg1
);
18254 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
18256 -- A pragma that applies to a Ghost entity becomes Ghost for the
18257 -- purposes of legality checks and removal of ignored Ghost code.
18259 Mark_Pragma_As_Ghost
(N
, Ent
);
18261 -- The pragma may come from an aspect on a private declaration,
18262 -- even if the freeze point at which this is analyzed in the
18263 -- private part after the full view.
18265 if Has_Private_Declaration
(Ent
)
18266 and then From_Aspect_Specification
(N
)
18270 -- Check appropriate type argument
18272 elsif Is_Private_Type
(Ent
)
18273 or else Is_Protected_Type
(Ent
)
18274 or else (Is_Generic_Type
(Ent
) and then Is_Derived_Type
(Ent
))
18276 -- AI05-0028: The pragma applies to all composite types. Note
18277 -- that we apply this binding interpretation to earlier versions
18278 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
18279 -- choice since there are other compilers that do the same.
18281 or else Is_Composite_Type
(Ent
)
18287 ("pragma % can only be applied to private, formal derived, "
18288 & "protected, or composite type", Arg1
);
18291 -- Give an error if the pragma is applied to a protected type that
18292 -- does not qualify (due to having entries, or due to components
18293 -- that do not qualify).
18295 if Is_Protected_Type
(Ent
)
18296 and then not Has_Preelaborable_Initialization
(Ent
)
18299 ("protected type & does not have preelaborable "
18300 & "initialization", Ent
);
18302 -- Otherwise mark the type as definitely having preelaborable
18306 Set_Known_To_Have_Preelab_Init
(Ent
);
18309 if Has_Pragma_Preelab_Init
(Ent
)
18310 and then Warn_On_Redundant_Constructs
18312 Error_Pragma
("?r?duplicate pragma%!");
18314 Set_Has_Pragma_Preelab_Init
(Ent
);
18318 --------------------
18319 -- Persistent_BSS --
18320 --------------------
18322 -- pragma Persistent_BSS [(object_NAME)];
18324 when Pragma_Persistent_BSS
=> Persistent_BSS
: declare
18331 Check_At_Most_N_Arguments
(1);
18333 -- Case of application to specific object (one argument)
18335 if Arg_Count
= 1 then
18336 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
18338 if not Is_Entity_Name
(Get_Pragma_Arg
(Arg1
))
18340 Ekind_In
(Entity
(Get_Pragma_Arg
(Arg1
)), E_Variable
,
18343 Error_Pragma_Arg
("pragma% only applies to objects", Arg1
);
18346 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
18347 Decl
:= Parent
(Ent
);
18349 -- A pragma that applies to a Ghost entity becomes Ghost for
18350 -- the purposes of legality checks and removal of ignored Ghost
18353 Mark_Pragma_As_Ghost
(N
, Ent
);
18355 -- Check for duplication before inserting in list of
18356 -- representation items.
18358 Check_Duplicate_Pragma
(Ent
);
18360 if Rep_Item_Too_Late
(Ent
, N
) then
18364 if Present
(Expression
(Decl
)) then
18366 ("object for pragma% cannot have initialization", Arg1
);
18369 if not Is_Potentially_Persistent_Type
(Etype
(Ent
)) then
18371 ("object type for pragma% is not potentially persistent",
18376 Make_Linker_Section_Pragma
18377 (Ent
, Sloc
(N
), ".persistent.bss");
18378 Insert_After
(N
, Prag
);
18381 -- Case of use as configuration pragma with no arguments
18384 Check_Valid_Configuration_Pragma
;
18385 Persistent_BSS_Mode
:= True;
18387 end Persistent_BSS
;
18393 -- pragma Polling (ON | OFF);
18395 when Pragma_Polling
=>
18397 Check_Arg_Count
(1);
18398 Check_No_Identifiers
;
18399 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
18400 Polling_Required
:= (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
);
18402 -----------------------------------
18403 -- Post/Post_Class/Postcondition --
18404 -----------------------------------
18406 -- pragma Post (Boolean_EXPRESSION);
18407 -- pragma Post_Class (Boolean_EXPRESSION);
18408 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
18409 -- [,[Message =>] String_EXPRESSION]);
18411 -- Characteristics:
18413 -- * Analysis - The annotation undergoes initial checks to verify
18414 -- the legal placement and context. Secondary checks preanalyze the
18417 -- Analyze_Pre_Post_Condition_In_Decl_Part
18419 -- * Expansion - The annotation is expanded during the expansion of
18420 -- the related subprogram [body] contract as performed in:
18422 -- Expand_Subprogram_Contract
18424 -- * Template - The annotation utilizes the generic template of the
18425 -- related subprogram [body] when it is:
18427 -- aspect on subprogram declaration
18428 -- aspect on stand alone subprogram body
18429 -- pragma on stand alone subprogram body
18431 -- The annotation must prepare its own template when it is:
18433 -- pragma on subprogram declaration
18435 -- * Globals - Capture of global references must occur after full
18438 -- * Instance - The annotation is instantiated automatically when
18439 -- the related generic subprogram [body] is instantiated except for
18440 -- the "pragma on subprogram declaration" case. In that scenario
18441 -- the annotation must instantiate itself.
18444 Pragma_Post_Class |
18445 Pragma_Postcondition
=>
18446 Analyze_Pre_Post_Condition
;
18448 --------------------------------
18449 -- Pre/Pre_Class/Precondition --
18450 --------------------------------
18452 -- pragma Pre (Boolean_EXPRESSION);
18453 -- pragma Pre_Class (Boolean_EXPRESSION);
18454 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
18455 -- [,[Message =>] String_EXPRESSION]);
18457 -- Characteristics:
18459 -- * Analysis - The annotation undergoes initial checks to verify
18460 -- the legal placement and context. Secondary checks preanalyze the
18463 -- Analyze_Pre_Post_Condition_In_Decl_Part
18465 -- * Expansion - The annotation is expanded during the expansion of
18466 -- the related subprogram [body] contract as performed in:
18468 -- Expand_Subprogram_Contract
18470 -- * Template - The annotation utilizes the generic template of the
18471 -- related subprogram [body] when it is:
18473 -- aspect on subprogram declaration
18474 -- aspect on stand alone subprogram body
18475 -- pragma on stand alone subprogram body
18477 -- The annotation must prepare its own template when it is:
18479 -- pragma on subprogram declaration
18481 -- * Globals - Capture of global references must occur after full
18484 -- * Instance - The annotation is instantiated automatically when
18485 -- the related generic subprogram [body] is instantiated except for
18486 -- the "pragma on subprogram declaration" case. In that scenario
18487 -- the annotation must instantiate itself.
18491 Pragma_Precondition
=>
18492 Analyze_Pre_Post_Condition
;
18498 -- pragma Predicate
18499 -- ([Entity =>] type_LOCAL_NAME,
18500 -- [Check =>] boolean_EXPRESSION);
18502 when Pragma_Predicate
=> Predicate
: declare
18509 Check_Arg_Count
(2);
18510 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18511 Check_Optional_Identifier
(Arg2
, Name_Check
);
18513 Check_Arg_Is_Local_Name
(Arg1
);
18515 Type_Id
:= Get_Pragma_Arg
(Arg1
);
18516 Find_Type
(Type_Id
);
18517 Typ
:= Entity
(Type_Id
);
18519 if Typ
= Any_Type
then
18523 -- A pragma that applies to a Ghost entity becomes Ghost for the
18524 -- purposes of legality checks and removal of ignored Ghost code.
18526 Mark_Pragma_As_Ghost
(N
, Typ
);
18528 -- The remaining processing is simply to link the pragma on to
18529 -- the rep item chain, for processing when the type is frozen.
18530 -- This is accomplished by a call to Rep_Item_Too_Late. We also
18531 -- mark the type as having predicates.
18533 Set_Has_Predicates
(Typ
);
18534 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
18537 -----------------------
18538 -- Predicate_Failure --
18539 -----------------------
18541 -- pragma Predicate_Failure
18542 -- ([Entity =>] type_LOCAL_NAME,
18543 -- [Message =>] string_EXPRESSION);
18545 when Pragma_Predicate_Failure
=> Predicate_Failure
: declare
18552 Check_Arg_Count
(2);
18553 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18554 Check_Optional_Identifier
(Arg2
, Name_Message
);
18556 Check_Arg_Is_Local_Name
(Arg1
);
18558 Type_Id
:= Get_Pragma_Arg
(Arg1
);
18559 Find_Type
(Type_Id
);
18560 Typ
:= Entity
(Type_Id
);
18562 if Typ
= Any_Type
then
18566 -- A pragma that applies to a Ghost entity becomes Ghost for the
18567 -- purposes of legality checks and removal of ignored Ghost code.
18569 Mark_Pragma_As_Ghost
(N
, Typ
);
18571 -- The remaining processing is simply to link the pragma on to
18572 -- the rep item chain, for processing when the type is frozen.
18573 -- This is accomplished by a call to Rep_Item_Too_Late.
18575 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
18576 end Predicate_Failure
;
18582 -- pragma Preelaborate [(library_unit_NAME)];
18584 -- Set the flag Is_Preelaborated of program unit name entity
18586 when Pragma_Preelaborate
=> Preelaborate
: declare
18587 Pa
: constant Node_Id
:= Parent
(N
);
18588 Pk
: constant Node_Kind
:= Nkind
(Pa
);
18592 Check_Ada_83_Warning
;
18593 Check_Valid_Library_Unit_Pragma
;
18595 if Nkind
(N
) = N_Null_Statement
then
18599 Ent
:= Find_Lib_Unit_Name
;
18601 -- A pragma that applies to a Ghost entity becomes Ghost for the
18602 -- purposes of legality checks and removal of ignored Ghost code.
18604 Mark_Pragma_As_Ghost
(N
, Ent
);
18605 Check_Duplicate_Pragma
(Ent
);
18607 -- This filters out pragmas inside generic parents that show up
18608 -- inside instantiations. Pragmas that come from aspects in the
18609 -- unit are not ignored.
18611 if Present
(Ent
) then
18612 if Pk
= N_Package_Specification
18613 and then Present
(Generic_Parent
(Pa
))
18614 and then not From_Aspect_Specification
(N
)
18619 if not Debug_Flag_U
then
18620 Set_Is_Preelaborated
(Ent
);
18621 Set_Suppress_Elaboration_Warnings
(Ent
);
18627 -------------------------------
18628 -- Prefix_Exception_Messages --
18629 -------------------------------
18631 -- pragma Prefix_Exception_Messages;
18633 when Pragma_Prefix_Exception_Messages
=>
18635 Check_Valid_Configuration_Pragma
;
18636 Check_Arg_Count
(0);
18637 Prefix_Exception_Messages
:= True;
18643 -- pragma Priority (EXPRESSION);
18645 when Pragma_Priority
=> Priority
: declare
18646 P
: constant Node_Id
:= Parent
(N
);
18651 Check_No_Identifiers
;
18652 Check_Arg_Count
(1);
18656 if Nkind
(P
) = N_Subprogram_Body
then
18657 Check_In_Main_Program
;
18659 Ent
:= Defining_Unit_Name
(Specification
(P
));
18661 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
18662 Ent
:= Defining_Identifier
(Ent
);
18665 Arg
:= Get_Pragma_Arg
(Arg1
);
18666 Analyze_And_Resolve
(Arg
, Standard_Integer
);
18670 if not Is_OK_Static_Expression
(Arg
) then
18671 Flag_Non_Static_Expr
18672 ("main subprogram priority is not static!", Arg
);
18675 -- If constraint error, then we already signalled an error
18677 elsif Raises_Constraint_Error
(Arg
) then
18680 -- Otherwise check in range except if Relaxed_RM_Semantics
18681 -- where we ignore the value if out of range.
18685 Val
: constant Uint
:= Expr_Value
(Arg
);
18687 if not Relaxed_RM_Semantics
18690 or else Val
> Expr_Value
(Expression
18691 (Parent
(RTE
(RE_Max_Priority
)))))
18694 ("main subprogram priority is out of range", Arg1
);
18697 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
18702 -- Load an arbitrary entity from System.Tasking.Stages or
18703 -- System.Tasking.Restricted.Stages (depending on the
18704 -- supported profile) to make sure that one of these packages
18705 -- is implicitly with'ed, since we need to have the tasking
18706 -- run time active for the pragma Priority to have any effect.
18707 -- Previously we with'ed the package System.Tasking, but this
18708 -- package does not trigger the required initialization of the
18709 -- run-time library.
18712 Discard
: Entity_Id
;
18713 pragma Warnings
(Off
, Discard
);
18715 if Restricted_Profile
then
18716 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
18718 Discard
:= RTE
(RE_Activate_Tasks
);
18722 -- Task or Protected, must be of type Integer
18724 elsif Nkind_In
(P
, N_Protected_Definition
, N_Task_Definition
) then
18725 Arg
:= Get_Pragma_Arg
(Arg1
);
18726 Ent
:= Defining_Identifier
(Parent
(P
));
18728 -- The expression must be analyzed in the special manner
18729 -- described in "Handling of Default and Per-Object
18730 -- Expressions" in sem.ads.
18732 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Any_Priority
));
18734 if not Is_OK_Static_Expression
(Arg
) then
18735 Check_Restriction
(Static_Priorities
, Arg
);
18738 -- Anything else is incorrect
18744 -- Check duplicate pragma before we chain the pragma in the Rep
18745 -- Item chain of Ent.
18747 Check_Duplicate_Pragma
(Ent
);
18748 Record_Rep_Item
(Ent
, N
);
18751 -----------------------------------
18752 -- Priority_Specific_Dispatching --
18753 -----------------------------------
18755 -- pragma Priority_Specific_Dispatching (
18756 -- policy_IDENTIFIER,
18757 -- first_priority_EXPRESSION,
18758 -- last_priority_EXPRESSION);
18760 when Pragma_Priority_Specific_Dispatching
=>
18761 Priority_Specific_Dispatching
: declare
18762 Prio_Id
: constant Entity_Id
:= RTE
(RE_Any_Priority
);
18763 -- This is the entity System.Any_Priority;
18766 Lower_Bound
: Node_Id
;
18767 Upper_Bound
: Node_Id
;
18773 Check_Arg_Count
(3);
18774 Check_No_Identifiers
;
18775 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
18776 Check_Valid_Configuration_Pragma
;
18777 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
18778 DP
:= Fold_Upper
(Name_Buffer
(1));
18780 Lower_Bound
:= Get_Pragma_Arg
(Arg2
);
18781 Check_Arg_Is_OK_Static_Expression
(Lower_Bound
, Standard_Integer
);
18782 Lower_Val
:= Expr_Value
(Lower_Bound
);
18784 Upper_Bound
:= Get_Pragma_Arg
(Arg3
);
18785 Check_Arg_Is_OK_Static_Expression
(Upper_Bound
, Standard_Integer
);
18786 Upper_Val
:= Expr_Value
(Upper_Bound
);
18788 -- It is not allowed to use Task_Dispatching_Policy and
18789 -- Priority_Specific_Dispatching in the same partition.
18791 if Task_Dispatching_Policy
/= ' ' then
18792 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
18794 ("pragma% incompatible with Task_Dispatching_Policy#");
18796 -- Check lower bound in range
18798 elsif Lower_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
18800 Lower_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
18803 ("first_priority is out of range", Arg2
);
18805 -- Check upper bound in range
18807 elsif Upper_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
18809 Upper_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
18812 ("last_priority is out of range", Arg3
);
18814 -- Check that the priority range is valid
18816 elsif Lower_Val
> Upper_Val
then
18818 ("last_priority_expression must be greater than or equal to "
18819 & "first_priority_expression");
18821 -- Store the new policy, but always preserve System_Location since
18822 -- we like the error message with the run-time name.
18825 -- Check overlapping in the priority ranges specified in other
18826 -- Priority_Specific_Dispatching pragmas within the same
18827 -- partition. We can only check those we know about.
18830 Specific_Dispatching
.First
.. Specific_Dispatching
.Last
18832 if Specific_Dispatching
.Table
(J
).First_Priority
in
18833 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
18834 or else Specific_Dispatching
.Table
(J
).Last_Priority
in
18835 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
18838 Specific_Dispatching
.Table
(J
).Pragma_Loc
;
18840 ("priority range overlaps with "
18841 & "Priority_Specific_Dispatching#");
18845 -- The use of Priority_Specific_Dispatching is incompatible
18846 -- with Task_Dispatching_Policy.
18848 if Task_Dispatching_Policy
/= ' ' then
18849 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
18851 ("Priority_Specific_Dispatching incompatible "
18852 & "with Task_Dispatching_Policy#");
18855 -- The use of Priority_Specific_Dispatching forces ceiling
18858 if Locking_Policy
/= ' ' and then Locking_Policy
/= 'C' then
18859 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
18861 ("Priority_Specific_Dispatching incompatible "
18862 & "with Locking_Policy#");
18864 -- Set the Ceiling_Locking policy, but preserve System_Location
18865 -- since we like the error message with the run time name.
18868 Locking_Policy
:= 'C';
18870 if Locking_Policy_Sloc
/= System_Location
then
18871 Locking_Policy_Sloc
:= Loc
;
18875 -- Add entry in the table
18877 Specific_Dispatching
.Append
18878 ((Dispatching_Policy
=> DP
,
18879 First_Priority
=> UI_To_Int
(Lower_Val
),
18880 Last_Priority
=> UI_To_Int
(Upper_Val
),
18881 Pragma_Loc
=> Loc
));
18883 end Priority_Specific_Dispatching
;
18889 -- pragma Profile (profile_IDENTIFIER);
18891 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18893 when Pragma_Profile
=>
18895 Check_Arg_Count
(1);
18896 Check_Valid_Configuration_Pragma
;
18897 Check_No_Identifiers
;
18900 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
18903 if Chars
(Argx
) = Name_Ravenscar
then
18904 Set_Ravenscar_Profile
(Ravenscar
, N
);
18906 elsif Chars
(Argx
) = Name_Gnat_Extended_Ravenscar
then
18907 Set_Ravenscar_Profile
(GNAT_Extended_Ravenscar
, N
);
18909 elsif Chars
(Argx
) = Name_Restricted
then
18910 Set_Profile_Restrictions
18912 N
, Warn
=> Treat_Restrictions_As_Warnings
);
18914 elsif Chars
(Argx
) = Name_Rational
then
18915 Set_Rational_Profile
;
18917 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
18918 Set_Profile_Restrictions
18919 (No_Implementation_Extensions
,
18920 N
, Warn
=> Treat_Restrictions_As_Warnings
);
18923 Error_Pragma_Arg
("& is not a valid profile", Argx
);
18927 ----------------------
18928 -- Profile_Warnings --
18929 ----------------------
18931 -- pragma Profile_Warnings (profile_IDENTIFIER);
18933 -- profile_IDENTIFIER => Restricted | Ravenscar
18935 when Pragma_Profile_Warnings
=>
18937 Check_Arg_Count
(1);
18938 Check_Valid_Configuration_Pragma
;
18939 Check_No_Identifiers
;
18942 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
18945 if Chars
(Argx
) = Name_Ravenscar
then
18946 Set_Profile_Restrictions
(Ravenscar
, N
, Warn
=> True);
18948 elsif Chars
(Argx
) = Name_Restricted
then
18949 Set_Profile_Restrictions
(Restricted
, N
, Warn
=> True);
18951 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
18952 Set_Profile_Restrictions
18953 (No_Implementation_Extensions
, N
, Warn
=> True);
18956 Error_Pragma_Arg
("& is not a valid profile", Argx
);
18960 --------------------------
18961 -- Propagate_Exceptions --
18962 --------------------------
18964 -- pragma Propagate_Exceptions;
18966 -- Note: this pragma is obsolete and has no effect
18968 when Pragma_Propagate_Exceptions
=>
18970 Check_Arg_Count
(0);
18972 if Warn_On_Obsolescent_Feature
then
18974 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18975 "and has no effect?j?", N
);
18978 -----------------------------
18979 -- Provide_Shift_Operators --
18980 -----------------------------
18982 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18984 when Pragma_Provide_Shift_Operators
=>
18985 Provide_Shift_Operators
: declare
18988 procedure Declare_Shift_Operator
(Nam
: Name_Id
);
18989 -- Insert declaration and pragma Instrinsic for named shift op
18991 ----------------------------
18992 -- Declare_Shift_Operator --
18993 ----------------------------
18995 procedure Declare_Shift_Operator
(Nam
: Name_Id
) is
19001 Make_Subprogram_Declaration
(Loc
,
19002 Make_Function_Specification
(Loc
,
19003 Defining_Unit_Name
=>
19004 Make_Defining_Identifier
(Loc
, Chars
=> Nam
),
19006 Result_Definition
=>
19007 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
)),
19009 Parameter_Specifications
=> New_List
(
19010 Make_Parameter_Specification
(Loc
,
19011 Defining_Identifier
=>
19012 Make_Defining_Identifier
(Loc
, Name_Value
),
19014 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
))),
19016 Make_Parameter_Specification
(Loc
,
19017 Defining_Identifier
=>
19018 Make_Defining_Identifier
(Loc
, Name_Amount
),
19020 New_Occurrence_Of
(Standard_Natural
, Loc
)))));
19024 Pragma_Identifier
=> Make_Identifier
(Loc
, Name_Import
),
19025 Pragma_Argument_Associations
=> New_List
(
19026 Make_Pragma_Argument_Association
(Loc
,
19027 Expression
=> Make_Identifier
(Loc
, Name_Intrinsic
)),
19028 Make_Pragma_Argument_Association
(Loc
,
19029 Expression
=> Make_Identifier
(Loc
, Nam
))));
19031 Insert_After
(N
, Import
);
19032 Insert_After
(N
, Func
);
19033 end Declare_Shift_Operator
;
19035 -- Start of processing for Provide_Shift_Operators
19039 Check_Arg_Count
(1);
19040 Check_Arg_Is_Local_Name
(Arg1
);
19042 Arg1
:= Get_Pragma_Arg
(Arg1
);
19044 -- We must have an entity name
19046 if not Is_Entity_Name
(Arg1
) then
19048 ("pragma % must apply to integer first subtype", Arg1
);
19051 -- If no Entity, means there was a prior error so ignore
19053 if Present
(Entity
(Arg1
)) then
19054 Ent
:= Entity
(Arg1
);
19056 -- Apply error checks
19058 if not Is_First_Subtype
(Ent
) then
19060 ("cannot apply pragma %",
19061 "\& is not a first subtype",
19064 elsif not Is_Integer_Type
(Ent
) then
19066 ("cannot apply pragma %",
19067 "\& is not an integer type",
19070 elsif Has_Shift_Operator
(Ent
) then
19072 ("cannot apply pragma %",
19073 "\& already has declared shift operators",
19076 elsif Is_Frozen
(Ent
) then
19078 ("pragma % appears too late",
19079 "\& is already frozen",
19083 -- Now declare the operators. We do this during analysis rather
19084 -- than expansion, since we want the operators available if we
19085 -- are operating in -gnatc or ASIS mode.
19087 Declare_Shift_Operator
(Name_Rotate_Left
);
19088 Declare_Shift_Operator
(Name_Rotate_Right
);
19089 Declare_Shift_Operator
(Name_Shift_Left
);
19090 Declare_Shift_Operator
(Name_Shift_Right
);
19091 Declare_Shift_Operator
(Name_Shift_Right_Arithmetic
);
19093 end Provide_Shift_Operators
;
19099 -- pragma Psect_Object (
19100 -- [Internal =>] LOCAL_NAME,
19101 -- [, [External =>] EXTERNAL_SYMBOL]
19102 -- [, [Size =>] EXTERNAL_SYMBOL]);
19104 when Pragma_Psect_Object | Pragma_Common_Object
=>
19105 Psect_Object
: declare
19106 Args
: Args_List
(1 .. 3);
19107 Names
: constant Name_List
(1 .. 3) := (
19112 Internal
: Node_Id
renames Args
(1);
19113 External
: Node_Id
renames Args
(2);
19114 Size
: Node_Id
renames Args
(3);
19116 Def_Id
: Entity_Id
;
19118 procedure Check_Arg
(Arg
: Node_Id
);
19119 -- Checks that argument is either a string literal or an
19120 -- identifier, and posts error message if not.
19126 procedure Check_Arg
(Arg
: Node_Id
) is
19128 if not Nkind_In
(Original_Node
(Arg
),
19133 ("inappropriate argument for pragma %", Arg
);
19137 -- Start of processing for Common_Object/Psect_Object
19141 Gather_Associations
(Names
, Args
);
19142 Process_Extended_Import_Export_Internal_Arg
(Internal
);
19144 Def_Id
:= Entity
(Internal
);
19146 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
19148 ("pragma% must designate an object", Internal
);
19151 Check_Arg
(Internal
);
19153 if Is_Imported
(Def_Id
) or else Is_Exported
(Def_Id
) then
19155 ("cannot use pragma% for imported/exported object",
19159 if Is_Concurrent_Type
(Etype
(Internal
)) then
19161 ("cannot specify pragma % for task/protected object",
19165 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
19167 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
19169 Error_Msg_N
("??duplicate Common/Psect_Object pragma", N
);
19172 if Ekind
(Def_Id
) = E_Constant
then
19174 ("cannot specify pragma % for a constant", Internal
);
19177 if Is_Record_Type
(Etype
(Internal
)) then
19183 Ent
:= First_Entity
(Etype
(Internal
));
19184 while Present
(Ent
) loop
19185 Decl
:= Declaration_Node
(Ent
);
19187 if Ekind
(Ent
) = E_Component
19188 and then Nkind
(Decl
) = N_Component_Declaration
19189 and then Present
(Expression
(Decl
))
19190 and then Warn_On_Export_Import
19193 ("?x?object for pragma % has defaults", Internal
);
19203 if Present
(Size
) then
19207 if Present
(External
) then
19208 Check_Arg_Is_External_Name
(External
);
19211 -- If all error tests pass, link pragma on to the rep item chain
19213 Record_Rep_Item
(Def_Id
, N
);
19220 -- pragma Pure [(library_unit_NAME)];
19222 when Pragma_Pure
=> Pure
: declare
19226 Check_Ada_83_Warning
;
19227 Check_Valid_Library_Unit_Pragma
;
19229 if Nkind
(N
) = N_Null_Statement
then
19233 Ent
:= Find_Lib_Unit_Name
;
19235 -- A pragma that applies to a Ghost entity becomes Ghost for the
19236 -- purposes of legality checks and removal of ignored Ghost code.
19238 Mark_Pragma_As_Ghost
(N
, Ent
);
19240 if not Debug_Flag_U
then
19242 Set_Has_Pragma_Pure
(Ent
);
19243 Set_Suppress_Elaboration_Warnings
(Ent
);
19247 -------------------
19248 -- Pure_Function --
19249 -------------------
19251 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
19253 when Pragma_Pure_Function
=> Pure_Function
: declare
19254 Def_Id
: Entity_Id
;
19257 Effective
: Boolean := False;
19261 Check_Arg_Count
(1);
19262 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19263 Check_Arg_Is_Local_Name
(Arg1
);
19264 E_Id
:= Get_Pragma_Arg
(Arg1
);
19266 if Error_Posted
(E_Id
) then
19270 -- Loop through homonyms (overloadings) of referenced entity
19272 E
:= Entity
(E_Id
);
19274 -- A pragma that applies to a Ghost entity becomes Ghost for the
19275 -- purposes of legality checks and removal of ignored Ghost code.
19277 Mark_Pragma_As_Ghost
(N
, E
);
19279 if Present
(E
) then
19281 Def_Id
:= Get_Base_Subprogram
(E
);
19283 if not Ekind_In
(Def_Id
, E_Function
,
19284 E_Generic_Function
,
19288 ("pragma% requires a function name", Arg1
);
19291 Set_Is_Pure
(Def_Id
);
19293 if not Has_Pragma_Pure_Function
(Def_Id
) then
19294 Set_Has_Pragma_Pure_Function
(Def_Id
);
19298 exit when From_Aspect_Specification
(N
);
19300 exit when No
(E
) or else Scope
(E
) /= Current_Scope
;
19304 and then Warn_On_Redundant_Constructs
19307 ("pragma Pure_Function on& is redundant?r?",
19313 --------------------
19314 -- Queuing_Policy --
19315 --------------------
19317 -- pragma Queuing_Policy (policy_IDENTIFIER);
19319 when Pragma_Queuing_Policy
=> declare
19323 Check_Ada_83_Warning
;
19324 Check_Arg_Count
(1);
19325 Check_No_Identifiers
;
19326 Check_Arg_Is_Queuing_Policy
(Arg1
);
19327 Check_Valid_Configuration_Pragma
;
19328 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
19329 QP
:= Fold_Upper
(Name_Buffer
(1));
19331 if Queuing_Policy
/= ' '
19332 and then Queuing_Policy
/= QP
19334 Error_Msg_Sloc
:= Queuing_Policy_Sloc
;
19335 Error_Pragma
("queuing policy incompatible with policy#");
19337 -- Set new policy, but always preserve System_Location since we
19338 -- like the error message with the run time name.
19341 Queuing_Policy
:= QP
;
19343 if Queuing_Policy_Sloc
/= System_Location
then
19344 Queuing_Policy_Sloc
:= Loc
;
19353 -- pragma Rational, for compatibility with foreign compiler
19355 when Pragma_Rational
=>
19356 Set_Rational_Profile
;
19358 ---------------------
19359 -- Refined_Depends --
19360 ---------------------
19362 -- pragma Refined_Depends (DEPENDENCY_RELATION);
19364 -- DEPENDENCY_RELATION ::=
19366 -- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE})
19368 -- DEPENDENCY_CLAUSE ::=
19369 -- OUTPUT_LIST =>[+] INPUT_LIST
19370 -- | NULL_DEPENDENCY_CLAUSE
19372 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
19374 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
19376 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
19378 -- OUTPUT ::= NAME | FUNCTION_RESULT
19381 -- where FUNCTION_RESULT is a function Result attribute_reference
19383 -- Characteristics:
19385 -- * Analysis - The annotation undergoes initial checks to verify
19386 -- the legal placement and context. Secondary checks fully analyze
19387 -- the dependency clauses/global list in:
19389 -- Analyze_Refined_Depends_In_Decl_Part
19391 -- * Expansion - None.
19393 -- * Template - The annotation utilizes the generic template of the
19394 -- related subprogram body.
19396 -- * Globals - Capture of global references must occur after full
19399 -- * Instance - The annotation is instantiated automatically when
19400 -- the related generic subprogram body is instantiated.
19402 when Pragma_Refined_Depends
=> Refined_Depends
: declare
19403 Body_Id
: Entity_Id
;
19405 Spec_Id
: Entity_Id
;
19408 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19412 -- Chain the pragma on the contract for further processing by
19413 -- Analyze_Refined_Depends_In_Decl_Part.
19415 Add_Contract_Item
(N
, Body_Id
);
19417 -- The legality checks of pragmas Refined_Depends and
19418 -- Refined_Global are affected by the SPARK mode in effect and
19419 -- the volatility of the context. In addition these two pragmas
19420 -- are subject to an inherent order:
19422 -- 1) Refined_Global
19423 -- 2) Refined_Depends
19425 -- Analyze all these pragmas in the order outlined above
19427 Analyze_If_Present
(Pragma_SPARK_Mode
);
19428 Analyze_If_Present
(Pragma_Volatile_Function
);
19429 Analyze_If_Present
(Pragma_Refined_Global
);
19430 Analyze_Refined_Depends_In_Decl_Part
(N
);
19432 end Refined_Depends
;
19434 --------------------
19435 -- Refined_Global --
19436 --------------------
19438 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
19440 -- GLOBAL_SPECIFICATION ::=
19443 -- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST})
19445 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
19447 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
19448 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
19449 -- GLOBAL_ITEM ::= NAME
19451 -- Characteristics:
19453 -- * Analysis - The annotation undergoes initial checks to verify
19454 -- the legal placement and context. Secondary checks fully analyze
19455 -- the dependency clauses/global list in:
19457 -- Analyze_Refined_Global_In_Decl_Part
19459 -- * Expansion - None.
19461 -- * Template - The annotation utilizes the generic template of the
19462 -- related subprogram body.
19464 -- * Globals - Capture of global references must occur after full
19467 -- * Instance - The annotation is instantiated automatically when
19468 -- the related generic subprogram body is instantiated.
19470 when Pragma_Refined_Global
=> Refined_Global
: declare
19471 Body_Id
: Entity_Id
;
19473 Spec_Id
: Entity_Id
;
19476 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19480 -- Chain the pragma on the contract for further processing by
19481 -- Analyze_Refined_Global_In_Decl_Part.
19483 Add_Contract_Item
(N
, Body_Id
);
19485 -- The legality checks of pragmas Refined_Depends and
19486 -- Refined_Global are affected by the SPARK mode in effect and
19487 -- the volatility of the context. In addition these two pragmas
19488 -- are subject to an inherent order:
19490 -- 1) Refined_Global
19491 -- 2) Refined_Depends
19493 -- Analyze all these pragmas in the order outlined above
19495 Analyze_If_Present
(Pragma_SPARK_Mode
);
19496 Analyze_If_Present
(Pragma_Volatile_Function
);
19497 Analyze_Refined_Global_In_Decl_Part
(N
);
19498 Analyze_If_Present
(Pragma_Refined_Depends
);
19500 end Refined_Global
;
19506 -- pragma Refined_Post (boolean_EXPRESSION);
19508 -- Characteristics:
19510 -- * Analysis - The annotation is fully analyzed immediately upon
19511 -- elaboration as it cannot forward reference entities.
19513 -- * Expansion - The annotation is expanded during the expansion of
19514 -- the related subprogram body contract as performed in:
19516 -- Expand_Subprogram_Contract
19518 -- * Template - The annotation utilizes the generic template of the
19519 -- related subprogram body.
19521 -- * Globals - Capture of global references must occur after full
19524 -- * Instance - The annotation is instantiated automatically when
19525 -- the related generic subprogram body is instantiated.
19527 when Pragma_Refined_Post
=> Refined_Post
: declare
19528 Body_Id
: Entity_Id
;
19530 Spec_Id
: Entity_Id
;
19533 Analyze_Refined_Depends_Global_Post
(Spec_Id
, Body_Id
, Legal
);
19535 -- Fully analyze the pragma when it appears inside a subprogram
19536 -- body because it cannot benefit from forward references.
19540 -- Chain the pragma on the contract for completeness
19542 Add_Contract_Item
(N
, Body_Id
);
19544 -- The legality checks of pragma Refined_Post are affected by
19545 -- the SPARK mode in effect and the volatility of the context.
19546 -- Analyze all pragmas in a specific order.
19548 Analyze_If_Present
(Pragma_SPARK_Mode
);
19549 Analyze_If_Present
(Pragma_Volatile_Function
);
19550 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
19552 -- Currently it is not possible to inline pre/postconditions on
19553 -- a subprogram subject to pragma Inline_Always.
19555 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
19559 -------------------
19560 -- Refined_State --
19561 -------------------
19563 -- pragma Refined_State (REFINEMENT_LIST);
19565 -- REFINEMENT_LIST ::=
19566 -- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
19568 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
19570 -- CONSTITUENT_LIST ::=
19573 -- | (CONSTITUENT {, CONSTITUENT})
19575 -- CONSTITUENT ::= object_NAME | state_NAME
19577 -- Characteristics:
19579 -- * Analysis - The annotation undergoes initial checks to verify
19580 -- the legal placement and context. Secondary checks preanalyze the
19581 -- refinement clauses in:
19583 -- Analyze_Refined_State_In_Decl_Part
19585 -- * Expansion - None.
19587 -- * Template - The annotation utilizes the template of the related
19590 -- * Globals - Capture of global references must occur after full
19593 -- * Instance - The annotation is instantiated automatically when
19594 -- the related generic package body is instantiated.
19596 when Pragma_Refined_State
=> Refined_State
: declare
19597 Pack_Decl
: Node_Id
;
19598 Spec_Id
: Entity_Id
;
19602 Check_No_Identifiers
;
19603 Check_Arg_Count
(1);
19605 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
19607 -- Ensure the proper placement of the pragma. Refined states must
19608 -- be associated with a package body.
19610 if Nkind
(Pack_Decl
) = N_Package_Body
then
19613 -- Otherwise the pragma is associated with an illegal construct
19620 Spec_Id
:= Corresponding_Spec
(Pack_Decl
);
19622 -- Chain the pragma on the contract for further processing by
19623 -- Analyze_Refined_State_In_Decl_Part.
19625 Add_Contract_Item
(N
, Defining_Entity
(Pack_Decl
));
19627 -- The legality checks of pragma Refined_State are affected by the
19628 -- SPARK mode in effect. Analyze all pragmas in a specific order.
19630 Analyze_If_Present
(Pragma_SPARK_Mode
);
19632 -- A pragma that applies to a Ghost entity becomes Ghost for the
19633 -- purposes of legality checks and removal of ignored Ghost code.
19635 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
19637 -- State refinement is allowed only when the corresponding package
19638 -- declaration has non-null pragma Abstract_State. Refinement not
19639 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
19641 if SPARK_Mode
/= Off
19643 (No
(Abstract_States
(Spec_Id
))
19644 or else Has_Null_Abstract_State
(Spec_Id
))
19647 ("useless refinement, package & does not define abstract "
19648 & "states", N
, Spec_Id
);
19653 -----------------------
19654 -- Relative_Deadline --
19655 -----------------------
19657 -- pragma Relative_Deadline (time_span_EXPRESSION);
19659 when Pragma_Relative_Deadline
=> Relative_Deadline
: declare
19660 P
: constant Node_Id
:= Parent
(N
);
19665 Check_No_Identifiers
;
19666 Check_Arg_Count
(1);
19668 Arg
:= Get_Pragma_Arg
(Arg1
);
19670 -- The expression must be analyzed in the special manner described
19671 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
19673 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
19677 if Nkind
(P
) = N_Subprogram_Body
then
19678 Check_In_Main_Program
;
19680 -- Only Task and subprogram cases allowed
19682 elsif Nkind
(P
) /= N_Task_Definition
then
19686 -- Check duplicate pragma before we set the corresponding flag
19688 if Has_Relative_Deadline_Pragma
(P
) then
19689 Error_Pragma
("duplicate pragma% not allowed");
19692 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
19693 -- Relative_Deadline pragma node cannot be inserted in the Rep
19694 -- Item chain of Ent since it is rewritten by the expander as a
19695 -- procedure call statement that will break the chain.
19697 Set_Has_Relative_Deadline_Pragma
(P
);
19698 end Relative_Deadline
;
19700 ------------------------
19701 -- Remote_Access_Type --
19702 ------------------------
19704 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
19706 when Pragma_Remote_Access_Type
=> Remote_Access_Type
: declare
19711 Check_Arg_Count
(1);
19712 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19713 Check_Arg_Is_Local_Name
(Arg1
);
19715 E
:= Entity
(Get_Pragma_Arg
(Arg1
));
19717 -- A pragma that applies to a Ghost entity becomes Ghost for the
19718 -- purposes of legality checks and removal of ignored Ghost code.
19720 Mark_Pragma_As_Ghost
(N
, E
);
19722 if Nkind
(Parent
(E
)) = N_Formal_Type_Declaration
19723 and then Ekind
(E
) = E_General_Access_Type
19724 and then Is_Class_Wide_Type
(Directly_Designated_Type
(E
))
19725 and then Scope
(Root_Type
(Directly_Designated_Type
(E
)))
19727 and then Is_Valid_Remote_Object_Type
19728 (Root_Type
(Directly_Designated_Type
(E
)))
19730 Set_Is_Remote_Types
(E
);
19734 ("pragma% applies only to formal access to classwide types",
19737 end Remote_Access_Type
;
19739 ---------------------------
19740 -- Remote_Call_Interface --
19741 ---------------------------
19743 -- pragma Remote_Call_Interface [(library_unit_NAME)];
19745 when Pragma_Remote_Call_Interface
=> Remote_Call_Interface
: declare
19746 Cunit_Node
: Node_Id
;
19747 Cunit_Ent
: Entity_Id
;
19751 Check_Ada_83_Warning
;
19752 Check_Valid_Library_Unit_Pragma
;
19754 if Nkind
(N
) = N_Null_Statement
then
19758 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
19759 K
:= Nkind
(Unit
(Cunit_Node
));
19760 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
19762 -- A pragma that applies to a Ghost entity becomes Ghost for the
19763 -- purposes of legality checks and removal of ignored Ghost code.
19765 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
19767 if K
= N_Package_Declaration
19768 or else K
= N_Generic_Package_Declaration
19769 or else K
= N_Subprogram_Declaration
19770 or else K
= N_Generic_Subprogram_Declaration
19771 or else (K
= N_Subprogram_Body
19772 and then Acts_As_Spec
(Unit
(Cunit_Node
)))
19777 "pragma% must apply to package or subprogram declaration");
19780 Set_Is_Remote_Call_Interface
(Cunit_Ent
);
19781 end Remote_Call_Interface
;
19787 -- pragma Remote_Types [(library_unit_NAME)];
19789 when Pragma_Remote_Types
=> Remote_Types
: declare
19790 Cunit_Node
: Node_Id
;
19791 Cunit_Ent
: Entity_Id
;
19794 Check_Ada_83_Warning
;
19795 Check_Valid_Library_Unit_Pragma
;
19797 if Nkind
(N
) = N_Null_Statement
then
19801 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
19802 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
19804 -- A pragma that applies to a Ghost entity becomes Ghost for the
19805 -- purposes of legality checks and removal of ignored Ghost code.
19807 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
19809 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
19810 N_Generic_Package_Declaration
)
19813 ("pragma% can only apply to a package declaration");
19816 Set_Is_Remote_Types
(Cunit_Ent
);
19823 -- pragma Ravenscar;
19825 when Pragma_Ravenscar
=>
19827 Check_Arg_Count
(0);
19828 Check_Valid_Configuration_Pragma
;
19829 Set_Ravenscar_Profile
(Ravenscar
, N
);
19831 if Warn_On_Obsolescent_Feature
then
19833 ("pragma Ravenscar is an obsolescent feature?j?", N
);
19835 ("|use pragma Profile (Ravenscar) instead?j?", N
);
19838 -------------------------
19839 -- Restricted_Run_Time --
19840 -------------------------
19842 -- pragma Restricted_Run_Time;
19844 when Pragma_Restricted_Run_Time
=>
19846 Check_Arg_Count
(0);
19847 Check_Valid_Configuration_Pragma
;
19848 Set_Profile_Restrictions
19849 (Restricted
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
19851 if Warn_On_Obsolescent_Feature
then
19853 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
19856 ("|use pragma Profile (Restricted) instead?j?", N
);
19863 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
19866 -- restriction_IDENTIFIER
19867 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19869 when Pragma_Restrictions
=>
19870 Process_Restrictions_Or_Restriction_Warnings
19871 (Warn
=> Treat_Restrictions_As_Warnings
);
19873 --------------------------
19874 -- Restriction_Warnings --
19875 --------------------------
19877 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
19880 -- restriction_IDENTIFIER
19881 -- | restriction_parameter_IDENTIFIER => EXPRESSION
19883 when Pragma_Restriction_Warnings
=>
19885 Process_Restrictions_Or_Restriction_Warnings
(Warn
=> True);
19891 -- pragma Reviewable;
19893 when Pragma_Reviewable
=>
19894 Check_Ada_83_Warning
;
19895 Check_Arg_Count
(0);
19897 -- Call dummy debugging function rv. This is done to assist front
19898 -- end debugging. By placing a Reviewable pragma in the source
19899 -- program, a breakpoint on rv catches this place in the source,
19900 -- allowing convenient stepping to the point of interest.
19904 --------------------------
19905 -- Short_Circuit_And_Or --
19906 --------------------------
19908 -- pragma Short_Circuit_And_Or;
19910 when Pragma_Short_Circuit_And_Or
=>
19912 Check_Arg_Count
(0);
19913 Check_Valid_Configuration_Pragma
;
19914 Short_Circuit_And_Or
:= True;
19916 -------------------
19917 -- Share_Generic --
19918 -------------------
19920 -- pragma Share_Generic (GNAME {, GNAME});
19922 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
19924 when Pragma_Share_Generic
=>
19926 Process_Generic_List
;
19932 -- pragma Shared (LOCAL_NAME);
19934 when Pragma_Shared
=>
19936 Process_Atomic_Independent_Shared_Volatile
;
19938 --------------------
19939 -- Shared_Passive --
19940 --------------------
19942 -- pragma Shared_Passive [(library_unit_NAME)];
19944 -- Set the flag Is_Shared_Passive of program unit name entity
19946 when Pragma_Shared_Passive
=> Shared_Passive
: declare
19947 Cunit_Node
: Node_Id
;
19948 Cunit_Ent
: Entity_Id
;
19951 Check_Ada_83_Warning
;
19952 Check_Valid_Library_Unit_Pragma
;
19954 if Nkind
(N
) = N_Null_Statement
then
19958 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
19959 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
19961 -- A pragma that applies to a Ghost entity becomes Ghost for the
19962 -- purposes of legality checks and removal of ignored Ghost code.
19964 Mark_Pragma_As_Ghost
(N
, Cunit_Ent
);
19966 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
19967 N_Generic_Package_Declaration
)
19970 ("pragma% can only apply to a package declaration");
19973 Set_Is_Shared_Passive
(Cunit_Ent
);
19974 end Shared_Passive
;
19976 -----------------------
19977 -- Short_Descriptors --
19978 -----------------------
19980 -- pragma Short_Descriptors;
19982 -- Recognize and validate, but otherwise ignore
19984 when Pragma_Short_Descriptors
=>
19986 Check_Arg_Count
(0);
19987 Check_Valid_Configuration_Pragma
;
19989 ------------------------------
19990 -- Simple_Storage_Pool_Type --
19991 ------------------------------
19993 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
19995 when Pragma_Simple_Storage_Pool_Type
=>
19996 Simple_Storage_Pool_Type
: declare
20002 Check_Arg_Count
(1);
20003 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
20005 Type_Id
:= Get_Pragma_Arg
(Arg1
);
20006 Find_Type
(Type_Id
);
20007 Typ
:= Entity
(Type_Id
);
20009 if Typ
= Any_Type
then
20013 -- A pragma that applies to a Ghost entity becomes Ghost for the
20014 -- purposes of legality checks and removal of ignored Ghost code.
20016 Mark_Pragma_As_Ghost
(N
, Typ
);
20018 -- We require the pragma to apply to a type declared in a package
20019 -- declaration, but not (immediately) within a package body.
20021 if Ekind
(Current_Scope
) /= E_Package
20022 or else In_Package_Body
(Current_Scope
)
20025 ("pragma% can only apply to type declared immediately "
20026 & "within a package declaration");
20029 -- A simple storage pool type must be an immutably limited record
20030 -- or private type. If the pragma is given for a private type,
20031 -- the full type is similarly restricted (which is checked later
20032 -- in Freeze_Entity).
20034 if Is_Record_Type
(Typ
)
20035 and then not Is_Limited_View
(Typ
)
20038 ("pragma% can only apply to explicitly limited record type");
20040 elsif Is_Private_Type
(Typ
) and then not Is_Limited_Type
(Typ
) then
20042 ("pragma% can only apply to a private type that is limited");
20044 elsif not Is_Record_Type
(Typ
)
20045 and then not Is_Private_Type
(Typ
)
20048 ("pragma% can only apply to limited record or private type");
20051 Record_Rep_Item
(Typ
, N
);
20052 end Simple_Storage_Pool_Type
;
20054 ----------------------
20055 -- Source_File_Name --
20056 ----------------------
20058 -- There are five forms for this pragma:
20060 -- pragma Source_File_Name (
20061 -- [UNIT_NAME =>] unit_NAME,
20062 -- BODY_FILE_NAME => STRING_LITERAL
20063 -- [, [INDEX =>] INTEGER_LITERAL]);
20065 -- pragma Source_File_Name (
20066 -- [UNIT_NAME =>] unit_NAME,
20067 -- SPEC_FILE_NAME => STRING_LITERAL
20068 -- [, [INDEX =>] INTEGER_LITERAL]);
20070 -- pragma Source_File_Name (
20071 -- BODY_FILE_NAME => STRING_LITERAL
20072 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20073 -- [, CASING => CASING_SPEC]);
20075 -- pragma Source_File_Name (
20076 -- SPEC_FILE_NAME => STRING_LITERAL
20077 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20078 -- [, CASING => CASING_SPEC]);
20080 -- pragma Source_File_Name (
20081 -- SUBUNIT_FILE_NAME => STRING_LITERAL
20082 -- [, DOT_REPLACEMENT => STRING_LITERAL]
20083 -- [, CASING => CASING_SPEC]);
20085 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
20087 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
20088 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
20089 -- only be used when no project file is used, while SFNP can only be
20090 -- used when a project file is used.
20092 -- No processing here. Processing was completed during parsing, since
20093 -- we need to have file names set as early as possible. Units are
20094 -- loaded well before semantic processing starts.
20096 -- The only processing we defer to this point is the check for
20097 -- correct placement.
20099 when Pragma_Source_File_Name
=>
20101 Check_Valid_Configuration_Pragma
;
20103 ------------------------------
20104 -- Source_File_Name_Project --
20105 ------------------------------
20107 -- See Source_File_Name for syntax
20109 -- No processing here. Processing was completed during parsing, since
20110 -- we need to have file names set as early as possible. Units are
20111 -- loaded well before semantic processing starts.
20113 -- The only processing we defer to this point is the check for
20114 -- correct placement.
20116 when Pragma_Source_File_Name_Project
=>
20118 Check_Valid_Configuration_Pragma
;
20120 -- Check that a pragma Source_File_Name_Project is used only in a
20121 -- configuration pragmas file.
20123 -- Pragmas Source_File_Name_Project should only be generated by
20124 -- the Project Manager in configuration pragmas files.
20126 -- This is really an ugly test. It seems to depend on some
20127 -- accidental and undocumented property. At the very least it
20128 -- needs to be documented, but it would be better to have a
20129 -- clean way of testing if we are in a configuration file???
20131 if Present
(Parent
(N
)) then
20133 ("pragma% can only appear in a configuration pragmas file");
20136 ----------------------
20137 -- Source_Reference --
20138 ----------------------
20140 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
20142 -- Nothing to do, all processing completed in Par.Prag, since we need
20143 -- the information for possible parser messages that are output.
20145 when Pragma_Source_Reference
=>
20152 -- pragma SPARK_Mode [(On | Off)];
20154 when Pragma_SPARK_Mode
=> Do_SPARK_Mode
: declare
20155 Mode_Id
: SPARK_Mode_Type
;
20157 procedure Check_Pragma_Conformance
20158 (Context_Pragma
: Node_Id
;
20159 Entity
: Entity_Id
;
20160 Entity_Pragma
: Node_Id
);
20161 -- Subsidiary to routines Process_xxx. Verify the SPARK_Mode
20162 -- conformance of pragma N depending the following scenarios:
20164 -- If pragma Context_Pragma is not Empty, verify that pragma N is
20165 -- compatible with the pragma Context_Pragma that was inherited
20166 -- from the context:
20167 -- * If the mode of Context_Pragma is ON, then the new mode can
20169 -- * If the mode of Context_Pragma is OFF, then the only allowed
20170 -- new mode is also OFF. Emit error if this is not the case.
20172 -- If Entity is not Empty, verify that pragma N is compatible with
20173 -- pragma Entity_Pragma that belongs to Entity.
20174 -- * If Entity_Pragma is Empty, always issue an error as this
20175 -- corresponds to the case where a previous section of Entity
20176 -- has no SPARK_Mode set.
20177 -- * If the mode of Entity_Pragma is ON, then the new mode can
20179 -- * If the mode of Entity_Pragma is OFF, then the only allowed
20180 -- new mode is also OFF. Emit error if this is not the case.
20182 procedure Check_Library_Level_Entity
(E
: Entity_Id
);
20183 -- Subsidiary to routines Process_xxx. Verify that the related
20184 -- entity E subject to pragma SPARK_Mode is library-level.
20186 procedure Process_Body
(Decl
: Node_Id
);
20187 -- Verify the legality of pragma SPARK_Mode when it appears as the
20188 -- top of the body declarations of entry, package, protected unit,
20189 -- subprogram or task unit body denoted by Decl.
20191 procedure Process_Overloadable
(Decl
: Node_Id
);
20192 -- Verify the legality of pragma SPARK_Mode when it applies to an
20193 -- entry or [generic] subprogram declaration denoted by Decl.
20195 procedure Process_Private_Part
(Decl
: Node_Id
);
20196 -- Verify the legality of pragma SPARK_Mode when it appears at the
20197 -- top of the private declarations of a package spec, protected or
20198 -- task unit declaration denoted by Decl.
20200 procedure Process_Statement_Part
(Decl
: Node_Id
);
20201 -- Verify the legality of pragma SPARK_Mode when it appears at the
20202 -- top of the statement sequence of a package body denoted by node
20205 procedure Process_Visible_Part
(Decl
: Node_Id
);
20206 -- Verify the legality of pragma SPARK_Mode when it appears at the
20207 -- top of the visible declarations of a package spec, protected or
20208 -- task unit declaration denoted by Decl. The routine is also used
20209 -- on protected or task units declared without a definition.
20211 procedure Set_SPARK_Context
;
20212 -- Subsidiary to routines Process_xxx. Set the global variables
20213 -- which represent the mode of the context from pragma N. Ensure
20214 -- that Dynamic_Elaboration_Checks are off if the new mode is On.
20216 ------------------------------
20217 -- Check_Pragma_Conformance --
20218 ------------------------------
20220 procedure Check_Pragma_Conformance
20221 (Context_Pragma
: Node_Id
;
20222 Entity
: Entity_Id
;
20223 Entity_Pragma
: Node_Id
)
20225 Err_Id
: Entity_Id
;
20229 -- The current pragma may appear without an argument. If this
20230 -- is the case, associate all error messages with the pragma
20233 if Present
(Arg1
) then
20239 -- The mode of the current pragma is compared against that of
20240 -- an enclosing context.
20242 if Present
(Context_Pragma
) then
20243 pragma Assert
(Nkind
(Context_Pragma
) = N_Pragma
);
20245 -- Issue an error if the new mode is less restrictive than
20246 -- that of the context.
20248 if Get_SPARK_Mode_From_Pragma
(Context_Pragma
) = Off
20249 and then Get_SPARK_Mode_From_Pragma
(N
) = On
20252 ("cannot change SPARK_Mode from Off to On", Err_N
);
20253 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
20254 Error_Msg_N
("\SPARK_Mode was set to Off#", Err_N
);
20259 -- The mode of the current pragma is compared against that of
20260 -- an initial package, protected type, subprogram or task type
20263 if Present
(Entity
) then
20265 -- A simple protected or task type is transformed into an
20266 -- anonymous type whose name cannot be used to issue error
20267 -- messages. Recover the original entity of the type.
20269 if Ekind_In
(Entity
, E_Protected_Type
, E_Task_Type
) then
20272 (Original_Node
(Unit_Declaration_Node
(Entity
)));
20277 -- Both the initial declaration and the completion carry
20278 -- SPARK_Mode pragmas.
20280 if Present
(Entity_Pragma
) then
20281 pragma Assert
(Nkind
(Entity_Pragma
) = N_Pragma
);
20283 -- Issue an error if the new mode is less restrictive
20284 -- than that of the initial declaration.
20286 if Get_SPARK_Mode_From_Pragma
(Entity_Pragma
) = Off
20287 and then Get_SPARK_Mode_From_Pragma
(N
) = On
20289 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
20290 Error_Msg_Sloc
:= Sloc
(Entity_Pragma
);
20292 ("\value Off was set for SPARK_Mode on&#",
20297 -- Otherwise the initial declaration lacks a SPARK_Mode
20298 -- pragma in which case the current pragma is illegal as
20299 -- it cannot "complete".
20302 Error_Msg_N
("incorrect use of SPARK_Mode", Err_N
);
20303 Error_Msg_Sloc
:= Sloc
(Err_Id
);
20305 ("\no value was set for SPARK_Mode on&#",
20310 end Check_Pragma_Conformance
;
20312 --------------------------------
20313 -- Check_Library_Level_Entity --
20314 --------------------------------
20316 procedure Check_Library_Level_Entity
(E
: Entity_Id
) is
20317 procedure Add_Entity_To_Name_Buffer
;
20318 -- Add the E_Kind of entity E to the name buffer
20320 -------------------------------
20321 -- Add_Entity_To_Name_Buffer --
20322 -------------------------------
20324 procedure Add_Entity_To_Name_Buffer
is
20326 if Ekind_In
(E
, E_Entry
, E_Entry_Family
) then
20327 Add_Str_To_Name_Buffer
("entry");
20329 elsif Ekind_In
(E
, E_Generic_Package
,
20333 Add_Str_To_Name_Buffer
("package");
20335 elsif Ekind_In
(E
, E_Protected_Body
, E_Protected_Type
) then
20336 Add_Str_To_Name_Buffer
("protected type");
20338 elsif Ekind_In
(E
, E_Function
,
20339 E_Generic_Function
,
20340 E_Generic_Procedure
,
20344 Add_Str_To_Name_Buffer
("subprogram");
20347 pragma Assert
(Ekind_In
(E
, E_Task_Body
, E_Task_Type
));
20348 Add_Str_To_Name_Buffer
("task type");
20350 end Add_Entity_To_Name_Buffer
;
20354 Msg_1
: constant String := "incorrect placement of pragma%";
20357 -- Start of processing for Check_Library_Level_Entity
20360 if not Is_Library_Level_Entity
(E
) then
20361 Error_Msg_Name_1
:= Pname
;
20362 Error_Msg_N
(Fix_Error
(Msg_1
), N
);
20365 Add_Str_To_Name_Buffer
("\& is not a library-level ");
20366 Add_Entity_To_Name_Buffer
;
20368 Msg_2
:= Name_Find
;
20369 Error_Msg_NE
(Get_Name_String
(Msg_2
), N
, E
);
20373 end Check_Library_Level_Entity
;
20379 procedure Process_Body
(Decl
: Node_Id
) is
20380 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20381 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Decl
);
20384 -- Ignore pragma when applied to the special body created for
20385 -- inlining, recognized by its internal name _Parent.
20387 if Chars
(Body_Id
) = Name_uParent
then
20391 Check_Library_Level_Entity
(Body_Id
);
20393 -- For entry bodies, verify the legality against:
20394 -- * The mode of the context
20395 -- * The mode of the spec (if any)
20397 if Nkind_In
(Decl
, N_Entry_Body
, N_Subprogram_Body
) then
20399 -- A stand alone subprogram body
20401 if Body_Id
= Spec_Id
then
20402 Check_Pragma_Conformance
20403 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20405 Entity_Pragma
=> Empty
);
20407 -- An entry or subprogram body that completes a previous
20411 Check_Pragma_Conformance
20412 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20414 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
20418 Set_SPARK_Pragma
(Body_Id
, N
);
20419 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20421 -- For package bodies, verify the legality against:
20422 -- * The mode of the context
20423 -- * The mode of the private part
20425 -- This case is separated from protected and task bodies
20426 -- because the statement part of the package body inherits
20427 -- the mode of the body declarations.
20429 elsif Nkind
(Decl
) = N_Package_Body
then
20430 Check_Pragma_Conformance
20431 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20433 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
20436 Set_SPARK_Pragma
(Body_Id
, N
);
20437 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20438 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
20439 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
20441 -- For protected and task bodies, verify the legality against:
20442 -- * The mode of the context
20443 -- * The mode of the private part
20447 (Nkind_In
(Decl
, N_Protected_Body
, N_Task_Body
));
20449 Check_Pragma_Conformance
20450 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
20452 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
));
20455 Set_SPARK_Pragma
(Body_Id
, N
);
20456 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
20460 --------------------------
20461 -- Process_Overloadable --
20462 --------------------------
20464 procedure Process_Overloadable
(Decl
: Node_Id
) is
20465 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20466 Spec_Typ
: constant Entity_Id
:= Etype
(Spec_Id
);
20469 Check_Library_Level_Entity
(Spec_Id
);
20471 -- Verify the legality against:
20472 -- * The mode of the context
20474 Check_Pragma_Conformance
20475 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
20477 Entity_Pragma
=> Empty
);
20479 Set_SPARK_Pragma
(Spec_Id
, N
);
20480 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
20482 -- When the pragma applies to the anonymous object created for
20483 -- a single task type, decorate the type as well. This scenario
20484 -- arises when the single task type lacks a task definition,
20485 -- therefore there is no issue with respect to a potential
20486 -- pragma SPARK_Mode in the private part.
20488 -- task type Anon_Task_Typ;
20489 -- Obj : Anon_Task_Typ;
20490 -- pragma SPARK_Mode ...;
20492 if Is_Single_Task_Object
(Spec_Id
) then
20493 Set_SPARK_Pragma
(Spec_Typ
, N
);
20494 Set_SPARK_Pragma_Inherited
(Spec_Typ
, False);
20495 Set_SPARK_Aux_Pragma
(Spec_Typ
, N
);
20496 Set_SPARK_Aux_Pragma_Inherited
(Spec_Typ
, True);
20498 end Process_Overloadable
;
20500 --------------------------
20501 -- Process_Private_Part --
20502 --------------------------
20504 procedure Process_Private_Part
(Decl
: Node_Id
) is
20505 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20508 Check_Library_Level_Entity
(Spec_Id
);
20510 -- Verify the legality against:
20511 -- * The mode of the visible declarations
20513 Check_Pragma_Conformance
20514 (Context_Pragma
=> Empty
,
20516 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
));
20519 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
20520 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, False);
20521 end Process_Private_Part
;
20523 ----------------------------
20524 -- Process_Statement_Part --
20525 ----------------------------
20527 procedure Process_Statement_Part
(Decl
: Node_Id
) is
20528 Body_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20531 Check_Library_Level_Entity
(Body_Id
);
20533 -- Verify the legality against:
20534 -- * The mode of the body declarations
20536 Check_Pragma_Conformance
20537 (Context_Pragma
=> Empty
,
20539 Entity_Pragma
=> SPARK_Pragma
(Body_Id
));
20542 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
20543 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, False);
20544 end Process_Statement_Part
;
20546 --------------------------
20547 -- Process_Visible_Part --
20548 --------------------------
20550 procedure Process_Visible_Part
(Decl
: Node_Id
) is
20551 Spec_Id
: constant Entity_Id
:= Defining_Entity
(Decl
);
20552 Obj_Id
: Entity_Id
;
20555 Check_Library_Level_Entity
(Spec_Id
);
20557 -- Verify the legality against:
20558 -- * The mode of the context
20560 Check_Pragma_Conformance
20561 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
20563 Entity_Pragma
=> Empty
);
20565 -- A task unit declared without a definition does not set the
20566 -- SPARK_Mode of the context because the task does not have any
20567 -- entries that could inherit the mode.
20569 if not Nkind_In
(Decl
, N_Single_Task_Declaration
,
20570 N_Task_Type_Declaration
)
20575 Set_SPARK_Pragma
(Spec_Id
, N
);
20576 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
20577 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
20578 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, True);
20580 -- When the pragma applies to a single protected or task type,
20581 -- decorate the corresponding anonymous object as well.
20583 -- protected Anon_Prot_Typ is
20584 -- pragma SPARK_Mode ...;
20586 -- end Anon_Prot_Typ;
20588 -- Obj : Anon_Prot_Typ;
20590 if Is_Single_Concurrent_Type
(Spec_Id
) then
20591 Obj_Id
:= Anonymous_Object
(Spec_Id
);
20593 Set_SPARK_Pragma
(Obj_Id
, N
);
20594 Set_SPARK_Pragma_Inherited
(Obj_Id
, False);
20596 end Process_Visible_Part
;
20598 -----------------------
20599 -- Set_SPARK_Context --
20600 -----------------------
20602 procedure Set_SPARK_Context
is
20604 SPARK_Mode
:= Mode_Id
;
20605 SPARK_Mode_Pragma
:= N
;
20607 if SPARK_Mode
= On
then
20608 Dynamic_Elaboration_Checks
:= False;
20610 end Set_SPARK_Context
;
20618 -- Start of processing for Do_SPARK_Mode
20621 -- When a SPARK_Mode pragma appears inside an instantiation whose
20622 -- enclosing context has SPARK_Mode set to "off", the pragma has
20623 -- no semantic effect.
20625 if Ignore_Pragma_SPARK_Mode
then
20626 Rewrite
(N
, Make_Null_Statement
(Loc
));
20632 Check_No_Identifiers
;
20633 Check_At_Most_N_Arguments
(1);
20635 -- Check the legality of the mode (no argument = ON)
20637 if Arg_Count
= 1 then
20638 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
20639 Mode
:= Chars
(Get_Pragma_Arg
(Arg1
));
20644 Mode_Id
:= Get_SPARK_Mode_Type
(Mode
);
20645 Context
:= Parent
(N
);
20647 -- The pragma appears in a configuration pragmas file
20649 if No
(Context
) then
20650 Check_Valid_Configuration_Pragma
;
20652 if Present
(SPARK_Mode_Pragma
) then
20653 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
20654 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
20660 -- The pragma acts as a configuration pragma in a compilation unit
20662 -- pragma SPARK_Mode ...;
20663 -- package Pack is ...;
20665 elsif Nkind
(Context
) = N_Compilation_Unit
20666 and then List_Containing
(N
) = Context_Items
(Context
)
20668 Check_Valid_Configuration_Pragma
;
20671 -- Otherwise the placement of the pragma within the tree dictates
20672 -- its associated construct. Inspect the declarative list where
20673 -- the pragma resides to find a potential construct.
20677 while Present
(Stmt
) loop
20679 -- Skip prior pragmas, but check for duplicates. Note that
20680 -- this also takes care of pragmas generated for aspects.
20682 if Nkind
(Stmt
) = N_Pragma
then
20683 if Pragma_Name
(Stmt
) = Pname
then
20684 Error_Msg_Name_1
:= Pname
;
20685 Error_Msg_Sloc
:= Sloc
(Stmt
);
20686 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
20690 -- The pragma applies to an expression function that has
20691 -- already been rewritten into a subprogram declaration.
20693 -- function Expr_Func return ... is (...);
20694 -- pragma SPARK_Mode ...;
20696 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
20697 and then Nkind
(Original_Node
(Stmt
)) =
20698 N_Expression_Function
20700 Process_Overloadable
(Stmt
);
20703 -- The pragma applies to the anonymous object created for a
20704 -- single concurrent type.
20706 -- protected type Anon_Prot_Typ ...;
20707 -- Obj : Anon_Prot_Typ;
20708 -- pragma SPARK_Mode ...;
20710 elsif Nkind
(Stmt
) = N_Object_Declaration
20711 and then Is_Single_Concurrent_Object
20712 (Defining_Entity
(Stmt
))
20714 Process_Overloadable
(Stmt
);
20717 -- Skip internally generated code
20719 elsif not Comes_From_Source
(Stmt
) then
20722 -- The pragma applies to an entry or [generic] subprogram
20726 -- pragma SPARK_Mode ...;
20729 -- procedure Proc ...;
20730 -- pragma SPARK_Mode ...;
20732 elsif Nkind_In
(Stmt
, N_Generic_Subprogram_Declaration
,
20733 N_Subprogram_Declaration
)
20734 or else (Nkind
(Stmt
) = N_Entry_Declaration
20735 and then Is_Protected_Type
20736 (Scope
(Defining_Entity
(Stmt
))))
20738 Process_Overloadable
(Stmt
);
20741 -- Otherwise the pragma does not apply to a legal construct
20742 -- or it does not appear at the top of a declarative or a
20743 -- statement list. Issue an error and stop the analysis.
20753 -- The pragma applies to a package or a subprogram that acts as
20754 -- a compilation unit.
20756 -- procedure Proc ...;
20757 -- pragma SPARK_Mode ...;
20759 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
20760 Context
:= Unit
(Parent
(Context
));
20763 -- The pragma appears at the top of entry, package, protected
20764 -- unit, subprogram or task unit body declarations.
20766 -- entry Ent when ... is
20767 -- pragma SPARK_Mode ...;
20769 -- package body Pack is
20770 -- pragma SPARK_Mode ...;
20772 -- procedure Proc ... is
20773 -- pragma SPARK_Mode;
20775 -- protected body Prot is
20776 -- pragma SPARK_Mode ...;
20778 if Nkind_In
(Context
, N_Entry_Body
,
20784 Process_Body
(Context
);
20786 -- The pragma appears at the top of the visible or private
20787 -- declaration of a package spec, protected or task unit.
20790 -- pragma SPARK_Mode ...;
20792 -- pragma SPARK_Mode ...;
20794 -- protected [type] Prot is
20795 -- pragma SPARK_Mode ...;
20797 -- pragma SPARK_Mode ...;
20799 elsif Nkind_In
(Context
, N_Package_Specification
,
20800 N_Protected_Definition
,
20803 if List_Containing
(N
) = Visible_Declarations
(Context
) then
20804 Process_Visible_Part
(Parent
(Context
));
20806 Process_Private_Part
(Parent
(Context
));
20809 -- The pragma appears at the top of package body statements
20811 -- package body Pack is
20813 -- pragma SPARK_Mode;
20815 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
20816 and then Nkind
(Parent
(Context
)) = N_Package_Body
20818 Process_Statement_Part
(Parent
(Context
));
20820 -- The pragma appeared as an aspect of a [generic] subprogram
20821 -- declaration that acts as a compilation unit.
20824 -- procedure Proc ...;
20825 -- pragma SPARK_Mode ...;
20827 elsif Nkind_In
(Context
, N_Generic_Subprogram_Declaration
,
20828 N_Subprogram_Declaration
)
20830 Process_Overloadable
(Context
);
20832 -- The pragma does not apply to a legal construct, issue error
20840 --------------------------------
20841 -- Static_Elaboration_Desired --
20842 --------------------------------
20844 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
20846 when Pragma_Static_Elaboration_Desired
=>
20848 Check_At_Most_N_Arguments
(1);
20850 if Is_Compilation_Unit
(Current_Scope
)
20851 and then Ekind
(Current_Scope
) = E_Package
20853 Set_Static_Elaboration_Desired
(Current_Scope
, True);
20855 Error_Pragma
("pragma% must apply to a library-level package");
20862 -- pragma Storage_Size (EXPRESSION);
20864 when Pragma_Storage_Size
=> Storage_Size
: declare
20865 P
: constant Node_Id
:= Parent
(N
);
20869 Check_No_Identifiers
;
20870 Check_Arg_Count
(1);
20872 -- The expression must be analyzed in the special manner described
20873 -- in "Handling of Default Expressions" in sem.ads.
20875 Arg
:= Get_Pragma_Arg
(Arg1
);
20876 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
20878 if not Is_OK_Static_Expression
(Arg
) then
20879 Check_Restriction
(Static_Storage_Size
, Arg
);
20882 if Nkind
(P
) /= N_Task_Definition
then
20887 if Has_Storage_Size_Pragma
(P
) then
20888 Error_Pragma
("duplicate pragma% not allowed");
20890 Set_Has_Storage_Size_Pragma
(P
, True);
20893 Record_Rep_Item
(Defining_Identifier
(Parent
(P
)), N
);
20901 -- pragma Storage_Unit (NUMERIC_LITERAL);
20903 -- Only permitted argument is System'Storage_Unit value
20905 when Pragma_Storage_Unit
=>
20906 Check_No_Identifiers
;
20907 Check_Arg_Count
(1);
20908 Check_Arg_Is_Integer_Literal
(Arg1
);
20910 if Intval
(Get_Pragma_Arg
(Arg1
)) /=
20911 UI_From_Int
(Ttypes
.System_Storage_Unit
)
20913 Error_Msg_Uint_1
:= UI_From_Int
(Ttypes
.System_Storage_Unit
);
20915 ("the only allowed argument for pragma% is ^", Arg1
);
20918 --------------------
20919 -- Stream_Convert --
20920 --------------------
20922 -- pragma Stream_Convert (
20923 -- [Entity =>] type_LOCAL_NAME,
20924 -- [Read =>] function_NAME,
20925 -- [Write =>] function NAME);
20927 when Pragma_Stream_Convert
=> Stream_Convert
: declare
20929 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
);
20930 -- Check that the given argument is the name of a local function
20931 -- of one argument that is not overloaded earlier in the current
20932 -- local scope. A check is also made that the argument is a
20933 -- function with one parameter.
20935 --------------------------------------
20936 -- Check_OK_Stream_Convert_Function --
20937 --------------------------------------
20939 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
) is
20943 Check_Arg_Is_Local_Name
(Arg
);
20944 Ent
:= Entity
(Get_Pragma_Arg
(Arg
));
20946 if Has_Homonym
(Ent
) then
20948 ("argument for pragma% may not be overloaded", Arg
);
20951 if Ekind
(Ent
) /= E_Function
20952 or else No
(First_Formal
(Ent
))
20953 or else Present
(Next_Formal
(First_Formal
(Ent
)))
20956 ("argument for pragma% must be function of one argument",
20959 end Check_OK_Stream_Convert_Function
;
20961 -- Start of processing for Stream_Convert
20965 Check_Arg_Order
((Name_Entity
, Name_Read
, Name_Write
));
20966 Check_Arg_Count
(3);
20967 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20968 Check_Optional_Identifier
(Arg2
, Name_Read
);
20969 Check_Optional_Identifier
(Arg3
, Name_Write
);
20970 Check_Arg_Is_Local_Name
(Arg1
);
20971 Check_OK_Stream_Convert_Function
(Arg2
);
20972 Check_OK_Stream_Convert_Function
(Arg3
);
20975 Typ
: constant Entity_Id
:=
20976 Underlying_Type
(Entity
(Get_Pragma_Arg
(Arg1
)));
20977 Read
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg2
));
20978 Write
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg3
));
20981 Check_First_Subtype
(Arg1
);
20983 -- Check for too early or too late. Note that we don't enforce
20984 -- the rule about primitive operations in this case, since, as
20985 -- is the case for explicit stream attributes themselves, these
20986 -- restrictions are not appropriate. Note that the chaining of
20987 -- the pragma by Rep_Item_Too_Late is actually the critical
20988 -- processing done for this pragma.
20990 if Rep_Item_Too_Early
(Typ
, N
)
20992 Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True)
20997 -- Return if previous error
20999 if Etype
(Typ
) = Any_Type
21001 Etype
(Read
) = Any_Type
21003 Etype
(Write
) = Any_Type
21010 if Underlying_Type
(Etype
(Read
)) /= Typ
then
21012 ("incorrect return type for function&", Arg2
);
21015 if Underlying_Type
(Etype
(First_Formal
(Write
))) /= Typ
then
21017 ("incorrect parameter type for function&", Arg3
);
21020 if Underlying_Type
(Etype
(First_Formal
(Read
))) /=
21021 Underlying_Type
(Etype
(Write
))
21024 ("result type of & does not match Read parameter type",
21028 end Stream_Convert
;
21034 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
21036 -- This is processed by the parser since some of the style checks
21037 -- take place during source scanning and parsing. This means that
21038 -- we don't need to issue error messages here.
21040 when Pragma_Style_Checks
=> Style_Checks
: declare
21041 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
21047 Check_No_Identifiers
;
21049 -- Two argument form
21051 if Arg_Count
= 2 then
21052 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
21059 E_Id
:= Get_Pragma_Arg
(Arg2
);
21062 if not Is_Entity_Name
(E_Id
) then
21064 ("second argument of pragma% must be entity name",
21068 E
:= Entity
(E_Id
);
21070 if not Ignore_Style_Checks_Pragmas
then
21075 Set_Suppress_Style_Checks
21076 (E
, Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Off
);
21077 exit when No
(Homonym
(E
));
21084 -- One argument form
21087 Check_Arg_Count
(1);
21089 if Nkind
(A
) = N_String_Literal
then
21093 Slen
: constant Natural := Natural (String_Length
(S
));
21094 Options
: String (1 .. Slen
);
21100 C
:= Get_String_Char
(S
, Int
(J
));
21101 exit when not In_Character_Range
(C
);
21102 Options
(J
) := Get_Character
(C
);
21104 -- If at end of string, set options. As per discussion
21105 -- above, no need to check for errors, since we issued
21106 -- them in the parser.
21109 if not Ignore_Style_Checks_Pragmas
then
21110 Set_Style_Check_Options
(Options
);
21120 elsif Nkind
(A
) = N_Identifier
then
21121 if Chars
(A
) = Name_All_Checks
then
21122 if not Ignore_Style_Checks_Pragmas
then
21124 Set_GNAT_Style_Check_Options
;
21126 Set_Default_Style_Check_Options
;
21130 elsif Chars
(A
) = Name_On
then
21131 if not Ignore_Style_Checks_Pragmas
then
21132 Style_Check
:= True;
21135 elsif Chars
(A
) = Name_Off
then
21136 if not Ignore_Style_Checks_Pragmas
then
21137 Style_Check
:= False;
21148 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
21150 when Pragma_Subtitle
=>
21152 Check_Arg_Count
(1);
21153 Check_Optional_Identifier
(Arg1
, Name_Subtitle
);
21154 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
21161 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
21163 when Pragma_Suppress
=>
21164 Process_Suppress_Unsuppress
(Suppress_Case
=> True);
21170 -- pragma Suppress_All;
21172 -- The only check made here is that the pragma has no arguments.
21173 -- There are no placement rules, and the processing required (setting
21174 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
21175 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
21176 -- then creates and inserts a pragma Suppress (All_Checks).
21178 when Pragma_Suppress_All
=>
21180 Check_Arg_Count
(0);
21182 -------------------------
21183 -- Suppress_Debug_Info --
21184 -------------------------
21186 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
21188 when Pragma_Suppress_Debug_Info
=> Suppress_Debug_Info
: declare
21189 Nam_Id
: Entity_Id
;
21193 Check_Arg_Count
(1);
21194 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21195 Check_Arg_Is_Local_Name
(Arg1
);
21197 Nam_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
21199 -- A pragma that applies to a Ghost entity becomes Ghost for the
21200 -- purposes of legality checks and removal of ignored Ghost code.
21202 Mark_Pragma_As_Ghost
(N
, Nam_Id
);
21203 Set_Debug_Info_Off
(Nam_Id
);
21204 end Suppress_Debug_Info
;
21206 ----------------------------------
21207 -- Suppress_Exception_Locations --
21208 ----------------------------------
21210 -- pragma Suppress_Exception_Locations;
21212 when Pragma_Suppress_Exception_Locations
=>
21214 Check_Arg_Count
(0);
21215 Check_Valid_Configuration_Pragma
;
21216 Exception_Locations_Suppressed
:= True;
21218 -----------------------------
21219 -- Suppress_Initialization --
21220 -----------------------------
21222 -- pragma Suppress_Initialization ([Entity =>] type_Name);
21224 when Pragma_Suppress_Initialization
=> Suppress_Init
: declare
21230 Check_Arg_Count
(1);
21231 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21232 Check_Arg_Is_Local_Name
(Arg1
);
21234 E_Id
:= Get_Pragma_Arg
(Arg1
);
21236 if Etype
(E_Id
) = Any_Type
then
21240 E
:= Entity
(E_Id
);
21242 -- A pragma that applies to a Ghost entity becomes Ghost for the
21243 -- purposes of legality checks and removal of ignored Ghost code.
21245 Mark_Pragma_As_Ghost
(N
, E
);
21247 if not Is_Type
(E
) and then Ekind
(E
) /= E_Variable
then
21249 ("pragma% requires variable, type or subtype", Arg1
);
21252 if Rep_Item_Too_Early
(E
, N
)
21254 Rep_Item_Too_Late
(E
, N
, FOnly
=> True)
21259 -- For incomplete/private type, set flag on full view
21261 if Is_Incomplete_Or_Private_Type
(E
) then
21262 if No
(Full_View
(Base_Type
(E
))) then
21264 ("argument of pragma% cannot be an incomplete type", Arg1
);
21266 Set_Suppress_Initialization
(Full_View
(Base_Type
(E
)));
21269 -- For first subtype, set flag on base type
21271 elsif Is_First_Subtype
(E
) then
21272 Set_Suppress_Initialization
(Base_Type
(E
));
21274 -- For other than first subtype, set flag on subtype or variable
21277 Set_Suppress_Initialization
(E
);
21285 -- pragma System_Name (DIRECT_NAME);
21287 -- Syntax check: one argument, which must be the identifier GNAT or
21288 -- the identifier GCC, no other identifiers are acceptable.
21290 when Pragma_System_Name
=>
21292 Check_No_Identifiers
;
21293 Check_Arg_Count
(1);
21294 Check_Arg_Is_One_Of
(Arg1
, Name_Gcc
, Name_Gnat
);
21296 -----------------------------
21297 -- Task_Dispatching_Policy --
21298 -----------------------------
21300 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
21302 when Pragma_Task_Dispatching_Policy
=> declare
21306 Check_Ada_83_Warning
;
21307 Check_Arg_Count
(1);
21308 Check_No_Identifiers
;
21309 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
21310 Check_Valid_Configuration_Pragma
;
21311 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
21312 DP
:= Fold_Upper
(Name_Buffer
(1));
21314 if Task_Dispatching_Policy
/= ' '
21315 and then Task_Dispatching_Policy
/= DP
21317 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
21319 ("task dispatching policy incompatible with policy#");
21321 -- Set new policy, but always preserve System_Location since we
21322 -- like the error message with the run time name.
21325 Task_Dispatching_Policy
:= DP
;
21327 if Task_Dispatching_Policy_Sloc
/= System_Location
then
21328 Task_Dispatching_Policy_Sloc
:= Loc
;
21337 -- pragma Task_Info (EXPRESSION);
21339 when Pragma_Task_Info
=> Task_Info
: declare
21340 P
: constant Node_Id
:= Parent
(N
);
21346 if Warn_On_Obsolescent_Feature
then
21348 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
21349 & "instead?j?", N
);
21352 if Nkind
(P
) /= N_Task_Definition
then
21353 Error_Pragma
("pragma% must appear in task definition");
21356 Check_No_Identifiers
;
21357 Check_Arg_Count
(1);
21359 Analyze_And_Resolve
21360 (Get_Pragma_Arg
(Arg1
), RTE
(RE_Task_Info_Type
));
21362 if Etype
(Get_Pragma_Arg
(Arg1
)) = Any_Type
then
21366 Ent
:= Defining_Identifier
(Parent
(P
));
21368 -- Check duplicate pragma before we chain the pragma in the Rep
21369 -- Item chain of Ent.
21372 (Ent
, Name_Task_Info
, Check_Parents
=> False)
21374 Error_Pragma
("duplicate pragma% not allowed");
21377 Record_Rep_Item
(Ent
, N
);
21384 -- pragma Task_Name (string_EXPRESSION);
21386 when Pragma_Task_Name
=> Task_Name
: declare
21387 P
: constant Node_Id
:= Parent
(N
);
21392 Check_No_Identifiers
;
21393 Check_Arg_Count
(1);
21395 Arg
:= Get_Pragma_Arg
(Arg1
);
21397 -- The expression is used in the call to Create_Task, and must be
21398 -- expanded there, not in the context of the current spec. It must
21399 -- however be analyzed to capture global references, in case it
21400 -- appears in a generic context.
21402 Preanalyze_And_Resolve
(Arg
, Standard_String
);
21404 if Nkind
(P
) /= N_Task_Definition
then
21408 Ent
:= Defining_Identifier
(Parent
(P
));
21410 -- Check duplicate pragma before we chain the pragma in the Rep
21411 -- Item chain of Ent.
21414 (Ent
, Name_Task_Name
, Check_Parents
=> False)
21416 Error_Pragma
("duplicate pragma% not allowed");
21419 Record_Rep_Item
(Ent
, N
);
21426 -- pragma Task_Storage (
21427 -- [Task_Type =>] LOCAL_NAME,
21428 -- [Top_Guard =>] static_integer_EXPRESSION);
21430 when Pragma_Task_Storage
=> Task_Storage
: declare
21431 Args
: Args_List
(1 .. 2);
21432 Names
: constant Name_List
(1 .. 2) := (
21436 Task_Type
: Node_Id
renames Args
(1);
21437 Top_Guard
: Node_Id
renames Args
(2);
21443 Gather_Associations
(Names
, Args
);
21445 if No
(Task_Type
) then
21447 ("missing task_type argument for pragma%");
21450 Check_Arg_Is_Local_Name
(Task_Type
);
21452 Ent
:= Entity
(Task_Type
);
21454 if not Is_Task_Type
(Ent
) then
21456 ("argument for pragma% must be task type", Task_Type
);
21459 if No
(Top_Guard
) then
21461 ("pragma% takes two arguments", Task_Type
);
21463 Check_Arg_Is_OK_Static_Expression
(Top_Guard
, Any_Integer
);
21466 Check_First_Subtype
(Task_Type
);
21468 if Rep_Item_Too_Late
(Ent
, N
) then
21477 -- pragma Test_Case
21478 -- ([Name =>] Static_String_EXPRESSION
21479 -- ,[Mode =>] MODE_TYPE
21480 -- [, Requires => Boolean_EXPRESSION]
21481 -- [, Ensures => Boolean_EXPRESSION]);
21483 -- MODE_TYPE ::= Nominal | Robustness
21485 -- Characteristics:
21487 -- * Analysis - The annotation undergoes initial checks to verify
21488 -- the legal placement and context. Secondary checks preanalyze the
21491 -- Analyze_Test_Case_In_Decl_Part
21493 -- * Expansion - None.
21495 -- * Template - The annotation utilizes the generic template of the
21496 -- related subprogram when it is:
21498 -- aspect on subprogram declaration
21500 -- The annotation must prepare its own template when it is:
21502 -- pragma on subprogram declaration
21504 -- * Globals - Capture of global references must occur after full
21507 -- * Instance - The annotation is instantiated automatically when
21508 -- the related generic subprogram is instantiated except for the
21509 -- "pragma on subprogram declaration" case. In that scenario the
21510 -- annotation must instantiate itself.
21512 when Pragma_Test_Case
=> Test_Case
: declare
21513 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
);
21514 -- Ensure that the contract of subprogram Subp_Id does not contain
21515 -- another Test_Case pragma with the same Name as the current one.
21517 -------------------------
21518 -- Check_Distinct_Name --
21519 -------------------------
21521 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
) is
21522 Items
: constant Node_Id
:= Contract
(Subp_Id
);
21523 Name
: constant String_Id
:= Get_Name_From_CTC_Pragma
(N
);
21527 -- Inspect all Test_Case pragma of the related subprogram
21528 -- looking for one with a duplicate "Name" argument.
21530 if Present
(Items
) then
21531 Prag
:= Contract_Test_Cases
(Items
);
21532 while Present
(Prag
) loop
21533 if Pragma_Name
(Prag
) = Name_Test_Case
21535 and then String_Equal
21536 (Name
, Get_Name_From_CTC_Pragma
(Prag
))
21538 Error_Msg_Sloc
:= Sloc
(Prag
);
21539 Error_Pragma
("name for pragma % is already used #");
21542 Prag
:= Next_Pragma
(Prag
);
21545 end Check_Distinct_Name
;
21549 Pack_Decl
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
21552 Subp_Decl
: Node_Id
;
21553 Subp_Id
: Entity_Id
;
21555 -- Start of processing for Test_Case
21559 Check_At_Least_N_Arguments
(2);
21560 Check_At_Most_N_Arguments
(4);
21562 ((Name_Name
, Name_Mode
, Name_Requires
, Name_Ensures
));
21566 Check_Optional_Identifier
(Arg1
, Name_Name
);
21567 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
21571 Check_Optional_Identifier
(Arg2
, Name_Mode
);
21572 Check_Arg_Is_One_Of
(Arg2
, Name_Nominal
, Name_Robustness
);
21574 -- Arguments "Requires" and "Ensures"
21576 if Present
(Arg3
) then
21577 if Present
(Arg4
) then
21578 Check_Identifier
(Arg3
, Name_Requires
);
21579 Check_Identifier
(Arg4
, Name_Ensures
);
21581 Check_Identifier_Is_One_Of
21582 (Arg3
, Name_Requires
, Name_Ensures
);
21586 -- Pragma Test_Case must be associated with a subprogram declared
21587 -- in a library-level package. First determine whether the current
21588 -- compilation unit is a legal context.
21590 if Nkind_In
(Pack_Decl
, N_Package_Declaration
,
21591 N_Generic_Package_Declaration
)
21595 -- Otherwise the placement is illegal
21602 Subp_Decl
:= Find_Related_Declaration_Or_Body
(N
);
21604 -- Find the enclosing context
21606 Context
:= Parent
(Subp_Decl
);
21608 if Present
(Context
) then
21609 Context
:= Parent
(Context
);
21612 -- Verify the placement of the pragma
21614 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
21616 ("pragma % cannot be applied to abstract subprogram");
21619 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
21620 Error_Pragma
("pragma % cannot be applied to entry");
21623 -- The context is a [generic] subprogram declared at the top level
21624 -- of the [generic] package unit.
21626 elsif Nkind_In
(Subp_Decl
, N_Generic_Subprogram_Declaration
,
21627 N_Subprogram_Declaration
)
21628 and then Present
(Context
)
21629 and then Nkind_In
(Context
, N_Generic_Package_Declaration
,
21630 N_Package_Declaration
)
21634 -- Otherwise the placement is illegal
21641 Subp_Id
:= Defining_Entity
(Subp_Decl
);
21643 -- Chain the pragma on the contract for further processing by
21644 -- Analyze_Test_Case_In_Decl_Part.
21646 Add_Contract_Item
(N
, Subp_Id
);
21648 -- A pragma that applies to a Ghost entity becomes Ghost for the
21649 -- purposes of legality checks and removal of ignored Ghost code.
21651 Mark_Pragma_As_Ghost
(N
, Subp_Id
);
21653 -- Preanalyze the original aspect argument "Name" for ASIS or for
21654 -- a generic subprogram to properly capture global references.
21656 if ASIS_Mode
or else Is_Generic_Subprogram
(Subp_Id
) then
21657 Asp_Arg
:= Test_Case_Arg
(N
, Name_Name
, From_Aspect
=> True);
21659 if Present
(Asp_Arg
) then
21661 -- The argument appears with an identifier in association
21664 if Nkind
(Asp_Arg
) = N_Component_Association
then
21665 Asp_Arg
:= Expression
(Asp_Arg
);
21668 Check_Expr_Is_OK_Static_Expression
21669 (Asp_Arg
, Standard_String
);
21673 -- Ensure that the all Test_Case pragmas of the related subprogram
21674 -- have distinct names.
21676 Check_Distinct_Name
(Subp_Id
);
21678 -- Fully analyze the pragma when it appears inside an entry
21679 -- or subprogram body because it cannot benefit from forward
21682 if Nkind_In
(Subp_Decl
, N_Entry_Body
,
21684 N_Subprogram_Body_Stub
)
21686 -- The legality checks of pragma Test_Case are affected by the
21687 -- SPARK mode in effect and the volatility of the context.
21688 -- Analyze all pragmas in a specific order.
21690 Analyze_If_Present
(Pragma_SPARK_Mode
);
21691 Analyze_If_Present
(Pragma_Volatile_Function
);
21692 Analyze_Test_Case_In_Decl_Part
(N
);
21696 --------------------------
21697 -- Thread_Local_Storage --
21698 --------------------------
21700 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
21702 when Pragma_Thread_Local_Storage
=> Thread_Local_Storage
: declare
21708 Check_Arg_Count
(1);
21709 Check_Optional_Identifier
(Arg1
, Name_Entity
);
21710 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
21712 Id
:= Get_Pragma_Arg
(Arg1
);
21715 if not Is_Entity_Name
(Id
)
21716 or else Ekind
(Entity
(Id
)) /= E_Variable
21718 Error_Pragma_Arg
("local variable name required", Arg1
);
21723 -- A pragma that applies to a Ghost entity becomes Ghost for the
21724 -- purposes of legality checks and removal of ignored Ghost code.
21726 Mark_Pragma_As_Ghost
(N
, E
);
21728 if Rep_Item_Too_Early
(E
, N
)
21730 Rep_Item_Too_Late
(E
, N
)
21735 Set_Has_Pragma_Thread_Local_Storage
(E
);
21736 Set_Has_Gigi_Rep_Item
(E
);
21737 end Thread_Local_Storage
;
21743 -- pragma Time_Slice (static_duration_EXPRESSION);
21745 when Pragma_Time_Slice
=> Time_Slice
: declare
21751 Check_Arg_Count
(1);
21752 Check_No_Identifiers
;
21753 Check_In_Main_Program
;
21754 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_Duration
);
21756 if not Error_Posted
(Arg1
) then
21758 while Present
(Nod
) loop
21759 if Nkind
(Nod
) = N_Pragma
21760 and then Pragma_Name
(Nod
) = Name_Time_Slice
21762 Error_Msg_Name_1
:= Pname
;
21763 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
21770 -- Process only if in main unit
21772 if Get_Source_Unit
(Loc
) = Main_Unit
then
21773 Opt
.Time_Slice_Set
:= True;
21774 Val
:= Expr_Value_R
(Get_Pragma_Arg
(Arg1
));
21776 if Val
<= Ureal_0
then
21777 Opt
.Time_Slice_Value
:= 0;
21779 elsif Val
> UR_From_Uint
(UI_From_Int
(1000)) then
21780 Opt
.Time_Slice_Value
:= 1_000_000_000
;
21783 Opt
.Time_Slice_Value
:=
21784 UI_To_Int
(UR_To_Uint
(Val
* UI_From_Int
(1_000_000
)));
21793 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
21795 -- TITLING_OPTION ::=
21796 -- [Title =>] STRING_LITERAL
21797 -- | [Subtitle =>] STRING_LITERAL
21799 when Pragma_Title
=> Title
: declare
21800 Args
: Args_List
(1 .. 2);
21801 Names
: constant Name_List
(1 .. 2) := (
21807 Gather_Associations
(Names
, Args
);
21810 for J
in 1 .. 2 loop
21811 if Present
(Args
(J
)) then
21812 Check_Arg_Is_OK_Static_Expression
21813 (Args
(J
), Standard_String
);
21818 ----------------------------
21819 -- Type_Invariant[_Class] --
21820 ----------------------------
21822 -- pragma Type_Invariant[_Class]
21823 -- ([Entity =>] type_LOCAL_NAME,
21824 -- [Check =>] EXPRESSION);
21826 when Pragma_Type_Invariant |
21827 Pragma_Type_Invariant_Class
=>
21828 Type_Invariant
: declare
21829 I_Pragma
: Node_Id
;
21832 Check_Arg_Count
(2);
21834 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
21835 -- setting Class_Present for the Type_Invariant_Class case.
21837 Set_Class_Present
(N
, Prag_Id
= Pragma_Type_Invariant_Class
);
21838 I_Pragma
:= New_Copy
(N
);
21839 Set_Pragma_Identifier
21840 (I_Pragma
, Make_Identifier
(Loc
, Name_Invariant
));
21841 Rewrite
(N
, I_Pragma
);
21842 Set_Analyzed
(N
, False);
21844 end Type_Invariant
;
21846 ---------------------
21847 -- Unchecked_Union --
21848 ---------------------
21850 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
21852 when Pragma_Unchecked_Union
=> Unchecked_Union
: declare
21853 Assoc
: constant Node_Id
:= Arg1
;
21854 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
21864 Check_No_Identifiers
;
21865 Check_Arg_Count
(1);
21866 Check_Arg_Is_Local_Name
(Arg1
);
21868 Find_Type
(Type_Id
);
21870 Typ
:= Entity
(Type_Id
);
21872 -- A pragma that applies to a Ghost entity becomes Ghost for the
21873 -- purposes of legality checks and removal of ignored Ghost code.
21875 Mark_Pragma_As_Ghost
(N
, Typ
);
21878 or else Rep_Item_Too_Early
(Typ
, N
)
21882 Typ
:= Underlying_Type
(Typ
);
21885 if Rep_Item_Too_Late
(Typ
, N
) then
21889 Check_First_Subtype
(Arg1
);
21891 -- Note remaining cases are references to a type in the current
21892 -- declarative part. If we find an error, we post the error on
21893 -- the relevant type declaration at an appropriate point.
21895 if not Is_Record_Type
(Typ
) then
21896 Error_Msg_N
("unchecked union must be record type", Typ
);
21899 elsif Is_Tagged_Type
(Typ
) then
21900 Error_Msg_N
("unchecked union must not be tagged", Typ
);
21903 elsif not Has_Discriminants
(Typ
) then
21905 ("unchecked union must have one discriminant", Typ
);
21908 -- Note: in previous versions of GNAT we used to check for limited
21909 -- types and give an error, but in fact the standard does allow
21910 -- Unchecked_Union on limited types, so this check was removed.
21912 -- Similarly, GNAT used to require that all discriminants have
21913 -- default values, but this is not mandated by the RM.
21915 -- Proceed with basic error checks completed
21918 Tdef
:= Type_Definition
(Declaration_Node
(Typ
));
21919 Clist
:= Component_List
(Tdef
);
21921 -- Check presence of component list and variant part
21923 if No
(Clist
) or else No
(Variant_Part
(Clist
)) then
21925 ("unchecked union must have variant part", Tdef
);
21929 -- Check components
21931 Comp
:= First
(Component_Items
(Clist
));
21932 while Present
(Comp
) loop
21933 Check_Component
(Comp
, Typ
);
21937 -- Check variant part
21939 Vpart
:= Variant_Part
(Clist
);
21941 Variant
:= First
(Variants
(Vpart
));
21942 while Present
(Variant
) loop
21943 Check_Variant
(Variant
, Typ
);
21948 Set_Is_Unchecked_Union
(Typ
);
21949 Set_Convention
(Typ
, Convention_C
);
21950 Set_Has_Unchecked_Union
(Base_Type
(Typ
));
21951 Set_Is_Unchecked_Union
(Base_Type
(Typ
));
21952 end Unchecked_Union
;
21954 ------------------------
21955 -- Unimplemented_Unit --
21956 ------------------------
21958 -- pragma Unimplemented_Unit;
21960 -- Note: this only gives an error if we are generating code, or if
21961 -- we are in a generic library unit (where the pragma appears in the
21962 -- body, not in the spec).
21964 when Pragma_Unimplemented_Unit
=> Unimplemented_Unit
: declare
21965 Cunitent
: constant Entity_Id
:=
21966 Cunit_Entity
(Get_Source_Unit
(Loc
));
21967 Ent_Kind
: constant Entity_Kind
:=
21972 Check_Arg_Count
(0);
21974 if Operating_Mode
= Generate_Code
21975 or else Ent_Kind
= E_Generic_Function
21976 or else Ent_Kind
= E_Generic_Procedure
21977 or else Ent_Kind
= E_Generic_Package
21979 Get_Name_String
(Chars
(Cunitent
));
21980 Set_Casing
(Mixed_Case
);
21981 Write_Str
(Name_Buffer
(1 .. Name_Len
));
21982 Write_Str
(" is not supported in this configuration");
21984 raise Unrecoverable_Error
;
21986 end Unimplemented_Unit
;
21988 ------------------------
21989 -- Universal_Aliasing --
21990 ------------------------
21992 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
21994 when Pragma_Universal_Aliasing
=> Universal_Alias
: declare
21999 Check_Arg_Count
(1);
22000 Check_Optional_Identifier
(Arg2
, Name_Entity
);
22001 Check_Arg_Is_Local_Name
(Arg1
);
22002 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
22004 if E_Id
= Any_Type
then
22006 elsif No
(E_Id
) or else not Is_Type
(E_Id
) then
22007 Error_Pragma_Arg
("pragma% requires type", Arg1
);
22010 -- A pragma that applies to a Ghost entity becomes Ghost for the
22011 -- purposes of legality checks and removal of ignored Ghost code.
22013 Mark_Pragma_As_Ghost
(N
, E_Id
);
22014 Set_Universal_Aliasing
(Implementation_Base_Type
(E_Id
));
22015 Record_Rep_Item
(E_Id
, N
);
22016 end Universal_Alias
;
22018 --------------------
22019 -- Universal_Data --
22020 --------------------
22022 -- pragma Universal_Data [(library_unit_NAME)];
22024 when Pragma_Universal_Data
=>
22027 -- If this is a configuration pragma, then set the universal
22028 -- addressing option, otherwise confirm that the pragma satisfies
22029 -- the requirements of library unit pragma placement and leave it
22030 -- to the GNAAMP back end to detect the pragma (avoids transitive
22031 -- setting of the option due to withed units).
22033 if Is_Configuration_Pragma
then
22034 Universal_Addressing_On_AAMP
:= True;
22036 Check_Valid_Library_Unit_Pragma
;
22039 if not AAMP_On_Target
then
22040 Error_Pragma
("??pragma% ignored (applies only to AAMP)");
22047 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
22049 when Pragma_Unmodified
=> Unmodified
: declare
22051 Arg_Expr
: Node_Id
;
22052 Arg_Id
: Entity_Id
;
22054 Ghost_Error_Posted
: Boolean := False;
22055 -- Flag set when an error concerning the illegal mix of Ghost and
22056 -- non-Ghost variables is emitted.
22058 Ghost_Id
: Entity_Id
:= Empty
;
22059 -- The entity of the first Ghost variable encountered while
22060 -- processing the arguments of the pragma.
22064 Check_At_Least_N_Arguments
(1);
22066 -- Loop through arguments
22069 while Present
(Arg
) loop
22070 Check_No_Identifier
(Arg
);
22072 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
22073 -- in fact generate reference, so that the entity will have a
22074 -- reference, which will inhibit any warnings about it not
22075 -- being referenced, and also properly show up in the ali file
22076 -- as a reference. But this reference is recorded before the
22077 -- Has_Pragma_Unreferenced flag is set, so that no warning is
22078 -- generated for this reference.
22080 Check_Arg_Is_Local_Name
(Arg
);
22081 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22083 if Is_Entity_Name
(Arg_Expr
) then
22084 Arg_Id
:= Entity
(Arg_Expr
);
22086 if Is_Assignable
(Arg_Id
) then
22087 Set_Has_Pragma_Unmodified
(Arg_Id
);
22089 -- A pragma that applies to a Ghost entity becomes Ghost
22090 -- for the purposes of legality checks and removal of
22091 -- ignored Ghost code.
22093 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22095 -- Capture the entity of the first Ghost variable being
22096 -- processed for error detection purposes.
22098 if Is_Ghost_Entity
(Arg_Id
) then
22099 if No
(Ghost_Id
) then
22100 Ghost_Id
:= Arg_Id
;
22103 -- Otherwise the variable is non-Ghost. It is illegal
22104 -- to mix references to Ghost and non-Ghost entities
22107 elsif Present
(Ghost_Id
)
22108 and then not Ghost_Error_Posted
22110 Ghost_Error_Posted
:= True;
22112 Error_Msg_Name_1
:= Pname
;
22114 ("pragma % cannot mention ghost and non-ghost "
22117 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22118 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22120 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22121 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22124 -- Otherwise the pragma referenced an illegal entity
22128 ("pragma% can only be applied to a variable", Arg_Expr
);
22140 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
22142 -- or when used in a context clause:
22144 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
22146 when Pragma_Unreferenced
=> Unreferenced
: declare
22148 Arg_Expr
: Node_Id
;
22149 Arg_Id
: Entity_Id
;
22152 Ghost_Error_Posted
: Boolean := False;
22153 -- Flag set when an error concerning the illegal mix of Ghost and
22154 -- non-Ghost names is emitted.
22156 Ghost_Id
: Entity_Id
:= Empty
;
22157 -- The entity of the first Ghost name encountered while processing
22158 -- the arguments of the pragma.
22162 Check_At_Least_N_Arguments
(1);
22164 -- Check case of appearing within context clause
22166 if Is_In_Context_Clause
then
22168 -- The arguments must all be units mentioned in a with clause
22169 -- in the same context clause. Note we already checked (in
22170 -- Par.Prag) that the arguments are either identifiers or
22171 -- selected components.
22174 while Present
(Arg
) loop
22175 Citem
:= First
(List_Containing
(N
));
22176 while Citem
/= N
loop
22177 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22179 if Nkind
(Citem
) = N_With_Clause
22180 and then Same_Name
(Name
(Citem
), Arg_Expr
)
22182 Set_Has_Pragma_Unreferenced
22185 (Library_Unit
(Citem
))));
22186 Set_Elab_Unit_Name
(Arg_Expr
, Name
(Citem
));
22195 ("argument of pragma% is not withed unit", Arg
);
22201 -- Case of not in list of context items
22205 while Present
(Arg
) loop
22206 Check_No_Identifier
(Arg
);
22208 -- Note: the analyze call done by Check_Arg_Is_Local_Name
22209 -- will in fact generate reference, so that the entity will
22210 -- have a reference, which will inhibit any warnings about
22211 -- it not being referenced, and also properly show up in the
22212 -- ali file as a reference. But this reference is recorded
22213 -- before the Has_Pragma_Unreferenced flag is set, so that
22214 -- no warning is generated for this reference.
22216 Check_Arg_Is_Local_Name
(Arg
);
22217 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22219 if Is_Entity_Name
(Arg_Expr
) then
22220 Arg_Id
:= Entity
(Arg_Expr
);
22222 -- If the entity is overloaded, the pragma applies to the
22223 -- most recent overloading, as documented. In this case,
22224 -- name resolution does not generate a reference, so it
22225 -- must be done here explicitly.
22227 if Is_Overloaded
(Arg_Expr
) then
22228 Generate_Reference
(Arg_Id
, N
);
22231 Set_Has_Pragma_Unreferenced
(Arg_Id
);
22233 -- A pragma that applies to a Ghost entity becomes Ghost
22234 -- for the purposes of legality checks and removal of
22235 -- ignored Ghost code.
22237 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22239 -- Capture the entity of the first Ghost name being
22240 -- processed for error detection purposes.
22242 if Is_Ghost_Entity
(Arg_Id
) then
22243 if No
(Ghost_Id
) then
22244 Ghost_Id
:= Arg_Id
;
22247 -- Otherwise the name is non-Ghost. It is illegal to mix
22248 -- references to Ghost and non-Ghost entities
22251 elsif Present
(Ghost_Id
)
22252 and then not Ghost_Error_Posted
22254 Ghost_Error_Posted
:= True;
22256 Error_Msg_Name_1
:= Pname
;
22258 ("pragma % cannot mention ghost and non-ghost names",
22261 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22262 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22264 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22265 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22274 --------------------------
22275 -- Unreferenced_Objects --
22276 --------------------------
22278 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
22280 when Pragma_Unreferenced_Objects
=> Unreferenced_Objects
: declare
22282 Arg_Expr
: Node_Id
;
22283 Arg_Id
: Entity_Id
;
22285 Ghost_Error_Posted
: Boolean := False;
22286 -- Flag set when an error concerning the illegal mix of Ghost and
22287 -- non-Ghost types is emitted.
22289 Ghost_Id
: Entity_Id
:= Empty
;
22290 -- The entity of the first Ghost type encountered while processing
22291 -- the arguments of the pragma.
22295 Check_At_Least_N_Arguments
(1);
22298 while Present
(Arg
) loop
22299 Check_No_Identifier
(Arg
);
22300 Check_Arg_Is_Local_Name
(Arg
);
22301 Arg_Expr
:= Get_Pragma_Arg
(Arg
);
22303 if Is_Entity_Name
(Arg_Expr
) then
22304 Arg_Id
:= Entity
(Arg_Expr
);
22306 if Is_Type
(Arg_Id
) then
22307 Set_Has_Pragma_Unreferenced_Objects
(Arg_Id
);
22309 -- A pragma that applies to a Ghost entity becomes Ghost
22310 -- for the purposes of legality checks and removal of
22311 -- ignored Ghost code.
22313 Mark_Pragma_As_Ghost
(N
, Arg_Id
);
22315 -- Capture the entity of the first Ghost type being
22316 -- processed for error detection purposes.
22318 if Is_Ghost_Entity
(Arg_Id
) then
22319 if No
(Ghost_Id
) then
22320 Ghost_Id
:= Arg_Id
;
22323 -- Otherwise the type is non-Ghost. It is illegal to mix
22324 -- references to Ghost and non-Ghost entities
22327 elsif Present
(Ghost_Id
)
22328 and then not Ghost_Error_Posted
22330 Ghost_Error_Posted
:= True;
22332 Error_Msg_Name_1
:= Pname
;
22334 ("pragma % cannot mention ghost and non-ghost types",
22337 Error_Msg_Sloc
:= Sloc
(Ghost_Id
);
22338 Error_Msg_NE
("\& # declared as ghost", N
, Ghost_Id
);
22340 Error_Msg_Sloc
:= Sloc
(Arg_Id
);
22341 Error_Msg_NE
("\& # declared as non-ghost", N
, Arg_Id
);
22345 ("argument for pragma% must be type or subtype", Arg
);
22349 ("argument for pragma% must be type or subtype", Arg
);
22354 end Unreferenced_Objects
;
22356 ------------------------------
22357 -- Unreserve_All_Interrupts --
22358 ------------------------------
22360 -- pragma Unreserve_All_Interrupts;
22362 when Pragma_Unreserve_All_Interrupts
=>
22364 Check_Arg_Count
(0);
22366 if In_Extended_Main_Code_Unit
(Main_Unit_Entity
) then
22367 Unreserve_All_Interrupts
:= True;
22374 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
22376 when Pragma_Unsuppress
=>
22378 Process_Suppress_Unsuppress
(Suppress_Case
=> False);
22380 ----------------------------
22381 -- Unevaluated_Use_Of_Old --
22382 ----------------------------
22384 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
22386 when Pragma_Unevaluated_Use_Of_Old
=>
22388 Check_Arg_Count
(1);
22389 Check_No_Identifiers
;
22390 Check_Arg_Is_One_Of
(Arg1
, Name_Error
, Name_Warn
, Name_Allow
);
22392 -- Suppress/Unsuppress can appear as a configuration pragma, or in
22393 -- a declarative part or a package spec.
22395 if not Is_Configuration_Pragma
then
22396 Check_Is_In_Decl_Part_Or_Package_Spec
;
22399 -- Store proper setting of Uneval_Old
22401 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
22402 Uneval_Old
:= Fold_Upper
(Name_Buffer
(1));
22404 -------------------
22405 -- Use_VADS_Size --
22406 -------------------
22408 -- pragma Use_VADS_Size;
22410 when Pragma_Use_VADS_Size
=>
22412 Check_Arg_Count
(0);
22413 Check_Valid_Configuration_Pragma
;
22414 Use_VADS_Size
:= True;
22416 ---------------------
22417 -- Validity_Checks --
22418 ---------------------
22420 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
22422 when Pragma_Validity_Checks
=> Validity_Checks
: declare
22423 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
22429 Check_Arg_Count
(1);
22430 Check_No_Identifiers
;
22432 -- Pragma always active unless in CodePeer or GNATprove modes,
22433 -- which use a fixed configuration of validity checks.
22435 if not (CodePeer_Mode
or GNATprove_Mode
) then
22436 if Nkind
(A
) = N_String_Literal
then
22440 Slen
: constant Natural := Natural (String_Length
(S
));
22441 Options
: String (1 .. Slen
);
22445 -- Couldn't we use a for loop here over Options'Range???
22449 C
:= Get_String_Char
(S
, Int
(J
));
22451 -- This is a weird test, it skips setting validity
22452 -- checks entirely if any element of S is out of
22453 -- range of Character, what is that about ???
22455 exit when not In_Character_Range
(C
);
22456 Options
(J
) := Get_Character
(C
);
22459 Set_Validity_Check_Options
(Options
);
22467 elsif Nkind
(A
) = N_Identifier
then
22468 if Chars
(A
) = Name_All_Checks
then
22469 Set_Validity_Check_Options
("a");
22470 elsif Chars
(A
) = Name_On
then
22471 Validity_Checks_On
:= True;
22472 elsif Chars
(A
) = Name_Off
then
22473 Validity_Checks_On
:= False;
22477 end Validity_Checks
;
22483 -- pragma Volatile (LOCAL_NAME);
22485 when Pragma_Volatile
=>
22486 Process_Atomic_Independent_Shared_Volatile
;
22488 -------------------------
22489 -- Volatile_Components --
22490 -------------------------
22492 -- pragma Volatile_Components (array_LOCAL_NAME);
22494 -- Volatile is handled by the same circuit as Atomic_Components
22496 --------------------------
22497 -- Volatile_Full_Access --
22498 --------------------------
22500 -- pragma Volatile_Full_Access (LOCAL_NAME);
22502 when Pragma_Volatile_Full_Access
=>
22504 Process_Atomic_Independent_Shared_Volatile
;
22506 -----------------------
22507 -- Volatile_Function --
22508 -----------------------
22510 -- pragma Volatile_Function [ (boolean_EXPRESSION) ];
22512 when Pragma_Volatile_Function
=> Volatile_Function
: declare
22513 Over_Id
: Entity_Id
;
22514 Spec_Id
: Entity_Id
;
22515 Subp_Decl
: Node_Id
;
22519 Check_No_Identifiers
;
22520 Check_At_Most_N_Arguments
(1);
22523 Find_Related_Declaration_Or_Body
(N
, Do_Checks
=> True);
22525 -- Generic subprogram
22527 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
22530 -- Body acts as spec
22532 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
22533 and then No
(Corresponding_Spec
(Subp_Decl
))
22537 -- Body stub acts as spec
22539 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
22540 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
22546 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
22554 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
22556 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
22561 -- Chain the pragma on the contract for completeness
22563 Add_Contract_Item
(N
, Spec_Id
);
22565 -- The legality checks of pragma Volatile_Function are affected by
22566 -- the SPARK mode in effect. Analyze all pragmas in a specific
22569 Analyze_If_Present
(Pragma_SPARK_Mode
);
22571 -- A pragma that applies to a Ghost entity becomes Ghost for the
22572 -- purposes of legality checks and removal of ignored Ghost code.
22574 Mark_Pragma_As_Ghost
(N
, Spec_Id
);
22576 -- A volatile function cannot override a non-volatile function
22577 -- (SPARK RM 7.1.2(15)). Overriding checks are usually performed
22578 -- in New_Overloaded_Entity, however at that point the pragma has
22579 -- not been processed yet.
22581 Over_Id
:= Overridden_Operation
(Spec_Id
);
22583 if Present
(Over_Id
)
22584 and then not Is_Volatile_Function
(Over_Id
)
22587 ("incompatible volatile function values in effect", Spec_Id
);
22589 Error_Msg_Sloc
:= Sloc
(Over_Id
);
22591 ("\& declared # with Volatile_Function value `False`",
22594 Error_Msg_Sloc
:= Sloc
(Spec_Id
);
22596 ("\overridden # with Volatile_Function value `True`",
22600 -- Analyze the Boolean expression (if any)
22602 if Present
(Arg1
) then
22603 Check_Static_Boolean_Expression
(Get_Pragma_Arg
(Arg1
));
22605 end Volatile_Function
;
22607 ----------------------
22608 -- Warning_As_Error --
22609 ----------------------
22611 -- pragma Warning_As_Error (static_string_EXPRESSION);
22613 when Pragma_Warning_As_Error
=>
22615 Check_Arg_Count
(1);
22616 Check_No_Identifiers
;
22617 Check_Valid_Configuration_Pragma
;
22619 if not Is_Static_String_Expression
(Arg1
) then
22621 ("argument of pragma% must be static string expression",
22624 -- OK static string expression
22627 Acquire_Warning_Match_String
(Arg1
);
22628 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
22629 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
22630 new String'(Name_Buffer (1 .. Name_Len));
22637 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
22639 -- DETAILS ::= On | Off
22640 -- DETAILS ::= On | Off, local_NAME
22641 -- DETAILS ::= static_string_EXPRESSION
22642 -- DETAILS ::= On | Off, static_string_EXPRESSION
22644 -- TOOL_NAME ::= GNAT | GNATProve
22646 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
22648 -- Note: If the first argument matches an allowed tool name, it is
22649 -- always considered to be a tool name, even if there is a string
22650 -- variable of that name.
22652 -- Note if the second argument of DETAILS is a local_NAME then the
22653 -- second form is always understood. If the intention is to use
22654 -- the fourth form, then you can write NAME & "" to force the
22655 -- intepretation as a static_string_EXPRESSION.
22657 when Pragma_Warnings => Warnings : declare
22658 Reason : String_Id;
22662 Check_At_Least_N_Arguments (1);
22664 -- See if last argument is labeled Reason. If so, make sure we
22665 -- have a string literal or a concatenation of string literals,
22666 -- and acquire the REASON string. Then remove the REASON argument
22667 -- by decreasing Num_Args by one; Remaining processing looks only
22668 -- at first Num_Args arguments).
22671 Last_Arg : constant Node_Id :=
22672 Last (Pragma_Argument_Associations (N));
22675 if Nkind (Last_Arg) = N_Pragma_Argument_Association
22676 and then Chars (Last_Arg) = Name_Reason
22679 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
22680 Reason := End_String;
22681 Arg_Count := Arg_Count - 1;
22683 -- Not allowed in compiler units (bootstrap issues)
22685 Check_Compiler_Unit ("Reason for pragma Warnings", N);
22687 -- No REASON string, set null string as reason
22690 Reason := Null_String_Id;
22694 -- Now proceed with REASON taken care of and eliminated
22696 Check_No_Identifiers;
22698 -- If debug flag -gnatd.i is set, pragma is ignored
22700 if Debug_Flag_Dot_I then
22704 -- Process various forms of the pragma
22707 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
22708 Shifted_Args : List_Id;
22711 -- See if first argument is a tool name, currently either
22712 -- GNAT or GNATprove. If so, either ignore the pragma if the
22713 -- tool used does not match, or continue as if no tool name
22714 -- was given otherwise, by shifting the arguments.
22716 if Nkind (Argx) = N_Identifier
22717 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
22719 if Chars (Argx) = Name_Gnat then
22720 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
22721 Rewrite (N, Make_Null_Statement (Loc));
22726 elsif Chars (Argx) = Name_Gnatprove then
22727 if not GNATprove_Mode then
22728 Rewrite (N, Make_Null_Statement (Loc));
22734 raise Program_Error;
22737 -- At this point, the pragma Warnings applies to the tool,
22738 -- so continue with shifted arguments.
22740 Arg_Count := Arg_Count - 1;
22742 if Arg_Count = 1 then
22743 Shifted_Args := New_List (New_Copy (Arg2));
22744 elsif Arg_Count = 2 then
22745 Shifted_Args := New_List (New_Copy (Arg2),
22747 elsif Arg_Count = 3 then
22748 Shifted_Args := New_List (New_Copy (Arg2),
22752 raise Program_Error;
22757 Chars => Name_Warnings,
22758 Pragma_Argument_Associations => Shifted_Args));
22763 -- One argument case
22765 if Arg_Count = 1 then
22767 -- On/Off one argument case was processed by parser
22769 if Nkind (Argx) = N_Identifier
22770 and then Nam_In (Chars (Argx), Name_On, Name_Off)
22774 -- One argument case must be ON/OFF or static string expr
22776 elsif not Is_Static_String_Expression (Arg1) then
22778 ("argument of pragma% must be On/Off or static string "
22779 & "expression", Arg1);
22781 -- One argument string expression case
22785 Lit : constant Node_Id := Expr_Value_S (Argx);
22786 Str : constant String_Id := Strval (Lit);
22787 Len : constant Nat := String_Length (Str);
22795 while J <= Len loop
22796 C := Get_String_Char (Str, J);
22797 OK := In_Character_Range (C);
22800 Chr := Get_Character (C);
22802 -- Dash case: only -Wxxx is accepted
22809 C := Get_String_Char (Str, J);
22810 Chr := Get_Character (C);
22811 exit when Chr = 'W
';
22816 elsif J < Len and then Chr = '.' then
22818 C := Get_String_Char (Str, J);
22819 Chr := Get_Character (C);
22821 if not Set_Dot_Warning_Switch (Chr) then
22823 ("invalid warning switch character "
22824 & '.' & Chr, Arg1);
22830 OK := Set_Warning_Switch (Chr);
22836 ("invalid warning switch character " & Chr,
22845 -- Two or more arguments (must be two)
22848 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
22849 Check_Arg_Count (2);
22857 E_Id := Get_Pragma_Arg (Arg2);
22860 -- In the expansion of an inlined body, a reference to
22861 -- the formal may be wrapped in a conversion if the
22862 -- actual is a conversion. Retrieve the real entity name.
22864 if (In_Instance_Body or In_Inlined_Body)
22865 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
22867 E_Id := Expression (E_Id);
22870 -- Entity name case
22872 if Is_Entity_Name (E_Id) then
22873 E := Entity (E_Id);
22880 (E, (Chars (Get_Pragma_Arg (Arg1)) =
22883 -- For OFF case, make entry in warnings off
22884 -- pragma table for later processing. But we do
22885 -- not do that within an instance, since these
22886 -- warnings are about what is needed in the
22887 -- template, not an instance of it.
22889 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
22890 and then Warn_On_Warnings_Off
22891 and then not In_Instance
22893 Warnings_Off_Pragmas.Append ((N, E, Reason));
22896 if Is_Enumeration_Type (E) then
22900 Lit := First_Literal (E);
22901 while Present (Lit) loop
22902 Set_Warnings_Off (Lit);
22903 Next_Literal (Lit);
22908 exit when No (Homonym (E));
22913 -- Error if not entity or static string expression case
22915 elsif not Is_Static_String_Expression (Arg2) then
22917 ("second argument of pragma% must be entity name "
22918 & "or static string expression", Arg2);
22920 -- Static string expression case
22923 Acquire_Warning_Match_String (Arg2);
22925 -- Note on configuration pragma case: If this is a
22926 -- configuration pragma, then for an OFF pragma, we
22927 -- just set Config True in the call, which is all
22928 -- that needs to be done. For the case of ON, this
22929 -- is normally an error, unless it is canceling the
22930 -- effect of a previous OFF pragma in the same file.
22931 -- In any other case, an error will be signalled (ON
22932 -- with no matching OFF).
22934 -- Note: We set Used if we are inside a generic to
22935 -- disable the test that the non-config case actually
22936 -- cancels a warning. That's because we can't be sure
22937 -- there isn't an instantiation in some other unit
22938 -- where a warning is suppressed.
22940 -- We could do a little better here by checking if the
22941 -- generic unit we are inside is public, but for now
22942 -- we don't bother with that refinement.
22944 if Chars (Argx) = Name_Off then
22945 Set_Specific_Warning_Off
22946 (Loc, Name_Buffer (1 .. Name_Len), Reason,
22947 Config => Is_Configuration_Pragma,
22948 Used => Inside_A_Generic or else In_Instance);
22950 elsif Chars (Argx) = Name_On then
22951 Set_Specific_Warning_On
22952 (Loc, Name_Buffer (1 .. Name_Len), Err);
22956 ("??pragma Warnings On with no matching "
22957 & "Warnings Off", Loc);
22966 -------------------
22967 -- Weak_External --
22968 -------------------
22970 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
22972 when Pragma_Weak_External => Weak_External : declare
22977 Check_Arg_Count (1);
22978 Check_Optional_Identifier (Arg1, Name_Entity);
22979 Check_Arg_Is_Library_Level_Local_Name (Arg1);
22980 Ent := Entity (Get_Pragma_Arg (Arg1));
22982 if Rep_Item_Too_Early (Ent, N) then
22985 Ent := Underlying_Type (Ent);
22988 -- The only processing required is to link this item on to the
22989 -- list of rep items for the given entity. This is accomplished
22990 -- by the call to Rep_Item_Too_Late (when no error is detected
22991 -- and False is returned).
22993 if Rep_Item_Too_Late (Ent, N) then
22996 Set_Has_Gigi_Rep_Item (Ent);
23000 -----------------------------
23001 -- Wide_Character_Encoding --
23002 -----------------------------
23004 -- pragma Wide_Character_Encoding (IDENTIFIER);
23006 when Pragma_Wide_Character_Encoding =>
23009 -- Nothing to do, handled in parser. Note that we do not enforce
23010 -- configuration pragma placement, this pragma can appear at any
23011 -- place in the source, allowing mixed encodings within a single
23016 --------------------
23017 -- Unknown_Pragma --
23018 --------------------
23020 -- Should be impossible, since the case of an unknown pragma is
23021 -- separately processed before the case statement is entered.
23023 when Unknown_Pragma =>
23024 raise Program_Error;
23027 -- AI05-0144: detect dangerous order dependence. Disabled for now,
23028 -- until AI is formally approved.
23030 -- Check_Order_Dependence;
23033 when Pragma_Exit => null;
23034 end Analyze_Pragma;
23036 ---------------------------------------------
23037 -- Analyze_Pre_Post_Condition_In_Decl_Part --
23038 ---------------------------------------------
23040 procedure Analyze_Pre_Post_Condition_In_Decl_Part
23042 Freeze_Id : Entity_Id := Empty)
23044 procedure Process_Class_Wide_Condition
23046 Spec_Id : Entity_Id;
23047 Subp_Decl : Node_Id);
23048 -- Replace the type of all references to the controlling formal of
23049 -- subprogram Spec_Id found in expression Expr with the corresponding
23050 -- class-wide type. Subp_Decl is the subprogram [body] declaration
23051 -- where the pragma resides.
23053 ----------------------------------
23054 -- Process_Class_Wide_Condition --
23055 ----------------------------------
23057 procedure Process_Class_Wide_Condition
23059 Spec_Id : Entity_Id;
23060 Subp_Decl : Node_Id)
23062 Disp_Typ : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
23064 ACW : Entity_Id := Empty;
23065 -- Access to Disp_Typ'Class, created if there is a controlling formal
23066 -- that is an access parameter.
23068 function Access_Class_Wide_Type return Entity_Id;
23069 -- If expression Expr contains a reference to a controlling access
23070 -- parameter, create an access to Disp_Typ'Class for the necessary
23071 -- conversions if one does not exist.
23073 function Replace_Type (N : Node_Id) return Traverse_Result;
23074 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
23075 -- aspect for a primitive subprogram of a tagged type Disp_Typ, a
23076 -- name that denotes a formal parameter of type Disp_Typ is treated
23077 -- as having type Disp_Typ'Class. Similarly, a name that denotes a
23078 -- formal access parameter of type access-to-Disp_Typ is interpreted
23079 -- as with type access-to-Disp_Typ'Class. This ensures the expression
23080 -- is well defined for a primitive subprogram of a type descended
23083 ----------------------------
23084 -- Access_Class_Wide_Type --
23085 ----------------------------
23087 function Access_Class_Wide_Type return Entity_Id is
23088 Loc : constant Source_Ptr := Sloc (N);
23092 ACW := Make_Temporary (Loc, 'T
');
23094 Insert_Before_And_Analyze (Subp_Decl,
23095 Make_Full_Type_Declaration (Loc,
23096 Defining_Identifier => ACW,
23098 Make_Access_To_Object_Definition (Loc,
23099 Subtype_Indication =>
23100 New_Occurrence_Of (Class_Wide_Type (Disp_Typ), Loc),
23101 All_Present => True)));
23103 Freeze_Before (Subp_Decl, ACW);
23107 end Access_Class_Wide_Type;
23113 function Replace_Type (N : Node_Id) return Traverse_Result is
23114 Context : constant Node_Id := Parent (N);
23115 Loc : constant Source_Ptr := Sloc (N);
23116 CW_Typ : Entity_Id := Empty;
23121 if Is_Entity_Name (N)
23122 and then Present (Entity (N))
23123 and then Is_Formal (Entity (N))
23126 Typ := Etype (Ent);
23128 -- Do not perform the type replacement for selector names in
23129 -- parameter associations. These carry an entity for reference
23130 -- purposes, but semantically they are just identifiers.
23132 if Nkind (Context) = N_Type_Conversion then
23135 elsif Nkind (Context) = N_Parameter_Association
23136 and then Selector_Name (Context) = N
23140 elsif Typ = Disp_Typ then
23141 CW_Typ := Class_Wide_Type (Typ);
23143 elsif Is_Access_Type (Typ)
23144 and then Designated_Type (Typ) = Disp_Typ
23146 CW_Typ := Access_Class_Wide_Type;
23149 if Present (CW_Typ) then
23151 Make_Type_Conversion (Loc,
23152 Subtype_Mark => New_Occurrence_Of (CW_Typ, Loc),
23153 Expression => New_Occurrence_Of (Ent, Loc)));
23154 Set_Etype (N, CW_Typ);
23161 procedure Replace_Types is new Traverse_Proc (Replace_Type);
23163 -- Start of processing for Process_Class_Wide_Condition
23166 -- The subprogram subject to Pre'Class/Post'Class does not have a
23167 -- dispatching type, therefore the aspect/pragma is illegal.
23169 if No (Disp_Typ) then
23170 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
23172 if From_Aspect_Specification (N) then
23174 ("aspect % can only be specified for a primitive operation "
23175 & "of a tagged type", Corresponding_Aspect (N));
23177 -- The pragma is a source construct
23181 ("pragma % can only be specified for a primitive operation "
23182 & "of a tagged type", N);
23186 Replace_Types (Expr);
23187 end Process_Class_Wide_Condition;
23191 Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N);
23192 Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl);
23193 Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id));
23195 Save_Ghost_Mode : constant Ghost_Mode_Type := Ghost_Mode;
23198 Restore_Scope : Boolean := False;
23200 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
23203 -- Do not analyze the pragma multiple times
23205 if Is_Analyzed_Pragma (N) then
23209 -- Set the Ghost mode in effect from the pragma. Due to the delayed
23210 -- analysis of the pragma, the Ghost mode at point of declaration and
23211 -- point of analysis may not necessarely be the same. Use the mode in
23212 -- effect at the point of declaration.
23214 Set_Ghost_Mode (N);
23216 -- Ensure that the subprogram and its formals are visible when analyzing
23217 -- the expression of the pragma.
23219 if not In_Open_Scopes (Spec_Id) then
23220 Restore_Scope := True;
23221 Push_Scope (Spec_Id);
23223 if Is_Generic_Subprogram (Spec_Id) then
23224 Install_Generic_Formals (Spec_Id);
23226 Install_Formals (Spec_Id);
23230 Errors := Serious_Errors_Detected;
23231 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
23233 -- Emit a clarification message when the expression contains at least
23234 -- one undefined reference, possibly due to contract "freezing".
23236 if Errors /= Serious_Errors_Detected
23237 and then Present (Freeze_Id)
23238 and then Has_Undefined_Reference (Expr)
23240 Contract_Freeze_Error (Spec_Id, Freeze_Id);
23243 -- For a class-wide condition, a reference to a controlling formal must
23244 -- be interpreted as having the class-wide type (or an access to such)
23245 -- so that the inherited condition can be properly applied to any
23246 -- overriding operation (see ARM12 6.6.1 (7)).
23248 if Class_Present (N) then
23249 Process_Class_Wide_Condition (Expr, Spec_Id, Subp_Decl);
23252 if Restore_Scope then
23256 -- Currently it is not possible to inline pre/postconditions on a
23257 -- subprogram subject to pragma Inline_Always.
23259 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
23260 Ghost_Mode := Save_Ghost_Mode;
23262 Set_Is_Analyzed_Pragma (N);
23263 end Analyze_Pre_Post_Condition_In_Decl_Part;
23265 ------------------------------------------
23266 -- Analyze_Refined_Depends_In_Decl_Part --
23267 ------------------------------------------
23269 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
23270 Body_Inputs : Elist_Id := No_Elist;
23271 Body_Outputs : Elist_Id := No_Elist;
23272 -- The inputs and outputs of the subprogram body synthesized from pragma
23273 -- Refined_Depends.
23275 Dependencies : List_Id := No_List;
23277 -- The corresponding Depends pragma along with its clauses
23279 Matched_Items : Elist_Id := No_Elist;
23280 -- A list containing the entities of all successfully matched items
23281 -- found in pragma Depends.
23283 Refinements : List_Id := No_List;
23284 -- The clauses of pragma Refined_Depends
23286 Spec_Id : Entity_Id;
23287 -- The entity of the subprogram subject to pragma Refined_Depends
23289 Spec_Inputs : Elist_Id := No_Elist;
23290 Spec_Outputs : Elist_Id := No_Elist;
23291 -- The inputs and outputs of the subprogram spec synthesized from pragma
23294 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
23295 -- Try to match a single dependency clause Dep_Clause against one or
23296 -- more refinement clauses found in list Refinements. Each successful
23297 -- match eliminates at least one refinement clause from Refinements.
23299 procedure Check_Output_States;
23300 -- Determine whether pragma Depends contains an output state with a
23301 -- visible refinement and if so, ensure that pragma Refined_Depends
23302 -- mentions all its constituents as outputs.
23304 procedure Normalize_Clauses (Clauses : List_Id);
23305 -- Given a list of dependence or refinement clauses Clauses, normalize
23306 -- each clause by creating multiple dependencies with exactly one input
23309 procedure Report_Extra_Clauses;
23310 -- Emit an error for each extra clause found in list Refinements
23312 -----------------------------
23313 -- Check_Dependency_Clause --
23314 -----------------------------
23316 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
23317 Dep_Input : constant Node_Id := Expression (Dep_Clause);
23318 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
23320 function Is_In_Out_State_Clause return Boolean;
23321 -- Determine whether dependence clause Dep_Clause denotes an abstract
23322 -- state that depends on itself (State => State).
23324 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
23325 -- Determine whether item Item denotes an abstract state with visible
23326 -- null refinement.
23328 procedure Match_Items
23329 (Dep_Item : Node_Id;
23330 Ref_Item : Node_Id;
23331 Matched : out Boolean);
23332 -- Try to match dependence item Dep_Item against refinement item
23333 -- Ref_Item. To match against a possible null refinement (see 2, 7),
23334 -- set Ref_Item to Empty. Flag Matched is set to True when one of
23335 -- the following conformance scenarios is in effect:
23336 -- 1) Both items denote null
23337 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
23338 -- 3) Both items denote attribute 'Result
23339 -- 4) Both items denote the same object
23340 -- 5) Both items denote the same formal parameter
23341 -- 6) Both items denote the same current instance of a type
23342 -- 7) Both items denote the same discriminant
23343 -- 8) Dep_Item is an abstract state with visible null refinement
23344 -- and Ref_Item denotes null.
23345 -- 9) Dep_Item is an abstract state with visible null refinement
23346 -- and Ref_Item is Empty (special case).
23347 -- 10) Dep_Item is an abstract state with visible non-null
23348 -- refinement and Ref_Item denotes one of its constituents.
23349 -- 11) Dep_Item is an abstract state without a visible refinement
23350 -- and Ref_Item denotes the same state.
23351 -- When scenario 10 is in effect, the entity of the abstract state
23352 -- denoted by Dep_Item is added to list Refined_States.
23354 procedure Record_Item
(Item_Id
: Entity_Id
);
23355 -- Store the entity of an item denoted by Item_Id in Matched_Items
23357 ----------------------------
23358 -- Is_In_Out_State_Clause --
23359 ----------------------------
23361 function Is_In_Out_State_Clause
return Boolean is
23362 Dep_Input_Id
: Entity_Id
;
23363 Dep_Output_Id
: Entity_Id
;
23366 -- Detect the following clause:
23369 if Is_Entity_Name
(Dep_Input
)
23370 and then Is_Entity_Name
(Dep_Output
)
23372 -- Handle abstract views generated for limited with clauses
23374 Dep_Input_Id
:= Available_View
(Entity_Of
(Dep_Input
));
23375 Dep_Output_Id
:= Available_View
(Entity_Of
(Dep_Output
));
23378 Ekind
(Dep_Input_Id
) = E_Abstract_State
23379 and then Dep_Input_Id
= Dep_Output_Id
;
23383 end Is_In_Out_State_Clause
;
23385 ---------------------------
23386 -- Is_Null_Refined_State --
23387 ---------------------------
23389 function Is_Null_Refined_State
(Item
: Node_Id
) return Boolean is
23390 Item_Id
: Entity_Id
;
23393 if Is_Entity_Name
(Item
) then
23395 -- Handle abstract views generated for limited with clauses
23397 Item_Id
:= Available_View
(Entity_Of
(Item
));
23400 Ekind
(Item_Id
) = E_Abstract_State
23401 and then Has_Null_Visible_Refinement
(Item_Id
);
23405 end Is_Null_Refined_State
;
23411 procedure Match_Items
23412 (Dep_Item
: Node_Id
;
23413 Ref_Item
: Node_Id
;
23414 Matched
: out Boolean)
23416 Dep_Item_Id
: Entity_Id
;
23417 Ref_Item_Id
: Entity_Id
;
23420 -- Assume that the two items do not match
23424 -- A null matches null or Empty (special case)
23426 if Nkind
(Dep_Item
) = N_Null
23427 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
23431 -- Attribute 'Result matches attribute 'Result
23433 elsif Is_Attribute_Result
(Dep_Item
)
23434 and then Is_Attribute_Result
(Dep_Item
)
23438 -- Abstract states, current instances of concurrent types,
23439 -- discriminants, formal parameters and objects.
23441 elsif Is_Entity_Name
(Dep_Item
) then
23443 -- Handle abstract views generated for limited with clauses
23445 Dep_Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
23447 if Ekind
(Dep_Item_Id
) = E_Abstract_State
then
23449 -- An abstract state with visible null refinement matches
23450 -- null or Empty (special case).
23452 if Has_Null_Visible_Refinement
(Dep_Item_Id
)
23453 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
23455 Record_Item
(Dep_Item_Id
);
23458 -- An abstract state with visible non-null refinement
23459 -- matches one of its constituents.
23461 elsif Has_Non_Null_Visible_Refinement
(Dep_Item_Id
) then
23462 if Is_Entity_Name
(Ref_Item
) then
23463 Ref_Item_Id
:= Entity_Of
(Ref_Item
);
23465 if Ekind_In
(Ref_Item_Id
, E_Abstract_State
,
23468 and then Present
(Encapsulating_State
(Ref_Item_Id
))
23469 and then Encapsulating_State
(Ref_Item_Id
) =
23472 Record_Item
(Dep_Item_Id
);
23477 -- An abstract state without a visible refinement matches
23480 elsif Is_Entity_Name
(Ref_Item
)
23481 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
23483 Record_Item
(Dep_Item_Id
);
23487 -- A current instance of a concurrent type, discriminant,
23488 -- formal parameter or an object matches itself.
23490 elsif Is_Entity_Name
(Ref_Item
)
23491 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
23493 Record_Item
(Dep_Item_Id
);
23503 procedure Record_Item
(Item_Id
: Entity_Id
) is
23505 if not Contains
(Matched_Items
, Item_Id
) then
23506 Append_New_Elmt
(Item_Id
, Matched_Items
);
23512 Clause_Matched
: Boolean := False;
23513 Dummy
: Boolean := False;
23514 Inputs_Match
: Boolean;
23515 Next_Ref_Clause
: Node_Id
;
23516 Outputs_Match
: Boolean;
23517 Ref_Clause
: Node_Id
;
23518 Ref_Input
: Node_Id
;
23519 Ref_Output
: Node_Id
;
23521 -- Start of processing for Check_Dependency_Clause
23524 -- Do not perform this check in an instance because it was already
23525 -- performed successfully in the generic template.
23527 if Is_Generic_Instance
(Spec_Id
) then
23531 -- Examine all refinement clauses and compare them against the
23532 -- dependence clause.
23534 Ref_Clause
:= First
(Refinements
);
23535 while Present
(Ref_Clause
) loop
23536 Next_Ref_Clause
:= Next
(Ref_Clause
);
23538 -- Obtain the attributes of the current refinement clause
23540 Ref_Input
:= Expression
(Ref_Clause
);
23541 Ref_Output
:= First
(Choices
(Ref_Clause
));
23543 -- The current refinement clause matches the dependence clause
23544 -- when both outputs match and both inputs match. See routine
23545 -- Match_Items for all possible conformance scenarios.
23547 -- Depends Dep_Output => Dep_Input
23551 -- Refined_Depends Ref_Output => Ref_Input
23554 (Dep_Item
=> Dep_Input
,
23555 Ref_Item
=> Ref_Input
,
23556 Matched
=> Inputs_Match
);
23559 (Dep_Item
=> Dep_Output
,
23560 Ref_Item
=> Ref_Output
,
23561 Matched
=> Outputs_Match
);
23563 -- An In_Out state clause may be matched against a refinement with
23564 -- a null input or null output as long as the non-null side of the
23565 -- relation contains a valid constituent of the In_Out_State.
23567 if Is_In_Out_State_Clause
then
23569 -- Depends => (State => State)
23570 -- Refined_Depends => (null => Constit) -- OK
23573 and then not Outputs_Match
23574 and then Nkind
(Ref_Output
) = N_Null
23576 Outputs_Match
:= True;
23579 -- Depends => (State => State)
23580 -- Refined_Depends => (Constit => null) -- OK
23582 if not Inputs_Match
23583 and then Outputs_Match
23584 and then Nkind
(Ref_Input
) = N_Null
23586 Inputs_Match
:= True;
23590 -- The current refinement clause is legally constructed following
23591 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
23592 -- the pool of candidates. The seach continues because a single
23593 -- dependence clause may have multiple matching refinements.
23595 if Inputs_Match
and then Outputs_Match
then
23596 Clause_Matched
:= True;
23597 Remove
(Ref_Clause
);
23600 Ref_Clause
:= Next_Ref_Clause
;
23603 -- Depending on the order or composition of refinement clauses, an
23604 -- In_Out state clause may not be directly refinable.
23606 -- Depends => ((Output, State) => (Input, State))
23607 -- Refined_State => (State => (Constit_1, Constit_2))
23608 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
23610 -- Matching normalized clause (State => State) fails because there is
23611 -- no direct refinement capable of satisfying this relation. Another
23612 -- similar case arises when clauses (Constit_1 => Input) and (Output
23613 -- => Constit_2) are matched first, leaving no candidates for clause
23614 -- (State => State). Both scenarios are legal as long as one of the
23615 -- previous clauses mentioned a valid constituent of State.
23617 if not Clause_Matched
23618 and then Is_In_Out_State_Clause
23620 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
23622 Clause_Matched
:= True;
23625 -- A clause where the input is an abstract state with visible null
23626 -- refinement is implicitly matched when the output has already been
23627 -- matched in a previous clause.
23629 -- Depends => (Output => State) -- implicitly OK
23630 -- Refined_State => (State => null)
23631 -- Refined_Depends => (Output => ...)
23633 if not Clause_Matched
23634 and then Is_Null_Refined_State
(Dep_Input
)
23635 and then Is_Entity_Name
(Dep_Output
)
23637 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Output
)))
23639 Clause_Matched
:= True;
23642 -- A clause where the output is an abstract state with visible null
23643 -- refinement is implicitly matched when the input has already been
23644 -- matched in a previous clause.
23646 -- Depends => (State => Input) -- implicitly OK
23647 -- Refined_State => (State => null)
23648 -- Refined_Depends => (... => Input)
23650 if not Clause_Matched
23651 and then Is_Null_Refined_State
(Dep_Output
)
23652 and then Is_Entity_Name
(Dep_Input
)
23654 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
23656 Clause_Matched
:= True;
23659 -- At this point either all refinement clauses have been examined or
23660 -- pragma Refined_Depends contains a solitary null. Only an abstract
23661 -- state with null refinement can possibly match these cases.
23663 -- Depends => (State => null)
23664 -- Refined_State => (State => null)
23665 -- Refined_Depends => null -- OK
23667 if not Clause_Matched
then
23669 (Dep_Item
=> Dep_Input
,
23671 Matched
=> Inputs_Match
);
23674 (Dep_Item
=> Dep_Output
,
23676 Matched
=> Outputs_Match
);
23678 Clause_Matched
:= Inputs_Match
and Outputs_Match
;
23681 -- If the contents of Refined_Depends are legal, then the current
23682 -- dependence clause should be satisfied either by an explicit match
23683 -- or by one of the special cases.
23685 if not Clause_Matched
then
23687 (Fix_Msg
(Spec_Id
, "dependence clause of subprogram & has no "
23688 & "matching refinement in body"), Dep_Clause
, Spec_Id
);
23690 end Check_Dependency_Clause
;
23692 -------------------------
23693 -- Check_Output_States --
23694 -------------------------
23696 procedure Check_Output_States
is
23697 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
23698 -- Determine whether all constituents of state State_Id with visible
23699 -- refinement are used as outputs in pragma Refined_Depends. Emit an
23700 -- error if this is not the case.
23702 -----------------------------
23703 -- Check_Constituent_Usage --
23704 -----------------------------
23706 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
23707 Constit_Elmt
: Elmt_Id
;
23708 Constit_Id
: Entity_Id
;
23709 Posted
: Boolean := False;
23712 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
23713 while Present
(Constit_Elmt
) loop
23714 Constit_Id
:= Node
(Constit_Elmt
);
23716 -- The constituent acts as an input (SPARK RM 7.2.5(3))
23718 if Present
(Body_Inputs
)
23719 and then Appears_In
(Body_Inputs
, Constit_Id
)
23721 Error_Msg_Name_1
:= Chars
(State_Id
);
23723 ("constituent & of state % must act as output in "
23724 & "dependence refinement", N
, Constit_Id
);
23726 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
23728 elsif No
(Body_Outputs
)
23729 or else not Appears_In
(Body_Outputs
, Constit_Id
)
23734 ("output state & must be replaced by all its "
23735 & "constituents in dependence refinement",
23740 ("\constituent & is missing in output list",
23744 Next_Elmt
(Constit_Elmt
);
23746 end Check_Constituent_Usage
;
23751 Item_Elmt
: Elmt_Id
;
23752 Item_Id
: Entity_Id
;
23754 -- Start of processing for Check_Output_States
23757 -- Do not perform this check in an instance because it was already
23758 -- performed successfully in the generic template.
23760 if Is_Generic_Instance
(Spec_Id
) then
23763 -- Inspect the outputs of pragma Depends looking for a state with a
23764 -- visible refinement.
23766 elsif Present
(Spec_Outputs
) then
23767 Item_Elmt
:= First_Elmt
(Spec_Outputs
);
23768 while Present
(Item_Elmt
) loop
23769 Item
:= Node
(Item_Elmt
);
23771 -- Deal with the mixed nature of the input and output lists
23773 if Nkind
(Item
) = N_Defining_Identifier
then
23776 Item_Id
:= Available_View
(Entity_Of
(Item
));
23779 if Ekind
(Item_Id
) = E_Abstract_State
then
23781 -- The state acts as an input-output, skip it
23783 if Present
(Spec_Inputs
)
23784 and then Appears_In
(Spec_Inputs
, Item_Id
)
23788 -- Ensure that all of the constituents are utilized as
23789 -- outputs in pragma Refined_Depends.
23791 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
23792 Check_Constituent_Usage
(Item_Id
);
23796 Next_Elmt
(Item_Elmt
);
23799 end Check_Output_States
;
23801 -----------------------
23802 -- Normalize_Clauses --
23803 -----------------------
23805 procedure Normalize_Clauses
(Clauses
: List_Id
) is
23806 procedure Normalize_Inputs
(Clause
: Node_Id
);
23807 -- Normalize clause Clause by creating multiple clauses for each
23808 -- input item of Clause. It is assumed that Clause has exactly one
23809 -- output. The transformation is as follows:
23811 -- Output => (Input_1, Input_2) -- original
23813 -- Output => Input_1 -- normalizations
23814 -- Output => Input_2
23816 procedure Normalize_Outputs
(Clause
: Node_Id
);
23817 -- Normalize clause Clause by creating multiple clause for each
23818 -- output item of Clause. The transformation is as follows:
23820 -- (Output_1, Output_2) => Input -- original
23822 -- Output_1 => Input -- normalization
23823 -- Output_2 => Input
23825 ----------------------
23826 -- Normalize_Inputs --
23827 ----------------------
23829 procedure Normalize_Inputs
(Clause
: Node_Id
) is
23830 Inputs
: constant Node_Id
:= Expression
(Clause
);
23831 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
23832 Output
: constant List_Id
:= Choices
(Clause
);
23833 Last_Input
: Node_Id
;
23835 New_Clause
: Node_Id
;
23836 Next_Input
: Node_Id
;
23839 -- Normalization is performed only when the original clause has
23840 -- more than one input. Multiple inputs appear as an aggregate.
23842 if Nkind
(Inputs
) = N_Aggregate
then
23843 Last_Input
:= Last
(Expressions
(Inputs
));
23845 -- Create a new clause for each input
23847 Input
:= First
(Expressions
(Inputs
));
23848 while Present
(Input
) loop
23849 Next_Input
:= Next
(Input
);
23851 -- Unhook the current input from the original input list
23852 -- because it will be relocated to a new clause.
23856 -- Special processing for the last input. At this point the
23857 -- original aggregate has been stripped down to one element.
23858 -- Replace the aggregate by the element itself.
23860 if Input
= Last_Input
then
23861 Rewrite
(Inputs
, Input
);
23863 -- Generate a clause of the form:
23868 Make_Component_Association
(Loc
,
23869 Choices
=> New_Copy_List_Tree
(Output
),
23870 Expression
=> Input
);
23872 -- The new clause contains replicated content that has
23873 -- already been analyzed, mark the clause as analyzed.
23875 Set_Analyzed
(New_Clause
);
23876 Insert_After
(Clause
, New_Clause
);
23879 Input
:= Next_Input
;
23882 end Normalize_Inputs
;
23884 -----------------------
23885 -- Normalize_Outputs --
23886 -----------------------
23888 procedure Normalize_Outputs
(Clause
: Node_Id
) is
23889 Inputs
: constant Node_Id
:= Expression
(Clause
);
23890 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
23891 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
23892 Last_Output
: Node_Id
;
23893 New_Clause
: Node_Id
;
23894 Next_Output
: Node_Id
;
23898 -- Multiple outputs appear as an aggregate. Nothing to do when
23899 -- the clause has exactly one output.
23901 if Nkind
(Outputs
) = N_Aggregate
then
23902 Last_Output
:= Last
(Expressions
(Outputs
));
23904 -- Create a clause for each output. Note that each time a new
23905 -- clause is created, the original output list slowly shrinks
23906 -- until there is one item left.
23908 Output
:= First
(Expressions
(Outputs
));
23909 while Present
(Output
) loop
23910 Next_Output
:= Next
(Output
);
23912 -- Unhook the output from the original output list as it
23913 -- will be relocated to a new clause.
23917 -- Special processing for the last output. At this point
23918 -- the original aggregate has been stripped down to one
23919 -- element. Replace the aggregate by the element itself.
23921 if Output
= Last_Output
then
23922 Rewrite
(Outputs
, Output
);
23925 -- Generate a clause of the form:
23926 -- (Output => Inputs)
23929 Make_Component_Association
(Loc
,
23930 Choices
=> New_List
(Output
),
23931 Expression
=> New_Copy_Tree
(Inputs
));
23933 -- The new clause contains replicated content that has
23934 -- already been analyzed. There is not need to reanalyze
23937 Set_Analyzed
(New_Clause
);
23938 Insert_After
(Clause
, New_Clause
);
23941 Output
:= Next_Output
;
23944 end Normalize_Outputs
;
23950 -- Start of processing for Normalize_Clauses
23953 Clause
:= First
(Clauses
);
23954 while Present
(Clause
) loop
23955 Normalize_Outputs
(Clause
);
23959 Clause
:= First
(Clauses
);
23960 while Present
(Clause
) loop
23961 Normalize_Inputs
(Clause
);
23964 end Normalize_Clauses
;
23966 --------------------------
23967 -- Report_Extra_Clauses --
23968 --------------------------
23970 procedure Report_Extra_Clauses
is
23974 -- Do not perform this check in an instance because it was already
23975 -- performed successfully in the generic template.
23977 if Is_Generic_Instance
(Spec_Id
) then
23980 elsif Present
(Refinements
) then
23981 Clause
:= First
(Refinements
);
23982 while Present
(Clause
) loop
23984 -- Do not complain about a null input refinement, since a null
23985 -- input legitimately matches anything.
23987 if Nkind
(Clause
) = N_Component_Association
23988 and then Nkind
(Expression
(Clause
)) = N_Null
23994 ("unmatched or extra clause in dependence refinement",
24001 end Report_Extra_Clauses
;
24005 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
24006 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
24007 Errors
: constant Nat
:= Serious_Errors_Detected
;
24013 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
24016 -- Do not analyze the pragma multiple times
24018 if Is_Analyzed_Pragma
(N
) then
24022 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
24024 -- Use the anonymous object as the proper spec when Refined_Depends
24025 -- applies to the body of a single task type. The object carries the
24026 -- proper Chars as well as all non-refined versions of pragmas.
24028 if Is_Single_Concurrent_Type
(Spec_Id
) then
24029 Spec_Id
:= Anonymous_Object
(Spec_Id
);
24032 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
24034 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
24035 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
24037 if No
(Depends
) then
24039 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
24040 & "& lacks aspect or pragma Depends"), N
, Spec_Id
);
24044 Deps
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
24046 -- A null dependency relation renders the refinement useless because it
24047 -- cannot possibly mention abstract states with visible refinement. Note
24048 -- that the inverse is not true as states may be refined to null
24049 -- (SPARK RM 7.2.5(2)).
24051 if Nkind
(Deps
) = N_Null
then
24053 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
24054 & "depend on abstract state with visible refinement"), N
, Spec_Id
);
24058 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
24059 -- This ensures that the categorization of all refined dependency items
24060 -- is consistent with their role.
24062 Analyze_Depends_In_Decl_Part
(N
);
24064 -- Do not match dependencies against refinements if Refined_Depends is
24065 -- illegal to avoid emitting misleading error.
24067 if Serious_Errors_Detected
= Errors
then
24069 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
24070 -- the inputs and outputs of the subprogram spec and body to verify
24071 -- the use of states with visible refinement and their constituents.
24073 if No
(Get_Pragma
(Spec_Id
, Pragma_Global
))
24074 or else No
(Get_Pragma
(Body_Id
, Pragma_Refined_Global
))
24076 Collect_Subprogram_Inputs_Outputs
24077 (Subp_Id
=> Spec_Id
,
24078 Synthesize
=> True,
24079 Subp_Inputs
=> Spec_Inputs
,
24080 Subp_Outputs
=> Spec_Outputs
,
24081 Global_Seen
=> Dummy
);
24083 Collect_Subprogram_Inputs_Outputs
24084 (Subp_Id
=> Body_Id
,
24085 Synthesize
=> True,
24086 Subp_Inputs
=> Body_Inputs
,
24087 Subp_Outputs
=> Body_Outputs
,
24088 Global_Seen
=> Dummy
);
24090 -- For an output state with a visible refinement, ensure that all
24091 -- constituents appear as outputs in the dependency refinement.
24093 Check_Output_States
;
24096 -- Matching is disabled in ASIS because clauses are not normalized as
24097 -- this is a tree altering activity similar to expansion.
24103 -- Multiple dependency clauses appear as component associations of an
24104 -- aggregate. Note that the clauses are copied because the algorithm
24105 -- modifies them and this should not be visible in Depends.
24107 pragma Assert
(Nkind
(Deps
) = N_Aggregate
);
24108 Dependencies
:= New_Copy_List_Tree
(Component_Associations
(Deps
));
24109 Normalize_Clauses
(Dependencies
);
24111 Refs
:= Expression
(Get_Argument
(N
, Spec_Id
));
24113 if Nkind
(Refs
) = N_Null
then
24114 Refinements
:= No_List
;
24116 -- Multiple dependency clauses appear as component associations of an
24117 -- aggregate. Note that the clauses are copied because the algorithm
24118 -- modifies them and this should not be visible in Refined_Depends.
24120 else pragma Assert
(Nkind
(Refs
) = N_Aggregate
);
24121 Refinements
:= New_Copy_List_Tree
(Component_Associations
(Refs
));
24122 Normalize_Clauses
(Refinements
);
24125 -- At this point the clauses of pragmas Depends and Refined_Depends
24126 -- have been normalized into simple dependencies between one output
24127 -- and one input. Examine all clauses of pragma Depends looking for
24128 -- matching clauses in pragma Refined_Depends.
24130 Clause
:= First
(Dependencies
);
24131 while Present
(Clause
) loop
24132 Check_Dependency_Clause
(Clause
);
24136 if Serious_Errors_Detected
= Errors
then
24137 Report_Extra_Clauses
;
24142 Set_Is_Analyzed_Pragma
(N
);
24143 end Analyze_Refined_Depends_In_Decl_Part
;
24145 -----------------------------------------
24146 -- Analyze_Refined_Global_In_Decl_Part --
24147 -----------------------------------------
24149 procedure Analyze_Refined_Global_In_Decl_Part
(N
: Node_Id
) is
24151 -- The corresponding Global pragma
24153 Has_In_State
: Boolean := False;
24154 Has_In_Out_State
: Boolean := False;
24155 Has_Out_State
: Boolean := False;
24156 Has_Proof_In_State
: Boolean := False;
24157 -- These flags are set when the corresponding Global pragma has a state
24158 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
24161 Has_Null_State
: Boolean := False;
24162 -- This flag is set when the corresponding Global pragma has at least
24163 -- one state with a null refinement.
24165 In_Constits
: Elist_Id
:= No_Elist
;
24166 In_Out_Constits
: Elist_Id
:= No_Elist
;
24167 Out_Constits
: Elist_Id
:= No_Elist
;
24168 Proof_In_Constits
: Elist_Id
:= No_Elist
;
24169 -- These lists contain the entities of all Input, In_Out, Output and
24170 -- Proof_In constituents that appear in Refined_Global and participate
24171 -- in state refinement.
24173 In_Items
: Elist_Id
:= No_Elist
;
24174 In_Out_Items
: Elist_Id
:= No_Elist
;
24175 Out_Items
: Elist_Id
:= No_Elist
;
24176 Proof_In_Items
: Elist_Id
:= No_Elist
;
24177 -- These list contain the entities of all Input, In_Out, Output and
24178 -- Proof_In items defined in the corresponding Global pragma.
24180 Spec_Id
: Entity_Id
;
24181 -- The entity of the subprogram subject to pragma Refined_Global
24183 States
: Elist_Id
:= No_Elist
;
24184 -- A list of all states with visible refinement found in pragma Global
24186 procedure Check_In_Out_States
;
24187 -- Determine whether the corresponding Global pragma mentions In_Out
24188 -- states with visible refinement and if so, ensure that one of the
24189 -- following completions apply to the constituents of the state:
24190 -- 1) there is at least one constituent of mode In_Out
24191 -- 2) there is at least one Input and one Output constituent
24192 -- 3) not all constituents are present and one of them is of mode
24194 -- This routine may remove elements from In_Constits, In_Out_Constits,
24195 -- Out_Constits and Proof_In_Constits.
24197 procedure Check_Input_States
;
24198 -- Determine whether the corresponding Global pragma mentions Input
24199 -- states with visible refinement and if so, ensure that at least one of
24200 -- its constituents appears as an Input item in Refined_Global.
24201 -- This routine may remove elements from In_Constits, In_Out_Constits,
24202 -- Out_Constits and Proof_In_Constits.
24204 procedure Check_Output_States
;
24205 -- Determine whether the corresponding Global pragma mentions Output
24206 -- states with visible refinement and if so, ensure that all of its
24207 -- constituents appear as Output items in Refined_Global.
24208 -- This routine may remove elements from In_Constits, In_Out_Constits,
24209 -- Out_Constits and Proof_In_Constits.
24211 procedure Check_Proof_In_States
;
24212 -- Determine whether the corresponding Global pragma mentions Proof_In
24213 -- states with visible refinement and if so, ensure that at least one of
24214 -- its constituents appears as a Proof_In item in Refined_Global.
24215 -- This routine may remove elements from In_Constits, In_Out_Constits,
24216 -- Out_Constits and Proof_In_Constits.
24218 procedure Check_Refined_Global_List
24220 Global_Mode
: Name_Id
:= Name_Input
);
24221 -- Verify the legality of a single global list declaration. Global_Mode
24222 -- denotes the current mode in effect.
24224 procedure Collect_Global_Items
24226 Mode
: Name_Id
:= Name_Input
);
24227 -- Gather all input, in out, output and Proof_In items from node List
24228 -- and separate them in lists In_Items, In_Out_Items, Out_Items and
24229 -- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State
24230 -- and Has_Proof_In_State are set when there is at least one abstract
24231 -- state with visible refinement available in the corresponding mode.
24232 -- Flag Has_Null_State is set when at least state has a null refinement.
24233 -- Mode enotes the current global mode in effect.
24235 function Present_Then_Remove
24237 Item
: Entity_Id
) return Boolean;
24238 -- Search List for a particular entity Item. If Item has been found,
24239 -- remove it from List. This routine is used to strip lists In_Constits,
24240 -- In_Out_Constits and Out_Constits of valid constituents.
24242 procedure Report_Extra_Constituents
;
24243 -- Emit an error for each constituent found in lists In_Constits,
24244 -- In_Out_Constits and Out_Constits.
24246 -------------------------
24247 -- Check_In_Out_States --
24248 -------------------------
24250 procedure Check_In_Out_States
is
24251 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24252 -- Determine whether one of the following coverage scenarios is in
24254 -- 1) there is at least one constituent of mode In_Out
24255 -- 2) there is at least one Input and one Output constituent
24256 -- 3) not all constituents are present and one of them is of mode
24258 -- If this is not the case, emit an error.
24260 -----------------------------
24261 -- Check_Constituent_Usage --
24262 -----------------------------
24264 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24265 Constit_Elmt
: Elmt_Id
;
24266 Constit_Id
: Entity_Id
;
24267 Has_Missing
: Boolean := False;
24268 In_Out_Seen
: Boolean := False;
24269 In_Seen
: Boolean := False;
24270 Out_Seen
: Boolean := False;
24273 -- Process all the constituents of the state and note their modes
24274 -- within the global refinement.
24276 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
24277 while Present
(Constit_Elmt
) loop
24278 Constit_Id
:= Node
(Constit_Elmt
);
24280 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
24283 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
) then
24284 In_Out_Seen
:= True;
24286 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
24289 -- A Proof_In constituent cannot participate in the completion
24290 -- of an Output state (SPARK RM 7.2.4(5)).
24292 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
24293 Error_Msg_Name_1
:= Chars
(State_Id
);
24295 ("constituent & of state % must have mode Input, In_Out "
24296 & "or Output in global refinement", N
, Constit_Id
);
24299 Has_Missing
:= True;
24302 Next_Elmt
(Constit_Elmt
);
24305 -- A single In_Out constituent is a valid completion
24307 if In_Out_Seen
then
24310 -- A pair of one Input and one Output constituent is a valid
24313 elsif In_Seen
and Out_Seen
then
24316 -- A single Output constituent is a valid completion only when
24317 -- some of the other constituents are missing (SPARK RM 7.2.4(5)).
24319 elsif Out_Seen
and Has_Missing
then
24322 -- The state lacks a completion
24324 elsif not In_Seen
and not In_Out_Seen
and not Out_Seen
then
24326 ("missing global refinement of state &", N
, State_Id
);
24328 -- Otherwise the state has a malformed completion where at least
24329 -- one of the constituents has a different mode.
24333 ("global refinement of state & redefines the mode of its "
24334 & "constituents", N
, State_Id
);
24336 end Check_Constituent_Usage
;
24340 Item_Elmt
: Elmt_Id
;
24341 Item_Id
: Entity_Id
;
24343 -- Start of processing for Check_In_Out_States
24346 -- Do not perform this check in an instance because it was already
24347 -- performed successfully in the generic template.
24349 if Is_Generic_Instance
(Spec_Id
) then
24352 -- Inspect the In_Out items of the corresponding Global pragma
24353 -- looking for a state with a visible refinement.
24355 elsif Has_In_Out_State
and then Present
(In_Out_Items
) then
24356 Item_Elmt
:= First_Elmt
(In_Out_Items
);
24357 while Present
(Item_Elmt
) loop
24358 Item_Id
:= Node
(Item_Elmt
);
24360 -- Ensure that one of the three coverage variants is satisfied
24362 if Ekind
(Item_Id
) = E_Abstract_State
24363 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24365 Check_Constituent_Usage
(Item_Id
);
24368 Next_Elmt
(Item_Elmt
);
24371 end Check_In_Out_States
;
24373 ------------------------
24374 -- Check_Input_States --
24375 ------------------------
24377 procedure Check_Input_States
is
24378 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24379 -- Determine whether at least one constituent of state State_Id with
24380 -- visible refinement is used and has mode Input. Ensure that the
24381 -- remaining constituents do not have In_Out, Output or Proof_In
24384 -----------------------------
24385 -- Check_Constituent_Usage --
24386 -----------------------------
24388 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24389 Constit_Elmt
: Elmt_Id
;
24390 Constit_Id
: Entity_Id
;
24391 In_Seen
: Boolean := False;
24394 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
24395 while Present
(Constit_Elmt
) loop
24396 Constit_Id
:= Node
(Constit_Elmt
);
24398 -- At least one of the constituents appears as an Input
24400 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
24403 -- The constituent appears in the global refinement, but has
24404 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
24406 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24407 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
24408 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24410 Error_Msg_Name_1
:= Chars
(State_Id
);
24412 ("constituent & of state % must have mode Input in global "
24413 & "refinement", N
, Constit_Id
);
24416 Next_Elmt
(Constit_Elmt
);
24419 -- Not one of the constituents appeared as Input
24421 if not In_Seen
then
24423 ("global refinement of state & must include at least one "
24424 & "constituent of mode Input", N
, State_Id
);
24426 end Check_Constituent_Usage
;
24430 Item_Elmt
: Elmt_Id
;
24431 Item_Id
: Entity_Id
;
24433 -- Start of processing for Check_Input_States
24436 -- Do not perform this check in an instance because it was already
24437 -- performed successfully in the generic template.
24439 if Is_Generic_Instance
(Spec_Id
) then
24442 -- Inspect the Input items of the corresponding Global pragma looking
24443 -- for a state with a visible refinement.
24445 elsif Has_In_State
and then Present
(In_Items
) then
24446 Item_Elmt
:= First_Elmt
(In_Items
);
24447 while Present
(Item_Elmt
) loop
24448 Item_Id
:= Node
(Item_Elmt
);
24450 -- Ensure that at least one of the constituents is utilized and
24451 -- is of mode Input.
24453 if Ekind
(Item_Id
) = E_Abstract_State
24454 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24456 Check_Constituent_Usage
(Item_Id
);
24459 Next_Elmt
(Item_Elmt
);
24462 end Check_Input_States
;
24464 -------------------------
24465 -- Check_Output_States --
24466 -------------------------
24468 procedure Check_Output_States
is
24469 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24470 -- Determine whether all constituents of state State_Id with visible
24471 -- refinement are used and have mode Output. Emit an error if this is
24474 -----------------------------
24475 -- Check_Constituent_Usage --
24476 -----------------------------
24478 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24479 Constit_Elmt
: Elmt_Id
;
24480 Constit_Id
: Entity_Id
;
24481 Posted
: Boolean := False;
24484 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
24485 while Present
(Constit_Elmt
) loop
24486 Constit_Id
:= Node
(Constit_Elmt
);
24488 if Present_Then_Remove
(Out_Constits
, Constit_Id
) then
24491 -- The constituent appears in the global refinement, but has
24492 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
24494 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
24495 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24496 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
24498 Error_Msg_Name_1
:= Chars
(State_Id
);
24500 ("constituent & of state % must have mode Output in "
24501 & "global refinement", N
, Constit_Id
);
24503 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
24509 ("output state & must be replaced by all its "
24510 & "constituents in global refinement", N
, State_Id
);
24514 ("\constituent & is missing in output list",
24518 Next_Elmt
(Constit_Elmt
);
24520 end Check_Constituent_Usage
;
24524 Item_Elmt
: Elmt_Id
;
24525 Item_Id
: Entity_Id
;
24527 -- Start of processing for Check_Output_States
24530 -- Do not perform this check in an instance because it was already
24531 -- performed successfully in the generic template.
24533 if Is_Generic_Instance
(Spec_Id
) then
24536 -- Inspect the Output items of the corresponding Global pragma
24537 -- looking for a state with a visible refinement.
24539 elsif Has_Out_State
and then Present
(Out_Items
) then
24540 Item_Elmt
:= First_Elmt
(Out_Items
);
24541 while Present
(Item_Elmt
) loop
24542 Item_Id
:= Node
(Item_Elmt
);
24544 -- Ensure that all of the constituents are utilized and they
24545 -- have mode Output.
24547 if Ekind
(Item_Id
) = E_Abstract_State
24548 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24550 Check_Constituent_Usage
(Item_Id
);
24553 Next_Elmt
(Item_Elmt
);
24556 end Check_Output_States
;
24558 ---------------------------
24559 -- Check_Proof_In_States --
24560 ---------------------------
24562 procedure Check_Proof_In_States
is
24563 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
24564 -- Determine whether at least one constituent of state State_Id with
24565 -- visible refinement is used and has mode Proof_In. Ensure that the
24566 -- remaining constituents do not have Input, In_Out or Output modes.
24568 -----------------------------
24569 -- Check_Constituent_Usage --
24570 -----------------------------
24572 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
24573 Constit_Elmt
: Elmt_Id
;
24574 Constit_Id
: Entity_Id
;
24575 Proof_In_Seen
: Boolean := False;
24578 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
24579 while Present
(Constit_Elmt
) loop
24580 Constit_Id
:= Node
(Constit_Elmt
);
24582 -- At least one of the constituents appears as Proof_In
24584 if Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
24585 Proof_In_Seen
:= True;
24587 -- The constituent appears in the global refinement, but has
24588 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
24590 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
24591 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
24592 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
24594 Error_Msg_Name_1
:= Chars
(State_Id
);
24596 ("constituent & of state % must have mode Proof_In in "
24597 & "global refinement", N
, Constit_Id
);
24600 Next_Elmt
(Constit_Elmt
);
24603 -- Not one of the constituents appeared as Proof_In
24605 if not Proof_In_Seen
then
24607 ("global refinement of state & must include at least one "
24608 & "constituent of mode Proof_In", N
, State_Id
);
24610 end Check_Constituent_Usage
;
24614 Item_Elmt
: Elmt_Id
;
24615 Item_Id
: Entity_Id
;
24617 -- Start of processing for Check_Proof_In_States
24620 -- Do not perform this check in an instance because it was already
24621 -- performed successfully in the generic template.
24623 if Is_Generic_Instance
(Spec_Id
) then
24626 -- Inspect the Proof_In items of the corresponding Global pragma
24627 -- looking for a state with a visible refinement.
24629 elsif Has_Proof_In_State
and then Present
(Proof_In_Items
) then
24630 Item_Elmt
:= First_Elmt
(Proof_In_Items
);
24631 while Present
(Item_Elmt
) loop
24632 Item_Id
:= Node
(Item_Elmt
);
24634 -- Ensure that at least one of the constituents is utilized and
24635 -- is of mode Proof_In
24637 if Ekind
(Item_Id
) = E_Abstract_State
24638 and then Has_Non_Null_Visible_Refinement
(Item_Id
)
24640 Check_Constituent_Usage
(Item_Id
);
24643 Next_Elmt
(Item_Elmt
);
24646 end Check_Proof_In_States
;
24648 -------------------------------
24649 -- Check_Refined_Global_List --
24650 -------------------------------
24652 procedure Check_Refined_Global_List
24654 Global_Mode
: Name_Id
:= Name_Input
)
24656 procedure Check_Refined_Global_Item
24658 Global_Mode
: Name_Id
);
24659 -- Verify the legality of a single global item declaration. Parameter
24660 -- Global_Mode denotes the current mode in effect.
24662 -------------------------------
24663 -- Check_Refined_Global_Item --
24664 -------------------------------
24666 procedure Check_Refined_Global_Item
24668 Global_Mode
: Name_Id
)
24670 Item_Id
: constant Entity_Id
:= Entity_Of
(Item
);
24672 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
);
24673 -- Issue a common error message for all mode mismatches. Expect
24674 -- denotes the expected mode.
24676 -----------------------------
24677 -- Inconsistent_Mode_Error --
24678 -----------------------------
24680 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
) is
24683 ("global item & has inconsistent modes", Item
, Item_Id
);
24685 Error_Msg_Name_1
:= Global_Mode
;
24686 Error_Msg_Name_2
:= Expect
;
24687 SPARK_Msg_N
("\expected mode %, found mode %", Item
);
24688 end Inconsistent_Mode_Error
;
24690 -- Start of processing for Check_Refined_Global_Item
24693 -- When the state or object acts as a constituent of another
24694 -- state with a visible refinement, collect it for the state
24695 -- completeness checks performed later on. Note that the item
24696 -- acts as a constituent only when the encapsulating state is
24697 -- present in pragma Global.
24699 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Constant
, E_Variable
)
24700 and then Present
(Encapsulating_State
(Item_Id
))
24701 and then Has_Visible_Refinement
(Encapsulating_State
(Item_Id
))
24702 and then Contains
(States
, Encapsulating_State
(Item_Id
))
24704 if Global_Mode
= Name_Input
then
24705 Append_New_Elmt
(Item_Id
, In_Constits
);
24707 elsif Global_Mode
= Name_In_Out
then
24708 Append_New_Elmt
(Item_Id
, In_Out_Constits
);
24710 elsif Global_Mode
= Name_Output
then
24711 Append_New_Elmt
(Item_Id
, Out_Constits
);
24713 elsif Global_Mode
= Name_Proof_In
then
24714 Append_New_Elmt
(Item_Id
, Proof_In_Constits
);
24717 -- When not a constituent, ensure that both occurrences of the
24718 -- item in pragmas Global and Refined_Global match.
24720 elsif Contains
(In_Items
, Item_Id
) then
24721 if Global_Mode
/= Name_Input
then
24722 Inconsistent_Mode_Error
(Name_Input
);
24725 elsif Contains
(In_Out_Items
, Item_Id
) then
24726 if Global_Mode
/= Name_In_Out
then
24727 Inconsistent_Mode_Error
(Name_In_Out
);
24730 elsif Contains
(Out_Items
, Item_Id
) then
24731 if Global_Mode
/= Name_Output
then
24732 Inconsistent_Mode_Error
(Name_Output
);
24735 elsif Contains
(Proof_In_Items
, Item_Id
) then
24738 -- The item does not appear in the corresponding Global pragma,
24739 -- it must be an extra (SPARK RM 7.2.4(3)).
24742 SPARK_Msg_NE
("extra global item &", Item
, Item_Id
);
24744 end Check_Refined_Global_Item
;
24750 -- Start of processing for Check_Refined_Global_List
24753 -- Do not perform this check in an instance because it was already
24754 -- performed successfully in the generic template.
24756 if Is_Generic_Instance
(Spec_Id
) then
24759 elsif Nkind
(List
) = N_Null
then
24762 -- Single global item declaration
24764 elsif Nkind_In
(List
, N_Expanded_Name
,
24766 N_Selected_Component
)
24768 Check_Refined_Global_Item
(List
, Global_Mode
);
24770 -- Simple global list or moded global list declaration
24772 elsif Nkind
(List
) = N_Aggregate
then
24774 -- The declaration of a simple global list appear as a collection
24777 if Present
(Expressions
(List
)) then
24778 Item
:= First
(Expressions
(List
));
24779 while Present
(Item
) loop
24780 Check_Refined_Global_Item
(Item
, Global_Mode
);
24784 -- The declaration of a moded global list appears as a collection
24785 -- of component associations where individual choices denote
24788 elsif Present
(Component_Associations
(List
)) then
24789 Item
:= First
(Component_Associations
(List
));
24790 while Present
(Item
) loop
24791 Check_Refined_Global_List
24792 (List
=> Expression
(Item
),
24793 Global_Mode
=> Chars
(First
(Choices
(Item
))));
24801 raise Program_Error
;
24807 raise Program_Error
;
24809 end Check_Refined_Global_List
;
24811 --------------------------
24812 -- Collect_Global_Items --
24813 --------------------------
24815 procedure Collect_Global_Items
24817 Mode
: Name_Id
:= Name_Input
)
24819 procedure Collect_Global_Item
24821 Item_Mode
: Name_Id
);
24822 -- Add a single item to the appropriate list. Item_Mode denotes the
24823 -- current mode in effect.
24825 -------------------------
24826 -- Collect_Global_Item --
24827 -------------------------
24829 procedure Collect_Global_Item
24831 Item_Mode
: Name_Id
)
24833 Item_Id
: constant Entity_Id
:= Available_View
(Entity_Of
(Item
));
24834 -- The above handles abstract views of variables and states built
24835 -- for limited with clauses.
24838 -- Signal that the global list contains at least one abstract
24839 -- state with a visible refinement. Note that the refinement may
24840 -- be null in which case there are no constituents.
24842 if Ekind
(Item_Id
) = E_Abstract_State
then
24843 if Has_Null_Visible_Refinement
(Item_Id
) then
24844 Has_Null_State
:= True;
24846 elsif Has_Non_Null_Visible_Refinement
(Item_Id
) then
24847 Append_New_Elmt
(Item_Id
, States
);
24849 if Item_Mode
= Name_Input
then
24850 Has_In_State
:= True;
24851 elsif Item_Mode
= Name_In_Out
then
24852 Has_In_Out_State
:= True;
24853 elsif Item_Mode
= Name_Output
then
24854 Has_Out_State
:= True;
24855 elsif Item_Mode
= Name_Proof_In
then
24856 Has_Proof_In_State
:= True;
24861 -- Add the item to the proper list
24863 if Item_Mode
= Name_Input
then
24864 Append_New_Elmt
(Item_Id
, In_Items
);
24865 elsif Item_Mode
= Name_In_Out
then
24866 Append_New_Elmt
(Item_Id
, In_Out_Items
);
24867 elsif Item_Mode
= Name_Output
then
24868 Append_New_Elmt
(Item_Id
, Out_Items
);
24869 elsif Item_Mode
= Name_Proof_In
then
24870 Append_New_Elmt
(Item_Id
, Proof_In_Items
);
24872 end Collect_Global_Item
;
24878 -- Start of processing for Collect_Global_Items
24881 if Nkind
(List
) = N_Null
then
24884 -- Single global item declaration
24886 elsif Nkind_In
(List
, N_Expanded_Name
,
24888 N_Selected_Component
)
24890 Collect_Global_Item
(List
, Mode
);
24892 -- Single global list or moded global list declaration
24894 elsif Nkind
(List
) = N_Aggregate
then
24896 -- The declaration of a simple global list appear as a collection
24899 if Present
(Expressions
(List
)) then
24900 Item
:= First
(Expressions
(List
));
24901 while Present
(Item
) loop
24902 Collect_Global_Item
(Item
, Mode
);
24906 -- The declaration of a moded global list appears as a collection
24907 -- of component associations where individual choices denote mode.
24909 elsif Present
(Component_Associations
(List
)) then
24910 Item
:= First
(Component_Associations
(List
));
24911 while Present
(Item
) loop
24912 Collect_Global_Items
24913 (List
=> Expression
(Item
),
24914 Mode
=> Chars
(First
(Choices
(Item
))));
24922 raise Program_Error
;
24925 -- To accomodate partial decoration of disabled SPARK features, this
24926 -- routine may be called with illegal input. If this is the case, do
24927 -- not raise Program_Error.
24932 end Collect_Global_Items
;
24934 -------------------------
24935 -- Present_Then_Remove --
24936 -------------------------
24938 function Present_Then_Remove
24940 Item
: Entity_Id
) return Boolean
24945 if Present
(List
) then
24946 Elmt
:= First_Elmt
(List
);
24947 while Present
(Elmt
) loop
24948 if Node
(Elmt
) = Item
then
24949 Remove_Elmt
(List
, Elmt
);
24958 end Present_Then_Remove
;
24960 -------------------------------
24961 -- Report_Extra_Constituents --
24962 -------------------------------
24964 procedure Report_Extra_Constituents
is
24965 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
);
24966 -- Emit an error for every element of List
24968 ---------------------------------------
24969 -- Report_Extra_Constituents_In_List --
24970 ---------------------------------------
24972 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
) is
24973 Constit_Elmt
: Elmt_Id
;
24976 if Present
(List
) then
24977 Constit_Elmt
:= First_Elmt
(List
);
24978 while Present
(Constit_Elmt
) loop
24979 SPARK_Msg_NE
("extra constituent &", N
, Node
(Constit_Elmt
));
24980 Next_Elmt
(Constit_Elmt
);
24983 end Report_Extra_Constituents_In_List
;
24985 -- Start of processing for Report_Extra_Constituents
24988 -- Do not perform this check in an instance because it was already
24989 -- performed successfully in the generic template.
24991 if Is_Generic_Instance
(Spec_Id
) then
24995 Report_Extra_Constituents_In_List
(In_Constits
);
24996 Report_Extra_Constituents_In_List
(In_Out_Constits
);
24997 Report_Extra_Constituents_In_List
(Out_Constits
);
24998 Report_Extra_Constituents_In_List
(Proof_In_Constits
);
25000 end Report_Extra_Constituents
;
25004 Body_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
25005 Errors
: constant Nat
:= Serious_Errors_Detected
;
25008 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
25011 -- Do not analyze the pragma multiple times
25013 if Is_Analyzed_Pragma
(N
) then
25017 Spec_Id
:= Unique_Defining_Entity
(Body_Decl
);
25019 -- Use the anonymous object as the proper spec when Refined_Global
25020 -- applies to the body of a single task type. The object carries the
25021 -- proper Chars as well as all non-refined versions of pragmas.
25023 if Is_Single_Concurrent_Type
(Spec_Id
) then
25024 Spec_Id
:= Anonymous_Object
(Spec_Id
);
25027 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
25028 Items
:= Expression
(Get_Argument
(N
, Spec_Id
));
25030 -- The subprogram declaration lacks pragma Global. This renders
25031 -- Refined_Global useless as there is nothing to refine.
25033 if No
(Global
) then
25035 (Fix_Msg
(Spec_Id
, "useless refinement, declaration of subprogram "
25036 & "& lacks aspect or pragma Global"), N
, Spec_Id
);
25040 -- Extract all relevant items from the corresponding Global pragma
25042 Collect_Global_Items
(Expression
(Get_Argument
(Global
, Spec_Id
)));
25044 -- Package and subprogram bodies are instantiated individually in
25045 -- a separate compiler pass. Due to this mode of instantiation, the
25046 -- refinement of a state may no longer be visible when a subprogram
25047 -- body contract is instantiated. Since the generic template is legal,
25048 -- do not perform this check in the instance to circumvent this oddity.
25050 if Is_Generic_Instance
(Spec_Id
) then
25053 -- Non-instance case
25056 -- The corresponding Global pragma must mention at least one state
25057 -- witha visible refinement at the point Refined_Global is processed.
25058 -- States with null refinements need Refined_Global pragma
25059 -- (SPARK RM 7.2.4(2)).
25061 if not Has_In_State
25062 and then not Has_In_Out_State
25063 and then not Has_Out_State
25064 and then not Has_Proof_In_State
25065 and then not Has_Null_State
25068 (Fix_Msg
(Spec_Id
, "useless refinement, subprogram & does not "
25069 & "depend on abstract state with visible refinement"),
25073 -- The global refinement of inputs and outputs cannot be null when
25074 -- the corresponding Global pragma contains at least one item except
25075 -- in the case where we have states with null refinements.
25077 elsif Nkind
(Items
) = N_Null
25079 (Present
(In_Items
)
25080 or else Present
(In_Out_Items
)
25081 or else Present
(Out_Items
)
25082 or else Present
(Proof_In_Items
))
25083 and then not Has_Null_State
25086 (Fix_Msg
(Spec_Id
, "refinement cannot be null, subprogram & has "
25087 & "global items"), N
, Spec_Id
);
25092 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
25093 -- This ensures that the categorization of all refined global items is
25094 -- consistent with their role.
25096 Analyze_Global_In_Decl_Part
(N
);
25098 -- Perform all refinement checks with respect to completeness and mode
25101 if Serious_Errors_Detected
= Errors
then
25102 Check_Refined_Global_List
(Items
);
25105 -- For Input states with visible refinement, at least one constituent
25106 -- must be used as an Input in the global refinement.
25108 if Serious_Errors_Detected
= Errors
then
25109 Check_Input_States
;
25112 -- Verify all possible completion variants for In_Out states with
25113 -- visible refinement.
25115 if Serious_Errors_Detected
= Errors
then
25116 Check_In_Out_States
;
25119 -- For Output states with visible refinement, all constituents must be
25120 -- used as Outputs in the global refinement.
25122 if Serious_Errors_Detected
= Errors
then
25123 Check_Output_States
;
25126 -- For Proof_In states with visible refinement, at least one constituent
25127 -- must be used as Proof_In in the global refinement.
25129 if Serious_Errors_Detected
= Errors
then
25130 Check_Proof_In_States
;
25133 -- Emit errors for all constituents that belong to other states with
25134 -- visible refinement that do not appear in Global.
25136 if Serious_Errors_Detected
= Errors
then
25137 Report_Extra_Constituents
;
25141 Set_Is_Analyzed_Pragma
(N
);
25142 end Analyze_Refined_Global_In_Decl_Part
;
25144 ----------------------------------------
25145 -- Analyze_Refined_State_In_Decl_Part --
25146 ----------------------------------------
25148 procedure Analyze_Refined_State_In_Decl_Part
25150 Freeze_Id
: Entity_Id
:= Empty
)
25152 Body_Decl
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
25153 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
25154 Spec_Id
: constant Entity_Id
:= Corresponding_Spec
(Body_Decl
);
25156 Available_States
: Elist_Id
:= No_Elist
;
25157 -- A list of all abstract states defined in the package declaration that
25158 -- are available for refinement. The list is used to report unrefined
25161 Body_States
: Elist_Id
:= No_Elist
;
25162 -- A list of all hidden states that appear in the body of the related
25163 -- package. The list is used to report unused hidden states.
25165 Constituents_Seen
: Elist_Id
:= No_Elist
;
25166 -- A list that contains all constituents processed so far. The list is
25167 -- used to detect multiple uses of the same constituent.
25169 Freeze_Posted
: Boolean := False;
25170 -- A flag that controls the output of a freezing-related error (see use
25173 Refined_States_Seen
: Elist_Id
:= No_Elist
;
25174 -- A list that contains all refined states processed so far. The list is
25175 -- used to detect duplicate refinements.
25177 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
);
25178 -- Perform full analysis of a single refinement clause
25180 procedure Report_Unrefined_States
(States
: Elist_Id
);
25181 -- Emit errors for all unrefined abstract states found in list States
25183 -------------------------------
25184 -- Analyze_Refinement_Clause --
25185 -------------------------------
25187 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
) is
25188 AR_Constit
: Entity_Id
:= Empty
;
25189 AW_Constit
: Entity_Id
:= Empty
;
25190 ER_Constit
: Entity_Id
:= Empty
;
25191 EW_Constit
: Entity_Id
:= Empty
;
25192 -- The entities of external constituents that contain one of the
25193 -- following enabled properties: Async_Readers, Async_Writers,
25194 -- Effective_Reads and Effective_Writes.
25196 External_Constit_Seen
: Boolean := False;
25197 -- Flag used to mark when at least one external constituent is part
25198 -- of the state refinement.
25200 Non_Null_Seen
: Boolean := False;
25201 Null_Seen
: Boolean := False;
25202 -- Flags used to detect multiple uses of null in a single clause or a
25203 -- mixture of null and non-null constituents.
25205 Part_Of_Constits
: Elist_Id
:= No_Elist
;
25206 -- A list of all candidate constituents subject to indicator Part_Of
25207 -- where the encapsulating state is the current state.
25210 State_Id
: Entity_Id
;
25211 -- The current state being refined
25213 procedure Analyze_Constituent
(Constit
: Node_Id
);
25214 -- Perform full analysis of a single constituent
25216 procedure Check_External_Property
25217 (Prop_Nam
: Name_Id
;
25219 Constit
: Entity_Id
);
25220 -- Determine whether a property denoted by name Prop_Nam is present
25221 -- in both the refined state and constituent Constit. Flag Enabled
25222 -- should be set when the property applies to the refined state. If
25223 -- this is not the case, emit an error message.
25225 procedure Match_State
;
25226 -- Determine whether the state being refined appears in list
25227 -- Available_States. Emit an error when attempting to re-refine the
25228 -- state or when the state is not defined in the package declaration,
25229 -- otherwise remove the state from Available_States.
25231 procedure Report_Unused_Constituents
(Constits
: Elist_Id
);
25232 -- Emit errors for all unused Part_Of constituents in list Constits
25234 -------------------------
25235 -- Analyze_Constituent --
25236 -------------------------
25238 procedure Analyze_Constituent
(Constit
: Node_Id
) is
25239 procedure Match_Constituent
(Constit_Id
: Entity_Id
);
25240 -- Determine whether constituent Constit denoted by its entity
25241 -- Constit_Id appears in Body_States. Emit an error when the
25242 -- constituent is not a valid hidden state of the related package
25243 -- or when it is used more than once. Otherwise remove the
25244 -- constituent from Body_States.
25246 -----------------------
25247 -- Match_Constituent --
25248 -----------------------
25250 procedure Match_Constituent
(Constit_Id
: Entity_Id
) is
25251 procedure Collect_Constituent
;
25252 -- Verify the legality of constituent Constit_Id and add it to
25253 -- the refinements of State_Id.
25255 -------------------------
25256 -- Collect_Constituent --
25257 -------------------------
25259 procedure Collect_Constituent
is
25261 if Is_Ghost_Entity
(State_Id
) then
25262 if Is_Ghost_Entity
(Constit_Id
) then
25264 -- The Ghost policy in effect at the point of abstract
25265 -- state declaration and constituent must match
25266 -- (SPARK RM 6.9(16)).
25268 if Is_Checked_Ghost_Entity
(State_Id
)
25269 and then Is_Ignored_Ghost_Entity
(Constit_Id
)
25271 Error_Msg_Sloc
:= Sloc
(Constit
);
25274 ("incompatible ghost policies in effect", State
);
25276 ("\abstract state & declared with ghost policy "
25277 & "Check", State
, State_Id
);
25279 ("\constituent & declared # with ghost policy "
25280 & "Ignore", State
, Constit_Id
);
25282 elsif Is_Ignored_Ghost_Entity
(State_Id
)
25283 and then Is_Checked_Ghost_Entity
(Constit_Id
)
25285 Error_Msg_Sloc
:= Sloc
(Constit
);
25288 ("incompatible ghost policies in effect", State
);
25290 ("\abstract state & declared with ghost policy "
25291 & "Ignore", State
, State_Id
);
25293 ("\constituent & declared # with ghost policy "
25294 & "Check", State
, Constit_Id
);
25297 -- A constituent of a Ghost abstract state must be a
25298 -- Ghost entity (SPARK RM 7.2.2(12)).
25302 ("constituent of ghost state & must be ghost",
25303 Constit
, State_Id
);
25307 -- A synchronized state must be refined by a synchronized
25308 -- object or another synchronized state (SPARK RM 9.6).
25310 if Is_Synchronized_State
(State_Id
)
25311 and then not Is_Synchronized_Object
(Constit_Id
)
25312 and then not Is_Synchronized_State
(Constit_Id
)
25315 ("constituent of synchronized state & must be "
25316 & "synchronized", Constit
, State_Id
);
25319 -- Add the constituent to the list of processed items to aid
25320 -- with the detection of duplicates.
25322 Append_New_Elmt
(Constit_Id
, Constituents_Seen
);
25324 -- Collect the constituent in the list of refinement items
25325 -- and establish a relation between the refined state and
25328 Append_Elmt
(Constit_Id
, Refinement_Constituents
(State_Id
));
25329 Set_Encapsulating_State
(Constit_Id
, State_Id
);
25331 -- The state has at least one legal constituent, mark the
25332 -- start of the refinement region. The region ends when the
25333 -- body declarations end (see routine Analyze_Declarations).
25335 Set_Has_Visible_Refinement
(State_Id
);
25337 -- When the constituent is external, save its relevant
25338 -- property for further checks.
25340 if Async_Readers_Enabled
(Constit_Id
) then
25341 AR_Constit
:= Constit_Id
;
25342 External_Constit_Seen
:= True;
25345 if Async_Writers_Enabled
(Constit_Id
) then
25346 AW_Constit
:= Constit_Id
;
25347 External_Constit_Seen
:= True;
25350 if Effective_Reads_Enabled
(Constit_Id
) then
25351 ER_Constit
:= Constit_Id
;
25352 External_Constit_Seen
:= True;
25355 if Effective_Writes_Enabled
(Constit_Id
) then
25356 EW_Constit
:= Constit_Id
;
25357 External_Constit_Seen
:= True;
25359 end Collect_Constituent
;
25363 State_Elmt
: Elmt_Id
;
25365 -- Start of processing for Match_Constituent
25368 -- Detect a duplicate use of a constituent
25370 if Contains
(Constituents_Seen
, Constit_Id
) then
25372 ("duplicate use of constituent &", Constit
, Constit_Id
);
25376 -- The constituent is subject to a Part_Of indicator
25378 if Present
(Encapsulating_State
(Constit_Id
)) then
25379 if Encapsulating_State
(Constit_Id
) = State_Id
then
25380 Remove
(Part_Of_Constits
, Constit_Id
);
25381 Collect_Constituent
;
25383 -- The constituent is part of another state and is used
25384 -- incorrectly in the refinement of the current state.
25387 Error_Msg_Name_1
:= Chars
(State_Id
);
25389 ("& cannot act as constituent of state %",
25390 Constit
, Constit_Id
);
25392 ("\Part_Of indicator specifies encapsulator &",
25393 Constit
, Encapsulating_State
(Constit_Id
));
25396 -- The only other source of legal constituents is the body
25397 -- state space of the related package.
25400 if Present
(Body_States
) then
25401 State_Elmt
:= First_Elmt
(Body_States
);
25402 while Present
(State_Elmt
) loop
25404 -- Consume a valid constituent to signal that it has
25405 -- been encountered.
25407 if Node
(State_Elmt
) = Constit_Id
then
25408 Remove_Elmt
(Body_States
, State_Elmt
);
25409 Collect_Constituent
;
25413 Next_Elmt
(State_Elmt
);
25417 -- Constants are part of the hidden state of a package, but
25418 -- the compiler cannot determine whether they have variable
25419 -- input (SPARK RM 7.1.1(2)) and cannot classify them as a
25420 -- hidden state. Accept the constant quietly even if it is
25421 -- a visible state or lacks a Part_Of indicator.
25423 if Ekind
(Constit_Id
) = E_Constant
then
25426 -- If we get here, then the constituent is not a hidden
25427 -- state of the related package and may not be used in a
25428 -- refinement (SPARK RM 7.2.2(9)).
25431 Error_Msg_Name_1
:= Chars
(Spec_Id
);
25433 ("cannot use & in refinement, constituent is not a "
25434 & "hidden state of package %", Constit
, Constit_Id
);
25437 end Match_Constituent
;
25441 Constit_Id
: Entity_Id
;
25443 -- Start of processing for Analyze_Constituent
25446 -- Detect multiple uses of null in a single refinement clause or a
25447 -- mixture of null and non-null constituents.
25449 if Nkind
(Constit
) = N_Null
then
25452 ("multiple null constituents not allowed", Constit
);
25454 elsif Non_Null_Seen
then
25456 ("cannot mix null and non-null constituents", Constit
);
25461 -- Collect the constituent in the list of refinement items
25463 Append_Elmt
(Constit
, Refinement_Constituents
(State_Id
));
25465 -- The state has at least one legal constituent, mark the
25466 -- start of the refinement region. The region ends when the
25467 -- body declarations end (see Analyze_Declarations).
25469 Set_Has_Visible_Refinement
(State_Id
);
25472 -- Non-null constituents
25475 Non_Null_Seen
:= True;
25479 ("cannot mix null and non-null constituents", Constit
);
25483 Resolve_State
(Constit
);
25485 -- Ensure that the constituent denotes a valid state or a
25486 -- whole object (SPARK RM 7.2.2(5)).
25488 if Is_Entity_Name
(Constit
) then
25489 Constit_Id
:= Entity_Of
(Constit
);
25491 -- When a constituent is declared after a subprogram body
25492 -- that caused "freezing" of the related contract where
25493 -- pragma Refined_State resides, the constituent appears
25494 -- undefined and carries Any_Id as its entity.
25496 -- package body Pack
25497 -- with Refined_State => (State => Constit)
25500 -- with Refined_Global => (Input => Constit)
25508 if Constit_Id
= Any_Id
then
25509 SPARK_Msg_NE
("& is undefined", Constit
, Constit_Id
);
25511 -- Emit a specialized info message when the contract of
25512 -- the related package body was "frozen" by another body.
25513 -- Note that it is not possible to precisely identify why
25514 -- the constituent is undefined because it is not visible
25515 -- when pragma Refined_State is analyzed. This message is
25516 -- a reasonable approximation.
25518 if Present
(Freeze_Id
) and then not Freeze_Posted
then
25519 Freeze_Posted
:= True;
25521 Error_Msg_Name_1
:= Chars
(Body_Id
);
25522 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
25524 ("body & declared # freezes the contract of %",
25527 ("\all constituents must be declared before body #",
25530 -- A misplaced constituent is a critical error because
25531 -- pragma Refined_Depends or Refined_Global depends on
25532 -- the proper link between a state and a constituent.
25533 -- Stop the compilation, as this leads to a multitude
25534 -- of misleading cascaded errors.
25536 raise Program_Error
;
25539 -- The constituent is a valid state or object
25541 elsif Ekind_In
(Constit_Id
, E_Abstract_State
,
25545 Match_Constituent
(Constit_Id
);
25547 -- The variable may eventually become a constituent of a
25548 -- single protected/task type. Record the reference now
25549 -- and verify its legality when analyzing the contract of
25550 -- the variable (SPARK RM 9.3).
25552 if Ekind
(Constit_Id
) = E_Variable
then
25553 Record_Possible_Part_Of_Reference
25554 (Var_Id
=> Constit_Id
,
25558 -- Otherwise the constituent is illegal
25562 ("constituent & must denote object or state",
25563 Constit
, Constit_Id
);
25566 -- The constituent is illegal
25569 SPARK_Msg_N
("malformed constituent", Constit
);
25572 end Analyze_Constituent
;
25574 -----------------------------
25575 -- Check_External_Property --
25576 -----------------------------
25578 procedure Check_External_Property
25579 (Prop_Nam
: Name_Id
;
25581 Constit
: Entity_Id
)
25584 Error_Msg_Name_1
:= Prop_Nam
;
25586 -- The property is enabled in the related Abstract_State pragma
25587 -- that defines the state (SPARK RM 7.2.8(3)).
25590 if No
(Constit
) then
25592 ("external state & requires at least one constituent with "
25593 & "property %", State
, State_Id
);
25596 -- The property is missing in the declaration of the state, but
25597 -- a constituent is introducing it in the state refinement
25598 -- (SPARK RM 7.2.8(3)).
25600 elsif Present
(Constit
) then
25601 Error_Msg_Name_2
:= Chars
(Constit
);
25603 ("external state & lacks property % set by constituent %",
25606 end Check_External_Property
;
25612 procedure Match_State
is
25613 State_Elmt
: Elmt_Id
;
25616 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
25618 if Contains
(Refined_States_Seen
, State_Id
) then
25620 ("duplicate refinement of state &", State
, State_Id
);
25624 -- Inspect the abstract states defined in the package declaration
25625 -- looking for a match.
25627 State_Elmt
:= First_Elmt
(Available_States
);
25628 while Present
(State_Elmt
) loop
25630 -- A valid abstract state is being refined in the body. Add
25631 -- the state to the list of processed refined states to aid
25632 -- with the detection of duplicate refinements. Remove the
25633 -- state from Available_States to signal that it has already
25636 if Node
(State_Elmt
) = State_Id
then
25637 Append_New_Elmt
(State_Id
, Refined_States_Seen
);
25638 Remove_Elmt
(Available_States
, State_Elmt
);
25642 Next_Elmt
(State_Elmt
);
25645 -- If we get here, we are refining a state that is not defined in
25646 -- the package declaration.
25648 Error_Msg_Name_1
:= Chars
(Spec_Id
);
25650 ("cannot refine state, & is not defined in package %",
25654 --------------------------------
25655 -- Report_Unused_Constituents --
25656 --------------------------------
25658 procedure Report_Unused_Constituents
(Constits
: Elist_Id
) is
25659 Constit_Elmt
: Elmt_Id
;
25660 Constit_Id
: Entity_Id
;
25661 Posted
: Boolean := False;
25664 if Present
(Constits
) then
25665 Constit_Elmt
:= First_Elmt
(Constits
);
25666 while Present
(Constit_Elmt
) loop
25667 Constit_Id
:= Node
(Constit_Elmt
);
25669 -- Generate an error message of the form:
25671 -- state ... has unused Part_Of constituents
25672 -- abstract state ... defined at ...
25673 -- constant ... defined at ...
25674 -- variable ... defined at ...
25679 ("state & has unused Part_Of constituents",
25683 Error_Msg_Sloc
:= Sloc
(Constit_Id
);
25685 if Ekind
(Constit_Id
) = E_Abstract_State
then
25687 ("\abstract state & defined #", State
, Constit_Id
);
25689 elsif Ekind
(Constit_Id
) = E_Constant
then
25691 ("\constant & defined #", State
, Constit_Id
);
25694 pragma Assert
(Ekind
(Constit_Id
) = E_Variable
);
25695 SPARK_Msg_NE
("\variable & defined #", State
, Constit_Id
);
25698 Next_Elmt
(Constit_Elmt
);
25701 end Report_Unused_Constituents
;
25703 -- Local declarations
25705 Body_Ref
: Node_Id
;
25706 Body_Ref_Elmt
: Elmt_Id
;
25708 Extra_State
: Node_Id
;
25710 -- Start of processing for Analyze_Refinement_Clause
25713 -- A refinement clause appears as a component association where the
25714 -- sole choice is the state and the expressions are the constituents.
25715 -- This is a syntax error, always report.
25717 if Nkind
(Clause
) /= N_Component_Association
then
25718 Error_Msg_N
("malformed state refinement clause", Clause
);
25722 -- Analyze the state name of a refinement clause
25724 State
:= First
(Choices
(Clause
));
25727 Resolve_State
(State
);
25729 -- Ensure that the state name denotes a valid abstract state that is
25730 -- defined in the spec of the related package.
25732 if Is_Entity_Name
(State
) then
25733 State_Id
:= Entity_Of
(State
);
25735 -- When the abstract state is undefined, it appears as Any_Id. Do
25736 -- not continue with the analysis of the clause.
25738 if State_Id
= Any_Id
then
25741 -- Catch any attempts to re-refine a state or refine a state that
25742 -- is not defined in the package declaration.
25744 elsif Ekind
(State_Id
) = E_Abstract_State
then
25748 SPARK_Msg_NE
("& must denote abstract state", State
, State_Id
);
25752 -- References to a state with visible refinement are illegal.
25753 -- When nested packages are involved, detecting such references is
25754 -- tricky because pragma Refined_State is analyzed later than the
25755 -- offending pragma Depends or Global. References that occur in
25756 -- such nested context are stored in a list. Emit errors for all
25757 -- references found in Body_References (SPARK RM 6.1.4(8)).
25759 if Present
(Body_References
(State_Id
)) then
25760 Body_Ref_Elmt
:= First_Elmt
(Body_References
(State_Id
));
25761 while Present
(Body_Ref_Elmt
) loop
25762 Body_Ref
:= Node
(Body_Ref_Elmt
);
25764 SPARK_Msg_N
("reference to & not allowed", Body_Ref
);
25765 Error_Msg_Sloc
:= Sloc
(State
);
25766 SPARK_Msg_N
("\refinement of & is visible#", Body_Ref
);
25768 Next_Elmt
(Body_Ref_Elmt
);
25772 -- The state name is illegal. This is a syntax error, always report.
25775 Error_Msg_N
("malformed state name in refinement clause", State
);
25779 -- A refinement clause may only refine one state at a time
25781 Extra_State
:= Next
(State
);
25783 if Present
(Extra_State
) then
25785 ("refinement clause cannot cover multiple states", Extra_State
);
25788 -- Replicate the Part_Of constituents of the refined state because
25789 -- the algorithm will consume items.
25791 Part_Of_Constits
:= New_Copy_Elist
(Part_Of_Constituents
(State_Id
));
25793 -- Analyze all constituents of the refinement. Multiple constituents
25794 -- appear as an aggregate.
25796 Constit
:= Expression
(Clause
);
25798 if Nkind
(Constit
) = N_Aggregate
then
25799 if Present
(Component_Associations
(Constit
)) then
25801 ("constituents of refinement clause must appear in "
25802 & "positional form", Constit
);
25804 else pragma Assert
(Present
(Expressions
(Constit
)));
25805 Constit
:= First
(Expressions
(Constit
));
25806 while Present
(Constit
) loop
25807 Analyze_Constituent
(Constit
);
25812 -- Various forms of a single constituent. Note that these may include
25813 -- malformed constituents.
25816 Analyze_Constituent
(Constit
);
25819 -- A refined external state is subject to special rules with respect
25820 -- to its properties and constituents.
25822 if Is_External_State
(State_Id
) then
25824 -- The set of properties that all external constituents yield must
25825 -- match that of the refined state. There are two cases to detect:
25826 -- the refined state lacks a property or has an extra property.
25828 if External_Constit_Seen
then
25829 Check_External_Property
25830 (Prop_Nam
=> Name_Async_Readers
,
25831 Enabled
=> Async_Readers_Enabled
(State_Id
),
25832 Constit
=> AR_Constit
);
25834 Check_External_Property
25835 (Prop_Nam
=> Name_Async_Writers
,
25836 Enabled
=> Async_Writers_Enabled
(State_Id
),
25837 Constit
=> AW_Constit
);
25839 Check_External_Property
25840 (Prop_Nam
=> Name_Effective_Reads
,
25841 Enabled
=> Effective_Reads_Enabled
(State_Id
),
25842 Constit
=> ER_Constit
);
25844 Check_External_Property
25845 (Prop_Nam
=> Name_Effective_Writes
,
25846 Enabled
=> Effective_Writes_Enabled
(State_Id
),
25847 Constit
=> EW_Constit
);
25849 -- An external state may be refined to null (SPARK RM 7.2.8(2))
25851 elsif Null_Seen
then
25854 -- The external state has constituents, but none of them are
25855 -- external (SPARK RM 7.2.8(2)).
25859 ("external state & requires at least one external "
25860 & "constituent or null refinement", State
, State_Id
);
25863 -- When a refined state is not external, it should not have external
25864 -- constituents (SPARK RM 7.2.8(1)).
25866 elsif External_Constit_Seen
then
25868 ("non-external state & cannot contain external constituents in "
25869 & "refinement", State
, State_Id
);
25872 -- Ensure that all Part_Of candidate constituents have been mentioned
25873 -- in the refinement clause.
25875 Report_Unused_Constituents
(Part_Of_Constits
);
25876 end Analyze_Refinement_Clause
;
25878 -----------------------------
25879 -- Report_Unrefined_States --
25880 -----------------------------
25882 procedure Report_Unrefined_States
(States
: Elist_Id
) is
25883 State_Elmt
: Elmt_Id
;
25886 if Present
(States
) then
25887 State_Elmt
:= First_Elmt
(States
);
25888 while Present
(State_Elmt
) loop
25890 ("abstract state & must be refined", Node
(State_Elmt
));
25892 Next_Elmt
(State_Elmt
);
25895 end Report_Unrefined_States
;
25897 -- Local declarations
25899 Clauses
: constant Node_Id
:= Expression
(Get_Argument
(N
, Spec_Id
));
25902 -- Start of processing for Analyze_Refined_State_In_Decl_Part
25905 -- Do not analyze the pragma multiple times
25907 if Is_Analyzed_Pragma
(N
) then
25911 -- Replicate the abstract states declared by the package because the
25912 -- matching algorithm will consume states.
25914 Available_States
:= New_Copy_Elist
(Abstract_States
(Spec_Id
));
25916 -- Gather all abstract states and objects declared in the visible
25917 -- state space of the package body. These items must be utilized as
25918 -- constituents in a state refinement.
25920 Body_States
:= Collect_Body_States
(Body_Id
);
25922 -- Multiple non-null state refinements appear as an aggregate
25924 if Nkind
(Clauses
) = N_Aggregate
then
25925 if Present
(Expressions
(Clauses
)) then
25927 ("state refinements must appear as component associations",
25930 else pragma Assert
(Present
(Component_Associations
(Clauses
)));
25931 Clause
:= First
(Component_Associations
(Clauses
));
25932 while Present
(Clause
) loop
25933 Analyze_Refinement_Clause
(Clause
);
25938 -- Various forms of a single state refinement. Note that these may
25939 -- include malformed refinements.
25942 Analyze_Refinement_Clause
(Clauses
);
25945 -- List all abstract states that were left unrefined
25947 Report_Unrefined_States
(Available_States
);
25949 Set_Is_Analyzed_Pragma
(N
);
25950 end Analyze_Refined_State_In_Decl_Part
;
25952 ------------------------------------
25953 -- Analyze_Test_Case_In_Decl_Part --
25954 ------------------------------------
25956 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
) is
25957 Subp_Decl
: constant Node_Id
:= Find_Related_Declaration_Or_Body
(N
);
25958 Spec_Id
: constant Entity_Id
:= Unique_Defining_Entity
(Subp_Decl
);
25960 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
);
25961 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
25962 -- denoted by Arg_Nam.
25964 ------------------------------
25965 -- Preanalyze_Test_Case_Arg --
25966 ------------------------------
25968 procedure Preanalyze_Test_Case_Arg
(Arg_Nam
: Name_Id
) is
25972 -- Preanalyze the original aspect argument for ASIS or for a generic
25973 -- subprogram to properly capture global references.
25975 if ASIS_Mode
or else Is_Generic_Subprogram
(Spec_Id
) then
25979 Arg_Nam
=> Arg_Nam
,
25980 From_Aspect
=> True);
25982 if Present
(Arg
) then
25983 Preanalyze_Assert_Expression
25984 (Expression
(Arg
), Standard_Boolean
);
25988 Arg
:= Test_Case_Arg
(N
, Arg_Nam
);
25990 if Present
(Arg
) then
25991 Preanalyze_Assert_Expression
(Expression
(Arg
), Standard_Boolean
);
25993 end Preanalyze_Test_Case_Arg
;
25997 Restore_Scope
: Boolean := False;
25999 -- Start of processing for Analyze_Test_Case_In_Decl_Part
26002 -- Do not analyze the pragma multiple times
26004 if Is_Analyzed_Pragma
(N
) then
26008 -- Ensure that the formal parameters are visible when analyzing all
26009 -- clauses. This falls out of the general rule of aspects pertaining
26010 -- to subprogram declarations.
26012 if not In_Open_Scopes
(Spec_Id
) then
26013 Restore_Scope
:= True;
26014 Push_Scope
(Spec_Id
);
26016 if Is_Generic_Subprogram
(Spec_Id
) then
26017 Install_Generic_Formals
(Spec_Id
);
26019 Install_Formals
(Spec_Id
);
26023 Preanalyze_Test_Case_Arg
(Name_Requires
);
26024 Preanalyze_Test_Case_Arg
(Name_Ensures
);
26026 if Restore_Scope
then
26030 -- Currently it is not possible to inline pre/postconditions on a
26031 -- subprogram subject to pragma Inline_Always.
26033 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
26035 Set_Is_Analyzed_Pragma
(N
);
26036 end Analyze_Test_Case_In_Decl_Part
;
26042 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean is
26047 if Present
(List
) then
26048 Elmt
:= First_Elmt
(List
);
26049 while Present
(Elmt
) loop
26050 if Nkind
(Node
(Elmt
)) = N_Defining_Identifier
then
26053 Id
:= Entity_Of
(Node
(Elmt
));
26056 if Id
= Item_Id
then
26067 -----------------------------
26068 -- Check_Applicable_Policy --
26069 -----------------------------
26071 procedure Check_Applicable_Policy
(N
: Node_Id
) is
26075 Ename
: constant Name_Id
:= Original_Aspect_Pragma_Name
(N
);
26078 -- No effect if not valid assertion kind name
26080 if not Is_Valid_Assertion_Kind
(Ename
) then
26084 -- Loop through entries in check policy list
26086 PP
:= Opt
.Check_Policy_List
;
26087 while Present
(PP
) loop
26089 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
26090 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
26094 or else Pnm
= Name_Assertion
26095 or else (Pnm
= Name_Statement_Assertions
26096 and then Nam_In
(Ename
, Name_Assert
,
26097 Name_Assert_And_Cut
,
26099 Name_Loop_Invariant
,
26100 Name_Loop_Variant
))
26102 Policy
:= Chars
(Get_Pragma_Arg
(Last
(PPA
)));
26105 when Name_Off | Name_Ignore
=>
26106 Set_Is_Ignored
(N
, True);
26107 Set_Is_Checked
(N
, False);
26109 when Name_On | Name_Check
=>
26110 Set_Is_Checked
(N
, True);
26111 Set_Is_Ignored
(N
, False);
26113 when Name_Disable
=>
26114 Set_Is_Ignored
(N
, True);
26115 Set_Is_Checked
(N
, False);
26116 Set_Is_Disabled
(N
, True);
26118 -- That should be exhaustive, the null here is a defence
26119 -- against a malformed tree from previous errors.
26128 PP
:= Next_Pragma
(PP
);
26132 -- If there are no specific entries that matched, then we let the
26133 -- setting of assertions govern. Note that this provides the needed
26134 -- compatibility with the RM for the cases of assertion, invariant,
26135 -- precondition, predicate, and postcondition.
26137 if Assertions_Enabled
then
26138 Set_Is_Checked
(N
, True);
26139 Set_Is_Ignored
(N
, False);
26141 Set_Is_Checked
(N
, False);
26142 Set_Is_Ignored
(N
, True);
26144 end Check_Applicable_Policy
;
26146 -------------------------------
26147 -- Check_External_Properties --
26148 -------------------------------
26150 procedure Check_External_Properties
26158 -- All properties enabled
26160 if AR
and AW
and ER
and EW
then
26163 -- Async_Readers + Effective_Writes
26164 -- Async_Readers + Async_Writers + Effective_Writes
26166 elsif AR
and EW
and not ER
then
26169 -- Async_Writers + Effective_Reads
26170 -- Async_Readers + Async_Writers + Effective_Reads
26172 elsif AW
and ER
and not EW
then
26175 -- Async_Readers + Async_Writers
26177 elsif AR
and AW
and not ER
and not EW
then
26182 elsif AR
and not AW
and not ER
and not EW
then
26187 elsif AW
and not AR
and not ER
and not EW
then
26192 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
26195 end Check_External_Properties
;
26201 function Check_Kind
(Nam
: Name_Id
) return Name_Id
is
26205 -- Loop through entries in check policy list
26207 PP
:= Opt
.Check_Policy_List
;
26208 while Present
(PP
) loop
26210 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
26211 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
26215 or else (Pnm
= Name_Assertion
26216 and then Is_Valid_Assertion_Kind
(Nam
))
26217 or else (Pnm
= Name_Statement_Assertions
26218 and then Nam_In
(Nam
, Name_Assert
,
26219 Name_Assert_And_Cut
,
26221 Name_Loop_Invariant
,
26222 Name_Loop_Variant
))
26224 case (Chars
(Get_Pragma_Arg
(Last
(PPA
)))) is
26225 when Name_On | Name_Check
=>
26227 when Name_Off | Name_Ignore
=>
26228 return Name_Ignore
;
26229 when Name_Disable
=>
26230 return Name_Disable
;
26232 raise Program_Error
;
26236 PP
:= Next_Pragma
(PP
);
26241 -- If there are no specific entries that matched, then we let the
26242 -- setting of assertions govern. Note that this provides the needed
26243 -- compatibility with the RM for the cases of assertion, invariant,
26244 -- precondition, predicate, and postcondition.
26246 if Assertions_Enabled
then
26249 return Name_Ignore
;
26253 ---------------------------
26254 -- Check_Missing_Part_Of --
26255 ---------------------------
26257 procedure Check_Missing_Part_Of
(Item_Id
: Entity_Id
) is
26258 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean;
26259 -- Determine whether a package denoted by Pack_Id declares at least one
26262 -----------------------
26263 -- Has_Visible_State --
26264 -----------------------
26266 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean is
26267 Item_Id
: Entity_Id
;
26270 -- Traverse the entity chain of the package trying to find at least
26271 -- one visible abstract state, variable or a package [instantiation]
26272 -- that declares a visible state.
26274 Item_Id
:= First_Entity
(Pack_Id
);
26275 while Present
(Item_Id
)
26276 and then not In_Private_Part
(Item_Id
)
26278 -- Do not consider internally generated items
26280 if not Comes_From_Source
(Item_Id
) then
26283 -- A visible state has been found
26285 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
26288 -- Recursively peek into nested packages and instantiations
26290 elsif Ekind
(Item_Id
) = E_Package
26291 and then Has_Visible_State
(Item_Id
)
26296 Next_Entity
(Item_Id
);
26300 end Has_Visible_State
;
26304 Pack_Id
: Entity_Id
;
26305 Placement
: State_Space_Kind
;
26307 -- Start of processing for Check_Missing_Part_Of
26310 -- Do not consider abstract states, variables or package instantiations
26311 -- coming from an instance as those always inherit the Part_Of indicator
26312 -- of the instance itself.
26314 if In_Instance
then
26317 -- Do not consider internally generated entities as these can never
26318 -- have a Part_Of indicator.
26320 elsif not Comes_From_Source
(Item_Id
) then
26323 -- Perform these checks only when SPARK_Mode is enabled as they will
26324 -- interfere with standard Ada rules and produce false positives.
26326 elsif SPARK_Mode
/= On
then
26329 -- Do not consider constants, because the compiler cannot accurately
26330 -- determine whether they have variable input (SPARK RM 7.1.1(2)) and
26331 -- act as a hidden state of a package.
26333 elsif Ekind
(Item_Id
) = E_Constant
then
26337 -- Find where the abstract state, variable or package instantiation
26338 -- lives with respect to the state space.
26340 Find_Placement_In_State_Space
26341 (Item_Id
=> Item_Id
,
26342 Placement
=> Placement
,
26343 Pack_Id
=> Pack_Id
);
26345 -- Items that appear in a non-package construct (subprogram, block, etc)
26346 -- do not require a Part_Of indicator because they can never act as a
26349 if Placement
= Not_In_Package
then
26352 -- An item declared in the body state space of a package always act as a
26353 -- constituent and does not need explicit Part_Of indicator.
26355 elsif Placement
= Body_State_Space
then
26358 -- In general an item declared in the visible state space of a package
26359 -- does not require a Part_Of indicator. The only exception is when the
26360 -- related package is a private child unit in which case Part_Of must
26361 -- denote a state in the parent unit or in one of its descendants.
26363 elsif Placement
= Visible_State_Space
then
26364 if Is_Child_Unit
(Pack_Id
)
26365 and then Is_Private_Descendant
(Pack_Id
)
26367 -- A package instantiation does not need a Part_Of indicator when
26368 -- the related generic template has no visible state.
26370 if Ekind
(Item_Id
) = E_Package
26371 and then Is_Generic_Instance
(Item_Id
)
26372 and then not Has_Visible_State
(Item_Id
)
26376 -- All other cases require Part_Of
26380 ("indicator Part_Of is required in this context "
26381 & "(SPARK RM 7.2.6(3))", Item_Id
);
26382 Error_Msg_Name_1
:= Chars
(Pack_Id
);
26384 ("\& is declared in the visible part of private child "
26385 & "unit %", Item_Id
);
26389 -- When the item appears in the private state space of a packge, it must
26390 -- be a part of some state declared by the said package.
26392 else pragma Assert
(Placement
= Private_State_Space
);
26394 -- The related package does not declare a state, the item cannot act
26395 -- as a Part_Of constituent.
26397 if No
(Get_Pragma
(Pack_Id
, Pragma_Abstract_State
)) then
26400 -- A package instantiation does not need a Part_Of indicator when the
26401 -- related generic template has no visible state.
26403 elsif Ekind
(Pack_Id
) = E_Package
26404 and then Is_Generic_Instance
(Pack_Id
)
26405 and then not Has_Visible_State
(Pack_Id
)
26409 -- All other cases require Part_Of
26413 ("indicator Part_Of is required in this context "
26414 & "(SPARK RM 7.2.6(2))", Item_Id
);
26415 Error_Msg_Name_1
:= Chars
(Pack_Id
);
26417 ("\& is declared in the private part of package %", Item_Id
);
26420 end Check_Missing_Part_Of
;
26422 ---------------------------------------------------
26423 -- Check_Postcondition_Use_In_Inlined_Subprogram --
26424 ---------------------------------------------------
26426 procedure Check_Postcondition_Use_In_Inlined_Subprogram
26428 Spec_Id
: Entity_Id
)
26431 if Warn_On_Redundant_Constructs
26432 and then Has_Pragma_Inline_Always
(Spec_Id
)
26434 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
26436 if From_Aspect_Specification
(Prag
) then
26438 ("aspect % not enforced on inlined subprogram &?r?",
26439 Corresponding_Aspect
(Prag
), Spec_Id
);
26442 ("pragma % not enforced on inlined subprogram &?r?",
26446 end Check_Postcondition_Use_In_Inlined_Subprogram
;
26448 -------------------------------------
26449 -- Check_State_And_Constituent_Use --
26450 -------------------------------------
26452 procedure Check_State_And_Constituent_Use
26453 (States
: Elist_Id
;
26454 Constits
: Elist_Id
;
26457 function Find_Encapsulating_State
26458 (Constit_Id
: Entity_Id
) return Entity_Id
;
26459 -- Given the entity of a constituent, try to find a corresponding
26460 -- encapsulating state that appears in the same context. The routine
26461 -- returns Empty is no such state is found.
26463 ------------------------------
26464 -- Find_Encapsulating_State --
26465 ------------------------------
26467 function Find_Encapsulating_State
26468 (Constit_Id
: Entity_Id
) return Entity_Id
26470 State_Id
: Entity_Id
;
26473 -- Since a constituent may be part of a larger constituent set, climb
26474 -- the encapsulating state chain looking for a state that appears in
26475 -- the same context.
26477 State_Id
:= Encapsulating_State
(Constit_Id
);
26478 while Present
(State_Id
) loop
26479 if Contains
(States
, State_Id
) then
26483 State_Id
:= Encapsulating_State
(State_Id
);
26487 end Find_Encapsulating_State
;
26491 Constit_Elmt
: Elmt_Id
;
26492 Constit_Id
: Entity_Id
;
26493 State_Id
: Entity_Id
;
26495 -- Start of processing for Check_State_And_Constituent_Use
26498 -- Nothing to do if there are no states or constituents
26500 if No
(States
) or else No
(Constits
) then
26504 -- Inspect the list of constituents and try to determine whether its
26505 -- encapsulating state is in list States.
26507 Constit_Elmt
:= First_Elmt
(Constits
);
26508 while Present
(Constit_Elmt
) loop
26509 Constit_Id
:= Node
(Constit_Elmt
);
26511 -- Determine whether the constituent is part of an encapsulating
26512 -- state that appears in the same context and if this is the case,
26513 -- emit an error (SPARK RM 7.2.6(7)).
26515 State_Id
:= Find_Encapsulating_State
(Constit_Id
);
26517 if Present
(State_Id
) then
26518 Error_Msg_Name_1
:= Chars
(Constit_Id
);
26520 ("cannot mention state & and its constituent % in the same "
26521 & "context", Context
, State_Id
);
26525 Next_Elmt
(Constit_Elmt
);
26527 end Check_State_And_Constituent_Use
;
26529 ---------------------------------------
26530 -- Collect_Subprogram_Inputs_Outputs --
26531 ---------------------------------------
26533 procedure Collect_Subprogram_Inputs_Outputs
26534 (Subp_Id
: Entity_Id
;
26535 Synthesize
: Boolean := False;
26536 Subp_Inputs
: in out Elist_Id
;
26537 Subp_Outputs
: in out Elist_Id
;
26538 Global_Seen
: out Boolean)
26540 procedure Collect_Dependency_Clause
(Clause
: Node_Id
);
26541 -- Collect all relevant items from a dependency clause
26543 procedure Collect_Global_List
26545 Mode
: Name_Id
:= Name_Input
);
26546 -- Collect all relevant items from a global list
26548 -------------------------------
26549 -- Collect_Dependency_Clause --
26550 -------------------------------
26552 procedure Collect_Dependency_Clause
(Clause
: Node_Id
) is
26553 procedure Collect_Dependency_Item
26555 Is_Input
: Boolean);
26556 -- Add an item to the proper subprogram input or output collection
26558 -----------------------------
26559 -- Collect_Dependency_Item --
26560 -----------------------------
26562 procedure Collect_Dependency_Item
26564 Is_Input
: Boolean)
26569 -- Nothing to collect when the item is null
26571 if Nkind
(Item
) = N_Null
then
26574 -- Ditto for attribute 'Result
26576 elsif Is_Attribute_Result
(Item
) then
26579 -- Multiple items appear as an aggregate
26581 elsif Nkind
(Item
) = N_Aggregate
then
26582 Extra
:= First
(Expressions
(Item
));
26583 while Present
(Extra
) loop
26584 Collect_Dependency_Item
(Extra
, Is_Input
);
26588 -- Otherwise this is a solitary item
26592 Append_New_Elmt
(Item
, Subp_Inputs
);
26594 Append_New_Elmt
(Item
, Subp_Outputs
);
26597 end Collect_Dependency_Item
;
26599 -- Start of processing for Collect_Dependency_Clause
26602 if Nkind
(Clause
) = N_Null
then
26605 -- A dependency cause appears as component association
26607 elsif Nkind
(Clause
) = N_Component_Association
then
26608 Collect_Dependency_Item
26609 (Item
=> Expression
(Clause
),
26612 Collect_Dependency_Item
26613 (Item
=> First
(Choices
(Clause
)),
26614 Is_Input
=> False);
26616 -- To accomodate partial decoration of disabled SPARK features, this
26617 -- routine may be called with illegal input. If this is the case, do
26618 -- not raise Program_Error.
26623 end Collect_Dependency_Clause
;
26625 -------------------------
26626 -- Collect_Global_List --
26627 -------------------------
26629 procedure Collect_Global_List
26631 Mode
: Name_Id
:= Name_Input
)
26633 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
26634 -- Add an item to the proper subprogram input or output collection
26636 -------------------------
26637 -- Collect_Global_Item --
26638 -------------------------
26640 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
26642 if Nam_In
(Mode
, Name_In_Out
, Name_Input
) then
26643 Append_New_Elmt
(Item
, Subp_Inputs
);
26646 if Nam_In
(Mode
, Name_In_Out
, Name_Output
) then
26647 Append_New_Elmt
(Item
, Subp_Outputs
);
26649 end Collect_Global_Item
;
26656 -- Start of processing for Collect_Global_List
26659 if Nkind
(List
) = N_Null
then
26662 -- Single global item declaration
26664 elsif Nkind_In
(List
, N_Expanded_Name
,
26666 N_Selected_Component
)
26668 Collect_Global_Item
(List
, Mode
);
26670 -- Simple global list or moded global list declaration
26672 elsif Nkind
(List
) = N_Aggregate
then
26673 if Present
(Expressions
(List
)) then
26674 Item
:= First
(Expressions
(List
));
26675 while Present
(Item
) loop
26676 Collect_Global_Item
(Item
, Mode
);
26681 Assoc
:= First
(Component_Associations
(List
));
26682 while Present
(Assoc
) loop
26683 Collect_Global_List
26684 (List
=> Expression
(Assoc
),
26685 Mode
=> Chars
(First
(Choices
(Assoc
))));
26690 -- To accomodate partial decoration of disabled SPARK features, this
26691 -- routine may be called with illegal input. If this is the case, do
26692 -- not raise Program_Error.
26697 end Collect_Global_List
;
26704 Formal
: Entity_Id
;
26706 Spec_Id
: Entity_Id
;
26707 Subp_Decl
: Node_Id
;
26710 -- Start of processing for Collect_Subprogram_Inputs_Outputs
26713 Global_Seen
:= False;
26715 -- Process all formal parameters of entries, [generic] subprograms, and
26718 if Ekind_In
(Subp_Id
, E_Entry
,
26721 E_Generic_Function
,
26722 E_Generic_Procedure
,
26726 Subp_Decl
:= Unit_Declaration_Node
(Subp_Id
);
26727 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
26729 -- Process all [generic] formal parameters
26731 Formal
:= First_Entity
(Spec_Id
);
26732 while Present
(Formal
) loop
26733 if Ekind_In
(Formal
, E_Generic_In_Parameter
,
26734 E_In_Out_Parameter
,
26737 Append_New_Elmt
(Formal
, Subp_Inputs
);
26740 if Ekind_In
(Formal
, E_Generic_In_Out_Parameter
,
26741 E_In_Out_Parameter
,
26744 Append_New_Elmt
(Formal
, Subp_Outputs
);
26746 -- Out parameters can act as inputs when the related type is
26747 -- tagged, unconstrained array, unconstrained record, or record
26748 -- with unconstrained components.
26750 if Ekind
(Formal
) = E_Out_Parameter
26751 and then Is_Unconstrained_Or_Tagged_Item
(Formal
)
26753 Append_New_Elmt
(Formal
, Subp_Inputs
);
26757 Next_Entity
(Formal
);
26760 -- Otherwise the input denotes a task type, a task body, or the
26761 -- anonymous object created for a single task type.
26763 elsif Ekind_In
(Subp_Id
, E_Task_Type
, E_Task_Body
)
26764 or else Is_Single_Task_Object
(Subp_Id
)
26766 Subp_Decl
:= Declaration_Node
(Subp_Id
);
26767 Spec_Id
:= Unique_Defining_Entity
(Subp_Decl
);
26770 -- When processing an entry, subprogram or task body, look for pragmas
26771 -- Refined_Depends and Refined_Global as they specify the inputs and
26774 if Is_Entry_Body
(Subp_Id
)
26775 or else Ekind_In
(Subp_Id
, E_Subprogram_Body
, E_Task_Body
)
26777 Depends
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Depends
);
26778 Global
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Global
);
26780 -- Subprogram declaration or stand alone body case, look for pragmas
26781 -- Depends and Global
26784 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
26785 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
26788 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
26789 -- because it provides finer granularity of inputs and outputs.
26791 if Present
(Global
) then
26792 Global_Seen
:= True;
26793 Collect_Global_List
(Expression
(Get_Argument
(Global
, Spec_Id
)));
26795 -- When the related subprogram lacks pragma [Refined_]Global, fall back
26796 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
26797 -- the inputs and outputs from [Refined_]Depends.
26799 elsif Synthesize
and then Present
(Depends
) then
26800 Clauses
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
26802 -- Multiple dependency clauses appear as an aggregate
26804 if Nkind
(Clauses
) = N_Aggregate
then
26805 Clause
:= First
(Component_Associations
(Clauses
));
26806 while Present
(Clause
) loop
26807 Collect_Dependency_Clause
(Clause
);
26811 -- Otherwise this is a single dependency clause
26814 Collect_Dependency_Clause
(Clauses
);
26818 -- The current instance of a protected type acts as a formal parameter
26819 -- of mode IN for functions and IN OUT for entries and procedures
26820 -- (SPARK RM 6.1.4).
26822 if Ekind
(Scope
(Spec_Id
)) = E_Protected_Type
then
26823 Typ
:= Scope
(Spec_Id
);
26825 -- Use the anonymous object when the type is single protected
26827 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
26828 Typ
:= Anonymous_Object
(Typ
);
26831 Append_New_Elmt
(Typ
, Subp_Inputs
);
26833 if Ekind_In
(Spec_Id
, E_Entry
, E_Entry_Family
, E_Procedure
) then
26834 Append_New_Elmt
(Typ
, Subp_Outputs
);
26837 -- The current instance of a task type acts as a formal parameter of
26838 -- mode IN OUT (SPARK RM 6.1.4).
26840 elsif Ekind
(Spec_Id
) = E_Task_Type
then
26843 -- Use the anonymous object when the type is single task
26845 if Is_Single_Concurrent_Type_Declaration
(Declaration_Node
(Typ
)) then
26846 Typ
:= Anonymous_Object
(Typ
);
26849 Append_New_Elmt
(Typ
, Subp_Inputs
);
26850 Append_New_Elmt
(Typ
, Subp_Outputs
);
26852 elsif Is_Single_Task_Object
(Spec_Id
) then
26853 Append_New_Elmt
(Spec_Id
, Subp_Inputs
);
26854 Append_New_Elmt
(Spec_Id
, Subp_Outputs
);
26856 end Collect_Subprogram_Inputs_Outputs
;
26858 ---------------------------
26859 -- Contract_Freeze_Error --
26860 ---------------------------
26862 procedure Contract_Freeze_Error
26863 (Contract_Id
: Entity_Id
;
26864 Freeze_Id
: Entity_Id
)
26867 Error_Msg_Name_1
:= Chars
(Contract_Id
);
26868 Error_Msg_Sloc
:= Sloc
(Freeze_Id
);
26871 ("body & declared # freezes the contract of%", Contract_Id
, Freeze_Id
);
26873 ("\all contractual items must be declared before body #", Contract_Id
);
26874 end Contract_Freeze_Error
;
26876 ---------------------------------
26877 -- Delay_Config_Pragma_Analyze --
26878 ---------------------------------
26880 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean is
26882 return Nam_In
(Pragma_Name
(N
), Name_Interrupt_State
,
26883 Name_Priority_Specific_Dispatching
);
26884 end Delay_Config_Pragma_Analyze
;
26886 -----------------------
26887 -- Duplication_Error --
26888 -----------------------
26890 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
) is
26891 Prag_From_Asp
: constant Boolean := From_Aspect_Specification
(Prag
);
26892 Prev_From_Asp
: constant Boolean := From_Aspect_Specification
(Prev
);
26895 Error_Msg_Sloc
:= Sloc
(Prev
);
26896 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
26898 -- Emit a precise message to distinguish between source pragmas and
26899 -- pragmas generated from aspects. The ordering of the two pragmas is
26903 -- Prag -- duplicate
26905 -- No error is emitted when both pragmas come from aspects because this
26906 -- is already detected by the general aspect analysis mechanism.
26908 if Prag_From_Asp
and Prev_From_Asp
then
26910 elsif Prag_From_Asp
then
26911 Error_Msg_N
("aspect % duplicates pragma declared #", Prag
);
26912 elsif Prev_From_Asp
then
26913 Error_Msg_N
("pragma % duplicates aspect declared #", Prag
);
26915 Error_Msg_N
("pragma % duplicates pragma declared #", Prag
);
26917 end Duplication_Error
;
26919 --------------------------
26920 -- Find_Related_Context --
26921 --------------------------
26923 function Find_Related_Context
26925 Do_Checks
: Boolean := False) return Node_Id
26930 Stmt
:= Prev
(Prag
);
26931 while Present
(Stmt
) loop
26933 -- Skip prior pragmas, but check for duplicates
26935 if Nkind
(Stmt
) = N_Pragma
then
26936 if Do_Checks
and then Pragma_Name
(Stmt
) = Pragma_Name
(Prag
) then
26942 -- Skip internally generated code
26944 elsif not Comes_From_Source
(Stmt
) then
26946 -- The anonymous object created for a single concurrent type is a
26947 -- suitable context.
26949 if Nkind
(Stmt
) = N_Object_Declaration
26950 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
26955 -- Return the current source construct
26965 end Find_Related_Context
;
26967 --------------------------------------
26968 -- Find_Related_Declaration_Or_Body --
26969 --------------------------------------
26971 function Find_Related_Declaration_Or_Body
26973 Do_Checks
: Boolean := False) return Node_Id
26975 Prag_Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
26977 procedure Expression_Function_Error
;
26978 -- Emit an error concerning pragma Prag that illegaly applies to an
26979 -- expression function.
26981 -------------------------------
26982 -- Expression_Function_Error --
26983 -------------------------------
26985 procedure Expression_Function_Error
is
26987 Error_Msg_Name_1
:= Prag_Nam
;
26989 -- Emit a precise message to distinguish between source pragmas and
26990 -- pragmas generated from aspects.
26992 if From_Aspect_Specification
(Prag
) then
26994 ("aspect % cannot apply to a stand alone expression function",
26998 ("pragma % cannot apply to a stand alone expression function",
27001 end Expression_Function_Error
;
27005 Context
: constant Node_Id
:= Parent
(Prag
);
27008 Look_For_Body
: constant Boolean :=
27009 Nam_In
(Prag_Nam
, Name_Refined_Depends
,
27010 Name_Refined_Global
,
27011 Name_Refined_Post
);
27012 -- Refinement pragmas must be associated with a subprogram body [stub]
27014 -- Start of processing for Find_Related_Declaration_Or_Body
27017 Stmt
:= Prev
(Prag
);
27018 while Present
(Stmt
) loop
27020 -- Skip prior pragmas, but check for duplicates. Pragmas produced
27021 -- by splitting a complex pre/postcondition are not considered to
27024 if Nkind
(Stmt
) = N_Pragma
then
27026 and then not Split_PPC
(Stmt
)
27027 and then Original_Aspect_Pragma_Name
(Stmt
) = Prag_Nam
27034 -- Emit an error when a refinement pragma appears on an expression
27035 -- function without a completion.
27038 and then Look_For_Body
27039 and then Nkind
(Stmt
) = N_Subprogram_Declaration
27040 and then Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
27041 and then not Has_Completion
(Defining_Entity
(Stmt
))
27043 Expression_Function_Error
;
27046 -- The refinement pragma applies to a subprogram body stub
27048 elsif Look_For_Body
27049 and then Nkind
(Stmt
) = N_Subprogram_Body_Stub
27053 -- Skip internally generated code
27055 elsif not Comes_From_Source
(Stmt
) then
27057 -- The anonymous object created for a single concurrent type is a
27058 -- suitable context.
27060 if Nkind
(Stmt
) = N_Object_Declaration
27061 and then Is_Single_Concurrent_Object
(Defining_Entity
(Stmt
))
27065 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
then
27067 -- The subprogram declaration is an internally generated spec
27068 -- for an expression function.
27070 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
27073 -- The subprogram is actually an instance housed within an
27074 -- anonymous wrapper package.
27076 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
27081 -- Return the current construct which is either a subprogram body,
27082 -- a subprogram declaration or is illegal.
27091 -- If we fall through, then the pragma was either the first declaration
27092 -- or it was preceded by other pragmas and no source constructs.
27094 -- The pragma is associated with a library-level subprogram
27096 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
27097 return Unit
(Parent
(Context
));
27099 -- The pragma appears inside the declarations of an entry body
27101 elsif Nkind
(Context
) = N_Entry_Body
then
27104 -- The pragma appears inside the statements of a subprogram body. This
27105 -- placement is the result of subprogram contract expansion.
27107 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
then
27108 return Parent
(Context
);
27110 -- The pragma appears inside the declarative part of a subprogram body
27112 elsif Nkind
(Context
) = N_Subprogram_Body
then
27115 -- The pragma appears inside the declarative part of a task body
27117 elsif Nkind
(Context
) = N_Task_Body
then
27120 -- The pragma is a byproduct of aspect expansion, return the related
27121 -- context of the original aspect. This case has a lower priority as
27122 -- the above circuitry pinpoints precisely the related context.
27124 elsif Present
(Corresponding_Aspect
(Prag
)) then
27125 return Parent
(Corresponding_Aspect
(Prag
));
27127 -- No candidate subprogram [body] found
27132 end Find_Related_Declaration_Or_Body
;
27134 ----------------------------------
27135 -- Find_Related_Package_Or_Body --
27136 ----------------------------------
27138 function Find_Related_Package_Or_Body
27140 Do_Checks
: Boolean := False) return Node_Id
27142 Context
: constant Node_Id
:= Parent
(Prag
);
27143 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
27147 Stmt
:= Prev
(Prag
);
27148 while Present
(Stmt
) loop
27150 -- Skip prior pragmas, but check for duplicates
27152 if Nkind
(Stmt
) = N_Pragma
then
27153 if Do_Checks
and then Pragma_Name
(Stmt
) = Prag_Nam
then
27159 -- Skip internally generated code
27161 elsif not Comes_From_Source
(Stmt
) then
27162 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
27164 -- The subprogram declaration is an internally generated spec
27165 -- for an expression function.
27167 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
27170 -- The subprogram is actually an instance housed within an
27171 -- anonymous wrapper package.
27173 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
27178 -- Return the current source construct which is illegal
27187 -- If we fall through, then the pragma was either the first declaration
27188 -- or it was preceded by other pragmas and no source constructs.
27190 -- The pragma is associated with a package. The immediate context in
27191 -- this case is the specification of the package.
27193 if Nkind
(Context
) = N_Package_Specification
then
27194 return Parent
(Context
);
27196 -- The pragma appears in the declarations of a package body
27198 elsif Nkind
(Context
) = N_Package_Body
then
27201 -- The pragma appears in the statements of a package body
27203 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
27204 and then Nkind
(Parent
(Context
)) = N_Package_Body
27206 return Parent
(Context
);
27208 -- The pragma is a byproduct of aspect expansion, return the related
27209 -- context of the original aspect. This case has a lower priority as
27210 -- the above circuitry pinpoints precisely the related context.
27212 elsif Present
(Corresponding_Aspect
(Prag
)) then
27213 return Parent
(Corresponding_Aspect
(Prag
));
27215 -- No candidate packge [body] found
27220 end Find_Related_Package_Or_Body
;
27226 function Get_Argument
27228 Context_Id
: Entity_Id
:= Empty
) return Node_Id
27230 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
27233 -- Use the expression of the original aspect when compiling for ASIS or
27234 -- when analyzing the template of a generic unit. In both cases the
27235 -- aspect's tree must be decorated to allow for ASIS queries or to save
27236 -- the global references in the generic context.
27238 if From_Aspect_Specification
(Prag
)
27239 and then (ASIS_Mode
or else (Present
(Context_Id
)
27240 and then Is_Generic_Unit
(Context_Id
)))
27242 return Corresponding_Aspect
(Prag
);
27244 -- Otherwise use the expression of the pragma
27246 elsif Present
(Args
) then
27247 return First
(Args
);
27254 -------------------------
27255 -- Get_Base_Subprogram --
27256 -------------------------
27258 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
is
27259 Result
: Entity_Id
;
27262 -- Follow subprogram renaming chain
27266 if Is_Subprogram
(Result
)
27268 Nkind
(Parent
(Declaration_Node
(Result
))) =
27269 N_Subprogram_Renaming_Declaration
27270 and then Present
(Alias
(Result
))
27272 Result
:= Alias
(Result
);
27276 end Get_Base_Subprogram
;
27278 -----------------------
27279 -- Get_SPARK_Mode_Type --
27280 -----------------------
27282 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
is
27284 if N
= Name_On
then
27286 elsif N
= Name_Off
then
27289 -- Any other argument is illegal
27292 raise Program_Error
;
27294 end Get_SPARK_Mode_Type
;
27296 --------------------------------
27297 -- Get_SPARK_Mode_From_Pragma --
27298 --------------------------------
27300 function Get_SPARK_Mode_From_Pragma
(N
: Node_Id
) return SPARK_Mode_Type
is
27305 pragma Assert
(Nkind
(N
) = N_Pragma
);
27306 Args
:= Pragma_Argument_Associations
(N
);
27308 -- Extract the mode from the argument list
27310 if Present
(Args
) then
27311 Mode
:= First
(Pragma_Argument_Associations
(N
));
27312 return Get_SPARK_Mode_Type
(Chars
(Get_Pragma_Arg
(Mode
)));
27314 -- If SPARK_Mode pragma has no argument, default is ON
27319 end Get_SPARK_Mode_From_Pragma
;
27321 ---------------------------
27322 -- Has_Extra_Parentheses --
27323 ---------------------------
27325 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean is
27329 -- The aggregate should not have an expression list because a clause
27330 -- is always interpreted as a component association. The only way an
27331 -- expression list can sneak in is by adding extra parentheses around
27332 -- the individual clauses:
27334 -- Depends (Output => Input) -- proper form
27335 -- Depends ((Output => Input)) -- extra parentheses
27337 -- Since the extra parentheses are not allowed by the syntax of the
27338 -- pragma, flag them now to avoid emitting misleading errors down the
27341 if Nkind
(Clause
) = N_Aggregate
27342 and then Present
(Expressions
(Clause
))
27344 Expr
:= First
(Expressions
(Clause
));
27345 while Present
(Expr
) loop
27347 -- A dependency clause surrounded by extra parentheses appears
27348 -- as an aggregate of component associations with an optional
27349 -- Paren_Count set.
27351 if Nkind
(Expr
) = N_Aggregate
27352 and then Present
(Component_Associations
(Expr
))
27355 ("dependency clause contains extra parentheses", Expr
);
27357 -- Otherwise the expression is a malformed construct
27360 SPARK_Msg_N
("malformed dependency clause", Expr
);
27370 end Has_Extra_Parentheses
;
27376 procedure Initialize
is
27387 Dummy
:= Dummy
+ 1;
27390 -----------------------------
27391 -- Is_Config_Static_String --
27392 -----------------------------
27394 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean is
27396 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean;
27397 -- This is an internal recursive function that is just like the outer
27398 -- function except that it adds the string to the name buffer rather
27399 -- than placing the string in the name buffer.
27401 ------------------------------
27402 -- Add_Config_Static_String --
27403 ------------------------------
27405 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean is
27412 if Nkind
(N
) = N_Op_Concat
then
27413 if Add_Config_Static_String
(Left_Opnd
(N
)) then
27414 N
:= Right_Opnd
(N
);
27420 if Nkind
(N
) /= N_String_Literal
then
27421 Error_Msg_N
("string literal expected for pragma argument", N
);
27425 for J
in 1 .. String_Length
(Strval
(N
)) loop
27426 C
:= Get_String_Char
(Strval
(N
), J
);
27428 if not In_Character_Range
(C
) then
27430 ("string literal contains invalid wide character",
27431 Sloc
(N
) + 1 + Source_Ptr
(J
));
27435 Add_Char_To_Name_Buffer
(Get_Character
(C
));
27440 end Add_Config_Static_String
;
27442 -- Start of processing for Is_Config_Static_String
27447 return Add_Config_Static_String
(Arg
);
27448 end Is_Config_Static_String
;
27450 ---------------------
27451 -- Is_CCT_Instance --
27452 ---------------------
27454 function Is_CCT_Instance
(Ref
: Node_Id
) return Boolean is
27455 Ref_Id
: constant Entity_Id
:= Entity
(Ref
);
27459 -- Climb the scope chain looking for an enclosing concurrent type that
27460 -- matches the referenced entity.
27462 S
:= Current_Scope
;
27463 while Present
(S
) and then S
/= Standard_Standard
loop
27464 if Ekind_In
(S
, E_Protected_Type
, E_Task_Type
) and then S
= Ref_Id
27473 end Is_CCT_Instance
;
27475 -------------------------------
27476 -- Is_Elaboration_SPARK_Mode --
27477 -------------------------------
27479 function Is_Elaboration_SPARK_Mode
(N
: Node_Id
) return Boolean is
27482 (Nkind
(N
) = N_Pragma
27483 and then Pragma_Name
(N
) = Name_SPARK_Mode
27484 and then Is_List_Member
(N
));
27486 -- Pragma SPARK_Mode affects the elaboration of a package body when it
27487 -- appears in the statement part of the body.
27490 Present
(Parent
(N
))
27491 and then Nkind
(Parent
(N
)) = N_Handled_Sequence_Of_Statements
27492 and then List_Containing
(N
) = Statements
(Parent
(N
))
27493 and then Present
(Parent
(Parent
(N
)))
27494 and then Nkind
(Parent
(Parent
(N
))) = N_Package_Body
;
27495 end Is_Elaboration_SPARK_Mode
;
27497 -----------------------
27498 -- Is_Enabled_Pragma --
27499 -----------------------
27501 function Is_Enabled_Pragma
(Prag
: Node_Id
) return Boolean is
27505 if Present
(Prag
) then
27506 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
27508 if Present
(Arg
) then
27509 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg
)));
27511 -- The lack of a Boolean argument automatically enables the pragma
27517 -- The pragma is missing, therefore it is not enabled
27522 end Is_Enabled_Pragma
;
27524 -----------------------------------------
27525 -- Is_Non_Significant_Pragma_Reference --
27526 -----------------------------------------
27528 -- This function makes use of the following static table which indicates
27529 -- whether appearance of some name in a given pragma is to be considered
27530 -- as a reference for the purposes of warnings about unreferenced objects.
27532 -- -1 indicates that appearence in any argument is significant
27533 -- 0 indicates that appearance in any argument is not significant
27534 -- +n indicates that appearance as argument n is significant, but all
27535 -- other arguments are not significant
27536 -- 9n arguments from n on are significant, before n insignificant
27538 Sig_Flags
: constant array (Pragma_Id
) of Int
:=
27539 (Pragma_Abort_Defer
=> -1,
27540 Pragma_Abstract_State
=> -1,
27541 Pragma_Ada_83
=> -1,
27542 Pragma_Ada_95
=> -1,
27543 Pragma_Ada_05
=> -1,
27544 Pragma_Ada_2005
=> -1,
27545 Pragma_Ada_12
=> -1,
27546 Pragma_Ada_2012
=> -1,
27547 Pragma_All_Calls_Remote
=> -1,
27548 Pragma_Allow_Integer_Address
=> -1,
27549 Pragma_Annotate
=> 93,
27550 Pragma_Assert
=> -1,
27551 Pragma_Assert_And_Cut
=> -1,
27552 Pragma_Assertion_Policy
=> 0,
27553 Pragma_Assume
=> -1,
27554 Pragma_Assume_No_Invalid_Values
=> 0,
27555 Pragma_Async_Readers
=> 0,
27556 Pragma_Async_Writers
=> 0,
27557 Pragma_Asynchronous
=> 0,
27558 Pragma_Atomic
=> 0,
27559 Pragma_Atomic_Components
=> 0,
27560 Pragma_Attach_Handler
=> -1,
27561 Pragma_Attribute_Definition
=> 92,
27562 Pragma_Check
=> -1,
27563 Pragma_Check_Float_Overflow
=> 0,
27564 Pragma_Check_Name
=> 0,
27565 Pragma_Check_Policy
=> 0,
27566 Pragma_CPP_Class
=> 0,
27567 Pragma_CPP_Constructor
=> 0,
27568 Pragma_CPP_Virtual
=> 0,
27569 Pragma_CPP_Vtable
=> 0,
27571 Pragma_C_Pass_By_Copy
=> 0,
27572 Pragma_Comment
=> -1,
27573 Pragma_Common_Object
=> 0,
27574 Pragma_Compile_Time_Error
=> -1,
27575 Pragma_Compile_Time_Warning
=> -1,
27576 Pragma_Compiler_Unit
=> -1,
27577 Pragma_Compiler_Unit_Warning
=> -1,
27578 Pragma_Complete_Representation
=> 0,
27579 Pragma_Complex_Representation
=> 0,
27580 Pragma_Component_Alignment
=> 0,
27581 Pragma_Constant_After_Elaboration
=> 0,
27582 Pragma_Contract_Cases
=> -1,
27583 Pragma_Controlled
=> 0,
27584 Pragma_Convention
=> 0,
27585 Pragma_Convention_Identifier
=> 0,
27586 Pragma_Debug
=> -1,
27587 Pragma_Debug_Policy
=> 0,
27588 Pragma_Detect_Blocking
=> 0,
27589 Pragma_Default_Initial_Condition
=> -1,
27590 Pragma_Default_Scalar_Storage_Order
=> 0,
27591 Pragma_Default_Storage_Pool
=> 0,
27592 Pragma_Depends
=> -1,
27593 Pragma_Disable_Atomic_Synchronization
=> 0,
27594 Pragma_Discard_Names
=> 0,
27595 Pragma_Dispatching_Domain
=> -1,
27596 Pragma_Effective_Reads
=> 0,
27597 Pragma_Effective_Writes
=> 0,
27598 Pragma_Elaborate
=> 0,
27599 Pragma_Elaborate_All
=> 0,
27600 Pragma_Elaborate_Body
=> 0,
27601 Pragma_Elaboration_Checks
=> 0,
27602 Pragma_Eliminate
=> 0,
27603 Pragma_Enable_Atomic_Synchronization
=> 0,
27604 Pragma_Export
=> -1,
27605 Pragma_Export_Function
=> -1,
27606 Pragma_Export_Object
=> -1,
27607 Pragma_Export_Procedure
=> -1,
27608 Pragma_Export_Value
=> -1,
27609 Pragma_Export_Valued_Procedure
=> -1,
27610 Pragma_Extend_System
=> -1,
27611 Pragma_Extensions_Allowed
=> 0,
27612 Pragma_Extensions_Visible
=> 0,
27613 Pragma_External
=> -1,
27614 Pragma_Favor_Top_Level
=> 0,
27615 Pragma_External_Name_Casing
=> 0,
27616 Pragma_Fast_Math
=> 0,
27617 Pragma_Finalize_Storage_Only
=> 0,
27619 Pragma_Global
=> -1,
27620 Pragma_Ident
=> -1,
27621 Pragma_Ignore_Pragma
=> 0,
27622 Pragma_Implementation_Defined
=> -1,
27623 Pragma_Implemented
=> -1,
27624 Pragma_Implicit_Packing
=> 0,
27625 Pragma_Import
=> 93,
27626 Pragma_Import_Function
=> 0,
27627 Pragma_Import_Object
=> 0,
27628 Pragma_Import_Procedure
=> 0,
27629 Pragma_Import_Valued_Procedure
=> 0,
27630 Pragma_Independent
=> 0,
27631 Pragma_Independent_Components
=> 0,
27632 Pragma_Initial_Condition
=> -1,
27633 Pragma_Initialize_Scalars
=> 0,
27634 Pragma_Initializes
=> -1,
27635 Pragma_Inline
=> 0,
27636 Pragma_Inline_Always
=> 0,
27637 Pragma_Inline_Generic
=> 0,
27638 Pragma_Inspection_Point
=> -1,
27639 Pragma_Interface
=> 92,
27640 Pragma_Interface_Name
=> 0,
27641 Pragma_Interrupt_Handler
=> -1,
27642 Pragma_Interrupt_Priority
=> -1,
27643 Pragma_Interrupt_State
=> -1,
27644 Pragma_Invariant
=> -1,
27645 Pragma_Keep_Names
=> 0,
27646 Pragma_License
=> 0,
27647 Pragma_Link_With
=> -1,
27648 Pragma_Linker_Alias
=> -1,
27649 Pragma_Linker_Constructor
=> -1,
27650 Pragma_Linker_Destructor
=> -1,
27651 Pragma_Linker_Options
=> -1,
27652 Pragma_Linker_Section
=> 0,
27654 Pragma_Lock_Free
=> 0,
27655 Pragma_Locking_Policy
=> 0,
27656 Pragma_Loop_Invariant
=> -1,
27657 Pragma_Loop_Optimize
=> 0,
27658 Pragma_Loop_Variant
=> -1,
27659 Pragma_Machine_Attribute
=> -1,
27661 Pragma_Main_Storage
=> -1,
27662 Pragma_Memory_Size
=> 0,
27663 Pragma_No_Return
=> 0,
27664 Pragma_No_Body
=> 0,
27665 Pragma_No_Elaboration_Code_All
=> 0,
27666 Pragma_No_Inline
=> 0,
27667 Pragma_No_Run_Time
=> -1,
27668 Pragma_No_Strict_Aliasing
=> -1,
27669 Pragma_No_Tagged_Streams
=> 0,
27670 Pragma_Normalize_Scalars
=> 0,
27671 Pragma_Obsolescent
=> 0,
27672 Pragma_Optimize
=> 0,
27673 Pragma_Optimize_Alignment
=> 0,
27674 Pragma_Overflow_Mode
=> 0,
27675 Pragma_Overriding_Renamings
=> 0,
27676 Pragma_Ordered
=> 0,
27679 Pragma_Part_Of
=> 0,
27680 Pragma_Partition_Elaboration_Policy
=> 0,
27681 Pragma_Passive
=> 0,
27682 Pragma_Persistent_BSS
=> 0,
27683 Pragma_Polling
=> 0,
27684 Pragma_Prefix_Exception_Messages
=> 0,
27686 Pragma_Postcondition
=> -1,
27687 Pragma_Post_Class
=> -1,
27689 Pragma_Precondition
=> -1,
27690 Pragma_Predicate
=> -1,
27691 Pragma_Predicate_Failure
=> -1,
27692 Pragma_Preelaborable_Initialization
=> -1,
27693 Pragma_Preelaborate
=> 0,
27694 Pragma_Pre_Class
=> -1,
27695 Pragma_Priority
=> -1,
27696 Pragma_Priority_Specific_Dispatching
=> 0,
27697 Pragma_Profile
=> 0,
27698 Pragma_Profile_Warnings
=> 0,
27699 Pragma_Propagate_Exceptions
=> 0,
27700 Pragma_Provide_Shift_Operators
=> 0,
27701 Pragma_Psect_Object
=> 0,
27703 Pragma_Pure_Function
=> 0,
27704 Pragma_Queuing_Policy
=> 0,
27705 Pragma_Rational
=> 0,
27706 Pragma_Ravenscar
=> 0,
27707 Pragma_Refined_Depends
=> -1,
27708 Pragma_Refined_Global
=> -1,
27709 Pragma_Refined_Post
=> -1,
27710 Pragma_Refined_State
=> -1,
27711 Pragma_Relative_Deadline
=> 0,
27712 Pragma_Remote_Access_Type
=> -1,
27713 Pragma_Remote_Call_Interface
=> -1,
27714 Pragma_Remote_Types
=> -1,
27715 Pragma_Restricted_Run_Time
=> 0,
27716 Pragma_Restriction_Warnings
=> 0,
27717 Pragma_Restrictions
=> 0,
27718 Pragma_Reviewable
=> -1,
27719 Pragma_Short_Circuit_And_Or
=> 0,
27720 Pragma_Share_Generic
=> 0,
27721 Pragma_Shared
=> 0,
27722 Pragma_Shared_Passive
=> 0,
27723 Pragma_Short_Descriptors
=> 0,
27724 Pragma_Simple_Storage_Pool_Type
=> 0,
27725 Pragma_Source_File_Name
=> 0,
27726 Pragma_Source_File_Name_Project
=> 0,
27727 Pragma_Source_Reference
=> 0,
27728 Pragma_SPARK_Mode
=> 0,
27729 Pragma_Storage_Size
=> -1,
27730 Pragma_Storage_Unit
=> 0,
27731 Pragma_Static_Elaboration_Desired
=> 0,
27732 Pragma_Stream_Convert
=> 0,
27733 Pragma_Style_Checks
=> 0,
27734 Pragma_Subtitle
=> 0,
27735 Pragma_Suppress
=> 0,
27736 Pragma_Suppress_Exception_Locations
=> 0,
27737 Pragma_Suppress_All
=> 0,
27738 Pragma_Suppress_Debug_Info
=> 0,
27739 Pragma_Suppress_Initialization
=> 0,
27740 Pragma_System_Name
=> 0,
27741 Pragma_Task_Dispatching_Policy
=> 0,
27742 Pragma_Task_Info
=> -1,
27743 Pragma_Task_Name
=> -1,
27744 Pragma_Task_Storage
=> -1,
27745 Pragma_Test_Case
=> -1,
27746 Pragma_Thread_Local_Storage
=> -1,
27747 Pragma_Time_Slice
=> -1,
27749 Pragma_Type_Invariant
=> -1,
27750 Pragma_Type_Invariant_Class
=> -1,
27751 Pragma_Unchecked_Union
=> 0,
27752 Pragma_Unimplemented_Unit
=> 0,
27753 Pragma_Universal_Aliasing
=> 0,
27754 Pragma_Universal_Data
=> 0,
27755 Pragma_Unmodified
=> 0,
27756 Pragma_Unreferenced
=> 0,
27757 Pragma_Unreferenced_Objects
=> 0,
27758 Pragma_Unreserve_All_Interrupts
=> 0,
27759 Pragma_Unsuppress
=> 0,
27760 Pragma_Unevaluated_Use_Of_Old
=> 0,
27761 Pragma_Use_VADS_Size
=> 0,
27762 Pragma_Validity_Checks
=> 0,
27763 Pragma_Volatile
=> 0,
27764 Pragma_Volatile_Components
=> 0,
27765 Pragma_Volatile_Full_Access
=> 0,
27766 Pragma_Volatile_Function
=> 0,
27767 Pragma_Warning_As_Error
=> 0,
27768 Pragma_Warnings
=> 0,
27769 Pragma_Weak_External
=> 0,
27770 Pragma_Wide_Character_Encoding
=> 0,
27771 Unknown_Pragma
=> 0);
27773 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean is
27779 function Arg_No
return Nat
;
27780 -- Returns an integer showing what argument we are in. A value of
27781 -- zero means we are not in any of the arguments.
27787 function Arg_No
return Nat
is
27792 A
:= First
(Pragma_Argument_Associations
(Parent
(P
)));
27806 -- Start of processing for Non_Significant_Pragma_Reference
27811 if Nkind
(P
) /= N_Pragma_Argument_Association
then
27815 Id
:= Get_Pragma_Id
(Parent
(P
));
27816 C
:= Sig_Flags
(Id
);
27831 return AN
< (C
- 90);
27837 end Is_Non_Significant_Pragma_Reference
;
27839 ------------------------------
27840 -- Is_Pragma_String_Literal --
27841 ------------------------------
27843 -- This function returns true if the corresponding pragma argument is a
27844 -- static string expression. These are the only cases in which string
27845 -- literals can appear as pragma arguments. We also allow a string literal
27846 -- as the first argument to pragma Assert (although it will of course
27847 -- always generate a type error).
27849 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean is
27850 Pragn
: constant Node_Id
:= Parent
(Par
);
27851 Assoc
: constant List_Id
:= Pragma_Argument_Associations
(Pragn
);
27852 Pname
: constant Name_Id
:= Pragma_Name
(Pragn
);
27858 N
:= First
(Assoc
);
27865 if Pname
= Name_Assert
then
27868 elsif Pname
= Name_Export
then
27871 elsif Pname
= Name_Ident
then
27874 elsif Pname
= Name_Import
then
27877 elsif Pname
= Name_Interface_Name
then
27880 elsif Pname
= Name_Linker_Alias
then
27883 elsif Pname
= Name_Linker_Section
then
27886 elsif Pname
= Name_Machine_Attribute
then
27889 elsif Pname
= Name_Source_File_Name
then
27892 elsif Pname
= Name_Source_Reference
then
27895 elsif Pname
= Name_Title
then
27898 elsif Pname
= Name_Subtitle
then
27904 end Is_Pragma_String_Literal
;
27906 ---------------------------
27907 -- Is_Private_SPARK_Mode --
27908 ---------------------------
27910 function Is_Private_SPARK_Mode
(N
: Node_Id
) return Boolean is
27913 (Nkind
(N
) = N_Pragma
27914 and then Pragma_Name
(N
) = Name_SPARK_Mode
27915 and then Is_List_Member
(N
));
27917 -- For pragma SPARK_Mode to be private, it has to appear in the private
27918 -- declarations of a package.
27921 Present
(Parent
(N
))
27922 and then Nkind
(Parent
(N
)) = N_Package_Specification
27923 and then List_Containing
(N
) = Private_Declarations
(Parent
(N
));
27924 end Is_Private_SPARK_Mode
;
27926 -------------------------------------
27927 -- Is_Unconstrained_Or_Tagged_Item --
27928 -------------------------------------
27930 function Is_Unconstrained_Or_Tagged_Item
27931 (Item
: Entity_Id
) return Boolean
27933 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean;
27934 -- Determine whether record type Typ has at least one unconstrained
27937 ---------------------------------
27938 -- Has_Unconstrained_Component --
27939 ---------------------------------
27941 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean is
27945 Comp
:= First_Component
(Typ
);
27946 while Present
(Comp
) loop
27947 if Is_Unconstrained_Or_Tagged_Item
(Comp
) then
27951 Next_Component
(Comp
);
27955 end Has_Unconstrained_Component
;
27959 Typ
: constant Entity_Id
:= Etype
(Item
);
27961 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
27964 if Is_Tagged_Type
(Typ
) then
27967 elsif Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
27970 elsif Is_Record_Type
(Typ
) then
27971 if Has_Discriminants
(Typ
) and then not Is_Constrained
(Typ
) then
27974 return Has_Unconstrained_Component
(Typ
);
27977 elsif Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
) then
27983 end Is_Unconstrained_Or_Tagged_Item
;
27985 -----------------------------
27986 -- Is_Valid_Assertion_Kind --
27987 -----------------------------
27989 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean is
27996 Name_Static_Predicate |
27997 Name_Dynamic_Predicate |
28002 Name_Type_Invariant |
28003 Name_uType_Invariant |
28007 Name_Assert_And_Cut |
28009 Name_Contract_Cases |
28011 Name_Default_Initial_Condition |
28013 Name_Initial_Condition |
28016 Name_Loop_Invariant |
28017 Name_Loop_Variant |
28018 Name_Postcondition |
28019 Name_Precondition |
28021 Name_Refined_Post |
28022 Name_Statement_Assertions
=> return True;
28024 when others => return False;
28026 end Is_Valid_Assertion_Kind
;
28028 --------------------------------------
28029 -- Process_Compilation_Unit_Pragmas --
28030 --------------------------------------
28032 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
) is
28034 -- A special check for pragma Suppress_All, a very strange DEC pragma,
28035 -- strange because it comes at the end of the unit. Rational has the
28036 -- same name for a pragma, but treats it as a program unit pragma, In
28037 -- GNAT we just decide to allow it anywhere at all. If it appeared then
28038 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
28039 -- node, and we insert a pragma Suppress (All_Checks) at the start of
28040 -- the context clause to ensure the correct processing.
28042 if Has_Pragma_Suppress_All
(N
) then
28043 Prepend_To
(Context_Items
(N
),
28044 Make_Pragma
(Sloc
(N
),
28045 Chars
=> Name_Suppress
,
28046 Pragma_Argument_Associations
=> New_List
(
28047 Make_Pragma_Argument_Association
(Sloc
(N
),
28048 Expression
=> Make_Identifier
(Sloc
(N
), Name_All_Checks
)))));
28051 -- Nothing else to do at the current time
28053 end Process_Compilation_Unit_Pragmas
;
28055 ------------------------------------
28056 -- Record_Possible_Body_Reference --
28057 ------------------------------------
28059 procedure Record_Possible_Body_Reference
28060 (State_Id
: Entity_Id
;
28064 Spec_Id
: Entity_Id
;
28067 -- Ensure that we are dealing with a reference to a state
28069 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
28071 -- Climb the tree starting from the reference looking for a package body
28072 -- whose spec declares the referenced state. This criteria automatically
28073 -- excludes references in package specs which are legal. Note that it is
28074 -- not wise to emit an error now as the package body may lack pragma
28075 -- Refined_State or the referenced state may not be mentioned in the
28076 -- refinement. This approach avoids the generation of misleading errors.
28079 while Present
(Context
) loop
28080 if Nkind
(Context
) = N_Package_Body
then
28081 Spec_Id
:= Corresponding_Spec
(Context
);
28083 if Present
(Abstract_States
(Spec_Id
))
28084 and then Contains
(Abstract_States
(Spec_Id
), State_Id
)
28086 if No
(Body_References
(State_Id
)) then
28087 Set_Body_References
(State_Id
, New_Elmt_List
);
28090 Append_Elmt
(Ref
, To
=> Body_References
(State_Id
));
28095 Context
:= Parent
(Context
);
28097 end Record_Possible_Body_Reference
;
28099 ------------------------------------------
28100 -- Relocate_Pragmas_To_Anonymous_Object --
28101 ------------------------------------------
28103 procedure Relocate_Pragmas_To_Anonymous_Object
28104 (Typ_Decl
: Node_Id
;
28105 Obj_Decl
: Node_Id
)
28109 Next_Decl
: Node_Id
;
28112 if Nkind
(Typ_Decl
) = N_Protected_Type_Declaration
then
28113 Def
:= Protected_Definition
(Typ_Decl
);
28115 pragma Assert
(Nkind
(Typ_Decl
) = N_Task_Type_Declaration
);
28116 Def
:= Task_Definition
(Typ_Decl
);
28119 -- The concurrent definition has a visible declaration list. Inspect it
28120 -- and relocate all canidate pragmas.
28122 if Present
(Def
) and then Present
(Visible_Declarations
(Def
)) then
28123 Decl
:= First
(Visible_Declarations
(Def
));
28124 while Present
(Decl
) loop
28126 -- Preserve the following declaration for iteration purposes due
28127 -- to possible relocation of a pragma.
28129 Next_Decl
:= Next
(Decl
);
28131 if Nkind
(Decl
) = N_Pragma
28132 and then Pragma_On_Anonymous_Object_OK
(Get_Pragma_Id
(Decl
))
28135 Insert_After
(Obj_Decl
, Decl
);
28137 -- Skip internally generated code
28139 elsif not Comes_From_Source
(Decl
) then
28142 -- No candidate pragmas are available for relocation
28151 end Relocate_Pragmas_To_Anonymous_Object
;
28153 ------------------------------
28154 -- Relocate_Pragmas_To_Body --
28155 ------------------------------
28157 procedure Relocate_Pragmas_To_Body
28158 (Subp_Body
: Node_Id
;
28159 Target_Body
: Node_Id
:= Empty
)
28161 procedure Relocate_Pragma
(Prag
: Node_Id
);
28162 -- Remove a single pragma from its current list and add it to the
28163 -- declarations of the proper body (either Subp_Body or Target_Body).
28165 ---------------------
28166 -- Relocate_Pragma --
28167 ---------------------
28169 procedure Relocate_Pragma
(Prag
: Node_Id
) is
28174 -- When subprogram stubs or expression functions are involves, the
28175 -- destination declaration list belongs to the proper body.
28177 if Present
(Target_Body
) then
28178 Target
:= Target_Body
;
28180 Target
:= Subp_Body
;
28183 Decls
:= Declarations
(Target
);
28187 Set_Declarations
(Target
, Decls
);
28190 -- Unhook the pragma from its current list
28193 Prepend
(Prag
, Decls
);
28194 end Relocate_Pragma
;
28198 Body_Id
: constant Entity_Id
:=
28199 Defining_Unit_Name
(Specification
(Subp_Body
));
28200 Next_Stmt
: Node_Id
;
28203 -- Start of processing for Relocate_Pragmas_To_Body
28206 -- Do not process a body that comes from a separate unit as no construct
28207 -- can possibly follow it.
28209 if not Is_List_Member
(Subp_Body
) then
28212 -- Do not relocate pragmas that follow a stub if the stub does not have
28215 elsif Nkind
(Subp_Body
) = N_Subprogram_Body_Stub
28216 and then No
(Target_Body
)
28220 -- Do not process internally generated routine _Postconditions
28222 elsif Ekind
(Body_Id
) = E_Procedure
28223 and then Chars
(Body_Id
) = Name_uPostconditions
28228 -- Look at what is following the body. We are interested in certain kind
28229 -- of pragmas (either from source or byproducts of expansion) that can
28230 -- apply to a body [stub].
28232 Stmt
:= Next
(Subp_Body
);
28233 while Present
(Stmt
) loop
28235 -- Preserve the following statement for iteration purposes due to a
28236 -- possible relocation of a pragma.
28238 Next_Stmt
:= Next
(Stmt
);
28240 -- Move a candidate pragma following the body to the declarations of
28243 if Nkind
(Stmt
) = N_Pragma
28244 and then Pragma_On_Body_Or_Stub_OK
(Get_Pragma_Id
(Stmt
))
28246 Relocate_Pragma
(Stmt
);
28248 -- Skip internally generated code
28250 elsif not Comes_From_Source
(Stmt
) then
28253 -- No candidate pragmas are available for relocation
28261 end Relocate_Pragmas_To_Body
;
28263 -------------------
28264 -- Resolve_State --
28265 -------------------
28267 procedure Resolve_State
(N
: Node_Id
) is
28272 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
28273 Func
:= Entity
(N
);
28275 -- Handle overloading of state names by functions. Traverse the
28276 -- homonym chain looking for an abstract state.
28278 if Ekind
(Func
) = E_Function
and then Has_Homonym
(Func
) then
28279 State
:= Homonym
(Func
);
28280 while Present
(State
) loop
28282 -- Resolve the overloading by setting the proper entity of the
28283 -- reference to that of the state.
28285 if Ekind
(State
) = E_Abstract_State
then
28286 Set_Etype
(N
, Standard_Void_Type
);
28287 Set_Entity
(N
, State
);
28288 Set_Associated_Node
(N
, State
);
28292 State
:= Homonym
(State
);
28295 -- A function can never act as a state. If the homonym chain does
28296 -- not contain a corresponding state, then something went wrong in
28297 -- the overloading mechanism.
28299 raise Program_Error
;
28304 ----------------------------
28305 -- Rewrite_Assertion_Kind --
28306 ----------------------------
28308 procedure Rewrite_Assertion_Kind
(N
: Node_Id
) is
28312 if Nkind
(N
) = N_Attribute_Reference
28313 and then Attribute_Name
(N
) = Name_Class
28314 and then Nkind
(Prefix
(N
)) = N_Identifier
28316 case Chars
(Prefix
(N
)) is
28321 when Name_Type_Invariant
=>
28322 Nam
:= Name_uType_Invariant
;
28323 when Name_Invariant
=>
28324 Nam
:= Name_uInvariant
;
28329 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
=> Nam
));
28331 end Rewrite_Assertion_Kind
;
28339 Dummy
:= Dummy
+ 1;
28342 --------------------------------
28343 -- Set_Encoded_Interface_Name --
28344 --------------------------------
28346 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
) is
28347 Str
: constant String_Id
:= Strval
(S
);
28348 Len
: constant Int
:= String_Length
(Str
);
28353 Hex
: constant array (0 .. 15) of Character := "0123456789abcdef";
28356 -- Stores encoded value of character code CC. The encoding we use an
28357 -- underscore followed by four lower case hex digits.
28363 procedure Encode
is
28365 Store_String_Char
(Get_Char_Code
('_'));
28367 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 12))));
28369 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 8 and 16#
0F#
))));
28371 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 4 and 16#
0F#
))));
28373 (Get_Char_Code
(Hex
(Integer (CC
and 16#
0F#
))));
28376 -- Start of processing for Set_Encoded_Interface_Name
28379 -- If first character is asterisk, this is a link name, and we leave it
28380 -- completely unmodified. We also ignore null strings (the latter case
28381 -- happens only in error cases) and no encoding should occur for AAMP
28382 -- interface names.
28385 or else Get_String_Char
(Str
, 1) = Get_Char_Code
('*')
28386 or else AAMP_On_Target
28388 Set_Interface_Name
(E
, S
);
28393 CC
:= Get_String_Char
(Str
, J
);
28395 exit when not In_Character_Range
(CC
);
28397 C
:= Get_Character
(CC
);
28399 exit when C
/= '_' and then C
/= '$'
28400 and then C
not in '0' .. '9'
28401 and then C
not in 'a' .. 'z'
28402 and then C
not in 'A' .. 'Z';
28405 Set_Interface_Name
(E
, S
);
28413 -- Here we need to encode. The encoding we use as follows:
28414 -- three underscores + four hex digits (lower case)
28418 for J
in 1 .. String_Length
(Str
) loop
28419 CC
:= Get_String_Char
(Str
, J
);
28421 if not In_Character_Range
(CC
) then
28424 C
:= Get_Character
(CC
);
28426 if C
= '_' or else C
= '$'
28427 or else C
in '0' .. '9'
28428 or else C
in 'a' .. 'z'
28429 or else C
in 'A' .. 'Z'
28431 Store_String_Char
(CC
);
28438 Set_Interface_Name
(E
,
28439 Make_String_Literal
(Sloc
(S
),
28440 Strval
=> End_String
));
28442 end Set_Encoded_Interface_Name
;
28444 ------------------------
28445 -- Set_Elab_Unit_Name --
28446 ------------------------
28448 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
) is
28453 if Nkind
(N
) = N_Identifier
28454 and then Nkind
(With_Item
) = N_Identifier
28456 Set_Entity
(N
, Entity
(With_Item
));
28458 elsif Nkind
(N
) = N_Selected_Component
then
28459 Change_Selected_Component_To_Expanded_Name
(N
);
28460 Set_Entity
(N
, Entity
(With_Item
));
28461 Set_Entity
(Selector_Name
(N
), Entity
(N
));
28463 Pref
:= Prefix
(N
);
28464 Scop
:= Scope
(Entity
(N
));
28465 while Nkind
(Pref
) = N_Selected_Component
loop
28466 Change_Selected_Component_To_Expanded_Name
(Pref
);
28467 Set_Entity
(Selector_Name
(Pref
), Scop
);
28468 Set_Entity
(Pref
, Scop
);
28469 Pref
:= Prefix
(Pref
);
28470 Scop
:= Scope
(Scop
);
28473 Set_Entity
(Pref
, Scop
);
28476 Generate_Reference
(Entity
(With_Item
), N
, Set_Ref
=> False);
28477 end Set_Elab_Unit_Name
;
28479 -------------------
28480 -- Test_Case_Arg --
28481 -------------------
28483 function Test_Case_Arg
28486 From_Aspect
: Boolean := False) return Node_Id
28488 Aspect
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
28493 pragma Assert
(Nam_In
(Arg_Nam
, Name_Ensures
,
28498 -- The caller requests the aspect argument
28500 if From_Aspect
then
28501 if Present
(Aspect
)
28502 and then Nkind
(Expression
(Aspect
)) = N_Aggregate
28504 Args
:= Expression
(Aspect
);
28506 -- "Name" and "Mode" may appear without an identifier as a
28507 -- positional association.
28509 if Present
(Expressions
(Args
)) then
28510 Arg
:= First
(Expressions
(Args
));
28512 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
28520 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
28525 -- Some or all arguments may appear as component associatons
28527 if Present
(Component_Associations
(Args
)) then
28528 Arg
:= First
(Component_Associations
(Args
));
28529 while Present
(Arg
) loop
28530 if Chars
(First
(Choices
(Arg
))) = Arg_Nam
then
28539 -- Otherwise retrieve the argument directly from the pragma
28542 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
28544 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
28548 -- Skip argument "Name"
28552 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
28556 -- Skip argument "Mode"
28560 -- Arguments "Requires" and "Ensures" are optional and may not be
28563 while Present
(Arg
) loop
28564 if Chars
(Arg
) = Arg_Nam
then