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 Csets
; use Csets
;
37 with Debug
; use Debug
;
38 with Einfo
; use Einfo
;
39 with Elists
; use Elists
;
40 with Errout
; use Errout
;
41 with Exp_Dist
; use Exp_Dist
;
42 with Exp_Util
; use Exp_Util
;
43 with Freeze
; use Freeze
;
44 with Ghost
; use Ghost
;
46 with Lib
.Writ
; use Lib
.Writ
;
47 with Lib
.Xref
; use Lib
.Xref
;
48 with Namet
.Sp
; use Namet
.Sp
;
49 with Nlists
; use Nlists
;
50 with Nmake
; use Nmake
;
51 with Output
; use Output
;
52 with Par_SCO
; use Par_SCO
;
53 with Restrict
; use Restrict
;
54 with Rident
; use Rident
;
55 with Rtsfind
; use Rtsfind
;
57 with Sem_Aux
; use Sem_Aux
;
58 with Sem_Ch3
; use Sem_Ch3
;
59 with Sem_Ch6
; use Sem_Ch6
;
60 with Sem_Ch8
; use Sem_Ch8
;
61 with Sem_Ch12
; use Sem_Ch12
;
62 with Sem_Ch13
; use Sem_Ch13
;
63 with Sem_Disp
; use Sem_Disp
;
64 with Sem_Dist
; use Sem_Dist
;
65 with Sem_Elim
; use Sem_Elim
;
66 with Sem_Eval
; use Sem_Eval
;
67 with Sem_Intr
; use Sem_Intr
;
68 with Sem_Mech
; use Sem_Mech
;
69 with Sem_Res
; use Sem_Res
;
70 with Sem_Type
; use Sem_Type
;
71 with Sem_Util
; use Sem_Util
;
72 with Sem_Warn
; use Sem_Warn
;
73 with Stand
; use Stand
;
74 with Sinfo
; use Sinfo
;
75 with Sinfo
.CN
; use Sinfo
.CN
;
76 with Sinput
; use Sinput
;
77 with Stringt
; use Stringt
;
78 with Stylesw
; use Stylesw
;
80 with Targparm
; use Targparm
;
81 with Tbuild
; use Tbuild
;
83 with Uintp
; use Uintp
;
84 with Uname
; use Uname
;
85 with Urealp
; use Urealp
;
86 with Validsw
; use Validsw
;
87 with Warnsw
; use Warnsw
;
89 package body Sem_Prag
is
91 ----------------------------------------------
92 -- Common Handling of Import-Export Pragmas --
93 ----------------------------------------------
95 -- In the following section, a number of Import_xxx and Export_xxx pragmas
96 -- are defined by GNAT. These are compatible with the DEC pragmas of the
97 -- same name, and all have the following common form and processing:
100 -- [Internal =>] LOCAL_NAME
101 -- [, [External =>] EXTERNAL_SYMBOL]
102 -- [, other optional parameters ]);
105 -- [Internal =>] LOCAL_NAME
106 -- [, [External =>] EXTERNAL_SYMBOL]
107 -- [, other optional parameters ]);
109 -- EXTERNAL_SYMBOL ::=
111 -- | static_string_EXPRESSION
113 -- The internal LOCAL_NAME designates the entity that is imported or
114 -- exported, and must refer to an entity in the current declarative
115 -- part (as required by the rules for LOCAL_NAME).
117 -- The external linker name is designated by the External parameter if
118 -- given, or the Internal parameter if not (if there is no External
119 -- parameter, the External parameter is a copy of the Internal name).
121 -- If the External parameter is given as a string, then this string is
122 -- treated as an external name (exactly as though it had been given as an
123 -- External_Name parameter for a normal Import pragma).
125 -- If the External parameter is given as an identifier (or there is no
126 -- External parameter, so that the Internal identifier is used), then
127 -- the external name is the characters of the identifier, translated
128 -- to all lower case letters.
130 -- Note: the external name specified or implied by any of these special
131 -- Import_xxx or Export_xxx pragmas override an external or link name
132 -- specified in a previous Import or Export pragma.
134 -- Note: these and all other DEC-compatible GNAT pragmas allow full use of
135 -- named notation, following the standard rules for subprogram calls, i.e.
136 -- parameters can be given in any order if named notation is used, and
137 -- positional and named notation can be mixed, subject to the rule that all
138 -- positional parameters must appear first.
140 -- Note: All these pragmas are implemented exactly following the DEC design
141 -- and implementation and are intended to be fully compatible with the use
142 -- of these pragmas in the DEC Ada compiler.
144 --------------------------------------------
145 -- Checking for Duplicated External Names --
146 --------------------------------------------
148 -- It is suspicious if two separate Export pragmas use the same external
149 -- name. The following table is used to diagnose this situation so that
150 -- an appropriate warning can be issued.
152 -- The Node_Id stored is for the N_String_Literal node created to hold
153 -- the value of the external name. The Sloc of this node is used to
154 -- cross-reference the location of the duplication.
156 package Externals
is new Table
.Table
(
157 Table_Component_Type
=> Node_Id
,
158 Table_Index_Type
=> Int
,
159 Table_Low_Bound
=> 0,
160 Table_Initial
=> 100,
161 Table_Increment
=> 100,
162 Table_Name
=> "Name_Externals");
164 -------------------------------------
165 -- Local Subprograms and Variables --
166 -------------------------------------
168 procedure Add_Item
(Item
: Entity_Id
; To_List
: in out Elist_Id
);
169 -- Subsidiary routine to the analysis of pragmas Depends, Global and
170 -- Refined_State. Append an entity to a list. If the list is empty, create
173 function Adjust_External_Name_Case
(N
: Node_Id
) return Node_Id
;
174 -- This routine is used for possible casing adjustment of an explicit
175 -- external name supplied as a string literal (the node N), according to
176 -- the casing requirement of Opt.External_Name_Casing. If this is set to
177 -- As_Is, then the string literal is returned unchanged, but if it is set
178 -- to Uppercase or Lowercase, then a new string literal with appropriate
179 -- casing is constructed.
181 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean;
182 -- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends.
183 -- Query whether a particular item appears in a mixed list of nodes and
184 -- entities. It is assumed that all nodes in the list have entities.
186 function Check_Kind
(Nam
: Name_Id
) return Name_Id
;
187 -- This function is used in connection with pragmas Assert, Check,
188 -- and assertion aspects and pragmas, to determine if Check pragmas
189 -- (or corresponding assertion aspects or pragmas) are currently active
190 -- as determined by the presence of -gnata on the command line (which
191 -- sets the default), and the appearance of pragmas Check_Policy and
192 -- Assertion_Policy as configuration pragmas either in a configuration
193 -- pragma file, or at the start of the current unit, or locally given
194 -- Check_Policy and Assertion_Policy pragmas that are currently active.
196 -- The value returned is one of the names Check, Ignore, Disable (On
197 -- returns Check, and Off returns Ignore).
199 -- Note: for assertion kinds Pre'Class, Post'Class, Invariant'Class,
200 -- and Type_Invariant'Class, the name passed is Name_uPre, Name_uPost,
201 -- Name_uInvariant, or Name_uType_Invariant, which corresponds to _Pre,
202 -- _Post, _Invariant, or _Type_Invariant, which are special names used
203 -- in identifiers to represent these attribute references.
205 procedure Check_Postcondition_Use_In_Inlined_Subprogram
207 Subp_Id
: Entity_Id
);
208 -- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition,
209 -- Precondition, Refined_Post and Test_Case. Emit a warning when pragma
210 -- Prag is associated with subprogram Subp_Id subject to Inline_Always.
212 procedure Check_State_And_Constituent_Use
216 -- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_]
217 -- Global and Initializes. Determine whether a state from list States and a
218 -- corresponding constituent from list Constits (if any) appear in the same
219 -- context denoted by Context. If this is the case, emit an error.
221 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
);
222 -- Subsidiary to routines Find_Related_Package_Or_Body and
223 -- Find_Related_Subprogram_Or_Body. Emit an error on pragma Prag that
224 -- duplicates previous pragma Prev.
226 function Find_Related_Package_Or_Body
228 Do_Checks
: Boolean := False) return Node_Id
;
229 -- Subsidiary to the analysis of pragmas Abstract_State, Initial_Condition,
230 -- Initializes and Refined_State. Find the declaration of the related
231 -- package [body] subject to pragma Prag. The return value is either
232 -- N_Package_Declaration, N_Package_Body or Empty if the placement of
233 -- the pragma is illegal. If flag Do_Checks is set, the routine reports
234 -- duplicate pragmas.
236 function Get_Argument
238 Spec_Id
: Entity_Id
:= Empty
) return Node_Id
;
239 -- Obtain the argument of pragma Prag depending on context and the nature
240 -- of the pragma. The argument is extracted in the following manner:
242 -- When the pragma is generated from an aspect, return the corresponding
243 -- aspect for ASIS or when Spec_Id denotes a generic subprogram.
245 -- Otherwise return the first argument of Prag
247 -- Spec_Id denotes the entity of the subprogram spec where Prag resides
249 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
;
250 -- If Def_Id refers to a renamed subprogram, then the base subprogram (the
251 -- original one, following the renaming chain) is returned. Otherwise the
252 -- entity is returned unchanged. Should be in Einfo???
254 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
;
255 -- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram
256 -- Get_SPARK_Mode_Type. Convert a name into a corresponding value of type
259 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean;
260 -- Subsidiary to the analysis of pragmas Depends and Refined_Depends.
261 -- Determine whether dependency clause Clause is surrounded by extra
262 -- parentheses. If this is the case, issue an error message.
264 function Is_Unconstrained_Or_Tagged_Item
(Item
: Entity_Id
) return Boolean;
265 -- Subsidiary to Collect_Subprogram_Inputs_Outputs and the analysis of
266 -- pragma Depends. Determine whether the type of dependency item Item is
267 -- tagged, unconstrained array, unconstrained record or a record with at
268 -- least one unconstrained component.
270 procedure Record_Possible_Body_Reference
271 (State_Id
: Entity_Id
;
273 -- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_]
274 -- Global. Given an abstract state denoted by State_Id and a reference Ref
275 -- to it, determine whether the reference appears in a package body that
276 -- will eventually refine the state. If this is the case, record the
277 -- reference for future checks (see Analyze_Refined_State_In_Decls).
279 procedure Resolve_State
(N
: Node_Id
);
280 -- Handle the overloading of state names by functions. When N denotes a
281 -- function, this routine finds the corresponding state and sets the entity
282 -- of N to that of the state.
284 procedure Rewrite_Assertion_Kind
(N
: Node_Id
);
285 -- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class,
286 -- then it is rewritten as an identifier with the corresponding special
287 -- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check
290 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
);
291 -- Place semantic information on the argument of an Elaborate/Elaborate_All
292 -- pragma. Entity name for unit and its parents is taken from item in
293 -- previous with_clause that mentions the unit.
295 Dummy
: Integer := 0;
296 pragma Volatile
(Dummy
);
297 -- Dummy volatile integer used in bodies of ip/rv to prevent optimization
300 pragma No_Inline
(ip
);
301 -- A dummy procedure called when pragma Inspection_Point is analyzed. This
302 -- is just to help debugging the front end. If a pragma Inspection_Point
303 -- is added to a source program, then breaking on ip will get you to that
304 -- point in the program.
307 pragma No_Inline
(rv
);
308 -- This is a dummy function called by the processing for pragma Reviewable.
309 -- It is there for assisting front end debugging. By placing a Reviewable
310 -- pragma in the source program, a breakpoint on rv catches this place in
311 -- the source, allowing convenient stepping to the point of interest.
317 procedure Add_Item
(Item
: Entity_Id
; To_List
: in out Elist_Id
) is
319 Append_New_Elmt
(Item
, To
=> To_List
);
322 -------------------------------
323 -- Adjust_External_Name_Case --
324 -------------------------------
326 function Adjust_External_Name_Case
(N
: Node_Id
) return Node_Id
is
330 -- Adjust case of literal if required
332 if Opt
.External_Name_Exp_Casing
= As_Is
then
336 -- Copy existing string
342 for J
in 1 .. String_Length
(Strval
(N
)) loop
343 CC
:= Get_String_Char
(Strval
(N
), J
);
345 if Opt
.External_Name_Exp_Casing
= Uppercase
346 and then CC
>= Get_Char_Code
('a')
347 and then CC
<= Get_Char_Code
('z')
349 Store_String_Char
(CC
- 32);
351 elsif Opt
.External_Name_Exp_Casing
= Lowercase
352 and then CC
>= Get_Char_Code
('A')
353 and then CC
<= Get_Char_Code
('Z')
355 Store_String_Char
(CC
+ 32);
358 Store_String_Char
(CC
);
363 Make_String_Literal
(Sloc
(N
),
364 Strval
=> End_String
);
366 end Adjust_External_Name_Case
;
368 -----------------------------------------
369 -- Analyze_Contract_Cases_In_Decl_Part --
370 -----------------------------------------
372 procedure Analyze_Contract_Cases_In_Decl_Part
(N
: Node_Id
) is
373 Others_Seen
: Boolean := False;
375 procedure Analyze_Contract_Case
(CCase
: Node_Id
);
376 -- Verify the legality of a single contract case
378 ---------------------------
379 -- Analyze_Contract_Case --
380 ---------------------------
382 procedure Analyze_Contract_Case
(CCase
: Node_Id
) is
383 Case_Guard
: Node_Id
;
385 Extra_Guard
: Node_Id
;
388 if Nkind
(CCase
) = N_Component_Association
then
389 Case_Guard
:= First
(Choices
(CCase
));
390 Conseq
:= Expression
(CCase
);
392 -- Each contract case must have exactly one case guard
394 Extra_Guard
:= Next
(Case_Guard
);
396 if Present
(Extra_Guard
) then
398 ("contract case must have exactly one case guard",
402 -- Check placement of OTHERS if available (SPARK RM 6.1.3(1))
404 if Nkind
(Case_Guard
) = N_Others_Choice
then
407 ("only one others choice allowed in contract cases",
413 elsif Others_Seen
then
415 ("others must be the last choice in contract cases", N
);
418 -- Preanalyze the case guard and consequence
420 if Nkind
(Case_Guard
) /= N_Others_Choice
then
421 Preanalyze_Assert_Expression
(Case_Guard
, Standard_Boolean
);
424 Preanalyze_Assert_Expression
(Conseq
, Standard_Boolean
);
426 -- The contract case is malformed
429 Error_Msg_N
("wrong syntax in contract case", CCase
);
431 end Analyze_Contract_Case
;
441 Restore_Scope
: Boolean := False;
442 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
444 -- Start of processing for Analyze_Contract_Cases_In_Decl_Part
449 Subp_Decl
:= Find_Related_Subprogram_Or_Body
(N
);
450 Spec_Id
:= Corresponding_Spec_Of
(Subp_Decl
);
451 Subp_Id
:= Defining_Entity
(Subp_Decl
);
452 All_Cases
:= Expression
(Get_Argument
(N
, Subp_Id
));
454 -- Single and multiple contract cases must appear in aggregate form. If
455 -- this is not the case, then either the parser of the analysis of the
456 -- pragma failed to produce an aggregate.
458 pragma Assert
(Nkind
(All_Cases
) = N_Aggregate
);
460 if Present
(Component_Associations
(All_Cases
)) then
462 -- Ensure that the formal parameters are visible when analyzing all
463 -- clauses. This falls out of the general rule of aspects pertaining
464 -- to subprogram declarations. Skip the installation for subprogram
465 -- bodies because the formals are already visible.
467 if not In_Open_Scopes
(Spec_Id
) then
468 Restore_Scope
:= True;
469 Push_Scope
(Spec_Id
);
471 if Is_Generic_Subprogram
(Spec_Id
) then
472 Install_Generic_Formals
(Spec_Id
);
474 Install_Formals
(Spec_Id
);
478 CCase
:= First
(Component_Associations
(All_Cases
));
479 while Present
(CCase
) loop
480 Analyze_Contract_Case
(CCase
);
484 -- Currently it is not possible to inline pre/postconditions on a
485 -- subprogram subject to pragma Inline_Always.
487 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
489 if Restore_Scope
then
493 Error_Msg_N
("wrong syntax for constract cases", N
);
495 end Analyze_Contract_Cases_In_Decl_Part
;
497 ----------------------------------
498 -- Analyze_Depends_In_Decl_Part --
499 ----------------------------------
501 procedure Analyze_Depends_In_Decl_Part
(N
: Node_Id
) is
502 Loc
: constant Source_Ptr
:= Sloc
(N
);
504 All_Inputs_Seen
: Elist_Id
:= No_Elist
;
505 -- A list containing the entities of all the inputs processed so far.
506 -- The list is populated with unique entities because the same input
507 -- may appear in multiple input lists.
509 All_Outputs_Seen
: Elist_Id
:= No_Elist
;
510 -- A list containing the entities of all the outputs processed so far.
511 -- The list is populated with unique entities because output items are
512 -- unique in a dependence relation.
514 Constits_Seen
: Elist_Id
:= No_Elist
;
515 -- A list containing the entities of all constituents processed so far.
516 -- It aids in detecting illegal usage of a state and a corresponding
517 -- constituent in pragma [Refinde_]Depends.
519 Global_Seen
: Boolean := False;
520 -- A flag set when pragma Global has been processed
522 Null_Output_Seen
: Boolean := False;
523 -- A flag used to track the legality of a null output
525 Result_Seen
: Boolean := False;
526 -- A flag set when Subp_Id'Result is processed
529 -- The entity of the subprogram subject to pragma [Refined_]Depends
531 States_Seen
: Elist_Id
:= No_Elist
;
532 -- A list containing the entities of all states processed so far. It
533 -- helps in detecting illegal usage of a state and a corresponding
534 -- constituent in pragma [Refined_]Depends.
537 -- The entity of the subprogram [body or stub] subject to pragma
538 -- [Refined_]Depends.
540 Subp_Inputs
: Elist_Id
:= No_Elist
;
541 Subp_Outputs
: Elist_Id
:= No_Elist
;
542 -- Two lists containing the full set of inputs and output of the related
543 -- subprograms. Note that these lists contain both nodes and entities.
545 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
);
546 -- Subsidiary routine to Check_Role and Check_Usage. Add the item kind
547 -- to the name buffer. The individual kinds are as follows:
548 -- E_Abstract_State - "state"
549 -- E_In_Parameter - "parameter"
550 -- E_In_Out_Parameter - "parameter"
551 -- E_Out_Parameter - "parameter"
552 -- E_Variable - "global"
554 procedure Analyze_Dependency_Clause
557 -- Verify the legality of a single dependency clause. Flag Is_Last
558 -- denotes whether Clause is the last clause in the relation.
560 procedure Check_Function_Return
;
561 -- Verify that Funtion'Result appears as one of the outputs
562 -- (SPARK RM 6.1.5(10)).
569 -- Ensure that an item fulfils its designated input and/or output role
570 -- as specified by pragma Global (if any) or the enclosing context. If
571 -- this is not the case, emit an error. Item and Item_Id denote the
572 -- attributes of an item. Flag Is_Input should be set when item comes
573 -- from an input list. Flag Self_Ref should be set when the item is an
574 -- output and the dependency clause has operator "+".
576 procedure Check_Usage
577 (Subp_Items
: Elist_Id
;
578 Used_Items
: Elist_Id
;
580 -- Verify that all items from Subp_Items appear in Used_Items. Emit an
581 -- error if this is not the case.
583 procedure Normalize_Clause
(Clause
: Node_Id
);
584 -- Remove a self-dependency "+" from the input list of a clause
586 -----------------------------
587 -- Add_Item_To_Name_Buffer --
588 -----------------------------
590 procedure Add_Item_To_Name_Buffer
(Item_Id
: Entity_Id
) is
592 if Ekind
(Item_Id
) = E_Abstract_State
then
593 Add_Str_To_Name_Buffer
("state");
595 elsif Is_Formal
(Item_Id
) then
596 Add_Str_To_Name_Buffer
("parameter");
598 elsif Ekind
(Item_Id
) = E_Variable
then
599 Add_Str_To_Name_Buffer
("global");
601 -- The routine should not be called with non-SPARK items
606 end Add_Item_To_Name_Buffer
;
608 -------------------------------
609 -- Analyze_Dependency_Clause --
610 -------------------------------
612 procedure Analyze_Dependency_Clause
616 procedure Analyze_Input_List
(Inputs
: Node_Id
);
617 -- Verify the legality of a single input list
619 procedure Analyze_Input_Output
624 Seen
: in out Elist_Id
;
625 Null_Seen
: in out Boolean;
626 Non_Null_Seen
: in out Boolean);
627 -- Verify the legality of a single input or output item. Flag
628 -- Is_Input should be set whenever Item is an input, False when it
629 -- denotes an output. Flag Self_Ref should be set when the item is an
630 -- output and the dependency clause has a "+". Flag Top_Level should
631 -- be set whenever Item appears immediately within an input or output
632 -- list. Seen is a collection of all abstract states, variables and
633 -- formals processed so far. Flag Null_Seen denotes whether a null
634 -- input or output has been encountered. Flag Non_Null_Seen denotes
635 -- whether a non-null input or output has been encountered.
637 ------------------------
638 -- Analyze_Input_List --
639 ------------------------
641 procedure Analyze_Input_List
(Inputs
: Node_Id
) is
642 Inputs_Seen
: Elist_Id
:= No_Elist
;
643 -- A list containing the entities of all inputs that appear in the
644 -- current input list.
646 Non_Null_Input_Seen
: Boolean := False;
647 Null_Input_Seen
: Boolean := False;
648 -- Flags used to check the legality of an input list
653 -- Multiple inputs appear as an aggregate
655 if Nkind
(Inputs
) = N_Aggregate
then
656 if Present
(Component_Associations
(Inputs
)) then
658 ("nested dependency relations not allowed", Inputs
);
660 elsif Present
(Expressions
(Inputs
)) then
661 Input
:= First
(Expressions
(Inputs
));
662 while Present
(Input
) loop
669 Null_Seen
=> Null_Input_Seen
,
670 Non_Null_Seen
=> Non_Null_Input_Seen
);
675 -- Syntax error, always report
678 Error_Msg_N
("malformed input dependency list", Inputs
);
681 -- Process a solitary input
690 Null_Seen
=> Null_Input_Seen
,
691 Non_Null_Seen
=> Non_Null_Input_Seen
);
694 -- Detect an illegal dependency clause of the form
698 if Null_Output_Seen
and then Null_Input_Seen
then
700 ("null dependency clause cannot have a null input list",
703 end Analyze_Input_List
;
705 --------------------------
706 -- Analyze_Input_Output --
707 --------------------------
709 procedure Analyze_Input_Output
714 Seen
: in out Elist_Id
;
715 Null_Seen
: in out Boolean;
716 Non_Null_Seen
: in out Boolean)
718 Is_Output
: constant Boolean := not Is_Input
;
723 -- Multiple input or output items appear as an aggregate
725 if Nkind
(Item
) = N_Aggregate
then
726 if not Top_Level
then
727 SPARK_Msg_N
("nested grouping of items not allowed", Item
);
729 elsif Present
(Component_Associations
(Item
)) then
731 ("nested dependency relations not allowed", Item
);
733 -- Recursively analyze the grouped items
735 elsif Present
(Expressions
(Item
)) then
736 Grouped
:= First
(Expressions
(Item
));
737 while Present
(Grouped
) loop
740 Is_Input
=> Is_Input
,
741 Self_Ref
=> Self_Ref
,
744 Null_Seen
=> Null_Seen
,
745 Non_Null_Seen
=> Non_Null_Seen
);
750 -- Syntax error, always report
753 Error_Msg_N
("malformed dependency list", Item
);
756 -- Process Function'Result in the context of a dependency clause
758 elsif Is_Attribute_Result
(Item
) then
759 Non_Null_Seen
:= True;
761 -- It is sufficent to analyze the prefix of 'Result in order to
762 -- establish legality of the attribute.
764 Analyze
(Prefix
(Item
));
766 -- The prefix of 'Result must denote the function for which
767 -- pragma Depends applies (SPARK RM 6.1.5(11)).
769 if not Is_Entity_Name
(Prefix
(Item
))
770 or else Ekind
(Spec_Id
) /= E_Function
771 or else Entity
(Prefix
(Item
)) /= Spec_Id
773 Error_Msg_Name_1
:= Name_Result
;
775 ("prefix of attribute % must denote the enclosing "
778 -- Function'Result is allowed to appear on the output side of a
779 -- dependency clause (SPARK RM 6.1.5(6)).
782 SPARK_Msg_N
("function result cannot act as input", Item
);
786 ("cannot mix null and non-null dependency items", Item
);
792 -- Detect multiple uses of null in a single dependency list or
793 -- throughout the whole relation. Verify the placement of a null
794 -- output list relative to the other clauses (SPARK RM 6.1.5(12)).
796 elsif Nkind
(Item
) = N_Null
then
799 ("multiple null dependency relations not allowed", Item
);
801 elsif Non_Null_Seen
then
803 ("cannot mix null and non-null dependency items", Item
);
811 ("null output list must be the last clause in a "
812 & "dependency relation", Item
);
814 -- Catch a useless dependence of the form:
819 ("useless dependence, null depends on itself", Item
);
827 Non_Null_Seen
:= True;
830 SPARK_Msg_N
("cannot mix null and non-null items", Item
);
834 Resolve_State
(Item
);
836 -- Find the entity of the item. If this is a renaming, climb
837 -- the renaming chain to reach the root object. Renamings of
838 -- non-entire objects do not yield an entity (Empty).
840 Item_Id
:= Entity_Of
(Item
);
842 if Present
(Item_Id
) then
843 if Ekind_In
(Item_Id
, E_Abstract_State
,
849 -- Ensure that the item fulfils its role as input and/or
850 -- output as specified by pragma Global or the enclosing
853 Check_Role
(Item
, Item_Id
, Is_Input
, Self_Ref
);
855 -- Detect multiple uses of the same state, variable or
856 -- formal parameter. If this is not the case, add the
857 -- item to the list of processed relations.
859 if Contains
(Seen
, Item_Id
) then
861 ("duplicate use of item &", Item
, Item_Id
);
863 Add_Item
(Item_Id
, Seen
);
866 -- Detect illegal use of an input related to a null
867 -- output. Such input items cannot appear in other
868 -- input lists (SPARK RM 6.1.5(13)).
871 and then Null_Output_Seen
872 and then Contains
(All_Inputs_Seen
, Item_Id
)
875 ("input of a null output list cannot appear in "
876 & "multiple input lists", Item
);
879 -- Add an input or a self-referential output to the list
880 -- of all processed inputs.
882 if Is_Input
or else Self_Ref
then
883 Add_Item
(Item_Id
, All_Inputs_Seen
);
886 -- State related checks (SPARK RM 6.1.5(3))
888 if Ekind
(Item_Id
) = E_Abstract_State
then
889 if Has_Visible_Refinement
(Item_Id
) then
891 ("cannot mention state & in global refinement",
893 SPARK_Msg_N
("\use its constituents instead", Item
);
896 -- If the reference to the abstract state appears in
897 -- an enclosing package body that will eventually
898 -- refine the state, record the reference for future
902 Record_Possible_Body_Reference
903 (State_Id
=> Item_Id
,
908 -- When the item renames an entire object, replace the
909 -- item with a reference to the object.
911 if Present
(Renamed_Object
(Entity
(Item
))) then
913 New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
917 -- Add the entity of the current item to the list of
920 if Ekind
(Item_Id
) = E_Abstract_State
then
921 Add_Item
(Item_Id
, States_Seen
);
924 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
)
925 and then Present
(Encapsulating_State
(Item_Id
))
927 Add_Item
(Item_Id
, Constits_Seen
);
930 -- All other input/output items are illegal
931 -- (SPARK RM 6.1.5(1)).
935 ("item must denote parameter, variable, or state",
939 -- All other input/output items are illegal
940 -- (SPARK RM 6.1.5(1)). This is a syntax error, always report.
944 ("item must denote parameter, variable, or state", Item
);
947 end Analyze_Input_Output
;
955 Non_Null_Output_Seen
: Boolean := False;
956 -- Flag used to check the legality of an output list
958 -- Start of processing for Analyze_Dependency_Clause
961 Inputs
:= Expression
(Clause
);
964 -- An input list with a self-dependency appears as operator "+" where
965 -- the actuals inputs are the right operand.
967 if Nkind
(Inputs
) = N_Op_Plus
then
968 Inputs
:= Right_Opnd
(Inputs
);
972 -- Process the output_list of a dependency_clause
974 Output
:= First
(Choices
(Clause
));
975 while Present
(Output
) loop
979 Self_Ref
=> Self_Ref
,
981 Seen
=> All_Outputs_Seen
,
982 Null_Seen
=> Null_Output_Seen
,
983 Non_Null_Seen
=> Non_Null_Output_Seen
);
988 -- Process the input_list of a dependency_clause
990 Analyze_Input_List
(Inputs
);
991 end Analyze_Dependency_Clause
;
993 ---------------------------
994 -- Check_Function_Return --
995 ---------------------------
997 procedure Check_Function_Return
is
999 if Ekind
(Spec_Id
) = E_Function
and then not Result_Seen
then
1001 ("result of & must appear in exactly one output list",
1004 end Check_Function_Return
;
1010 procedure Check_Role
1012 Item_Id
: Entity_Id
;
1017 (Item_Is_Input
: out Boolean;
1018 Item_Is_Output
: out Boolean);
1019 -- Find the input/output role of Item_Id. Flags Item_Is_Input and
1020 -- Item_Is_Output are set depending on the role.
1022 procedure Role_Error
1023 (Item_Is_Input
: Boolean;
1024 Item_Is_Output
: Boolean);
1025 -- Emit an error message concerning the incorrect use of Item in
1026 -- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output
1027 -- denote whether the item is an input and/or an output.
1034 (Item_Is_Input
: out Boolean;
1035 Item_Is_Output
: out Boolean)
1038 Item_Is_Input
:= False;
1039 Item_Is_Output
:= False;
1041 -- Abstract state cases
1043 if Ekind
(Item_Id
) = E_Abstract_State
then
1045 -- When pragma Global is present, the mode of the state may be
1046 -- further constrained by setting a more restrictive mode.
1049 if Appears_In
(Subp_Inputs
, Item_Id
) then
1050 Item_Is_Input
:= True;
1053 if Appears_In
(Subp_Outputs
, Item_Id
) then
1054 Item_Is_Output
:= True;
1057 -- Otherwise the state has a default IN OUT mode
1060 Item_Is_Input
:= True;
1061 Item_Is_Output
:= True;
1066 elsif Ekind
(Item_Id
) = E_In_Parameter
then
1067 Item_Is_Input
:= True;
1069 elsif Ekind
(Item_Id
) = E_In_Out_Parameter
then
1070 Item_Is_Input
:= True;
1071 Item_Is_Output
:= True;
1073 elsif Ekind
(Item_Id
) = E_Out_Parameter
then
1074 if Scope
(Item_Id
) = Spec_Id
then
1076 -- An OUT parameter of the related subprogram has mode IN
1077 -- if its type is unconstrained or tagged because array
1078 -- bounds, discriminants or tags can be read.
1080 if Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1081 Item_Is_Input
:= True;
1084 Item_Is_Output
:= True;
1086 -- An OUT parameter of an enclosing subprogram behaves as a
1087 -- read-write variable in which case the mode is IN OUT.
1090 Item_Is_Input
:= True;
1091 Item_Is_Output
:= True;
1096 else pragma Assert
(Ekind
(Item_Id
) = E_Variable
);
1098 -- When pragma Global is present, the mode of the variable may
1099 -- be further constrained by setting a more restrictive mode.
1103 -- A variable has mode IN when its type is unconstrained or
1104 -- tagged because array bounds, discriminants or tags can be
1107 if Appears_In
(Subp_Inputs
, Item_Id
)
1108 or else Is_Unconstrained_Or_Tagged_Item
(Item_Id
)
1110 Item_Is_Input
:= True;
1113 if Appears_In
(Subp_Outputs
, Item_Id
) then
1114 Item_Is_Output
:= True;
1117 -- Otherwise the variable has a default IN OUT mode
1120 Item_Is_Input
:= True;
1121 Item_Is_Output
:= True;
1130 procedure Role_Error
1131 (Item_Is_Input
: Boolean;
1132 Item_Is_Output
: Boolean)
1134 Error_Msg
: Name_Id
;
1139 -- When the item is not part of the input and the output set of
1140 -- the related subprogram, then it appears as extra in pragma
1141 -- [Refined_]Depends.
1143 if not Item_Is_Input
and then not Item_Is_Output
then
1144 Add_Item_To_Name_Buffer
(Item_Id
);
1145 Add_Str_To_Name_Buffer
1146 (" & cannot appear in dependence relation");
1148 Error_Msg
:= Name_Find
;
1149 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1151 Error_Msg_Name_1
:= Chars
(Subp_Id
);
1153 ("\& is not part of the input or output set of subprogram %",
1156 -- The mode of the item and its role in pragma [Refined_]Depends
1157 -- are in conflict. Construct a detailed message explaining the
1158 -- illegality (SPARK RM 6.1.5(5-6)).
1161 if Item_Is_Input
then
1162 Add_Str_To_Name_Buffer
("read-only");
1164 Add_Str_To_Name_Buffer
("write-only");
1167 Add_Char_To_Name_Buffer
(' ');
1168 Add_Item_To_Name_Buffer
(Item_Id
);
1169 Add_Str_To_Name_Buffer
(" & cannot appear as ");
1171 if Item_Is_Input
then
1172 Add_Str_To_Name_Buffer
("output");
1174 Add_Str_To_Name_Buffer
("input");
1177 Add_Str_To_Name_Buffer
(" in dependence relation");
1178 Error_Msg
:= Name_Find
;
1179 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1185 Item_Is_Input
: Boolean;
1186 Item_Is_Output
: Boolean;
1188 -- Start of processing for Check_Role
1191 Find_Role
(Item_Is_Input
, Item_Is_Output
);
1196 if not Item_Is_Input
then
1197 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1200 -- Self-referential item
1203 if not Item_Is_Input
or else not Item_Is_Output
then
1204 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1209 elsif not Item_Is_Output
then
1210 Role_Error
(Item_Is_Input
, Item_Is_Output
);
1218 procedure Check_Usage
1219 (Subp_Items
: Elist_Id
;
1220 Used_Items
: Elist_Id
;
1223 procedure Usage_Error
(Item
: Node_Id
; Item_Id
: Entity_Id
);
1224 -- Emit an error concerning the illegal usage of an item
1230 procedure Usage_Error
(Item
: Node_Id
; Item_Id
: Entity_Id
) is
1231 Error_Msg
: Name_Id
;
1238 -- Unconstrained and tagged items are not part of the explicit
1239 -- input set of the related subprogram, they do not have to be
1240 -- present in a dependence relation and should not be flagged
1241 -- (SPARK RM 6.1.5(8)).
1243 if not Is_Unconstrained_Or_Tagged_Item
(Item_Id
) then
1246 Add_Item_To_Name_Buffer
(Item_Id
);
1247 Add_Str_To_Name_Buffer
1248 (" & must appear in at least one input dependence list");
1250 Error_Msg
:= Name_Find
;
1251 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1254 -- Output case (SPARK RM 6.1.5(10))
1259 Add_Item_To_Name_Buffer
(Item_Id
);
1260 Add_Str_To_Name_Buffer
1261 (" & must appear in exactly one output dependence list");
1263 Error_Msg
:= Name_Find
;
1264 SPARK_Msg_NE
(Get_Name_String
(Error_Msg
), Item
, Item_Id
);
1272 Item_Id
: Entity_Id
;
1274 -- Start of processing for Check_Usage
1277 if No
(Subp_Items
) then
1281 -- Each input or output of the subprogram must appear in a dependency
1284 Elmt
:= First_Elmt
(Subp_Items
);
1285 while Present
(Elmt
) loop
1286 Item
:= Node
(Elmt
);
1288 if Nkind
(Item
) = N_Defining_Identifier
then
1291 Item_Id
:= Entity_Of
(Item
);
1294 -- The item does not appear in a dependency
1296 if Present
(Item_Id
)
1297 and then not Contains
(Used_Items
, Item_Id
)
1299 if Is_Formal
(Item_Id
) then
1300 Usage_Error
(Item
, Item_Id
);
1302 -- States and global variables are not used properly only when
1303 -- the subprogram is subject to pragma Global.
1305 elsif Global_Seen
then
1306 Usage_Error
(Item
, Item_Id
);
1314 ----------------------
1315 -- Normalize_Clause --
1316 ----------------------
1318 procedure Normalize_Clause
(Clause
: Node_Id
) is
1319 procedure Create_Or_Modify_Clause
1325 Multiple
: Boolean);
1326 -- Create a brand new clause to represent the self-reference or
1327 -- modify the input and/or output lists of an existing clause. Output
1328 -- denotes a self-referencial output. Outputs is the output list of a
1329 -- clause. Inputs is the input list of a clause. After denotes the
1330 -- clause after which the new clause is to be inserted. Flag In_Place
1331 -- should be set when normalizing the last output of an output list.
1332 -- Flag Multiple should be set when Output comes from a list with
1335 -----------------------------
1336 -- Create_Or_Modify_Clause --
1337 -----------------------------
1339 procedure Create_Or_Modify_Clause
1347 procedure Propagate_Output
1350 -- Handle the various cases of output propagation to the input
1351 -- list. Output denotes a self-referencial output item. Inputs is
1352 -- the input list of a clause.
1354 ----------------------
1355 -- Propagate_Output --
1356 ----------------------
1358 procedure Propagate_Output
1362 function In_Input_List
1364 Inputs
: List_Id
) return Boolean;
1365 -- Determine whether a particulat item appears in the input
1366 -- list of a clause.
1372 function In_Input_List
1374 Inputs
: List_Id
) return Boolean
1379 Elmt
:= First
(Inputs
);
1380 while Present
(Elmt
) loop
1381 if Entity_Of
(Elmt
) = Item
then
1393 Output_Id
: constant Entity_Id
:= Entity_Of
(Output
);
1396 -- Start of processing for Propagate_Output
1399 -- The clause is of the form:
1401 -- (Output =>+ null)
1403 -- Remove null input and replace it with a copy of the output:
1405 -- (Output => Output)
1407 if Nkind
(Inputs
) = N_Null
then
1408 Rewrite
(Inputs
, New_Copy_Tree
(Output
));
1410 -- The clause is of the form:
1412 -- (Output =>+ (Input1, ..., InputN))
1414 -- Determine whether the output is not already mentioned in the
1415 -- input list and if not, add it to the list of inputs:
1417 -- (Output => (Output, Input1, ..., InputN))
1419 elsif Nkind
(Inputs
) = N_Aggregate
then
1420 Grouped
:= Expressions
(Inputs
);
1422 if not In_Input_List
1426 Prepend_To
(Grouped
, New_Copy_Tree
(Output
));
1429 -- The clause is of the form:
1431 -- (Output =>+ Input)
1433 -- If the input does not mention the output, group the two
1436 -- (Output => (Output, Input))
1438 elsif Entity_Of
(Inputs
) /= Output_Id
then
1440 Make_Aggregate
(Loc
,
1441 Expressions
=> New_List
(
1442 New_Copy_Tree
(Output
),
1443 New_Copy_Tree
(Inputs
))));
1445 end Propagate_Output
;
1449 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
1450 New_Clause
: Node_Id
;
1452 -- Start of processing for Create_Or_Modify_Clause
1455 -- A null output depending on itself does not require any
1458 if Nkind
(Output
) = N_Null
then
1461 -- A function result cannot depend on itself because it cannot
1462 -- appear in the input list of a relation (SPARK RM 6.1.5(10)).
1464 elsif Is_Attribute_Result
(Output
) then
1465 SPARK_Msg_N
("function result cannot depend on itself", Output
);
1469 -- When performing the transformation in place, simply add the
1470 -- output to the list of inputs (if not already there). This case
1471 -- arises when dealing with the last output of an output list -
1472 -- we perform the normalization in place to avoid generating a
1476 Propagate_Output
(Output
, Inputs
);
1478 -- A list with multiple outputs is slowly trimmed until only
1479 -- one element remains. When this happens, replace aggregate
1480 -- with the element itself.
1484 Rewrite
(Outputs
, Output
);
1490 -- Unchain the output from its output list as it will appear in
1491 -- a new clause. Note that we cannot simply rewrite the output
1492 -- as null because this will violate the semantics of pragma
1497 -- Generate a new clause of the form:
1498 -- (Output => Inputs)
1501 Make_Component_Association
(Loc
,
1502 Choices
=> New_List
(Output
),
1503 Expression
=> New_Copy_Tree
(Inputs
));
1505 -- The new clause contains replicated content that has already
1506 -- been analyzed. There is not need to reanalyze it or
1507 -- renormalize it again.
1509 Set_Analyzed
(New_Clause
);
1512 (Output
=> First
(Choices
(New_Clause
)),
1513 Inputs
=> Expression
(New_Clause
));
1515 Insert_After
(After
, New_Clause
);
1517 end Create_Or_Modify_Clause
;
1521 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
1523 Last_Output
: Node_Id
;
1524 Next_Output
: Node_Id
;
1527 -- Start of processing for Normalize_Clause
1530 -- A self-dependency appears as operator "+". Remove the "+" from the
1531 -- tree by moving the real inputs to their proper place.
1533 if Nkind
(Expression
(Clause
)) = N_Op_Plus
then
1534 Rewrite
(Expression
(Clause
), Right_Opnd
(Expression
(Clause
)));
1535 Inputs
:= Expression
(Clause
);
1537 -- Multiple outputs appear as an aggregate
1539 if Nkind
(Outputs
) = N_Aggregate
then
1540 Last_Output
:= Last
(Expressions
(Outputs
));
1542 Output
:= First
(Expressions
(Outputs
));
1543 while Present
(Output
) loop
1545 -- Normalization may remove an output from its list,
1546 -- preserve the subsequent output now.
1548 Next_Output
:= Next
(Output
);
1550 Create_Or_Modify_Clause
1555 In_Place
=> Output
= Last_Output
,
1558 Output
:= Next_Output
;
1564 Create_Or_Modify_Clause
1573 end Normalize_Clause
;
1580 Last_Clause
: Node_Id
;
1581 Subp_Decl
: Node_Id
;
1583 Restore_Scope
: Boolean := False;
1584 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
1586 -- Start of processing for Analyze_Depends_In_Decl_Part
1591 Subp_Decl
:= Find_Related_Subprogram_Or_Body
(N
);
1592 Subp_Id
:= Defining_Entity
(Subp_Decl
);
1593 Deps
:= Expression
(Get_Argument
(N
, Subp_Id
));
1595 -- The logic in this routine is used to analyze both pragma Depends and
1596 -- pragma Refined_Depends since they have the same syntax and base
1597 -- semantics. Find the entity of the corresponding spec when analyzing
1600 Spec_Id
:= Corresponding_Spec_Of
(Subp_Decl
);
1602 -- Empty dependency list
1604 if Nkind
(Deps
) = N_Null
then
1606 -- Gather all states, variables and formal parameters that the
1607 -- subprogram may depend on. These items are obtained from the
1608 -- parameter profile or pragma [Refined_]Global (if available).
1610 Collect_Subprogram_Inputs_Outputs
1611 (Subp_Id
=> Subp_Id
,
1612 Subp_Inputs
=> Subp_Inputs
,
1613 Subp_Outputs
=> Subp_Outputs
,
1614 Global_Seen
=> Global_Seen
);
1616 -- Verify that every input or output of the subprogram appear in a
1619 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1620 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1621 Check_Function_Return
;
1623 -- Dependency clauses appear as component associations of an aggregate
1625 elsif Nkind
(Deps
) = N_Aggregate
then
1627 -- Do not attempt to perform analysis of a syntactically illegal
1628 -- clause as this will lead to misleading errors.
1630 if Has_Extra_Parentheses
(Deps
) then
1634 if Present
(Component_Associations
(Deps
)) then
1635 Last_Clause
:= Last
(Component_Associations
(Deps
));
1637 -- Gather all states, variables and formal parameters that the
1638 -- subprogram may depend on. These items are obtained from the
1639 -- parameter profile or pragma [Refined_]Global (if available).
1641 Collect_Subprogram_Inputs_Outputs
1642 (Subp_Id
=> Subp_Id
,
1643 Subp_Inputs
=> Subp_Inputs
,
1644 Subp_Outputs
=> Subp_Outputs
,
1645 Global_Seen
=> Global_Seen
);
1647 -- Ensure that the formal parameters are visible when analyzing
1648 -- all clauses. This falls out of the general rule of aspects
1649 -- pertaining to subprogram declarations. Skip the installation
1650 -- for subprogram bodies because the formals are already visible.
1652 if not In_Open_Scopes
(Spec_Id
) then
1653 Restore_Scope
:= True;
1654 Push_Scope
(Spec_Id
);
1656 if Is_Generic_Subprogram
(Spec_Id
) then
1657 Install_Generic_Formals
(Spec_Id
);
1659 Install_Formals
(Spec_Id
);
1663 Clause
:= First
(Component_Associations
(Deps
));
1664 while Present
(Clause
) loop
1665 Errors
:= Serious_Errors_Detected
;
1667 -- Normalization may create extra clauses that contain
1668 -- replicated input and output names. There is no need to
1671 if not Analyzed
(Clause
) then
1672 Set_Analyzed
(Clause
);
1674 Analyze_Dependency_Clause
1676 Is_Last
=> Clause
= Last_Clause
);
1679 -- Do not normalize a clause if errors were detected (count
1680 -- of Serious_Errors has increased) because the inputs and/or
1681 -- outputs may denote illegal items. Normalization is disabled
1682 -- in ASIS mode as it alters the tree by introducing new nodes
1683 -- similar to expansion.
1685 if Serious_Errors_Detected
= Errors
and then not ASIS_Mode
then
1686 Normalize_Clause
(Clause
);
1692 if Restore_Scope
then
1696 -- Verify that every input or output of the subprogram appear in a
1699 Check_Usage
(Subp_Inputs
, All_Inputs_Seen
, True);
1700 Check_Usage
(Subp_Outputs
, All_Outputs_Seen
, False);
1701 Check_Function_Return
;
1703 -- The dependency list is malformed. This is a syntax error, always
1707 Error_Msg_N
("malformed dependency relation", Deps
);
1711 -- The top level dependency relation is malformed. This is a syntax
1712 -- error, always report.
1715 Error_Msg_N
("malformed dependency relation", Deps
);
1719 -- Ensure that a state and a corresponding constituent do not appear
1720 -- together in pragma [Refined_]Depends.
1722 Check_State_And_Constituent_Use
1723 (States
=> States_Seen
,
1724 Constits
=> Constits_Seen
,
1726 end Analyze_Depends_In_Decl_Part
;
1728 --------------------------------------------
1729 -- Analyze_External_Property_In_Decl_Part --
1730 --------------------------------------------
1732 procedure Analyze_External_Property_In_Decl_Part
1734 Expr_Val
: out Boolean)
1736 Arg1
: constant Node_Id
:= First
(Pragma_Argument_Associations
(N
));
1737 Obj_Id
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
1738 Expr
: constant Node_Id
:= Get_Pragma_Arg
(Next
(Arg1
));
1741 Error_Msg_Name_1
:= Pragma_Name
(N
);
1743 -- An external property pragma must apply to an effectively volatile
1744 -- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)).
1745 -- The check is performed at the end of the declarative region due to a
1746 -- possible out-of-order arrangement of pragmas:
1749 -- pragma Async_Readers (Obj);
1750 -- pragma Volatile (Obj);
1752 if not Is_Effectively_Volatile
(Obj_Id
) then
1754 ("external property % must apply to a volatile object", N
);
1757 -- Ensure that the Boolean expression (if present) is static. A missing
1758 -- argument defaults the value to True (SPARK RM 7.1.2(5)).
1762 if Present
(Expr
) then
1763 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
1765 if Is_OK_Static_Expression
(Expr
) then
1766 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
1768 SPARK_Msg_N
("expression of % must be static", Expr
);
1771 end Analyze_External_Property_In_Decl_Part
;
1773 ---------------------------------
1774 -- Analyze_Global_In_Decl_Part --
1775 ---------------------------------
1777 procedure Analyze_Global_In_Decl_Part
(N
: Node_Id
) is
1778 Constits_Seen
: Elist_Id
:= No_Elist
;
1779 -- A list containing the entities of all constituents processed so far.
1780 -- It aids in detecting illegal usage of a state and a corresponding
1781 -- constituent in pragma [Refinde_]Global.
1783 Seen
: Elist_Id
:= No_Elist
;
1784 -- A list containing the entities of all the items processed so far. It
1785 -- plays a role in detecting distinct entities.
1787 Spec_Id
: Entity_Id
;
1788 -- The entity of the subprogram subject to pragma [Refined_]Global
1790 States_Seen
: Elist_Id
:= No_Elist
;
1791 -- A list containing the entities of all states processed so far. It
1792 -- helps in detecting illegal usage of a state and a corresponding
1793 -- constituent in pragma [Refined_]Global.
1795 Subp_Id
: Entity_Id
;
1796 -- The entity of the subprogram [body or stub] subject to pragma
1797 -- [Refined_]Global.
1799 In_Out_Seen
: Boolean := False;
1800 Input_Seen
: Boolean := False;
1801 Output_Seen
: Boolean := False;
1802 Proof_Seen
: Boolean := False;
1803 -- Flags used to verify the consistency of modes
1805 procedure Analyze_Global_List
1807 Global_Mode
: Name_Id
:= Name_Input
);
1808 -- Verify the legality of a single global list declaration. Global_Mode
1809 -- denotes the current mode in effect.
1811 -------------------------
1812 -- Analyze_Global_List --
1813 -------------------------
1815 procedure Analyze_Global_List
1817 Global_Mode
: Name_Id
:= Name_Input
)
1819 procedure Analyze_Global_Item
1821 Global_Mode
: Name_Id
);
1822 -- Verify the legality of a single global item declaration.
1823 -- Global_Mode denotes the current mode in effect.
1825 procedure Check_Duplicate_Mode
1827 Status
: in out Boolean);
1828 -- Flag Status denotes whether a particular mode has been seen while
1829 -- processing a global list. This routine verifies that Mode is not a
1830 -- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)).
1832 procedure Check_Mode_Restriction_In_Enclosing_Context
1834 Item_Id
: Entity_Id
);
1835 -- Verify that an item of mode In_Out or Output does not appear as an
1836 -- input in the Global aspect of an enclosing subprogram. If this is
1837 -- the case, emit an error. Item and Item_Id are respectively the
1838 -- item and its entity.
1840 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
);
1841 -- Mode denotes either In_Out or Output. Depending on the kind of the
1842 -- related subprogram, emit an error if those two modes apply to a
1843 -- function (SPARK RM 6.1.4(10)).
1845 -------------------------
1846 -- Analyze_Global_Item --
1847 -------------------------
1849 procedure Analyze_Global_Item
1851 Global_Mode
: Name_Id
)
1853 Item_Id
: Entity_Id
;
1856 -- Detect one of the following cases
1858 -- with Global => (null, Name)
1859 -- with Global => (Name_1, null, Name_2)
1860 -- with Global => (Name, null)
1862 if Nkind
(Item
) = N_Null
then
1863 SPARK_Msg_N
("cannot mix null and non-null global items", Item
);
1868 Resolve_State
(Item
);
1870 -- Find the entity of the item. If this is a renaming, climb the
1871 -- renaming chain to reach the root object. Renamings of non-
1872 -- entire objects do not yield an entity (Empty).
1874 Item_Id
:= Entity_Of
(Item
);
1876 if Present
(Item_Id
) then
1878 -- A global item may denote a formal parameter of an enclosing
1879 -- subprogram (SPARK RM 6.1.4(6)). Do this check first to
1880 -- provide a better error diagnostic.
1882 if Is_Formal
(Item_Id
) then
1883 if Scope
(Item_Id
) = Spec_Id
then
1885 ("global item cannot reference parameter of subprogram",
1890 -- A constant cannot act as a global item (SPARK RM 6.1.4(7)).
1891 -- Do this check first to provide a better error diagnostic.
1893 elsif Ekind
(Item_Id
) = E_Constant
then
1894 SPARK_Msg_N
("global item cannot denote a constant", Item
);
1896 -- A formal object may act as a global item inside a generic
1898 elsif Is_Formal_Object
(Item_Id
) then
1901 -- The only legal references are those to abstract states and
1902 -- variables (SPARK RM 6.1.4(4)).
1904 elsif not Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
1906 ("global item must denote variable or state", Item
);
1910 -- State related checks
1912 if Ekind
(Item_Id
) = E_Abstract_State
then
1914 -- An abstract state with visible refinement cannot appear
1915 -- in pragma [Refined_]Global as its place must be taken by
1916 -- some of its constituents (SPARK RM 6.1.4(8)).
1918 if Has_Visible_Refinement
(Item_Id
) then
1920 ("cannot mention state & in global refinement",
1922 SPARK_Msg_N
("\use its constituents instead", Item
);
1925 -- If the reference to the abstract state appears in an
1926 -- enclosing package body that will eventually refine the
1927 -- state, record the reference for future checks.
1930 Record_Possible_Body_Reference
1931 (State_Id
=> Item_Id
,
1935 -- Variable related checks. These are only relevant when
1936 -- SPARK_Mode is on as they are not standard Ada legality
1939 elsif SPARK_Mode
= On
1940 and then Is_Effectively_Volatile
(Item_Id
)
1942 -- An effectively volatile object cannot appear as a global
1943 -- item of a function (SPARK RM 7.1.3(9)).
1945 if Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
1947 ("volatile object & cannot act as global item of a "
1948 & "function", Item
, Item_Id
);
1951 -- An effectively volatile object with external property
1952 -- Effective_Reads set to True must have mode Output or
1955 elsif Effective_Reads_Enabled
(Item_Id
)
1956 and then Global_Mode
= Name_Input
1959 ("volatile object & with property Effective_Reads must "
1960 & "have mode In_Out or Output (SPARK RM 7.1.3(11))",
1966 -- When the item renames an entire object, replace the item
1967 -- with a reference to the object.
1969 if Present
(Renamed_Object
(Entity
(Item
))) then
1970 Rewrite
(Item
, New_Occurrence_Of
(Item_Id
, Sloc
(Item
)));
1974 -- Some form of illegal construct masquerading as a name
1975 -- (SPARK RM 6.1.4(4)).
1978 Error_Msg_N
("global item must denote variable or state", Item
);
1982 -- Verify that an output does not appear as an input in an
1983 -- enclosing subprogram.
1985 if Nam_In
(Global_Mode
, Name_In_Out
, Name_Output
) then
1986 Check_Mode_Restriction_In_Enclosing_Context
(Item
, Item_Id
);
1989 -- The same entity might be referenced through various way.
1990 -- Check the entity of the item rather than the item itself
1991 -- (SPARK RM 6.1.4(11)).
1993 if Contains
(Seen
, Item_Id
) then
1994 SPARK_Msg_N
("duplicate global item", Item
);
1996 -- Add the entity of the current item to the list of processed
2000 Add_Item
(Item_Id
, Seen
);
2002 if Ekind
(Item_Id
) = E_Abstract_State
then
2003 Add_Item
(Item_Id
, States_Seen
);
2006 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
)
2007 and then Present
(Encapsulating_State
(Item_Id
))
2009 Add_Item
(Item_Id
, Constits_Seen
);
2012 end Analyze_Global_Item
;
2014 --------------------------
2015 -- Check_Duplicate_Mode --
2016 --------------------------
2018 procedure Check_Duplicate_Mode
2020 Status
: in out Boolean)
2024 SPARK_Msg_N
("duplicate global mode", Mode
);
2028 end Check_Duplicate_Mode
;
2030 -------------------------------------------------
2031 -- Check_Mode_Restriction_In_Enclosing_Context --
2032 -------------------------------------------------
2034 procedure Check_Mode_Restriction_In_Enclosing_Context
2036 Item_Id
: Entity_Id
)
2038 Context
: Entity_Id
;
2040 Inputs
: Elist_Id
:= No_Elist
;
2041 Outputs
: Elist_Id
:= No_Elist
;
2044 -- Traverse the scope stack looking for enclosing subprograms
2045 -- subject to pragma [Refined_]Global.
2047 Context
:= Scope
(Subp_Id
);
2048 while Present
(Context
) and then Context
/= Standard_Standard
loop
2049 if Is_Subprogram
(Context
)
2051 (Present
(Get_Pragma
(Context
, Pragma_Global
))
2053 Present
(Get_Pragma
(Context
, Pragma_Refined_Global
)))
2055 Collect_Subprogram_Inputs_Outputs
2056 (Subp_Id
=> Context
,
2057 Subp_Inputs
=> Inputs
,
2058 Subp_Outputs
=> Outputs
,
2059 Global_Seen
=> Dummy
);
2061 -- The item is classified as In_Out or Output but appears as
2062 -- an Input in an enclosing subprogram (SPARK RM 6.1.4(12)).
2064 if Appears_In
(Inputs
, Item_Id
)
2065 and then not Appears_In
(Outputs
, Item_Id
)
2068 ("global item & cannot have mode In_Out or Output",
2071 ("\item already appears as input of subprogram &",
2074 -- Stop the traversal once an error has been detected
2080 Context
:= Scope
(Context
);
2082 end Check_Mode_Restriction_In_Enclosing_Context
;
2084 ----------------------------------------
2085 -- Check_Mode_Restriction_In_Function --
2086 ----------------------------------------
2088 procedure Check_Mode_Restriction_In_Function
(Mode
: Node_Id
) is
2090 if Ekind
(Spec_Id
) = E_Function
then
2092 ("global mode & is not applicable to functions", Mode
);
2094 end Check_Mode_Restriction_In_Function
;
2102 -- Start of processing for Analyze_Global_List
2105 if Nkind
(List
) = N_Null
then
2106 Set_Analyzed
(List
);
2108 -- Single global item declaration
2110 elsif Nkind_In
(List
, N_Expanded_Name
,
2112 N_Selected_Component
)
2114 Analyze_Global_Item
(List
, Global_Mode
);
2116 -- Simple global list or moded global list declaration
2118 elsif Nkind
(List
) = N_Aggregate
then
2119 Set_Analyzed
(List
);
2121 -- The declaration of a simple global list appear as a collection
2124 if Present
(Expressions
(List
)) then
2125 if Present
(Component_Associations
(List
)) then
2127 ("cannot mix moded and non-moded global lists", List
);
2130 Item
:= First
(Expressions
(List
));
2131 while Present
(Item
) loop
2132 Analyze_Global_Item
(Item
, Global_Mode
);
2137 -- The declaration of a moded global list appears as a collection
2138 -- of component associations where individual choices denote
2141 elsif Present
(Component_Associations
(List
)) then
2142 if Present
(Expressions
(List
)) then
2144 ("cannot mix moded and non-moded global lists", List
);
2147 Assoc
:= First
(Component_Associations
(List
));
2148 while Present
(Assoc
) loop
2149 Mode
:= First
(Choices
(Assoc
));
2151 if Nkind
(Mode
) = N_Identifier
then
2152 if Chars
(Mode
) = Name_In_Out
then
2153 Check_Duplicate_Mode
(Mode
, In_Out_Seen
);
2154 Check_Mode_Restriction_In_Function
(Mode
);
2156 elsif Chars
(Mode
) = Name_Input
then
2157 Check_Duplicate_Mode
(Mode
, Input_Seen
);
2159 elsif Chars
(Mode
) = Name_Output
then
2160 Check_Duplicate_Mode
(Mode
, Output_Seen
);
2161 Check_Mode_Restriction_In_Function
(Mode
);
2163 elsif Chars
(Mode
) = Name_Proof_In
then
2164 Check_Duplicate_Mode
(Mode
, Proof_Seen
);
2167 SPARK_Msg_N
("invalid mode selector", Mode
);
2171 SPARK_Msg_N
("invalid mode selector", Mode
);
2174 -- Items in a moded list appear as a collection of
2175 -- expressions. Reuse the existing machinery to analyze
2179 (List
=> Expression
(Assoc
),
2180 Global_Mode
=> Chars
(Mode
));
2188 raise Program_Error
;
2191 -- Any other attempt to declare a global item is illegal. This is a
2192 -- syntax error, always report.
2195 Error_Msg_N
("malformed global list", List
);
2197 end Analyze_Global_List
;
2202 Subp_Decl
: Node_Id
;
2204 Restore_Scope
: Boolean := False;
2205 -- Set True if we do a Push_Scope requiring a Pop_Scope on exit
2207 -- Start of processing for Analyze_Global_In_Decl_Part
2212 Subp_Decl
:= Find_Related_Subprogram_Or_Body
(N
);
2213 Subp_Id
:= Defining_Entity
(Subp_Decl
);
2214 Items
:= Expression
(Get_Argument
(N
, Subp_Id
));
2216 -- The logic in this routine is used to analyze both pragma Global and
2217 -- pragma Refined_Global since they have the same syntax and base
2218 -- semantics. Find the entity of the corresponding spec when analyzing
2221 Spec_Id
:= Corresponding_Spec_Of
(Subp_Decl
);
2223 -- There is nothing to be done for a null global list
2225 if Nkind
(Items
) = N_Null
then
2226 Set_Analyzed
(Items
);
2228 -- Analyze the various forms of global lists and items. Note that some
2229 -- of these may be malformed in which case the analysis emits error
2233 -- Ensure that the formal parameters are visible when processing an
2234 -- item. This falls out of the general rule of aspects pertaining to
2235 -- subprogram declarations.
2237 if not In_Open_Scopes
(Spec_Id
) then
2238 Restore_Scope
:= True;
2239 Push_Scope
(Spec_Id
);
2241 if Is_Generic_Subprogram
(Spec_Id
) then
2242 Install_Generic_Formals
(Spec_Id
);
2244 Install_Formals
(Spec_Id
);
2248 Analyze_Global_List
(Items
);
2250 if Restore_Scope
then
2255 -- Ensure that a state and a corresponding constituent do not appear
2256 -- together in pragma [Refined_]Global.
2258 Check_State_And_Constituent_Use
2259 (States
=> States_Seen
,
2260 Constits
=> Constits_Seen
,
2262 end Analyze_Global_In_Decl_Part
;
2264 --------------------------------------------
2265 -- Analyze_Initial_Condition_In_Decl_Part --
2266 --------------------------------------------
2268 procedure Analyze_Initial_Condition_In_Decl_Part
(N
: Node_Id
) is
2269 Expr
: constant Node_Id
:= Expression
(Get_Argument
(N
));
2274 -- The expression is preanalyzed because it has not been moved to its
2275 -- final place yet. A direct analysis may generate side effects and this
2276 -- is not desired at this point.
2278 Preanalyze_Assert_Expression
(Expr
, Standard_Boolean
);
2279 end Analyze_Initial_Condition_In_Decl_Part
;
2281 --------------------------------------
2282 -- Analyze_Initializes_In_Decl_Part --
2283 --------------------------------------
2285 procedure Analyze_Initializes_In_Decl_Part
(N
: Node_Id
) is
2286 Pack_Spec
: constant Node_Id
:= Parent
(N
);
2287 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Parent
(Pack_Spec
));
2289 Constits_Seen
: Elist_Id
:= No_Elist
;
2290 -- A list containing the entities of all constituents processed so far.
2291 -- It aids in detecting illegal usage of a state and a corresponding
2292 -- constituent in pragma Initializes.
2294 Items_Seen
: Elist_Id
:= No_Elist
;
2295 -- A list of all initialization items processed so far. This list is
2296 -- used to detect duplicate items.
2298 Non_Null_Seen
: Boolean := False;
2299 Null_Seen
: Boolean := False;
2300 -- Flags used to check the legality of a null initialization list
2302 States_And_Vars
: Elist_Id
:= No_Elist
;
2303 -- A list of all abstract states and variables declared in the visible
2304 -- declarations of the related package. This list is used to detect the
2305 -- legality of initialization items.
2307 States_Seen
: Elist_Id
:= No_Elist
;
2308 -- A list containing the entities of all states processed so far. It
2309 -- helps in detecting illegal usage of a state and a corresponding
2310 -- constituent in pragma Initializes.
2312 procedure Analyze_Initialization_Item
(Item
: Node_Id
);
2313 -- Verify the legality of a single initialization item
2315 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
);
2316 -- Verify the legality of a single initialization item followed by a
2317 -- list of input items.
2319 procedure Collect_States_And_Variables
;
2320 -- Inspect the visible declarations of the related package and gather
2321 -- the entities of all abstract states and variables in States_And_Vars.
2323 ---------------------------------
2324 -- Analyze_Initialization_Item --
2325 ---------------------------------
2327 procedure Analyze_Initialization_Item
(Item
: Node_Id
) is
2328 Item_Id
: Entity_Id
;
2331 -- Null initialization list
2333 if Nkind
(Item
) = N_Null
then
2335 SPARK_Msg_N
("multiple null initializations not allowed", Item
);
2337 elsif Non_Null_Seen
then
2339 ("cannot mix null and non-null initialization items", Item
);
2344 -- Initialization item
2347 Non_Null_Seen
:= True;
2351 ("cannot mix null and non-null initialization items", Item
);
2355 Resolve_State
(Item
);
2357 if Is_Entity_Name
(Item
) then
2358 Item_Id
:= Entity_Of
(Item
);
2360 if Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
2362 -- The state or variable must be declared in the visible
2363 -- declarations of the package (SPARK RM 7.1.5(7)).
2365 if not Contains
(States_And_Vars
, Item_Id
) then
2366 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2368 ("initialization item & must appear in the visible "
2369 & "declarations of package %", Item
, Item_Id
);
2371 -- Detect a duplicate use of the same initialization item
2372 -- (SPARK RM 7.1.5(5)).
2374 elsif Contains
(Items_Seen
, Item_Id
) then
2375 SPARK_Msg_N
("duplicate initialization item", Item
);
2377 -- The item is legal, add it to the list of processed states
2381 Add_Item
(Item_Id
, Items_Seen
);
2383 if Ekind
(Item_Id
) = E_Abstract_State
then
2384 Add_Item
(Item_Id
, States_Seen
);
2387 if Present
(Encapsulating_State
(Item_Id
)) then
2388 Add_Item
(Item_Id
, Constits_Seen
);
2392 -- The item references something that is not a state or a
2393 -- variable (SPARK RM 7.1.5(3)).
2397 ("initialization item must denote variable or state",
2401 -- Some form of illegal construct masquerading as a name
2402 -- (SPARK RM 7.1.5(3)). This is a syntax error, always report.
2406 ("initialization item must denote variable or state", Item
);
2409 end Analyze_Initialization_Item
;
2411 ---------------------------------------------
2412 -- Analyze_Initialization_Item_With_Inputs --
2413 ---------------------------------------------
2415 procedure Analyze_Initialization_Item_With_Inputs
(Item
: Node_Id
) is
2416 Inputs_Seen
: Elist_Id
:= No_Elist
;
2417 -- A list of all inputs processed so far. This list is used to detect
2418 -- duplicate uses of an input.
2420 Non_Null_Seen
: Boolean := False;
2421 Null_Seen
: Boolean := False;
2422 -- Flags used to check the legality of an input list
2424 procedure Analyze_Input_Item
(Input
: Node_Id
);
2425 -- Verify the legality of a single input item
2427 ------------------------
2428 -- Analyze_Input_Item --
2429 ------------------------
2431 procedure Analyze_Input_Item
(Input
: Node_Id
) is
2432 Input_Id
: Entity_Id
;
2437 if Nkind
(Input
) = N_Null
then
2440 ("multiple null initializations not allowed", Item
);
2442 elsif Non_Null_Seen
then
2444 ("cannot mix null and non-null initialization item", Item
);
2452 Non_Null_Seen
:= True;
2456 ("cannot mix null and non-null initialization item", Item
);
2460 Resolve_State
(Input
);
2462 if Is_Entity_Name
(Input
) then
2463 Input_Id
:= Entity_Of
(Input
);
2465 if Ekind_In
(Input_Id
, E_Abstract_State
,
2471 -- The input cannot denote states or variables declared
2472 -- within the related package.
2474 if Within_Scope
(Input_Id
, Current_Scope
) then
2475 Error_Msg_Name_1
:= Chars
(Pack_Id
);
2477 ("input item & cannot denote a visible variable or "
2478 & "state of package % (SPARK RM 7.1.5(4))",
2481 -- Detect a duplicate use of the same input item
2482 -- (SPARK RM 7.1.5(5)).
2484 elsif Contains
(Inputs_Seen
, Input_Id
) then
2485 SPARK_Msg_N
("duplicate input item", Input
);
2487 -- Input is legal, add it to the list of processed inputs
2490 Add_Item
(Input_Id
, Inputs_Seen
);
2492 if Ekind
(Input_Id
) = E_Abstract_State
then
2493 Add_Item
(Input_Id
, States_Seen
);
2496 if Ekind_In
(Input_Id
, E_Abstract_State
, E_Variable
)
2497 and then Present
(Encapsulating_State
(Input_Id
))
2499 Add_Item
(Input_Id
, Constits_Seen
);
2503 -- The input references something that is not a state or a
2504 -- variable (SPARK RM 7.1.5(3)).
2508 ("input item must denote variable or state", Input
);
2511 -- Some form of illegal construct masquerading as a name
2512 -- (SPARK RM 7.1.5(3)).
2516 ("input item must denote variable or state", Input
);
2519 end Analyze_Input_Item
;
2523 Inputs
: constant Node_Id
:= Expression
(Item
);
2527 Name_Seen
: Boolean := False;
2528 -- A flag used to detect multiple item names
2530 -- Start of processing for Analyze_Initialization_Item_With_Inputs
2533 -- Inspect the name of an item with inputs
2535 Elmt
:= First
(Choices
(Item
));
2536 while Present
(Elmt
) loop
2538 SPARK_Msg_N
("only one item allowed in initialization", Elmt
);
2541 Analyze_Initialization_Item
(Elmt
);
2547 -- Multiple input items appear as an aggregate
2549 if Nkind
(Inputs
) = N_Aggregate
then
2550 if Present
(Expressions
(Inputs
)) then
2551 Input
:= First
(Expressions
(Inputs
));
2552 while Present
(Input
) loop
2553 Analyze_Input_Item
(Input
);
2558 if Present
(Component_Associations
(Inputs
)) then
2560 ("inputs must appear in named association form", Inputs
);
2563 -- Single input item
2566 Analyze_Input_Item
(Inputs
);
2568 end Analyze_Initialization_Item_With_Inputs
;
2570 ----------------------------------
2571 -- Collect_States_And_Variables --
2572 ----------------------------------
2574 procedure Collect_States_And_Variables
is
2578 -- Collect the abstract states defined in the package (if any)
2580 if Present
(Abstract_States
(Pack_Id
)) then
2581 States_And_Vars
:= New_Copy_Elist
(Abstract_States
(Pack_Id
));
2584 -- Collect all variables the appear in the visible declarations of
2585 -- the related package.
2587 if Present
(Visible_Declarations
(Pack_Spec
)) then
2588 Decl
:= First
(Visible_Declarations
(Pack_Spec
));
2589 while Present
(Decl
) loop
2590 if Nkind
(Decl
) = N_Object_Declaration
2591 and then Ekind
(Defining_Entity
(Decl
)) = E_Variable
2592 and then Comes_From_Source
(Decl
)
2594 Add_Item
(Defining_Entity
(Decl
), States_And_Vars
);
2600 end Collect_States_And_Variables
;
2604 Inits
: constant Node_Id
:= Expression
(Get_Argument
(N
));
2607 -- Start of processing for Analyze_Initializes_In_Decl_Part
2612 -- Nothing to do when the initialization list is empty
2614 if Nkind
(Inits
) = N_Null
then
2618 -- Single and multiple initialization clauses appear as an aggregate. If
2619 -- this is not the case, then either the parser or the analysis of the
2620 -- pragma failed to produce an aggregate.
2622 pragma Assert
(Nkind
(Inits
) = N_Aggregate
);
2624 -- Initialize the various lists used during analysis
2626 Collect_States_And_Variables
;
2628 if Present
(Expressions
(Inits
)) then
2629 Init
:= First
(Expressions
(Inits
));
2630 while Present
(Init
) loop
2631 Analyze_Initialization_Item
(Init
);
2636 if Present
(Component_Associations
(Inits
)) then
2637 Init
:= First
(Component_Associations
(Inits
));
2638 while Present
(Init
) loop
2639 Analyze_Initialization_Item_With_Inputs
(Init
);
2644 -- Ensure that a state and a corresponding constituent do not appear
2645 -- together in pragma Initializes.
2647 Check_State_And_Constituent_Use
2648 (States
=> States_Seen
,
2649 Constits
=> Constits_Seen
,
2651 end Analyze_Initializes_In_Decl_Part
;
2653 --------------------
2654 -- Analyze_Pragma --
2655 --------------------
2657 procedure Analyze_Pragma
(N
: Node_Id
) is
2658 Loc
: constant Source_Ptr
:= Sloc
(N
);
2659 Prag_Id
: Pragma_Id
;
2662 -- Name of the source pragma, or name of the corresponding aspect for
2663 -- pragmas which originate in a source aspect. In the latter case, the
2664 -- name may be different from the pragma name.
2666 Pragma_Exit
: exception;
2667 -- This exception is used to exit pragma processing completely. It
2668 -- is used when an error is detected, and no further processing is
2669 -- required. It is also used if an earlier error has left the tree in
2670 -- a state where the pragma should not be processed.
2673 -- Number of pragma argument associations
2679 -- First four pragma arguments (pragma argument association nodes, or
2680 -- Empty if the corresponding argument does not exist).
2682 type Name_List
is array (Natural range <>) of Name_Id
;
2683 type Args_List
is array (Natural range <>) of Node_Id
;
2684 -- Types used for arguments to Check_Arg_Order and Gather_Associations
2686 -----------------------
2687 -- Local Subprograms --
2688 -----------------------
2690 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
);
2691 -- Used by pragma Warnings (Off, string), and Warn_As_Error (string) to
2692 -- get the given string argument, and place it in Name_Buffer, adding
2693 -- leading and trailing asterisks if they are not already present. The
2694 -- caller has already checked that Arg is a static string expression.
2696 procedure Ada_2005_Pragma
;
2697 -- Called for pragmas defined in Ada 2005, that are not in Ada 95. In
2698 -- Ada 95 mode, these are implementation defined pragmas, so should be
2699 -- caught by the No_Implementation_Pragmas restriction.
2701 procedure Ada_2012_Pragma
;
2702 -- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05.
2703 -- In Ada 95 or 05 mode, these are implementation defined pragmas, so
2704 -- should be caught by the No_Implementation_Pragmas restriction.
2706 procedure Analyze_Part_Of
2707 (Item_Id
: Entity_Id
;
2710 Legal
: out Boolean);
2711 -- Subsidiary to the analysis of pragmas Abstract_State and Part_Of.
2712 -- Perform full analysis of indicator Part_Of. Item_Id is the entity of
2713 -- an abstract state, variable or package instantiation. State is the
2714 -- encapsulating state. Indic is the Part_Of indicator. Flag Legal is
2715 -- set when the indicator is legal.
2717 procedure Analyze_Pre_Post_Condition
;
2718 -- Subsidiary to the analysis of pragmas Precondition and Postcondition
2720 procedure Analyze_Refined_Pragma
2721 (Spec_Id
: out Entity_Id
;
2722 Body_Id
: out Entity_Id
;
2723 Legal
: out Boolean);
2724 -- Subsidiary routine to the analysis of body pragmas Refined_Depends,
2725 -- Refined_Global and Refined_Post. Check the placement and related
2726 -- context of the pragma. Spec_Id is the entity of the related
2727 -- subprogram. Body_Id is the entity of the subprogram body. Flag
2728 -- Legal is set when the pragma is properly placed.
2730 procedure Check_Ada_83_Warning
;
2731 -- Issues a warning message for the current pragma if operating in Ada
2732 -- 83 mode (used for language pragmas that are not a standard part of
2733 -- Ada 83). This procedure does not raise Pragma_Exit. Also notes use
2736 procedure Check_Arg_Count
(Required
: Nat
);
2737 -- Check argument count for pragma is equal to given parameter. If not,
2738 -- then issue an error message and raise Pragma_Exit.
2740 -- Note: all routines whose name is Check_Arg_Is_xxx take an argument
2741 -- Arg which can either be a pragma argument association, in which case
2742 -- the check is applied to the expression of the association or an
2743 -- expression directly.
2745 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
);
2746 -- Check that an argument has the right form for an EXTERNAL_NAME
2747 -- parameter of an extended import/export pragma. The rule is that the
2748 -- name must be an identifier or string literal (in Ada 83 mode) or a
2749 -- static string expression (in Ada 95 mode).
2751 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
);
2752 -- Check the specified argument Arg to make sure that it is an
2753 -- identifier. If not give error and raise Pragma_Exit.
2755 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
);
2756 -- Check the specified argument Arg to make sure that it is an integer
2757 -- literal. If not give error and raise Pragma_Exit.
2759 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
);
2760 -- Check the specified argument Arg to make sure that it has the proper
2761 -- syntactic form for a local name and meets the semantic requirements
2762 -- for a local name. The local name is analyzed as part of the
2763 -- processing for this call. In addition, the local name is required
2764 -- to represent an entity at the library level.
2766 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
);
2767 -- Check the specified argument Arg to make sure that it has the proper
2768 -- syntactic form for a local name and meets the semantic requirements
2769 -- for a local name. The local name is analyzed as part of the
2770 -- processing for this call.
2772 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
);
2773 -- Check the specified argument Arg to make sure that it is a valid
2774 -- locking policy name. If not give error and raise Pragma_Exit.
2776 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
);
2777 -- Check the specified argument Arg to make sure that it is a valid
2778 -- elaboration policy name. If not give error and raise Pragma_Exit.
2780 procedure Check_Arg_Is_One_Of
2783 procedure Check_Arg_Is_One_Of
2785 N1
, N2
, N3
: Name_Id
);
2786 procedure Check_Arg_Is_One_Of
2788 N1
, N2
, N3
, N4
: Name_Id
);
2789 procedure Check_Arg_Is_One_Of
2791 N1
, N2
, N3
, N4
, N5
: Name_Id
);
2792 -- Check the specified argument Arg to make sure that it is an
2793 -- identifier whose name matches either N1 or N2 (or N3, N4, N5 if
2794 -- present). If not then give error and raise Pragma_Exit.
2796 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
);
2797 -- Check the specified argument Arg to make sure that it is a valid
2798 -- queuing policy name. If not give error and raise Pragma_Exit.
2800 procedure Check_Arg_Is_OK_Static_Expression
2802 Typ
: Entity_Id
:= Empty
);
2803 -- Check the specified argument Arg to make sure that it is a static
2804 -- expression of the given type (i.e. it will be analyzed and resolved
2805 -- using this type, which can be any valid argument to Resolve, e.g.
2806 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2807 -- Typ is left Empty, then any static expression is allowed. Includes
2808 -- checking that the argument does not raise Constraint_Error.
2810 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
);
2811 -- Check the specified argument Arg to make sure that it is a valid task
2812 -- dispatching policy name. If not give error and raise Pragma_Exit.
2814 procedure Check_Arg_Order
(Names
: Name_List
);
2815 -- Checks for an instance of two arguments with identifiers for the
2816 -- current pragma which are not in the sequence indicated by Names,
2817 -- and if so, generates a fatal message about bad order of arguments.
2819 procedure Check_At_Least_N_Arguments
(N
: Nat
);
2820 -- Check there are at least N arguments present
2822 procedure Check_At_Most_N_Arguments
(N
: Nat
);
2823 -- Check there are no more than N arguments present
2825 procedure Check_Component
2828 In_Variant_Part
: Boolean := False);
2829 -- Examine an Unchecked_Union component for correct use of per-object
2830 -- constrained subtypes, and for restrictions on finalizable components.
2831 -- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part
2832 -- should be set when Comp comes from a record variant.
2834 procedure Check_Declaration_Order
(First
: Node_Id
; Second
: Node_Id
);
2835 -- Subsidiary routine to the analysis of pragmas Abstract_State,
2836 -- Initial_Condition and Initializes. Determine whether pragma First
2837 -- appears before pragma Second. If this is not the case, emit an error.
2839 procedure Check_Duplicate_Pragma
(E
: Entity_Id
);
2840 -- Check if a rep item of the same name as the current pragma is already
2841 -- chained as a rep pragma to the given entity. If so give a message
2842 -- about the duplicate, and then raise Pragma_Exit so does not return.
2843 -- Note that if E is a type, then this routine avoids flagging a pragma
2844 -- which applies to a parent type from which E is derived.
2846 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
);
2847 -- Nam is an N_String_Literal node containing the external name set by
2848 -- an Import or Export pragma (or extended Import or Export pragma).
2849 -- This procedure checks for possible duplications if this is the export
2850 -- case, and if found, issues an appropriate error message.
2852 procedure Check_Expr_Is_OK_Static_Expression
2854 Typ
: Entity_Id
:= Empty
);
2855 -- Check the specified expression Expr to make sure that it is a static
2856 -- expression of the given type (i.e. it will be analyzed and resolved
2857 -- using this type, which can be any valid argument to Resolve, e.g.
2858 -- Any_Integer is OK). If not, given error and raise Pragma_Exit. If
2859 -- Typ is left Empty, then any static expression is allowed. Includes
2860 -- checking that the expression does not raise Constraint_Error.
2862 procedure Check_First_Subtype
(Arg
: Node_Id
);
2863 -- Checks that Arg, whose expression is an entity name, references a
2866 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
2867 -- Checks that the given argument has an identifier, and if so, requires
2868 -- it to match the given identifier name. If there is no identifier, or
2869 -- a non-matching identifier, then an error message is given and
2870 -- Pragma_Exit is raised.
2872 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
);
2873 -- Checks that the given argument has an identifier, and if so, requires
2874 -- it to match one of the given identifier names. If there is no
2875 -- identifier, or a non-matching identifier, then an error message is
2876 -- given and Pragma_Exit is raised.
2878 procedure Check_In_Main_Program
;
2879 -- Common checks for pragmas that appear within a main program
2880 -- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU).
2882 procedure Check_Interrupt_Or_Attach_Handler
;
2883 -- Common processing for first argument of pragma Interrupt_Handler or
2884 -- pragma Attach_Handler.
2886 procedure Check_Loop_Pragma_Placement
;
2887 -- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant
2888 -- appear immediately within a construct restricted to loops, and that
2889 -- pragmas Loop_Invariant and Loop_Variant are grouped together.
2891 procedure Check_Is_In_Decl_Part_Or_Package_Spec
;
2892 -- Check that pragma appears in a declarative part, or in a package
2893 -- specification, i.e. that it does not occur in a statement sequence
2896 procedure Check_No_Identifier
(Arg
: Node_Id
);
2897 -- Checks that the given argument does not have an identifier. If
2898 -- an identifier is present, then an error message is issued, and
2899 -- Pragma_Exit is raised.
2901 procedure Check_No_Identifiers
;
2902 -- Checks that none of the arguments to the pragma has an identifier.
2903 -- If any argument has an identifier, then an error message is issued,
2904 -- and Pragma_Exit is raised.
2906 procedure Check_No_Link_Name
;
2907 -- Checks that no link name is specified
2909 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
);
2910 -- Checks if the given argument has an identifier, and if so, requires
2911 -- it to match the given identifier name. If there is a non-matching
2912 -- identifier, then an error message is given and Pragma_Exit is raised.
2914 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String);
2915 -- Checks if the given argument has an identifier, and if so, requires
2916 -- it to match the given identifier name. If there is a non-matching
2917 -- identifier, then an error message is given and Pragma_Exit is raised.
2918 -- In this version of the procedure, the identifier name is given as
2919 -- a string with lower case letters.
2921 procedure Check_Static_Constraint
(Constr
: Node_Id
);
2922 -- Constr is a constraint from an N_Subtype_Indication node from a
2923 -- component constraint in an Unchecked_Union type. This routine checks
2924 -- that the constraint is static as required by the restrictions for
2927 procedure Check_Valid_Configuration_Pragma
;
2928 -- Legality checks for placement of a configuration pragma
2930 procedure Check_Valid_Library_Unit_Pragma
;
2931 -- Legality checks for library unit pragmas. A special case arises for
2932 -- pragmas in generic instances that come from copies of the original
2933 -- library unit pragmas in the generic templates. In the case of other
2934 -- than library level instantiations these can appear in contexts which
2935 -- would normally be invalid (they only apply to the original template
2936 -- and to library level instantiations), and they are simply ignored,
2937 -- which is implemented by rewriting them as null statements.
2939 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
);
2940 -- Check an Unchecked_Union variant for lack of nested variants and
2941 -- presence of at least one component. UU_Typ is the related Unchecked_
2944 procedure Create_Generic_Template
2946 Subp_Id
: Entity_Id
);
2947 -- Subsidiary routine to the processing of pragmas Contract_Cases,
2948 -- Depends, Global, Postcondition, Precondition and Test_Case. Create
2949 -- a generic template for pragma Prag when Prag is a source construct
2950 -- and the related context denoted by Subp_Id is a generic subprogram.
2952 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
);
2953 -- Subsidiary routine to the processing of pragmas Abstract_State,
2954 -- Contract_Cases, Depends, Global, Initializes, Refined_Depends,
2955 -- Refined_Global and Refined_State. Transform argument Arg into
2956 -- an aggregate if not one already. N_Null is never transformed.
2957 -- Arg may denote an aspect specification or a pragma argument
2960 procedure Error_Pragma
(Msg
: String);
2961 pragma No_Return
(Error_Pragma
);
2962 -- Outputs error message for current pragma. The message contains a %
2963 -- that will be replaced with the pragma name, and the flag is placed
2964 -- on the pragma itself. Pragma_Exit is then raised. Note: this routine
2965 -- calls Fix_Error (see spec of that procedure for details).
2967 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
);
2968 pragma No_Return
(Error_Pragma_Arg
);
2969 -- Outputs error message for current pragma. The message may contain
2970 -- a % that will be replaced with the pragma name. The parameter Arg
2971 -- may either be a pragma argument association, in which case the flag
2972 -- is placed on the expression of this association, or an expression,
2973 -- in which case the flag is placed directly on the expression. The
2974 -- message is placed using Error_Msg_N, so the message may also contain
2975 -- an & insertion character which will reference the given Arg value.
2976 -- After placing the message, Pragma_Exit is raised. Note: this routine
2977 -- calls Fix_Error (see spec of that procedure for details).
2979 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
);
2980 pragma No_Return
(Error_Pragma_Arg
);
2981 -- Similar to above form of Error_Pragma_Arg except that two messages
2982 -- are provided, the second is a continuation comment starting with \.
2984 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
);
2985 pragma No_Return
(Error_Pragma_Arg_Ident
);
2986 -- Outputs error message for current pragma. The message may contain a %
2987 -- that will be replaced with the pragma name. The parameter Arg must be
2988 -- a pragma argument association with a non-empty identifier (i.e. its
2989 -- Chars field must be set), and the error message is placed on the
2990 -- identifier. The message is placed using Error_Msg_N so the message
2991 -- may also contain an & insertion character which will reference
2992 -- the identifier. After placing the message, Pragma_Exit is raised.
2993 -- Note: this routine calls Fix_Error (see spec of that procedure for
2996 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
);
2997 pragma No_Return
(Error_Pragma_Ref
);
2998 -- Outputs error message for current pragma. The message may contain
2999 -- a % that will be replaced with the pragma name. The parameter Ref
3000 -- must be an entity whose name can be referenced by & and sloc by #.
3001 -- After placing the message, Pragma_Exit is raised. Note: this routine
3002 -- calls Fix_Error (see spec of that procedure for details).
3004 function Find_Lib_Unit_Name
return Entity_Id
;
3005 -- Used for a library unit pragma to find the entity to which the
3006 -- library unit pragma applies, returns the entity found.
3008 procedure Find_Program_Unit_Name
(Id
: Node_Id
);
3009 -- If the pragma is a compilation unit pragma, the id must denote the
3010 -- compilation unit in the same compilation, and the pragma must appear
3011 -- in the list of preceding or trailing pragmas. If it is a program
3012 -- unit pragma that is not a compilation unit pragma, then the
3013 -- identifier must be visible.
3015 function Find_Unique_Parameterless_Procedure
3017 Arg
: Node_Id
) return Entity_Id
;
3018 -- Used for a procedure pragma to find the unique parameterless
3019 -- procedure identified by Name, returns it if it exists, otherwise
3020 -- errors out and uses Arg as the pragma argument for the message.
3022 function Fix_Error
(Msg
: String) return String;
3023 -- This is called prior to issuing an error message. Msg is the normal
3024 -- error message issued in the pragma case. This routine checks for the
3025 -- case of a pragma coming from an aspect in the source, and returns a
3026 -- message suitable for the aspect case as follows:
3028 -- Each substring "pragma" is replaced by "aspect"
3030 -- If "argument of" is at the start of the error message text, it is
3031 -- replaced by "entity for".
3033 -- If "argument" is at the start of the error message text, it is
3034 -- replaced by "entity".
3036 -- So for example, "argument of pragma X must be discrete type"
3037 -- returns "entity for aspect X must be a discrete type".
3039 -- Finally Error_Msg_Name_1 is set to the name of the aspect (which may
3040 -- be different from the pragma name). If the current pragma results
3041 -- from rewriting another pragma, then Error_Msg_Name_1 is set to the
3042 -- original pragma name.
3044 procedure Gather_Associations
3046 Args
: out Args_List
);
3047 -- This procedure is used to gather the arguments for a pragma that
3048 -- permits arbitrary ordering of parameters using the normal rules
3049 -- for named and positional parameters. The Names argument is a list
3050 -- of Name_Id values that corresponds to the allowed pragma argument
3051 -- association identifiers in order. The result returned in Args is
3052 -- a list of corresponding expressions that are the pragma arguments.
3053 -- Note that this is a list of expressions, not of pragma argument
3054 -- associations (Gather_Associations has completely checked all the
3055 -- optional identifiers when it returns). An entry in Args is Empty
3056 -- on return if the corresponding argument is not present.
3058 procedure GNAT_Pragma
;
3059 -- Called for all GNAT defined pragmas to check the relevant restriction
3060 -- (No_Implementation_Pragmas).
3062 function Is_Before_First_Decl
3063 (Pragma_Node
: Node_Id
;
3064 Decls
: List_Id
) return Boolean;
3065 -- Return True if Pragma_Node is before the first declarative item in
3066 -- Decls where Decls is the list of declarative items.
3068 function Is_Configuration_Pragma
return Boolean;
3069 -- Determines if the placement of the current pragma is appropriate
3070 -- for a configuration pragma.
3072 function Is_In_Context_Clause
return Boolean;
3073 -- Returns True if pragma appears within the context clause of a unit,
3074 -- and False for any other placement (does not generate any messages).
3076 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean;
3077 -- Analyzes the argument, and determines if it is a static string
3078 -- expression, returns True if so, False if non-static or not String.
3079 -- A special case is that a string literal returns True in Ada 83 mode
3080 -- (which has no such thing as static string expressions). Note that
3081 -- the call analyzes its argument, so this cannot be used for the case
3082 -- where an identifier might not be declared.
3084 procedure Pragma_Misplaced
;
3085 pragma No_Return
(Pragma_Misplaced
);
3086 -- Issue fatal error message for misplaced pragma
3088 procedure Process_Atomic_Independent_Shared_Volatile
;
3089 -- Common processing for pragmas Atomic, Independent, Shared, Volatile.
3090 -- Note that Shared is an obsolete Ada 83 pragma and treated as being
3091 -- identical in effect to pragma Atomic.
3093 procedure Process_Compile_Time_Warning_Or_Error
;
3094 -- Common processing for Compile_Time_Error and Compile_Time_Warning
3096 procedure Process_Convention
3097 (C
: out Convention_Id
;
3098 Ent
: out Entity_Id
);
3099 -- Common processing for Convention, Interface, Import and Export.
3100 -- Checks first two arguments of pragma, and sets the appropriate
3101 -- convention value in the specified entity or entities. On return
3102 -- C is the convention, Ent is the referenced entity.
3104 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
);
3105 -- Common processing for Disable/Enable_Atomic_Synchronization. Nam is
3106 -- Name_Suppress for Disable and Name_Unsuppress for Enable.
3108 procedure Process_Extended_Import_Export_Object_Pragma
3109 (Arg_Internal
: Node_Id
;
3110 Arg_External
: Node_Id
;
3111 Arg_Size
: Node_Id
);
3112 -- Common processing for the pragmas Import/Export_Object. The three
3113 -- arguments correspond to the three named parameters of the pragmas. An
3114 -- argument is empty if the corresponding parameter is not present in
3117 procedure Process_Extended_Import_Export_Internal_Arg
3118 (Arg_Internal
: Node_Id
:= Empty
);
3119 -- Common processing for all extended Import and Export pragmas. The
3120 -- argument is the pragma parameter for the Internal argument. If
3121 -- Arg_Internal is empty or inappropriate, an error message is posted.
3122 -- Otherwise, on normal return, the Entity_Field of Arg_Internal is
3123 -- set to identify the referenced entity.
3125 procedure Process_Extended_Import_Export_Subprogram_Pragma
3126 (Arg_Internal
: Node_Id
;
3127 Arg_External
: Node_Id
;
3128 Arg_Parameter_Types
: Node_Id
;
3129 Arg_Result_Type
: Node_Id
:= Empty
;
3130 Arg_Mechanism
: Node_Id
;
3131 Arg_Result_Mechanism
: Node_Id
:= Empty
);
3132 -- Common processing for all extended Import and Export pragmas applying
3133 -- to subprograms. The caller omits any arguments that do not apply to
3134 -- the pragma in question (for example, Arg_Result_Type can be non-Empty
3135 -- only in the Import_Function and Export_Function cases). The argument
3136 -- names correspond to the allowed pragma association identifiers.
3138 procedure Process_Generic_List
;
3139 -- Common processing for Share_Generic and Inline_Generic
3141 procedure Process_Import_Or_Interface
;
3142 -- Common processing for Import or Interface
3144 procedure Process_Import_Predefined_Type
;
3145 -- Processing for completing a type with pragma Import. This is used
3146 -- to declare types that match predefined C types, especially for cases
3147 -- without corresponding Ada predefined type.
3149 type Inline_Status
is (Suppressed
, Disabled
, Enabled
);
3150 -- Inline status of a subprogram, indicated as follows:
3151 -- Suppressed: inlining is suppressed for the subprogram
3152 -- Disabled: no inlining is requested for the subprogram
3153 -- Enabled: inlining is requested/required for the subprogram
3155 procedure Process_Inline
(Status
: Inline_Status
);
3156 -- Common processing for Inline, Inline_Always and No_Inline. Parameter
3157 -- indicates the inline status specified by the pragma.
3159 procedure Process_Interface_Name
3160 (Subprogram_Def
: Entity_Id
;
3162 Link_Arg
: Node_Id
);
3163 -- Given the last two arguments of pragma Import, pragma Export, or
3164 -- pragma Interface_Name, performs validity checks and sets the
3165 -- Interface_Name field of the given subprogram entity to the
3166 -- appropriate external or link name, depending on the arguments given.
3167 -- Ext_Arg is always present, but Link_Arg may be missing. Note that
3168 -- Ext_Arg may represent the Link_Name if Link_Arg is missing, and
3169 -- appropriate named notation is used for Ext_Arg. If neither Ext_Arg
3170 -- nor Link_Arg is present, the interface name is set to the default
3171 -- from the subprogram name.
3173 procedure Process_Interrupt_Or_Attach_Handler
;
3174 -- Common processing for Interrupt and Attach_Handler pragmas
3176 procedure Process_Restrictions_Or_Restriction_Warnings
(Warn
: Boolean);
3177 -- Common processing for Restrictions and Restriction_Warnings pragmas.
3178 -- Warn is True for Restriction_Warnings, or for Restrictions if the
3179 -- flag Treat_Restrictions_As_Warnings is set, and False if this flag
3180 -- is not set in the Restrictions case.
3182 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean);
3183 -- Common processing for Suppress and Unsuppress. The boolean parameter
3184 -- Suppress_Case is True for the Suppress case, and False for the
3187 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
);
3188 -- Subsidiary to the analysis of pragmas Independent[_Components].
3189 -- Record such a pragma N applied to entity E for future checks.
3191 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
);
3192 -- This procedure sets the Is_Exported flag for the given entity,
3193 -- checking that the entity was not previously imported. Arg is
3194 -- the argument that specified the entity. A check is also made
3195 -- for exporting inappropriate entities.
3197 procedure Set_Extended_Import_Export_External_Name
3198 (Internal_Ent
: Entity_Id
;
3199 Arg_External
: Node_Id
);
3200 -- Common processing for all extended import export pragmas. The first
3201 -- argument, Internal_Ent, is the internal entity, which has already
3202 -- been checked for validity by the caller. Arg_External is from the
3203 -- Import or Export pragma, and may be null if no External parameter
3204 -- was present. If Arg_External is present and is a non-null string
3205 -- (a null string is treated as the default), then the Interface_Name
3206 -- field of Internal_Ent is set appropriately.
3208 procedure Set_Imported
(E
: Entity_Id
);
3209 -- This procedure sets the Is_Imported flag for the given entity,
3210 -- checking that it is not previously exported or imported.
3212 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
);
3213 -- Mech is a parameter passing mechanism (see Import_Function syntax
3214 -- for MECHANISM_NAME). This routine checks that the mechanism argument
3215 -- has the right form, and if not issues an error message. If the
3216 -- argument has the right form then the Mechanism field of Ent is
3217 -- set appropriately.
3219 procedure Set_Rational_Profile
;
3220 -- Activate the set of configuration pragmas and permissions that make
3221 -- up the Rational profile.
3223 procedure Set_Ravenscar_Profile
(N
: Node_Id
);
3224 -- Activate the set of configuration pragmas and restrictions that make
3225 -- up the Ravenscar Profile. N is the corresponding pragma node, which
3226 -- is used for error messages on any constructs violating the profile.
3228 ----------------------------------
3229 -- Acquire_Warning_Match_String --
3230 ----------------------------------
3232 procedure Acquire_Warning_Match_String
(Arg
: Node_Id
) is
3234 String_To_Name_Buffer
3235 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
3237 -- Add asterisk at start if not already there
3239 if Name_Len
> 0 and then Name_Buffer
(1) /= '*' then
3240 Name_Buffer
(2 .. Name_Len
+ 1) :=
3241 Name_Buffer
(1 .. Name_Len
);
3242 Name_Buffer
(1) := '*';
3243 Name_Len
:= Name_Len
+ 1;
3246 -- Add asterisk at end if not already there
3248 if Name_Buffer
(Name_Len
) /= '*' then
3249 Name_Len
:= Name_Len
+ 1;
3250 Name_Buffer
(Name_Len
) := '*';
3252 end Acquire_Warning_Match_String
;
3254 ---------------------
3255 -- Ada_2005_Pragma --
3256 ---------------------
3258 procedure Ada_2005_Pragma
is
3260 if Ada_Version
<= Ada_95
then
3261 Check_Restriction
(No_Implementation_Pragmas
, N
);
3263 end Ada_2005_Pragma
;
3265 ---------------------
3266 -- Ada_2012_Pragma --
3267 ---------------------
3269 procedure Ada_2012_Pragma
is
3271 if Ada_Version
<= Ada_2005
then
3272 Check_Restriction
(No_Implementation_Pragmas
, N
);
3274 end Ada_2012_Pragma
;
3276 ---------------------
3277 -- Analyze_Part_Of --
3278 ---------------------
3280 procedure Analyze_Part_Of
3281 (Item_Id
: Entity_Id
;
3284 Legal
: out Boolean)
3286 Pack_Id
: Entity_Id
;
3287 Placement
: State_Space_Kind
;
3288 Parent_Unit
: Entity_Id
;
3289 State_Id
: Entity_Id
;
3292 -- Assume that the pragma/option is illegal
3296 if Nkind_In
(State
, N_Expanded_Name
,
3298 N_Selected_Component
)
3301 Resolve_State
(State
);
3303 if Is_Entity_Name
(State
)
3304 and then Ekind
(Entity
(State
)) = E_Abstract_State
3306 State_Id
:= Entity
(State
);
3310 ("indicator Part_Of must denote an abstract state", State
);
3314 -- This is a syntax error, always report
3318 ("indicator Part_Of must denote an abstract state", State
);
3322 -- Determine where the state, variable or the package instantiation
3323 -- lives with respect to the enclosing packages or package bodies (if
3324 -- any). This placement dictates the legality of the encapsulating
3327 Find_Placement_In_State_Space
3328 (Item_Id
=> Item_Id
,
3329 Placement
=> Placement
,
3330 Pack_Id
=> Pack_Id
);
3332 -- The item appears in a non-package construct with a declarative
3333 -- part (subprogram, block, etc). As such, the item is not allowed
3334 -- to be a part of an encapsulating state because the item is not
3337 if Placement
= Not_In_Package
then
3339 ("indicator Part_Of cannot appear in this context "
3340 & "(SPARK RM 7.2.6(5))", Indic
);
3341 Error_Msg_Name_1
:= Chars
(Scope
(State_Id
));
3343 ("\& is not part of the hidden state of package %",
3346 -- The item appears in the visible state space of some package. In
3347 -- general this scenario does not warrant Part_Of except when the
3348 -- package is a private child unit and the encapsulating state is
3349 -- declared in a parent unit or a public descendant of that parent
3352 elsif Placement
= Visible_State_Space
then
3353 if Is_Child_Unit
(Pack_Id
)
3354 and then Is_Private_Descendant
(Pack_Id
)
3356 -- A variable or state abstraction which is part of the
3357 -- visible state of a private child unit (or one of its public
3358 -- descendants) must have its Part_Of indicator specified. The
3359 -- Part_Of indicator must denote a state abstraction declared
3360 -- by either the parent unit of the private unit or by a public
3361 -- descendant of that parent unit.
3363 -- Find nearest private ancestor (which can be the current unit
3366 Parent_Unit
:= Pack_Id
;
3367 while Present
(Parent_Unit
) loop
3368 exit when Private_Present
3369 (Parent
(Unit_Declaration_Node
(Parent_Unit
)));
3370 Parent_Unit
:= Scope
(Parent_Unit
);
3373 Parent_Unit
:= Scope
(Parent_Unit
);
3375 if not Is_Child_Or_Sibling
(Pack_Id
, Scope
(State_Id
)) then
3377 ("indicator Part_Of must denote an abstract state of& "
3378 & "or public descendant (SPARK RM 7.2.6(3))",
3379 Indic
, Parent_Unit
);
3381 elsif Scope
(State_Id
) = Parent_Unit
3382 or else (Is_Ancestor_Package
(Parent_Unit
, Scope
(State_Id
))
3384 not Is_Private_Descendant
(Scope
(State_Id
)))
3390 ("indicator Part_Of must denote an abstract state of& "
3391 & "or public descendant (SPARK RM 7.2.6(3))",
3392 Indic
, Parent_Unit
);
3395 -- Indicator Part_Of is not needed when the related package is not
3396 -- a private child unit or a public descendant thereof.
3400 ("indicator Part_Of cannot appear in this context "
3401 & "(SPARK RM 7.2.6(5))", Indic
);
3402 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3404 ("\& is declared in the visible part of package %",
3408 -- When the item appears in the private state space of a package, the
3409 -- encapsulating state must be declared in the same package.
3411 elsif Placement
= Private_State_Space
then
3412 if Scope
(State_Id
) /= Pack_Id
then
3414 ("indicator Part_Of must designate an abstract state of "
3415 & "package & (SPARK RM 7.2.6(2))", Indic
, Pack_Id
);
3416 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3418 ("\& is declared in the private part of package %",
3422 -- Items declared in the body state space of a package do not need
3423 -- Part_Of indicators as the refinement has already been seen.
3427 ("indicator Part_Of cannot appear in this context "
3428 & "(SPARK RM 7.2.6(5))", Indic
);
3430 if Scope
(State_Id
) = Pack_Id
then
3431 Error_Msg_Name_1
:= Chars
(Pack_Id
);
3433 ("\& is declared in the body of package %", Indic
, Item_Id
);
3438 end Analyze_Part_Of
;
3440 --------------------------------
3441 -- Analyze_Pre_Post_Condition --
3442 --------------------------------
3444 procedure Analyze_Pre_Post_Condition
is
3445 Prag_Iden
: constant Node_Id
:= Pragma_Identifier
(N
);
3446 Subp_Decl
: Node_Id
;
3447 Subp_Id
: Entity_Id
;
3449 Duplicates_OK
: Boolean := False;
3450 -- Flag set when a pre/postcondition allows multiple pragmas of the
3453 In_Body_OK
: Boolean := False;
3454 -- Flag set when a pre/postcondition is allowed to appear on a body
3455 -- even though the subprogram may have a spec.
3457 Is_Pre_Post
: Boolean := False;
3458 -- Flag set when the pragma is one of Pre, Pre_Class, Post or
3462 -- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to
3463 -- offer uniformity among the various kinds of pre/postconditions by
3464 -- rewriting the pragma identifier. This allows the retrieval of the
3465 -- original pragma name by routine Original_Aspect_Pragma_Name.
3467 if Comes_From_Source
(N
) then
3468 if Nam_In
(Pname
, Name_Pre
, Name_Pre_Class
) then
3469 Is_Pre_Post
:= True;
3470 Set_Class_Present
(N
, Pname
= Name_Pre_Class
);
3471 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Precondition
));
3473 elsif Nam_In
(Pname
, Name_Post
, Name_Post_Class
) then
3474 Is_Pre_Post
:= True;
3475 Set_Class_Present
(N
, Pname
= Name_Post_Class
);
3476 Rewrite
(Prag_Iden
, Make_Identifier
(Loc
, Name_Postcondition
));
3480 -- Determine the semantics with respect to duplicates and placement
3481 -- in a body. Pragmas Precondition and Postcondition were introduced
3482 -- before aspects and are not subject to the same aspect-like rules.
3484 if Nam_In
(Pname
, Name_Precondition
, Name_Postcondition
) then
3485 Duplicates_OK
:= True;
3491 -- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single
3492 -- argument without an identifier.
3495 Check_Arg_Count
(1);
3496 Check_No_Identifiers
;
3498 -- Pragmas Precondition and Postcondition have complex argument
3502 Check_At_Least_N_Arguments
(1);
3503 Check_At_Most_N_Arguments
(2);
3504 Check_Optional_Identifier
(Arg1
, Name_Check
);
3506 if Present
(Arg2
) then
3507 Check_Optional_Identifier
(Arg2
, Name_Message
);
3508 Preanalyze_Spec_Expression
3509 (Get_Pragma_Arg
(Arg2
), Standard_String
);
3513 -- For a pragma PPC in the extended main source unit, record enabled
3515 -- ??? nothing checks that the pragma is in the main source unit
3517 if Is_Checked
(N
) and then not Split_PPC
(N
) then
3518 Set_SCO_Pragma_Enabled
(Loc
);
3521 -- Ensure the proper placement of the pragma
3524 Find_Related_Subprogram_Or_Body
(N
, Do_Checks
=> not Duplicates_OK
);
3526 -- When a pre/postcondition pragma applies to an abstract subprogram,
3527 -- its original form must be an aspect with 'Class.
3529 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
3530 if not From_Aspect_Specification
(N
) then
3532 ("pragma % cannot be applied to abstract subprogram");
3534 elsif not Class_Present
(N
) then
3536 ("aspect % requires ''Class for abstract subprogram");
3539 -- Entry declaration
3541 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
3544 -- Generic subprogram declaration
3546 elsif Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
3551 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
3552 and then (No
(Corresponding_Spec
(Subp_Decl
)) or In_Body_OK
)
3556 -- Subprogram body stub
3558 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
3559 and then (No
(Corresponding_Spec_Of_Stub
(Subp_Decl
)) or In_Body_OK
)
3563 -- Subprogram declaration
3565 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
3567 -- AI05-0230: When a pre/postcondition pragma applies to a null
3568 -- procedure, its original form must be an aspect with 'Class.
3570 if Nkind
(Specification
(Subp_Decl
)) = N_Procedure_Specification
3571 and then Null_Present
(Specification
(Subp_Decl
))
3572 and then From_Aspect_Specification
(N
)
3573 and then not Class_Present
(N
)
3575 Error_Pragma
("aspect % requires ''Class for null procedure");
3578 -- Otherwise the placement is illegal
3585 Subp_Id
:= Defining_Entity
(Subp_Decl
);
3587 -- Construct a generic template for the pragma when the context is a
3588 -- generic subprogram and the pragma is a source construct.
3590 Create_Generic_Template
(N
, Subp_Id
);
3592 -- Fully analyze the pragma when it appears inside a subprogram
3593 -- body because it cannot benefit from forward references.
3595 if Nkind_In
(Subp_Decl
, N_Subprogram_Body
,
3596 N_Subprogram_Body_Stub
)
3598 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
3601 -- Chain the pragma on the contract for further processing
3603 Add_Contract_Item
(N
, Subp_Id
);
3604 end Analyze_Pre_Post_Condition
;
3606 ----------------------------
3607 -- Analyze_Refined_Pragma --
3608 ----------------------------
3610 procedure Analyze_Refined_Pragma
3611 (Spec_Id
: out Entity_Id
;
3612 Body_Id
: out Entity_Id
;
3613 Legal
: out Boolean)
3615 Body_Decl
: Node_Id
;
3616 Spec_Decl
: Node_Id
;
3619 -- Assume that the pragma is illegal
3626 Check_Arg_Count
(1);
3627 Check_No_Identifiers
;
3629 -- Verify the placement of the pragma and check for duplicates. The
3630 -- pragma must apply to a subprogram body [stub].
3632 Body_Decl
:= Find_Related_Subprogram_Or_Body
(N
, Do_Checks
=> True);
3634 -- Extract the entities of the spec and body
3636 if Nkind
(Body_Decl
) = N_Subprogram_Body
then
3637 Body_Id
:= Defining_Entity
(Body_Decl
);
3638 Spec_Id
:= Corresponding_Spec
(Body_Decl
);
3640 elsif Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
3641 Body_Id
:= Defining_Entity
(Body_Decl
);
3642 Spec_Id
:= Corresponding_Spec_Of_Stub
(Body_Decl
);
3649 -- The pragma must apply to the second declaration of a subprogram.
3650 -- In other words, the body [stub] cannot acts as a spec.
3652 if No
(Spec_Id
) then
3653 Error_Pragma
("pragma % cannot apply to a stand alone body");
3656 -- Catch the case where the subprogram body is a subunit and acts as
3657 -- the third declaration of the subprogram.
3659 elsif Nkind
(Parent
(Body_Decl
)) = N_Subunit
then
3660 Error_Pragma
("pragma % cannot apply to a subunit");
3664 -- The pragma can only apply to the body [stub] of a subprogram
3665 -- declared in the visible part of a package. Retrieve the context of
3666 -- the subprogram declaration.
3668 Spec_Decl
:= Unit_Declaration_Node
(Spec_Id
);
3670 if Nkind
(Parent
(Spec_Decl
)) /= N_Package_Specification
then
3672 ("pragma % must apply to the body of a subprogram declared in a "
3673 & "package specification");
3677 -- If we get here, then the pragma is legal
3679 if Nam_In
(Pname
, Name_Refined_Depends
,
3680 Name_Refined_Global
,
3683 Ensure_Aggregate_Form
(Get_Argument
(N
));
3687 end Analyze_Refined_Pragma
;
3689 --------------------------
3690 -- Check_Ada_83_Warning --
3691 --------------------------
3693 procedure Check_Ada_83_Warning
is
3695 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
3696 Error_Msg_N
("(Ada 83) pragma& is non-standard??", N
);
3698 end Check_Ada_83_Warning
;
3700 ---------------------
3701 -- Check_Arg_Count --
3702 ---------------------
3704 procedure Check_Arg_Count
(Required
: Nat
) is
3706 if Arg_Count
/= Required
then
3707 Error_Pragma
("wrong number of arguments for pragma%");
3709 end Check_Arg_Count
;
3711 --------------------------------
3712 -- Check_Arg_Is_External_Name --
3713 --------------------------------
3715 procedure Check_Arg_Is_External_Name
(Arg
: Node_Id
) is
3716 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3719 if Nkind
(Argx
) = N_Identifier
then
3723 Analyze_And_Resolve
(Argx
, Standard_String
);
3725 if Is_OK_Static_Expression
(Argx
) then
3728 elsif Etype
(Argx
) = Any_Type
then
3731 -- An interesting special case, if we have a string literal and
3732 -- we are in Ada 83 mode, then we allow it even though it will
3733 -- not be flagged as static. This allows expected Ada 83 mode
3734 -- use of external names which are string literals, even though
3735 -- technically these are not static in Ada 83.
3737 elsif Ada_Version
= Ada_83
3738 and then Nkind
(Argx
) = N_String_Literal
3742 -- Static expression that raises Constraint_Error. This has
3743 -- already been flagged, so just exit from pragma processing.
3745 elsif Is_OK_Static_Expression
(Argx
) then
3748 -- Here we have a real error (non-static expression)
3751 Error_Msg_Name_1
:= Pname
;
3754 Msg
: constant String :=
3755 "argument for pragma% must be a identifier or "
3756 & "static string expression!";
3758 Flag_Non_Static_Expr
(Fix_Error
(Msg
), Argx
);
3763 end Check_Arg_Is_External_Name
;
3765 -----------------------------
3766 -- Check_Arg_Is_Identifier --
3767 -----------------------------
3769 procedure Check_Arg_Is_Identifier
(Arg
: Node_Id
) is
3770 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3772 if Nkind
(Argx
) /= N_Identifier
then
3774 ("argument for pragma% must be identifier", Argx
);
3776 end Check_Arg_Is_Identifier
;
3778 ----------------------------------
3779 -- Check_Arg_Is_Integer_Literal --
3780 ----------------------------------
3782 procedure Check_Arg_Is_Integer_Literal
(Arg
: Node_Id
) is
3783 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3785 if Nkind
(Argx
) /= N_Integer_Literal
then
3787 ("argument for pragma% must be integer literal", Argx
);
3789 end Check_Arg_Is_Integer_Literal
;
3791 -------------------------------------------
3792 -- Check_Arg_Is_Library_Level_Local_Name --
3793 -------------------------------------------
3797 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3798 -- | library_unit_NAME
3800 procedure Check_Arg_Is_Library_Level_Local_Name
(Arg
: Node_Id
) is
3802 Check_Arg_Is_Local_Name
(Arg
);
3804 if not Is_Library_Level_Entity
(Entity
(Get_Pragma_Arg
(Arg
)))
3805 and then Comes_From_Source
(N
)
3808 ("argument for pragma% must be library level entity", Arg
);
3810 end Check_Arg_Is_Library_Level_Local_Name
;
3812 -----------------------------
3813 -- Check_Arg_Is_Local_Name --
3814 -----------------------------
3818 -- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR
3819 -- | library_unit_NAME
3821 procedure Check_Arg_Is_Local_Name
(Arg
: Node_Id
) is
3822 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3827 if Nkind
(Argx
) not in N_Direct_Name
3828 and then (Nkind
(Argx
) /= N_Attribute_Reference
3829 or else Present
(Expressions
(Argx
))
3830 or else Nkind
(Prefix
(Argx
)) /= N_Identifier
)
3831 and then (not Is_Entity_Name
(Argx
)
3832 or else not Is_Compilation_Unit
(Entity
(Argx
)))
3834 Error_Pragma_Arg
("argument for pragma% must be local name", Argx
);
3837 -- No further check required if not an entity name
3839 if not Is_Entity_Name
(Argx
) then
3845 Ent
: constant Entity_Id
:= Entity
(Argx
);
3846 Scop
: constant Entity_Id
:= Scope
(Ent
);
3849 -- Case of a pragma applied to a compilation unit: pragma must
3850 -- occur immediately after the program unit in the compilation.
3852 if Is_Compilation_Unit
(Ent
) then
3854 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
3857 -- Case of pragma placed immediately after spec
3859 if Parent
(N
) = Aux_Decls_Node
(Parent
(Decl
)) then
3862 -- Case of pragma placed immediately after body
3864 elsif Nkind
(Decl
) = N_Subprogram_Declaration
3865 and then Present
(Corresponding_Body
(Decl
))
3869 (Parent
(Unit_Declaration_Node
3870 (Corresponding_Body
(Decl
))));
3872 -- All other cases are illegal
3879 -- Special restricted placement rule from 10.2.1(11.8/2)
3881 elsif Is_Generic_Formal
(Ent
)
3882 and then Prag_Id
= Pragma_Preelaborable_Initialization
3884 OK
:= List_Containing
(N
) =
3885 Generic_Formal_Declarations
3886 (Unit_Declaration_Node
(Scop
));
3888 -- If this is an aspect applied to a subprogram body, the
3889 -- pragma is inserted in its declarative part.
3891 elsif From_Aspect_Specification
(N
)
3892 and then Ent
= Current_Scope
3894 Nkind
(Unit_Declaration_Node
(Ent
)) = N_Subprogram_Body
3898 -- If the aspect is a predicate (possibly others ???) and the
3899 -- context is a record type, this is a discriminant expression
3900 -- within a type declaration, that freezes the predicated
3903 elsif From_Aspect_Specification
(N
)
3904 and then Prag_Id
= Pragma_Predicate
3905 and then Ekind
(Current_Scope
) = E_Record_Type
3906 and then Scop
= Scope
(Current_Scope
)
3910 -- Default case, just check that the pragma occurs in the scope
3911 -- of the entity denoted by the name.
3914 OK
:= Current_Scope
= Scop
;
3919 ("pragma% argument must be in same declarative part", Arg
);
3923 end Check_Arg_Is_Local_Name
;
3925 ---------------------------------
3926 -- Check_Arg_Is_Locking_Policy --
3927 ---------------------------------
3929 procedure Check_Arg_Is_Locking_Policy
(Arg
: Node_Id
) is
3930 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3933 Check_Arg_Is_Identifier
(Argx
);
3935 if not Is_Locking_Policy_Name
(Chars
(Argx
)) then
3936 Error_Pragma_Arg
("& is not a valid locking policy name", Argx
);
3938 end Check_Arg_Is_Locking_Policy
;
3940 -----------------------------------------------
3941 -- Check_Arg_Is_Partition_Elaboration_Policy --
3942 -----------------------------------------------
3944 procedure Check_Arg_Is_Partition_Elaboration_Policy
(Arg
: Node_Id
) is
3945 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3948 Check_Arg_Is_Identifier
(Argx
);
3950 if not Is_Partition_Elaboration_Policy_Name
(Chars
(Argx
)) then
3952 ("& is not a valid partition elaboration policy name", Argx
);
3954 end Check_Arg_Is_Partition_Elaboration_Policy
;
3956 -------------------------
3957 -- Check_Arg_Is_One_Of --
3958 -------------------------
3960 procedure Check_Arg_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
3961 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3964 Check_Arg_Is_Identifier
(Argx
);
3966 if not Nam_In
(Chars
(Argx
), N1
, N2
) then
3967 Error_Msg_Name_2
:= N1
;
3968 Error_Msg_Name_3
:= N2
;
3969 Error_Pragma_Arg
("argument for pragma% must be% or%", Argx
);
3971 end Check_Arg_Is_One_Of
;
3973 procedure Check_Arg_Is_One_Of
3975 N1
, N2
, N3
: Name_Id
)
3977 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3980 Check_Arg_Is_Identifier
(Argx
);
3982 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
) then
3983 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
3985 end Check_Arg_Is_One_Of
;
3987 procedure Check_Arg_Is_One_Of
3989 N1
, N2
, N3
, N4
: Name_Id
)
3991 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
3994 Check_Arg_Is_Identifier
(Argx
);
3996 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
) then
3997 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
3999 end Check_Arg_Is_One_Of
;
4001 procedure Check_Arg_Is_One_Of
4003 N1
, N2
, N3
, N4
, N5
: Name_Id
)
4005 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4008 Check_Arg_Is_Identifier
(Argx
);
4010 if not Nam_In
(Chars
(Argx
), N1
, N2
, N3
, N4
, N5
) then
4011 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
4013 end Check_Arg_Is_One_Of
;
4015 ---------------------------------
4016 -- Check_Arg_Is_Queuing_Policy --
4017 ---------------------------------
4019 procedure Check_Arg_Is_Queuing_Policy
(Arg
: Node_Id
) is
4020 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4023 Check_Arg_Is_Identifier
(Argx
);
4025 if not Is_Queuing_Policy_Name
(Chars
(Argx
)) then
4026 Error_Pragma_Arg
("& is not a valid queuing policy name", Argx
);
4028 end Check_Arg_Is_Queuing_Policy
;
4030 ---------------------------------------
4031 -- Check_Arg_Is_OK_Static_Expression --
4032 ---------------------------------------
4034 procedure Check_Arg_Is_OK_Static_Expression
4036 Typ
: Entity_Id
:= Empty
)
4039 Check_Expr_Is_OK_Static_Expression
(Get_Pragma_Arg
(Arg
), Typ
);
4040 end Check_Arg_Is_OK_Static_Expression
;
4042 ------------------------------------------
4043 -- Check_Arg_Is_Task_Dispatching_Policy --
4044 ------------------------------------------
4046 procedure Check_Arg_Is_Task_Dispatching_Policy
(Arg
: Node_Id
) is
4047 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4050 Check_Arg_Is_Identifier
(Argx
);
4052 if not Is_Task_Dispatching_Policy_Name
(Chars
(Argx
)) then
4054 ("& is not an allowed task dispatching policy name", Argx
);
4056 end Check_Arg_Is_Task_Dispatching_Policy
;
4058 ---------------------
4059 -- Check_Arg_Order --
4060 ---------------------
4062 procedure Check_Arg_Order
(Names
: Name_List
) is
4065 Highest_So_Far
: Natural := 0;
4066 -- Highest index in Names seen do far
4070 for J
in 1 .. Arg_Count
loop
4071 if Chars
(Arg
) /= No_Name
then
4072 for K
in Names
'Range loop
4073 if Chars
(Arg
) = Names
(K
) then
4074 if K
< Highest_So_Far
then
4075 Error_Msg_Name_1
:= Pname
;
4077 ("parameters out of order for pragma%", Arg
);
4078 Error_Msg_Name_1
:= Names
(K
);
4079 Error_Msg_Name_2
:= Names
(Highest_So_Far
);
4080 Error_Msg_N
("\% must appear before %", Arg
);
4084 Highest_So_Far
:= K
;
4092 end Check_Arg_Order
;
4094 --------------------------------
4095 -- Check_At_Least_N_Arguments --
4096 --------------------------------
4098 procedure Check_At_Least_N_Arguments
(N
: Nat
) is
4100 if Arg_Count
< N
then
4101 Error_Pragma
("too few arguments for pragma%");
4103 end Check_At_Least_N_Arguments
;
4105 -------------------------------
4106 -- Check_At_Most_N_Arguments --
4107 -------------------------------
4109 procedure Check_At_Most_N_Arguments
(N
: Nat
) is
4112 if Arg_Count
> N
then
4114 for J
in 1 .. N
loop
4116 Error_Pragma_Arg
("too many arguments for pragma%", Arg
);
4119 end Check_At_Most_N_Arguments
;
4121 ---------------------
4122 -- Check_Component --
4123 ---------------------
4125 procedure Check_Component
4128 In_Variant_Part
: Boolean := False)
4130 Comp_Id
: constant Entity_Id
:= Defining_Identifier
(Comp
);
4131 Sindic
: constant Node_Id
:=
4132 Subtype_Indication
(Component_Definition
(Comp
));
4133 Typ
: constant Entity_Id
:= Etype
(Comp_Id
);
4136 -- Ada 2005 (AI-216): If a component subtype is subject to a per-
4137 -- object constraint, then the component type shall be an Unchecked_
4140 if Nkind
(Sindic
) = N_Subtype_Indication
4141 and then Has_Per_Object_Constraint
(Comp_Id
)
4142 and then not Is_Unchecked_Union
(Etype
(Subtype_Mark
(Sindic
)))
4145 ("component subtype subject to per-object constraint "
4146 & "must be an Unchecked_Union", Comp
);
4148 -- Ada 2012 (AI05-0026): For an unchecked union type declared within
4149 -- the body of a generic unit, or within the body of any of its
4150 -- descendant library units, no part of the type of a component
4151 -- declared in a variant_part of the unchecked union type shall be of
4152 -- a formal private type or formal private extension declared within
4153 -- the formal part of the generic unit.
4155 elsif Ada_Version
>= Ada_2012
4156 and then In_Generic_Body
(UU_Typ
)
4157 and then In_Variant_Part
4158 and then Is_Private_Type
(Typ
)
4159 and then Is_Generic_Type
(Typ
)
4162 ("component of unchecked union cannot be of generic type", Comp
);
4164 elsif Needs_Finalization
(Typ
) then
4166 ("component of unchecked union cannot be controlled", Comp
);
4168 elsif Has_Task
(Typ
) then
4170 ("component of unchecked union cannot have tasks", Comp
);
4172 end Check_Component
;
4174 -----------------------------
4175 -- Check_Declaration_Order --
4176 -----------------------------
4178 procedure Check_Declaration_Order
(First
: Node_Id
; Second
: Node_Id
) is
4179 procedure Check_Aspect_Specification_Order
;
4180 -- Inspect the aspect specifications of the context to determine the
4183 --------------------------------------
4184 -- Check_Aspect_Specification_Order --
4185 --------------------------------------
4187 procedure Check_Aspect_Specification_Order
is
4188 Asp_First
: constant Node_Id
:= Corresponding_Aspect
(First
);
4189 Asp_Second
: constant Node_Id
:= Corresponding_Aspect
(Second
);
4193 -- Both aspects must be part of the same aspect specification list
4196 (List_Containing
(Asp_First
) = List_Containing
(Asp_Second
));
4198 -- Try to reach Second starting from First in a left to right
4199 -- traversal of the aspect specifications.
4201 Asp
:= Next
(Asp_First
);
4202 while Present
(Asp
) loop
4204 -- The order is ok, First is followed by Second
4206 if Asp
= Asp_Second
then
4213 -- If we get here, then the aspects are out of order
4215 SPARK_Msg_N
("aspect % cannot come after aspect %", First
);
4216 end Check_Aspect_Specification_Order
;
4222 -- Start of processing for Check_Declaration_Order
4225 -- Cannot check the order if one of the pragmas is missing
4227 if No
(First
) or else No
(Second
) then
4231 -- Set up the error names in case the order is incorrect
4233 Error_Msg_Name_1
:= Pragma_Name
(First
);
4234 Error_Msg_Name_2
:= Pragma_Name
(Second
);
4236 if From_Aspect_Specification
(First
) then
4238 -- Both pragmas are actually aspects, check their declaration
4239 -- order in the associated aspect specification list. Otherwise
4240 -- First is an aspect and Second a source pragma.
4242 if From_Aspect_Specification
(Second
) then
4243 Check_Aspect_Specification_Order
;
4246 -- Abstract_States is a source pragma
4249 if From_Aspect_Specification
(Second
) then
4250 SPARK_Msg_N
("pragma % cannot come after aspect %", First
);
4252 -- Both pragmas are source constructs. Try to reach First from
4253 -- Second by traversing the declarations backwards.
4256 Stmt
:= Prev
(Second
);
4257 while Present
(Stmt
) loop
4259 -- The order is ok, First is followed by Second
4261 if Stmt
= First
then
4268 -- If we get here, then the pragmas are out of order
4270 SPARK_Msg_N
("pragma % cannot come after pragma %", First
);
4273 end Check_Declaration_Order
;
4275 ----------------------------
4276 -- Check_Duplicate_Pragma --
4277 ----------------------------
4279 procedure Check_Duplicate_Pragma
(E
: Entity_Id
) is
4280 Id
: Entity_Id
:= E
;
4284 -- Nothing to do if this pragma comes from an aspect specification,
4285 -- since we could not be duplicating a pragma, and we dealt with the
4286 -- case of duplicated aspects in Analyze_Aspect_Specifications.
4288 if From_Aspect_Specification
(N
) then
4292 -- Otherwise current pragma may duplicate previous pragma or a
4293 -- previously given aspect specification or attribute definition
4294 -- clause for the same pragma.
4296 P
:= Get_Rep_Item
(E
, Pragma_Name
(N
), Check_Parents
=> False);
4300 -- If the entity is a type, then we have to make sure that the
4301 -- ostensible duplicate is not for a parent type from which this
4305 if Nkind
(P
) = N_Pragma
then
4307 Args
: constant List_Id
:=
4308 Pragma_Argument_Associations
(P
);
4311 and then Is_Entity_Name
(Expression
(First
(Args
)))
4312 and then Is_Type
(Entity
(Expression
(First
(Args
))))
4313 and then Entity
(Expression
(First
(Args
))) /= E
4319 elsif Nkind
(P
) = N_Aspect_Specification
4320 and then Is_Type
(Entity
(P
))
4321 and then Entity
(P
) /= E
4327 -- Here we have a definite duplicate
4329 Error_Msg_Name_1
:= Pragma_Name
(N
);
4330 Error_Msg_Sloc
:= Sloc
(P
);
4332 -- For a single protected or a single task object, the error is
4333 -- issued on the original entity.
4335 if Ekind_In
(Id
, E_Task_Type
, E_Protected_Type
) then
4336 Id
:= Defining_Identifier
(Original_Node
(Parent
(Id
)));
4339 if Nkind
(P
) = N_Aspect_Specification
4340 or else From_Aspect_Specification
(P
)
4342 Error_Msg_NE
("aspect% for & previously given#", N
, Id
);
4344 Error_Msg_NE
("pragma% for & duplicates pragma#", N
, Id
);
4349 end Check_Duplicate_Pragma
;
4351 ----------------------------------
4352 -- Check_Duplicated_Export_Name --
4353 ----------------------------------
4355 procedure Check_Duplicated_Export_Name
(Nam
: Node_Id
) is
4356 String_Val
: constant String_Id
:= Strval
(Nam
);
4359 -- We are only interested in the export case, and in the case of
4360 -- generics, it is the instance, not the template, that is the
4361 -- problem (the template will generate a warning in any case).
4363 if not Inside_A_Generic
4364 and then (Prag_Id
= Pragma_Export
4366 Prag_Id
= Pragma_Export_Procedure
4368 Prag_Id
= Pragma_Export_Valued_Procedure
4370 Prag_Id
= Pragma_Export_Function
)
4372 for J
in Externals
.First
.. Externals
.Last
loop
4373 if String_Equal
(String_Val
, Strval
(Externals
.Table
(J
))) then
4374 Error_Msg_Sloc
:= Sloc
(Externals
.Table
(J
));
4375 Error_Msg_N
("external name duplicates name given#", Nam
);
4380 Externals
.Append
(Nam
);
4382 end Check_Duplicated_Export_Name
;
4384 ----------------------------------------
4385 -- Check_Expr_Is_OK_Static_Expression --
4386 ----------------------------------------
4388 procedure Check_Expr_Is_OK_Static_Expression
4390 Typ
: Entity_Id
:= Empty
)
4393 if Present
(Typ
) then
4394 Analyze_And_Resolve
(Expr
, Typ
);
4396 Analyze_And_Resolve
(Expr
);
4399 if Is_OK_Static_Expression
(Expr
) then
4402 elsif Etype
(Expr
) = Any_Type
then
4405 -- An interesting special case, if we have a string literal and we
4406 -- are in Ada 83 mode, then we allow it even though it will not be
4407 -- flagged as static. This allows the use of Ada 95 pragmas like
4408 -- Import in Ada 83 mode. They will of course be flagged with
4409 -- warnings as usual, but will not cause errors.
4411 elsif Ada_Version
= Ada_83
4412 and then Nkind
(Expr
) = N_String_Literal
4416 -- Static expression that raises Constraint_Error. This has already
4417 -- been flagged, so just exit from pragma processing.
4419 elsif Is_OK_Static_Expression
(Expr
) then
4422 -- Finally, we have a real error
4425 Error_Msg_Name_1
:= Pname
;
4426 Flag_Non_Static_Expr
4427 (Fix_Error
("argument for pragma% must be a static expression!"),
4431 end Check_Expr_Is_OK_Static_Expression
;
4433 -------------------------
4434 -- Check_First_Subtype --
4435 -------------------------
4437 procedure Check_First_Subtype
(Arg
: Node_Id
) is
4438 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
4439 Ent
: constant Entity_Id
:= Entity
(Argx
);
4442 if Is_First_Subtype
(Ent
) then
4445 elsif Is_Type
(Ent
) then
4447 ("pragma% cannot apply to subtype", Argx
);
4449 elsif Is_Object
(Ent
) then
4451 ("pragma% cannot apply to object, requires a type", Argx
);
4455 ("pragma% cannot apply to&, requires a type", Argx
);
4457 end Check_First_Subtype
;
4459 ----------------------
4460 -- Check_Identifier --
4461 ----------------------
4463 procedure Check_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
4466 and then Nkind
(Arg
) = N_Pragma_Argument_Association
4468 if Chars
(Arg
) = No_Name
or else Chars
(Arg
) /= Id
then
4469 Error_Msg_Name_1
:= Pname
;
4470 Error_Msg_Name_2
:= Id
;
4471 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
4475 end Check_Identifier
;
4477 --------------------------------
4478 -- Check_Identifier_Is_One_Of --
4479 --------------------------------
4481 procedure Check_Identifier_Is_One_Of
(Arg
: Node_Id
; N1
, N2
: Name_Id
) is
4484 and then Nkind
(Arg
) = N_Pragma_Argument_Association
4486 if Chars
(Arg
) = No_Name
then
4487 Error_Msg_Name_1
:= Pname
;
4488 Error_Msg_N
("pragma% argument expects an identifier", Arg
);
4491 elsif Chars
(Arg
) /= N1
4492 and then Chars
(Arg
) /= N2
4494 Error_Msg_Name_1
:= Pname
;
4495 Error_Msg_N
("invalid identifier for pragma% argument", Arg
);
4499 end Check_Identifier_Is_One_Of
;
4501 ---------------------------
4502 -- Check_In_Main_Program --
4503 ---------------------------
4505 procedure Check_In_Main_Program
is
4506 P
: constant Node_Id
:= Parent
(N
);
4509 -- Must be at in subprogram body
4511 if Nkind
(P
) /= N_Subprogram_Body
then
4512 Error_Pragma
("% pragma allowed only in subprogram");
4514 -- Otherwise warn if obviously not main program
4516 elsif Present
(Parameter_Specifications
(Specification
(P
)))
4517 or else not Is_Compilation_Unit
(Defining_Entity
(P
))
4519 Error_Msg_Name_1
:= Pname
;
4521 ("??pragma% is only effective in main program", N
);
4523 end Check_In_Main_Program
;
4525 ---------------------------------------
4526 -- Check_Interrupt_Or_Attach_Handler --
4527 ---------------------------------------
4529 procedure Check_Interrupt_Or_Attach_Handler
is
4530 Arg1_X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
4531 Handler_Proc
, Proc_Scope
: Entity_Id
;
4536 if Prag_Id
= Pragma_Interrupt_Handler
then
4537 Check_Restriction
(No_Dynamic_Attachment
, N
);
4540 Handler_Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
4541 Proc_Scope
:= Scope
(Handler_Proc
);
4543 -- On AAMP only, a pragma Interrupt_Handler is supported for
4544 -- nonprotected parameterless procedures.
4546 if not AAMP_On_Target
4547 or else Prag_Id
= Pragma_Attach_Handler
4549 if Ekind
(Proc_Scope
) /= E_Protected_Type
then
4551 ("argument of pragma% must be protected procedure", Arg1
);
4554 -- For pragma case (as opposed to access case), check placement.
4555 -- We don't need to do that for aspects, because we have the
4556 -- check that they aspect applies an appropriate procedure.
4558 if not From_Aspect_Specification
(N
)
4559 and then Parent
(N
) /= Protected_Definition
(Parent
(Proc_Scope
))
4561 Error_Pragma
("pragma% must be in protected definition");
4565 if not Is_Library_Level_Entity
(Proc_Scope
)
4566 or else (AAMP_On_Target
4567 and then not Is_Library_Level_Entity
(Handler_Proc
))
4570 ("argument for pragma% must be library level entity", Arg1
);
4573 -- AI05-0033: A pragma cannot appear within a generic body, because
4574 -- instance can be in a nested scope. The check that protected type
4575 -- is itself a library-level declaration is done elsewhere.
4577 -- Note: we omit this check in Relaxed_RM_Semantics mode to properly
4578 -- handle code prior to AI-0033. Analysis tools typically are not
4579 -- interested in this pragma in any case, so no need to worry too
4580 -- much about its placement.
4582 if Inside_A_Generic
then
4583 if Ekind
(Scope
(Current_Scope
)) = E_Generic_Package
4584 and then In_Package_Body
(Scope
(Current_Scope
))
4585 and then not Relaxed_RM_Semantics
4587 Error_Pragma
("pragma% cannot be used inside a generic");
4590 end Check_Interrupt_Or_Attach_Handler
;
4592 ---------------------------------
4593 -- Check_Loop_Pragma_Placement --
4594 ---------------------------------
4596 procedure Check_Loop_Pragma_Placement
is
4597 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
);
4598 -- Verify whether the current pragma is properly grouped with other
4599 -- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the
4600 -- related loop where the pragma appears.
4602 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean;
4603 -- Determine whether an arbitrary statement Stmt denotes pragma
4604 -- Loop_Invariant or Loop_Variant.
4606 procedure Placement_Error
(Constr
: Node_Id
);
4607 pragma No_Return
(Placement_Error
);
4608 -- Node Constr denotes the last loop restricted construct before we
4609 -- encountered an illegal relation between enclosing constructs. Emit
4610 -- an error depending on what Constr was.
4612 --------------------------------
4613 -- Check_Loop_Pragma_Grouping --
4614 --------------------------------
4616 procedure Check_Loop_Pragma_Grouping
(Loop_Stmt
: Node_Id
) is
4617 Stop_Search
: exception;
4618 -- This exception is used to terminate the recursive descent of
4619 -- routine Check_Grouping.
4621 procedure Check_Grouping
(L
: List_Id
);
4622 -- Find the first group of pragmas in list L and if successful,
4623 -- ensure that the current pragma is part of that group. The
4624 -- routine raises Stop_Search once such a check is performed to
4625 -- halt the recursive descent.
4627 procedure Grouping_Error
(Prag
: Node_Id
);
4628 pragma No_Return
(Grouping_Error
);
4629 -- Emit an error concerning the current pragma indicating that it
4630 -- should be placed after pragma Prag.
4632 --------------------
4633 -- Check_Grouping --
4634 --------------------
4636 procedure Check_Grouping
(L
: List_Id
) is
4642 -- Inspect the list of declarations or statements looking for
4643 -- the first grouping of pragmas:
4646 -- pragma Loop_Invariant ...;
4647 -- pragma Loop_Variant ...;
4649 -- pragma Loop_Variant ...; -- current pragma
4651 -- If the current pragma is not in the grouping, then it must
4652 -- either appear in a different declarative or statement list
4653 -- or the construct at (1) is separating the pragma from the
4657 while Present
(Stmt
) loop
4659 -- Pragmas Loop_Invariant and Loop_Variant may only appear
4660 -- inside a loop or a block housed inside a loop. Inspect
4661 -- the declarations and statements of the block as they may
4662 -- contain the first grouping.
4664 if Nkind
(Stmt
) = N_Block_Statement
then
4665 HSS
:= Handled_Statement_Sequence
(Stmt
);
4667 Check_Grouping
(Declarations
(Stmt
));
4669 if Present
(HSS
) then
4670 Check_Grouping
(Statements
(HSS
));
4673 -- First pragma of the first topmost grouping has been found
4675 elsif Is_Loop_Pragma
(Stmt
) then
4677 -- The group and the current pragma are not in the same
4678 -- declarative or statement list.
4680 if List_Containing
(Stmt
) /= List_Containing
(N
) then
4681 Grouping_Error
(Stmt
);
4683 -- Try to reach the current pragma from the first pragma
4684 -- of the grouping while skipping other members:
4686 -- pragma Loop_Invariant ...; -- first pragma
4687 -- pragma Loop_Variant ...; -- member
4689 -- pragma Loop_Variant ...; -- current pragma
4692 while Present
(Stmt
) loop
4694 -- The current pragma is either the first pragma
4695 -- of the group or is a member of the group. Stop
4696 -- the search as the placement is legal.
4701 -- Skip group members, but keep track of the last
4702 -- pragma in the group.
4704 elsif Is_Loop_Pragma
(Stmt
) then
4707 -- A non-pragma is separating the group from the
4708 -- current pragma, the placement is illegal.
4711 Grouping_Error
(Prag
);
4717 -- If the traversal did not reach the current pragma,
4718 -- then the list must be malformed.
4720 raise Program_Error
;
4728 --------------------
4729 -- Grouping_Error --
4730 --------------------
4732 procedure Grouping_Error
(Prag
: Node_Id
) is
4734 Error_Msg_Sloc
:= Sloc
(Prag
);
4735 Error_Pragma
("pragma% must appear next to pragma#");
4738 -- Start of processing for Check_Loop_Pragma_Grouping
4741 -- Inspect the statements of the loop or nested blocks housed
4742 -- within to determine whether the current pragma is part of the
4743 -- first topmost grouping of Loop_Invariant and Loop_Variant.
4745 Check_Grouping
(Statements
(Loop_Stmt
));
4748 when Stop_Search
=> null;
4749 end Check_Loop_Pragma_Grouping
;
4751 --------------------
4752 -- Is_Loop_Pragma --
4753 --------------------
4755 function Is_Loop_Pragma
(Stmt
: Node_Id
) return Boolean is
4757 -- Inspect the original node as Loop_Invariant and Loop_Variant
4758 -- pragmas are rewritten to null when assertions are disabled.
4760 if Nkind
(Original_Node
(Stmt
)) = N_Pragma
then
4762 Nam_In
(Pragma_Name
(Original_Node
(Stmt
)),
4763 Name_Loop_Invariant
,
4770 ---------------------
4771 -- Placement_Error --
4772 ---------------------
4774 procedure Placement_Error
(Constr
: Node_Id
) is
4775 LA
: constant String := " with Loop_Entry";
4778 if Prag_Id
= Pragma_Assert
then
4779 Error_Msg_String
(1 .. LA
'Length) := LA
;
4780 Error_Msg_Strlen
:= LA
'Length;
4782 Error_Msg_Strlen
:= 0;
4785 if Nkind
(Constr
) = N_Pragma
then
4787 ("pragma %~ must appear immediately within the statements "
4791 ("block containing pragma %~ must appear immediately within "
4792 & "the statements of a loop", Constr
);
4794 end Placement_Error
;
4796 -- Local declarations
4801 -- Start of processing for Check_Loop_Pragma_Placement
4804 -- Check that pragma appears immediately within a loop statement,
4805 -- ignoring intervening block statements.
4809 while Present
(Stmt
) loop
4811 -- The pragma or previous block must appear immediately within the
4812 -- current block's declarative or statement part.
4814 if Nkind
(Stmt
) = N_Block_Statement
then
4815 if (No
(Declarations
(Stmt
))
4816 or else List_Containing
(Prev
) /= Declarations
(Stmt
))
4818 List_Containing
(Prev
) /=
4819 Statements
(Handled_Statement_Sequence
(Stmt
))
4821 Placement_Error
(Prev
);
4824 -- Keep inspecting the parents because we are now within a
4825 -- chain of nested blocks.
4829 Stmt
:= Parent
(Stmt
);
4832 -- The pragma or previous block must appear immediately within the
4833 -- statements of the loop.
4835 elsif Nkind
(Stmt
) = N_Loop_Statement
then
4836 if List_Containing
(Prev
) /= Statements
(Stmt
) then
4837 Placement_Error
(Prev
);
4840 -- Stop the traversal because we reached the innermost loop
4841 -- regardless of whether we encountered an error or not.
4845 -- Ignore a handled statement sequence. Note that this node may
4846 -- be related to a subprogram body in which case we will emit an
4847 -- error on the next iteration of the search.
4849 elsif Nkind
(Stmt
) = N_Handled_Sequence_Of_Statements
then
4850 Stmt
:= Parent
(Stmt
);
4852 -- Any other statement breaks the chain from the pragma to the
4856 Placement_Error
(Prev
);
4861 -- Check that the current pragma Loop_Invariant or Loop_Variant is
4862 -- grouped together with other such pragmas.
4864 if Is_Loop_Pragma
(N
) then
4866 -- The previous check should have located the related loop
4868 pragma Assert
(Nkind
(Stmt
) = N_Loop_Statement
);
4869 Check_Loop_Pragma_Grouping
(Stmt
);
4871 end Check_Loop_Pragma_Placement
;
4873 -------------------------------------------
4874 -- Check_Is_In_Decl_Part_Or_Package_Spec --
4875 -------------------------------------------
4877 procedure Check_Is_In_Decl_Part_Or_Package_Spec
is
4886 elsif Nkind
(P
) = N_Handled_Sequence_Of_Statements
then
4889 elsif Nkind_In
(P
, N_Package_Specification
,
4894 -- Note: the following tests seem a little peculiar, because
4895 -- they test for bodies, but if we were in the statement part
4896 -- of the body, we would already have hit the handled statement
4897 -- sequence, so the only way we get here is by being in the
4898 -- declarative part of the body.
4900 elsif Nkind_In
(P
, N_Subprogram_Body
,
4911 Error_Pragma
("pragma% is not in declarative part or package spec");
4912 end Check_Is_In_Decl_Part_Or_Package_Spec
;
4914 -------------------------
4915 -- Check_No_Identifier --
4916 -------------------------
4918 procedure Check_No_Identifier
(Arg
: Node_Id
) is
4920 if Nkind
(Arg
) = N_Pragma_Argument_Association
4921 and then Chars
(Arg
) /= No_Name
4923 Error_Pragma_Arg_Ident
4924 ("pragma% does not permit identifier& here", Arg
);
4926 end Check_No_Identifier
;
4928 --------------------------
4929 -- Check_No_Identifiers --
4930 --------------------------
4932 procedure Check_No_Identifiers
is
4936 for J
in 1 .. Arg_Count
loop
4937 Check_No_Identifier
(Arg_Node
);
4940 end Check_No_Identifiers
;
4942 ------------------------
4943 -- Check_No_Link_Name --
4944 ------------------------
4946 procedure Check_No_Link_Name
is
4948 if Present
(Arg3
) and then Chars
(Arg3
) = Name_Link_Name
then
4952 if Present
(Arg4
) then
4954 ("Link_Name argument not allowed for Import Intrinsic", Arg4
);
4956 end Check_No_Link_Name
;
4958 -------------------------------
4959 -- Check_Optional_Identifier --
4960 -------------------------------
4962 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: Name_Id
) is
4965 and then Nkind
(Arg
) = N_Pragma_Argument_Association
4966 and then Chars
(Arg
) /= No_Name
4968 if Chars
(Arg
) /= Id
then
4969 Error_Msg_Name_1
:= Pname
;
4970 Error_Msg_Name_2
:= Id
;
4971 Error_Msg_N
("pragma% argument expects identifier%", Arg
);
4975 end Check_Optional_Identifier
;
4977 procedure Check_Optional_Identifier
(Arg
: Node_Id
; Id
: String) is
4979 Name_Buffer
(1 .. Id
'Length) := Id
;
4980 Name_Len
:= Id
'Length;
4981 Check_Optional_Identifier
(Arg
, Name_Find
);
4982 end Check_Optional_Identifier
;
4984 -----------------------------
4985 -- Check_Static_Constraint --
4986 -----------------------------
4988 -- Note: for convenience in writing this procedure, in addition to
4989 -- the officially (i.e. by spec) allowed argument which is always a
4990 -- constraint, it also allows ranges and discriminant associations.
4991 -- Above is not clear ???
4993 procedure Check_Static_Constraint
(Constr
: Node_Id
) is
4995 procedure Require_Static
(E
: Node_Id
);
4996 -- Require given expression to be static expression
4998 --------------------
4999 -- Require_Static --
5000 --------------------
5002 procedure Require_Static
(E
: Node_Id
) is
5004 if not Is_OK_Static_Expression
(E
) then
5005 Flag_Non_Static_Expr
5006 ("non-static constraint not allowed in Unchecked_Union!", E
);
5011 -- Start of processing for Check_Static_Constraint
5014 case Nkind
(Constr
) is
5015 when N_Discriminant_Association
=>
5016 Require_Static
(Expression
(Constr
));
5019 Require_Static
(Low_Bound
(Constr
));
5020 Require_Static
(High_Bound
(Constr
));
5022 when N_Attribute_Reference
=>
5023 Require_Static
(Type_Low_Bound
(Etype
(Prefix
(Constr
))));
5024 Require_Static
(Type_High_Bound
(Etype
(Prefix
(Constr
))));
5026 when N_Range_Constraint
=>
5027 Check_Static_Constraint
(Range_Expression
(Constr
));
5029 when N_Index_Or_Discriminant_Constraint
=>
5033 IDC
:= First
(Constraints
(Constr
));
5034 while Present
(IDC
) loop
5035 Check_Static_Constraint
(IDC
);
5043 end Check_Static_Constraint
;
5045 --------------------------------------
5046 -- Check_Valid_Configuration_Pragma --
5047 --------------------------------------
5049 -- A configuration pragma must appear in the context clause of a
5050 -- compilation unit, and only other pragmas may precede it. Note that
5051 -- the test also allows use in a configuration pragma file.
5053 procedure Check_Valid_Configuration_Pragma
is
5055 if not Is_Configuration_Pragma
then
5056 Error_Pragma
("incorrect placement for configuration pragma%");
5058 end Check_Valid_Configuration_Pragma
;
5060 -------------------------------------
5061 -- Check_Valid_Library_Unit_Pragma --
5062 -------------------------------------
5064 procedure Check_Valid_Library_Unit_Pragma
is
5066 Parent_Node
: Node_Id
;
5067 Unit_Name
: Entity_Id
;
5068 Unit_Kind
: Node_Kind
;
5069 Unit_Node
: Node_Id
;
5070 Sindex
: Source_File_Index
;
5073 if not Is_List_Member
(N
) then
5077 Plist
:= List_Containing
(N
);
5078 Parent_Node
:= Parent
(Plist
);
5080 if Parent_Node
= Empty
then
5083 -- Case of pragma appearing after a compilation unit. In this case
5084 -- it must have an argument with the corresponding name and must
5085 -- be part of the following pragmas of its parent.
5087 elsif Nkind
(Parent_Node
) = N_Compilation_Unit_Aux
then
5088 if Plist
/= Pragmas_After
(Parent_Node
) then
5091 elsif Arg_Count
= 0 then
5093 ("argument required if outside compilation unit");
5096 Check_No_Identifiers
;
5097 Check_Arg_Count
(1);
5098 Unit_Node
:= Unit
(Parent
(Parent_Node
));
5099 Unit_Kind
:= Nkind
(Unit_Node
);
5101 Analyze
(Get_Pragma_Arg
(Arg1
));
5103 if Unit_Kind
= N_Generic_Subprogram_Declaration
5104 or else Unit_Kind
= N_Subprogram_Declaration
5106 Unit_Name
:= Defining_Entity
(Unit_Node
);
5108 elsif Unit_Kind
in N_Generic_Instantiation
then
5109 Unit_Name
:= Defining_Entity
(Unit_Node
);
5112 Unit_Name
:= Cunit_Entity
(Current_Sem_Unit
);
5115 if Chars
(Unit_Name
) /=
5116 Chars
(Entity
(Get_Pragma_Arg
(Arg1
)))
5119 ("pragma% argument is not current unit name", Arg1
);
5122 if Ekind
(Unit_Name
) = E_Package
5123 and then Present
(Renamed_Entity
(Unit_Name
))
5125 Error_Pragma
("pragma% not allowed for renamed package");
5129 -- Pragma appears other than after a compilation unit
5132 -- Here we check for the generic instantiation case and also
5133 -- for the case of processing a generic formal package. We
5134 -- detect these cases by noting that the Sloc on the node
5135 -- does not belong to the current compilation unit.
5137 Sindex
:= Source_Index
(Current_Sem_Unit
);
5139 if Loc
not in Source_First
(Sindex
) .. Source_Last
(Sindex
) then
5140 Rewrite
(N
, Make_Null_Statement
(Loc
));
5143 -- If before first declaration, the pragma applies to the
5144 -- enclosing unit, and the name if present must be this name.
5146 elsif Is_Before_First_Decl
(N
, Plist
) then
5147 Unit_Node
:= Unit_Declaration_Node
(Current_Scope
);
5148 Unit_Kind
:= Nkind
(Unit_Node
);
5150 if Nkind
(Parent
(Unit_Node
)) /= N_Compilation_Unit
then
5153 elsif Unit_Kind
= N_Subprogram_Body
5154 and then not Acts_As_Spec
(Unit_Node
)
5158 elsif Nkind
(Parent_Node
) = N_Package_Body
then
5161 elsif Nkind
(Parent_Node
) = N_Package_Specification
5162 and then Plist
= Private_Declarations
(Parent_Node
)
5166 elsif (Nkind
(Parent_Node
) = N_Generic_Package_Declaration
5167 or else Nkind
(Parent_Node
) =
5168 N_Generic_Subprogram_Declaration
)
5169 and then Plist
= Generic_Formal_Declarations
(Parent_Node
)
5173 elsif Arg_Count
> 0 then
5174 Analyze
(Get_Pragma_Arg
(Arg1
));
5176 if Entity
(Get_Pragma_Arg
(Arg1
)) /= Current_Scope
then
5178 ("name in pragma% must be enclosing unit", Arg1
);
5181 -- It is legal to have no argument in this context
5187 -- Error if not before first declaration. This is because a
5188 -- library unit pragma argument must be the name of a library
5189 -- unit (RM 10.1.5(7)), but the only names permitted in this
5190 -- context are (RM 10.1.5(6)) names of subprogram declarations,
5191 -- generic subprogram declarations or generic instantiations.
5195 ("pragma% misplaced, must be before first declaration");
5199 end Check_Valid_Library_Unit_Pragma
;
5205 procedure Check_Variant
(Variant
: Node_Id
; UU_Typ
: Entity_Id
) is
5206 Clist
: constant Node_Id
:= Component_List
(Variant
);
5210 Comp
:= First
(Component_Items
(Clist
));
5211 while Present
(Comp
) loop
5212 Check_Component
(Comp
, UU_Typ
, In_Variant_Part
=> True);
5217 -----------------------------
5218 -- Create_Generic_Template --
5219 -----------------------------
5221 procedure Create_Generic_Template
5223 Subp_Id
: Entity_Id
)
5226 if Comes_From_Source
(Prag
)
5227 and then Is_Generic_Subprogram
(Subp_Id
)
5230 (Prag
, Copy_Generic_Node
(Prag
, Empty
, Instantiating
=> False));
5232 end Create_Generic_Template
;
5234 ---------------------------
5235 -- Ensure_Aggregate_Form --
5236 ---------------------------
5238 procedure Ensure_Aggregate_Form
(Arg
: Node_Id
) is
5239 CFSD
: constant Boolean := Get_Comes_From_Source_Default
;
5240 Expr
: constant Node_Id
:= Expression
(Arg
);
5241 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5242 Comps
: List_Id
:= No_List
;
5243 Exprs
: List_Id
:= No_List
;
5244 Nam
: Name_Id
:= No_Name
;
5245 Nam_Loc
: Source_Ptr
;
5248 -- The pragma argument is in positional form:
5250 -- pragma Depends (Nam => ...)
5254 -- Note that the Sloc of the Chars field is the Sloc of the pragma
5255 -- argument association.
5257 if Nkind
(Arg
) = N_Pragma_Argument_Association
then
5259 Nam_Loc
:= Sloc
(Arg
);
5261 -- Remove the pragma argument name as this will be captured in the
5264 Set_Chars
(Arg
, No_Name
);
5267 -- The argument is already in aggregate form, but the presence of a
5268 -- name causes this to be interpreted as named association which in
5269 -- turn must be converted into an aggregate.
5271 -- pragma Global (In_Out => (A, B, C))
5275 -- pragma Global ((In_Out => (A, B, C)))
5277 -- aggregate aggregate
5279 if Nkind
(Expr
) = N_Aggregate
then
5280 if Nam
= No_Name
then
5284 -- Do not transform a null argument into an aggregate as N_Null has
5285 -- special meaning in formal verification pragmas.
5287 elsif Nkind
(Expr
) = N_Null
then
5291 -- Everything comes from source if the original comes from source
5293 Set_Comes_From_Source_Default
(Comes_From_Source
(Arg
));
5295 -- Positional argument is transformed into an aggregate with an
5296 -- Expressions list.
5298 if Nam
= No_Name
then
5299 Exprs
:= New_List
(Relocate_Node
(Expr
));
5301 -- An associative argument is transformed into an aggregate with
5302 -- Component_Associations.
5306 Make_Component_Association
(Loc
,
5307 Choices
=> New_List
(Make_Identifier
(Nam_Loc
, Nam
)),
5308 Expression
=> Relocate_Node
(Expr
)));
5311 Set_Expression
(Arg
,
5312 Make_Aggregate
(Loc
,
5313 Component_Associations
=> Comps
,
5314 Expressions
=> Exprs
));
5316 -- Restore Comes_From_Source default
5318 Set_Comes_From_Source_Default
(CFSD
);
5319 end Ensure_Aggregate_Form
;
5325 procedure Error_Pragma
(Msg
: String) is
5327 Error_Msg_Name_1
:= Pname
;
5328 Error_Msg_N
(Fix_Error
(Msg
), N
);
5332 ----------------------
5333 -- Error_Pragma_Arg --
5334 ----------------------
5336 procedure Error_Pragma_Arg
(Msg
: String; Arg
: Node_Id
) is
5338 Error_Msg_Name_1
:= Pname
;
5339 Error_Msg_N
(Fix_Error
(Msg
), Get_Pragma_Arg
(Arg
));
5341 end Error_Pragma_Arg
;
5343 procedure Error_Pragma_Arg
(Msg1
, Msg2
: String; Arg
: Node_Id
) is
5345 Error_Msg_Name_1
:= Pname
;
5346 Error_Msg_N
(Fix_Error
(Msg1
), Get_Pragma_Arg
(Arg
));
5347 Error_Pragma_Arg
(Msg2
, Arg
);
5348 end Error_Pragma_Arg
;
5350 ----------------------------
5351 -- Error_Pragma_Arg_Ident --
5352 ----------------------------
5354 procedure Error_Pragma_Arg_Ident
(Msg
: String; Arg
: Node_Id
) is
5356 Error_Msg_Name_1
:= Pname
;
5357 Error_Msg_N
(Fix_Error
(Msg
), Arg
);
5359 end Error_Pragma_Arg_Ident
;
5361 ----------------------
5362 -- Error_Pragma_Ref --
5363 ----------------------
5365 procedure Error_Pragma_Ref
(Msg
: String; Ref
: Entity_Id
) is
5367 Error_Msg_Name_1
:= Pname
;
5368 Error_Msg_Sloc
:= Sloc
(Ref
);
5369 Error_Msg_NE
(Fix_Error
(Msg
), N
, Ref
);
5371 end Error_Pragma_Ref
;
5373 ------------------------
5374 -- Find_Lib_Unit_Name --
5375 ------------------------
5377 function Find_Lib_Unit_Name
return Entity_Id
is
5379 -- Return inner compilation unit entity, for case of nested
5380 -- categorization pragmas. This happens in generic unit.
5382 if Nkind
(Parent
(N
)) = N_Package_Specification
5383 and then Defining_Entity
(Parent
(N
)) /= Current_Scope
5385 return Defining_Entity
(Parent
(N
));
5387 return Current_Scope
;
5389 end Find_Lib_Unit_Name
;
5391 ----------------------------
5392 -- Find_Program_Unit_Name --
5393 ----------------------------
5395 procedure Find_Program_Unit_Name
(Id
: Node_Id
) is
5396 Unit_Name
: Entity_Id
;
5397 Unit_Kind
: Node_Kind
;
5398 P
: constant Node_Id
:= Parent
(N
);
5401 if Nkind
(P
) = N_Compilation_Unit
then
5402 Unit_Kind
:= Nkind
(Unit
(P
));
5404 if Nkind_In
(Unit_Kind
, N_Subprogram_Declaration
,
5405 N_Package_Declaration
)
5406 or else Unit_Kind
in N_Generic_Declaration
5408 Unit_Name
:= Defining_Entity
(Unit
(P
));
5410 if Chars
(Id
) = Chars
(Unit_Name
) then
5411 Set_Entity
(Id
, Unit_Name
);
5412 Set_Etype
(Id
, Etype
(Unit_Name
));
5414 Set_Etype
(Id
, Any_Type
);
5416 ("cannot find program unit referenced by pragma%");
5420 Set_Etype
(Id
, Any_Type
);
5421 Error_Pragma
("pragma% inapplicable to this unit");
5427 end Find_Program_Unit_Name
;
5429 -----------------------------------------
5430 -- Find_Unique_Parameterless_Procedure --
5431 -----------------------------------------
5433 function Find_Unique_Parameterless_Procedure
5435 Arg
: Node_Id
) return Entity_Id
5437 Proc
: Entity_Id
:= Empty
;
5440 -- The body of this procedure needs some comments ???
5442 if not Is_Entity_Name
(Name
) then
5444 ("argument of pragma% must be entity name", Arg
);
5446 elsif not Is_Overloaded
(Name
) then
5447 Proc
:= Entity
(Name
);
5449 if Ekind
(Proc
) /= E_Procedure
5450 or else Present
(First_Formal
(Proc
))
5453 ("argument of pragma% must be parameterless procedure", Arg
);
5458 Found
: Boolean := False;
5460 Index
: Interp_Index
;
5463 Get_First_Interp
(Name
, Index
, It
);
5464 while Present
(It
.Nam
) loop
5467 if Ekind
(Proc
) = E_Procedure
5468 and then No
(First_Formal
(Proc
))
5472 Set_Entity
(Name
, Proc
);
5473 Set_Is_Overloaded
(Name
, False);
5476 ("ambiguous handler name for pragma% ", Arg
);
5480 Get_Next_Interp
(Index
, It
);
5485 ("argument of pragma% must be parameterless procedure",
5488 Proc
:= Entity
(Name
);
5494 end Find_Unique_Parameterless_Procedure
;
5500 function Fix_Error
(Msg
: String) return String is
5501 Res
: String (Msg
'Range) := Msg
;
5502 Res_Last
: Natural := Msg
'Last;
5506 -- If we have a rewriting of another pragma, go to that pragma
5508 if Is_Rewrite_Substitution
(N
)
5509 and then Nkind
(Original_Node
(N
)) = N_Pragma
5511 Error_Msg_Name_1
:= Pragma_Name
(Original_Node
(N
));
5514 -- Case where pragma comes from an aspect specification
5516 if From_Aspect_Specification
(N
) then
5518 -- Change appearence of "pragma" in message to "aspect"
5521 while J
<= Res_Last
- 5 loop
5522 if Res
(J
.. J
+ 5) = "pragma" then
5523 Res
(J
.. J
+ 5) := "aspect";
5531 -- Change "argument of" at start of message to "entity for"
5534 and then Res
(Res
'First .. Res
'First + 10) = "argument of"
5536 Res
(Res
'First .. Res
'First + 9) := "entity for";
5537 Res
(Res
'First + 10 .. Res_Last
- 1) :=
5538 Res
(Res
'First + 11 .. Res_Last
);
5539 Res_Last
:= Res_Last
- 1;
5542 -- Change "argument" at start of message to "entity"
5545 and then Res
(Res
'First .. Res
'First + 7) = "argument"
5547 Res
(Res
'First .. Res
'First + 5) := "entity";
5548 Res
(Res
'First + 6 .. Res_Last
- 2) :=
5549 Res
(Res
'First + 8 .. Res_Last
);
5550 Res_Last
:= Res_Last
- 2;
5553 -- Get name from corresponding aspect
5555 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(N
);
5558 -- Return possibly modified message
5560 return Res
(Res
'First .. Res_Last
);
5563 -------------------------
5564 -- Gather_Associations --
5565 -------------------------
5567 procedure Gather_Associations
5569 Args
: out Args_List
)
5574 -- Initialize all parameters to Empty
5576 for J
in Args
'Range loop
5580 -- That's all we have to do if there are no argument associations
5582 if No
(Pragma_Argument_Associations
(N
)) then
5586 -- Otherwise first deal with any positional parameters present
5588 Arg
:= First
(Pragma_Argument_Associations
(N
));
5589 for Index
in Args
'Range loop
5590 exit when No
(Arg
) or else Chars
(Arg
) /= No_Name
;
5591 Args
(Index
) := Get_Pragma_Arg
(Arg
);
5595 -- Positional parameters all processed, if any left, then we
5596 -- have too many positional parameters.
5598 if Present
(Arg
) and then Chars
(Arg
) = No_Name
then
5600 ("too many positional associations for pragma%", Arg
);
5603 -- Process named parameters if any are present
5605 while Present
(Arg
) loop
5606 if Chars
(Arg
) = No_Name
then
5608 ("positional association cannot follow named association",
5612 for Index
in Names
'Range loop
5613 if Names
(Index
) = Chars
(Arg
) then
5614 if Present
(Args
(Index
)) then
5616 ("duplicate argument association for pragma%", Arg
);
5618 Args
(Index
) := Get_Pragma_Arg
(Arg
);
5623 if Index
= Names
'Last then
5624 Error_Msg_Name_1
:= Pname
;
5625 Error_Msg_N
("pragma% does not allow & argument", Arg
);
5627 -- Check for possible misspelling
5629 for Index1
in Names
'Range loop
5630 if Is_Bad_Spelling_Of
5631 (Chars
(Arg
), Names
(Index1
))
5633 Error_Msg_Name_1
:= Names
(Index1
);
5634 Error_Msg_N
-- CODEFIX
5635 ("\possible misspelling of%", Arg
);
5647 end Gather_Associations
;
5653 procedure GNAT_Pragma
is
5655 -- We need to check the No_Implementation_Pragmas restriction for
5656 -- the case of a pragma from source. Note that the case of aspects
5657 -- generating corresponding pragmas marks these pragmas as not being
5658 -- from source, so this test also catches that case.
5660 if Comes_From_Source
(N
) then
5661 Check_Restriction
(No_Implementation_Pragmas
, N
);
5665 --------------------------
5666 -- Is_Before_First_Decl --
5667 --------------------------
5669 function Is_Before_First_Decl
5670 (Pragma_Node
: Node_Id
;
5671 Decls
: List_Id
) return Boolean
5673 Item
: Node_Id
:= First
(Decls
);
5676 -- Only other pragmas can come before this pragma
5679 if No
(Item
) or else Nkind
(Item
) /= N_Pragma
then
5682 elsif Item
= Pragma_Node
then
5688 end Is_Before_First_Decl
;
5690 -----------------------------
5691 -- Is_Configuration_Pragma --
5692 -----------------------------
5694 -- A configuration pragma must appear in the context clause of a
5695 -- compilation unit, and only other pragmas may precede it. Note that
5696 -- the test below also permits use in a configuration pragma file.
5698 function Is_Configuration_Pragma
return Boolean is
5699 Lis
: constant List_Id
:= List_Containing
(N
);
5700 Par
: constant Node_Id
:= Parent
(N
);
5704 -- If no parent, then we are in the configuration pragma file,
5705 -- so the placement is definitely appropriate.
5710 -- Otherwise we must be in the context clause of a compilation unit
5711 -- and the only thing allowed before us in the context list is more
5712 -- configuration pragmas.
5714 elsif Nkind
(Par
) = N_Compilation_Unit
5715 and then Context_Items
(Par
) = Lis
5722 elsif Nkind
(Prg
) /= N_Pragma
then
5732 end Is_Configuration_Pragma
;
5734 --------------------------
5735 -- Is_In_Context_Clause --
5736 --------------------------
5738 function Is_In_Context_Clause
return Boolean is
5740 Parent_Node
: Node_Id
;
5743 if not Is_List_Member
(N
) then
5747 Plist
:= List_Containing
(N
);
5748 Parent_Node
:= Parent
(Plist
);
5750 if Parent_Node
= Empty
5751 or else Nkind
(Parent_Node
) /= N_Compilation_Unit
5752 or else Context_Items
(Parent_Node
) /= Plist
5759 end Is_In_Context_Clause
;
5761 ---------------------------------
5762 -- Is_Static_String_Expression --
5763 ---------------------------------
5765 function Is_Static_String_Expression
(Arg
: Node_Id
) return Boolean is
5766 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
5767 Lit
: constant Boolean := Nkind
(Argx
) = N_String_Literal
;
5770 Analyze_And_Resolve
(Argx
);
5772 -- Special case Ada 83, where the expression will never be static,
5773 -- but we will return true if we had a string literal to start with.
5775 if Ada_Version
= Ada_83
then
5778 -- Normal case, true only if we end up with a string literal that
5779 -- is marked as being the result of evaluating a static expression.
5782 return Is_OK_Static_Expression
(Argx
)
5783 and then Nkind
(Argx
) = N_String_Literal
;
5786 end Is_Static_String_Expression
;
5788 ----------------------
5789 -- Pragma_Misplaced --
5790 ----------------------
5792 procedure Pragma_Misplaced
is
5794 Error_Pragma
("incorrect placement of pragma%");
5795 end Pragma_Misplaced
;
5797 ------------------------------------------------
5798 -- Process_Atomic_Independent_Shared_Volatile --
5799 ------------------------------------------------
5801 procedure Process_Atomic_Independent_Shared_Volatile
is
5808 procedure Set_Atomic
(E
: Entity_Id
);
5809 -- Set given type as atomic, and if no explicit alignment was given,
5810 -- set alignment to unknown, since back end knows what the alignment
5811 -- requirements are for atomic arrays. Note: this step is necessary
5812 -- for derived types.
5818 procedure Set_Atomic
(E
: Entity_Id
) is
5822 if not Has_Alignment_Clause
(E
) then
5823 Set_Alignment
(E
, Uint_0
);
5827 -- Start of processing for Process_Atomic_Independent_Shared_Volatile
5830 Check_Ada_83_Warning
;
5831 Check_No_Identifiers
;
5832 Check_Arg_Count
(1);
5833 Check_Arg_Is_Local_Name
(Arg1
);
5834 E_Id
:= Get_Pragma_Arg
(Arg1
);
5836 if Etype
(E_Id
) = Any_Type
then
5841 D
:= Declaration_Node
(E
);
5844 -- Check duplicate before we chain ourselves
5846 Check_Duplicate_Pragma
(E
);
5848 -- Now check appropriateness of the entity
5851 if Rep_Item_Too_Early
(E
, N
)
5853 Rep_Item_Too_Late
(E
, N
)
5857 Check_First_Subtype
(Arg1
);
5860 if Prag_Id
= Pragma_Atomic
or else Prag_Id
= Pragma_Shared
then
5862 Set_Atomic
(Underlying_Type
(E
));
5863 Set_Atomic
(Base_Type
(E
));
5866 -- Atomic/Shared imply both Independent and Volatile
5868 if Prag_Id
/= Pragma_Volatile
then
5869 Set_Is_Independent
(E
);
5870 Set_Is_Independent
(Underlying_Type
(E
));
5871 Set_Is_Independent
(Base_Type
(E
));
5873 if Prag_Id
= Pragma_Independent
then
5874 Record_Independence_Check
(N
, Base_Type
(E
));
5878 -- Attribute belongs on the base type. If the view of the type is
5879 -- currently private, it also belongs on the underlying type.
5881 if Prag_Id
/= Pragma_Independent
then
5882 Set_Is_Volatile
(Base_Type
(E
));
5883 Set_Is_Volatile
(Underlying_Type
(E
));
5885 Set_Treat_As_Volatile
(E
);
5886 Set_Treat_As_Volatile
(Underlying_Type
(E
));
5889 elsif K
= N_Object_Declaration
5890 or else (K
= N_Component_Declaration
5891 and then Original_Record_Component
(E
) = E
)
5893 if Rep_Item_Too_Late
(E
, N
) then
5897 if Prag_Id
= Pragma_Atomic
or else Prag_Id
= Pragma_Shared
then
5900 -- If the object declaration has an explicit initialization, a
5901 -- temporary may have to be created to hold the expression, to
5902 -- ensure that access to the object remain atomic.
5904 if Nkind
(Parent
(E
)) = N_Object_Declaration
5905 and then Present
(Expression
(Parent
(E
)))
5907 Set_Has_Delayed_Freeze
(E
);
5910 -- An interesting improvement here. If an object of composite
5911 -- type X is declared atomic, and the type X isn't, that's a
5912 -- pity, since it may not have appropriate alignment etc. We
5913 -- can rescue this in the special case where the object and
5914 -- type are in the same unit by just setting the type as
5915 -- atomic, so that the back end will process it as atomic.
5917 -- Note: we used to do this for elementary types as well,
5918 -- but that turns out to be a bad idea and can have unwanted
5919 -- effects, most notably if the type is elementary, the object
5920 -- a simple component within a record, and both are in a spec:
5921 -- every object of this type in the entire program will be
5922 -- treated as atomic, thus incurring a potentially costly
5923 -- synchronization operation for every access.
5925 -- Of course it would be best if the back end could just adjust
5926 -- the alignment etc for the specific object, but that's not
5927 -- something we are capable of doing at this point.
5929 Utyp
:= Underlying_Type
(Etype
(E
));
5932 and then Is_Composite_Type
(Utyp
)
5933 and then Sloc
(E
) > No_Location
5934 and then Sloc
(Utyp
) > No_Location
5936 Get_Source_File_Index
(Sloc
(E
)) =
5937 Get_Source_File_Index
(Sloc
(Underlying_Type
(Etype
(E
))))
5939 Set_Is_Atomic
(Underlying_Type
(Etype
(E
)));
5943 -- Atomic/Shared imply both Independent and Volatile
5945 if Prag_Id
/= Pragma_Volatile
then
5946 Set_Is_Independent
(E
);
5948 if Prag_Id
= Pragma_Independent
then
5949 Record_Independence_Check
(N
, E
);
5953 if Prag_Id
/= Pragma_Independent
then
5954 Set_Is_Volatile
(E
);
5955 Set_Treat_As_Volatile
(E
);
5959 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
5962 -- The following check is only relevant when SPARK_Mode is on as
5963 -- this is not a standard Ada legality rule. Pragma Volatile can
5964 -- only apply to a full type declaration or an object declaration
5965 -- (SPARK RM C.6(1)).
5968 and then Prag_Id
= Pragma_Volatile
5969 and then not Nkind_In
(K
, N_Full_Type_Declaration
,
5970 N_Object_Declaration
)
5973 ("argument of pragma % must denote a full type or object "
5974 & "declaration", Arg1
);
5976 end Process_Atomic_Independent_Shared_Volatile
;
5978 -------------------------------------------
5979 -- Process_Compile_Time_Warning_Or_Error --
5980 -------------------------------------------
5982 procedure Process_Compile_Time_Warning_Or_Error
is
5983 Arg1x
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
5986 Check_Arg_Count
(2);
5987 Check_No_Identifiers
;
5988 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
5989 Analyze_And_Resolve
(Arg1x
, Standard_Boolean
);
5991 if Compile_Time_Known_Value
(Arg1x
) then
5992 if Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
))) then
5994 Str
: constant String_Id
:=
5995 Strval
(Get_Pragma_Arg
(Arg2
));
5996 Len
: constant Int
:= String_Length
(Str
);
6001 Cent
: constant Entity_Id
:=
6002 Cunit_Entity
(Current_Sem_Unit
);
6004 Force
: constant Boolean :=
6005 Prag_Id
= Pragma_Compile_Time_Warning
6007 Is_Spec_Name
(Unit_Name
(Current_Sem_Unit
))
6008 and then (Ekind
(Cent
) /= E_Package
6009 or else not In_Private_Part
(Cent
));
6010 -- Set True if this is the warning case, and we are in the
6011 -- visible part of a package spec, or in a subprogram spec,
6012 -- in which case we want to force the client to see the
6013 -- warning, even though it is not in the main unit.
6016 -- Loop through segments of message separated by line feeds.
6017 -- We output these segments as separate messages with
6018 -- continuation marks for all but the first.
6023 Error_Msg_Strlen
:= 0;
6025 -- Loop to copy characters from argument to error message
6029 exit when Ptr
> Len
;
6030 CC
:= Get_String_Char
(Str
, Ptr
);
6033 -- Ignore wide chars ??? else store character
6035 if In_Character_Range
(CC
) then
6036 C
:= Get_Character
(CC
);
6037 exit when C
= ASCII
.LF
;
6038 Error_Msg_Strlen
:= Error_Msg_Strlen
+ 1;
6039 Error_Msg_String
(Error_Msg_Strlen
) := C
;
6043 -- Here with one line ready to go
6045 Error_Msg_Warn
:= Prag_Id
= Pragma_Compile_Time_Warning
;
6047 -- If this is a warning in a spec, then we want clients
6048 -- to see the warning, so mark the message with the
6049 -- special sequence !! to force the warning. In the case
6050 -- of a package spec, we do not force this if we are in
6051 -- the private part of the spec.
6054 if Cont
= False then
6055 Error_Msg_N
("<<~!!", Arg1
);
6058 Error_Msg_N
("\<<~!!", Arg1
);
6061 -- Error, rather than warning, or in a body, so we do not
6062 -- need to force visibility for client (error will be
6063 -- output in any case, and this is the situation in which
6064 -- we do not want a client to get a warning, since the
6065 -- warning is in the body or the spec private part).
6068 if Cont
= False then
6069 Error_Msg_N
("<<~", Arg1
);
6072 Error_Msg_N
("\<<~", Arg1
);
6076 exit when Ptr
> Len
;
6081 end Process_Compile_Time_Warning_Or_Error
;
6083 ------------------------
6084 -- Process_Convention --
6085 ------------------------
6087 procedure Process_Convention
6088 (C
: out Convention_Id
;
6089 Ent
: out Entity_Id
)
6093 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
);
6094 -- Called if we have more than one Export/Import/Convention pragma.
6095 -- This is generally illegal, but we have a special case of allowing
6096 -- Import and Interface to coexist if they specify the convention in
6097 -- a consistent manner. We are allowed to do this, since Interface is
6098 -- an implementation defined pragma, and we choose to do it since we
6099 -- know Rational allows this combination. S is the entity id of the
6100 -- subprogram in question. This procedure also sets the special flag
6101 -- Import_Interface_Present in both pragmas in the case where we do
6102 -- have matching Import and Interface pragmas.
6104 procedure Set_Convention_From_Pragma
(E
: Entity_Id
);
6105 -- Set convention in entity E, and also flag that the entity has a
6106 -- convention pragma. If entity is for a private or incomplete type,
6107 -- also set convention and flag on underlying type. This procedure
6108 -- also deals with the special case of C_Pass_By_Copy convention,
6109 -- and error checks for inappropriate convention specification.
6111 -------------------------------
6112 -- Diagnose_Multiple_Pragmas --
6113 -------------------------------
6115 procedure Diagnose_Multiple_Pragmas
(S
: Entity_Id
) is
6116 Pdec
: constant Node_Id
:= Declaration_Node
(S
);
6120 function Same_Convention
(Decl
: Node_Id
) return Boolean;
6121 -- Decl is a pragma node. This function returns True if this
6122 -- pragma has a first argument that is an identifier with a
6123 -- Chars field corresponding to the Convention_Id C.
6125 function Same_Name
(Decl
: Node_Id
) return Boolean;
6126 -- Decl is a pragma node. This function returns True if this
6127 -- pragma has a second argument that is an identifier with a
6128 -- Chars field that matches the Chars of the current subprogram.
6130 ---------------------
6131 -- Same_Convention --
6132 ---------------------
6134 function Same_Convention
(Decl
: Node_Id
) return Boolean is
6135 Arg1
: constant Node_Id
:=
6136 First
(Pragma_Argument_Associations
(Decl
));
6139 if Present
(Arg1
) then
6141 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
6143 if Nkind
(Arg
) = N_Identifier
6144 and then Is_Convention_Name
(Chars
(Arg
))
6145 and then Get_Convention_Id
(Chars
(Arg
)) = C
6153 end Same_Convention
;
6159 function Same_Name
(Decl
: Node_Id
) return Boolean is
6160 Arg1
: constant Node_Id
:=
6161 First
(Pragma_Argument_Associations
(Decl
));
6169 Arg2
:= Next
(Arg1
);
6176 Arg
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
6178 if Nkind
(Arg
) = N_Identifier
6179 and then Chars
(Arg
) = Chars
(S
)
6188 -- Start of processing for Diagnose_Multiple_Pragmas
6193 -- Definitely give message if we have Convention/Export here
6195 if Prag_Id
= Pragma_Convention
or else Prag_Id
= Pragma_Export
then
6198 -- If we have an Import or Export, scan back from pragma to
6199 -- find any previous pragma applying to the same procedure.
6200 -- The scan will be terminated by the start of the list, or
6201 -- hitting the subprogram declaration. This won't allow one
6202 -- pragma to appear in the public part and one in the private
6203 -- part, but that seems very unlikely in practice.
6207 while Present
(Decl
) and then Decl
/= Pdec
loop
6209 -- Look for pragma with same name as us
6211 if Nkind
(Decl
) = N_Pragma
6212 and then Same_Name
(Decl
)
6214 -- Give error if same as our pragma or Export/Convention
6216 if Nam_In
(Pragma_Name
(Decl
), Name_Export
,
6222 -- Case of Import/Interface or the other way round
6224 elsif Nam_In
(Pragma_Name
(Decl
), Name_Interface
,
6227 -- Here we know that we have Import and Interface. It
6228 -- doesn't matter which way round they are. See if
6229 -- they specify the same convention. If so, all OK,
6230 -- and set special flags to stop other messages
6232 if Same_Convention
(Decl
) then
6233 Set_Import_Interface_Present
(N
);
6234 Set_Import_Interface_Present
(Decl
);
6237 -- If different conventions, special message
6240 Error_Msg_Sloc
:= Sloc
(Decl
);
6242 ("convention differs from that given#", Arg1
);
6252 -- Give message if needed if we fall through those tests
6253 -- except on Relaxed_RM_Semantics where we let go: either this
6254 -- is a case accepted/ignored by other Ada compilers (e.g.
6255 -- a mix of Convention and Import), or another error will be
6256 -- generated later (e.g. using both Import and Export).
6258 if Err
and not Relaxed_RM_Semantics
then
6260 ("at most one Convention/Export/Import pragma is allowed",
6263 end Diagnose_Multiple_Pragmas
;
6265 --------------------------------
6266 -- Set_Convention_From_Pragma --
6267 --------------------------------
6269 procedure Set_Convention_From_Pragma
(E
: Entity_Id
) is
6271 -- Ada 2005 (AI-430): Check invalid attempt to change convention
6272 -- for an overridden dispatching operation. Technically this is
6273 -- an amendment and should only be done in Ada 2005 mode. However,
6274 -- this is clearly a mistake, since the problem that is addressed
6275 -- by this AI is that there is a clear gap in the RM.
6277 if Is_Dispatching_Operation
(E
)
6278 and then Present
(Overridden_Operation
(E
))
6279 and then C
/= Convention
(Overridden_Operation
(E
))
6282 ("cannot change convention for overridden dispatching "
6283 & "operation", Arg1
);
6286 -- Special checks for Convention_Stdcall
6288 if C
= Convention_Stdcall
then
6290 -- A dispatching call is not allowed. A dispatching subprogram
6291 -- cannot be used to interface to the Win32 API, so in fact
6292 -- this check does not impose any effective restriction.
6294 if Is_Dispatching_Operation
(E
) then
6295 Error_Msg_Sloc
:= Sloc
(E
);
6297 -- Note: make this unconditional so that if there is more
6298 -- than one call to which the pragma applies, we get a
6299 -- message for each call. Also don't use Error_Pragma,
6300 -- so that we get multiple messages.
6303 ("dispatching subprogram# cannot use Stdcall convention!",
6306 -- Subprograms are not allowed
6308 elsif not Is_Subprogram_Or_Generic_Subprogram
(E
)
6312 and then Ekind
(E
) /= E_Variable
6314 -- An access to subprogram is also allowed
6318 and then Ekind
(Designated_Type
(E
)) = E_Subprogram_Type
)
6320 -- Allow internal call to set convention of subprogram type
6322 and then not (Ekind
(E
) = E_Subprogram_Type
)
6325 ("second argument of pragma% must be subprogram (type)",
6330 -- Set the convention
6332 Set_Convention
(E
, C
);
6333 Set_Has_Convention_Pragma
(E
);
6335 -- For the case of a record base type, also set the convention of
6336 -- any anonymous access types declared in the record which do not
6337 -- currently have a specified convention.
6339 if Is_Record_Type
(E
) and then Is_Base_Type
(E
) then
6344 Comp
:= First_Component
(E
);
6345 while Present
(Comp
) loop
6346 if Present
(Etype
(Comp
))
6347 and then Ekind_In
(Etype
(Comp
),
6348 E_Anonymous_Access_Type
,
6349 E_Anonymous_Access_Subprogram_Type
)
6350 and then not Has_Convention_Pragma
(Comp
)
6352 Set_Convention
(Comp
, C
);
6355 Next_Component
(Comp
);
6360 -- Deal with incomplete/private type case, where underlying type
6361 -- is available, so set convention of that underlying type.
6363 if Is_Incomplete_Or_Private_Type
(E
)
6364 and then Present
(Underlying_Type
(E
))
6366 Set_Convention
(Underlying_Type
(E
), C
);
6367 Set_Has_Convention_Pragma
(Underlying_Type
(E
), True);
6370 -- A class-wide type should inherit the convention of the specific
6371 -- root type (although this isn't specified clearly by the RM).
6373 if Is_Type
(E
) and then Present
(Class_Wide_Type
(E
)) then
6374 Set_Convention
(Class_Wide_Type
(E
), C
);
6377 -- If the entity is a record type, then check for special case of
6378 -- C_Pass_By_Copy, which is treated the same as C except that the
6379 -- special record flag is set. This convention is only permitted
6380 -- on record types (see AI95-00131).
6382 if Cname
= Name_C_Pass_By_Copy
then
6383 if Is_Record_Type
(E
) then
6384 Set_C_Pass_By_Copy
(Base_Type
(E
));
6385 elsif Is_Incomplete_Or_Private_Type
(E
)
6386 and then Is_Record_Type
(Underlying_Type
(E
))
6388 Set_C_Pass_By_Copy
(Base_Type
(Underlying_Type
(E
)));
6391 ("C_Pass_By_Copy convention allowed only for record type",
6396 -- If the entity is a derived boolean type, check for the special
6397 -- case of convention C, C++, or Fortran, where we consider any
6398 -- nonzero value to represent true.
6400 if Is_Discrete_Type
(E
)
6401 and then Root_Type
(Etype
(E
)) = Standard_Boolean
6407 C
= Convention_Fortran
)
6409 Set_Nonzero_Is_True
(Base_Type
(E
));
6411 end Set_Convention_From_Pragma
;
6415 Comp_Unit
: Unit_Number_Type
;
6420 -- Start of processing for Process_Convention
6423 Check_At_Least_N_Arguments
(2);
6424 Check_Optional_Identifier
(Arg1
, Name_Convention
);
6425 Check_Arg_Is_Identifier
(Arg1
);
6426 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
6428 -- C_Pass_By_Copy is treated as a synonym for convention C (this is
6429 -- tested again below to set the critical flag).
6431 if Cname
= Name_C_Pass_By_Copy
then
6434 -- Otherwise we must have something in the standard convention list
6436 elsif Is_Convention_Name
(Cname
) then
6437 C
:= Get_Convention_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
6439 -- Otherwise warn on unrecognized convention
6442 if Warn_On_Export_Import
then
6444 ("??unrecognized convention name, C assumed",
6445 Get_Pragma_Arg
(Arg1
));
6451 Check_Optional_Identifier
(Arg2
, Name_Entity
);
6452 Check_Arg_Is_Local_Name
(Arg2
);
6454 Id
:= Get_Pragma_Arg
(Arg2
);
6457 if not Is_Entity_Name
(Id
) then
6458 Error_Pragma_Arg
("entity name required", Arg2
);
6463 -- Set entity to return
6467 -- Ada_Pass_By_Copy special checking
6469 if C
= Convention_Ada_Pass_By_Copy
then
6470 if not Is_First_Subtype
(E
) then
6472 ("convention `Ada_Pass_By_Copy` only allowed for types",
6476 if Is_By_Reference_Type
(E
) then
6478 ("convention `Ada_Pass_By_Copy` not allowed for by-reference "
6482 -- Ada_Pass_By_Reference special checking
6484 elsif C
= Convention_Ada_Pass_By_Reference
then
6485 if not Is_First_Subtype
(E
) then
6487 ("convention `Ada_Pass_By_Reference` only allowed for types",
6491 if Is_By_Copy_Type
(E
) then
6493 ("convention `Ada_Pass_By_Reference` not allowed for by-copy "
6498 -- Go to renamed subprogram if present, since convention applies to
6499 -- the actual renamed entity, not to the renaming entity. If the
6500 -- subprogram is inherited, go to parent subprogram.
6502 if Is_Subprogram
(E
)
6503 and then Present
(Alias
(E
))
6505 if Nkind
(Parent
(Declaration_Node
(E
))) =
6506 N_Subprogram_Renaming_Declaration
6508 if Scope
(E
) /= Scope
(Alias
(E
)) then
6510 ("cannot apply pragma% to non-local entity&#", E
);
6515 elsif Nkind_In
(Parent
(E
), N_Full_Type_Declaration
,
6516 N_Private_Extension_Declaration
)
6517 and then Scope
(E
) = Scope
(Alias
(E
))
6521 -- Return the parent subprogram the entity was inherited from
6527 -- Check that we are not applying this to a specless body. Relax this
6528 -- check if Relaxed_RM_Semantics to accomodate other Ada compilers.
6530 if Is_Subprogram
(E
)
6531 and then Nkind
(Parent
(Declaration_Node
(E
))) = N_Subprogram_Body
6532 and then not Relaxed_RM_Semantics
6535 ("pragma% requires separate spec and must come before body");
6538 -- Check that we are not applying this to a named constant
6540 if Ekind_In
(E
, E_Named_Integer
, E_Named_Real
) then
6541 Error_Msg_Name_1
:= Pname
;
6543 ("cannot apply pragma% to named constant!",
6544 Get_Pragma_Arg
(Arg2
));
6546 ("\supply appropriate type for&!", Arg2
);
6549 if Ekind
(E
) = E_Enumeration_Literal
then
6550 Error_Pragma
("enumeration literal not allowed for pragma%");
6553 -- Check for rep item appearing too early or too late
6555 if Etype
(E
) = Any_Type
6556 or else Rep_Item_Too_Early
(E
, N
)
6560 elsif Present
(Underlying_Type
(E
)) then
6561 E
:= Underlying_Type
(E
);
6564 if Rep_Item_Too_Late
(E
, N
) then
6568 if Has_Convention_Pragma
(E
) then
6569 Diagnose_Multiple_Pragmas
(E
);
6571 elsif Convention
(E
) = Convention_Protected
6572 or else Ekind
(Scope
(E
)) = E_Protected_Type
6575 ("a protected operation cannot be given a different convention",
6579 -- For Intrinsic, a subprogram is required
6581 if C
= Convention_Intrinsic
6582 and then not Is_Subprogram_Or_Generic_Subprogram
(E
)
6585 ("second argument of pragma% must be a subprogram", Arg2
);
6588 -- Deal with non-subprogram cases
6590 if not Is_Subprogram_Or_Generic_Subprogram
(E
) then
6591 Set_Convention_From_Pragma
(E
);
6594 Check_First_Subtype
(Arg2
);
6595 Set_Convention_From_Pragma
(Base_Type
(E
));
6597 -- For access subprograms, we must set the convention on the
6598 -- internally generated directly designated type as well.
6600 if Ekind
(E
) = E_Access_Subprogram_Type
then
6601 Set_Convention_From_Pragma
(Directly_Designated_Type
(E
));
6605 -- For the subprogram case, set proper convention for all homonyms
6606 -- in same scope and the same declarative part, i.e. the same
6607 -- compilation unit.
6610 Comp_Unit
:= Get_Source_Unit
(E
);
6611 Set_Convention_From_Pragma
(E
);
6613 -- Treat a pragma Import as an implicit body, and pragma import
6614 -- as implicit reference (for navigation in GPS).
6616 if Prag_Id
= Pragma_Import
then
6617 Generate_Reference
(E
, Id
, 'b');
6619 -- For exported entities we restrict the generation of references
6620 -- to entities exported to foreign languages since entities
6621 -- exported to Ada do not provide further information to GPS and
6622 -- add undesired references to the output of the gnatxref tool.
6624 elsif Prag_Id
= Pragma_Export
6625 and then Convention
(E
) /= Convention_Ada
6627 Generate_Reference
(E
, Id
, 'i');
6630 -- If the pragma comes from from an aspect, it only applies to the
6631 -- given entity, not its homonyms.
6633 if From_Aspect_Specification
(N
) then
6637 -- Otherwise Loop through the homonyms of the pragma argument's
6638 -- entity, an apply convention to those in the current scope.
6644 exit when No
(E1
) or else Scope
(E1
) /= Current_Scope
;
6646 -- Ignore entry for which convention is already set
6648 if Has_Convention_Pragma
(E1
) then
6652 -- Do not set the pragma on inherited operations or on formal
6655 if Comes_From_Source
(E1
)
6656 and then Comp_Unit
= Get_Source_Unit
(E1
)
6657 and then not Is_Formal_Subprogram
(E1
)
6658 and then Nkind
(Original_Node
(Parent
(E1
))) /=
6659 N_Full_Type_Declaration
6661 if Present
(Alias
(E1
))
6662 and then Scope
(E1
) /= Scope
(Alias
(E1
))
6665 ("cannot apply pragma% to non-local entity& declared#",
6669 Set_Convention_From_Pragma
(E1
);
6671 if Prag_Id
= Pragma_Import
then
6672 Generate_Reference
(E1
, Id
, 'b');
6680 end Process_Convention
;
6682 ----------------------------------------
6683 -- Process_Disable_Enable_Atomic_Sync --
6684 ----------------------------------------
6686 procedure Process_Disable_Enable_Atomic_Sync
(Nam
: Name_Id
) is
6688 Check_No_Identifiers
;
6689 Check_At_Most_N_Arguments
(1);
6691 -- Modeled internally as
6692 -- pragma Suppress/Unsuppress (Atomic_Synchronization [,Entity])
6696 Pragma_Identifier
=>
6697 Make_Identifier
(Loc
, Nam
),
6698 Pragma_Argument_Associations
=> New_List
(
6699 Make_Pragma_Argument_Association
(Loc
,
6701 Make_Identifier
(Loc
, Name_Atomic_Synchronization
)))));
6703 if Present
(Arg1
) then
6704 Append_To
(Pragma_Argument_Associations
(N
), New_Copy
(Arg1
));
6708 end Process_Disable_Enable_Atomic_Sync
;
6710 -------------------------------------------------
6711 -- Process_Extended_Import_Export_Internal_Arg --
6712 -------------------------------------------------
6714 procedure Process_Extended_Import_Export_Internal_Arg
6715 (Arg_Internal
: Node_Id
:= Empty
)
6718 if No
(Arg_Internal
) then
6719 Error_Pragma
("Internal parameter required for pragma%");
6722 if Nkind
(Arg_Internal
) = N_Identifier
then
6725 elsif Nkind
(Arg_Internal
) = N_Operator_Symbol
6726 and then (Prag_Id
= Pragma_Import_Function
6728 Prag_Id
= Pragma_Export_Function
)
6734 ("wrong form for Internal parameter for pragma%", Arg_Internal
);
6737 Check_Arg_Is_Local_Name
(Arg_Internal
);
6738 end Process_Extended_Import_Export_Internal_Arg
;
6740 --------------------------------------------------
6741 -- Process_Extended_Import_Export_Object_Pragma --
6742 --------------------------------------------------
6744 procedure Process_Extended_Import_Export_Object_Pragma
6745 (Arg_Internal
: Node_Id
;
6746 Arg_External
: Node_Id
;
6752 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
6753 Def_Id
:= Entity
(Arg_Internal
);
6755 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
6757 ("pragma% must designate an object", Arg_Internal
);
6760 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
6762 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
6765 ("previous Common/Psect_Object applies, pragma % not permitted",
6769 if Rep_Item_Too_Late
(Def_Id
, N
) then
6773 Set_Extended_Import_Export_External_Name
(Def_Id
, Arg_External
);
6775 if Present
(Arg_Size
) then
6776 Check_Arg_Is_External_Name
(Arg_Size
);
6779 -- Export_Object case
6781 if Prag_Id
= Pragma_Export_Object
then
6782 if not Is_Library_Level_Entity
(Def_Id
) then
6784 ("argument for pragma% must be library level entity",
6788 if Ekind
(Current_Scope
) = E_Generic_Package
then
6789 Error_Pragma
("pragma& cannot appear in a generic unit");
6792 if not Size_Known_At_Compile_Time
(Etype
(Def_Id
)) then
6794 ("exported object must have compile time known size",
6798 if Warn_On_Export_Import
and then Is_Exported
(Def_Id
) then
6799 Error_Msg_N
("??duplicate Export_Object pragma", N
);
6801 Set_Exported
(Def_Id
, Arg_Internal
);
6804 -- Import_Object case
6807 if Is_Concurrent_Type
(Etype
(Def_Id
)) then
6809 ("cannot use pragma% for task/protected object",
6813 if Ekind
(Def_Id
) = E_Constant
then
6815 ("cannot import a constant", Arg_Internal
);
6818 if Warn_On_Export_Import
6819 and then Has_Discriminants
(Etype
(Def_Id
))
6822 ("imported value must be initialized??", Arg_Internal
);
6825 if Warn_On_Export_Import
6826 and then Is_Access_Type
(Etype
(Def_Id
))
6829 ("cannot import object of an access type??", Arg_Internal
);
6832 if Warn_On_Export_Import
6833 and then Is_Imported
(Def_Id
)
6835 Error_Msg_N
("??duplicate Import_Object pragma", N
);
6837 -- Check for explicit initialization present. Note that an
6838 -- initialization generated by the code generator, e.g. for an
6839 -- access type, does not count here.
6841 elsif Present
(Expression
(Parent
(Def_Id
)))
6844 (Original_Node
(Expression
(Parent
(Def_Id
))))
6846 Error_Msg_Sloc
:= Sloc
(Def_Id
);
6848 ("imported entities cannot be initialized (RM B.1(24))",
6849 "\no initialization allowed for & declared#", Arg1
);
6851 Set_Imported
(Def_Id
);
6852 Note_Possible_Modification
(Arg_Internal
, Sure
=> False);
6855 end Process_Extended_Import_Export_Object_Pragma
;
6857 ------------------------------------------------------
6858 -- Process_Extended_Import_Export_Subprogram_Pragma --
6859 ------------------------------------------------------
6861 procedure Process_Extended_Import_Export_Subprogram_Pragma
6862 (Arg_Internal
: Node_Id
;
6863 Arg_External
: Node_Id
;
6864 Arg_Parameter_Types
: Node_Id
;
6865 Arg_Result_Type
: Node_Id
:= Empty
;
6866 Arg_Mechanism
: Node_Id
;
6867 Arg_Result_Mechanism
: Node_Id
:= Empty
)
6873 Ambiguous
: Boolean;
6876 function Same_Base_Type
6878 Formal
: Entity_Id
) return Boolean;
6879 -- Determines if Ptype references the type of Formal. Note that only
6880 -- the base types need to match according to the spec. Ptype here is
6881 -- the argument from the pragma, which is either a type name, or an
6882 -- access attribute.
6884 --------------------
6885 -- Same_Base_Type --
6886 --------------------
6888 function Same_Base_Type
6890 Formal
: Entity_Id
) return Boolean
6892 Ftyp
: constant Entity_Id
:= Base_Type
(Etype
(Formal
));
6896 -- Case where pragma argument is typ'Access
6898 if Nkind
(Ptype
) = N_Attribute_Reference
6899 and then Attribute_Name
(Ptype
) = Name_Access
6901 Pref
:= Prefix
(Ptype
);
6904 if not Is_Entity_Name
(Pref
)
6905 or else Entity
(Pref
) = Any_Type
6910 -- We have a match if the corresponding argument is of an
6911 -- anonymous access type, and its designated type matches the
6912 -- type of the prefix of the access attribute
6914 return Ekind
(Ftyp
) = E_Anonymous_Access_Type
6915 and then Base_Type
(Entity
(Pref
)) =
6916 Base_Type
(Etype
(Designated_Type
(Ftyp
)));
6918 -- Case where pragma argument is a type name
6923 if not Is_Entity_Name
(Ptype
)
6924 or else Entity
(Ptype
) = Any_Type
6929 -- We have a match if the corresponding argument is of the type
6930 -- given in the pragma (comparing base types)
6932 return Base_Type
(Entity
(Ptype
)) = Ftyp
;
6936 -- Start of processing for
6937 -- Process_Extended_Import_Export_Subprogram_Pragma
6940 Process_Extended_Import_Export_Internal_Arg
(Arg_Internal
);
6944 -- Loop through homonyms (overloadings) of the entity
6946 Hom_Id
:= Entity
(Arg_Internal
);
6947 while Present
(Hom_Id
) loop
6948 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
6950 -- We need a subprogram in the current scope
6952 if not Is_Subprogram
(Def_Id
)
6953 or else Scope
(Def_Id
) /= Current_Scope
6960 -- Pragma cannot apply to subprogram body
6962 if Is_Subprogram
(Def_Id
)
6963 and then Nkind
(Parent
(Declaration_Node
(Def_Id
))) =
6967 ("pragma% requires separate spec"
6968 & " and must come before body");
6971 -- Test result type if given, note that the result type
6972 -- parameter can only be present for the function cases.
6974 if Present
(Arg_Result_Type
)
6975 and then not Same_Base_Type
(Arg_Result_Type
, Def_Id
)
6979 elsif Etype
(Def_Id
) /= Standard_Void_Type
6981 Nam_In
(Pname
, Name_Export_Procedure
, Name_Import_Procedure
)
6985 -- Test parameter types if given. Note that this parameter
6986 -- has not been analyzed (and must not be, since it is
6987 -- semantic nonsense), so we get it as the parser left it.
6989 elsif Present
(Arg_Parameter_Types
) then
6990 Check_Matching_Types
: declare
6995 Formal
:= First_Formal
(Def_Id
);
6997 if Nkind
(Arg_Parameter_Types
) = N_Null
then
6998 if Present
(Formal
) then
7002 -- A list of one type, e.g. (List) is parsed as
7003 -- a parenthesized expression.
7005 elsif Nkind
(Arg_Parameter_Types
) /= N_Aggregate
7006 and then Paren_Count
(Arg_Parameter_Types
) = 1
7009 or else Present
(Next_Formal
(Formal
))
7014 Same_Base_Type
(Arg_Parameter_Types
, Formal
);
7017 -- A list of more than one type is parsed as a aggregate
7019 elsif Nkind
(Arg_Parameter_Types
) = N_Aggregate
7020 and then Paren_Count
(Arg_Parameter_Types
) = 0
7022 Ptype
:= First
(Expressions
(Arg_Parameter_Types
));
7023 while Present
(Ptype
) or else Present
(Formal
) loop
7026 or else not Same_Base_Type
(Ptype
, Formal
)
7031 Next_Formal
(Formal
);
7036 -- Anything else is of the wrong form
7040 ("wrong form for Parameter_Types parameter",
7041 Arg_Parameter_Types
);
7043 end Check_Matching_Types
;
7046 -- Match is now False if the entry we found did not match
7047 -- either a supplied Parameter_Types or Result_Types argument
7053 -- Ambiguous case, the flag Ambiguous shows if we already
7054 -- detected this and output the initial messages.
7057 if not Ambiguous
then
7059 Error_Msg_Name_1
:= Pname
;
7061 ("pragma% does not uniquely identify subprogram!",
7063 Error_Msg_Sloc
:= Sloc
(Ent
);
7064 Error_Msg_N
("matching subprogram #!", N
);
7068 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7069 Error_Msg_N
("matching subprogram #!", N
);
7074 Hom_Id
:= Homonym
(Hom_Id
);
7077 -- See if we found an entry
7080 if not Ambiguous
then
7081 if Is_Generic_Subprogram
(Entity
(Arg_Internal
)) then
7083 ("pragma% cannot be given for generic subprogram");
7086 ("pragma% does not identify local subprogram");
7093 -- Import pragmas must be for imported entities
7095 if Prag_Id
= Pragma_Import_Function
7097 Prag_Id
= Pragma_Import_Procedure
7099 Prag_Id
= Pragma_Import_Valued_Procedure
7101 if not Is_Imported
(Ent
) then
7103 ("pragma Import or Interface must precede pragma%");
7106 -- Here we have the Export case which can set the entity as exported
7108 -- But does not do so if the specified external name is null, since
7109 -- that is taken as a signal in DEC Ada 83 (with which we want to be
7110 -- compatible) to request no external name.
7112 elsif Nkind
(Arg_External
) = N_String_Literal
7113 and then String_Length
(Strval
(Arg_External
)) = 0
7117 -- In all other cases, set entity as exported
7120 Set_Exported
(Ent
, Arg_Internal
);
7123 -- Special processing for Valued_Procedure cases
7125 if Prag_Id
= Pragma_Import_Valued_Procedure
7127 Prag_Id
= Pragma_Export_Valued_Procedure
7129 Formal
:= First_Formal
(Ent
);
7132 Error_Pragma
("at least one parameter required for pragma%");
7134 elsif Ekind
(Formal
) /= E_Out_Parameter
then
7135 Error_Pragma
("first parameter must have mode out for pragma%");
7138 Set_Is_Valued_Procedure
(Ent
);
7142 Set_Extended_Import_Export_External_Name
(Ent
, Arg_External
);
7144 -- Process Result_Mechanism argument if present. We have already
7145 -- checked that this is only allowed for the function case.
7147 if Present
(Arg_Result_Mechanism
) then
7148 Set_Mechanism_Value
(Ent
, Arg_Result_Mechanism
);
7151 -- Process Mechanism parameter if present. Note that this parameter
7152 -- is not analyzed, and must not be analyzed since it is semantic
7153 -- nonsense, so we get it in exactly as the parser left it.
7155 if Present
(Arg_Mechanism
) then
7163 -- A single mechanism association without a formal parameter
7164 -- name is parsed as a parenthesized expression. All other
7165 -- cases are parsed as aggregates, so we rewrite the single
7166 -- parameter case as an aggregate for consistency.
7168 if Nkind
(Arg_Mechanism
) /= N_Aggregate
7169 and then Paren_Count
(Arg_Mechanism
) = 1
7171 Rewrite
(Arg_Mechanism
,
7172 Make_Aggregate
(Sloc
(Arg_Mechanism
),
7173 Expressions
=> New_List
(
7174 Relocate_Node
(Arg_Mechanism
))));
7177 -- Case of only mechanism name given, applies to all formals
7179 if Nkind
(Arg_Mechanism
) /= N_Aggregate
then
7180 Formal
:= First_Formal
(Ent
);
7181 while Present
(Formal
) loop
7182 Set_Mechanism_Value
(Formal
, Arg_Mechanism
);
7183 Next_Formal
(Formal
);
7186 -- Case of list of mechanism associations given
7189 if Null_Record_Present
(Arg_Mechanism
) then
7191 ("inappropriate form for Mechanism parameter",
7195 -- Deal with positional ones first
7197 Formal
:= First_Formal
(Ent
);
7199 if Present
(Expressions
(Arg_Mechanism
)) then
7200 Mname
:= First
(Expressions
(Arg_Mechanism
));
7201 while Present
(Mname
) loop
7204 ("too many mechanism associations", Mname
);
7207 Set_Mechanism_Value
(Formal
, Mname
);
7208 Next_Formal
(Formal
);
7213 -- Deal with named entries
7215 if Present
(Component_Associations
(Arg_Mechanism
)) then
7216 Massoc
:= First
(Component_Associations
(Arg_Mechanism
));
7217 while Present
(Massoc
) loop
7218 Choice
:= First
(Choices
(Massoc
));
7220 if Nkind
(Choice
) /= N_Identifier
7221 or else Present
(Next
(Choice
))
7224 ("incorrect form for mechanism association",
7228 Formal
:= First_Formal
(Ent
);
7232 ("parameter name & not present", Choice
);
7235 if Chars
(Choice
) = Chars
(Formal
) then
7237 (Formal
, Expression
(Massoc
));
7239 -- Set entity on identifier (needed by ASIS)
7241 Set_Entity
(Choice
, Formal
);
7246 Next_Formal
(Formal
);
7255 end Process_Extended_Import_Export_Subprogram_Pragma
;
7257 --------------------------
7258 -- Process_Generic_List --
7259 --------------------------
7261 procedure Process_Generic_List
is
7266 Check_No_Identifiers
;
7267 Check_At_Least_N_Arguments
(1);
7269 -- Check all arguments are names of generic units or instances
7272 while Present
(Arg
) loop
7273 Exp
:= Get_Pragma_Arg
(Arg
);
7276 if not Is_Entity_Name
(Exp
)
7278 (not Is_Generic_Instance
(Entity
(Exp
))
7280 not Is_Generic_Unit
(Entity
(Exp
)))
7283 ("pragma% argument must be name of generic unit/instance",
7289 end Process_Generic_List
;
7291 ------------------------------------
7292 -- Process_Import_Predefined_Type --
7293 ------------------------------------
7295 procedure Process_Import_Predefined_Type
is
7296 Loc
: constant Source_Ptr
:= Sloc
(N
);
7298 Ftyp
: Node_Id
:= Empty
;
7304 String_To_Name_Buffer
(Strval
(Expression
(Arg3
)));
7307 Elmt
:= First_Elmt
(Predefined_Float_Types
);
7308 while Present
(Elmt
) and then Chars
(Node
(Elmt
)) /= Nam
loop
7312 Ftyp
:= Node
(Elmt
);
7314 if Present
(Ftyp
) then
7316 -- Don't build a derived type declaration, because predefined C
7317 -- types have no declaration anywhere, so cannot really be named.
7318 -- Instead build a full type declaration, starting with an
7319 -- appropriate type definition is built
7321 if Is_Floating_Point_Type
(Ftyp
) then
7322 Def
:= Make_Floating_Point_Definition
(Loc
,
7323 Make_Integer_Literal
(Loc
, Digits_Value
(Ftyp
)),
7324 Make_Real_Range_Specification
(Loc
,
7325 Make_Real_Literal
(Loc
, Realval
(Type_Low_Bound
(Ftyp
))),
7326 Make_Real_Literal
(Loc
, Realval
(Type_High_Bound
(Ftyp
)))));
7328 -- Should never have a predefined type we cannot handle
7331 raise Program_Error
;
7334 -- Build and insert a Full_Type_Declaration, which will be
7335 -- analyzed as soon as this list entry has been analyzed.
7337 Decl
:= Make_Full_Type_Declaration
(Loc
,
7338 Make_Defining_Identifier
(Loc
, Chars
(Expression
(Arg2
))),
7339 Type_Definition
=> Def
);
7341 Insert_After
(N
, Decl
);
7342 Mark_Rewrite_Insertion
(Decl
);
7345 Error_Pragma_Arg
("no matching type found for pragma%",
7348 end Process_Import_Predefined_Type
;
7350 ---------------------------------
7351 -- Process_Import_Or_Interface --
7352 ---------------------------------
7354 procedure Process_Import_Or_Interface
is
7360 -- In Relaxed_RM_Semantics, support old Ada 83 style:
7361 -- pragma Import (Entity, "external name");
7363 if Relaxed_RM_Semantics
7364 and then Arg_Count
= 2
7365 and then Prag_Id
= Pragma_Import
7366 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
7369 Def_Id
:= Get_Pragma_Arg
(Arg1
);
7372 if not Is_Entity_Name
(Def_Id
) then
7373 Error_Pragma_Arg
("entity name required", Arg1
);
7376 Def_Id
:= Entity
(Def_Id
);
7377 Kill_Size_Check_Code
(Def_Id
);
7378 Note_Possible_Modification
(Get_Pragma_Arg
(Arg1
), Sure
=> False);
7381 Process_Convention
(C
, Def_Id
);
7382 Kill_Size_Check_Code
(Def_Id
);
7383 Note_Possible_Modification
(Get_Pragma_Arg
(Arg2
), Sure
=> False);
7386 -- Various error checks
7388 if Ekind_In
(Def_Id
, E_Variable
, E_Constant
) then
7390 -- We do not permit Import to apply to a renaming declaration
7392 if Present
(Renamed_Object
(Def_Id
)) then
7394 ("pragma% not allowed for object renaming", Arg2
);
7396 -- User initialization is not allowed for imported object, but
7397 -- the object declaration may contain a default initialization,
7398 -- that will be discarded. Note that an explicit initialization
7399 -- only counts if it comes from source, otherwise it is simply
7400 -- the code generator making an implicit initialization explicit.
7402 elsif Present
(Expression
(Parent
(Def_Id
)))
7403 and then Comes_From_Source
7404 (Original_Node
(Expression
(Parent
(Def_Id
))))
7406 -- Set imported flag to prevent cascaded errors
7408 Set_Is_Imported
(Def_Id
);
7410 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7412 ("no initialization allowed for declaration of& #",
7413 "\imported entities cannot be initialized (RM B.1(24))",
7417 -- If the pragma comes from an aspect specification the
7418 -- Is_Imported flag has already been set.
7420 if not From_Aspect_Specification
(N
) then
7421 Set_Imported
(Def_Id
);
7424 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
7426 -- Note that we do not set Is_Public here. That's because we
7427 -- only want to set it if there is no address clause, and we
7428 -- don't know that yet, so we delay that processing till
7431 -- pragma Import completes deferred constants
7433 if Ekind
(Def_Id
) = E_Constant
then
7434 Set_Has_Completion
(Def_Id
);
7437 -- It is not possible to import a constant of an unconstrained
7438 -- array type (e.g. string) because there is no simple way to
7439 -- write a meaningful subtype for it.
7441 if Is_Array_Type
(Etype
(Def_Id
))
7442 and then not Is_Constrained
(Etype
(Def_Id
))
7445 ("imported constant& must have a constrained subtype",
7450 elsif Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
7452 -- If the name is overloaded, pragma applies to all of the denoted
7453 -- entities in the same declarative part, unless the pragma comes
7454 -- from an aspect specification or was generated by the compiler
7455 -- (such as for pragma Provide_Shift_Operators).
7458 while Present
(Hom_Id
) loop
7460 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
7462 -- Ignore inherited subprograms because the pragma will apply
7463 -- to the parent operation, which is the one called.
7465 if Is_Overloadable
(Def_Id
)
7466 and then Present
(Alias
(Def_Id
))
7470 -- If it is not a subprogram, it must be in an outer scope and
7471 -- pragma does not apply.
7473 elsif not Is_Subprogram_Or_Generic_Subprogram
(Def_Id
) then
7476 -- The pragma does not apply to primitives of interfaces
7478 elsif Is_Dispatching_Operation
(Def_Id
)
7479 and then Present
(Find_Dispatching_Type
(Def_Id
))
7480 and then Is_Interface
(Find_Dispatching_Type
(Def_Id
))
7484 -- Verify that the homonym is in the same declarative part (not
7485 -- just the same scope). If the pragma comes from an aspect
7486 -- specification we know that it is part of the declaration.
7488 elsif Parent
(Unit_Declaration_Node
(Def_Id
)) /= Parent
(N
)
7489 and then Nkind
(Parent
(N
)) /= N_Compilation_Unit_Aux
7490 and then not From_Aspect_Specification
(N
)
7495 -- If the pragma comes from an aspect specification the
7496 -- Is_Imported flag has already been set.
7498 if not From_Aspect_Specification
(N
) then
7499 Set_Imported
(Def_Id
);
7502 -- Reject an Import applied to an abstract subprogram
7504 if Is_Subprogram
(Def_Id
)
7505 and then Is_Abstract_Subprogram
(Def_Id
)
7507 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7509 ("cannot import abstract subprogram& declared#",
7513 -- Special processing for Convention_Intrinsic
7515 if C
= Convention_Intrinsic
then
7517 -- Link_Name argument not allowed for intrinsic
7521 Set_Is_Intrinsic_Subprogram
(Def_Id
);
7523 -- If no external name is present, then check that this
7524 -- is a valid intrinsic subprogram. If an external name
7525 -- is present, then this is handled by the back end.
7528 Check_Intrinsic_Subprogram
7529 (Def_Id
, Get_Pragma_Arg
(Arg2
));
7533 -- Verify that the subprogram does not have a completion
7534 -- through a renaming declaration. For other completions the
7535 -- pragma appears as a too late representation.
7538 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Def_Id
);
7542 and then Nkind
(Decl
) = N_Subprogram_Declaration
7543 and then Present
(Corresponding_Body
(Decl
))
7544 and then Nkind
(Unit_Declaration_Node
7545 (Corresponding_Body
(Decl
))) =
7546 N_Subprogram_Renaming_Declaration
7548 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7550 ("cannot import&, renaming already provided for "
7551 & "declaration #", N
, Def_Id
);
7555 -- If the pragma comes from an aspect specification, there
7556 -- must be an Import aspect specified as well. In the rare
7557 -- case where Import is set to False, the suprogram needs to
7558 -- have a local completion.
7561 Imp_Aspect
: constant Node_Id
:=
7562 Find_Aspect
(Def_Id
, Aspect_Import
);
7566 if Present
(Imp_Aspect
)
7567 and then Present
(Expression
(Imp_Aspect
))
7569 Expr
:= Expression
(Imp_Aspect
);
7570 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
7572 if Is_Entity_Name
(Expr
)
7573 and then Entity
(Expr
) = Standard_True
7575 Set_Has_Completion
(Def_Id
);
7578 -- If there is no expression, the default is True, as for
7579 -- all boolean aspects. Same for the older pragma.
7582 Set_Has_Completion
(Def_Id
);
7586 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
7589 if Is_Compilation_Unit
(Hom_Id
) then
7591 -- Its possible homonyms are not affected by the pragma.
7592 -- Such homonyms might be present in the context of other
7593 -- units being compiled.
7597 elsif From_Aspect_Specification
(N
) then
7600 -- If the pragma was created by the compiler, then we don't
7601 -- want it to apply to other homonyms. This kind of case can
7602 -- occur when using pragma Provide_Shift_Operators, which
7603 -- generates implicit shift and rotate operators with Import
7604 -- pragmas that might apply to earlier explicit or implicit
7605 -- declarations marked with Import (for example, coming from
7606 -- an earlier pragma Provide_Shift_Operators for another type),
7607 -- and we don't generally want other homonyms being treated
7608 -- as imported or the pragma flagged as an illegal duplicate.
7610 elsif not Comes_From_Source
(N
) then
7614 Hom_Id
:= Homonym
(Hom_Id
);
7618 -- When the convention is Java or CIL, we also allow Import to
7619 -- be given for packages, generic packages, exceptions, record
7620 -- components, and access to subprograms.
7622 elsif (C
= Convention_Java
or else C
= Convention_CIL
)
7624 (Is_Package_Or_Generic_Package
(Def_Id
)
7625 or else Ekind
(Def_Id
) = E_Exception
7626 or else Ekind
(Def_Id
) = E_Access_Subprogram_Type
7627 or else Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
)
7629 Set_Imported
(Def_Id
);
7630 Set_Is_Public
(Def_Id
);
7631 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
7633 -- Import a CPP class
7635 elsif C
= Convention_CPP
7636 and then (Is_Record_Type
(Def_Id
)
7637 or else Ekind
(Def_Id
) = E_Incomplete_Type
)
7639 if Ekind
(Def_Id
) = E_Incomplete_Type
then
7640 if Present
(Full_View
(Def_Id
)) then
7641 Def_Id
:= Full_View
(Def_Id
);
7645 ("cannot import 'C'P'P type before full declaration seen",
7646 Get_Pragma_Arg
(Arg2
));
7648 -- Although we have reported the error we decorate it as
7649 -- CPP_Class to avoid reporting spurious errors
7651 Set_Is_CPP_Class
(Def_Id
);
7656 -- Types treated as CPP classes must be declared limited (note:
7657 -- this used to be a warning but there is no real benefit to it
7658 -- since we did effectively intend to treat the type as limited
7661 if not Is_Limited_Type
(Def_Id
) then
7663 ("imported 'C'P'P type must be limited",
7664 Get_Pragma_Arg
(Arg2
));
7667 if Etype
(Def_Id
) /= Def_Id
7668 and then not Is_CPP_Class
(Root_Type
(Def_Id
))
7670 Error_Msg_N
("root type must be a 'C'P'P type", Arg1
);
7673 Set_Is_CPP_Class
(Def_Id
);
7675 -- Imported CPP types must not have discriminants (because C++
7676 -- classes do not have discriminants).
7678 if Has_Discriminants
(Def_Id
) then
7680 ("imported 'C'P'P type cannot have discriminants",
7681 First
(Discriminant_Specifications
7682 (Declaration_Node
(Def_Id
))));
7685 -- Check that components of imported CPP types do not have default
7686 -- expressions. For private types this check is performed when the
7687 -- full view is analyzed (see Process_Full_View).
7689 if not Is_Private_Type
(Def_Id
) then
7690 Check_CPP_Type_Has_No_Defaults
(Def_Id
);
7693 -- Import a CPP exception
7695 elsif C
= Convention_CPP
7696 and then Ekind
(Def_Id
) = E_Exception
7700 ("'External_'Name arguments is required for 'Cpp exception",
7703 -- As only a string is allowed, Check_Arg_Is_External_Name
7706 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
7709 if Present
(Arg4
) then
7711 ("Link_Name argument not allowed for imported Cpp exception",
7715 -- Do not call Set_Interface_Name as the name of the exception
7716 -- shouldn't be modified (and in particular it shouldn't be
7717 -- the External_Name). For exceptions, the External_Name is the
7718 -- name of the RTTI structure.
7720 -- ??? Emit an error if pragma Import/Export_Exception is present
7722 elsif Nkind
(Parent
(Def_Id
)) = N_Incomplete_Type_Declaration
then
7724 Check_Arg_Count
(3);
7725 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
7727 Process_Import_Predefined_Type
;
7731 ("second argument of pragma% must be object, subprogram "
7732 & "or incomplete type",
7736 -- If this pragma applies to a compilation unit, then the unit, which
7737 -- is a subprogram, does not require (or allow) a body. We also do
7738 -- not need to elaborate imported procedures.
7740 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
7742 Cunit
: constant Node_Id
:= Parent
(Parent
(N
));
7744 Set_Body_Required
(Cunit
, False);
7747 end Process_Import_Or_Interface
;
7749 --------------------
7750 -- Process_Inline --
7751 --------------------
7753 procedure Process_Inline
(Status
: Inline_Status
) is
7760 procedure Make_Inline
(Subp
: Entity_Id
);
7761 -- Subp is the defining unit name of the subprogram declaration. Set
7762 -- the flag, as well as the flag in the corresponding body, if there
7765 procedure Set_Inline_Flags
(Subp
: Entity_Id
);
7766 -- Sets Is_Inlined and Has_Pragma_Inline flags for Subp and also
7767 -- Has_Pragma_Inline_Always for the Inline_Always case.
7769 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean;
7770 -- Returns True if it can be determined at this stage that inlining
7771 -- is not possible, for example if the body is available and contains
7772 -- exception handlers, we prevent inlining, since otherwise we can
7773 -- get undefined symbols at link time. This function also emits a
7774 -- warning if front-end inlining is enabled and the pragma appears
7777 -- ??? is business with link symbols still valid, or does it relate
7778 -- to front end ZCX which is being phased out ???
7780 ---------------------------
7781 -- Inlining_Not_Possible --
7782 ---------------------------
7784 function Inlining_Not_Possible
(Subp
: Entity_Id
) return Boolean is
7785 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp
);
7789 if Nkind
(Decl
) = N_Subprogram_Body
then
7790 Stats
:= Handled_Statement_Sequence
(Decl
);
7791 return Present
(Exception_Handlers
(Stats
))
7792 or else Present
(At_End_Proc
(Stats
));
7794 elsif Nkind
(Decl
) = N_Subprogram_Declaration
7795 and then Present
(Corresponding_Body
(Decl
))
7797 if Front_End_Inlining
7798 and then Analyzed
(Corresponding_Body
(Decl
))
7800 Error_Msg_N
("pragma appears too late, ignored??", N
);
7803 -- If the subprogram is a renaming as body, the body is just a
7804 -- call to the renamed subprogram, and inlining is trivially
7808 Nkind
(Unit_Declaration_Node
(Corresponding_Body
(Decl
))) =
7809 N_Subprogram_Renaming_Declaration
7815 Handled_Statement_Sequence
7816 (Unit_Declaration_Node
(Corresponding_Body
(Decl
)));
7819 Present
(Exception_Handlers
(Stats
))
7820 or else Present
(At_End_Proc
(Stats
));
7824 -- If body is not available, assume the best, the check is
7825 -- performed again when compiling enclosing package bodies.
7829 end Inlining_Not_Possible
;
7835 procedure Make_Inline
(Subp
: Entity_Id
) is
7836 Kind
: constant Entity_Kind
:= Ekind
(Subp
);
7837 Inner_Subp
: Entity_Id
:= Subp
;
7840 -- Ignore if bad type, avoid cascaded error
7842 if Etype
(Subp
) = Any_Type
then
7846 -- If inlining is not possible, for now do not treat as an error
7848 elsif Status
/= Suppressed
7849 and then Inlining_Not_Possible
(Subp
)
7854 -- Here we have a candidate for inlining, but we must exclude
7855 -- derived operations. Otherwise we would end up trying to inline
7856 -- a phantom declaration, and the result would be to drag in a
7857 -- body which has no direct inlining associated with it. That
7858 -- would not only be inefficient but would also result in the
7859 -- backend doing cross-unit inlining in cases where it was
7860 -- definitely inappropriate to do so.
7862 -- However, a simple Comes_From_Source test is insufficient, since
7863 -- we do want to allow inlining of generic instances which also do
7864 -- not come from source. We also need to recognize specs generated
7865 -- by the front-end for bodies that carry the pragma. Finally,
7866 -- predefined operators do not come from source but are not
7867 -- inlineable either.
7869 elsif Is_Generic_Instance
(Subp
)
7870 or else Nkind
(Parent
(Parent
(Subp
))) = N_Subprogram_Declaration
7874 elsif not Comes_From_Source
(Subp
)
7875 and then Scope
(Subp
) /= Standard_Standard
7881 -- The referenced entity must either be the enclosing entity, or
7882 -- an entity declared within the current open scope.
7884 if Present
(Scope
(Subp
))
7885 and then Scope
(Subp
) /= Current_Scope
7886 and then Subp
/= Current_Scope
7889 ("argument of% must be entity in current scope", Assoc
);
7893 -- Processing for procedure, operator or function. If subprogram
7894 -- is aliased (as for an instance) indicate that the renamed
7895 -- entity (if declared in the same unit) is inlined.
7897 if Is_Subprogram
(Subp
) then
7898 Inner_Subp
:= Ultimate_Alias
(Inner_Subp
);
7900 if In_Same_Source_Unit
(Subp
, Inner_Subp
) then
7901 Set_Inline_Flags
(Inner_Subp
);
7903 Decl
:= Parent
(Parent
(Inner_Subp
));
7905 if Nkind
(Decl
) = N_Subprogram_Declaration
7906 and then Present
(Corresponding_Body
(Decl
))
7908 Set_Inline_Flags
(Corresponding_Body
(Decl
));
7910 elsif Is_Generic_Instance
(Subp
) then
7912 -- Indicate that the body needs to be created for
7913 -- inlining subsequent calls. The instantiation node
7914 -- follows the declaration of the wrapper package
7917 if Scope
(Subp
) /= Standard_Standard
7919 Need_Subprogram_Instance_Body
7920 (Next
(Unit_Declaration_Node
(Scope
(Alias
(Subp
)))),
7926 -- Inline is a program unit pragma (RM 10.1.5) and cannot
7927 -- appear in a formal part to apply to a formal subprogram.
7928 -- Do not apply check within an instance or a formal package
7929 -- the test will have been applied to the original generic.
7931 elsif Nkind
(Decl
) in N_Formal_Subprogram_Declaration
7932 and then List_Containing
(Decl
) = List_Containing
(N
)
7933 and then not In_Instance
7936 ("Inline cannot apply to a formal subprogram", N
);
7938 -- If Subp is a renaming, it is the renamed entity that
7939 -- will appear in any call, and be inlined. However, for
7940 -- ASIS uses it is convenient to indicate that the renaming
7941 -- itself is an inlined subprogram, so that some gnatcheck
7942 -- rules can be applied in the absence of expansion.
7944 elsif Nkind
(Decl
) = N_Subprogram_Renaming_Declaration
then
7945 Set_Inline_Flags
(Subp
);
7951 -- For a generic subprogram set flag as well, for use at the point
7952 -- of instantiation, to determine whether the body should be
7955 elsif Is_Generic_Subprogram
(Subp
) then
7956 Set_Inline_Flags
(Subp
);
7959 -- Literals are by definition inlined
7961 elsif Kind
= E_Enumeration_Literal
then
7964 -- Anything else is an error
7968 ("expect subprogram name for pragma%", Assoc
);
7972 ----------------------
7973 -- Set_Inline_Flags --
7974 ----------------------
7976 procedure Set_Inline_Flags
(Subp
: Entity_Id
) is
7978 -- First set the Has_Pragma_XXX flags and issue the appropriate
7979 -- errors and warnings for suspicious combinations.
7981 if Prag_Id
= Pragma_No_Inline
then
7982 if Has_Pragma_Inline_Always
(Subp
) then
7984 ("Inline_Always and No_Inline are mutually exclusive", N
);
7985 elsif Has_Pragma_Inline
(Subp
) then
7987 ("Inline and No_Inline both specified for& ??",
7988 N
, Entity
(Subp_Id
));
7991 Set_Has_Pragma_No_Inline
(Subp
);
7993 if Prag_Id
= Pragma_Inline_Always
then
7994 if Has_Pragma_No_Inline
(Subp
) then
7996 ("Inline_Always and No_Inline are mutually exclusive",
8000 Set_Has_Pragma_Inline_Always
(Subp
);
8002 if Has_Pragma_No_Inline
(Subp
) then
8004 ("Inline and No_Inline both specified for& ??",
8005 N
, Entity
(Subp_Id
));
8009 if not Has_Pragma_Inline
(Subp
) then
8010 Set_Has_Pragma_Inline
(Subp
);
8014 -- Then adjust the Is_Inlined flag. It can never be set if the
8015 -- subprogram is subject to pragma No_Inline.
8019 Set_Is_Inlined
(Subp
, False);
8023 if not Has_Pragma_No_Inline
(Subp
) then
8024 Set_Is_Inlined
(Subp
, True);
8027 end Set_Inline_Flags
;
8029 -- Start of processing for Process_Inline
8032 Check_No_Identifiers
;
8033 Check_At_Least_N_Arguments
(1);
8035 if Status
= Enabled
then
8036 Inline_Processing_Required
:= True;
8040 while Present
(Assoc
) loop
8041 Subp_Id
:= Get_Pragma_Arg
(Assoc
);
8045 if Is_Entity_Name
(Subp_Id
) then
8046 Subp
:= Entity
(Subp_Id
);
8048 if Subp
= Any_Id
then
8050 -- If previous error, avoid cascaded errors
8052 Check_Error_Detected
;
8058 -- For the pragma case, climb homonym chain. This is
8059 -- what implements allowing the pragma in the renaming
8060 -- case, with the result applying to the ancestors, and
8061 -- also allows Inline to apply to all previous homonyms.
8063 if not From_Aspect_Specification
(N
) then
8064 while Present
(Homonym
(Subp
))
8065 and then Scope
(Homonym
(Subp
)) = Current_Scope
8067 Make_Inline
(Homonym
(Subp
));
8068 Subp
:= Homonym
(Subp
);
8075 Error_Pragma_Arg
("inappropriate argument for pragma%", Assoc
);
8082 ----------------------------
8083 -- Process_Interface_Name --
8084 ----------------------------
8086 procedure Process_Interface_Name
8087 (Subprogram_Def
: Entity_Id
;
8093 String_Val
: String_Id
;
8095 procedure Check_Form_Of_Interface_Name
8097 Ext_Name_Case
: Boolean);
8098 -- SN is a string literal node for an interface name. This routine
8099 -- performs some minimal checks that the name is reasonable. In
8100 -- particular that no spaces or other obviously incorrect characters
8101 -- appear. This is only a warning, since any characters are allowed.
8102 -- Ext_Name_Case is True for an External_Name, False for a Link_Name.
8104 ----------------------------------
8105 -- Check_Form_Of_Interface_Name --
8106 ----------------------------------
8108 procedure Check_Form_Of_Interface_Name
8110 Ext_Name_Case
: Boolean)
8112 S
: constant String_Id
:= Strval
(Expr_Value_S
(SN
));
8113 SL
: constant Nat
:= String_Length
(S
);
8118 Error_Msg_N
("interface name cannot be null string", SN
);
8121 for J
in 1 .. SL
loop
8122 C
:= Get_String_Char
(S
, J
);
8124 -- Look for dubious character and issue unconditional warning.
8125 -- Definitely dubious if not in character range.
8127 if not In_Character_Range
(C
)
8129 -- For all cases except CLI target,
8130 -- commas, spaces and slashes are dubious (in CLI, we use
8131 -- commas and backslashes in external names to specify
8132 -- assembly version and public key, while slashes and spaces
8133 -- can be used in names to mark nested classes and
8136 or else ((not Ext_Name_Case
or else VM_Target
/= CLI_Target
)
8137 and then (Get_Character
(C
) = ','
8139 Get_Character
(C
) = '\'))
8140 or else (VM_Target
/= CLI_Target
8141 and then (Get_Character
(C
) = ' '
8143 Get_Character
(C
) = '/'))
8146 ("??interface name contains illegal character",
8147 Sloc
(SN
) + Source_Ptr
(J
));
8150 end Check_Form_Of_Interface_Name
;
8152 -- Start of processing for Process_Interface_Name
8155 if No
(Link_Arg
) then
8156 if No
(Ext_Arg
) then
8157 if VM_Target
= CLI_Target
8158 and then Ekind
(Subprogram_Def
) = E_Package
8159 and then Nkind
(Parent
(Subprogram_Def
)) =
8160 N_Package_Specification
8161 and then Present
(Generic_Parent
(Parent
(Subprogram_Def
)))
8166 (Generic_Parent
(Parent
(Subprogram_Def
))));
8171 elsif Chars
(Ext_Arg
) = Name_Link_Name
then
8173 Link_Nam
:= Expression
(Ext_Arg
);
8176 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8177 Ext_Nam
:= Expression
(Ext_Arg
);
8182 Check_Optional_Identifier
(Ext_Arg
, Name_External_Name
);
8183 Check_Optional_Identifier
(Link_Arg
, Name_Link_Name
);
8184 Ext_Nam
:= Expression
(Ext_Arg
);
8185 Link_Nam
:= Expression
(Link_Arg
);
8188 -- Check expressions for external name and link name are static
8190 if Present
(Ext_Nam
) then
8191 Check_Arg_Is_OK_Static_Expression
(Ext_Nam
, Standard_String
);
8192 Check_Form_Of_Interface_Name
(Ext_Nam
, Ext_Name_Case
=> True);
8194 -- Verify that external name is not the name of a local entity,
8195 -- which would hide the imported one and could lead to run-time
8196 -- surprises. The problem can only arise for entities declared in
8197 -- a package body (otherwise the external name is fully qualified
8198 -- and will not conflict).
8206 if Prag_Id
= Pragma_Import
then
8207 String_To_Name_Buffer
(Strval
(Expr_Value_S
(Ext_Nam
)));
8209 E
:= Entity_Id
(Get_Name_Table_Int
(Nam
));
8211 if Nam
/= Chars
(Subprogram_Def
)
8212 and then Present
(E
)
8213 and then not Is_Overloadable
(E
)
8214 and then Is_Immediately_Visible
(E
)
8215 and then not Is_Imported
(E
)
8216 and then Ekind
(Scope
(E
)) = E_Package
8219 while Present
(Par
) loop
8220 if Nkind
(Par
) = N_Package_Body
then
8221 Error_Msg_Sloc
:= Sloc
(E
);
8223 ("imported entity is hidden by & declared#",
8228 Par
:= Parent
(Par
);
8235 if Present
(Link_Nam
) then
8236 Check_Arg_Is_OK_Static_Expression
(Link_Nam
, Standard_String
);
8237 Check_Form_Of_Interface_Name
(Link_Nam
, Ext_Name_Case
=> False);
8240 -- If there is no link name, just set the external name
8242 if No
(Link_Nam
) then
8243 Link_Nam
:= Adjust_External_Name_Case
(Expr_Value_S
(Ext_Nam
));
8245 -- For the Link_Name case, the given literal is preceded by an
8246 -- asterisk, which indicates to GCC that the given name should be
8247 -- taken literally, and in particular that no prepending of
8248 -- underlines should occur, even in systems where this is the
8254 if VM_Target
= No_VM
then
8255 Store_String_Char
(Get_Char_Code
('*'));
8258 String_Val
:= Strval
(Expr_Value_S
(Link_Nam
));
8259 Store_String_Chars
(String_Val
);
8261 Make_String_Literal
(Sloc
(Link_Nam
),
8262 Strval
=> End_String
);
8265 -- Set the interface name. If the entity is a generic instance, use
8266 -- its alias, which is the callable entity.
8268 if Is_Generic_Instance
(Subprogram_Def
) then
8269 Set_Encoded_Interface_Name
8270 (Alias
(Get_Base_Subprogram
(Subprogram_Def
)), Link_Nam
);
8272 Set_Encoded_Interface_Name
8273 (Get_Base_Subprogram
(Subprogram_Def
), Link_Nam
);
8276 -- We allow duplicated export names in CIL/Java, as they are always
8277 -- enclosed in a namespace that differentiates them, and overloaded
8278 -- entities are supported by the VM.
8280 if Convention
(Subprogram_Def
) /= Convention_CIL
8282 Convention
(Subprogram_Def
) /= Convention_Java
8284 Check_Duplicated_Export_Name
(Link_Nam
);
8286 end Process_Interface_Name
;
8288 -----------------------------------------
8289 -- Process_Interrupt_Or_Attach_Handler --
8290 -----------------------------------------
8292 procedure Process_Interrupt_Or_Attach_Handler
is
8293 Arg1_X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
8294 Handler_Proc
: constant Entity_Id
:= Entity
(Arg1_X
);
8295 Proc_Scope
: constant Entity_Id
:= Scope
(Handler_Proc
);
8298 Set_Is_Interrupt_Handler
(Handler_Proc
);
8300 -- If the pragma is not associated with a handler procedure within a
8301 -- protected type, then it must be for a nonprotected procedure for
8302 -- the AAMP target, in which case we don't associate a representation
8303 -- item with the procedure's scope.
8305 if Ekind
(Proc_Scope
) = E_Protected_Type
then
8306 if Prag_Id
= Pragma_Interrupt_Handler
8308 Prag_Id
= Pragma_Attach_Handler
8310 Record_Rep_Item
(Proc_Scope
, N
);
8313 end Process_Interrupt_Or_Attach_Handler
;
8315 --------------------------------------------------
8316 -- Process_Restrictions_Or_Restriction_Warnings --
8317 --------------------------------------------------
8319 -- Note: some of the simple identifier cases were handled in par-prag,
8320 -- but it is harmless (and more straightforward) to simply handle all
8321 -- cases here, even if it means we repeat a bit of work in some cases.
8323 procedure Process_Restrictions_Or_Restriction_Warnings
8327 R_Id
: Restriction_Id
;
8333 -- Ignore all Restrictions pragmas in CodePeer mode
8335 if CodePeer_Mode
then
8339 Check_Ada_83_Warning
;
8340 Check_At_Least_N_Arguments
(1);
8341 Check_Valid_Configuration_Pragma
;
8344 while Present
(Arg
) loop
8346 Expr
:= Get_Pragma_Arg
(Arg
);
8348 -- Case of no restriction identifier present
8350 if Id
= No_Name
then
8351 if Nkind
(Expr
) /= N_Identifier
then
8353 ("invalid form for restriction", Arg
);
8358 (Process_Restriction_Synonyms
(Expr
));
8360 if R_Id
not in All_Boolean_Restrictions
then
8361 Error_Msg_Name_1
:= Pname
;
8363 ("invalid restriction identifier&", Get_Pragma_Arg
(Arg
));
8365 -- Check for possible misspelling
8367 for J
in Restriction_Id
loop
8369 Rnm
: constant String := Restriction_Id
'Image (J
);
8372 Name_Buffer
(1 .. Rnm
'Length) := Rnm
;
8373 Name_Len
:= Rnm
'Length;
8374 Set_Casing
(All_Lower_Case
);
8376 if Is_Bad_Spelling_Of
(Chars
(Expr
), Name_Enter
) then
8378 (Identifier_Casing
(Current_Source_File
));
8379 Error_Msg_String
(1 .. Rnm
'Length) :=
8380 Name_Buffer
(1 .. Name_Len
);
8381 Error_Msg_Strlen
:= Rnm
'Length;
8382 Error_Msg_N
-- CODEFIX
8383 ("\possible misspelling of ""~""",
8384 Get_Pragma_Arg
(Arg
));
8393 if Implementation_Restriction
(R_Id
) then
8394 Check_Restriction
(No_Implementation_Restrictions
, Arg
);
8397 -- Special processing for No_Elaboration_Code restriction
8399 if R_Id
= No_Elaboration_Code
then
8401 -- Restriction is only recognized within a configuration
8402 -- pragma file, or within a unit of the main extended
8403 -- program. Note: the test for Main_Unit is needed to
8404 -- properly include the case of configuration pragma files.
8406 if not (Current_Sem_Unit
= Main_Unit
8407 or else In_Extended_Main_Source_Unit
(N
))
8411 -- Don't allow in a subunit unless already specified in
8414 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
8415 and then Nkind
(Unit
(Parent
(N
))) = N_Subunit
8416 and then not Restriction_Active
(No_Elaboration_Code
)
8419 ("invalid specification of ""No_Elaboration_Code""",
8422 ("\restriction cannot be specified in a subunit", N
);
8424 ("\unless also specified in body or spec", N
);
8427 -- If we accept a No_Elaboration_Code restriction, then it
8428 -- needs to be added to the configuration restriction set so
8429 -- that we get proper application to other units in the main
8430 -- extended source as required.
8433 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
8437 -- If this is a warning, then set the warning unless we already
8438 -- have a real restriction active (we never want a warning to
8439 -- override a real restriction).
8442 if not Restriction_Active
(R_Id
) then
8443 Set_Restriction
(R_Id
, N
);
8444 Restriction_Warnings
(R_Id
) := True;
8447 -- If real restriction case, then set it and make sure that the
8448 -- restriction warning flag is off, since a real restriction
8449 -- always overrides a warning.
8452 Set_Restriction
(R_Id
, N
);
8453 Restriction_Warnings
(R_Id
) := False;
8456 -- Check for obsolescent restrictions in Ada 2005 mode
8459 and then Ada_Version
>= Ada_2005
8460 and then (R_Id
= No_Asynchronous_Control
8462 R_Id
= No_Unchecked_Deallocation
8464 R_Id
= No_Unchecked_Conversion
)
8466 Check_Restriction
(No_Obsolescent_Features
, N
);
8469 -- A very special case that must be processed here: pragma
8470 -- Restrictions (No_Exceptions) turns off all run-time
8471 -- checking. This is a bit dubious in terms of the formal
8472 -- language definition, but it is what is intended by RM
8473 -- H.4(12). Restriction_Warnings never affects generated code
8474 -- so this is done only in the real restriction case.
8476 -- Atomic_Synchronization is not a real check, so it is not
8477 -- affected by this processing).
8479 -- Ignore the effect of pragma Restrictions (No_Exceptions) on
8480 -- run-time checks in CodePeer and GNATprove modes: we want to
8481 -- generate checks for analysis purposes, as set respectively
8482 -- by -gnatC and -gnatd.F
8485 and then not (CodePeer_Mode
or GNATprove_Mode
)
8486 and then R_Id
= No_Exceptions
8488 for J
in Scope_Suppress
.Suppress
'Range loop
8489 if J
/= Atomic_Synchronization
then
8490 Scope_Suppress
.Suppress
(J
) := True;
8495 -- Case of No_Dependence => unit-name. Note that the parser
8496 -- already made the necessary entry in the No_Dependence table.
8498 elsif Id
= Name_No_Dependence
then
8499 if not OK_No_Dependence_Unit_Name
(Expr
) then
8503 -- Case of No_Specification_Of_Aspect => aspect-identifier
8505 elsif Id
= Name_No_Specification_Of_Aspect
then
8510 if Nkind
(Expr
) /= N_Identifier
then
8513 A_Id
:= Get_Aspect_Id
(Chars
(Expr
));
8516 if A_Id
= No_Aspect
then
8517 Error_Pragma_Arg
("invalid restriction name", Arg
);
8519 Set_Restriction_No_Specification_Of_Aspect
(Expr
, Warn
);
8523 -- Case of No_Use_Of_Attribute => attribute-identifier
8525 elsif Id
= Name_No_Use_Of_Attribute
then
8526 if Nkind
(Expr
) /= N_Identifier
8527 or else not Is_Attribute_Name
(Chars
(Expr
))
8529 Error_Msg_N
("unknown attribute name??", Expr
);
8532 Set_Restriction_No_Use_Of_Attribute
(Expr
, Warn
);
8535 -- Case of No_Use_Of_Entity => fully-qualified-name
8537 elsif Id
= Name_No_Use_Of_Entity
then
8539 -- Restriction is only recognized within a configuration
8540 -- pragma file, or within a unit of the main extended
8541 -- program. Note: the test for Main_Unit is needed to
8542 -- properly include the case of configuration pragma files.
8544 if Current_Sem_Unit
= Main_Unit
8545 or else In_Extended_Main_Source_Unit
(N
)
8547 if not OK_No_Dependence_Unit_Name
(Expr
) then
8548 Error_Msg_N
("wrong form for entity name", Expr
);
8550 Set_Restriction_No_Use_Of_Entity
8551 (Expr
, Warn
, No_Profile
);
8555 -- Case of No_Use_Of_Pragma => pragma-identifier
8557 elsif Id
= Name_No_Use_Of_Pragma
then
8558 if Nkind
(Expr
) /= N_Identifier
8559 or else not Is_Pragma_Name
(Chars
(Expr
))
8561 Error_Msg_N
("unknown pragma name??", Expr
);
8563 Set_Restriction_No_Use_Of_Pragma
(Expr
, Warn
);
8566 -- All other cases of restriction identifier present
8569 R_Id
:= Get_Restriction_Id
(Process_Restriction_Synonyms
(Arg
));
8570 Analyze_And_Resolve
(Expr
, Any_Integer
);
8572 if R_Id
not in All_Parameter_Restrictions
then
8574 ("invalid restriction parameter identifier", Arg
);
8576 elsif not Is_OK_Static_Expression
(Expr
) then
8577 Flag_Non_Static_Expr
8578 ("value must be static expression!", Expr
);
8581 elsif not Is_Integer_Type
(Etype
(Expr
))
8582 or else Expr_Value
(Expr
) < 0
8585 ("value must be non-negative integer", Arg
);
8588 -- Restriction pragma is active
8590 Val
:= Expr_Value
(Expr
);
8592 if not UI_Is_In_Int_Range
(Val
) then
8594 ("pragma ignored, value too large??", Arg
);
8597 -- Warning case. If the real restriction is active, then we
8598 -- ignore the request, since warning never overrides a real
8599 -- restriction. Otherwise we set the proper warning. Note that
8600 -- this circuit sets the warning again if it is already set,
8601 -- which is what we want, since the constant may have changed.
8604 if not Restriction_Active
(R_Id
) then
8606 (R_Id
, N
, Integer (UI_To_Int
(Val
)));
8607 Restriction_Warnings
(R_Id
) := True;
8610 -- Real restriction case, set restriction and make sure warning
8611 -- flag is off since real restriction always overrides warning.
8614 Set_Restriction
(R_Id
, N
, Integer (UI_To_Int
(Val
)));
8615 Restriction_Warnings
(R_Id
) := False;
8621 end Process_Restrictions_Or_Restriction_Warnings
;
8623 ---------------------------------
8624 -- Process_Suppress_Unsuppress --
8625 ---------------------------------
8627 -- Note: this procedure makes entries in the check suppress data
8628 -- structures managed by Sem. See spec of package Sem for full
8629 -- details on how we handle recording of check suppression.
8631 procedure Process_Suppress_Unsuppress
(Suppress_Case
: Boolean) is
8636 In_Package_Spec
: constant Boolean :=
8637 Is_Package_Or_Generic_Package
(Current_Scope
)
8638 and then not In_Package_Body
(Current_Scope
);
8640 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
);
8641 -- Used to suppress a single check on the given entity
8643 --------------------------------
8644 -- Suppress_Unsuppress_Echeck --
8645 --------------------------------
8647 procedure Suppress_Unsuppress_Echeck
(E
: Entity_Id
; C
: Check_Id
) is
8649 -- Check for error of trying to set atomic synchronization for
8650 -- a non-atomic variable.
8652 if C
= Atomic_Synchronization
8653 and then not (Is_Atomic
(E
) or else Has_Atomic_Components
(E
))
8656 ("pragma & requires atomic type or variable",
8657 Pragma_Identifier
(Original_Node
(N
)));
8660 Set_Checks_May_Be_Suppressed
(E
);
8662 if In_Package_Spec
then
8663 Push_Global_Suppress_Stack_Entry
8666 Suppress
=> Suppress_Case
);
8668 Push_Local_Suppress_Stack_Entry
8671 Suppress
=> Suppress_Case
);
8674 -- If this is a first subtype, and the base type is distinct,
8675 -- then also set the suppress flags on the base type.
8677 if Is_First_Subtype
(E
) and then Etype
(E
) /= E
then
8678 Suppress_Unsuppress_Echeck
(Etype
(E
), C
);
8680 end Suppress_Unsuppress_Echeck
;
8682 -- Start of processing for Process_Suppress_Unsuppress
8685 -- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes
8686 -- on user code: we want to generate checks for analysis purposes, as
8687 -- set respectively by -gnatC and -gnatd.F
8689 if (CodePeer_Mode
or GNATprove_Mode
)
8690 and then Comes_From_Source
(N
)
8695 -- Suppress/Unsuppress can appear as a configuration pragma, or in a
8696 -- declarative part or a package spec (RM 11.5(5)).
8698 if not Is_Configuration_Pragma
then
8699 Check_Is_In_Decl_Part_Or_Package_Spec
;
8702 Check_At_Least_N_Arguments
(1);
8703 Check_At_Most_N_Arguments
(2);
8704 Check_No_Identifier
(Arg1
);
8705 Check_Arg_Is_Identifier
(Arg1
);
8707 C
:= Get_Check_Id
(Chars
(Get_Pragma_Arg
(Arg1
)));
8709 if C
= No_Check_Id
then
8711 ("argument of pragma% is not valid check name", Arg1
);
8714 -- Warn that suppress of Elaboration_Check has no effect in SPARK
8716 if C
= Elaboration_Check
and then SPARK_Mode
= On
then
8718 ("Suppress of Elaboration_Check ignored in SPARK??",
8719 "\elaboration checking rules are statically enforced "
8720 & "(SPARK RM 7.7)", Arg1
);
8723 -- One-argument case
8725 if Arg_Count
= 1 then
8727 -- Make an entry in the local scope suppress table. This is the
8728 -- table that directly shows the current value of the scope
8729 -- suppress check for any check id value.
8731 if C
= All_Checks
then
8733 -- For All_Checks, we set all specific predefined checks with
8734 -- the exception of Elaboration_Check, which is handled
8735 -- specially because of not wanting All_Checks to have the
8736 -- effect of deactivating static elaboration order processing.
8737 -- Atomic_Synchronization is also not affected, since this is
8738 -- not a real check.
8740 for J
in Scope_Suppress
.Suppress
'Range loop
8741 if J
/= Elaboration_Check
8743 J
/= Atomic_Synchronization
8745 Scope_Suppress
.Suppress
(J
) := Suppress_Case
;
8749 -- If not All_Checks, and predefined check, then set appropriate
8750 -- scope entry. Note that we will set Elaboration_Check if this
8751 -- is explicitly specified. Atomic_Synchronization is allowed
8752 -- only if internally generated and entity is atomic.
8754 elsif C
in Predefined_Check_Id
8755 and then (not Comes_From_Source
(N
)
8756 or else C
/= Atomic_Synchronization
)
8758 Scope_Suppress
.Suppress
(C
) := Suppress_Case
;
8761 -- Also make an entry in the Local_Entity_Suppress table
8763 Push_Local_Suppress_Stack_Entry
8766 Suppress
=> Suppress_Case
);
8768 -- Case of two arguments present, where the check is suppressed for
8769 -- a specified entity (given as the second argument of the pragma)
8772 -- This is obsolescent in Ada 2005 mode
8774 if Ada_Version
>= Ada_2005
then
8775 Check_Restriction
(No_Obsolescent_Features
, Arg2
);
8778 Check_Optional_Identifier
(Arg2
, Name_On
);
8779 E_Id
:= Get_Pragma_Arg
(Arg2
);
8782 if not Is_Entity_Name
(E_Id
) then
8784 ("second argument of pragma% must be entity name", Arg2
);
8793 -- Enforce RM 11.5(7) which requires that for a pragma that
8794 -- appears within a package spec, the named entity must be
8795 -- within the package spec. We allow the package name itself
8796 -- to be mentioned since that makes sense, although it is not
8797 -- strictly allowed by 11.5(7).
8800 and then E
/= Current_Scope
8801 and then Scope
(E
) /= Current_Scope
8804 ("entity in pragma% is not in package spec (RM 11.5(7))",
8808 -- Loop through homonyms. As noted below, in the case of a package
8809 -- spec, only homonyms within the package spec are considered.
8812 Suppress_Unsuppress_Echeck
(E
, C
);
8814 if Is_Generic_Instance
(E
)
8815 and then Is_Subprogram
(E
)
8816 and then Present
(Alias
(E
))
8818 Suppress_Unsuppress_Echeck
(Alias
(E
), C
);
8821 -- Move to next homonym if not aspect spec case
8823 exit when From_Aspect_Specification
(N
);
8827 -- If we are within a package specification, the pragma only
8828 -- applies to homonyms in the same scope.
8830 exit when In_Package_Spec
8831 and then Scope
(E
) /= Current_Scope
;
8834 end Process_Suppress_Unsuppress
;
8836 -------------------------------
8837 -- Record_Independence_Check --
8838 -------------------------------
8840 procedure Record_Independence_Check
(N
: Node_Id
; E
: Entity_Id
) is
8842 -- For GCC back ends the validation is done a priori
8844 if VM_Target
= No_VM
and then not AAMP_On_Target
then
8848 Independence_Checks
.Append
((N
, E
));
8849 end Record_Independence_Check
;
8855 procedure Set_Exported
(E
: Entity_Id
; Arg
: Node_Id
) is
8857 if Is_Imported
(E
) then
8859 ("cannot export entity& that was previously imported", Arg
);
8861 elsif Present
(Address_Clause
(E
))
8862 and then not Relaxed_RM_Semantics
8865 ("cannot export entity& that has an address clause", Arg
);
8868 Set_Is_Exported
(E
);
8870 -- Generate a reference for entity explicitly, because the
8871 -- identifier may be overloaded and name resolution will not
8874 Generate_Reference
(E
, Arg
);
8876 -- Deal with exporting non-library level entity
8878 if not Is_Library_Level_Entity
(E
) then
8880 -- Not allowed at all for subprograms
8882 if Is_Subprogram
(E
) then
8883 Error_Pragma_Arg
("local subprogram& cannot be exported", Arg
);
8885 -- Otherwise set public and statically allocated
8889 Set_Is_Statically_Allocated
(E
);
8891 -- Warn if the corresponding W flag is set
8893 if Warn_On_Export_Import
8895 -- Only do this for something that was in the source. Not
8896 -- clear if this can be False now (there used for sure to be
8897 -- cases on some systems where it was False), but anyway the
8898 -- test is harmless if not needed, so it is retained.
8900 and then Comes_From_Source
(Arg
)
8903 ("?x?& has been made static as a result of Export",
8906 ("\?x?this usage is non-standard and non-portable",
8912 if Warn_On_Export_Import
and then Is_Type
(E
) then
8913 Error_Msg_NE
("exporting a type has no effect?x?", Arg
, E
);
8916 if Warn_On_Export_Import
and Inside_A_Generic
then
8918 ("all instances of& will have the same external name?x?",
8923 ----------------------------------------------
8924 -- Set_Extended_Import_Export_External_Name --
8925 ----------------------------------------------
8927 procedure Set_Extended_Import_Export_External_Name
8928 (Internal_Ent
: Entity_Id
;
8929 Arg_External
: Node_Id
)
8931 Old_Name
: constant Node_Id
:= Interface_Name
(Internal_Ent
);
8935 if No
(Arg_External
) then
8939 Check_Arg_Is_External_Name
(Arg_External
);
8941 if Nkind
(Arg_External
) = N_String_Literal
then
8942 if String_Length
(Strval
(Arg_External
)) = 0 then
8945 New_Name
:= Adjust_External_Name_Case
(Arg_External
);
8948 elsif Nkind
(Arg_External
) = N_Identifier
then
8949 New_Name
:= Get_Default_External_Name
(Arg_External
);
8951 -- Check_Arg_Is_External_Name should let through only identifiers and
8952 -- string literals or static string expressions (which are folded to
8953 -- string literals).
8956 raise Program_Error
;
8959 -- If we already have an external name set (by a prior normal Import
8960 -- or Export pragma), then the external names must match
8962 if Present
(Interface_Name
(Internal_Ent
)) then
8964 -- Ignore mismatching names in CodePeer mode, to support some
8965 -- old compilers which would export the same procedure under
8966 -- different names, e.g:
8968 -- pragma Export_Procedure (P, "a");
8969 -- pragma Export_Procedure (P, "b");
8971 if CodePeer_Mode
then
8975 Check_Matching_Internal_Names
: declare
8976 S1
: constant String_Id
:= Strval
(Old_Name
);
8977 S2
: constant String_Id
:= Strval
(New_Name
);
8980 pragma No_Return
(Mismatch
);
8981 -- Called if names do not match
8987 procedure Mismatch
is
8989 Error_Msg_Sloc
:= Sloc
(Old_Name
);
8991 ("external name does not match that given #",
8995 -- Start of processing for Check_Matching_Internal_Names
8998 if String_Length
(S1
) /= String_Length
(S2
) then
9002 for J
in 1 .. String_Length
(S1
) loop
9003 if Get_String_Char
(S1
, J
) /= Get_String_Char
(S2
, J
) then
9008 end Check_Matching_Internal_Names
;
9010 -- Otherwise set the given name
9013 Set_Encoded_Interface_Name
(Internal_Ent
, New_Name
);
9014 Check_Duplicated_Export_Name
(New_Name
);
9016 end Set_Extended_Import_Export_External_Name
;
9022 procedure Set_Imported
(E
: Entity_Id
) is
9024 -- Error message if already imported or exported
9026 if Is_Exported
(E
) or else Is_Imported
(E
) then
9028 -- Error if being set Exported twice
9030 if Is_Exported
(E
) then
9031 Error_Msg_NE
("entity& was previously exported", N
, E
);
9033 -- Ignore error in CodePeer mode where we treat all imported
9034 -- subprograms as unknown.
9036 elsif CodePeer_Mode
then
9039 -- OK if Import/Interface case
9041 elsif Import_Interface_Present
(N
) then
9044 -- Error if being set Imported twice
9047 Error_Msg_NE
("entity& was previously imported", N
, E
);
9050 Error_Msg_Name_1
:= Pname
;
9052 ("\(pragma% applies to all previous entities)", N
);
9054 Error_Msg_Sloc
:= Sloc
(E
);
9055 Error_Msg_NE
("\import not allowed for& declared#", N
, E
);
9057 -- Here if not previously imported or exported, OK to import
9060 Set_Is_Imported
(E
);
9062 -- For subprogram, set Import_Pragma field
9064 if Is_Subprogram
(E
) then
9065 Set_Import_Pragma
(E
, N
);
9068 -- If the entity is an object that is not at the library level,
9069 -- then it is statically allocated. We do not worry about objects
9070 -- with address clauses in this context since they are not really
9071 -- imported in the linker sense.
9074 and then not Is_Library_Level_Entity
(E
)
9075 and then No
(Address_Clause
(E
))
9077 Set_Is_Statically_Allocated
(E
);
9084 -------------------------
9085 -- Set_Mechanism_Value --
9086 -------------------------
9088 -- Note: the mechanism name has not been analyzed (and cannot indeed be
9089 -- analyzed, since it is semantic nonsense), so we get it in the exact
9090 -- form created by the parser.
9092 procedure Set_Mechanism_Value
(Ent
: Entity_Id
; Mech_Name
: Node_Id
) is
9093 procedure Bad_Mechanism
;
9094 pragma No_Return
(Bad_Mechanism
);
9095 -- Signal bad mechanism name
9097 -------------------------
9098 -- Bad_Mechanism_Value --
9099 -------------------------
9101 procedure Bad_Mechanism
is
9103 Error_Pragma_Arg
("unrecognized mechanism name", Mech_Name
);
9106 -- Start of processing for Set_Mechanism_Value
9109 if Mechanism
(Ent
) /= Default_Mechanism
then
9111 ("mechanism for & has already been set", Mech_Name
, Ent
);
9114 -- MECHANISM_NAME ::= value | reference
9116 if Nkind
(Mech_Name
) = N_Identifier
then
9117 if Chars
(Mech_Name
) = Name_Value
then
9118 Set_Mechanism
(Ent
, By_Copy
);
9121 elsif Chars
(Mech_Name
) = Name_Reference
then
9122 Set_Mechanism
(Ent
, By_Reference
);
9125 elsif Chars
(Mech_Name
) = Name_Copy
then
9127 ("bad mechanism name, Value assumed", Mech_Name
);
9136 end Set_Mechanism_Value
;
9138 --------------------------
9139 -- Set_Rational_Profile --
9140 --------------------------
9142 -- The Rational profile includes Implicit_Packing, Use_Vads_Size, and
9143 -- and extension to the semantics of renaming declarations.
9145 procedure Set_Rational_Profile
is
9147 Implicit_Packing
:= True;
9148 Overriding_Renamings
:= True;
9149 Use_VADS_Size
:= True;
9150 end Set_Rational_Profile
;
9152 ---------------------------
9153 -- Set_Ravenscar_Profile --
9154 ---------------------------
9156 -- The tasks to be done here are
9158 -- Set required policies
9160 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9161 -- pragma Locking_Policy (Ceiling_Locking)
9163 -- Set Detect_Blocking mode
9165 -- Set required restrictions (see System.Rident for detailed list)
9167 -- Set the No_Dependence rules
9168 -- No_Dependence => Ada.Asynchronous_Task_Control
9169 -- No_Dependence => Ada.Calendar
9170 -- No_Dependence => Ada.Execution_Time.Group_Budget
9171 -- No_Dependence => Ada.Execution_Time.Timers
9172 -- No_Dependence => Ada.Task_Attributes
9173 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9175 procedure Set_Ravenscar_Profile
(N
: Node_Id
) is
9176 Prefix_Entity
: Entity_Id
;
9177 Selector_Entity
: Entity_Id
;
9178 Prefix_Node
: Node_Id
;
9182 -- pragma Task_Dispatching_Policy (FIFO_Within_Priorities)
9184 if Task_Dispatching_Policy
/= ' '
9185 and then Task_Dispatching_Policy
/= 'F'
9187 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
9188 Error_Pragma
("Profile (Ravenscar) incompatible with policy#");
9190 -- Set the FIFO_Within_Priorities policy, but always preserve
9191 -- System_Location since we like the error message with the run time
9195 Task_Dispatching_Policy
:= 'F';
9197 if Task_Dispatching_Policy_Sloc
/= System_Location
then
9198 Task_Dispatching_Policy_Sloc
:= Loc
;
9202 -- pragma Locking_Policy (Ceiling_Locking)
9204 if Locking_Policy
/= ' '
9205 and then Locking_Policy
/= 'C'
9207 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
9208 Error_Pragma
("Profile (Ravenscar) incompatible with policy#");
9210 -- Set the Ceiling_Locking policy, but preserve System_Location since
9211 -- we like the error message with the run time name.
9214 Locking_Policy
:= 'C';
9216 if Locking_Policy_Sloc
/= System_Location
then
9217 Locking_Policy_Sloc
:= Loc
;
9221 -- pragma Detect_Blocking
9223 Detect_Blocking
:= True;
9225 -- Set the corresponding restrictions
9227 Set_Profile_Restrictions
9228 (Ravenscar
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
9230 -- Set the No_Dependence restrictions
9232 -- The following No_Dependence restrictions:
9233 -- No_Dependence => Ada.Asynchronous_Task_Control
9234 -- No_Dependence => Ada.Calendar
9235 -- No_Dependence => Ada.Task_Attributes
9236 -- are already set by previous call to Set_Profile_Restrictions.
9238 -- Set the following restrictions which were added to Ada 2005:
9239 -- No_Dependence => Ada.Execution_Time.Group_Budget
9240 -- No_Dependence => Ada.Execution_Time.Timers
9242 if Ada_Version
>= Ada_2005
then
9243 Name_Buffer
(1 .. 3) := "ada";
9246 Prefix_Entity
:= Make_Identifier
(Loc
, Name_Find
);
9248 Name_Buffer
(1 .. 14) := "execution_time";
9251 Selector_Entity
:= Make_Identifier
(Loc
, Name_Find
);
9254 Make_Selected_Component
9256 Prefix
=> Prefix_Entity
,
9257 Selector_Name
=> Selector_Entity
);
9259 Name_Buffer
(1 .. 13) := "group_budgets";
9262 Selector_Entity
:= Make_Identifier
(Loc
, Name_Find
);
9265 Make_Selected_Component
9267 Prefix
=> Prefix_Node
,
9268 Selector_Name
=> Selector_Entity
);
9270 Set_Restriction_No_Dependence
9272 Warn
=> Treat_Restrictions_As_Warnings
,
9273 Profile
=> Ravenscar
);
9275 Name_Buffer
(1 .. 6) := "timers";
9278 Selector_Entity
:= Make_Identifier
(Loc
, Name_Find
);
9281 Make_Selected_Component
9283 Prefix
=> Prefix_Node
,
9284 Selector_Name
=> Selector_Entity
);
9286 Set_Restriction_No_Dependence
9288 Warn
=> Treat_Restrictions_As_Warnings
,
9289 Profile
=> Ravenscar
);
9292 -- Set the following restrictions which was added to Ada 2012 (see
9294 -- No_Dependence => System.Multiprocessors.Dispatching_Domains
9296 if Ada_Version
>= Ada_2012
then
9297 Name_Buffer
(1 .. 6) := "system";
9300 Prefix_Entity
:= Make_Identifier
(Loc
, Name_Find
);
9302 Name_Buffer
(1 .. 15) := "multiprocessors";
9305 Selector_Entity
:= Make_Identifier
(Loc
, Name_Find
);
9308 Make_Selected_Component
9310 Prefix
=> Prefix_Entity
,
9311 Selector_Name
=> Selector_Entity
);
9313 Name_Buffer
(1 .. 19) := "dispatching_domains";
9316 Selector_Entity
:= Make_Identifier
(Loc
, Name_Find
);
9319 Make_Selected_Component
9321 Prefix
=> Prefix_Node
,
9322 Selector_Name
=> Selector_Entity
);
9324 Set_Restriction_No_Dependence
9326 Warn
=> Treat_Restrictions_As_Warnings
,
9327 Profile
=> Ravenscar
);
9329 end Set_Ravenscar_Profile
;
9331 -- Start of processing for Analyze_Pragma
9334 -- The following code is a defense against recursion. Not clear that
9335 -- this can happen legitimately, but perhaps some error situations
9336 -- can cause it, and we did see this recursion during testing.
9338 if Analyzed
(N
) then
9341 Set_Analyzed
(N
, True);
9344 -- Deal with unrecognized pragma
9346 Pname
:= Pragma_Name
(N
);
9348 if not Is_Pragma_Name
(Pname
) then
9349 if Warn_On_Unrecognized_Pragma
then
9350 Error_Msg_Name_1
:= Pname
;
9351 Error_Msg_N
("?g?unrecognized pragma%!", Pragma_Identifier
(N
));
9353 for PN
in First_Pragma_Name
.. Last_Pragma_Name
loop
9354 if Is_Bad_Spelling_Of
(Pname
, PN
) then
9355 Error_Msg_Name_1
:= PN
;
9356 Error_Msg_N
-- CODEFIX
9357 ("\?g?possible misspelling of %!", Pragma_Identifier
(N
));
9366 -- Here to start processing for recognized pragma
9368 Prag_Id
:= Get_Pragma_Id
(Pname
);
9369 Pname
:= Original_Aspect_Pragma_Name
(N
);
9371 -- Capture setting of Opt.Uneval_Old
9373 case Opt
.Uneval_Old
is
9375 Set_Uneval_Old_Accept
(N
);
9379 Set_Uneval_Old_Warn
(N
);
9381 raise Program_Error
;
9384 -- Check applicable policy. We skip this if Is_Checked or Is_Ignored
9385 -- is already set, indicating that we have already checked the policy
9386 -- at the right point. This happens for example in the case of a pragma
9387 -- that is derived from an Aspect.
9389 if Is_Ignored
(N
) or else Is_Checked
(N
) then
9392 -- For a pragma that is a rewriting of another pragma, copy the
9393 -- Is_Checked/Is_Ignored status from the rewritten pragma.
9395 elsif Is_Rewrite_Substitution
(N
)
9396 and then Nkind
(Original_Node
(N
)) = N_Pragma
9397 and then Original_Node
(N
) /= N
9399 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
9400 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
9402 -- Otherwise query the applicable policy at this point
9405 Check_Applicable_Policy
(N
);
9407 -- If pragma is disabled, rewrite as NULL and skip analysis
9409 if Is_Disabled
(N
) then
9410 Rewrite
(N
, Make_Null_Statement
(Loc
));
9424 if Present
(Pragma_Argument_Associations
(N
)) then
9425 Arg_Count
:= List_Length
(Pragma_Argument_Associations
(N
));
9426 Arg1
:= First
(Pragma_Argument_Associations
(N
));
9428 if Present
(Arg1
) then
9429 Arg2
:= Next
(Arg1
);
9431 if Present
(Arg2
) then
9432 Arg3
:= Next
(Arg2
);
9434 if Present
(Arg3
) then
9435 Arg4
:= Next
(Arg3
);
9441 Check_Restriction_No_Use_Of_Pragma
(N
);
9443 -- An enumeration type defines the pragmas that are supported by the
9444 -- implementation. Get_Pragma_Id (in package Prag) transforms a name
9445 -- into the corresponding enumeration value for the following case.
9453 -- pragma Abort_Defer;
9455 when Pragma_Abort_Defer
=>
9457 Check_Arg_Count
(0);
9459 -- The only required semantic processing is to check the
9460 -- placement. This pragma must appear at the start of the
9461 -- statement sequence of a handled sequence of statements.
9463 if Nkind
(Parent
(N
)) /= N_Handled_Sequence_Of_Statements
9464 or else N
/= First
(Statements
(Parent
(N
)))
9469 --------------------
9470 -- Abstract_State --
9471 --------------------
9473 -- pragma Abstract_State (ABSTRACT_STATE_LIST);
9475 -- ABSTRACT_STATE_LIST ::=
9477 -- | STATE_NAME_WITH_OPTIONS
9478 -- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS} )
9480 -- STATE_NAME_WITH_OPTIONS ::=
9482 -- | (STATE_NAME with OPTION_LIST)
9484 -- OPTION_LIST ::= OPTION {, OPTION}
9488 -- | NAME_VALUE_OPTION
9490 -- SIMPLE_OPTION ::= Ghost
9492 -- NAME_VALUE_OPTION ::=
9493 -- Part_Of => ABSTRACT_STATE
9494 -- | External [=> EXTERNAL_PROPERTY_LIST]
9496 -- EXTERNAL_PROPERTY_LIST ::=
9497 -- EXTERNAL_PROPERTY
9498 -- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY} )
9500 -- EXTERNAL_PROPERTY ::=
9501 -- Async_Readers [=> boolean_EXPRESSION]
9502 -- | Async_Writers [=> boolean_EXPRESSION]
9503 -- | Effective_Reads [=> boolean_EXPRESSION]
9504 -- | Effective_Writes [=> boolean_EXPRESSION]
9505 -- others => boolean_EXPRESSION
9507 -- STATE_NAME ::= defining_identifier
9509 -- ABSTRACT_STATE ::= name
9511 when Pragma_Abstract_State
=> Abstract_State
: declare
9512 Missing_Parentheses
: Boolean := False;
9513 -- Flag set when a state declaration with options is not properly
9516 -- Flags used to verify the consistency of states
9518 Non_Null_Seen
: Boolean := False;
9519 Null_Seen
: Boolean := False;
9521 procedure Analyze_Abstract_State
9523 Pack_Id
: Entity_Id
);
9524 -- Verify the legality of a single state declaration. Create and
9525 -- decorate a state abstraction entity and introduce it into the
9526 -- visibility chain. Pack_Id denotes the entity or the related
9527 -- package where pragma Abstract_State appears.
9529 procedure Malformed_State_Error
(State
: Node_Id
);
9530 -- Emit an error concerning the illegal declaration of abstract
9531 -- state State. This routine diagnoses syntax errors that lead to
9532 -- a different parse tree. The error is issued regardless of the
9533 -- SPARK mode in effect.
9535 ----------------------------
9536 -- Analyze_Abstract_State --
9537 ----------------------------
9539 procedure Analyze_Abstract_State
9541 Pack_Id
: Entity_Id
)
9543 -- Flags used to verify the consistency of options
9545 AR_Seen
: Boolean := False;
9546 AW_Seen
: Boolean := False;
9547 ER_Seen
: Boolean := False;
9548 EW_Seen
: Boolean := False;
9549 External_Seen
: Boolean := False;
9550 Others_Seen
: Boolean := False;
9551 Part_Of_Seen
: Boolean := False;
9553 -- Flags used to store the static value of all external states'
9556 AR_Val
: Boolean := False;
9557 AW_Val
: Boolean := False;
9558 ER_Val
: Boolean := False;
9559 EW_Val
: Boolean := False;
9561 State_Id
: Entity_Id
:= Empty
;
9562 -- The entity to be generated for the current state declaration
9564 procedure Analyze_External_Option
(Opt
: Node_Id
);
9565 -- Verify the legality of option External
9567 procedure Analyze_External_Property
9569 Expr
: Node_Id
:= Empty
);
9570 -- Verify the legailty of a single external property. Prop
9571 -- denotes the external property. Expr is the expression used
9572 -- to set the property.
9574 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
);
9575 -- Verify the legality of option Part_Of
9577 procedure Check_Duplicate_Option
9579 Status
: in out Boolean);
9580 -- Flag Status denotes whether a particular option has been
9581 -- seen while processing a state. This routine verifies that
9582 -- Opt is not a duplicate option and sets the flag Status
9583 -- (SPARK RM 7.1.4(1)).
9585 procedure Check_Duplicate_Property
9587 Status
: in out Boolean);
9588 -- Flag Status denotes whether a particular property has been
9589 -- seen while processing option External. This routine verifies
9590 -- that Prop is not a duplicate property and sets flag Status.
9591 -- Opt is not a duplicate property and sets the flag Status.
9592 -- (SPARK RM 7.1.4(2))
9594 procedure Create_Abstract_State
9599 -- Generate an abstract state entity with name Nam and enter it
9600 -- into visibility. Decl is the "declaration" of the state as
9601 -- it appears in pragma Abstract_State. Loc is the location of
9602 -- the related state "declaration". Flag Is_Null should be set
9603 -- when the associated Abstract_State pragma defines a null
9606 -----------------------------
9607 -- Analyze_External_Option --
9608 -----------------------------
9610 procedure Analyze_External_Option
(Opt
: Node_Id
) is
9611 Errors
: constant Nat
:= Serious_Errors_Detected
;
9613 Props
: Node_Id
:= Empty
;
9616 Check_Duplicate_Option
(Opt
, External_Seen
);
9618 if Nkind
(Opt
) = N_Component_Association
then
9619 Props
:= Expression
(Opt
);
9622 -- External state with properties
9624 if Present
(Props
) then
9626 -- Multiple properties appear as an aggregate
9628 if Nkind
(Props
) = N_Aggregate
then
9630 -- Simple property form
9632 Prop
:= First
(Expressions
(Props
));
9633 while Present
(Prop
) loop
9634 Analyze_External_Property
(Prop
);
9638 -- Property with expression form
9640 Prop
:= First
(Component_Associations
(Props
));
9641 while Present
(Prop
) loop
9642 Analyze_External_Property
9643 (Prop
=> First
(Choices
(Prop
)),
9644 Expr
=> Expression
(Prop
));
9652 Analyze_External_Property
(Props
);
9655 -- An external state defined without any properties defaults
9656 -- all properties to True.
9665 -- Once all external properties have been processed, verify
9666 -- their mutual interaction. Do not perform the check when
9667 -- at least one of the properties is illegal as this will
9668 -- produce a bogus error.
9670 if Errors
= Serious_Errors_Detected
then
9671 Check_External_Properties
9672 (State
, AR_Val
, AW_Val
, ER_Val
, EW_Val
);
9674 end Analyze_External_Option
;
9676 -------------------------------
9677 -- Analyze_External_Property --
9678 -------------------------------
9680 procedure Analyze_External_Property
9682 Expr
: Node_Id
:= Empty
)
9687 -- Check the placement of "others" (if available)
9689 if Nkind
(Prop
) = N_Others_Choice
then
9692 ("only one others choice allowed in option External",
9695 Others_Seen
:= True;
9698 elsif Others_Seen
then
9700 ("others must be the last property in option External",
9703 -- The only remaining legal options are the four predefined
9704 -- external properties.
9706 elsif Nkind
(Prop
) = N_Identifier
9707 and then Nam_In
(Chars
(Prop
), Name_Async_Readers
,
9709 Name_Effective_Reads
,
9710 Name_Effective_Writes
)
9714 -- Otherwise the construct is not a valid property
9717 SPARK_Msg_N
("invalid external state property", Prop
);
9721 -- Ensure that the expression of the external state property
9722 -- is static Boolean (if applicable) (SPARK RM 7.1.2(5)).
9724 if Present
(Expr
) then
9725 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
9727 if Is_OK_Static_Expression
(Expr
) then
9728 Expr_Val
:= Is_True
(Expr_Value
(Expr
));
9731 ("expression of external state property must be "
9735 -- The lack of expression defaults the property to True
9743 if Nkind
(Prop
) = N_Identifier
then
9744 if Chars
(Prop
) = Name_Async_Readers
then
9745 Check_Duplicate_Property
(Prop
, AR_Seen
);
9748 elsif Chars
(Prop
) = Name_Async_Writers
then
9749 Check_Duplicate_Property
(Prop
, AW_Seen
);
9752 elsif Chars
(Prop
) = Name_Effective_Reads
then
9753 Check_Duplicate_Property
(Prop
, ER_Seen
);
9757 Check_Duplicate_Property
(Prop
, EW_Seen
);
9761 -- The handling of property "others" must take into account
9762 -- all other named properties that have been encountered so
9763 -- far. Only those that have not been seen are affected by
9783 end Analyze_External_Property
;
9785 ----------------------------
9786 -- Analyze_Part_Of_Option --
9787 ----------------------------
9789 procedure Analyze_Part_Of_Option
(Opt
: Node_Id
) is
9790 Encaps
: constant Node_Id
:= Expression
(Opt
);
9791 Encaps_Id
: Entity_Id
;
9795 Check_Duplicate_Option
(Opt
, Part_Of_Seen
);
9798 (Item_Id
=> State_Id
,
9800 Indic
=> First
(Choices
(Opt
)),
9803 -- The Part_Of indicator turns an abstract state into a
9804 -- constituent of the encapsulating state.
9807 Encaps_Id
:= Entity
(Encaps
);
9809 Append_Elmt
(State_Id
, Part_Of_Constituents
(Encaps_Id
));
9810 Set_Encapsulating_State
(State_Id
, Encaps_Id
);
9812 end Analyze_Part_Of_Option
;
9814 ----------------------------
9815 -- Check_Duplicate_Option --
9816 ----------------------------
9818 procedure Check_Duplicate_Option
9820 Status
: in out Boolean)
9824 SPARK_Msg_N
("duplicate state option", Opt
);
9828 end Check_Duplicate_Option
;
9830 ------------------------------
9831 -- Check_Duplicate_Property --
9832 ------------------------------
9834 procedure Check_Duplicate_Property
9836 Status
: in out Boolean)
9840 SPARK_Msg_N
("duplicate external property", Prop
);
9844 end Check_Duplicate_Property
;
9846 ---------------------------
9847 -- Create_Abstract_State --
9848 ---------------------------
9850 procedure Create_Abstract_State
9857 -- The abstract state may be semi-declared when the related
9858 -- package was withed through a limited with clause. In that
9859 -- case reuse the entity to fully declare the state.
9861 if Present
(Decl
) and then Present
(Entity
(Decl
)) then
9862 State_Id
:= Entity
(Decl
);
9864 -- Otherwise the elaboration of pragma Abstract_State
9865 -- declares the state.
9868 State_Id
:= Make_Defining_Identifier
(Loc
, Nam
);
9870 if Present
(Decl
) then
9871 Set_Entity
(Decl
, State_Id
);
9875 -- Null states never come from source
9877 Set_Comes_From_Source
(State_Id
, not Is_Null
);
9878 Set_Parent
(State_Id
, State
);
9879 Set_Ekind
(State_Id
, E_Abstract_State
);
9880 Set_Etype
(State_Id
, Standard_Void_Type
);
9881 Set_Encapsulating_State
(State_Id
, Empty
);
9882 Set_Refinement_Constituents
(State_Id
, New_Elmt_List
);
9883 Set_Part_Of_Constituents
(State_Id
, New_Elmt_List
);
9885 -- An abstract state declared within a Ghost region becomes
9886 -- Ghost (SPARK RM 6.9(2)).
9888 if Ghost_Mode
> None
then
9889 Set_Is_Ghost_Entity
(State_Id
);
9892 -- Establish a link between the state declaration and the
9893 -- abstract state entity. Note that a null state remains as
9894 -- N_Null and does not carry any linkages.
9897 if Present
(Decl
) then
9898 Set_Entity
(Decl
, State_Id
);
9899 Set_Etype
(Decl
, Standard_Void_Type
);
9902 -- Every non-null state must be defined, nameable and
9905 Push_Scope
(Pack_Id
);
9906 Generate_Definition
(State_Id
);
9907 Enter_Name
(State_Id
);
9910 end Create_Abstract_State
;
9917 -- Start of processing for Analyze_Abstract_State
9920 -- A package with a null abstract state is not allowed to
9921 -- declare additional states.
9925 ("package & has null abstract state", State
, Pack_Id
);
9927 -- Null states appear as internally generated entities
9929 elsif Nkind
(State
) = N_Null
then
9930 Create_Abstract_State
9931 (Nam
=> New_Internal_Name
('S'),
9933 Loc
=> Sloc
(State
),
9937 -- Catch a case where a null state appears in a list of
9940 if Non_Null_Seen
then
9942 ("package & has non-null abstract state",
9946 -- Simple state declaration
9948 elsif Nkind
(State
) = N_Identifier
then
9949 Create_Abstract_State
9950 (Nam
=> Chars
(State
),
9952 Loc
=> Sloc
(State
),
9954 Non_Null_Seen
:= True;
9956 -- State declaration with various options. This construct
9957 -- appears as an extension aggregate in the tree.
9959 elsif Nkind
(State
) = N_Extension_Aggregate
then
9960 if Nkind
(Ancestor_Part
(State
)) = N_Identifier
then
9961 Create_Abstract_State
9962 (Nam
=> Chars
(Ancestor_Part
(State
)),
9963 Decl
=> Ancestor_Part
(State
),
9964 Loc
=> Sloc
(Ancestor_Part
(State
)),
9966 Non_Null_Seen
:= True;
9969 ("state name must be an identifier",
9970 Ancestor_Part
(State
));
9973 -- Options External and Ghost appear as expressions
9975 Opt
:= First
(Expressions
(State
));
9976 while Present
(Opt
) loop
9977 if Nkind
(Opt
) = N_Identifier
then
9978 if Chars
(Opt
) = Name_External
then
9979 Analyze_External_Option
(Opt
);
9981 elsif Chars
(Opt
) = Name_Ghost
then
9982 if Present
(State_Id
) then
9983 Set_Is_Ghost_Entity
(State_Id
);
9986 -- Option Part_Of without an encapsulating state is
9987 -- illegal. (SPARK RM 7.1.4(9)).
9989 elsif Chars
(Opt
) = Name_Part_Of
then
9991 ("indicator Part_Of must denote an abstract "
9994 -- Do not emit an error message when a previous state
9995 -- declaration with options was not parenthesized as
9996 -- the option is actually another state declaration.
9998 -- with Abstract_State
9999 -- (State_1 with ..., -- missing parentheses
10000 -- (State_2 with ...),
10001 -- State_3) -- ok state declaration
10003 elsif Missing_Parentheses
then
10006 -- Otherwise the option is not allowed. Note that it
10007 -- is not possible to distinguish between an option
10008 -- and a state declaration when a previous state with
10009 -- options not properly parentheses.
10011 -- with Abstract_State
10012 -- (State_1 with ..., -- missing parentheses
10013 -- State_2); -- could be an option
10017 ("simple option not allowed in state declaration",
10021 -- Catch a case where missing parentheses around a state
10022 -- declaration with options cause a subsequent state
10023 -- declaration with options to be treated as an option.
10025 -- with Abstract_State
10026 -- (State_1 with ..., -- missing parentheses
10027 -- (State_2 with ...))
10029 elsif Nkind
(Opt
) = N_Extension_Aggregate
then
10030 Missing_Parentheses
:= True;
10032 ("state declaration must be parenthesized",
10033 Ancestor_Part
(State
));
10035 -- Otherwise the option is malformed
10038 SPARK_Msg_N
("malformed option", Opt
);
10044 -- Options External and Part_Of appear as component
10047 Opt
:= First
(Component_Associations
(State
));
10048 while Present
(Opt
) loop
10049 Opt_Nam
:= First
(Choices
(Opt
));
10051 if Nkind
(Opt_Nam
) = N_Identifier
then
10052 if Chars
(Opt_Nam
) = Name_External
then
10053 Analyze_External_Option
(Opt
);
10055 elsif Chars
(Opt_Nam
) = Name_Part_Of
then
10056 Analyze_Part_Of_Option
(Opt
);
10059 SPARK_Msg_N
("invalid state option", Opt
);
10062 SPARK_Msg_N
("invalid state option", Opt
);
10068 -- Any other attempt to declare a state is illegal
10071 Malformed_State_Error
(State
);
10075 -- Guard against a junk state. In such cases no entity is
10076 -- generated and the subsequent checks cannot be applied.
10078 if Present
(State_Id
) then
10080 -- Verify whether the state does not introduce an illegal
10081 -- hidden state within a package subject to a null abstract
10084 Check_No_Hidden_State
(State_Id
);
10086 -- Check whether the lack of option Part_Of agrees with the
10087 -- placement of the abstract state with respect to the state
10090 if not Part_Of_Seen
then
10091 Check_Missing_Part_Of
(State_Id
);
10094 -- Associate the state with its related package
10096 if No
(Abstract_States
(Pack_Id
)) then
10097 Set_Abstract_States
(Pack_Id
, New_Elmt_List
);
10100 Append_Elmt
(State_Id
, Abstract_States
(Pack_Id
));
10102 end Analyze_Abstract_State
;
10104 ---------------------------
10105 -- Malformed_State_Error --
10106 ---------------------------
10108 procedure Malformed_State_Error
(State
: Node_Id
) is
10110 Error_Msg_N
("malformed abstract state declaration", State
);
10112 -- An abstract state with a simple option is being declared
10113 -- with "=>" rather than the legal "with". The state appears
10114 -- as a component association.
10116 if Nkind
(State
) = N_Component_Association
then
10117 Error_Msg_N
("\\use WITH to specify simple option", State
);
10119 end Malformed_State_Error
;
10123 Pack_Decl
: Node_Id
;
10124 Pack_Id
: Entity_Id
;
10128 -- Start of processing for Abstract_State
10132 Check_No_Identifiers
;
10133 Check_Arg_Count
(1);
10135 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
10137 -- Ensure the proper placement of the pragma. Abstract states must
10138 -- be associated with a package declaration.
10140 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
10141 N_Package_Declaration
)
10145 -- Otherwise the pragma is associated with an illegal construct
10152 Ensure_Aggregate_Form
(Get_Argument
(N
));
10153 Pack_Id
:= Defining_Entity
(Pack_Decl
);
10155 -- Mark the associated package as Ghost if it is subject to aspect
10156 -- or pragma Ghost as this affects the declaration of an abstract
10159 if Is_Subject_To_Ghost
(Unit_Declaration_Node
(Pack_Id
)) then
10160 Set_Is_Ghost_Entity
(Pack_Id
);
10163 States
:= Expression
(Get_Argument
(N
));
10165 -- Multiple non-null abstract states appear as an aggregate
10167 if Nkind
(States
) = N_Aggregate
then
10168 State
:= First
(Expressions
(States
));
10169 while Present
(State
) loop
10170 Analyze_Abstract_State
(State
, Pack_Id
);
10174 -- An abstract state with a simple option is being illegaly
10175 -- declared with "=>" rather than "with". In this case the
10176 -- state declaration appears as a component association.
10178 if Present
(Component_Associations
(States
)) then
10179 State
:= First
(Component_Associations
(States
));
10180 while Present
(State
) loop
10181 Malformed_State_Error
(State
);
10186 -- Various forms of a single abstract state. Note that these may
10187 -- include malformed state declarations.
10190 Analyze_Abstract_State
(States
, Pack_Id
);
10193 -- Save the pragma for retrieval by other tools
10195 Add_Contract_Item
(N
, Pack_Id
);
10197 -- Verify the declaration order of pragmas Abstract_State and
10200 Check_Declaration_Order
10202 Second
=> Get_Pragma
(Pack_Id
, Pragma_Initializes
));
10203 end Abstract_State
;
10211 -- Note: this pragma also has some specific processing in Par.Prag
10212 -- because we want to set the Ada version mode during parsing.
10214 when Pragma_Ada_83
=>
10216 Check_Arg_Count
(0);
10218 -- We really should check unconditionally for proper configuration
10219 -- pragma placement, since we really don't want mixed Ada modes
10220 -- within a single unit, and the GNAT reference manual has always
10221 -- said this was a configuration pragma, but we did not check and
10222 -- are hesitant to add the check now.
10224 -- However, we really cannot tolerate mixing Ada 2005 or Ada 2012
10225 -- with Ada 83 or Ada 95, so we must check if we are in Ada 2005
10226 -- or Ada 2012 mode.
10228 if Ada_Version
>= Ada_2005
then
10229 Check_Valid_Configuration_Pragma
;
10232 -- Now set Ada 83 mode
10234 Ada_Version
:= Ada_83
;
10235 Ada_Version_Explicit
:= Ada_83
;
10236 Ada_Version_Pragma
:= N
;
10244 -- Note: this pragma also has some specific processing in Par.Prag
10245 -- because we want to set the Ada 83 version mode during parsing.
10247 when Pragma_Ada_95
=>
10249 Check_Arg_Count
(0);
10251 -- We really should check unconditionally for proper configuration
10252 -- pragma placement, since we really don't want mixed Ada modes
10253 -- within a single unit, and the GNAT reference manual has always
10254 -- said this was a configuration pragma, but we did not check and
10255 -- are hesitant to add the check now.
10257 -- However, we really cannot tolerate mixing Ada 2005 with Ada 83
10258 -- or Ada 95, so we must check if we are in Ada 2005 mode.
10260 if Ada_Version
>= Ada_2005
then
10261 Check_Valid_Configuration_Pragma
;
10264 -- Now set Ada 95 mode
10266 Ada_Version
:= Ada_95
;
10267 Ada_Version_Explicit
:= Ada_95
;
10268 Ada_Version_Pragma
:= N
;
10270 ---------------------
10271 -- Ada_05/Ada_2005 --
10272 ---------------------
10275 -- pragma Ada_05 (LOCAL_NAME);
10277 -- pragma Ada_2005;
10278 -- pragma Ada_2005 (LOCAL_NAME):
10280 -- Note: these pragmas also have some specific processing in Par.Prag
10281 -- because we want to set the Ada 2005 version mode during parsing.
10283 -- The one argument form is used for managing the transition from
10284 -- Ada 95 to Ada 2005 in the run-time library. If an entity is marked
10285 -- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95
10286 -- mode will generate a warning. In addition, in Ada_83 or Ada_95
10287 -- mode, a preference rule is established which does not choose
10288 -- such an entity unless it is unambiguously specified. This avoids
10289 -- extra subprograms marked this way from generating ambiguities in
10290 -- otherwise legal pre-Ada_2005 programs. The one argument form is
10291 -- intended for exclusive use in the GNAT run-time library.
10293 when Pragma_Ada_05 | Pragma_Ada_2005
=> declare
10299 if Arg_Count
= 1 then
10300 Check_Arg_Is_Local_Name
(Arg1
);
10301 E_Id
:= Get_Pragma_Arg
(Arg1
);
10303 if Etype
(E_Id
) = Any_Type
then
10307 Set_Is_Ada_2005_Only
(Entity
(E_Id
));
10308 Record_Rep_Item
(Entity
(E_Id
), N
);
10311 Check_Arg_Count
(0);
10313 -- For Ada_2005 we unconditionally enforce the documented
10314 -- configuration pragma placement, since we do not want to
10315 -- tolerate mixed modes in a unit involving Ada 2005. That
10316 -- would cause real difficulties for those cases where there
10317 -- are incompatibilities between Ada 95 and Ada 2005.
10319 Check_Valid_Configuration_Pragma
;
10321 -- Now set appropriate Ada mode
10323 Ada_Version
:= Ada_2005
;
10324 Ada_Version_Explicit
:= Ada_2005
;
10325 Ada_Version_Pragma
:= N
;
10329 ---------------------
10330 -- Ada_12/Ada_2012 --
10331 ---------------------
10334 -- pragma Ada_12 (LOCAL_NAME);
10336 -- pragma Ada_2012;
10337 -- pragma Ada_2012 (LOCAL_NAME):
10339 -- Note: these pragmas also have some specific processing in Par.Prag
10340 -- because we want to set the Ada 2012 version mode during parsing.
10342 -- The one argument form is used for managing the transition from Ada
10343 -- 2005 to Ada 2012 in the run-time library. If an entity is marked
10344 -- as Ada_201 only, then referencing the entity in any pre-Ada_2012
10345 -- mode will generate a warning. In addition, in any pre-Ada_2012
10346 -- mode, a preference rule is established which does not choose
10347 -- such an entity unless it is unambiguously specified. This avoids
10348 -- extra subprograms marked this way from generating ambiguities in
10349 -- otherwise legal pre-Ada_2012 programs. The one argument form is
10350 -- intended for exclusive use in the GNAT run-time library.
10352 when Pragma_Ada_12 | Pragma_Ada_2012
=> declare
10358 if Arg_Count
= 1 then
10359 Check_Arg_Is_Local_Name
(Arg1
);
10360 E_Id
:= Get_Pragma_Arg
(Arg1
);
10362 if Etype
(E_Id
) = Any_Type
then
10366 Set_Is_Ada_2012_Only
(Entity
(E_Id
));
10367 Record_Rep_Item
(Entity
(E_Id
), N
);
10370 Check_Arg_Count
(0);
10372 -- For Ada_2012 we unconditionally enforce the documented
10373 -- configuration pragma placement, since we do not want to
10374 -- tolerate mixed modes in a unit involving Ada 2012. That
10375 -- would cause real difficulties for those cases where there
10376 -- are incompatibilities between Ada 95 and Ada 2012. We could
10377 -- allow mixing of Ada 2005 and Ada 2012 but it's not worth it.
10379 Check_Valid_Configuration_Pragma
;
10381 -- Now set appropriate Ada mode
10383 Ada_Version
:= Ada_2012
;
10384 Ada_Version_Explicit
:= Ada_2012
;
10385 Ada_Version_Pragma
:= N
;
10389 ----------------------
10390 -- All_Calls_Remote --
10391 ----------------------
10393 -- pragma All_Calls_Remote [(library_package_NAME)];
10395 when Pragma_All_Calls_Remote
=> All_Calls_Remote
: declare
10396 Lib_Entity
: Entity_Id
;
10399 Check_Ada_83_Warning
;
10400 Check_Valid_Library_Unit_Pragma
;
10402 if Nkind
(N
) = N_Null_Statement
then
10406 Lib_Entity
:= Find_Lib_Unit_Name
;
10408 -- This pragma should only apply to a RCI unit (RM E.2.3(23))
10410 if Present
(Lib_Entity
)
10411 and then not Debug_Flag_U
10413 if not Is_Remote_Call_Interface
(Lib_Entity
) then
10414 Error_Pragma
("pragma% only apply to rci unit");
10416 -- Set flag for entity of the library unit
10419 Set_Has_All_Calls_Remote
(Lib_Entity
);
10423 end All_Calls_Remote
;
10425 ---------------------------
10426 -- Allow_Integer_Address --
10427 ---------------------------
10429 -- pragma Allow_Integer_Address;
10431 when Pragma_Allow_Integer_Address
=>
10433 Check_Valid_Configuration_Pragma
;
10434 Check_Arg_Count
(0);
10436 -- If Address is a private type, then set the flag to allow
10437 -- integer address values. If Address is not private, then this
10438 -- pragma has no purpose, so it is simply ignored. Not clear if
10439 -- there are any such targets now.
10441 if Opt
.Address_Is_Private
then
10442 Opt
.Allow_Integer_Address
:= True;
10450 -- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]);
10451 -- ARG ::= NAME | EXPRESSION
10453 -- The first two arguments are by convention intended to refer to an
10454 -- external tool and a tool-specific function. These arguments are
10457 when Pragma_Annotate
=> Annotate
: declare
10463 Check_At_Least_N_Arguments
(1);
10465 -- See if last argument is Entity => local_Name, and if so process
10466 -- and then remove it for remaining processing.
10469 Last_Arg
: constant Node_Id
:=
10470 Last
(Pragma_Argument_Associations
(N
));
10473 if Nkind
(Last_Arg
) = N_Pragma_Argument_Association
10474 and then Chars
(Last_Arg
) = Name_Entity
10476 Check_Arg_Is_Local_Name
(Last_Arg
);
10477 Arg_Count
:= Arg_Count
- 1;
10479 -- Not allowed in compiler units (bootstrap issues)
10481 Check_Compiler_Unit
("Entity for pragma Annotate", N
);
10485 -- Continue processing with last argument removed for now
10487 Check_Arg_Is_Identifier
(Arg1
);
10488 Check_No_Identifiers
;
10491 -- Second parameter is optional, it is never analyzed
10496 -- Here if we have a second parameter
10499 -- Second parameter must be identifier
10501 Check_Arg_Is_Identifier
(Arg2
);
10503 -- Process remaining parameters if any
10505 Arg
:= Next
(Arg2
);
10506 while Present
(Arg
) loop
10507 Exp
:= Get_Pragma_Arg
(Arg
);
10510 if Is_Entity_Name
(Exp
) then
10513 -- For string literals, we assume Standard_String as the
10514 -- type, unless the string contains wide or wide_wide
10517 elsif Nkind
(Exp
) = N_String_Literal
then
10518 if Has_Wide_Wide_Character
(Exp
) then
10519 Resolve
(Exp
, Standard_Wide_Wide_String
);
10520 elsif Has_Wide_Character
(Exp
) then
10521 Resolve
(Exp
, Standard_Wide_String
);
10523 Resolve
(Exp
, Standard_String
);
10526 elsif Is_Overloaded
(Exp
) then
10528 ("ambiguous argument for pragma%", Exp
);
10539 -------------------------------------------------
10540 -- Assert/Assert_And_Cut/Assume/Loop_Invariant --
10541 -------------------------------------------------
10544 -- ( [Check => ] Boolean_EXPRESSION
10545 -- [, [Message =>] Static_String_EXPRESSION]);
10547 -- pragma Assert_And_Cut
10548 -- ( [Check => ] Boolean_EXPRESSION
10549 -- [, [Message =>] Static_String_EXPRESSION]);
10552 -- ( [Check => ] Boolean_EXPRESSION
10553 -- [, [Message =>] Static_String_EXPRESSION]);
10555 -- pragma Loop_Invariant
10556 -- ( [Check => ] Boolean_EXPRESSION
10557 -- [, [Message =>] Static_String_EXPRESSION]);
10559 when Pragma_Assert |
10560 Pragma_Assert_And_Cut |
10562 Pragma_Loop_Invariant
=>
10564 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean;
10565 -- Determine whether expression Expr contains a Loop_Entry
10566 -- attribute reference.
10568 -------------------------
10569 -- Contains_Loop_Entry --
10570 -------------------------
10572 function Contains_Loop_Entry
(Expr
: Node_Id
) return Boolean is
10573 Has_Loop_Entry
: Boolean := False;
10575 function Process
(N
: Node_Id
) return Traverse_Result
;
10576 -- Process function for traversal to look for Loop_Entry
10582 function Process
(N
: Node_Id
) return Traverse_Result
is
10584 if Nkind
(N
) = N_Attribute_Reference
10585 and then Attribute_Name
(N
) = Name_Loop_Entry
10587 Has_Loop_Entry
:= True;
10594 procedure Traverse
is new Traverse_Proc
(Process
);
10596 -- Start of processing for Contains_Loop_Entry
10600 return Has_Loop_Entry
;
10601 end Contains_Loop_Entry
;
10608 -- Start of processing for Assert
10611 -- Assert is an Ada 2005 RM-defined pragma
10613 if Prag_Id
= Pragma_Assert
then
10616 -- The remaining ones are GNAT pragmas
10622 Check_At_Least_N_Arguments
(1);
10623 Check_At_Most_N_Arguments
(2);
10624 Check_Arg_Order
((Name_Check
, Name_Message
));
10625 Check_Optional_Identifier
(Arg1
, Name_Check
);
10626 Expr
:= Get_Pragma_Arg
(Arg1
);
10628 -- Special processing for Loop_Invariant, Loop_Variant or for
10629 -- other cases where a Loop_Entry attribute is present. If the
10630 -- assertion pragma contains attribute Loop_Entry, ensure that
10631 -- the related pragma is within a loop.
10633 if Prag_Id
= Pragma_Loop_Invariant
10634 or else Prag_Id
= Pragma_Loop_Variant
10635 or else Contains_Loop_Entry
(Expr
)
10637 Check_Loop_Pragma_Placement
;
10639 -- Perform preanalysis to deal with embedded Loop_Entry
10642 Preanalyze_Assert_Expression
(Expression
(Arg1
), Any_Boolean
);
10645 -- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating
10646 -- a corresponding Check pragma:
10648 -- pragma Check (name, condition [, msg]);
10650 -- Where name is the identifier matching the pragma name. So
10651 -- rewrite pragma in this manner, transfer the message argument
10652 -- if present, and analyze the result
10654 -- Note: When dealing with a semantically analyzed tree, the
10655 -- information that a Check node N corresponds to a source Assert,
10656 -- Assume, or Assert_And_Cut pragma can be retrieved from the
10657 -- pragma kind of Original_Node(N).
10660 Make_Pragma_Argument_Association
(Loc
,
10661 Expression
=> Make_Identifier
(Loc
, Pname
)),
10662 Make_Pragma_Argument_Association
(Sloc
(Expr
),
10663 Expression
=> Expr
));
10665 if Arg_Count
> 1 then
10666 Check_Optional_Identifier
(Arg2
, Name_Message
);
10668 -- Provide semantic annnotations for optional argument, for
10669 -- ASIS use, before rewriting.
10671 Preanalyze_And_Resolve
(Expression
(Arg2
), Standard_String
);
10672 Append_To
(Newa
, New_Copy_Tree
(Arg2
));
10675 -- Rewrite as Check pragma
10679 Chars
=> Name_Check
,
10680 Pragma_Argument_Associations
=> Newa
));
10684 ----------------------
10685 -- Assertion_Policy --
10686 ----------------------
10688 -- pragma Assertion_Policy (POLICY_IDENTIFIER);
10690 -- The following form is Ada 2012 only, but we allow it in all modes
10692 -- Pragma Assertion_Policy (
10693 -- ASSERTION_KIND => POLICY_IDENTIFIER
10694 -- {, ASSERTION_KIND => POLICY_IDENTIFIER});
10696 -- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND
10698 -- RM_ASSERTION_KIND ::= Assert |
10699 -- Static_Predicate |
10700 -- Dynamic_Predicate |
10705 -- Type_Invariant |
10706 -- Type_Invariant'Class
10708 -- ID_ASSERTION_KIND ::= Assert_And_Cut |
10710 -- Contract_Cases |
10712 -- Default_Initial_Condition |
10714 -- Initial_Condition |
10715 -- Loop_Invariant |
10721 -- Statement_Assertions
10723 -- Note: The RM_ASSERTION_KIND list is language-defined, and the
10724 -- ID_ASSERTION_KIND list contains implementation-defined additions
10725 -- recognized by GNAT. The effect is to control the behavior of
10726 -- identically named aspects and pragmas, depending on the specified
10727 -- policy identifier:
10729 -- POLICY_IDENTIFIER ::= Check | Disable | Ignore
10731 -- Note: Check and Ignore are language-defined. Disable is a GNAT
10732 -- implementation defined addition that results in totally ignoring
10733 -- the corresponding assertion. If Disable is specified, then the
10734 -- argument of the assertion is not even analyzed. This is useful
10735 -- when the aspect/pragma argument references entities in a with'ed
10736 -- package that is replaced by a dummy package in the final build.
10738 -- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class,
10739 -- and Type_Invariant'Class were recognized by the parser and
10740 -- transformed into references to the special internal identifiers
10741 -- _Pre, _Post, _Invariant, and _Type_Invariant, so no special
10742 -- processing is required here.
10744 when Pragma_Assertion_Policy
=> Assertion_Policy
: declare
10753 -- This can always appear as a configuration pragma
10755 if Is_Configuration_Pragma
then
10758 -- It can also appear in a declarative part or package spec in Ada
10759 -- 2012 mode. We allow this in other modes, but in that case we
10760 -- consider that we have an Ada 2012 pragma on our hands.
10763 Check_Is_In_Decl_Part_Or_Package_Spec
;
10767 -- One argument case with no identifier (first form above)
10770 and then (Nkind
(Arg1
) /= N_Pragma_Argument_Association
10771 or else Chars
(Arg1
) = No_Name
)
10773 Check_Arg_Is_One_Of
10774 (Arg1
, Name_Check
, Name_Disable
, Name_Ignore
);
10776 -- Treat one argument Assertion_Policy as equivalent to:
10778 -- pragma Check_Policy (Assertion, policy)
10780 -- So rewrite pragma in that manner and link on to the chain
10781 -- of Check_Policy pragmas, marking the pragma as analyzed.
10783 Policy
:= Get_Pragma_Arg
(Arg1
);
10787 Chars
=> Name_Check_Policy
,
10788 Pragma_Argument_Associations
=> New_List
(
10789 Make_Pragma_Argument_Association
(Loc
,
10790 Expression
=> Make_Identifier
(Loc
, Name_Assertion
)),
10792 Make_Pragma_Argument_Association
(Loc
,
10794 Make_Identifier
(Sloc
(Policy
), Chars
(Policy
))))));
10797 -- Here if we have two or more arguments
10800 Check_At_Least_N_Arguments
(1);
10803 -- Loop through arguments
10806 while Present
(Arg
) loop
10807 LocP
:= Sloc
(Arg
);
10809 -- Kind must be specified
10811 if Nkind
(Arg
) /= N_Pragma_Argument_Association
10812 or else Chars
(Arg
) = No_Name
10815 ("missing assertion kind for pragma%", Arg
);
10818 -- Check Kind and Policy have allowed forms
10820 Kind
:= Chars
(Arg
);
10822 if not Is_Valid_Assertion_Kind
(Kind
) then
10824 ("invalid assertion kind for pragma%", Arg
);
10827 Check_Arg_Is_One_Of
10828 (Arg
, Name_Check
, Name_Disable
, Name_Ignore
);
10830 -- Rewrite the Assertion_Policy pragma as a series of
10831 -- Check_Policy pragmas of the form:
10833 -- Check_Policy (Kind, Policy);
10835 -- Note: the insertion of the pragmas cannot be done with
10836 -- Insert_Action because in the configuration case, there
10837 -- are no scopes on the scope stack and the mechanism will
10840 Insert_Before_And_Analyze
(N
,
10842 Chars
=> Name_Check_Policy
,
10843 Pragma_Argument_Associations
=> New_List
(
10844 Make_Pragma_Argument_Association
(LocP
,
10845 Expression
=> Make_Identifier
(LocP
, Kind
)),
10846 Make_Pragma_Argument_Association
(LocP
,
10847 Expression
=> Get_Pragma_Arg
(Arg
)))));
10852 -- Rewrite the Assertion_Policy pragma as null since we have
10853 -- now inserted all the equivalent Check pragmas.
10855 Rewrite
(N
, Make_Null_Statement
(Loc
));
10858 end Assertion_Policy
;
10860 ------------------------------
10861 -- Assume_No_Invalid_Values --
10862 ------------------------------
10864 -- pragma Assume_No_Invalid_Values (On | Off);
10866 when Pragma_Assume_No_Invalid_Values
=>
10868 Check_Valid_Configuration_Pragma
;
10869 Check_Arg_Count
(1);
10870 Check_No_Identifiers
;
10871 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
10873 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
10874 Assume_No_Invalid_Values
:= True;
10876 Assume_No_Invalid_Values
:= False;
10879 --------------------------
10880 -- Attribute_Definition --
10881 --------------------------
10883 -- pragma Attribute_Definition
10884 -- ([Attribute =>] ATTRIBUTE_DESIGNATOR,
10885 -- [Entity =>] LOCAL_NAME,
10886 -- [Expression =>] EXPRESSION | NAME);
10888 when Pragma_Attribute_Definition
=> Attribute_Definition
: declare
10889 Attribute_Designator
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
10894 Check_Arg_Count
(3);
10895 Check_Optional_Identifier
(Arg1
, "attribute");
10896 Check_Optional_Identifier
(Arg2
, "entity");
10897 Check_Optional_Identifier
(Arg3
, "expression");
10899 if Nkind
(Attribute_Designator
) /= N_Identifier
then
10900 Error_Msg_N
("attribute name expected", Attribute_Designator
);
10904 Check_Arg_Is_Local_Name
(Arg2
);
10906 -- If the attribute is not recognized, then issue a warning (not
10907 -- an error), and ignore the pragma.
10909 Aname
:= Chars
(Attribute_Designator
);
10911 if not Is_Attribute_Name
(Aname
) then
10912 Bad_Attribute
(Attribute_Designator
, Aname
, Warn
=> True);
10916 -- Otherwise, rewrite the pragma as an attribute definition clause
10919 Make_Attribute_Definition_Clause
(Loc
,
10920 Name
=> Get_Pragma_Arg
(Arg2
),
10922 Expression
=> Get_Pragma_Arg
(Arg3
)));
10924 end Attribute_Definition
;
10926 ------------------------------------------------------------------
10927 -- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes --
10928 ------------------------------------------------------------------
10930 -- pragma Asynch_Readers ( object_LOCAL_NAME [, FLAG] );
10931 -- pragma Asynch_Writers ( object_LOCAL_NAME [, FLAG] );
10932 -- pragma Effective_Reads ( object_LOCAL_NAME [, FLAG] );
10933 -- pragma Effective_Writes ( object_LOCAL_NAME [, FLAG] );
10935 -- FLAG ::= boolean_EXPRESSION
10937 when Pragma_Async_Readers |
10938 Pragma_Async_Writers |
10939 Pragma_Effective_Reads |
10940 Pragma_Effective_Writes
=>
10941 Async_Effective
: declare
10945 Obj_Id
: Entity_Id
;
10949 Check_No_Identifiers
;
10950 Check_At_Least_N_Arguments
(1);
10951 Check_At_Most_N_Arguments
(2);
10952 Check_Arg_Is_Local_Name
(Arg1
);
10953 Error_Msg_Name_1
:= Pname
;
10955 Obj
:= Get_Pragma_Arg
(Arg1
);
10956 Expr
:= Get_Pragma_Arg
(Arg2
);
10958 -- Perform minimal verification to ensure that the argument is at
10959 -- least a variable. Subsequent finer grained checks will be done
10960 -- at the end of the declarative region the contains the pragma.
10962 if Is_Entity_Name
(Obj
)
10963 and then Present
(Entity
(Obj
))
10964 and then Ekind
(Entity
(Obj
)) = E_Variable
10966 Obj_Id
:= Entity
(Obj
);
10968 -- Detect a duplicate pragma. Note that it is not efficient to
10969 -- examine preceding statements as Boolean aspects may appear
10970 -- anywhere between the related object declaration and its
10971 -- freeze point. As an alternative, inspect the contents of the
10972 -- variable contract.
10974 Duplic
:= Get_Pragma
(Obj_Id
, Prag_Id
);
10976 if Present
(Duplic
) then
10977 Error_Msg_Sloc
:= Sloc
(Duplic
);
10978 Error_Msg_N
("pragma % duplicates pragma declared #", N
);
10980 -- No duplicate detected
10983 if Present
(Expr
) then
10984 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
10987 -- Chain the pragma on the contract for further processing
10989 Add_Contract_Item
(N
, Obj_Id
);
10992 Error_Pragma
("pragma % must apply to a volatile object");
10994 end Async_Effective
;
11000 -- pragma Asynchronous (LOCAL_NAME);
11002 when Pragma_Asynchronous
=> Asynchronous
: declare
11008 Formal
: Entity_Id
;
11010 procedure Process_Async_Pragma
;
11011 -- Common processing for procedure and access-to-procedure case
11013 --------------------------
11014 -- Process_Async_Pragma --
11015 --------------------------
11017 procedure Process_Async_Pragma
is
11020 Set_Is_Asynchronous
(Nm
);
11024 -- The formals should be of mode IN (RM E.4.1(6))
11027 while Present
(S
) loop
11028 Formal
:= Defining_Identifier
(S
);
11030 if Nkind
(Formal
) = N_Defining_Identifier
11031 and then Ekind
(Formal
) /= E_In_Parameter
11034 ("pragma% procedure can only have IN parameter",
11041 Set_Is_Asynchronous
(Nm
);
11042 end Process_Async_Pragma
;
11044 -- Start of processing for pragma Asynchronous
11047 Check_Ada_83_Warning
;
11048 Check_No_Identifiers
;
11049 Check_Arg_Count
(1);
11050 Check_Arg_Is_Local_Name
(Arg1
);
11052 if Debug_Flag_U
then
11056 C_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
11057 Analyze
(Get_Pragma_Arg
(Arg1
));
11058 Nm
:= Entity
(Get_Pragma_Arg
(Arg1
));
11060 if not Is_Remote_Call_Interface
(C_Ent
)
11061 and then not Is_Remote_Types
(C_Ent
)
11063 -- This pragma should only appear in an RCI or Remote Types
11064 -- unit (RM E.4.1(4)).
11067 ("pragma% not in Remote_Call_Interface or Remote_Types unit");
11070 if Ekind
(Nm
) = E_Procedure
11071 and then Nkind
(Parent
(Nm
)) = N_Procedure_Specification
11073 if not Is_Remote_Call_Interface
(Nm
) then
11075 ("pragma% cannot be applied on non-remote procedure",
11079 L
:= Parameter_Specifications
(Parent
(Nm
));
11080 Process_Async_Pragma
;
11083 elsif Ekind
(Nm
) = E_Function
then
11085 ("pragma% cannot be applied to function", Arg1
);
11087 elsif Is_Remote_Access_To_Subprogram_Type
(Nm
) then
11088 if Is_Record_Type
(Nm
) then
11090 -- A record type that is the Equivalent_Type for a remote
11091 -- access-to-subprogram type.
11093 N
:= Declaration_Node
(Corresponding_Remote_Type
(Nm
));
11096 -- A non-expanded RAS type (distribution is not enabled)
11098 N
:= Declaration_Node
(Nm
);
11101 if Nkind
(N
) = N_Full_Type_Declaration
11102 and then Nkind
(Type_Definition
(N
)) =
11103 N_Access_Procedure_Definition
11105 L
:= Parameter_Specifications
(Type_Definition
(N
));
11106 Process_Async_Pragma
;
11108 if Is_Asynchronous
(Nm
)
11109 and then Expander_Active
11110 and then Get_PCS_Name
/= Name_No_DSA
11112 RACW_Type_Is_Asynchronous
(Underlying_RACW_Type
(Nm
));
11117 ("pragma% cannot reference access-to-function type",
11121 -- Only other possibility is Access-to-class-wide type
11123 elsif Is_Access_Type
(Nm
)
11124 and then Is_Class_Wide_Type
(Designated_Type
(Nm
))
11126 Check_First_Subtype
(Arg1
);
11127 Set_Is_Asynchronous
(Nm
);
11128 if Expander_Active
then
11129 RACW_Type_Is_Asynchronous
(Nm
);
11133 Error_Pragma_Arg
("inappropriate argument for pragma%", Arg1
);
11141 -- pragma Atomic (LOCAL_NAME);
11143 when Pragma_Atomic
=>
11144 Process_Atomic_Independent_Shared_Volatile
;
11146 -----------------------
11147 -- Atomic_Components --
11148 -----------------------
11150 -- pragma Atomic_Components (array_LOCAL_NAME);
11152 -- This processing is shared by Volatile_Components
11154 when Pragma_Atomic_Components |
11155 Pragma_Volatile_Components
=>
11157 Atomic_Components
: declare
11164 Check_Ada_83_Warning
;
11165 Check_No_Identifiers
;
11166 Check_Arg_Count
(1);
11167 Check_Arg_Is_Local_Name
(Arg1
);
11168 E_Id
:= Get_Pragma_Arg
(Arg1
);
11170 if Etype
(E_Id
) = Any_Type
then
11174 E
:= Entity
(E_Id
);
11176 Check_Duplicate_Pragma
(E
);
11178 if Rep_Item_Too_Early
(E
, N
)
11180 Rep_Item_Too_Late
(E
, N
)
11185 D
:= Declaration_Node
(E
);
11188 if (K
= N_Full_Type_Declaration
and then Is_Array_Type
(E
))
11190 ((Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
11191 and then Nkind
(D
) = N_Object_Declaration
11192 and then Nkind
(Object_Definition
(D
)) =
11193 N_Constrained_Array_Definition
)
11195 -- The flag is set on the object, or on the base type
11197 if Nkind
(D
) /= N_Object_Declaration
then
11198 E
:= Base_Type
(E
);
11201 -- Atomic implies both Independent and Volatile
11203 if Prag_Id
= Pragma_Atomic_Components
then
11204 Set_Has_Atomic_Components
(E
);
11205 Set_Has_Independent_Components
(E
);
11208 Set_Has_Volatile_Components
(E
);
11211 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
11213 end Atomic_Components
;
11215 --------------------
11216 -- Attach_Handler --
11217 --------------------
11219 -- pragma Attach_Handler (handler_NAME, EXPRESSION);
11221 when Pragma_Attach_Handler
=>
11222 Check_Ada_83_Warning
;
11223 Check_No_Identifiers
;
11224 Check_Arg_Count
(2);
11226 if No_Run_Time_Mode
then
11227 Error_Msg_CRT
("Attach_Handler pragma", N
);
11229 Check_Interrupt_Or_Attach_Handler
;
11231 -- The expression that designates the attribute may depend on a
11232 -- discriminant, and is therefore a per-object expression, to
11233 -- be expanded in the init proc. If expansion is enabled, then
11234 -- perform semantic checks on a copy only.
11239 Parg2
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
11242 -- In Relaxed_RM_Semantics mode, we allow any static
11243 -- integer value, for compatibility with other compilers.
11245 if Relaxed_RM_Semantics
11246 and then Nkind
(Parg2
) = N_Integer_Literal
11248 Typ
:= Standard_Integer
;
11250 Typ
:= RTE
(RE_Interrupt_ID
);
11253 if Expander_Active
then
11254 Temp
:= New_Copy_Tree
(Parg2
);
11255 Set_Parent
(Temp
, N
);
11256 Preanalyze_And_Resolve
(Temp
, Typ
);
11259 Resolve
(Parg2
, Typ
);
11263 Process_Interrupt_Or_Attach_Handler
;
11266 --------------------
11267 -- C_Pass_By_Copy --
11268 --------------------
11270 -- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION);
11272 when Pragma_C_Pass_By_Copy
=> C_Pass_By_Copy
: declare
11278 Check_Valid_Configuration_Pragma
;
11279 Check_Arg_Count
(1);
11280 Check_Optional_Identifier
(Arg1
, "max_size");
11282 Arg
:= Get_Pragma_Arg
(Arg1
);
11283 Check_Arg_Is_OK_Static_Expression
(Arg
, Any_Integer
);
11285 Val
:= Expr_Value
(Arg
);
11289 ("maximum size for pragma% must be positive", Arg1
);
11291 elsif UI_Is_In_Int_Range
(Val
) then
11292 Default_C_Record_Mechanism
:= UI_To_Int
(Val
);
11294 -- If a giant value is given, Int'Last will do well enough.
11295 -- If sometime someone complains that a record larger than
11296 -- two gigabytes is not copied, we will worry about it then.
11299 Default_C_Record_Mechanism
:= Mechanism_Type
'Last;
11301 end C_Pass_By_Copy
;
11307 -- pragma Check ([Name =>] CHECK_KIND,
11308 -- [Check =>] Boolean_EXPRESSION
11309 -- [,[Message =>] String_EXPRESSION]);
11311 -- CHECK_KIND ::= IDENTIFIER |
11314 -- Invariant'Class |
11315 -- Type_Invariant'Class
11317 -- The identifiers Assertions and Statement_Assertions are not
11318 -- allowed, since they have special meaning for Check_Policy.
11320 when Pragma_Check
=> Check
: declare
11328 Check_At_Least_N_Arguments
(2);
11329 Check_At_Most_N_Arguments
(3);
11330 Check_Optional_Identifier
(Arg1
, Name_Name
);
11331 Check_Optional_Identifier
(Arg2
, Name_Check
);
11333 if Arg_Count
= 3 then
11334 Check_Optional_Identifier
(Arg3
, Name_Message
);
11335 Str
:= Get_Pragma_Arg
(Arg3
);
11338 Rewrite_Assertion_Kind
(Get_Pragma_Arg
(Arg1
));
11339 Check_Arg_Is_Identifier
(Arg1
);
11340 Cname
:= Chars
(Get_Pragma_Arg
(Arg1
));
11342 -- Check forbidden name Assertions or Statement_Assertions
11345 when Name_Assertions
=>
11347 ("""Assertions"" is not allowed as a check kind "
11348 & "for pragma%", Arg1
);
11350 when Name_Statement_Assertions
=>
11352 ("""Statement_Assertions"" is not allowed as a check kind "
11353 & "for pragma%", Arg1
);
11359 -- Check applicable policy. We skip this if Checked/Ignored status
11360 -- is already set (e.g. in the casse of a pragma from an aspect).
11362 if Is_Checked
(N
) or else Is_Ignored
(N
) then
11365 -- For a non-source pragma that is a rewriting of another pragma,
11366 -- copy the Is_Checked/Ignored status from the rewritten pragma.
11368 elsif Is_Rewrite_Substitution
(N
)
11369 and then Nkind
(Original_Node
(N
)) = N_Pragma
11370 and then Original_Node
(N
) /= N
11372 Set_Is_Ignored
(N
, Is_Ignored
(Original_Node
(N
)));
11373 Set_Is_Checked
(N
, Is_Checked
(Original_Node
(N
)));
11375 -- Otherwise query the applicable policy at this point
11378 case Check_Kind
(Cname
) is
11379 when Name_Ignore
=>
11380 Set_Is_Ignored
(N
, True);
11381 Set_Is_Checked
(N
, False);
11384 Set_Is_Ignored
(N
, False);
11385 Set_Is_Checked
(N
, True);
11387 -- For disable, rewrite pragma as null statement and skip
11388 -- rest of the analysis of the pragma.
11390 when Name_Disable
=>
11391 Rewrite
(N
, Make_Null_Statement
(Loc
));
11395 -- No other possibilities
11398 raise Program_Error
;
11402 -- If check kind was not Disable, then continue pragma analysis
11404 Expr
:= Get_Pragma_Arg
(Arg2
);
11406 -- Deal with SCO generation
11409 when Name_Predicate |
11412 -- Nothing to do: since checks occur in client units,
11413 -- the SCO for the aspect in the declaration unit is
11414 -- conservatively always enabled.
11420 if Is_Checked
(N
) and then not Split_PPC
(N
) then
11422 -- Mark aspect/pragma SCO as enabled
11424 Set_SCO_Pragma_Enabled
(Loc
);
11428 -- Deal with analyzing the string argument.
11430 if Arg_Count
= 3 then
11432 -- If checks are not on we don't want any expansion (since
11433 -- such expansion would not get properly deleted) but
11434 -- we do want to analyze (to get proper references).
11435 -- The Preanalyze_And_Resolve routine does just what we want
11437 if Is_Ignored
(N
) then
11438 Preanalyze_And_Resolve
(Str
, Standard_String
);
11440 -- Otherwise we need a proper analysis and expansion
11443 Analyze_And_Resolve
(Str
, Standard_String
);
11447 -- Now you might think we could just do the same with the Boolean
11448 -- expression if checks are off (and expansion is on) and then
11449 -- rewrite the check as a null statement. This would work but we
11450 -- would lose the useful warnings about an assertion being bound
11451 -- to fail even if assertions are turned off.
11453 -- So instead we wrap the boolean expression in an if statement
11454 -- that looks like:
11456 -- if False and then condition then
11460 -- The reason we do this rewriting during semantic analysis rather
11461 -- than as part of normal expansion is that we cannot analyze and
11462 -- expand the code for the boolean expression directly, or it may
11463 -- cause insertion of actions that would escape the attempt to
11464 -- suppress the check code.
11466 -- Note that the Sloc for the if statement corresponds to the
11467 -- argument condition, not the pragma itself. The reason for
11468 -- this is that we may generate a warning if the condition is
11469 -- False at compile time, and we do not want to delete this
11470 -- warning when we delete the if statement.
11472 if Expander_Active
and Is_Ignored
(N
) then
11473 Eloc
:= Sloc
(Expr
);
11476 Make_If_Statement
(Eloc
,
11478 Make_And_Then
(Eloc
,
11479 Left_Opnd
=> Make_Identifier
(Eloc
, Name_False
),
11480 Right_Opnd
=> Expr
),
11481 Then_Statements
=> New_List
(
11482 Make_Null_Statement
(Eloc
))));
11484 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
11486 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
11488 -- Check is active or expansion not active. In these cases we can
11489 -- just go ahead and analyze the boolean with no worries.
11492 In_Assertion_Expr
:= In_Assertion_Expr
+ 1;
11493 Analyze_And_Resolve
(Expr
, Any_Boolean
);
11494 In_Assertion_Expr
:= In_Assertion_Expr
- 1;
11498 --------------------------
11499 -- Check_Float_Overflow --
11500 --------------------------
11502 -- pragma Check_Float_Overflow;
11504 when Pragma_Check_Float_Overflow
=>
11506 Check_Valid_Configuration_Pragma
;
11507 Check_Arg_Count
(0);
11508 Check_Float_Overflow
:= not Machine_Overflows_On_Target
;
11514 -- pragma Check_Name (check_IDENTIFIER);
11516 when Pragma_Check_Name
=>
11518 Check_No_Identifiers
;
11519 Check_Valid_Configuration_Pragma
;
11520 Check_Arg_Count
(1);
11521 Check_Arg_Is_Identifier
(Arg1
);
11524 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
11527 for J
in Check_Names
.First
.. Check_Names
.Last
loop
11528 if Check_Names
.Table
(J
) = Nam
then
11533 Check_Names
.Append
(Nam
);
11540 -- This is the old style syntax, which is still allowed in all modes:
11542 -- pragma Check_Policy ([Name =>] CHECK_KIND
11543 -- [Policy =>] POLICY_IDENTIFIER);
11545 -- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore
11547 -- CHECK_KIND ::= IDENTIFIER |
11550 -- Type_Invariant'Class |
11553 -- This is the new style syntax, compatible with Assertion_Policy
11554 -- and also allowed in all modes.
11556 -- Pragma Check_Policy (
11557 -- CHECK_KIND => POLICY_IDENTIFIER
11558 -- {, CHECK_KIND => POLICY_IDENTIFIER});
11560 -- Note: the identifiers Name and Policy are not allowed as
11561 -- Check_Kind values. This avoids ambiguities between the old and
11562 -- new form syntax.
11564 when Pragma_Check_Policy
=> Check_Policy
: declare
11570 Check_At_Least_N_Arguments
(1);
11572 -- A Check_Policy pragma can appear either as a configuration
11573 -- pragma, or in a declarative part or a package spec (see RM
11574 -- 11.5(5) for rules for Suppress/Unsuppress which are also
11575 -- followed for Check_Policy).
11577 if not Is_Configuration_Pragma
then
11578 Check_Is_In_Decl_Part_Or_Package_Spec
;
11581 -- Figure out if we have the old or new syntax. We have the
11582 -- old syntax if the first argument has no identifier, or the
11583 -- identifier is Name.
11585 if Nkind
(Arg1
) /= N_Pragma_Argument_Association
11586 or else Nam_In
(Chars
(Arg1
), No_Name
, Name_Name
)
11590 Check_Arg_Count
(2);
11591 Check_Optional_Identifier
(Arg1
, Name_Name
);
11592 Kind
:= Get_Pragma_Arg
(Arg1
);
11593 Rewrite_Assertion_Kind
(Kind
);
11594 Check_Arg_Is_Identifier
(Arg1
);
11596 -- Check forbidden check kind
11598 if Nam_In
(Chars
(Kind
), Name_Name
, Name_Policy
) then
11599 Error_Msg_Name_2
:= Chars
(Kind
);
11601 ("pragma% does not allow% as check name", Arg1
);
11606 Check_Optional_Identifier
(Arg2
, Name_Policy
);
11607 Check_Arg_Is_One_Of
11609 Name_On
, Name_Off
, Name_Check
, Name_Disable
, Name_Ignore
);
11610 Ident
:= Get_Pragma_Arg
(Arg2
);
11612 if Chars
(Kind
) = Name_Ghost
then
11614 -- Pragma Check_Policy specifying a Ghost policy cannot
11615 -- occur within a ghost subprogram or package.
11617 if Ghost_Mode
> None
then
11619 ("pragma % cannot appear within ghost subprogram or "
11622 -- The policy identifier of pragma Ghost must be either
11623 -- Check or Ignore (SPARK RM 6.9(7)).
11625 elsif not Nam_In
(Chars
(Ident
), Name_Check
,
11629 ("argument of pragma % Ghost must be Check or Ignore",
11634 -- And chain pragma on the Check_Policy_List for search
11636 Set_Next_Pragma
(N
, Opt
.Check_Policy_List
);
11637 Opt
.Check_Policy_List
:= N
;
11639 -- For the new syntax, what we do is to convert each argument to
11640 -- an old syntax equivalent. We do that because we want to chain
11641 -- old style Check_Policy pragmas for the search (we don't want
11642 -- to have to deal with multiple arguments in the search).
11652 while Present
(Arg
) loop
11653 LocP
:= Sloc
(Arg
);
11654 Argx
:= Get_Pragma_Arg
(Arg
);
11656 -- Kind must be specified
11658 if Nkind
(Arg
) /= N_Pragma_Argument_Association
11659 or else Chars
(Arg
) = No_Name
11662 ("missing assertion kind for pragma%", Arg
);
11665 -- Construct equivalent old form syntax Check_Policy
11666 -- pragma and insert it to get remaining checks.
11670 Chars
=> Name_Check_Policy
,
11671 Pragma_Argument_Associations
=> New_List
(
11672 Make_Pragma_Argument_Association
(LocP
,
11674 Make_Identifier
(LocP
, Chars
(Arg
))),
11675 Make_Pragma_Argument_Association
(Sloc
(Argx
),
11676 Expression
=> Argx
))));
11681 -- Rewrite original Check_Policy pragma to null, since we
11682 -- have converted it into a series of old syntax pragmas.
11684 Rewrite
(N
, Make_Null_Statement
(Loc
));
11690 ---------------------
11691 -- CIL_Constructor --
11692 ---------------------
11694 -- pragma CIL_Constructor ([Entity =>] LOCAL_NAME);
11696 -- Processing for this pragma is shared with Java_Constructor
11702 -- pragma Comment (static_string_EXPRESSION)
11704 -- Processing for pragma Comment shares the circuitry for pragma
11705 -- Ident. The only differences are that Ident enforces a limit of 31
11706 -- characters on its argument, and also enforces limitations on
11707 -- placement for DEC compatibility. Pragma Comment shares neither of
11708 -- these restrictions.
11710 -------------------
11711 -- Common_Object --
11712 -------------------
11714 -- pragma Common_Object (
11715 -- [Internal =>] LOCAL_NAME
11716 -- [, [External =>] EXTERNAL_SYMBOL]
11717 -- [, [Size =>] EXTERNAL_SYMBOL]);
11719 -- Processing for this pragma is shared with Psect_Object
11721 ------------------------
11722 -- Compile_Time_Error --
11723 ------------------------
11725 -- pragma Compile_Time_Error
11726 -- (boolean_EXPRESSION, static_string_EXPRESSION);
11728 when Pragma_Compile_Time_Error
=>
11730 Process_Compile_Time_Warning_Or_Error
;
11732 --------------------------
11733 -- Compile_Time_Warning --
11734 --------------------------
11736 -- pragma Compile_Time_Warning
11737 -- (boolean_EXPRESSION, static_string_EXPRESSION);
11739 when Pragma_Compile_Time_Warning
=>
11741 Process_Compile_Time_Warning_Or_Error
;
11743 ---------------------------
11744 -- Compiler_Unit_Warning --
11745 ---------------------------
11747 -- pragma Compiler_Unit_Warning;
11751 -- Originally, we had only pragma Compiler_Unit, and it resulted in
11752 -- errors not warnings. This means that we had introduced a big extra
11753 -- inertia to compiler changes, since even if we implemented a new
11754 -- feature, and even if all versions to be used for bootstrapping
11755 -- implemented this new feature, we could not use it, since old
11756 -- compilers would give errors for using this feature in units
11757 -- having Compiler_Unit pragmas.
11759 -- By changing Compiler_Unit to Compiler_Unit_Warning, we solve the
11760 -- problem. We no longer have any units mentioning Compiler_Unit,
11761 -- so old compilers see Compiler_Unit_Warning which is unrecognized,
11762 -- and thus generates a warning which can be ignored. So that deals
11763 -- with the problem of old compilers not implementing the newer form
11766 -- Newer compilers recognize the new pragma, but generate warning
11767 -- messages instead of errors, which again can be ignored in the
11768 -- case of an old compiler which implements a wanted new feature
11769 -- but at the time felt like warning about it for older compilers.
11771 -- We retain Compiler_Unit so that new compilers can be used to build
11772 -- older run-times that use this pragma. That's an unusual case, but
11773 -- it's easy enough to handle, so why not?
11775 when Pragma_Compiler_Unit | Pragma_Compiler_Unit_Warning
=>
11777 Check_Arg_Count
(0);
11779 -- Only recognized in main unit
11781 if Current_Sem_Unit
= Main_Unit
then
11782 Compiler_Unit
:= True;
11785 -----------------------------
11786 -- Complete_Representation --
11787 -----------------------------
11789 -- pragma Complete_Representation;
11791 when Pragma_Complete_Representation
=>
11793 Check_Arg_Count
(0);
11795 if Nkind
(Parent
(N
)) /= N_Record_Representation_Clause
then
11797 ("pragma & must appear within record representation clause");
11800 ----------------------------
11801 -- Complex_Representation --
11802 ----------------------------
11804 -- pragma Complex_Representation ([Entity =>] LOCAL_NAME);
11806 when Pragma_Complex_Representation
=> Complex_Representation
: declare
11813 Check_Arg_Count
(1);
11814 Check_Optional_Identifier
(Arg1
, Name_Entity
);
11815 Check_Arg_Is_Local_Name
(Arg1
);
11816 E_Id
:= Get_Pragma_Arg
(Arg1
);
11818 if Etype
(E_Id
) = Any_Type
then
11822 E
:= Entity
(E_Id
);
11824 if not Is_Record_Type
(E
) then
11826 ("argument for pragma% must be record type", Arg1
);
11829 Ent
:= First_Entity
(E
);
11832 or else No
(Next_Entity
(Ent
))
11833 or else Present
(Next_Entity
(Next_Entity
(Ent
)))
11834 or else not Is_Floating_Point_Type
(Etype
(Ent
))
11835 or else Etype
(Ent
) /= Etype
(Next_Entity
(Ent
))
11838 ("record for pragma% must have two fields of the same "
11839 & "floating-point type", Arg1
);
11842 Set_Has_Complex_Representation
(Base_Type
(E
));
11844 -- We need to treat the type has having a non-standard
11845 -- representation, for back-end purposes, even though in
11846 -- general a complex will have the default representation
11847 -- of a record with two real components.
11849 Set_Has_Non_Standard_Rep
(Base_Type
(E
));
11851 end Complex_Representation
;
11853 -------------------------
11854 -- Component_Alignment --
11855 -------------------------
11857 -- pragma Component_Alignment (
11858 -- [Form =>] ALIGNMENT_CHOICE
11859 -- [, [Name =>] type_LOCAL_NAME]);
11861 -- ALIGNMENT_CHOICE ::=
11863 -- | Component_Size_4
11867 when Pragma_Component_Alignment
=> Component_AlignmentP
: declare
11868 Args
: Args_List
(1 .. 2);
11869 Names
: constant Name_List
(1 .. 2) := (
11873 Form
: Node_Id
renames Args
(1);
11874 Name
: Node_Id
renames Args
(2);
11876 Atype
: Component_Alignment_Kind
;
11881 Gather_Associations
(Names
, Args
);
11884 Error_Pragma
("missing Form argument for pragma%");
11887 Check_Arg_Is_Identifier
(Form
);
11889 -- Get proper alignment, note that Default = Component_Size on all
11890 -- machines we have so far, and we want to set this value rather
11891 -- than the default value to indicate that it has been explicitly
11892 -- set (and thus will not get overridden by the default component
11893 -- alignment for the current scope)
11895 if Chars
(Form
) = Name_Component_Size
then
11896 Atype
:= Calign_Component_Size
;
11898 elsif Chars
(Form
) = Name_Component_Size_4
then
11899 Atype
:= Calign_Component_Size_4
;
11901 elsif Chars
(Form
) = Name_Default
then
11902 Atype
:= Calign_Component_Size
;
11904 elsif Chars
(Form
) = Name_Storage_Unit
then
11905 Atype
:= Calign_Storage_Unit
;
11909 ("invalid Form parameter for pragma%", Form
);
11912 -- Case with no name, supplied, affects scope table entry
11916 (Scope_Stack
.Last
).Component_Alignment_Default
:= Atype
;
11918 -- Case of name supplied
11921 Check_Arg_Is_Local_Name
(Name
);
11923 Typ
:= Entity
(Name
);
11926 or else Rep_Item_Too_Early
(Typ
, N
)
11930 Typ
:= Underlying_Type
(Typ
);
11933 if not Is_Record_Type
(Typ
)
11934 and then not Is_Array_Type
(Typ
)
11937 ("Name parameter of pragma% must identify record or "
11938 & "array type", Name
);
11941 -- An explicit Component_Alignment pragma overrides an
11942 -- implicit pragma Pack, but not an explicit one.
11944 if not Has_Pragma_Pack
(Base_Type
(Typ
)) then
11945 Set_Is_Packed
(Base_Type
(Typ
), False);
11946 Set_Component_Alignment
(Base_Type
(Typ
), Atype
);
11949 end Component_AlignmentP
;
11951 --------------------
11952 -- Contract_Cases --
11953 --------------------
11955 -- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE));
11957 -- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE
11959 -- CASE_GUARD ::= boolean_EXPRESSION | others
11961 -- CONSEQUENCE ::= boolean_EXPRESSION
11963 when Pragma_Contract_Cases
=> Contract_Cases
: declare
11964 Subp_Decl
: Node_Id
;
11965 Subp_Id
: Entity_Id
;
11969 Check_No_Identifiers
;
11970 Check_Arg_Count
(1);
11972 -- The pragma is analyzed at the end of the declarative part which
11973 -- contains the related subprogram. Reset the analyzed flag.
11975 Set_Analyzed
(N
, False);
11977 -- Ensure the proper placement of the pragma. Contract_Cases must
11978 -- be associated with a subprogram declaration or a body that acts
11982 Find_Related_Subprogram_Or_Body
(N
, Do_Checks
=> True);
11984 -- Generic subprogram
11986 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
11989 -- Body acts as spec
11991 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
11992 and then No
(Corresponding_Spec
(Subp_Decl
))
11996 -- Body stub acts as spec
11998 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
11999 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
12005 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
12013 Subp_Id
:= Defining_Entity
(Subp_Decl
);
12015 Ensure_Aggregate_Form
(Get_Argument
(N
, Subp_Id
));
12017 -- Construct a generic template for the pragma when the context is
12018 -- a generic subprogram and the pragma is a source construct.
12020 Create_Generic_Template
(N
, Subp_Id
);
12022 -- Fully analyze the pragma when it appears inside a subprogram
12023 -- body because it cannot benefit from forward references.
12025 if Nkind
(Subp_Decl
) = N_Subprogram_Body
then
12026 Analyze_Contract_Cases_In_Decl_Part
(N
);
12029 -- Chain the pragma on the contract for further processing
12031 Add_Contract_Item
(N
, Subp_Id
);
12032 end Contract_Cases
;
12038 -- pragma Controlled (first_subtype_LOCAL_NAME);
12040 when Pragma_Controlled
=> Controlled
: declare
12044 Check_No_Identifiers
;
12045 Check_Arg_Count
(1);
12046 Check_Arg_Is_Local_Name
(Arg1
);
12047 Arg
:= Get_Pragma_Arg
(Arg1
);
12049 if not Is_Entity_Name
(Arg
)
12050 or else not Is_Access_Type
(Entity
(Arg
))
12052 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
12054 Set_Has_Pragma_Controlled
(Base_Type
(Entity
(Arg
)));
12062 -- pragma Convention ([Convention =>] convention_IDENTIFIER,
12063 -- [Entity =>] LOCAL_NAME);
12065 when Pragma_Convention
=> Convention
: declare
12068 pragma Warnings
(Off
, C
);
12069 pragma Warnings
(Off
, E
);
12071 Check_Arg_Order
((Name_Convention
, Name_Entity
));
12072 Check_Ada_83_Warning
;
12073 Check_Arg_Count
(2);
12074 Process_Convention
(C
, E
);
12077 ---------------------------
12078 -- Convention_Identifier --
12079 ---------------------------
12081 -- pragma Convention_Identifier ([Name =>] IDENTIFIER,
12082 -- [Convention =>] convention_IDENTIFIER);
12084 when Pragma_Convention_Identifier
=> Convention_Identifier
: declare
12090 Check_Arg_Order
((Name_Name
, Name_Convention
));
12091 Check_Arg_Count
(2);
12092 Check_Optional_Identifier
(Arg1
, Name_Name
);
12093 Check_Optional_Identifier
(Arg2
, Name_Convention
);
12094 Check_Arg_Is_Identifier
(Arg1
);
12095 Check_Arg_Is_Identifier
(Arg2
);
12096 Idnam
:= Chars
(Get_Pragma_Arg
(Arg1
));
12097 Cname
:= Chars
(Get_Pragma_Arg
(Arg2
));
12099 if Is_Convention_Name
(Cname
) then
12100 Record_Convention_Identifier
12101 (Idnam
, Get_Convention_Id
(Cname
));
12104 ("second arg for % pragma must be convention", Arg2
);
12106 end Convention_Identifier
;
12112 -- pragma CPP_Class ([Entity =>] LOCAL_NAME)
12114 when Pragma_CPP_Class
=> CPP_Class
: declare
12118 if Warn_On_Obsolescent_Feature
then
12120 ("'G'N'A'T pragma cpp'_class is now obsolete and has no "
12121 & "effect; replace it by pragma import?j?", N
);
12124 Check_Arg_Count
(1);
12128 Chars
=> Name_Import
,
12129 Pragma_Argument_Associations
=> New_List
(
12130 Make_Pragma_Argument_Association
(Loc
,
12131 Expression
=> Make_Identifier
(Loc
, Name_CPP
)),
12132 New_Copy
(First
(Pragma_Argument_Associations
(N
))))));
12136 ---------------------
12137 -- CPP_Constructor --
12138 ---------------------
12140 -- pragma CPP_Constructor ([Entity =>] LOCAL_NAME
12141 -- [, [External_Name =>] static_string_EXPRESSION ]
12142 -- [, [Link_Name =>] static_string_EXPRESSION ]);
12144 when Pragma_CPP_Constructor
=> CPP_Constructor
: declare
12147 Def_Id
: Entity_Id
;
12148 Tag_Typ
: Entity_Id
;
12152 Check_At_Least_N_Arguments
(1);
12153 Check_At_Most_N_Arguments
(3);
12154 Check_Optional_Identifier
(Arg1
, Name_Entity
);
12155 Check_Arg_Is_Local_Name
(Arg1
);
12157 Id
:= Get_Pragma_Arg
(Arg1
);
12158 Find_Program_Unit_Name
(Id
);
12160 -- If we did not find the name, we are done
12162 if Etype
(Id
) = Any_Type
then
12166 Def_Id
:= Entity
(Id
);
12168 -- Check if already defined as constructor
12170 if Is_Constructor
(Def_Id
) then
12172 ("??duplicate argument for pragma 'C'P'P_Constructor", Arg1
);
12176 if Ekind
(Def_Id
) = E_Function
12177 and then (Is_CPP_Class
(Etype
(Def_Id
))
12178 or else (Is_Class_Wide_Type
(Etype
(Def_Id
))
12180 Is_CPP_Class
(Root_Type
(Etype
(Def_Id
)))))
12182 if Scope
(Def_Id
) /= Scope
(Etype
(Def_Id
)) then
12184 ("'C'P'P constructor must be defined in the scope of "
12185 & "its returned type", Arg1
);
12188 if Arg_Count
>= 2 then
12189 Set_Imported
(Def_Id
);
12190 Set_Is_Public
(Def_Id
);
12191 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
12194 Set_Has_Completion
(Def_Id
);
12195 Set_Is_Constructor
(Def_Id
);
12196 Set_Convention
(Def_Id
, Convention_CPP
);
12198 -- Imported C++ constructors are not dispatching primitives
12199 -- because in C++ they don't have a dispatch table slot.
12200 -- However, in Ada the constructor has the profile of a
12201 -- function that returns a tagged type and therefore it has
12202 -- been treated as a primitive operation during semantic
12203 -- analysis. We now remove it from the list of primitive
12204 -- operations of the type.
12206 if Is_Tagged_Type
(Etype
(Def_Id
))
12207 and then not Is_Class_Wide_Type
(Etype
(Def_Id
))
12208 and then Is_Dispatching_Operation
(Def_Id
)
12210 Tag_Typ
:= Etype
(Def_Id
);
12212 Elmt
:= First_Elmt
(Primitive_Operations
(Tag_Typ
));
12213 while Present
(Elmt
) and then Node
(Elmt
) /= Def_Id
loop
12217 Remove_Elmt
(Primitive_Operations
(Tag_Typ
), Elmt
);
12218 Set_Is_Dispatching_Operation
(Def_Id
, False);
12221 -- For backward compatibility, if the constructor returns a
12222 -- class wide type, and we internally change the return type to
12223 -- the corresponding root type.
12225 if Is_Class_Wide_Type
(Etype
(Def_Id
)) then
12226 Set_Etype
(Def_Id
, Root_Type
(Etype
(Def_Id
)));
12230 ("pragma% requires function returning a 'C'P'P_Class type",
12233 end CPP_Constructor
;
12239 when Pragma_CPP_Virtual
=> CPP_Virtual
: declare
12243 if Warn_On_Obsolescent_Feature
then
12245 ("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no "
12254 when Pragma_CPP_Vtable
=> CPP_Vtable
: declare
12258 if Warn_On_Obsolescent_Feature
then
12260 ("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no "
12269 -- pragma CPU (EXPRESSION);
12271 when Pragma_CPU
=> CPU
: declare
12272 P
: constant Node_Id
:= Parent
(N
);
12278 Check_No_Identifiers
;
12279 Check_Arg_Count
(1);
12283 if Nkind
(P
) = N_Subprogram_Body
then
12284 Check_In_Main_Program
;
12286 Arg
:= Get_Pragma_Arg
(Arg1
);
12287 Analyze_And_Resolve
(Arg
, Any_Integer
);
12289 Ent
:= Defining_Unit_Name
(Specification
(P
));
12291 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
12292 Ent
:= Defining_Identifier
(Ent
);
12297 if not Is_OK_Static_Expression
(Arg
) then
12298 Flag_Non_Static_Expr
12299 ("main subprogram affinity is not static!", Arg
);
12302 -- If constraint error, then we already signalled an error
12304 elsif Raises_Constraint_Error
(Arg
) then
12307 -- Otherwise check in range
12311 CPU_Id
: constant Entity_Id
:= RTE
(RE_CPU_Range
);
12312 -- This is the entity System.Multiprocessors.CPU_Range;
12314 Val
: constant Uint
:= Expr_Value
(Arg
);
12317 if Val
< Expr_Value
(Type_Low_Bound
(CPU_Id
))
12319 Val
> Expr_Value
(Type_High_Bound
(CPU_Id
))
12322 ("main subprogram CPU is out of range", Arg1
);
12328 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
12332 elsif Nkind
(P
) = N_Task_Definition
then
12333 Arg
:= Get_Pragma_Arg
(Arg1
);
12334 Ent
:= Defining_Identifier
(Parent
(P
));
12336 -- The expression must be analyzed in the special manner
12337 -- described in "Handling of Default and Per-Object
12338 -- Expressions" in sem.ads.
12340 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_CPU_Range
));
12342 -- Anything else is incorrect
12348 -- Check duplicate pragma before we chain the pragma in the Rep
12349 -- Item chain of Ent.
12351 Check_Duplicate_Pragma
(Ent
);
12352 Record_Rep_Item
(Ent
, N
);
12359 -- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT);
12361 when Pragma_Debug
=> Debug
: declare
12368 -- The condition for executing the call is that the expander
12369 -- is active and that we are not ignoring this debug pragma.
12374 (Expander_Active
and then not Is_Ignored
(N
)),
12377 if not Is_Ignored
(N
) then
12378 Set_SCO_Pragma_Enabled
(Loc
);
12381 if Arg_Count
= 2 then
12383 Make_And_Then
(Loc
,
12384 Left_Opnd
=> Relocate_Node
(Cond
),
12385 Right_Opnd
=> Get_Pragma_Arg
(Arg1
));
12386 Call
:= Get_Pragma_Arg
(Arg2
);
12388 Call
:= Get_Pragma_Arg
(Arg1
);
12392 N_Indexed_Component
,
12396 N_Selected_Component
)
12398 -- If this pragma Debug comes from source, its argument was
12399 -- parsed as a name form (which is syntactically identical).
12400 -- In a generic context a parameterless call will be left as
12401 -- an expanded name (if global) or selected_component if local.
12402 -- Change it to a procedure call statement now.
12404 Change_Name_To_Procedure_Call_Statement
(Call
);
12406 elsif Nkind
(Call
) = N_Procedure_Call_Statement
then
12408 -- Already in the form of a procedure call statement: nothing
12409 -- to do (could happen in case of an internally generated
12415 -- All other cases: diagnose error
12418 ("argument of pragma ""Debug"" is not procedure call",
12423 -- Rewrite into a conditional with an appropriate condition. We
12424 -- wrap the procedure call in a block so that overhead from e.g.
12425 -- use of the secondary stack does not generate execution overhead
12426 -- for suppressed conditions.
12428 -- Normally the analysis that follows will freeze the subprogram
12429 -- being called. However, if the call is to a null procedure,
12430 -- we want to freeze it before creating the block, because the
12431 -- analysis that follows may be done with expansion disabled, in
12432 -- which case the body will not be generated, leading to spurious
12435 if Nkind
(Call
) = N_Procedure_Call_Statement
12436 and then Is_Entity_Name
(Name
(Call
))
12438 Analyze
(Name
(Call
));
12439 Freeze_Before
(N
, Entity
(Name
(Call
)));
12443 Make_Implicit_If_Statement
(N
,
12445 Then_Statements
=> New_List
(
12446 Make_Block_Statement
(Loc
,
12447 Handled_Statement_Sequence
=>
12448 Make_Handled_Sequence_Of_Statements
(Loc
,
12449 Statements
=> New_List
(Relocate_Node
(Call
)))))));
12452 -- Ignore pragma Debug in GNATprove mode. Do this rewriting
12453 -- after analysis of the normally rewritten node, to capture all
12454 -- references to entities, which avoids issuing wrong warnings
12455 -- about unused entities.
12457 if GNATprove_Mode
then
12458 Rewrite
(N
, Make_Null_Statement
(Loc
));
12466 -- pragma Debug_Policy (On | Off | Check | Disable | Ignore)
12468 when Pragma_Debug_Policy
=>
12470 Check_Arg_Count
(1);
12471 Check_No_Identifiers
;
12472 Check_Arg_Is_Identifier
(Arg1
);
12474 -- Exactly equivalent to pragma Check_Policy (Debug, arg), so
12475 -- rewrite it that way, and let the rest of the checking come
12476 -- from analyzing the rewritten pragma.
12480 Chars
=> Name_Check_Policy
,
12481 Pragma_Argument_Associations
=> New_List
(
12482 Make_Pragma_Argument_Association
(Loc
,
12483 Expression
=> Make_Identifier
(Loc
, Name_Debug
)),
12485 Make_Pragma_Argument_Association
(Loc
,
12486 Expression
=> Get_Pragma_Arg
(Arg1
)))));
12489 -------------------------------
12490 -- Default_Initial_Condition --
12491 -------------------------------
12493 -- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ];
12495 when Pragma_Default_Initial_Condition
=> Default_Init_Cond
: declare
12502 Check_No_Identifiers
;
12503 Check_At_Most_N_Arguments
(1);
12506 while Present
(Stmt
) loop
12508 -- Skip prior pragmas, but check for duplicates
12510 if Nkind
(Stmt
) = N_Pragma
then
12511 if Pragma_Name
(Stmt
) = Pname
then
12512 Error_Msg_Name_1
:= Pname
;
12513 Error_Msg_Sloc
:= Sloc
(Stmt
);
12514 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
12517 -- Skip internally generated code
12519 elsif not Comes_From_Source
(Stmt
) then
12522 -- The associated private type [extension] has been found, stop
12525 elsif Nkind_In
(Stmt
, N_Private_Extension_Declaration
,
12526 N_Private_Type_Declaration
)
12528 Typ
:= Defining_Entity
(Stmt
);
12531 -- The pragma does not apply to a legal construct, issue an
12532 -- error and stop the analysis.
12539 Stmt
:= Prev
(Stmt
);
12542 Set_Has_Default_Init_Cond
(Typ
);
12543 Set_Has_Inherited_Default_Init_Cond
(Typ
, False);
12545 -- Chain the pragma on the rep item chain for further processing
12547 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
12548 end Default_Init_Cond
;
12550 ----------------------------------
12551 -- Default_Scalar_Storage_Order --
12552 ----------------------------------
12554 -- pragma Default_Scalar_Storage_Order
12555 -- (High_Order_First | Low_Order_First);
12557 when Pragma_Default_Scalar_Storage_Order
=> DSSO
: declare
12558 Default
: Character;
12562 Check_Arg_Count
(1);
12564 -- Default_Scalar_Storage_Order can appear as a configuration
12565 -- pragma, or in a declarative part of a package spec.
12567 if not Is_Configuration_Pragma
then
12568 Check_Is_In_Decl_Part_Or_Package_Spec
;
12571 Check_No_Identifiers
;
12572 Check_Arg_Is_One_Of
12573 (Arg1
, Name_High_Order_First
, Name_Low_Order_First
);
12574 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
12575 Default
:= Fold_Upper
(Name_Buffer
(1));
12577 if not Support_Nondefault_SSO_On_Target
12578 and then (Ttypes
.Bytes_Big_Endian
/= (Default
= 'H'))
12580 if Warn_On_Unrecognized_Pragma
then
12582 ("non-default Scalar_Storage_Order not supported "
12583 & "on target?g?", N
);
12585 ("\pragma Default_Scalar_Storage_Order ignored?g?", N
);
12588 -- Here set the specified default
12591 Opt
.Default_SSO
:= Default
;
12595 --------------------------
12596 -- Default_Storage_Pool --
12597 --------------------------
12599 -- pragma Default_Storage_Pool (storage_pool_NAME | null);
12601 when Pragma_Default_Storage_Pool
=>
12603 Check_Arg_Count
(1);
12605 -- Default_Storage_Pool can appear as a configuration pragma, or
12606 -- in a declarative part of a package spec.
12608 if not Is_Configuration_Pragma
then
12609 Check_Is_In_Decl_Part_Or_Package_Spec
;
12612 -- Case of Default_Storage_Pool (null);
12614 if Nkind
(Expression
(Arg1
)) = N_Null
then
12615 Analyze
(Expression
(Arg1
));
12617 -- This is an odd case, this is not really an expression, so
12618 -- we don't have a type for it. So just set the type to Empty.
12620 Set_Etype
(Expression
(Arg1
), Empty
);
12622 -- Case of Default_Storage_Pool (storage_pool_NAME);
12625 -- If it's a configuration pragma, then the only allowed
12626 -- argument is "null".
12628 if Is_Configuration_Pragma
then
12629 Error_Pragma_Arg
("NULL expected", Arg1
);
12632 -- The expected type for a non-"null" argument is
12633 -- Root_Storage_Pool'Class, and the pool must be a variable.
12635 Analyze_And_Resolve
12636 (Get_Pragma_Arg
(Arg1
),
12637 Typ
=> Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
12639 if not Is_Variable
(Expression
(Arg1
)) then
12641 ("default storage pool must be a variable", Arg1
);
12645 -- Finally, record the pool name (or null). Freeze.Freeze_Entity
12646 -- for an access type will use this information to set the
12647 -- appropriate attributes of the access type.
12649 Default_Pool
:= Expression
(Arg1
);
12655 -- pragma Depends (DEPENDENCY_RELATION);
12657 -- DEPENDENCY_RELATION ::=
12659 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
12661 -- DEPENDENCY_CLAUSE ::=
12662 -- OUTPUT_LIST =>[+] INPUT_LIST
12663 -- | NULL_DEPENDENCY_CLAUSE
12665 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
12667 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
12669 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
12671 -- OUTPUT ::= NAME | FUNCTION_RESULT
12674 -- where FUNCTION_RESULT is a function Result attribute_reference
12676 when Pragma_Depends
=> Depends
: declare
12677 Subp_Decl
: Node_Id
;
12678 Subp_Id
: Entity_Id
;
12682 Check_Arg_Count
(1);
12684 -- Ensure the proper placement of the pragma. Depends must be
12685 -- associated with a subprogram declaration or a body that acts
12689 Find_Related_Subprogram_Or_Body
(N
, Do_Checks
=> True);
12691 -- Body acts as spec
12693 if Nkind
(Subp_Decl
) = N_Subprogram_Body
12694 and then No
(Corresponding_Spec
(Subp_Decl
))
12698 -- Body stub acts as spec
12700 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
12701 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
12705 -- Subprogram declaration
12707 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
12715 Subp_Id
:= Defining_Entity
(Subp_Decl
);
12717 Ensure_Aggregate_Form
(Get_Argument
(N
, Subp_Id
));
12719 -- Construct a generic template for the pragma when the context is
12720 -- a generic subprogram and the pragma is a source construct.
12722 Create_Generic_Template
(N
, Subp_Id
);
12724 -- When the pragma appears on a subprogram body, perform the full
12727 if Nkind
(Subp_Decl
) = N_Subprogram_Body
then
12728 Analyze_Depends_In_Decl_Part
(N
);
12731 -- Chain the pragma on the contract for further processing
12733 Add_Contract_Item
(N
, Subp_Id
);
12736 ---------------------
12737 -- Detect_Blocking --
12738 ---------------------
12740 -- pragma Detect_Blocking;
12742 when Pragma_Detect_Blocking
=>
12744 Check_Arg_Count
(0);
12745 Check_Valid_Configuration_Pragma
;
12746 Detect_Blocking
:= True;
12748 ------------------------------------
12749 -- Disable_Atomic_Synchronization --
12750 ------------------------------------
12752 -- pragma Disable_Atomic_Synchronization [(Entity)];
12754 when Pragma_Disable_Atomic_Synchronization
=>
12756 Process_Disable_Enable_Atomic_Sync
(Name_Suppress
);
12758 -------------------
12759 -- Discard_Names --
12760 -------------------
12762 -- pragma Discard_Names [([On =>] LOCAL_NAME)];
12764 when Pragma_Discard_Names
=> Discard_Names
: declare
12769 Check_Ada_83_Warning
;
12771 -- Deal with configuration pragma case
12773 if Arg_Count
= 0 and then Is_Configuration_Pragma
then
12774 Global_Discard_Names
:= True;
12777 -- Otherwise, check correct appropriate context
12780 Check_Is_In_Decl_Part_Or_Package_Spec
;
12782 if Arg_Count
= 0 then
12784 -- If there is no parameter, then from now on this pragma
12785 -- applies to any enumeration, exception or tagged type
12786 -- defined in the current declarative part, and recursively
12787 -- to any nested scope.
12789 Set_Discard_Names
(Current_Scope
);
12793 Check_Arg_Count
(1);
12794 Check_Optional_Identifier
(Arg1
, Name_On
);
12795 Check_Arg_Is_Local_Name
(Arg1
);
12797 E_Id
:= Get_Pragma_Arg
(Arg1
);
12799 if Etype
(E_Id
) = Any_Type
then
12802 E
:= Entity
(E_Id
);
12805 if (Is_First_Subtype
(E
)
12807 (Is_Enumeration_Type
(E
) or else Is_Tagged_Type
(E
)))
12808 or else Ekind
(E
) = E_Exception
12810 Set_Discard_Names
(E
);
12811 Record_Rep_Item
(E
, N
);
12815 ("inappropriate entity for pragma%", Arg1
);
12822 ------------------------
12823 -- Dispatching_Domain --
12824 ------------------------
12826 -- pragma Dispatching_Domain (EXPRESSION);
12828 when Pragma_Dispatching_Domain
=> Dispatching_Domain
: declare
12829 P
: constant Node_Id
:= Parent
(N
);
12835 Check_No_Identifiers
;
12836 Check_Arg_Count
(1);
12838 -- This pragma is born obsolete, but not the aspect
12840 if not From_Aspect_Specification
(N
) then
12842 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
12845 if Nkind
(P
) = N_Task_Definition
then
12846 Arg
:= Get_Pragma_Arg
(Arg1
);
12847 Ent
:= Defining_Identifier
(Parent
(P
));
12849 -- The expression must be analyzed in the special manner
12850 -- described in "Handling of Default and Per-Object
12851 -- Expressions" in sem.ads.
12853 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Dispatching_Domain
));
12855 -- Check duplicate pragma before we chain the pragma in the Rep
12856 -- Item chain of Ent.
12858 Check_Duplicate_Pragma
(Ent
);
12859 Record_Rep_Item
(Ent
, N
);
12861 -- Anything else is incorrect
12866 end Dispatching_Domain
;
12872 -- pragma Elaborate (library_unit_NAME {, library_unit_NAME});
12874 when Pragma_Elaborate
=> Elaborate
: declare
12879 -- Pragma must be in context items list of a compilation unit
12881 if not Is_In_Context_Clause
then
12885 -- Must be at least one argument
12887 if Arg_Count
= 0 then
12888 Error_Pragma
("pragma% requires at least one argument");
12891 -- In Ada 83 mode, there can be no items following it in the
12892 -- context list except other pragmas and implicit with clauses
12893 -- (e.g. those added by use of Rtsfind). In Ada 95 mode, this
12894 -- placement rule does not apply.
12896 if Ada_Version
= Ada_83
and then Comes_From_Source
(N
) then
12898 while Present
(Citem
) loop
12899 if Nkind
(Citem
) = N_Pragma
12900 or else (Nkind
(Citem
) = N_With_Clause
12901 and then Implicit_With
(Citem
))
12906 ("(Ada 83) pragma% must be at end of context clause");
12913 -- Finally, the arguments must all be units mentioned in a with
12914 -- clause in the same context clause. Note we already checked (in
12915 -- Par.Prag) that the arguments are all identifiers or selected
12919 Outer
: while Present
(Arg
) loop
12920 Citem
:= First
(List_Containing
(N
));
12921 Inner
: while Citem
/= N
loop
12922 if Nkind
(Citem
) = N_With_Clause
12923 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
12925 Set_Elaborate_Present
(Citem
, True);
12926 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
12928 -- With the pragma present, elaboration calls on
12929 -- subprograms from the named unit need no further
12930 -- checks, as long as the pragma appears in the current
12931 -- compilation unit. If the pragma appears in some unit
12932 -- in the context, there might still be a need for an
12933 -- Elaborate_All_Desirable from the current compilation
12934 -- to the named unit, so we keep the check enabled.
12936 if In_Extended_Main_Source_Unit
(N
) then
12938 -- This does not apply in SPARK mode, where we allow
12939 -- pragma Elaborate, but we don't trust it to be right
12940 -- so we will still insist on the Elaborate_All.
12942 if SPARK_Mode
/= On
then
12943 Set_Suppress_Elaboration_Warnings
12944 (Entity
(Name
(Citem
)));
12956 ("argument of pragma% is not withed unit", Arg
);
12962 -- Give a warning if operating in static mode with one of the
12963 -- gnatwl/-gnatwE (elaboration warnings enabled) switches set.
12966 and not Dynamic_Elaboration_Checks
12968 -- pragma Elaborate not allowed in SPARK mode anyway. We
12969 -- already complained about it, no point in generating any
12970 -- further complaint.
12972 and SPARK_Mode
/= On
12975 ("?l?use of pragma Elaborate may not be safe", N
);
12977 ("?l?use pragma Elaborate_All instead if possible", N
);
12981 -------------------
12982 -- Elaborate_All --
12983 -------------------
12985 -- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME});
12987 when Pragma_Elaborate_All
=> Elaborate_All
: declare
12992 Check_Ada_83_Warning
;
12994 -- Pragma must be in context items list of a compilation unit
12996 if not Is_In_Context_Clause
then
13000 -- Must be at least one argument
13002 if Arg_Count
= 0 then
13003 Error_Pragma
("pragma% requires at least one argument");
13006 -- Note: unlike pragma Elaborate, pragma Elaborate_All does not
13007 -- have to appear at the end of the context clause, but may
13008 -- appear mixed in with other items, even in Ada 83 mode.
13010 -- Final check: the arguments must all be units mentioned in
13011 -- a with clause in the same context clause. Note that we
13012 -- already checked (in Par.Prag) that all the arguments are
13013 -- either identifiers or selected components.
13016 Outr
: while Present
(Arg
) loop
13017 Citem
:= First
(List_Containing
(N
));
13018 Innr
: while Citem
/= N
loop
13019 if Nkind
(Citem
) = N_With_Clause
13020 and then Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg
))
13022 Set_Elaborate_All_Present
(Citem
, True);
13023 Set_Elab_Unit_Name
(Get_Pragma_Arg
(Arg
), Name
(Citem
));
13025 -- Suppress warnings and elaboration checks on the named
13026 -- unit if the pragma is in the current compilation, as
13027 -- for pragma Elaborate.
13029 if In_Extended_Main_Source_Unit
(N
) then
13030 Set_Suppress_Elaboration_Warnings
13031 (Entity
(Name
(Citem
)));
13040 Set_Error_Posted
(N
);
13042 ("argument of pragma% is not withed unit", Arg
);
13049 --------------------
13050 -- Elaborate_Body --
13051 --------------------
13053 -- pragma Elaborate_Body [( library_unit_NAME )];
13055 when Pragma_Elaborate_Body
=> Elaborate_Body
: declare
13056 Cunit_Node
: Node_Id
;
13057 Cunit_Ent
: Entity_Id
;
13060 Check_Ada_83_Warning
;
13061 Check_Valid_Library_Unit_Pragma
;
13063 if Nkind
(N
) = N_Null_Statement
then
13067 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
13068 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
13070 if Nkind_In
(Unit
(Cunit_Node
), N_Package_Body
,
13073 Error_Pragma
("pragma% must refer to a spec, not a body");
13075 Set_Body_Required
(Cunit_Node
, True);
13076 Set_Has_Pragma_Elaborate_Body
(Cunit_Ent
);
13078 -- If we are in dynamic elaboration mode, then we suppress
13079 -- elaboration warnings for the unit, since it is definitely
13080 -- fine NOT to do dynamic checks at the first level (and such
13081 -- checks will be suppressed because no elaboration boolean
13082 -- is created for Elaborate_Body packages).
13084 -- But in the static model of elaboration, Elaborate_Body is
13085 -- definitely NOT good enough to ensure elaboration safety on
13086 -- its own, since the body may WITH other units that are not
13087 -- safe from an elaboration point of view, so a client must
13088 -- still do an Elaborate_All on such units.
13090 -- Debug flag -gnatdD restores the old behavior of 3.13, where
13091 -- Elaborate_Body always suppressed elab warnings.
13093 if Dynamic_Elaboration_Checks
or Debug_Flag_DD
then
13094 Set_Suppress_Elaboration_Warnings
(Cunit_Ent
);
13097 end Elaborate_Body
;
13099 ------------------------
13100 -- Elaboration_Checks --
13101 ------------------------
13103 -- pragma Elaboration_Checks (Static | Dynamic);
13105 when Pragma_Elaboration_Checks
=>
13107 Check_Arg_Count
(1);
13108 Check_Arg_Is_One_Of
(Arg1
, Name_Static
, Name_Dynamic
);
13110 -- Set flag accordingly (ignore attempt at dynamic elaboration
13111 -- checks in SPARK mode).
13113 Dynamic_Elaboration_Checks
:=
13114 (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Dynamic
)
13115 and then SPARK_Mode
/= On
;
13121 -- pragma Eliminate (
13122 -- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT,
13123 -- [,[Entity =>] IDENTIFIER |
13124 -- SELECTED_COMPONENT |
13126 -- [, OVERLOADING_RESOLUTION]);
13128 -- OVERLOADING_RESOLUTION ::= PARAMETER_AND_RESULT_TYPE_PROFILE |
13131 -- PARAMETER_AND_RESULT_TYPE_PROFILE ::= PROCEDURE_PROFILE |
13132 -- FUNCTION_PROFILE
13134 -- PROCEDURE_PROFILE ::= Parameter_Types => PARAMETER_TYPES
13136 -- FUNCTION_PROFILE ::= [Parameter_Types => PARAMETER_TYPES,]
13137 -- Result_Type => result_SUBTYPE_NAME]
13139 -- PARAMETER_TYPES ::= (SUBTYPE_NAME {, SUBTYPE_NAME})
13140 -- SUBTYPE_NAME ::= STRING_LITERAL
13142 -- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE
13143 -- SOURCE_TRACE ::= STRING_LITERAL
13145 when Pragma_Eliminate
=> Eliminate
: declare
13146 Args
: Args_List
(1 .. 5);
13147 Names
: constant Name_List
(1 .. 5) := (
13150 Name_Parameter_Types
,
13152 Name_Source_Location
);
13154 Unit_Name
: Node_Id
renames Args
(1);
13155 Entity
: Node_Id
renames Args
(2);
13156 Parameter_Types
: Node_Id
renames Args
(3);
13157 Result_Type
: Node_Id
renames Args
(4);
13158 Source_Location
: Node_Id
renames Args
(5);
13162 Check_Valid_Configuration_Pragma
;
13163 Gather_Associations
(Names
, Args
);
13165 if No
(Unit_Name
) then
13166 Error_Pragma
("missing Unit_Name argument for pragma%");
13170 and then (Present
(Parameter_Types
)
13172 Present
(Result_Type
)
13174 Present
(Source_Location
))
13176 Error_Pragma
("missing Entity argument for pragma%");
13179 if (Present
(Parameter_Types
)
13181 Present
(Result_Type
))
13183 Present
(Source_Location
)
13186 ("parameter profile and source location cannot be used "
13187 & "together in pragma%");
13190 Process_Eliminate_Pragma
13199 -----------------------------------
13200 -- Enable_Atomic_Synchronization --
13201 -----------------------------------
13203 -- pragma Enable_Atomic_Synchronization [(Entity)];
13205 when Pragma_Enable_Atomic_Synchronization
=>
13207 Process_Disable_Enable_Atomic_Sync
(Name_Unsuppress
);
13214 -- [ Convention =>] convention_IDENTIFIER,
13215 -- [ Entity =>] LOCAL_NAME
13216 -- [, [External_Name =>] static_string_EXPRESSION ]
13217 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13219 when Pragma_Export
=> Export
: declare
13221 Def_Id
: Entity_Id
;
13223 pragma Warnings
(Off
, C
);
13226 Check_Ada_83_Warning
;
13230 Name_External_Name
,
13233 Check_At_Least_N_Arguments
(2);
13234 Check_At_Most_N_Arguments
(4);
13236 -- In Relaxed_RM_Semantics, support old Ada 83 style:
13237 -- pragma Export (Entity, "external name");
13239 if Relaxed_RM_Semantics
13240 and then Arg_Count
= 2
13241 and then Nkind
(Expression
(Arg2
)) = N_String_Literal
13244 Def_Id
:= Get_Pragma_Arg
(Arg1
);
13247 if not Is_Entity_Name
(Def_Id
) then
13248 Error_Pragma_Arg
("entity name required", Arg1
);
13251 Def_Id
:= Entity
(Def_Id
);
13252 Set_Exported
(Def_Id
, Arg1
);
13255 Process_Convention
(C
, Def_Id
);
13257 if Ekind
(Def_Id
) /= E_Constant
then
13258 Note_Possible_Modification
13259 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
13262 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
13263 Set_Exported
(Def_Id
, Arg2
);
13266 -- If the entity is a deferred constant, propagate the information
13267 -- to the full view, because gigi elaborates the full view only.
13269 if Ekind
(Def_Id
) = E_Constant
13270 and then Present
(Full_View
(Def_Id
))
13273 Id2
: constant Entity_Id
:= Full_View
(Def_Id
);
13275 Set_Is_Exported
(Id2
, Is_Exported
(Def_Id
));
13276 Set_First_Rep_Item
(Id2
, First_Rep_Item
(Def_Id
));
13277 Set_Interface_Name
(Id2
, Einfo
.Interface_Name
(Def_Id
));
13282 ---------------------
13283 -- Export_Function --
13284 ---------------------
13286 -- pragma Export_Function (
13287 -- [Internal =>] LOCAL_NAME
13288 -- [, [External =>] EXTERNAL_SYMBOL]
13289 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13290 -- [, [Result_Type =>] TYPE_DESIGNATOR]
13291 -- [, [Mechanism =>] MECHANISM]
13292 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
13294 -- EXTERNAL_SYMBOL ::=
13296 -- | static_string_EXPRESSION
13298 -- PARAMETER_TYPES ::=
13300 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13302 -- TYPE_DESIGNATOR ::=
13304 -- | subtype_Name ' Access
13308 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13310 -- MECHANISM_ASSOCIATION ::=
13311 -- [formal_parameter_NAME =>] MECHANISM_NAME
13313 -- MECHANISM_NAME ::=
13317 when Pragma_Export_Function
=> Export_Function
: declare
13318 Args
: Args_List
(1 .. 6);
13319 Names
: constant Name_List
(1 .. 6) := (
13322 Name_Parameter_Types
,
13325 Name_Result_Mechanism
);
13327 Internal
: Node_Id
renames Args
(1);
13328 External
: Node_Id
renames Args
(2);
13329 Parameter_Types
: Node_Id
renames Args
(3);
13330 Result_Type
: Node_Id
renames Args
(4);
13331 Mechanism
: Node_Id
renames Args
(5);
13332 Result_Mechanism
: Node_Id
renames Args
(6);
13336 Gather_Associations
(Names
, Args
);
13337 Process_Extended_Import_Export_Subprogram_Pragma
(
13338 Arg_Internal
=> Internal
,
13339 Arg_External
=> External
,
13340 Arg_Parameter_Types
=> Parameter_Types
,
13341 Arg_Result_Type
=> Result_Type
,
13342 Arg_Mechanism
=> Mechanism
,
13343 Arg_Result_Mechanism
=> Result_Mechanism
);
13344 end Export_Function
;
13346 -------------------
13347 -- Export_Object --
13348 -------------------
13350 -- pragma Export_Object (
13351 -- [Internal =>] LOCAL_NAME
13352 -- [, [External =>] EXTERNAL_SYMBOL]
13353 -- [, [Size =>] EXTERNAL_SYMBOL]);
13355 -- EXTERNAL_SYMBOL ::=
13357 -- | static_string_EXPRESSION
13359 -- PARAMETER_TYPES ::=
13361 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13363 -- TYPE_DESIGNATOR ::=
13365 -- | subtype_Name ' Access
13369 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13371 -- MECHANISM_ASSOCIATION ::=
13372 -- [formal_parameter_NAME =>] MECHANISM_NAME
13374 -- MECHANISM_NAME ::=
13378 when Pragma_Export_Object
=> Export_Object
: declare
13379 Args
: Args_List
(1 .. 3);
13380 Names
: constant Name_List
(1 .. 3) := (
13385 Internal
: Node_Id
renames Args
(1);
13386 External
: Node_Id
renames Args
(2);
13387 Size
: Node_Id
renames Args
(3);
13391 Gather_Associations
(Names
, Args
);
13392 Process_Extended_Import_Export_Object_Pragma
(
13393 Arg_Internal
=> Internal
,
13394 Arg_External
=> External
,
13398 ----------------------
13399 -- Export_Procedure --
13400 ----------------------
13402 -- pragma Export_Procedure (
13403 -- [Internal =>] LOCAL_NAME
13404 -- [, [External =>] EXTERNAL_SYMBOL]
13405 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13406 -- [, [Mechanism =>] MECHANISM]);
13408 -- EXTERNAL_SYMBOL ::=
13410 -- | static_string_EXPRESSION
13412 -- PARAMETER_TYPES ::=
13414 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13416 -- TYPE_DESIGNATOR ::=
13418 -- | subtype_Name ' Access
13422 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13424 -- MECHANISM_ASSOCIATION ::=
13425 -- [formal_parameter_NAME =>] MECHANISM_NAME
13427 -- MECHANISM_NAME ::=
13431 when Pragma_Export_Procedure
=> Export_Procedure
: declare
13432 Args
: Args_List
(1 .. 4);
13433 Names
: constant Name_List
(1 .. 4) := (
13436 Name_Parameter_Types
,
13439 Internal
: Node_Id
renames Args
(1);
13440 External
: Node_Id
renames Args
(2);
13441 Parameter_Types
: Node_Id
renames Args
(3);
13442 Mechanism
: Node_Id
renames Args
(4);
13446 Gather_Associations
(Names
, Args
);
13447 Process_Extended_Import_Export_Subprogram_Pragma
(
13448 Arg_Internal
=> Internal
,
13449 Arg_External
=> External
,
13450 Arg_Parameter_Types
=> Parameter_Types
,
13451 Arg_Mechanism
=> Mechanism
);
13452 end Export_Procedure
;
13458 -- pragma Export_Value (
13459 -- [Value =>] static_integer_EXPRESSION,
13460 -- [Link_Name =>] static_string_EXPRESSION);
13462 when Pragma_Export_Value
=>
13464 Check_Arg_Order
((Name_Value
, Name_Link_Name
));
13465 Check_Arg_Count
(2);
13467 Check_Optional_Identifier
(Arg1
, Name_Value
);
13468 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
13470 Check_Optional_Identifier
(Arg2
, Name_Link_Name
);
13471 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
13473 -----------------------------
13474 -- Export_Valued_Procedure --
13475 -----------------------------
13477 -- pragma Export_Valued_Procedure (
13478 -- [Internal =>] LOCAL_NAME
13479 -- [, [External =>] EXTERNAL_SYMBOL,]
13480 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
13481 -- [, [Mechanism =>] MECHANISM]);
13483 -- EXTERNAL_SYMBOL ::=
13485 -- | static_string_EXPRESSION
13487 -- PARAMETER_TYPES ::=
13489 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
13491 -- TYPE_DESIGNATOR ::=
13493 -- | subtype_Name ' Access
13497 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
13499 -- MECHANISM_ASSOCIATION ::=
13500 -- [formal_parameter_NAME =>] MECHANISM_NAME
13502 -- MECHANISM_NAME ::=
13506 when Pragma_Export_Valued_Procedure
=>
13507 Export_Valued_Procedure
: declare
13508 Args
: Args_List
(1 .. 4);
13509 Names
: constant Name_List
(1 .. 4) := (
13512 Name_Parameter_Types
,
13515 Internal
: Node_Id
renames Args
(1);
13516 External
: Node_Id
renames Args
(2);
13517 Parameter_Types
: Node_Id
renames Args
(3);
13518 Mechanism
: Node_Id
renames Args
(4);
13522 Gather_Associations
(Names
, Args
);
13523 Process_Extended_Import_Export_Subprogram_Pragma
(
13524 Arg_Internal
=> Internal
,
13525 Arg_External
=> External
,
13526 Arg_Parameter_Types
=> Parameter_Types
,
13527 Arg_Mechanism
=> Mechanism
);
13528 end Export_Valued_Procedure
;
13530 -------------------
13531 -- Extend_System --
13532 -------------------
13534 -- pragma Extend_System ([Name =>] Identifier);
13536 when Pragma_Extend_System
=> Extend_System
: declare
13539 Check_Valid_Configuration_Pragma
;
13540 Check_Arg_Count
(1);
13541 Check_Optional_Identifier
(Arg1
, Name_Name
);
13542 Check_Arg_Is_Identifier
(Arg1
);
13544 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
13547 and then Name_Buffer
(1 .. 4) = "aux_"
13549 if Present
(System_Extend_Pragma_Arg
) then
13550 if Chars
(Get_Pragma_Arg
(Arg1
)) =
13551 Chars
(Expression
(System_Extend_Pragma_Arg
))
13555 Error_Msg_Sloc
:= Sloc
(System_Extend_Pragma_Arg
);
13556 Error_Pragma
("pragma% conflicts with that #");
13560 System_Extend_Pragma_Arg
:= Arg1
;
13562 if not GNAT_Mode
then
13563 System_Extend_Unit
:= Arg1
;
13567 Error_Pragma
("incorrect name for pragma%, must be Aux_xxx");
13571 ------------------------
13572 -- Extensions_Allowed --
13573 ------------------------
13575 -- pragma Extensions_Allowed (ON | OFF);
13577 when Pragma_Extensions_Allowed
=>
13579 Check_Arg_Count
(1);
13580 Check_No_Identifiers
;
13581 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
13583 if Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
then
13584 Extensions_Allowed
:= True;
13585 Ada_Version
:= Ada_Version_Type
'Last;
13588 Extensions_Allowed
:= False;
13589 Ada_Version
:= Ada_Version_Explicit
;
13590 Ada_Version_Pragma
:= Empty
;
13593 ------------------------
13594 -- Extensions_Visible --
13595 ------------------------
13597 -- pragma Extensions_Visible [ (boolean_EXPRESSION) ];
13599 when Pragma_Extensions_Visible
=> Extensions_Visible
: declare
13601 Formal
: Entity_Id
;
13602 Has_OK_Formal
: Boolean := False;
13603 Spec_Id
: Entity_Id
;
13604 Subp_Decl
: Node_Id
;
13605 Subp_Id
: Entity_Id
;
13609 Check_No_Identifiers
;
13610 Check_At_Most_N_Arguments
(1);
13613 Find_Related_Subprogram_Or_Body
(N
, Do_Checks
=> True);
13615 -- Generic subprogram declaration
13617 if Nkind
(Subp_Decl
) = N_Generic_Subprogram_Declaration
then
13620 -- Body acts as spec
13622 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body
13623 and then No
(Corresponding_Spec
(Subp_Decl
))
13627 -- Body stub acts as spec
13629 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
13630 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
13634 -- Subprogram declaration
13636 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
13639 -- Otherwise the pragma is associated with an illegal construct
13642 Error_Pragma
("pragma % must apply to a subprogram");
13646 Spec_Id
:= Corresponding_Spec_Of
(Subp_Decl
);
13647 Subp_Id
:= Defining_Entity
(Subp_Decl
);
13649 -- Examine the formals of the related subprogram
13651 Formal
:= First_Formal
(Spec_Id
);
13652 while Present
(Formal
) loop
13654 -- At least one of the formals is of a specific tagged type,
13655 -- the pragma is legal.
13657 if Is_Specific_Tagged_Type
(Etype
(Formal
)) then
13658 Has_OK_Formal
:= True;
13661 -- A generic subprogram with at least one formal of a private
13662 -- type ensures the legality of the pragma because the actual
13663 -- may be specifically tagged. Note that this is verified by
13664 -- the check above at instantiation time.
13666 elsif Is_Private_Type
(Etype
(Formal
))
13667 and then Is_Generic_Type
(Etype
(Formal
))
13669 Has_OK_Formal
:= True;
13673 Next_Formal
(Formal
);
13676 if not Has_OK_Formal
then
13677 Error_Msg_Name_1
:= Pname
;
13678 Error_Msg_N
(Fix_Error
("incorrect placement of pragma %"), N
);
13680 ("\subprogram & lacks parameter of specific tagged or "
13681 & "generic private type", N
, Spec_Id
);
13685 -- Construct a generic template for the pragma when the context is
13686 -- a generic subprogram and the pragma is a source construct.
13688 Create_Generic_Template
(N
, Subp_Id
);
13690 -- Analyze the Boolean expression (if any)
13692 if Present
(Arg1
) then
13693 Expr
:= Expression
(Get_Argument
(N
));
13695 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
13697 if not Is_OK_Static_Expression
(Expr
) then
13699 ("expression of pragma % must be static", Expr
);
13704 -- Chain the pragma on the contract for further processing
13706 Add_Contract_Item
(N
, Subp_Id
);
13707 end Extensions_Visible
;
13713 -- pragma External (
13714 -- [ Convention =>] convention_IDENTIFIER,
13715 -- [ Entity =>] LOCAL_NAME
13716 -- [, [External_Name =>] static_string_EXPRESSION ]
13717 -- [, [Link_Name =>] static_string_EXPRESSION ]);
13719 when Pragma_External
=> External
: declare
13720 Def_Id
: Entity_Id
;
13723 pragma Warnings
(Off
, C
);
13730 Name_External_Name
,
13732 Check_At_Least_N_Arguments
(2);
13733 Check_At_Most_N_Arguments
(4);
13734 Process_Convention
(C
, Def_Id
);
13735 Note_Possible_Modification
13736 (Get_Pragma_Arg
(Arg2
), Sure
=> False);
13737 Process_Interface_Name
(Def_Id
, Arg3
, Arg4
);
13738 Set_Exported
(Def_Id
, Arg2
);
13741 --------------------------
13742 -- External_Name_Casing --
13743 --------------------------
13745 -- pragma External_Name_Casing (
13746 -- UPPERCASE | LOWERCASE
13747 -- [, AS_IS | UPPERCASE | LOWERCASE]);
13749 when Pragma_External_Name_Casing
=> External_Name_Casing
: declare
13752 Check_No_Identifiers
;
13754 if Arg_Count
= 2 then
13755 Check_Arg_Is_One_Of
13756 (Arg2
, Name_As_Is
, Name_Uppercase
, Name_Lowercase
);
13758 case Chars
(Get_Pragma_Arg
(Arg2
)) is
13760 Opt
.External_Name_Exp_Casing
:= As_Is
;
13762 when Name_Uppercase
=>
13763 Opt
.External_Name_Exp_Casing
:= Uppercase
;
13765 when Name_Lowercase
=>
13766 Opt
.External_Name_Exp_Casing
:= Lowercase
;
13773 Check_Arg_Count
(1);
13776 Check_Arg_Is_One_Of
(Arg1
, Name_Uppercase
, Name_Lowercase
);
13778 case Chars
(Get_Pragma_Arg
(Arg1
)) is
13779 when Name_Uppercase
=>
13780 Opt
.External_Name_Imp_Casing
:= Uppercase
;
13782 when Name_Lowercase
=>
13783 Opt
.External_Name_Imp_Casing
:= Lowercase
;
13788 end External_Name_Casing
;
13794 -- pragma Fast_Math;
13796 when Pragma_Fast_Math
=>
13798 Check_No_Identifiers
;
13799 Check_Valid_Configuration_Pragma
;
13802 --------------------------
13803 -- Favor_Top_Level --
13804 --------------------------
13806 -- pragma Favor_Top_Level (type_NAME);
13808 when Pragma_Favor_Top_Level
=> Favor_Top_Level
: declare
13809 Named_Entity
: Entity_Id
;
13813 Check_No_Identifiers
;
13814 Check_Arg_Count
(1);
13815 Check_Arg_Is_Local_Name
(Arg1
);
13816 Named_Entity
:= Entity
(Get_Pragma_Arg
(Arg1
));
13818 -- If it's an access-to-subprogram type (in particular, not a
13819 -- subtype), set the flag on that type.
13821 if Is_Access_Subprogram_Type
(Named_Entity
) then
13822 Set_Can_Use_Internal_Rep
(Named_Entity
, False);
13824 -- Otherwise it's an error (name denotes the wrong sort of entity)
13828 ("access-to-subprogram type expected",
13829 Get_Pragma_Arg
(Arg1
));
13831 end Favor_Top_Level
;
13833 ---------------------------
13834 -- Finalize_Storage_Only --
13835 ---------------------------
13837 -- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME);
13839 when Pragma_Finalize_Storage_Only
=> Finalize_Storage
: declare
13840 Assoc
: constant Node_Id
:= Arg1
;
13841 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
13846 Check_No_Identifiers
;
13847 Check_Arg_Count
(1);
13848 Check_Arg_Is_Local_Name
(Arg1
);
13850 Find_Type
(Type_Id
);
13851 Typ
:= Entity
(Type_Id
);
13854 or else Rep_Item_Too_Early
(Typ
, N
)
13858 Typ
:= Underlying_Type
(Typ
);
13861 if not Is_Controlled
(Typ
) then
13862 Error_Pragma
("pragma% must specify controlled type");
13865 Check_First_Subtype
(Arg1
);
13867 if Finalize_Storage_Only
(Typ
) then
13868 Error_Pragma
("duplicate pragma%, only one allowed");
13870 elsif not Rep_Item_Too_Late
(Typ
, N
) then
13871 Set_Finalize_Storage_Only
(Base_Type
(Typ
), True);
13873 end Finalize_Storage
;
13879 -- pragma Ghost [ (boolean_EXPRESSION) ];
13881 when Pragma_Ghost
=> Ghost
: declare
13885 Orig_Stmt
: Node_Id
;
13886 Prev_Id
: Entity_Id
;
13891 Check_No_Identifiers
;
13892 Check_At_Most_N_Arguments
(1);
13894 Context
:= Parent
(N
);
13896 -- Handle compilation units
13898 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
13899 Context
:= Unit
(Parent
(Context
));
13904 while Present
(Stmt
) loop
13906 -- Skip prior pragmas, but check for duplicates
13908 if Nkind
(Stmt
) = N_Pragma
then
13909 if Pragma_Name
(Stmt
) = Pname
then
13910 Error_Msg_Name_1
:= Pname
;
13911 Error_Msg_Sloc
:= Sloc
(Stmt
);
13912 Error_Msg_N
("pragma % duplicates pragma declared#", N
);
13915 -- Protected and task types cannot be subject to pragma Ghost
13917 elsif Nkind
(Stmt
) = N_Protected_Type_Declaration
then
13918 Error_Pragma
("pragma % cannot apply to a protected type");
13921 elsif Nkind
(Stmt
) = N_Task_Type_Declaration
then
13922 Error_Pragma
("pragma % cannot apply to a task type");
13925 -- Skip internally generated code
13927 elsif not Comes_From_Source
(Stmt
) then
13928 Orig_Stmt
:= Original_Node
(Stmt
);
13930 -- When pragma Ghost applies to an untagged derivation, the
13931 -- derivation is transformed into a [sub]type declaration.
13933 if Nkind_In
(Stmt
, N_Full_Type_Declaration
,
13934 N_Subtype_Declaration
)
13935 and then Comes_From_Source
(Orig_Stmt
)
13936 and then Nkind
(Orig_Stmt
) = N_Full_Type_Declaration
13937 and then Nkind
(Type_Definition
(Orig_Stmt
)) =
13938 N_Derived_Type_Definition
13940 Id
:= Defining_Entity
(Stmt
);
13943 -- When pragma Ghost applies to an expression function, the
13944 -- expression function is transformed into a subprogram.
13946 elsif Nkind
(Stmt
) = N_Subprogram_Declaration
13947 and then Comes_From_Source
(Orig_Stmt
)
13948 and then Nkind
(Orig_Stmt
) = N_Expression_Function
13950 Id
:= Defining_Entity
(Stmt
);
13954 -- The pragma applies to a legal construct, stop the traversal
13956 elsif Nkind_In
(Stmt
, N_Abstract_Subprogram_Declaration
,
13957 N_Full_Type_Declaration
,
13958 N_Generic_Subprogram_Declaration
,
13959 N_Object_Declaration
,
13960 N_Private_Extension_Declaration
,
13961 N_Private_Type_Declaration
,
13962 N_Subprogram_Declaration
,
13963 N_Subtype_Declaration
)
13965 Id
:= Defining_Entity
(Stmt
);
13968 -- The pragma does not apply to a legal construct, issue an
13969 -- error and stop the analysis.
13973 ("pragma % must apply to an object, package, subprogram "
13978 Stmt
:= Prev
(Stmt
);
13983 -- When pragma Ghost is associated with a [generic] package, it
13984 -- appears in the visible declarations.
13986 if Nkind
(Context
) = N_Package_Specification
13987 and then Present
(Visible_Declarations
(Context
))
13988 and then List_Containing
(N
) = Visible_Declarations
(Context
)
13990 Id
:= Defining_Entity
(Context
);
13992 -- Pragma Ghost applies to a stand alone subprogram body
13994 elsif Nkind
(Context
) = N_Subprogram_Body
13995 and then No
(Corresponding_Spec
(Context
))
13997 Id
:= Defining_Entity
(Context
);
14003 ("pragma % must apply to an object, package, subprogram or "
14008 -- A derived type or type extension cannot be subject to pragma
14009 -- Ghost if either the parent type or one of the progenitor types
14010 -- is not Ghost (SPARK RM 6.9(9)).
14012 if Is_Derived_Type
(Id
) then
14013 Check_Ghost_Derivation
(Id
);
14016 -- Handle completions of types and constants that are subject to
14019 if Is_Record_Type
(Id
) or else Ekind
(Id
) = E_Constant
then
14020 Prev_Id
:= Incomplete_Or_Partial_View
(Id
);
14022 if Present
(Prev_Id
) and then not Is_Ghost_Entity
(Prev_Id
) then
14023 Error_Msg_Name_1
:= Pname
;
14025 -- The full declaration of a deferred constant cannot be
14026 -- subject to pragma Ghost unless the deferred declaration
14027 -- is also Ghost (SPARK RM 6.9(10)).
14029 if Ekind
(Prev_Id
) = E_Constant
then
14030 Error_Msg_Name_1
:= Pname
;
14031 Error_Msg_NE
(Fix_Error
14032 ("pragma % must apply to declaration of deferred "
14033 & "constant &"), N
, Id
);
14036 -- Pragma Ghost may appear on the full view of an incomplete
14037 -- type because the incomplete declaration lacks aspects and
14038 -- cannot be subject to pragma Ghost.
14040 elsif Ekind
(Prev_Id
) = E_Incomplete_Type
then
14043 -- The full declaration of a type cannot be subject to
14044 -- pragma Ghost unless the partial view is also Ghost
14045 -- (SPARK RM 6.9(10)).
14048 Error_Msg_NE
(Fix_Error
14049 ("pragma % must apply to partial view of type &"),
14056 -- Analyze the Boolean expression (if any)
14058 if Present
(Arg1
) then
14059 Expr
:= Get_Pragma_Arg
(Arg1
);
14061 Analyze_And_Resolve
(Expr
, Standard_Boolean
);
14063 if Is_OK_Static_Expression
(Expr
) then
14065 -- "Ghostness" cannot be turned off once enabled within a
14066 -- region (SPARK RM 6.9(7)).
14068 if Is_False
(Expr_Value
(Expr
))
14069 and then Ghost_Mode
> None
14072 ("pragma % with value False cannot appear in enabled "
14077 -- Otherwie the expression is not static
14081 ("expression of pragma % must be static", Expr
);
14086 Set_Is_Ghost_Entity
(Id
);
14093 -- pragma Global (GLOBAL_SPECIFICATION);
14095 -- GLOBAL_SPECIFICATION ::=
14098 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
14100 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
14102 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
14103 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
14104 -- GLOBAL_ITEM ::= NAME
14106 when Pragma_Global
=> Global
: declare
14107 Subp_Decl
: Node_Id
;
14108 Subp_Id
: Entity_Id
;
14112 Check_Arg_Count
(1);
14114 -- Ensure the proper placement of the pragma. Global must be
14115 -- associated with a subprogram declaration or a body that acts
14119 Find_Related_Subprogram_Or_Body
(N
, Do_Checks
=> True);
14121 -- Body acts as spec
14123 if Nkind
(Subp_Decl
) = N_Subprogram_Body
14124 and then No
(Corresponding_Spec
(Subp_Decl
))
14128 -- Body stub acts as spec
14130 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
14131 and then No
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
14135 -- Subprogram declaration
14137 elsif Nkind
(Subp_Decl
) = N_Subprogram_Declaration
then
14145 Subp_Id
:= Defining_Entity
(Subp_Decl
);
14147 Ensure_Aggregate_Form
(Get_Argument
(N
, Subp_Id
));
14149 -- Construct a generic template for the pragma when the context is
14150 -- a generic subprogram and the pragma is a source construct.
14152 Create_Generic_Template
(N
, Subp_Id
);
14154 -- When the pragma appears on a subprogram body, perform the full
14157 if Nkind
(Subp_Decl
) = N_Subprogram_Body
then
14158 Analyze_Global_In_Decl_Part
(N
);
14161 -- Chain the pragma on the contract for further processing
14163 Add_Contract_Item
(N
, Subp_Id
);
14170 -- pragma Ident (static_string_EXPRESSION)
14172 -- Note: pragma Comment shares this processing. Pragma Ident is
14173 -- identical in effect to pragma Commment.
14175 when Pragma_Ident | Pragma_Comment
=> Ident
: declare
14180 Check_Arg_Count
(1);
14181 Check_No_Identifiers
;
14182 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
14185 Str
:= Expr_Value_S
(Get_Pragma_Arg
(Arg1
));
14192 GP
:= Parent
(Parent
(N
));
14194 if Nkind_In
(GP
, N_Package_Declaration
,
14195 N_Generic_Package_Declaration
)
14200 -- If we have a compilation unit, then record the ident value,
14201 -- checking for improper duplication.
14203 if Nkind
(GP
) = N_Compilation_Unit
then
14204 CS
:= Ident_String
(Current_Sem_Unit
);
14206 if Present
(CS
) then
14208 -- If we have multiple instances, concatenate them, but
14209 -- not in ASIS, where we want the original tree.
14211 if not ASIS_Mode
then
14212 Start_String
(Strval
(CS
));
14213 Store_String_Char
(' ');
14214 Store_String_Chars
(Strval
(Str
));
14215 Set_Strval
(CS
, End_String
);
14219 Set_Ident_String
(Current_Sem_Unit
, Str
);
14222 -- For subunits, we just ignore the Ident, since in GNAT these
14223 -- are not separate object files, and hence not separate units
14224 -- in the unit table.
14226 elsif Nkind
(GP
) = N_Subunit
then
14232 ----------------------------
14233 -- Implementation_Defined --
14234 ----------------------------
14236 -- pragma Implementation_Defined (LOCAL_NAME);
14238 -- Marks previously declared entity as implementation defined. For
14239 -- an overloaded entity, applies to the most recent homonym.
14241 -- pragma Implementation_Defined;
14243 -- The form with no arguments appears anywhere within a scope, most
14244 -- typically a package spec, and indicates that all entities that are
14245 -- defined within the package spec are Implementation_Defined.
14247 when Pragma_Implementation_Defined
=> Implementation_Defined
: declare
14252 Check_No_Identifiers
;
14254 -- Form with no arguments
14256 if Arg_Count
= 0 then
14257 Set_Is_Implementation_Defined
(Current_Scope
);
14259 -- Form with one argument
14262 Check_Arg_Count
(1);
14263 Check_Arg_Is_Local_Name
(Arg1
);
14264 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
14265 Set_Is_Implementation_Defined
(Ent
);
14267 end Implementation_Defined
;
14273 -- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND);
14275 -- IMPLEMENTATION_KIND ::=
14276 -- By_Entry | By_Protected_Procedure | By_Any | Optional
14278 -- "By_Any" and "Optional" are treated as synonyms in order to
14279 -- support Ada 2012 aspect Synchronization.
14281 when Pragma_Implemented
=> Implemented
: declare
14282 Proc_Id
: Entity_Id
;
14287 Check_Arg_Count
(2);
14288 Check_No_Identifiers
;
14289 Check_Arg_Is_Identifier
(Arg1
);
14290 Check_Arg_Is_Local_Name
(Arg1
);
14291 Check_Arg_Is_One_Of
(Arg2
,
14294 Name_By_Protected_Procedure
,
14297 -- Extract the name of the local procedure
14299 Proc_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
14301 -- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a
14302 -- primitive procedure of a synchronized tagged type.
14304 if Ekind
(Proc_Id
) = E_Procedure
14305 and then Is_Primitive
(Proc_Id
)
14306 and then Present
(First_Formal
(Proc_Id
))
14308 Typ
:= Etype
(First_Formal
(Proc_Id
));
14310 if Is_Tagged_Type
(Typ
)
14313 -- Check for a protected, a synchronized or a task interface
14315 ((Is_Interface
(Typ
)
14316 and then Is_Synchronized_Interface
(Typ
))
14318 -- Check for a protected type or a task type that implements
14322 (Is_Concurrent_Record_Type
(Typ
)
14323 and then Present
(Interfaces
(Typ
)))
14325 -- In analysis-only mode, examine original protected type
14328 (Nkind
(Parent
(Typ
)) = N_Protected_Type_Declaration
14329 and then Present
(Interface_List
(Parent
(Typ
))))
14331 -- Check for a private record extension with keyword
14335 (Ekind_In
(Typ
, E_Record_Type_With_Private
,
14336 E_Record_Subtype_With_Private
)
14337 and then Synchronized_Present
(Parent
(Typ
))))
14342 ("controlling formal must be of synchronized tagged type",
14347 -- Procedures declared inside a protected type must be accepted
14349 elsif Ekind
(Proc_Id
) = E_Procedure
14350 and then Is_Protected_Type
(Scope
(Proc_Id
))
14354 -- The first argument is not a primitive procedure
14358 ("pragma % must be applied to a primitive procedure", Arg1
);
14362 -- Ada 2012 (AI05-0030): Cannot apply the implementation_kind
14363 -- By_Protected_Procedure to the primitive procedure of a task
14366 if Chars
(Arg2
) = Name_By_Protected_Procedure
14367 and then Is_Interface
(Typ
)
14368 and then Is_Task_Interface
(Typ
)
14371 ("implementation kind By_Protected_Procedure cannot be "
14372 & "applied to a task interface primitive", Arg2
);
14376 Record_Rep_Item
(Proc_Id
, N
);
14379 ----------------------
14380 -- Implicit_Packing --
14381 ----------------------
14383 -- pragma Implicit_Packing;
14385 when Pragma_Implicit_Packing
=>
14387 Check_Arg_Count
(0);
14388 Implicit_Packing
:= True;
14395 -- [Convention =>] convention_IDENTIFIER,
14396 -- [Entity =>] LOCAL_NAME
14397 -- [, [External_Name =>] static_string_EXPRESSION ]
14398 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14400 when Pragma_Import
=>
14401 Check_Ada_83_Warning
;
14405 Name_External_Name
,
14408 Check_At_Least_N_Arguments
(2);
14409 Check_At_Most_N_Arguments
(4);
14410 Process_Import_Or_Interface
;
14412 ---------------------
14413 -- Import_Function --
14414 ---------------------
14416 -- pragma Import_Function (
14417 -- [Internal =>] LOCAL_NAME,
14418 -- [, [External =>] EXTERNAL_SYMBOL]
14419 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14420 -- [, [Result_Type =>] SUBTYPE_MARK]
14421 -- [, [Mechanism =>] MECHANISM]
14422 -- [, [Result_Mechanism =>] MECHANISM_NAME]);
14424 -- EXTERNAL_SYMBOL ::=
14426 -- | static_string_EXPRESSION
14428 -- PARAMETER_TYPES ::=
14430 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14432 -- TYPE_DESIGNATOR ::=
14434 -- | subtype_Name ' Access
14438 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14440 -- MECHANISM_ASSOCIATION ::=
14441 -- [formal_parameter_NAME =>] MECHANISM_NAME
14443 -- MECHANISM_NAME ::=
14447 when Pragma_Import_Function
=> Import_Function
: declare
14448 Args
: Args_List
(1 .. 6);
14449 Names
: constant Name_List
(1 .. 6) := (
14452 Name_Parameter_Types
,
14455 Name_Result_Mechanism
);
14457 Internal
: Node_Id
renames Args
(1);
14458 External
: Node_Id
renames Args
(2);
14459 Parameter_Types
: Node_Id
renames Args
(3);
14460 Result_Type
: Node_Id
renames Args
(4);
14461 Mechanism
: Node_Id
renames Args
(5);
14462 Result_Mechanism
: Node_Id
renames Args
(6);
14466 Gather_Associations
(Names
, Args
);
14467 Process_Extended_Import_Export_Subprogram_Pragma
(
14468 Arg_Internal
=> Internal
,
14469 Arg_External
=> External
,
14470 Arg_Parameter_Types
=> Parameter_Types
,
14471 Arg_Result_Type
=> Result_Type
,
14472 Arg_Mechanism
=> Mechanism
,
14473 Arg_Result_Mechanism
=> Result_Mechanism
);
14474 end Import_Function
;
14476 -------------------
14477 -- Import_Object --
14478 -------------------
14480 -- pragma Import_Object (
14481 -- [Internal =>] LOCAL_NAME
14482 -- [, [External =>] EXTERNAL_SYMBOL]
14483 -- [, [Size =>] EXTERNAL_SYMBOL]);
14485 -- EXTERNAL_SYMBOL ::=
14487 -- | static_string_EXPRESSION
14489 when Pragma_Import_Object
=> Import_Object
: declare
14490 Args
: Args_List
(1 .. 3);
14491 Names
: constant Name_List
(1 .. 3) := (
14496 Internal
: Node_Id
renames Args
(1);
14497 External
: Node_Id
renames Args
(2);
14498 Size
: Node_Id
renames Args
(3);
14502 Gather_Associations
(Names
, Args
);
14503 Process_Extended_Import_Export_Object_Pragma
(
14504 Arg_Internal
=> Internal
,
14505 Arg_External
=> External
,
14509 ----------------------
14510 -- Import_Procedure --
14511 ----------------------
14513 -- pragma Import_Procedure (
14514 -- [Internal =>] LOCAL_NAME
14515 -- [, [External =>] EXTERNAL_SYMBOL]
14516 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14517 -- [, [Mechanism =>] MECHANISM]);
14519 -- EXTERNAL_SYMBOL ::=
14521 -- | static_string_EXPRESSION
14523 -- PARAMETER_TYPES ::=
14525 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14527 -- TYPE_DESIGNATOR ::=
14529 -- | subtype_Name ' Access
14533 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14535 -- MECHANISM_ASSOCIATION ::=
14536 -- [formal_parameter_NAME =>] MECHANISM_NAME
14538 -- MECHANISM_NAME ::=
14542 when Pragma_Import_Procedure
=> Import_Procedure
: declare
14543 Args
: Args_List
(1 .. 4);
14544 Names
: constant Name_List
(1 .. 4) := (
14547 Name_Parameter_Types
,
14550 Internal
: Node_Id
renames Args
(1);
14551 External
: Node_Id
renames Args
(2);
14552 Parameter_Types
: Node_Id
renames Args
(3);
14553 Mechanism
: Node_Id
renames Args
(4);
14557 Gather_Associations
(Names
, Args
);
14558 Process_Extended_Import_Export_Subprogram_Pragma
(
14559 Arg_Internal
=> Internal
,
14560 Arg_External
=> External
,
14561 Arg_Parameter_Types
=> Parameter_Types
,
14562 Arg_Mechanism
=> Mechanism
);
14563 end Import_Procedure
;
14565 -----------------------------
14566 -- Import_Valued_Procedure --
14567 -----------------------------
14569 -- pragma Import_Valued_Procedure (
14570 -- [Internal =>] LOCAL_NAME
14571 -- [, [External =>] EXTERNAL_SYMBOL]
14572 -- [, [Parameter_Types =>] (PARAMETER_TYPES)]
14573 -- [, [Mechanism =>] MECHANISM]);
14575 -- EXTERNAL_SYMBOL ::=
14577 -- | static_string_EXPRESSION
14579 -- PARAMETER_TYPES ::=
14581 -- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@}
14583 -- TYPE_DESIGNATOR ::=
14585 -- | subtype_Name ' Access
14589 -- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@})
14591 -- MECHANISM_ASSOCIATION ::=
14592 -- [formal_parameter_NAME =>] MECHANISM_NAME
14594 -- MECHANISM_NAME ::=
14598 when Pragma_Import_Valued_Procedure
=>
14599 Import_Valued_Procedure
: declare
14600 Args
: Args_List
(1 .. 4);
14601 Names
: constant Name_List
(1 .. 4) := (
14604 Name_Parameter_Types
,
14607 Internal
: Node_Id
renames Args
(1);
14608 External
: Node_Id
renames Args
(2);
14609 Parameter_Types
: Node_Id
renames Args
(3);
14610 Mechanism
: Node_Id
renames Args
(4);
14614 Gather_Associations
(Names
, Args
);
14615 Process_Extended_Import_Export_Subprogram_Pragma
(
14616 Arg_Internal
=> Internal
,
14617 Arg_External
=> External
,
14618 Arg_Parameter_Types
=> Parameter_Types
,
14619 Arg_Mechanism
=> Mechanism
);
14620 end Import_Valued_Procedure
;
14626 -- pragma Independent (LOCAL_NAME);
14628 when Pragma_Independent
=>
14629 Process_Atomic_Independent_Shared_Volatile
;
14631 ----------------------------
14632 -- Independent_Components --
14633 ----------------------------
14635 -- pragma Independent_Components (array_or_record_LOCAL_NAME);
14637 when Pragma_Independent_Components
=> Independent_Components
: declare
14645 Check_Ada_83_Warning
;
14647 Check_No_Identifiers
;
14648 Check_Arg_Count
(1);
14649 Check_Arg_Is_Local_Name
(Arg1
);
14650 E_Id
:= Get_Pragma_Arg
(Arg1
);
14652 if Etype
(E_Id
) = Any_Type
then
14656 E
:= Entity
(E_Id
);
14658 -- Check duplicate before we chain ourselves
14660 Check_Duplicate_Pragma
(E
);
14662 -- Check appropriate entity
14664 if Rep_Item_Too_Early
(E
, N
)
14666 Rep_Item_Too_Late
(E
, N
)
14671 D
:= Declaration_Node
(E
);
14674 -- The flag is set on the base type, or on the object
14676 if K
= N_Full_Type_Declaration
14677 and then (Is_Array_Type
(E
) or else Is_Record_Type
(E
))
14679 Set_Has_Independent_Components
(Base_Type
(E
));
14680 Record_Independence_Check
(N
, Base_Type
(E
));
14682 -- For record type, set all components independent
14684 if Is_Record_Type
(E
) then
14685 C
:= First_Component
(E
);
14686 while Present
(C
) loop
14687 Set_Is_Independent
(C
);
14688 Next_Component
(C
);
14692 elsif (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
14693 and then Nkind
(D
) = N_Object_Declaration
14694 and then Nkind
(Object_Definition
(D
)) =
14695 N_Constrained_Array_Definition
14697 Set_Has_Independent_Components
(E
);
14698 Record_Independence_Check
(N
, E
);
14701 Error_Pragma_Arg
("inappropriate entity for pragma%", Arg1
);
14703 end Independent_Components
;
14705 -----------------------
14706 -- Initial_Condition --
14707 -----------------------
14709 -- pragma Initial_Condition (boolean_EXPRESSION);
14711 when Pragma_Initial_Condition
=> Initial_Condition
: declare
14712 Pack_Decl
: Node_Id
;
14713 Pack_Id
: Entity_Id
;
14717 Check_No_Identifiers
;
14718 Check_Arg_Count
(1);
14720 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
14722 -- Ensure the proper placement of the pragma. Initial_Condition
14723 -- must be associated with a package declaration.
14725 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
14726 N_Package_Declaration
)
14730 -- Otherwise the pragma is associated with an illegal context
14737 -- The pragma must be analyzed at the end of the visible
14738 -- declarations of the related package. Save the pragma for later
14739 -- (see Analyze_Initial_Condition_In_Decl_Part) by adding it to
14740 -- the contract of the package.
14742 Pack_Id
:= Defining_Entity
(Pack_Decl
);
14743 Add_Contract_Item
(N
, Pack_Id
);
14745 -- Verify the declaration order of pragma Initial_Condition with
14746 -- respect to pragmas Abstract_State and Initializes when SPARK
14747 -- checks are enabled.
14749 if SPARK_Mode
/= Off
then
14750 Check_Declaration_Order
14751 (First
=> Get_Pragma
(Pack_Id
, Pragma_Abstract_State
),
14754 Check_Declaration_Order
14755 (First
=> Get_Pragma
(Pack_Id
, Pragma_Initializes
),
14758 end Initial_Condition
;
14760 ------------------------
14761 -- Initialize_Scalars --
14762 ------------------------
14764 -- pragma Initialize_Scalars;
14766 when Pragma_Initialize_Scalars
=>
14768 Check_Arg_Count
(0);
14769 Check_Valid_Configuration_Pragma
;
14770 Check_Restriction
(No_Initialize_Scalars
, N
);
14772 -- Initialize_Scalars creates false positives in CodePeer, and
14773 -- incorrect negative results in GNATprove mode, so ignore this
14774 -- pragma in these modes.
14776 if not Restriction_Active
(No_Initialize_Scalars
)
14777 and then not (CodePeer_Mode
or GNATprove_Mode
)
14779 Init_Or_Norm_Scalars
:= True;
14780 Initialize_Scalars
:= True;
14787 -- pragma Initializes (INITIALIZATION_SPEC);
14789 -- INITIALIZATION_SPEC ::= null | INITIALIZATION_LIST
14791 -- INITIALIZATION_LIST ::=
14792 -- INITIALIZATION_ITEM
14793 -- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM})
14795 -- INITIALIZATION_ITEM ::= name [=> INPUT_LIST]
14800 -- | (INPUT {, INPUT})
14804 when Pragma_Initializes
=> Initializes
: declare
14805 Pack_Decl
: Node_Id
;
14806 Pack_Id
: Entity_Id
;
14810 Check_No_Identifiers
;
14811 Check_Arg_Count
(1);
14813 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
14815 -- Ensure the proper placement of the pragma. Initializes must be
14816 -- associated with a package declaration.
14818 if Nkind_In
(Pack_Decl
, N_Generic_Package_Declaration
,
14819 N_Package_Declaration
)
14823 -- Otherwise the pragma is associated with an illegal construc
14830 Ensure_Aggregate_Form
(Get_Argument
(N
));
14832 -- The pragma must be analyzed at the end of the visible
14833 -- declarations of the related package. Save the pragma for later
14834 -- (see Analyze_Initializes_In_Decl_Part) by adding it to the
14835 -- contract of the package.
14837 Pack_Id
:= Defining_Entity
(Pack_Decl
);
14838 Add_Contract_Item
(N
, Pack_Id
);
14840 -- Verify the declaration order of pragmas Abstract_State and
14841 -- Initializes when SPARK checks are enabled.
14843 if SPARK_Mode
/= Off
then
14844 Check_Declaration_Order
14845 (First
=> Get_Pragma
(Pack_Id
, Pragma_Abstract_State
),
14854 -- pragma Inline ( NAME {, NAME} );
14856 when Pragma_Inline
=>
14858 -- Pragma always active unless in GNATprove mode. It is disabled
14859 -- in GNATprove mode because frontend inlining is applied
14860 -- independently of pragmas Inline and Inline_Always for
14861 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode
14864 if not GNATprove_Mode
then
14866 -- Inline status is Enabled if inlining option is active
14868 if Inline_Active
then
14869 Process_Inline
(Enabled
);
14871 Process_Inline
(Disabled
);
14875 -------------------
14876 -- Inline_Always --
14877 -------------------
14879 -- pragma Inline_Always ( NAME {, NAME} );
14881 when Pragma_Inline_Always
=>
14884 -- Pragma always active unless in CodePeer mode or GNATprove
14885 -- mode. It is disabled in CodePeer mode because inlining is
14886 -- not helpful, and enabling it caused walk order issues. It
14887 -- is disabled in GNATprove mode because frontend inlining is
14888 -- applied independently of pragmas Inline and Inline_Always for
14889 -- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in
14892 if not CodePeer_Mode
and not GNATprove_Mode
then
14893 Process_Inline
(Enabled
);
14896 --------------------
14897 -- Inline_Generic --
14898 --------------------
14900 -- pragma Inline_Generic (NAME {, NAME});
14902 when Pragma_Inline_Generic
=>
14904 Process_Generic_List
;
14906 ----------------------
14907 -- Inspection_Point --
14908 ----------------------
14910 -- pragma Inspection_Point [(object_NAME {, object_NAME})];
14912 when Pragma_Inspection_Point
=> Inspection_Point
: declare
14919 if Arg_Count
> 0 then
14922 Exp
:= Get_Pragma_Arg
(Arg
);
14925 if not Is_Entity_Name
(Exp
)
14926 or else not Is_Object
(Entity
(Exp
))
14928 Error_Pragma_Arg
("object name required", Arg
);
14932 exit when No
(Arg
);
14935 end Inspection_Point
;
14941 -- pragma Interface (
14942 -- [ Convention =>] convention_IDENTIFIER,
14943 -- [ Entity =>] LOCAL_NAME
14944 -- [, [External_Name =>] static_string_EXPRESSION ]
14945 -- [, [Link_Name =>] static_string_EXPRESSION ]);
14947 when Pragma_Interface
=>
14952 Name_External_Name
,
14954 Check_At_Least_N_Arguments
(2);
14955 Check_At_Most_N_Arguments
(4);
14956 Process_Import_Or_Interface
;
14958 -- In Ada 2005, the permission to use Interface (a reserved word)
14959 -- as a pragma name is considered an obsolescent feature, and this
14960 -- pragma was already obsolescent in Ada 95.
14962 if Ada_Version
>= Ada_95
then
14964 (No_Obsolescent_Features
, Pragma_Identifier
(N
));
14966 if Warn_On_Obsolescent_Feature
then
14968 ("pragma Interface is an obsolescent feature?j?", N
);
14970 ("|use pragma Import instead?j?", N
);
14974 --------------------
14975 -- Interface_Name --
14976 --------------------
14978 -- pragma Interface_Name (
14979 -- [ Entity =>] LOCAL_NAME
14980 -- [,[External_Name =>] static_string_EXPRESSION ]
14981 -- [,[Link_Name =>] static_string_EXPRESSION ]);
14983 when Pragma_Interface_Name
=> Interface_Name
: declare
14985 Def_Id
: Entity_Id
;
14986 Hom_Id
: Entity_Id
;
14992 ((Name_Entity
, Name_External_Name
, Name_Link_Name
));
14993 Check_At_Least_N_Arguments
(2);
14994 Check_At_Most_N_Arguments
(3);
14995 Id
:= Get_Pragma_Arg
(Arg1
);
14998 -- This is obsolete from Ada 95 on, but it is an implementation
14999 -- defined pragma, so we do not consider that it violates the
15000 -- restriction (No_Obsolescent_Features).
15002 if Ada_Version
>= Ada_95
then
15003 if Warn_On_Obsolescent_Feature
then
15005 ("pragma Interface_Name is an obsolescent feature?j?", N
);
15007 ("|use pragma Import instead?j?", N
);
15011 if not Is_Entity_Name
(Id
) then
15013 ("first argument for pragma% must be entity name", Arg1
);
15014 elsif Etype
(Id
) = Any_Type
then
15017 Def_Id
:= Entity
(Id
);
15020 -- Special DEC-compatible processing for the object case, forces
15021 -- object to be imported.
15023 if Ekind
(Def_Id
) = E_Variable
then
15024 Kill_Size_Check_Code
(Def_Id
);
15025 Note_Possible_Modification
(Id
, Sure
=> False);
15027 -- Initialization is not allowed for imported variable
15029 if Present
(Expression
(Parent
(Def_Id
)))
15030 and then Comes_From_Source
(Expression
(Parent
(Def_Id
)))
15032 Error_Msg_Sloc
:= Sloc
(Def_Id
);
15034 ("no initialization allowed for declaration of& #",
15038 -- For compatibility, support VADS usage of providing both
15039 -- pragmas Interface and Interface_Name to obtain the effect
15040 -- of a single Import pragma.
15042 if Is_Imported
(Def_Id
)
15043 and then Present
(First_Rep_Item
(Def_Id
))
15044 and then Nkind
(First_Rep_Item
(Def_Id
)) = N_Pragma
15046 Pragma_Name
(First_Rep_Item
(Def_Id
)) = Name_Interface
15050 Set_Imported
(Def_Id
);
15053 Set_Is_Public
(Def_Id
);
15054 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
15057 -- Otherwise must be subprogram
15059 elsif not Is_Subprogram
(Def_Id
) then
15061 ("argument of pragma% is not subprogram", Arg1
);
15064 Check_At_Most_N_Arguments
(3);
15068 -- Loop through homonyms
15071 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
15073 if Is_Imported
(Def_Id
) then
15074 Process_Interface_Name
(Def_Id
, Arg2
, Arg3
);
15078 exit when From_Aspect_Specification
(N
);
15079 Hom_Id
:= Homonym
(Hom_Id
);
15081 exit when No
(Hom_Id
)
15082 or else Scope
(Hom_Id
) /= Current_Scope
;
15087 ("argument of pragma% is not imported subprogram",
15091 end Interface_Name
;
15093 -----------------------
15094 -- Interrupt_Handler --
15095 -----------------------
15097 -- pragma Interrupt_Handler (handler_NAME);
15099 when Pragma_Interrupt_Handler
=>
15100 Check_Ada_83_Warning
;
15101 Check_Arg_Count
(1);
15102 Check_No_Identifiers
;
15104 if No_Run_Time_Mode
then
15105 Error_Msg_CRT
("Interrupt_Handler pragma", N
);
15107 Check_Interrupt_Or_Attach_Handler
;
15108 Process_Interrupt_Or_Attach_Handler
;
15111 ------------------------
15112 -- Interrupt_Priority --
15113 ------------------------
15115 -- pragma Interrupt_Priority [(EXPRESSION)];
15117 when Pragma_Interrupt_Priority
=> Interrupt_Priority
: declare
15118 P
: constant Node_Id
:= Parent
(N
);
15123 Check_Ada_83_Warning
;
15125 if Arg_Count
/= 0 then
15126 Arg
:= Get_Pragma_Arg
(Arg1
);
15127 Check_Arg_Count
(1);
15128 Check_No_Identifiers
;
15130 -- The expression must be analyzed in the special manner
15131 -- described in "Handling of Default and Per-Object
15132 -- Expressions" in sem.ads.
15134 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Interrupt_Priority
));
15137 if not Nkind_In
(P
, N_Task_Definition
, N_Protected_Definition
) then
15142 Ent
:= Defining_Identifier
(Parent
(P
));
15144 -- Check duplicate pragma before we chain the pragma in the Rep
15145 -- Item chain of Ent.
15147 Check_Duplicate_Pragma
(Ent
);
15148 Record_Rep_Item
(Ent
, N
);
15150 end Interrupt_Priority
;
15152 ---------------------
15153 -- Interrupt_State --
15154 ---------------------
15156 -- pragma Interrupt_State (
15157 -- [Name =>] INTERRUPT_ID,
15158 -- [State =>] INTERRUPT_STATE);
15160 -- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION
15161 -- INTERRUPT_STATE => System | Runtime | User
15163 -- Note: if the interrupt id is given as an identifier, then it must
15164 -- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is
15165 -- given as a static integer expression which must be in the range of
15166 -- Ada.Interrupts.Interrupt_ID.
15168 when Pragma_Interrupt_State
=> Interrupt_State
: declare
15169 Int_Id
: constant Entity_Id
:= RTE
(RE_Interrupt_ID
);
15170 -- This is the entity Ada.Interrupts.Interrupt_ID;
15172 State_Type
: Character;
15173 -- Set to 's'/'r'/'u' for System/Runtime/User
15176 -- Index to entry in Interrupt_States table
15179 -- Value of interrupt
15181 Arg1X
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
15182 -- The first argument to the pragma
15184 Int_Ent
: Entity_Id
;
15185 -- Interrupt entity in Ada.Interrupts.Names
15189 Check_Arg_Order
((Name_Name
, Name_State
));
15190 Check_Arg_Count
(2);
15192 Check_Optional_Identifier
(Arg1
, Name_Name
);
15193 Check_Optional_Identifier
(Arg2
, Name_State
);
15194 Check_Arg_Is_Identifier
(Arg2
);
15196 -- First argument is identifier
15198 if Nkind
(Arg1X
) = N_Identifier
then
15200 -- Search list of names in Ada.Interrupts.Names
15202 Int_Ent
:= First_Entity
(RTE
(RE_Names
));
15204 if No
(Int_Ent
) then
15205 Error_Pragma_Arg
("invalid interrupt name", Arg1
);
15207 elsif Chars
(Int_Ent
) = Chars
(Arg1X
) then
15208 Int_Val
:= Expr_Value
(Constant_Value
(Int_Ent
));
15212 Next_Entity
(Int_Ent
);
15215 -- First argument is not an identifier, so it must be a static
15216 -- expression of type Ada.Interrupts.Interrupt_ID.
15219 Check_Arg_Is_OK_Static_Expression
(Arg1
, Any_Integer
);
15220 Int_Val
:= Expr_Value
(Arg1X
);
15222 if Int_Val
< Expr_Value
(Type_Low_Bound
(Int_Id
))
15224 Int_Val
> Expr_Value
(Type_High_Bound
(Int_Id
))
15227 ("value not in range of type "
15228 & """Ada.Interrupts.Interrupt_'I'D""", Arg1
);
15234 case Chars
(Get_Pragma_Arg
(Arg2
)) is
15235 when Name_Runtime
=> State_Type
:= 'r';
15236 when Name_System
=> State_Type
:= 's';
15237 when Name_User
=> State_Type
:= 'u';
15240 Error_Pragma_Arg
("invalid interrupt state", Arg2
);
15243 -- Check if entry is already stored
15245 IST_Num
:= Interrupt_States
.First
;
15247 -- If entry not found, add it
15249 if IST_Num
> Interrupt_States
.Last
then
15250 Interrupt_States
.Append
15251 ((Interrupt_Number
=> UI_To_Int
(Int_Val
),
15252 Interrupt_State
=> State_Type
,
15253 Pragma_Loc
=> Loc
));
15256 -- Case of entry for the same entry
15258 elsif Int_Val
= Interrupt_States
.Table
(IST_Num
).
15261 -- If state matches, done, no need to make redundant entry
15264 State_Type
= Interrupt_States
.Table
(IST_Num
).
15267 -- Otherwise if state does not match, error
15270 Interrupt_States
.Table
(IST_Num
).Pragma_Loc
;
15272 ("state conflicts with that given #", Arg2
);
15276 IST_Num
:= IST_Num
+ 1;
15278 end Interrupt_State
;
15284 -- pragma Invariant
15285 -- ([Entity =>] type_LOCAL_NAME,
15286 -- [Check =>] EXPRESSION
15287 -- [,[Message =>] String_Expression]);
15289 when Pragma_Invariant
=> Invariant
: declare
15296 Check_At_Least_N_Arguments
(2);
15297 Check_At_Most_N_Arguments
(3);
15298 Check_Optional_Identifier
(Arg1
, Name_Entity
);
15299 Check_Optional_Identifier
(Arg2
, Name_Check
);
15301 if Arg_Count
= 3 then
15302 Check_Optional_Identifier
(Arg3
, Name_Message
);
15303 Check_Arg_Is_OK_Static_Expression
(Arg3
, Standard_String
);
15306 Check_Arg_Is_Local_Name
(Arg1
);
15308 Type_Id
:= Get_Pragma_Arg
(Arg1
);
15309 Find_Type
(Type_Id
);
15310 Typ
:= Entity
(Type_Id
);
15312 if Typ
= Any_Type
then
15315 -- Invariants allowed in interface types (RM 7.3.2(3/3))
15317 elsif Is_Interface
(Typ
) then
15320 -- An invariant must apply to a private type, or appear in the
15321 -- private part of a package spec and apply to a completion.
15322 -- a class-wide invariant can only appear on a private declaration
15323 -- or private extension, not a completion.
15325 elsif Ekind_In
(Typ
, E_Private_Type
,
15326 E_Record_Type_With_Private
,
15327 E_Limited_Private_Type
)
15331 elsif In_Private_Part
(Current_Scope
)
15332 and then Has_Private_Declaration
(Typ
)
15333 and then not Class_Present
(N
)
15337 elsif In_Private_Part
(Current_Scope
) then
15339 ("pragma% only allowed for private type declared in "
15340 & "visible part", Arg1
);
15344 ("pragma% only allowed for private type", Arg1
);
15347 -- Not allowed for abstract type in the non-class case (it is
15348 -- allowed to use Invariant'Class for abstract types).
15350 if Is_Abstract_Type
(Typ
) and then not Class_Present
(N
) then
15352 ("pragma% not allowed for abstract type", Arg1
);
15355 -- Note that the type has at least one invariant, and also that
15356 -- it has inheritable invariants if we have Invariant'Class
15357 -- or Type_Invariant'Class. Build the corresponding invariant
15358 -- procedure declaration, so that calls to it can be generated
15359 -- before the body is built (e.g. within an expression function).
15361 -- Interface types have no invariant procedure; their invariants
15362 -- are propagated to the build invariant procedure of all the
15363 -- types covering the interface type.
15365 if not Is_Interface
(Typ
) then
15366 Insert_After_And_Analyze
15367 (N
, Build_Invariant_Procedure_Declaration
(Typ
));
15370 if Class_Present
(N
) then
15371 Set_Has_Inheritable_Invariants
(Typ
);
15374 -- The remaining processing is simply to link the pragma on to
15375 -- the rep item chain, for processing when the type is frozen.
15376 -- This is accomplished by a call to Rep_Item_Too_Late.
15378 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
15381 ----------------------
15382 -- Java_Constructor --
15383 ----------------------
15385 -- pragma Java_Constructor ([Entity =>] LOCAL_NAME);
15387 -- Also handles pragma CIL_Constructor
15389 when Pragma_CIL_Constructor | Pragma_Java_Constructor
=>
15390 Java_Constructor
: declare
15391 Convention
: Convention_Id
;
15392 Def_Id
: Entity_Id
;
15393 Hom_Id
: Entity_Id
;
15395 This_Formal
: Entity_Id
;
15399 Check_Arg_Count
(1);
15400 Check_Optional_Identifier
(Arg1
, Name_Entity
);
15401 Check_Arg_Is_Local_Name
(Arg1
);
15403 Id
:= Get_Pragma_Arg
(Arg1
);
15404 Find_Program_Unit_Name
(Id
);
15406 -- If we did not find the name, we are done
15408 if Etype
(Id
) = Any_Type
then
15412 -- Check wrong use of pragma in wrong VM target
15414 if VM_Target
= No_VM
then
15417 elsif VM_Target
= CLI_Target
15418 and then Prag_Id
= Pragma_Java_Constructor
15420 Error_Pragma
("must use pragma 'C'I'L_'Constructor");
15422 elsif VM_Target
= JVM_Target
15423 and then Prag_Id
= Pragma_CIL_Constructor
15425 Error_Pragma
("must use pragma 'Java_'Constructor");
15429 when Pragma_CIL_Constructor
=> Convention
:= Convention_CIL
;
15430 when Pragma_Java_Constructor
=> Convention
:= Convention_Java
;
15431 when others => null;
15434 Hom_Id
:= Entity
(Id
);
15436 -- Loop through homonyms
15439 Def_Id
:= Get_Base_Subprogram
(Hom_Id
);
15441 -- The constructor is required to be a function
15443 if Ekind
(Def_Id
) /= E_Function
then
15444 if VM_Target
= JVM_Target
then
15446 ("pragma% requires function returning a 'Java access "
15450 ("pragma% requires function returning a 'C'I'L access "
15455 -- Check arguments: For tagged type the first formal must be
15456 -- named "this" and its type must be a named access type
15457 -- designating a class-wide tagged type that has convention
15458 -- CIL/Java. The first formal must also have a null default
15459 -- value. For example:
15461 -- type Typ is tagged ...
15462 -- type Ref is access all Typ;
15463 -- pragma Convention (CIL, Typ);
15465 -- function New_Typ (This : Ref) return Ref;
15466 -- function New_Typ (This : Ref; I : Integer) return Ref;
15467 -- pragma Cil_Constructor (New_Typ);
15469 -- Reason: The first formal must NOT be a primitive of the
15472 -- This rule also applies to constructors of delegates used
15473 -- to interface with standard target libraries. For example:
15475 -- type Delegate is access procedure ...
15476 -- pragma Import (CIL, Delegate, ...);
15478 -- function new_Delegate
15479 -- (This : Delegate := null; ... ) return Delegate;
15481 -- For value-types this rule does not apply.
15483 if not Is_Value_Type
(Etype
(Def_Id
)) then
15484 if No
(First_Formal
(Def_Id
)) then
15485 Error_Msg_Name_1
:= Pname
;
15486 Error_Msg_N
("% function must have parameters", Def_Id
);
15490 -- In the JRE library we have several occurrences in which
15491 -- the "this" parameter is not the first formal.
15493 This_Formal
:= First_Formal
(Def_Id
);
15495 -- In the JRE library we have several occurrences in which
15496 -- the "this" parameter is not the first formal. Search for
15499 if VM_Target
= JVM_Target
then
15500 while Present
(This_Formal
)
15501 and then Get_Name_String
(Chars
(This_Formal
)) /= "this"
15503 Next_Formal
(This_Formal
);
15506 if No
(This_Formal
) then
15507 This_Formal
:= First_Formal
(Def_Id
);
15511 -- Warning: The first parameter should be named "this".
15512 -- We temporarily allow it because we have the following
15513 -- case in the Java runtime (file s-osinte.ads) ???
15515 -- function new_Thread
15516 -- (Self_Id : System.Address) return Thread_Id;
15517 -- pragma Java_Constructor (new_Thread);
15519 if VM_Target
= JVM_Target
15520 and then Get_Name_String
(Chars
(First_Formal
(Def_Id
)))
15522 and then Etype
(First_Formal
(Def_Id
)) = RTE
(RE_Address
)
15526 elsif Get_Name_String
(Chars
(This_Formal
)) /= "this" then
15527 Error_Msg_Name_1
:= Pname
;
15529 ("first formal of % function must be named `this`",
15530 Parent
(This_Formal
));
15532 elsif not Is_Access_Type
(Etype
(This_Formal
)) then
15533 Error_Msg_Name_1
:= Pname
;
15535 ("first formal of % function must be an access type",
15536 Parameter_Type
(Parent
(This_Formal
)));
15538 -- For delegates the type of the first formal must be a
15539 -- named access-to-subprogram type (see previous example)
15541 elsif Ekind
(Etype
(Def_Id
)) = E_Access_Subprogram_Type
15542 and then Ekind
(Etype
(This_Formal
))
15543 /= E_Access_Subprogram_Type
15545 Error_Msg_Name_1
:= Pname
;
15547 ("first formal of % function must be a named access "
15548 & "to subprogram type",
15549 Parameter_Type
(Parent
(This_Formal
)));
15551 -- Warning: We should reject anonymous access types because
15552 -- the constructor must not be handled as a primitive of the
15553 -- tagged type. We temporarily allow it because this profile
15554 -- is currently generated by cil2ada???
15556 elsif Ekind
(Etype
(Def_Id
)) /= E_Access_Subprogram_Type
15557 and then not Ekind_In
(Etype
(This_Formal
),
15559 E_General_Access_Type
,
15560 E_Anonymous_Access_Type
)
15562 Error_Msg_Name_1
:= Pname
;
15564 ("first formal of % function must be a named access "
15565 & "type", Parameter_Type
(Parent
(This_Formal
)));
15567 elsif Atree
.Convention
15568 (Designated_Type
(Etype
(This_Formal
))) /= Convention
15570 Error_Msg_Name_1
:= Pname
;
15572 if Convention
= Convention_Java
then
15574 ("pragma% requires convention 'Cil in designated "
15575 & "type", Parameter_Type
(Parent
(This_Formal
)));
15578 ("pragma% requires convention 'Java in designated "
15579 & "type", Parameter_Type
(Parent
(This_Formal
)));
15582 elsif No
(Expression
(Parent
(This_Formal
)))
15583 or else Nkind
(Expression
(Parent
(This_Formal
))) /= N_Null
15585 Error_Msg_Name_1
:= Pname
;
15587 ("pragma% requires first formal with default `null`",
15588 Parameter_Type
(Parent
(This_Formal
)));
15592 -- Check result type: the constructor must be a function
15594 -- * a value type (only allowed in the CIL compiler)
15595 -- * an access-to-subprogram type with convention Java/CIL
15596 -- * an access-type designating a type that has convention
15599 if Is_Value_Type
(Etype
(Def_Id
)) then
15602 -- Access-to-subprogram type with convention Java/CIL
15604 elsif Ekind
(Etype
(Def_Id
)) = E_Access_Subprogram_Type
then
15605 if Atree
.Convention
(Etype
(Def_Id
)) /= Convention
then
15606 if Convention
= Convention_Java
then
15608 ("pragma% requires function returning a 'Java "
15609 & "access type", Arg1
);
15611 pragma Assert
(Convention
= Convention_CIL
);
15613 ("pragma% requires function returning a 'C'I'L "
15614 & "access type", Arg1
);
15618 elsif Is_Access_Type
(Etype
(Def_Id
)) then
15619 if not Ekind_In
(Etype
(Def_Id
), E_Access_Type
,
15620 E_General_Access_Type
)
15623 (Designated_Type
(Etype
(Def_Id
))) /= Convention
15625 Error_Msg_Name_1
:= Pname
;
15627 if Convention
= Convention_Java
then
15629 ("pragma% requires function returning a named "
15630 & "'Java access type", Arg1
);
15633 ("pragma% requires function returning a named "
15634 & "'C'I'L access type", Arg1
);
15639 Set_Is_Constructor
(Def_Id
);
15640 Set_Convention
(Def_Id
, Convention
);
15641 Set_Is_Imported
(Def_Id
);
15643 exit when From_Aspect_Specification
(N
);
15644 Hom_Id
:= Homonym
(Hom_Id
);
15646 exit when No
(Hom_Id
) or else Scope
(Hom_Id
) /= Current_Scope
;
15648 end Java_Constructor
;
15650 ----------------------
15651 -- Java_Interface --
15652 ----------------------
15654 -- pragma Java_Interface ([Entity =>] LOCAL_NAME);
15656 when Pragma_Java_Interface
=> Java_Interface
: declare
15662 Check_Arg_Count
(1);
15663 Check_Optional_Identifier
(Arg1
, Name_Entity
);
15664 Check_Arg_Is_Local_Name
(Arg1
);
15666 Arg
:= Get_Pragma_Arg
(Arg1
);
15669 if Etype
(Arg
) = Any_Type
then
15673 if not Is_Entity_Name
(Arg
)
15674 or else not Is_Type
(Entity
(Arg
))
15676 Error_Pragma_Arg
("pragma% requires a type mark", Arg1
);
15679 Typ
:= Underlying_Type
(Entity
(Arg
));
15681 -- For now simply check some of the semantic constraints on the
15682 -- type. This currently leaves out some restrictions on interface
15683 -- types, namely that the parent type must be java.lang.Object.Typ
15684 -- and that all primitives of the type should be declared
15687 if not Is_Tagged_Type
(Typ
) or else not Is_Abstract_Type
(Typ
) then
15689 ("pragma% requires an abstract tagged type", Arg1
);
15691 elsif not Has_Discriminants
(Typ
)
15692 or else Ekind
(Etype
(First_Discriminant
(Typ
)))
15693 /= E_Anonymous_Access_Type
15695 not Is_Class_Wide_Type
15696 (Designated_Type
(Etype
(First_Discriminant
(Typ
))))
15699 ("type must have a class-wide access discriminant", Arg1
);
15701 end Java_Interface
;
15707 -- pragma Keep_Names ([On => ] LOCAL_NAME);
15709 when Pragma_Keep_Names
=> Keep_Names
: declare
15714 Check_Arg_Count
(1);
15715 Check_Optional_Identifier
(Arg1
, Name_On
);
15716 Check_Arg_Is_Local_Name
(Arg1
);
15718 Arg
:= Get_Pragma_Arg
(Arg1
);
15721 if Etype
(Arg
) = Any_Type
then
15725 if not Is_Entity_Name
(Arg
)
15726 or else Ekind
(Entity
(Arg
)) /= E_Enumeration_Type
15729 ("pragma% requires a local enumeration type", Arg1
);
15732 Set_Discard_Names
(Entity
(Arg
), False);
15739 -- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL);
15741 when Pragma_License
=>
15744 -- Do not analyze pragma any further in CodePeer mode, to avoid
15745 -- extraneous errors in this implementation-dependent pragma,
15746 -- which has a different profile on other compilers.
15748 if CodePeer_Mode
then
15752 Check_Arg_Count
(1);
15753 Check_No_Identifiers
;
15754 Check_Valid_Configuration_Pragma
;
15755 Check_Arg_Is_Identifier
(Arg1
);
15758 Sind
: constant Source_File_Index
:=
15759 Source_Index
(Current_Sem_Unit
);
15762 case Chars
(Get_Pragma_Arg
(Arg1
)) is
15764 Set_License
(Sind
, GPL
);
15766 when Name_Modified_GPL
=>
15767 Set_License
(Sind
, Modified_GPL
);
15769 when Name_Restricted
=>
15770 Set_License
(Sind
, Restricted
);
15772 when Name_Unrestricted
=>
15773 Set_License
(Sind
, Unrestricted
);
15776 Error_Pragma_Arg
("invalid license name", Arg1
);
15784 -- pragma Link_With (string_EXPRESSION {, string_EXPRESSION});
15786 when Pragma_Link_With
=> Link_With
: declare
15792 if Operating_Mode
= Generate_Code
15793 and then In_Extended_Main_Source_Unit
(N
)
15795 Check_At_Least_N_Arguments
(1);
15796 Check_No_Identifiers
;
15797 Check_Is_In_Decl_Part_Or_Package_Spec
;
15798 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
15802 while Present
(Arg
) loop
15803 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
15805 -- Store argument, converting sequences of spaces to a
15806 -- single null character (this is one of the differences
15807 -- in processing between Link_With and Linker_Options).
15809 Arg_Store
: declare
15810 C
: constant Char_Code
:= Get_Char_Code
(' ');
15811 S
: constant String_Id
:=
15812 Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
)));
15813 L
: constant Nat
:= String_Length
(S
);
15816 procedure Skip_Spaces
;
15817 -- Advance F past any spaces
15823 procedure Skip_Spaces
is
15825 while F
<= L
and then Get_String_Char
(S
, F
) = C
loop
15830 -- Start of processing for Arg_Store
15833 Skip_Spaces
; -- skip leading spaces
15835 -- Loop through characters, changing any embedded
15836 -- sequence of spaces to a single null character (this
15837 -- is how Link_With/Linker_Options differ)
15840 if Get_String_Char
(S
, F
) = C
then
15843 Store_String_Char
(ASCII
.NUL
);
15846 Store_String_Char
(Get_String_Char
(S
, F
));
15854 if Present
(Arg
) then
15855 Store_String_Char
(ASCII
.NUL
);
15859 Store_Linker_Option_String
(End_String
);
15867 -- pragma Linker_Alias (
15868 -- [Entity =>] LOCAL_NAME
15869 -- [Target =>] static_string_EXPRESSION);
15871 when Pragma_Linker_Alias
=>
15873 Check_Arg_Order
((Name_Entity
, Name_Target
));
15874 Check_Arg_Count
(2);
15875 Check_Optional_Identifier
(Arg1
, Name_Entity
);
15876 Check_Optional_Identifier
(Arg2
, Name_Target
);
15877 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
15878 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
15880 -- The only processing required is to link this item on to the
15881 -- list of rep items for the given entity. This is accomplished
15882 -- by the call to Rep_Item_Too_Late (when no error is detected
15883 -- and False is returned).
15885 if Rep_Item_Too_Late
(Entity
(Get_Pragma_Arg
(Arg1
)), N
) then
15888 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
15891 ------------------------
15892 -- Linker_Constructor --
15893 ------------------------
15895 -- pragma Linker_Constructor (procedure_LOCAL_NAME);
15897 -- Code is shared with Linker_Destructor
15899 -----------------------
15900 -- Linker_Destructor --
15901 -----------------------
15903 -- pragma Linker_Destructor (procedure_LOCAL_NAME);
15905 when Pragma_Linker_Constructor |
15906 Pragma_Linker_Destructor
=>
15907 Linker_Constructor
: declare
15913 Check_Arg_Count
(1);
15914 Check_No_Identifiers
;
15915 Check_Arg_Is_Local_Name
(Arg1
);
15916 Arg1_X
:= Get_Pragma_Arg
(Arg1
);
15918 Proc
:= Find_Unique_Parameterless_Procedure
(Arg1_X
, Arg1
);
15920 if not Is_Library_Level_Entity
(Proc
) then
15922 ("argument for pragma% must be library level entity", Arg1
);
15925 -- The only processing required is to link this item on to the
15926 -- list of rep items for the given entity. This is accomplished
15927 -- by the call to Rep_Item_Too_Late (when no error is detected
15928 -- and False is returned).
15930 if Rep_Item_Too_Late
(Proc
, N
) then
15933 Set_Has_Gigi_Rep_Item
(Proc
);
15935 end Linker_Constructor
;
15937 --------------------
15938 -- Linker_Options --
15939 --------------------
15941 -- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION});
15943 when Pragma_Linker_Options
=> Linker_Options
: declare
15947 Check_Ada_83_Warning
;
15948 Check_No_Identifiers
;
15949 Check_Arg_Count
(1);
15950 Check_Is_In_Decl_Part_Or_Package_Spec
;
15951 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
15952 Start_String
(Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg1
))));
15955 while Present
(Arg
) loop
15956 Check_Arg_Is_OK_Static_Expression
(Arg
, Standard_String
);
15957 Store_String_Char
(ASCII
.NUL
);
15959 (Strval
(Expr_Value_S
(Get_Pragma_Arg
(Arg
))));
15963 if Operating_Mode
= Generate_Code
15964 and then In_Extended_Main_Source_Unit
(N
)
15966 Store_Linker_Option_String
(End_String
);
15968 end Linker_Options
;
15970 --------------------
15971 -- Linker_Section --
15972 --------------------
15974 -- pragma Linker_Section (
15975 -- [Entity =>] LOCAL_NAME
15976 -- [Section =>] static_string_EXPRESSION);
15978 when Pragma_Linker_Section
=> Linker_Section
: declare
15985 Check_Arg_Order
((Name_Entity
, Name_Section
));
15986 Check_Arg_Count
(2);
15987 Check_Optional_Identifier
(Arg1
, Name_Entity
);
15988 Check_Optional_Identifier
(Arg2
, Name_Section
);
15989 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
15990 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
15992 -- Check kind of entity
15994 Arg
:= Get_Pragma_Arg
(Arg1
);
15995 Ent
:= Entity
(Arg
);
15997 case Ekind
(Ent
) is
15999 -- Objects (constants and variables) and types. For these cases
16000 -- all we need to do is to set the Linker_Section_pragma field,
16001 -- checking that we do not have a duplicate.
16003 when E_Constant | E_Variable | Type_Kind
=>
16004 LPE
:= Linker_Section_Pragma
(Ent
);
16006 if Present
(LPE
) then
16007 Error_Msg_Sloc
:= Sloc
(LPE
);
16009 ("Linker_Section already specified for &#", Arg1
, Ent
);
16012 Set_Linker_Section_Pragma
(Ent
, N
);
16016 when Subprogram_Kind
=>
16018 -- Aspect case, entity already set
16020 if From_Aspect_Specification
(N
) then
16021 Set_Linker_Section_Pragma
16022 (Entity
(Corresponding_Aspect
(N
)), N
);
16024 -- Pragma case, we must climb the homonym chain, but skip
16025 -- any for which the linker section is already set.
16029 if No
(Linker_Section_Pragma
(Ent
)) then
16030 Set_Linker_Section_Pragma
(Ent
, N
);
16033 Ent
:= Homonym
(Ent
);
16035 or else Scope
(Ent
) /= Current_Scope
;
16039 -- All other cases are illegal
16043 ("pragma% applies only to objects, subprograms, and types",
16046 end Linker_Section
;
16052 -- pragma List (On | Off)
16054 -- There is nothing to do here, since we did all the processing for
16055 -- this pragma in Par.Prag (so that it works properly even in syntax
16058 when Pragma_List
=>
16065 -- pragma Lock_Free [(Boolean_EXPRESSION)];
16067 when Pragma_Lock_Free
=> Lock_Free
: declare
16068 P
: constant Node_Id
:= Parent
(N
);
16074 Check_No_Identifiers
;
16075 Check_At_Most_N_Arguments
(1);
16077 -- Protected definition case
16079 if Nkind
(P
) = N_Protected_Definition
then
16080 Ent
:= Defining_Identifier
(Parent
(P
));
16084 if Arg_Count
= 1 then
16085 Arg
:= Get_Pragma_Arg
(Arg1
);
16086 Val
:= Is_True
(Static_Boolean
(Arg
));
16088 -- No arguments (expression is considered to be True)
16094 -- Check duplicate pragma before we chain the pragma in the Rep
16095 -- Item chain of Ent.
16097 Check_Duplicate_Pragma
(Ent
);
16098 Record_Rep_Item
(Ent
, N
);
16099 Set_Uses_Lock_Free
(Ent
, Val
);
16101 -- Anything else is incorrect placement
16108 --------------------
16109 -- Locking_Policy --
16110 --------------------
16112 -- pragma Locking_Policy (policy_IDENTIFIER);
16114 when Pragma_Locking_Policy
=> declare
16115 subtype LP_Range
is Name_Id
16116 range First_Locking_Policy_Name
.. Last_Locking_Policy_Name
;
16121 Check_Ada_83_Warning
;
16122 Check_Arg_Count
(1);
16123 Check_No_Identifiers
;
16124 Check_Arg_Is_Locking_Policy
(Arg1
);
16125 Check_Valid_Configuration_Pragma
;
16126 LP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
16129 when Name_Ceiling_Locking
=>
16131 when Name_Inheritance_Locking
=>
16133 when Name_Concurrent_Readers_Locking
=>
16137 if Locking_Policy
/= ' '
16138 and then Locking_Policy
/= LP
16140 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
16141 Error_Pragma
("locking policy incompatible with policy#");
16143 -- Set new policy, but always preserve System_Location since we
16144 -- like the error message with the run time name.
16147 Locking_Policy
:= LP
;
16149 if Locking_Policy_Sloc
/= System_Location
then
16150 Locking_Policy_Sloc
:= Loc
;
16155 -------------------
16156 -- Loop_Optimize --
16157 -------------------
16159 -- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } );
16161 -- OPTIMIZATION_HINT ::=
16162 -- Ivdep | No_Unroll | Unroll | No_Vector | Vector
16164 when Pragma_Loop_Optimize
=> Loop_Optimize
: declare
16169 Check_At_Least_N_Arguments
(1);
16170 Check_No_Identifiers
;
16172 Hint
:= First
(Pragma_Argument_Associations
(N
));
16173 while Present
(Hint
) loop
16174 Check_Arg_Is_One_Of
(Hint
, Name_Ivdep
,
16182 Check_Loop_Pragma_Placement
;
16189 -- pragma Loop_Variant
16190 -- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } );
16192 -- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION
16194 -- CHANGE_DIRECTION ::= Increases | Decreases
16196 when Pragma_Loop_Variant
=> Loop_Variant
: declare
16201 Check_At_Least_N_Arguments
(1);
16202 Check_Loop_Pragma_Placement
;
16204 -- Process all increasing / decreasing expressions
16206 Variant
:= First
(Pragma_Argument_Associations
(N
));
16207 while Present
(Variant
) loop
16208 if not Nam_In
(Chars
(Variant
), Name_Decreases
,
16211 Error_Pragma_Arg
("wrong change modifier", Variant
);
16214 Preanalyze_Assert_Expression
16215 (Expression
(Variant
), Any_Discrete
);
16221 -----------------------
16222 -- Machine_Attribute --
16223 -----------------------
16225 -- pragma Machine_Attribute (
16226 -- [Entity =>] LOCAL_NAME,
16227 -- [Attribute_Name =>] static_string_EXPRESSION
16228 -- [, [Info =>] static_EXPRESSION] );
16230 when Pragma_Machine_Attribute
=> Machine_Attribute
: declare
16231 Def_Id
: Entity_Id
;
16235 Check_Arg_Order
((Name_Entity
, Name_Attribute_Name
, Name_Info
));
16237 if Arg_Count
= 3 then
16238 Check_Optional_Identifier
(Arg3
, Name_Info
);
16239 Check_Arg_Is_OK_Static_Expression
(Arg3
);
16241 Check_Arg_Count
(2);
16244 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16245 Check_Optional_Identifier
(Arg2
, Name_Attribute_Name
);
16246 Check_Arg_Is_Local_Name
(Arg1
);
16247 Check_Arg_Is_OK_Static_Expression
(Arg2
, Standard_String
);
16248 Def_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
16250 if Is_Access_Type
(Def_Id
) then
16251 Def_Id
:= Designated_Type
(Def_Id
);
16254 if Rep_Item_Too_Early
(Def_Id
, N
) then
16258 Def_Id
:= Underlying_Type
(Def_Id
);
16260 -- The only processing required is to link this item on to the
16261 -- list of rep items for the given entity. This is accomplished
16262 -- by the call to Rep_Item_Too_Late (when no error is detected
16263 -- and False is returned).
16265 if Rep_Item_Too_Late
(Def_Id
, N
) then
16268 Set_Has_Gigi_Rep_Item
(Entity
(Get_Pragma_Arg
(Arg1
)));
16270 end Machine_Attribute
;
16277 -- (MAIN_OPTION [, MAIN_OPTION]);
16280 -- [STACK_SIZE =>] static_integer_EXPRESSION
16281 -- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION
16282 -- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION
16284 when Pragma_Main
=> Main
: declare
16285 Args
: Args_List
(1 .. 3);
16286 Names
: constant Name_List
(1 .. 3) := (
16288 Name_Task_Stack_Size_Default
,
16289 Name_Time_Slicing_Enabled
);
16295 Gather_Associations
(Names
, Args
);
16297 for J
in 1 .. 2 loop
16298 if Present
(Args
(J
)) then
16299 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
16303 if Present
(Args
(3)) then
16304 Check_Arg_Is_OK_Static_Expression
(Args
(3), Standard_Boolean
);
16308 while Present
(Nod
) loop
16309 if Nkind
(Nod
) = N_Pragma
16310 and then Pragma_Name
(Nod
) = Name_Main
16312 Error_Msg_Name_1
:= Pname
;
16313 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
16324 -- pragma Main_Storage
16325 -- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]);
16327 -- MAIN_STORAGE_OPTION ::=
16328 -- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION
16329 -- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION
16331 when Pragma_Main_Storage
=> Main_Storage
: declare
16332 Args
: Args_List
(1 .. 2);
16333 Names
: constant Name_List
(1 .. 2) := (
16334 Name_Working_Storage
,
16341 Gather_Associations
(Names
, Args
);
16343 for J
in 1 .. 2 loop
16344 if Present
(Args
(J
)) then
16345 Check_Arg_Is_OK_Static_Expression
(Args
(J
), Any_Integer
);
16349 Check_In_Main_Program
;
16352 while Present
(Nod
) loop
16353 if Nkind
(Nod
) = N_Pragma
16354 and then Pragma_Name
(Nod
) = Name_Main_Storage
16356 Error_Msg_Name_1
:= Pname
;
16357 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
16368 -- pragma Memory_Size (NUMERIC_LITERAL)
16370 when Pragma_Memory_Size
=>
16373 -- Memory size is simply ignored
16375 Check_No_Identifiers
;
16376 Check_Arg_Count
(1);
16377 Check_Arg_Is_Integer_Literal
(Arg1
);
16385 -- The only correct use of this pragma is on its own in a file, in
16386 -- which case it is specially processed (see Gnat1drv.Check_Bad_Body
16387 -- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to
16388 -- check for a file containing nothing but a No_Body pragma). If we
16389 -- attempt to process it during normal semantics processing, it means
16390 -- it was misplaced.
16392 when Pragma_No_Body
=>
16396 -----------------------------
16397 -- No_Elaboration_Code_All --
16398 -----------------------------
16400 -- pragma No_Elaboration_Code_All;
16402 when Pragma_No_Elaboration_Code_All
=> NECA
: declare
16405 Check_Valid_Library_Unit_Pragma
;
16407 if Nkind
(N
) = N_Null_Statement
then
16411 -- Must appear for a spec or generic spec
16413 if not Nkind_In
(Unit
(Cunit
(Current_Sem_Unit
)),
16414 N_Generic_Package_Declaration
,
16415 N_Generic_Subprogram_Declaration
,
16416 N_Package_Declaration
,
16417 N_Subprogram_Declaration
)
16421 ("pragma% can only occur for package "
16422 & "or subprogram spec"));
16425 -- Set flag in unit table
16427 Set_No_Elab_Code_All
(Current_Sem_Unit
);
16429 -- Set restriction No_Elaboration_Code if this is the main unit
16431 if Current_Sem_Unit
= Main_Unit
then
16432 Set_Restriction
(No_Elaboration_Code
, N
);
16435 -- If we are in the main unit or in an extended main source unit,
16436 -- then we also add it to the configuration restrictions so that
16437 -- it will apply to all units in the extended main source.
16439 if Current_Sem_Unit
= Main_Unit
16440 or else In_Extended_Main_Source_Unit
(N
)
16442 Add_To_Config_Boolean_Restrictions
(No_Elaboration_Code
);
16445 -- If in main extended unit, activate transitive with test
16447 if In_Extended_Main_Source_Unit
(N
) then
16448 Opt
.No_Elab_Code_All_Pragma
:= N
;
16456 -- pragma No_Inline ( NAME {, NAME} );
16458 when Pragma_No_Inline
=>
16460 Process_Inline
(Suppressed
);
16466 -- pragma No_Return (procedure_LOCAL_NAME {, procedure_Local_Name});
16468 when Pragma_No_Return
=> No_Return
: declare
16476 Check_At_Least_N_Arguments
(1);
16478 -- Loop through arguments of pragma
16481 while Present
(Arg
) loop
16482 Check_Arg_Is_Local_Name
(Arg
);
16483 Id
:= Get_Pragma_Arg
(Arg
);
16486 if not Is_Entity_Name
(Id
) then
16487 Error_Pragma_Arg
("entity name required", Arg
);
16490 if Etype
(Id
) = Any_Type
then
16494 -- Loop to find matching procedures
16499 and then Scope
(E
) = Current_Scope
16501 if Ekind_In
(E
, E_Procedure
, E_Generic_Procedure
) then
16504 -- Set flag on any alias as well
16506 if Is_Overloadable
(E
) and then Present
(Alias
(E
)) then
16507 Set_No_Return
(Alias
(E
));
16513 exit when From_Aspect_Specification
(N
);
16517 -- If entity in not in current scope it may be the enclosing
16518 -- suprogram body to which the aspect applies.
16521 if Entity
(Id
) = Current_Scope
16522 and then From_Aspect_Specification
(N
)
16524 Set_No_Return
(Entity
(Id
));
16526 Error_Pragma_Arg
("no procedure& found for pragma%", Arg
);
16538 -- pragma No_Run_Time;
16540 -- Note: this pragma is retained for backwards compatibility. See
16541 -- body of Rtsfind for full details on its handling.
16543 when Pragma_No_Run_Time
=>
16545 Check_Valid_Configuration_Pragma
;
16546 Check_Arg_Count
(0);
16548 No_Run_Time_Mode
:= True;
16549 Configurable_Run_Time_Mode
:= True;
16551 -- Set Duration to 32 bits if word size is 32
16553 if Ttypes
.System_Word_Size
= 32 then
16554 Duration_32_Bits_On_Target
:= True;
16557 -- Set appropriate restrictions
16559 Set_Restriction
(No_Finalization
, N
);
16560 Set_Restriction
(No_Exception_Handlers
, N
);
16561 Set_Restriction
(Max_Tasks
, N
, 0);
16562 Set_Restriction
(No_Tasking
, N
);
16564 -----------------------
16565 -- No_Tagged_Streams --
16566 -----------------------
16568 -- pragma No_Tagged_Streams;
16569 -- pragma No_Tagged_Streams ([Entity => ]tagged_type_local_NAME);
16571 when Pragma_No_Tagged_Streams
=> No_Tagged_Strms
: declare
16577 Check_At_Most_N_Arguments
(1);
16579 -- One argument case
16581 if Arg_Count
= 1 then
16582 Check_Optional_Identifier
(Arg1
, Name_Entity
);
16583 Check_Arg_Is_Local_Name
(Arg1
);
16584 E_Id
:= Get_Pragma_Arg
(Arg1
);
16586 if Etype
(E_Id
) = Any_Type
then
16590 E
:= Entity
(E_Id
);
16592 Check_Duplicate_Pragma
(E
);
16594 if not Is_Tagged_Type
(E
) or else Is_Derived_Type
(E
) then
16596 ("argument for pragma% must be root tagged type", Arg1
);
16599 if Rep_Item_Too_Early
(E
, N
)
16601 Rep_Item_Too_Late
(E
, N
)
16605 Set_No_Tagged_Streams_Pragma
(E
, N
);
16608 -- Zero argument case
16611 Check_Is_In_Decl_Part_Or_Package_Spec
;
16612 No_Tagged_Streams
:= N
;
16614 end No_Tagged_Strms
;
16616 ------------------------
16617 -- No_Strict_Aliasing --
16618 ------------------------
16620 -- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)];
16622 when Pragma_No_Strict_Aliasing
=> No_Strict_Aliasing
: declare
16627 Check_At_Most_N_Arguments
(1);
16629 if Arg_Count
= 0 then
16630 Check_Valid_Configuration_Pragma
;
16631 Opt
.No_Strict_Aliasing
:= True;
16634 Check_Optional_Identifier
(Arg2
, Name_Entity
);
16635 Check_Arg_Is_Local_Name
(Arg1
);
16636 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
16638 if E_Id
= Any_Type
then
16640 elsif No
(E_Id
) or else not Is_Access_Type
(E_Id
) then
16641 Error_Pragma_Arg
("pragma% requires access type", Arg1
);
16644 Set_No_Strict_Aliasing
(Implementation_Base_Type
(E_Id
));
16646 end No_Strict_Aliasing
;
16648 -----------------------
16649 -- Normalize_Scalars --
16650 -----------------------
16652 -- pragma Normalize_Scalars;
16654 when Pragma_Normalize_Scalars
=>
16655 Check_Ada_83_Warning
;
16656 Check_Arg_Count
(0);
16657 Check_Valid_Configuration_Pragma
;
16659 -- Normalize_Scalars creates false positives in CodePeer, and
16660 -- incorrect negative results in GNATprove mode, so ignore this
16661 -- pragma in these modes.
16663 if not (CodePeer_Mode
or GNATprove_Mode
) then
16664 Normalize_Scalars
:= True;
16665 Init_Or_Norm_Scalars
:= True;
16672 -- pragma Obsolescent;
16674 -- pragma Obsolescent (
16675 -- [Message =>] static_string_EXPRESSION
16676 -- [,[Version =>] Ada_05]]);
16678 -- pragma Obsolescent (
16679 -- [Entity =>] NAME
16680 -- [,[Message =>] static_string_EXPRESSION
16681 -- [,[Version =>] Ada_05]] );
16683 when Pragma_Obsolescent
=> Obsolescent
: declare
16687 procedure Set_Obsolescent
(E
: Entity_Id
);
16688 -- Given an entity Ent, mark it as obsolescent if appropriate
16690 ---------------------
16691 -- Set_Obsolescent --
16692 ---------------------
16694 procedure Set_Obsolescent
(E
: Entity_Id
) is
16703 -- Entity name was given
16705 if Present
(Ename
) then
16707 -- If entity name matches, we are fine. Save entity in
16708 -- pragma argument, for ASIS use.
16710 if Chars
(Ename
) = Chars
(Ent
) then
16711 Set_Entity
(Ename
, Ent
);
16712 Generate_Reference
(Ent
, Ename
);
16714 -- If entity name does not match, only possibility is an
16715 -- enumeration literal from an enumeration type declaration.
16717 elsif Ekind
(Ent
) /= E_Enumeration_Type
then
16719 ("pragma % entity name does not match declaration");
16722 Ent
:= First_Literal
(E
);
16726 ("pragma % entity name does not match any "
16727 & "enumeration literal");
16729 elsif Chars
(Ent
) = Chars
(Ename
) then
16730 Set_Entity
(Ename
, Ent
);
16731 Generate_Reference
(Ent
, Ename
);
16735 Ent
:= Next_Literal
(Ent
);
16741 -- Ent points to entity to be marked
16743 if Arg_Count
>= 1 then
16745 -- Deal with static string argument
16747 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
16748 S
:= Strval
(Get_Pragma_Arg
(Arg1
));
16750 for J
in 1 .. String_Length
(S
) loop
16751 if not In_Character_Range
(Get_String_Char
(S
, J
)) then
16753 ("pragma% argument does not allow wide characters",
16758 Obsolescent_Warnings
.Append
16759 ((Ent
=> Ent
, Msg
=> Strval
(Get_Pragma_Arg
(Arg1
))));
16761 -- Check for Ada_05 parameter
16763 if Arg_Count
/= 1 then
16764 Check_Arg_Count
(2);
16767 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg2
);
16770 Check_Arg_Is_Identifier
(Argx
);
16772 if Chars
(Argx
) /= Name_Ada_05
then
16773 Error_Msg_Name_2
:= Name_Ada_05
;
16775 ("only allowed argument for pragma% is %", Argx
);
16778 if Ada_Version_Explicit
< Ada_2005
16779 or else not Warn_On_Ada_2005_Compatibility
16787 -- Set flag if pragma active
16790 Set_Is_Obsolescent
(Ent
);
16794 end Set_Obsolescent
;
16796 -- Start of processing for pragma Obsolescent
16801 Check_At_Most_N_Arguments
(3);
16803 -- See if first argument specifies an entity name
16807 (Chars
(Arg1
) = Name_Entity
16809 Nkind_In
(Get_Pragma_Arg
(Arg1
), N_Character_Literal
,
16811 N_Operator_Symbol
))
16813 Ename
:= Get_Pragma_Arg
(Arg1
);
16815 -- Eliminate first argument, so we can share processing
16819 Arg_Count
:= Arg_Count
- 1;
16821 -- No Entity name argument given
16827 if Arg_Count
>= 1 then
16828 Check_Optional_Identifier
(Arg1
, Name_Message
);
16830 if Arg_Count
= 2 then
16831 Check_Optional_Identifier
(Arg2
, Name_Version
);
16835 -- Get immediately preceding declaration
16838 while Present
(Decl
) and then Nkind
(Decl
) = N_Pragma
loop
16842 -- Cases where we do not follow anything other than another pragma
16846 -- First case: library level compilation unit declaration with
16847 -- the pragma immediately following the declaration.
16849 if Nkind
(Parent
(N
)) = N_Compilation_Unit_Aux
then
16851 (Defining_Entity
(Unit
(Parent
(Parent
(N
)))));
16854 -- Case 2: library unit placement for package
16858 Ent
: constant Entity_Id
:= Find_Lib_Unit_Name
;
16860 if Is_Package_Or_Generic_Package
(Ent
) then
16861 Set_Obsolescent
(Ent
);
16867 -- Cases where we must follow a declaration, including an
16868 -- abstract subprogram declaration, which is not in the
16869 -- other node subtypes.
16872 if Nkind
(Decl
) not in N_Declaration
16873 and then Nkind
(Decl
) not in N_Later_Decl_Item
16874 and then Nkind
(Decl
) not in N_Generic_Declaration
16875 and then Nkind
(Decl
) not in N_Renaming_Declaration
16876 and then Nkind
(Decl
) /= N_Abstract_Subprogram_Declaration
16879 ("pragma% misplaced, "
16880 & "must immediately follow a declaration");
16883 Set_Obsolescent
(Defining_Entity
(Decl
));
16893 -- pragma Optimize (Time | Space | Off);
16895 -- The actual check for optimize is done in Gigi. Note that this
16896 -- pragma does not actually change the optimization setting, it
16897 -- simply checks that it is consistent with the pragma.
16899 when Pragma_Optimize
=>
16900 Check_No_Identifiers
;
16901 Check_Arg_Count
(1);
16902 Check_Arg_Is_One_Of
(Arg1
, Name_Time
, Name_Space
, Name_Off
);
16904 ------------------------
16905 -- Optimize_Alignment --
16906 ------------------------
16908 -- pragma Optimize_Alignment (Time | Space | Off);
16910 when Pragma_Optimize_Alignment
=> Optimize_Alignment
: begin
16912 Check_No_Identifiers
;
16913 Check_Arg_Count
(1);
16914 Check_Valid_Configuration_Pragma
;
16917 Nam
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(Arg1
));
16921 Opt
.Optimize_Alignment
:= 'T';
16923 Opt
.Optimize_Alignment
:= 'S';
16925 Opt
.Optimize_Alignment
:= 'O';
16927 Error_Pragma_Arg
("invalid argument for pragma%", Arg1
);
16931 -- Set indication that mode is set locally. If we are in fact in a
16932 -- configuration pragma file, this setting is harmless since the
16933 -- switch will get reset anyway at the start of each unit.
16935 Optimize_Alignment_Local
:= True;
16936 end Optimize_Alignment
;
16942 -- pragma Ordered (first_enumeration_subtype_LOCAL_NAME);
16944 when Pragma_Ordered
=> Ordered
: declare
16945 Assoc
: constant Node_Id
:= Arg1
;
16951 Check_No_Identifiers
;
16952 Check_Arg_Count
(1);
16953 Check_Arg_Is_Local_Name
(Arg1
);
16955 Type_Id
:= Get_Pragma_Arg
(Assoc
);
16956 Find_Type
(Type_Id
);
16957 Typ
:= Entity
(Type_Id
);
16959 if Typ
= Any_Type
then
16962 Typ
:= Underlying_Type
(Typ
);
16965 if not Is_Enumeration_Type
(Typ
) then
16966 Error_Pragma
("pragma% must specify enumeration type");
16969 Check_First_Subtype
(Arg1
);
16970 Set_Has_Pragma_Ordered
(Base_Type
(Typ
));
16973 -------------------
16974 -- Overflow_Mode --
16975 -------------------
16977 -- pragma Overflow_Mode
16978 -- ([General => ] MODE [, [Assertions => ] MODE]);
16980 -- MODE := STRICT | MINIMIZED | ELIMINATED
16982 -- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64
16983 -- since System.Bignums makes this assumption. This is true of nearly
16984 -- all (all?) targets.
16986 when Pragma_Overflow_Mode
=> Overflow_Mode
: declare
16987 function Get_Overflow_Mode
16989 Arg
: Node_Id
) return Overflow_Mode_Type
;
16990 -- Function to process one pragma argument, Arg. If an identifier
16991 -- is present, it must be Name. Mode type is returned if a valid
16992 -- argument exists, otherwise an error is signalled.
16994 -----------------------
16995 -- Get_Overflow_Mode --
16996 -----------------------
16998 function Get_Overflow_Mode
17000 Arg
: Node_Id
) return Overflow_Mode_Type
17002 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg
);
17005 Check_Optional_Identifier
(Arg
, Name
);
17006 Check_Arg_Is_Identifier
(Argx
);
17008 if Chars
(Argx
) = Name_Strict
then
17011 elsif Chars
(Argx
) = Name_Minimized
then
17014 elsif Chars
(Argx
) = Name_Eliminated
then
17015 if Ttypes
.Standard_Long_Long_Integer_Size
/= 64 then
17017 ("Eliminated not implemented on this target", Argx
);
17023 Error_Pragma_Arg
("invalid argument for pragma%", Argx
);
17025 end Get_Overflow_Mode
;
17027 -- Start of processing for Overflow_Mode
17031 Check_At_Least_N_Arguments
(1);
17032 Check_At_Most_N_Arguments
(2);
17034 -- Process first argument
17036 Scope_Suppress
.Overflow_Mode_General
:=
17037 Get_Overflow_Mode
(Name_General
, Arg1
);
17039 -- Case of only one argument
17041 if Arg_Count
= 1 then
17042 Scope_Suppress
.Overflow_Mode_Assertions
:=
17043 Scope_Suppress
.Overflow_Mode_General
;
17045 -- Case of two arguments present
17048 Scope_Suppress
.Overflow_Mode_Assertions
:=
17049 Get_Overflow_Mode
(Name_Assertions
, Arg2
);
17053 --------------------------
17054 -- Overriding Renamings --
17055 --------------------------
17057 -- pragma Overriding_Renamings;
17059 when Pragma_Overriding_Renamings
=>
17061 Check_Arg_Count
(0);
17062 Check_Valid_Configuration_Pragma
;
17063 Overriding_Renamings
:= True;
17069 -- pragma Pack (first_subtype_LOCAL_NAME);
17071 when Pragma_Pack
=> Pack
: declare
17072 Assoc
: constant Node_Id
:= Arg1
;
17076 Ignore
: Boolean := False;
17079 Check_No_Identifiers
;
17080 Check_Arg_Count
(1);
17081 Check_Arg_Is_Local_Name
(Arg1
);
17082 Type_Id
:= Get_Pragma_Arg
(Assoc
);
17084 if not Is_Entity_Name
(Type_Id
)
17085 or else not Is_Type
(Entity
(Type_Id
))
17088 ("argument for pragma% must be type or subtype", Arg1
);
17091 Find_Type
(Type_Id
);
17092 Typ
:= Entity
(Type_Id
);
17095 or else Rep_Item_Too_Early
(Typ
, N
)
17099 Typ
:= Underlying_Type
(Typ
);
17102 if not Is_Array_Type
(Typ
) and then not Is_Record_Type
(Typ
) then
17103 Error_Pragma
("pragma% must specify array or record type");
17106 Check_First_Subtype
(Arg1
);
17107 Check_Duplicate_Pragma
(Typ
);
17111 if Is_Array_Type
(Typ
) then
17112 Ctyp
:= Component_Type
(Typ
);
17114 -- Ignore pack that does nothing
17116 if Known_Static_Esize
(Ctyp
)
17117 and then Known_Static_RM_Size
(Ctyp
)
17118 and then Esize
(Ctyp
) = RM_Size
(Ctyp
)
17119 and then Addressable
(Esize
(Ctyp
))
17124 -- Process OK pragma Pack. Note that if there is a separate
17125 -- component clause present, the Pack will be cancelled. This
17126 -- processing is in Freeze.
17128 if not Rep_Item_Too_Late
(Typ
, N
) then
17130 -- In CodePeer mode, we do not need complex front-end
17131 -- expansions related to pragma Pack, so disable handling
17134 if CodePeer_Mode
then
17137 -- Don't attempt any packing for VM targets. We possibly
17138 -- could deal with some cases of array bit-packing, but we
17139 -- don't bother, since this is not a typical kind of
17140 -- representation in the VM context anyway (and would not
17141 -- for example work nicely with the debugger).
17143 elsif VM_Target
/= No_VM
then
17144 if not GNAT_Mode
then
17146 ("??pragma% ignored in this configuration");
17149 -- Normal case where we do the pack action
17153 Set_Is_Packed
(Base_Type
(Typ
));
17154 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
17157 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
17161 -- For record types, the pack is always effective
17163 else pragma Assert
(Is_Record_Type
(Typ
));
17164 if not Rep_Item_Too_Late
(Typ
, N
) then
17166 -- Ignore pack request with warning in VM mode (skip warning
17167 -- if we are compiling GNAT run time library).
17169 if VM_Target
/= No_VM
then
17170 if not GNAT_Mode
then
17172 ("??pragma% ignored in this configuration");
17175 -- Normal case of pack request active
17178 Set_Is_Packed
(Base_Type
(Typ
));
17179 Set_Has_Pragma_Pack
(Base_Type
(Typ
));
17180 Set_Has_Non_Standard_Rep
(Base_Type
(Typ
));
17192 -- There is nothing to do here, since we did all the processing for
17193 -- this pragma in Par.Prag (so that it works properly even in syntax
17196 when Pragma_Page
=>
17203 -- pragma Part_Of (ABSTRACT_STATE);
17205 -- ABSTRACT_STATE ::= NAME
17207 when Pragma_Part_Of
=> Part_Of
: declare
17208 procedure Propagate_Part_Of
17209 (Pack_Id
: Entity_Id
;
17210 State_Id
: Entity_Id
;
17211 Instance
: Node_Id
);
17212 -- Propagate the Part_Of indicator to all abstract states and
17213 -- variables declared in the visible state space of a package
17214 -- denoted by Pack_Id. State_Id is the encapsulating state.
17215 -- Instance is the package instantiation node.
17217 -----------------------
17218 -- Propagate_Part_Of --
17219 -----------------------
17221 procedure Propagate_Part_Of
17222 (Pack_Id
: Entity_Id
;
17223 State_Id
: Entity_Id
;
17224 Instance
: Node_Id
)
17226 Has_Item
: Boolean := False;
17227 -- Flag set when the visible state space contains at least one
17228 -- abstract state or variable.
17230 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
);
17231 -- Propagate the Part_Of indicator to all abstract states and
17232 -- variables declared in the visible state space of a package
17233 -- denoted by Pack_Id.
17235 -----------------------
17236 -- Propagate_Part_Of --
17237 -----------------------
17239 procedure Propagate_Part_Of
(Pack_Id
: Entity_Id
) is
17240 Item_Id
: Entity_Id
;
17243 -- Traverse the entity chain of the package and set relevant
17244 -- attributes of abstract states and variables declared in
17245 -- the visible state space of the package.
17247 Item_Id
:= First_Entity
(Pack_Id
);
17248 while Present
(Item_Id
)
17249 and then not In_Private_Part
(Item_Id
)
17251 -- Do not consider internally generated items
17253 if not Comes_From_Source
(Item_Id
) then
17256 -- The Part_Of indicator turns an abstract state or
17257 -- variable into a constituent of the encapsulating
17260 elsif Ekind_In
(Item_Id
, E_Abstract_State
,
17265 Append_Elmt
(Item_Id
, Part_Of_Constituents
(State_Id
));
17266 Set_Encapsulating_State
(Item_Id
, State_Id
);
17268 -- Recursively handle nested packages and instantiations
17270 elsif Ekind
(Item_Id
) = E_Package
then
17271 Propagate_Part_Of
(Item_Id
);
17274 Next_Entity
(Item_Id
);
17276 end Propagate_Part_Of
;
17278 -- Start of processing for Propagate_Part_Of
17281 Propagate_Part_Of
(Pack_Id
);
17283 -- Detect a package instantiation that is subject to a Part_Of
17284 -- indicator, but has no visible state.
17286 if not Has_Item
then
17288 ("package instantiation & has Part_Of indicator but "
17289 & "lacks visible state", Instance
, Pack_Id
);
17291 end Propagate_Part_Of
;
17295 Item_Id
: Entity_Id
;
17298 State_Id
: Entity_Id
;
17301 -- Start of processing for Part_Of
17305 Check_No_Identifiers
;
17306 Check_Arg_Count
(1);
17308 -- Ensure the proper placement of the pragma. Part_Of must appear
17309 -- on a variable declaration or a package instantiation.
17312 while Present
(Stmt
) loop
17314 -- Skip prior pragmas, but check for duplicates
17316 if Nkind
(Stmt
) = N_Pragma
then
17317 if Pragma_Name
(Stmt
) = Pname
then
17318 Error_Msg_Name_1
:= Pname
;
17319 Error_Msg_Sloc
:= Sloc
(Stmt
);
17320 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
17323 -- Skip internally generated code
17325 elsif not Comes_From_Source
(Stmt
) then
17328 -- The pragma applies to an object declaration (possibly a
17329 -- variable) or a package instantiation. Stop the traversal
17330 -- and continue the analysis.
17332 elsif Nkind_In
(Stmt
, N_Object_Declaration
,
17333 N_Package_Instantiation
)
17337 -- The pragma does not apply to a legal construct, issue an
17338 -- error and stop the analysis.
17345 Stmt
:= Prev
(Stmt
);
17348 -- When the context is an object declaration, ensure that we are
17349 -- dealing with a variable.
17351 if Nkind
(Stmt
) = N_Object_Declaration
17352 and then Ekind
(Defining_Entity
(Stmt
)) /= E_Variable
17354 SPARK_Msg_N
("indicator Part_Of must apply to a variable", N
);
17358 -- Extract the entity of the related object declaration or package
17359 -- instantiation. In the case of the instantiation, use the entity
17360 -- of the instance spec.
17362 if Nkind
(Stmt
) = N_Package_Instantiation
then
17363 Stmt
:= Instance_Spec
(Stmt
);
17366 Item_Id
:= Defining_Entity
(Stmt
);
17367 State
:= Get_Pragma_Arg
(Arg1
);
17369 -- Detect any discrepancies between the placement of the object
17370 -- or package instantiation with respect to state space and the
17371 -- encapsulating state.
17374 (Item_Id
=> Item_Id
,
17380 State_Id
:= Entity
(State
);
17382 -- Add the pragma to the contract of the item. This aids with
17383 -- the detection of a missing but required Part_Of indicator.
17385 Add_Contract_Item
(N
, Item_Id
);
17387 -- The Part_Of indicator turns a variable into a constituent
17388 -- of the encapsulating state.
17390 if Ekind
(Item_Id
) = E_Variable
then
17391 Append_Elmt
(Item_Id
, Part_Of_Constituents
(State_Id
));
17392 Set_Encapsulating_State
(Item_Id
, State_Id
);
17394 -- Propagate the Part_Of indicator to the visible state space
17395 -- of the package instantiation.
17399 (Pack_Id
=> Item_Id
,
17400 State_Id
=> State_Id
,
17406 ----------------------------------
17407 -- Partition_Elaboration_Policy --
17408 ----------------------------------
17410 -- pragma Partition_Elaboration_Policy (policy_IDENTIFIER);
17412 when Pragma_Partition_Elaboration_Policy
=> declare
17413 subtype PEP_Range
is Name_Id
17414 range First_Partition_Elaboration_Policy_Name
17415 .. Last_Partition_Elaboration_Policy_Name
;
17416 PEP_Val
: PEP_Range
;
17421 Check_Arg_Count
(1);
17422 Check_No_Identifiers
;
17423 Check_Arg_Is_Partition_Elaboration_Policy
(Arg1
);
17424 Check_Valid_Configuration_Pragma
;
17425 PEP_Val
:= Chars
(Get_Pragma_Arg
(Arg1
));
17428 when Name_Concurrent
=>
17430 when Name_Sequential
=>
17434 if Partition_Elaboration_Policy
/= ' '
17435 and then Partition_Elaboration_Policy
/= PEP
17437 Error_Msg_Sloc
:= Partition_Elaboration_Policy_Sloc
;
17439 ("partition elaboration policy incompatible with policy#");
17441 -- Set new policy, but always preserve System_Location since we
17442 -- like the error message with the run time name.
17445 Partition_Elaboration_Policy
:= PEP
;
17447 if Partition_Elaboration_Policy_Sloc
/= System_Location
then
17448 Partition_Elaboration_Policy_Sloc
:= Loc
;
17457 -- pragma Passive [(PASSIVE_FORM)];
17459 -- PASSIVE_FORM ::= Semaphore | No
17461 when Pragma_Passive
=>
17464 if Nkind
(Parent
(N
)) /= N_Task_Definition
then
17465 Error_Pragma
("pragma% must be within task definition");
17468 if Arg_Count
/= 0 then
17469 Check_Arg_Count
(1);
17470 Check_Arg_Is_One_Of
(Arg1
, Name_Semaphore
, Name_No
);
17473 ----------------------------------
17474 -- Preelaborable_Initialization --
17475 ----------------------------------
17477 -- pragma Preelaborable_Initialization (DIRECT_NAME);
17479 when Pragma_Preelaborable_Initialization
=> Preelab_Init
: declare
17484 Check_Arg_Count
(1);
17485 Check_No_Identifiers
;
17486 Check_Arg_Is_Identifier
(Arg1
);
17487 Check_Arg_Is_Local_Name
(Arg1
);
17488 Check_First_Subtype
(Arg1
);
17489 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
17491 -- The pragma may come from an aspect on a private declaration,
17492 -- even if the freeze point at which this is analyzed in the
17493 -- private part after the full view.
17495 if Has_Private_Declaration
(Ent
)
17496 and then From_Aspect_Specification
(N
)
17500 -- Check appropriate type argument
17502 elsif Is_Private_Type
(Ent
)
17503 or else Is_Protected_Type
(Ent
)
17504 or else (Is_Generic_Type
(Ent
) and then Is_Derived_Type
(Ent
))
17506 -- AI05-0028: The pragma applies to all composite types. Note
17507 -- that we apply this binding interpretation to earlier versions
17508 -- of Ada, so there is no Ada 2012 guard. Seems a reasonable
17509 -- choice since there are other compilers that do the same.
17511 or else Is_Composite_Type
(Ent
)
17517 ("pragma % can only be applied to private, formal derived, "
17518 & "protected, or composite type", Arg1
);
17521 -- Give an error if the pragma is applied to a protected type that
17522 -- does not qualify (due to having entries, or due to components
17523 -- that do not qualify).
17525 if Is_Protected_Type
(Ent
)
17526 and then not Has_Preelaborable_Initialization
(Ent
)
17529 ("protected type & does not have preelaborable "
17530 & "initialization", Ent
);
17532 -- Otherwise mark the type as definitely having preelaborable
17536 Set_Known_To_Have_Preelab_Init
(Ent
);
17539 if Has_Pragma_Preelab_Init
(Ent
)
17540 and then Warn_On_Redundant_Constructs
17542 Error_Pragma
("?r?duplicate pragma%!");
17544 Set_Has_Pragma_Preelab_Init
(Ent
);
17548 --------------------
17549 -- Persistent_BSS --
17550 --------------------
17552 -- pragma Persistent_BSS [(object_NAME)];
17554 when Pragma_Persistent_BSS
=> Persistent_BSS
: declare
17561 Check_At_Most_N_Arguments
(1);
17563 -- Case of application to specific object (one argument)
17565 if Arg_Count
= 1 then
17566 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
17568 if not Is_Entity_Name
(Get_Pragma_Arg
(Arg1
))
17570 Ekind_In
(Entity
(Get_Pragma_Arg
(Arg1
)), E_Variable
,
17573 Error_Pragma_Arg
("pragma% only applies to objects", Arg1
);
17576 Ent
:= Entity
(Get_Pragma_Arg
(Arg1
));
17577 Decl
:= Parent
(Ent
);
17579 -- Check for duplication before inserting in list of
17580 -- representation items.
17582 Check_Duplicate_Pragma
(Ent
);
17584 if Rep_Item_Too_Late
(Ent
, N
) then
17588 if Present
(Expression
(Decl
)) then
17590 ("object for pragma% cannot have initialization", Arg1
);
17593 if not Is_Potentially_Persistent_Type
(Etype
(Ent
)) then
17595 ("object type for pragma% is not potentially persistent",
17600 Make_Linker_Section_Pragma
17601 (Ent
, Sloc
(N
), ".persistent.bss");
17602 Insert_After
(N
, Prag
);
17605 -- Case of use as configuration pragma with no arguments
17608 Check_Valid_Configuration_Pragma
;
17609 Persistent_BSS_Mode
:= True;
17611 end Persistent_BSS
;
17617 -- pragma Polling (ON | OFF);
17619 when Pragma_Polling
=>
17621 Check_Arg_Count
(1);
17622 Check_No_Identifiers
;
17623 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
17624 Polling_Required
:= (Chars
(Get_Pragma_Arg
(Arg1
)) = Name_On
);
17626 -----------------------------------
17627 -- Post/Post_Class/Postcondition --
17628 -----------------------------------
17630 -- pragma Post (Boolean_EXPRESSION);
17631 -- pragma Post_Class (Boolean_EXPRESSION);
17632 -- pragma Postcondition ([Check =>] Boolean_EXPRESSION
17633 -- [,[Message =>] String_EXPRESSION]);
17636 Pragma_Post_Class |
17637 Pragma_Postcondition
=>
17638 Analyze_Pre_Post_Condition
;
17640 --------------------------------
17641 -- Pre/Pre_Class/Precondition --
17642 --------------------------------
17644 -- pragma Pre (Boolean_EXPRESSION);
17645 -- pragma Pre_Class (Boolean_EXPRESSION);
17646 -- pragma Precondition ([Check =>] Boolean_EXPRESSION
17647 -- [,[Message =>] String_EXPRESSION]);
17651 Pragma_Precondition
=>
17652 Analyze_Pre_Post_Condition
;
17658 -- pragma Predicate
17659 -- ([Entity =>] type_LOCAL_NAME,
17660 -- [Check =>] boolean_EXPRESSION);
17662 when Pragma_Predicate
=> Predicate
: declare
17669 Check_Arg_Count
(2);
17670 Check_Optional_Identifier
(Arg1
, Name_Entity
);
17671 Check_Optional_Identifier
(Arg2
, Name_Check
);
17673 Check_Arg_Is_Local_Name
(Arg1
);
17675 Type_Id
:= Get_Pragma_Arg
(Arg1
);
17676 Find_Type
(Type_Id
);
17677 Typ
:= Entity
(Type_Id
);
17679 if Typ
= Any_Type
then
17683 -- The remaining processing is simply to link the pragma on to
17684 -- the rep item chain, for processing when the type is frozen.
17685 -- This is accomplished by a call to Rep_Item_Too_Late. We also
17686 -- mark the type as having predicates.
17688 Set_Has_Predicates
(Typ
);
17689 Discard
:= Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True);
17696 -- pragma Preelaborate [(library_unit_NAME)];
17698 -- Set the flag Is_Preelaborated of program unit name entity
17700 when Pragma_Preelaborate
=> Preelaborate
: declare
17701 Pa
: constant Node_Id
:= Parent
(N
);
17702 Pk
: constant Node_Kind
:= Nkind
(Pa
);
17706 Check_Ada_83_Warning
;
17707 Check_Valid_Library_Unit_Pragma
;
17709 if Nkind
(N
) = N_Null_Statement
then
17713 Ent
:= Find_Lib_Unit_Name
;
17714 Check_Duplicate_Pragma
(Ent
);
17716 -- This filters out pragmas inside generic parents that show up
17717 -- inside instantiations. Pragmas that come from aspects in the
17718 -- unit are not ignored.
17720 if Present
(Ent
) then
17721 if Pk
= N_Package_Specification
17722 and then Present
(Generic_Parent
(Pa
))
17723 and then not From_Aspect_Specification
(N
)
17728 if not Debug_Flag_U
then
17729 Set_Is_Preelaborated
(Ent
);
17730 Set_Suppress_Elaboration_Warnings
(Ent
);
17736 -------------------------------
17737 -- Prefix_Exception_Messages --
17738 -------------------------------
17740 -- pragma Prefix_Exception_Messages;
17742 when Pragma_Prefix_Exception_Messages
=>
17744 Check_Valid_Configuration_Pragma
;
17745 Check_Arg_Count
(0);
17746 Prefix_Exception_Messages
:= True;
17752 -- pragma Priority (EXPRESSION);
17754 when Pragma_Priority
=> Priority
: declare
17755 P
: constant Node_Id
:= Parent
(N
);
17760 Check_No_Identifiers
;
17761 Check_Arg_Count
(1);
17765 if Nkind
(P
) = N_Subprogram_Body
then
17766 Check_In_Main_Program
;
17768 Ent
:= Defining_Unit_Name
(Specification
(P
));
17770 if Nkind
(Ent
) = N_Defining_Program_Unit_Name
then
17771 Ent
:= Defining_Identifier
(Ent
);
17774 Arg
:= Get_Pragma_Arg
(Arg1
);
17775 Analyze_And_Resolve
(Arg
, Standard_Integer
);
17779 if not Is_OK_Static_Expression
(Arg
) then
17780 Flag_Non_Static_Expr
17781 ("main subprogram priority is not static!", Arg
);
17784 -- If constraint error, then we already signalled an error
17786 elsif Raises_Constraint_Error
(Arg
) then
17789 -- Otherwise check in range except if Relaxed_RM_Semantics
17790 -- where we ignore the value if out of range.
17794 Val
: constant Uint
:= Expr_Value
(Arg
);
17796 if not Relaxed_RM_Semantics
17799 or else Val
> Expr_Value
(Expression
17800 (Parent
(RTE
(RE_Max_Priority
)))))
17803 ("main subprogram priority is out of range", Arg1
);
17806 (Current_Sem_Unit
, UI_To_Int
(Expr_Value
(Arg
)));
17811 -- Load an arbitrary entity from System.Tasking.Stages or
17812 -- System.Tasking.Restricted.Stages (depending on the
17813 -- supported profile) to make sure that one of these packages
17814 -- is implicitly with'ed, since we need to have the tasking
17815 -- run time active for the pragma Priority to have any effect.
17816 -- Previously we with'ed the package System.Tasking, but this
17817 -- package does not trigger the required initialization of the
17818 -- run-time library.
17821 Discard
: Entity_Id
;
17822 pragma Warnings
(Off
, Discard
);
17824 if Restricted_Profile
then
17825 Discard
:= RTE
(RE_Activate_Restricted_Tasks
);
17827 Discard
:= RTE
(RE_Activate_Tasks
);
17831 -- Task or Protected, must be of type Integer
17833 elsif Nkind_In
(P
, N_Protected_Definition
, N_Task_Definition
) then
17834 Arg
:= Get_Pragma_Arg
(Arg1
);
17835 Ent
:= Defining_Identifier
(Parent
(P
));
17837 -- The expression must be analyzed in the special manner
17838 -- described in "Handling of Default and Per-Object
17839 -- Expressions" in sem.ads.
17841 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Any_Priority
));
17843 if not Is_OK_Static_Expression
(Arg
) then
17844 Check_Restriction
(Static_Priorities
, Arg
);
17847 -- Anything else is incorrect
17853 -- Check duplicate pragma before we chain the pragma in the Rep
17854 -- Item chain of Ent.
17856 Check_Duplicate_Pragma
(Ent
);
17857 Record_Rep_Item
(Ent
, N
);
17860 -----------------------------------
17861 -- Priority_Specific_Dispatching --
17862 -----------------------------------
17864 -- pragma Priority_Specific_Dispatching (
17865 -- policy_IDENTIFIER,
17866 -- first_priority_EXPRESSION,
17867 -- last_priority_EXPRESSION);
17869 when Pragma_Priority_Specific_Dispatching
=>
17870 Priority_Specific_Dispatching
: declare
17871 Prio_Id
: constant Entity_Id
:= RTE
(RE_Any_Priority
);
17872 -- This is the entity System.Any_Priority;
17875 Lower_Bound
: Node_Id
;
17876 Upper_Bound
: Node_Id
;
17882 Check_Arg_Count
(3);
17883 Check_No_Identifiers
;
17884 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
17885 Check_Valid_Configuration_Pragma
;
17886 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
17887 DP
:= Fold_Upper
(Name_Buffer
(1));
17889 Lower_Bound
:= Get_Pragma_Arg
(Arg2
);
17890 Check_Arg_Is_OK_Static_Expression
(Lower_Bound
, Standard_Integer
);
17891 Lower_Val
:= Expr_Value
(Lower_Bound
);
17893 Upper_Bound
:= Get_Pragma_Arg
(Arg3
);
17894 Check_Arg_Is_OK_Static_Expression
(Upper_Bound
, Standard_Integer
);
17895 Upper_Val
:= Expr_Value
(Upper_Bound
);
17897 -- It is not allowed to use Task_Dispatching_Policy and
17898 -- Priority_Specific_Dispatching in the same partition.
17900 if Task_Dispatching_Policy
/= ' ' then
17901 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
17903 ("pragma% incompatible with Task_Dispatching_Policy#");
17905 -- Check lower bound in range
17907 elsif Lower_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
17909 Lower_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
17912 ("first_priority is out of range", Arg2
);
17914 -- Check upper bound in range
17916 elsif Upper_Val
< Expr_Value
(Type_Low_Bound
(Prio_Id
))
17918 Upper_Val
> Expr_Value
(Type_High_Bound
(Prio_Id
))
17921 ("last_priority is out of range", Arg3
);
17923 -- Check that the priority range is valid
17925 elsif Lower_Val
> Upper_Val
then
17927 ("last_priority_expression must be greater than or equal to "
17928 & "first_priority_expression");
17930 -- Store the new policy, but always preserve System_Location since
17931 -- we like the error message with the run-time name.
17934 -- Check overlapping in the priority ranges specified in other
17935 -- Priority_Specific_Dispatching pragmas within the same
17936 -- partition. We can only check those we know about.
17939 Specific_Dispatching
.First
.. Specific_Dispatching
.Last
17941 if Specific_Dispatching
.Table
(J
).First_Priority
in
17942 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
17943 or else Specific_Dispatching
.Table
(J
).Last_Priority
in
17944 UI_To_Int
(Lower_Val
) .. UI_To_Int
(Upper_Val
)
17947 Specific_Dispatching
.Table
(J
).Pragma_Loc
;
17949 ("priority range overlaps with "
17950 & "Priority_Specific_Dispatching#");
17954 -- The use of Priority_Specific_Dispatching is incompatible
17955 -- with Task_Dispatching_Policy.
17957 if Task_Dispatching_Policy
/= ' ' then
17958 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
17960 ("Priority_Specific_Dispatching incompatible "
17961 & "with Task_Dispatching_Policy#");
17964 -- The use of Priority_Specific_Dispatching forces ceiling
17967 if Locking_Policy
/= ' ' and then Locking_Policy
/= 'C' then
17968 Error_Msg_Sloc
:= Locking_Policy_Sloc
;
17970 ("Priority_Specific_Dispatching incompatible "
17971 & "with Locking_Policy#");
17973 -- Set the Ceiling_Locking policy, but preserve System_Location
17974 -- since we like the error message with the run time name.
17977 Locking_Policy
:= 'C';
17979 if Locking_Policy_Sloc
/= System_Location
then
17980 Locking_Policy_Sloc
:= Loc
;
17984 -- Add entry in the table
17986 Specific_Dispatching
.Append
17987 ((Dispatching_Policy
=> DP
,
17988 First_Priority
=> UI_To_Int
(Lower_Val
),
17989 Last_Priority
=> UI_To_Int
(Upper_Val
),
17990 Pragma_Loc
=> Loc
));
17992 end Priority_Specific_Dispatching
;
17998 -- pragma Profile (profile_IDENTIFIER);
18000 -- profile_IDENTIFIER => Restricted | Ravenscar | Rational
18002 when Pragma_Profile
=>
18004 Check_Arg_Count
(1);
18005 Check_Valid_Configuration_Pragma
;
18006 Check_No_Identifiers
;
18009 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
18012 if Chars
(Argx
) = Name_Ravenscar
then
18013 Set_Ravenscar_Profile
(N
);
18015 elsif Chars
(Argx
) = Name_Restricted
then
18016 Set_Profile_Restrictions
18018 N
, Warn
=> Treat_Restrictions_As_Warnings
);
18020 elsif Chars
(Argx
) = Name_Rational
then
18021 Set_Rational_Profile
;
18023 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
18024 Set_Profile_Restrictions
18025 (No_Implementation_Extensions
,
18026 N
, Warn
=> Treat_Restrictions_As_Warnings
);
18029 Error_Pragma_Arg
("& is not a valid profile", Argx
);
18033 ----------------------
18034 -- Profile_Warnings --
18035 ----------------------
18037 -- pragma Profile_Warnings (profile_IDENTIFIER);
18039 -- profile_IDENTIFIER => Restricted | Ravenscar
18041 when Pragma_Profile_Warnings
=>
18043 Check_Arg_Count
(1);
18044 Check_Valid_Configuration_Pragma
;
18045 Check_No_Identifiers
;
18048 Argx
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
18051 if Chars
(Argx
) = Name_Ravenscar
then
18052 Set_Profile_Restrictions
(Ravenscar
, N
, Warn
=> True);
18054 elsif Chars
(Argx
) = Name_Restricted
then
18055 Set_Profile_Restrictions
(Restricted
, N
, Warn
=> True);
18057 elsif Chars
(Argx
) = Name_No_Implementation_Extensions
then
18058 Set_Profile_Restrictions
18059 (No_Implementation_Extensions
, N
, Warn
=> True);
18062 Error_Pragma_Arg
("& is not a valid profile", Argx
);
18066 --------------------------
18067 -- Propagate_Exceptions --
18068 --------------------------
18070 -- pragma Propagate_Exceptions;
18072 -- Note: this pragma is obsolete and has no effect
18074 when Pragma_Propagate_Exceptions
=>
18076 Check_Arg_Count
(0);
18078 if Warn_On_Obsolescent_Feature
then
18080 ("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " &
18081 "and has no effect?j?", N
);
18084 -----------------------------
18085 -- Provide_Shift_Operators --
18086 -----------------------------
18088 -- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME);
18090 when Pragma_Provide_Shift_Operators
=>
18091 Provide_Shift_Operators
: declare
18094 procedure Declare_Shift_Operator
(Nam
: Name_Id
);
18095 -- Insert declaration and pragma Instrinsic for named shift op
18097 ----------------------------
18098 -- Declare_Shift_Operator --
18099 ----------------------------
18101 procedure Declare_Shift_Operator
(Nam
: Name_Id
) is
18107 Make_Subprogram_Declaration
(Loc
,
18108 Make_Function_Specification
(Loc
,
18109 Defining_Unit_Name
=>
18110 Make_Defining_Identifier
(Loc
, Chars
=> Nam
),
18112 Result_Definition
=>
18113 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
)),
18115 Parameter_Specifications
=> New_List
(
18116 Make_Parameter_Specification
(Loc
,
18117 Defining_Identifier
=>
18118 Make_Defining_Identifier
(Loc
, Name_Value
),
18120 Make_Identifier
(Loc
, Chars
=> Chars
(Ent
))),
18122 Make_Parameter_Specification
(Loc
,
18123 Defining_Identifier
=>
18124 Make_Defining_Identifier
(Loc
, Name_Amount
),
18126 New_Occurrence_Of
(Standard_Natural
, Loc
)))));
18130 Pragma_Identifier
=> Make_Identifier
(Loc
, Name_Import
),
18131 Pragma_Argument_Associations
=> New_List
(
18132 Make_Pragma_Argument_Association
(Loc
,
18133 Expression
=> Make_Identifier
(Loc
, Name_Intrinsic
)),
18134 Make_Pragma_Argument_Association
(Loc
,
18135 Expression
=> Make_Identifier
(Loc
, Nam
))));
18137 Insert_After
(N
, Import
);
18138 Insert_After
(N
, Func
);
18139 end Declare_Shift_Operator
;
18141 -- Start of processing for Provide_Shift_Operators
18145 Check_Arg_Count
(1);
18146 Check_Arg_Is_Local_Name
(Arg1
);
18148 Arg1
:= Get_Pragma_Arg
(Arg1
);
18150 -- We must have an entity name
18152 if not Is_Entity_Name
(Arg1
) then
18154 ("pragma % must apply to integer first subtype", Arg1
);
18157 -- If no Entity, means there was a prior error so ignore
18159 if Present
(Entity
(Arg1
)) then
18160 Ent
:= Entity
(Arg1
);
18162 -- Apply error checks
18164 if not Is_First_Subtype
(Ent
) then
18166 ("cannot apply pragma %",
18167 "\& is not a first subtype",
18170 elsif not Is_Integer_Type
(Ent
) then
18172 ("cannot apply pragma %",
18173 "\& is not an integer type",
18176 elsif Has_Shift_Operator
(Ent
) then
18178 ("cannot apply pragma %",
18179 "\& already has declared shift operators",
18182 elsif Is_Frozen
(Ent
) then
18184 ("pragma % appears too late",
18185 "\& is already frozen",
18189 -- Now declare the operators. We do this during analysis rather
18190 -- than expansion, since we want the operators available if we
18191 -- are operating in -gnatc or ASIS mode.
18193 Declare_Shift_Operator
(Name_Rotate_Left
);
18194 Declare_Shift_Operator
(Name_Rotate_Right
);
18195 Declare_Shift_Operator
(Name_Shift_Left
);
18196 Declare_Shift_Operator
(Name_Shift_Right
);
18197 Declare_Shift_Operator
(Name_Shift_Right_Arithmetic
);
18199 end Provide_Shift_Operators
;
18205 -- pragma Psect_Object (
18206 -- [Internal =>] LOCAL_NAME,
18207 -- [, [External =>] EXTERNAL_SYMBOL]
18208 -- [, [Size =>] EXTERNAL_SYMBOL]);
18210 when Pragma_Psect_Object | Pragma_Common_Object
=>
18211 Psect_Object
: declare
18212 Args
: Args_List
(1 .. 3);
18213 Names
: constant Name_List
(1 .. 3) := (
18218 Internal
: Node_Id
renames Args
(1);
18219 External
: Node_Id
renames Args
(2);
18220 Size
: Node_Id
renames Args
(3);
18222 Def_Id
: Entity_Id
;
18224 procedure Check_Arg
(Arg
: Node_Id
);
18225 -- Checks that argument is either a string literal or an
18226 -- identifier, and posts error message if not.
18232 procedure Check_Arg
(Arg
: Node_Id
) is
18234 if not Nkind_In
(Original_Node
(Arg
),
18239 ("inappropriate argument for pragma %", Arg
);
18243 -- Start of processing for Common_Object/Psect_Object
18247 Gather_Associations
(Names
, Args
);
18248 Process_Extended_Import_Export_Internal_Arg
(Internal
);
18250 Def_Id
:= Entity
(Internal
);
18252 if not Ekind_In
(Def_Id
, E_Constant
, E_Variable
) then
18254 ("pragma% must designate an object", Internal
);
18257 Check_Arg
(Internal
);
18259 if Is_Imported
(Def_Id
) or else Is_Exported
(Def_Id
) then
18261 ("cannot use pragma% for imported/exported object",
18265 if Is_Concurrent_Type
(Etype
(Internal
)) then
18267 ("cannot specify pragma % for task/protected object",
18271 if Has_Rep_Pragma
(Def_Id
, Name_Common_Object
)
18273 Has_Rep_Pragma
(Def_Id
, Name_Psect_Object
)
18275 Error_Msg_N
("??duplicate Common/Psect_Object pragma", N
);
18278 if Ekind
(Def_Id
) = E_Constant
then
18280 ("cannot specify pragma % for a constant", Internal
);
18283 if Is_Record_Type
(Etype
(Internal
)) then
18289 Ent
:= First_Entity
(Etype
(Internal
));
18290 while Present
(Ent
) loop
18291 Decl
:= Declaration_Node
(Ent
);
18293 if Ekind
(Ent
) = E_Component
18294 and then Nkind
(Decl
) = N_Component_Declaration
18295 and then Present
(Expression
(Decl
))
18296 and then Warn_On_Export_Import
18299 ("?x?object for pragma % has defaults", Internal
);
18309 if Present
(Size
) then
18313 if Present
(External
) then
18314 Check_Arg_Is_External_Name
(External
);
18317 -- If all error tests pass, link pragma on to the rep item chain
18319 Record_Rep_Item
(Def_Id
, N
);
18326 -- pragma Pure [(library_unit_NAME)];
18328 when Pragma_Pure
=> Pure
: declare
18332 Check_Ada_83_Warning
;
18333 Check_Valid_Library_Unit_Pragma
;
18335 if Nkind
(N
) = N_Null_Statement
then
18339 Ent
:= Find_Lib_Unit_Name
;
18341 Set_Has_Pragma_Pure
(Ent
);
18342 Set_Suppress_Elaboration_Warnings
(Ent
);
18345 -------------------
18346 -- Pure_Function --
18347 -------------------
18349 -- pragma Pure_Function ([Entity =>] function_LOCAL_NAME);
18351 when Pragma_Pure_Function
=> Pure_Function
: declare
18354 Def_Id
: Entity_Id
;
18355 Effective
: Boolean := False;
18359 Check_Arg_Count
(1);
18360 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18361 Check_Arg_Is_Local_Name
(Arg1
);
18362 E_Id
:= Get_Pragma_Arg
(Arg1
);
18364 if Error_Posted
(E_Id
) then
18368 -- Loop through homonyms (overloadings) of referenced entity
18370 E
:= Entity
(E_Id
);
18372 if Present
(E
) then
18374 Def_Id
:= Get_Base_Subprogram
(E
);
18376 if not Ekind_In
(Def_Id
, E_Function
,
18377 E_Generic_Function
,
18381 ("pragma% requires a function name", Arg1
);
18384 Set_Is_Pure
(Def_Id
);
18386 if not Has_Pragma_Pure_Function
(Def_Id
) then
18387 Set_Has_Pragma_Pure_Function
(Def_Id
);
18391 exit when From_Aspect_Specification
(N
);
18393 exit when No
(E
) or else Scope
(E
) /= Current_Scope
;
18397 and then Warn_On_Redundant_Constructs
18400 ("pragma Pure_Function on& is redundant?r?",
18406 --------------------
18407 -- Queuing_Policy --
18408 --------------------
18410 -- pragma Queuing_Policy (policy_IDENTIFIER);
18412 when Pragma_Queuing_Policy
=> declare
18416 Check_Ada_83_Warning
;
18417 Check_Arg_Count
(1);
18418 Check_No_Identifiers
;
18419 Check_Arg_Is_Queuing_Policy
(Arg1
);
18420 Check_Valid_Configuration_Pragma
;
18421 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
18422 QP
:= Fold_Upper
(Name_Buffer
(1));
18424 if Queuing_Policy
/= ' '
18425 and then Queuing_Policy
/= QP
18427 Error_Msg_Sloc
:= Queuing_Policy_Sloc
;
18428 Error_Pragma
("queuing policy incompatible with policy#");
18430 -- Set new policy, but always preserve System_Location since we
18431 -- like the error message with the run time name.
18434 Queuing_Policy
:= QP
;
18436 if Queuing_Policy_Sloc
/= System_Location
then
18437 Queuing_Policy_Sloc
:= Loc
;
18446 -- pragma Rational, for compatibility with foreign compiler
18448 when Pragma_Rational
=>
18449 Set_Rational_Profile
;
18451 ------------------------------------
18452 -- Refined_Depends/Refined_Global --
18453 ------------------------------------
18455 -- pragma Refined_Depends (DEPENDENCY_RELATION);
18457 -- DEPENDENCY_RELATION ::=
18459 -- | DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}
18461 -- DEPENDENCY_CLAUSE ::=
18462 -- OUTPUT_LIST =>[+] INPUT_LIST
18463 -- | NULL_DEPENDENCY_CLAUSE
18465 -- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST
18467 -- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT})
18469 -- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT})
18471 -- OUTPUT ::= NAME | FUNCTION_RESULT
18474 -- where FUNCTION_RESULT is a function Result attribute_reference
18476 -- pragma Refined_Global (GLOBAL_SPECIFICATION);
18478 -- GLOBAL_SPECIFICATION ::=
18481 -- | MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}
18483 -- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST
18485 -- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In
18486 -- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM})
18487 -- GLOBAL_ITEM ::= NAME
18489 when Pragma_Refined_Depends |
18490 Pragma_Refined_Global
=> Refined_Depends_Global
:
18492 Body_Id
: Entity_Id
;
18494 Spec_Id
: Entity_Id
;
18497 Analyze_Refined_Pragma
(Spec_Id
, Body_Id
, Legal
);
18499 -- Save the pragma in the contract of the subprogram body. The
18500 -- remaining analysis is performed at the end of the enclosing
18504 Add_Contract_Item
(N
, Body_Id
);
18506 end Refined_Depends_Global
;
18512 -- pragma Refined_Post (boolean_EXPRESSION);
18514 when Pragma_Refined_Post
=> Refined_Post
: declare
18515 Body_Id
: Entity_Id
;
18517 Spec_Id
: Entity_Id
;
18520 Analyze_Refined_Pragma
(Spec_Id
, Body_Id
, Legal
);
18522 -- Fully analyze the pragma when it appears inside a subprogram
18523 -- body because it cannot benefit from forward references.
18526 Analyze_Pre_Post_Condition_In_Decl_Part
(N
);
18528 -- Currently it is not possible to inline pre/postconditions on
18529 -- a subprogram subject to pragma Inline_Always.
18531 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
18533 -- Chain the pragma on the contract for easy retrieval
18535 Add_Contract_Item
(N
, Body_Id
);
18539 -------------------
18540 -- Refined_State --
18541 -------------------
18543 -- pragma Refined_State (REFINEMENT_LIST);
18545 -- REFINEMENT_LIST ::=
18546 -- REFINEMENT_CLAUSE
18547 -- | (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE})
18549 -- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST
18551 -- CONSTITUENT_LIST ::=
18554 -- | (CONSTITUENT {, CONSTITUENT})
18556 -- CONSTITUENT ::= object_NAME | state_NAME
18558 when Pragma_Refined_State
=> Refined_State
: declare
18559 Pack_Decl
: Node_Id
;
18560 Spec_Id
: Entity_Id
;
18564 Check_No_Identifiers
;
18565 Check_Arg_Count
(1);
18567 Pack_Decl
:= Find_Related_Package_Or_Body
(N
, Do_Checks
=> True);
18569 -- Ensure the proper placement of the pragma. Refined states must
18570 -- be associated with a package body.
18572 if Nkind
(Pack_Decl
) = N_Package_Body
then
18575 -- Otherwise the pragma is associated with an illegal construct
18582 Spec_Id
:= Corresponding_Spec
(Pack_Decl
);
18584 -- State refinement is allowed only when the corresponding package
18585 -- declaration has non-null pragma Abstract_State. Refinement not
18586 -- enforced when SPARK checks are suppressed (SPARK RM 7.2.2(3)).
18588 if SPARK_Mode
/= Off
18590 (No
(Abstract_States
(Spec_Id
))
18591 or else Has_Null_Abstract_State
(Spec_Id
))
18594 ("useless refinement, package & does not define abstract "
18595 & "states", N
, Spec_Id
);
18599 -- The pragma must be analyzed at the end of the declarations as
18600 -- it has visibility over the whole declarative region. Save the
18601 -- pragma for later (see Analyze_Refined_State_In_Decl_Part) by
18602 -- adding it to the contract of the package body.
18604 Add_Contract_Item
(N
, Defining_Entity
(Pack_Decl
));
18607 -----------------------
18608 -- Relative_Deadline --
18609 -----------------------
18611 -- pragma Relative_Deadline (time_span_EXPRESSION);
18613 when Pragma_Relative_Deadline
=> Relative_Deadline
: declare
18614 P
: constant Node_Id
:= Parent
(N
);
18619 Check_No_Identifiers
;
18620 Check_Arg_Count
(1);
18622 Arg
:= Get_Pragma_Arg
(Arg1
);
18624 -- The expression must be analyzed in the special manner described
18625 -- in "Handling of Default and Per-Object Expressions" in sem.ads.
18627 Preanalyze_Spec_Expression
(Arg
, RTE
(RE_Time_Span
));
18631 if Nkind
(P
) = N_Subprogram_Body
then
18632 Check_In_Main_Program
;
18634 -- Only Task and subprogram cases allowed
18636 elsif Nkind
(P
) /= N_Task_Definition
then
18640 -- Check duplicate pragma before we set the corresponding flag
18642 if Has_Relative_Deadline_Pragma
(P
) then
18643 Error_Pragma
("duplicate pragma% not allowed");
18646 -- Set Has_Relative_Deadline_Pragma only for tasks. Note that
18647 -- Relative_Deadline pragma node cannot be inserted in the Rep
18648 -- Item chain of Ent since it is rewritten by the expander as a
18649 -- procedure call statement that will break the chain.
18651 Set_Has_Relative_Deadline_Pragma
(P
, True);
18652 end Relative_Deadline
;
18654 ------------------------
18655 -- Remote_Access_Type --
18656 ------------------------
18658 -- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME);
18660 when Pragma_Remote_Access_Type
=> Remote_Access_Type
: declare
18665 Check_Arg_Count
(1);
18666 Check_Optional_Identifier
(Arg1
, Name_Entity
);
18667 Check_Arg_Is_Local_Name
(Arg1
);
18669 E
:= Entity
(Get_Pragma_Arg
(Arg1
));
18671 if Nkind
(Parent
(E
)) = N_Formal_Type_Declaration
18672 and then Ekind
(E
) = E_General_Access_Type
18673 and then Is_Class_Wide_Type
(Directly_Designated_Type
(E
))
18674 and then Scope
(Root_Type
(Directly_Designated_Type
(E
)))
18676 and then Is_Valid_Remote_Object_Type
18677 (Root_Type
(Directly_Designated_Type
(E
)))
18679 Set_Is_Remote_Types
(E
);
18683 ("pragma% applies only to formal access to classwide types",
18686 end Remote_Access_Type
;
18688 ---------------------------
18689 -- Remote_Call_Interface --
18690 ---------------------------
18692 -- pragma Remote_Call_Interface [(library_unit_NAME)];
18694 when Pragma_Remote_Call_Interface
=> Remote_Call_Interface
: declare
18695 Cunit_Node
: Node_Id
;
18696 Cunit_Ent
: Entity_Id
;
18700 Check_Ada_83_Warning
;
18701 Check_Valid_Library_Unit_Pragma
;
18703 if Nkind
(N
) = N_Null_Statement
then
18707 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
18708 K
:= Nkind
(Unit
(Cunit_Node
));
18709 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
18711 if K
= N_Package_Declaration
18712 or else K
= N_Generic_Package_Declaration
18713 or else K
= N_Subprogram_Declaration
18714 or else K
= N_Generic_Subprogram_Declaration
18715 or else (K
= N_Subprogram_Body
18716 and then Acts_As_Spec
(Unit
(Cunit_Node
)))
18721 "pragma% must apply to package or subprogram declaration");
18724 Set_Is_Remote_Call_Interface
(Cunit_Ent
);
18725 end Remote_Call_Interface
;
18731 -- pragma Remote_Types [(library_unit_NAME)];
18733 when Pragma_Remote_Types
=> Remote_Types
: declare
18734 Cunit_Node
: Node_Id
;
18735 Cunit_Ent
: Entity_Id
;
18738 Check_Ada_83_Warning
;
18739 Check_Valid_Library_Unit_Pragma
;
18741 if Nkind
(N
) = N_Null_Statement
then
18745 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
18746 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
18748 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
18749 N_Generic_Package_Declaration
)
18752 ("pragma% can only apply to a package declaration");
18755 Set_Is_Remote_Types
(Cunit_Ent
);
18762 -- pragma Ravenscar;
18764 when Pragma_Ravenscar
=>
18766 Check_Arg_Count
(0);
18767 Check_Valid_Configuration_Pragma
;
18768 Set_Ravenscar_Profile
(N
);
18770 if Warn_On_Obsolescent_Feature
then
18772 ("pragma Ravenscar is an obsolescent feature?j?", N
);
18774 ("|use pragma Profile (Ravenscar) instead?j?", N
);
18777 -------------------------
18778 -- Restricted_Run_Time --
18779 -------------------------
18781 -- pragma Restricted_Run_Time;
18783 when Pragma_Restricted_Run_Time
=>
18785 Check_Arg_Count
(0);
18786 Check_Valid_Configuration_Pragma
;
18787 Set_Profile_Restrictions
18788 (Restricted
, N
, Warn
=> Treat_Restrictions_As_Warnings
);
18790 if Warn_On_Obsolescent_Feature
then
18792 ("pragma Restricted_Run_Time is an obsolescent feature?j?",
18795 ("|use pragma Profile (Restricted) instead?j?", N
);
18802 -- pragma Restrictions (RESTRICTION {, RESTRICTION});
18805 -- restriction_IDENTIFIER
18806 -- | restriction_parameter_IDENTIFIER => EXPRESSION
18808 when Pragma_Restrictions
=>
18809 Process_Restrictions_Or_Restriction_Warnings
18810 (Warn
=> Treat_Restrictions_As_Warnings
);
18812 --------------------------
18813 -- Restriction_Warnings --
18814 --------------------------
18816 -- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION});
18819 -- restriction_IDENTIFIER
18820 -- | restriction_parameter_IDENTIFIER => EXPRESSION
18822 when Pragma_Restriction_Warnings
=>
18824 Process_Restrictions_Or_Restriction_Warnings
(Warn
=> True);
18830 -- pragma Reviewable;
18832 when Pragma_Reviewable
=>
18833 Check_Ada_83_Warning
;
18834 Check_Arg_Count
(0);
18836 -- Call dummy debugging function rv. This is done to assist front
18837 -- end debugging. By placing a Reviewable pragma in the source
18838 -- program, a breakpoint on rv catches this place in the source,
18839 -- allowing convenient stepping to the point of interest.
18843 --------------------------
18844 -- Short_Circuit_And_Or --
18845 --------------------------
18847 -- pragma Short_Circuit_And_Or;
18849 when Pragma_Short_Circuit_And_Or
=>
18851 Check_Arg_Count
(0);
18852 Check_Valid_Configuration_Pragma
;
18853 Short_Circuit_And_Or
:= True;
18855 -------------------
18856 -- Share_Generic --
18857 -------------------
18859 -- pragma Share_Generic (GNAME {, GNAME});
18861 -- GNAME ::= generic_unit_NAME | generic_instance_NAME
18863 when Pragma_Share_Generic
=>
18865 Process_Generic_List
;
18871 -- pragma Shared (LOCAL_NAME);
18873 when Pragma_Shared
=>
18875 Process_Atomic_Independent_Shared_Volatile
;
18877 --------------------
18878 -- Shared_Passive --
18879 --------------------
18881 -- pragma Shared_Passive [(library_unit_NAME)];
18883 -- Set the flag Is_Shared_Passive of program unit name entity
18885 when Pragma_Shared_Passive
=> Shared_Passive
: declare
18886 Cunit_Node
: Node_Id
;
18887 Cunit_Ent
: Entity_Id
;
18890 Check_Ada_83_Warning
;
18891 Check_Valid_Library_Unit_Pragma
;
18893 if Nkind
(N
) = N_Null_Statement
then
18897 Cunit_Node
:= Cunit
(Current_Sem_Unit
);
18898 Cunit_Ent
:= Cunit_Entity
(Current_Sem_Unit
);
18900 if not Nkind_In
(Unit
(Cunit_Node
), N_Package_Declaration
,
18901 N_Generic_Package_Declaration
)
18904 ("pragma% can only apply to a package declaration");
18907 Set_Is_Shared_Passive
(Cunit_Ent
);
18908 end Shared_Passive
;
18910 -----------------------
18911 -- Short_Descriptors --
18912 -----------------------
18914 -- pragma Short_Descriptors;
18916 -- Recognize and validate, but otherwise ignore
18918 when Pragma_Short_Descriptors
=>
18920 Check_Arg_Count
(0);
18921 Check_Valid_Configuration_Pragma
;
18923 ------------------------------
18924 -- Simple_Storage_Pool_Type --
18925 ------------------------------
18927 -- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME);
18929 when Pragma_Simple_Storage_Pool_Type
=>
18930 Simple_Storage_Pool_Type
: declare
18936 Check_Arg_Count
(1);
18937 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
18939 Type_Id
:= Get_Pragma_Arg
(Arg1
);
18940 Find_Type
(Type_Id
);
18941 Typ
:= Entity
(Type_Id
);
18943 if Typ
= Any_Type
then
18947 -- We require the pragma to apply to a type declared in a package
18948 -- declaration, but not (immediately) within a package body.
18950 if Ekind
(Current_Scope
) /= E_Package
18951 or else In_Package_Body
(Current_Scope
)
18954 ("pragma% can only apply to type declared immediately "
18955 & "within a package declaration");
18958 -- A simple storage pool type must be an immutably limited record
18959 -- or private type. If the pragma is given for a private type,
18960 -- the full type is similarly restricted (which is checked later
18961 -- in Freeze_Entity).
18963 if Is_Record_Type
(Typ
)
18964 and then not Is_Limited_View
(Typ
)
18967 ("pragma% can only apply to explicitly limited record type");
18969 elsif Is_Private_Type
(Typ
) and then not Is_Limited_Type
(Typ
) then
18971 ("pragma% can only apply to a private type that is limited");
18973 elsif not Is_Record_Type
(Typ
)
18974 and then not Is_Private_Type
(Typ
)
18977 ("pragma% can only apply to limited record or private type");
18980 Record_Rep_Item
(Typ
, N
);
18981 end Simple_Storage_Pool_Type
;
18983 ----------------------
18984 -- Source_File_Name --
18985 ----------------------
18987 -- There are five forms for this pragma:
18989 -- pragma Source_File_Name (
18990 -- [UNIT_NAME =>] unit_NAME,
18991 -- BODY_FILE_NAME => STRING_LITERAL
18992 -- [, [INDEX =>] INTEGER_LITERAL]);
18994 -- pragma Source_File_Name (
18995 -- [UNIT_NAME =>] unit_NAME,
18996 -- SPEC_FILE_NAME => STRING_LITERAL
18997 -- [, [INDEX =>] INTEGER_LITERAL]);
18999 -- pragma Source_File_Name (
19000 -- BODY_FILE_NAME => STRING_LITERAL
19001 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19002 -- [, CASING => CASING_SPEC]);
19004 -- pragma Source_File_Name (
19005 -- SPEC_FILE_NAME => STRING_LITERAL
19006 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19007 -- [, CASING => CASING_SPEC]);
19009 -- pragma Source_File_Name (
19010 -- SUBUNIT_FILE_NAME => STRING_LITERAL
19011 -- [, DOT_REPLACEMENT => STRING_LITERAL]
19012 -- [, CASING => CASING_SPEC]);
19014 -- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase
19016 -- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma
19017 -- Source_File_Name (SFN), however their usage is exclusive: SFN can
19018 -- only be used when no project file is used, while SFNP can only be
19019 -- used when a project file is used.
19021 -- No processing here. Processing was completed during parsing, since
19022 -- we need to have file names set as early as possible. Units are
19023 -- loaded well before semantic processing starts.
19025 -- The only processing we defer to this point is the check for
19026 -- correct placement.
19028 when Pragma_Source_File_Name
=>
19030 Check_Valid_Configuration_Pragma
;
19032 ------------------------------
19033 -- Source_File_Name_Project --
19034 ------------------------------
19036 -- See Source_File_Name for syntax
19038 -- No processing here. Processing was completed during parsing, since
19039 -- we need to have file names set as early as possible. Units are
19040 -- loaded well before semantic processing starts.
19042 -- The only processing we defer to this point is the check for
19043 -- correct placement.
19045 when Pragma_Source_File_Name_Project
=>
19047 Check_Valid_Configuration_Pragma
;
19049 -- Check that a pragma Source_File_Name_Project is used only in a
19050 -- configuration pragmas file.
19052 -- Pragmas Source_File_Name_Project should only be generated by
19053 -- the Project Manager in configuration pragmas files.
19055 -- This is really an ugly test. It seems to depend on some
19056 -- accidental and undocumented property. At the very least it
19057 -- needs to be documented, but it would be better to have a
19058 -- clean way of testing if we are in a configuration file???
19060 if Present
(Parent
(N
)) then
19062 ("pragma% can only appear in a configuration pragmas file");
19065 ----------------------
19066 -- Source_Reference --
19067 ----------------------
19069 -- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]);
19071 -- Nothing to do, all processing completed in Par.Prag, since we need
19072 -- the information for possible parser messages that are output.
19074 when Pragma_Source_Reference
=>
19081 -- pragma SPARK_Mode [(On | Off)];
19083 when Pragma_SPARK_Mode
=> Do_SPARK_Mode
: declare
19084 Mode_Id
: SPARK_Mode_Type
;
19086 procedure Check_Pragma_Conformance
19087 (Context_Pragma
: Node_Id
;
19088 Entity_Pragma
: Node_Id
;
19089 Entity
: Entity_Id
);
19090 -- If Context_Pragma is not Empty, verify that the new pragma N
19091 -- is compatible with the pragma Context_Pragma that was inherited
19092 -- from the context:
19093 -- . if Context_Pragma is ON, then the new mode can be anything
19094 -- . if Context_Pragma is OFF, then the only allowed new mode is
19097 -- If Entity is not Empty, verify that the new pragma N is
19098 -- compatible with Entity_Pragma, the SPARK_Mode previously set
19099 -- for Entity (which may be Empty):
19100 -- . if Entity_Pragma is ON, then the new mode can be anything
19101 -- . if Entity_Pragma is OFF, then the only allowed new mode is
19103 -- . if Entity_Pragma is Empty, we always issue an error, as this
19104 -- corresponds to a case where a previous section of Entity
19105 -- had no SPARK_Mode set.
19107 procedure Check_Library_Level_Entity
(E
: Entity_Id
);
19108 -- Verify that pragma is applied to library-level entity E
19110 procedure Set_SPARK_Flags
;
19111 -- Sets SPARK_Mode from Mode_Id and SPARK_Mode_Pragma from N,
19112 -- and ensures that Dynamic_Elaboration_Checks are off if the
19113 -- call sets SPARK_Mode On.
19115 ------------------------------
19116 -- Check_Pragma_Conformance --
19117 ------------------------------
19119 procedure Check_Pragma_Conformance
19120 (Context_Pragma
: Node_Id
;
19121 Entity_Pragma
: Node_Id
;
19122 Entity
: Entity_Id
)
19124 Arg
: Node_Id
:= Arg1
;
19127 -- The current pragma may appear without an argument. If this
19128 -- is the case, associate all error messages with the pragma
19135 -- The mode of the current pragma is compared against that of
19136 -- an enclosing context.
19138 if Present
(Context_Pragma
) then
19139 pragma Assert
(Nkind
(Context_Pragma
) = N_Pragma
);
19141 -- Issue an error if the new mode is less restrictive than
19142 -- that of the context.
19144 if Get_SPARK_Mode_From_Pragma
(Context_Pragma
) = Off
19145 and then Get_SPARK_Mode_From_Pragma
(N
) = On
19148 ("cannot change SPARK_Mode from Off to On", Arg
);
19149 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
19150 Error_Msg_N
("\SPARK_Mode was set to Off#", Arg
);
19155 -- The mode of the current pragma is compared against that of
19156 -- an initial package/subprogram declaration.
19158 if Present
(Entity
) then
19160 -- Both the initial declaration and the completion carry
19161 -- SPARK_Mode pragmas.
19163 if Present
(Entity_Pragma
) then
19164 pragma Assert
(Nkind
(Entity_Pragma
) = N_Pragma
);
19166 -- Issue an error if the new mode is less restrictive
19167 -- than that of the initial declaration.
19169 if Get_SPARK_Mode_From_Pragma
(Entity_Pragma
) = Off
19170 and then Get_SPARK_Mode_From_Pragma
(N
) = On
19172 Error_Msg_N
("incorrect use of SPARK_Mode", Arg
);
19173 Error_Msg_Sloc
:= Sloc
(Entity_Pragma
);
19175 ("\value Off was set for SPARK_Mode on&#",
19180 -- Otherwise the initial declaration lacks a SPARK_Mode
19181 -- pragma in which case the current pragma is illegal as
19182 -- it cannot "complete".
19185 Error_Msg_N
("incorrect use of SPARK_Mode", Arg
);
19186 Error_Msg_Sloc
:= Sloc
(Entity
);
19188 ("\no value was set for SPARK_Mode on&#",
19193 end Check_Pragma_Conformance
;
19195 --------------------------------
19196 -- Check_Library_Level_Entity --
19197 --------------------------------
19199 procedure Check_Library_Level_Entity
(E
: Entity_Id
) is
19200 MsgF
: constant String := "incorrect placement of pragma%";
19203 if not Is_Library_Level_Entity
(E
) then
19204 Error_Msg_Name_1
:= Pname
;
19205 Error_Msg_N
(Fix_Error
(MsgF
), N
);
19207 if Ekind_In
(E
, E_Generic_Package
,
19212 ("\& is not a library-level package", N
, E
);
19215 ("\& is not a library-level subprogram", N
, E
);
19220 end Check_Library_Level_Entity
;
19222 ---------------------
19223 -- Set_SPARK_Flags --
19224 ---------------------
19226 procedure Set_SPARK_Flags
is
19228 SPARK_Mode
:= Mode_Id
;
19229 SPARK_Mode_Pragma
:= N
;
19231 if SPARK_Mode
= On
then
19232 Dynamic_Elaboration_Checks
:= False;
19234 end Set_SPARK_Flags
;
19238 Body_Id
: Entity_Id
;
19241 Spec_Id
: Entity_Id
;
19244 -- Start of processing for Do_SPARK_Mode
19247 -- When a SPARK_Mode pragma appears inside an instantiation whose
19248 -- enclosing context has SPARK_Mode set to "off", the pragma has
19249 -- no semantic effect.
19251 if Ignore_Pragma_SPARK_Mode
then
19252 Rewrite
(N
, Make_Null_Statement
(Loc
));
19258 Check_No_Identifiers
;
19259 Check_At_Most_N_Arguments
(1);
19261 -- Check the legality of the mode (no argument = ON)
19263 if Arg_Count
= 1 then
19264 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
19265 Mode
:= Chars
(Get_Pragma_Arg
(Arg1
));
19270 Mode_Id
:= Get_SPARK_Mode_Type
(Mode
);
19271 Context
:= Parent
(N
);
19273 -- The pragma appears in a configuration pragmas file
19275 if No
(Context
) then
19276 Check_Valid_Configuration_Pragma
;
19278 if Present
(SPARK_Mode_Pragma
) then
19279 Error_Msg_Sloc
:= Sloc
(SPARK_Mode_Pragma
);
19280 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
19286 -- The pragma acts as a configuration pragma in a compilation unit
19288 -- pragma SPARK_Mode ...;
19289 -- package Pack is ...;
19291 elsif Nkind
(Context
) = N_Compilation_Unit
19292 and then List_Containing
(N
) = Context_Items
(Context
)
19294 Check_Valid_Configuration_Pragma
;
19297 -- Otherwise the placement of the pragma within the tree dictates
19298 -- its associated construct. Inspect the declarative list where
19299 -- the pragma resides to find a potential construct.
19303 while Present
(Stmt
) loop
19305 -- Skip prior pragmas, but check for duplicates
19307 if Nkind
(Stmt
) = N_Pragma
then
19308 if Pragma_Name
(Stmt
) = Pname
then
19309 Error_Msg_Name_1
:= Pname
;
19310 Error_Msg_Sloc
:= Sloc
(Stmt
);
19311 Error_Msg_N
("pragma% duplicates pragma declared#", N
);
19315 -- The pragma applies to a [generic] subprogram declaration.
19316 -- Note that this case covers an internally generated spec
19317 -- for a stand alone body.
19320 -- procedure Proc ...;
19321 -- pragma SPARK_Mode ..;
19323 elsif Nkind_In
(Stmt
, N_Generic_Subprogram_Declaration
,
19324 N_Subprogram_Declaration
)
19326 Spec_Id
:= Defining_Entity
(Stmt
);
19327 Check_Library_Level_Entity
(Spec_Id
);
19328 Check_Pragma_Conformance
19329 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
19330 Entity_Pragma
=> Empty
,
19333 Set_SPARK_Pragma
(Spec_Id
, N
);
19334 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
19337 -- Skip internally generated code
19339 elsif not Comes_From_Source
(Stmt
) then
19342 -- Otherwise the pragma does not apply to a legal construct
19343 -- or it does not appear at the top of a declarative or a
19344 -- statement list. Issue an error and stop the analysis.
19354 -- The pragma applies to a package or a subprogram that acts as
19355 -- a compilation unit.
19357 -- procedure Proc ...;
19358 -- pragma SPARK_Mode ...;
19360 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
19361 Context
:= Unit
(Parent
(Context
));
19364 -- The pragma appears within package declarations
19366 if Nkind
(Context
) = N_Package_Specification
then
19367 Spec_Id
:= Defining_Entity
(Context
);
19368 Check_Library_Level_Entity
(Spec_Id
);
19370 -- The pragma is at the top of the visible declarations
19373 -- pragma SPARK_Mode ...;
19375 if List_Containing
(N
) = Visible_Declarations
(Context
) then
19376 Check_Pragma_Conformance
19377 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
19378 Entity_Pragma
=> Empty
,
19382 Set_SPARK_Pragma
(Spec_Id
, N
);
19383 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
19384 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
19385 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, True);
19387 -- The pragma is at the top of the private declarations
19391 -- pragma SPARK_Mode ...;
19394 Check_Pragma_Conformance
19395 (Context_Pragma
=> Empty
,
19396 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
),
19397 Entity
=> Spec_Id
);
19400 Set_SPARK_Aux_Pragma
(Spec_Id
, N
);
19401 Set_SPARK_Aux_Pragma_Inherited
(Spec_Id
, False);
19404 -- The pragma appears at the top of package body declarations
19406 -- package body Pack is
19407 -- pragma SPARK_Mode ...;
19409 elsif Nkind
(Context
) = N_Package_Body
then
19410 Spec_Id
:= Corresponding_Spec
(Context
);
19411 Body_Id
:= Defining_Entity
(Context
);
19412 Check_Library_Level_Entity
(Body_Id
);
19413 Check_Pragma_Conformance
19414 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
19415 Entity_Pragma
=> SPARK_Aux_Pragma
(Spec_Id
),
19416 Entity
=> Spec_Id
);
19419 Set_SPARK_Pragma
(Body_Id
, N
);
19420 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
19421 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
19422 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, True);
19424 -- The pragma appears at the top of package body statements
19426 -- package body Pack is
19428 -- pragma SPARK_Mode;
19430 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
19431 and then Nkind
(Parent
(Context
)) = N_Package_Body
19433 Context
:= Parent
(Context
);
19434 Spec_Id
:= Corresponding_Spec
(Context
);
19435 Body_Id
:= Defining_Entity
(Context
);
19436 Check_Library_Level_Entity
(Body_Id
);
19437 Check_Pragma_Conformance
19438 (Context_Pragma
=> Empty
,
19439 Entity_Pragma
=> SPARK_Pragma
(Body_Id
),
19440 Entity
=> Body_Id
);
19443 Set_SPARK_Aux_Pragma
(Body_Id
, N
);
19444 Set_SPARK_Aux_Pragma_Inherited
(Body_Id
, False);
19446 -- The pragma appeared as an aspect of a [generic] subprogram
19447 -- declaration that acts as a compilation unit.
19450 -- procedure Proc ...;
19451 -- pragma SPARK_Mode ...;
19453 elsif Nkind_In
(Context
, N_Generic_Subprogram_Declaration
,
19454 N_Subprogram_Declaration
)
19456 Spec_Id
:= Defining_Entity
(Context
);
19457 Check_Library_Level_Entity
(Spec_Id
);
19458 Check_Pragma_Conformance
19459 (Context_Pragma
=> SPARK_Pragma
(Spec_Id
),
19460 Entity_Pragma
=> Empty
,
19463 Set_SPARK_Pragma
(Spec_Id
, N
);
19464 Set_SPARK_Pragma_Inherited
(Spec_Id
, False);
19466 -- The pragma appears at the top of subprogram body
19469 -- procedure Proc ... is
19470 -- pragma SPARK_Mode;
19472 elsif Nkind
(Context
) = N_Subprogram_Body
then
19473 Spec_Id
:= Corresponding_Spec
(Context
);
19474 Context
:= Specification
(Context
);
19475 Body_Id
:= Defining_Entity
(Context
);
19477 -- Ignore pragma when applied to the special body created
19478 -- for inlining, recognized by its internal name _Parent.
19480 if Chars
(Body_Id
) = Name_uParent
then
19484 Check_Library_Level_Entity
(Body_Id
);
19486 -- The body is a completion of a previous declaration
19488 if Present
(Spec_Id
) then
19489 Check_Pragma_Conformance
19490 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
19491 Entity_Pragma
=> SPARK_Pragma
(Spec_Id
),
19492 Entity
=> Spec_Id
);
19494 -- The body acts as spec
19497 Check_Pragma_Conformance
19498 (Context_Pragma
=> SPARK_Pragma
(Body_Id
),
19499 Entity_Pragma
=> Empty
,
19505 Set_SPARK_Pragma
(Body_Id
, N
);
19506 Set_SPARK_Pragma_Inherited
(Body_Id
, False);
19508 -- The pragma does not apply to a legal construct, issue error
19516 --------------------------------
19517 -- Static_Elaboration_Desired --
19518 --------------------------------
19520 -- pragma Static_Elaboration_Desired (DIRECT_NAME);
19522 when Pragma_Static_Elaboration_Desired
=>
19524 Check_At_Most_N_Arguments
(1);
19526 if Is_Compilation_Unit
(Current_Scope
)
19527 and then Ekind
(Current_Scope
) = E_Package
19529 Set_Static_Elaboration_Desired
(Current_Scope
, True);
19531 Error_Pragma
("pragma% must apply to a library-level package");
19538 -- pragma Storage_Size (EXPRESSION);
19540 when Pragma_Storage_Size
=> Storage_Size
: declare
19541 P
: constant Node_Id
:= Parent
(N
);
19545 Check_No_Identifiers
;
19546 Check_Arg_Count
(1);
19548 -- The expression must be analyzed in the special manner described
19549 -- in "Handling of Default Expressions" in sem.ads.
19551 Arg
:= Get_Pragma_Arg
(Arg1
);
19552 Preanalyze_Spec_Expression
(Arg
, Any_Integer
);
19554 if not Is_OK_Static_Expression
(Arg
) then
19555 Check_Restriction
(Static_Storage_Size
, Arg
);
19558 if Nkind
(P
) /= N_Task_Definition
then
19563 if Has_Storage_Size_Pragma
(P
) then
19564 Error_Pragma
("duplicate pragma% not allowed");
19566 Set_Has_Storage_Size_Pragma
(P
, True);
19569 Record_Rep_Item
(Defining_Identifier
(Parent
(P
)), N
);
19577 -- pragma Storage_Unit (NUMERIC_LITERAL);
19579 -- Only permitted argument is System'Storage_Unit value
19581 when Pragma_Storage_Unit
=>
19582 Check_No_Identifiers
;
19583 Check_Arg_Count
(1);
19584 Check_Arg_Is_Integer_Literal
(Arg1
);
19586 if Intval
(Get_Pragma_Arg
(Arg1
)) /=
19587 UI_From_Int
(Ttypes
.System_Storage_Unit
)
19589 Error_Msg_Uint_1
:= UI_From_Int
(Ttypes
.System_Storage_Unit
);
19591 ("the only allowed argument for pragma% is ^", Arg1
);
19594 --------------------
19595 -- Stream_Convert --
19596 --------------------
19598 -- pragma Stream_Convert (
19599 -- [Entity =>] type_LOCAL_NAME,
19600 -- [Read =>] function_NAME,
19601 -- [Write =>] function NAME);
19603 when Pragma_Stream_Convert
=> Stream_Convert
: declare
19605 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
);
19606 -- Check that the given argument is the name of a local function
19607 -- of one argument that is not overloaded earlier in the current
19608 -- local scope. A check is also made that the argument is a
19609 -- function with one parameter.
19611 --------------------------------------
19612 -- Check_OK_Stream_Convert_Function --
19613 --------------------------------------
19615 procedure Check_OK_Stream_Convert_Function
(Arg
: Node_Id
) is
19619 Check_Arg_Is_Local_Name
(Arg
);
19620 Ent
:= Entity
(Get_Pragma_Arg
(Arg
));
19622 if Has_Homonym
(Ent
) then
19624 ("argument for pragma% may not be overloaded", Arg
);
19627 if Ekind
(Ent
) /= E_Function
19628 or else No
(First_Formal
(Ent
))
19629 or else Present
(Next_Formal
(First_Formal
(Ent
)))
19632 ("argument for pragma% must be function of one argument",
19635 end Check_OK_Stream_Convert_Function
;
19637 -- Start of processing for Stream_Convert
19641 Check_Arg_Order
((Name_Entity
, Name_Read
, Name_Write
));
19642 Check_Arg_Count
(3);
19643 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19644 Check_Optional_Identifier
(Arg2
, Name_Read
);
19645 Check_Optional_Identifier
(Arg3
, Name_Write
);
19646 Check_Arg_Is_Local_Name
(Arg1
);
19647 Check_OK_Stream_Convert_Function
(Arg2
);
19648 Check_OK_Stream_Convert_Function
(Arg3
);
19651 Typ
: constant Entity_Id
:=
19652 Underlying_Type
(Entity
(Get_Pragma_Arg
(Arg1
)));
19653 Read
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg2
));
19654 Write
: constant Entity_Id
:= Entity
(Get_Pragma_Arg
(Arg3
));
19657 Check_First_Subtype
(Arg1
);
19659 -- Check for too early or too late. Note that we don't enforce
19660 -- the rule about primitive operations in this case, since, as
19661 -- is the case for explicit stream attributes themselves, these
19662 -- restrictions are not appropriate. Note that the chaining of
19663 -- the pragma by Rep_Item_Too_Late is actually the critical
19664 -- processing done for this pragma.
19666 if Rep_Item_Too_Early
(Typ
, N
)
19668 Rep_Item_Too_Late
(Typ
, N
, FOnly
=> True)
19673 -- Return if previous error
19675 if Etype
(Typ
) = Any_Type
19677 Etype
(Read
) = Any_Type
19679 Etype
(Write
) = Any_Type
19686 if Underlying_Type
(Etype
(Read
)) /= Typ
then
19688 ("incorrect return type for function&", Arg2
);
19691 if Underlying_Type
(Etype
(First_Formal
(Write
))) /= Typ
then
19693 ("incorrect parameter type for function&", Arg3
);
19696 if Underlying_Type
(Etype
(First_Formal
(Read
))) /=
19697 Underlying_Type
(Etype
(Write
))
19700 ("result type of & does not match Read parameter type",
19704 end Stream_Convert
;
19710 -- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
19712 -- This is processed by the parser since some of the style checks
19713 -- take place during source scanning and parsing. This means that
19714 -- we don't need to issue error messages here.
19716 when Pragma_Style_Checks
=> Style_Checks
: declare
19717 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
19723 Check_No_Identifiers
;
19725 -- Two argument form
19727 if Arg_Count
= 2 then
19728 Check_Arg_Is_One_Of
(Arg1
, Name_On
, Name_Off
);
19735 E_Id
:= Get_Pragma_Arg
(Arg2
);
19738 if not Is_Entity_Name
(E_Id
) then
19740 ("second argument of pragma% must be entity name",
19744 E
:= Entity
(E_Id
);
19746 if not Ignore_Style_Checks_Pragmas
then
19751 Set_Suppress_Style_Checks
19752 (E
, Chars
(Get_Pragma_Arg
(Arg1
)) = Name_Off
);
19753 exit when No
(Homonym
(E
));
19760 -- One argument form
19763 Check_Arg_Count
(1);
19765 if Nkind
(A
) = N_String_Literal
then
19769 Slen
: constant Natural := Natural (String_Length
(S
));
19770 Options
: String (1 .. Slen
);
19776 C
:= Get_String_Char
(S
, Int
(J
));
19777 exit when not In_Character_Range
(C
);
19778 Options
(J
) := Get_Character
(C
);
19780 -- If at end of string, set options. As per discussion
19781 -- above, no need to check for errors, since we issued
19782 -- them in the parser.
19785 if not Ignore_Style_Checks_Pragmas
then
19786 Set_Style_Check_Options
(Options
);
19796 elsif Nkind
(A
) = N_Identifier
then
19797 if Chars
(A
) = Name_All_Checks
then
19798 if not Ignore_Style_Checks_Pragmas
then
19800 Set_GNAT_Style_Check_Options
;
19802 Set_Default_Style_Check_Options
;
19806 elsif Chars
(A
) = Name_On
then
19807 if not Ignore_Style_Checks_Pragmas
then
19808 Style_Check
:= True;
19811 elsif Chars
(A
) = Name_Off
then
19812 if not Ignore_Style_Checks_Pragmas
then
19813 Style_Check
:= False;
19824 -- pragma Subtitle ([Subtitle =>] STRING_LITERAL);
19826 when Pragma_Subtitle
=>
19828 Check_Arg_Count
(1);
19829 Check_Optional_Identifier
(Arg1
, Name_Subtitle
);
19830 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
19837 -- pragma Suppress (IDENTIFIER [, [On =>] NAME]);
19839 when Pragma_Suppress
=>
19840 Process_Suppress_Unsuppress
(Suppress_Case
=> True);
19846 -- pragma Suppress_All;
19848 -- The only check made here is that the pragma has no arguments.
19849 -- There are no placement rules, and the processing required (setting
19850 -- the Has_Pragma_Suppress_All flag in the compilation unit node was
19851 -- taken care of by the parser). Process_Compilation_Unit_Pragmas
19852 -- then creates and inserts a pragma Suppress (All_Checks).
19854 when Pragma_Suppress_All
=>
19856 Check_Arg_Count
(0);
19858 -------------------------
19859 -- Suppress_Debug_Info --
19860 -------------------------
19862 -- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME);
19864 when Pragma_Suppress_Debug_Info
=>
19866 Check_Arg_Count
(1);
19867 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19868 Check_Arg_Is_Local_Name
(Arg1
);
19869 Set_Debug_Info_Off
(Entity
(Get_Pragma_Arg
(Arg1
)));
19871 ----------------------------------
19872 -- Suppress_Exception_Locations --
19873 ----------------------------------
19875 -- pragma Suppress_Exception_Locations;
19877 when Pragma_Suppress_Exception_Locations
=>
19879 Check_Arg_Count
(0);
19880 Check_Valid_Configuration_Pragma
;
19881 Exception_Locations_Suppressed
:= True;
19883 -----------------------------
19884 -- Suppress_Initialization --
19885 -----------------------------
19887 -- pragma Suppress_Initialization ([Entity =>] type_Name);
19889 when Pragma_Suppress_Initialization
=> Suppress_Init
: declare
19895 Check_Arg_Count
(1);
19896 Check_Optional_Identifier
(Arg1
, Name_Entity
);
19897 Check_Arg_Is_Local_Name
(Arg1
);
19899 E_Id
:= Get_Pragma_Arg
(Arg1
);
19901 if Etype
(E_Id
) = Any_Type
then
19905 E
:= Entity
(E_Id
);
19907 if not Is_Type
(E
) and then Ekind
(E
) /= E_Variable
then
19909 ("pragma% requires variable, type or subtype", Arg1
);
19912 if Rep_Item_Too_Early
(E
, N
)
19914 Rep_Item_Too_Late
(E
, N
, FOnly
=> True)
19919 -- For incomplete/private type, set flag on full view
19921 if Is_Incomplete_Or_Private_Type
(E
) then
19922 if No
(Full_View
(Base_Type
(E
))) then
19924 ("argument of pragma% cannot be an incomplete type", Arg1
);
19926 Set_Suppress_Initialization
(Full_View
(Base_Type
(E
)));
19929 -- For first subtype, set flag on base type
19931 elsif Is_First_Subtype
(E
) then
19932 Set_Suppress_Initialization
(Base_Type
(E
));
19934 -- For other than first subtype, set flag on subtype or variable
19937 Set_Suppress_Initialization
(E
);
19945 -- pragma System_Name (DIRECT_NAME);
19947 -- Syntax check: one argument, which must be the identifier GNAT or
19948 -- the identifier GCC, no other identifiers are acceptable.
19950 when Pragma_System_Name
=>
19952 Check_No_Identifiers
;
19953 Check_Arg_Count
(1);
19954 Check_Arg_Is_One_Of
(Arg1
, Name_Gcc
, Name_Gnat
);
19956 -----------------------------
19957 -- Task_Dispatching_Policy --
19958 -----------------------------
19960 -- pragma Task_Dispatching_Policy (policy_IDENTIFIER);
19962 when Pragma_Task_Dispatching_Policy
=> declare
19966 Check_Ada_83_Warning
;
19967 Check_Arg_Count
(1);
19968 Check_No_Identifiers
;
19969 Check_Arg_Is_Task_Dispatching_Policy
(Arg1
);
19970 Check_Valid_Configuration_Pragma
;
19971 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
19972 DP
:= Fold_Upper
(Name_Buffer
(1));
19974 if Task_Dispatching_Policy
/= ' '
19975 and then Task_Dispatching_Policy
/= DP
19977 Error_Msg_Sloc
:= Task_Dispatching_Policy_Sloc
;
19979 ("task dispatching policy incompatible with policy#");
19981 -- Set new policy, but always preserve System_Location since we
19982 -- like the error message with the run time name.
19985 Task_Dispatching_Policy
:= DP
;
19987 if Task_Dispatching_Policy_Sloc
/= System_Location
then
19988 Task_Dispatching_Policy_Sloc
:= Loc
;
19997 -- pragma Task_Info (EXPRESSION);
19999 when Pragma_Task_Info
=> Task_Info
: declare
20000 P
: constant Node_Id
:= Parent
(N
);
20006 if Warn_On_Obsolescent_Feature
then
20008 ("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U "
20009 & "instead?j?", N
);
20012 if Nkind
(P
) /= N_Task_Definition
then
20013 Error_Pragma
("pragma% must appear in task definition");
20016 Check_No_Identifiers
;
20017 Check_Arg_Count
(1);
20019 Analyze_And_Resolve
20020 (Get_Pragma_Arg
(Arg1
), RTE
(RE_Task_Info_Type
));
20022 if Etype
(Get_Pragma_Arg
(Arg1
)) = Any_Type
then
20026 Ent
:= Defining_Identifier
(Parent
(P
));
20028 -- Check duplicate pragma before we chain the pragma in the Rep
20029 -- Item chain of Ent.
20032 (Ent
, Name_Task_Info
, Check_Parents
=> False)
20034 Error_Pragma
("duplicate pragma% not allowed");
20037 Record_Rep_Item
(Ent
, N
);
20044 -- pragma Task_Name (string_EXPRESSION);
20046 when Pragma_Task_Name
=> Task_Name
: declare
20047 P
: constant Node_Id
:= Parent
(N
);
20052 Check_No_Identifiers
;
20053 Check_Arg_Count
(1);
20055 Arg
:= Get_Pragma_Arg
(Arg1
);
20057 -- The expression is used in the call to Create_Task, and must be
20058 -- expanded there, not in the context of the current spec. It must
20059 -- however be analyzed to capture global references, in case it
20060 -- appears in a generic context.
20062 Preanalyze_And_Resolve
(Arg
, Standard_String
);
20064 if Nkind
(P
) /= N_Task_Definition
then
20068 Ent
:= Defining_Identifier
(Parent
(P
));
20070 -- Check duplicate pragma before we chain the pragma in the Rep
20071 -- Item chain of Ent.
20074 (Ent
, Name_Task_Name
, Check_Parents
=> False)
20076 Error_Pragma
("duplicate pragma% not allowed");
20079 Record_Rep_Item
(Ent
, N
);
20086 -- pragma Task_Storage (
20087 -- [Task_Type =>] LOCAL_NAME,
20088 -- [Top_Guard =>] static_integer_EXPRESSION);
20090 when Pragma_Task_Storage
=> Task_Storage
: declare
20091 Args
: Args_List
(1 .. 2);
20092 Names
: constant Name_List
(1 .. 2) := (
20096 Task_Type
: Node_Id
renames Args
(1);
20097 Top_Guard
: Node_Id
renames Args
(2);
20103 Gather_Associations
(Names
, Args
);
20105 if No
(Task_Type
) then
20107 ("missing task_type argument for pragma%");
20110 Check_Arg_Is_Local_Name
(Task_Type
);
20112 Ent
:= Entity
(Task_Type
);
20114 if not Is_Task_Type
(Ent
) then
20116 ("argument for pragma% must be task type", Task_Type
);
20119 if No
(Top_Guard
) then
20121 ("pragma% takes two arguments", Task_Type
);
20123 Check_Arg_Is_OK_Static_Expression
(Top_Guard
, Any_Integer
);
20126 Check_First_Subtype
(Task_Type
);
20128 if Rep_Item_Too_Late
(Ent
, N
) then
20137 -- pragma Test_Case
20138 -- ([Name =>] Static_String_EXPRESSION
20139 -- ,[Mode =>] MODE_TYPE
20140 -- [, Requires => Boolean_EXPRESSION]
20141 -- [, Ensures => Boolean_EXPRESSION]);
20143 -- MODE_TYPE ::= Nominal | Robustness
20145 when Pragma_Test_Case
=> Test_Case
: declare
20146 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
);
20147 -- Ensure that the contract of subprogram Subp_Id does not contain
20148 -- another Test_Case pragma with the same Name as the current one.
20150 -------------------------
20151 -- Check_Distinct_Name --
20152 -------------------------
20154 procedure Check_Distinct_Name
(Subp_Id
: Entity_Id
) is
20155 Items
: constant Node_Id
:= Contract
(Subp_Id
);
20156 Name
: constant String_Id
:= Get_Name_From_CTC_Pragma
(N
);
20160 -- Inspect all Test_Case pragma of the related subprogram
20161 -- looking for one with a duplicate "Name" argument.
20163 if Present
(Items
) then
20164 Prag
:= Contract_Test_Cases
(Items
);
20165 while Present
(Prag
) loop
20166 if Pragma_Name
(Prag
) = Name_Test_Case
20167 and then String_Equal
20168 (Name
, Get_Name_From_CTC_Pragma
(Prag
))
20170 Error_Msg_Sloc
:= Sloc
(Prag
);
20171 Error_Pragma
("name for pragma % is already used #");
20174 Prag
:= Next_Pragma
(Prag
);
20177 end Check_Distinct_Name
;
20181 Pack_Decl
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
20184 Subp_Decl
: Node_Id
;
20185 Subp_Id
: Entity_Id
;
20187 -- Start of processing for Test_Case
20191 Check_At_Least_N_Arguments
(2);
20192 Check_At_Most_N_Arguments
(4);
20194 ((Name_Name
, Name_Mode
, Name_Requires
, Name_Ensures
));
20198 Check_Optional_Identifier
(Arg1
, Name_Name
);
20199 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_String
);
20203 Check_Optional_Identifier
(Arg2
, Name_Mode
);
20204 Check_Arg_Is_One_Of
(Arg2
, Name_Nominal
, Name_Robustness
);
20206 -- Arguments "Requires" and "Ensures"
20208 if Present
(Arg3
) then
20209 if Present
(Arg4
) then
20210 Check_Identifier
(Arg3
, Name_Requires
);
20211 Check_Identifier
(Arg4
, Name_Ensures
);
20213 Check_Identifier_Is_One_Of
20214 (Arg3
, Name_Requires
, Name_Ensures
);
20218 -- Pragma Test_Case must be associated with a subprogram declared
20219 -- in a library-level package. First determine whether the current
20220 -- compilation unit is a legal context.
20222 if Nkind_In
(Pack_Decl
, N_Package_Declaration
,
20223 N_Generic_Package_Declaration
)
20227 -- Otherwise the placement is illegal
20234 Subp_Decl
:= Find_Related_Subprogram_Or_Body
(N
);
20236 -- Find the enclosing context
20238 Context
:= Parent
(Subp_Decl
);
20240 if Present
(Context
) then
20241 Context
:= Parent
(Context
);
20244 -- Verify the placement of the pragma
20246 if Nkind
(Subp_Decl
) = N_Abstract_Subprogram_Declaration
then
20248 ("pragma % cannot be applied to abstract subprogram");
20251 elsif Nkind
(Subp_Decl
) = N_Entry_Declaration
then
20252 Error_Pragma
("pragma % cannot be applied to entry");
20255 -- The context is a [generic] subprogram declared at the top level
20256 -- of the [generic] package unit.
20258 elsif Nkind_In
(Subp_Decl
, N_Generic_Subprogram_Declaration
,
20259 N_Subprogram_Declaration
)
20260 and then Present
(Context
)
20261 and then Nkind_In
(Context
, N_Generic_Package_Declaration
,
20262 N_Package_Declaration
)
20264 Subp_Id
:= Defining_Entity
(Subp_Decl
);
20266 -- Otherwise the placement is illegal
20273 -- Preanalyze the original aspect argument "Name" for ASIS or for
20274 -- a generic subprogram to properly capture global references.
20276 if ASIS_Mode
or else Is_Generic_Subprogram
(Subp_Id
) then
20277 Asp_Arg
:= Test_Case_Arg
(N
, Name_Name
, From_Aspect
=> True);
20279 if Present
(Asp_Arg
) then
20281 -- The argument appears with an identifier in association
20284 if Nkind
(Asp_Arg
) = N_Component_Association
then
20285 Asp_Arg
:= Expression
(Asp_Arg
);
20288 Check_Expr_Is_OK_Static_Expression
20289 (Asp_Arg
, Standard_String
);
20293 -- Ensure that the all Test_Case pragmas of the related subprogram
20294 -- have distinct names.
20296 Check_Distinct_Name
(Subp_Id
);
20298 -- Construct a generic template for the pragma when the context is
20299 -- a generic subprogram and the pragma is a source construct.
20301 Create_Generic_Template
(N
, Subp_Id
);
20303 -- Fully analyze the pragma when it appears inside a subprogram
20304 -- body because it cannot benefit from forward references.
20306 if Nkind_In
(Subp_Decl
, N_Subprogram_Body
,
20307 N_Subprogram_Body_Stub
)
20309 Analyze_Test_Case_In_Decl_Part
(N
);
20312 -- Chain the pragma on the contract for further processing
20314 Add_Contract_Item
(N
, Subp_Id
);
20317 --------------------------
20318 -- Thread_Local_Storage --
20319 --------------------------
20321 -- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
20323 when Pragma_Thread_Local_Storage
=> Thread_Local_Storage
: declare
20329 Check_Arg_Count
(1);
20330 Check_Optional_Identifier
(Arg1
, Name_Entity
);
20331 Check_Arg_Is_Library_Level_Local_Name
(Arg1
);
20333 Id
:= Get_Pragma_Arg
(Arg1
);
20336 if not Is_Entity_Name
(Id
)
20337 or else Ekind
(Entity
(Id
)) /= E_Variable
20339 Error_Pragma_Arg
("local variable name required", Arg1
);
20344 if Rep_Item_Too_Early
(E
, N
)
20345 or else Rep_Item_Too_Late
(E
, N
)
20350 Set_Has_Pragma_Thread_Local_Storage
(E
);
20351 Set_Has_Gigi_Rep_Item
(E
);
20352 end Thread_Local_Storage
;
20358 -- pragma Time_Slice (static_duration_EXPRESSION);
20360 when Pragma_Time_Slice
=> Time_Slice
: declare
20366 Check_Arg_Count
(1);
20367 Check_No_Identifiers
;
20368 Check_In_Main_Program
;
20369 Check_Arg_Is_OK_Static_Expression
(Arg1
, Standard_Duration
);
20371 if not Error_Posted
(Arg1
) then
20373 while Present
(Nod
) loop
20374 if Nkind
(Nod
) = N_Pragma
20375 and then Pragma_Name
(Nod
) = Name_Time_Slice
20377 Error_Msg_Name_1
:= Pname
;
20378 Error_Msg_N
("duplicate pragma% not permitted", Nod
);
20385 -- Process only if in main unit
20387 if Get_Source_Unit
(Loc
) = Main_Unit
then
20388 Opt
.Time_Slice_Set
:= True;
20389 Val
:= Expr_Value_R
(Get_Pragma_Arg
(Arg1
));
20391 if Val
<= Ureal_0
then
20392 Opt
.Time_Slice_Value
:= 0;
20394 elsif Val
> UR_From_Uint
(UI_From_Int
(1000)) then
20395 Opt
.Time_Slice_Value
:= 1_000_000_000
;
20398 Opt
.Time_Slice_Value
:=
20399 UI_To_Int
(UR_To_Uint
(Val
* UI_From_Int
(1_000_000
)));
20408 -- pragma Title (TITLING_OPTION [, TITLING OPTION]);
20410 -- TITLING_OPTION ::=
20411 -- [Title =>] STRING_LITERAL
20412 -- | [Subtitle =>] STRING_LITERAL
20414 when Pragma_Title
=> Title
: declare
20415 Args
: Args_List
(1 .. 2);
20416 Names
: constant Name_List
(1 .. 2) := (
20422 Gather_Associations
(Names
, Args
);
20425 for J
in 1 .. 2 loop
20426 if Present
(Args
(J
)) then
20427 Check_Arg_Is_OK_Static_Expression
20428 (Args
(J
), Standard_String
);
20433 ----------------------------
20434 -- Type_Invariant[_Class] --
20435 ----------------------------
20437 -- pragma Type_Invariant[_Class]
20438 -- ([Entity =>] type_LOCAL_NAME,
20439 -- [Check =>] EXPRESSION);
20441 when Pragma_Type_Invariant |
20442 Pragma_Type_Invariant_Class
=>
20443 Type_Invariant
: declare
20444 I_Pragma
: Node_Id
;
20447 Check_Arg_Count
(2);
20449 -- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma,
20450 -- setting Class_Present for the Type_Invariant_Class case.
20452 Set_Class_Present
(N
, Prag_Id
= Pragma_Type_Invariant_Class
);
20453 I_Pragma
:= New_Copy
(N
);
20454 Set_Pragma_Identifier
20455 (I_Pragma
, Make_Identifier
(Loc
, Name_Invariant
));
20456 Rewrite
(N
, I_Pragma
);
20457 Set_Analyzed
(N
, False);
20459 end Type_Invariant
;
20461 ---------------------
20462 -- Unchecked_Union --
20463 ---------------------
20465 -- pragma Unchecked_Union (first_subtype_LOCAL_NAME)
20467 when Pragma_Unchecked_Union
=> Unchecked_Union
: declare
20468 Assoc
: constant Node_Id
:= Arg1
;
20469 Type_Id
: constant Node_Id
:= Get_Pragma_Arg
(Assoc
);
20479 Check_No_Identifiers
;
20480 Check_Arg_Count
(1);
20481 Check_Arg_Is_Local_Name
(Arg1
);
20483 Find_Type
(Type_Id
);
20485 Typ
:= Entity
(Type_Id
);
20488 or else Rep_Item_Too_Early
(Typ
, N
)
20492 Typ
:= Underlying_Type
(Typ
);
20495 if Rep_Item_Too_Late
(Typ
, N
) then
20499 Check_First_Subtype
(Arg1
);
20501 -- Note remaining cases are references to a type in the current
20502 -- declarative part. If we find an error, we post the error on
20503 -- the relevant type declaration at an appropriate point.
20505 if not Is_Record_Type
(Typ
) then
20506 Error_Msg_N
("unchecked union must be record type", Typ
);
20509 elsif Is_Tagged_Type
(Typ
) then
20510 Error_Msg_N
("unchecked union must not be tagged", Typ
);
20513 elsif not Has_Discriminants
(Typ
) then
20515 ("unchecked union must have one discriminant", Typ
);
20518 -- Note: in previous versions of GNAT we used to check for limited
20519 -- types and give an error, but in fact the standard does allow
20520 -- Unchecked_Union on limited types, so this check was removed.
20522 -- Similarly, GNAT used to require that all discriminants have
20523 -- default values, but this is not mandated by the RM.
20525 -- Proceed with basic error checks completed
20528 Tdef
:= Type_Definition
(Declaration_Node
(Typ
));
20529 Clist
:= Component_List
(Tdef
);
20531 -- Check presence of component list and variant part
20533 if No
(Clist
) or else No
(Variant_Part
(Clist
)) then
20535 ("unchecked union must have variant part", Tdef
);
20539 -- Check components
20541 Comp
:= First
(Component_Items
(Clist
));
20542 while Present
(Comp
) loop
20543 Check_Component
(Comp
, Typ
);
20547 -- Check variant part
20549 Vpart
:= Variant_Part
(Clist
);
20551 Variant
:= First
(Variants
(Vpart
));
20552 while Present
(Variant
) loop
20553 Check_Variant
(Variant
, Typ
);
20558 Set_Is_Unchecked_Union
(Typ
);
20559 Set_Convention
(Typ
, Convention_C
);
20560 Set_Has_Unchecked_Union
(Base_Type
(Typ
));
20561 Set_Is_Unchecked_Union
(Base_Type
(Typ
));
20562 end Unchecked_Union
;
20564 ------------------------
20565 -- Unimplemented_Unit --
20566 ------------------------
20568 -- pragma Unimplemented_Unit;
20570 -- Note: this only gives an error if we are generating code, or if
20571 -- we are in a generic library unit (where the pragma appears in the
20572 -- body, not in the spec).
20574 when Pragma_Unimplemented_Unit
=> Unimplemented_Unit
: declare
20575 Cunitent
: constant Entity_Id
:=
20576 Cunit_Entity
(Get_Source_Unit
(Loc
));
20577 Ent_Kind
: constant Entity_Kind
:=
20582 Check_Arg_Count
(0);
20584 if Operating_Mode
= Generate_Code
20585 or else Ent_Kind
= E_Generic_Function
20586 or else Ent_Kind
= E_Generic_Procedure
20587 or else Ent_Kind
= E_Generic_Package
20589 Get_Name_String
(Chars
(Cunitent
));
20590 Set_Casing
(Mixed_Case
);
20591 Write_Str
(Name_Buffer
(1 .. Name_Len
));
20592 Write_Str
(" is not supported in this configuration");
20594 raise Unrecoverable_Error
;
20596 end Unimplemented_Unit
;
20598 ------------------------
20599 -- Universal_Aliasing --
20600 ------------------------
20602 -- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)];
20604 when Pragma_Universal_Aliasing
=> Universal_Alias
: declare
20609 Check_Arg_Count
(1);
20610 Check_Optional_Identifier
(Arg2
, Name_Entity
);
20611 Check_Arg_Is_Local_Name
(Arg1
);
20612 E_Id
:= Entity
(Get_Pragma_Arg
(Arg1
));
20614 if E_Id
= Any_Type
then
20616 elsif No
(E_Id
) or else not Is_Type
(E_Id
) then
20617 Error_Pragma_Arg
("pragma% requires type", Arg1
);
20620 Set_Universal_Aliasing
(Implementation_Base_Type
(E_Id
));
20621 Record_Rep_Item
(E_Id
, N
);
20622 end Universal_Alias
;
20624 --------------------
20625 -- Universal_Data --
20626 --------------------
20628 -- pragma Universal_Data [(library_unit_NAME)];
20630 when Pragma_Universal_Data
=>
20633 -- If this is a configuration pragma, then set the universal
20634 -- addressing option, otherwise confirm that the pragma satisfies
20635 -- the requirements of library unit pragma placement and leave it
20636 -- to the GNAAMP back end to detect the pragma (avoids transitive
20637 -- setting of the option due to withed units).
20639 if Is_Configuration_Pragma
then
20640 Universal_Addressing_On_AAMP
:= True;
20642 Check_Valid_Library_Unit_Pragma
;
20645 if not AAMP_On_Target
then
20646 Error_Pragma
("??pragma% ignored (applies only to AAMP)");
20653 -- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME});
20655 when Pragma_Unmodified
=> Unmodified
: declare
20656 Arg_Node
: Node_Id
;
20657 Arg_Expr
: Node_Id
;
20658 Arg_Ent
: Entity_Id
;
20662 Check_At_Least_N_Arguments
(1);
20664 -- Loop through arguments
20667 while Present
(Arg_Node
) loop
20668 Check_No_Identifier
(Arg_Node
);
20670 -- Note: the analyze call done by Check_Arg_Is_Local_Name will
20671 -- in fact generate reference, so that the entity will have a
20672 -- reference, which will inhibit any warnings about it not
20673 -- being referenced, and also properly show up in the ali file
20674 -- as a reference. But this reference is recorded before the
20675 -- Has_Pragma_Unreferenced flag is set, so that no warning is
20676 -- generated for this reference.
20678 Check_Arg_Is_Local_Name
(Arg_Node
);
20679 Arg_Expr
:= Get_Pragma_Arg
(Arg_Node
);
20681 if Is_Entity_Name
(Arg_Expr
) then
20682 Arg_Ent
:= Entity
(Arg_Expr
);
20684 if not Is_Assignable
(Arg_Ent
) then
20686 ("pragma% can only be applied to a variable",
20689 Set_Has_Pragma_Unmodified
(Arg_Ent
);
20701 -- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME});
20703 -- or when used in a context clause:
20705 -- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}
20707 when Pragma_Unreferenced
=> Unreferenced
: declare
20708 Arg_Node
: Node_Id
;
20709 Arg_Expr
: Node_Id
;
20710 Arg_Ent
: Entity_Id
;
20715 Check_At_Least_N_Arguments
(1);
20717 -- Check case of appearing within context clause
20719 if Is_In_Context_Clause
then
20721 -- The arguments must all be units mentioned in a with clause
20722 -- in the same context clause. Note we already checked (in
20723 -- Par.Prag) that the arguments are either identifiers or
20724 -- selected components.
20727 while Present
(Arg_Node
) loop
20728 Citem
:= First
(List_Containing
(N
));
20729 while Citem
/= N
loop
20730 if Nkind
(Citem
) = N_With_Clause
20732 Same_Name
(Name
(Citem
), Get_Pragma_Arg
(Arg_Node
))
20734 Set_Has_Pragma_Unreferenced
20737 (Library_Unit
(Citem
))));
20739 (Get_Pragma_Arg
(Arg_Node
), Name
(Citem
));
20748 ("argument of pragma% is not withed unit", Arg_Node
);
20754 -- Case of not in list of context items
20758 while Present
(Arg_Node
) loop
20759 Check_No_Identifier
(Arg_Node
);
20761 -- Note: the analyze call done by Check_Arg_Is_Local_Name
20762 -- will in fact generate reference, so that the entity will
20763 -- have a reference, which will inhibit any warnings about
20764 -- it not being referenced, and also properly show up in the
20765 -- ali file as a reference. But this reference is recorded
20766 -- before the Has_Pragma_Unreferenced flag is set, so that
20767 -- no warning is generated for this reference.
20769 Check_Arg_Is_Local_Name
(Arg_Node
);
20770 Arg_Expr
:= Get_Pragma_Arg
(Arg_Node
);
20772 if Is_Entity_Name
(Arg_Expr
) then
20773 Arg_Ent
:= Entity
(Arg_Expr
);
20775 -- If the entity is overloaded, the pragma applies to the
20776 -- most recent overloading, as documented. In this case,
20777 -- name resolution does not generate a reference, so it
20778 -- must be done here explicitly.
20780 if Is_Overloaded
(Arg_Expr
) then
20781 Generate_Reference
(Arg_Ent
, N
);
20784 Set_Has_Pragma_Unreferenced
(Arg_Ent
);
20792 --------------------------
20793 -- Unreferenced_Objects --
20794 --------------------------
20796 -- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME});
20798 when Pragma_Unreferenced_Objects
=> Unreferenced_Objects
: declare
20799 Arg_Node
: Node_Id
;
20800 Arg_Expr
: Node_Id
;
20804 Check_At_Least_N_Arguments
(1);
20807 while Present
(Arg_Node
) loop
20808 Check_No_Identifier
(Arg_Node
);
20809 Check_Arg_Is_Local_Name
(Arg_Node
);
20810 Arg_Expr
:= Get_Pragma_Arg
(Arg_Node
);
20812 if not Is_Entity_Name
(Arg_Expr
)
20813 or else not Is_Type
(Entity
(Arg_Expr
))
20816 ("argument for pragma% must be type or subtype", Arg_Node
);
20819 Set_Has_Pragma_Unreferenced_Objects
(Entity
(Arg_Expr
));
20822 end Unreferenced_Objects
;
20824 ------------------------------
20825 -- Unreserve_All_Interrupts --
20826 ------------------------------
20828 -- pragma Unreserve_All_Interrupts;
20830 when Pragma_Unreserve_All_Interrupts
=>
20832 Check_Arg_Count
(0);
20834 if In_Extended_Main_Code_Unit
(Main_Unit_Entity
) then
20835 Unreserve_All_Interrupts
:= True;
20842 -- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]);
20844 when Pragma_Unsuppress
=>
20846 Process_Suppress_Unsuppress
(Suppress_Case
=> False);
20848 ----------------------------
20849 -- Unevaluated_Use_Of_Old --
20850 ----------------------------
20852 -- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow);
20854 when Pragma_Unevaluated_Use_Of_Old
=>
20856 Check_Arg_Count
(1);
20857 Check_No_Identifiers
;
20858 Check_Arg_Is_One_Of
(Arg1
, Name_Error
, Name_Warn
, Name_Allow
);
20860 -- Suppress/Unsuppress can appear as a configuration pragma, or in
20861 -- a declarative part or a package spec.
20863 if not Is_Configuration_Pragma
then
20864 Check_Is_In_Decl_Part_Or_Package_Spec
;
20867 -- Store proper setting of Uneval_Old
20869 Get_Name_String
(Chars
(Get_Pragma_Arg
(Arg1
)));
20870 Uneval_Old
:= Fold_Upper
(Name_Buffer
(1));
20872 -------------------
20873 -- Use_VADS_Size --
20874 -------------------
20876 -- pragma Use_VADS_Size;
20878 when Pragma_Use_VADS_Size
=>
20880 Check_Arg_Count
(0);
20881 Check_Valid_Configuration_Pragma
;
20882 Use_VADS_Size
:= True;
20884 ---------------------
20885 -- Validity_Checks --
20886 ---------------------
20888 -- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL);
20890 when Pragma_Validity_Checks
=> Validity_Checks
: declare
20891 A
: constant Node_Id
:= Get_Pragma_Arg
(Arg1
);
20897 Check_Arg_Count
(1);
20898 Check_No_Identifiers
;
20900 -- Pragma always active unless in CodePeer or GNATprove modes,
20901 -- which use a fixed configuration of validity checks.
20903 if not (CodePeer_Mode
or GNATprove_Mode
) then
20904 if Nkind
(A
) = N_String_Literal
then
20908 Slen
: constant Natural := Natural (String_Length
(S
));
20909 Options
: String (1 .. Slen
);
20913 -- Couldn't we use a for loop here over Options'Range???
20917 C
:= Get_String_Char
(S
, Int
(J
));
20919 -- This is a weird test, it skips setting validity
20920 -- checks entirely if any element of S is out of
20921 -- range of Character, what is that about ???
20923 exit when not In_Character_Range
(C
);
20924 Options
(J
) := Get_Character
(C
);
20927 Set_Validity_Check_Options
(Options
);
20935 elsif Nkind
(A
) = N_Identifier
then
20936 if Chars
(A
) = Name_All_Checks
then
20937 Set_Validity_Check_Options
("a");
20938 elsif Chars
(A
) = Name_On
then
20939 Validity_Checks_On
:= True;
20940 elsif Chars
(A
) = Name_Off
then
20941 Validity_Checks_On
:= False;
20945 end Validity_Checks
;
20951 -- pragma Volatile (LOCAL_NAME);
20953 when Pragma_Volatile
=>
20954 Process_Atomic_Independent_Shared_Volatile
;
20956 -------------------------
20957 -- Volatile_Components --
20958 -------------------------
20960 -- pragma Volatile_Components (array_LOCAL_NAME);
20962 -- Volatile is handled by the same circuit as Atomic_Components
20964 ----------------------
20965 -- Warning_As_Error --
20966 ----------------------
20968 -- pragma Warning_As_Error (static_string_EXPRESSION);
20970 when Pragma_Warning_As_Error
=>
20972 Check_Arg_Count
(1);
20973 Check_No_Identifiers
;
20974 Check_Valid_Configuration_Pragma
;
20976 if not Is_Static_String_Expression
(Arg1
) then
20978 ("argument of pragma% must be static string expression",
20981 -- OK static string expression
20984 Acquire_Warning_Match_String
(Arg1
);
20985 Warnings_As_Errors_Count
:= Warnings_As_Errors_Count
+ 1;
20986 Warnings_As_Errors
(Warnings_As_Errors_Count
) :=
20987 new String'(Name_Buffer (1 .. Name_Len));
20994 -- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]);
20996 -- DETAILS ::= On | Off
20997 -- DETAILS ::= On | Off, local_NAME
20998 -- DETAILS ::= static_string_EXPRESSION
20999 -- DETAILS ::= On | Off, static_string_EXPRESSION
21001 -- TOOL_NAME ::= GNAT | GNATProve
21003 -- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL}
21005 -- Note: If the first argument matches an allowed tool name, it is
21006 -- always considered to be a tool name, even if there is a string
21007 -- variable of that name.
21009 -- Note if the second argument of DETAILS is a local_NAME then the
21010 -- second form is always understood. If the intention is to use
21011 -- the fourth form, then you can write NAME & "" to force the
21012 -- intepretation as a static_string_EXPRESSION.
21014 when Pragma_Warnings => Warnings : declare
21015 Reason : String_Id;
21019 Check_At_Least_N_Arguments (1);
21021 -- See if last argument is labeled Reason. If so, make sure we
21022 -- have a string literal or a concatenation of string literals,
21023 -- and acquire the REASON string. Then remove the REASON argument
21024 -- by decreasing Num_Args by one; Remaining processing looks only
21025 -- at first Num_Args arguments).
21028 Last_Arg : constant Node_Id :=
21029 Last (Pragma_Argument_Associations (N));
21032 if Nkind (Last_Arg) = N_Pragma_Argument_Association
21033 and then Chars (Last_Arg) = Name_Reason
21036 Get_Reason_String (Get_Pragma_Arg (Last_Arg));
21037 Reason := End_String;
21038 Arg_Count := Arg_Count - 1;
21040 -- Not allowed in compiler units (bootstrap issues)
21042 Check_Compiler_Unit ("Reason for pragma Warnings", N);
21044 -- No REASON string, set null string as reason
21047 Reason := Null_String_Id;
21051 -- Now proceed with REASON taken care of and eliminated
21053 Check_No_Identifiers;
21055 -- If debug flag -gnatd.i is set, pragma is ignored
21057 if Debug_Flag_Dot_I then
21061 -- Process various forms of the pragma
21064 Argx : constant Node_Id := Get_Pragma_Arg (Arg1);
21065 Shifted_Args : List_Id;
21068 -- See if first argument is a tool name, currently either
21069 -- GNAT or GNATprove. If so, either ignore the pragma if the
21070 -- tool used does not match, or continue as if no tool name
21071 -- was given otherwise, by shifting the arguments.
21073 if Nkind (Argx) = N_Identifier
21074 and then Nam_In (Chars (Argx), Name_Gnat, Name_Gnatprove)
21076 if Chars (Argx) = Name_Gnat then
21077 if CodePeer_Mode or GNATprove_Mode or ASIS_Mode then
21078 Rewrite (N, Make_Null_Statement (Loc));
21083 elsif Chars (Argx) = Name_Gnatprove then
21084 if not GNATprove_Mode then
21085 Rewrite (N, Make_Null_Statement (Loc));
21091 raise Program_Error;
21094 -- At this point, the pragma Warnings applies to the tool,
21095 -- so continue with shifted arguments.
21097 Arg_Count := Arg_Count - 1;
21099 if Arg_Count = 1 then
21100 Shifted_Args := New_List (New_Copy (Arg2));
21101 elsif Arg_Count = 2 then
21102 Shifted_Args := New_List (New_Copy (Arg2),
21104 elsif Arg_Count = 3 then
21105 Shifted_Args := New_List (New_Copy (Arg2),
21109 raise Program_Error;
21114 Chars => Name_Warnings,
21115 Pragma_Argument_Associations => Shifted_Args));
21120 -- One argument case
21122 if Arg_Count = 1 then
21124 -- On/Off one argument case was processed by parser
21126 if Nkind (Argx) = N_Identifier
21127 and then Nam_In (Chars (Argx), Name_On, Name_Off)
21131 -- One argument case must be ON/OFF or static string expr
21133 elsif not Is_Static_String_Expression (Arg1) then
21135 ("argument of pragma% must be On/Off or static string "
21136 & "expression", Arg1);
21138 -- One argument string expression case
21142 Lit : constant Node_Id := Expr_Value_S (Argx);
21143 Str : constant String_Id := Strval (Lit);
21144 Len : constant Nat := String_Length (Str);
21152 while J <= Len loop
21153 C := Get_String_Char (Str, J);
21154 OK := In_Character_Range (C);
21157 Chr := Get_Character (C);
21159 -- Dash case: only -Wxxx is accepted
21166 C := Get_String_Char (Str, J);
21167 Chr := Get_Character (C);
21168 exit when Chr = 'W
';
21173 elsif J < Len and then Chr = '.' then
21175 C := Get_String_Char (Str, J);
21176 Chr := Get_Character (C);
21178 if not Set_Dot_Warning_Switch (Chr) then
21180 ("invalid warning switch character "
21181 & '.' & Chr, Arg1);
21187 OK := Set_Warning_Switch (Chr);
21193 ("invalid warning switch character " & Chr,
21202 -- Two or more arguments (must be two)
21205 Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off);
21206 Check_Arg_Count (2);
21214 E_Id := Get_Pragma_Arg (Arg2);
21217 -- In the expansion of an inlined body, a reference to
21218 -- the formal may be wrapped in a conversion if the
21219 -- actual is a conversion. Retrieve the real entity name.
21221 if (In_Instance_Body or In_Inlined_Body)
21222 and then Nkind (E_Id) = N_Unchecked_Type_Conversion
21224 E_Id := Expression (E_Id);
21227 -- Entity name case
21229 if Is_Entity_Name (E_Id) then
21230 E := Entity (E_Id);
21237 (E, (Chars (Get_Pragma_Arg (Arg1)) =
21240 -- For OFF case, make entry in warnings off
21241 -- pragma table for later processing. But we do
21242 -- not do that within an instance, since these
21243 -- warnings are about what is needed in the
21244 -- template, not an instance of it.
21246 if Chars (Get_Pragma_Arg (Arg1)) = Name_Off
21247 and then Warn_On_Warnings_Off
21248 and then not In_Instance
21250 Warnings_Off_Pragmas.Append ((N, E, Reason));
21253 if Is_Enumeration_Type (E) then
21257 Lit := First_Literal (E);
21258 while Present (Lit) loop
21259 Set_Warnings_Off (Lit);
21260 Next_Literal (Lit);
21265 exit when No (Homonym (E));
21270 -- Error if not entity or static string expression case
21272 elsif not Is_Static_String_Expression (Arg2) then
21274 ("second argument of pragma% must be entity name "
21275 & "or static string expression", Arg2);
21277 -- Static string expression case
21280 Acquire_Warning_Match_String (Arg2);
21282 -- Note on configuration pragma case: If this is a
21283 -- configuration pragma, then for an OFF pragma, we
21284 -- just set Config True in the call, which is all
21285 -- that needs to be done. For the case of ON, this
21286 -- is normally an error, unless it is canceling the
21287 -- effect of a previous OFF pragma in the same file.
21288 -- In any other case, an error will be signalled (ON
21289 -- with no matching OFF).
21291 -- Note: We set Used if we are inside a generic to
21292 -- disable the test that the non-config case actually
21293 -- cancels a warning. That's because we can't be sure
21294 -- there isn't an instantiation in some other unit
21295 -- where a warning is suppressed.
21297 -- We could do a little better here by checking if the
21298 -- generic unit we are inside is public, but for now
21299 -- we don't bother with that refinement.
21301 if Chars (Argx) = Name_Off then
21302 Set_Specific_Warning_Off
21303 (Loc, Name_Buffer (1 .. Name_Len), Reason,
21304 Config => Is_Configuration_Pragma,
21305 Used => Inside_A_Generic or else In_Instance);
21307 elsif Chars (Argx) = Name_On then
21308 Set_Specific_Warning_On
21309 (Loc, Name_Buffer (1 .. Name_Len), Err);
21313 ("??pragma Warnings On with no matching "
21314 & "Warnings Off", Loc);
21323 -------------------
21324 -- Weak_External --
21325 -------------------
21327 -- pragma Weak_External ([Entity =>] LOCAL_NAME);
21329 when Pragma_Weak_External => Weak_External : declare
21334 Check_Arg_Count (1);
21335 Check_Optional_Identifier (Arg1, Name_Entity);
21336 Check_Arg_Is_Library_Level_Local_Name (Arg1);
21337 Ent := Entity (Get_Pragma_Arg (Arg1));
21339 if Rep_Item_Too_Early (Ent, N) then
21342 Ent := Underlying_Type (Ent);
21345 -- The only processing required is to link this item on to the
21346 -- list of rep items for the given entity. This is accomplished
21347 -- by the call to Rep_Item_Too_Late (when no error is detected
21348 -- and False is returned).
21350 if Rep_Item_Too_Late (Ent, N) then
21353 Set_Has_Gigi_Rep_Item (Ent);
21357 -----------------------------
21358 -- Wide_Character_Encoding --
21359 -----------------------------
21361 -- pragma Wide_Character_Encoding (IDENTIFIER);
21363 when Pragma_Wide_Character_Encoding =>
21366 -- Nothing to do, handled in parser. Note that we do not enforce
21367 -- configuration pragma placement, this pragma can appear at any
21368 -- place in the source, allowing mixed encodings within a single
21373 --------------------
21374 -- Unknown_Pragma --
21375 --------------------
21377 -- Should be impossible, since the case of an unknown pragma is
21378 -- separately processed before the case statement is entered.
21380 when Unknown_Pragma =>
21381 raise Program_Error;
21384 -- AI05-0144: detect dangerous order dependence. Disabled for now,
21385 -- until AI is formally approved.
21387 -- Check_Order_Dependence;
21390 when Pragma_Exit => null;
21391 end Analyze_Pragma;
21393 ---------------------------------------------
21394 -- Analyze_Pre_Post_Condition_In_Decl_Part --
21395 ---------------------------------------------
21397 procedure Analyze_Pre_Post_Condition_In_Decl_Part (N : Node_Id) is
21398 procedure Process_Class_Wide_Condition
21400 Spec_Id : Entity_Id;
21401 Subp_Decl : Node_Id);
21402 -- Replace the type of all references to the controlling formal of
21403 -- subprogram Spec_Id found in expression Expr with the corresponding
21404 -- class-wide type. Subp_Decl is the subprogram [body] declaration
21405 -- where the pragma resides.
21407 ----------------------------------
21408 -- Process_Class_Wide_Condition --
21409 ----------------------------------
21411 procedure Process_Class_Wide_Condition
21413 Spec_Id : Entity_Id;
21414 Subp_Decl : Node_Id)
21416 Disp_Typ : constant Entity_Id := Find_Dispatching_Type (Spec_Id);
21418 ACW : Entity_Id := Empty;
21419 -- Access to Disp_Typ'Class, created if there is a controlling formal
21420 -- that is an access parameter.
21422 function Access_Class_Wide_Type return Entity_Id;
21423 -- If expression Expr contains a reference to a controlling access
21424 -- parameter, create an access to Disp_Typ'Class for the necessary
21425 -- conversions if one does not exist.
21427 function Replace_Type (N : Node_Id) return Traverse_Result;
21428 -- ARM 6.1.1: Within the expression for a Pre'Class or Post'Class
21429 -- aspect for a primitive subprogram of a tagged type Disp_Typ, a
21430 -- name that denotes a formal parameter of type Disp_Typ is treated
21431 -- as having type Disp_Typ'Class. Similarly, a name that denotes a
21432 -- formal access parameter of type access-to-Disp_Typ is interpreted
21433 -- as with type access-to-Disp_Typ'Class. This ensures the expression
21434 -- is well defined for a primitive subprogram of a type descended
21437 ----------------------------
21438 -- Access_Class_Wide_Type --
21439 ----------------------------
21441 function Access_Class_Wide_Type return Entity_Id is
21442 Loc : constant Source_Ptr := Sloc (N);
21446 ACW := Make_Temporary (Loc, 'T
');
21448 Insert_Before_And_Analyze (Subp_Decl,
21449 Make_Full_Type_Declaration (Loc,
21450 Defining_Identifier => ACW,
21452 Make_Access_To_Object_Definition (Loc,
21453 Subtype_Indication =>
21454 New_Occurrence_Of (Class_Wide_Type (Disp_Typ), Loc),
21455 All_Present => True)));
21457 Freeze_Before (Subp_Decl, ACW);
21461 end Access_Class_Wide_Type;
21467 function Replace_Type (N : Node_Id) return Traverse_Result is
21468 Context : constant Node_Id := Parent (N);
21469 Loc : constant Source_Ptr := Sloc (N);
21470 CW_Typ : Entity_Id := Empty;
21475 if Is_Entity_Name (N)
21476 and then Present (Entity (N))
21477 and then Is_Formal (Entity (N))
21480 Typ := Etype (Ent);
21482 -- Do not perform the type replacement for selector names in
21483 -- parameter associations. These carry an entity for reference
21484 -- purposes, but semantically they are just identifiers.
21486 if Nkind (Context) = N_Type_Conversion then
21489 elsif Nkind (Context) = N_Parameter_Association
21490 and then Selector_Name (Context) = N
21494 elsif Typ = Disp_Typ then
21495 CW_Typ := Class_Wide_Type (Typ);
21497 elsif Is_Access_Type (Typ)
21498 and then Designated_Type (Typ) = Disp_Typ
21500 CW_Typ := Access_Class_Wide_Type;
21503 if Present (CW_Typ) then
21505 Make_Type_Conversion (Loc,
21506 Subtype_Mark => New_Occurrence_Of (CW_Typ, Loc),
21507 Expression => New_Occurrence_Of (Ent, Loc)));
21508 Set_Etype (N, CW_Typ);
21515 procedure Replace_Types is new Traverse_Proc (Replace_Type);
21517 -- Start of processing for Process_Class_Wide_Condition
21520 -- The subprogram subject to Pre'Class/Post'Class does not have a
21521 -- dispatching type, therefore the aspect/pragma is illegal.
21523 if No (Disp_Typ) then
21524 Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N);
21526 if From_Aspect_Specification (N) then
21528 ("aspect % can only be specified for a primitive operation "
21529 & "of a tagged type", Corresponding_Aspect (N));
21531 -- The pragma is a source construct
21535 ("pragma % can only be specified for a primitive operation "
21536 & "of a tagged type", N);
21540 Replace_Types (Expr);
21541 end Process_Class_Wide_Condition;
21545 Subp_Decl : constant Node_Id := Find_Related_Subprogram_Or_Body (N);
21546 Expr : constant Node_Id :=
21547 Expression (Get_Argument (N, Defining_Entity (Subp_Decl)));
21548 Spec_Id : constant Entity_Id := Corresponding_Spec_Of (Subp_Decl);
21550 Restore_Scope : Boolean := False;
21551 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
21553 -- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part
21556 -- Ensure that the subprogram and its formals are visible when analyzing
21557 -- the expression of the pragma.
21559 if not In_Open_Scopes (Spec_Id) then
21560 Restore_Scope := True;
21561 Push_Scope (Spec_Id);
21563 if Is_Generic_Subprogram (Spec_Id) then
21564 Install_Generic_Formals (Spec_Id);
21566 Install_Formals (Spec_Id);
21570 Preanalyze_Assert_Expression (Expr, Standard_Boolean);
21572 -- For a class-wide condition, a reference to a controlling formal must
21573 -- be interpreted as having the class-wide type (or an access to such)
21574 -- so that the inherited condition can be properly applied to any
21575 -- overriding operation (see ARM12 6.6.1 (7)).
21577 if Class_Present (N) then
21578 Process_Class_Wide_Condition (Expr, Spec_Id, Subp_Decl);
21581 -- Currently it is not possible to inline pre/postconditions on a
21582 -- subprogram subject to pragma Inline_Always.
21584 Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id);
21586 -- Remove the subprogram from the scope stack now that the pre-analysis
21587 -- of the precondition/postcondition is done.
21589 if Restore_Scope then
21592 end Analyze_Pre_Post_Condition_In_Decl_Part;
21594 ------------------------------------------
21595 -- Analyze_Refined_Depends_In_Decl_Part --
21596 ------------------------------------------
21598 procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is
21599 Body_Inputs : Elist_Id := No_Elist;
21600 Body_Outputs : Elist_Id := No_Elist;
21601 -- The inputs and outputs of the subprogram body synthesized from pragma
21602 -- Refined_Depends.
21604 Dependencies : List_Id := No_List;
21606 -- The corresponding Depends pragma along with its clauses
21608 Matched_Items : Elist_Id := No_Elist;
21609 -- A list containing the entities of all successfully matched items
21610 -- found in pragma Depends.
21612 Refinements : List_Id := No_List;
21613 -- The clauses of pragma Refined_Depends
21615 Spec_Id : Entity_Id;
21616 -- The entity of the subprogram subject to pragma Refined_Depends
21618 Spec_Inputs : Elist_Id := No_Elist;
21619 Spec_Outputs : Elist_Id := No_Elist;
21620 -- The inputs and outputs of the subprogram spec synthesized from pragma
21623 procedure Check_Dependency_Clause (Dep_Clause : Node_Id);
21624 -- Try to match a single dependency clause Dep_Clause against one or
21625 -- more refinement clauses found in list Refinements. Each successful
21626 -- match eliminates at least one refinement clause from Refinements.
21628 procedure Check_Output_States;
21629 -- Determine whether pragma Depends contains an output state with a
21630 -- visible refinement and if so, ensure that pragma Refined_Depends
21631 -- mentions all its constituents as outputs.
21633 procedure Normalize_Clauses (Clauses : List_Id);
21634 -- Given a list of dependence or refinement clauses Clauses, normalize
21635 -- each clause by creating multiple dependencies with exactly one input
21638 procedure Report_Extra_Clauses;
21639 -- Emit an error for each extra clause found in list Refinements
21641 -----------------------------
21642 -- Check_Dependency_Clause --
21643 -----------------------------
21645 procedure Check_Dependency_Clause (Dep_Clause : Node_Id) is
21646 Dep_Input : constant Node_Id := Expression (Dep_Clause);
21647 Dep_Output : constant Node_Id := First (Choices (Dep_Clause));
21649 function Is_In_Out_State_Clause return Boolean;
21650 -- Determine whether dependence clause Dep_Clause denotes an abstract
21651 -- state that depends on itself (State => State).
21653 function Is_Null_Refined_State (Item : Node_Id) return Boolean;
21654 -- Determine whether item Item denotes an abstract state with visible
21655 -- null refinement.
21657 procedure Match_Items
21658 (Dep_Item : Node_Id;
21659 Ref_Item : Node_Id;
21660 Matched : out Boolean);
21661 -- Try to match dependence item Dep_Item against refinement item
21662 -- Ref_Item. To match against a possible null refinement (see 2, 7),
21663 -- set Ref_Item to Empty. Flag Matched is set to True when one of
21664 -- the following conformance scenarios is in effect:
21665 -- 1) Both items denote null
21666 -- 2) Dep_Item denotes null and Ref_Item is Empty (special case)
21667 -- 3) Both items denote attribute 'Result
21668 -- 4) Both items denote the same formal parameter
21669 -- 5) Both items denote the same variable
21670 -- 6) Dep_Item is an abstract state with visible null refinement
21671 -- and Ref_Item denotes null.
21672 -- 7) Dep_Item is an abstract state with visible null refinement
21673 -- and Ref_Item is Empty (special case).
21674 -- 8) Dep_Item is an abstract state with visible non-null
21675 -- refinement and Ref_Item denotes one of its constituents.
21676 -- 9) Dep_Item is an abstract state without a visible refinement
21677 -- and Ref_Item denotes the same state.
21678 -- When scenario 8 is in effect, the entity of the abstract state
21679 -- denoted by Dep_Item is added to list Refined_States.
21681 procedure Record_Item
(Item_Id
: Entity_Id
);
21682 -- Store the entity of an item denoted by Item_Id in Matched_Items
21684 ----------------------------
21685 -- Is_In_Out_State_Clause --
21686 ----------------------------
21688 function Is_In_Out_State_Clause
return Boolean is
21689 Dep_Input_Id
: Entity_Id
;
21690 Dep_Output_Id
: Entity_Id
;
21693 -- Detect the following clause:
21696 if Is_Entity_Name
(Dep_Input
)
21697 and then Is_Entity_Name
(Dep_Output
)
21699 -- Handle abstract views generated for limited with clauses
21701 Dep_Input_Id
:= Available_View
(Entity_Of
(Dep_Input
));
21702 Dep_Output_Id
:= Available_View
(Entity_Of
(Dep_Output
));
21705 Ekind
(Dep_Input_Id
) = E_Abstract_State
21706 and then Dep_Input_Id
= Dep_Output_Id
;
21710 end Is_In_Out_State_Clause
;
21712 ---------------------------
21713 -- Is_Null_Refined_State --
21714 ---------------------------
21716 function Is_Null_Refined_State
(Item
: Node_Id
) return Boolean is
21717 Item_Id
: Entity_Id
;
21720 if Is_Entity_Name
(Item
) then
21722 -- Handle abstract views generated for limited with clauses
21724 Item_Id
:= Available_View
(Entity_Of
(Item
));
21726 return Ekind
(Item_Id
) = E_Abstract_State
21727 and then Has_Null_Refinement
(Item_Id
);
21732 end Is_Null_Refined_State
;
21738 procedure Match_Items
21739 (Dep_Item
: Node_Id
;
21740 Ref_Item
: Node_Id
;
21741 Matched
: out Boolean)
21743 Dep_Item_Id
: Entity_Id
;
21744 Ref_Item_Id
: Entity_Id
;
21747 -- Assume that the two items do not match
21751 -- A null matches null or Empty (special case)
21753 if Nkind
(Dep_Item
) = N_Null
21754 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
21758 -- Attribute 'Result matches attribute 'Result
21760 elsif Is_Attribute_Result
(Dep_Item
)
21761 and then Is_Attribute_Result
(Dep_Item
)
21765 -- Abstract states, formal parameters and variables
21767 elsif Is_Entity_Name
(Dep_Item
) then
21769 -- Handle abstract views generated for limited with clauses
21771 Dep_Item_Id
:= Available_View
(Entity_Of
(Dep_Item
));
21773 if Ekind
(Dep_Item_Id
) = E_Abstract_State
then
21775 -- An abstract state with visible null refinement matches
21776 -- null or Empty (special case).
21778 if Has_Null_Refinement
(Dep_Item_Id
)
21779 and then (No
(Ref_Item
) or else Nkind
(Ref_Item
) = N_Null
)
21781 Record_Item
(Dep_Item_Id
);
21784 -- An abstract state with visible non-null refinement
21785 -- matches one of its constituents.
21787 elsif Has_Non_Null_Refinement
(Dep_Item_Id
) then
21788 if Is_Entity_Name
(Ref_Item
) then
21789 Ref_Item_Id
:= Entity_Of
(Ref_Item
);
21791 if Ekind_In
(Ref_Item_Id
, E_Abstract_State
, E_Variable
)
21792 and then Present
(Encapsulating_State
(Ref_Item_Id
))
21793 and then Encapsulating_State
(Ref_Item_Id
) =
21796 Record_Item
(Dep_Item_Id
);
21801 -- An abstract state without a visible refinement matches
21804 elsif Is_Entity_Name
(Ref_Item
)
21805 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
21807 Record_Item
(Dep_Item_Id
);
21811 -- A formal parameter or a variable matches itself
21813 elsif Is_Entity_Name
(Ref_Item
)
21814 and then Entity_Of
(Ref_Item
) = Dep_Item_Id
21816 Record_Item
(Dep_Item_Id
);
21826 procedure Record_Item
(Item_Id
: Entity_Id
) is
21828 if not Contains
(Matched_Items
, Item_Id
) then
21829 Add_Item
(Item_Id
, Matched_Items
);
21835 Clause_Matched
: Boolean := False;
21836 Dummy
: Boolean := False;
21837 Inputs_Match
: Boolean;
21838 Next_Ref_Clause
: Node_Id
;
21839 Outputs_Match
: Boolean;
21840 Ref_Clause
: Node_Id
;
21841 Ref_Input
: Node_Id
;
21842 Ref_Output
: Node_Id
;
21844 -- Start of processing for Check_Dependency_Clause
21847 -- Examine all refinement clauses and compare them against the
21848 -- dependence clause.
21850 Ref_Clause
:= First
(Refinements
);
21851 while Present
(Ref_Clause
) loop
21852 Next_Ref_Clause
:= Next
(Ref_Clause
);
21854 -- Obtain the attributes of the current refinement clause
21856 Ref_Input
:= Expression
(Ref_Clause
);
21857 Ref_Output
:= First
(Choices
(Ref_Clause
));
21859 -- The current refinement clause matches the dependence clause
21860 -- when both outputs match and both inputs match. See routine
21861 -- Match_Items for all possible conformance scenarios.
21863 -- Depends Dep_Output => Dep_Input
21867 -- Refined_Depends Ref_Output => Ref_Input
21870 (Dep_Item
=> Dep_Input
,
21871 Ref_Item
=> Ref_Input
,
21872 Matched
=> Inputs_Match
);
21875 (Dep_Item
=> Dep_Output
,
21876 Ref_Item
=> Ref_Output
,
21877 Matched
=> Outputs_Match
);
21879 -- An In_Out state clause may be matched against a refinement with
21880 -- a null input or null output as long as the non-null side of the
21881 -- relation contains a valid constituent of the In_Out_State.
21883 if Is_In_Out_State_Clause
then
21885 -- Depends => (State => State)
21886 -- Refined_Depends => (null => Constit) -- OK
21889 and then not Outputs_Match
21890 and then Nkind
(Ref_Output
) = N_Null
21892 Outputs_Match
:= True;
21895 -- Depends => (State => State)
21896 -- Refined_Depends => (Constit => null) -- OK
21898 if not Inputs_Match
21899 and then Outputs_Match
21900 and then Nkind
(Ref_Input
) = N_Null
21902 Inputs_Match
:= True;
21906 -- The current refinement clause is legally constructed following
21907 -- the rules in SPARK RM 7.2.5, therefore it can be removed from
21908 -- the pool of candidates. The seach continues because a single
21909 -- dependence clause may have multiple matching refinements.
21911 if Inputs_Match
and then Outputs_Match
then
21912 Clause_Matched
:= True;
21913 Remove
(Ref_Clause
);
21916 Ref_Clause
:= Next_Ref_Clause
;
21919 -- Depending on the order or composition of refinement clauses, an
21920 -- In_Out state clause may not be directly refinable.
21922 -- Depends => ((Output, State) => (Input, State))
21923 -- Refined_State => (State => (Constit_1, Constit_2))
21924 -- Refined_Depends => (Constit_1 => Input, Output => Constit_2)
21926 -- Matching normalized clause (State => State) fails because there is
21927 -- no direct refinement capable of satisfying this relation. Another
21928 -- similar case arises when clauses (Constit_1 => Input) and (Output
21929 -- => Constit_2) are matched first, leaving no candidates for clause
21930 -- (State => State). Both scenarios are legal as long as one of the
21931 -- previous clauses mentioned a valid constituent of State.
21933 if not Clause_Matched
21934 and then Is_In_Out_State_Clause
21936 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
21938 Clause_Matched
:= True;
21941 -- A clause where the input is an abstract state with visible null
21942 -- refinement is implicitly matched when the output has already been
21943 -- matched in a previous clause.
21945 -- Depends => (Output => State) -- implicitly OK
21946 -- Refined_State => (State => null)
21947 -- Refined_Depends => (Output => ...)
21949 if not Clause_Matched
21950 and then Is_Null_Refined_State
(Dep_Input
)
21951 and then Is_Entity_Name
(Dep_Output
)
21953 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Output
)))
21955 Clause_Matched
:= True;
21958 -- A clause where the output is an abstract state with visible null
21959 -- refinement is implicitly matched when the input has already been
21960 -- matched in a previous clause.
21962 -- Depends => (State => Input) -- implicitly OK
21963 -- Refined_State => (State => null)
21964 -- Refined_Depends => (... => Input)
21966 if not Clause_Matched
21967 and then Is_Null_Refined_State
(Dep_Output
)
21968 and then Is_Entity_Name
(Dep_Input
)
21970 Contains
(Matched_Items
, Available_View
(Entity_Of
(Dep_Input
)))
21972 Clause_Matched
:= True;
21975 -- At this point either all refinement clauses have been examined or
21976 -- pragma Refined_Depends contains a solitary null. Only an abstract
21977 -- state with null refinement can possibly match these cases.
21979 -- Depends => (State => null)
21980 -- Refined_State => (State => null)
21981 -- Refined_Depends => null -- OK
21983 if not Clause_Matched
then
21985 (Dep_Item
=> Dep_Input
,
21987 Matched
=> Inputs_Match
);
21990 (Dep_Item
=> Dep_Output
,
21992 Matched
=> Outputs_Match
);
21994 Clause_Matched
:= Inputs_Match
and Outputs_Match
;
21997 -- If the contents of Refined_Depends are legal, then the current
21998 -- dependence clause should be satisfied either by an explicit match
21999 -- or by one of the special cases.
22001 if not Clause_Matched
then
22003 ("dependence clause of subprogram & has no matching refinement "
22004 & "in body", Dep_Clause
, Spec_Id
);
22006 end Check_Dependency_Clause
;
22008 -------------------------
22009 -- Check_Output_States --
22010 -------------------------
22012 procedure Check_Output_States
is
22013 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
22014 -- Determine whether all constituents of state State_Id with visible
22015 -- refinement are used as outputs in pragma Refined_Depends. Emit an
22016 -- error if this is not the case.
22018 -----------------------------
22019 -- Check_Constituent_Usage --
22020 -----------------------------
22022 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
22023 Constit_Elmt
: Elmt_Id
;
22024 Constit_Id
: Entity_Id
;
22025 Posted
: Boolean := False;
22028 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
22029 while Present
(Constit_Elmt
) loop
22030 Constit_Id
:= Node
(Constit_Elmt
);
22032 -- The constituent acts as an input (SPARK RM 7.2.5(3))
22034 if Present
(Body_Inputs
)
22035 and then Appears_In
(Body_Inputs
, Constit_Id
)
22037 Error_Msg_Name_1
:= Chars
(State_Id
);
22039 ("constituent & of state % must act as output in "
22040 & "dependence refinement", N
, Constit_Id
);
22042 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22044 elsif No
(Body_Outputs
)
22045 or else not Appears_In
(Body_Outputs
, Constit_Id
)
22050 ("output state & must be replaced by all its "
22051 & "constituents in dependence refinement",
22056 ("\constituent & is missing in output list",
22060 Next_Elmt
(Constit_Elmt
);
22062 end Check_Constituent_Usage
;
22067 Item_Elmt
: Elmt_Id
;
22068 Item_Id
: Entity_Id
;
22070 -- Start of processing for Check_Output_States
22073 -- Inspect the outputs of pragma Depends looking for a state with a
22074 -- visible refinement.
22076 if Present
(Spec_Outputs
) then
22077 Item_Elmt
:= First_Elmt
(Spec_Outputs
);
22078 while Present
(Item_Elmt
) loop
22079 Item
:= Node
(Item_Elmt
);
22081 -- Deal with the mixed nature of the input and output lists
22083 if Nkind
(Item
) = N_Defining_Identifier
then
22086 Item_Id
:= Available_View
(Entity_Of
(Item
));
22089 if Ekind
(Item_Id
) = E_Abstract_State
then
22091 -- The state acts as an input-output, skip it
22093 if Present
(Spec_Inputs
)
22094 and then Appears_In
(Spec_Inputs
, Item_Id
)
22098 -- Ensure that all of the constituents are utilized as
22099 -- outputs in pragma Refined_Depends.
22101 elsif Has_Non_Null_Refinement
(Item_Id
) then
22102 Check_Constituent_Usage
(Item_Id
);
22106 Next_Elmt
(Item_Elmt
);
22109 end Check_Output_States
;
22111 -----------------------
22112 -- Normalize_Clauses --
22113 -----------------------
22115 procedure Normalize_Clauses
(Clauses
: List_Id
) is
22116 procedure Normalize_Inputs
(Clause
: Node_Id
);
22117 -- Normalize clause Clause by creating multiple clauses for each
22118 -- input item of Clause. It is assumed that Clause has exactly one
22119 -- output. The transformation is as follows:
22121 -- Output => (Input_1, Input_2) -- original
22123 -- Output => Input_1 -- normalizations
22124 -- Output => Input_2
22126 procedure Normalize_Outputs
(Clause
: Node_Id
);
22127 -- Normalize clause Clause by creating multiple clause for each
22128 -- output item of Clause. The transformation is as follows:
22130 -- (Output_1, Output_2) => Input -- original
22132 -- Output_1 => Input -- normalization
22133 -- Output_2 => Input
22135 ----------------------
22136 -- Normalize_Inputs --
22137 ----------------------
22139 procedure Normalize_Inputs
(Clause
: Node_Id
) is
22140 Inputs
: constant Node_Id
:= Expression
(Clause
);
22141 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
22142 Output
: constant List_Id
:= Choices
(Clause
);
22143 Last_Input
: Node_Id
;
22145 New_Clause
: Node_Id
;
22146 Next_Input
: Node_Id
;
22149 -- Normalization is performed only when the original clause has
22150 -- more than one input. Multiple inputs appear as an aggregate.
22152 if Nkind
(Inputs
) = N_Aggregate
then
22153 Last_Input
:= Last
(Expressions
(Inputs
));
22155 -- Create a new clause for each input
22157 Input
:= First
(Expressions
(Inputs
));
22158 while Present
(Input
) loop
22159 Next_Input
:= Next
(Input
);
22161 -- Unhook the current input from the original input list
22162 -- because it will be relocated to a new clause.
22166 -- Special processing for the last input. At this point the
22167 -- original aggregate has been stripped down to one element.
22168 -- Replace the aggregate by the element itself.
22170 if Input
= Last_Input
then
22171 Rewrite
(Inputs
, Input
);
22173 -- Generate a clause of the form:
22178 Make_Component_Association
(Loc
,
22179 Choices
=> New_Copy_List_Tree
(Output
),
22180 Expression
=> Input
);
22182 -- The new clause contains replicated content that has
22183 -- already been analyzed, mark the clause as analyzed.
22185 Set_Analyzed
(New_Clause
);
22186 Insert_After
(Clause
, New_Clause
);
22189 Input
:= Next_Input
;
22192 end Normalize_Inputs
;
22194 -----------------------
22195 -- Normalize_Outputs --
22196 -----------------------
22198 procedure Normalize_Outputs
(Clause
: Node_Id
) is
22199 Inputs
: constant Node_Id
:= Expression
(Clause
);
22200 Loc
: constant Source_Ptr
:= Sloc
(Clause
);
22201 Outputs
: constant Node_Id
:= First
(Choices
(Clause
));
22202 Last_Output
: Node_Id
;
22203 New_Clause
: Node_Id
;
22204 Next_Output
: Node_Id
;
22208 -- Multiple outputs appear as an aggregate. Nothing to do when
22209 -- the clause has exactly one output.
22211 if Nkind
(Outputs
) = N_Aggregate
then
22212 Last_Output
:= Last
(Expressions
(Outputs
));
22214 -- Create a clause for each output. Note that each time a new
22215 -- clause is created, the original output list slowly shrinks
22216 -- until there is one item left.
22218 Output
:= First
(Expressions
(Outputs
));
22219 while Present
(Output
) loop
22220 Next_Output
:= Next
(Output
);
22222 -- Unhook the output from the original output list as it
22223 -- will be relocated to a new clause.
22227 -- Special processing for the last output. At this point
22228 -- the original aggregate has been stripped down to one
22229 -- element. Replace the aggregate by the element itself.
22231 if Output
= Last_Output
then
22232 Rewrite
(Outputs
, Output
);
22235 -- Generate a clause of the form:
22236 -- (Output => Inputs)
22239 Make_Component_Association
(Loc
,
22240 Choices
=> New_List
(Output
),
22241 Expression
=> New_Copy_Tree
(Inputs
));
22243 -- The new clause contains replicated content that has
22244 -- already been analyzed. There is not need to reanalyze
22247 Set_Analyzed
(New_Clause
);
22248 Insert_After
(Clause
, New_Clause
);
22251 Output
:= Next_Output
;
22254 end Normalize_Outputs
;
22260 -- Start of processing for Normalize_Clauses
22263 Clause
:= First
(Clauses
);
22264 while Present
(Clause
) loop
22265 Normalize_Outputs
(Clause
);
22269 Clause
:= First
(Clauses
);
22270 while Present
(Clause
) loop
22271 Normalize_Inputs
(Clause
);
22274 end Normalize_Clauses
;
22276 --------------------------
22277 -- Report_Extra_Clauses --
22278 --------------------------
22280 procedure Report_Extra_Clauses
is
22284 if Present
(Refinements
) then
22285 Clause
:= First
(Refinements
);
22286 while Present
(Clause
) loop
22288 -- Do not complain about a null input refinement, since a null
22289 -- input legitimately matches anything.
22291 if Nkind
(Clause
) /= N_Component_Association
22292 or else Nkind
(Expression
(Clause
)) /= N_Null
22295 ("unmatched or extra clause in dependence refinement",
22302 end Report_Extra_Clauses
;
22306 Body_Decl
: constant Node_Id
:= Find_Related_Subprogram_Or_Body
(N
);
22307 Body_Id
: constant Entity_Id
:= Defining_Entity
(Body_Decl
);
22308 Errors
: constant Nat
:= Serious_Errors_Detected
;
22309 Refs
: constant Node_Id
:= Expression
(Get_Argument
(N
));
22314 -- Start of processing for Analyze_Refined_Depends_In_Decl_Part
22317 if Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
22318 Spec_Id
:= Corresponding_Spec_Of_Stub
(Body_Decl
);
22320 Spec_Id
:= Corresponding_Spec
(Body_Decl
);
22323 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
22325 -- Subprogram declarations lacks pragma Depends. Refined_Depends is
22326 -- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)).
22328 if No
(Depends
) then
22330 ("useless refinement, declaration of subprogram & lacks aspect or "
22331 & "pragma Depends", N
, Spec_Id
);
22335 Deps
:= Expression
(Get_Argument
(Depends
));
22337 -- A null dependency relation renders the refinement useless because it
22338 -- cannot possibly mention abstract states with visible refinement. Note
22339 -- that the inverse is not true as states may be refined to null
22340 -- (SPARK RM 7.2.5(2)).
22342 if Nkind
(Deps
) = N_Null
then
22344 ("useless refinement, subprogram & does not depend on abstract "
22345 & "state with visible refinement", N
, Spec_Id
);
22349 -- Analyze Refined_Depends as if it behaved as a regular pragma Depends.
22350 -- This ensures that the categorization of all refined dependency items
22351 -- is consistent with their role.
22353 Analyze_Depends_In_Decl_Part
(N
);
22355 -- Do not match dependencies against refinements if Refined_Depends is
22356 -- illegal to avoid emitting misleading error.
22358 if Serious_Errors_Detected
= Errors
then
22360 -- The related subprogram lacks pragma [Refined_]Global. Synthesize
22361 -- the inputs and outputs of the subprogram spec and body to verify
22362 -- the use of states with visible refinement and their constituents.
22364 if No
(Get_Pragma
(Spec_Id
, Pragma_Global
))
22365 or else No
(Get_Pragma
(Body_Id
, Pragma_Refined_Global
))
22367 Collect_Subprogram_Inputs_Outputs
22368 (Subp_Id
=> Spec_Id
,
22369 Synthesize
=> True,
22370 Subp_Inputs
=> Spec_Inputs
,
22371 Subp_Outputs
=> Spec_Outputs
,
22372 Global_Seen
=> Dummy
);
22374 Collect_Subprogram_Inputs_Outputs
22375 (Subp_Id
=> Body_Id
,
22376 Synthesize
=> True,
22377 Subp_Inputs
=> Body_Inputs
,
22378 Subp_Outputs
=> Body_Outputs
,
22379 Global_Seen
=> Dummy
);
22381 -- For an output state with a visible refinement, ensure that all
22382 -- constituents appear as outputs in the dependency refinement.
22384 Check_Output_States
;
22387 -- Matching is disabled in ASIS because clauses are not normalized as
22388 -- this is a tree altering activity similar to expansion.
22394 -- Multiple dependency clauses appear as component associations of an
22395 -- aggregate. Note that the clauses are copied because the algorithm
22396 -- modifies them and this should not be visible in Depends.
22398 pragma Assert
(Nkind
(Deps
) = N_Aggregate
);
22399 Dependencies
:= New_Copy_List_Tree
(Component_Associations
(Deps
));
22400 Normalize_Clauses
(Dependencies
);
22402 if Nkind
(Refs
) = N_Null
then
22403 Refinements
:= No_List
;
22405 -- Multiple dependency clauses appear as component associations of an
22406 -- aggregate. Note that the clauses are copied because the algorithm
22407 -- modifies them and this should not be visible in Refined_Depends.
22409 else pragma Assert
(Nkind
(Refs
) = N_Aggregate
);
22410 Refinements
:= New_Copy_List_Tree
(Component_Associations
(Refs
));
22411 Normalize_Clauses
(Refinements
);
22414 -- At this point the clauses of pragmas Depends and Refined_Depends
22415 -- have been normalized into simple dependencies between one output
22416 -- and one input. Examine all clauses of pragma Depends looking for
22417 -- matching clauses in pragma Refined_Depends.
22419 Clause
:= First
(Dependencies
);
22420 while Present
(Clause
) loop
22421 Check_Dependency_Clause
(Clause
);
22425 if Serious_Errors_Detected
= Errors
then
22426 Report_Extra_Clauses
;
22429 end Analyze_Refined_Depends_In_Decl_Part
;
22431 -----------------------------------------
22432 -- Analyze_Refined_Global_In_Decl_Part --
22433 -----------------------------------------
22435 procedure Analyze_Refined_Global_In_Decl_Part
(N
: Node_Id
) is
22437 -- The corresponding Global pragma
22439 Has_In_State
: Boolean := False;
22440 Has_In_Out_State
: Boolean := False;
22441 Has_Out_State
: Boolean := False;
22442 Has_Proof_In_State
: Boolean := False;
22443 -- These flags are set when the corresponding Global pragma has a state
22444 -- of mode Input, In_Out, Output or Proof_In respectively with a visible
22447 Has_Null_State
: Boolean := False;
22448 -- This flag is set when the corresponding Global pragma has at least
22449 -- one state with a null refinement.
22451 In_Constits
: Elist_Id
:= No_Elist
;
22452 In_Out_Constits
: Elist_Id
:= No_Elist
;
22453 Out_Constits
: Elist_Id
:= No_Elist
;
22454 Proof_In_Constits
: Elist_Id
:= No_Elist
;
22455 -- These lists contain the entities of all Input, In_Out, Output and
22456 -- Proof_In constituents that appear in Refined_Global and participate
22457 -- in state refinement.
22459 In_Items
: Elist_Id
:= No_Elist
;
22460 In_Out_Items
: Elist_Id
:= No_Elist
;
22461 Out_Items
: Elist_Id
:= No_Elist
;
22462 Proof_In_Items
: Elist_Id
:= No_Elist
;
22463 -- These list contain the entities of all Input, In_Out, Output and
22464 -- Proof_In items defined in the corresponding Global pragma.
22466 procedure Check_In_Out_States
;
22467 -- Determine whether the corresponding Global pragma mentions In_Out
22468 -- states with visible refinement and if so, ensure that one of the
22469 -- following completions apply to the constituents of the state:
22470 -- 1) there is at least one constituent of mode In_Out
22471 -- 2) there is at least one Input and one Output constituent
22472 -- 3) not all constituents are present and one of them is of mode
22474 -- This routine may remove elements from In_Constits, In_Out_Constits,
22475 -- Out_Constits and Proof_In_Constits.
22477 procedure Check_Input_States
;
22478 -- Determine whether the corresponding Global pragma mentions Input
22479 -- states with visible refinement and if so, ensure that at least one of
22480 -- its constituents appears as an Input item in Refined_Global.
22481 -- This routine may remove elements from In_Constits, In_Out_Constits,
22482 -- Out_Constits and Proof_In_Constits.
22484 procedure Check_Output_States
;
22485 -- Determine whether the corresponding Global pragma mentions Output
22486 -- states with visible refinement and if so, ensure that all of its
22487 -- constituents appear as Output items in Refined_Global.
22488 -- This routine may remove elements from In_Constits, In_Out_Constits,
22489 -- Out_Constits and Proof_In_Constits.
22491 procedure Check_Proof_In_States
;
22492 -- Determine whether the corresponding Global pragma mentions Proof_In
22493 -- states with visible refinement and if so, ensure that at least one of
22494 -- its constituents appears as a Proof_In item in Refined_Global.
22495 -- This routine may remove elements from In_Constits, In_Out_Constits,
22496 -- Out_Constits and Proof_In_Constits.
22498 procedure Check_Refined_Global_List
22500 Global_Mode
: Name_Id
:= Name_Input
);
22501 -- Verify the legality of a single global list declaration. Global_Mode
22502 -- denotes the current mode in effect.
22504 procedure Collect_Global_Items
(Prag
: Node_Id
);
22505 -- Gather all input, in out, output and Proof_In items of pragma Prag
22506 -- in lists In_Items, In_Out_Items, Out_Items and Proof_In_Items. Flags
22507 -- Has_In_State, Has_In_Out_State, Has_Out_State and Has_Proof_In_State
22508 -- are set when there is at least one abstract state with visible
22509 -- refinement available in the corresponding mode. Flag Has_Null_State
22510 -- is set when at least state has a null refinement.
22512 function Present_Then_Remove
22514 Item
: Entity_Id
) return Boolean;
22515 -- Search List for a particular entity Item. If Item has been found,
22516 -- remove it from List. This routine is used to strip lists In_Constits,
22517 -- In_Out_Constits and Out_Constits of valid constituents.
22519 procedure Report_Extra_Constituents
;
22520 -- Emit an error for each constituent found in lists In_Constits,
22521 -- In_Out_Constits and Out_Constits.
22523 -------------------------
22524 -- Check_In_Out_States --
22525 -------------------------
22527 procedure Check_In_Out_States
is
22528 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
22529 -- Determine whether one of the following coverage scenarios is in
22531 -- 1) there is at least one constituent of mode In_Out
22532 -- 2) there is at least one Input and one Output constituent
22533 -- 3) not all constituents are present and one of them is of mode
22535 -- If this is not the case, emit an error.
22537 -----------------------------
22538 -- Check_Constituent_Usage --
22539 -----------------------------
22541 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
22542 Constit_Elmt
: Elmt_Id
;
22543 Constit_Id
: Entity_Id
;
22544 Has_Missing
: Boolean := False;
22545 In_Out_Seen
: Boolean := False;
22546 In_Seen
: Boolean := False;
22547 Out_Seen
: Boolean := False;
22550 -- Process all the constituents of the state and note their modes
22551 -- within the global refinement.
22553 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
22554 while Present
(Constit_Elmt
) loop
22555 Constit_Id
:= Node
(Constit_Elmt
);
22557 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
22560 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
) then
22561 In_Out_Seen
:= True;
22563 elsif Present_Then_Remove
(Out_Constits
, Constit_Id
) then
22566 -- A Proof_In constituent cannot participate in the completion
22567 -- of an Output state (SPARK RM 7.2.4(5)).
22569 elsif Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
22570 Error_Msg_Name_1
:= Chars
(State_Id
);
22572 ("constituent & of state % must have mode Input, In_Out "
22573 & "or Output in global refinement",
22577 Has_Missing
:= True;
22580 Next_Elmt
(Constit_Elmt
);
22583 -- A single In_Out constituent is a valid completion
22585 if In_Out_Seen
then
22588 -- A pair of one Input and one Output constituent is a valid
22591 elsif In_Seen
and then Out_Seen
then
22594 -- A single Output constituent is a valid completion only when
22595 -- some of the other constituents are missing (SPARK RM 7.2.4(5)).
22597 elsif Has_Missing
and then Out_Seen
then
22602 ("global refinement of state & redefines the mode of its "
22603 & "constituents", N
, State_Id
);
22605 end Check_Constituent_Usage
;
22609 Item_Elmt
: Elmt_Id
;
22610 Item_Id
: Entity_Id
;
22612 -- Start of processing for Check_In_Out_States
22615 -- Inspect the In_Out items of the corresponding Global pragma
22616 -- looking for a state with a visible refinement.
22618 if Has_In_Out_State
and then Present
(In_Out_Items
) then
22619 Item_Elmt
:= First_Elmt
(In_Out_Items
);
22620 while Present
(Item_Elmt
) loop
22621 Item_Id
:= Node
(Item_Elmt
);
22623 -- Ensure that one of the three coverage variants is satisfied
22625 if Ekind
(Item_Id
) = E_Abstract_State
22626 and then Has_Non_Null_Refinement
(Item_Id
)
22628 Check_Constituent_Usage
(Item_Id
);
22631 Next_Elmt
(Item_Elmt
);
22634 end Check_In_Out_States
;
22636 ------------------------
22637 -- Check_Input_States --
22638 ------------------------
22640 procedure Check_Input_States
is
22641 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
22642 -- Determine whether at least one constituent of state State_Id with
22643 -- visible refinement is used and has mode Input. Ensure that the
22644 -- remaining constituents do not have In_Out, Output or Proof_In
22647 -----------------------------
22648 -- Check_Constituent_Usage --
22649 -----------------------------
22651 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
22652 Constit_Elmt
: Elmt_Id
;
22653 Constit_Id
: Entity_Id
;
22654 In_Seen
: Boolean := False;
22657 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
22658 while Present
(Constit_Elmt
) loop
22659 Constit_Id
:= Node
(Constit_Elmt
);
22661 -- At least one of the constituents appears as an Input
22663 if Present_Then_Remove
(In_Constits
, Constit_Id
) then
22666 -- The constituent appears in the global refinement, but has
22667 -- mode In_Out, Output or Proof_In (SPARK RM 7.2.4(5)).
22669 elsif Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
22670 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
22671 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
22673 Error_Msg_Name_1
:= Chars
(State_Id
);
22675 ("constituent & of state % must have mode Input in global "
22676 & "refinement", N
, Constit_Id
);
22679 Next_Elmt
(Constit_Elmt
);
22682 -- Not one of the constituents appeared as Input
22684 if not In_Seen
then
22686 ("global refinement of state & must include at least one "
22687 & "constituent of mode Input", N
, State_Id
);
22689 end Check_Constituent_Usage
;
22693 Item_Elmt
: Elmt_Id
;
22694 Item_Id
: Entity_Id
;
22696 -- Start of processing for Check_Input_States
22699 -- Inspect the Input items of the corresponding Global pragma
22700 -- looking for a state with a visible refinement.
22702 if Has_In_State
and then Present
(In_Items
) then
22703 Item_Elmt
:= First_Elmt
(In_Items
);
22704 while Present
(Item_Elmt
) loop
22705 Item_Id
:= Node
(Item_Elmt
);
22707 -- Ensure that at least one of the constituents is utilized and
22708 -- is of mode Input.
22710 if Ekind
(Item_Id
) = E_Abstract_State
22711 and then Has_Non_Null_Refinement
(Item_Id
)
22713 Check_Constituent_Usage
(Item_Id
);
22716 Next_Elmt
(Item_Elmt
);
22719 end Check_Input_States
;
22721 -------------------------
22722 -- Check_Output_States --
22723 -------------------------
22725 procedure Check_Output_States
is
22726 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
22727 -- Determine whether all constituents of state State_Id with visible
22728 -- refinement are used and have mode Output. Emit an error if this is
22731 -----------------------------
22732 -- Check_Constituent_Usage --
22733 -----------------------------
22735 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
22736 Constit_Elmt
: Elmt_Id
;
22737 Constit_Id
: Entity_Id
;
22738 Posted
: Boolean := False;
22741 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
22742 while Present
(Constit_Elmt
) loop
22743 Constit_Id
:= Node
(Constit_Elmt
);
22745 if Present_Then_Remove
(Out_Constits
, Constit_Id
) then
22748 -- The constituent appears in the global refinement, but has
22749 -- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)).
22751 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
22752 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
22753 or else Present_Then_Remove
(Proof_In_Constits
, Constit_Id
)
22755 Error_Msg_Name_1
:= Chars
(State_Id
);
22757 ("constituent & of state % must have mode Output in "
22758 & "global refinement", N
, Constit_Id
);
22760 -- The constituent is altogether missing (SPARK RM 7.2.5(3))
22766 ("output state & must be replaced by all its "
22767 & "constituents in global refinement", N
, State_Id
);
22771 ("\constituent & is missing in output list",
22775 Next_Elmt
(Constit_Elmt
);
22777 end Check_Constituent_Usage
;
22781 Item_Elmt
: Elmt_Id
;
22782 Item_Id
: Entity_Id
;
22784 -- Start of processing for Check_Output_States
22787 -- Inspect the Output items of the corresponding Global pragma
22788 -- looking for a state with a visible refinement.
22790 if Has_Out_State
and then Present
(Out_Items
) then
22791 Item_Elmt
:= First_Elmt
(Out_Items
);
22792 while Present
(Item_Elmt
) loop
22793 Item_Id
:= Node
(Item_Elmt
);
22795 -- Ensure that all of the constituents are utilized and they
22796 -- have mode Output.
22798 if Ekind
(Item_Id
) = E_Abstract_State
22799 and then Has_Non_Null_Refinement
(Item_Id
)
22801 Check_Constituent_Usage
(Item_Id
);
22804 Next_Elmt
(Item_Elmt
);
22807 end Check_Output_States
;
22809 ---------------------------
22810 -- Check_Proof_In_States --
22811 ---------------------------
22813 procedure Check_Proof_In_States
is
22814 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
);
22815 -- Determine whether at least one constituent of state State_Id with
22816 -- visible refinement is used and has mode Proof_In. Ensure that the
22817 -- remaining constituents do not have Input, In_Out or Output modes.
22819 -----------------------------
22820 -- Check_Constituent_Usage --
22821 -----------------------------
22823 procedure Check_Constituent_Usage
(State_Id
: Entity_Id
) is
22824 Constit_Elmt
: Elmt_Id
;
22825 Constit_Id
: Entity_Id
;
22826 Proof_In_Seen
: Boolean := False;
22829 Constit_Elmt
:= First_Elmt
(Refinement_Constituents
(State_Id
));
22830 while Present
(Constit_Elmt
) loop
22831 Constit_Id
:= Node
(Constit_Elmt
);
22833 -- At least one of the constituents appears as Proof_In
22835 if Present_Then_Remove
(Proof_In_Constits
, Constit_Id
) then
22836 Proof_In_Seen
:= True;
22838 -- The constituent appears in the global refinement, but has
22839 -- mode Input, In_Out or Output (SPARK RM 7.2.4(5)).
22841 elsif Present_Then_Remove
(In_Constits
, Constit_Id
)
22842 or else Present_Then_Remove
(In_Out_Constits
, Constit_Id
)
22843 or else Present_Then_Remove
(Out_Constits
, Constit_Id
)
22845 Error_Msg_Name_1
:= Chars
(State_Id
);
22847 ("constituent & of state % must have mode Proof_In in "
22848 & "global refinement", N
, Constit_Id
);
22851 Next_Elmt
(Constit_Elmt
);
22854 -- Not one of the constituents appeared as Proof_In
22856 if not Proof_In_Seen
then
22858 ("global refinement of state & must include at least one "
22859 & "constituent of mode Proof_In", N
, State_Id
);
22861 end Check_Constituent_Usage
;
22865 Item_Elmt
: Elmt_Id
;
22866 Item_Id
: Entity_Id
;
22868 -- Start of processing for Check_Proof_In_States
22871 -- Inspect the Proof_In items of the corresponding Global pragma
22872 -- looking for a state with a visible refinement.
22874 if Has_Proof_In_State
and then Present
(Proof_In_Items
) then
22875 Item_Elmt
:= First_Elmt
(Proof_In_Items
);
22876 while Present
(Item_Elmt
) loop
22877 Item_Id
:= Node
(Item_Elmt
);
22879 -- Ensure that at least one of the constituents is utilized and
22880 -- is of mode Proof_In
22882 if Ekind
(Item_Id
) = E_Abstract_State
22883 and then Has_Non_Null_Refinement
(Item_Id
)
22885 Check_Constituent_Usage
(Item_Id
);
22888 Next_Elmt
(Item_Elmt
);
22891 end Check_Proof_In_States
;
22893 -------------------------------
22894 -- Check_Refined_Global_List --
22895 -------------------------------
22897 procedure Check_Refined_Global_List
22899 Global_Mode
: Name_Id
:= Name_Input
)
22901 procedure Check_Refined_Global_Item
22903 Global_Mode
: Name_Id
);
22904 -- Verify the legality of a single global item declaration. Parameter
22905 -- Global_Mode denotes the current mode in effect.
22907 -------------------------------
22908 -- Check_Refined_Global_Item --
22909 -------------------------------
22911 procedure Check_Refined_Global_Item
22913 Global_Mode
: Name_Id
)
22915 Item_Id
: constant Entity_Id
:= Entity_Of
(Item
);
22917 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
);
22918 -- Issue a common error message for all mode mismatches. Expect
22919 -- denotes the expected mode.
22921 -----------------------------
22922 -- Inconsistent_Mode_Error --
22923 -----------------------------
22925 procedure Inconsistent_Mode_Error
(Expect
: Name_Id
) is
22928 ("global item & has inconsistent modes", Item
, Item_Id
);
22930 Error_Msg_Name_1
:= Global_Mode
;
22931 Error_Msg_Name_2
:= Expect
;
22932 SPARK_Msg_N
("\expected mode %, found mode %", Item
);
22933 end Inconsistent_Mode_Error
;
22935 -- Start of processing for Check_Refined_Global_Item
22938 -- When the state or variable acts as a constituent of another
22939 -- state with a visible refinement, collect it for the state
22940 -- completeness checks performed later on.
22942 if Present
(Encapsulating_State
(Item_Id
))
22943 and then Has_Visible_Refinement
(Encapsulating_State
(Item_Id
))
22945 if Global_Mode
= Name_Input
then
22946 Add_Item
(Item_Id
, In_Constits
);
22948 elsif Global_Mode
= Name_In_Out
then
22949 Add_Item
(Item_Id
, In_Out_Constits
);
22951 elsif Global_Mode
= Name_Output
then
22952 Add_Item
(Item_Id
, Out_Constits
);
22954 elsif Global_Mode
= Name_Proof_In
then
22955 Add_Item
(Item_Id
, Proof_In_Constits
);
22958 -- When not a constituent, ensure that both occurrences of the
22959 -- item in pragmas Global and Refined_Global match.
22961 elsif Contains
(In_Items
, Item_Id
) then
22962 if Global_Mode
/= Name_Input
then
22963 Inconsistent_Mode_Error
(Name_Input
);
22966 elsif Contains
(In_Out_Items
, Item_Id
) then
22967 if Global_Mode
/= Name_In_Out
then
22968 Inconsistent_Mode_Error
(Name_In_Out
);
22971 elsif Contains
(Out_Items
, Item_Id
) then
22972 if Global_Mode
/= Name_Output
then
22973 Inconsistent_Mode_Error
(Name_Output
);
22976 elsif Contains
(Proof_In_Items
, Item_Id
) then
22979 -- The item does not appear in the corresponding Global pragma,
22980 -- it must be an extra (SPARK RM 7.2.4(3)).
22983 SPARK_Msg_NE
("extra global item &", Item
, Item_Id
);
22985 end Check_Refined_Global_Item
;
22991 -- Start of processing for Check_Refined_Global_List
22994 if Nkind
(List
) = N_Null
then
22997 -- Single global item declaration
22999 elsif Nkind_In
(List
, N_Expanded_Name
,
23001 N_Selected_Component
)
23003 Check_Refined_Global_Item
(List
, Global_Mode
);
23005 -- Simple global list or moded global list declaration
23007 elsif Nkind
(List
) = N_Aggregate
then
23009 -- The declaration of a simple global list appear as a collection
23012 if Present
(Expressions
(List
)) then
23013 Item
:= First
(Expressions
(List
));
23014 while Present
(Item
) loop
23015 Check_Refined_Global_Item
(Item
, Global_Mode
);
23020 -- The declaration of a moded global list appears as a collection
23021 -- of component associations where individual choices denote
23024 elsif Present
(Component_Associations
(List
)) then
23025 Item
:= First
(Component_Associations
(List
));
23026 while Present
(Item
) loop
23027 Check_Refined_Global_List
23028 (List
=> Expression
(Item
),
23029 Global_Mode
=> Chars
(First
(Choices
(Item
))));
23037 raise Program_Error
;
23043 raise Program_Error
;
23045 end Check_Refined_Global_List
;
23047 --------------------------
23048 -- Collect_Global_Items --
23049 --------------------------
23051 procedure Collect_Global_Items
(Prag
: Node_Id
) is
23052 procedure Process_Global_List
23054 Mode
: Name_Id
:= Name_Input
);
23055 -- Collect all items housed in a global list. Formal Mode denotes the
23056 -- current mode in effect.
23058 -------------------------
23059 -- Process_Global_List --
23060 -------------------------
23062 procedure Process_Global_List
23064 Mode
: Name_Id
:= Name_Input
)
23066 procedure Process_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
23067 -- Add a single item to the appropriate list. Formal Mode denotes
23068 -- the current mode in effect.
23070 -------------------------
23071 -- Process_Global_Item --
23072 -------------------------
23074 procedure Process_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
23075 Item_Id
: constant Entity_Id
:=
23076 Available_View
(Entity_Of
(Item
));
23077 -- The above handles abstract views of variables and states
23078 -- built for limited with clauses.
23081 -- Signal that the global list contains at least one abstract
23082 -- state with a visible refinement. Note that the refinement
23083 -- may be null in which case there are no constituents.
23085 if Ekind
(Item_Id
) = E_Abstract_State
then
23086 if Has_Null_Refinement
(Item_Id
) then
23087 Has_Null_State
:= True;
23089 elsif Has_Non_Null_Refinement
(Item_Id
) then
23090 if Mode
= Name_Input
then
23091 Has_In_State
:= True;
23092 elsif Mode
= Name_In_Out
then
23093 Has_In_Out_State
:= True;
23094 elsif Mode
= Name_Output
then
23095 Has_Out_State
:= True;
23096 elsif Mode
= Name_Proof_In
then
23097 Has_Proof_In_State
:= True;
23102 -- Add the item to the proper list
23104 if Mode
= Name_Input
then
23105 Add_Item
(Item_Id
, In_Items
);
23106 elsif Mode
= Name_In_Out
then
23107 Add_Item
(Item_Id
, In_Out_Items
);
23108 elsif Mode
= Name_Output
then
23109 Add_Item
(Item_Id
, Out_Items
);
23110 elsif Mode
= Name_Proof_In
then
23111 Add_Item
(Item_Id
, Proof_In_Items
);
23113 end Process_Global_Item
;
23119 -- Start of processing for Process_Global_List
23122 if Nkind
(List
) = N_Null
then
23125 -- Single global item declaration
23127 elsif Nkind_In
(List
, N_Expanded_Name
,
23129 N_Selected_Component
)
23131 Process_Global_Item
(List
, Mode
);
23133 -- Single global list or moded global list declaration
23135 elsif Nkind
(List
) = N_Aggregate
then
23137 -- The declaration of a simple global list appear as a
23138 -- collection of expressions.
23140 if Present
(Expressions
(List
)) then
23141 Item
:= First
(Expressions
(List
));
23142 while Present
(Item
) loop
23143 Process_Global_Item
(Item
, Mode
);
23147 -- The declaration of a moded global list appears as a
23148 -- collection of component associations where individual
23149 -- choices denote mode.
23151 elsif Present
(Component_Associations
(List
)) then
23152 Item
:= First
(Component_Associations
(List
));
23153 while Present
(Item
) loop
23154 Process_Global_List
23155 (List
=> Expression
(Item
),
23156 Mode
=> Chars
(First
(Choices
(Item
))));
23164 raise Program_Error
;
23167 -- To accomodate partial decoration of disabled SPARK features,
23168 -- this routine may be called with illegal input. If this is the
23169 -- case, do not raise Program_Error.
23174 end Process_Global_List
;
23176 -- Start of processing for Collect_Global_Items
23179 Process_Global_List
(Expression
(Get_Argument
(Prag
)));
23180 end Collect_Global_Items
;
23182 -------------------------
23183 -- Present_Then_Remove --
23184 -------------------------
23186 function Present_Then_Remove
23188 Item
: Entity_Id
) return Boolean
23193 if Present
(List
) then
23194 Elmt
:= First_Elmt
(List
);
23195 while Present
(Elmt
) loop
23196 if Node
(Elmt
) = Item
then
23197 Remove_Elmt
(List
, Elmt
);
23206 end Present_Then_Remove
;
23208 -------------------------------
23209 -- Report_Extra_Constituents --
23210 -------------------------------
23212 procedure Report_Extra_Constituents
is
23213 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
);
23214 -- Emit an error for every element of List
23216 ---------------------------------------
23217 -- Report_Extra_Constituents_In_List --
23218 ---------------------------------------
23220 procedure Report_Extra_Constituents_In_List
(List
: Elist_Id
) is
23221 Constit_Elmt
: Elmt_Id
;
23224 if Present
(List
) then
23225 Constit_Elmt
:= First_Elmt
(List
);
23226 while Present
(Constit_Elmt
) loop
23227 SPARK_Msg_NE
("extra constituent &", N
, Node
(Constit_Elmt
));
23228 Next_Elmt
(Constit_Elmt
);
23231 end Report_Extra_Constituents_In_List
;
23233 -- Start of processing for Report_Extra_Constituents
23236 Report_Extra_Constituents_In_List
(In_Constits
);
23237 Report_Extra_Constituents_In_List
(In_Out_Constits
);
23238 Report_Extra_Constituents_In_List
(Out_Constits
);
23239 Report_Extra_Constituents_In_List
(Proof_In_Constits
);
23240 end Report_Extra_Constituents
;
23244 Body_Decl
: constant Node_Id
:= Find_Related_Subprogram_Or_Body
(N
);
23245 Errors
: constant Nat
:= Serious_Errors_Detected
;
23246 Items
: constant Node_Id
:= Expression
(Get_Argument
(N
));
23247 Spec_Id
: Entity_Id
;
23249 -- Start of processing for Analyze_Refined_Global_In_Decl_Part
23252 if Nkind
(Body_Decl
) = N_Subprogram_Body_Stub
then
23253 Spec_Id
:= Corresponding_Spec_Of_Stub
(Body_Decl
);
23255 Spec_Id
:= Corresponding_Spec
(Body_Decl
);
23258 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
23260 -- The subprogram declaration lacks pragma Global. This renders
23261 -- Refined_Global useless as there is nothing to refine.
23263 if No
(Global
) then
23265 ("useless refinement, declaration of subprogram & lacks aspect or "
23266 & "pragma Global", N
, Spec_Id
);
23270 -- Extract all relevant items from the corresponding Global pragma
23272 Collect_Global_Items
(Global
);
23274 -- Corresponding Global pragma must mention at least one state witha
23275 -- visible refinement at the point Refined_Global is processed. States
23276 -- with null refinements need Refined_Global pragma (SPARK RM 7.2.4(2)).
23278 if not Has_In_State
23279 and then not Has_In_Out_State
23280 and then not Has_Out_State
23281 and then not Has_Proof_In_State
23282 and then not Has_Null_State
23285 ("useless refinement, subprogram & does not depend on abstract "
23286 & "state with visible refinement", N
, Spec_Id
);
23290 -- The global refinement of inputs and outputs cannot be null when the
23291 -- corresponding Global pragma contains at least one item except in the
23292 -- case where we have states with null refinements.
23294 if Nkind
(Items
) = N_Null
23296 (Present
(In_Items
)
23297 or else Present
(In_Out_Items
)
23298 or else Present
(Out_Items
)
23299 or else Present
(Proof_In_Items
))
23300 and then not Has_Null_State
23303 ("refinement cannot be null, subprogram & has global items",
23308 -- Analyze Refined_Global as if it behaved as a regular pragma Global.
23309 -- This ensures that the categorization of all refined global items is
23310 -- consistent with their role.
23312 Analyze_Global_In_Decl_Part
(N
);
23314 -- Perform all refinement checks with respect to completeness and mode
23317 if Serious_Errors_Detected
= Errors
then
23318 Check_Refined_Global_List
(Items
);
23321 -- For Input states with visible refinement, at least one constituent
23322 -- must be used as an Input in the global refinement.
23324 if Serious_Errors_Detected
= Errors
then
23325 Check_Input_States
;
23328 -- Verify all possible completion variants for In_Out states with
23329 -- visible refinement.
23331 if Serious_Errors_Detected
= Errors
then
23332 Check_In_Out_States
;
23335 -- For Output states with visible refinement, all constituents must be
23336 -- used as Outputs in the global refinement.
23338 if Serious_Errors_Detected
= Errors
then
23339 Check_Output_States
;
23342 -- For Proof_In states with visible refinement, at least one constituent
23343 -- must be used as Proof_In in the global refinement.
23345 if Serious_Errors_Detected
= Errors
then
23346 Check_Proof_In_States
;
23349 -- Emit errors for all constituents that belong to other states with
23350 -- visible refinement that do not appear in Global.
23352 if Serious_Errors_Detected
= Errors
then
23353 Report_Extra_Constituents
;
23355 end Analyze_Refined_Global_In_Decl_Part
;
23357 ----------------------------------------
23358 -- Analyze_Refined_State_In_Decl_Part --
23359 ----------------------------------------
23361 procedure Analyze_Refined_State_In_Decl_Part
(N
: Node_Id
) is
23362 Available_States
: Elist_Id
:= No_Elist
;
23363 -- A list of all abstract states defined in the package declaration that
23364 -- are available for refinement. The list is used to report unrefined
23367 Body_Id
: Entity_Id
;
23368 -- The body entity of the package subject to pragma Refined_State
23370 Body_States
: Elist_Id
:= No_Elist
;
23371 -- A list of all hidden states that appear in the body of the related
23372 -- package. The list is used to report unused hidden states.
23374 Constituents_Seen
: Elist_Id
:= No_Elist
;
23375 -- A list that contains all constituents processed so far. The list is
23376 -- used to detect multiple uses of the same constituent.
23378 Refined_States_Seen
: Elist_Id
:= No_Elist
;
23379 -- A list that contains all refined states processed so far. The list is
23380 -- used to detect duplicate refinements.
23382 Spec_Id
: Entity_Id
;
23383 -- The spec entity of the package subject to pragma Refined_State
23385 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
);
23386 -- Perform full analysis of a single refinement clause
23388 function Collect_Body_States
(Pack_Id
: Entity_Id
) return Elist_Id
;
23389 -- Gather the entities of all abstract states and variables declared in
23390 -- the body state space of package Pack_Id.
23392 procedure Report_Unrefined_States
(States
: Elist_Id
);
23393 -- Emit errors for all unrefined abstract states found in list States
23395 procedure Report_Unused_States
(States
: Elist_Id
);
23396 -- Emit errors for all unused states found in list States
23398 -------------------------------
23399 -- Analyze_Refinement_Clause --
23400 -------------------------------
23402 procedure Analyze_Refinement_Clause
(Clause
: Node_Id
) is
23403 AR_Constit
: Entity_Id
:= Empty
;
23404 AW_Constit
: Entity_Id
:= Empty
;
23405 ER_Constit
: Entity_Id
:= Empty
;
23406 EW_Constit
: Entity_Id
:= Empty
;
23407 -- The entities of external constituents that contain one of the
23408 -- following enabled properties: Async_Readers, Async_Writers,
23409 -- Effective_Reads and Effective_Writes.
23411 External_Constit_Seen
: Boolean := False;
23412 -- Flag used to mark when at least one external constituent is part
23413 -- of the state refinement.
23415 Non_Null_Seen
: Boolean := False;
23416 Null_Seen
: Boolean := False;
23417 -- Flags used to detect multiple uses of null in a single clause or a
23418 -- mixture of null and non-null constituents.
23420 Part_Of_Constits
: Elist_Id
:= No_Elist
;
23421 -- A list of all candidate constituents subject to indicator Part_Of
23422 -- where the encapsulating state is the current state.
23425 State_Id
: Entity_Id
;
23426 -- The current state being refined
23428 procedure Analyze_Constituent
(Constit
: Node_Id
);
23429 -- Perform full analysis of a single constituent
23431 procedure Check_External_Property
23432 (Prop_Nam
: Name_Id
;
23434 Constit
: Entity_Id
);
23435 -- Determine whether a property denoted by name Prop_Nam is present
23436 -- in both the refined state and constituent Constit. Flag Enabled
23437 -- should be set when the property applies to the refined state. If
23438 -- this is not the case, emit an error message.
23440 procedure Check_Matching_State
;
23441 -- Determine whether the state being refined appears in list
23442 -- Available_States. Emit an error when attempting to re-refine the
23443 -- state or when the state is not defined in the package declaration,
23444 -- otherwise remove the state from Available_States.
23446 procedure Report_Unused_Constituents
(Constits
: Elist_Id
);
23447 -- Emit errors for all unused Part_Of constituents in list Constits
23449 -------------------------
23450 -- Analyze_Constituent --
23451 -------------------------
23453 procedure Analyze_Constituent
(Constit
: Node_Id
) is
23454 procedure Check_Ghost_Constituent
(Constit_Id
: Entity_Id
);
23455 -- Verify that the constituent Constit_Id is a Ghost entity if the
23456 -- abstract state being refined is also Ghost. If this is the case
23457 -- verify that the Ghost policy in effect at the point of state
23458 -- and constituent declaration is the same.
23460 procedure Check_Matching_Constituent
(Constit_Id
: Entity_Id
);
23461 -- Determine whether constituent Constit denoted by its entity
23462 -- Constit_Id appears in Hidden_States. Emit an error when the
23463 -- constituent is not a valid hidden state of the related package
23464 -- or when it is used more than once. Otherwise remove the
23465 -- constituent from Hidden_States.
23467 --------------------------------
23468 -- Check_Matching_Constituent --
23469 --------------------------------
23471 procedure Check_Matching_Constituent
(Constit_Id
: Entity_Id
) is
23472 procedure Collect_Constituent
;
23473 -- Add constituent Constit_Id to the refinements of State_Id
23475 -------------------------
23476 -- Collect_Constituent --
23477 -------------------------
23479 procedure Collect_Constituent
is
23481 -- Add the constituent to the list of processed items to aid
23482 -- with the detection of duplicates.
23484 Add_Item
(Constit_Id
, Constituents_Seen
);
23486 -- Collect the constituent in the list of refinement items
23487 -- and establish a relation between the refined state and
23490 Append_Elmt
(Constit_Id
, Refinement_Constituents
(State_Id
));
23491 Set_Encapsulating_State
(Constit_Id
, State_Id
);
23493 -- The state has at least one legal constituent, mark the
23494 -- start of the refinement region. The region ends when the
23495 -- body declarations end (see routine Analyze_Declarations).
23497 Set_Has_Visible_Refinement
(State_Id
);
23499 -- When the constituent is external, save its relevant
23500 -- property for further checks.
23502 if Async_Readers_Enabled
(Constit_Id
) then
23503 AR_Constit
:= Constit_Id
;
23504 External_Constit_Seen
:= True;
23507 if Async_Writers_Enabled
(Constit_Id
) then
23508 AW_Constit
:= Constit_Id
;
23509 External_Constit_Seen
:= True;
23512 if Effective_Reads_Enabled
(Constit_Id
) then
23513 ER_Constit
:= Constit_Id
;
23514 External_Constit_Seen
:= True;
23517 if Effective_Writes_Enabled
(Constit_Id
) then
23518 EW_Constit
:= Constit_Id
;
23519 External_Constit_Seen
:= True;
23521 end Collect_Constituent
;
23525 State_Elmt
: Elmt_Id
;
23527 -- Start of processing for Check_Matching_Constituent
23530 -- Detect a duplicate use of a constituent
23532 if Contains
(Constituents_Seen
, Constit_Id
) then
23534 ("duplicate use of constituent &", Constit
, Constit_Id
);
23538 -- The constituent is subject to a Part_Of indicator
23540 if Present
(Encapsulating_State
(Constit_Id
)) then
23541 if Encapsulating_State
(Constit_Id
) = State_Id
then
23542 Check_Ghost_Constituent
(Constit_Id
);
23543 Remove
(Part_Of_Constits
, Constit_Id
);
23544 Collect_Constituent
;
23546 -- The constituent is part of another state and is used
23547 -- incorrectly in the refinement of the current state.
23550 Error_Msg_Name_1
:= Chars
(State_Id
);
23552 ("& cannot act as constituent of state %",
23553 Constit
, Constit_Id
);
23555 ("\Part_Of indicator specifies & as encapsulating "
23556 & "state", Constit
, Encapsulating_State
(Constit_Id
));
23559 -- The only other source of legal constituents is the body
23560 -- state space of the related package.
23563 if Present
(Body_States
) then
23564 State_Elmt
:= First_Elmt
(Body_States
);
23565 while Present
(State_Elmt
) loop
23567 -- Consume a valid constituent to signal that it has
23568 -- been encountered.
23570 if Node
(State_Elmt
) = Constit_Id
then
23571 Check_Ghost_Constituent
(Constit_Id
);
23573 Remove_Elmt
(Body_States
, State_Elmt
);
23574 Collect_Constituent
;
23578 Next_Elmt
(State_Elmt
);
23582 -- If we get here, then the constituent is not a hidden
23583 -- state of the related package and may not be used in a
23584 -- refinement (SPARK RM 7.2.2(9)).
23586 Error_Msg_Name_1
:= Chars
(Spec_Id
);
23588 ("cannot use & in refinement, constituent is not a hidden "
23589 & "state of package %", Constit
, Constit_Id
);
23591 end Check_Matching_Constituent
;
23593 -----------------------------
23594 -- Check_Ghost_Constituent --
23595 -----------------------------
23597 procedure Check_Ghost_Constituent
(Constit_Id
: Entity_Id
) is
23599 if Is_Ghost_Entity
(State_Id
) then
23600 if Is_Ghost_Entity
(Constit_Id
) then
23602 -- The Ghost policy in effect at the point of abstract
23603 -- state declaration and constituent must match
23604 -- (SPARK RM 6.9(16)).
23606 if Is_Checked_Ghost_Entity
(State_Id
)
23607 and then Is_Ignored_Ghost_Entity
(Constit_Id
)
23609 Error_Msg_Sloc
:= Sloc
(Constit
);
23612 ("incompatible ghost policies in effect", State
);
23614 ("\abstract state & declared with ghost policy "
23615 & "Check", State
, State_Id
);
23617 ("\constituent & declared # with ghost policy "
23618 & "Ignore", State
, Constit_Id
);
23620 elsif Is_Ignored_Ghost_Entity
(State_Id
)
23621 and then Is_Checked_Ghost_Entity
(Constit_Id
)
23623 Error_Msg_Sloc
:= Sloc
(Constit
);
23626 ("incompatible ghost policies in effect", State
);
23628 ("\abstract state & declared with ghost policy "
23629 & "Ignore", State
, State_Id
);
23631 ("\constituent & declared # with ghost policy "
23632 & "Check", State
, Constit_Id
);
23635 -- A constituent of a Ghost abstract state must be a Ghost
23636 -- entity (SPARK RM 7.2.2(12)).
23640 ("constituent of ghost state & must be ghost",
23641 Constit
, State_Id
);
23644 end Check_Ghost_Constituent
;
23648 Constit_Id
: Entity_Id
;
23650 -- Start of processing for Analyze_Constituent
23653 -- Detect multiple uses of null in a single refinement clause or a
23654 -- mixture of null and non-null constituents.
23656 if Nkind
(Constit
) = N_Null
then
23659 ("multiple null constituents not allowed", Constit
);
23661 elsif Non_Null_Seen
then
23663 ("cannot mix null and non-null constituents", Constit
);
23668 -- Collect the constituent in the list of refinement items
23670 Append_Elmt
(Constit
, Refinement_Constituents
(State_Id
));
23672 -- The state has at least one legal constituent, mark the
23673 -- start of the refinement region. The region ends when the
23674 -- body declarations end (see Analyze_Declarations).
23676 Set_Has_Visible_Refinement
(State_Id
);
23679 -- Non-null constituents
23682 Non_Null_Seen
:= True;
23686 ("cannot mix null and non-null constituents", Constit
);
23690 Resolve_State
(Constit
);
23692 -- Ensure that the constituent denotes a valid state or a
23695 if Is_Entity_Name
(Constit
) then
23696 Constit_Id
:= Entity_Of
(Constit
);
23698 if Ekind_In
(Constit_Id
, E_Abstract_State
, E_Variable
) then
23699 Check_Matching_Constituent
(Constit_Id
);
23703 ("constituent & must denote a variable or state (SPARK "
23704 & "RM 7.2.2(5))", Constit
, Constit_Id
);
23707 -- The constituent is illegal
23710 SPARK_Msg_N
("malformed constituent", Constit
);
23713 end Analyze_Constituent
;
23715 -----------------------------
23716 -- Check_External_Property --
23717 -----------------------------
23719 procedure Check_External_Property
23720 (Prop_Nam
: Name_Id
;
23722 Constit
: Entity_Id
)
23725 Error_Msg_Name_1
:= Prop_Nam
;
23727 -- The property is enabled in the related Abstract_State pragma
23728 -- that defines the state (SPARK RM 7.2.8(3)).
23731 if No
(Constit
) then
23733 ("external state & requires at least one constituent with "
23734 & "property %", State
, State_Id
);
23737 -- The property is missing in the declaration of the state, but
23738 -- a constituent is introducing it in the state refinement
23739 -- (SPARK RM 7.2.8(3)).
23741 elsif Present
(Constit
) then
23742 Error_Msg_Name_2
:= Chars
(Constit
);
23744 ("external state & lacks property % set by constituent %",
23747 end Check_External_Property
;
23749 --------------------------
23750 -- Check_Matching_State --
23751 --------------------------
23753 procedure Check_Matching_State
is
23754 State_Elmt
: Elmt_Id
;
23757 -- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8))
23759 if Contains
(Refined_States_Seen
, State_Id
) then
23761 ("duplicate refinement of state &", State
, State_Id
);
23765 -- Inspect the abstract states defined in the package declaration
23766 -- looking for a match.
23768 State_Elmt
:= First_Elmt
(Available_States
);
23769 while Present
(State_Elmt
) loop
23771 -- A valid abstract state is being refined in the body. Add
23772 -- the state to the list of processed refined states to aid
23773 -- with the detection of duplicate refinements. Remove the
23774 -- state from Available_States to signal that it has already
23777 if Node
(State_Elmt
) = State_Id
then
23778 Add_Item
(State_Id
, Refined_States_Seen
);
23779 Remove_Elmt
(Available_States
, State_Elmt
);
23783 Next_Elmt
(State_Elmt
);
23786 -- If we get here, we are refining a state that is not defined in
23787 -- the package declaration.
23789 Error_Msg_Name_1
:= Chars
(Spec_Id
);
23791 ("cannot refine state, & is not defined in package %",
23793 end Check_Matching_State
;
23795 --------------------------------
23796 -- Report_Unused_Constituents --
23797 --------------------------------
23799 procedure Report_Unused_Constituents
(Constits
: Elist_Id
) is
23800 Constit_Elmt
: Elmt_Id
;
23801 Constit_Id
: Entity_Id
;
23802 Posted
: Boolean := False;
23805 if Present
(Constits
) then
23806 Constit_Elmt
:= First_Elmt
(Constits
);
23807 while Present
(Constit_Elmt
) loop
23808 Constit_Id
:= Node
(Constit_Elmt
);
23810 -- Generate an error message of the form:
23812 -- state ... has unused Part_Of constituents
23813 -- abstract state ... defined at ...
23814 -- variable ... defined at ...
23819 ("state & has unused Part_Of constituents",
23823 Error_Msg_Sloc
:= Sloc
(Constit_Id
);
23825 if Ekind
(Constit_Id
) = E_Abstract_State
then
23827 ("\abstract state & defined #", State
, Constit_Id
);
23830 ("\variable & defined #", State
, Constit_Id
);
23833 Next_Elmt
(Constit_Elmt
);
23836 end Report_Unused_Constituents
;
23838 -- Local declarations
23840 Body_Ref
: Node_Id
;
23841 Body_Ref_Elmt
: Elmt_Id
;
23843 Extra_State
: Node_Id
;
23845 -- Start of processing for Analyze_Refinement_Clause
23848 -- A refinement clause appears as a component association where the
23849 -- sole choice is the state and the expressions are the constituents.
23850 -- This is a syntax error, always report.
23852 if Nkind
(Clause
) /= N_Component_Association
then
23853 Error_Msg_N
("malformed state refinement clause", Clause
);
23857 -- Analyze the state name of a refinement clause
23859 State
:= First
(Choices
(Clause
));
23862 Resolve_State
(State
);
23864 -- Ensure that the state name denotes a valid abstract state that is
23865 -- defined in the spec of the related package.
23867 if Is_Entity_Name
(State
) then
23868 State_Id
:= Entity_Of
(State
);
23870 -- Catch any attempts to re-refine a state or refine a state that
23871 -- is not defined in the package declaration.
23873 if Ekind
(State_Id
) = E_Abstract_State
then
23874 Check_Matching_State
;
23877 ("& must denote an abstract state", State
, State_Id
);
23881 -- References to a state with visible refinement are illegal.
23882 -- When nested packages are involved, detecting such references is
23883 -- tricky because pragma Refined_State is analyzed later than the
23884 -- offending pragma Depends or Global. References that occur in
23885 -- such nested context are stored in a list. Emit errors for all
23886 -- references found in Body_References (SPARK RM 6.1.4(8)).
23888 if Present
(Body_References
(State_Id
)) then
23889 Body_Ref_Elmt
:= First_Elmt
(Body_References
(State_Id
));
23890 while Present
(Body_Ref_Elmt
) loop
23891 Body_Ref
:= Node
(Body_Ref_Elmt
);
23893 SPARK_Msg_N
("reference to & not allowed", Body_Ref
);
23894 Error_Msg_Sloc
:= Sloc
(State
);
23895 SPARK_Msg_N
("\refinement of & is visible#", Body_Ref
);
23897 Next_Elmt
(Body_Ref_Elmt
);
23901 -- The state name is illegal. This is a syntax error, always report.
23904 Error_Msg_N
("malformed state name in refinement clause", State
);
23908 -- A refinement clause may only refine one state at a time
23910 Extra_State
:= Next
(State
);
23912 if Present
(Extra_State
) then
23914 ("refinement clause cannot cover multiple states", Extra_State
);
23917 -- Replicate the Part_Of constituents of the refined state because
23918 -- the algorithm will consume items.
23920 Part_Of_Constits
:= New_Copy_Elist
(Part_Of_Constituents
(State_Id
));
23922 -- Analyze all constituents of the refinement. Multiple constituents
23923 -- appear as an aggregate.
23925 Constit
:= Expression
(Clause
);
23927 if Nkind
(Constit
) = N_Aggregate
then
23928 if Present
(Component_Associations
(Constit
)) then
23930 ("constituents of refinement clause must appear in "
23931 & "positional form", Constit
);
23933 else pragma Assert
(Present
(Expressions
(Constit
)));
23934 Constit
:= First
(Expressions
(Constit
));
23935 while Present
(Constit
) loop
23936 Analyze_Constituent
(Constit
);
23942 -- Various forms of a single constituent. Note that these may include
23943 -- malformed constituents.
23946 Analyze_Constituent
(Constit
);
23949 -- A refined external state is subject to special rules with respect
23950 -- to its properties and constituents.
23952 if Is_External_State
(State_Id
) then
23954 -- The set of properties that all external constituents yield must
23955 -- match that of the refined state. There are two cases to detect:
23956 -- the refined state lacks a property or has an extra property.
23958 if External_Constit_Seen
then
23959 Check_External_Property
23960 (Prop_Nam
=> Name_Async_Readers
,
23961 Enabled
=> Async_Readers_Enabled
(State_Id
),
23962 Constit
=> AR_Constit
);
23964 Check_External_Property
23965 (Prop_Nam
=> Name_Async_Writers
,
23966 Enabled
=> Async_Writers_Enabled
(State_Id
),
23967 Constit
=> AW_Constit
);
23969 Check_External_Property
23970 (Prop_Nam
=> Name_Effective_Reads
,
23971 Enabled
=> Effective_Reads_Enabled
(State_Id
),
23972 Constit
=> ER_Constit
);
23974 Check_External_Property
23975 (Prop_Nam
=> Name_Effective_Writes
,
23976 Enabled
=> Effective_Writes_Enabled
(State_Id
),
23977 Constit
=> EW_Constit
);
23979 -- An external state may be refined to null (SPARK RM 7.2.8(2))
23981 elsif Null_Seen
then
23984 -- The external state has constituents, but none of them are
23985 -- external (SPARK RM 7.2.8(2)).
23989 ("external state & requires at least one external "
23990 & "constituent or null refinement", State
, State_Id
);
23993 -- When a refined state is not external, it should not have external
23994 -- constituents (SPARK RM 7.2.8(1)).
23996 elsif External_Constit_Seen
then
23998 ("non-external state & cannot contain external constituents in "
23999 & "refinement", State
, State_Id
);
24002 -- Ensure that all Part_Of candidate constituents have been mentioned
24003 -- in the refinement clause.
24005 Report_Unused_Constituents
(Part_Of_Constits
);
24006 end Analyze_Refinement_Clause
;
24008 -------------------------
24009 -- Collect_Body_States --
24010 -------------------------
24012 function Collect_Body_States
(Pack_Id
: Entity_Id
) return Elist_Id
is
24013 Result
: Elist_Id
:= No_Elist
;
24014 -- A list containing all body states of Pack_Id
24016 procedure Collect_Visible_States
(Pack_Id
: Entity_Id
);
24017 -- Gather the entities of all abstract states and variables declared
24018 -- in the visible state space of package Pack_Id.
24020 ----------------------------
24021 -- Collect_Visible_States --
24022 ----------------------------
24024 procedure Collect_Visible_States
(Pack_Id
: Entity_Id
) is
24025 Item_Id
: Entity_Id
;
24028 -- Traverse the entity chain of the package and inspect all
24031 Item_Id
:= First_Entity
(Pack_Id
);
24032 while Present
(Item_Id
) and then not In_Private_Part
(Item_Id
) loop
24034 -- Do not consider internally generated items as those cannot
24035 -- be named and participate in refinement.
24037 if not Comes_From_Source
(Item_Id
) then
24040 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
24041 Add_Item
(Item_Id
, Result
);
24043 -- Recursively gather the visible states of a nested package
24045 elsif Ekind
(Item_Id
) = E_Package
then
24046 Collect_Visible_States
(Item_Id
);
24049 Next_Entity
(Item_Id
);
24051 end Collect_Visible_States
;
24055 Pack_Body
: constant Node_Id
:=
24056 Declaration_Node
(Body_Entity
(Pack_Id
));
24058 Item_Id
: Entity_Id
;
24060 -- Start of processing for Collect_Body_States
24063 -- Inspect the declarations of the body looking for source variables,
24064 -- packages and package instantiations.
24066 Decl
:= First
(Declarations
(Pack_Body
));
24067 while Present
(Decl
) loop
24068 if Nkind
(Decl
) = N_Object_Declaration
then
24069 Item_Id
:= Defining_Entity
(Decl
);
24071 -- Capture source variables only as internally generated
24072 -- temporaries cannot be named and participate in refinement.
24074 if Ekind
(Item_Id
) = E_Variable
24075 and then Comes_From_Source
(Item_Id
)
24077 Add_Item
(Item_Id
, Result
);
24080 elsif Nkind
(Decl
) = N_Package_Declaration
then
24081 Item_Id
:= Defining_Entity
(Decl
);
24083 -- Capture the visible abstract states and variables of a
24084 -- source package [instantiation].
24086 if Comes_From_Source
(Item_Id
) then
24087 Collect_Visible_States
(Item_Id
);
24095 end Collect_Body_States
;
24097 -----------------------------
24098 -- Report_Unrefined_States --
24099 -----------------------------
24101 procedure Report_Unrefined_States
(States
: Elist_Id
) is
24102 State_Elmt
: Elmt_Id
;
24105 if Present
(States
) then
24106 State_Elmt
:= First_Elmt
(States
);
24107 while Present
(State_Elmt
) loop
24109 ("abstract state & must be refined", Node
(State_Elmt
));
24111 Next_Elmt
(State_Elmt
);
24114 end Report_Unrefined_States
;
24116 --------------------------
24117 -- Report_Unused_States --
24118 --------------------------
24120 procedure Report_Unused_States
(States
: Elist_Id
) is
24121 Posted
: Boolean := False;
24122 State_Elmt
: Elmt_Id
;
24123 State_Id
: Entity_Id
;
24126 if Present
(States
) then
24127 State_Elmt
:= First_Elmt
(States
);
24128 while Present
(State_Elmt
) loop
24129 State_Id
:= Node
(State_Elmt
);
24131 -- Generate an error message of the form:
24133 -- body of package ... has unused hidden states
24134 -- abstract state ... defined at ...
24135 -- variable ... defined at ...
24140 ("body of package & has unused hidden states", Body_Id
);
24143 Error_Msg_Sloc
:= Sloc
(State_Id
);
24145 if Ekind
(State_Id
) = E_Abstract_State
then
24147 ("\abstract state & defined #", Body_Id
, State_Id
);
24150 ("\variable & defined #", Body_Id
, State_Id
);
24153 Next_Elmt
(State_Elmt
);
24156 end Report_Unused_States
;
24158 -- Local declarations
24160 Body_Decl
: constant Node_Id
:= Parent
(N
);
24161 Clauses
: constant Node_Id
:= Expression
(Get_Argument
(N
));
24164 -- Start of processing for Analyze_Refined_State_In_Decl_Part
24169 Body_Id
:= Defining_Entity
(Body_Decl
);
24170 Spec_Id
:= Corresponding_Spec
(Body_Decl
);
24172 -- Replicate the abstract states declared by the package because the
24173 -- matching algorithm will consume states.
24175 Available_States
:= New_Copy_Elist
(Abstract_States
(Spec_Id
));
24177 -- Gather all abstract states and variables declared in the visible
24178 -- state space of the package body. These items must be utilized as
24179 -- constituents in a state refinement.
24181 Body_States
:= Collect_Body_States
(Spec_Id
);
24183 -- Multiple non-null state refinements appear as an aggregate
24185 if Nkind
(Clauses
) = N_Aggregate
then
24186 if Present
(Expressions
(Clauses
)) then
24188 ("state refinements must appear as component associations",
24191 else pragma Assert
(Present
(Component_Associations
(Clauses
)));
24192 Clause
:= First
(Component_Associations
(Clauses
));
24193 while Present
(Clause
) loop
24194 Analyze_Refinement_Clause
(Clause
);
24200 -- Various forms of a single state refinement. Note that these may
24201 -- include malformed refinements.
24204 Analyze_Refinement_Clause
(Clauses
);
24207 -- List all abstract states that were left unrefined
24209 Report_Unrefined_States
(Available_States
);
24211 -- Ensure that all abstract states and variables declared in the body
24212 -- state space of the related package are utilized as constituents.
24214 Report_Unused_States
(Body_States
);
24215 end Analyze_Refined_State_In_Decl_Part
;
24217 ------------------------------------
24218 -- Analyze_Test_Case_In_Decl_Part --
24219 ------------------------------------
24221 procedure Analyze_Test_Case_In_Decl_Part
(N
: Node_Id
) is
24222 procedure Preanalyze_Test_Case_Arg
24223 (Arg_Nam
: Name_Id
;
24224 Spec_Id
: Entity_Id
);
24225 -- Preanalyze one of the optional arguments "Requires" or "Ensures"
24226 -- denoted by Arg_Nam. Spec_Id is the entity of the subprogram spec
24227 -- subject to pragma Test_Case.
24229 ------------------------------
24230 -- Preanalyze_Test_Case_Arg --
24231 ------------------------------
24233 procedure Preanalyze_Test_Case_Arg
24234 (Arg_Nam
: Name_Id
;
24235 Spec_Id
: Entity_Id
)
24240 -- Preanalyze the original aspect argument for ASIS or for a generic
24241 -- subprogram to properly capture global references.
24243 if ASIS_Mode
or else Is_Generic_Subprogram
(Spec_Id
) then
24247 Arg_Nam
=> Arg_Nam
,
24248 From_Aspect
=> True);
24250 if Present
(Arg
) then
24251 Preanalyze_Assert_Expression
24252 (Expression
(Arg
), Standard_Boolean
);
24256 Arg
:= Test_Case_Arg
(N
, Arg_Nam
);
24258 if Present
(Arg
) then
24259 Preanalyze_Assert_Expression
(Expression
(Arg
), Standard_Boolean
);
24261 end Preanalyze_Test_Case_Arg
;
24265 Spec_Id
: Entity_Id
;
24266 Subp_Decl
: Node_Id
;
24268 Restore_Scope
: Boolean := False;
24269 -- Gets set True if we do a Push_Scope needing a Pop_Scope on exit
24271 -- Start of processing for Analyze_Test_Case_In_Decl_Part
24274 Subp_Decl
:= Find_Related_Subprogram_Or_Body
(N
);
24275 Spec_Id
:= Corresponding_Spec_Of
(Subp_Decl
);
24277 -- Ensure that the formal parameters are visible when analyzing all
24278 -- clauses. This falls out of the general rule of aspects pertaining
24279 -- to subprogram declarations.
24281 if not In_Open_Scopes
(Spec_Id
) then
24282 Restore_Scope
:= True;
24283 Push_Scope
(Spec_Id
);
24285 if Is_Generic_Subprogram
(Spec_Id
) then
24286 Install_Generic_Formals
(Spec_Id
);
24288 Install_Formals
(Spec_Id
);
24292 Preanalyze_Test_Case_Arg
(Name_Requires
, Spec_Id
);
24293 Preanalyze_Test_Case_Arg
(Name_Ensures
, Spec_Id
);
24295 -- Currently it is not possible to inline pre/postconditions on a
24296 -- subprogram subject to pragma Inline_Always.
24298 Check_Postcondition_Use_In_Inlined_Subprogram
(N
, Spec_Id
);
24300 if Restore_Scope
then
24303 end Analyze_Test_Case_In_Decl_Part
;
24309 function Appears_In
(List
: Elist_Id
; Item_Id
: Entity_Id
) return Boolean is
24314 if Present
(List
) then
24315 Elmt
:= First_Elmt
(List
);
24316 while Present
(Elmt
) loop
24317 if Nkind
(Node
(Elmt
)) = N_Defining_Identifier
then
24320 Id
:= Entity_Of
(Node
(Elmt
));
24323 if Id
= Item_Id
then
24334 -----------------------------
24335 -- Check_Applicable_Policy --
24336 -----------------------------
24338 procedure Check_Applicable_Policy
(N
: Node_Id
) is
24342 Ename
: constant Name_Id
:= Original_Aspect_Pragma_Name
(N
);
24345 -- No effect if not valid assertion kind name
24347 if not Is_Valid_Assertion_Kind
(Ename
) then
24351 -- Loop through entries in check policy list
24353 PP
:= Opt
.Check_Policy_List
;
24354 while Present
(PP
) loop
24356 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
24357 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
24361 or else Pnm
= Name_Assertion
24362 or else (Pnm
= Name_Statement_Assertions
24363 and then Nam_In
(Ename
, Name_Assert
,
24364 Name_Assert_And_Cut
,
24366 Name_Loop_Invariant
,
24367 Name_Loop_Variant
))
24369 Policy
:= Chars
(Get_Pragma_Arg
(Last
(PPA
)));
24372 when Name_Off | Name_Ignore
=>
24373 Set_Is_Ignored
(N
, True);
24374 Set_Is_Checked
(N
, False);
24376 when Name_On | Name_Check
=>
24377 Set_Is_Checked
(N
, True);
24378 Set_Is_Ignored
(N
, False);
24380 when Name_Disable
=>
24381 Set_Is_Ignored
(N
, True);
24382 Set_Is_Checked
(N
, False);
24383 Set_Is_Disabled
(N
, True);
24385 -- That should be exhaustive, the null here is a defence
24386 -- against a malformed tree from previous errors.
24395 PP
:= Next_Pragma
(PP
);
24399 -- If there are no specific entries that matched, then we let the
24400 -- setting of assertions govern. Note that this provides the needed
24401 -- compatibility with the RM for the cases of assertion, invariant,
24402 -- precondition, predicate, and postcondition.
24404 if Assertions_Enabled
then
24405 Set_Is_Checked
(N
, True);
24406 Set_Is_Ignored
(N
, False);
24408 Set_Is_Checked
(N
, False);
24409 Set_Is_Ignored
(N
, True);
24411 end Check_Applicable_Policy
;
24413 -------------------------------
24414 -- Check_External_Properties --
24415 -------------------------------
24417 procedure Check_External_Properties
24425 -- All properties enabled
24427 if AR
and AW
and ER
and EW
then
24430 -- Async_Readers + Effective_Writes
24431 -- Async_Readers + Async_Writers + Effective_Writes
24433 elsif AR
and EW
and not ER
then
24436 -- Async_Writers + Effective_Reads
24437 -- Async_Readers + Async_Writers + Effective_Reads
24439 elsif AW
and ER
and not EW
then
24442 -- Async_Readers + Async_Writers
24444 elsif AR
and AW
and not ER
and not EW
then
24449 elsif AR
and not AW
and not ER
and not EW
then
24454 elsif AW
and not AR
and not ER
and not EW
then
24459 ("illegal combination of external properties (SPARK RM 7.1.2(6))",
24462 end Check_External_Properties
;
24468 function Check_Kind
(Nam
: Name_Id
) return Name_Id
is
24472 -- Loop through entries in check policy list
24474 PP
:= Opt
.Check_Policy_List
;
24475 while Present
(PP
) loop
24477 PPA
: constant List_Id
:= Pragma_Argument_Associations
(PP
);
24478 Pnm
: constant Name_Id
:= Chars
(Get_Pragma_Arg
(First
(PPA
)));
24482 or else (Pnm
= Name_Assertion
24483 and then Is_Valid_Assertion_Kind
(Nam
))
24484 or else (Pnm
= Name_Statement_Assertions
24485 and then Nam_In
(Nam
, Name_Assert
,
24486 Name_Assert_And_Cut
,
24488 Name_Loop_Invariant
,
24489 Name_Loop_Variant
))
24491 case (Chars
(Get_Pragma_Arg
(Last
(PPA
)))) is
24492 when Name_On | Name_Check
=>
24494 when Name_Off | Name_Ignore
=>
24495 return Name_Ignore
;
24496 when Name_Disable
=>
24497 return Name_Disable
;
24499 raise Program_Error
;
24503 PP
:= Next_Pragma
(PP
);
24508 -- If there are no specific entries that matched, then we let the
24509 -- setting of assertions govern. Note that this provides the needed
24510 -- compatibility with the RM for the cases of assertion, invariant,
24511 -- precondition, predicate, and postcondition.
24513 if Assertions_Enabled
then
24516 return Name_Ignore
;
24520 ---------------------------
24521 -- Check_Missing_Part_Of --
24522 ---------------------------
24524 procedure Check_Missing_Part_Of
(Item_Id
: Entity_Id
) is
24525 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean;
24526 -- Determine whether a package denoted by Pack_Id declares at least one
24529 -----------------------
24530 -- Has_Visible_State --
24531 -----------------------
24533 function Has_Visible_State
(Pack_Id
: Entity_Id
) return Boolean is
24534 Item_Id
: Entity_Id
;
24537 -- Traverse the entity chain of the package trying to find at least
24538 -- one visible abstract state, variable or a package [instantiation]
24539 -- that declares a visible state.
24541 Item_Id
:= First_Entity
(Pack_Id
);
24542 while Present
(Item_Id
)
24543 and then not In_Private_Part
(Item_Id
)
24545 -- Do not consider internally generated items
24547 if not Comes_From_Source
(Item_Id
) then
24550 -- A visible state has been found
24552 elsif Ekind_In
(Item_Id
, E_Abstract_State
, E_Variable
) then
24555 -- Recursively peek into nested packages and instantiations
24557 elsif Ekind
(Item_Id
) = E_Package
24558 and then Has_Visible_State
(Item_Id
)
24563 Next_Entity
(Item_Id
);
24567 end Has_Visible_State
;
24571 Pack_Id
: Entity_Id
;
24572 Placement
: State_Space_Kind
;
24574 -- Start of processing for Check_Missing_Part_Of
24577 -- Do not consider abstract states, variables or package instantiations
24578 -- coming from an instance as those always inherit the Part_Of indicator
24579 -- of the instance itself.
24581 if In_Instance
then
24584 -- Do not consider internally generated entities as these can never
24585 -- have a Part_Of indicator.
24587 elsif not Comes_From_Source
(Item_Id
) then
24590 -- Perform these checks only when SPARK_Mode is enabled as they will
24591 -- interfere with standard Ada rules and produce false positives.
24593 elsif SPARK_Mode
/= On
then
24597 -- Find where the abstract state, variable or package instantiation
24598 -- lives with respect to the state space.
24600 Find_Placement_In_State_Space
24601 (Item_Id
=> Item_Id
,
24602 Placement
=> Placement
,
24603 Pack_Id
=> Pack_Id
);
24605 -- Items that appear in a non-package construct (subprogram, block, etc)
24606 -- do not require a Part_Of indicator because they can never act as a
24609 if Placement
= Not_In_Package
then
24612 -- An item declared in the body state space of a package always act as a
24613 -- constituent and does not need explicit Part_Of indicator.
24615 elsif Placement
= Body_State_Space
then
24618 -- In general an item declared in the visible state space of a package
24619 -- does not require a Part_Of indicator. The only exception is when the
24620 -- related package is a private child unit in which case Part_Of must
24621 -- denote a state in the parent unit or in one of its descendants.
24623 elsif Placement
= Visible_State_Space
then
24624 if Is_Child_Unit
(Pack_Id
)
24625 and then Is_Private_Descendant
(Pack_Id
)
24627 -- A package instantiation does not need a Part_Of indicator when
24628 -- the related generic template has no visible state.
24630 if Ekind
(Item_Id
) = E_Package
24631 and then Is_Generic_Instance
(Item_Id
)
24632 and then not Has_Visible_State
(Item_Id
)
24636 -- All other cases require Part_Of
24640 ("indicator Part_Of is required in this context "
24641 & "(SPARK RM 7.2.6(3))", Item_Id
);
24642 Error_Msg_Name_1
:= Chars
(Pack_Id
);
24644 ("\& is declared in the visible part of private child "
24645 & "unit %", Item_Id
);
24649 -- When the item appears in the private state space of a packge, it must
24650 -- be a part of some state declared by the said package.
24652 else pragma Assert
(Placement
= Private_State_Space
);
24654 -- The related package does not declare a state, the item cannot act
24655 -- as a Part_Of constituent.
24657 if No
(Get_Pragma
(Pack_Id
, Pragma_Abstract_State
)) then
24660 -- A package instantiation does not need a Part_Of indicator when the
24661 -- related generic template has no visible state.
24663 elsif Ekind
(Pack_Id
) = E_Package
24664 and then Is_Generic_Instance
(Pack_Id
)
24665 and then not Has_Visible_State
(Pack_Id
)
24669 -- All other cases require Part_Of
24673 ("indicator Part_Of is required in this context "
24674 & "(SPARK RM 7.2.6(2))", Item_Id
);
24675 Error_Msg_Name_1
:= Chars
(Pack_Id
);
24677 ("\& is declared in the private part of package %", Item_Id
);
24680 end Check_Missing_Part_Of
;
24682 ---------------------------------------------------
24683 -- Check_Postcondition_Use_In_Inlined_Subprogram --
24684 ---------------------------------------------------
24686 procedure Check_Postcondition_Use_In_Inlined_Subprogram
24688 Subp_Id
: Entity_Id
)
24691 if Warn_On_Redundant_Constructs
24692 and then Has_Pragma_Inline_Always
(Subp_Id
)
24694 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
24696 if From_Aspect_Specification
(Prag
) then
24698 ("aspect % not enforced on inlined subprogram &?r?",
24699 Corresponding_Aspect
(Prag
), Subp_Id
);
24702 ("pragma % not enforced on inlined subprogram &?r?",
24706 end Check_Postcondition_Use_In_Inlined_Subprogram
;
24708 -------------------------------------
24709 -- Check_State_And_Constituent_Use --
24710 -------------------------------------
24712 procedure Check_State_And_Constituent_Use
24713 (States
: Elist_Id
;
24714 Constits
: Elist_Id
;
24717 function Find_Encapsulating_State
24718 (Constit_Id
: Entity_Id
) return Entity_Id
;
24719 -- Given the entity of a constituent, try to find a corresponding
24720 -- encapsulating state that appears in the same context. The routine
24721 -- returns Empty is no such state is found.
24723 ------------------------------
24724 -- Find_Encapsulating_State --
24725 ------------------------------
24727 function Find_Encapsulating_State
24728 (Constit_Id
: Entity_Id
) return Entity_Id
24730 State_Id
: Entity_Id
;
24733 -- Since a constituent may be part of a larger constituent set, climb
24734 -- the encapsulated state chain looking for a state that appears in
24735 -- the same context.
24737 State_Id
:= Encapsulating_State
(Constit_Id
);
24738 while Present
(State_Id
) loop
24739 if Contains
(States
, State_Id
) then
24743 State_Id
:= Encapsulating_State
(State_Id
);
24747 end Find_Encapsulating_State
;
24751 Constit_Elmt
: Elmt_Id
;
24752 Constit_Id
: Entity_Id
;
24753 State_Id
: Entity_Id
;
24755 -- Start of processing for Check_State_And_Constituent_Use
24758 -- Nothing to do if there are no states or constituents
24760 if No
(States
) or else No
(Constits
) then
24764 -- Inspect the list of constituents and try to determine whether its
24765 -- encapsulating state is in list States.
24767 Constit_Elmt
:= First_Elmt
(Constits
);
24768 while Present
(Constit_Elmt
) loop
24769 Constit_Id
:= Node
(Constit_Elmt
);
24771 -- Determine whether the constituent is part of an encapsulating
24772 -- state that appears in the same context and if this is the case,
24773 -- emit an error (SPARK RM 7.2.6(7)).
24775 State_Id
:= Find_Encapsulating_State
(Constit_Id
);
24777 if Present
(State_Id
) then
24778 Error_Msg_Name_1
:= Chars
(Constit_Id
);
24780 ("cannot mention state & and its constituent % in the same "
24781 & "context", Context
, State_Id
);
24785 Next_Elmt
(Constit_Elmt
);
24787 end Check_State_And_Constituent_Use
;
24789 ---------------------------------------
24790 -- Collect_Subprogram_Inputs_Outputs --
24791 ---------------------------------------
24793 procedure Collect_Subprogram_Inputs_Outputs
24794 (Subp_Id
: Entity_Id
;
24795 Synthesize
: Boolean := False;
24796 Subp_Inputs
: in out Elist_Id
;
24797 Subp_Outputs
: in out Elist_Id
;
24798 Global_Seen
: out Boolean)
24800 procedure Collect_Dependency_Clause
(Clause
: Node_Id
);
24801 -- Collect all relevant items from a dependency clause
24803 procedure Collect_Global_List
24805 Mode
: Name_Id
:= Name_Input
);
24806 -- Collect all relevant items from a global list
24808 -------------------------------
24809 -- Collect_Dependency_Clause --
24810 -------------------------------
24812 procedure Collect_Dependency_Clause
(Clause
: Node_Id
) is
24813 procedure Collect_Dependency_Item
24815 Is_Input
: Boolean);
24816 -- Add an item to the proper subprogram input or output collection
24818 -----------------------------
24819 -- Collect_Dependency_Item --
24820 -----------------------------
24822 procedure Collect_Dependency_Item
24824 Is_Input
: Boolean)
24829 -- Nothing to collect when the item is null
24831 if Nkind
(Item
) = N_Null
then
24834 -- Ditto for attribute 'Result
24836 elsif Is_Attribute_Result
(Item
) then
24839 -- Multiple items appear as an aggregate
24841 elsif Nkind
(Item
) = N_Aggregate
then
24842 Extra
:= First
(Expressions
(Item
));
24843 while Present
(Extra
) loop
24844 Collect_Dependency_Item
(Extra
, Is_Input
);
24848 -- Otherwise this is a solitary item
24852 Add_Item
(Item
, Subp_Inputs
);
24854 Add_Item
(Item
, Subp_Outputs
);
24857 end Collect_Dependency_Item
;
24859 -- Start of processing for Collect_Dependency_Clause
24862 if Nkind
(Clause
) = N_Null
then
24865 -- A dependency cause appears as component association
24867 elsif Nkind
(Clause
) = N_Component_Association
then
24868 Collect_Dependency_Item
24869 (Expression
(Clause
), Is_Input
=> True);
24870 Collect_Dependency_Item
24871 (First
(Choices
(Clause
)), Is_Input
=> False);
24873 -- To accomodate partial decoration of disabled SPARK features, this
24874 -- routine may be called with illegal input. If this is the case, do
24875 -- not raise Program_Error.
24880 end Collect_Dependency_Clause
;
24882 -------------------------
24883 -- Collect_Global_List --
24884 -------------------------
24886 procedure Collect_Global_List
24888 Mode
: Name_Id
:= Name_Input
)
24890 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
);
24891 -- Add an item to the proper subprogram input or output collection
24893 -------------------------
24894 -- Collect_Global_Item --
24895 -------------------------
24897 procedure Collect_Global_Item
(Item
: Node_Id
; Mode
: Name_Id
) is
24899 if Nam_In
(Mode
, Name_In_Out
, Name_Input
) then
24900 Add_Item
(Item
, Subp_Inputs
);
24903 if Nam_In
(Mode
, Name_In_Out
, Name_Output
) then
24904 Add_Item
(Item
, Subp_Outputs
);
24906 end Collect_Global_Item
;
24913 -- Start of processing for Collect_Global_List
24916 if Nkind
(List
) = N_Null
then
24919 -- Single global item declaration
24921 elsif Nkind_In
(List
, N_Expanded_Name
,
24923 N_Selected_Component
)
24925 Collect_Global_Item
(List
, Mode
);
24927 -- Simple global list or moded global list declaration
24929 elsif Nkind
(List
) = N_Aggregate
then
24930 if Present
(Expressions
(List
)) then
24931 Item
:= First
(Expressions
(List
));
24932 while Present
(Item
) loop
24933 Collect_Global_Item
(Item
, Mode
);
24938 Assoc
:= First
(Component_Associations
(List
));
24939 while Present
(Assoc
) loop
24940 Collect_Global_List
24941 (List
=> Expression
(Assoc
),
24942 Mode
=> Chars
(First
(Choices
(Assoc
))));
24947 -- To accomodate partial decoration of disabled SPARK features, this
24948 -- routine may be called with illegal input. If this is the case, do
24949 -- not raise Program_Error.
24954 end Collect_Global_List
;
24958 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
24959 Spec_Id
: constant Entity_Id
:= Corresponding_Spec_Of
(Subp_Decl
);
24963 Formal
: Entity_Id
;
24967 -- Start of processing for Collect_Subprogram_Inputs_Outputs
24970 Global_Seen
:= False;
24972 -- Process all formal parameters
24974 Formal
:= First_Formal
(Spec_Id
);
24975 while Present
(Formal
) loop
24976 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_In_Parameter
) then
24977 Add_Item
(Formal
, Subp_Inputs
);
24980 if Ekind_In
(Formal
, E_In_Out_Parameter
, E_Out_Parameter
) then
24981 Add_Item
(Formal
, Subp_Outputs
);
24983 -- Out parameters can act as inputs when the related type is
24984 -- tagged, unconstrained array, unconstrained record or record
24985 -- with unconstrained components.
24987 if Ekind
(Formal
) = E_Out_Parameter
24988 and then Is_Unconstrained_Or_Tagged_Item
(Formal
)
24990 Add_Item
(Formal
, Subp_Inputs
);
24994 Next_Formal
(Formal
);
24997 -- When processing a subprogram body, look for pragmas Refined_Depends
24998 -- and Refined_Global as they specify the inputs and outputs.
25000 if Ekind
(Subp_Id
) = E_Subprogram_Body
then
25001 Depends
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Depends
);
25002 Global
:= Get_Pragma
(Subp_Id
, Pragma_Refined_Global
);
25004 -- Subprogram declaration case, look for pragmas Depends and Global
25007 Depends
:= Get_Pragma
(Spec_Id
, Pragma_Depends
);
25008 Global
:= Get_Pragma
(Spec_Id
, Pragma_Global
);
25011 -- Pragma [Refined_]Global takes precedence over [Refined_]Depends
25012 -- because it provides finer granularity of inputs and outputs.
25014 if Present
(Global
) then
25015 Global_Seen
:= True;
25016 List
:= Expression
(Get_Argument
(Global
, Spec_Id
));
25018 -- The pragma may not have been analyzed because of the arbitrary
25019 -- declaration order of aspects. Make sure that it is analyzed for
25020 -- the purposes of item extraction.
25022 if not Analyzed
(List
) then
25023 if Pragma_Name
(Global
) = Name_Refined_Global
then
25024 Analyze_Refined_Global_In_Decl_Part
(Global
);
25026 Analyze_Global_In_Decl_Part
(Global
);
25030 Collect_Global_List
(List
);
25032 -- When the related subprogram lacks pragma [Refined_]Global, fall back
25033 -- to [Refined_]Depends if the caller requests this behavior. Synthesize
25034 -- the inputs and outputs from [Refined_]Depends.
25036 elsif Synthesize
and then Present
(Depends
) then
25037 Clauses
:= Expression
(Get_Argument
(Depends
, Spec_Id
));
25039 -- Multiple dependency clauses appear as an aggregate
25041 if Nkind
(Clauses
) = N_Aggregate
then
25042 Clause
:= First
(Component_Associations
(Clauses
));
25043 while Present
(Clause
) loop
25044 Collect_Dependency_Clause
(Clause
);
25048 -- Otherwise this is a single dependency clause
25051 Collect_Dependency_Clause
(Clauses
);
25054 end Collect_Subprogram_Inputs_Outputs
;
25056 ---------------------------------
25057 -- Delay_Config_Pragma_Analyze --
25058 ---------------------------------
25060 function Delay_Config_Pragma_Analyze
(N
: Node_Id
) return Boolean is
25062 return Nam_In
(Pragma_Name
(N
), Name_Interrupt_State
,
25063 Name_Priority_Specific_Dispatching
);
25064 end Delay_Config_Pragma_Analyze
;
25066 -----------------------
25067 -- Duplication_Error --
25068 -----------------------
25070 procedure Duplication_Error
(Prag
: Node_Id
; Prev
: Node_Id
) is
25071 Prag_From_Asp
: constant Boolean := From_Aspect_Specification
(Prag
);
25072 Prev_From_Asp
: constant Boolean := From_Aspect_Specification
(Prev
);
25075 Error_Msg_Sloc
:= Sloc
(Prev
);
25076 Error_Msg_Name_1
:= Original_Aspect_Pragma_Name
(Prag
);
25078 -- Emit a precise message to distinguish between source pragmas and
25079 -- pragmas generated from aspects. The ordering of the two pragmas is
25083 -- Prag -- duplicate
25085 -- No error is emitted when both pragmas come from aspects because this
25086 -- is already detected by the general aspect analysis mechanism.
25088 if Prag_From_Asp
and Prev_From_Asp
then
25090 elsif Prag_From_Asp
then
25091 Error_Msg_N
("aspect % duplicates pragma declared #", Prag
);
25092 elsif Prev_From_Asp
then
25093 Error_Msg_N
("pragma % duplicates aspect declared #", Prag
);
25095 Error_Msg_N
("pragma % duplicates pragma declared #", Prag
);
25097 end Duplication_Error
;
25099 ----------------------------------
25100 -- Find_Related_Package_Or_Body --
25101 ----------------------------------
25103 function Find_Related_Package_Or_Body
25105 Do_Checks
: Boolean := False) return Node_Id
25107 Context
: constant Node_Id
:= Parent
(Prag
);
25108 Prag_Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
25112 Stmt
:= Prev
(Prag
);
25113 while Present
(Stmt
) loop
25115 -- Skip prior pragmas, but check for duplicates
25117 if Nkind
(Stmt
) = N_Pragma
then
25118 if Do_Checks
and then Pragma_Name
(Stmt
) = Prag_Nam
then
25124 -- Skip internally generated code
25126 elsif not Comes_From_Source
(Stmt
) then
25127 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
25129 -- The subprogram declaration is an internally generated spec
25130 -- for an expression function.
25132 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
25135 -- The subprogram is actually an instance housed within an
25136 -- anonymous wrapper package.
25138 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
25143 -- Return the current source construct which is illegal
25152 -- If we fall through, then the pragma was either the first declaration
25153 -- or it was preceded by other pragmas and no source constructs.
25155 -- The pragma is associated with a package. The immediate context in
25156 -- this case is the specification of the package.
25158 if Nkind
(Context
) = N_Package_Specification
then
25159 return Parent
(Context
);
25161 -- The pragma appears in the declarations of a package body
25163 elsif Nkind
(Context
) = N_Package_Body
then
25166 -- The pragma appears in the statements of a package body
25168 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
25169 and then Nkind
(Parent
(Context
)) = N_Package_Body
25171 return Parent
(Context
);
25173 -- The pragma is a byproduct of aspect expansion, return the related
25174 -- context of the original aspect. This case has a lower priority as
25175 -- the above circuitry pinpoints precisely the related context.
25177 elsif Present
(Corresponding_Aspect
(Prag
)) then
25178 return Parent
(Corresponding_Aspect
(Prag
));
25180 -- No candidate packge [body] found
25185 end Find_Related_Package_Or_Body
;
25187 -------------------------------------
25188 -- Find_Related_Subprogram_Or_Body --
25189 -------------------------------------
25191 function Find_Related_Subprogram_Or_Body
25193 Do_Checks
: Boolean := False) return Node_Id
25195 Prag_Nam
: constant Name_Id
:= Original_Aspect_Pragma_Name
(Prag
);
25197 procedure Expression_Function_Error
;
25198 -- Emit an error concerning pragma Prag that illegaly applies to an
25199 -- expression function.
25201 -------------------------------
25202 -- Expression_Function_Error --
25203 -------------------------------
25205 procedure Expression_Function_Error
is
25207 Error_Msg_Name_1
:= Prag_Nam
;
25209 -- Emit a precise message to distinguish between source pragmas and
25210 -- pragmas generated from aspects.
25212 if From_Aspect_Specification
(Prag
) then
25214 ("aspect % cannot apply to a stand alone expression function",
25218 ("pragma % cannot apply to a stand alone expression function",
25221 end Expression_Function_Error
;
25225 Context
: constant Node_Id
:= Parent
(Prag
);
25228 Look_For_Body
: constant Boolean :=
25229 Nam_In
(Prag_Nam
, Name_Refined_Depends
,
25230 Name_Refined_Global
,
25231 Name_Refined_Post
);
25232 -- Refinement pragmas must be associated with a subprogram body [stub]
25234 -- Start of processing for Find_Related_Subprogram_Or_Body
25237 Stmt
:= Prev
(Prag
);
25238 while Present
(Stmt
) loop
25240 -- Skip prior pragmas, but check for duplicates. Pragmas produced
25241 -- by splitting a complex pre/postcondition are not considered to
25244 if Nkind
(Stmt
) = N_Pragma
then
25246 and then not Split_PPC
(Stmt
)
25247 and then Original_Aspect_Pragma_Name
(Stmt
) = Prag_Nam
25254 -- Emit an error when a refinement pragma appears on an expression
25255 -- function without a completion.
25258 and then Look_For_Body
25259 and then Nkind
(Stmt
) = N_Subprogram_Declaration
25260 and then Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
25261 and then not Has_Completion
(Defining_Entity
(Stmt
))
25263 Expression_Function_Error
;
25266 -- The refinement pragma applies to a subprogram body stub
25268 elsif Look_For_Body
25269 and then Nkind
(Stmt
) = N_Subprogram_Body_Stub
25273 -- Skip internally generated code
25275 elsif not Comes_From_Source
(Stmt
) then
25276 if Nkind
(Stmt
) = N_Subprogram_Declaration
then
25278 -- The subprogram declaration is an internally generated spec
25279 -- for an expression function.
25281 if Nkind
(Original_Node
(Stmt
)) = N_Expression_Function
then
25284 -- The subprogram is actually an instance housed within an
25285 -- anonymous wrapper package.
25287 elsif Present
(Generic_Parent
(Specification
(Stmt
))) then
25292 -- Return the current construct which is either a subprogram body,
25293 -- a subprogram declaration or is illegal.
25302 -- If we fall through, then the pragma was either the first declaration
25303 -- or it was preceded by other pragmas and no source constructs.
25305 -- The pragma is associated with a library-level subprogram
25307 if Nkind
(Context
) = N_Compilation_Unit_Aux
then
25308 return Unit
(Parent
(Context
));
25310 -- The pragma appears inside the statements of a subprogram body. This
25311 -- placement is the result of subprogram contract expansion.
25313 elsif Nkind
(Context
) = N_Handled_Sequence_Of_Statements
then
25314 return Parent
(Context
);
25316 -- The pragma appears inside the declarative part of a subprogram body
25318 elsif Nkind
(Context
) = N_Subprogram_Body
then
25321 -- The pragma is a byproduct of aspect expansion, return the related
25322 -- context of the original aspect. This case has a lower priority as
25323 -- the above circuitry pinpoints precisely the related context.
25325 elsif Present
(Corresponding_Aspect
(Prag
)) then
25326 return Parent
(Corresponding_Aspect
(Prag
));
25328 -- No candidate subprogram [body] found
25333 end Find_Related_Subprogram_Or_Body
;
25339 function Get_Argument
25341 Spec_Id
: Entity_Id
:= Empty
) return Node_Id
25343 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
25346 -- Use the expression of the original aspect if possible when compiling
25347 -- for ASIS or when analyzing the template of a generic subprogram. In
25348 -- both cases the aspect's tree must be decorated to allow for ASIS
25349 -- queries or to save all global references in the generic context.
25351 if From_Aspect_Specification
(Prag
)
25353 (ASIS_Mode
or else (Present
(Spec_Id
)
25354 and then Is_Generic_Subprogram
(Spec_Id
)))
25356 return Corresponding_Aspect
(Prag
);
25358 -- Otherwise use the expression of the pragma
25360 elsif Present
(Args
) then
25361 return First
(Args
);
25368 -------------------------
25369 -- Get_Base_Subprogram --
25370 -------------------------
25372 function Get_Base_Subprogram
(Def_Id
: Entity_Id
) return Entity_Id
is
25373 Result
: Entity_Id
;
25376 -- Follow subprogram renaming chain
25380 if Is_Subprogram
(Result
)
25382 Nkind
(Parent
(Declaration_Node
(Result
))) =
25383 N_Subprogram_Renaming_Declaration
25384 and then Present
(Alias
(Result
))
25386 Result
:= Alias
(Result
);
25390 end Get_Base_Subprogram
;
25392 -----------------------
25393 -- Get_SPARK_Mode_Type --
25394 -----------------------
25396 function Get_SPARK_Mode_Type
(N
: Name_Id
) return SPARK_Mode_Type
is
25398 if N
= Name_On
then
25400 elsif N
= Name_Off
then
25403 -- Any other argument is illegal
25406 raise Program_Error
;
25408 end Get_SPARK_Mode_Type
;
25410 --------------------------------
25411 -- Get_SPARK_Mode_From_Pragma --
25412 --------------------------------
25414 function Get_SPARK_Mode_From_Pragma
(N
: Node_Id
) return SPARK_Mode_Type
is
25419 pragma Assert
(Nkind
(N
) = N_Pragma
);
25420 Args
:= Pragma_Argument_Associations
(N
);
25422 -- Extract the mode from the argument list
25424 if Present
(Args
) then
25425 Mode
:= First
(Pragma_Argument_Associations
(N
));
25426 return Get_SPARK_Mode_Type
(Chars
(Get_Pragma_Arg
(Mode
)));
25428 -- If SPARK_Mode pragma has no argument, default is ON
25433 end Get_SPARK_Mode_From_Pragma
;
25435 ---------------------------
25436 -- Has_Extra_Parentheses --
25437 ---------------------------
25439 function Has_Extra_Parentheses
(Clause
: Node_Id
) return Boolean is
25443 -- The aggregate should not have an expression list because a clause
25444 -- is always interpreted as a component association. The only way an
25445 -- expression list can sneak in is by adding extra parentheses around
25446 -- the individual clauses:
25448 -- Depends (Output => Input) -- proper form
25449 -- Depends ((Output => Input)) -- extra parentheses
25451 -- Since the extra parentheses are not allowed by the syntax of the
25452 -- pragma, flag them now to avoid emitting misleading errors down the
25455 if Nkind
(Clause
) = N_Aggregate
25456 and then Present
(Expressions
(Clause
))
25458 Expr
:= First
(Expressions
(Clause
));
25459 while Present
(Expr
) loop
25461 -- A dependency clause surrounded by extra parentheses appears
25462 -- as an aggregate of component associations with an optional
25463 -- Paren_Count set.
25465 if Nkind
(Expr
) = N_Aggregate
25466 and then Present
(Component_Associations
(Expr
))
25469 ("dependency clause contains extra parentheses", Expr
);
25471 -- Otherwise the expression is a malformed construct
25474 SPARK_Msg_N
("malformed dependency clause", Expr
);
25484 end Has_Extra_Parentheses
;
25490 procedure Initialize
is
25501 Dummy
:= Dummy
+ 1;
25504 -----------------------------
25505 -- Is_Config_Static_String --
25506 -----------------------------
25508 function Is_Config_Static_String
(Arg
: Node_Id
) return Boolean is
25510 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean;
25511 -- This is an internal recursive function that is just like the outer
25512 -- function except that it adds the string to the name buffer rather
25513 -- than placing the string in the name buffer.
25515 ------------------------------
25516 -- Add_Config_Static_String --
25517 ------------------------------
25519 function Add_Config_Static_String
(Arg
: Node_Id
) return Boolean is
25526 if Nkind
(N
) = N_Op_Concat
then
25527 if Add_Config_Static_String
(Left_Opnd
(N
)) then
25528 N
:= Right_Opnd
(N
);
25534 if Nkind
(N
) /= N_String_Literal
then
25535 Error_Msg_N
("string literal expected for pragma argument", N
);
25539 for J
in 1 .. String_Length
(Strval
(N
)) loop
25540 C
:= Get_String_Char
(Strval
(N
), J
);
25542 if not In_Character_Range
(C
) then
25544 ("string literal contains invalid wide character",
25545 Sloc
(N
) + 1 + Source_Ptr
(J
));
25549 Add_Char_To_Name_Buffer
(Get_Character
(C
));
25554 end Add_Config_Static_String
;
25556 -- Start of processing for Is_Config_Static_String
25561 return Add_Config_Static_String
(Arg
);
25562 end Is_Config_Static_String
;
25564 -------------------------------
25565 -- Is_Elaboration_SPARK_Mode --
25566 -------------------------------
25568 function Is_Elaboration_SPARK_Mode
(N
: Node_Id
) return Boolean is
25571 (Nkind
(N
) = N_Pragma
25572 and then Pragma_Name
(N
) = Name_SPARK_Mode
25573 and then Is_List_Member
(N
));
25575 -- Pragma SPARK_Mode affects the elaboration of a package body when it
25576 -- appears in the statement part of the body.
25579 Present
(Parent
(N
))
25580 and then Nkind
(Parent
(N
)) = N_Handled_Sequence_Of_Statements
25581 and then List_Containing
(N
) = Statements
(Parent
(N
))
25582 and then Present
(Parent
(Parent
(N
)))
25583 and then Nkind
(Parent
(Parent
(N
))) = N_Package_Body
;
25584 end Is_Elaboration_SPARK_Mode
;
25586 -----------------------------------------
25587 -- Is_Non_Significant_Pragma_Reference --
25588 -----------------------------------------
25590 -- This function makes use of the following static table which indicates
25591 -- whether appearance of some name in a given pragma is to be considered
25592 -- as a reference for the purposes of warnings about unreferenced objects.
25594 -- -1 indicates that appearence in any argument is significant
25595 -- 0 indicates that appearance in any argument is not significant
25596 -- +n indicates that appearance as argument n is significant, but all
25597 -- other arguments are not significant
25598 -- 9n arguments from n on are significant, before n inisignificant
25600 Sig_Flags
: constant array (Pragma_Id
) of Int
:=
25601 (Pragma_Abort_Defer
=> -1,
25602 Pragma_Abstract_State
=> -1,
25603 Pragma_Ada_83
=> -1,
25604 Pragma_Ada_95
=> -1,
25605 Pragma_Ada_05
=> -1,
25606 Pragma_Ada_2005
=> -1,
25607 Pragma_Ada_12
=> -1,
25608 Pragma_Ada_2012
=> -1,
25609 Pragma_All_Calls_Remote
=> -1,
25610 Pragma_Allow_Integer_Address
=> -1,
25611 Pragma_Annotate
=> 93,
25612 Pragma_Assert
=> -1,
25613 Pragma_Assert_And_Cut
=> -1,
25614 Pragma_Assertion_Policy
=> 0,
25615 Pragma_Assume
=> -1,
25616 Pragma_Assume_No_Invalid_Values
=> 0,
25617 Pragma_Async_Readers
=> 0,
25618 Pragma_Async_Writers
=> 0,
25619 Pragma_Asynchronous
=> 0,
25620 Pragma_Atomic
=> 0,
25621 Pragma_Atomic_Components
=> 0,
25622 Pragma_Attach_Handler
=> -1,
25623 Pragma_Attribute_Definition
=> 92,
25624 Pragma_Check
=> -1,
25625 Pragma_Check_Float_Overflow
=> 0,
25626 Pragma_Check_Name
=> 0,
25627 Pragma_Check_Policy
=> 0,
25628 Pragma_CIL_Constructor
=> 0,
25629 Pragma_CPP_Class
=> 0,
25630 Pragma_CPP_Constructor
=> 0,
25631 Pragma_CPP_Virtual
=> 0,
25632 Pragma_CPP_Vtable
=> 0,
25634 Pragma_C_Pass_By_Copy
=> 0,
25635 Pragma_Comment
=> -1,
25636 Pragma_Common_Object
=> 0,
25637 Pragma_Compile_Time_Error
=> -1,
25638 Pragma_Compile_Time_Warning
=> -1,
25639 Pragma_Compiler_Unit
=> -1,
25640 Pragma_Compiler_Unit_Warning
=> -1,
25641 Pragma_Complete_Representation
=> 0,
25642 Pragma_Complex_Representation
=> 0,
25643 Pragma_Component_Alignment
=> 0,
25644 Pragma_Contract_Cases
=> -1,
25645 Pragma_Controlled
=> 0,
25646 Pragma_Convention
=> 0,
25647 Pragma_Convention_Identifier
=> 0,
25648 Pragma_Debug
=> -1,
25649 Pragma_Debug_Policy
=> 0,
25650 Pragma_Detect_Blocking
=> 0,
25651 Pragma_Default_Initial_Condition
=> -1,
25652 Pragma_Default_Scalar_Storage_Order
=> 0,
25653 Pragma_Default_Storage_Pool
=> 0,
25654 Pragma_Depends
=> -1,
25655 Pragma_Disable_Atomic_Synchronization
=> 0,
25656 Pragma_Discard_Names
=> 0,
25657 Pragma_Dispatching_Domain
=> -1,
25658 Pragma_Effective_Reads
=> 0,
25659 Pragma_Effective_Writes
=> 0,
25660 Pragma_Elaborate
=> 0,
25661 Pragma_Elaborate_All
=> 0,
25662 Pragma_Elaborate_Body
=> 0,
25663 Pragma_Elaboration_Checks
=> 0,
25664 Pragma_Eliminate
=> 0,
25665 Pragma_Enable_Atomic_Synchronization
=> 0,
25666 Pragma_Export
=> -1,
25667 Pragma_Export_Function
=> -1,
25668 Pragma_Export_Object
=> -1,
25669 Pragma_Export_Procedure
=> -1,
25670 Pragma_Export_Value
=> -1,
25671 Pragma_Export_Valued_Procedure
=> -1,
25672 Pragma_Extend_System
=> -1,
25673 Pragma_Extensions_Allowed
=> 0,
25674 Pragma_Extensions_Visible
=> 0,
25675 Pragma_External
=> -1,
25676 Pragma_Favor_Top_Level
=> 0,
25677 Pragma_External_Name_Casing
=> 0,
25678 Pragma_Fast_Math
=> 0,
25679 Pragma_Finalize_Storage_Only
=> 0,
25681 Pragma_Global
=> -1,
25682 Pragma_Ident
=> -1,
25683 Pragma_Implementation_Defined
=> -1,
25684 Pragma_Implemented
=> -1,
25685 Pragma_Implicit_Packing
=> 0,
25686 Pragma_Import
=> 93,
25687 Pragma_Import_Function
=> 0,
25688 Pragma_Import_Object
=> 0,
25689 Pragma_Import_Procedure
=> 0,
25690 Pragma_Import_Valued_Procedure
=> 0,
25691 Pragma_Independent
=> 0,
25692 Pragma_Independent_Components
=> 0,
25693 Pragma_Initial_Condition
=> -1,
25694 Pragma_Initialize_Scalars
=> 0,
25695 Pragma_Initializes
=> -1,
25696 Pragma_Inline
=> 0,
25697 Pragma_Inline_Always
=> 0,
25698 Pragma_Inline_Generic
=> 0,
25699 Pragma_Inspection_Point
=> -1,
25700 Pragma_Interface
=> 92,
25701 Pragma_Interface_Name
=> 0,
25702 Pragma_Interrupt_Handler
=> -1,
25703 Pragma_Interrupt_Priority
=> -1,
25704 Pragma_Interrupt_State
=> -1,
25705 Pragma_Invariant
=> -1,
25706 Pragma_Java_Constructor
=> -1,
25707 Pragma_Java_Interface
=> -1,
25708 Pragma_Keep_Names
=> 0,
25709 Pragma_License
=> 0,
25710 Pragma_Link_With
=> -1,
25711 Pragma_Linker_Alias
=> -1,
25712 Pragma_Linker_Constructor
=> -1,
25713 Pragma_Linker_Destructor
=> -1,
25714 Pragma_Linker_Options
=> -1,
25715 Pragma_Linker_Section
=> 0,
25717 Pragma_Lock_Free
=> 0,
25718 Pragma_Locking_Policy
=> 0,
25719 Pragma_Loop_Invariant
=> -1,
25720 Pragma_Loop_Optimize
=> 0,
25721 Pragma_Loop_Variant
=> -1,
25722 Pragma_Machine_Attribute
=> -1,
25724 Pragma_Main_Storage
=> -1,
25725 Pragma_Memory_Size
=> 0,
25726 Pragma_No_Return
=> 0,
25727 Pragma_No_Body
=> 0,
25728 Pragma_No_Elaboration_Code_All
=> 0,
25729 Pragma_No_Inline
=> 0,
25730 Pragma_No_Run_Time
=> -1,
25731 Pragma_No_Strict_Aliasing
=> -1,
25732 Pragma_No_Tagged_Streams
=> 0,
25733 Pragma_Normalize_Scalars
=> 0,
25734 Pragma_Obsolescent
=> 0,
25735 Pragma_Optimize
=> 0,
25736 Pragma_Optimize_Alignment
=> 0,
25737 Pragma_Overflow_Mode
=> 0,
25738 Pragma_Overriding_Renamings
=> 0,
25739 Pragma_Ordered
=> 0,
25742 Pragma_Part_Of
=> 0,
25743 Pragma_Partition_Elaboration_Policy
=> 0,
25744 Pragma_Passive
=> 0,
25745 Pragma_Persistent_BSS
=> 0,
25746 Pragma_Polling
=> 0,
25747 Pragma_Prefix_Exception_Messages
=> 0,
25749 Pragma_Postcondition
=> -1,
25750 Pragma_Post_Class
=> -1,
25752 Pragma_Precondition
=> -1,
25753 Pragma_Predicate
=> -1,
25754 Pragma_Preelaborable_Initialization
=> -1,
25755 Pragma_Preelaborate
=> 0,
25756 Pragma_Pre_Class
=> -1,
25757 Pragma_Priority
=> -1,
25758 Pragma_Priority_Specific_Dispatching
=> 0,
25759 Pragma_Profile
=> 0,
25760 Pragma_Profile_Warnings
=> 0,
25761 Pragma_Propagate_Exceptions
=> 0,
25762 Pragma_Provide_Shift_Operators
=> 0,
25763 Pragma_Psect_Object
=> 0,
25765 Pragma_Pure_Function
=> 0,
25766 Pragma_Queuing_Policy
=> 0,
25767 Pragma_Rational
=> 0,
25768 Pragma_Ravenscar
=> 0,
25769 Pragma_Refined_Depends
=> -1,
25770 Pragma_Refined_Global
=> -1,
25771 Pragma_Refined_Post
=> -1,
25772 Pragma_Refined_State
=> -1,
25773 Pragma_Relative_Deadline
=> 0,
25774 Pragma_Remote_Access_Type
=> -1,
25775 Pragma_Remote_Call_Interface
=> -1,
25776 Pragma_Remote_Types
=> -1,
25777 Pragma_Restricted_Run_Time
=> 0,
25778 Pragma_Restriction_Warnings
=> 0,
25779 Pragma_Restrictions
=> 0,
25780 Pragma_Reviewable
=> -1,
25781 Pragma_Short_Circuit_And_Or
=> 0,
25782 Pragma_Share_Generic
=> 0,
25783 Pragma_Shared
=> 0,
25784 Pragma_Shared_Passive
=> 0,
25785 Pragma_Short_Descriptors
=> 0,
25786 Pragma_Simple_Storage_Pool_Type
=> 0,
25787 Pragma_Source_File_Name
=> 0,
25788 Pragma_Source_File_Name_Project
=> 0,
25789 Pragma_Source_Reference
=> 0,
25790 Pragma_SPARK_Mode
=> 0,
25791 Pragma_Storage_Size
=> -1,
25792 Pragma_Storage_Unit
=> 0,
25793 Pragma_Static_Elaboration_Desired
=> 0,
25794 Pragma_Stream_Convert
=> 0,
25795 Pragma_Style_Checks
=> 0,
25796 Pragma_Subtitle
=> 0,
25797 Pragma_Suppress
=> 0,
25798 Pragma_Suppress_Exception_Locations
=> 0,
25799 Pragma_Suppress_All
=> 0,
25800 Pragma_Suppress_Debug_Info
=> 0,
25801 Pragma_Suppress_Initialization
=> 0,
25802 Pragma_System_Name
=> 0,
25803 Pragma_Task_Dispatching_Policy
=> 0,
25804 Pragma_Task_Info
=> -1,
25805 Pragma_Task_Name
=> -1,
25806 Pragma_Task_Storage
=> -1,
25807 Pragma_Test_Case
=> -1,
25808 Pragma_Thread_Local_Storage
=> -1,
25809 Pragma_Time_Slice
=> -1,
25811 Pragma_Type_Invariant
=> -1,
25812 Pragma_Type_Invariant_Class
=> -1,
25813 Pragma_Unchecked_Union
=> 0,
25814 Pragma_Unimplemented_Unit
=> 0,
25815 Pragma_Universal_Aliasing
=> 0,
25816 Pragma_Universal_Data
=> 0,
25817 Pragma_Unmodified
=> 0,
25818 Pragma_Unreferenced
=> 0,
25819 Pragma_Unreferenced_Objects
=> 0,
25820 Pragma_Unreserve_All_Interrupts
=> 0,
25821 Pragma_Unsuppress
=> 0,
25822 Pragma_Unevaluated_Use_Of_Old
=> 0,
25823 Pragma_Use_VADS_Size
=> 0,
25824 Pragma_Validity_Checks
=> 0,
25825 Pragma_Volatile
=> 0,
25826 Pragma_Volatile_Components
=> 0,
25827 Pragma_Warning_As_Error
=> 0,
25828 Pragma_Warnings
=> 0,
25829 Pragma_Weak_External
=> 0,
25830 Pragma_Wide_Character_Encoding
=> 0,
25831 Unknown_Pragma
=> 0);
25833 function Is_Non_Significant_Pragma_Reference
(N
: Node_Id
) return Boolean is
25839 function Arg_No
return Nat
;
25840 -- Returns an integer showing what argument we are in. A value of
25841 -- zero means we are not in any of the arguments.
25847 function Arg_No
return Nat
is
25852 A
:= First
(Pragma_Argument_Associations
(Parent
(P
)));
25866 -- Start of processing for Non_Significant_Pragma_Reference
25871 if Nkind
(P
) /= N_Pragma_Argument_Association
then
25875 Id
:= Get_Pragma_Id
(Parent
(P
));
25876 C
:= Sig_Flags
(Id
);
25891 return AN
< (C
- 90);
25897 end Is_Non_Significant_Pragma_Reference
;
25899 ------------------------------
25900 -- Is_Pragma_String_Literal --
25901 ------------------------------
25903 -- This function returns true if the corresponding pragma argument is a
25904 -- static string expression. These are the only cases in which string
25905 -- literals can appear as pragma arguments. We also allow a string literal
25906 -- as the first argument to pragma Assert (although it will of course
25907 -- always generate a type error).
25909 function Is_Pragma_String_Literal
(Par
: Node_Id
) return Boolean is
25910 Pragn
: constant Node_Id
:= Parent
(Par
);
25911 Assoc
: constant List_Id
:= Pragma_Argument_Associations
(Pragn
);
25912 Pname
: constant Name_Id
:= Pragma_Name
(Pragn
);
25918 N
:= First
(Assoc
);
25925 if Pname
= Name_Assert
then
25928 elsif Pname
= Name_Export
then
25931 elsif Pname
= Name_Ident
then
25934 elsif Pname
= Name_Import
then
25937 elsif Pname
= Name_Interface_Name
then
25940 elsif Pname
= Name_Linker_Alias
then
25943 elsif Pname
= Name_Linker_Section
then
25946 elsif Pname
= Name_Machine_Attribute
then
25949 elsif Pname
= Name_Source_File_Name
then
25952 elsif Pname
= Name_Source_Reference
then
25955 elsif Pname
= Name_Title
then
25958 elsif Pname
= Name_Subtitle
then
25964 end Is_Pragma_String_Literal
;
25966 ---------------------------
25967 -- Is_Private_SPARK_Mode --
25968 ---------------------------
25970 function Is_Private_SPARK_Mode
(N
: Node_Id
) return Boolean is
25973 (Nkind
(N
) = N_Pragma
25974 and then Pragma_Name
(N
) = Name_SPARK_Mode
25975 and then Is_List_Member
(N
));
25977 -- For pragma SPARK_Mode to be private, it has to appear in the private
25978 -- declarations of a package.
25981 Present
(Parent
(N
))
25982 and then Nkind
(Parent
(N
)) = N_Package_Specification
25983 and then List_Containing
(N
) = Private_Declarations
(Parent
(N
));
25984 end Is_Private_SPARK_Mode
;
25986 -------------------------------------
25987 -- Is_Unconstrained_Or_Tagged_Item --
25988 -------------------------------------
25990 function Is_Unconstrained_Or_Tagged_Item
25991 (Item
: Entity_Id
) return Boolean
25993 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean;
25994 -- Determine whether record type Typ has at least one unconstrained
25997 ---------------------------------
25998 -- Has_Unconstrained_Component --
25999 ---------------------------------
26001 function Has_Unconstrained_Component
(Typ
: Entity_Id
) return Boolean is
26005 Comp
:= First_Component
(Typ
);
26006 while Present
(Comp
) loop
26007 if Is_Unconstrained_Or_Tagged_Item
(Comp
) then
26011 Next_Component
(Comp
);
26015 end Has_Unconstrained_Component
;
26019 Typ
: constant Entity_Id
:= Etype
(Item
);
26021 -- Start of processing for Is_Unconstrained_Or_Tagged_Item
26024 if Is_Tagged_Type
(Typ
) then
26027 elsif Is_Array_Type
(Typ
) and then not Is_Constrained
(Typ
) then
26030 elsif Is_Record_Type
(Typ
) then
26031 if Has_Discriminants
(Typ
) and then not Is_Constrained
(Typ
) then
26034 return Has_Unconstrained_Component
(Typ
);
26037 elsif Is_Private_Type
(Typ
) and then Has_Discriminants
(Typ
) then
26043 end Is_Unconstrained_Or_Tagged_Item
;
26045 -----------------------------
26046 -- Is_Valid_Assertion_Kind --
26047 -----------------------------
26049 function Is_Valid_Assertion_Kind
(Nam
: Name_Id
) return Boolean is
26056 Name_Static_Predicate |
26057 Name_Dynamic_Predicate |
26062 Name_Type_Invariant |
26063 Name_uType_Invariant |
26067 Name_Assert_And_Cut |
26069 Name_Contract_Cases |
26071 Name_Default_Initial_Condition |
26073 Name_Initial_Condition |
26076 Name_Loop_Invariant |
26077 Name_Loop_Variant |
26078 Name_Postcondition |
26079 Name_Precondition |
26081 Name_Refined_Post |
26082 Name_Statement_Assertions
=> return True;
26084 when others => return False;
26086 end Is_Valid_Assertion_Kind
;
26088 --------------------------------------
26089 -- Process_Compilation_Unit_Pragmas --
26090 --------------------------------------
26092 procedure Process_Compilation_Unit_Pragmas
(N
: Node_Id
) is
26094 -- A special check for pragma Suppress_All, a very strange DEC pragma,
26095 -- strange because it comes at the end of the unit. Rational has the
26096 -- same name for a pragma, but treats it as a program unit pragma, In
26097 -- GNAT we just decide to allow it anywhere at all. If it appeared then
26098 -- the flag Has_Pragma_Suppress_All was set on the compilation unit
26099 -- node, and we insert a pragma Suppress (All_Checks) at the start of
26100 -- the context clause to ensure the correct processing.
26102 if Has_Pragma_Suppress_All
(N
) then
26103 Prepend_To
(Context_Items
(N
),
26104 Make_Pragma
(Sloc
(N
),
26105 Chars
=> Name_Suppress
,
26106 Pragma_Argument_Associations
=> New_List
(
26107 Make_Pragma_Argument_Association
(Sloc
(N
),
26108 Expression
=> Make_Identifier
(Sloc
(N
), Name_All_Checks
)))));
26111 -- Nothing else to do at the current time
26113 end Process_Compilation_Unit_Pragmas
;
26115 ------------------------------------
26116 -- Record_Possible_Body_Reference --
26117 ------------------------------------
26119 procedure Record_Possible_Body_Reference
26120 (State_Id
: Entity_Id
;
26124 Spec_Id
: Entity_Id
;
26127 -- Ensure that we are dealing with a reference to a state
26129 pragma Assert
(Ekind
(State_Id
) = E_Abstract_State
);
26131 -- Climb the tree starting from the reference looking for a package body
26132 -- whose spec declares the referenced state. This criteria automatically
26133 -- excludes references in package specs which are legal. Note that it is
26134 -- not wise to emit an error now as the package body may lack pragma
26135 -- Refined_State or the referenced state may not be mentioned in the
26136 -- refinement. This approach avoids the generation of misleading errors.
26139 while Present
(Context
) loop
26140 if Nkind
(Context
) = N_Package_Body
then
26141 Spec_Id
:= Corresponding_Spec
(Context
);
26143 if Present
(Abstract_States
(Spec_Id
))
26144 and then Contains
(Abstract_States
(Spec_Id
), State_Id
)
26146 if No
(Body_References
(State_Id
)) then
26147 Set_Body_References
(State_Id
, New_Elmt_List
);
26150 Append_Elmt
(Ref
, To
=> Body_References
(State_Id
));
26155 Context
:= Parent
(Context
);
26157 end Record_Possible_Body_Reference
;
26159 ------------------------------
26160 -- Relocate_Pragmas_To_Body --
26161 ------------------------------
26163 procedure Relocate_Pragmas_To_Body
26164 (Subp_Body
: Node_Id
;
26165 Target_Body
: Node_Id
:= Empty
)
26167 procedure Relocate_Pragma
(Prag
: Node_Id
);
26168 -- Remove a single pragma from its current list and add it to the
26169 -- declarations of the proper body (either Subp_Body or Target_Body).
26171 ---------------------
26172 -- Relocate_Pragma --
26173 ---------------------
26175 procedure Relocate_Pragma
(Prag
: Node_Id
) is
26180 -- When subprogram stubs or expression functions are involves, the
26181 -- destination declaration list belongs to the proper body.
26183 if Present
(Target_Body
) then
26184 Target
:= Target_Body
;
26186 Target
:= Subp_Body
;
26189 Decls
:= Declarations
(Target
);
26193 Set_Declarations
(Target
, Decls
);
26196 -- Unhook the pragma from its current list
26199 Prepend
(Prag
, Decls
);
26200 end Relocate_Pragma
;
26204 Body_Id
: constant Entity_Id
:=
26205 Defining_Unit_Name
(Specification
(Subp_Body
));
26206 Next_Stmt
: Node_Id
;
26209 -- Start of processing for Relocate_Pragmas_To_Body
26212 -- Do not process a body that comes from a separate unit as no construct
26213 -- can possibly follow it.
26215 if not Is_List_Member
(Subp_Body
) then
26218 -- Do not relocate pragmas that follow a stub if the stub does not have
26221 elsif Nkind
(Subp_Body
) = N_Subprogram_Body_Stub
26222 and then No
(Target_Body
)
26226 -- Do not process internally generated routine _Postconditions
26228 elsif Ekind
(Body_Id
) = E_Procedure
26229 and then Chars
(Body_Id
) = Name_uPostconditions
26234 -- Look at what is following the body. We are interested in certain kind
26235 -- of pragmas (either from source or byproducts of expansion) that can
26236 -- apply to a body [stub].
26238 Stmt
:= Next
(Subp_Body
);
26239 while Present
(Stmt
) loop
26241 -- Preserve the following statement for iteration purposes due to a
26242 -- possible relocation of a pragma.
26244 Next_Stmt
:= Next
(Stmt
);
26246 -- Move a candidate pragma following the body to the declarations of
26249 if Nkind
(Stmt
) = N_Pragma
26250 and then Pragma_On_Body_Or_Stub_OK
(Get_Pragma_Id
(Stmt
))
26252 Relocate_Pragma
(Stmt
);
26254 -- Skip internally generated code
26256 elsif not Comes_From_Source
(Stmt
) then
26259 -- No candidate pragmas are available for relocation
26267 end Relocate_Pragmas_To_Body
;
26269 -------------------
26270 -- Resolve_State --
26271 -------------------
26273 procedure Resolve_State
(N
: Node_Id
) is
26278 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
26279 Func
:= Entity
(N
);
26281 -- Handle overloading of state names by functions. Traverse the
26282 -- homonym chain looking for an abstract state.
26284 if Ekind
(Func
) = E_Function
and then Has_Homonym
(Func
) then
26285 State
:= Homonym
(Func
);
26286 while Present
(State
) loop
26288 -- Resolve the overloading by setting the proper entity of the
26289 -- reference to that of the state.
26291 if Ekind
(State
) = E_Abstract_State
then
26292 Set_Etype
(N
, Standard_Void_Type
);
26293 Set_Entity
(N
, State
);
26294 Set_Associated_Node
(N
, State
);
26298 State
:= Homonym
(State
);
26301 -- A function can never act as a state. If the homonym chain does
26302 -- not contain a corresponding state, then something went wrong in
26303 -- the overloading mechanism.
26305 raise Program_Error
;
26310 ----------------------------
26311 -- Rewrite_Assertion_Kind --
26312 ----------------------------
26314 procedure Rewrite_Assertion_Kind
(N
: Node_Id
) is
26318 if Nkind
(N
) = N_Attribute_Reference
26319 and then Attribute_Name
(N
) = Name_Class
26320 and then Nkind
(Prefix
(N
)) = N_Identifier
26322 case Chars
(Prefix
(N
)) is
26327 when Name_Type_Invariant
=>
26328 Nam
:= Name_uType_Invariant
;
26329 when Name_Invariant
=>
26330 Nam
:= Name_uInvariant
;
26335 Rewrite
(N
, Make_Identifier
(Sloc
(N
), Chars
=> Nam
));
26337 end Rewrite_Assertion_Kind
;
26345 Dummy
:= Dummy
+ 1;
26348 --------------------------------
26349 -- Set_Encoded_Interface_Name --
26350 --------------------------------
26352 procedure Set_Encoded_Interface_Name
(E
: Entity_Id
; S
: Node_Id
) is
26353 Str
: constant String_Id
:= Strval
(S
);
26354 Len
: constant Int
:= String_Length
(Str
);
26359 Hex
: constant array (0 .. 15) of Character := "0123456789abcdef";
26362 -- Stores encoded value of character code CC. The encoding we use an
26363 -- underscore followed by four lower case hex digits.
26369 procedure Encode
is
26371 Store_String_Char
(Get_Char_Code
('_'));
26373 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 12))));
26375 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 8 and 16#
0F#
))));
26377 (Get_Char_Code
(Hex
(Integer (CC
/ 2 ** 4 and 16#
0F#
))));
26379 (Get_Char_Code
(Hex
(Integer (CC
and 16#
0F#
))));
26382 -- Start of processing for Set_Encoded_Interface_Name
26385 -- If first character is asterisk, this is a link name, and we leave it
26386 -- completely unmodified. We also ignore null strings (the latter case
26387 -- happens only in error cases) and no encoding should occur for Java or
26388 -- AAMP interface names.
26391 or else Get_String_Char
(Str
, 1) = Get_Char_Code
('*')
26392 or else VM_Target
/= No_VM
26393 or else AAMP_On_Target
26395 Set_Interface_Name
(E
, S
);
26400 CC
:= Get_String_Char
(Str
, J
);
26402 exit when not In_Character_Range
(CC
);
26404 C
:= Get_Character
(CC
);
26406 exit when C
/= '_' and then C
/= '$'
26407 and then C
not in '0' .. '9'
26408 and then C
not in 'a' .. 'z'
26409 and then C
not in 'A' .. 'Z';
26412 Set_Interface_Name
(E
, S
);
26420 -- Here we need to encode. The encoding we use as follows:
26421 -- three underscores + four hex digits (lower case)
26425 for J
in 1 .. String_Length
(Str
) loop
26426 CC
:= Get_String_Char
(Str
, J
);
26428 if not In_Character_Range
(CC
) then
26431 C
:= Get_Character
(CC
);
26433 if C
= '_' or else C
= '$'
26434 or else C
in '0' .. '9'
26435 or else C
in 'a' .. 'z'
26436 or else C
in 'A' .. 'Z'
26438 Store_String_Char
(CC
);
26445 Set_Interface_Name
(E
,
26446 Make_String_Literal
(Sloc
(S
),
26447 Strval
=> End_String
));
26449 end Set_Encoded_Interface_Name
;
26451 ------------------------
26452 -- Set_Elab_Unit_Name --
26453 ------------------------
26455 procedure Set_Elab_Unit_Name
(N
: Node_Id
; With_Item
: Node_Id
) is
26460 if Nkind
(N
) = N_Identifier
26461 and then Nkind
(With_Item
) = N_Identifier
26463 Set_Entity
(N
, Entity
(With_Item
));
26465 elsif Nkind
(N
) = N_Selected_Component
then
26466 Change_Selected_Component_To_Expanded_Name
(N
);
26467 Set_Entity
(N
, Entity
(With_Item
));
26468 Set_Entity
(Selector_Name
(N
), Entity
(N
));
26470 Pref
:= Prefix
(N
);
26471 Scop
:= Scope
(Entity
(N
));
26472 while Nkind
(Pref
) = N_Selected_Component
loop
26473 Change_Selected_Component_To_Expanded_Name
(Pref
);
26474 Set_Entity
(Selector_Name
(Pref
), Scop
);
26475 Set_Entity
(Pref
, Scop
);
26476 Pref
:= Prefix
(Pref
);
26477 Scop
:= Scope
(Scop
);
26480 Set_Entity
(Pref
, Scop
);
26483 Generate_Reference
(Entity
(With_Item
), N
, Set_Ref
=> False);
26484 end Set_Elab_Unit_Name
;
26486 -------------------
26487 -- Test_Case_Arg --
26488 -------------------
26490 function Test_Case_Arg
26493 From_Aspect
: Boolean := False) return Node_Id
26495 Aspect
: constant Node_Id
:= Corresponding_Aspect
(Prag
);
26500 pragma Assert
(Nam_In
(Arg_Nam
, Name_Ensures
,
26505 -- The caller requests the aspect argument
26507 if From_Aspect
then
26508 if Present
(Aspect
)
26509 and then Nkind
(Expression
(Aspect
)) = N_Aggregate
26511 Args
:= Expression
(Aspect
);
26513 -- "Name" and "Mode" may appear without an identifier as a
26514 -- positional association.
26516 if Present
(Expressions
(Args
)) then
26517 Arg
:= First
(Expressions
(Args
));
26519 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
26527 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
26532 -- Some or all arguments may appear as component associatons
26534 if Present
(Component_Associations
(Args
)) then
26535 Arg
:= First
(Component_Associations
(Args
));
26536 while Present
(Arg
) loop
26537 if Chars
(First
(Choices
(Arg
))) = Arg_Nam
then
26546 -- Otherwise retrieve the argument directly from the pragma
26549 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
26551 if Present
(Arg
) and then Arg_Nam
= Name_Name
then
26555 -- Skip argument "Name"
26559 if Present
(Arg
) and then Arg_Nam
= Name_Mode
then
26563 -- Skip argument "Mode"
26567 -- Arguments "Requires" and "Ensures" are optional and may not be
26570 while Present
(Arg
) loop
26571 if Chars
(Arg
) = Arg_Nam
then