| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E M _ P R A G -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 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. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 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). |
| 31 |
|
| 32 |
with Aspects; use Aspects; |
| 33 |
with Atree; use Atree; |
| 34 |
with Casing; use Casing; |
| 35 |
with Checks; use Checks; |
| 36 |
with Contracts; use Contracts; |
| 37 |
with Csets; use Csets; |
| 38 |
with Debug; use Debug; |
| 39 |
with Einfo; use Einfo; |
| 40 |
with Einfo.Entities; use Einfo.Entities; |
| 41 |
with Einfo.Utils; use Einfo.Utils; |
| 42 |
with Elists; use Elists; |
| 43 |
with Errout; use Errout; |
| 44 |
with Exp_Dist; use Exp_Dist; |
| 45 |
with Exp_Util; use Exp_Util; |
| 46 |
with Expander; use Expander; |
| 47 |
with Freeze; use Freeze; |
| 48 |
with Ghost; use Ghost; |
| 49 |
with GNAT_CUDA; use GNAT_CUDA; |
| 50 |
with Gnatvsn; use Gnatvsn; |
| 51 |
with Lib; use Lib; |
| 52 |
with Lib.Writ; use Lib.Writ; |
| 53 |
with Lib.Xref; use Lib.Xref; |
| 54 |
with Namet.Sp; use Namet.Sp; |
| 55 |
with Nlists; use Nlists; |
| 56 |
with Nmake; use Nmake; |
| 57 |
with Output; use Output; |
| 58 |
with Par_SCO; use Par_SCO; |
| 59 |
with Restrict; use Restrict; |
| 60 |
with Rident; use Rident; |
| 61 |
with Rtsfind; use Rtsfind; |
| 62 |
with Sem; use Sem; |
| 63 |
with Sem_Aux; use Sem_Aux; |
| 64 |
with Sem_Ch3; use Sem_Ch3; |
| 65 |
with Sem_Ch6; use Sem_Ch6; |
| 66 |
with Sem_Ch7; use Sem_Ch7; |
| 67 |
with Sem_Ch8; use Sem_Ch8; |
| 68 |
with Sem_Ch12; use Sem_Ch12; |
| 69 |
with Sem_Ch13; use Sem_Ch13; |
| 70 |
with Sem_Disp; use Sem_Disp; |
| 71 |
with Sem_Dist; use Sem_Dist; |
| 72 |
with Sem_Elab; use Sem_Elab; |
| 73 |
with Sem_Elim; use Sem_Elim; |
| 74 |
with Sem_Eval; use Sem_Eval; |
| 75 |
with Sem_Intr; use Sem_Intr; |
| 76 |
with Sem_Mech; use Sem_Mech; |
| 77 |
with Sem_Res; use Sem_Res; |
| 78 |
with Sem_Type; use Sem_Type; |
| 79 |
with Sem_Util; use Sem_Util; |
| 80 |
with Sem_Warn; use Sem_Warn; |
| 81 |
with Stand; use Stand; |
| 82 |
with Sinfo; use Sinfo; |
| 83 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 84 |
with Sinfo.Utils; use Sinfo.Utils; |
| 85 |
with Sinfo.CN; use Sinfo.CN; |
| 86 |
with Sinput; use Sinput; |
| 87 |
with Stringt; use Stringt; |
| 88 |
with Strub; use Strub; |
| 89 |
with Stylesw; use Stylesw; |
| 90 |
with Table; |
| 91 |
with Targparm; use Targparm; |
| 92 |
with Tbuild; use Tbuild; |
| 93 |
with Ttypes; use Ttypes; |
| 94 |
with Uintp; use Uintp; |
| 95 |
with Uname; use Uname; |
| 96 |
with Urealp; use Urealp; |
| 97 |
with Validsw; use Validsw; |
| 98 |
with Warnsw; use Warnsw; |
| 99 |
|
| 100 |
with System.Case_Util; |
| 101 |
|
| 102 |
package body Sem_Prag is |
| 103 |
|
| 104 |
---------------------------------------------- |
| 105 |
-- Common Handling of Import-Export Pragmas -- |
| 106 |
---------------------------------------------- |
| 107 |
|
| 108 |
-- In the following section, a number of Import_xxx and Export_xxx pragmas |
| 109 |
-- are defined by GNAT. These are compatible with the DEC pragmas of the |
| 110 |
-- same name, and all have the following common form and processing: |
| 111 |
|
| 112 |
-- pragma Export_xxx |
| 113 |
-- [Internal =>] LOCAL_NAME |
| 114 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 115 |
-- [, other optional parameters ]); |
| 116 |
|
| 117 |
-- pragma Import_xxx |
| 118 |
-- [Internal =>] LOCAL_NAME |
| 119 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 120 |
-- [, other optional parameters ]); |
| 121 |
|
| 122 |
-- EXTERNAL_SYMBOL ::= |
| 123 |
-- IDENTIFIER |
| 124 |
-- | static_string_EXPRESSION |
| 125 |
|
| 126 |
-- The internal LOCAL_NAME designates the entity that is imported or |
| 127 |
-- exported, and must refer to an entity in the current declarative |
| 128 |
-- part (as required by the rules for LOCAL_NAME). |
| 129 |
|
| 130 |
-- The external linker name is designated by the External parameter if |
| 131 |
-- given, or the Internal parameter if not (if there is no External |
| 132 |
-- parameter, the External parameter is a copy of the Internal name). |
| 133 |
|
| 134 |
-- If the External parameter is given as a string, then this string is |
| 135 |
-- treated as an external name (exactly as though it had been given as an |
| 136 |
-- External_Name parameter for a normal Import pragma). |
| 137 |
|
| 138 |
-- If the External parameter is given as an identifier (or there is no |
| 139 |
-- External parameter, so that the Internal identifier is used), then |
| 140 |
-- the external name is the characters of the identifier, translated |
| 141 |
-- to all lower case letters. |
| 142 |
|
| 143 |
-- Note: the external name specified or implied by any of these special |
| 144 |
-- Import_xxx or Export_xxx pragmas override an external or link name |
| 145 |
-- specified in a previous Import or Export pragma. |
| 146 |
|
| 147 |
-- Note: these and all other DEC-compatible GNAT pragmas allow full use of |
| 148 |
-- named notation, following the standard rules for subprogram calls, i.e. |
| 149 |
-- parameters can be given in any order if named notation is used, and |
| 150 |
-- positional and named notation can be mixed, subject to the rule that all |
| 151 |
-- positional parameters must appear first. |
| 152 |
|
| 153 |
-- Note: All these pragmas are implemented exactly following the DEC design |
| 154 |
-- and implementation and are intended to be fully compatible with the use |
| 155 |
-- of these pragmas in the DEC Ada compiler. |
| 156 |
|
| 157 |
-------------------------------------------- |
| 158 |
-- Checking for Duplicated External Names -- |
| 159 |
-------------------------------------------- |
| 160 |
|
| 161 |
-- It is suspicious if two separate Export pragmas use the same external |
| 162 |
-- name. The following table is used to diagnose this situation so that |
| 163 |
-- an appropriate warning can be issued. |
| 164 |
|
| 165 |
-- The Node_Id stored is for the N_String_Literal node created to hold |
| 166 |
-- the value of the external name. The Sloc of this node is used to |
| 167 |
-- cross-reference the location of the duplication. |
| 168 |
|
| 169 |
package Externals is new Table.Table ( |
| 170 |
Table_Component_Type => Node_Id, |
| 171 |
Table_Index_Type => Int, |
| 172 |
Table_Low_Bound => 0, |
| 173 |
Table_Initial => 100, |
| 174 |
Table_Increment => 100, |
| 175 |
Table_Name => "Name_Externals"); |
| 176 |
|
| 177 |
------------------------------------- |
| 178 |
-- Local Subprograms and Variables -- |
| 179 |
------------------------------------- |
| 180 |
|
| 181 |
function Adjust_External_Name_Case (N : Node_Id) return Node_Id; |
| 182 |
-- This routine is used for possible casing adjustment of an explicit |
| 183 |
-- external name supplied as a string literal (the node N), according to |
| 184 |
-- the casing requirement of Opt.External_Name_Casing. If this is set to |
| 185 |
-- As_Is, then the string literal is returned unchanged, but if it is set |
| 186 |
-- to Uppercase or Lowercase, then a new string literal with appropriate |
| 187 |
-- casing is constructed. |
| 188 |
|
| 189 |
procedure Analyze_If_Present_Internal |
| 190 |
(N : Node_Id; |
| 191 |
Id : Pragma_Id; |
| 192 |
Included : Boolean); |
| 193 |
-- Inspect the remainder of the list containing pragma N and look for a |
| 194 |
-- pragma that matches Id. If found, analyze the pragma. If Included is |
| 195 |
-- True, N is included in the search. |
| 196 |
|
| 197 |
procedure Analyze_Part_Of |
| 198 |
(Indic : Node_Id; |
| 199 |
Item_Id : Entity_Id; |
| 200 |
Encap : Node_Id; |
| 201 |
Encap_Id : out Entity_Id; |
| 202 |
Legal : out Boolean); |
| 203 |
-- Subsidiary to Analyze_Part_Of_In_Decl_Part, Analyze_Part_Of_Option and |
| 204 |
-- Analyze_Pragma. Perform full analysis of indicator Part_Of. Indic is the |
| 205 |
-- Part_Of indicator. Item_Id is the entity of an abstract state, object or |
| 206 |
-- package instantiation. Encap denotes the encapsulating state or single |
| 207 |
-- concurrent type. Encap_Id is the entity of Encap. Flag Legal is set when |
| 208 |
-- the indicator is legal. |
| 209 |
|
| 210 |
function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean; |
| 211 |
-- Subsidiary to analysis of pragmas Depends, Global and Refined_Depends. |
| 212 |
-- Query whether a particular item appears in a mixed list of nodes and |
| 213 |
-- entities. It is assumed that all nodes in the list have entities. |
| 214 |
|
| 215 |
procedure Check_Postcondition_Use_In_Inlined_Subprogram |
| 216 |
(Prag : Node_Id; |
| 217 |
Spec_Id : Entity_Id); |
| 218 |
-- Subsidiary to the analysis of pragmas Contract_Cases, Postcondition, |
| 219 |
-- Precondition, Refined_Post, Subprogram_Variant, and Test_Case. Emit a |
| 220 |
-- warning when pragma Prag is associated with subprogram Spec_Id subject |
| 221 |
-- to Inline_Always, assertions are enabled and inling is done in the |
| 222 |
-- frontend. |
| 223 |
|
| 224 |
procedure Check_State_And_Constituent_Use |
| 225 |
(States : Elist_Id; |
| 226 |
Constits : Elist_Id; |
| 227 |
Context : Node_Id); |
| 228 |
-- Subsidiary to the analysis of pragmas [Refined_]Depends, [Refined_] |
| 229 |
-- Global and Initializes. Determine whether a state from list States and a |
| 230 |
-- corresponding constituent from list Constits (if any) appear in the same |
| 231 |
-- context denoted by Context. If this is the case, emit an error. |
| 232 |
|
| 233 |
procedure Contract_Freeze_Error |
| 234 |
(Contract_Id : Entity_Id; |
| 235 |
Freeze_Id : Entity_Id); |
| 236 |
-- Subsidiary to the analysis of pragmas Contract_Cases, Exceptional_Cases, |
| 237 |
-- Part_Of, Post, Pre and Subprogram_Variant. Emit a freezing-related error |
| 238 |
-- message where Freeze_Id is the entity of a body which caused contract |
| 239 |
-- freezing and Contract_Id denotes the entity of the affected contstruct. |
| 240 |
|
| 241 |
procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id); |
| 242 |
-- Subsidiary to all Find_Related_xxx routines. Emit an error on pragma |
| 243 |
-- Prag that duplicates previous pragma Prev. |
| 244 |
|
| 245 |
function Find_Encapsulating_State |
| 246 |
(States : Elist_Id; |
| 247 |
Constit_Id : Entity_Id) return Entity_Id; |
| 248 |
-- Given the entity of a constituent Constit_Id, find the corresponding |
| 249 |
-- encapsulating state which appears in States. The routine returns Empty |
| 250 |
-- if no such state is found. |
| 251 |
|
| 252 |
function Find_Related_Context |
| 253 |
(Prag : Node_Id; |
| 254 |
Do_Checks : Boolean := False) return Node_Id; |
| 255 |
-- Subsidiary to the analysis of pragmas |
| 256 |
-- Async_Readers |
| 257 |
-- Async_Writers |
| 258 |
-- Constant_After_Elaboration |
| 259 |
-- Effective_Reads |
| 260 |
-- Effective_Writers |
| 261 |
-- No_Caching |
| 262 |
-- Part_Of |
| 263 |
-- Find the first source declaration or statement found while traversing |
| 264 |
-- the previous node chain starting from pragma Prag. If flag Do_Checks is |
| 265 |
-- set, the routine reports duplicate pragmas. The routine returns Empty |
| 266 |
-- when reaching the start of the node chain. |
| 267 |
|
| 268 |
function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id; |
| 269 |
-- If Def_Id refers to a renamed subprogram, then the base subprogram (the |
| 270 |
-- original one, following the renaming chain) is returned. Otherwise the |
| 271 |
-- entity is returned unchanged. Should be in Einfo??? |
| 272 |
|
| 273 |
function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type; |
| 274 |
-- Subsidiary to the analysis of pragma SPARK_Mode as well as subprogram |
| 275 |
-- Get_SPARK_Mode_From_Annotation. Convert a name into a corresponding |
| 276 |
-- value of type SPARK_Mode_Type. |
| 277 |
|
| 278 |
function Has_Extra_Parentheses (Clause : Node_Id) return Boolean; |
| 279 |
-- Subsidiary to the analysis of pragmas Depends and Refined_Depends. |
| 280 |
-- Determine whether dependency clause Clause is surrounded by extra |
| 281 |
-- parentheses. If this is the case, issue an error message. |
| 282 |
|
| 283 |
procedure Record_Possible_Body_Reference |
| 284 |
(State_Id : Entity_Id; |
| 285 |
Ref : Node_Id); |
| 286 |
-- Subsidiary to the analysis of pragmas [Refined_]Depends and [Refined_] |
| 287 |
-- Global. Given an abstract state denoted by State_Id and a reference Ref |
| 288 |
-- to it, determine whether the reference appears in a package body that |
| 289 |
-- will eventually refine the state. If this is the case, record the |
| 290 |
-- reference for future checks (see Analyze_Refined_State_In_Decls). |
| 291 |
|
| 292 |
procedure Resolve_State (N : Node_Id); |
| 293 |
-- Handle the overloading of state names by functions. When N denotes a |
| 294 |
-- function, this routine finds the corresponding state and sets the entity |
| 295 |
-- of N to that of the state. |
| 296 |
|
| 297 |
procedure Rewrite_Assertion_Kind |
| 298 |
(N : Node_Id; |
| 299 |
From_Policy : Boolean := False); |
| 300 |
-- If N is Pre'Class, Post'Class, Invariant'Class, or Type_Invariant'Class, |
| 301 |
-- then it is rewritten as an identifier with the corresponding special |
| 302 |
-- name _Pre, _Post, _Invariant, or _Type_Invariant. Used by pragmas Check |
| 303 |
-- and Check_Policy. If the names are Precondition or Postcondition, this |
| 304 |
-- combination is deprecated in favor of Assertion_Policy and Ada2012 |
| 305 |
-- Aspect names. The parameter From_Policy indicates that the pragma |
| 306 |
-- is the old non-standard Check_Policy and not a rewritten pragma. |
| 307 |
|
| 308 |
procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id); |
| 309 |
-- Place semantic information on the argument of an Elaborate/Elaborate_All |
| 310 |
-- pragma. Entity name for unit and its parents is taken from item in |
| 311 |
-- previous with_clause that mentions the unit. |
| 312 |
|
| 313 |
procedure Validate_Compile_Time_Warning_Or_Error |
| 314 |
(N : Node_Id; |
| 315 |
Eloc : Source_Ptr); |
| 316 |
-- Common processing for Compile_Time_Error and Compile_Time_Warning of |
| 317 |
-- pragma N. Called when the pragma is processed as part of its regular |
| 318 |
-- analysis but also called after calling the back end to validate these |
| 319 |
-- pragmas for size and alignment appropriateness. |
| 320 |
|
| 321 |
procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id); |
| 322 |
-- N is a pragma Compile_Time_Error or Compile_Warning_Error whose boolean |
| 323 |
-- expression is not known at compile time during the front end. This |
| 324 |
-- procedure makes an entry in a table. The actual checking is performed by |
| 325 |
-- Validate_Compile_Time_Warning_Errors, which is invoked after calling the |
| 326 |
-- back end. |
| 327 |
|
| 328 |
Dummy : Integer := 0; |
| 329 |
pragma Volatile (Dummy); |
| 330 |
-- Dummy volatile integer used in bodies of ip/rv to prevent optimization |
| 331 |
|
| 332 |
procedure ip; |
| 333 |
pragma No_Inline (ip); |
| 334 |
-- A dummy procedure called when pragma Inspection_Point is analyzed. This |
| 335 |
-- is just to help debugging the front end. If a pragma Inspection_Point |
| 336 |
-- is added to a source program, then breaking on ip will get you to that |
| 337 |
-- point in the program. |
| 338 |
|
| 339 |
procedure rv; |
| 340 |
pragma No_Inline (rv); |
| 341 |
-- This is a dummy function called by the processing for pragma Reviewable. |
| 342 |
-- It is there for assisting front end debugging. By placing a Reviewable |
| 343 |
-- pragma in the source program, a breakpoint on rv catches this place in |
| 344 |
-- the source, allowing convenient stepping to the point of interest. |
| 345 |
|
| 346 |
------------------------------------------------------ |
| 347 |
-- Table for Defer_Compile_Time_Warning_Error_To_BE -- |
| 348 |
------------------------------------------------------ |
| 349 |
|
| 350 |
-- The following table collects pragmas Compile_Time_Error and Compile_ |
| 351 |
-- Time_Warning for validation. Entries are made by calls to subprogram |
| 352 |
-- Defer_Compile_Time_Warning_Error_To_BE, and the call to the procedure |
| 353 |
-- Validate_Compile_Time_Warning_Errors does the actual error checking |
| 354 |
-- and posting of warning and error messages. The reason for this delayed |
| 355 |
-- processing is to take advantage of back-annotations of attributes size |
| 356 |
-- and alignment values performed by the back end. |
| 357 |
|
| 358 |
-- Note: the reason we store a Source_Ptr value instead of a Node_Id is |
| 359 |
-- that by the time Validate_Compile_Time_Warning_Errors is called, Sprint |
| 360 |
-- will already have modified all Sloc values if the -gnatD option is set. |
| 361 |
|
| 362 |
type CTWE_Entry is record |
| 363 |
Eloc : Source_Ptr; |
| 364 |
-- Source location used in warnings and error messages |
| 365 |
|
| 366 |
Prag : Node_Id; |
| 367 |
-- Pragma Compile_Time_Error or Compile_Time_Warning |
| 368 |
|
| 369 |
Scope : Node_Id; |
| 370 |
-- The scope which encloses the pragma |
| 371 |
end record; |
| 372 |
|
| 373 |
package Compile_Time_Warnings_Errors is new Table.Table ( |
| 374 |
Table_Component_Type => CTWE_Entry, |
| 375 |
Table_Index_Type => Int, |
| 376 |
Table_Low_Bound => 1, |
| 377 |
Table_Initial => 50, |
| 378 |
Table_Increment => 200, |
| 379 |
Table_Name => "Compile_Time_Warnings_Errors"); |
| 380 |
|
| 381 |
------------------------------- |
| 382 |
-- Adjust_External_Name_Case -- |
| 383 |
------------------------------- |
| 384 |
|
| 385 |
function Adjust_External_Name_Case (N : Node_Id) return Node_Id is |
| 386 |
CC : Char_Code; |
| 387 |
|
| 388 |
begin |
| 389 |
-- Adjust case of literal if required |
| 390 |
|
| 391 |
if Opt.External_Name_Exp_Casing = As_Is then |
| 392 |
return N; |
| 393 |
|
| 394 |
else |
| 395 |
-- Copy existing string |
| 396 |
|
| 397 |
Start_String; |
| 398 |
|
| 399 |
-- Set proper casing |
| 400 |
|
| 401 |
for J in 1 .. String_Length (Strval (N)) loop |
| 402 |
CC := Get_String_Char (Strval (N), J); |
| 403 |
|
| 404 |
if Opt.External_Name_Exp_Casing = Uppercase |
| 405 |
and then CC in Get_Char_Code ('a') .. Get_Char_Code ('z') |
| 406 |
then |
| 407 |
Store_String_Char (CC - 32); |
| 408 |
|
| 409 |
elsif Opt.External_Name_Exp_Casing = Lowercase |
| 410 |
and then CC in Get_Char_Code ('A') .. Get_Char_Code ('Z') |
| 411 |
then |
| 412 |
Store_String_Char (CC + 32); |
| 413 |
|
| 414 |
else |
| 415 |
Store_String_Char (CC); |
| 416 |
end if; |
| 417 |
end loop; |
| 418 |
|
| 419 |
return |
| 420 |
Make_String_Literal (Sloc (N), |
| 421 |
Strval => End_String); |
| 422 |
end if; |
| 423 |
end Adjust_External_Name_Case; |
| 424 |
|
| 425 |
-------------------------------------------- |
| 426 |
-- Analyze_Always_Terminates_In_Decl_Part -- |
| 427 |
-------------------------------------------- |
| 428 |
|
| 429 |
procedure Analyze_Always_Terminates_In_Decl_Part |
| 430 |
(N : Node_Id; |
| 431 |
Freeze_Id : Entity_Id := Empty) |
| 432 |
is |
| 433 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 434 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 435 |
Arg1 : constant Node_Id := |
| 436 |
First (Pragma_Argument_Associations (N)); |
| 437 |
|
| 438 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 439 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 440 |
-- Save the Ghost-related attributes to restore on exit |
| 441 |
|
| 442 |
Errors : Nat; |
| 443 |
Restore_Scope : Boolean := False; |
| 444 |
|
| 445 |
begin |
| 446 |
-- Do not analyze the pragma multiple times |
| 447 |
|
| 448 |
if Is_Analyzed_Pragma (N) then |
| 449 |
return; |
| 450 |
end if; |
| 451 |
|
| 452 |
if Present (Arg1) then |
| 453 |
|
| 454 |
-- Set the Ghost mode in effect from the pragma. Due to the delayed |
| 455 |
-- analysis of the pragma, the Ghost mode at point of declaration and |
| 456 |
-- point of analysis may not necessarily be the same. Use the mode in |
| 457 |
-- effect at the point of declaration. |
| 458 |
|
| 459 |
Set_Ghost_Mode (N); |
| 460 |
|
| 461 |
-- Ensure that the subprogram and its formals are visible when |
| 462 |
-- analyzing the expression of the pragma. |
| 463 |
|
| 464 |
if not In_Open_Scopes (Spec_Id) then |
| 465 |
Restore_Scope := True; |
| 466 |
|
| 467 |
if Is_Generic_Subprogram (Spec_Id) then |
| 468 |
Push_Scope (Spec_Id); |
| 469 |
Install_Generic_Formals (Spec_Id); |
| 470 |
else |
| 471 |
Push_Scope (Spec_Id); |
| 472 |
Install_Formals (Spec_Id); |
| 473 |
end if; |
| 474 |
end if; |
| 475 |
|
| 476 |
Errors := Serious_Errors_Detected; |
| 477 |
Preanalyze_Assert_Expression (Expression (Arg1), Standard_Boolean); |
| 478 |
|
| 479 |
-- Emit a clarification message when the expression contains at least |
| 480 |
-- one undefined reference, possibly due to contract freezing. |
| 481 |
|
| 482 |
if Errors /= Serious_Errors_Detected |
| 483 |
and then Present (Freeze_Id) |
| 484 |
and then Has_Undefined_Reference (Expression (Arg1)) |
| 485 |
then |
| 486 |
Contract_Freeze_Error (Spec_Id, Freeze_Id); |
| 487 |
end if; |
| 488 |
|
| 489 |
if Restore_Scope then |
| 490 |
End_Scope; |
| 491 |
end if; |
| 492 |
|
| 493 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 494 |
end if; |
| 495 |
|
| 496 |
Set_Is_Analyzed_Pragma (N); |
| 497 |
|
| 498 |
end Analyze_Always_Terminates_In_Decl_Part; |
| 499 |
|
| 500 |
----------------------------------------- |
| 501 |
-- Analyze_Contract_Cases_In_Decl_Part -- |
| 502 |
----------------------------------------- |
| 503 |
|
| 504 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 505 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 506 |
-- Ghost mode. |
| 507 |
|
| 508 |
procedure Analyze_Contract_Cases_In_Decl_Part |
| 509 |
(N : Node_Id; |
| 510 |
Freeze_Id : Entity_Id := Empty) |
| 511 |
is |
| 512 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 513 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 514 |
|
| 515 |
Others_Seen : Boolean := False; |
| 516 |
-- This flag is set when an "others" choice is encountered. It is used |
| 517 |
-- to detect multiple illegal occurrences of "others". |
| 518 |
|
| 519 |
procedure Analyze_Contract_Case (CCase : Node_Id); |
| 520 |
-- Verify the legality of a single contract case |
| 521 |
|
| 522 |
--------------------------- |
| 523 |
-- Analyze_Contract_Case -- |
| 524 |
--------------------------- |
| 525 |
|
| 526 |
procedure Analyze_Contract_Case (CCase : Node_Id) is |
| 527 |
Case_Guard : Node_Id; |
| 528 |
Conseq : Node_Id; |
| 529 |
Errors : Nat; |
| 530 |
Extra_Guard : Node_Id; |
| 531 |
|
| 532 |
begin |
| 533 |
if Nkind (CCase) = N_Component_Association then |
| 534 |
Case_Guard := First (Choices (CCase)); |
| 535 |
Conseq := Expression (CCase); |
| 536 |
|
| 537 |
-- Each contract case must have exactly one case guard |
| 538 |
|
| 539 |
Extra_Guard := Next (Case_Guard); |
| 540 |
|
| 541 |
if Present (Extra_Guard) then |
| 542 |
Error_Msg_N |
| 543 |
("contract case must have exactly one case guard", |
| 544 |
Extra_Guard); |
| 545 |
end if; |
| 546 |
|
| 547 |
-- Check placement of OTHERS if available (SPARK RM 6.1.3(1)) |
| 548 |
|
| 549 |
if Nkind (Case_Guard) = N_Others_Choice then |
| 550 |
if Others_Seen then |
| 551 |
Error_Msg_N |
| 552 |
("only one OTHERS choice allowed in contract cases", |
| 553 |
Case_Guard); |
| 554 |
else |
| 555 |
Others_Seen := True; |
| 556 |
end if; |
| 557 |
|
| 558 |
elsif Others_Seen then |
| 559 |
Error_Msg_N |
| 560 |
("OTHERS must be the last choice in contract cases", N); |
| 561 |
end if; |
| 562 |
|
| 563 |
-- Preanalyze the case guard and consequence |
| 564 |
|
| 565 |
if Nkind (Case_Guard) /= N_Others_Choice then |
| 566 |
Errors := Serious_Errors_Detected; |
| 567 |
Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean); |
| 568 |
|
| 569 |
-- Emit a clarification message when the case guard contains |
| 570 |
-- at least one undefined reference, possibly due to contract |
| 571 |
-- freezing. |
| 572 |
|
| 573 |
if Errors /= Serious_Errors_Detected |
| 574 |
and then Present (Freeze_Id) |
| 575 |
and then Has_Undefined_Reference (Case_Guard) |
| 576 |
then |
| 577 |
Contract_Freeze_Error (Spec_Id, Freeze_Id); |
| 578 |
end if; |
| 579 |
end if; |
| 580 |
|
| 581 |
Errors := Serious_Errors_Detected; |
| 582 |
Preanalyze_Assert_Expression (Conseq, Standard_Boolean); |
| 583 |
|
| 584 |
-- Emit a clarification message when the consequence contains |
| 585 |
-- at least one undefined reference, possibly due to contract |
| 586 |
-- freezing. |
| 587 |
|
| 588 |
if Errors /= Serious_Errors_Detected |
| 589 |
and then Present (Freeze_Id) |
| 590 |
and then Has_Undefined_Reference (Conseq) |
| 591 |
then |
| 592 |
Contract_Freeze_Error (Spec_Id, Freeze_Id); |
| 593 |
end if; |
| 594 |
|
| 595 |
-- The contract case is malformed |
| 596 |
|
| 597 |
else |
| 598 |
Error_Msg_N ("wrong syntax in contract case", CCase); |
| 599 |
end if; |
| 600 |
end Analyze_Contract_Case; |
| 601 |
|
| 602 |
-- Local variables |
| 603 |
|
| 604 |
CCases : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
| 605 |
|
| 606 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 607 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 608 |
-- Save the Ghost-related attributes to restore on exit |
| 609 |
|
| 610 |
CCase : Node_Id; |
| 611 |
Restore_Scope : Boolean := False; |
| 612 |
|
| 613 |
-- Start of processing for Analyze_Contract_Cases_In_Decl_Part |
| 614 |
|
| 615 |
begin |
| 616 |
-- Do not analyze the pragma multiple times |
| 617 |
|
| 618 |
if Is_Analyzed_Pragma (N) then |
| 619 |
return; |
| 620 |
end if; |
| 621 |
|
| 622 |
-- Set the Ghost mode in effect from the pragma. Due to the delayed |
| 623 |
-- analysis of the pragma, the Ghost mode at point of declaration and |
| 624 |
-- point of analysis may not necessarily be the same. Use the mode in |
| 625 |
-- effect at the point of declaration. |
| 626 |
|
| 627 |
Set_Ghost_Mode (N); |
| 628 |
|
| 629 |
-- Single and multiple contract cases must appear in aggregate form. If |
| 630 |
-- this is not the case, then either the parser or the analysis of the |
| 631 |
-- pragma failed to produce an aggregate, e.g. when the contract is |
| 632 |
-- "null" or a "(null record)". |
| 633 |
|
| 634 |
pragma Assert |
| 635 |
(if Nkind (CCases) = N_Aggregate |
| 636 |
then Null_Record_Present (CCases) |
| 637 |
xor (Present (Component_Associations (CCases)) |
| 638 |
or |
| 639 |
Present (Expressions (CCases))) |
| 640 |
else Nkind (CCases) = N_Null); |
| 641 |
|
| 642 |
-- Only CASE_GUARD => CONSEQUENCE clauses are allowed |
| 643 |
|
| 644 |
if Nkind (CCases) = N_Aggregate |
| 645 |
and then Present (Component_Associations (CCases)) |
| 646 |
and then No (Expressions (CCases)) |
| 647 |
then |
| 648 |
|
| 649 |
-- Check that the expression is a proper aggregate (no parentheses) |
| 650 |
|
| 651 |
if Paren_Count (CCases) /= 0 then |
| 652 |
Error_Msg_F -- CODEFIX |
| 653 |
("redundant parentheses", CCases); |
| 654 |
end if; |
| 655 |
|
| 656 |
-- Ensure that the formal parameters are visible when analyzing all |
| 657 |
-- clauses. This falls out of the general rule of aspects pertaining |
| 658 |
-- to subprogram declarations. |
| 659 |
|
| 660 |
if not In_Open_Scopes (Spec_Id) then |
| 661 |
Restore_Scope := True; |
| 662 |
Push_Scope (Spec_Id); |
| 663 |
|
| 664 |
if Is_Generic_Subprogram (Spec_Id) then |
| 665 |
Install_Generic_Formals (Spec_Id); |
| 666 |
else |
| 667 |
Install_Formals (Spec_Id); |
| 668 |
end if; |
| 669 |
end if; |
| 670 |
|
| 671 |
CCase := First (Component_Associations (CCases)); |
| 672 |
while Present (CCase) loop |
| 673 |
Analyze_Contract_Case (CCase); |
| 674 |
Next (CCase); |
| 675 |
end loop; |
| 676 |
|
| 677 |
if Restore_Scope then |
| 678 |
End_Scope; |
| 679 |
end if; |
| 680 |
|
| 681 |
-- Currently it is not possible to inline pre/postconditions on a |
| 682 |
-- subprogram subject to pragma Inline_Always. |
| 683 |
|
| 684 |
Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); |
| 685 |
|
| 686 |
-- Otherwise the pragma is illegal |
| 687 |
|
| 688 |
else |
| 689 |
Error_Msg_N ("wrong syntax for contract cases", N); |
| 690 |
end if; |
| 691 |
|
| 692 |
Set_Is_Analyzed_Pragma (N); |
| 693 |
|
| 694 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 695 |
end Analyze_Contract_Cases_In_Decl_Part; |
| 696 |
|
| 697 |
---------------------------------- |
| 698 |
-- Analyze_Depends_In_Decl_Part -- |
| 699 |
---------------------------------- |
| 700 |
|
| 701 |
procedure Analyze_Depends_In_Decl_Part (N : Node_Id) is |
| 702 |
Loc : constant Source_Ptr := Sloc (N); |
| 703 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 704 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 705 |
|
| 706 |
All_Inputs_Seen : Elist_Id := No_Elist; |
| 707 |
-- A list containing the entities of all the inputs processed so far. |
| 708 |
-- The list is populated with unique entities because the same input |
| 709 |
-- may appear in multiple input lists. |
| 710 |
|
| 711 |
All_Outputs_Seen : Elist_Id := No_Elist; |
| 712 |
-- A list containing the entities of all the outputs processed so far. |
| 713 |
-- The list is populated with unique entities because output items are |
| 714 |
-- unique in a dependence relation. |
| 715 |
|
| 716 |
Constits_Seen : Elist_Id := No_Elist; |
| 717 |
-- A list containing the entities of all constituents processed so far. |
| 718 |
-- It aids in detecting illegal usage of a state and a corresponding |
| 719 |
-- constituent in pragma [Refinde_]Depends. |
| 720 |
|
| 721 |
Global_Seen : Boolean := False; |
| 722 |
-- A flag set when pragma Global has been processed |
| 723 |
|
| 724 |
Null_Output_Seen : Boolean := False; |
| 725 |
-- A flag used to track the legality of a null output |
| 726 |
|
| 727 |
Result_Seen : Boolean := False; |
| 728 |
-- A flag set when Spec_Id'Result is processed |
| 729 |
|
| 730 |
States_Seen : Elist_Id := No_Elist; |
| 731 |
-- A list containing the entities of all states processed so far. It |
| 732 |
-- helps in detecting illegal usage of a state and a corresponding |
| 733 |
-- constituent in pragma [Refined_]Depends. |
| 734 |
|
| 735 |
Subp_Inputs : Elist_Id := No_Elist; |
| 736 |
Subp_Outputs : Elist_Id := No_Elist; |
| 737 |
-- Two lists containing the full set of inputs and output of the related |
| 738 |
-- subprograms. Note that these lists contain both nodes and entities. |
| 739 |
|
| 740 |
Task_Input_Seen : Boolean := False; |
| 741 |
Task_Output_Seen : Boolean := False; |
| 742 |
-- Flags used to track the implicit dependence of a task unit on itself |
| 743 |
|
| 744 |
procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id); |
| 745 |
-- Subsidiary routine to Check_Role and Check_Usage. Add the item kind |
| 746 |
-- to the name buffer. The individual kinds are as follows: |
| 747 |
-- E_Abstract_State - "state" |
| 748 |
-- E_Constant - "constant" |
| 749 |
-- E_Generic_In_Out_Parameter - "generic parameter" |
| 750 |
-- E_Generic_In_Parameter - "generic parameter" |
| 751 |
-- E_In_Parameter - "parameter" |
| 752 |
-- E_In_Out_Parameter - "parameter" |
| 753 |
-- E_Loop_Parameter - "loop parameter" |
| 754 |
-- E_Out_Parameter - "parameter" |
| 755 |
-- E_Protected_Type - "current instance of protected type" |
| 756 |
-- E_Task_Type - "current instance of task type" |
| 757 |
-- E_Variable - "global" |
| 758 |
|
| 759 |
procedure Analyze_Dependency_Clause |
| 760 |
(Clause : Node_Id; |
| 761 |
Is_Last : Boolean); |
| 762 |
-- Verify the legality of a single dependency clause. Flag Is_Last |
| 763 |
-- denotes whether Clause is the last clause in the relation. |
| 764 |
|
| 765 |
procedure Check_Function_Return; |
| 766 |
-- Verify that Funtion'Result appears as one of the outputs |
| 767 |
-- (SPARK RM 6.1.5(10)). |
| 768 |
|
| 769 |
procedure Check_Role |
| 770 |
(Item : Node_Id; |
| 771 |
Item_Id : Entity_Id; |
| 772 |
Is_Input : Boolean; |
| 773 |
Self_Ref : Boolean); |
| 774 |
-- Ensure that an item fulfills its designated input and/or output role |
| 775 |
-- as specified by pragma Global (if any) or the enclosing context. If |
| 776 |
-- this is not the case, emit an error. Item and Item_Id denote the |
| 777 |
-- attributes of an item. Flag Is_Input should be set when item comes |
| 778 |
-- from an input list. Flag Self_Ref should be set when the item is an |
| 779 |
-- output and the dependency clause has operator "+". |
| 780 |
|
| 781 |
procedure Check_Usage |
| 782 |
(Subp_Items : Elist_Id; |
| 783 |
Used_Items : Elist_Id; |
| 784 |
Is_Input : Boolean); |
| 785 |
-- Verify that all items from Subp_Items appear in Used_Items. Emit an |
| 786 |
-- error if this is not the case. |
| 787 |
|
| 788 |
procedure Normalize_Clause (Clause : Node_Id); |
| 789 |
-- Remove a self-dependency "+" from the input list of a clause |
| 790 |
|
| 791 |
----------------------------- |
| 792 |
-- Add_Item_To_Name_Buffer -- |
| 793 |
----------------------------- |
| 794 |
|
| 795 |
procedure Add_Item_To_Name_Buffer (Item_Id : Entity_Id) is |
| 796 |
begin |
| 797 |
if Ekind (Item_Id) = E_Abstract_State then |
| 798 |
Add_Str_To_Name_Buffer ("state"); |
| 799 |
|
| 800 |
elsif Ekind (Item_Id) = E_Constant then |
| 801 |
Add_Str_To_Name_Buffer ("constant"); |
| 802 |
|
| 803 |
elsif Is_Formal_Object (Item_Id) then |
| 804 |
Add_Str_To_Name_Buffer ("generic parameter"); |
| 805 |
|
| 806 |
elsif Is_Formal (Item_Id) then |
| 807 |
Add_Str_To_Name_Buffer ("parameter"); |
| 808 |
|
| 809 |
elsif Ekind (Item_Id) = E_Loop_Parameter then |
| 810 |
Add_Str_To_Name_Buffer ("loop parameter"); |
| 811 |
|
| 812 |
elsif Ekind (Item_Id) = E_Protected_Type |
| 813 |
or else Is_Single_Protected_Object (Item_Id) |
| 814 |
then |
| 815 |
Add_Str_To_Name_Buffer ("current instance of protected type"); |
| 816 |
|
| 817 |
elsif Ekind (Item_Id) = E_Task_Type |
| 818 |
or else Is_Single_Task_Object (Item_Id) |
| 819 |
then |
| 820 |
Add_Str_To_Name_Buffer ("current instance of task type"); |
| 821 |
|
| 822 |
elsif Ekind (Item_Id) = E_Variable then |
| 823 |
Add_Str_To_Name_Buffer ("global"); |
| 824 |
|
| 825 |
-- The routine should not be called with non-SPARK items |
| 826 |
|
| 827 |
else |
| 828 |
raise Program_Error; |
| 829 |
end if; |
| 830 |
end Add_Item_To_Name_Buffer; |
| 831 |
|
| 832 |
------------------------------- |
| 833 |
-- Analyze_Dependency_Clause -- |
| 834 |
------------------------------- |
| 835 |
|
| 836 |
procedure Analyze_Dependency_Clause |
| 837 |
(Clause : Node_Id; |
| 838 |
Is_Last : Boolean) |
| 839 |
is |
| 840 |
procedure Analyze_Input_List (Inputs : Node_Id); |
| 841 |
-- Verify the legality of a single input list |
| 842 |
|
| 843 |
procedure Analyze_Input_Output |
| 844 |
(Item : Node_Id; |
| 845 |
Is_Input : Boolean; |
| 846 |
Self_Ref : Boolean; |
| 847 |
Top_Level : Boolean; |
| 848 |
Seen : in out Elist_Id; |
| 849 |
Null_Seen : in out Boolean; |
| 850 |
Non_Null_Seen : in out Boolean); |
| 851 |
-- Verify the legality of a single input or output item. Flag |
| 852 |
-- Is_Input should be set whenever Item is an input, False when it |
| 853 |
-- denotes an output. Flag Self_Ref should be set when the item is an |
| 854 |
-- output and the dependency clause has a "+". Flag Top_Level should |
| 855 |
-- be set whenever Item appears immediately within an input or output |
| 856 |
-- list. Seen is a collection of all abstract states, objects and |
| 857 |
-- formals processed so far. Flag Null_Seen denotes whether a null |
| 858 |
-- input or output has been encountered. Flag Non_Null_Seen denotes |
| 859 |
-- whether a non-null input or output has been encountered. |
| 860 |
|
| 861 |
------------------------ |
| 862 |
-- Analyze_Input_List -- |
| 863 |
------------------------ |
| 864 |
|
| 865 |
procedure Analyze_Input_List (Inputs : Node_Id) is |
| 866 |
Inputs_Seen : Elist_Id := No_Elist; |
| 867 |
-- A list containing the entities of all inputs that appear in the |
| 868 |
-- current input list. |
| 869 |
|
| 870 |
Non_Null_Input_Seen : Boolean := False; |
| 871 |
Null_Input_Seen : Boolean := False; |
| 872 |
-- Flags used to check the legality of an input list |
| 873 |
|
| 874 |
Input : Node_Id; |
| 875 |
|
| 876 |
begin |
| 877 |
-- Multiple inputs appear as an aggregate |
| 878 |
|
| 879 |
if Nkind (Inputs) = N_Aggregate then |
| 880 |
if Present (Component_Associations (Inputs)) then |
| 881 |
SPARK_Msg_N |
| 882 |
("nested dependency relations not allowed", Inputs); |
| 883 |
|
| 884 |
elsif Present (Expressions (Inputs)) then |
| 885 |
Input := First (Expressions (Inputs)); |
| 886 |
while Present (Input) loop |
| 887 |
Analyze_Input_Output |
| 888 |
(Item => Input, |
| 889 |
Is_Input => True, |
| 890 |
Self_Ref => False, |
| 891 |
Top_Level => False, |
| 892 |
Seen => Inputs_Seen, |
| 893 |
Null_Seen => Null_Input_Seen, |
| 894 |
Non_Null_Seen => Non_Null_Input_Seen); |
| 895 |
|
| 896 |
Next (Input); |
| 897 |
end loop; |
| 898 |
|
| 899 |
-- Syntax error, always report |
| 900 |
|
| 901 |
else |
| 902 |
Error_Msg_N ("malformed input dependency list", Inputs); |
| 903 |
end if; |
| 904 |
|
| 905 |
-- Process a solitary input |
| 906 |
|
| 907 |
else |
| 908 |
Analyze_Input_Output |
| 909 |
(Item => Inputs, |
| 910 |
Is_Input => True, |
| 911 |
Self_Ref => False, |
| 912 |
Top_Level => False, |
| 913 |
Seen => Inputs_Seen, |
| 914 |
Null_Seen => Null_Input_Seen, |
| 915 |
Non_Null_Seen => Non_Null_Input_Seen); |
| 916 |
end if; |
| 917 |
|
| 918 |
-- Detect an illegal dependency clause of the form |
| 919 |
|
| 920 |
-- (null =>[+] null) |
| 921 |
|
| 922 |
if Null_Output_Seen and then Null_Input_Seen then |
| 923 |
SPARK_Msg_N |
| 924 |
("null dependency clause cannot have a null input list", |
| 925 |
Inputs); |
| 926 |
end if; |
| 927 |
end Analyze_Input_List; |
| 928 |
|
| 929 |
-------------------------- |
| 930 |
-- Analyze_Input_Output -- |
| 931 |
-------------------------- |
| 932 |
|
| 933 |
procedure Analyze_Input_Output |
| 934 |
(Item : Node_Id; |
| 935 |
Is_Input : Boolean; |
| 936 |
Self_Ref : Boolean; |
| 937 |
Top_Level : Boolean; |
| 938 |
Seen : in out Elist_Id; |
| 939 |
Null_Seen : in out Boolean; |
| 940 |
Non_Null_Seen : in out Boolean) |
| 941 |
is |
| 942 |
procedure Current_Task_Instance_Seen; |
| 943 |
-- Set the appropriate global flag when the current instance of a |
| 944 |
-- task unit is encountered. |
| 945 |
|
| 946 |
-------------------------------- |
| 947 |
-- Current_Task_Instance_Seen -- |
| 948 |
-------------------------------- |
| 949 |
|
| 950 |
procedure Current_Task_Instance_Seen is |
| 951 |
begin |
| 952 |
if Is_Input then |
| 953 |
Task_Input_Seen := True; |
| 954 |
else |
| 955 |
Task_Output_Seen := True; |
| 956 |
end if; |
| 957 |
end Current_Task_Instance_Seen; |
| 958 |
|
| 959 |
-- Local variables |
| 960 |
|
| 961 |
Is_Output : constant Boolean := not Is_Input; |
| 962 |
Grouped : Node_Id; |
| 963 |
Item_Id : Entity_Id; |
| 964 |
|
| 965 |
-- Start of processing for Analyze_Input_Output |
| 966 |
|
| 967 |
begin |
| 968 |
-- Multiple input or output items appear as an aggregate |
| 969 |
|
| 970 |
if Nkind (Item) = N_Aggregate then |
| 971 |
if not Top_Level then |
| 972 |
SPARK_Msg_N ("nested grouping of items not allowed", Item); |
| 973 |
|
| 974 |
elsif Present (Component_Associations (Item)) then |
| 975 |
SPARK_Msg_N |
| 976 |
("nested dependency relations not allowed", Item); |
| 977 |
|
| 978 |
-- Recursively analyze the grouped items |
| 979 |
|
| 980 |
elsif Present (Expressions (Item)) then |
| 981 |
Grouped := First (Expressions (Item)); |
| 982 |
while Present (Grouped) loop |
| 983 |
Analyze_Input_Output |
| 984 |
(Item => Grouped, |
| 985 |
Is_Input => Is_Input, |
| 986 |
Self_Ref => Self_Ref, |
| 987 |
Top_Level => False, |
| 988 |
Seen => Seen, |
| 989 |
Null_Seen => Null_Seen, |
| 990 |
Non_Null_Seen => Non_Null_Seen); |
| 991 |
|
| 992 |
Next (Grouped); |
| 993 |
end loop; |
| 994 |
|
| 995 |
-- Syntax error, always report |
| 996 |
|
| 997 |
else |
| 998 |
Error_Msg_N ("malformed dependency list", Item); |
| 999 |
end if; |
| 1000 |
|
| 1001 |
-- Process attribute 'Result in the context of a dependency clause |
| 1002 |
|
| 1003 |
elsif Is_Attribute_Result (Item) then |
| 1004 |
Non_Null_Seen := True; |
| 1005 |
|
| 1006 |
Analyze (Item); |
| 1007 |
|
| 1008 |
-- Attribute 'Result is allowed to appear on the output side of |
| 1009 |
-- a dependency clause (SPARK RM 6.1.5(6)). |
| 1010 |
|
| 1011 |
if Is_Input then |
| 1012 |
SPARK_Msg_N ("function result cannot act as input", Item); |
| 1013 |
|
| 1014 |
elsif Null_Seen then |
| 1015 |
SPARK_Msg_N |
| 1016 |
("cannot mix null and non-null dependency items", Item); |
| 1017 |
|
| 1018 |
else |
| 1019 |
Result_Seen := True; |
| 1020 |
end if; |
| 1021 |
|
| 1022 |
-- Detect multiple uses of null in a single dependency list or |
| 1023 |
-- throughout the whole relation. Verify the placement of a null |
| 1024 |
-- output list relative to the other clauses (SPARK RM 6.1.5(12)). |
| 1025 |
|
| 1026 |
elsif Nkind (Item) = N_Null then |
| 1027 |
if Null_Seen then |
| 1028 |
SPARK_Msg_N |
| 1029 |
("multiple null dependency relations not allowed", Item); |
| 1030 |
|
| 1031 |
elsif Non_Null_Seen then |
| 1032 |
SPARK_Msg_N |
| 1033 |
("cannot mix null and non-null dependency items", Item); |
| 1034 |
|
| 1035 |
else |
| 1036 |
Null_Seen := True; |
| 1037 |
|
| 1038 |
if Is_Output then |
| 1039 |
if not Is_Last then |
| 1040 |
SPARK_Msg_N |
| 1041 |
("null output list must be the last clause in a " |
| 1042 |
& "dependency relation", Item); |
| 1043 |
|
| 1044 |
-- Catch a useless dependence of the form: |
| 1045 |
-- null =>+ ... |
| 1046 |
|
| 1047 |
elsif Self_Ref then |
| 1048 |
SPARK_Msg_N |
| 1049 |
("useless dependence, null depends on itself", Item); |
| 1050 |
end if; |
| 1051 |
end if; |
| 1052 |
end if; |
| 1053 |
|
| 1054 |
-- Default case |
| 1055 |
|
| 1056 |
else |
| 1057 |
Non_Null_Seen := True; |
| 1058 |
|
| 1059 |
if Null_Seen then |
| 1060 |
SPARK_Msg_N ("cannot mix null and non-null items", Item); |
| 1061 |
end if; |
| 1062 |
|
| 1063 |
Analyze (Item); |
| 1064 |
Resolve_State (Item); |
| 1065 |
|
| 1066 |
-- Find the entity of the item. If this is a renaming, climb |
| 1067 |
-- the renaming chain to reach the root object. Renamings of |
| 1068 |
-- non-entire objects do not yield an entity (Empty). |
| 1069 |
|
| 1070 |
Item_Id := Entity_Of (Item); |
| 1071 |
|
| 1072 |
if Present (Item_Id) then |
| 1073 |
|
| 1074 |
-- Constants |
| 1075 |
|
| 1076 |
if Ekind (Item_Id) in E_Constant | E_Loop_Parameter |
| 1077 |
or else |
| 1078 |
|
| 1079 |
-- Current instances of concurrent types |
| 1080 |
|
| 1081 |
Ekind (Item_Id) in E_Protected_Type | E_Task_Type |
| 1082 |
or else |
| 1083 |
|
| 1084 |
-- Formal parameters |
| 1085 |
|
| 1086 |
Ekind (Item_Id) in E_Generic_In_Out_Parameter |
| 1087 |
| E_Generic_In_Parameter |
| 1088 |
| E_In_Parameter |
| 1089 |
| E_In_Out_Parameter |
| 1090 |
| E_Out_Parameter |
| 1091 |
or else |
| 1092 |
|
| 1093 |
-- States, variables |
| 1094 |
|
| 1095 |
Ekind (Item_Id) in E_Abstract_State | E_Variable |
| 1096 |
then |
| 1097 |
-- A [generic] function is not allowed to have Output |
| 1098 |
-- items in its dependency relations. Note that "null" |
| 1099 |
-- and attribute 'Result are still valid items. |
| 1100 |
|
| 1101 |
if Ekind (Spec_Id) in E_Function | E_Generic_Function |
| 1102 |
and then not Is_Function_With_Side_Effects (Spec_Id) |
| 1103 |
and then not Is_Input |
| 1104 |
then |
| 1105 |
Error_Msg_Code := |
| 1106 |
GEC_Output_In_Function_Global_Or_Depends; |
| 1107 |
SPARK_Msg_N |
| 1108 |
("output item is not applicable to function '[[]']", |
| 1109 |
Item); |
| 1110 |
end if; |
| 1111 |
|
| 1112 |
-- The item denotes a concurrent type. Note that single |
| 1113 |
-- protected/task types are not considered here because |
| 1114 |
-- they behave as objects in the context of pragma |
| 1115 |
-- [Refined_]Depends. |
| 1116 |
|
| 1117 |
if Ekind (Item_Id) in E_Protected_Type | E_Task_Type then |
| 1118 |
|
| 1119 |
-- This use is legal as long as the concurrent type is |
| 1120 |
-- the current instance of an enclosing type. |
| 1121 |
|
| 1122 |
if Is_CCT_Instance (Item_Id, Spec_Id) then |
| 1123 |
|
| 1124 |
-- The dependence of a task unit on itself is |
| 1125 |
-- implicit and may or may not be explicitly |
| 1126 |
-- specified (SPARK RM 6.1.4). |
| 1127 |
|
| 1128 |
if Ekind (Item_Id) = E_Task_Type then |
| 1129 |
Current_Task_Instance_Seen; |
| 1130 |
end if; |
| 1131 |
|
| 1132 |
-- Otherwise this is not the current instance |
| 1133 |
|
| 1134 |
else |
| 1135 |
SPARK_Msg_N |
| 1136 |
("invalid use of subtype mark in dependency " |
| 1137 |
& "relation", Item); |
| 1138 |
end if; |
| 1139 |
|
| 1140 |
-- The dependency of a task unit on itself is implicit |
| 1141 |
-- and may or may not be explicitly specified |
| 1142 |
-- (SPARK RM 6.1.4). |
| 1143 |
|
| 1144 |
elsif Is_Single_Task_Object (Item_Id) |
| 1145 |
and then Is_CCT_Instance (Etype (Item_Id), Spec_Id) |
| 1146 |
then |
| 1147 |
Current_Task_Instance_Seen; |
| 1148 |
end if; |
| 1149 |
|
| 1150 |
-- Ensure that the item fulfills its role as input and/or |
| 1151 |
-- output as specified by pragma Global or the enclosing |
| 1152 |
-- context. |
| 1153 |
|
| 1154 |
Check_Role (Item, Item_Id, Is_Input, Self_Ref); |
| 1155 |
|
| 1156 |
-- Detect multiple uses of the same state, variable or |
| 1157 |
-- formal parameter. If this is not the case, add the |
| 1158 |
-- item to the list of processed relations. |
| 1159 |
|
| 1160 |
if Contains (Seen, Item_Id) then |
| 1161 |
SPARK_Msg_NE |
| 1162 |
("duplicate use of item &", Item, Item_Id); |
| 1163 |
else |
| 1164 |
Append_New_Elmt (Item_Id, Seen); |
| 1165 |
end if; |
| 1166 |
|
| 1167 |
-- Detect illegal use of an input related to a null |
| 1168 |
-- output. Such input items cannot appear in other |
| 1169 |
-- input lists (SPARK RM 6.1.5(13)). |
| 1170 |
|
| 1171 |
if Is_Input |
| 1172 |
and then Null_Output_Seen |
| 1173 |
and then Contains (All_Inputs_Seen, Item_Id) |
| 1174 |
then |
| 1175 |
SPARK_Msg_N |
| 1176 |
("input of a null output list cannot appear in " |
| 1177 |
& "multiple input lists", Item); |
| 1178 |
end if; |
| 1179 |
|
| 1180 |
-- Add an input or a self-referential output to the list |
| 1181 |
-- of all processed inputs. |
| 1182 |
|
| 1183 |
if Is_Input or else Self_Ref then |
| 1184 |
Append_New_Elmt (Item_Id, All_Inputs_Seen); |
| 1185 |
end if; |
| 1186 |
|
| 1187 |
-- State related checks (SPARK RM 6.1.5(3)) |
| 1188 |
|
| 1189 |
if Ekind (Item_Id) = E_Abstract_State then |
| 1190 |
|
| 1191 |
-- Package and subprogram bodies are instantiated |
| 1192 |
-- individually in a separate compiler pass. Due to |
| 1193 |
-- this mode of instantiation, the refinement of a |
| 1194 |
-- state may no longer be visible when a subprogram |
| 1195 |
-- body contract is instantiated. Since the generic |
| 1196 |
-- template is legal, do not perform this check in |
| 1197 |
-- the instance to circumvent this oddity. |
| 1198 |
|
| 1199 |
if In_Instance then |
| 1200 |
null; |
| 1201 |
|
| 1202 |
-- An abstract state with visible refinement cannot |
| 1203 |
-- appear in pragma [Refined_]Depends as its place |
| 1204 |
-- must be taken by some of its constituents |
| 1205 |
-- (SPARK RM 6.1.4(7)). |
| 1206 |
|
| 1207 |
elsif Has_Visible_Refinement (Item_Id) then |
| 1208 |
SPARK_Msg_NE |
| 1209 |
("cannot mention state & in dependence relation", |
| 1210 |
Item, Item_Id); |
| 1211 |
SPARK_Msg_N ("\use its constituents instead", Item); |
| 1212 |
return; |
| 1213 |
|
| 1214 |
-- If the reference to the abstract state appears in |
| 1215 |
-- an enclosing package body that will eventually |
| 1216 |
-- refine the state, record the reference for future |
| 1217 |
-- checks. |
| 1218 |
|
| 1219 |
else |
| 1220 |
Record_Possible_Body_Reference |
| 1221 |
(State_Id => Item_Id, |
| 1222 |
Ref => Item); |
| 1223 |
end if; |
| 1224 |
|
| 1225 |
elsif Ekind (Item_Id) in E_Constant | E_Variable |
| 1226 |
and then Present (Ultimate_Overlaid_Entity (Item_Id)) |
| 1227 |
then |
| 1228 |
SPARK_Msg_NE |
| 1229 |
("overlaying object & cannot appear in Depends", |
| 1230 |
Item, Item_Id); |
| 1231 |
SPARK_Msg_NE |
| 1232 |
("\use the overlaid object & instead", |
| 1233 |
Item, Ultimate_Overlaid_Entity (Item_Id)); |
| 1234 |
return; |
| 1235 |
end if; |
| 1236 |
|
| 1237 |
-- When the item renames an entire object, replace the |
| 1238 |
-- item with a reference to the object. |
| 1239 |
|
| 1240 |
if Entity (Item) /= Item_Id then |
| 1241 |
Rewrite (Item, |
| 1242 |
New_Occurrence_Of (Item_Id, Sloc (Item))); |
| 1243 |
Analyze (Item); |
| 1244 |
end if; |
| 1245 |
|
| 1246 |
-- Add the entity of the current item to the list of |
| 1247 |
-- processed items. |
| 1248 |
|
| 1249 |
if Ekind (Item_Id) = E_Abstract_State then |
| 1250 |
Append_New_Elmt (Item_Id, States_Seen); |
| 1251 |
|
| 1252 |
-- The variable may eventually become a constituent of a |
| 1253 |
-- single protected/task type. Record the reference now |
| 1254 |
-- and verify its legality when analyzing the contract of |
| 1255 |
-- the variable (SPARK RM 9.3). |
| 1256 |
|
| 1257 |
elsif Ekind (Item_Id) = E_Variable then |
| 1258 |
Record_Possible_Part_Of_Reference |
| 1259 |
(Var_Id => Item_Id, |
| 1260 |
Ref => Item); |
| 1261 |
end if; |
| 1262 |
|
| 1263 |
if Ekind (Item_Id) in E_Abstract_State |
| 1264 |
| E_Constant |
| 1265 |
| E_Variable |
| 1266 |
and then Present (Encapsulating_State (Item_Id)) |
| 1267 |
then |
| 1268 |
Append_New_Elmt (Item_Id, Constits_Seen); |
| 1269 |
end if; |
| 1270 |
|
| 1271 |
-- All other input/output items are illegal |
| 1272 |
-- (SPARK RM 6.1.5(1)). |
| 1273 |
|
| 1274 |
else |
| 1275 |
SPARK_Msg_N |
| 1276 |
("item must denote parameter, variable, state or " |
| 1277 |
& "current instance of concurrent type", Item); |
| 1278 |
end if; |
| 1279 |
|
| 1280 |
-- All other input/output items are illegal |
| 1281 |
-- (SPARK RM 6.1.5(1)). This is a syntax error, always report. |
| 1282 |
|
| 1283 |
else |
| 1284 |
Error_Msg_N |
| 1285 |
("item must denote parameter, variable, state or current " |
| 1286 |
& "instance of concurrent type", Item); |
| 1287 |
end if; |
| 1288 |
end if; |
| 1289 |
end Analyze_Input_Output; |
| 1290 |
|
| 1291 |
-- Local variables |
| 1292 |
|
| 1293 |
Inputs : Node_Id; |
| 1294 |
Output : Node_Id; |
| 1295 |
Self_Ref : Boolean; |
| 1296 |
|
| 1297 |
Non_Null_Output_Seen : Boolean := False; |
| 1298 |
-- Flag used to check the legality of an output list |
| 1299 |
|
| 1300 |
-- Start of processing for Analyze_Dependency_Clause |
| 1301 |
|
| 1302 |
begin |
| 1303 |
Inputs := Expression (Clause); |
| 1304 |
Self_Ref := False; |
| 1305 |
|
| 1306 |
-- An input list with a self-dependency appears as operator "+" where |
| 1307 |
-- the actuals inputs are the right operand. |
| 1308 |
|
| 1309 |
if Nkind (Inputs) = N_Op_Plus then |
| 1310 |
Inputs := Right_Opnd (Inputs); |
| 1311 |
Self_Ref := True; |
| 1312 |
end if; |
| 1313 |
|
| 1314 |
-- Process the output_list of a dependency_clause |
| 1315 |
|
| 1316 |
Output := First (Choices (Clause)); |
| 1317 |
while Present (Output) loop |
| 1318 |
Analyze_Input_Output |
| 1319 |
(Item => Output, |
| 1320 |
Is_Input => False, |
| 1321 |
Self_Ref => Self_Ref, |
| 1322 |
Top_Level => True, |
| 1323 |
Seen => All_Outputs_Seen, |
| 1324 |
Null_Seen => Null_Output_Seen, |
| 1325 |
Non_Null_Seen => Non_Null_Output_Seen); |
| 1326 |
|
| 1327 |
Next (Output); |
| 1328 |
end loop; |
| 1329 |
|
| 1330 |
-- Process the input_list of a dependency_clause |
| 1331 |
|
| 1332 |
Analyze_Input_List (Inputs); |
| 1333 |
end Analyze_Dependency_Clause; |
| 1334 |
|
| 1335 |
--------------------------- |
| 1336 |
-- Check_Function_Return -- |
| 1337 |
--------------------------- |
| 1338 |
|
| 1339 |
procedure Check_Function_Return is |
| 1340 |
begin |
| 1341 |
if Ekind (Spec_Id) in E_Function | E_Generic_Function |
| 1342 |
and then not Result_Seen |
| 1343 |
then |
| 1344 |
SPARK_Msg_NE |
| 1345 |
("result of & must appear in exactly one output list", |
| 1346 |
N, Spec_Id); |
| 1347 |
end if; |
| 1348 |
end Check_Function_Return; |
| 1349 |
|
| 1350 |
---------------- |
| 1351 |
-- Check_Role -- |
| 1352 |
---------------- |
| 1353 |
|
| 1354 |
procedure Check_Role |
| 1355 |
(Item : Node_Id; |
| 1356 |
Item_Id : Entity_Id; |
| 1357 |
Is_Input : Boolean; |
| 1358 |
Self_Ref : Boolean) |
| 1359 |
is |
| 1360 |
procedure Find_Role |
| 1361 |
(Item_Is_Input : out Boolean; |
| 1362 |
Item_Is_Output : out Boolean); |
| 1363 |
-- Find the input/output role of Item_Id. Flags Item_Is_Input and |
| 1364 |
-- Item_Is_Output are set depending on the role. |
| 1365 |
|
| 1366 |
procedure Role_Error |
| 1367 |
(Item_Is_Input : Boolean; |
| 1368 |
Item_Is_Output : Boolean); |
| 1369 |
-- Emit an error message concerning the incorrect use of Item in |
| 1370 |
-- pragma [Refined_]Depends. Flags Item_Is_Input and Item_Is_Output |
| 1371 |
-- denote whether the item is an input and/or an output. |
| 1372 |
|
| 1373 |
--------------- |
| 1374 |
-- Find_Role -- |
| 1375 |
--------------- |
| 1376 |
|
| 1377 |
procedure Find_Role |
| 1378 |
(Item_Is_Input : out Boolean; |
| 1379 |
Item_Is_Output : out Boolean) |
| 1380 |
is |
| 1381 |
-- A constant or an IN parameter of a protected entry, procedure, |
| 1382 |
-- or function with side-effects, if it is of an |
| 1383 |
-- access-to-variable type, should be handled like a variable, as |
| 1384 |
-- the underlying memory pointed-to can be modified. Use |
| 1385 |
-- Adjusted_Kind to do this adjustment. |
| 1386 |
|
| 1387 |
Adjusted_Kind : Entity_Kind := Ekind (Item_Id); |
| 1388 |
|
| 1389 |
begin |
| 1390 |
if (Ekind (Item_Id) in E_Constant | E_Generic_In_Parameter |
| 1391 |
or else |
| 1392 |
(Ekind (Item_Id) = E_In_Parameter |
| 1393 |
and then |
| 1394 |
(Ekind (Scope (Item_Id)) not in E_Function |
| 1395 |
| E_Generic_Function |
| 1396 |
or else |
| 1397 |
Is_Function_With_Side_Effects (Scope (Item_Id))))) |
| 1398 |
and then Is_Access_Variable (Etype (Item_Id)) |
| 1399 |
and then (Ekind (Spec_Id) not in E_Function |
| 1400 |
| E_Generic_Function |
| 1401 |
or else Is_Function_With_Side_Effects (Spec_Id)) |
| 1402 |
then |
| 1403 |
Adjusted_Kind := E_Variable; |
| 1404 |
end if; |
| 1405 |
|
| 1406 |
case Adjusted_Kind is |
| 1407 |
|
| 1408 |
-- Abstract states |
| 1409 |
|
| 1410 |
when E_Abstract_State => |
| 1411 |
|
| 1412 |
-- When pragma Global is present it determines the mode of |
| 1413 |
-- the abstract state. |
| 1414 |
|
| 1415 |
if Global_Seen then |
| 1416 |
Item_Is_Input := Appears_In (Subp_Inputs, Item_Id); |
| 1417 |
Item_Is_Output := Appears_In (Subp_Outputs, Item_Id); |
| 1418 |
|
| 1419 |
-- Otherwise the state has a default IN OUT mode, because it |
| 1420 |
-- behaves as a variable. |
| 1421 |
|
| 1422 |
else |
| 1423 |
Item_Is_Input := True; |
| 1424 |
Item_Is_Output := True; |
| 1425 |
end if; |
| 1426 |
|
| 1427 |
-- Constants and IN parameters |
| 1428 |
|
| 1429 |
when E_Constant |
| 1430 |
| E_Generic_In_Parameter |
| 1431 |
| E_In_Parameter |
| 1432 |
| E_Loop_Parameter |
| 1433 |
=> |
| 1434 |
-- When pragma Global is present it determines the mode |
| 1435 |
-- of constant objects as inputs (and such objects cannot |
| 1436 |
-- appear as outputs in the Global contract). |
| 1437 |
|
| 1438 |
if Global_Seen then |
| 1439 |
Item_Is_Input := Appears_In (Subp_Inputs, Item_Id); |
| 1440 |
else |
| 1441 |
Item_Is_Input := True; |
| 1442 |
end if; |
| 1443 |
|
| 1444 |
Item_Is_Output := False; |
| 1445 |
|
| 1446 |
-- Variables and IN OUT parameters, as well as constants and |
| 1447 |
-- IN parameters of access type which are handled like |
| 1448 |
-- variables. |
| 1449 |
|
| 1450 |
when E_Generic_In_Out_Parameter |
| 1451 |
| E_In_Out_Parameter |
| 1452 |
| E_Out_Parameter |
| 1453 |
| E_Variable |
| 1454 |
=> |
| 1455 |
-- An OUT parameter of the related subprogram; it cannot |
| 1456 |
-- appear in Global. |
| 1457 |
|
| 1458 |
if Adjusted_Kind = E_Out_Parameter |
| 1459 |
and then Scope (Item_Id) = Spec_Id |
| 1460 |
then |
| 1461 |
|
| 1462 |
-- The parameter has mode IN if its type is unconstrained |
| 1463 |
-- or tagged because array bounds, discriminants or tags |
| 1464 |
-- can be read. |
| 1465 |
|
| 1466 |
Item_Is_Input := |
| 1467 |
Is_Unconstrained_Or_Tagged_Item (Item_Id); |
| 1468 |
|
| 1469 |
Item_Is_Output := True; |
| 1470 |
|
| 1471 |
-- A parameter of an enclosing subprogram; it can appear |
| 1472 |
-- in Global and behaves as a read-write variable. |
| 1473 |
|
| 1474 |
else |
| 1475 |
-- When pragma Global is present it determines the mode |
| 1476 |
-- of the object. |
| 1477 |
|
| 1478 |
if Global_Seen then |
| 1479 |
|
| 1480 |
-- A variable has mode IN when its type is |
| 1481 |
-- unconstrained or tagged because array bounds, |
| 1482 |
-- discriminants, or tags can be read. |
| 1483 |
|
| 1484 |
Item_Is_Input := |
| 1485 |
Appears_In (Subp_Inputs, Item_Id) |
| 1486 |
or else Is_Unconstrained_Or_Tagged_Item (Item_Id); |
| 1487 |
|
| 1488 |
Item_Is_Output := Appears_In (Subp_Outputs, Item_Id); |
| 1489 |
|
| 1490 |
-- Otherwise the variable has a default IN OUT mode |
| 1491 |
|
| 1492 |
else |
| 1493 |
Item_Is_Input := True; |
| 1494 |
Item_Is_Output := True; |
| 1495 |
end if; |
| 1496 |
end if; |
| 1497 |
|
| 1498 |
-- Protected types |
| 1499 |
|
| 1500 |
when E_Protected_Type => |
| 1501 |
if Global_Seen then |
| 1502 |
|
| 1503 |
-- A variable has mode IN when its type is unconstrained |
| 1504 |
-- or tagged because array bounds, discriminants or tags |
| 1505 |
-- can be read. |
| 1506 |
|
| 1507 |
Item_Is_Input := |
| 1508 |
Appears_In (Subp_Inputs, Item_Id) |
| 1509 |
or else Is_Unconstrained_Or_Tagged_Item (Item_Id); |
| 1510 |
|
| 1511 |
Item_Is_Output := Appears_In (Subp_Outputs, Item_Id); |
| 1512 |
|
| 1513 |
else |
| 1514 |
-- A protected type acts as a formal parameter of mode IN |
| 1515 |
-- when it applies to a protected function. |
| 1516 |
|
| 1517 |
if Ekind (Spec_Id) = E_Function then |
| 1518 |
Item_Is_Input := True; |
| 1519 |
Item_Is_Output := False; |
| 1520 |
|
| 1521 |
-- Otherwise the protected type acts as a formal of mode |
| 1522 |
-- IN OUT. |
| 1523 |
|
| 1524 |
else |
| 1525 |
Item_Is_Input := True; |
| 1526 |
Item_Is_Output := True; |
| 1527 |
end if; |
| 1528 |
end if; |
| 1529 |
|
| 1530 |
-- Task types |
| 1531 |
|
| 1532 |
when E_Task_Type => |
| 1533 |
|
| 1534 |
-- When pragma Global is present it determines the mode of |
| 1535 |
-- the object. |
| 1536 |
|
| 1537 |
if Global_Seen then |
| 1538 |
Item_Is_Input := |
| 1539 |
Appears_In (Subp_Inputs, Item_Id) |
| 1540 |
or else Is_Unconstrained_Or_Tagged_Item (Item_Id); |
| 1541 |
|
| 1542 |
Item_Is_Output := Appears_In (Subp_Outputs, Item_Id); |
| 1543 |
|
| 1544 |
-- Otherwise task types act as IN OUT parameters |
| 1545 |
|
| 1546 |
else |
| 1547 |
Item_Is_Input := True; |
| 1548 |
Item_Is_Output := True; |
| 1549 |
end if; |
| 1550 |
|
| 1551 |
when others => |
| 1552 |
raise Program_Error; |
| 1553 |
end case; |
| 1554 |
end Find_Role; |
| 1555 |
|
| 1556 |
---------------- |
| 1557 |
-- Role_Error -- |
| 1558 |
---------------- |
| 1559 |
|
| 1560 |
procedure Role_Error |
| 1561 |
(Item_Is_Input : Boolean; |
| 1562 |
Item_Is_Output : Boolean) |
| 1563 |
is |
| 1564 |
begin |
| 1565 |
Name_Len := 0; |
| 1566 |
|
| 1567 |
-- When the item is not part of the input and the output set of |
| 1568 |
-- the related subprogram, then it appears as extra in pragma |
| 1569 |
-- [Refined_]Depends. |
| 1570 |
|
| 1571 |
if not Item_Is_Input and then not Item_Is_Output then |
| 1572 |
Add_Item_To_Name_Buffer (Item_Id); |
| 1573 |
Add_Str_To_Name_Buffer |
| 1574 |
(" & cannot appear in dependence relation"); |
| 1575 |
|
| 1576 |
SPARK_Msg_NE (To_String (Global_Name_Buffer), Item, Item_Id); |
| 1577 |
|
| 1578 |
Error_Msg_Name_1 := Chars (Spec_Id); |
| 1579 |
SPARK_Msg_NE |
| 1580 |
(Fix_Msg (Spec_Id, "\& is not part of the input or output " |
| 1581 |
& "set of subprogram %"), Item, Item_Id); |
| 1582 |
|
| 1583 |
-- The mode of the item and its role in pragma [Refined_]Depends |
| 1584 |
-- are in conflict. Construct a detailed message explaining the |
| 1585 |
-- illegality (SPARK RM 6.1.5(5-6)). |
| 1586 |
|
| 1587 |
else |
| 1588 |
if Item_Is_Input then |
| 1589 |
Add_Str_To_Name_Buffer ("read-only"); |
| 1590 |
else |
| 1591 |
Add_Str_To_Name_Buffer ("write-only"); |
| 1592 |
end if; |
| 1593 |
|
| 1594 |
Add_Char_To_Name_Buffer (' '); |
| 1595 |
Add_Item_To_Name_Buffer (Item_Id); |
| 1596 |
Add_Str_To_Name_Buffer (" & cannot appear as "); |
| 1597 |
|
| 1598 |
if Item_Is_Input then |
| 1599 |
Add_Str_To_Name_Buffer ("output"); |
| 1600 |
else |
| 1601 |
Add_Str_To_Name_Buffer ("input"); |
| 1602 |
end if; |
| 1603 |
|
| 1604 |
Add_Str_To_Name_Buffer (" in dependence relation"); |
| 1605 |
|
| 1606 |
SPARK_Msg_NE (To_String (Global_Name_Buffer), Item, Item_Id); |
| 1607 |
end if; |
| 1608 |
end Role_Error; |
| 1609 |
|
| 1610 |
-- Local variables |
| 1611 |
|
| 1612 |
Item_Is_Input : Boolean; |
| 1613 |
Item_Is_Output : Boolean; |
| 1614 |
|
| 1615 |
-- Start of processing for Check_Role |
| 1616 |
|
| 1617 |
begin |
| 1618 |
Find_Role (Item_Is_Input, Item_Is_Output); |
| 1619 |
|
| 1620 |
-- Input item |
| 1621 |
|
| 1622 |
if Is_Input then |
| 1623 |
if not Item_Is_Input then |
| 1624 |
Role_Error (Item_Is_Input, Item_Is_Output); |
| 1625 |
end if; |
| 1626 |
|
| 1627 |
-- Self-referential item |
| 1628 |
|
| 1629 |
elsif Self_Ref then |
| 1630 |
if not Item_Is_Input or else not Item_Is_Output then |
| 1631 |
Role_Error (Item_Is_Input, Item_Is_Output); |
| 1632 |
end if; |
| 1633 |
|
| 1634 |
-- Output item |
| 1635 |
|
| 1636 |
elsif not Item_Is_Output then |
| 1637 |
Role_Error (Item_Is_Input, Item_Is_Output); |
| 1638 |
end if; |
| 1639 |
end Check_Role; |
| 1640 |
|
| 1641 |
----------------- |
| 1642 |
-- Check_Usage -- |
| 1643 |
----------------- |
| 1644 |
|
| 1645 |
procedure Check_Usage |
| 1646 |
(Subp_Items : Elist_Id; |
| 1647 |
Used_Items : Elist_Id; |
| 1648 |
Is_Input : Boolean) |
| 1649 |
is |
| 1650 |
procedure Usage_Error (Item_Id : Entity_Id); |
| 1651 |
-- Emit an error concerning the illegal usage of an item |
| 1652 |
|
| 1653 |
----------------- |
| 1654 |
-- Usage_Error -- |
| 1655 |
----------------- |
| 1656 |
|
| 1657 |
procedure Usage_Error (Item_Id : Entity_Id) is |
| 1658 |
begin |
| 1659 |
-- Input case |
| 1660 |
|
| 1661 |
if Is_Input then |
| 1662 |
|
| 1663 |
-- Unconstrained and tagged items are not part of the explicit |
| 1664 |
-- input set of the related subprogram, they do not have to be |
| 1665 |
-- present in a dependence relation and should not be flagged |
| 1666 |
-- (SPARK RM 6.1.5(5)). |
| 1667 |
|
| 1668 |
if not Is_Unconstrained_Or_Tagged_Item (Item_Id) then |
| 1669 |
Name_Len := 0; |
| 1670 |
|
| 1671 |
Add_Item_To_Name_Buffer (Item_Id); |
| 1672 |
Add_Str_To_Name_Buffer |
| 1673 |
(" & is missing from input dependence list"); |
| 1674 |
|
| 1675 |
SPARK_Msg_NE (To_String (Global_Name_Buffer), N, Item_Id); |
| 1676 |
SPARK_Msg_NE |
| 1677 |
("\add `null ='> &` dependency to ignore this input", |
| 1678 |
N, Item_Id); |
| 1679 |
end if; |
| 1680 |
|
| 1681 |
-- Output case (SPARK RM 6.1.5(10)) |
| 1682 |
|
| 1683 |
else |
| 1684 |
Name_Len := 0; |
| 1685 |
|
| 1686 |
Add_Item_To_Name_Buffer (Item_Id); |
| 1687 |
Add_Str_To_Name_Buffer |
| 1688 |
(" & is missing from output dependence list"); |
| 1689 |
|
| 1690 |
SPARK_Msg_NE (To_String (Global_Name_Buffer), N, Item_Id); |
| 1691 |
end if; |
| 1692 |
end Usage_Error; |
| 1693 |
|
| 1694 |
-- Local variables |
| 1695 |
|
| 1696 |
Elmt : Elmt_Id; |
| 1697 |
Item : Node_Id; |
| 1698 |
Item_Id : Entity_Id; |
| 1699 |
|
| 1700 |
-- Start of processing for Check_Usage |
| 1701 |
|
| 1702 |
begin |
| 1703 |
if No (Subp_Items) then |
| 1704 |
return; |
| 1705 |
end if; |
| 1706 |
|
| 1707 |
-- Each input or output of the subprogram must appear in a dependency |
| 1708 |
-- relation. |
| 1709 |
|
| 1710 |
Elmt := First_Elmt (Subp_Items); |
| 1711 |
while Present (Elmt) loop |
| 1712 |
Item := Node (Elmt); |
| 1713 |
|
| 1714 |
if Nkind (Item) = N_Defining_Identifier then |
| 1715 |
Item_Id := Item; |
| 1716 |
else |
| 1717 |
Item_Id := Entity_Of (Item); |
| 1718 |
end if; |
| 1719 |
|
| 1720 |
-- The item does not appear in a dependency |
| 1721 |
|
| 1722 |
if Present (Item_Id) |
| 1723 |
and then not Contains (Used_Items, Item_Id) |
| 1724 |
then |
| 1725 |
if Is_Formal (Item_Id) then |
| 1726 |
Usage_Error (Item_Id); |
| 1727 |
|
| 1728 |
-- The current instance of a protected type behaves as a formal |
| 1729 |
-- parameter (SPARK RM 6.1.4). |
| 1730 |
|
| 1731 |
elsif Ekind (Item_Id) = E_Protected_Type |
| 1732 |
or else Is_Single_Protected_Object (Item_Id) |
| 1733 |
then |
| 1734 |
Usage_Error (Item_Id); |
| 1735 |
|
| 1736 |
-- The current instance of a task type behaves as a formal |
| 1737 |
-- parameter (SPARK RM 6.1.4). |
| 1738 |
|
| 1739 |
elsif Ekind (Item_Id) = E_Task_Type |
| 1740 |
or else Is_Single_Task_Object (Item_Id) |
| 1741 |
then |
| 1742 |
-- The dependence of a task unit on itself is implicit and |
| 1743 |
-- may or may not be explicitly specified (SPARK RM 6.1.4). |
| 1744 |
-- Emit an error if only one input/output is present. |
| 1745 |
|
| 1746 |
if Task_Input_Seen /= Task_Output_Seen then |
| 1747 |
Usage_Error (Item_Id); |
| 1748 |
end if; |
| 1749 |
|
| 1750 |
-- States and global objects are not used properly only when |
| 1751 |
-- the subprogram is subject to pragma Global. |
| 1752 |
|
| 1753 |
elsif Global_Seen |
| 1754 |
and then Ekind (Item_Id) in E_Abstract_State |
| 1755 |
| E_Constant |
| 1756 |
| E_Loop_Parameter |
| 1757 |
| E_Protected_Type |
| 1758 |
| E_Task_Type |
| 1759 |
| E_Variable |
| 1760 |
| Formal_Kind |
| 1761 |
then |
| 1762 |
Usage_Error (Item_Id); |
| 1763 |
end if; |
| 1764 |
end if; |
| 1765 |
|
| 1766 |
Next_Elmt (Elmt); |
| 1767 |
end loop; |
| 1768 |
end Check_Usage; |
| 1769 |
|
| 1770 |
---------------------- |
| 1771 |
-- Normalize_Clause -- |
| 1772 |
---------------------- |
| 1773 |
|
| 1774 |
procedure Normalize_Clause (Clause : Node_Id) is |
| 1775 |
procedure Create_Or_Modify_Clause |
| 1776 |
(Output : Node_Id; |
| 1777 |
Outputs : Node_Id; |
| 1778 |
Inputs : Node_Id; |
| 1779 |
After : Node_Id; |
| 1780 |
In_Place : Boolean; |
| 1781 |
Multiple : Boolean); |
| 1782 |
-- Create a brand new clause to represent the self-reference or |
| 1783 |
-- modify the input and/or output lists of an existing clause. Output |
| 1784 |
-- denotes a self-referencial output. Outputs is the output list of a |
| 1785 |
-- clause. Inputs is the input list of a clause. After denotes the |
| 1786 |
-- clause after which the new clause is to be inserted. Flag In_Place |
| 1787 |
-- should be set when normalizing the last output of an output list. |
| 1788 |
-- Flag Multiple should be set when Output comes from a list with |
| 1789 |
-- multiple items. |
| 1790 |
|
| 1791 |
----------------------------- |
| 1792 |
-- Create_Or_Modify_Clause -- |
| 1793 |
----------------------------- |
| 1794 |
|
| 1795 |
procedure Create_Or_Modify_Clause |
| 1796 |
(Output : Node_Id; |
| 1797 |
Outputs : Node_Id; |
| 1798 |
Inputs : Node_Id; |
| 1799 |
After : Node_Id; |
| 1800 |
In_Place : Boolean; |
| 1801 |
Multiple : Boolean) |
| 1802 |
is |
| 1803 |
procedure Propagate_Output |
| 1804 |
(Output : Node_Id; |
| 1805 |
Inputs : Node_Id); |
| 1806 |
-- Handle the various cases of output propagation to the input |
| 1807 |
-- list. Output denotes a self-referencial output item. Inputs |
| 1808 |
-- is the input list of a clause. |
| 1809 |
|
| 1810 |
---------------------- |
| 1811 |
-- Propagate_Output -- |
| 1812 |
---------------------- |
| 1813 |
|
| 1814 |
procedure Propagate_Output |
| 1815 |
(Output : Node_Id; |
| 1816 |
Inputs : Node_Id) |
| 1817 |
is |
| 1818 |
function In_Input_List |
| 1819 |
(Item : Entity_Id; |
| 1820 |
Inputs : List_Id) return Boolean; |
| 1821 |
-- Determine whether a particulat item appears in the input |
| 1822 |
-- list of a clause. |
| 1823 |
|
| 1824 |
------------------- |
| 1825 |
-- In_Input_List -- |
| 1826 |
------------------- |
| 1827 |
|
| 1828 |
function In_Input_List |
| 1829 |
(Item : Entity_Id; |
| 1830 |
Inputs : List_Id) return Boolean |
| 1831 |
is |
| 1832 |
Elmt : Node_Id; |
| 1833 |
|
| 1834 |
begin |
| 1835 |
Elmt := First (Inputs); |
| 1836 |
while Present (Elmt) loop |
| 1837 |
if Entity_Of (Elmt) = Item then |
| 1838 |
return True; |
| 1839 |
end if; |
| 1840 |
|
| 1841 |
Next (Elmt); |
| 1842 |
end loop; |
| 1843 |
|
| 1844 |
return False; |
| 1845 |
end In_Input_List; |
| 1846 |
|
| 1847 |
-- Local variables |
| 1848 |
|
| 1849 |
Output_Id : constant Entity_Id := Entity_Of (Output); |
| 1850 |
Grouped : List_Id; |
| 1851 |
|
| 1852 |
-- Start of processing for Propagate_Output |
| 1853 |
|
| 1854 |
begin |
| 1855 |
-- The clause is of the form: |
| 1856 |
|
| 1857 |
-- (Output =>+ null) |
| 1858 |
|
| 1859 |
-- Remove null input and replace it with a copy of the output: |
| 1860 |
|
| 1861 |
-- (Output => Output) |
| 1862 |
|
| 1863 |
if Nkind (Inputs) = N_Null then |
| 1864 |
Rewrite (Inputs, New_Copy_Tree (Output)); |
| 1865 |
|
| 1866 |
-- The clause is of the form: |
| 1867 |
|
| 1868 |
-- (Output =>+ (Input1, ..., InputN)) |
| 1869 |
|
| 1870 |
-- Determine whether the output is not already mentioned in the |
| 1871 |
-- input list and if not, add it to the list of inputs: |
| 1872 |
|
| 1873 |
-- (Output => (Output, Input1, ..., InputN)) |
| 1874 |
|
| 1875 |
elsif Nkind (Inputs) = N_Aggregate then |
| 1876 |
Grouped := Expressions (Inputs); |
| 1877 |
|
| 1878 |
if not In_Input_List |
| 1879 |
(Item => Output_Id, |
| 1880 |
Inputs => Grouped) |
| 1881 |
then |
| 1882 |
Prepend_To (Grouped, New_Copy_Tree (Output)); |
| 1883 |
end if; |
| 1884 |
|
| 1885 |
-- The clause is of the form: |
| 1886 |
|
| 1887 |
-- (Output =>+ Input) |
| 1888 |
|
| 1889 |
-- If the input does not mention the output, group the two |
| 1890 |
-- together: |
| 1891 |
|
| 1892 |
-- (Output => (Output, Input)) |
| 1893 |
|
| 1894 |
elsif Entity_Of (Inputs) /= Output_Id then |
| 1895 |
Rewrite (Inputs, |
| 1896 |
Make_Aggregate (Loc, |
| 1897 |
Expressions => New_List ( |
| 1898 |
New_Copy_Tree (Output), |
| 1899 |
New_Copy_Tree (Inputs)))); |
| 1900 |
end if; |
| 1901 |
end Propagate_Output; |
| 1902 |
|
| 1903 |
-- Local variables |
| 1904 |
|
| 1905 |
Loc : constant Source_Ptr := Sloc (Clause); |
| 1906 |
New_Clause : Node_Id; |
| 1907 |
|
| 1908 |
-- Start of processing for Create_Or_Modify_Clause |
| 1909 |
|
| 1910 |
begin |
| 1911 |
-- A null output depending on itself does not require any |
| 1912 |
-- normalization. |
| 1913 |
|
| 1914 |
if Nkind (Output) = N_Null then |
| 1915 |
return; |
| 1916 |
|
| 1917 |
-- A function result cannot depend on itself because it cannot |
| 1918 |
-- appear in the input list of a relation (SPARK RM 6.1.5(10)). |
| 1919 |
|
| 1920 |
elsif Is_Attribute_Result (Output) then |
| 1921 |
SPARK_Msg_N ("function result cannot depend on itself", Output); |
| 1922 |
return; |
| 1923 |
end if; |
| 1924 |
|
| 1925 |
-- When performing the transformation in place, simply add the |
| 1926 |
-- output to the list of inputs (if not already there). This |
| 1927 |
-- case arises when dealing with the last output of an output |
| 1928 |
-- list. Perform the normalization in place to avoid generating |
| 1929 |
-- a malformed tree. |
| 1930 |
|
| 1931 |
if In_Place then |
| 1932 |
Propagate_Output (Output, Inputs); |
| 1933 |
|
| 1934 |
-- A list with multiple outputs is slowly trimmed until only |
| 1935 |
-- one element remains. When this happens, replace aggregate |
| 1936 |
-- with the element itself. |
| 1937 |
|
| 1938 |
if Multiple then |
| 1939 |
Remove (Output); |
| 1940 |
Rewrite (Outputs, Output); |
| 1941 |
end if; |
| 1942 |
|
| 1943 |
-- Default case |
| 1944 |
|
| 1945 |
else |
| 1946 |
-- Unchain the output from its output list as it will appear in |
| 1947 |
-- a new clause. Note that we cannot simply rewrite the output |
| 1948 |
-- as null because this will violate the semantics of pragma |
| 1949 |
-- Depends. |
| 1950 |
|
| 1951 |
Remove (Output); |
| 1952 |
|
| 1953 |
-- Generate a new clause of the form: |
| 1954 |
-- (Output => Inputs) |
| 1955 |
|
| 1956 |
New_Clause := |
| 1957 |
Make_Component_Association (Loc, |
| 1958 |
Choices => New_List (Output), |
| 1959 |
Expression => New_Copy_Tree (Inputs)); |
| 1960 |
|
| 1961 |
-- The new clause contains replicated content that has already |
| 1962 |
-- been analyzed. There is not need to reanalyze or renormalize |
| 1963 |
-- it again. |
| 1964 |
|
| 1965 |
Set_Analyzed (New_Clause); |
| 1966 |
|
| 1967 |
Propagate_Output |
| 1968 |
(Output => First (Choices (New_Clause)), |
| 1969 |
Inputs => Expression (New_Clause)); |
| 1970 |
|
| 1971 |
Insert_After (After, New_Clause); |
| 1972 |
end if; |
| 1973 |
end Create_Or_Modify_Clause; |
| 1974 |
|
| 1975 |
-- Local variables |
| 1976 |
|
| 1977 |
Outputs : constant Node_Id := First (Choices (Clause)); |
| 1978 |
Inputs : Node_Id; |
| 1979 |
Last_Output : Node_Id; |
| 1980 |
Next_Output : Node_Id; |
| 1981 |
Output : Node_Id; |
| 1982 |
|
| 1983 |
-- Start of processing for Normalize_Clause |
| 1984 |
|
| 1985 |
begin |
| 1986 |
-- A self-dependency appears as operator "+". Remove the "+" from the |
| 1987 |
-- tree by moving the real inputs to their proper place. |
| 1988 |
|
| 1989 |
if Nkind (Expression (Clause)) = N_Op_Plus then |
| 1990 |
Rewrite (Expression (Clause), Right_Opnd (Expression (Clause))); |
| 1991 |
Inputs := Expression (Clause); |
| 1992 |
|
| 1993 |
-- Multiple outputs appear as an aggregate |
| 1994 |
|
| 1995 |
if Nkind (Outputs) = N_Aggregate then |
| 1996 |
Last_Output := Last (Expressions (Outputs)); |
| 1997 |
|
| 1998 |
Output := First (Expressions (Outputs)); |
| 1999 |
while Present (Output) loop |
| 2000 |
|
| 2001 |
-- Normalization may remove an output from its list, |
| 2002 |
-- preserve the subsequent output now. |
| 2003 |
|
| 2004 |
Next_Output := Next (Output); |
| 2005 |
|
| 2006 |
Create_Or_Modify_Clause |
| 2007 |
(Output => Output, |
| 2008 |
Outputs => Outputs, |
| 2009 |
Inputs => Inputs, |
| 2010 |
After => Clause, |
| 2011 |
In_Place => Output = Last_Output, |
| 2012 |
Multiple => True); |
| 2013 |
|
| 2014 |
Output := Next_Output; |
| 2015 |
end loop; |
| 2016 |
|
| 2017 |
-- Solitary output |
| 2018 |
|
| 2019 |
else |
| 2020 |
Create_Or_Modify_Clause |
| 2021 |
(Output => Outputs, |
| 2022 |
Outputs => Empty, |
| 2023 |
Inputs => Inputs, |
| 2024 |
After => Empty, |
| 2025 |
In_Place => True, |
| 2026 |
Multiple => False); |
| 2027 |
end if; |
| 2028 |
end if; |
| 2029 |
end Normalize_Clause; |
| 2030 |
|
| 2031 |
-- Local variables |
| 2032 |
|
| 2033 |
Deps : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
| 2034 |
Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl); |
| 2035 |
|
| 2036 |
Clause : Node_Id; |
| 2037 |
Errors : Nat; |
| 2038 |
Last_Clause : Node_Id; |
| 2039 |
Restore_Scope : Boolean := False; |
| 2040 |
|
| 2041 |
-- Start of processing for Analyze_Depends_In_Decl_Part |
| 2042 |
|
| 2043 |
begin |
| 2044 |
-- Do not analyze the pragma multiple times |
| 2045 |
|
| 2046 |
if Is_Analyzed_Pragma (N) then |
| 2047 |
return; |
| 2048 |
end if; |
| 2049 |
|
| 2050 |
-- Empty dependency list |
| 2051 |
|
| 2052 |
if Nkind (Deps) = N_Null then |
| 2053 |
|
| 2054 |
-- Gather all states, objects and formal parameters that the |
| 2055 |
-- subprogram may depend on. These items are obtained from the |
| 2056 |
-- parameter profile or pragma [Refined_]Global (if available). |
| 2057 |
|
| 2058 |
Collect_Subprogram_Inputs_Outputs |
| 2059 |
(Subp_Id => Subp_Id, |
| 2060 |
Subp_Inputs => Subp_Inputs, |
| 2061 |
Subp_Outputs => Subp_Outputs, |
| 2062 |
Global_Seen => Global_Seen); |
| 2063 |
|
| 2064 |
-- Verify that every input or output of the subprogram appear in a |
| 2065 |
-- dependency. |
| 2066 |
|
| 2067 |
Check_Usage (Subp_Inputs, All_Inputs_Seen, True); |
| 2068 |
Check_Usage (Subp_Outputs, All_Outputs_Seen, False); |
| 2069 |
Check_Function_Return; |
| 2070 |
|
| 2071 |
-- Dependency clauses appear as component associations of an aggregate |
| 2072 |
|
| 2073 |
elsif Nkind (Deps) = N_Aggregate then |
| 2074 |
|
| 2075 |
-- Do not attempt to perform analysis of a syntactically illegal |
| 2076 |
-- clause as this will lead to misleading errors. |
| 2077 |
|
| 2078 |
if Has_Extra_Parentheses (Deps) then |
| 2079 |
goto Leave; |
| 2080 |
end if; |
| 2081 |
|
| 2082 |
if Present (Component_Associations (Deps)) then |
| 2083 |
Last_Clause := Last (Component_Associations (Deps)); |
| 2084 |
|
| 2085 |
-- Gather all states, objects and formal parameters that the |
| 2086 |
-- subprogram may depend on. These items are obtained from the |
| 2087 |
-- parameter profile or pragma [Refined_]Global (if available). |
| 2088 |
|
| 2089 |
Collect_Subprogram_Inputs_Outputs |
| 2090 |
(Subp_Id => Subp_Id, |
| 2091 |
Subp_Inputs => Subp_Inputs, |
| 2092 |
Subp_Outputs => Subp_Outputs, |
| 2093 |
Global_Seen => Global_Seen); |
| 2094 |
|
| 2095 |
-- When pragma [Refined_]Depends appears on a single concurrent |
| 2096 |
-- type, it is relocated to the anonymous object. |
| 2097 |
|
| 2098 |
if Is_Single_Concurrent_Object (Spec_Id) then |
| 2099 |
null; |
| 2100 |
|
| 2101 |
-- Ensure that the formal parameters are visible when analyzing |
| 2102 |
-- all clauses. This falls out of the general rule of aspects |
| 2103 |
-- pertaining to subprogram declarations. |
| 2104 |
|
| 2105 |
elsif not In_Open_Scopes (Spec_Id) then |
| 2106 |
Restore_Scope := True; |
| 2107 |
Push_Scope (Spec_Id); |
| 2108 |
|
| 2109 |
if Ekind (Spec_Id) = E_Task_Type then |
| 2110 |
|
| 2111 |
-- Task discriminants cannot appear in the [Refined_]Depends |
| 2112 |
-- contract, but must be present for the analysis so that we |
| 2113 |
-- can reject them with an informative error message. |
| 2114 |
|
| 2115 |
if Has_Discriminants (Spec_Id) then |
| 2116 |
Install_Discriminants (Spec_Id); |
| 2117 |
end if; |
| 2118 |
|
| 2119 |
elsif Is_Generic_Subprogram (Spec_Id) then |
| 2120 |
Install_Generic_Formals (Spec_Id); |
| 2121 |
|
| 2122 |
else |
| 2123 |
Install_Formals (Spec_Id); |
| 2124 |
end if; |
| 2125 |
end if; |
| 2126 |
|
| 2127 |
Clause := First (Component_Associations (Deps)); |
| 2128 |
while Present (Clause) loop |
| 2129 |
Errors := Serious_Errors_Detected; |
| 2130 |
|
| 2131 |
-- The normalization mechanism may create extra clauses that |
| 2132 |
-- contain replicated input and output names. There is no need |
| 2133 |
-- to reanalyze them. |
| 2134 |
|
| 2135 |
if not Analyzed (Clause) then |
| 2136 |
Set_Analyzed (Clause); |
| 2137 |
|
| 2138 |
Analyze_Dependency_Clause |
| 2139 |
(Clause => Clause, |
| 2140 |
Is_Last => Clause = Last_Clause); |
| 2141 |
end if; |
| 2142 |
|
| 2143 |
-- Do not normalize a clause if errors were detected (count |
| 2144 |
-- of Serious_Errors has increased) because the inputs and/or |
| 2145 |
-- outputs may denote illegal items. |
| 2146 |
|
| 2147 |
if Serious_Errors_Detected = Errors then |
| 2148 |
Normalize_Clause (Clause); |
| 2149 |
end if; |
| 2150 |
|
| 2151 |
Next (Clause); |
| 2152 |
end loop; |
| 2153 |
|
| 2154 |
if Restore_Scope then |
| 2155 |
End_Scope; |
| 2156 |
end if; |
| 2157 |
|
| 2158 |
-- Verify that every input or output of the subprogram appear in a |
| 2159 |
-- dependency. |
| 2160 |
|
| 2161 |
Check_Usage (Subp_Inputs, All_Inputs_Seen, True); |
| 2162 |
Check_Usage (Subp_Outputs, All_Outputs_Seen, False); |
| 2163 |
Check_Function_Return; |
| 2164 |
|
| 2165 |
-- The dependency list is malformed. This is a syntax error, always |
| 2166 |
-- report. |
| 2167 |
|
| 2168 |
else |
| 2169 |
Error_Msg_N ("malformed dependency relation", Deps); |
| 2170 |
goto Leave; |
| 2171 |
end if; |
| 2172 |
|
| 2173 |
-- The top level dependency relation is malformed. This is a syntax |
| 2174 |
-- error, always report. |
| 2175 |
|
| 2176 |
else |
| 2177 |
Error_Msg_N ("malformed dependency relation", Deps); |
| 2178 |
goto Leave; |
| 2179 |
end if; |
| 2180 |
|
| 2181 |
-- Ensure that a state and a corresponding constituent do not appear |
| 2182 |
-- together in pragma [Refined_]Depends. |
| 2183 |
|
| 2184 |
Check_State_And_Constituent_Use |
| 2185 |
(States => States_Seen, |
| 2186 |
Constits => Constits_Seen, |
| 2187 |
Context => N); |
| 2188 |
|
| 2189 |
<<Leave>> |
| 2190 |
Set_Is_Analyzed_Pragma (N); |
| 2191 |
end Analyze_Depends_In_Decl_Part; |
| 2192 |
|
| 2193 |
-------------------------------------------- |
| 2194 |
-- Analyze_Exceptional_Cases_In_Decl_Part -- |
| 2195 |
-------------------------------------------- |
| 2196 |
|
| 2197 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 2198 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 2199 |
-- Ghost mode. |
| 2200 |
|
| 2201 |
procedure Analyze_Exceptional_Cases_In_Decl_Part |
| 2202 |
(N : Node_Id; |
| 2203 |
Freeze_Id : Entity_Id := Empty) |
| 2204 |
is |
| 2205 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 2206 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 2207 |
|
| 2208 |
procedure Analyze_Exceptional_Contract (Exceptional_Contract : Node_Id); |
| 2209 |
-- Verify the legality of a single exceptional contract |
| 2210 |
|
| 2211 |
procedure Check_Duplication (Id : Node_Id; Contracts : List_Id); |
| 2212 |
-- Iterate through the identifiers in each contract to find duplicates |
| 2213 |
|
| 2214 |
function Check_Param (N : Node_Id) return Traverse_Result; |
| 2215 |
-- Parameters of modes OUT or IN OUT of the subprogram shall not occur |
| 2216 |
-- in the consequences of an exceptional contract unless they are either |
| 2217 |
-- passed by reference or occur in the prefix of a reference to the 'Old |
| 2218 |
-- attribute or as direct prefixes of attributes that do not actually |
| 2219 |
-- read data from the object (SPARK RM 6.1.9(1)). References to |
| 2220 |
-- attribute Result should not occur either. |
| 2221 |
|
| 2222 |
----------------- |
| 2223 |
-- Check_Param -- |
| 2224 |
----------------- |
| 2225 |
|
| 2226 |
function Check_Param (N : Node_Id) return Traverse_Result is |
| 2227 |
begin |
| 2228 |
case Nkind (N) is |
| 2229 |
when N_Identifier | N_Expanded_Name => |
| 2230 |
declare |
| 2231 |
Id : constant Entity_Id := Entity (N); |
| 2232 |
begin |
| 2233 |
if Present (Id) |
| 2234 |
and then Ekind (Id) in E_Out_Parameter |
| 2235 |
| E_In_Out_Parameter |
| 2236 |
and then Scope (Id) = Spec_Id |
| 2237 |
and then not Is_By_Reference_Type (Etype (Id)) |
| 2238 |
and then not Is_Aliased (Id) |
| 2239 |
then |
| 2240 |
declare |
| 2241 |
Mode : constant String := |
| 2242 |
(if Ekind (Id) = E_Out_Parameter then "out" |
| 2243 |
else "in out"); |
| 2244 |
begin |
| 2245 |
Error_Msg_N |
| 2246 |
("formal parameter of mode """ & Mode |
| 2247 |
& """ in consequence of Exceptional_Cases", N); |
| 2248 |
Error_Msg_N |
| 2249 |
("\only parameters passed by reference are allowed", |
| 2250 |
N); |
| 2251 |
end; |
| 2252 |
end if; |
| 2253 |
end; |
| 2254 |
|
| 2255 |
when N_Attribute_Reference => |
| 2256 |
case Attribute_Name (N) is |
| 2257 |
when Name_Old => |
| 2258 |
return Skip; |
| 2259 |
when Name_Constrained |
| 2260 |
| Name_First |
| 2261 |
| Name_Last |
| 2262 |
| Name_Length |
| 2263 |
| Name_Range |
| 2264 |
=> |
| 2265 |
if Nkind (Prefix (N)) in N_Identifier |
| 2266 |
| N_Expanded_Name |
| 2267 |
then |
| 2268 |
return Skip; |
| 2269 |
end if; |
| 2270 |
when Name_Result => |
| 2271 |
Error_Msg_N |
| 2272 |
("attribute Result in consequence of Exceptional_Cases", |
| 2273 |
N); |
| 2274 |
when others => null; |
| 2275 |
end case; |
| 2276 |
|
| 2277 |
when others => null; |
| 2278 |
end case; |
| 2279 |
|
| 2280 |
return OK; |
| 2281 |
end Check_Param; |
| 2282 |
|
| 2283 |
procedure Check_Params is new Traverse_More_Proc (Check_Param); |
| 2284 |
|
| 2285 |
---------------------------------- |
| 2286 |
-- Analyze_Exceptional_Contract -- |
| 2287 |
---------------------------------- |
| 2288 |
|
| 2289 |
procedure Analyze_Exceptional_Contract (Exceptional_Contract : Node_Id) |
| 2290 |
is |
| 2291 |
Exception_Choice : Node_Id; |
| 2292 |
Consequence : Node_Id; |
| 2293 |
Errors : Nat; |
| 2294 |
|
| 2295 |
begin |
| 2296 |
if Nkind (Exceptional_Contract) /= N_Component_Association then |
| 2297 |
Error_Msg_N |
| 2298 |
("wrong syntax in exceptional contract", Exceptional_Contract); |
| 2299 |
return; |
| 2300 |
end if; |
| 2301 |
|
| 2302 |
Exception_Choice := First (Choices (Exceptional_Contract)); |
| 2303 |
Consequence := Expression (Exceptional_Contract); |
| 2304 |
|
| 2305 |
while Present (Exception_Choice) loop |
| 2306 |
if Nkind (Exception_Choice) = N_Others_Choice then |
| 2307 |
if Present (Next (Exception_Choice)) |
| 2308 |
or else Present (Next (Exceptional_Contract)) |
| 2309 |
or else Present (Prev (Exception_Choice)) |
| 2310 |
then |
| 2311 |
Error_Msg_N |
| 2312 |
("OTHERS must appear alone and last", Exception_Choice); |
| 2313 |
end if; |
| 2314 |
|
| 2315 |
else |
| 2316 |
Analyze (Exception_Choice); |
| 2317 |
|
| 2318 |
if Is_Entity_Name (Exception_Choice) |
| 2319 |
and then Ekind (Entity (Exception_Choice)) = E_Exception |
| 2320 |
then |
| 2321 |
if Present (Renamed_Entity (Entity (Exception_Choice))) |
| 2322 |
and then Entity (Exception_Choice) = Standard_Numeric_Error |
| 2323 |
then |
| 2324 |
Check_Restriction |
| 2325 |
(No_Obsolescent_Features, Exception_Choice); |
| 2326 |
|
| 2327 |
if Warn_On_Obsolescent_Feature then |
| 2328 |
Error_Msg_N |
| 2329 |
("Numeric_Error is an obsolescent feature " & |
| 2330 |
"(RM J.6(1))?j?", |
| 2331 |
Exception_Choice); |
| 2332 |
Error_Msg_N |
| 2333 |
("\use Constraint_Error instead?j?", |
| 2334 |
Exception_Choice); |
| 2335 |
end if; |
| 2336 |
end if; |
| 2337 |
|
| 2338 |
Check_Duplication |
| 2339 |
(Exception_Choice, List_Containing (Exceptional_Contract)); |
| 2340 |
|
| 2341 |
-- Check for exception declared within generic formal |
| 2342 |
-- package (which is illegal, see RM 11.2(8)). |
| 2343 |
|
| 2344 |
declare |
| 2345 |
Ent : Entity_Id := Entity (Exception_Choice); |
| 2346 |
Scop : Entity_Id; |
| 2347 |
|
| 2348 |
begin |
| 2349 |
if Present (Renamed_Entity (Ent)) then |
| 2350 |
Ent := Renamed_Entity (Ent); |
| 2351 |
end if; |
| 2352 |
|
| 2353 |
Scop := Scope (Ent); |
| 2354 |
while Scop /= Standard_Standard |
| 2355 |
and then Ekind (Scop) = E_Package |
| 2356 |
loop |
| 2357 |
if Nkind (Declaration_Node (Scop)) = |
| 2358 |
N_Package_Specification |
| 2359 |
and then |
| 2360 |
Nkind (Original_Node (Parent |
| 2361 |
(Declaration_Node (Scop)))) = |
| 2362 |
N_Formal_Package_Declaration |
| 2363 |
then |
| 2364 |
Error_Msg_NE |
| 2365 |
("exception& is declared in generic formal " |
| 2366 |
& "package", Exception_Choice, Ent); |
| 2367 |
Error_Msg_N |
| 2368 |
("\and therefore cannot appear in contract " |
| 2369 |
& "(RM 11.2(8))", Exception_Choice); |
| 2370 |
exit; |
| 2371 |
|
| 2372 |
-- If the exception is declared in an inner instance, |
| 2373 |
-- nothing else to check. |
| 2374 |
|
| 2375 |
elsif Is_Generic_Instance (Scop) then |
| 2376 |
exit; |
| 2377 |
end if; |
| 2378 |
|
| 2379 |
Scop := Scope (Scop); |
| 2380 |
end loop; |
| 2381 |
end; |
| 2382 |
else |
| 2383 |
Error_Msg_N ("exception name expected", Exception_Choice); |
| 2384 |
end if; |
| 2385 |
end if; |
| 2386 |
|
| 2387 |
Next (Exception_Choice); |
| 2388 |
end loop; |
| 2389 |
|
| 2390 |
-- Now analyze the expressions of this contract |
| 2391 |
|
| 2392 |
Errors := Serious_Errors_Detected; |
| 2393 |
|
| 2394 |
-- Preanalyze_Assert_Expression enforcing the expression type |
| 2395 |
|
| 2396 |
Preanalyze_Assert_Expression (Consequence, Any_Boolean); |
| 2397 |
|
| 2398 |
Check_Params (Consequence); |
| 2399 |
|
| 2400 |
-- Emit a clarification message when the consequence contains at |
| 2401 |
-- least one undefined reference, possibly due to contract freezing. |
| 2402 |
|
| 2403 |
if Errors /= Serious_Errors_Detected |
| 2404 |
and then Present (Freeze_Id) |
| 2405 |
and then Has_Undefined_Reference (Consequence) |
| 2406 |
then |
| 2407 |
Contract_Freeze_Error (Spec_Id, Freeze_Id); |
| 2408 |
end if; |
| 2409 |
end Analyze_Exceptional_Contract; |
| 2410 |
|
| 2411 |
----------------------- |
| 2412 |
-- Check_Duplication -- |
| 2413 |
----------------------- |
| 2414 |
|
| 2415 |
procedure Check_Duplication (Id : Node_Id; Contracts : List_Id) is |
| 2416 |
Contract : Node_Id; |
| 2417 |
Id1 : Node_Id; |
| 2418 |
Id_Entity : Entity_Id := Entity (Id); |
| 2419 |
|
| 2420 |
begin |
| 2421 |
if Present (Renamed_Entity (Id_Entity)) then |
| 2422 |
Id_Entity := Renamed_Entity (Id_Entity); |
| 2423 |
end if; |
| 2424 |
|
| 2425 |
Contract := First (Contracts); |
| 2426 |
while Present (Contract) loop |
| 2427 |
Id1 := First (Choices (Contract)); |
| 2428 |
while Present (Id1) loop |
| 2429 |
|
| 2430 |
-- Only check against the exception choices which precede |
| 2431 |
-- Id in the contract, since the ones that follow Id have not |
| 2432 |
-- been analyzed yet and will be checked in a subsequent call. |
| 2433 |
|
| 2434 |
if Id = Id1 then |
| 2435 |
return; |
| 2436 |
|
| 2437 |
-- Duplication both simple and via a renaming across different |
| 2438 |
-- exceptional contracts is illegal. |
| 2439 |
|
| 2440 |
elsif Nkind (Id1) /= N_Others_Choice |
| 2441 |
and then |
| 2442 |
(Id_Entity = Entity (Id1) |
| 2443 |
or else Id_Entity = Renamed_Entity (Entity (Id1))) |
| 2444 |
and then Contract /= Parent (Id) |
| 2445 |
then |
| 2446 |
Error_Msg_Sloc := Sloc (Id1); |
| 2447 |
Error_Msg_NE ("exception choice duplicates &#", Id, Id1); |
| 2448 |
end if; |
| 2449 |
|
| 2450 |
Next (Id1); |
| 2451 |
end loop; |
| 2452 |
|
| 2453 |
Next (Contract); |
| 2454 |
end loop; |
| 2455 |
end Check_Duplication; |
| 2456 |
|
| 2457 |
-- Local variables |
| 2458 |
|
| 2459 |
Exceptional_Contracts : constant Node_Id := |
| 2460 |
Expression (Get_Argument (N, Spec_Id)); |
| 2461 |
|
| 2462 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 2463 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 2464 |
-- Save the Ghost-related attributes to restore on exit |
| 2465 |
|
| 2466 |
Exceptional_Contract : Node_Id; |
| 2467 |
Restore_Scope : Boolean := False; |
| 2468 |
|
| 2469 |
-- Start of processing for Analyze_Subprogram_Variant_In_Decl_Part |
| 2470 |
|
| 2471 |
begin |
| 2472 |
-- Do not analyze the pragma multiple times |
| 2473 |
|
| 2474 |
if Is_Analyzed_Pragma (N) then |
| 2475 |
return; |
| 2476 |
end if; |
| 2477 |
|
| 2478 |
-- Set the Ghost mode in effect from the pragma. Due to the delayed |
| 2479 |
-- analysis of the pragma, the Ghost mode at point of declaration and |
| 2480 |
-- point of analysis may not necessarily be the same. Use the mode in |
| 2481 |
-- effect at the point of declaration. |
| 2482 |
|
| 2483 |
Set_Ghost_Mode (N); |
| 2484 |
|
| 2485 |
-- Single and multiple contracts must appear in aggregate form. If this |
| 2486 |
-- is not the case, then either the parser of the analysis of the pragma |
| 2487 |
-- failed to produce an aggregate, e.g. when the contract is "null" or a |
| 2488 |
-- "(null record)". |
| 2489 |
|
| 2490 |
pragma Assert |
| 2491 |
(if Nkind (Exceptional_Contracts) = N_Aggregate |
| 2492 |
then Null_Record_Present (Exceptional_Contracts) |
| 2493 |
xor (Present (Component_Associations (Exceptional_Contracts)) |
| 2494 |
or |
| 2495 |
Present (Expressions (Exceptional_Contracts))) |
| 2496 |
else Nkind (Exceptional_Contracts) = N_Null); |
| 2497 |
|
| 2498 |
-- Only clauses of the following form are allowed: |
| 2499 |
-- |
| 2500 |
-- exceptional_contract ::= |
| 2501 |
-- [choice_parameter_specification:] |
| 2502 |
-- exception_choice {'|' exception_choice} => consequence |
| 2503 |
-- |
| 2504 |
-- where |
| 2505 |
-- |
| 2506 |
-- consequence ::= Boolean_expression |
| 2507 |
|
| 2508 |
if Nkind (Exceptional_Contracts) = N_Aggregate |
| 2509 |
and then Present (Component_Associations (Exceptional_Contracts)) |
| 2510 |
and then No (Expressions (Exceptional_Contracts)) |
| 2511 |
then |
| 2512 |
|
| 2513 |
-- Check that the expression is a proper aggregate (no parentheses) |
| 2514 |
|
| 2515 |
if Paren_Count (Exceptional_Contracts) /= 0 then |
| 2516 |
Error_Msg_F -- CODEFIX |
| 2517 |
("redundant parentheses", Exceptional_Contracts); |
| 2518 |
end if; |
| 2519 |
|
| 2520 |
-- Ensure that the formal parameters are visible when analyzing all |
| 2521 |
-- clauses. This falls out of the general rule of aspects pertaining |
| 2522 |
-- to subprogram declarations. |
| 2523 |
|
| 2524 |
if not In_Open_Scopes (Spec_Id) then |
| 2525 |
Restore_Scope := True; |
| 2526 |
Push_Scope (Spec_Id); |
| 2527 |
|
| 2528 |
if Is_Generic_Subprogram (Spec_Id) then |
| 2529 |
Install_Generic_Formals (Spec_Id); |
| 2530 |
else |
| 2531 |
Install_Formals (Spec_Id); |
| 2532 |
end if; |
| 2533 |
end if; |
| 2534 |
|
| 2535 |
Exceptional_Contract := |
| 2536 |
First (Component_Associations (Exceptional_Contracts)); |
| 2537 |
while Present (Exceptional_Contract) loop |
| 2538 |
Analyze_Exceptional_Contract (Exceptional_Contract); |
| 2539 |
Next (Exceptional_Contract); |
| 2540 |
end loop; |
| 2541 |
|
| 2542 |
if Restore_Scope then |
| 2543 |
End_Scope; |
| 2544 |
end if; |
| 2545 |
|
| 2546 |
-- Otherwise the pragma is illegal |
| 2547 |
|
| 2548 |
else |
| 2549 |
Error_Msg_N ("wrong syntax for exceptional cases", N); |
| 2550 |
end if; |
| 2551 |
|
| 2552 |
Set_Is_Analyzed_Pragma (N); |
| 2553 |
|
| 2554 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 2555 |
end Analyze_Exceptional_Cases_In_Decl_Part; |
| 2556 |
|
| 2557 |
------------------------------------- |
| 2558 |
-- Analyze_Exit_Cases_In_Decl_Part -- |
| 2559 |
------------------------------------- |
| 2560 |
|
| 2561 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 2562 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 2563 |
-- Ghost mode. |
| 2564 |
|
| 2565 |
procedure Analyze_Exit_Cases_In_Decl_Part |
| 2566 |
(N : Node_Id; |
| 2567 |
Freeze_Id : Entity_Id := Empty) |
| 2568 |
is |
| 2569 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 2570 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 2571 |
|
| 2572 |
Others_Seen : Boolean := False; |
| 2573 |
-- This flag is set when an "others" choice is encountered. It is used |
| 2574 |
-- to detect multiple illegal occurrences of "others". |
| 2575 |
|
| 2576 |
procedure Analyze_Exit_Contract (Exit_Contract : Node_Id); |
| 2577 |
-- Verify the legality of a single exit contract |
| 2578 |
|
| 2579 |
--------------------------- |
| 2580 |
-- Analyze_Exit_Contract -- |
| 2581 |
--------------------------- |
| 2582 |
|
| 2583 |
procedure Analyze_Exit_Contract (Exit_Contract : Node_Id) is |
| 2584 |
Case_Guard : Node_Id; |
| 2585 |
Exit_Kind : Node_Id; |
| 2586 |
Errors : Nat; |
| 2587 |
Extra_Guard : Node_Id; |
| 2588 |
|
| 2589 |
begin |
| 2590 |
if Nkind (Exit_Contract) = N_Component_Association then |
| 2591 |
Case_Guard := First (Choices (Exit_Contract)); |
| 2592 |
Exit_Kind := Expression (Exit_Contract); |
| 2593 |
|
| 2594 |
-- Each exit case must have exactly one case guard |
| 2595 |
|
| 2596 |
Extra_Guard := Next (Case_Guard); |
| 2597 |
|
| 2598 |
if Present (Extra_Guard) then |
| 2599 |
Error_Msg_N |
| 2600 |
("exit case must have exactly one case guard", |
| 2601 |
Extra_Guard); |
| 2602 |
end if; |
| 2603 |
|
| 2604 |
-- Check placement of OTHERS if available (SPARK RM 6.1.3(1)) |
| 2605 |
|
| 2606 |
if Nkind (Case_Guard) = N_Others_Choice then |
| 2607 |
if Others_Seen then |
| 2608 |
Error_Msg_N |
| 2609 |
("only one OTHERS choice allowed in exit cases", |
| 2610 |
Case_Guard); |
| 2611 |
else |
| 2612 |
Others_Seen := True; |
| 2613 |
end if; |
| 2614 |
|
| 2615 |
elsif Others_Seen then |
| 2616 |
Error_Msg_N |
| 2617 |
("OTHERS must be the last choice in exit cases", N); |
| 2618 |
end if; |
| 2619 |
|
| 2620 |
-- Preanalyze the case guard |
| 2621 |
|
| 2622 |
if Nkind (Case_Guard) /= N_Others_Choice then |
| 2623 |
Errors := Serious_Errors_Detected; |
| 2624 |
Preanalyze_Assert_Expression (Case_Guard, Standard_Boolean); |
| 2625 |
|
| 2626 |
-- Emit a clarification message when the case guard contains |
| 2627 |
-- at least one undefined reference, possibly due to contract |
| 2628 |
-- freezing. |
| 2629 |
|
| 2630 |
if Errors /= Serious_Errors_Detected |
| 2631 |
and then Present (Freeze_Id) |
| 2632 |
and then Has_Undefined_Reference (Case_Guard) |
| 2633 |
then |
| 2634 |
Contract_Freeze_Error (Spec_Id, Freeze_Id); |
| 2635 |
end if; |
| 2636 |
end if; |
| 2637 |
|
| 2638 |
-- Check the exit kind. It shall be either an exception or the |
| 2639 |
-- identifiers Normal_Return or Any_Exception. |
| 2640 |
|
| 2641 |
if Nkind (Exit_Kind) = N_Identifier then |
| 2642 |
if Chars (Exit_Kind) not in Name_Normal_Return |
| 2643 |
| Name_Exception_Raised |
| 2644 |
then |
| 2645 |
Error_Msg_N |
| 2646 |
("exit kind should be Normal_Return or Exception_Raised", |
| 2647 |
Exit_Kind); |
| 2648 |
end if; |
| 2649 |
|
| 2650 |
elsif Nkind (Exit_Kind) = N_Aggregate |
| 2651 |
and then Present (Component_Associations (Exit_Kind)) |
| 2652 |
then |
| 2653 |
declare |
| 2654 |
Assoc : constant Node_Id := |
| 2655 |
First (Component_Associations (Exit_Kind)); |
| 2656 |
Choice : constant Node_Id := First (Choice_List (Assoc)); |
| 2657 |
Exc : constant Node_Id := |
| 2658 |
(if Box_Present (Assoc) then Assoc |
| 2659 |
else Expression (Assoc)); |
| 2660 |
begin |
| 2661 |
if Present (Next (Assoc)) then |
| 2662 |
Error_Msg_N |
| 2663 |
("exit kind should have a single association", |
| 2664 |
Exit_Kind); |
| 2665 |
|
| 2666 |
elsif Present (Next (Choice)) |
| 2667 |
or else Nkind (Choice) /= N_Identifier |
| 2668 |
or else Chars (Choice) /= Name_Exception_Raised |
| 2669 |
then |
| 2670 |
Error_Msg_N |
| 2671 |
("exit kind should have a single choice named " |
| 2672 |
& "Exception_Raised", |
| 2673 |
Exit_Kind); |
| 2674 |
|
| 2675 |
elsif Nkind (Exc) /= N_Identifier then |
| 2676 |
Error_Msg_N |
| 2677 |
("exception name expected after Exception_Raised", |
| 2678 |
Exc); |
| 2679 |
|
| 2680 |
else |
| 2681 |
Analyze (Exc); |
| 2682 |
|
| 2683 |
if Is_Entity_Name (Exc) |
| 2684 |
and then Ekind (Entity (Exc)) = E_Exception |
| 2685 |
then |
| 2686 |
if Present (Renamed_Entity (Entity (Exc))) |
| 2687 |
and then Entity (Exc) = Standard_Numeric_Error |
| 2688 |
then |
| 2689 |
Check_Restriction (No_Obsolescent_Features, Exc); |
| 2690 |
|
| 2691 |
if Warn_On_Obsolescent_Feature then |
| 2692 |
Error_Msg_N |
| 2693 |
("Numeric_Error is an obsolescent feature " & |
| 2694 |
"(RM J.6(1))?j?", |
| 2695 |
Exc); |
| 2696 |
Error_Msg_N |
| 2697 |
("\use Constraint_Error instead?j?", |
| 2698 |
Exc); |
| 2699 |
end if; |
| 2700 |
end if; |
| 2701 |
|
| 2702 |
-- Check for exception declared within generic formal |
| 2703 |
-- package (which is illegal, see RM 11.2(8)). |
| 2704 |
|
| 2705 |
declare |
| 2706 |
Ent : Entity_Id := Entity (Exc); |
| 2707 |
Scop : Entity_Id; |
| 2708 |
|
| 2709 |
begin |
| 2710 |
if Present (Renamed_Entity (Ent)) then |
| 2711 |
Ent := Renamed_Entity (Ent); |
| 2712 |
end if; |
| 2713 |
|
| 2714 |
Scop := Scope (Ent); |
| 2715 |
while Scop /= Standard_Standard |
| 2716 |
and then Ekind (Scop) = E_Package |
| 2717 |
loop |
| 2718 |
if Nkind (Declaration_Node (Scop)) = |
| 2719 |
N_Package_Specification |
| 2720 |
and then |
| 2721 |
Nkind (Original_Node (Parent |
| 2722 |
(Declaration_Node (Scop)))) = |
| 2723 |
N_Formal_Package_Declaration |
| 2724 |
then |
| 2725 |
Error_Msg_NE |
| 2726 |
("exception& is declared in generic formal " |
| 2727 |
& "package", Exc, Ent); |
| 2728 |
Error_Msg_N |
| 2729 |
("\and therefore cannot appear in contract " |
| 2730 |
& "(RM 11.2(8))", Exc); |
| 2731 |
exit; |
| 2732 |
|
| 2733 |
-- If the exception is declared in an inner |
| 2734 |
-- instance, nothing else to check. |
| 2735 |
|
| 2736 |
elsif Is_Generic_Instance (Scop) then |
| 2737 |
exit; |
| 2738 |
end if; |
| 2739 |
|
| 2740 |
Scop := Scope (Scop); |
| 2741 |
end loop; |
| 2742 |
end; |
| 2743 |
else |
| 2744 |
Error_Msg_N |
| 2745 |
("exception name expected after Exception_Raised", |
| 2746 |
Exc); |
| 2747 |
end if; |
| 2748 |
end if; |
| 2749 |
end; |
| 2750 |
|
| 2751 |
else |
| 2752 |
Error_Msg_N ("wrong syntax", Exit_Kind); |
| 2753 |
end if; |
| 2754 |
|
| 2755 |
-- The exit case is malformed |
| 2756 |
|
| 2757 |
else |
| 2758 |
Error_Msg_N ("wrong syntax in exit case", Exit_Contract); |
| 2759 |
end if; |
| 2760 |
end Analyze_Exit_Contract; |
| 2761 |
|
| 2762 |
-- Local variables |
| 2763 |
|
| 2764 |
Exit_Contracts : constant Node_Id := |
| 2765 |
Expression (Get_Argument (N, Spec_Id)); |
| 2766 |
|
| 2767 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 2768 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 2769 |
-- Save the Ghost-related attributes to restore on exit |
| 2770 |
|
| 2771 |
Exit_Contract : Node_Id; |
| 2772 |
Restore_Scope : Boolean := False; |
| 2773 |
|
| 2774 |
-- Start of processing for Analyze_Exit_Cases_In_Decl_Part |
| 2775 |
|
| 2776 |
begin |
| 2777 |
-- Do not analyze the pragma multiple times |
| 2778 |
|
| 2779 |
if Is_Analyzed_Pragma (N) then |
| 2780 |
return; |
| 2781 |
end if; |
| 2782 |
|
| 2783 |
-- Set the Ghost mode in effect from the pragma. Due to the delayed |
| 2784 |
-- analysis of the pragma, the Ghost mode at point of declaration and |
| 2785 |
-- point of analysis may not necessarily be the same. Use the mode in |
| 2786 |
-- effect at the point of declaration. |
| 2787 |
|
| 2788 |
Set_Ghost_Mode (N); |
| 2789 |
|
| 2790 |
-- Single and multiple contracts must appear in aggregate form. If this |
| 2791 |
-- is not the case, then either the parser of the analysis of the pragma |
| 2792 |
-- failed to produce an aggregate, e.g. when the contract is "null" or a |
| 2793 |
-- "(null record)". |
| 2794 |
|
| 2795 |
pragma Assert |
| 2796 |
(if Nkind (Exit_Contracts) = N_Aggregate |
| 2797 |
then Null_Record_Present (Exit_Contracts) |
| 2798 |
xor (Present (Component_Associations (Exit_Contracts)) |
| 2799 |
or |
| 2800 |
Present (Expressions (Exit_Contracts))) |
| 2801 |
else Nkind (Exit_Contracts) = N_Null); |
| 2802 |
|
| 2803 |
-- Only clauses of the following form are allowed: |
| 2804 |
-- |
| 2805 |
-- exit_contract ::= |
| 2806 |
-- case_condition => exit_kind |
| 2807 |
-- |
| 2808 |
-- where |
| 2809 |
-- |
| 2810 |
-- case_condition ::= Boolean_expression |
| 2811 |
|
| 2812 |
if Nkind (Exit_Contracts) = N_Aggregate |
| 2813 |
and then Present (Component_Associations (Exit_Contracts)) |
| 2814 |
and then No (Expressions (Exit_Contracts)) |
| 2815 |
then |
| 2816 |
|
| 2817 |
-- Check that the expression is a proper aggregate (no parentheses) |
| 2818 |
|
| 2819 |
if Paren_Count (Exit_Contracts) /= 0 then |
| 2820 |
Error_Msg_F -- CODEFIX |
| 2821 |
("redundant parentheses", Exit_Contracts); |
| 2822 |
end if; |
| 2823 |
|
| 2824 |
-- Ensure that the formal parameters are visible when analyzing all |
| 2825 |
-- clauses. This falls out of the general rule of aspects pertaining |
| 2826 |
-- to subprogram declarations. |
| 2827 |
|
| 2828 |
if not In_Open_Scopes (Spec_Id) then |
| 2829 |
Restore_Scope := True; |
| 2830 |
Push_Scope (Spec_Id); |
| 2831 |
|
| 2832 |
if Is_Generic_Subprogram (Spec_Id) then |
| 2833 |
Install_Generic_Formals (Spec_Id); |
| 2834 |
else |
| 2835 |
Install_Formals (Spec_Id); |
| 2836 |
end if; |
| 2837 |
end if; |
| 2838 |
|
| 2839 |
Exit_Contract := |
| 2840 |
First (Component_Associations (Exit_Contracts)); |
| 2841 |
while Present (Exit_Contract) loop |
| 2842 |
Analyze_Exit_Contract (Exit_Contract); |
| 2843 |
Next (Exit_Contract); |
| 2844 |
end loop; |
| 2845 |
|
| 2846 |
if Restore_Scope then |
| 2847 |
End_Scope; |
| 2848 |
end if; |
| 2849 |
|
| 2850 |
-- Otherwise the pragma is illegal |
| 2851 |
|
| 2852 |
else |
| 2853 |
Error_Msg_N ("wrong syntax for exceptional cases", N); |
| 2854 |
end if; |
| 2855 |
|
| 2856 |
Set_Is_Analyzed_Pragma (N); |
| 2857 |
|
| 2858 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 2859 |
end Analyze_Exit_Cases_In_Decl_Part; |
| 2860 |
|
| 2861 |
-------------------------------------------- |
| 2862 |
-- Analyze_External_Property_In_Decl_Part -- |
| 2863 |
-------------------------------------------- |
| 2864 |
|
| 2865 |
procedure Analyze_External_Property_In_Decl_Part |
| 2866 |
(N : Node_Id; |
| 2867 |
Expr_Val : out Boolean) |
| 2868 |
is |
| 2869 |
Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pragma_Name (N)); |
| 2870 |
Arg1 : constant Node_Id := |
| 2871 |
First (Pragma_Argument_Associations (N)); |
| 2872 |
Obj_Decl : constant Node_Id := Find_Related_Context (N); |
| 2873 |
Obj_Id : constant Entity_Id := Defining_Entity (Obj_Decl); |
| 2874 |
Obj_Typ : Entity_Id; |
| 2875 |
Expr : Node_Id; |
| 2876 |
|
| 2877 |
begin |
| 2878 |
if Is_Type (Obj_Id) then |
| 2879 |
Obj_Typ := Obj_Id; |
| 2880 |
else |
| 2881 |
Obj_Typ := Etype (Obj_Id); |
| 2882 |
end if; |
| 2883 |
|
| 2884 |
-- Ensure that the Boolean expression (if present) is static. A missing |
| 2885 |
-- argument defaults the value to True (SPARK RM 7.1.2(5)). |
| 2886 |
|
| 2887 |
Expr_Val := True; |
| 2888 |
|
| 2889 |
if Present (Arg1) then |
| 2890 |
Expr := Get_Pragma_Arg (Arg1); |
| 2891 |
|
| 2892 |
if Is_OK_Static_Expression (Expr) then |
| 2893 |
Expr_Val := Is_True (Expr_Value (Expr)); |
| 2894 |
end if; |
| 2895 |
end if; |
| 2896 |
|
| 2897 |
-- The output parameter was set to the argument specified by the pragma. |
| 2898 |
-- Do not analyze the pragma multiple times. |
| 2899 |
|
| 2900 |
if Is_Analyzed_Pragma (N) then |
| 2901 |
return; |
| 2902 |
end if; |
| 2903 |
|
| 2904 |
Error_Msg_Name_1 := Pragma_Name (N); |
| 2905 |
|
| 2906 |
-- An external property pragma must apply to an effectively volatile |
| 2907 |
-- object other than a formal subprogram parameter (SPARK RM 7.1.3(2)). |
| 2908 |
-- The check is performed at the end of the declarative region due to a |
| 2909 |
-- possible out-of-order arrangement of pragmas: |
| 2910 |
|
| 2911 |
-- Obj : ...; |
| 2912 |
-- pragma Async_Readers (Obj); |
| 2913 |
-- pragma Volatile (Obj); |
| 2914 |
|
| 2915 |
if Prag_Id /= Pragma_No_Caching |
| 2916 |
and then not Is_Effectively_Volatile (Obj_Id) |
| 2917 |
then |
| 2918 |
if No_Caching_Enabled (Obj_Id) then |
| 2919 |
if Expr_Val then -- Confirming value of False is allowed |
| 2920 |
SPARK_Msg_N |
| 2921 |
("illegal combination of external property % and property " |
| 2922 |
& """No_Caching"" (SPARK RM 7.1.2(6))", N); |
| 2923 |
end if; |
| 2924 |
else |
| 2925 |
SPARK_Msg_N |
| 2926 |
("external property % must apply to a volatile type or object", |
| 2927 |
N); |
| 2928 |
end if; |
| 2929 |
|
| 2930 |
-- Pragma No_Caching should only apply to volatile types or variables of |
| 2931 |
-- a non-effectively volatile type (SPARK RM 7.1.2). |
| 2932 |
|
| 2933 |
elsif Prag_Id = Pragma_No_Caching then |
| 2934 |
if Is_Effectively_Volatile (Obj_Typ) then |
| 2935 |
SPARK_Msg_N ("property % must not apply to a type or object of " |
| 2936 |
& "an effectively volatile type", N); |
| 2937 |
elsif not Is_Volatile (Obj_Id) then |
| 2938 |
SPARK_Msg_N |
| 2939 |
("property % must apply to a volatile type or object", N); |
| 2940 |
end if; |
| 2941 |
end if; |
| 2942 |
|
| 2943 |
Set_Is_Analyzed_Pragma (N); |
| 2944 |
end Analyze_External_Property_In_Decl_Part; |
| 2945 |
|
| 2946 |
--------------------------------- |
| 2947 |
-- Analyze_Global_In_Decl_Part -- |
| 2948 |
--------------------------------- |
| 2949 |
|
| 2950 |
procedure Analyze_Global_In_Decl_Part (N : Node_Id) is |
| 2951 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 2952 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 2953 |
Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl); |
| 2954 |
|
| 2955 |
Constits_Seen : Elist_Id := No_Elist; |
| 2956 |
-- A list containing the entities of all constituents processed so far. |
| 2957 |
-- It aids in detecting illegal usage of a state and a corresponding |
| 2958 |
-- constituent in pragma [Refinde_]Global. |
| 2959 |
|
| 2960 |
Seen : Elist_Id := No_Elist; |
| 2961 |
-- A list containing the entities of all the items processed so far. It |
| 2962 |
-- plays a role in detecting distinct entities. |
| 2963 |
|
| 2964 |
States_Seen : Elist_Id := No_Elist; |
| 2965 |
-- A list containing the entities of all states processed so far. It |
| 2966 |
-- helps in detecting illegal usage of a state and a corresponding |
| 2967 |
-- constituent in pragma [Refined_]Global. |
| 2968 |
|
| 2969 |
In_Out_Seen : Boolean := False; |
| 2970 |
Input_Seen : Boolean := False; |
| 2971 |
Output_Seen : Boolean := False; |
| 2972 |
Proof_Seen : Boolean := False; |
| 2973 |
-- Flags used to verify the consistency of modes |
| 2974 |
|
| 2975 |
procedure Analyze_Global_List |
| 2976 |
(List : Node_Id; |
| 2977 |
Global_Mode : Name_Id := Name_Input); |
| 2978 |
-- Verify the legality of a single global list declaration. Global_Mode |
| 2979 |
-- denotes the current mode in effect. |
| 2980 |
|
| 2981 |
------------------------- |
| 2982 |
-- Analyze_Global_List -- |
| 2983 |
------------------------- |
| 2984 |
|
| 2985 |
procedure Analyze_Global_List |
| 2986 |
(List : Node_Id; |
| 2987 |
Global_Mode : Name_Id := Name_Input) |
| 2988 |
is |
| 2989 |
procedure Analyze_Global_Item |
| 2990 |
(Item : Node_Id; |
| 2991 |
Global_Mode : Name_Id); |
| 2992 |
-- Verify the legality of a single global item declaration denoted by |
| 2993 |
-- Item. Global_Mode denotes the current mode in effect. |
| 2994 |
|
| 2995 |
procedure Check_Duplicate_Mode |
| 2996 |
(Mode : Node_Id; |
| 2997 |
Status : in out Boolean); |
| 2998 |
-- Flag Status denotes whether a particular mode has been seen while |
| 2999 |
-- processing a global list. This routine verifies that Mode is not a |
| 3000 |
-- duplicate mode and sets the flag Status (SPARK RM 6.1.4(9)). |
| 3001 |
|
| 3002 |
procedure Check_Mode_Restriction_In_Enclosing_Context |
| 3003 |
(Item : Node_Id; |
| 3004 |
Item_Id : Entity_Id); |
| 3005 |
-- Verify that an item of mode In_Out or Output does not appear as |
| 3006 |
-- an input in the Global aspect of an enclosing subprogram or task |
| 3007 |
-- unit. If this is the case, emit an error. Item and Item_Id are |
| 3008 |
-- respectively the item and its entity. |
| 3009 |
|
| 3010 |
procedure Check_Mode_Restriction_In_Function (Mode : Node_Id); |
| 3011 |
-- Mode denotes either In_Out or Output. Depending on the kind of the |
| 3012 |
-- related subprogram, emit an error if those two modes apply to a |
| 3013 |
-- function (SPARK RM 6.1.4(10)). |
| 3014 |
|
| 3015 |
------------------------- |
| 3016 |
-- Analyze_Global_Item -- |
| 3017 |
------------------------- |
| 3018 |
|
| 3019 |
procedure Analyze_Global_Item |
| 3020 |
(Item : Node_Id; |
| 3021 |
Global_Mode : Name_Id) |
| 3022 |
is |
| 3023 |
Item_Id : Entity_Id; |
| 3024 |
|
| 3025 |
begin |
| 3026 |
-- Detect one of the following cases |
| 3027 |
|
| 3028 |
-- with Global => (null, Name) |
| 3029 |
-- with Global => (Name_1, null, Name_2) |
| 3030 |
-- with Global => (Name, null) |
| 3031 |
|
| 3032 |
if Nkind (Item) = N_Null then |
| 3033 |
SPARK_Msg_N ("cannot mix null and non-null global items", Item); |
| 3034 |
return; |
| 3035 |
end if; |
| 3036 |
|
| 3037 |
Analyze (Item); |
| 3038 |
Resolve_State (Item); |
| 3039 |
|
| 3040 |
-- Find the entity of the item. If this is a renaming, climb the |
| 3041 |
-- renaming chain to reach the root object. Renamings of non- |
| 3042 |
-- entire objects do not yield an entity (Empty). |
| 3043 |
|
| 3044 |
Item_Id := Entity_Of (Item); |
| 3045 |
|
| 3046 |
if Present (Item_Id) then |
| 3047 |
|
| 3048 |
-- A global item may denote a formal parameter of an enclosing |
| 3049 |
-- subprogram (SPARK RM 6.1.4(6)). Do this check first to |
| 3050 |
-- provide a better error diagnostic. |
| 3051 |
|
| 3052 |
if Is_Formal (Item_Id) then |
| 3053 |
if Scope (Item_Id) = Spec_Id then |
| 3054 |
SPARK_Msg_NE |
| 3055 |
(Fix_Msg (Spec_Id, "global item cannot reference " |
| 3056 |
& "parameter of subprogram &"), Item, Spec_Id); |
| 3057 |
return; |
| 3058 |
end if; |
| 3059 |
|
| 3060 |
-- A global item may denote a concurrent type as long as it is |
| 3061 |
-- the current instance of an enclosing protected or task type |
| 3062 |
-- (SPARK RM 6.1.4). |
| 3063 |
|
| 3064 |
elsif Ekind (Item_Id) in E_Protected_Type | E_Task_Type then |
| 3065 |
if Is_CCT_Instance (Item_Id, Spec_Id) then |
| 3066 |
|
| 3067 |
-- Pragma [Refined_]Global associated with a protected |
| 3068 |
-- subprogram cannot mention the current instance of a |
| 3069 |
-- protected type because the instance behaves as a |
| 3070 |
-- formal parameter. |
| 3071 |
|
| 3072 |
if Ekind (Item_Id) = E_Protected_Type then |
| 3073 |
if Scope (Spec_Id) = Item_Id then |
| 3074 |
Error_Msg_Name_1 := Chars (Item_Id); |
| 3075 |
SPARK_Msg_NE |
| 3076 |
(Fix_Msg (Spec_Id, "global item of subprogram & " |
| 3077 |
& "cannot reference current instance of " |
| 3078 |
& "protected type %"), Item, Spec_Id); |
| 3079 |
return; |
| 3080 |
end if; |
| 3081 |
|
| 3082 |
-- Pragma [Refined_]Global associated with a task type |
| 3083 |
-- cannot mention the current instance of a task type |
| 3084 |
-- because the instance behaves as a formal parameter. |
| 3085 |
|
| 3086 |
else pragma Assert (Ekind (Item_Id) = E_Task_Type); |
| 3087 |
if Spec_Id = Item_Id then |
| 3088 |
Error_Msg_Name_1 := Chars (Item_Id); |
| 3089 |
SPARK_Msg_NE |
| 3090 |
(Fix_Msg (Spec_Id, "global item of subprogram & " |
| 3091 |
& "cannot reference current instance of task " |
| 3092 |
& "type %"), Item, Spec_Id); |
| 3093 |
return; |
| 3094 |
end if; |
| 3095 |
end if; |
| 3096 |
|
| 3097 |
-- Otherwise the global item denotes a subtype mark that is |
| 3098 |
-- not a current instance. |
| 3099 |
|
| 3100 |
else |
| 3101 |
SPARK_Msg_N |
| 3102 |
("invalid use of subtype mark in global list", Item); |
| 3103 |
return; |
| 3104 |
end if; |
| 3105 |
|
| 3106 |
-- A global item may denote the anonymous object created for a |
| 3107 |
-- single protected/task type as long as the current instance |
| 3108 |
-- is the same single type (SPARK RM 6.1.4). |
| 3109 |
|
| 3110 |
elsif Is_Single_Concurrent_Object (Item_Id) |
| 3111 |
and then Is_CCT_Instance (Etype (Item_Id), Spec_Id) |
| 3112 |
then |
| 3113 |
-- Pragma [Refined_]Global associated with a protected |
| 3114 |
-- subprogram cannot mention the current instance of a |
| 3115 |
-- protected type because the instance behaves as a formal |
| 3116 |
-- parameter. |
| 3117 |
|
| 3118 |
if Is_Single_Protected_Object (Item_Id) then |
| 3119 |
if Scope (Spec_Id) = Etype (Item_Id) then |
| 3120 |
Error_Msg_Name_1 := Chars (Item_Id); |
| 3121 |
SPARK_Msg_NE |
| 3122 |
(Fix_Msg (Spec_Id, "global item of subprogram & " |
| 3123 |
& "cannot reference current instance of protected " |
| 3124 |
& "type %"), Item, Spec_Id); |
| 3125 |
return; |
| 3126 |
end if; |
| 3127 |
|
| 3128 |
-- Pragma [Refined_]Global associated with a task type |
| 3129 |
-- cannot mention the current instance of a task type |
| 3130 |
-- because the instance behaves as a formal parameter. |
| 3131 |
|
| 3132 |
else pragma Assert (Is_Single_Task_Object (Item_Id)); |
| 3133 |
if Spec_Id = Item_Id then |
| 3134 |
Error_Msg_Name_1 := Chars (Item_Id); |
| 3135 |
SPARK_Msg_NE |
| 3136 |
(Fix_Msg (Spec_Id, "global item of subprogram & " |
| 3137 |
& "cannot reference current instance of task " |
| 3138 |
& "type %"), Item, Spec_Id); |
| 3139 |
return; |
| 3140 |
end if; |
| 3141 |
end if; |
| 3142 |
|
| 3143 |
-- A formal object may act as a global item inside a generic |
| 3144 |
|
| 3145 |
elsif Is_Formal_Object (Item_Id) then |
| 3146 |
null; |
| 3147 |
|
| 3148 |
elsif Ekind (Item_Id) in E_Constant | E_Variable |
| 3149 |
and then Present (Ultimate_Overlaid_Entity (Item_Id)) |
| 3150 |
then |
| 3151 |
SPARK_Msg_NE |
| 3152 |
("overlaying object & cannot appear in Global", |
| 3153 |
Item, Item_Id); |
| 3154 |
SPARK_Msg_NE |
| 3155 |
("\use the overlaid object & instead", |
| 3156 |
Item, Ultimate_Overlaid_Entity (Item_Id)); |
| 3157 |
return; |
| 3158 |
|
| 3159 |
-- The only legal references are those to abstract states, |
| 3160 |
-- objects and various kinds of constants (SPARK RM 6.1.4(4)). |
| 3161 |
|
| 3162 |
elsif Ekind (Item_Id) not in E_Abstract_State |
| 3163 |
| E_Constant |
| 3164 |
| E_Loop_Parameter |
| 3165 |
| E_Variable |
| 3166 |
then |
| 3167 |
SPARK_Msg_N |
| 3168 |
("global item must denote object, state or current " |
| 3169 |
& "instance of concurrent type", Item); |
| 3170 |
|
| 3171 |
if Is_Named_Number (Item_Id) then |
| 3172 |
SPARK_Msg_NE |
| 3173 |
("\named number & is not an object", Item, Item_Id); |
| 3174 |
end if; |
| 3175 |
|
| 3176 |
return; |
| 3177 |
end if; |
| 3178 |
|
| 3179 |
-- State related checks |
| 3180 |
|
| 3181 |
if Ekind (Item_Id) = E_Abstract_State then |
| 3182 |
|
| 3183 |
-- Package and subprogram bodies are instantiated |
| 3184 |
-- individually in a separate compiler pass. Due to this |
| 3185 |
-- mode of instantiation, the refinement of a state may |
| 3186 |
-- no longer be visible when a subprogram body contract |
| 3187 |
-- is instantiated. Since the generic template is legal, |
| 3188 |
-- do not perform this check in the instance to circumvent |
| 3189 |
-- this oddity. |
| 3190 |
|
| 3191 |
if In_Instance then |
| 3192 |
null; |
| 3193 |
|
| 3194 |
-- An abstract state with visible refinement cannot appear |
| 3195 |
-- in pragma [Refined_]Global as its place must be taken by |
| 3196 |
-- some of its constituents (SPARK RM 6.1.4(7)). |
| 3197 |
|
| 3198 |
elsif Has_Visible_Refinement (Item_Id) then |
| 3199 |
SPARK_Msg_NE |
| 3200 |
("cannot mention state & in global refinement", |
| 3201 |
Item, Item_Id); |
| 3202 |
SPARK_Msg_N ("\use its constituents instead", Item); |
| 3203 |
return; |
| 3204 |
|
| 3205 |
-- If the reference to the abstract state appears in an |
| 3206 |
-- enclosing package body that will eventually refine the |
| 3207 |
-- state, record the reference for future checks. |
| 3208 |
|
| 3209 |
else |
| 3210 |
Record_Possible_Body_Reference |
| 3211 |
(State_Id => Item_Id, |
| 3212 |
Ref => Item); |
| 3213 |
end if; |
| 3214 |
|
| 3215 |
-- Constant related checks |
| 3216 |
|
| 3217 |
elsif Ekind (Item_Id) = E_Constant then |
| 3218 |
|
| 3219 |
-- Constant is a read-only item, therefore it cannot act as |
| 3220 |
-- an output. |
| 3221 |
|
| 3222 |
if Global_Mode in Name_In_Out | Name_Output then |
| 3223 |
|
| 3224 |
-- Constant of an access-to-variable type is a read-write |
| 3225 |
-- item in procedures, generic procedures, protected |
| 3226 |
-- entries and tasks. |
| 3227 |
|
| 3228 |
if Is_Access_Variable (Etype (Item_Id)) |
| 3229 |
and then (Ekind (Spec_Id) in E_Entry |
| 3230 |
| E_Entry_Family |
| 3231 |
| E_Procedure |
| 3232 |
| E_Generic_Procedure |
| 3233 |
| E_Task_Type |
| 3234 |
or else Is_Single_Task_Object (Spec_Id) |
| 3235 |
or else |
| 3236 |
Is_Function_With_Side_Effects (Spec_Id)) |
| 3237 |
then |
| 3238 |
null; |
| 3239 |
else |
| 3240 |
SPARK_Msg_NE |
| 3241 |
("constant & cannot act as output", Item, Item_Id); |
| 3242 |
return; |
| 3243 |
end if; |
| 3244 |
end if; |
| 3245 |
|
| 3246 |
-- Loop parameter related checks |
| 3247 |
|
| 3248 |
elsif Ekind (Item_Id) = E_Loop_Parameter then |
| 3249 |
|
| 3250 |
-- A loop parameter is a read-only item, therefore it cannot |
| 3251 |
-- act as an output. |
| 3252 |
|
| 3253 |
if Global_Mode in Name_In_Out | Name_Output then |
| 3254 |
SPARK_Msg_NE |
| 3255 |
("loop parameter & cannot act as output", |
| 3256 |
Item, Item_Id); |
| 3257 |
return; |
| 3258 |
end if; |
| 3259 |
end if; |
| 3260 |
|
| 3261 |
-- When the item renames an entire object, replace the item |
| 3262 |
-- with a reference to the object. |
| 3263 |
|
| 3264 |
if Entity (Item) /= Item_Id then |
| 3265 |
Rewrite (Item, New_Occurrence_Of (Item_Id, Sloc (Item))); |
| 3266 |
Analyze (Item); |
| 3267 |
end if; |
| 3268 |
|
| 3269 |
-- Some form of illegal construct masquerading as a name |
| 3270 |
-- (SPARK RM 6.1.4(4)). |
| 3271 |
|
| 3272 |
else |
| 3273 |
Error_Msg_N |
| 3274 |
("global item must denote object, state or current instance " |
| 3275 |
& "of concurrent type", Item); |
| 3276 |
return; |
| 3277 |
end if; |
| 3278 |
|
| 3279 |
-- Verify that an output does not appear as an input in an |
| 3280 |
-- enclosing subprogram. |
| 3281 |
|
| 3282 |
if Global_Mode in Name_In_Out | Name_Output then |
| 3283 |
Check_Mode_Restriction_In_Enclosing_Context (Item, Item_Id); |
| 3284 |
end if; |
| 3285 |
|
| 3286 |
-- The same entity might be referenced through various way. |
| 3287 |
-- Check the entity of the item rather than the item itself |
| 3288 |
-- (SPARK RM 6.1.4(10)). |
| 3289 |
|
| 3290 |
if Contains (Seen, Item_Id) then |
| 3291 |
SPARK_Msg_N ("duplicate global item", Item); |
| 3292 |
|
| 3293 |
-- Add the entity of the current item to the list of processed |
| 3294 |
-- items. |
| 3295 |
|
| 3296 |
else |
| 3297 |
Append_New_Elmt (Item_Id, Seen); |
| 3298 |
|
| 3299 |
if Ekind (Item_Id) = E_Abstract_State then |
| 3300 |
Append_New_Elmt (Item_Id, States_Seen); |
| 3301 |
|
| 3302 |
-- The variable may eventually become a constituent of a single |
| 3303 |
-- protected/task type. Record the reference now and verify its |
| 3304 |
-- legality when analyzing the contract of the variable |
| 3305 |
-- (SPARK RM 9.3). |
| 3306 |
|
| 3307 |
elsif Ekind (Item_Id) = E_Variable then |
| 3308 |
Record_Possible_Part_Of_Reference |
| 3309 |
(Var_Id => Item_Id, |
| 3310 |
Ref => Item); |
| 3311 |
end if; |
| 3312 |
|
| 3313 |
if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable |
| 3314 |
and then Present (Encapsulating_State (Item_Id)) |
| 3315 |
then |
| 3316 |
Append_New_Elmt (Item_Id, Constits_Seen); |
| 3317 |
end if; |
| 3318 |
end if; |
| 3319 |
end Analyze_Global_Item; |
| 3320 |
|
| 3321 |
-------------------------- |
| 3322 |
-- Check_Duplicate_Mode -- |
| 3323 |
-------------------------- |
| 3324 |
|
| 3325 |
procedure Check_Duplicate_Mode |
| 3326 |
(Mode : Node_Id; |
| 3327 |
Status : in out Boolean) |
| 3328 |
is |
| 3329 |
begin |
| 3330 |
if Status then |
| 3331 |
SPARK_Msg_N ("duplicate global mode", Mode); |
| 3332 |
end if; |
| 3333 |
|
| 3334 |
Status := True; |
| 3335 |
end Check_Duplicate_Mode; |
| 3336 |
|
| 3337 |
------------------------------------------------- |
| 3338 |
-- Check_Mode_Restriction_In_Enclosing_Context -- |
| 3339 |
------------------------------------------------- |
| 3340 |
|
| 3341 |
procedure Check_Mode_Restriction_In_Enclosing_Context |
| 3342 |
(Item : Node_Id; |
| 3343 |
Item_Id : Entity_Id) |
| 3344 |
is |
| 3345 |
Context : Entity_Id; |
| 3346 |
Dummy : Boolean; |
| 3347 |
Item_View : Entity_Id; |
| 3348 |
Inputs : Elist_Id := No_Elist; |
| 3349 |
Outputs : Elist_Id := No_Elist; |
| 3350 |
|
| 3351 |
begin |
| 3352 |
-- Traverse the scope stack looking for enclosing subprograms or |
| 3353 |
-- tasks subject to pragma [Refined_]Global. |
| 3354 |
|
| 3355 |
Context := Scope (Subp_Id); |
| 3356 |
Check_Context : |
| 3357 |
while Present (Context) and then Context /= Standard_Standard loop |
| 3358 |
|
| 3359 |
-- For a single task type, retrieve the corresponding object to |
| 3360 |
-- which pragma [Refined_]Global is attached. |
| 3361 |
|
| 3362 |
if Ekind (Context) = E_Task_Type |
| 3363 |
and then Is_Single_Concurrent_Type (Context) |
| 3364 |
then |
| 3365 |
Context := Anonymous_Object (Context); |
| 3366 |
end if; |
| 3367 |
|
| 3368 |
if Is_Subprogram_Or_Entry (Context) |
| 3369 |
or else Ekind (Context) = E_Task_Type |
| 3370 |
or else Is_Single_Task_Object (Context) |
| 3371 |
then |
| 3372 |
Collect_Subprogram_Inputs_Outputs |
| 3373 |
(Subp_Id => Context, |
| 3374 |
Subp_Inputs => Inputs, |
| 3375 |
Subp_Outputs => Outputs, |
| 3376 |
Global_Seen => Dummy); |
| 3377 |
|
| 3378 |
-- If the item is a constituent, we must check not just the |
| 3379 |
-- item itself, but also its encapsulating abstract states. |
| 3380 |
|
| 3381 |
Item_View := Item_Id; |
| 3382 |
|
| 3383 |
Check_View : loop |
| 3384 |
-- The item is classified as In_Out or Output but appears |
| 3385 |
-- as an Input or a formal parameter of mode IN in |
| 3386 |
-- an enclosing subprogram or task unit (SPARK RM |
| 3387 |
-- 6.1.4(13)). |
| 3388 |
|
| 3389 |
if Appears_In (Inputs, Item_View) |
| 3390 |
and then not Appears_In (Outputs, Item_View) |
| 3391 |
then |
| 3392 |
if Item_View = Item_Id then |
| 3393 |
SPARK_Msg_NE |
| 3394 |
("global item & " & |
| 3395 |
"cannot have mode In_Out or Output", |
| 3396 |
Item, Item_Id); |
| 3397 |
else |
| 3398 |
Error_Msg_Node_2 := Item_View; |
| 3399 |
SPARK_Msg_NE |
| 3400 |
("global constituent & of & " & |
| 3401 |
"cannot have mode In_Out or Output", |
| 3402 |
Item, Item_Id); |
| 3403 |
end if; |
| 3404 |
|
| 3405 |
if Is_Subprogram_Or_Entry (Context) then |
| 3406 |
SPARK_Msg_NE |
| 3407 |
(Fix_Msg (Subp_Id, "\item already appears " |
| 3408 |
& "as input of subprogram &"), Item, Context); |
| 3409 |
else |
| 3410 |
SPARK_Msg_NE |
| 3411 |
(Fix_Msg (Subp_Id, "\item already appears " |
| 3412 |
& "as input of task &"), Item, Context); |
| 3413 |
end if; |
| 3414 |
|
| 3415 |
-- Stop the traversal once an error has been detected |
| 3416 |
|
| 3417 |
exit Check_Context; |
| 3418 |
end if; |
| 3419 |
|
| 3420 |
if Ekind (Item_View) in E_Abstract_State |
| 3421 |
| E_Constant |
| 3422 |
| E_Variable |
| 3423 |
then |
| 3424 |
Item_View := Encapsulating_State (Item_View); |
| 3425 |
|
| 3426 |
exit Check_View when No (Item_View); |
| 3427 |
else |
| 3428 |
exit Check_View; |
| 3429 |
end if; |
| 3430 |
end loop Check_View; |
| 3431 |
|
| 3432 |
end if; |
| 3433 |
|
| 3434 |
Context := Scope (Context); |
| 3435 |
end loop Check_Context; |
| 3436 |
end Check_Mode_Restriction_In_Enclosing_Context; |
| 3437 |
|
| 3438 |
---------------------------------------- |
| 3439 |
-- Check_Mode_Restriction_In_Function -- |
| 3440 |
---------------------------------------- |
| 3441 |
|
| 3442 |
procedure Check_Mode_Restriction_In_Function (Mode : Node_Id) is |
| 3443 |
begin |
| 3444 |
if Ekind (Spec_Id) in E_Function | E_Generic_Function |
| 3445 |
and then not Is_Function_With_Side_Effects (Spec_Id) |
| 3446 |
then |
| 3447 |
Error_Msg_Code := GEC_Output_In_Function_Global_Or_Depends; |
| 3448 |
SPARK_Msg_N |
| 3449 |
("global mode & is not applicable to function '[[]']", Mode); |
| 3450 |
end if; |
| 3451 |
end Check_Mode_Restriction_In_Function; |
| 3452 |
|
| 3453 |
-- Local variables |
| 3454 |
|
| 3455 |
Assoc : Node_Id; |
| 3456 |
Item : Node_Id; |
| 3457 |
Mode : Node_Id; |
| 3458 |
|
| 3459 |
-- Start of processing for Analyze_Global_List |
| 3460 |
|
| 3461 |
begin |
| 3462 |
if Nkind (List) = N_Null then |
| 3463 |
Set_Analyzed (List); |
| 3464 |
|
| 3465 |
-- Single global item declaration |
| 3466 |
|
| 3467 |
elsif Nkind (List) in N_Expanded_Name |
| 3468 |
| N_Identifier |
| 3469 |
| N_Selected_Component |
| 3470 |
then |
| 3471 |
Analyze_Global_Item (List, Global_Mode); |
| 3472 |
|
| 3473 |
-- Simple global list or moded global list declaration |
| 3474 |
|
| 3475 |
elsif Nkind (List) = N_Aggregate then |
| 3476 |
Set_Analyzed (List); |
| 3477 |
|
| 3478 |
-- The declaration of a simple global list appear as a collection |
| 3479 |
-- of expressions. |
| 3480 |
|
| 3481 |
if Present (Expressions (List)) then |
| 3482 |
if Present (Component_Associations (List)) then |
| 3483 |
SPARK_Msg_N |
| 3484 |
("cannot mix moded and non-moded global lists", List); |
| 3485 |
end if; |
| 3486 |
|
| 3487 |
Item := First (Expressions (List)); |
| 3488 |
while Present (Item) loop |
| 3489 |
Analyze_Global_Item (Item, Global_Mode); |
| 3490 |
Next (Item); |
| 3491 |
end loop; |
| 3492 |
|
| 3493 |
-- The declaration of a moded global list appears as a collection |
| 3494 |
-- of component associations where individual choices denote |
| 3495 |
-- modes. |
| 3496 |
|
| 3497 |
elsif Present (Component_Associations (List)) then |
| 3498 |
if Present (Expressions (List)) then |
| 3499 |
SPARK_Msg_N |
| 3500 |
("cannot mix moded and non-moded global lists", List); |
| 3501 |
end if; |
| 3502 |
|
| 3503 |
Assoc := First (Component_Associations (List)); |
| 3504 |
while Present (Assoc) loop |
| 3505 |
Mode := First (Choices (Assoc)); |
| 3506 |
|
| 3507 |
if Nkind (Mode) = N_Identifier then |
| 3508 |
if Chars (Mode) = Name_In_Out then |
| 3509 |
Check_Duplicate_Mode (Mode, In_Out_Seen); |
| 3510 |
Check_Mode_Restriction_In_Function (Mode); |
| 3511 |
|
| 3512 |
elsif Chars (Mode) = Name_Input then |
| 3513 |
Check_Duplicate_Mode (Mode, Input_Seen); |
| 3514 |
|
| 3515 |
elsif Chars (Mode) = Name_Output then |
| 3516 |
Check_Duplicate_Mode (Mode, Output_Seen); |
| 3517 |
Check_Mode_Restriction_In_Function (Mode); |
| 3518 |
|
| 3519 |
elsif Chars (Mode) = Name_Proof_In then |
| 3520 |
Check_Duplicate_Mode (Mode, Proof_Seen); |
| 3521 |
|
| 3522 |
else |
| 3523 |
SPARK_Msg_N ("invalid mode selector", Mode); |
| 3524 |
end if; |
| 3525 |
|
| 3526 |
else |
| 3527 |
SPARK_Msg_N ("invalid mode selector", Mode); |
| 3528 |
end if; |
| 3529 |
|
| 3530 |
-- Items in a moded list appear as a collection of |
| 3531 |
-- expressions. Reuse the existing machinery to analyze |
| 3532 |
-- them. |
| 3533 |
|
| 3534 |
Analyze_Global_List |
| 3535 |
(List => Expression (Assoc), |
| 3536 |
Global_Mode => Chars (Mode)); |
| 3537 |
|
| 3538 |
Next (Assoc); |
| 3539 |
end loop; |
| 3540 |
|
| 3541 |
-- Invalid tree |
| 3542 |
|
| 3543 |
else |
| 3544 |
raise Program_Error; |
| 3545 |
end if; |
| 3546 |
|
| 3547 |
-- Any other attempt to declare a global item is illegal. This is a |
| 3548 |
-- syntax error, always report. |
| 3549 |
|
| 3550 |
else |
| 3551 |
Error_Msg_N ("malformed global list", List); |
| 3552 |
end if; |
| 3553 |
end Analyze_Global_List; |
| 3554 |
|
| 3555 |
-- Local variables |
| 3556 |
|
| 3557 |
Items : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
| 3558 |
|
| 3559 |
Restore_Scope : Boolean := False; |
| 3560 |
|
| 3561 |
-- Start of processing for Analyze_Global_In_Decl_Part |
| 3562 |
|
| 3563 |
begin |
| 3564 |
-- Do not analyze the pragma multiple times |
| 3565 |
|
| 3566 |
if Is_Analyzed_Pragma (N) then |
| 3567 |
return; |
| 3568 |
end if; |
| 3569 |
|
| 3570 |
-- There is nothing to be done for a null global list |
| 3571 |
|
| 3572 |
if Nkind (Items) = N_Null then |
| 3573 |
Set_Analyzed (Items); |
| 3574 |
|
| 3575 |
-- Analyze the various forms of global lists and items. Note that some |
| 3576 |
-- of these may be malformed in which case the analysis emits error |
| 3577 |
-- messages. |
| 3578 |
|
| 3579 |
else |
| 3580 |
-- When pragma [Refined_]Global appears on a single concurrent type, |
| 3581 |
-- it is relocated to the anonymous object. |
| 3582 |
|
| 3583 |
if Is_Single_Concurrent_Object (Spec_Id) then |
| 3584 |
null; |
| 3585 |
|
| 3586 |
-- Ensure that the formal parameters are visible when processing an |
| 3587 |
-- item. This falls out of the general rule of aspects pertaining to |
| 3588 |
-- subprogram declarations. |
| 3589 |
|
| 3590 |
elsif not In_Open_Scopes (Spec_Id) then |
| 3591 |
Restore_Scope := True; |
| 3592 |
Push_Scope (Spec_Id); |
| 3593 |
|
| 3594 |
if Ekind (Spec_Id) = E_Task_Type then |
| 3595 |
|
| 3596 |
-- Task discriminants cannot appear in the [Refined_]Global |
| 3597 |
-- contract, but must be present for the analysis so that we |
| 3598 |
-- can reject them with an informative error message. |
| 3599 |
|
| 3600 |
if Has_Discriminants (Spec_Id) then |
| 3601 |
Install_Discriminants (Spec_Id); |
| 3602 |
end if; |
| 3603 |
|
| 3604 |
elsif Is_Generic_Subprogram (Spec_Id) then |
| 3605 |
Install_Generic_Formals (Spec_Id); |
| 3606 |
|
| 3607 |
else |
| 3608 |
Install_Formals (Spec_Id); |
| 3609 |
end if; |
| 3610 |
end if; |
| 3611 |
|
| 3612 |
Analyze_Global_List (Items); |
| 3613 |
|
| 3614 |
if Restore_Scope then |
| 3615 |
End_Scope; |
| 3616 |
end if; |
| 3617 |
end if; |
| 3618 |
|
| 3619 |
-- Ensure that a state and a corresponding constituent do not appear |
| 3620 |
-- together in pragma [Refined_]Global. |
| 3621 |
|
| 3622 |
Check_State_And_Constituent_Use |
| 3623 |
(States => States_Seen, |
| 3624 |
Constits => Constits_Seen, |
| 3625 |
Context => N); |
| 3626 |
|
| 3627 |
Set_Is_Analyzed_Pragma (N); |
| 3628 |
end Analyze_Global_In_Decl_Part; |
| 3629 |
|
| 3630 |
--------------------------------- |
| 3631 |
-- Analyze_If_Present_Internal -- |
| 3632 |
--------------------------------- |
| 3633 |
|
| 3634 |
procedure Analyze_If_Present_Internal |
| 3635 |
(N : Node_Id; |
| 3636 |
Id : Pragma_Id; |
| 3637 |
Included : Boolean) |
| 3638 |
is |
| 3639 |
Stmt : Node_Id; |
| 3640 |
|
| 3641 |
begin |
| 3642 |
pragma Assert (Is_List_Member (N)); |
| 3643 |
|
| 3644 |
-- Inspect the declarations or statements following pragma N looking |
| 3645 |
-- for another pragma whose Id matches the caller's request. If it is |
| 3646 |
-- available, analyze it. |
| 3647 |
|
| 3648 |
if Included then |
| 3649 |
Stmt := N; |
| 3650 |
else |
| 3651 |
Stmt := Next (N); |
| 3652 |
end if; |
| 3653 |
|
| 3654 |
while Present (Stmt) loop |
| 3655 |
if Nkind (Stmt) = N_Pragma and then Get_Pragma_Id (Stmt) = Id then |
| 3656 |
Analyze_Pragma (Stmt); |
| 3657 |
exit; |
| 3658 |
|
| 3659 |
-- The first source declaration or statement immediately following |
| 3660 |
-- N ends the region where a pragma may appear. |
| 3661 |
|
| 3662 |
elsif Comes_From_Source (Stmt) then |
| 3663 |
exit; |
| 3664 |
end if; |
| 3665 |
|
| 3666 |
Next (Stmt); |
| 3667 |
end loop; |
| 3668 |
end Analyze_If_Present_Internal; |
| 3669 |
|
| 3670 |
-------------------------------------------- |
| 3671 |
-- Analyze_Initial_Condition_In_Decl_Part -- |
| 3672 |
-------------------------------------------- |
| 3673 |
|
| 3674 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 3675 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 3676 |
-- Ghost mode. |
| 3677 |
|
| 3678 |
procedure Analyze_Initial_Condition_In_Decl_Part (N : Node_Id) is |
| 3679 |
Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N); |
| 3680 |
Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl); |
| 3681 |
Expr : constant Node_Id := Expression (Get_Argument (N, Pack_Id)); |
| 3682 |
|
| 3683 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 3684 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 3685 |
-- Save the Ghost-related attributes to restore on exit |
| 3686 |
|
| 3687 |
begin |
| 3688 |
-- Do not analyze the pragma multiple times |
| 3689 |
|
| 3690 |
if Is_Analyzed_Pragma (N) then |
| 3691 |
return; |
| 3692 |
end if; |
| 3693 |
|
| 3694 |
-- Set the Ghost mode in effect from the pragma. Due to the delayed |
| 3695 |
-- analysis of the pragma, the Ghost mode at point of declaration and |
| 3696 |
-- point of analysis may not necessarily be the same. Use the mode in |
| 3697 |
-- effect at the point of declaration. |
| 3698 |
|
| 3699 |
Set_Ghost_Mode (N); |
| 3700 |
|
| 3701 |
-- The expression is preanalyzed because it has not been moved to its |
| 3702 |
-- final place yet. A direct analysis may generate side effects and this |
| 3703 |
-- is not desired at this point. |
| 3704 |
|
| 3705 |
Preanalyze_And_Resolve (Expr, Standard_Boolean); |
| 3706 |
Set_Is_Analyzed_Pragma (N); |
| 3707 |
|
| 3708 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 3709 |
end Analyze_Initial_Condition_In_Decl_Part; |
| 3710 |
|
| 3711 |
-------------------------------------- |
| 3712 |
-- Analyze_Initializes_In_Decl_Part -- |
| 3713 |
-------------------------------------- |
| 3714 |
|
| 3715 |
procedure Analyze_Initializes_In_Decl_Part (N : Node_Id) is |
| 3716 |
Pack_Decl : constant Node_Id := Find_Related_Package_Or_Body (N); |
| 3717 |
Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl); |
| 3718 |
|
| 3719 |
Constits_Seen : Elist_Id := No_Elist; |
| 3720 |
-- A list containing the entities of all constituents processed so far. |
| 3721 |
-- It aids in detecting illegal usage of a state and a corresponding |
| 3722 |
-- constituent in pragma Initializes. |
| 3723 |
|
| 3724 |
Items_Seen : Elist_Id := No_Elist; |
| 3725 |
-- A list of all initialization items processed so far. This list is |
| 3726 |
-- used to detect duplicate items. |
| 3727 |
|
| 3728 |
States_And_Objs : Elist_Id := No_Elist; |
| 3729 |
-- A list of all abstract states and objects declared in the visible |
| 3730 |
-- declarations of the related package. This list is used to detect the |
| 3731 |
-- legality of initialization items. |
| 3732 |
|
| 3733 |
States_Seen : Elist_Id := No_Elist; |
| 3734 |
-- A list containing the entities of all states processed so far. It |
| 3735 |
-- helps in detecting illegal usage of a state and a corresponding |
| 3736 |
-- constituent in pragma Initializes. |
| 3737 |
|
| 3738 |
procedure Analyze_Initialization_Item (Item : Node_Id); |
| 3739 |
-- Verify the legality of a single initialization item |
| 3740 |
|
| 3741 |
procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id); |
| 3742 |
-- Verify the legality of a single initialization item followed by a |
| 3743 |
-- list of input items. |
| 3744 |
|
| 3745 |
procedure Collect_States_And_Objects (Pack_Decl : Node_Id); |
| 3746 |
-- Inspect the visible declarations of the related package and gather |
| 3747 |
-- the entities of all abstract states and objects in States_And_Objs. |
| 3748 |
|
| 3749 |
--------------------------------- |
| 3750 |
-- Analyze_Initialization_Item -- |
| 3751 |
--------------------------------- |
| 3752 |
|
| 3753 |
procedure Analyze_Initialization_Item (Item : Node_Id) is |
| 3754 |
Item_Id : Entity_Id; |
| 3755 |
|
| 3756 |
begin |
| 3757 |
Analyze (Item); |
| 3758 |
Resolve_State (Item); |
| 3759 |
|
| 3760 |
if Is_Entity_Name (Item) then |
| 3761 |
Item_Id := Entity_Of (Item); |
| 3762 |
|
| 3763 |
if Present (Item_Id) |
| 3764 |
and then Ekind (Item_Id) in |
| 3765 |
E_Abstract_State | E_Constant | E_Variable |
| 3766 |
then |
| 3767 |
-- When the initialization item is undefined, it appears as |
| 3768 |
-- Any_Id. Do not continue with the analysis of the item. |
| 3769 |
|
| 3770 |
if Item_Id = Any_Id then |
| 3771 |
null; |
| 3772 |
|
| 3773 |
elsif Ekind (Item_Id) in E_Constant | E_Variable |
| 3774 |
and then Present (Ultimate_Overlaid_Entity (Item_Id)) |
| 3775 |
then |
| 3776 |
SPARK_Msg_NE |
| 3777 |
("overlaying object & cannot appear in Initializes", |
| 3778 |
Item, Item_Id); |
| 3779 |
SPARK_Msg_NE |
| 3780 |
("\use the overlaid object & instead", |
| 3781 |
Item, Ultimate_Overlaid_Entity (Item_Id)); |
| 3782 |
|
| 3783 |
-- The state or variable must be declared in the visible |
| 3784 |
-- declarations of the package (SPARK RM 7.1.5(7)). |
| 3785 |
|
| 3786 |
elsif not Contains (States_And_Objs, Item_Id) then |
| 3787 |
Error_Msg_Name_1 := Chars (Pack_Id); |
| 3788 |
SPARK_Msg_NE |
| 3789 |
("initialization item & must appear in the visible " |
| 3790 |
& "declarations of package %", Item, Item_Id); |
| 3791 |
|
| 3792 |
-- Detect a duplicate use of the same initialization item |
| 3793 |
-- (SPARK RM 7.1.5(5)). |
| 3794 |
|
| 3795 |
elsif Contains (Items_Seen, Item_Id) then |
| 3796 |
SPARK_Msg_N ("duplicate initialization item", Item); |
| 3797 |
|
| 3798 |
-- The item is legal, add it to the list of processed states |
| 3799 |
-- and variables. |
| 3800 |
|
| 3801 |
else |
| 3802 |
Append_New_Elmt (Item_Id, Items_Seen); |
| 3803 |
|
| 3804 |
if Ekind (Item_Id) = E_Abstract_State then |
| 3805 |
Append_New_Elmt (Item_Id, States_Seen); |
| 3806 |
end if; |
| 3807 |
|
| 3808 |
if Present (Encapsulating_State (Item_Id)) then |
| 3809 |
Append_New_Elmt (Item_Id, Constits_Seen); |
| 3810 |
end if; |
| 3811 |
end if; |
| 3812 |
|
| 3813 |
-- The item references something that is not a state or object |
| 3814 |
-- (SPARK RM 7.1.5(3)). |
| 3815 |
|
| 3816 |
else |
| 3817 |
SPARK_Msg_N |
| 3818 |
("initialization item must denote object or state", Item); |
| 3819 |
end if; |
| 3820 |
|
| 3821 |
-- Some form of illegal construct masquerading as a name |
| 3822 |
-- (SPARK RM 7.1.5(3)). This is a syntax error, always report. |
| 3823 |
|
| 3824 |
else |
| 3825 |
Error_Msg_N |
| 3826 |
("initialization item must denote object or state", Item); |
| 3827 |
end if; |
| 3828 |
end Analyze_Initialization_Item; |
| 3829 |
|
| 3830 |
--------------------------------------------- |
| 3831 |
-- Analyze_Initialization_Item_With_Inputs -- |
| 3832 |
--------------------------------------------- |
| 3833 |
|
| 3834 |
procedure Analyze_Initialization_Item_With_Inputs (Item : Node_Id) is |
| 3835 |
Inputs_Seen : Elist_Id := No_Elist; |
| 3836 |
-- A list of all inputs processed so far. This list is used to detect |
| 3837 |
-- duplicate uses of an input. |
| 3838 |
|
| 3839 |
Non_Null_Seen : Boolean := False; |
| 3840 |
Null_Seen : Boolean := False; |
| 3841 |
-- Flags used to check the legality of an input list |
| 3842 |
|
| 3843 |
procedure Analyze_Input_Item (Input : Node_Id); |
| 3844 |
-- Verify the legality of a single input item |
| 3845 |
|
| 3846 |
------------------------ |
| 3847 |
-- Analyze_Input_Item -- |
| 3848 |
------------------------ |
| 3849 |
|
| 3850 |
procedure Analyze_Input_Item (Input : Node_Id) is |
| 3851 |
Input_Id : Entity_Id; |
| 3852 |
|
| 3853 |
begin |
| 3854 |
-- Null input list |
| 3855 |
|
| 3856 |
if Nkind (Input) = N_Null then |
| 3857 |
if Null_Seen then |
| 3858 |
SPARK_Msg_N |
| 3859 |
("multiple null initializations not allowed", Item); |
| 3860 |
|
| 3861 |
elsif Non_Null_Seen then |
| 3862 |
SPARK_Msg_N |
| 3863 |
("cannot mix null and non-null initialization item", Item); |
| 3864 |
else |
| 3865 |
Null_Seen := True; |
| 3866 |
end if; |
| 3867 |
|
| 3868 |
-- Input item |
| 3869 |
|
| 3870 |
else |
| 3871 |
Non_Null_Seen := True; |
| 3872 |
|
| 3873 |
if Null_Seen then |
| 3874 |
SPARK_Msg_N |
| 3875 |
("cannot mix null and non-null initialization item", Item); |
| 3876 |
end if; |
| 3877 |
|
| 3878 |
Analyze (Input); |
| 3879 |
Resolve_State (Input); |
| 3880 |
|
| 3881 |
if Is_Entity_Name (Input) then |
| 3882 |
Input_Id := Entity_Of (Input); |
| 3883 |
|
| 3884 |
if Present (Input_Id) |
| 3885 |
and then Ekind (Input_Id) in E_Abstract_State |
| 3886 |
| E_Constant |
| 3887 |
| E_Generic_In_Out_Parameter |
| 3888 |
| E_Generic_In_Parameter |
| 3889 |
| E_In_Parameter |
| 3890 |
| E_In_Out_Parameter |
| 3891 |
| E_Out_Parameter |
| 3892 |
| E_Protected_Type |
| 3893 |
| E_Task_Type |
| 3894 |
| E_Variable |
| 3895 |
then |
| 3896 |
-- The input cannot denote states or objects declared |
| 3897 |
-- within the related package (SPARK RM 7.1.5(4)). |
| 3898 |
|
| 3899 |
if Within_Scope (Input_Id, Current_Scope) then |
| 3900 |
|
| 3901 |
-- Do not consider generic formal parameters or their |
| 3902 |
-- respective mappings to generic formals. Even though |
| 3903 |
-- the formals appear within the scope of the package, |
| 3904 |
-- it is allowed for an initialization item to depend |
| 3905 |
-- on an input item. |
| 3906 |
|
| 3907 |
if Is_Formal_Object (Input_Id) then |
| 3908 |
null; |
| 3909 |
|
| 3910 |
elsif Ekind (Input_Id) in E_Constant | E_Variable |
| 3911 |
and then Present (Corresponding_Generic_Association |
| 3912 |
(Declaration_Node (Input_Id))) |
| 3913 |
then |
| 3914 |
null; |
| 3915 |
|
| 3916 |
else |
| 3917 |
Error_Msg_Name_1 := Chars (Pack_Id); |
| 3918 |
SPARK_Msg_NE |
| 3919 |
("input item & cannot denote a visible object or " |
| 3920 |
& "state of package %", Input, Input_Id); |
| 3921 |
return; |
| 3922 |
end if; |
| 3923 |
end if; |
| 3924 |
|
| 3925 |
if Ekind (Input_Id) in E_Constant | E_Variable |
| 3926 |
and then Present (Ultimate_Overlaid_Entity (Input_Id)) |
| 3927 |
then |
| 3928 |
SPARK_Msg_NE |
| 3929 |
("overlaying object & cannot appear in Initializes", |
| 3930 |
Input, Input_Id); |
| 3931 |
SPARK_Msg_NE |
| 3932 |
("\use the overlaid object & instead", |
| 3933 |
Input, Ultimate_Overlaid_Entity (Input_Id)); |
| 3934 |
return; |
| 3935 |
end if; |
| 3936 |
|
| 3937 |
-- Detect a duplicate use of the same input item |
| 3938 |
-- (SPARK RM 7.1.5(5)). |
| 3939 |
|
| 3940 |
if Contains (Inputs_Seen, Input_Id) then |
| 3941 |
SPARK_Msg_N ("duplicate input item", Input); |
| 3942 |
return; |
| 3943 |
end if; |
| 3944 |
|
| 3945 |
-- At this point it is known that the input is legal. Add |
| 3946 |
-- it to the list of processed inputs. |
| 3947 |
|
| 3948 |
Append_New_Elmt (Input_Id, Inputs_Seen); |
| 3949 |
|
| 3950 |
if Ekind (Input_Id) = E_Abstract_State then |
| 3951 |
Append_New_Elmt (Input_Id, States_Seen); |
| 3952 |
end if; |
| 3953 |
|
| 3954 |
if Ekind (Input_Id) in E_Abstract_State |
| 3955 |
| E_Constant |
| 3956 |
| E_Variable |
| 3957 |
and then Present (Encapsulating_State (Input_Id)) |
| 3958 |
then |
| 3959 |
Append_New_Elmt (Input_Id, Constits_Seen); |
| 3960 |
end if; |
| 3961 |
|
| 3962 |
-- The input references something that is not a state or an |
| 3963 |
-- object (SPARK RM 7.1.5(3)). |
| 3964 |
|
| 3965 |
else |
| 3966 |
SPARK_Msg_N |
| 3967 |
("input item must denote object or state", Input); |
| 3968 |
end if; |
| 3969 |
|
| 3970 |
-- Some form of illegal construct masquerading as a name |
| 3971 |
-- (SPARK RM 7.1.5(3)). This is a syntax error, always report. |
| 3972 |
|
| 3973 |
else |
| 3974 |
Error_Msg_N |
| 3975 |
("input item must denote object or state", Input); |
| 3976 |
end if; |
| 3977 |
end if; |
| 3978 |
end Analyze_Input_Item; |
| 3979 |
|
| 3980 |
-- Local variables |
| 3981 |
|
| 3982 |
Inputs : constant Node_Id := Expression (Item); |
| 3983 |
Elmt : Node_Id; |
| 3984 |
Input : Node_Id; |
| 3985 |
|
| 3986 |
Name_Seen : Boolean := False; |
| 3987 |
-- A flag used to detect multiple item names |
| 3988 |
|
| 3989 |
-- Start of processing for Analyze_Initialization_Item_With_Inputs |
| 3990 |
|
| 3991 |
begin |
| 3992 |
-- Inspect the name of an item with inputs |
| 3993 |
|
| 3994 |
Elmt := First (Choices (Item)); |
| 3995 |
while Present (Elmt) loop |
| 3996 |
if Name_Seen then |
| 3997 |
SPARK_Msg_N ("only one item allowed in initialization", Elmt); |
| 3998 |
else |
| 3999 |
Name_Seen := True; |
| 4000 |
Analyze_Initialization_Item (Elmt); |
| 4001 |
end if; |
| 4002 |
|
| 4003 |
Next (Elmt); |
| 4004 |
end loop; |
| 4005 |
|
| 4006 |
-- Multiple input items appear as an aggregate |
| 4007 |
|
| 4008 |
if Nkind (Inputs) = N_Aggregate then |
| 4009 |
if Present (Expressions (Inputs)) then |
| 4010 |
Input := First (Expressions (Inputs)); |
| 4011 |
while Present (Input) loop |
| 4012 |
Analyze_Input_Item (Input); |
| 4013 |
Next (Input); |
| 4014 |
end loop; |
| 4015 |
end if; |
| 4016 |
|
| 4017 |
if Present (Component_Associations (Inputs)) then |
| 4018 |
SPARK_Msg_N |
| 4019 |
("inputs must appear in named association form", Inputs); |
| 4020 |
end if; |
| 4021 |
|
| 4022 |
-- Single input item |
| 4023 |
|
| 4024 |
else |
| 4025 |
Analyze_Input_Item (Inputs); |
| 4026 |
end if; |
| 4027 |
end Analyze_Initialization_Item_With_Inputs; |
| 4028 |
|
| 4029 |
-------------------------------- |
| 4030 |
-- Collect_States_And_Objects -- |
| 4031 |
-------------------------------- |
| 4032 |
|
| 4033 |
procedure Collect_States_And_Objects (Pack_Decl : Node_Id) is |
| 4034 |
Pack_Spec : constant Node_Id := Specification (Pack_Decl); |
| 4035 |
Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl); |
| 4036 |
Decl : Node_Id; |
| 4037 |
State_Elmt : Elmt_Id; |
| 4038 |
|
| 4039 |
begin |
| 4040 |
-- Collect the abstract states defined in the package (if any) |
| 4041 |
|
| 4042 |
if Has_Non_Null_Abstract_State (Pack_Id) then |
| 4043 |
State_Elmt := First_Elmt (Abstract_States (Pack_Id)); |
| 4044 |
while Present (State_Elmt) loop |
| 4045 |
Append_New_Elmt (Node (State_Elmt), States_And_Objs); |
| 4046 |
Next_Elmt (State_Elmt); |
| 4047 |
end loop; |
| 4048 |
end if; |
| 4049 |
|
| 4050 |
-- Collect all objects that appear in the visible declarations of the |
| 4051 |
-- related package. |
| 4052 |
|
| 4053 |
Decl := First (Visible_Declarations (Pack_Spec)); |
| 4054 |
while Present (Decl) loop |
| 4055 |
if Comes_From_Source (Decl) |
| 4056 |
and then Nkind (Decl) in N_Object_Declaration |
| 4057 |
| N_Object_Renaming_Declaration |
| 4058 |
then |
| 4059 |
Append_New_Elmt (Defining_Entity (Decl), States_And_Objs); |
| 4060 |
|
| 4061 |
elsif Nkind (Decl) = N_Package_Declaration then |
| 4062 |
Collect_States_And_Objects (Decl); |
| 4063 |
|
| 4064 |
elsif Is_Single_Concurrent_Type_Declaration (Decl) then |
| 4065 |
Append_New_Elmt |
| 4066 |
(Anonymous_Object (Defining_Entity (Decl)), |
| 4067 |
States_And_Objs); |
| 4068 |
end if; |
| 4069 |
|
| 4070 |
Next (Decl); |
| 4071 |
end loop; |
| 4072 |
end Collect_States_And_Objects; |
| 4073 |
|
| 4074 |
-- Local variables |
| 4075 |
|
| 4076 |
Inits : constant Node_Id := Expression (Get_Argument (N, Pack_Id)); |
| 4077 |
Init : Node_Id; |
| 4078 |
|
| 4079 |
-- Start of processing for Analyze_Initializes_In_Decl_Part |
| 4080 |
|
| 4081 |
begin |
| 4082 |
-- Do not analyze the pragma multiple times |
| 4083 |
|
| 4084 |
if Is_Analyzed_Pragma (N) then |
| 4085 |
return; |
| 4086 |
end if; |
| 4087 |
|
| 4088 |
-- Nothing to do when the initialization list is empty |
| 4089 |
|
| 4090 |
if Nkind (Inits) = N_Null then |
| 4091 |
return; |
| 4092 |
end if; |
| 4093 |
|
| 4094 |
-- Single and multiple initialization clauses appear as an aggregate. If |
| 4095 |
-- this is not the case, then either the parser or the analysis of the |
| 4096 |
-- pragma failed to produce an aggregate. |
| 4097 |
|
| 4098 |
pragma Assert (Nkind (Inits) = N_Aggregate); |
| 4099 |
|
| 4100 |
-- Initialize the various lists used during analysis |
| 4101 |
|
| 4102 |
Collect_States_And_Objects (Pack_Decl); |
| 4103 |
|
| 4104 |
if Present (Expressions (Inits)) then |
| 4105 |
Init := First (Expressions (Inits)); |
| 4106 |
while Present (Init) loop |
| 4107 |
Analyze_Initialization_Item (Init); |
| 4108 |
Next (Init); |
| 4109 |
end loop; |
| 4110 |
end if; |
| 4111 |
|
| 4112 |
if Present (Component_Associations (Inits)) then |
| 4113 |
Init := First (Component_Associations (Inits)); |
| 4114 |
while Present (Init) loop |
| 4115 |
Analyze_Initialization_Item_With_Inputs (Init); |
| 4116 |
Next (Init); |
| 4117 |
end loop; |
| 4118 |
end if; |
| 4119 |
|
| 4120 |
-- Ensure that a state and a corresponding constituent do not appear |
| 4121 |
-- together in pragma Initializes. |
| 4122 |
|
| 4123 |
Check_State_And_Constituent_Use |
| 4124 |
(States => States_Seen, |
| 4125 |
Constits => Constits_Seen, |
| 4126 |
Context => N); |
| 4127 |
|
| 4128 |
Set_Is_Analyzed_Pragma (N); |
| 4129 |
end Analyze_Initializes_In_Decl_Part; |
| 4130 |
|
| 4131 |
--------------------- |
| 4132 |
-- Analyze_Part_Of -- |
| 4133 |
--------------------- |
| 4134 |
|
| 4135 |
procedure Analyze_Part_Of |
| 4136 |
(Indic : Node_Id; |
| 4137 |
Item_Id : Entity_Id; |
| 4138 |
Encap : Node_Id; |
| 4139 |
Encap_Id : out Entity_Id; |
| 4140 |
Legal : out Boolean) |
| 4141 |
is |
| 4142 |
procedure Check_Part_Of_Abstract_State; |
| 4143 |
pragma Inline (Check_Part_Of_Abstract_State); |
| 4144 |
-- Verify the legality of indicator Part_Of when the encapsulator is an |
| 4145 |
-- abstract state. |
| 4146 |
|
| 4147 |
procedure Check_Part_Of_Concurrent_Type; |
| 4148 |
pragma Inline (Check_Part_Of_Concurrent_Type); |
| 4149 |
-- Verify the legality of indicator Part_Of when the encapsulator is a |
| 4150 |
-- single concurrent type. |
| 4151 |
|
| 4152 |
---------------------------------- |
| 4153 |
-- Check_Part_Of_Abstract_State -- |
| 4154 |
---------------------------------- |
| 4155 |
|
| 4156 |
procedure Check_Part_Of_Abstract_State is |
| 4157 |
Pack_Id : Entity_Id; |
| 4158 |
Placement : State_Space_Kind; |
| 4159 |
Parent_Unit : Entity_Id; |
| 4160 |
|
| 4161 |
begin |
| 4162 |
-- Determine where the object, package instantiation or state lives |
| 4163 |
-- with respect to the enclosing packages or package bodies. |
| 4164 |
|
| 4165 |
Find_Placement_In_State_Space |
| 4166 |
(Item_Id => Item_Id, |
| 4167 |
Placement => Placement, |
| 4168 |
Pack_Id => Pack_Id); |
| 4169 |
|
| 4170 |
-- The item appears in a non-package construct with a declarative |
| 4171 |
-- part (subprogram, block, etc). As such, the item is not allowed |
| 4172 |
-- to be a part of an encapsulating state because the item is not |
| 4173 |
-- visible. |
| 4174 |
|
| 4175 |
if Placement = Not_In_Package then |
| 4176 |
SPARK_Msg_N |
| 4177 |
("indicator Part_Of cannot appear in this context " |
| 4178 |
& "(SPARK RM 7.2.6(5))", Indic); |
| 4179 |
|
| 4180 |
Error_Msg_Name_1 := Chars (Scope (Encap_Id)); |
| 4181 |
SPARK_Msg_NE |
| 4182 |
("\& is not part of the hidden state of package %", |
| 4183 |
Indic, Item_Id); |
| 4184 |
return; |
| 4185 |
|
| 4186 |
-- The item appears in the visible state space of some package. In |
| 4187 |
-- general this scenario does not warrant Part_Of except when the |
| 4188 |
-- package is a nongeneric private child unit and the encapsulating |
| 4189 |
-- state is declared in a parent unit or a public descendant of that |
| 4190 |
-- parent unit. |
| 4191 |
|
| 4192 |
elsif Placement = Visible_State_Space then |
| 4193 |
if Is_Child_Unit (Pack_Id) |
| 4194 |
and then not Is_Generic_Unit (Pack_Id) |
| 4195 |
and then Is_Private_Descendant (Pack_Id) |
| 4196 |
then |
| 4197 |
-- A variable or state abstraction which is part of the visible |
| 4198 |
-- state of a nongeneric private child unit or its public |
| 4199 |
-- descendants must have its Part_Of indicator specified. The |
| 4200 |
-- Part_Of indicator must denote a state declared by either the |
| 4201 |
-- parent unit of the private unit or by a public descendant of |
| 4202 |
-- that parent unit. |
| 4203 |
|
| 4204 |
-- Find the nearest private ancestor (which can be the current |
| 4205 |
-- unit itself). |
| 4206 |
|
| 4207 |
Parent_Unit := Pack_Id; |
| 4208 |
while Present (Parent_Unit) loop |
| 4209 |
exit when Is_Private_Library_Unit (Parent_Unit); |
| 4210 |
Parent_Unit := Scope (Parent_Unit); |
| 4211 |
end loop; |
| 4212 |
|
| 4213 |
Parent_Unit := Scope (Parent_Unit); |
| 4214 |
|
| 4215 |
if not Is_Child_Or_Sibling (Pack_Id, Scope (Encap_Id)) then |
| 4216 |
SPARK_Msg_NE |
| 4217 |
("indicator Part_Of must denote abstract state of & or of " |
| 4218 |
& "its public descendant (SPARK RM 7.2.6(3))", |
| 4219 |
Indic, Parent_Unit); |
| 4220 |
return; |
| 4221 |
|
| 4222 |
elsif Scope (Encap_Id) = Parent_Unit |
| 4223 |
or else |
| 4224 |
(Is_Ancestor_Package (Parent_Unit, Scope (Encap_Id)) |
| 4225 |
and then not Is_Private_Descendant (Scope (Encap_Id))) |
| 4226 |
then |
| 4227 |
null; |
| 4228 |
|
| 4229 |
else |
| 4230 |
SPARK_Msg_NE |
| 4231 |
("indicator Part_Of must denote abstract state of & or of " |
| 4232 |
& "its public descendant (SPARK RM 7.2.6(3))", |
| 4233 |
Indic, Parent_Unit); |
| 4234 |
return; |
| 4235 |
end if; |
| 4236 |
|
| 4237 |
-- Indicator Part_Of is not needed when the related package is |
| 4238 |
-- not a nongeneric private child unit or a public descendant |
| 4239 |
-- thereof. |
| 4240 |
|
| 4241 |
else |
| 4242 |
SPARK_Msg_N |
| 4243 |
("indicator Part_Of cannot appear in this context " |
| 4244 |
& "(SPARK RM 7.2.6(5))", Indic); |
| 4245 |
|
| 4246 |
Error_Msg_Name_1 := Chars (Pack_Id); |
| 4247 |
SPARK_Msg_NE |
| 4248 |
("\& is declared in the visible part of package %", |
| 4249 |
Indic, Item_Id); |
| 4250 |
return; |
| 4251 |
end if; |
| 4252 |
|
| 4253 |
-- When the item appears in the private state space of a package, the |
| 4254 |
-- encapsulating state must be declared in the same package. |
| 4255 |
|
| 4256 |
elsif Placement = Private_State_Space then |
| 4257 |
|
| 4258 |
-- In the case of the abstract state of a nongeneric private |
| 4259 |
-- child package, it may be encapsulated in the state of a |
| 4260 |
-- public descendant of its parent package. |
| 4261 |
|
| 4262 |
declare |
| 4263 |
function Is_Public_Descendant |
| 4264 |
(Child, Ancestor : Entity_Id) |
| 4265 |
return Boolean; |
| 4266 |
-- Return True if Child is a public descendant of Pack |
| 4267 |
|
| 4268 |
-------------------------- |
| 4269 |
-- Is_Public_Descendant -- |
| 4270 |
-------------------------- |
| 4271 |
|
| 4272 |
function Is_Public_Descendant |
| 4273 |
(Child, Ancestor : Entity_Id) |
| 4274 |
return Boolean |
| 4275 |
is |
| 4276 |
P : Entity_Id := Child; |
| 4277 |
begin |
| 4278 |
while Is_Child_Unit (P) |
| 4279 |
and then not Is_Private_Library_Unit (P) |
| 4280 |
loop |
| 4281 |
if Scope (P) = Ancestor then |
| 4282 |
return True; |
| 4283 |
end if; |
| 4284 |
|
| 4285 |
P := Scope (P); |
| 4286 |
end loop; |
| 4287 |
|
| 4288 |
return False; |
| 4289 |
end Is_Public_Descendant; |
| 4290 |
|
| 4291 |
-- Local variables |
| 4292 |
|
| 4293 |
Immediate_Pack_Id : constant Entity_Id := Scope (Item_Id); |
| 4294 |
|
| 4295 |
Is_State_Of_Private_Child : constant Boolean := |
| 4296 |
Is_Child_Unit (Immediate_Pack_Id) |
| 4297 |
and then not Is_Generic_Unit (Immediate_Pack_Id) |
| 4298 |
and then Is_Private_Descendant (Immediate_Pack_Id); |
| 4299 |
|
| 4300 |
Is_OK_Through_Sibling : Boolean := False; |
| 4301 |
|
| 4302 |
begin |
| 4303 |
if Ekind (Item_Id) = E_Abstract_State |
| 4304 |
and then Is_State_Of_Private_Child |
| 4305 |
and then Is_Public_Descendant (Scope (Encap_Id), Pack_Id) |
| 4306 |
then |
| 4307 |
Is_OK_Through_Sibling := True; |
| 4308 |
end if; |
| 4309 |
|
| 4310 |
if Scope (Encap_Id) /= Pack_Id |
| 4311 |
and then not Is_OK_Through_Sibling |
| 4312 |
then |
| 4313 |
if Is_State_Of_Private_Child then |
| 4314 |
SPARK_Msg_NE |
| 4315 |
("indicator Part_Of must denote abstract state of & " |
| 4316 |
& "or of its public descendant " |
| 4317 |
& "(SPARK RM 7.2.6(3))", Indic, Pack_Id); |
| 4318 |
else |
| 4319 |
SPARK_Msg_NE |
| 4320 |
("indicator Part_Of must denote an abstract state of " |
| 4321 |
& "package & (SPARK RM 7.2.6(2))", Indic, Pack_Id); |
| 4322 |
end if; |
| 4323 |
|
| 4324 |
Error_Msg_Name_1 := Chars (Pack_Id); |
| 4325 |
SPARK_Msg_NE |
| 4326 |
("\& is declared in the private part of package %", |
| 4327 |
Indic, Item_Id); |
| 4328 |
return; |
| 4329 |
end if; |
| 4330 |
end; |
| 4331 |
|
| 4332 |
-- Items declared in the body state space of a package do not need |
| 4333 |
-- Part_Of indicators as the refinement has already been seen. |
| 4334 |
|
| 4335 |
else |
| 4336 |
SPARK_Msg_N |
| 4337 |
("indicator Part_Of cannot appear in this context " |
| 4338 |
& "(SPARK RM 7.2.6(5))", Indic); |
| 4339 |
|
| 4340 |
if Scope (Encap_Id) = Pack_Id then |
| 4341 |
Error_Msg_Name_1 := Chars (Pack_Id); |
| 4342 |
SPARK_Msg_NE |
| 4343 |
("\& is declared in the body of package %", Indic, Item_Id); |
| 4344 |
end if; |
| 4345 |
|
| 4346 |
return; |
| 4347 |
end if; |
| 4348 |
|
| 4349 |
-- In the case of state in a (descendant of a private) child which |
| 4350 |
-- is Part_Of the state of another package, the package defining the |
| 4351 |
-- encapsulating abstract state should have a body, to ensure that it |
| 4352 |
-- has a state refinement (SPARK RM 7.1.4(4)). |
| 4353 |
|
| 4354 |
if Enclosing_Comp_Unit_Node (Encap_Id) /= |
| 4355 |
Enclosing_Comp_Unit_Node (Item_Id) |
| 4356 |
and then not Unit_Requires_Body (Scope (Encap_Id)) |
| 4357 |
then |
| 4358 |
SPARK_Msg_N |
| 4359 |
("indicator Part_Of must denote abstract state of package " |
| 4360 |
& "with a body (SPARK RM 7.1.4(4))", Indic); |
| 4361 |
return; |
| 4362 |
end if; |
| 4363 |
|
| 4364 |
-- At this point it is known that the Part_Of indicator is legal |
| 4365 |
|
| 4366 |
Legal := True; |
| 4367 |
end Check_Part_Of_Abstract_State; |
| 4368 |
|
| 4369 |
----------------------------------- |
| 4370 |
-- Check_Part_Of_Concurrent_Type -- |
| 4371 |
----------------------------------- |
| 4372 |
|
| 4373 |
procedure Check_Part_Of_Concurrent_Type is |
| 4374 |
function In_Proper_Order |
| 4375 |
(First : Node_Id; |
| 4376 |
Second : Node_Id) return Boolean; |
| 4377 |
pragma Inline (In_Proper_Order); |
| 4378 |
-- Determine whether node First precedes node Second |
| 4379 |
|
| 4380 |
procedure Placement_Error; |
| 4381 |
pragma Inline (Placement_Error); |
| 4382 |
-- Emit an error concerning the illegal placement of the item with |
| 4383 |
-- respect to the single concurrent type. |
| 4384 |
|
| 4385 |
--------------------- |
| 4386 |
-- In_Proper_Order -- |
| 4387 |
--------------------- |
| 4388 |
|
| 4389 |
function In_Proper_Order |
| 4390 |
(First : Node_Id; |
| 4391 |
Second : Node_Id) return Boolean |
| 4392 |
is |
| 4393 |
N : Node_Id; |
| 4394 |
|
| 4395 |
begin |
| 4396 |
if List_Containing (First) = List_Containing (Second) then |
| 4397 |
N := First; |
| 4398 |
while Present (N) loop |
| 4399 |
if N = Second then |
| 4400 |
return True; |
| 4401 |
end if; |
| 4402 |
|
| 4403 |
Next (N); |
| 4404 |
end loop; |
| 4405 |
end if; |
| 4406 |
|
| 4407 |
return False; |
| 4408 |
end In_Proper_Order; |
| 4409 |
|
| 4410 |
--------------------- |
| 4411 |
-- Placement_Error -- |
| 4412 |
--------------------- |
| 4413 |
|
| 4414 |
procedure Placement_Error is |
| 4415 |
begin |
| 4416 |
SPARK_Msg_N |
| 4417 |
("indicator Part_Of must denote a previously declared single " |
| 4418 |
& "protected type or single task type", Encap); |
| 4419 |
end Placement_Error; |
| 4420 |
|
| 4421 |
-- Local variables |
| 4422 |
|
| 4423 |
Conc_Typ : constant Entity_Id := Etype (Encap_Id); |
| 4424 |
Encap_Decl : constant Node_Id := Declaration_Node (Encap_Id); |
| 4425 |
Encap_Context : constant Node_Id := Parent (Encap_Decl); |
| 4426 |
|
| 4427 |
Item_Context : Node_Id; |
| 4428 |
Item_Decl : Node_Id; |
| 4429 |
Prv_Decls : List_Id; |
| 4430 |
Vis_Decls : List_Id; |
| 4431 |
|
| 4432 |
-- Start of processing for Check_Part_Of_Concurrent_Type |
| 4433 |
|
| 4434 |
begin |
| 4435 |
-- Only abstract states and variables can act as constituents of an |
| 4436 |
-- encapsulating single concurrent type. |
| 4437 |
|
| 4438 |
if Ekind (Item_Id) in E_Abstract_State | E_Variable then |
| 4439 |
null; |
| 4440 |
|
| 4441 |
-- The constituent is a constant |
| 4442 |
|
| 4443 |
elsif Ekind (Item_Id) = E_Constant then |
| 4444 |
Error_Msg_Name_1 := Chars (Encap_Id); |
| 4445 |
SPARK_Msg_NE |
| 4446 |
(Fix_Msg (Conc_Typ, "constant & cannot act as constituent of " |
| 4447 |
& "single protected type %"), Indic, Item_Id); |
| 4448 |
return; |
| 4449 |
|
| 4450 |
-- The constituent is a package instantiation |
| 4451 |
|
| 4452 |
else |
| 4453 |
Error_Msg_Name_1 := Chars (Encap_Id); |
| 4454 |
SPARK_Msg_NE |
| 4455 |
(Fix_Msg (Conc_Typ, "package instantiation & cannot act as " |
| 4456 |
& "constituent of single protected type %"), Indic, Item_Id); |
| 4457 |
return; |
| 4458 |
end if; |
| 4459 |
|
| 4460 |
-- When the item denotes an abstract state of a nested package, use |
| 4461 |
-- the declaration of the package to detect proper placement. |
| 4462 |
|
| 4463 |
-- package Pack is |
| 4464 |
-- task T; |
| 4465 |
-- package Nested |
| 4466 |
-- with Abstract_State => (State with Part_Of => T) |
| 4467 |
|
| 4468 |
if Ekind (Item_Id) = E_Abstract_State then |
| 4469 |
Item_Decl := Unit_Declaration_Node (Scope (Item_Id)); |
| 4470 |
else |
| 4471 |
Item_Decl := Declaration_Node (Item_Id); |
| 4472 |
end if; |
| 4473 |
|
| 4474 |
Item_Context := Parent (Item_Decl); |
| 4475 |
|
| 4476 |
-- The item and the single concurrent type must appear in the same |
| 4477 |
-- declarative region, with the item following the declaration of |
| 4478 |
-- the single concurrent type (SPARK RM 9(3)). |
| 4479 |
|
| 4480 |
if Item_Context = Encap_Context then |
| 4481 |
if Nkind (Item_Context) in N_Package_Specification |
| 4482 |
| N_Protected_Definition |
| 4483 |
| N_Task_Definition |
| 4484 |
then |
| 4485 |
Prv_Decls := Private_Declarations (Item_Context); |
| 4486 |
Vis_Decls := Visible_Declarations (Item_Context); |
| 4487 |
|
| 4488 |
-- The placement is OK when the single concurrent type appears |
| 4489 |
-- within the visible declarations and the item in the private |
| 4490 |
-- declarations. |
| 4491 |
-- |
| 4492 |
-- package Pack is |
| 4493 |
-- protected PO ... |
| 4494 |
-- private |
| 4495 |
-- Constit : ... with Part_Of => PO; |
| 4496 |
-- end Pack; |
| 4497 |
|
| 4498 |
if List_Containing (Encap_Decl) = Vis_Decls |
| 4499 |
and then List_Containing (Item_Decl) = Prv_Decls |
| 4500 |
then |
| 4501 |
null; |
| 4502 |
|
| 4503 |
-- The placement is illegal when the item appears within the |
| 4504 |
-- visible declarations and the single concurrent type is in |
| 4505 |
-- the private declarations. |
| 4506 |
-- |
| 4507 |
-- package Pack is |
| 4508 |
-- Constit : ... with Part_Of => PO; |
| 4509 |
-- private |
| 4510 |
-- protected PO ... |
| 4511 |
-- end Pack; |
| 4512 |
|
| 4513 |
elsif List_Containing (Item_Decl) = Vis_Decls |
| 4514 |
and then List_Containing (Encap_Decl) = Prv_Decls |
| 4515 |
then |
| 4516 |
Placement_Error; |
| 4517 |
return; |
| 4518 |
|
| 4519 |
-- Otherwise both the item and the single concurrent type are |
| 4520 |
-- in the same list. Ensure that the declaration of the single |
| 4521 |
-- concurrent type precedes that of the item. |
| 4522 |
|
| 4523 |
elsif not In_Proper_Order |
| 4524 |
(First => Encap_Decl, |
| 4525 |
Second => Item_Decl) |
| 4526 |
then |
| 4527 |
Placement_Error; |
| 4528 |
return; |
| 4529 |
end if; |
| 4530 |
|
| 4531 |
-- Otherwise both the item and the single concurrent type are |
| 4532 |
-- in the same list. Ensure that the declaration of the single |
| 4533 |
-- concurrent type precedes that of the item. |
| 4534 |
|
| 4535 |
elsif not In_Proper_Order |
| 4536 |
(First => Encap_Decl, |
| 4537 |
Second => Item_Decl) |
| 4538 |
then |
| 4539 |
Placement_Error; |
| 4540 |
return; |
| 4541 |
end if; |
| 4542 |
|
| 4543 |
-- Otherwise the item and the single concurrent type reside within |
| 4544 |
-- unrelated regions. |
| 4545 |
|
| 4546 |
else |
| 4547 |
Error_Msg_Name_1 := Chars (Encap_Id); |
| 4548 |
SPARK_Msg_NE |
| 4549 |
(Fix_Msg (Conc_Typ, "constituent & must be declared " |
| 4550 |
& "immediately within the same region as single protected " |
| 4551 |
& "type %"), Indic, Item_Id); |
| 4552 |
return; |
| 4553 |
end if; |
| 4554 |
|
| 4555 |
-- At this point it is known that the Part_Of indicator is legal |
| 4556 |
|
| 4557 |
Legal := True; |
| 4558 |
end Check_Part_Of_Concurrent_Type; |
| 4559 |
|
| 4560 |
-- Start of processing for Analyze_Part_Of |
| 4561 |
|
| 4562 |
begin |
| 4563 |
-- Assume that the indicator is illegal |
| 4564 |
|
| 4565 |
Encap_Id := Empty; |
| 4566 |
Legal := False; |
| 4567 |
|
| 4568 |
if Nkind (Encap) in |
| 4569 |
N_Expanded_Name | N_Identifier | N_Selected_Component |
| 4570 |
then |
| 4571 |
Analyze (Encap); |
| 4572 |
Resolve_State (Encap); |
| 4573 |
|
| 4574 |
Encap_Id := Entity (Encap); |
| 4575 |
|
| 4576 |
-- The encapsulator is an abstract state |
| 4577 |
|
| 4578 |
if Ekind (Encap_Id) = E_Abstract_State then |
| 4579 |
null; |
| 4580 |
|
| 4581 |
-- The encapsulator is a single concurrent type (SPARK RM 9.3) |
| 4582 |
|
| 4583 |
elsif Is_Single_Concurrent_Object (Encap_Id) then |
| 4584 |
null; |
| 4585 |
|
| 4586 |
-- Otherwise the encapsulator is not a legal choice |
| 4587 |
|
| 4588 |
else |
| 4589 |
SPARK_Msg_N |
| 4590 |
("indicator Part_Of must denote abstract state, single " |
| 4591 |
& "protected type or single task type", Encap); |
| 4592 |
return; |
| 4593 |
end if; |
| 4594 |
|
| 4595 |
-- This is a syntax error, always report |
| 4596 |
|
| 4597 |
else |
| 4598 |
Error_Msg_N |
| 4599 |
("indicator Part_Of must denote abstract state, single protected " |
| 4600 |
& "type or single task type", Encap); |
| 4601 |
return; |
| 4602 |
end if; |
| 4603 |
|
| 4604 |
-- Catch a case where indicator Part_Of denotes the abstract view of a |
| 4605 |
-- variable which appears as an abstract state (SPARK RM 10.1.2 2). |
| 4606 |
|
| 4607 |
if From_Limited_With (Encap_Id) |
| 4608 |
and then Present (Non_Limited_View (Encap_Id)) |
| 4609 |
and then Ekind (Non_Limited_View (Encap_Id)) = E_Variable |
| 4610 |
then |
| 4611 |
SPARK_Msg_N ("indicator Part_Of must denote abstract state", Encap); |
| 4612 |
SPARK_Msg_N ("\& denotes abstract view of object", Encap); |
| 4613 |
return; |
| 4614 |
end if; |
| 4615 |
|
| 4616 |
-- The encapsulator is an abstract state |
| 4617 |
|
| 4618 |
if Ekind (Encap_Id) = E_Abstract_State then |
| 4619 |
Check_Part_Of_Abstract_State; |
| 4620 |
|
| 4621 |
-- The encapsulator is a single concurrent type |
| 4622 |
|
| 4623 |
else |
| 4624 |
Check_Part_Of_Concurrent_Type; |
| 4625 |
end if; |
| 4626 |
end Analyze_Part_Of; |
| 4627 |
|
| 4628 |
---------------------------------- |
| 4629 |
-- Analyze_Part_Of_In_Decl_Part -- |
| 4630 |
---------------------------------- |
| 4631 |
|
| 4632 |
procedure Analyze_Part_Of_In_Decl_Part |
| 4633 |
(N : Node_Id; |
| 4634 |
Freeze_Id : Entity_Id := Empty) |
| 4635 |
is |
| 4636 |
Encap : constant Node_Id := |
| 4637 |
Get_Pragma_Arg (First (Pragma_Argument_Associations (N))); |
| 4638 |
Errors : constant Nat := Serious_Errors_Detected; |
| 4639 |
Var_Decl : constant Node_Id := Find_Related_Context (N); |
| 4640 |
Var_Id : constant Entity_Id := Defining_Entity (Var_Decl); |
| 4641 |
Constits : Elist_Id; |
| 4642 |
Encap_Id : Entity_Id; |
| 4643 |
Legal : Boolean; |
| 4644 |
|
| 4645 |
begin |
| 4646 |
-- Detect any discrepancies between the placement of the variable with |
| 4647 |
-- respect to general state space and the encapsulating state or single |
| 4648 |
-- concurrent type. |
| 4649 |
|
| 4650 |
Analyze_Part_Of |
| 4651 |
(Indic => N, |
| 4652 |
Item_Id => Var_Id, |
| 4653 |
Encap => Encap, |
| 4654 |
Encap_Id => Encap_Id, |
| 4655 |
Legal => Legal); |
| 4656 |
|
| 4657 |
-- The Part_Of indicator turns the variable into a constituent of the |
| 4658 |
-- encapsulating state or single concurrent type. |
| 4659 |
|
| 4660 |
if Legal then |
| 4661 |
pragma Assert (Present (Encap_Id)); |
| 4662 |
Constits := Part_Of_Constituents (Encap_Id); |
| 4663 |
|
| 4664 |
if No (Constits) then |
| 4665 |
Constits := New_Elmt_List; |
| 4666 |
Set_Part_Of_Constituents (Encap_Id, Constits); |
| 4667 |
end if; |
| 4668 |
|
| 4669 |
Append_Elmt (Var_Id, Constits); |
| 4670 |
Set_Encapsulating_State (Var_Id, Encap_Id); |
| 4671 |
|
| 4672 |
-- A Part_Of constituent partially refines an abstract state. This |
| 4673 |
-- property does not apply to protected or task units. |
| 4674 |
|
| 4675 |
if Ekind (Encap_Id) = E_Abstract_State then |
| 4676 |
Set_Has_Partial_Visible_Refinement (Encap_Id); |
| 4677 |
end if; |
| 4678 |
end if; |
| 4679 |
|
| 4680 |
-- Emit a clarification message when the encapsulator is undefined, |
| 4681 |
-- possibly due to contract freezing. |
| 4682 |
|
| 4683 |
if Errors /= Serious_Errors_Detected |
| 4684 |
and then Present (Freeze_Id) |
| 4685 |
and then Has_Undefined_Reference (Encap) |
| 4686 |
then |
| 4687 |
Contract_Freeze_Error (Var_Id, Freeze_Id); |
| 4688 |
end if; |
| 4689 |
end Analyze_Part_Of_In_Decl_Part; |
| 4690 |
|
| 4691 |
-------------------- |
| 4692 |
-- Analyze_Pragma -- |
| 4693 |
-------------------- |
| 4694 |
|
| 4695 |
procedure Analyze_Pragma (N : Node_Id) is |
| 4696 |
Loc : constant Source_Ptr := Sloc (N); |
| 4697 |
|
| 4698 |
Pname : Name_Id := Pragma_Name (N); |
| 4699 |
-- Name of the source pragma, or name of the corresponding aspect for |
| 4700 |
-- pragmas which originate in a source aspect. In the latter case, the |
| 4701 |
-- name may be different from the pragma name. |
| 4702 |
|
| 4703 |
Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname); |
| 4704 |
|
| 4705 |
Pragma_Exit : exception; |
| 4706 |
-- This exception is used to exit pragma processing completely. It |
| 4707 |
-- is used when an error is detected, and no further processing is |
| 4708 |
-- required. It is also used if an earlier error has left the tree in |
| 4709 |
-- a state where the pragma should not be processed. |
| 4710 |
|
| 4711 |
Arg_Count : Nat; |
| 4712 |
-- Number of pragma argument associations |
| 4713 |
|
| 4714 |
Arg1 : Node_Id; |
| 4715 |
Arg2 : Node_Id; |
| 4716 |
Arg3 : Node_Id; |
| 4717 |
Arg4 : Node_Id; |
| 4718 |
Arg5 : Node_Id; |
| 4719 |
-- First five pragma arguments (pragma argument association nodes, or |
| 4720 |
-- Empty if the corresponding argument does not exist). |
| 4721 |
|
| 4722 |
type Name_List is array (Natural range <>) of Name_Id; |
| 4723 |
type Args_List is array (Natural range <>) of Node_Id; |
| 4724 |
-- Types used for arguments to Check_Arg_Order and Gather_Associations |
| 4725 |
|
| 4726 |
----------------------- |
| 4727 |
-- Local Subprograms -- |
| 4728 |
----------------------- |
| 4729 |
|
| 4730 |
procedure Ada_2005_Pragma; |
| 4731 |
-- Called for pragmas defined in Ada 2005, that are not in Ada 95. In |
| 4732 |
-- Ada 95 mode, these are implementation defined pragmas, so should be |
| 4733 |
-- caught by the No_Implementation_Pragmas restriction. |
| 4734 |
|
| 4735 |
procedure Ada_2012_Pragma; |
| 4736 |
-- Called for pragmas defined in Ada 2012, that are not in Ada 95 or 05. |
| 4737 |
-- In Ada 95 or 05 mode, these are implementation defined pragmas, so |
| 4738 |
-- should be caught by the No_Implementation_Pragmas restriction. |
| 4739 |
|
| 4740 |
procedure Analyze_Depends_Global |
| 4741 |
(Spec_Id : out Entity_Id; |
| 4742 |
Subp_Decl : out Node_Id; |
| 4743 |
Legal : out Boolean); |
| 4744 |
-- Subsidiary to the analysis of pragmas Depends and Global. Verify the |
| 4745 |
-- legality of the placement and related context of the pragma. Spec_Id |
| 4746 |
-- is the entity of the related subprogram. Subp_Decl is the declaration |
| 4747 |
-- of the related subprogram. Sets flag Legal when the pragma is legal. |
| 4748 |
|
| 4749 |
procedure Analyze_If_Present (Id : Pragma_Id); |
| 4750 |
-- Inspect the remainder of the list containing pragma N and look for |
| 4751 |
-- a pragma that matches Id. If found, analyze the pragma. |
| 4752 |
|
| 4753 |
procedure Analyze_Pre_Post_Condition; |
| 4754 |
-- Subsidiary to the analysis of pragmas Precondition and Postcondition |
| 4755 |
|
| 4756 |
procedure Analyze_Refined_Depends_Global_Post |
| 4757 |
(Spec_Id : out Entity_Id; |
| 4758 |
Body_Id : out Entity_Id; |
| 4759 |
Legal : out Boolean); |
| 4760 |
-- Subsidiary routine to the analysis of body pragmas Refined_Depends, |
| 4761 |
-- Refined_Global and Refined_Post. Verify the legality of the placement |
| 4762 |
-- and related context of the pragma. Spec_Id is the entity of the |
| 4763 |
-- related subprogram. Body_Id is the entity of the subprogram body. |
| 4764 |
-- Flag Legal is set when the pragma is legal. |
| 4765 |
|
| 4766 |
procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False); |
| 4767 |
-- Perform full analysis of pragma Unmodified and the write aspect of |
| 4768 |
-- pragma Unused. Flag Is_Unused should be set when verifying the |
| 4769 |
-- semantics of pragma Unused. |
| 4770 |
|
| 4771 |
procedure Analyze_Unreferenced_Or_Unused (Is_Unused : Boolean := False); |
| 4772 |
-- Perform full analysis of pragma Unreferenced and the read aspect of |
| 4773 |
-- pragma Unused. Flag Is_Unused should be set when verifying the |
| 4774 |
-- semantics of pragma Unused. |
| 4775 |
|
| 4776 |
procedure Check_Ada_83_Warning; |
| 4777 |
-- Issues a warning message for the current pragma if operating in Ada |
| 4778 |
-- 83 mode (used for language pragmas that are not a standard part of |
| 4779 |
-- Ada 83). This procedure does not raise Pragma_Exit. Also notes use |
| 4780 |
-- of 95 pragma. |
| 4781 |
|
| 4782 |
procedure Check_Arg_Count (Required : Nat); |
| 4783 |
-- Check argument count for pragma is equal to given parameter. If not, |
| 4784 |
-- then issue an error message and raise Pragma_Exit. |
| 4785 |
|
| 4786 |
-- Note: all routines whose name is Check_Arg_Is_xxx take an argument |
| 4787 |
-- Arg which can either be a pragma argument association, in which case |
| 4788 |
-- the check is applied to the expression of the association or an |
| 4789 |
-- expression directly. |
| 4790 |
|
| 4791 |
procedure Check_Arg_Is_External_Name (Arg : Node_Id); |
| 4792 |
-- Check that an argument has the right form for an EXTERNAL_NAME |
| 4793 |
-- parameter of an extended import/export pragma. The rule is that the |
| 4794 |
-- name must be an identifier or string literal (in Ada 83 mode) or a |
| 4795 |
-- static string expression (in Ada 95 mode). |
| 4796 |
|
| 4797 |
procedure Check_Arg_Is_Identifier (Arg : Node_Id); |
| 4798 |
-- Check the specified argument Arg to make sure that it is an |
| 4799 |
-- identifier. If not give error and raise Pragma_Exit. |
| 4800 |
|
| 4801 |
procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id); |
| 4802 |
-- Check the specified argument Arg to make sure that it is an integer |
| 4803 |
-- literal. If not give error and raise Pragma_Exit. |
| 4804 |
|
| 4805 |
procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id); |
| 4806 |
-- Check the specified argument Arg to make sure that it has the proper |
| 4807 |
-- syntactic form for a local name and meets the semantic requirements |
| 4808 |
-- for a local name. The local name is analyzed as part of the |
| 4809 |
-- processing for this call. In addition, the local name is required |
| 4810 |
-- to represent an entity at the library level. |
| 4811 |
|
| 4812 |
procedure Check_Arg_Is_Local_Name (Arg : Node_Id); |
| 4813 |
-- Check the specified argument Arg to make sure that it has the proper |
| 4814 |
-- syntactic form for a local name and meets the semantic requirements |
| 4815 |
-- for a local name. The local name is analyzed as part of the |
| 4816 |
-- processing for this call. |
| 4817 |
|
| 4818 |
procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id); |
| 4819 |
-- Check the specified argument Arg to make sure that it is a valid |
| 4820 |
-- locking policy name. If not give error and raise Pragma_Exit. |
| 4821 |
|
| 4822 |
procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id); |
| 4823 |
-- Check the specified argument Arg to make sure that it is a valid |
| 4824 |
-- elaboration policy name. If not give error and raise Pragma_Exit. |
| 4825 |
|
| 4826 |
procedure Check_Arg_Is_One_Of |
| 4827 |
(Arg : Node_Id; |
| 4828 |
N1, N2 : Name_Id); |
| 4829 |
procedure Check_Arg_Is_One_Of |
| 4830 |
(Arg : Node_Id; |
| 4831 |
N1, N2, N3 : Name_Id); |
| 4832 |
procedure Check_Arg_Is_One_Of |
| 4833 |
(Arg : Node_Id; |
| 4834 |
N1, N2, N3, N4 : Name_Id); |
| 4835 |
procedure Check_Arg_Is_One_Of |
| 4836 |
(Arg : Node_Id; |
| 4837 |
N1, N2, N3, N4, N5 : Name_Id); |
| 4838 |
-- Check the specified argument Arg to make sure that it is an |
| 4839 |
-- identifier whose name matches either N1 or N2 (or N3, N4, N5 if |
| 4840 |
-- present). If not then give error and raise Pragma_Exit. |
| 4841 |
|
| 4842 |
procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id); |
| 4843 |
-- Check the specified argument Arg to make sure that it is a valid |
| 4844 |
-- queuing policy name. If not give error and raise Pragma_Exit. |
| 4845 |
|
| 4846 |
procedure Check_Arg_Is_OK_Static_Expression |
| 4847 |
(Arg : Node_Id; |
| 4848 |
Typ : Entity_Id := Empty); |
| 4849 |
-- Check the specified argument Arg to make sure that it is a static |
| 4850 |
-- expression of the given type (i.e. it will be analyzed and resolved |
| 4851 |
-- using this type, which can be any valid argument to Resolve, e.g. |
| 4852 |
-- Any_Integer is OK). If not, given error and raise Pragma_Exit. If |
| 4853 |
-- Typ is left Empty, then any static expression is allowed. Includes |
| 4854 |
-- checking that the argument does not raise Constraint_Error. |
| 4855 |
|
| 4856 |
procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id); |
| 4857 |
-- Check the specified argument Arg to make sure that it is a valid task |
| 4858 |
-- dispatching policy name. If not give error and raise Pragma_Exit. |
| 4859 |
|
| 4860 |
procedure Check_Arg_Order (Names : Name_List); |
| 4861 |
-- Checks for an instance of two arguments with identifiers for the |
| 4862 |
-- current pragma which are not in the sequence indicated by Names, |
| 4863 |
-- and if so, generates a fatal message about bad order of arguments. |
| 4864 |
|
| 4865 |
procedure Check_At_Least_N_Arguments (N : Nat); |
| 4866 |
-- Check there are at least N arguments present |
| 4867 |
|
| 4868 |
procedure Check_At_Most_N_Arguments (N : Nat); |
| 4869 |
-- Check there are no more than N arguments present |
| 4870 |
|
| 4871 |
procedure Check_Component |
| 4872 |
(Comp : Node_Id; |
| 4873 |
UU_Typ : Entity_Id; |
| 4874 |
In_Variant_Part : Boolean := False); |
| 4875 |
-- Examine an Unchecked_Union component for correct use of per-object |
| 4876 |
-- constrained subtypes, and for restrictions on finalizable components. |
| 4877 |
-- UU_Typ is the related Unchecked_Union type. Flag In_Variant_Part |
| 4878 |
-- should be set when Comp comes from a record variant. |
| 4879 |
|
| 4880 |
procedure Check_Duplicate_Pragma (E : Entity_Id); |
| 4881 |
-- Check if a rep item of the same name as the current pragma is already |
| 4882 |
-- chained as a rep pragma to the given entity. If so give a message |
| 4883 |
-- about the duplicate, and then raise Pragma_Exit so does not return. |
| 4884 |
-- Note that if E is a type, then this routine avoids flagging a pragma |
| 4885 |
-- which applies to a parent type from which E is derived. |
| 4886 |
|
| 4887 |
procedure Check_Duplicated_Export_Name (Nam : Node_Id); |
| 4888 |
-- Nam is an N_String_Literal node containing the external name set by |
| 4889 |
-- an Import or Export pragma (or extended Import or Export pragma). |
| 4890 |
-- This procedure checks for possible duplications if this is the export |
| 4891 |
-- case, and if found, issues an appropriate error message. |
| 4892 |
|
| 4893 |
procedure Check_Expr_Is_OK_Static_Expression |
| 4894 |
(Expr : Node_Id; |
| 4895 |
Typ : Entity_Id := Empty); |
| 4896 |
-- Check the specified expression Expr to make sure that it is a static |
| 4897 |
-- expression of the given type (i.e. it will be analyzed and resolved |
| 4898 |
-- using this type, which can be any valid argument to Resolve, e.g. |
| 4899 |
-- Any_Integer is OK). If not, given error and raise Pragma_Exit. If |
| 4900 |
-- Typ is left Empty, then any static expression is allowed. Includes |
| 4901 |
-- checking that the expression does not raise Constraint_Error. |
| 4902 |
|
| 4903 |
procedure Check_First_Subtype (Arg : Node_Id); |
| 4904 |
-- Checks that Arg, whose expression is an entity name, references a |
| 4905 |
-- first subtype. |
| 4906 |
|
| 4907 |
procedure Check_Identifier (Arg : Node_Id; Id : Name_Id); |
| 4908 |
-- Checks that the given argument has an identifier, and if so, requires |
| 4909 |
-- it to match the given identifier name. If there is no identifier, or |
| 4910 |
-- a non-matching identifier, then an error message is given and |
| 4911 |
-- Pragma_Exit is raised. |
| 4912 |
|
| 4913 |
procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id); |
| 4914 |
-- Checks that the given argument has an identifier, and if so, requires |
| 4915 |
-- it to match one of the given identifier names. If there is no |
| 4916 |
-- identifier, or a non-matching identifier, then an error message is |
| 4917 |
-- given and Pragma_Exit is raised. |
| 4918 |
|
| 4919 |
procedure Check_In_Main_Program; |
| 4920 |
-- Common checks for pragmas that appear within a main program |
| 4921 |
-- (Priority, Main_Storage, Time_Slice, Relative_Deadline, CPU). |
| 4922 |
|
| 4923 |
procedure Check_Interrupt_Or_Attach_Handler; |
| 4924 |
-- Common processing for first argument of pragma Interrupt_Handler or |
| 4925 |
-- pragma Attach_Handler. |
| 4926 |
|
| 4927 |
procedure Check_Loop_Pragma_Placement; |
| 4928 |
-- Verify whether pragmas Loop_Invariant, Loop_Optimize and Loop_Variant |
| 4929 |
-- appear immediately within a construct restricted to loops, and that |
| 4930 |
-- pragmas Loop_Invariant and Loop_Variant are grouped together. |
| 4931 |
|
| 4932 |
procedure Check_Is_In_Decl_Part_Or_Package_Spec; |
| 4933 |
-- Check that pragma appears in a declarative part, or in a package |
| 4934 |
-- specification, i.e. that it does not occur in a statement sequence |
| 4935 |
-- in a body. |
| 4936 |
|
| 4937 |
procedure Check_No_Identifier (Arg : Node_Id); |
| 4938 |
-- Checks that the given argument does not have an identifier. If |
| 4939 |
-- an identifier is present, then an error message is issued, and |
| 4940 |
-- Pragma_Exit is raised. |
| 4941 |
|
| 4942 |
procedure Check_No_Identifiers; |
| 4943 |
-- Checks that none of the arguments to the pragma has an identifier. |
| 4944 |
-- If any argument has an identifier, then an error message is issued, |
| 4945 |
-- and Pragma_Exit is raised. |
| 4946 |
|
| 4947 |
procedure Check_No_Link_Name; |
| 4948 |
-- Checks that no link name is specified |
| 4949 |
|
| 4950 |
procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id); |
| 4951 |
-- Checks if the given argument has an identifier, and if so, requires |
| 4952 |
-- it to match the given identifier name. If there is a non-matching |
| 4953 |
-- identifier, then an error message is given and Pragma_Exit is raised. |
| 4954 |
|
| 4955 |
procedure Check_Optional_Identifier (Arg : Node_Id; Id : String); |
| 4956 |
-- Checks if the given argument has an identifier, and if so, requires |
| 4957 |
-- it to match the given identifier name. If there is a non-matching |
| 4958 |
-- identifier, then an error message is given and Pragma_Exit is raised. |
| 4959 |
-- In this version of the procedure, the identifier name is given as |
| 4960 |
-- a string with lower case letters. |
| 4961 |
|
| 4962 |
procedure Check_Static_Boolean_Expression (Expr : Node_Id); |
| 4963 |
-- Subsidiary to the analysis of pragmas Async_Readers, Async_Writers, |
| 4964 |
-- Constant_After_Elaboration, Effective_Reads, Effective_Writes, |
| 4965 |
-- Extensions_Visible, Side_Effects and Volatile_Function. Ensure |
| 4966 |
-- that expression Expr is an OK static boolean expression. Emit an |
| 4967 |
-- error if this is not the case. |
| 4968 |
|
| 4969 |
procedure Check_Static_Constraint (Constr : Node_Id); |
| 4970 |
-- Constr is a constraint from an N_Subtype_Indication node from a |
| 4971 |
-- component constraint in an Unchecked_Union type, a range, or a |
| 4972 |
-- discriminant association. This routine checks that the constraint |
| 4973 |
-- is static as required by the restrictions for Unchecked_Union. |
| 4974 |
|
| 4975 |
procedure Check_Valid_Configuration_Pragma; |
| 4976 |
-- Legality checks for placement of a configuration pragma |
| 4977 |
|
| 4978 |
procedure Check_Valid_Library_Unit_Pragma; |
| 4979 |
-- Legality checks for library unit pragmas. A special case arises for |
| 4980 |
-- pragmas in generic instances that come from copies of the original |
| 4981 |
-- library unit pragmas in the generic templates. In the case of other |
| 4982 |
-- than library level instantiations these can appear in contexts which |
| 4983 |
-- would normally be invalid (they only apply to the original template |
| 4984 |
-- and to library level instantiations), and they are simply ignored, |
| 4985 |
-- which is implemented by rewriting them as null statements and |
| 4986 |
-- optionally raising Pragma_Exit to terminate analysis. An exception |
| 4987 |
-- is not always raised to avoid exception propagation during the |
| 4988 |
-- bootstrap, so all callers should check whether N has been rewritten. |
| 4989 |
|
| 4990 |
procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id); |
| 4991 |
-- Check an Unchecked_Union variant for lack of nested variants and |
| 4992 |
-- presence of at least one component. UU_Typ is the related Unchecked_ |
| 4993 |
-- Union type. |
| 4994 |
|
| 4995 |
procedure Ensure_Aggregate_Form (Arg : Node_Id); |
| 4996 |
-- Subsidiary routine to the processing of pragmas Abstract_State, |
| 4997 |
-- Contract_Cases, Depends, Exceptional_Cases, Global, Initializes, |
| 4998 |
-- Refined_Depends, Refined_Global, Refined_State and |
| 4999 |
-- Subprogram_Variant. Transform argument Arg into an aggregate if not |
| 5000 |
-- one already. N_Null is never transformed. Arg may denote an aspect |
| 5001 |
-- specification or a pragma argument association. |
| 5002 |
|
| 5003 |
procedure Error_Pragma (Msg : String); |
| 5004 |
pragma No_Return (Error_Pragma); |
| 5005 |
-- Outputs error message for current pragma. The message contains a % |
| 5006 |
-- that will be replaced with the pragma name, and the flag is placed |
| 5007 |
-- on the pragma itself. Pragma_Exit is then raised. Note: this routine |
| 5008 |
-- calls Fix_Error (see spec of that procedure for details). |
| 5009 |
|
| 5010 |
procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id); |
| 5011 |
pragma No_Return (Error_Pragma_Arg); |
| 5012 |
-- Outputs error message for current pragma. The message may contain |
| 5013 |
-- a % that will be replaced with the pragma name. The parameter Arg |
| 5014 |
-- may either be a pragma argument association, in which case the flag |
| 5015 |
-- is placed on the expression of this association, or an expression, |
| 5016 |
-- in which case the flag is placed directly on the expression. The |
| 5017 |
-- message is placed using Error_Msg_N, so the message may also contain |
| 5018 |
-- an & insertion character which will reference the given Arg value. |
| 5019 |
-- After placing the message, Pragma_Exit is raised. Note: this routine |
| 5020 |
-- calls Fix_Error (see spec of that procedure for details). |
| 5021 |
|
| 5022 |
procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id); |
| 5023 |
pragma No_Return (Error_Pragma_Arg); |
| 5024 |
-- Similar to above form of Error_Pragma_Arg except that two messages |
| 5025 |
-- are provided, the second is a continuation comment starting with \. |
| 5026 |
|
| 5027 |
procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id); |
| 5028 |
pragma No_Return (Error_Pragma_Arg_Ident); |
| 5029 |
-- Outputs error message for current pragma. The message may contain a % |
| 5030 |
-- that will be replaced with the pragma name. The parameter Arg must be |
| 5031 |
-- a pragma argument association with a non-empty identifier (i.e. its |
| 5032 |
-- Chars field must be set), and the error message is placed on the |
| 5033 |
-- identifier. The message is placed using Error_Msg_N so the message |
| 5034 |
-- may also contain an & insertion character which will reference |
| 5035 |
-- the identifier. After placing the message, Pragma_Exit is raised. |
| 5036 |
-- Note: this routine calls Fix_Error (see spec of that procedure for |
| 5037 |
-- details). |
| 5038 |
|
| 5039 |
procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id); |
| 5040 |
pragma No_Return (Error_Pragma_Ref); |
| 5041 |
-- Outputs error message for current pragma. The message may contain |
| 5042 |
-- a % that will be replaced with the pragma name. The parameter Ref |
| 5043 |
-- must be an entity whose name can be referenced by & and sloc by #. |
| 5044 |
-- After placing the message, Pragma_Exit is raised. Note: this routine |
| 5045 |
-- calls Fix_Error (see spec of that procedure for details). |
| 5046 |
|
| 5047 |
function Find_Lib_Unit_Name return Entity_Id; |
| 5048 |
-- Used for a library unit pragma to find the entity to which the |
| 5049 |
-- library unit pragma applies, returns the entity found. |
| 5050 |
|
| 5051 |
procedure Find_Program_Unit_Name (Id : Node_Id); |
| 5052 |
-- If the pragma is a compilation unit pragma, the id must denote the |
| 5053 |
-- compilation unit in the same compilation, and the pragma must appear |
| 5054 |
-- in the list of preceding or trailing pragmas. If it is a program |
| 5055 |
-- unit pragma that is not a compilation unit pragma, then the |
| 5056 |
-- identifier must be visible. |
| 5057 |
|
| 5058 |
function Find_Unique_Parameterless_Procedure |
| 5059 |
(Name : Entity_Id; |
| 5060 |
Arg : Node_Id) return Entity_Id; |
| 5061 |
-- Used for a procedure pragma to find the unique parameterless |
| 5062 |
-- procedure identified by Name, returns it if it exists, otherwise |
| 5063 |
-- errors out and uses Arg as the pragma argument for the message. |
| 5064 |
|
| 5065 |
function Fix_Error (Msg : String) return String; |
| 5066 |
-- This is called prior to issuing an error message. Msg is the normal |
| 5067 |
-- error message issued in the pragma case. This routine checks for the |
| 5068 |
-- case of a pragma coming from an aspect in the source, and returns a |
| 5069 |
-- message suitable for the aspect case as follows: |
| 5070 |
-- |
| 5071 |
-- Each substring "pragma" is replaced by "aspect" |
| 5072 |
-- |
| 5073 |
-- If "argument of" is at the start of the error message text, it is |
| 5074 |
-- replaced by "entity for". |
| 5075 |
-- |
| 5076 |
-- If "argument" is at the start of the error message text, it is |
| 5077 |
-- replaced by "entity". |
| 5078 |
-- |
| 5079 |
-- So for example, "argument of pragma X must be discrete type" |
| 5080 |
-- returns "entity for aspect X must be a discrete type". |
| 5081 |
|
| 5082 |
-- Finally Error_Msg_Name_1 is set to the name of the aspect (which may |
| 5083 |
-- be different from the pragma name). If the current pragma results |
| 5084 |
-- from rewriting another pragma, then Error_Msg_Name_1 is set to the |
| 5085 |
-- original pragma name. |
| 5086 |
|
| 5087 |
procedure Gather_Associations |
| 5088 |
(Names : Name_List; |
| 5089 |
Args : out Args_List); |
| 5090 |
-- This procedure is used to gather the arguments for a pragma that |
| 5091 |
-- permits arbitrary ordering of parameters using the normal rules |
| 5092 |
-- for named and positional parameters. The Names argument is a list |
| 5093 |
-- of Name_Id values that corresponds to the allowed pragma argument |
| 5094 |
-- association identifiers in order. The result returned in Args is |
| 5095 |
-- a list of corresponding expressions that are the pragma arguments. |
| 5096 |
-- Note that this is a list of expressions, not of pragma argument |
| 5097 |
-- associations (Gather_Associations has completely checked all the |
| 5098 |
-- optional identifiers when it returns). An entry in Args is Empty |
| 5099 |
-- on return if the corresponding argument is not present. |
| 5100 |
|
| 5101 |
procedure GNAT_Pragma; |
| 5102 |
-- Called for all GNAT defined pragmas to check the relevant restriction |
| 5103 |
-- (No_Implementation_Pragmas). |
| 5104 |
|
| 5105 |
function Is_Before_First_Decl |
| 5106 |
(Pragma_Node : Node_Id; |
| 5107 |
Decls : List_Id) return Boolean; |
| 5108 |
-- Return True if Pragma_Node is before the first declarative item in |
| 5109 |
-- Decls where Decls is the list of declarative items. |
| 5110 |
|
| 5111 |
function Is_Configuration_Pragma return Boolean; |
| 5112 |
-- Determines if the placement of the current pragma is appropriate |
| 5113 |
-- for a configuration pragma. |
| 5114 |
|
| 5115 |
function Is_In_Context_Clause return Boolean; |
| 5116 |
-- Returns True if pragma appears within the context clause of a unit, |
| 5117 |
-- and False for any other placement (does not generate any messages). |
| 5118 |
|
| 5119 |
function Is_Static_String_Expression (Arg : Node_Id) return Boolean; |
| 5120 |
-- Analyzes the argument, and determines if it is a static string |
| 5121 |
-- expression, returns True if so, False if non-static or not String. |
| 5122 |
-- A special case is that a string literal returns True in Ada 83 mode |
| 5123 |
-- (which has no such thing as static string expressions). Note that |
| 5124 |
-- the call analyzes its argument, so this cannot be used for the case |
| 5125 |
-- where an identifier might not be declared. |
| 5126 |
|
| 5127 |
procedure Pragma_Misplaced; |
| 5128 |
pragma No_Return (Pragma_Misplaced); |
| 5129 |
-- Issue fatal error message for misplaced pragma |
| 5130 |
|
| 5131 |
procedure Process_Atomic_Independent_Shared_Volatile; |
| 5132 |
-- Common processing for pragmas Atomic, Independent, Shared, Volatile, |
| 5133 |
-- Volatile_Full_Access. Note that Shared is an obsolete Ada 83 pragma |
| 5134 |
-- and treated as being identical in effect to pragma Atomic. |
| 5135 |
|
| 5136 |
procedure Process_Compile_Time_Warning_Or_Error; |
| 5137 |
-- Common processing for Compile_Time_Error and Compile_Time_Warning |
| 5138 |
|
| 5139 |
procedure Process_Convention |
| 5140 |
(C : out Convention_Id; |
| 5141 |
Ent : out Entity_Id); |
| 5142 |
-- Common processing for Convention, Interface, Import and Export. |
| 5143 |
-- Checks first two arguments of pragma, and sets the appropriate |
| 5144 |
-- convention value in the specified entity or entities. On return |
| 5145 |
-- C is the convention, Ent is the referenced entity. |
| 5146 |
|
| 5147 |
procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id); |
| 5148 |
-- Common processing for Disable/Enable_Atomic_Synchronization. Nam is |
| 5149 |
-- Name_Suppress for Disable and Name_Unsuppress for Enable. |
| 5150 |
|
| 5151 |
procedure Process_Extended_Import_Export_Object_Pragma |
| 5152 |
(Arg_Internal : Node_Id; |
| 5153 |
Arg_External : Node_Id; |
| 5154 |
Arg_Size : Node_Id); |
| 5155 |
-- Common processing for the pragmas Import/Export_Object. The three |
| 5156 |
-- arguments correspond to the three named parameters of the pragmas. An |
| 5157 |
-- argument is empty if the corresponding parameter is not present in |
| 5158 |
-- the pragma. |
| 5159 |
|
| 5160 |
procedure Process_Extended_Import_Export_Internal_Arg |
| 5161 |
(Arg_Internal : Node_Id := Empty); |
| 5162 |
-- Common processing for all extended Import and Export pragmas. The |
| 5163 |
-- argument is the pragma parameter for the Internal argument. If |
| 5164 |
-- Arg_Internal is empty or inappropriate, an error message is posted. |
| 5165 |
-- Otherwise, on normal return, the Entity_Field of Arg_Internal is |
| 5166 |
-- set to identify the referenced entity. |
| 5167 |
|
| 5168 |
procedure Process_Extended_Import_Export_Subprogram_Pragma |
| 5169 |
(Arg_Internal : Node_Id; |
| 5170 |
Arg_External : Node_Id; |
| 5171 |
Arg_Parameter_Types : Node_Id; |
| 5172 |
Arg_Result_Type : Node_Id := Empty; |
| 5173 |
Arg_Mechanism : Node_Id; |
| 5174 |
Arg_Result_Mechanism : Node_Id := Empty); |
| 5175 |
-- Common processing for all extended Import and Export pragmas applying |
| 5176 |
-- to subprograms. The caller omits any arguments that do not apply to |
| 5177 |
-- the pragma in question (for example, Arg_Result_Type can be non-Empty |
| 5178 |
-- only in the Import_Function and Export_Function cases). The argument |
| 5179 |
-- names correspond to the allowed pragma association identifiers. |
| 5180 |
|
| 5181 |
procedure Process_Generic_List; |
| 5182 |
-- Common processing for Share_Generic and Inline_Generic |
| 5183 |
|
| 5184 |
procedure Process_Import_Or_Interface; |
| 5185 |
-- Common processing for Import or Interface |
| 5186 |
|
| 5187 |
procedure Process_Import_Predefined_Type; |
| 5188 |
-- Processing for completing a type with pragma Import. This is used |
| 5189 |
-- to declare types that match predefined C types, especially for cases |
| 5190 |
-- without corresponding Ada predefined type. |
| 5191 |
|
| 5192 |
type Inline_Status is (Suppressed, Disabled, Enabled); |
| 5193 |
-- Inline status of a subprogram, indicated as follows: |
| 5194 |
-- Suppressed: inlining is suppressed for the subprogram |
| 5195 |
-- Disabled: no inlining is requested for the subprogram |
| 5196 |
-- Enabled: inlining is requested/required for the subprogram |
| 5197 |
|
| 5198 |
procedure Process_Inline (Status : Inline_Status); |
| 5199 |
-- Common processing for No_Inline, Inline and Inline_Always. Parameter |
| 5200 |
-- indicates the inline status specified by the pragma. |
| 5201 |
|
| 5202 |
procedure Process_Interface_Name |
| 5203 |
(Subprogram_Def : Entity_Id; |
| 5204 |
Ext_Arg : Node_Id; |
| 5205 |
Link_Arg : Node_Id; |
| 5206 |
Prag : Node_Id); |
| 5207 |
-- Given the last two arguments of pragma Import, pragma Export, or |
| 5208 |
-- pragma Interface_Name, performs validity checks and sets the |
| 5209 |
-- Interface_Name field of the given subprogram entity to the |
| 5210 |
-- appropriate external or link name, depending on the arguments given. |
| 5211 |
-- Ext_Arg is always present, but Link_Arg may be missing. Note that |
| 5212 |
-- Ext_Arg may represent the Link_Name if Link_Arg is missing, and |
| 5213 |
-- appropriate named notation is used for Ext_Arg. If neither Ext_Arg |
| 5214 |
-- nor Link_Arg is present, the interface name is set to the default |
| 5215 |
-- from the subprogram name. In addition, the pragma itself is passed |
| 5216 |
-- to analyze any expressions in the case the pragma came from an aspect |
| 5217 |
-- specification. |
| 5218 |
|
| 5219 |
procedure Process_Interrupt_Or_Attach_Handler; |
| 5220 |
-- Common processing for Interrupt and Attach_Handler pragmas |
| 5221 |
|
| 5222 |
procedure Process_Restrictions_Or_Restriction_Warnings (Warn : Boolean); |
| 5223 |
-- Common processing for Restrictions and Restriction_Warnings pragmas. |
| 5224 |
-- Warn is True for Restriction_Warnings, or for Restrictions if the |
| 5225 |
-- flag Treat_Restrictions_As_Warnings is set, and False if this flag |
| 5226 |
-- is not set in the Restrictions case. |
| 5227 |
|
| 5228 |
procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean); |
| 5229 |
-- Common processing for Suppress and Unsuppress. The boolean parameter |
| 5230 |
-- Suppress_Case is True for the Suppress case, and False for the |
| 5231 |
-- Unsuppress case. |
| 5232 |
|
| 5233 |
procedure Record_Independence_Check (N : Node_Id; E : Entity_Id); |
| 5234 |
-- Subsidiary to the analysis of pragmas Independent[_Components]. |
| 5235 |
-- Record such a pragma N applied to entity E for future checks. |
| 5236 |
|
| 5237 |
procedure Set_Exported (E : Entity_Id; Arg : Node_Id); |
| 5238 |
-- This procedure sets the Is_Exported flag for the given entity, |
| 5239 |
-- checking that the entity was not previously imported. Arg is |
| 5240 |
-- the argument that specified the entity. A check is also made |
| 5241 |
-- for exporting inappropriate entities. |
| 5242 |
|
| 5243 |
procedure Set_Extended_Import_Export_External_Name |
| 5244 |
(Internal_Ent : Entity_Id; |
| 5245 |
Arg_External : Node_Id); |
| 5246 |
-- Common processing for all extended import export pragmas. The first |
| 5247 |
-- argument, Internal_Ent, is the internal entity, which has already |
| 5248 |
-- been checked for validity by the caller. Arg_External is from the |
| 5249 |
-- Import or Export pragma, and may be null if no External parameter |
| 5250 |
-- was present. If Arg_External is present and is a non-null string |
| 5251 |
-- (a null string is treated as the default), then the Interface_Name |
| 5252 |
-- field of Internal_Ent is set appropriately. |
| 5253 |
|
| 5254 |
procedure Set_Imported (E : Entity_Id); |
| 5255 |
-- This procedure sets the Is_Imported flag for the given entity, |
| 5256 |
-- checking that it is not previously exported or imported. |
| 5257 |
|
| 5258 |
procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id); |
| 5259 |
-- Mech is a parameter passing mechanism (see Import_Function syntax |
| 5260 |
-- for MECHANISM_NAME). This routine checks that the mechanism argument |
| 5261 |
-- has the right form, and if not issues an error message. If the |
| 5262 |
-- argument has the right form then the Mechanism field of Ent is |
| 5263 |
-- set appropriately. |
| 5264 |
|
| 5265 |
procedure Set_Rational_Profile; |
| 5266 |
-- Activate the set of configuration pragmas and permissions that make |
| 5267 |
-- up the Rational profile. |
| 5268 |
|
| 5269 |
procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id); |
| 5270 |
-- Activate the set of configuration pragmas and restrictions that make |
| 5271 |
-- up the Profile. Profile must be either GNAT_Extended_Ravenscar, |
| 5272 |
-- GNAT_Ravenscar_EDF, Jorvik, or Ravenscar. N is the corresponding |
| 5273 |
-- pragma node, which is used for error messages on any constructs |
| 5274 |
-- violating the profile. |
| 5275 |
|
| 5276 |
--------------------- |
| 5277 |
-- Ada_2005_Pragma -- |
| 5278 |
--------------------- |
| 5279 |
|
| 5280 |
procedure Ada_2005_Pragma is |
| 5281 |
begin |
| 5282 |
if Ada_Version <= Ada_95 then |
| 5283 |
Check_Restriction (No_Implementation_Pragmas, N); |
| 5284 |
end if; |
| 5285 |
end Ada_2005_Pragma; |
| 5286 |
|
| 5287 |
--------------------- |
| 5288 |
-- Ada_2012_Pragma -- |
| 5289 |
--------------------- |
| 5290 |
|
| 5291 |
procedure Ada_2012_Pragma is |
| 5292 |
begin |
| 5293 |
if Ada_Version <= Ada_2005 then |
| 5294 |
Check_Restriction (No_Implementation_Pragmas, N); |
| 5295 |
end if; |
| 5296 |
end Ada_2012_Pragma; |
| 5297 |
|
| 5298 |
---------------------------- |
| 5299 |
-- Analyze_Depends_Global -- |
| 5300 |
---------------------------- |
| 5301 |
|
| 5302 |
procedure Analyze_Depends_Global |
| 5303 |
(Spec_Id : out Entity_Id; |
| 5304 |
Subp_Decl : out Node_Id; |
| 5305 |
Legal : out Boolean) |
| 5306 |
is |
| 5307 |
begin |
| 5308 |
-- Assume that the pragma is illegal |
| 5309 |
|
| 5310 |
Spec_Id := Empty; |
| 5311 |
Subp_Decl := Empty; |
| 5312 |
Legal := False; |
| 5313 |
|
| 5314 |
GNAT_Pragma; |
| 5315 |
Check_Arg_Count (1); |
| 5316 |
|
| 5317 |
-- Ensure the proper placement of the pragma. Depends/Global must be |
| 5318 |
-- associated with a subprogram declaration or a body that acts as a |
| 5319 |
-- spec. |
| 5320 |
|
| 5321 |
Subp_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 5322 |
|
| 5323 |
-- Entry |
| 5324 |
|
| 5325 |
if Nkind (Subp_Decl) = N_Entry_Declaration then |
| 5326 |
null; |
| 5327 |
|
| 5328 |
-- Generic subprogram |
| 5329 |
|
| 5330 |
elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 5331 |
null; |
| 5332 |
|
| 5333 |
-- Object declaration of a single concurrent type |
| 5334 |
|
| 5335 |
elsif Nkind (Subp_Decl) = N_Object_Declaration |
| 5336 |
and then Is_Single_Concurrent_Object |
| 5337 |
(Unique_Defining_Entity (Subp_Decl)) |
| 5338 |
then |
| 5339 |
null; |
| 5340 |
|
| 5341 |
-- Single task type |
| 5342 |
|
| 5343 |
elsif Nkind (Subp_Decl) = N_Single_Task_Declaration then |
| 5344 |
null; |
| 5345 |
|
| 5346 |
-- Abstract subprogram declaration |
| 5347 |
|
| 5348 |
elsif Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then |
| 5349 |
null; |
| 5350 |
|
| 5351 |
-- Subprogram body acts as spec |
| 5352 |
|
| 5353 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 5354 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 5355 |
then |
| 5356 |
null; |
| 5357 |
|
| 5358 |
-- Subprogram body stub acts as spec |
| 5359 |
|
| 5360 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 5361 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 5362 |
then |
| 5363 |
null; |
| 5364 |
|
| 5365 |
-- Subprogram declaration |
| 5366 |
|
| 5367 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 5368 |
|
| 5369 |
-- Pragmas Global and Depends are forbidden on null procedures |
| 5370 |
-- (SPARK RM 6.1.2(2)). |
| 5371 |
|
| 5372 |
if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification |
| 5373 |
and then Null_Present (Specification (Subp_Decl)) |
| 5374 |
then |
| 5375 |
Error_Msg_N (Fix_Error |
| 5376 |
("pragma % cannot apply to null procedure"), N); |
| 5377 |
return; |
| 5378 |
end if; |
| 5379 |
|
| 5380 |
-- Task type |
| 5381 |
|
| 5382 |
elsif Nkind (Subp_Decl) = N_Task_Type_Declaration then |
| 5383 |
null; |
| 5384 |
|
| 5385 |
else |
| 5386 |
Pragma_Misplaced; |
| 5387 |
end if; |
| 5388 |
|
| 5389 |
-- If we get here, then the pragma is legal |
| 5390 |
|
| 5391 |
Legal := True; |
| 5392 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 5393 |
|
| 5394 |
-- When the related context is an entry, the entry must belong to a |
| 5395 |
-- protected unit (SPARK RM 6.1.4(6)). |
| 5396 |
|
| 5397 |
if Is_Entry_Declaration (Spec_Id) |
| 5398 |
and then Ekind (Scope (Spec_Id)) /= E_Protected_Type |
| 5399 |
then |
| 5400 |
Pragma_Misplaced; |
| 5401 |
|
| 5402 |
-- When the related context is an anonymous object created for a |
| 5403 |
-- simple concurrent type, the type must be a task |
| 5404 |
-- (SPARK RM 6.1.4(6)). |
| 5405 |
|
| 5406 |
elsif Is_Single_Concurrent_Object (Spec_Id) |
| 5407 |
and then Ekind (Etype (Spec_Id)) /= E_Task_Type |
| 5408 |
then |
| 5409 |
Pragma_Misplaced; |
| 5410 |
end if; |
| 5411 |
|
| 5412 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 5413 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 5414 |
|
| 5415 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 5416 |
Ensure_Aggregate_Form (Get_Argument (N, Spec_Id)); |
| 5417 |
end Analyze_Depends_Global; |
| 5418 |
|
| 5419 |
------------------------ |
| 5420 |
-- Analyze_If_Present -- |
| 5421 |
------------------------ |
| 5422 |
|
| 5423 |
procedure Analyze_If_Present (Id : Pragma_Id) is |
| 5424 |
begin |
| 5425 |
Analyze_If_Present_Internal (N, Id, Included => False); |
| 5426 |
end Analyze_If_Present; |
| 5427 |
|
| 5428 |
-------------------------------- |
| 5429 |
-- Analyze_Pre_Post_Condition -- |
| 5430 |
-------------------------------- |
| 5431 |
|
| 5432 |
procedure Analyze_Pre_Post_Condition is |
| 5433 |
Prag_Iden : constant Node_Id := Pragma_Identifier (N); |
| 5434 |
Subp_Decl : Node_Id; |
| 5435 |
Subp_Id : Entity_Id; |
| 5436 |
|
| 5437 |
Duplicates_OK : Boolean := False; |
| 5438 |
-- Flag set when a pre/postcondition allows multiple pragmas of the |
| 5439 |
-- same kind. |
| 5440 |
|
| 5441 |
In_Body_OK : Boolean := False; |
| 5442 |
-- Flag set when a pre/postcondition is allowed to appear on a body |
| 5443 |
-- even though the subprogram may have a spec. |
| 5444 |
|
| 5445 |
Is_Pre_Post : Boolean := False; |
| 5446 |
-- Flag set when the pragma is one of Pre, Pre_Class, Post or |
| 5447 |
-- Post_Class. |
| 5448 |
|
| 5449 |
function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean; |
| 5450 |
-- Implement rules in AI12-0131: an overriding operation can have |
| 5451 |
-- a class-wide precondition only if one of its ancestors has an |
| 5452 |
-- explicit class-wide precondition. |
| 5453 |
|
| 5454 |
----------------------------- |
| 5455 |
-- Inherits_Class_Wide_Pre -- |
| 5456 |
----------------------------- |
| 5457 |
|
| 5458 |
function Inherits_Class_Wide_Pre (E : Entity_Id) return Boolean is |
| 5459 |
Typ : constant Entity_Id := Find_Dispatching_Type (E); |
| 5460 |
Cont : Node_Id; |
| 5461 |
Prag : Node_Id; |
| 5462 |
Prev : Entity_Id := Overridden_Operation (E); |
| 5463 |
|
| 5464 |
begin |
| 5465 |
-- Check ancestors on the overriding operation to examine the |
| 5466 |
-- preconditions that may apply to them. |
| 5467 |
|
| 5468 |
while Present (Prev) loop |
| 5469 |
Cont := Contract (Prev); |
| 5470 |
if Present (Cont) then |
| 5471 |
Prag := Pre_Post_Conditions (Cont); |
| 5472 |
while Present (Prag) loop |
| 5473 |
if Pragma_Name (Prag) = Name_Precondition |
| 5474 |
and then Class_Present (Prag) |
| 5475 |
then |
| 5476 |
return True; |
| 5477 |
end if; |
| 5478 |
|
| 5479 |
Prag := Next_Pragma (Prag); |
| 5480 |
end loop; |
| 5481 |
end if; |
| 5482 |
|
| 5483 |
-- For a type derived from a generic formal type, the operation |
| 5484 |
-- inheriting the condition is a renaming, not an overriding of |
| 5485 |
-- the operation of the formal. Ditto for an inherited |
| 5486 |
-- operation which has no explicit contracts. |
| 5487 |
|
| 5488 |
if Is_Generic_Type (Find_Dispatching_Type (Prev)) |
| 5489 |
or else not Comes_From_Source (Prev) |
| 5490 |
then |
| 5491 |
Prev := Alias (Prev); |
| 5492 |
else |
| 5493 |
Prev := Overridden_Operation (Prev); |
| 5494 |
end if; |
| 5495 |
end loop; |
| 5496 |
|
| 5497 |
-- If the controlling type of the subprogram has progenitors, an |
| 5498 |
-- interface operation implemented by the current operation may |
| 5499 |
-- have a class-wide precondition. |
| 5500 |
|
| 5501 |
if Has_Interfaces (Typ) then |
| 5502 |
declare |
| 5503 |
Elmt : Elmt_Id; |
| 5504 |
Ints : Elist_Id; |
| 5505 |
Prim : Entity_Id; |
| 5506 |
Prim_Elmt : Elmt_Id; |
| 5507 |
Prim_List : Elist_Id; |
| 5508 |
|
| 5509 |
begin |
| 5510 |
Collect_Interfaces (Typ, Ints); |
| 5511 |
Elmt := First_Elmt (Ints); |
| 5512 |
|
| 5513 |
-- Iterate over the primitive operations of each interface |
| 5514 |
|
| 5515 |
while Present (Elmt) loop |
| 5516 |
Prim_List := Direct_Primitive_Operations (Node (Elmt)); |
| 5517 |
Prim_Elmt := First_Elmt (Prim_List); |
| 5518 |
while Present (Prim_Elmt) loop |
| 5519 |
Prim := Node (Prim_Elmt); |
| 5520 |
if Chars (Prim) = Chars (E) |
| 5521 |
and then Present (Contract (Prim)) |
| 5522 |
and then Class_Present |
| 5523 |
(Pre_Post_Conditions (Contract (Prim))) |
| 5524 |
then |
| 5525 |
return True; |
| 5526 |
end if; |
| 5527 |
|
| 5528 |
Next_Elmt (Prim_Elmt); |
| 5529 |
end loop; |
| 5530 |
|
| 5531 |
Next_Elmt (Elmt); |
| 5532 |
end loop; |
| 5533 |
end; |
| 5534 |
end if; |
| 5535 |
|
| 5536 |
return False; |
| 5537 |
end Inherits_Class_Wide_Pre; |
| 5538 |
|
| 5539 |
-- Start of processing for Analyze_Pre_Post_Condition |
| 5540 |
|
| 5541 |
begin |
| 5542 |
-- Change the name of pragmas Pre, Pre_Class, Post and Post_Class to |
| 5543 |
-- offer uniformity among the various kinds of pre/postconditions by |
| 5544 |
-- rewriting the pragma identifier. This allows the retrieval of the |
| 5545 |
-- original pragma name by routine Original_Aspect_Pragma_Name. |
| 5546 |
|
| 5547 |
if Comes_From_Source (N) then |
| 5548 |
if Pname in Name_Pre | Name_Pre_Class then |
| 5549 |
Is_Pre_Post := True; |
| 5550 |
Set_Class_Present (N, Pname = Name_Pre_Class); |
| 5551 |
Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Precondition)); |
| 5552 |
|
| 5553 |
elsif Pname in Name_Post | Name_Post_Class then |
| 5554 |
Is_Pre_Post := True; |
| 5555 |
Set_Class_Present (N, Pname = Name_Post_Class); |
| 5556 |
Rewrite (Prag_Iden, Make_Identifier (Loc, Name_Postcondition)); |
| 5557 |
end if; |
| 5558 |
end if; |
| 5559 |
|
| 5560 |
-- Determine the semantics with respect to duplicates and placement |
| 5561 |
-- in a body. Pragmas Precondition and Postcondition were introduced |
| 5562 |
-- before aspects and are not subject to the same aspect-like rules. |
| 5563 |
|
| 5564 |
if Pname in Name_Precondition | Name_Postcondition then |
| 5565 |
Duplicates_OK := True; |
| 5566 |
In_Body_OK := True; |
| 5567 |
end if; |
| 5568 |
|
| 5569 |
GNAT_Pragma; |
| 5570 |
|
| 5571 |
-- Pragmas Pre, Pre_Class, Post and Post_Class allow for a single |
| 5572 |
-- argument without an identifier. |
| 5573 |
|
| 5574 |
if Is_Pre_Post then |
| 5575 |
Check_Arg_Count (1); |
| 5576 |
Check_No_Identifiers; |
| 5577 |
|
| 5578 |
-- Pragmas Precondition and Postcondition have complex argument |
| 5579 |
-- profile. |
| 5580 |
|
| 5581 |
else |
| 5582 |
Check_At_Least_N_Arguments (1); |
| 5583 |
Check_At_Most_N_Arguments (2); |
| 5584 |
Check_Optional_Identifier (Arg1, Name_Check); |
| 5585 |
|
| 5586 |
if Present (Arg2) then |
| 5587 |
Check_Optional_Identifier (Arg2, Name_Message); |
| 5588 |
Preanalyze_Assert_Expression |
| 5589 |
(Get_Pragma_Arg (Arg2), Standard_String); |
| 5590 |
end if; |
| 5591 |
end if; |
| 5592 |
|
| 5593 |
-- For a pragma PPC in the extended main source unit, record enabled |
| 5594 |
-- status in SCO. |
| 5595 |
-- ??? nothing checks that the pragma is in the main source unit |
| 5596 |
|
| 5597 |
if Is_Checked (N) then |
| 5598 |
Set_SCO_Pragma_Enabled (Loc); |
| 5599 |
end if; |
| 5600 |
|
| 5601 |
-- Ensure the proper placement of the pragma |
| 5602 |
|
| 5603 |
Subp_Decl := |
| 5604 |
Find_Related_Declaration_Or_Body |
| 5605 |
(N, Do_Checks => not Duplicates_OK); |
| 5606 |
|
| 5607 |
-- Abstract subprogram |
| 5608 |
|
| 5609 |
if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then |
| 5610 |
if not Class_Present (N) then |
| 5611 |
if From_Aspect_Specification (N) then |
| 5612 |
Error_Pragma |
| 5613 |
("aspect % requires ''Class for abstract subprogram"); |
| 5614 |
else |
| 5615 |
Error_Pragma |
| 5616 |
("pragma % cannot be applied to abstract subprogram"); |
| 5617 |
end if; |
| 5618 |
end if; |
| 5619 |
|
| 5620 |
-- Entry declaration |
| 5621 |
|
| 5622 |
elsif Nkind (Subp_Decl) = N_Entry_Declaration then |
| 5623 |
null; |
| 5624 |
|
| 5625 |
-- Generic subprogram declaration |
| 5626 |
|
| 5627 |
elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 5628 |
null; |
| 5629 |
|
| 5630 |
-- Subprogram body |
| 5631 |
|
| 5632 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 5633 |
and then (No (Corresponding_Spec (Subp_Decl)) or In_Body_OK) |
| 5634 |
then |
| 5635 |
null; |
| 5636 |
|
| 5637 |
-- Subprogram body stub |
| 5638 |
|
| 5639 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 5640 |
and then (No (Corresponding_Spec_Of_Stub (Subp_Decl)) or In_Body_OK) |
| 5641 |
then |
| 5642 |
null; |
| 5643 |
|
| 5644 |
-- Subprogram declaration |
| 5645 |
|
| 5646 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 5647 |
|
| 5648 |
-- AI05-0230: When a pre/postcondition pragma applies to a null |
| 5649 |
-- procedure, its original form must be an aspect with 'Class. |
| 5650 |
|
| 5651 |
if Nkind (Specification (Subp_Decl)) = N_Procedure_Specification |
| 5652 |
and then Null_Present (Specification (Subp_Decl)) |
| 5653 |
and then From_Aspect_Specification (N) |
| 5654 |
and then not Class_Present (N) |
| 5655 |
then |
| 5656 |
Error_Pragma ("aspect % requires ''Class for null procedure"); |
| 5657 |
end if; |
| 5658 |
|
| 5659 |
-- Implement the legality checks mandated by AI12-0131: |
| 5660 |
-- Pre'Class shall not be specified for an overriding primitive |
| 5661 |
-- subprogram of a tagged type T unless the Pre'Class aspect is |
| 5662 |
-- specified for the corresponding primitive subprogram of some |
| 5663 |
-- ancestor of T. |
| 5664 |
|
| 5665 |
declare |
| 5666 |
E : constant Entity_Id := Defining_Entity (Subp_Decl); |
| 5667 |
|
| 5668 |
begin |
| 5669 |
if Class_Present (N) |
| 5670 |
and then Pragma_Name (N) = Name_Precondition |
| 5671 |
and then Present (Overridden_Operation (E)) |
| 5672 |
and then not Inherits_Class_Wide_Pre (E) |
| 5673 |
then |
| 5674 |
Error_Msg_N |
| 5675 |
("illegal class-wide precondition on overriding operation", |
| 5676 |
Corresponding_Aspect (N)); |
| 5677 |
end if; |
| 5678 |
end; |
| 5679 |
|
| 5680 |
-- A renaming declaration may inherit a generated pragma, its |
| 5681 |
-- placement comes from expansion, not from source. |
| 5682 |
|
| 5683 |
elsif Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration |
| 5684 |
and then not Comes_From_Source (N) |
| 5685 |
then |
| 5686 |
null; |
| 5687 |
|
| 5688 |
-- For Ada 2022, pre/postconditions can appear on formal subprograms |
| 5689 |
|
| 5690 |
elsif Nkind (Subp_Decl) = N_Formal_Concrete_Subprogram_Declaration |
| 5691 |
and then Ada_Version >= Ada_2022 |
| 5692 |
then |
| 5693 |
null; |
| 5694 |
|
| 5695 |
-- An access-to-subprogram type can have pre/postconditions, which |
| 5696 |
-- are both analyzed when attached to the type and copied to the |
| 5697 |
-- generated subprogram wrapper and analyzed there. |
| 5698 |
|
| 5699 |
elsif Nkind (Subp_Decl) = N_Full_Type_Declaration |
| 5700 |
and then Nkind (Type_Definition (Subp_Decl)) in |
| 5701 |
N_Access_To_Subprogram_Definition |
| 5702 |
then |
| 5703 |
if Ada_Version < Ada_2022 then |
| 5704 |
Error_Msg_Ada_2022_Feature |
| 5705 |
("pre/postcondition on access-to-subprogram", Loc); |
| 5706 |
raise Pragma_Exit; |
| 5707 |
end if; |
| 5708 |
|
| 5709 |
-- Otherwise the placement of the pragma is illegal |
| 5710 |
|
| 5711 |
else |
| 5712 |
Pragma_Misplaced; |
| 5713 |
end if; |
| 5714 |
|
| 5715 |
Subp_Id := Defining_Entity (Subp_Decl); |
| 5716 |
|
| 5717 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 5718 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 5719 |
|
| 5720 |
Mark_Ghost_Pragma (N, Subp_Id); |
| 5721 |
|
| 5722 |
-- Chain the pragma on the contract for further processing by |
| 5723 |
-- Analyze_Pre_Post_Condition_In_Decl_Part. |
| 5724 |
|
| 5725 |
if Chars (Prag_Iden) not in Name_Post_Class |
| 5726 |
| Name_Pre_Class |
| 5727 |
then |
| 5728 |
if Ekind (Subp_Id) in Access_Subprogram_Kind then |
| 5729 |
Add_Contract_Item (N, Directly_Designated_Type (Subp_Id)); |
| 5730 |
else |
| 5731 |
Add_Contract_Item (N, Subp_Id); |
| 5732 |
end if; |
| 5733 |
end if; |
| 5734 |
|
| 5735 |
-- Fully analyze the pragma when it appears inside an entry or |
| 5736 |
-- subprogram body because it cannot benefit from forward references. |
| 5737 |
|
| 5738 |
if Nkind (Subp_Decl) in N_Entry_Body |
| 5739 |
| N_Subprogram_Body |
| 5740 |
| N_Subprogram_Body_Stub |
| 5741 |
then |
| 5742 |
-- The legality checks of pragmas Precondition and Postcondition |
| 5743 |
-- are affected by the SPARK mode in effect and the volatility of |
| 5744 |
-- the context. Analyze all pragmas in a specific order. |
| 5745 |
|
| 5746 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 5747 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 5748 |
Analyze_Pre_Post_Condition_In_Decl_Part (N); |
| 5749 |
end if; |
| 5750 |
|
| 5751 |
-- Complete the decoration of Subp_Id saving in the tree copy of |
| 5752 |
-- class-wide pre/postcondition expression (for aspects this is |
| 5753 |
-- done when the aspect is analyzed). This is required to merge |
| 5754 |
-- the expression with inherited conditions. |
| 5755 |
|
| 5756 |
if Comes_From_Source (N) |
| 5757 |
and then Class_Present (N) |
| 5758 |
and then Is_Subprogram (Subp_Id) |
| 5759 |
then |
| 5760 |
declare |
| 5761 |
Expr : constant Node_Id := Expression (Get_Argument (N)); |
| 5762 |
|
| 5763 |
begin |
| 5764 |
if Pname = Name_Pre_Class then |
| 5765 |
if Is_Ignored (N) then |
| 5766 |
Set_Ignored_Class_Preconditions (Subp_Id, |
| 5767 |
New_Copy_Tree (Expr)); |
| 5768 |
else |
| 5769 |
Set_Class_Preconditions (Subp_Id, New_Copy_Tree (Expr)); |
| 5770 |
end if; |
| 5771 |
|
| 5772 |
else |
| 5773 |
if Is_Ignored (N) then |
| 5774 |
Set_Ignored_Class_Postconditions (Subp_Id, |
| 5775 |
New_Copy_Tree (Expr)); |
| 5776 |
else |
| 5777 |
Set_Class_Postconditions (Subp_Id, New_Copy_Tree (Expr)); |
| 5778 |
end if; |
| 5779 |
end if; |
| 5780 |
end; |
| 5781 |
end if; |
| 5782 |
end Analyze_Pre_Post_Condition; |
| 5783 |
|
| 5784 |
----------------------------------------- |
| 5785 |
-- Analyze_Refined_Depends_Global_Post -- |
| 5786 |
----------------------------------------- |
| 5787 |
|
| 5788 |
procedure Analyze_Refined_Depends_Global_Post |
| 5789 |
(Spec_Id : out Entity_Id; |
| 5790 |
Body_Id : out Entity_Id; |
| 5791 |
Legal : out Boolean) |
| 5792 |
is |
| 5793 |
Body_Decl : Node_Id; |
| 5794 |
Spec_Decl : Node_Id; |
| 5795 |
|
| 5796 |
begin |
| 5797 |
-- Assume that the pragma is illegal |
| 5798 |
|
| 5799 |
Spec_Id := Empty; |
| 5800 |
Body_Id := Empty; |
| 5801 |
Legal := False; |
| 5802 |
|
| 5803 |
GNAT_Pragma; |
| 5804 |
Check_Arg_Count (1); |
| 5805 |
Check_No_Identifiers; |
| 5806 |
|
| 5807 |
-- Verify the placement of the pragma and check for duplicates. The |
| 5808 |
-- pragma must apply to a subprogram body [stub]. |
| 5809 |
|
| 5810 |
Body_Decl := Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 5811 |
|
| 5812 |
if Nkind (Body_Decl) not in |
| 5813 |
N_Entry_Body | N_Subprogram_Body | N_Subprogram_Body_Stub | |
| 5814 |
N_Task_Body | N_Task_Body_Stub |
| 5815 |
then |
| 5816 |
Pragma_Misplaced; |
| 5817 |
end if; |
| 5818 |
|
| 5819 |
Body_Id := Defining_Entity (Body_Decl); |
| 5820 |
Spec_Id := Unique_Defining_Entity (Body_Decl); |
| 5821 |
|
| 5822 |
-- The pragma must apply to the second declaration of a subprogram. |
| 5823 |
-- In other words, the body [stub] cannot acts as a spec. |
| 5824 |
|
| 5825 |
if No (Spec_Id) then |
| 5826 |
Error_Pragma ("pragma % cannot apply to a stand alone body"); |
| 5827 |
|
| 5828 |
-- Catch the case where the subprogram body is a subunit and acts as |
| 5829 |
-- the third declaration of the subprogram. |
| 5830 |
|
| 5831 |
elsif Nkind (Parent (Body_Decl)) = N_Subunit then |
| 5832 |
Error_Pragma ("pragma % cannot apply to a subunit"); |
| 5833 |
end if; |
| 5834 |
|
| 5835 |
-- A refined pragma can only apply to the body [stub] of a subprogram |
| 5836 |
-- declared in the visible part of a package. Retrieve the context of |
| 5837 |
-- the subprogram declaration. |
| 5838 |
|
| 5839 |
Spec_Decl := Unit_Declaration_Node (Spec_Id); |
| 5840 |
|
| 5841 |
-- When dealing with protected entries or protected subprograms, use |
| 5842 |
-- the enclosing protected type as the proper context. |
| 5843 |
|
| 5844 |
if Ekind (Spec_Id) in E_Entry |
| 5845 |
| E_Entry_Family |
| 5846 |
| E_Function |
| 5847 |
| E_Procedure |
| 5848 |
and then Ekind (Scope (Spec_Id)) = E_Protected_Type |
| 5849 |
then |
| 5850 |
Spec_Decl := Declaration_Node (Scope (Spec_Id)); |
| 5851 |
end if; |
| 5852 |
|
| 5853 |
if Nkind (Parent (Spec_Decl)) /= N_Package_Specification then |
| 5854 |
Error_Pragma |
| 5855 |
(Fix_Msg (Spec_Id, "pragma % must apply to the body of " |
| 5856 |
& "subprogram declared in a package specification")); |
| 5857 |
end if; |
| 5858 |
|
| 5859 |
-- If we get here, then the pragma is legal |
| 5860 |
|
| 5861 |
Legal := True; |
| 5862 |
|
| 5863 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 5864 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 5865 |
|
| 5866 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 5867 |
|
| 5868 |
if Pname in Name_Refined_Depends | Name_Refined_Global then |
| 5869 |
Ensure_Aggregate_Form (Get_Argument (N, Spec_Id)); |
| 5870 |
end if; |
| 5871 |
end Analyze_Refined_Depends_Global_Post; |
| 5872 |
|
| 5873 |
---------------------------------- |
| 5874 |
-- Analyze_Unmodified_Or_Unused -- |
| 5875 |
---------------------------------- |
| 5876 |
|
| 5877 |
procedure Analyze_Unmodified_Or_Unused (Is_Unused : Boolean := False) is |
| 5878 |
Arg : Node_Id; |
| 5879 |
Arg_Expr : Node_Id; |
| 5880 |
Arg_Id : Entity_Id; |
| 5881 |
|
| 5882 |
Ghost_Error_Posted : Boolean := False; |
| 5883 |
-- Flag set when an error concerning the illegal mix of Ghost and |
| 5884 |
-- non-Ghost variables is emitted. |
| 5885 |
|
| 5886 |
Ghost_Id : Entity_Id := Empty; |
| 5887 |
-- The entity of the first Ghost variable encountered while |
| 5888 |
-- processing the arguments of the pragma. |
| 5889 |
|
| 5890 |
begin |
| 5891 |
GNAT_Pragma; |
| 5892 |
Check_At_Least_N_Arguments (1); |
| 5893 |
|
| 5894 |
-- Loop through arguments |
| 5895 |
|
| 5896 |
Arg := Arg1; |
| 5897 |
while Present (Arg) loop |
| 5898 |
Check_No_Identifier (Arg); |
| 5899 |
|
| 5900 |
-- Note: the analyze call done by Check_Arg_Is_Local_Name will |
| 5901 |
-- in fact generate reference, so that the entity will have a |
| 5902 |
-- reference, which will inhibit any warnings about it not |
| 5903 |
-- being referenced, and also properly show up in the ali file |
| 5904 |
-- as a reference. But this reference is recorded before the |
| 5905 |
-- Has_Pragma_Unreferenced flag is set, so that no warning is |
| 5906 |
-- generated for this reference. |
| 5907 |
|
| 5908 |
Check_Arg_Is_Local_Name (Arg); |
| 5909 |
Arg_Expr := Get_Pragma_Arg (Arg); |
| 5910 |
|
| 5911 |
if Is_Entity_Name (Arg_Expr) then |
| 5912 |
Arg_Id := Entity (Arg_Expr); |
| 5913 |
|
| 5914 |
-- Skip processing the argument if already flagged |
| 5915 |
|
| 5916 |
if Is_Assignable (Arg_Id) |
| 5917 |
and then not Has_Pragma_Unmodified (Arg_Id) |
| 5918 |
and then not Has_Pragma_Unused (Arg_Id) |
| 5919 |
then |
| 5920 |
Set_Has_Pragma_Unmodified (Arg_Id); |
| 5921 |
|
| 5922 |
if Is_Unused then |
| 5923 |
Set_Has_Pragma_Unused (Arg_Id); |
| 5924 |
end if; |
| 5925 |
|
| 5926 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 5927 |
-- the purposes of legality checks and removal of ignored |
| 5928 |
-- Ghost code. |
| 5929 |
|
| 5930 |
Mark_Ghost_Pragma (N, Arg_Id); |
| 5931 |
|
| 5932 |
-- Capture the entity of the first Ghost variable being |
| 5933 |
-- processed for error detection purposes. |
| 5934 |
|
| 5935 |
if Is_Ghost_Entity (Arg_Id) then |
| 5936 |
if No (Ghost_Id) then |
| 5937 |
Ghost_Id := Arg_Id; |
| 5938 |
end if; |
| 5939 |
|
| 5940 |
-- Otherwise the variable is non-Ghost. It is illegal to mix |
| 5941 |
-- references to Ghost and non-Ghost entities |
| 5942 |
-- (SPARK RM 6.9). |
| 5943 |
|
| 5944 |
elsif Present (Ghost_Id) |
| 5945 |
and then not Ghost_Error_Posted |
| 5946 |
then |
| 5947 |
Ghost_Error_Posted := True; |
| 5948 |
|
| 5949 |
Error_Msg_Name_1 := Pname; |
| 5950 |
Error_Msg_N |
| 5951 |
("pragma % cannot mention ghost and non-ghost " |
| 5952 |
& "variables", N); |
| 5953 |
|
| 5954 |
Error_Msg_Sloc := Sloc (Ghost_Id); |
| 5955 |
Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id); |
| 5956 |
|
| 5957 |
Error_Msg_Sloc := Sloc (Arg_Id); |
| 5958 |
Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id); |
| 5959 |
end if; |
| 5960 |
|
| 5961 |
-- Warn if already flagged as Unused or Unmodified |
| 5962 |
|
| 5963 |
elsif Has_Pragma_Unmodified (Arg_Id) then |
| 5964 |
if Has_Pragma_Unused (Arg_Id) then |
| 5965 |
Error_Msg_NE |
| 5966 |
(Fix_Error ("??pragma Unused already given for &!"), |
| 5967 |
Arg_Expr, Arg_Id); |
| 5968 |
else |
| 5969 |
Error_Msg_NE |
| 5970 |
(Fix_Error ("??pragma Unmodified already given for &!"), |
| 5971 |
Arg_Expr, Arg_Id); |
| 5972 |
end if; |
| 5973 |
|
| 5974 |
-- Otherwise the pragma referenced an illegal entity |
| 5975 |
|
| 5976 |
else |
| 5977 |
Error_Pragma_Arg |
| 5978 |
("pragma% can only be applied to a variable", Arg_Expr); |
| 5979 |
end if; |
| 5980 |
end if; |
| 5981 |
|
| 5982 |
Next (Arg); |
| 5983 |
end loop; |
| 5984 |
end Analyze_Unmodified_Or_Unused; |
| 5985 |
|
| 5986 |
------------------------------------ |
| 5987 |
-- Analyze_Unreferenced_Or_Unused -- |
| 5988 |
------------------------------------ |
| 5989 |
|
| 5990 |
procedure Analyze_Unreferenced_Or_Unused |
| 5991 |
(Is_Unused : Boolean := False) |
| 5992 |
is |
| 5993 |
Arg : Node_Id; |
| 5994 |
Arg_Expr : Node_Id; |
| 5995 |
Arg_Id : Entity_Id; |
| 5996 |
Citem : Node_Id; |
| 5997 |
|
| 5998 |
Ghost_Error_Posted : Boolean := False; |
| 5999 |
-- Flag set when an error concerning the illegal mix of Ghost and |
| 6000 |
-- non-Ghost names is emitted. |
| 6001 |
|
| 6002 |
Ghost_Id : Entity_Id := Empty; |
| 6003 |
-- The entity of the first Ghost name encountered while processing |
| 6004 |
-- the arguments of the pragma. |
| 6005 |
|
| 6006 |
begin |
| 6007 |
GNAT_Pragma; |
| 6008 |
Check_At_Least_N_Arguments (1); |
| 6009 |
|
| 6010 |
-- Check case of appearing within context clause |
| 6011 |
|
| 6012 |
if not Is_Unused and then Is_In_Context_Clause then |
| 6013 |
|
| 6014 |
-- The arguments must all be units mentioned in a with clause in |
| 6015 |
-- the same context clause. Note that Par.Prag already checked |
| 6016 |
-- that the arguments are either identifiers or selected |
| 6017 |
-- components. |
| 6018 |
|
| 6019 |
Arg := Arg1; |
| 6020 |
while Present (Arg) loop |
| 6021 |
Citem := First (List_Containing (N)); |
| 6022 |
while Citem /= N loop |
| 6023 |
Arg_Expr := Get_Pragma_Arg (Arg); |
| 6024 |
|
| 6025 |
if Nkind (Citem) = N_With_Clause |
| 6026 |
and then Same_Name (Name (Citem), Arg_Expr) |
| 6027 |
then |
| 6028 |
Set_Has_Pragma_Unreferenced |
| 6029 |
(Cunit_Entity |
| 6030 |
(Get_Source_Unit (Withed_Lib_Unit (Citem)))); |
| 6031 |
Set_Elab_Unit_Name (Arg_Expr, Name (Citem)); |
| 6032 |
exit; |
| 6033 |
end if; |
| 6034 |
|
| 6035 |
Next (Citem); |
| 6036 |
end loop; |
| 6037 |
|
| 6038 |
if Citem = N then |
| 6039 |
Error_Pragma_Arg |
| 6040 |
("argument of pragma% is not withed unit", Arg); |
| 6041 |
end if; |
| 6042 |
|
| 6043 |
Next (Arg); |
| 6044 |
end loop; |
| 6045 |
|
| 6046 |
-- Case of not in list of context items |
| 6047 |
|
| 6048 |
else |
| 6049 |
Arg := Arg1; |
| 6050 |
while Present (Arg) loop |
| 6051 |
Check_No_Identifier (Arg); |
| 6052 |
|
| 6053 |
-- Note: the analyze call done by Check_Arg_Is_Local_Name will |
| 6054 |
-- in fact generate reference, so that the entity will have a |
| 6055 |
-- reference, which will inhibit any warnings about it not |
| 6056 |
-- being referenced, and also properly show up in the ali file |
| 6057 |
-- as a reference. But this reference is recorded before the |
| 6058 |
-- Has_Pragma_Unreferenced flag is set, so that no warning is |
| 6059 |
-- generated for this reference. |
| 6060 |
|
| 6061 |
Check_Arg_Is_Local_Name (Arg); |
| 6062 |
Arg_Expr := Get_Pragma_Arg (Arg); |
| 6063 |
|
| 6064 |
if Is_Entity_Name (Arg_Expr) then |
| 6065 |
Arg_Id := Entity (Arg_Expr); |
| 6066 |
|
| 6067 |
-- Warn if already flagged as Unused or Unreferenced and |
| 6068 |
-- skip processing the argument. |
| 6069 |
|
| 6070 |
if Has_Pragma_Unreferenced (Arg_Id) then |
| 6071 |
if Has_Pragma_Unused (Arg_Id) then |
| 6072 |
Error_Msg_NE |
| 6073 |
(Fix_Error ("??pragma Unused already given for &!"), |
| 6074 |
Arg_Expr, Arg_Id); |
| 6075 |
else |
| 6076 |
Error_Msg_NE |
| 6077 |
(Fix_Error |
| 6078 |
("??pragma Unreferenced already given for &!"), |
| 6079 |
Arg_Expr, Arg_Id); |
| 6080 |
end if; |
| 6081 |
|
| 6082 |
-- Apply Unreferenced to the entity |
| 6083 |
|
| 6084 |
else |
| 6085 |
-- If the entity is overloaded, the pragma applies to the |
| 6086 |
-- most recent overloading, as documented. In this case, |
| 6087 |
-- name resolution does not generate a reference, so it |
| 6088 |
-- must be done here explicitly. |
| 6089 |
|
| 6090 |
if Is_Overloaded (Arg_Expr) then |
| 6091 |
Generate_Reference (Arg_Id, N); |
| 6092 |
end if; |
| 6093 |
|
| 6094 |
Set_Has_Pragma_Unreferenced (Arg_Id); |
| 6095 |
|
| 6096 |
if Is_Unused then |
| 6097 |
Set_Has_Pragma_Unused (Arg_Id); |
| 6098 |
end if; |
| 6099 |
|
| 6100 |
-- A pragma that applies to a Ghost entity becomes Ghost |
| 6101 |
-- for the purposes of legality checks and removal of |
| 6102 |
-- ignored Ghost code. |
| 6103 |
|
| 6104 |
Mark_Ghost_Pragma (N, Arg_Id); |
| 6105 |
|
| 6106 |
-- Capture the entity of the first Ghost name being |
| 6107 |
-- processed for error detection purposes. |
| 6108 |
|
| 6109 |
if Is_Ghost_Entity (Arg_Id) then |
| 6110 |
if No (Ghost_Id) then |
| 6111 |
Ghost_Id := Arg_Id; |
| 6112 |
end if; |
| 6113 |
|
| 6114 |
-- Otherwise the name is non-Ghost. It is illegal to mix |
| 6115 |
-- references to Ghost and non-Ghost entities |
| 6116 |
-- (SPARK RM 6.9). |
| 6117 |
|
| 6118 |
elsif Present (Ghost_Id) |
| 6119 |
and then not Ghost_Error_Posted |
| 6120 |
then |
| 6121 |
Ghost_Error_Posted := True; |
| 6122 |
|
| 6123 |
Error_Msg_Name_1 := Pname; |
| 6124 |
Error_Msg_N |
| 6125 |
("pragma % cannot mention ghost and non-ghost " |
| 6126 |
& "names", N); |
| 6127 |
|
| 6128 |
Error_Msg_Sloc := Sloc (Ghost_Id); |
| 6129 |
Error_Msg_NE |
| 6130 |
("\& # declared as ghost", N, Ghost_Id); |
| 6131 |
|
| 6132 |
Error_Msg_Sloc := Sloc (Arg_Id); |
| 6133 |
Error_Msg_NE |
| 6134 |
("\& # declared as non-ghost", N, Arg_Id); |
| 6135 |
end if; |
| 6136 |
end if; |
| 6137 |
end if; |
| 6138 |
|
| 6139 |
Next (Arg); |
| 6140 |
end loop; |
| 6141 |
end if; |
| 6142 |
end Analyze_Unreferenced_Or_Unused; |
| 6143 |
|
| 6144 |
-------------------------- |
| 6145 |
-- Check_Ada_83_Warning -- |
| 6146 |
-------------------------- |
| 6147 |
|
| 6148 |
procedure Check_Ada_83_Warning is |
| 6149 |
begin |
| 6150 |
if Ada_Version = Ada_83 and then Comes_From_Source (N) then |
| 6151 |
Error_Msg_N ("(Ada 83) pragma& is non-standard??", N); |
| 6152 |
end if; |
| 6153 |
end Check_Ada_83_Warning; |
| 6154 |
|
| 6155 |
--------------------- |
| 6156 |
-- Check_Arg_Count -- |
| 6157 |
--------------------- |
| 6158 |
|
| 6159 |
procedure Check_Arg_Count (Required : Nat) is |
| 6160 |
begin |
| 6161 |
if Arg_Count /= Required then |
| 6162 |
Error_Pragma ("wrong number of arguments for pragma%"); |
| 6163 |
end if; |
| 6164 |
end Check_Arg_Count; |
| 6165 |
|
| 6166 |
-------------------------------- |
| 6167 |
-- Check_Arg_Is_External_Name -- |
| 6168 |
-------------------------------- |
| 6169 |
|
| 6170 |
procedure Check_Arg_Is_External_Name (Arg : Node_Id) is |
| 6171 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6172 |
|
| 6173 |
begin |
| 6174 |
if Nkind (Argx) = N_Identifier then |
| 6175 |
return; |
| 6176 |
|
| 6177 |
else |
| 6178 |
Analyze_And_Resolve (Argx, Standard_String); |
| 6179 |
|
| 6180 |
if Is_OK_Static_Expression (Argx) then |
| 6181 |
return; |
| 6182 |
|
| 6183 |
elsif Etype (Argx) = Any_Type then |
| 6184 |
raise Pragma_Exit; |
| 6185 |
|
| 6186 |
-- An interesting special case, if we have a string literal and |
| 6187 |
-- we are in Ada 83 mode, then we allow it even though it will |
| 6188 |
-- not be flagged as static. This allows expected Ada 83 mode |
| 6189 |
-- use of external names which are string literals, even though |
| 6190 |
-- technically these are not static in Ada 83. |
| 6191 |
|
| 6192 |
elsif Ada_Version = Ada_83 |
| 6193 |
and then Nkind (Argx) = N_String_Literal |
| 6194 |
then |
| 6195 |
return; |
| 6196 |
|
| 6197 |
-- Here we have a real error (non-static expression) |
| 6198 |
|
| 6199 |
else |
| 6200 |
Error_Msg_Name_1 := Pname; |
| 6201 |
Flag_Non_Static_Expr |
| 6202 |
(Fix_Error ("argument for pragma% must be a identifier or " |
| 6203 |
& "static string expression!"), Argx); |
| 6204 |
|
| 6205 |
raise Pragma_Exit; |
| 6206 |
end if; |
| 6207 |
end if; |
| 6208 |
end Check_Arg_Is_External_Name; |
| 6209 |
|
| 6210 |
----------------------------- |
| 6211 |
-- Check_Arg_Is_Identifier -- |
| 6212 |
----------------------------- |
| 6213 |
|
| 6214 |
procedure Check_Arg_Is_Identifier (Arg : Node_Id) is |
| 6215 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6216 |
begin |
| 6217 |
if Nkind (Argx) /= N_Identifier then |
| 6218 |
Error_Pragma_Arg ("argument for pragma% must be identifier", Argx); |
| 6219 |
end if; |
| 6220 |
end Check_Arg_Is_Identifier; |
| 6221 |
|
| 6222 |
---------------------------------- |
| 6223 |
-- Check_Arg_Is_Integer_Literal -- |
| 6224 |
---------------------------------- |
| 6225 |
|
| 6226 |
procedure Check_Arg_Is_Integer_Literal (Arg : Node_Id) is |
| 6227 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6228 |
begin |
| 6229 |
if Nkind (Argx) /= N_Integer_Literal then |
| 6230 |
Error_Pragma_Arg |
| 6231 |
("argument for pragma% must be integer literal", Argx); |
| 6232 |
end if; |
| 6233 |
end Check_Arg_Is_Integer_Literal; |
| 6234 |
|
| 6235 |
------------------------------------------- |
| 6236 |
-- Check_Arg_Is_Library_Level_Local_Name -- |
| 6237 |
------------------------------------------- |
| 6238 |
|
| 6239 |
-- LOCAL_NAME ::= |
| 6240 |
-- DIRECT_NAME |
| 6241 |
-- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR |
| 6242 |
-- | library_unit_NAME |
| 6243 |
|
| 6244 |
procedure Check_Arg_Is_Library_Level_Local_Name (Arg : Node_Id) is |
| 6245 |
begin |
| 6246 |
Check_Arg_Is_Local_Name (Arg); |
| 6247 |
|
| 6248 |
-- If it came from an aspect, we want to give the error just as if it |
| 6249 |
-- came from source. |
| 6250 |
|
| 6251 |
if not Is_Library_Level_Entity (Entity (Get_Pragma_Arg (Arg))) |
| 6252 |
and then (Comes_From_Source (N) |
| 6253 |
or else Present (Corresponding_Aspect (Parent (Arg)))) |
| 6254 |
then |
| 6255 |
Error_Pragma_Arg |
| 6256 |
("argument for pragma% must be library level entity", Arg); |
| 6257 |
end if; |
| 6258 |
end Check_Arg_Is_Library_Level_Local_Name; |
| 6259 |
|
| 6260 |
----------------------------- |
| 6261 |
-- Check_Arg_Is_Local_Name -- |
| 6262 |
----------------------------- |
| 6263 |
|
| 6264 |
-- LOCAL_NAME ::= |
| 6265 |
-- DIRECT_NAME |
| 6266 |
-- | DIRECT_NAME'ATTRIBUTE_DESIGNATOR |
| 6267 |
-- | library_unit_NAME |
| 6268 |
|
| 6269 |
procedure Check_Arg_Is_Local_Name (Arg : Node_Id) is |
| 6270 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6271 |
|
| 6272 |
begin |
| 6273 |
-- If this pragma came from an aspect specification, we don't want to |
| 6274 |
-- check for this error, because that would cause spurious errors, in |
| 6275 |
-- case a type is frozen in a scope more nested than the type. The |
| 6276 |
-- aspect itself of course can't be anywhere but on the declaration |
| 6277 |
-- itself. |
| 6278 |
|
| 6279 |
if Nkind (Arg) = N_Pragma_Argument_Association then |
| 6280 |
if From_Aspect_Specification (Parent (Arg)) then |
| 6281 |
return; |
| 6282 |
end if; |
| 6283 |
|
| 6284 |
-- Arg is the Expression of an N_Pragma_Argument_Association |
| 6285 |
|
| 6286 |
else |
| 6287 |
if From_Aspect_Specification (Parent (Parent (Arg))) then |
| 6288 |
return; |
| 6289 |
end if; |
| 6290 |
end if; |
| 6291 |
|
| 6292 |
Analyze (Argx); |
| 6293 |
|
| 6294 |
if Nkind (Argx) not in N_Direct_Name |
| 6295 |
and then (Nkind (Argx) /= N_Attribute_Reference |
| 6296 |
or else Present (Expressions (Argx)) |
| 6297 |
or else Nkind (Prefix (Argx)) /= N_Identifier) |
| 6298 |
and then (not Is_Entity_Name (Argx) |
| 6299 |
or else not Is_Compilation_Unit (Entity (Argx))) |
| 6300 |
then |
| 6301 |
Error_Pragma_Arg ("argument for pragma% must be local name", Argx); |
| 6302 |
end if; |
| 6303 |
|
| 6304 |
-- No further check required if not an entity name |
| 6305 |
|
| 6306 |
if not Is_Entity_Name (Argx) then |
| 6307 |
null; |
| 6308 |
|
| 6309 |
else |
| 6310 |
declare |
| 6311 |
OK : Boolean; |
| 6312 |
Ent : constant Entity_Id := Entity (Argx); |
| 6313 |
Scop : constant Entity_Id := Scope (Ent); |
| 6314 |
|
| 6315 |
begin |
| 6316 |
-- Case of a pragma applied to a compilation unit: pragma must |
| 6317 |
-- occur immediately after the program unit in the compilation. |
| 6318 |
|
| 6319 |
if Is_Compilation_Unit (Ent) then |
| 6320 |
declare |
| 6321 |
Decl : constant Node_Id := Unit_Declaration_Node (Ent); |
| 6322 |
|
| 6323 |
begin |
| 6324 |
-- Case of pragma placed immediately after spec |
| 6325 |
|
| 6326 |
if Parent (N) = Aux_Decls_Node (Parent (Decl)) then |
| 6327 |
OK := True; |
| 6328 |
|
| 6329 |
-- Case of pragma placed immediately after body |
| 6330 |
|
| 6331 |
elsif Nkind (Decl) = N_Subprogram_Declaration |
| 6332 |
and then Present (Corresponding_Body (Decl)) |
| 6333 |
then |
| 6334 |
OK := Parent (N) = |
| 6335 |
Aux_Decls_Node |
| 6336 |
(Parent (Unit_Declaration_Node |
| 6337 |
(Corresponding_Body (Decl)))); |
| 6338 |
|
| 6339 |
-- All other cases are illegal |
| 6340 |
|
| 6341 |
else |
| 6342 |
OK := False; |
| 6343 |
end if; |
| 6344 |
end; |
| 6345 |
|
| 6346 |
-- Special restricted placement rule from 10.2.1(11.8/2) |
| 6347 |
|
| 6348 |
elsif Is_Generic_Formal (Ent) |
| 6349 |
and then Prag_Id = Pragma_Preelaborable_Initialization |
| 6350 |
then |
| 6351 |
OK := List_Containing (N) = |
| 6352 |
Generic_Formal_Declarations |
| 6353 |
(Unit_Declaration_Node (Scop)); |
| 6354 |
|
| 6355 |
-- If this is an aspect applied to a subprogram body, the |
| 6356 |
-- pragma is inserted in its declarative part. |
| 6357 |
|
| 6358 |
elsif From_Aspect_Specification (N) |
| 6359 |
and then Ent = Current_Scope |
| 6360 |
and then |
| 6361 |
Nkind (Unit_Declaration_Node (Ent)) = N_Subprogram_Body |
| 6362 |
then |
| 6363 |
OK := True; |
| 6364 |
|
| 6365 |
-- If the aspect is a predicate (possibly others ???) and the |
| 6366 |
-- context is a record type, this is a discriminant expression |
| 6367 |
-- within a type declaration, that freezes the predicated |
| 6368 |
-- subtype. |
| 6369 |
|
| 6370 |
elsif From_Aspect_Specification (N) |
| 6371 |
and then Prag_Id = Pragma_Predicate |
| 6372 |
and then Ekind (Current_Scope) = E_Record_Type |
| 6373 |
and then Scop = Scope (Current_Scope) |
| 6374 |
then |
| 6375 |
OK := True; |
| 6376 |
|
| 6377 |
-- Special case for postconditions wrappers |
| 6378 |
|
| 6379 |
elsif Ekind (Scop) in Subprogram_Kind |
| 6380 |
and then Present (Wrapped_Statements (Scop)) |
| 6381 |
and then Wrapped_Statements (Scop) = Current_Scope |
| 6382 |
then |
| 6383 |
OK := True; |
| 6384 |
|
| 6385 |
-- Default case, just check that the pragma occurs in the scope |
| 6386 |
-- of the entity denoted by the name. |
| 6387 |
|
| 6388 |
else |
| 6389 |
OK := Current_Scope = Scop; |
| 6390 |
end if; |
| 6391 |
|
| 6392 |
if not OK then |
| 6393 |
Error_Pragma_Arg |
| 6394 |
("pragma% argument must be in same declarative part", Arg); |
| 6395 |
end if; |
| 6396 |
end; |
| 6397 |
end if; |
| 6398 |
end Check_Arg_Is_Local_Name; |
| 6399 |
|
| 6400 |
--------------------------------- |
| 6401 |
-- Check_Arg_Is_Locking_Policy -- |
| 6402 |
--------------------------------- |
| 6403 |
|
| 6404 |
procedure Check_Arg_Is_Locking_Policy (Arg : Node_Id) is |
| 6405 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6406 |
|
| 6407 |
begin |
| 6408 |
Check_Arg_Is_Identifier (Argx); |
| 6409 |
|
| 6410 |
if not Is_Locking_Policy_Name (Chars (Argx)) then |
| 6411 |
Error_Pragma_Arg ("& is not a valid locking policy name", Argx); |
| 6412 |
end if; |
| 6413 |
end Check_Arg_Is_Locking_Policy; |
| 6414 |
|
| 6415 |
----------------------------------------------- |
| 6416 |
-- Check_Arg_Is_Partition_Elaboration_Policy -- |
| 6417 |
----------------------------------------------- |
| 6418 |
|
| 6419 |
procedure Check_Arg_Is_Partition_Elaboration_Policy (Arg : Node_Id) is |
| 6420 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6421 |
|
| 6422 |
begin |
| 6423 |
Check_Arg_Is_Identifier (Argx); |
| 6424 |
|
| 6425 |
if not Is_Partition_Elaboration_Policy_Name (Chars (Argx)) then |
| 6426 |
Error_Pragma_Arg |
| 6427 |
("& is not a valid partition elaboration policy name", Argx); |
| 6428 |
end if; |
| 6429 |
end Check_Arg_Is_Partition_Elaboration_Policy; |
| 6430 |
|
| 6431 |
------------------------- |
| 6432 |
-- Check_Arg_Is_One_Of -- |
| 6433 |
------------------------- |
| 6434 |
|
| 6435 |
procedure Check_Arg_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is |
| 6436 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6437 |
|
| 6438 |
begin |
| 6439 |
Check_Arg_Is_Identifier (Argx); |
| 6440 |
|
| 6441 |
if Chars (Argx) not in N1 | N2 then |
| 6442 |
Error_Msg_Name_2 := N1; |
| 6443 |
Error_Msg_Name_3 := N2; |
| 6444 |
Error_Pragma_Arg ("argument for pragma% must be% or%", Argx); |
| 6445 |
end if; |
| 6446 |
end Check_Arg_Is_One_Of; |
| 6447 |
|
| 6448 |
procedure Check_Arg_Is_One_Of |
| 6449 |
(Arg : Node_Id; |
| 6450 |
N1, N2, N3 : Name_Id) |
| 6451 |
is |
| 6452 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6453 |
|
| 6454 |
begin |
| 6455 |
Check_Arg_Is_Identifier (Argx); |
| 6456 |
|
| 6457 |
if Chars (Argx) not in N1 | N2 | N3 then |
| 6458 |
Error_Pragma_Arg ("invalid argument for pragma%", Argx); |
| 6459 |
end if; |
| 6460 |
end Check_Arg_Is_One_Of; |
| 6461 |
|
| 6462 |
procedure Check_Arg_Is_One_Of |
| 6463 |
(Arg : Node_Id; |
| 6464 |
N1, N2, N3, N4 : Name_Id) |
| 6465 |
is |
| 6466 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6467 |
|
| 6468 |
begin |
| 6469 |
Check_Arg_Is_Identifier (Argx); |
| 6470 |
|
| 6471 |
if Chars (Argx) not in N1 | N2 | N3 | N4 then |
| 6472 |
Error_Pragma_Arg ("invalid argument for pragma%", Argx); |
| 6473 |
end if; |
| 6474 |
end Check_Arg_Is_One_Of; |
| 6475 |
|
| 6476 |
procedure Check_Arg_Is_One_Of |
| 6477 |
(Arg : Node_Id; |
| 6478 |
N1, N2, N3, N4, N5 : Name_Id) |
| 6479 |
is |
| 6480 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6481 |
|
| 6482 |
begin |
| 6483 |
Check_Arg_Is_Identifier (Argx); |
| 6484 |
|
| 6485 |
if Chars (Argx) not in N1 | N2 | N3 | N4 | N5 then |
| 6486 |
Error_Pragma_Arg ("invalid argument for pragma%", Argx); |
| 6487 |
end if; |
| 6488 |
end Check_Arg_Is_One_Of; |
| 6489 |
|
| 6490 |
--------------------------------- |
| 6491 |
-- Check_Arg_Is_Queuing_Policy -- |
| 6492 |
--------------------------------- |
| 6493 |
|
| 6494 |
procedure Check_Arg_Is_Queuing_Policy (Arg : Node_Id) is |
| 6495 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6496 |
|
| 6497 |
begin |
| 6498 |
Check_Arg_Is_Identifier (Argx); |
| 6499 |
|
| 6500 |
if not Is_Queuing_Policy_Name (Chars (Argx)) then |
| 6501 |
Error_Pragma_Arg ("& is not a valid queuing policy name", Argx); |
| 6502 |
end if; |
| 6503 |
end Check_Arg_Is_Queuing_Policy; |
| 6504 |
|
| 6505 |
--------------------------------------- |
| 6506 |
-- Check_Arg_Is_OK_Static_Expression -- |
| 6507 |
--------------------------------------- |
| 6508 |
|
| 6509 |
procedure Check_Arg_Is_OK_Static_Expression |
| 6510 |
(Arg : Node_Id; |
| 6511 |
Typ : Entity_Id := Empty) |
| 6512 |
is |
| 6513 |
begin |
| 6514 |
Check_Expr_Is_OK_Static_Expression (Get_Pragma_Arg (Arg), Typ); |
| 6515 |
end Check_Arg_Is_OK_Static_Expression; |
| 6516 |
|
| 6517 |
------------------------------------------ |
| 6518 |
-- Check_Arg_Is_Task_Dispatching_Policy -- |
| 6519 |
------------------------------------------ |
| 6520 |
|
| 6521 |
procedure Check_Arg_Is_Task_Dispatching_Policy (Arg : Node_Id) is |
| 6522 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6523 |
|
| 6524 |
begin |
| 6525 |
Check_Arg_Is_Identifier (Argx); |
| 6526 |
|
| 6527 |
if not Is_Task_Dispatching_Policy_Name (Chars (Argx)) then |
| 6528 |
Error_Pragma_Arg |
| 6529 |
("& is not an allowed task dispatching policy name", Argx); |
| 6530 |
end if; |
| 6531 |
end Check_Arg_Is_Task_Dispatching_Policy; |
| 6532 |
|
| 6533 |
--------------------- |
| 6534 |
-- Check_Arg_Order -- |
| 6535 |
--------------------- |
| 6536 |
|
| 6537 |
procedure Check_Arg_Order (Names : Name_List) is |
| 6538 |
Arg : Node_Id; |
| 6539 |
|
| 6540 |
Highest_So_Far : Natural := 0; |
| 6541 |
-- Highest index in Names seen do far |
| 6542 |
|
| 6543 |
begin |
| 6544 |
Arg := Arg1; |
| 6545 |
for J in 1 .. Arg_Count loop |
| 6546 |
if Chars (Arg) /= No_Name then |
| 6547 |
for K in Names'Range loop |
| 6548 |
if Chars (Arg) = Names (K) then |
| 6549 |
if K < Highest_So_Far then |
| 6550 |
Error_Msg_Name_1 := Pname; |
| 6551 |
Error_Msg_N |
| 6552 |
("parameters out of order for pragma%", Arg); |
| 6553 |
Error_Msg_Name_1 := Names (K); |
| 6554 |
Error_Msg_Name_2 := Names (Highest_So_Far); |
| 6555 |
Error_Msg_N ("\% must appear before %", Arg); |
| 6556 |
raise Pragma_Exit; |
| 6557 |
|
| 6558 |
else |
| 6559 |
Highest_So_Far := K; |
| 6560 |
end if; |
| 6561 |
end if; |
| 6562 |
end loop; |
| 6563 |
end if; |
| 6564 |
|
| 6565 |
Arg := Next (Arg); |
| 6566 |
end loop; |
| 6567 |
end Check_Arg_Order; |
| 6568 |
|
| 6569 |
-------------------------------- |
| 6570 |
-- Check_At_Least_N_Arguments -- |
| 6571 |
-------------------------------- |
| 6572 |
|
| 6573 |
procedure Check_At_Least_N_Arguments (N : Nat) is |
| 6574 |
begin |
| 6575 |
if Arg_Count < N then |
| 6576 |
Error_Pragma ("too few arguments for pragma%"); |
| 6577 |
end if; |
| 6578 |
end Check_At_Least_N_Arguments; |
| 6579 |
|
| 6580 |
------------------------------- |
| 6581 |
-- Check_At_Most_N_Arguments -- |
| 6582 |
------------------------------- |
| 6583 |
|
| 6584 |
procedure Check_At_Most_N_Arguments (N : Nat) is |
| 6585 |
Arg : Node_Id; |
| 6586 |
begin |
| 6587 |
if Arg_Count > N then |
| 6588 |
Arg := Arg1; |
| 6589 |
for J in 1 .. N loop |
| 6590 |
Next (Arg); |
| 6591 |
Error_Pragma_Arg ("too many arguments for pragma%", Arg); |
| 6592 |
end loop; |
| 6593 |
end if; |
| 6594 |
end Check_At_Most_N_Arguments; |
| 6595 |
|
| 6596 |
--------------------- |
| 6597 |
-- Check_Component -- |
| 6598 |
--------------------- |
| 6599 |
|
| 6600 |
procedure Check_Component |
| 6601 |
(Comp : Node_Id; |
| 6602 |
UU_Typ : Entity_Id; |
| 6603 |
In_Variant_Part : Boolean := False) |
| 6604 |
is |
| 6605 |
Comp_Id : constant Entity_Id := Defining_Identifier (Comp); |
| 6606 |
Sindic : constant Node_Id := |
| 6607 |
Subtype_Indication (Component_Definition (Comp)); |
| 6608 |
Typ : constant Entity_Id := Etype (Comp_Id); |
| 6609 |
|
| 6610 |
begin |
| 6611 |
-- Ada 2005 (AI-216): If a component subtype is subject to a per- |
| 6612 |
-- object constraint, then the component type shall be an Unchecked_ |
| 6613 |
-- Union. |
| 6614 |
|
| 6615 |
if Nkind (Sindic) = N_Subtype_Indication |
| 6616 |
and then Has_Per_Object_Constraint (Comp_Id) |
| 6617 |
and then not Is_Unchecked_Union (Etype (Subtype_Mark (Sindic))) |
| 6618 |
then |
| 6619 |
Error_Msg_N |
| 6620 |
("component subtype subject to per-object constraint " |
| 6621 |
& "must be an Unchecked_Union", Comp); |
| 6622 |
|
| 6623 |
-- Ada 2012 (AI05-0026): For an unchecked union type declared within |
| 6624 |
-- the body of a generic unit, or within the body of any of its |
| 6625 |
-- descendant library units, no part of the type of a component |
| 6626 |
-- declared in a variant_part of the unchecked union type shall be of |
| 6627 |
-- a formal private type or formal private extension declared within |
| 6628 |
-- the formal part of the generic unit. |
| 6629 |
|
| 6630 |
elsif Ada_Version >= Ada_2012 |
| 6631 |
and then In_Generic_Body (UU_Typ) |
| 6632 |
and then In_Variant_Part |
| 6633 |
and then Is_Private_Type (Typ) |
| 6634 |
and then Is_Generic_Type (Typ) |
| 6635 |
then |
| 6636 |
Error_Msg_N |
| 6637 |
("component of unchecked union cannot be of generic type", Comp); |
| 6638 |
|
| 6639 |
elsif Needs_Finalization (Typ) then |
| 6640 |
Error_Msg_N |
| 6641 |
("component of unchecked union cannot be controlled", Comp); |
| 6642 |
|
| 6643 |
elsif Has_Task (Typ) then |
| 6644 |
Error_Msg_N |
| 6645 |
("component of unchecked union cannot have tasks", Comp); |
| 6646 |
end if; |
| 6647 |
end Check_Component; |
| 6648 |
|
| 6649 |
---------------------------- |
| 6650 |
-- Check_Duplicate_Pragma -- |
| 6651 |
---------------------------- |
| 6652 |
|
| 6653 |
procedure Check_Duplicate_Pragma (E : Entity_Id) is |
| 6654 |
Id : Entity_Id := E; |
| 6655 |
P : Node_Id; |
| 6656 |
|
| 6657 |
begin |
| 6658 |
-- Nothing to do if this pragma comes from an aspect specification, |
| 6659 |
-- since we could not be duplicating a pragma, and we dealt with the |
| 6660 |
-- case of duplicated aspects in Analyze_Aspect_Specifications. |
| 6661 |
|
| 6662 |
if From_Aspect_Specification (N) then |
| 6663 |
return; |
| 6664 |
end if; |
| 6665 |
|
| 6666 |
-- Otherwise current pragma may duplicate previous pragma or a |
| 6667 |
-- previously given aspect specification or attribute definition |
| 6668 |
-- clause for the same pragma. |
| 6669 |
|
| 6670 |
P := Get_Rep_Item (E, Pragma_Name (N), Check_Parents => False); |
| 6671 |
|
| 6672 |
if Present (P) then |
| 6673 |
|
| 6674 |
-- If the entity is a type, then we have to make sure that the |
| 6675 |
-- ostensible duplicate is not for a parent type from which this |
| 6676 |
-- type is derived. |
| 6677 |
|
| 6678 |
if Is_Type (E) then |
| 6679 |
if Nkind (P) = N_Pragma then |
| 6680 |
declare |
| 6681 |
Args : constant List_Id := |
| 6682 |
Pragma_Argument_Associations (P); |
| 6683 |
begin |
| 6684 |
if Present (Args) |
| 6685 |
and then Is_Entity_Name (Expression (First (Args))) |
| 6686 |
and then Is_Type (Entity (Expression (First (Args)))) |
| 6687 |
and then Entity (Expression (First (Args))) /= E |
| 6688 |
then |
| 6689 |
return; |
| 6690 |
end if; |
| 6691 |
end; |
| 6692 |
|
| 6693 |
elsif Nkind (P) = N_Aspect_Specification |
| 6694 |
and then Is_Type (Entity (P)) |
| 6695 |
and then Entity (P) /= E |
| 6696 |
then |
| 6697 |
return; |
| 6698 |
end if; |
| 6699 |
end if; |
| 6700 |
|
| 6701 |
-- Here we have a definite duplicate |
| 6702 |
|
| 6703 |
Error_Msg_Name_1 := Pragma_Name (N); |
| 6704 |
Error_Msg_Sloc := Sloc (P); |
| 6705 |
|
| 6706 |
-- For a single protected or a single task object, the error is |
| 6707 |
-- issued on the original entity. |
| 6708 |
|
| 6709 |
if Ekind (Id) in E_Task_Type | E_Protected_Type then |
| 6710 |
Id := Defining_Identifier (Original_Node (Parent (Id))); |
| 6711 |
end if; |
| 6712 |
|
| 6713 |
if Nkind (P) = N_Aspect_Specification |
| 6714 |
or else From_Aspect_Specification (P) |
| 6715 |
then |
| 6716 |
Error_Msg_NE ("aspect% for & previously given#", N, Id); |
| 6717 |
else |
| 6718 |
-- If -gnatwr is set, warn in case of a duplicate pragma |
| 6719 |
-- [No_]Inline which is suspicious but not an error, generate |
| 6720 |
-- an error for other pragmas. |
| 6721 |
|
| 6722 |
if Pragma_Name (N) in Name_Inline | Name_No_Inline then |
| 6723 |
if Warn_On_Redundant_Constructs then |
| 6724 |
Error_Msg_NE |
| 6725 |
("?r?pragma% for & duplicates pragma#", N, Id); |
| 6726 |
end if; |
| 6727 |
else |
| 6728 |
Error_Msg_NE ("pragma% for & duplicates pragma#", N, Id); |
| 6729 |
end if; |
| 6730 |
end if; |
| 6731 |
|
| 6732 |
raise Pragma_Exit; |
| 6733 |
end if; |
| 6734 |
end Check_Duplicate_Pragma; |
| 6735 |
|
| 6736 |
---------------------------------- |
| 6737 |
-- Check_Duplicated_Export_Name -- |
| 6738 |
---------------------------------- |
| 6739 |
|
| 6740 |
procedure Check_Duplicated_Export_Name (Nam : Node_Id) is |
| 6741 |
String_Val : constant String_Id := Strval (Nam); |
| 6742 |
|
| 6743 |
begin |
| 6744 |
-- We are only interested in the export case, and in the case of |
| 6745 |
-- generics, it is the instance, not the template, that is the |
| 6746 |
-- problem (the template will generate a warning in any case). |
| 6747 |
|
| 6748 |
if not Inside_A_Generic |
| 6749 |
and then (Prag_Id = Pragma_Export |
| 6750 |
or else |
| 6751 |
Prag_Id = Pragma_Export_Procedure |
| 6752 |
or else |
| 6753 |
Prag_Id = Pragma_Export_Valued_Procedure |
| 6754 |
or else |
| 6755 |
Prag_Id = Pragma_Export_Function) |
| 6756 |
then |
| 6757 |
for J in Externals.First .. Externals.Last loop |
| 6758 |
if String_Equal (String_Val, Strval (Externals.Table (J))) then |
| 6759 |
Error_Msg_Sloc := Sloc (Externals.Table (J)); |
| 6760 |
Error_Msg_N ("external name duplicates name given#", Nam); |
| 6761 |
exit; |
| 6762 |
end if; |
| 6763 |
end loop; |
| 6764 |
|
| 6765 |
Externals.Append (Nam); |
| 6766 |
end if; |
| 6767 |
end Check_Duplicated_Export_Name; |
| 6768 |
|
| 6769 |
---------------------------------------- |
| 6770 |
-- Check_Expr_Is_OK_Static_Expression -- |
| 6771 |
---------------------------------------- |
| 6772 |
|
| 6773 |
procedure Check_Expr_Is_OK_Static_Expression |
| 6774 |
(Expr : Node_Id; Typ : Entity_Id := Empty) is |
| 6775 |
begin |
| 6776 |
case Is_OK_Static_Expression_Of_Type (Expr, Typ) is |
| 6777 |
when Static => |
| 6778 |
null; |
| 6779 |
|
| 6780 |
when Not_Static => |
| 6781 |
Error_Msg_Name_1 := Pname; |
| 6782 |
Flag_Non_Static_Expr |
| 6783 |
(Fix_Error |
| 6784 |
("argument for pragma% must be a static expression!"), |
| 6785 |
Expr); |
| 6786 |
raise Pragma_Exit; |
| 6787 |
|
| 6788 |
when Invalid => |
| 6789 |
raise Pragma_Exit; |
| 6790 |
end case; |
| 6791 |
end Check_Expr_Is_OK_Static_Expression; |
| 6792 |
|
| 6793 |
------------------------- |
| 6794 |
-- Check_First_Subtype -- |
| 6795 |
------------------------- |
| 6796 |
|
| 6797 |
procedure Check_First_Subtype (Arg : Node_Id) is |
| 6798 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 6799 |
Ent : constant Entity_Id := Entity (Argx); |
| 6800 |
|
| 6801 |
begin |
| 6802 |
if Is_First_Subtype (Ent) then |
| 6803 |
null; |
| 6804 |
|
| 6805 |
elsif Is_Type (Ent) then |
| 6806 |
Error_Pragma_Arg |
| 6807 |
("pragma% cannot apply to subtype", Argx); |
| 6808 |
|
| 6809 |
elsif Is_Object (Ent) then |
| 6810 |
Error_Pragma_Arg |
| 6811 |
("pragma% cannot apply to object, requires a type", Argx); |
| 6812 |
|
| 6813 |
else |
| 6814 |
Error_Pragma_Arg |
| 6815 |
("pragma% cannot apply to&, requires a type", Argx); |
| 6816 |
end if; |
| 6817 |
end Check_First_Subtype; |
| 6818 |
|
| 6819 |
---------------------- |
| 6820 |
-- Check_Identifier -- |
| 6821 |
---------------------- |
| 6822 |
|
| 6823 |
procedure Check_Identifier (Arg : Node_Id; Id : Name_Id) is |
| 6824 |
begin |
| 6825 |
if Present (Arg) |
| 6826 |
and then Nkind (Arg) = N_Pragma_Argument_Association |
| 6827 |
then |
| 6828 |
if Chars (Arg) = No_Name or else Chars (Arg) /= Id then |
| 6829 |
Error_Msg_Name_1 := Pname; |
| 6830 |
Error_Msg_Name_2 := Id; |
| 6831 |
Error_Msg_N ("pragma% argument expects identifier%", Arg); |
| 6832 |
raise Pragma_Exit; |
| 6833 |
end if; |
| 6834 |
end if; |
| 6835 |
end Check_Identifier; |
| 6836 |
|
| 6837 |
-------------------------------- |
| 6838 |
-- Check_Identifier_Is_One_Of -- |
| 6839 |
-------------------------------- |
| 6840 |
|
| 6841 |
procedure Check_Identifier_Is_One_Of (Arg : Node_Id; N1, N2 : Name_Id) is |
| 6842 |
begin |
| 6843 |
if Present (Arg) |
| 6844 |
and then Nkind (Arg) = N_Pragma_Argument_Association |
| 6845 |
then |
| 6846 |
if Chars (Arg) = No_Name then |
| 6847 |
Error_Msg_Name_1 := Pname; |
| 6848 |
Error_Msg_N ("pragma% argument expects an identifier", Arg); |
| 6849 |
raise Pragma_Exit; |
| 6850 |
|
| 6851 |
elsif Chars (Arg) /= N1 |
| 6852 |
and then Chars (Arg) /= N2 |
| 6853 |
then |
| 6854 |
Error_Msg_Name_1 := Pname; |
| 6855 |
Error_Msg_N ("invalid identifier for pragma% argument", Arg); |
| 6856 |
raise Pragma_Exit; |
| 6857 |
end if; |
| 6858 |
end if; |
| 6859 |
end Check_Identifier_Is_One_Of; |
| 6860 |
|
| 6861 |
--------------------------- |
| 6862 |
-- Check_In_Main_Program -- |
| 6863 |
--------------------------- |
| 6864 |
|
| 6865 |
procedure Check_In_Main_Program is |
| 6866 |
P : constant Node_Id := Parent (N); |
| 6867 |
|
| 6868 |
begin |
| 6869 |
-- Must be in subprogram body |
| 6870 |
|
| 6871 |
if Nkind (P) /= N_Subprogram_Body then |
| 6872 |
Error_Pragma ("% pragma allowed only in subprogram"); |
| 6873 |
|
| 6874 |
-- Otherwise warn if obviously not main program |
| 6875 |
|
| 6876 |
elsif Present (Parameter_Specifications (Specification (P))) |
| 6877 |
or else not Is_Compilation_Unit (Defining_Entity (P)) |
| 6878 |
then |
| 6879 |
Error_Msg_Name_1 := Pname; |
| 6880 |
Error_Msg_N |
| 6881 |
("??pragma% is only effective in main program", N); |
| 6882 |
end if; |
| 6883 |
end Check_In_Main_Program; |
| 6884 |
|
| 6885 |
--------------------------------------- |
| 6886 |
-- Check_Interrupt_Or_Attach_Handler -- |
| 6887 |
--------------------------------------- |
| 6888 |
|
| 6889 |
procedure Check_Interrupt_Or_Attach_Handler is |
| 6890 |
Arg1_X : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 6891 |
Handler_Proc, Proc_Scope : Entity_Id; |
| 6892 |
|
| 6893 |
begin |
| 6894 |
Analyze (Arg1_X); |
| 6895 |
|
| 6896 |
if Prag_Id = Pragma_Interrupt_Handler then |
| 6897 |
Check_Restriction (No_Dynamic_Attachment, N); |
| 6898 |
end if; |
| 6899 |
|
| 6900 |
Handler_Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1); |
| 6901 |
Proc_Scope := Scope (Handler_Proc); |
| 6902 |
|
| 6903 |
if Nkind (Parent (Subprogram_Spec (Handler_Proc))) /= |
| 6904 |
N_Protected_Definition |
| 6905 |
then |
| 6906 |
Error_Pragma_Arg |
| 6907 |
("argument of pragma% must be protected procedure", Arg1); |
| 6908 |
end if; |
| 6909 |
|
| 6910 |
-- For pragma case (as opposed to aspect case), check placement. |
| 6911 |
-- We don't need to do that for aspects, because we have the |
| 6912 |
-- check that they aspect applies an appropriate procedure. |
| 6913 |
|
| 6914 |
if not From_Aspect_Specification (N) |
| 6915 |
and then Parent (N) /= Protected_Definition (Parent (Proc_Scope)) |
| 6916 |
then |
| 6917 |
Error_Pragma ("pragma% must be in protected definition"); |
| 6918 |
end if; |
| 6919 |
|
| 6920 |
if not Is_Library_Level_Entity (Proc_Scope) then |
| 6921 |
Error_Pragma_Arg |
| 6922 |
("argument for pragma% must be library level entity", Arg1); |
| 6923 |
end if; |
| 6924 |
|
| 6925 |
-- AI05-0033: A pragma cannot appear within a generic body, because |
| 6926 |
-- instance can be in a nested scope. The check that protected type |
| 6927 |
-- is itself a library-level declaration is done elsewhere. |
| 6928 |
|
| 6929 |
-- Note: we omit this check in Relaxed_RM_Semantics mode to properly |
| 6930 |
-- handle code prior to AI-0033. Analysis tools typically are not |
| 6931 |
-- interested in this pragma in any case, so no need to worry too |
| 6932 |
-- much about its placement. |
| 6933 |
|
| 6934 |
if Inside_A_Generic then |
| 6935 |
if Ekind (Scope (Current_Scope)) = E_Generic_Package |
| 6936 |
and then In_Package_Body (Scope (Current_Scope)) |
| 6937 |
and then not Relaxed_RM_Semantics |
| 6938 |
then |
| 6939 |
Error_Pragma ("pragma% cannot be used inside a generic"); |
| 6940 |
end if; |
| 6941 |
end if; |
| 6942 |
end Check_Interrupt_Or_Attach_Handler; |
| 6943 |
|
| 6944 |
--------------------------------- |
| 6945 |
-- Check_Loop_Pragma_Placement -- |
| 6946 |
--------------------------------- |
| 6947 |
|
| 6948 |
procedure Check_Loop_Pragma_Placement is |
| 6949 |
procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id); |
| 6950 |
-- Verify whether the current pragma is properly grouped with other |
| 6951 |
-- pragma Loop_Invariant and/or Loop_Variant. Node Loop_Stmt is the |
| 6952 |
-- related loop where the pragma appears. |
| 6953 |
|
| 6954 |
function Is_Loop_Pragma (Stmt : Node_Id) return Boolean; |
| 6955 |
-- Determine whether an arbitrary statement Stmt denotes pragma |
| 6956 |
-- Loop_Invariant or Loop_Variant. |
| 6957 |
|
| 6958 |
procedure Placement_Error (Constr : Node_Id); |
| 6959 |
pragma No_Return (Placement_Error); |
| 6960 |
-- Node Constr denotes the last loop restricted construct before we |
| 6961 |
-- encountered an illegal relation between enclosing constructs. Emit |
| 6962 |
-- an error depending on what Constr was. |
| 6963 |
|
| 6964 |
-------------------------------- |
| 6965 |
-- Check_Loop_Pragma_Grouping -- |
| 6966 |
-------------------------------- |
| 6967 |
|
| 6968 |
procedure Check_Loop_Pragma_Grouping (Loop_Stmt : Node_Id) is |
| 6969 |
function Check_Grouping (L : List_Id) return Boolean; |
| 6970 |
-- Find the first group of pragmas in list L and if successful, |
| 6971 |
-- ensure that the current pragma is part of that group. The |
| 6972 |
-- routine returns True once such a check is performed to |
| 6973 |
-- stop the analysis. |
| 6974 |
|
| 6975 |
procedure Grouping_Error (Prag : Node_Id); |
| 6976 |
pragma No_Return (Grouping_Error); |
| 6977 |
-- Emit an error concerning the current pragma indicating that it |
| 6978 |
-- should be placed after pragma Prag. |
| 6979 |
|
| 6980 |
-------------------- |
| 6981 |
-- Check_Grouping -- |
| 6982 |
-------------------- |
| 6983 |
|
| 6984 |
function Check_Grouping (L : List_Id) return Boolean is |
| 6985 |
HSS : Node_Id; |
| 6986 |
Stmt : Node_Id; |
| 6987 |
Prag : Node_Id := Empty; -- init to avoid warning |
| 6988 |
|
| 6989 |
begin |
| 6990 |
-- Inspect the list of declarations or statements looking for |
| 6991 |
-- the first grouping of pragmas: |
| 6992 |
|
| 6993 |
-- loop |
| 6994 |
-- pragma Loop_Invariant ...; |
| 6995 |
-- pragma Loop_Variant ...; |
| 6996 |
-- . . . -- (1) |
| 6997 |
-- pragma Loop_Variant ...; -- current pragma |
| 6998 |
|
| 6999 |
-- If the current pragma is not in the grouping, then it must |
| 7000 |
-- either appear in a different declarative or statement list |
| 7001 |
-- or the construct at (1) is separating the pragma from the |
| 7002 |
-- grouping. |
| 7003 |
|
| 7004 |
Stmt := First (L); |
| 7005 |
while Present (Stmt) loop |
| 7006 |
|
| 7007 |
-- First pragma of the first topmost grouping has been found |
| 7008 |
|
| 7009 |
if Is_Loop_Pragma (Stmt) then |
| 7010 |
|
| 7011 |
-- The group and the current pragma are not in the same |
| 7012 |
-- declarative or statement list. |
| 7013 |
|
| 7014 |
if not In_Same_List (Stmt, N) then |
| 7015 |
Grouping_Error (Stmt); |
| 7016 |
|
| 7017 |
-- Try to reach the current pragma from the first pragma |
| 7018 |
-- of the grouping while skipping other members: |
| 7019 |
|
| 7020 |
-- pragma Loop_Invariant ...; -- first pragma |
| 7021 |
-- pragma Loop_Variant ...; -- member |
| 7022 |
-- . . . |
| 7023 |
-- pragma Loop_Variant ...; -- current pragma |
| 7024 |
|
| 7025 |
else |
| 7026 |
while Present (Stmt) loop |
| 7027 |
-- The current pragma is either the first pragma |
| 7028 |
-- of the group or is a member of the group. |
| 7029 |
-- Stop the search as the placement is legal. |
| 7030 |
|
| 7031 |
if Stmt = N then |
| 7032 |
return True; |
| 7033 |
|
| 7034 |
-- Skip group members, but keep track of the |
| 7035 |
-- last pragma in the group. |
| 7036 |
|
| 7037 |
elsif Is_Loop_Pragma (Stmt) then |
| 7038 |
Prag := Stmt; |
| 7039 |
|
| 7040 |
-- Skip Annotate pragmas, typically used to justify |
| 7041 |
-- unproved loop pragmas in GNATprove. |
| 7042 |
|
| 7043 |
elsif Nkind (Stmt) = N_Pragma |
| 7044 |
and then Pragma_Name (Stmt) = Name_Annotate |
| 7045 |
then |
| 7046 |
null; |
| 7047 |
|
| 7048 |
-- Skip declarations and statements generated by |
| 7049 |
-- the compiler during expansion. Note that some |
| 7050 |
-- source statements (e.g. pragma Assert) may have |
| 7051 |
-- been transformed so that they do not appear as |
| 7052 |
-- coming from source anymore, so we instead look |
| 7053 |
-- at their Original_Node. |
| 7054 |
|
| 7055 |
elsif not Comes_From_Source (Original_Node (Stmt)) |
| 7056 |
then |
| 7057 |
null; |
| 7058 |
|
| 7059 |
-- A non-pragma is separating the group from the |
| 7060 |
-- current pragma, the placement is illegal. |
| 7061 |
|
| 7062 |
else |
| 7063 |
Grouping_Error (Prag); |
| 7064 |
end if; |
| 7065 |
|
| 7066 |
Next (Stmt); |
| 7067 |
end loop; |
| 7068 |
|
| 7069 |
-- If the traversal did not reach the current pragma, |
| 7070 |
-- then the list must be malformed. |
| 7071 |
|
| 7072 |
raise Program_Error; |
| 7073 |
end if; |
| 7074 |
|
| 7075 |
-- Pragmas Loop_Invariant and Loop_Variant may only appear |
| 7076 |
-- inside a loop or a block housed inside a loop. Inspect |
| 7077 |
-- the declarations and statements of the block as they may |
| 7078 |
-- contain the first grouping. This case follows the one for |
| 7079 |
-- loop pragmas, as block statements which originate in a |
| 7080 |
-- loop pragma (and so Is_Loop_Pragma will return True on |
| 7081 |
-- that block statement) should be treated in the previous |
| 7082 |
-- case. |
| 7083 |
|
| 7084 |
elsif Nkind (Stmt) = N_Block_Statement then |
| 7085 |
HSS := Handled_Statement_Sequence (Stmt); |
| 7086 |
|
| 7087 |
if Check_Grouping (Declarations (Stmt)) then |
| 7088 |
return True; |
| 7089 |
end if; |
| 7090 |
|
| 7091 |
if Present (HSS) then |
| 7092 |
if Check_Grouping (Statements (HSS)) then |
| 7093 |
return True; |
| 7094 |
end if; |
| 7095 |
end if; |
| 7096 |
end if; |
| 7097 |
|
| 7098 |
Next (Stmt); |
| 7099 |
end loop; |
| 7100 |
|
| 7101 |
return False; |
| 7102 |
end Check_Grouping; |
| 7103 |
|
| 7104 |
-------------------- |
| 7105 |
-- Grouping_Error -- |
| 7106 |
-------------------- |
| 7107 |
|
| 7108 |
procedure Grouping_Error (Prag : Node_Id) is |
| 7109 |
begin |
| 7110 |
Error_Msg_Sloc := Sloc (Prag); |
| 7111 |
Error_Pragma ("pragma% must appear next to pragma#"); |
| 7112 |
end Grouping_Error; |
| 7113 |
|
| 7114 |
Ignore : Boolean; |
| 7115 |
|
| 7116 |
-- Start of processing for Check_Loop_Pragma_Grouping |
| 7117 |
|
| 7118 |
begin |
| 7119 |
-- Inspect the statements of the loop or nested blocks housed |
| 7120 |
-- within to determine whether the current pragma is part of the |
| 7121 |
-- first topmost grouping of Loop_Invariant and Loop_Variant. |
| 7122 |
|
| 7123 |
Ignore := Check_Grouping (Statements (Loop_Stmt)); |
| 7124 |
end Check_Loop_Pragma_Grouping; |
| 7125 |
|
| 7126 |
-------------------- |
| 7127 |
-- Is_Loop_Pragma -- |
| 7128 |
-------------------- |
| 7129 |
|
| 7130 |
function Is_Loop_Pragma (Stmt : Node_Id) return Boolean is |
| 7131 |
Original_Stmt : constant Node_Id := Original_Node (Stmt); |
| 7132 |
|
| 7133 |
begin |
| 7134 |
-- Inspect the original node as Loop_Invariant and Loop_Variant |
| 7135 |
-- pragmas are rewritten to null when assertions are disabled. |
| 7136 |
|
| 7137 |
return Nkind (Original_Stmt) = N_Pragma |
| 7138 |
and then Pragma_Name_Unmapped (Original_Stmt) |
| 7139 |
in Name_Loop_Invariant | Name_Loop_Variant; |
| 7140 |
end Is_Loop_Pragma; |
| 7141 |
|
| 7142 |
--------------------- |
| 7143 |
-- Placement_Error -- |
| 7144 |
--------------------- |
| 7145 |
|
| 7146 |
procedure Placement_Error (Constr : Node_Id) is |
| 7147 |
LA : constant String := " with Loop_Entry"; |
| 7148 |
|
| 7149 |
begin |
| 7150 |
if Prag_Id = Pragma_Assert then |
| 7151 |
Error_Msg_String (1 .. LA'Length) := LA; |
| 7152 |
Error_Msg_Strlen := LA'Length; |
| 7153 |
else |
| 7154 |
Error_Msg_Strlen := 0; |
| 7155 |
end if; |
| 7156 |
|
| 7157 |
if Nkind (Constr) = N_Pragma then |
| 7158 |
Error_Pragma |
| 7159 |
("pragma %~ must appear immediately within the statements " |
| 7160 |
& "of a loop"); |
| 7161 |
else |
| 7162 |
Error_Pragma_Arg |
| 7163 |
("block containing pragma %~ must appear immediately within " |
| 7164 |
& "the statements of a loop", Constr); |
| 7165 |
end if; |
| 7166 |
end Placement_Error; |
| 7167 |
|
| 7168 |
-- Local declarations |
| 7169 |
|
| 7170 |
Prev : Node_Id; |
| 7171 |
Stmt : Node_Id; |
| 7172 |
|
| 7173 |
-- Start of processing for Check_Loop_Pragma_Placement |
| 7174 |
|
| 7175 |
begin |
| 7176 |
-- Check that pragma appears immediately within a loop statement, |
| 7177 |
-- ignoring intervening block statements. |
| 7178 |
|
| 7179 |
Prev := N; |
| 7180 |
Stmt := Parent (N); |
| 7181 |
while Present (Stmt) loop |
| 7182 |
|
| 7183 |
-- The pragma or previous block must appear immediately within the |
| 7184 |
-- current block's declarative or statement part. |
| 7185 |
|
| 7186 |
if Nkind (Stmt) = N_Block_Statement then |
| 7187 |
if (No (Declarations (Stmt)) |
| 7188 |
or else List_Containing (Prev) /= Declarations (Stmt)) |
| 7189 |
and then |
| 7190 |
List_Containing (Prev) /= |
| 7191 |
Statements (Handled_Statement_Sequence (Stmt)) |
| 7192 |
then |
| 7193 |
Placement_Error (Prev); |
| 7194 |
|
| 7195 |
-- Keep inspecting the parents because we are now within a |
| 7196 |
-- chain of nested blocks. |
| 7197 |
|
| 7198 |
else |
| 7199 |
Prev := Stmt; |
| 7200 |
Stmt := Parent (Stmt); |
| 7201 |
end if; |
| 7202 |
|
| 7203 |
-- The pragma or previous block must appear immediately within the |
| 7204 |
-- statements of the loop. |
| 7205 |
|
| 7206 |
elsif Nkind (Stmt) = N_Loop_Statement then |
| 7207 |
if List_Containing (Prev) /= Statements (Stmt) then |
| 7208 |
Placement_Error (Prev); |
| 7209 |
end if; |
| 7210 |
|
| 7211 |
-- Stop the traversal because we reached the innermost loop |
| 7212 |
-- regardless of whether we encountered an error or not. |
| 7213 |
|
| 7214 |
exit; |
| 7215 |
|
| 7216 |
-- Ignore a handled statement sequence. Note that this node may |
| 7217 |
-- be related to a subprogram body in which case we will emit an |
| 7218 |
-- error on the next iteration of the search. |
| 7219 |
|
| 7220 |
elsif Nkind (Stmt) = N_Handled_Sequence_Of_Statements then |
| 7221 |
Stmt := Parent (Stmt); |
| 7222 |
|
| 7223 |
-- Any other statement breaks the chain from the pragma to the |
| 7224 |
-- loop. |
| 7225 |
|
| 7226 |
else |
| 7227 |
Placement_Error (Prev); |
| 7228 |
end if; |
| 7229 |
end loop; |
| 7230 |
|
| 7231 |
-- Check that the current pragma Loop_Invariant or Loop_Variant is |
| 7232 |
-- grouped together with other such pragmas. |
| 7233 |
|
| 7234 |
if Is_Loop_Pragma (N) then |
| 7235 |
|
| 7236 |
-- The previous check should have located the related loop |
| 7237 |
|
| 7238 |
pragma Assert (Nkind (Stmt) = N_Loop_Statement); |
| 7239 |
Check_Loop_Pragma_Grouping (Stmt); |
| 7240 |
end if; |
| 7241 |
end Check_Loop_Pragma_Placement; |
| 7242 |
|
| 7243 |
------------------------------------------- |
| 7244 |
-- Check_Is_In_Decl_Part_Or_Package_Spec -- |
| 7245 |
------------------------------------------- |
| 7246 |
|
| 7247 |
procedure Check_Is_In_Decl_Part_Or_Package_Spec is |
| 7248 |
P : Node_Id; |
| 7249 |
|
| 7250 |
begin |
| 7251 |
P := Parent (N); |
| 7252 |
loop |
| 7253 |
if No (P) then |
| 7254 |
exit; |
| 7255 |
|
| 7256 |
elsif Nkind (P) = N_Handled_Sequence_Of_Statements then |
| 7257 |
exit; |
| 7258 |
|
| 7259 |
elsif Nkind (P) in N_Package_Specification | N_Block_Statement then |
| 7260 |
return; |
| 7261 |
|
| 7262 |
-- Note: the following tests seem a little peculiar, because |
| 7263 |
-- they test for bodies, but if we were in the statement part |
| 7264 |
-- of the body, we would already have hit the handled statement |
| 7265 |
-- sequence, so the only way we get here is by being in the |
| 7266 |
-- declarative part of the body. |
| 7267 |
|
| 7268 |
elsif Nkind (P) in |
| 7269 |
N_Subprogram_Body | N_Package_Body | N_Task_Body | N_Entry_Body |
| 7270 |
then |
| 7271 |
return; |
| 7272 |
end if; |
| 7273 |
|
| 7274 |
P := Parent (P); |
| 7275 |
end loop; |
| 7276 |
|
| 7277 |
Error_Pragma ("pragma% is not in declarative part or package spec"); |
| 7278 |
end Check_Is_In_Decl_Part_Or_Package_Spec; |
| 7279 |
|
| 7280 |
------------------------- |
| 7281 |
-- Check_No_Identifier -- |
| 7282 |
------------------------- |
| 7283 |
|
| 7284 |
procedure Check_No_Identifier (Arg : Node_Id) is |
| 7285 |
begin |
| 7286 |
if Nkind (Arg) = N_Pragma_Argument_Association |
| 7287 |
and then Chars (Arg) /= No_Name |
| 7288 |
then |
| 7289 |
Error_Pragma_Arg_Ident |
| 7290 |
("pragma% does not permit identifier& here", Arg); |
| 7291 |
end if; |
| 7292 |
end Check_No_Identifier; |
| 7293 |
|
| 7294 |
-------------------------- |
| 7295 |
-- Check_No_Identifiers -- |
| 7296 |
-------------------------- |
| 7297 |
|
| 7298 |
procedure Check_No_Identifiers is |
| 7299 |
Arg_Node : Node_Id; |
| 7300 |
begin |
| 7301 |
Arg_Node := Arg1; |
| 7302 |
for J in 1 .. Arg_Count loop |
| 7303 |
Check_No_Identifier (Arg_Node); |
| 7304 |
Next (Arg_Node); |
| 7305 |
end loop; |
| 7306 |
end Check_No_Identifiers; |
| 7307 |
|
| 7308 |
------------------------ |
| 7309 |
-- Check_No_Link_Name -- |
| 7310 |
------------------------ |
| 7311 |
|
| 7312 |
procedure Check_No_Link_Name is |
| 7313 |
begin |
| 7314 |
if Present (Arg3) and then Chars (Arg3) = Name_Link_Name then |
| 7315 |
Arg4 := Arg3; |
| 7316 |
end if; |
| 7317 |
|
| 7318 |
if Present (Arg4) then |
| 7319 |
Error_Pragma_Arg |
| 7320 |
("Link_Name argument not allowed for Import Intrinsic", Arg4); |
| 7321 |
end if; |
| 7322 |
end Check_No_Link_Name; |
| 7323 |
|
| 7324 |
------------------------------- |
| 7325 |
-- Check_Optional_Identifier -- |
| 7326 |
------------------------------- |
| 7327 |
|
| 7328 |
procedure Check_Optional_Identifier (Arg : Node_Id; Id : Name_Id) is |
| 7329 |
begin |
| 7330 |
if Present (Arg) |
| 7331 |
and then Nkind (Arg) = N_Pragma_Argument_Association |
| 7332 |
and then Chars (Arg) /= No_Name |
| 7333 |
then |
| 7334 |
if Chars (Arg) /= Id then |
| 7335 |
Error_Msg_Name_1 := Pname; |
| 7336 |
Error_Msg_Name_2 := Id; |
| 7337 |
Error_Msg_N ("pragma% argument expects identifier%", Arg); |
| 7338 |
raise Pragma_Exit; |
| 7339 |
end if; |
| 7340 |
end if; |
| 7341 |
end Check_Optional_Identifier; |
| 7342 |
|
| 7343 |
procedure Check_Optional_Identifier (Arg : Node_Id; Id : String) is |
| 7344 |
begin |
| 7345 |
Check_Optional_Identifier (Arg, Name_Find (Id)); |
| 7346 |
end Check_Optional_Identifier; |
| 7347 |
|
| 7348 |
------------------------------------- |
| 7349 |
-- Check_Static_Boolean_Expression -- |
| 7350 |
------------------------------------- |
| 7351 |
|
| 7352 |
procedure Check_Static_Boolean_Expression (Expr : Node_Id) is |
| 7353 |
begin |
| 7354 |
if Present (Expr) then |
| 7355 |
Analyze_And_Resolve (Expr, Standard_Boolean); |
| 7356 |
|
| 7357 |
if not Is_OK_Static_Expression (Expr) then |
| 7358 |
Error_Pragma_Arg |
| 7359 |
("expression of pragma % must be static", Expr); |
| 7360 |
end if; |
| 7361 |
end if; |
| 7362 |
end Check_Static_Boolean_Expression; |
| 7363 |
|
| 7364 |
----------------------------- |
| 7365 |
-- Check_Static_Constraint -- |
| 7366 |
----------------------------- |
| 7367 |
|
| 7368 |
procedure Check_Static_Constraint (Constr : Node_Id) is |
| 7369 |
|
| 7370 |
procedure Require_Static (E : Node_Id); |
| 7371 |
-- Require given expression to be static expression |
| 7372 |
|
| 7373 |
-------------------- |
| 7374 |
-- Require_Static -- |
| 7375 |
-------------------- |
| 7376 |
|
| 7377 |
procedure Require_Static (E : Node_Id) is |
| 7378 |
begin |
| 7379 |
if not Is_OK_Static_Expression (E) then |
| 7380 |
Flag_Non_Static_Expr |
| 7381 |
("non-static constraint not allowed in Unchecked_Union!", E); |
| 7382 |
raise Pragma_Exit; |
| 7383 |
end if; |
| 7384 |
end Require_Static; |
| 7385 |
|
| 7386 |
-- Start of processing for Check_Static_Constraint |
| 7387 |
|
| 7388 |
begin |
| 7389 |
case Nkind (Constr) is |
| 7390 |
when N_Discriminant_Association => |
| 7391 |
Require_Static (Expression (Constr)); |
| 7392 |
|
| 7393 |
when N_Range => |
| 7394 |
Require_Static (Low_Bound (Constr)); |
| 7395 |
Require_Static (High_Bound (Constr)); |
| 7396 |
|
| 7397 |
when N_Attribute_Reference => |
| 7398 |
Require_Static (Type_Low_Bound (Etype (Prefix (Constr)))); |
| 7399 |
Require_Static (Type_High_Bound (Etype (Prefix (Constr)))); |
| 7400 |
|
| 7401 |
when N_Range_Constraint => |
| 7402 |
Check_Static_Constraint (Range_Expression (Constr)); |
| 7403 |
|
| 7404 |
when N_Index_Or_Discriminant_Constraint => |
| 7405 |
declare |
| 7406 |
IDC : Entity_Id; |
| 7407 |
begin |
| 7408 |
IDC := First (Constraints (Constr)); |
| 7409 |
while Present (IDC) loop |
| 7410 |
Check_Static_Constraint (IDC); |
| 7411 |
Next (IDC); |
| 7412 |
end loop; |
| 7413 |
end; |
| 7414 |
|
| 7415 |
when others => |
| 7416 |
null; |
| 7417 |
end case; |
| 7418 |
end Check_Static_Constraint; |
| 7419 |
|
| 7420 |
-------------------------------------- |
| 7421 |
-- Check_Valid_Configuration_Pragma -- |
| 7422 |
-------------------------------------- |
| 7423 |
|
| 7424 |
-- A configuration pragma must appear in the context clause of a |
| 7425 |
-- compilation unit, and only other pragmas may precede it. Note that |
| 7426 |
-- the test also allows use in a configuration pragma file. |
| 7427 |
|
| 7428 |
procedure Check_Valid_Configuration_Pragma is |
| 7429 |
begin |
| 7430 |
if not Is_Configuration_Pragma then |
| 7431 |
Error_Pragma ("incorrect placement for configuration pragma%"); |
| 7432 |
end if; |
| 7433 |
end Check_Valid_Configuration_Pragma; |
| 7434 |
|
| 7435 |
------------------------------------- |
| 7436 |
-- Check_Valid_Library_Unit_Pragma -- |
| 7437 |
------------------------------------- |
| 7438 |
|
| 7439 |
procedure Check_Valid_Library_Unit_Pragma is |
| 7440 |
Plist : List_Id; |
| 7441 |
Parent_Node : Node_Id; |
| 7442 |
Unit_Name : Entity_Id; |
| 7443 |
Unit_Kind : Node_Kind; |
| 7444 |
Unit_Node : Node_Id; |
| 7445 |
Sindex : Source_File_Index; |
| 7446 |
|
| 7447 |
begin |
| 7448 |
if not Is_List_Member (N) then |
| 7449 |
Pragma_Misplaced; |
| 7450 |
|
| 7451 |
else |
| 7452 |
Plist := List_Containing (N); |
| 7453 |
Parent_Node := Parent (Plist); |
| 7454 |
|
| 7455 |
if Parent_Node = Empty then |
| 7456 |
Pragma_Misplaced; |
| 7457 |
|
| 7458 |
-- Case of pragma appearing after a compilation unit. In this case |
| 7459 |
-- it must have an argument with the corresponding name and must |
| 7460 |
-- be part of the following pragmas of its parent. |
| 7461 |
|
| 7462 |
elsif Nkind (Parent_Node) = N_Compilation_Unit_Aux then |
| 7463 |
if Plist /= Pragmas_After (Parent_Node) then |
| 7464 |
Error_Pragma |
| 7465 |
("pragma% misplaced, must be inside or after the " |
| 7466 |
& "compilation unit"); |
| 7467 |
|
| 7468 |
elsif Arg_Count = 0 then |
| 7469 |
Error_Pragma |
| 7470 |
("argument required if outside compilation unit"); |
| 7471 |
|
| 7472 |
else |
| 7473 |
Check_No_Identifiers; |
| 7474 |
Check_Arg_Count (1); |
| 7475 |
Unit_Node := Unit (Parent (Parent_Node)); |
| 7476 |
Unit_Kind := Nkind (Unit_Node); |
| 7477 |
|
| 7478 |
Analyze (Get_Pragma_Arg (Arg1)); |
| 7479 |
|
| 7480 |
if Unit_Kind = N_Generic_Subprogram_Declaration |
| 7481 |
or else Unit_Kind = N_Subprogram_Declaration |
| 7482 |
then |
| 7483 |
Unit_Name := Defining_Entity (Unit_Node); |
| 7484 |
|
| 7485 |
elsif Unit_Kind in N_Generic_Instantiation then |
| 7486 |
Unit_Name := Defining_Entity (Unit_Node); |
| 7487 |
|
| 7488 |
else |
| 7489 |
Unit_Name := Cunit_Entity (Current_Sem_Unit); |
| 7490 |
end if; |
| 7491 |
|
| 7492 |
if Chars (Unit_Name) /= |
| 7493 |
Chars (Entity (Get_Pragma_Arg (Arg1))) |
| 7494 |
then |
| 7495 |
Error_Pragma_Arg |
| 7496 |
("pragma% argument is not current unit name", Arg1); |
| 7497 |
end if; |
| 7498 |
|
| 7499 |
if Ekind (Unit_Name) = E_Package |
| 7500 |
and then Present (Renamed_Entity (Unit_Name)) |
| 7501 |
then |
| 7502 |
Error_Pragma ("pragma% not allowed for renamed package"); |
| 7503 |
end if; |
| 7504 |
end if; |
| 7505 |
|
| 7506 |
-- Pragma appears other than after a compilation unit |
| 7507 |
|
| 7508 |
else |
| 7509 |
-- Here we check for the generic instantiation case and also |
| 7510 |
-- for the case of processing a generic formal package. We |
| 7511 |
-- detect these cases by noting that the Sloc on the node |
| 7512 |
-- does not belong to the current compilation unit. |
| 7513 |
|
| 7514 |
Sindex := Source_Index (Current_Sem_Unit); |
| 7515 |
|
| 7516 |
if Loc not in Source_First (Sindex) .. Source_Last (Sindex) then |
| 7517 |
-- We do not want to raise an exception here since this code |
| 7518 |
-- is part of the bootstrap path where we cannot rely on |
| 7519 |
-- exception propagation working. |
| 7520 |
-- Instead the caller should check for N being rewritten as |
| 7521 |
-- a null statement. |
| 7522 |
-- This code triggers when compiling a-except.adb. |
| 7523 |
|
| 7524 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 7525 |
|
| 7526 |
-- If before first declaration, the pragma applies to the |
| 7527 |
-- enclosing unit, and the name if present must be this name. |
| 7528 |
|
| 7529 |
elsif Is_Before_First_Decl (N, Plist) then |
| 7530 |
Unit_Node := Unit_Declaration_Node (Current_Scope); |
| 7531 |
Unit_Kind := Nkind (Unit_Node); |
| 7532 |
|
| 7533 |
if Unit_Node = Standard_Package_Node then |
| 7534 |
Error_Pragma |
| 7535 |
("pragma% misplaced, must be inside or after the " |
| 7536 |
& "compilation unit"); |
| 7537 |
|
| 7538 |
elsif Nkind (Parent (Unit_Node)) /= N_Compilation_Unit then |
| 7539 |
Error_Pragma |
| 7540 |
("pragma% misplaced, must be on library unit"); |
| 7541 |
|
| 7542 |
elsif Unit_Kind = N_Subprogram_Body |
| 7543 |
and then not Acts_As_Spec (Unit_Node) |
| 7544 |
then |
| 7545 |
Error_Pragma |
| 7546 |
("pragma% misplaced, must be on the subprogram spec"); |
| 7547 |
|
| 7548 |
elsif Nkind (Parent_Node) = N_Package_Body then |
| 7549 |
Error_Pragma |
| 7550 |
("pragma% misplaced, must be on the package spec"); |
| 7551 |
|
| 7552 |
elsif Nkind (Parent_Node) = N_Package_Specification |
| 7553 |
and then Plist = Private_Declarations (Parent_Node) |
| 7554 |
then |
| 7555 |
Error_Pragma |
| 7556 |
("pragma% misplaced, must be in the public part"); |
| 7557 |
|
| 7558 |
elsif Nkind (Parent_Node) in N_Generic_Declaration |
| 7559 |
and then Plist = Generic_Formal_Declarations (Parent_Node) |
| 7560 |
then |
| 7561 |
Error_Pragma |
| 7562 |
("pragma% misplaced, must not be in formal part"); |
| 7563 |
|
| 7564 |
elsif Arg_Count > 0 then |
| 7565 |
Analyze (Get_Pragma_Arg (Arg1)); |
| 7566 |
|
| 7567 |
if Entity (Get_Pragma_Arg (Arg1)) /= Current_Scope then |
| 7568 |
Error_Pragma_Arg |
| 7569 |
("name in pragma% must be enclosing unit", Arg1); |
| 7570 |
end if; |
| 7571 |
|
| 7572 |
-- It is legal to have no argument in this context |
| 7573 |
|
| 7574 |
else |
| 7575 |
return; |
| 7576 |
end if; |
| 7577 |
|
| 7578 |
-- Error if not before first declaration. This is because a |
| 7579 |
-- library unit pragma argument must be the name of a library |
| 7580 |
-- unit (RM 10.1.5(7)), but the only names permitted in this |
| 7581 |
-- context are (RM 10.1.5(6)) names of subprogram declarations, |
| 7582 |
-- generic subprogram declarations or generic instantiations. |
| 7583 |
|
| 7584 |
else |
| 7585 |
Error_Pragma |
| 7586 |
("pragma% misplaced, must be before first declaration"); |
| 7587 |
end if; |
| 7588 |
end if; |
| 7589 |
end if; |
| 7590 |
end Check_Valid_Library_Unit_Pragma; |
| 7591 |
|
| 7592 |
------------------- |
| 7593 |
-- Check_Variant -- |
| 7594 |
------------------- |
| 7595 |
|
| 7596 |
procedure Check_Variant (Variant : Node_Id; UU_Typ : Entity_Id) is |
| 7597 |
Clist : constant Node_Id := Component_List (Variant); |
| 7598 |
Comp : Node_Id; |
| 7599 |
|
| 7600 |
begin |
| 7601 |
Comp := First_Non_Pragma (Component_Items (Clist)); |
| 7602 |
while Present (Comp) loop |
| 7603 |
Check_Component (Comp, UU_Typ, In_Variant_Part => True); |
| 7604 |
Next_Non_Pragma (Comp); |
| 7605 |
end loop; |
| 7606 |
end Check_Variant; |
| 7607 |
|
| 7608 |
--------------------------- |
| 7609 |
-- Ensure_Aggregate_Form -- |
| 7610 |
--------------------------- |
| 7611 |
|
| 7612 |
procedure Ensure_Aggregate_Form (Arg : Node_Id) is |
| 7613 |
CFSD : constant Boolean := Get_Comes_From_Source_Default; |
| 7614 |
Expr : constant Node_Id := Expression (Arg); |
| 7615 |
Loc : constant Source_Ptr := Sloc (Expr); |
| 7616 |
Comps : List_Id := No_List; |
| 7617 |
Exprs : List_Id := No_List; |
| 7618 |
Nam : Name_Id := No_Name; |
| 7619 |
Nam_Loc : Source_Ptr; |
| 7620 |
|
| 7621 |
begin |
| 7622 |
-- The pragma argument is in positional form: |
| 7623 |
|
| 7624 |
-- pragma Depends (Nam => ...) |
| 7625 |
-- ^ |
| 7626 |
-- Chars field |
| 7627 |
|
| 7628 |
-- Note that the Sloc of the Chars field is the Sloc of the pragma |
| 7629 |
-- argument association. |
| 7630 |
|
| 7631 |
if Nkind (Arg) = N_Pragma_Argument_Association then |
| 7632 |
Nam := Chars (Arg); |
| 7633 |
Nam_Loc := Sloc (Arg); |
| 7634 |
|
| 7635 |
-- Remove the pragma argument name as this will be captured in the |
| 7636 |
-- aggregate. |
| 7637 |
|
| 7638 |
Set_Chars (Arg, No_Name); |
| 7639 |
end if; |
| 7640 |
|
| 7641 |
-- The argument is already in aggregate form, but the presence of a |
| 7642 |
-- name causes this to be interpreted as named association which in |
| 7643 |
-- turn must be converted into an aggregate. |
| 7644 |
|
| 7645 |
-- pragma Global (In_Out => (A, B, C)) |
| 7646 |
-- ^ ^ |
| 7647 |
-- name aggregate |
| 7648 |
|
| 7649 |
-- pragma Global ((In_Out => (A, B, C))) |
| 7650 |
-- ^ ^ |
| 7651 |
-- aggregate aggregate |
| 7652 |
|
| 7653 |
if Nkind (Expr) = N_Aggregate then |
| 7654 |
if Nam = No_Name then |
| 7655 |
return; |
| 7656 |
end if; |
| 7657 |
|
| 7658 |
-- Do not transform a null argument into an aggregate as N_Null has |
| 7659 |
-- special meaning in formal verification pragmas. |
| 7660 |
|
| 7661 |
elsif Nkind (Expr) = N_Null then |
| 7662 |
return; |
| 7663 |
end if; |
| 7664 |
|
| 7665 |
-- Everything comes from source if the original comes from source |
| 7666 |
|
| 7667 |
Set_Comes_From_Source_Default (Comes_From_Source (Arg)); |
| 7668 |
|
| 7669 |
-- Positional argument is transformed into an aggregate with an |
| 7670 |
-- Expressions list. |
| 7671 |
|
| 7672 |
if Nam = No_Name then |
| 7673 |
Exprs := New_List (Relocate_Node (Expr)); |
| 7674 |
|
| 7675 |
-- An associative argument is transformed into an aggregate with |
| 7676 |
-- Component_Associations. |
| 7677 |
|
| 7678 |
else |
| 7679 |
Comps := New_List ( |
| 7680 |
Make_Component_Association (Loc, |
| 7681 |
Choices => New_List (Make_Identifier (Nam_Loc, Nam)), |
| 7682 |
Expression => Relocate_Node (Expr))); |
| 7683 |
end if; |
| 7684 |
|
| 7685 |
Set_Expression (Arg, |
| 7686 |
Make_Aggregate (Loc, |
| 7687 |
Component_Associations => Comps, |
| 7688 |
Expressions => Exprs)); |
| 7689 |
|
| 7690 |
-- Restore Comes_From_Source default |
| 7691 |
|
| 7692 |
Set_Comes_From_Source_Default (CFSD); |
| 7693 |
end Ensure_Aggregate_Form; |
| 7694 |
|
| 7695 |
------------------ |
| 7696 |
-- Error_Pragma -- |
| 7697 |
------------------ |
| 7698 |
|
| 7699 |
procedure Error_Pragma (Msg : String) is |
| 7700 |
begin |
| 7701 |
Error_Msg_Name_1 := Pname; |
| 7702 |
Error_Msg_N (Fix_Error (Msg), N); |
| 7703 |
raise Pragma_Exit; |
| 7704 |
end Error_Pragma; |
| 7705 |
|
| 7706 |
---------------------- |
| 7707 |
-- Error_Pragma_Arg -- |
| 7708 |
---------------------- |
| 7709 |
|
| 7710 |
procedure Error_Pragma_Arg (Msg : String; Arg : Node_Id) is |
| 7711 |
begin |
| 7712 |
Error_Msg_Name_1 := Pname; |
| 7713 |
Error_Msg_N (Fix_Error (Msg), Get_Pragma_Arg (Arg)); |
| 7714 |
raise Pragma_Exit; |
| 7715 |
end Error_Pragma_Arg; |
| 7716 |
|
| 7717 |
procedure Error_Pragma_Arg (Msg1, Msg2 : String; Arg : Node_Id) is |
| 7718 |
begin |
| 7719 |
Error_Msg_Name_1 := Pname; |
| 7720 |
Error_Msg_N (Fix_Error (Msg1), Get_Pragma_Arg (Arg)); |
| 7721 |
Error_Pragma_Arg (Msg2, Arg); |
| 7722 |
end Error_Pragma_Arg; |
| 7723 |
|
| 7724 |
---------------------------- |
| 7725 |
-- Error_Pragma_Arg_Ident -- |
| 7726 |
---------------------------- |
| 7727 |
|
| 7728 |
procedure Error_Pragma_Arg_Ident (Msg : String; Arg : Node_Id) is |
| 7729 |
begin |
| 7730 |
Error_Msg_Name_1 := Pname; |
| 7731 |
Error_Msg_N (Fix_Error (Msg), Arg); |
| 7732 |
raise Pragma_Exit; |
| 7733 |
end Error_Pragma_Arg_Ident; |
| 7734 |
|
| 7735 |
---------------------- |
| 7736 |
-- Error_Pragma_Ref -- |
| 7737 |
---------------------- |
| 7738 |
|
| 7739 |
procedure Error_Pragma_Ref (Msg : String; Ref : Entity_Id) is |
| 7740 |
begin |
| 7741 |
Error_Msg_Name_1 := Pname; |
| 7742 |
Error_Msg_Sloc := Sloc (Ref); |
| 7743 |
Error_Msg_NE (Fix_Error (Msg), N, Ref); |
| 7744 |
raise Pragma_Exit; |
| 7745 |
end Error_Pragma_Ref; |
| 7746 |
|
| 7747 |
------------------------ |
| 7748 |
-- Find_Lib_Unit_Name -- |
| 7749 |
------------------------ |
| 7750 |
|
| 7751 |
function Find_Lib_Unit_Name return Entity_Id is |
| 7752 |
begin |
| 7753 |
-- Return inner compilation unit entity, for case of nested |
| 7754 |
-- categorization pragmas. This happens in generic unit. |
| 7755 |
|
| 7756 |
if Nkind (Parent (N)) = N_Package_Specification |
| 7757 |
and then Defining_Entity (Parent (N)) /= Current_Scope |
| 7758 |
then |
| 7759 |
return Defining_Entity (Parent (N)); |
| 7760 |
else |
| 7761 |
return Current_Scope; |
| 7762 |
end if; |
| 7763 |
end Find_Lib_Unit_Name; |
| 7764 |
|
| 7765 |
---------------------------- |
| 7766 |
-- Find_Program_Unit_Name -- |
| 7767 |
---------------------------- |
| 7768 |
|
| 7769 |
procedure Find_Program_Unit_Name (Id : Node_Id) is |
| 7770 |
Unit_Name : Entity_Id; |
| 7771 |
Unit_Kind : Node_Kind; |
| 7772 |
P : constant Node_Id := Parent (N); |
| 7773 |
|
| 7774 |
begin |
| 7775 |
if Nkind (P) = N_Compilation_Unit then |
| 7776 |
Unit_Kind := Nkind (Unit (P)); |
| 7777 |
|
| 7778 |
if Unit_Kind in N_Subprogram_Declaration |
| 7779 |
| N_Package_Declaration |
| 7780 |
| N_Generic_Declaration |
| 7781 |
then |
| 7782 |
Unit_Name := Defining_Entity (Unit (P)); |
| 7783 |
|
| 7784 |
if Chars (Id) = Chars (Unit_Name) then |
| 7785 |
Set_Entity (Id, Unit_Name); |
| 7786 |
Set_Etype (Id, Etype (Unit_Name)); |
| 7787 |
else |
| 7788 |
Set_Etype (Id, Any_Type); |
| 7789 |
Error_Pragma |
| 7790 |
("cannot find program unit referenced by pragma%"); |
| 7791 |
end if; |
| 7792 |
|
| 7793 |
else |
| 7794 |
Set_Etype (Id, Any_Type); |
| 7795 |
Error_Pragma ("pragma% inapplicable to this unit"); |
| 7796 |
end if; |
| 7797 |
|
| 7798 |
else |
| 7799 |
Analyze (Id); |
| 7800 |
end if; |
| 7801 |
end Find_Program_Unit_Name; |
| 7802 |
|
| 7803 |
----------------------------------------- |
| 7804 |
-- Find_Unique_Parameterless_Procedure -- |
| 7805 |
----------------------------------------- |
| 7806 |
|
| 7807 |
function Find_Unique_Parameterless_Procedure |
| 7808 |
(Name : Entity_Id; |
| 7809 |
Arg : Node_Id) return Entity_Id |
| 7810 |
is |
| 7811 |
Proc : Entity_Id := Empty; |
| 7812 |
|
| 7813 |
begin |
| 7814 |
-- Perform sanity checks on Name |
| 7815 |
|
| 7816 |
if not Is_Entity_Name (Name) then |
| 7817 |
Error_Pragma_Arg |
| 7818 |
("argument of pragma% must be entity name", Arg); |
| 7819 |
|
| 7820 |
elsif not Is_Overloaded (Name) then |
| 7821 |
Proc := Entity (Name); |
| 7822 |
|
| 7823 |
if Ekind (Proc) /= E_Procedure |
| 7824 |
or else Present (First_Formal (Proc)) |
| 7825 |
then |
| 7826 |
Error_Pragma_Arg |
| 7827 |
("argument of pragma% must be parameterless procedure", Arg); |
| 7828 |
end if; |
| 7829 |
|
| 7830 |
-- Otherwise, search through interpretations looking for one which |
| 7831 |
-- has no parameters. |
| 7832 |
|
| 7833 |
else |
| 7834 |
declare |
| 7835 |
Found : Boolean := False; |
| 7836 |
It : Interp; |
| 7837 |
Index : Interp_Index; |
| 7838 |
|
| 7839 |
begin |
| 7840 |
Get_First_Interp (Name, Index, It); |
| 7841 |
while Present (It.Nam) loop |
| 7842 |
Proc := It.Nam; |
| 7843 |
|
| 7844 |
if Ekind (Proc) = E_Procedure |
| 7845 |
and then No (First_Formal (Proc)) |
| 7846 |
then |
| 7847 |
-- We found an interpretation, note it and continue |
| 7848 |
-- looking looking to verify it is unique. |
| 7849 |
|
| 7850 |
if not Found then |
| 7851 |
Found := True; |
| 7852 |
Set_Entity (Name, Proc); |
| 7853 |
Set_Is_Overloaded (Name, False); |
| 7854 |
|
| 7855 |
-- Two procedures with the same name, log an error |
| 7856 |
-- since the name is ambiguous. |
| 7857 |
|
| 7858 |
else |
| 7859 |
Error_Pragma_Arg |
| 7860 |
("ambiguous handler name for pragma%", Arg); |
| 7861 |
end if; |
| 7862 |
end if; |
| 7863 |
|
| 7864 |
Get_Next_Interp (Index, It); |
| 7865 |
end loop; |
| 7866 |
|
| 7867 |
if not Found then |
| 7868 |
-- Issue an error if we haven't found a suitable match for |
| 7869 |
-- Name. |
| 7870 |
|
| 7871 |
Error_Pragma_Arg |
| 7872 |
("argument of pragma% must be parameterless procedure", |
| 7873 |
Arg); |
| 7874 |
|
| 7875 |
else |
| 7876 |
Proc := Entity (Name); |
| 7877 |
end if; |
| 7878 |
end; |
| 7879 |
end if; |
| 7880 |
|
| 7881 |
return Proc; |
| 7882 |
end Find_Unique_Parameterless_Procedure; |
| 7883 |
|
| 7884 |
--------------- |
| 7885 |
-- Fix_Error -- |
| 7886 |
--------------- |
| 7887 |
|
| 7888 |
function Fix_Error (Msg : String) return String is |
| 7889 |
Res : String (Msg'Range) := Msg; |
| 7890 |
Res_Last : Natural := Msg'Last; |
| 7891 |
J : Natural; |
| 7892 |
|
| 7893 |
begin |
| 7894 |
-- If we have a rewriting of another pragma, go to that pragma |
| 7895 |
|
| 7896 |
if Is_Rewrite_Substitution (N) |
| 7897 |
and then Nkind (Original_Node (N)) = N_Pragma |
| 7898 |
then |
| 7899 |
Error_Msg_Name_1 := Pragma_Name (Original_Node (N)); |
| 7900 |
end if; |
| 7901 |
|
| 7902 |
-- Case where pragma comes from an aspect specification |
| 7903 |
|
| 7904 |
if From_Aspect_Specification (N) then |
| 7905 |
|
| 7906 |
-- Change appearance of "pragma" in message to "aspect" |
| 7907 |
|
| 7908 |
J := Res'First; |
| 7909 |
while J <= Res_Last - 5 loop |
| 7910 |
if Res (J .. J + 5) = "pragma" then |
| 7911 |
Res (J .. J + 5) := "aspect"; |
| 7912 |
J := J + 6; |
| 7913 |
|
| 7914 |
else |
| 7915 |
J := J + 1; |
| 7916 |
end if; |
| 7917 |
end loop; |
| 7918 |
|
| 7919 |
-- Change "argument of" at start of message to "entity for" |
| 7920 |
|
| 7921 |
if Res'Length > 11 |
| 7922 |
and then Res (Res'First .. Res'First + 10) = "argument of" |
| 7923 |
then |
| 7924 |
Res (Res'First .. Res'First + 9) := "entity for"; |
| 7925 |
Res (Res'First + 10 .. Res_Last - 1) := |
| 7926 |
Res (Res'First + 11 .. Res_Last); |
| 7927 |
Res_Last := Res_Last - 1; |
| 7928 |
end if; |
| 7929 |
|
| 7930 |
-- Change "argument" at start of message to "entity" |
| 7931 |
|
| 7932 |
if Res'Length > 8 |
| 7933 |
and then Res (Res'First .. Res'First + 7) = "argument" |
| 7934 |
then |
| 7935 |
Res (Res'First .. Res'First + 5) := "entity"; |
| 7936 |
Res (Res'First + 6 .. Res_Last - 2) := |
| 7937 |
Res (Res'First + 8 .. Res_Last); |
| 7938 |
Res_Last := Res_Last - 2; |
| 7939 |
end if; |
| 7940 |
|
| 7941 |
-- Get name from corresponding aspect |
| 7942 |
|
| 7943 |
Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N); |
| 7944 |
end if; |
| 7945 |
|
| 7946 |
-- Return possibly modified message |
| 7947 |
|
| 7948 |
return Res (Res'First .. Res_Last); |
| 7949 |
end Fix_Error; |
| 7950 |
|
| 7951 |
------------------------- |
| 7952 |
-- Gather_Associations -- |
| 7953 |
------------------------- |
| 7954 |
|
| 7955 |
procedure Gather_Associations |
| 7956 |
(Names : Name_List; |
| 7957 |
Args : out Args_List) |
| 7958 |
is |
| 7959 |
Arg : Node_Id; |
| 7960 |
|
| 7961 |
begin |
| 7962 |
-- Initialize all parameters to Empty |
| 7963 |
|
| 7964 |
for J in Args'Range loop |
| 7965 |
Args (J) := Empty; |
| 7966 |
end loop; |
| 7967 |
|
| 7968 |
-- That's all we have to do if there are no argument associations |
| 7969 |
|
| 7970 |
if No (Pragma_Argument_Associations (N)) then |
| 7971 |
return; |
| 7972 |
end if; |
| 7973 |
|
| 7974 |
-- Otherwise first deal with any positional parameters present |
| 7975 |
|
| 7976 |
Arg := First (Pragma_Argument_Associations (N)); |
| 7977 |
for Index in Args'Range loop |
| 7978 |
exit when No (Arg) or else Chars (Arg) /= No_Name; |
| 7979 |
Args (Index) := Get_Pragma_Arg (Arg); |
| 7980 |
Next (Arg); |
| 7981 |
end loop; |
| 7982 |
|
| 7983 |
-- Positional parameters all processed, if any left, then we |
| 7984 |
-- have too many positional parameters. |
| 7985 |
|
| 7986 |
if Present (Arg) and then Chars (Arg) = No_Name then |
| 7987 |
Error_Pragma_Arg |
| 7988 |
("too many positional associations for pragma%", Arg); |
| 7989 |
end if; |
| 7990 |
|
| 7991 |
-- Process named parameters if any are present |
| 7992 |
|
| 7993 |
while Present (Arg) loop |
| 7994 |
if Chars (Arg) = No_Name then |
| 7995 |
Error_Pragma_Arg |
| 7996 |
("positional association cannot follow named association", |
| 7997 |
Arg); |
| 7998 |
|
| 7999 |
else |
| 8000 |
for Index in Names'Range loop |
| 8001 |
if Names (Index) = Chars (Arg) then |
| 8002 |
if Present (Args (Index)) then |
| 8003 |
Error_Pragma_Arg |
| 8004 |
("duplicate argument association for pragma%", Arg); |
| 8005 |
else |
| 8006 |
Args (Index) := Get_Pragma_Arg (Arg); |
| 8007 |
exit; |
| 8008 |
end if; |
| 8009 |
end if; |
| 8010 |
|
| 8011 |
if Index = Names'Last then |
| 8012 |
Error_Msg_Name_1 := Pname; |
| 8013 |
Error_Msg_N ("pragma% does not allow & argument", Arg); |
| 8014 |
|
| 8015 |
-- Check for possible misspelling |
| 8016 |
|
| 8017 |
for Index1 in Names'Range loop |
| 8018 |
if Is_Bad_Spelling_Of |
| 8019 |
(Chars (Arg), Names (Index1)) |
| 8020 |
then |
| 8021 |
Error_Msg_Name_1 := Names (Index1); |
| 8022 |
Error_Msg_N -- CODEFIX |
| 8023 |
("\possible misspelling of%", Arg); |
| 8024 |
exit; |
| 8025 |
end if; |
| 8026 |
end loop; |
| 8027 |
|
| 8028 |
raise Pragma_Exit; |
| 8029 |
end if; |
| 8030 |
end loop; |
| 8031 |
end if; |
| 8032 |
|
| 8033 |
Next (Arg); |
| 8034 |
end loop; |
| 8035 |
end Gather_Associations; |
| 8036 |
|
| 8037 |
----------------- |
| 8038 |
-- GNAT_Pragma -- |
| 8039 |
----------------- |
| 8040 |
|
| 8041 |
procedure GNAT_Pragma is |
| 8042 |
begin |
| 8043 |
-- We need to check the No_Implementation_Pragmas restriction for |
| 8044 |
-- the case of a pragma from source. Note that the case of aspects |
| 8045 |
-- generating corresponding pragmas marks these pragmas as not being |
| 8046 |
-- from source, so this test also catches that case. |
| 8047 |
|
| 8048 |
if Comes_From_Source (N) then |
| 8049 |
Check_Restriction (No_Implementation_Pragmas, N); |
| 8050 |
end if; |
| 8051 |
end GNAT_Pragma; |
| 8052 |
|
| 8053 |
-------------------------- |
| 8054 |
-- Is_Before_First_Decl -- |
| 8055 |
-------------------------- |
| 8056 |
|
| 8057 |
function Is_Before_First_Decl |
| 8058 |
(Pragma_Node : Node_Id; |
| 8059 |
Decls : List_Id) return Boolean |
| 8060 |
is |
| 8061 |
Item : Node_Id := First (Decls); |
| 8062 |
|
| 8063 |
begin |
| 8064 |
-- Only other pragmas can come before this pragma, but they might |
| 8065 |
-- have been rewritten so check the original node. |
| 8066 |
|
| 8067 |
loop |
| 8068 |
if No (Item) or else Nkind (Original_Node (Item)) /= N_Pragma then |
| 8069 |
return False; |
| 8070 |
|
| 8071 |
elsif Item = Pragma_Node then |
| 8072 |
return True; |
| 8073 |
end if; |
| 8074 |
|
| 8075 |
Next (Item); |
| 8076 |
end loop; |
| 8077 |
end Is_Before_First_Decl; |
| 8078 |
|
| 8079 |
----------------------------- |
| 8080 |
-- Is_Configuration_Pragma -- |
| 8081 |
----------------------------- |
| 8082 |
|
| 8083 |
-- A configuration pragma must appear in the context clause of a |
| 8084 |
-- compilation unit, and only other pragmas may precede it. Note that |
| 8085 |
-- the test below also permits use in a configuration pragma file. |
| 8086 |
|
| 8087 |
function Is_Configuration_Pragma return Boolean is |
| 8088 |
Lis : List_Id; |
| 8089 |
Par : constant Node_Id := Parent (N); |
| 8090 |
Prg : Node_Id; |
| 8091 |
|
| 8092 |
begin |
| 8093 |
-- Don't evaluate List_Containing (N) if Parent (N) could be |
| 8094 |
-- an N_Aspect_Specification node. |
| 8095 |
|
| 8096 |
if not Is_List_Member (N) then |
| 8097 |
return False; |
| 8098 |
end if; |
| 8099 |
|
| 8100 |
Lis := List_Containing (N); |
| 8101 |
|
| 8102 |
-- If no parent, then we are in the configuration pragma file, |
| 8103 |
-- so the placement is definitely appropriate. |
| 8104 |
|
| 8105 |
if No (Par) then |
| 8106 |
return True; |
| 8107 |
|
| 8108 |
-- Otherwise we must be in the context clause of a compilation unit |
| 8109 |
-- and the only thing allowed before us in the context list is more |
| 8110 |
-- configuration pragmas. |
| 8111 |
|
| 8112 |
elsif Nkind (Par) = N_Compilation_Unit |
| 8113 |
and then Context_Items (Par) = Lis |
| 8114 |
then |
| 8115 |
Prg := First (Lis); |
| 8116 |
|
| 8117 |
loop |
| 8118 |
if Prg = N then |
| 8119 |
return True; |
| 8120 |
elsif Nkind (Prg) /= N_Pragma then |
| 8121 |
return False; |
| 8122 |
end if; |
| 8123 |
|
| 8124 |
Next (Prg); |
| 8125 |
end loop; |
| 8126 |
|
| 8127 |
else |
| 8128 |
return False; |
| 8129 |
end if; |
| 8130 |
end Is_Configuration_Pragma; |
| 8131 |
|
| 8132 |
-------------------------- |
| 8133 |
-- Is_In_Context_Clause -- |
| 8134 |
-------------------------- |
| 8135 |
|
| 8136 |
function Is_In_Context_Clause return Boolean is |
| 8137 |
Plist : List_Id; |
| 8138 |
Parent_Node : Node_Id; |
| 8139 |
|
| 8140 |
begin |
| 8141 |
if Is_List_Member (N) then |
| 8142 |
Plist := List_Containing (N); |
| 8143 |
Parent_Node := Parent (Plist); |
| 8144 |
|
| 8145 |
return Present (Parent_Node) |
| 8146 |
and then Nkind (Parent_Node) = N_Compilation_Unit |
| 8147 |
and then Context_Items (Parent_Node) = Plist; |
| 8148 |
end if; |
| 8149 |
|
| 8150 |
return False; |
| 8151 |
end Is_In_Context_Clause; |
| 8152 |
|
| 8153 |
--------------------------------- |
| 8154 |
-- Is_Static_String_Expression -- |
| 8155 |
--------------------------------- |
| 8156 |
|
| 8157 |
function Is_Static_String_Expression (Arg : Node_Id) return Boolean is |
| 8158 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 8159 |
Lit : constant Boolean := Nkind (Argx) = N_String_Literal; |
| 8160 |
|
| 8161 |
begin |
| 8162 |
Analyze_And_Resolve (Argx); |
| 8163 |
|
| 8164 |
-- Special case Ada 83, where the expression will never be static, |
| 8165 |
-- but we will return true if we had a string literal to start with. |
| 8166 |
|
| 8167 |
if Ada_Version = Ada_83 then |
| 8168 |
return Lit; |
| 8169 |
|
| 8170 |
-- Normal case, true only if we end up with a string literal that |
| 8171 |
-- is marked as being the result of evaluating a static expression. |
| 8172 |
|
| 8173 |
else |
| 8174 |
return Is_OK_Static_Expression (Argx) |
| 8175 |
and then Nkind (Argx) = N_String_Literal; |
| 8176 |
end if; |
| 8177 |
|
| 8178 |
end Is_Static_String_Expression; |
| 8179 |
|
| 8180 |
---------------------- |
| 8181 |
-- Pragma_Misplaced -- |
| 8182 |
---------------------- |
| 8183 |
|
| 8184 |
procedure Pragma_Misplaced is |
| 8185 |
begin |
| 8186 |
Error_Pragma ("incorrect placement of pragma%"); |
| 8187 |
end Pragma_Misplaced; |
| 8188 |
|
| 8189 |
------------------------------------------------ |
| 8190 |
-- Process_Atomic_Independent_Shared_Volatile -- |
| 8191 |
------------------------------------------------ |
| 8192 |
|
| 8193 |
procedure Process_Atomic_Independent_Shared_Volatile is |
| 8194 |
procedure Check_Full_Access_Only (Ent : Entity_Id); |
| 8195 |
-- Apply legality checks to type or object Ent subject to the |
| 8196 |
-- Full_Access_Only aspect in Ada 2022 (RM C.6(8.2)). |
| 8197 |
|
| 8198 |
procedure Mark_Component_Or_Object (Ent : Entity_Id); |
| 8199 |
-- Appropriately set flags on the given entity, either an array or |
| 8200 |
-- record component, or an object declaration) according to the |
| 8201 |
-- current pragma. |
| 8202 |
|
| 8203 |
procedure Mark_Type (Ent : Entity_Id); |
| 8204 |
-- Appropriately set flags on the given entity, a type |
| 8205 |
|
| 8206 |
procedure Set_Atomic_VFA (Ent : Entity_Id); |
| 8207 |
-- Set given type as Is_Atomic or Is_Volatile_Full_Access. Also, if |
| 8208 |
-- no explicit alignment was given, set alignment to unknown, since |
| 8209 |
-- back end knows what the alignment requirements are for atomic and |
| 8210 |
-- full access arrays. Note: this is necessary for derived types. |
| 8211 |
|
| 8212 |
------------------------- |
| 8213 |
-- Check_Full_Access_Only -- |
| 8214 |
------------------------- |
| 8215 |
|
| 8216 |
procedure Check_Full_Access_Only (Ent : Entity_Id) is |
| 8217 |
Typ : Entity_Id; |
| 8218 |
|
| 8219 |
Full_Access_Subcomponent : exception; |
| 8220 |
-- Exception raised if a full access subcomponent is found |
| 8221 |
|
| 8222 |
Generic_Type_Subcomponent : exception; |
| 8223 |
-- Exception raised if a subcomponent with generic type is found |
| 8224 |
|
| 8225 |
procedure Check_Subcomponents (Typ : Entity_Id); |
| 8226 |
-- Apply checks to subcomponents recursively |
| 8227 |
|
| 8228 |
------------------------- |
| 8229 |
-- Check_Subcomponents -- |
| 8230 |
------------------------- |
| 8231 |
|
| 8232 |
procedure Check_Subcomponents (Typ : Entity_Id) is |
| 8233 |
Comp : Entity_Id; |
| 8234 |
|
| 8235 |
begin |
| 8236 |
if Is_Array_Type (Typ) then |
| 8237 |
Comp := Component_Type (Typ); |
| 8238 |
|
| 8239 |
if Has_Atomic_Components (Typ) |
| 8240 |
or else Is_Full_Access (Comp) |
| 8241 |
then |
| 8242 |
raise Full_Access_Subcomponent; |
| 8243 |
|
| 8244 |
elsif Is_Generic_Type (Comp) then |
| 8245 |
raise Generic_Type_Subcomponent; |
| 8246 |
end if; |
| 8247 |
|
| 8248 |
-- Recurse on the component type |
| 8249 |
|
| 8250 |
Check_Subcomponents (Comp); |
| 8251 |
|
| 8252 |
elsif Is_Record_Type (Typ) then |
| 8253 |
Comp := First_Component_Or_Discriminant (Typ); |
| 8254 |
while Present (Comp) loop |
| 8255 |
|
| 8256 |
if Is_Full_Access (Comp) |
| 8257 |
or else Is_Full_Access (Etype (Comp)) |
| 8258 |
then |
| 8259 |
raise Full_Access_Subcomponent; |
| 8260 |
|
| 8261 |
elsif Is_Generic_Type (Etype (Comp)) then |
| 8262 |
raise Generic_Type_Subcomponent; |
| 8263 |
end if; |
| 8264 |
|
| 8265 |
-- Recurse on the component type |
| 8266 |
|
| 8267 |
Check_Subcomponents (Etype (Comp)); |
| 8268 |
|
| 8269 |
Next_Component_Or_Discriminant (Comp); |
| 8270 |
end loop; |
| 8271 |
end if; |
| 8272 |
end Check_Subcomponents; |
| 8273 |
|
| 8274 |
-- Start of processing for Check_Full_Access_Only |
| 8275 |
|
| 8276 |
begin |
| 8277 |
-- Fetch the type in case we are dealing with an object or |
| 8278 |
-- component. |
| 8279 |
|
| 8280 |
if Is_Type (Ent) then |
| 8281 |
Typ := Ent; |
| 8282 |
else |
| 8283 |
pragma Assert (Is_Object (Ent) |
| 8284 |
or else |
| 8285 |
Nkind (Declaration_Node (Ent)) = N_Component_Declaration); |
| 8286 |
|
| 8287 |
Typ := Etype (Ent); |
| 8288 |
end if; |
| 8289 |
|
| 8290 |
if not Is_Volatile (Ent) and then not Is_Volatile (Typ) then |
| 8291 |
Error_Pragma |
| 8292 |
("cannot have Full_Access_Only without Volatile/Atomic " |
| 8293 |
& "(RM C.6(8.2))"); |
| 8294 |
end if; |
| 8295 |
|
| 8296 |
-- Check all the subcomponents of the type recursively, if any |
| 8297 |
|
| 8298 |
Check_Subcomponents (Typ); |
| 8299 |
|
| 8300 |
exception |
| 8301 |
when Full_Access_Subcomponent => |
| 8302 |
Error_Pragma |
| 8303 |
("cannot have Full_Access_Only with full access subcomponent " |
| 8304 |
& "(RM C.6(8.2))"); |
| 8305 |
|
| 8306 |
when Generic_Type_Subcomponent => |
| 8307 |
Error_Pragma |
| 8308 |
("cannot have Full_Access_Only with subcomponent of generic " |
| 8309 |
& "type (RM C.6(8.2))"); |
| 8310 |
|
| 8311 |
end Check_Full_Access_Only; |
| 8312 |
|
| 8313 |
------------------------------ |
| 8314 |
-- Mark_Component_Or_Object -- |
| 8315 |
------------------------------ |
| 8316 |
|
| 8317 |
procedure Mark_Component_Or_Object (Ent : Entity_Id) is |
| 8318 |
begin |
| 8319 |
if Prag_Id = Pragma_Atomic |
| 8320 |
or else Prag_Id = Pragma_Shared |
| 8321 |
or else Prag_Id = Pragma_Volatile_Full_Access |
| 8322 |
then |
| 8323 |
if Prag_Id = Pragma_Volatile_Full_Access then |
| 8324 |
Set_Is_Volatile_Full_Access (Ent); |
| 8325 |
else |
| 8326 |
Set_Is_Atomic (Ent); |
| 8327 |
end if; |
| 8328 |
|
| 8329 |
-- If the object declaration has an explicit initialization, a |
| 8330 |
-- temporary may have to be created to hold the expression, to |
| 8331 |
-- ensure that access to the object remains atomic. |
| 8332 |
|
| 8333 |
if Nkind (Parent (Ent)) = N_Object_Declaration |
| 8334 |
and then Present (Expression (Parent (Ent))) |
| 8335 |
then |
| 8336 |
Set_Has_Delayed_Freeze (Ent); |
| 8337 |
end if; |
| 8338 |
end if; |
| 8339 |
|
| 8340 |
-- Atomic/Shared/Volatile_Full_Access imply Independent |
| 8341 |
|
| 8342 |
if Prag_Id /= Pragma_Volatile then |
| 8343 |
Set_Is_Independent (Ent); |
| 8344 |
|
| 8345 |
if Prag_Id = Pragma_Independent then |
| 8346 |
Record_Independence_Check (N, Ent); |
| 8347 |
end if; |
| 8348 |
end if; |
| 8349 |
|
| 8350 |
-- Atomic/Shared/Volatile_Full_Access imply Volatile |
| 8351 |
|
| 8352 |
if Prag_Id /= Pragma_Independent then |
| 8353 |
Set_Is_Volatile (Ent); |
| 8354 |
Set_Treat_As_Volatile (Ent); |
| 8355 |
end if; |
| 8356 |
end Mark_Component_Or_Object; |
| 8357 |
|
| 8358 |
--------------- |
| 8359 |
-- Mark_Type -- |
| 8360 |
--------------- |
| 8361 |
|
| 8362 |
procedure Mark_Type (Ent : Entity_Id) is |
| 8363 |
begin |
| 8364 |
-- Attribute belongs on the base type. If the view of the type is |
| 8365 |
-- currently private, it also belongs on the underlying type. |
| 8366 |
|
| 8367 |
-- In Ada 2022, the pragma can apply to a formal type, for which |
| 8368 |
-- there may be no underlying type. |
| 8369 |
|
| 8370 |
if Prag_Id = Pragma_Atomic |
| 8371 |
or else Prag_Id = Pragma_Shared |
| 8372 |
or else Prag_Id = Pragma_Volatile_Full_Access |
| 8373 |
then |
| 8374 |
Set_Atomic_VFA (Ent); |
| 8375 |
Set_Atomic_VFA (Base_Type (Ent)); |
| 8376 |
|
| 8377 |
if not Is_Generic_Type (Ent) then |
| 8378 |
Set_Atomic_VFA (Underlying_Type (Ent)); |
| 8379 |
end if; |
| 8380 |
end if; |
| 8381 |
|
| 8382 |
-- Atomic/Shared/Volatile_Full_Access imply Independent |
| 8383 |
|
| 8384 |
if Prag_Id /= Pragma_Volatile then |
| 8385 |
Set_Is_Independent (Ent); |
| 8386 |
Set_Is_Independent (Base_Type (Ent)); |
| 8387 |
|
| 8388 |
if not Is_Generic_Type (Ent) then |
| 8389 |
Set_Is_Independent (Underlying_Type (Ent)); |
| 8390 |
|
| 8391 |
if Prag_Id = Pragma_Independent then |
| 8392 |
Record_Independence_Check (N, Base_Type (Ent)); |
| 8393 |
end if; |
| 8394 |
end if; |
| 8395 |
end if; |
| 8396 |
|
| 8397 |
-- Atomic/Shared/Volatile_Full_Access imply Volatile |
| 8398 |
|
| 8399 |
if Prag_Id /= Pragma_Independent then |
| 8400 |
Set_Is_Volatile (Ent); |
| 8401 |
Set_Is_Volatile (Base_Type (Ent)); |
| 8402 |
|
| 8403 |
if not Is_Generic_Type (Ent) then |
| 8404 |
Set_Is_Volatile (Underlying_Type (Ent)); |
| 8405 |
Set_Treat_As_Volatile (Underlying_Type (Ent)); |
| 8406 |
end if; |
| 8407 |
|
| 8408 |
Set_Treat_As_Volatile (Ent); |
| 8409 |
end if; |
| 8410 |
|
| 8411 |
-- Apply Volatile to the composite type's individual components, |
| 8412 |
-- (RM C.6(8/3)). |
| 8413 |
|
| 8414 |
if Prag_Id = Pragma_Volatile |
| 8415 |
and then Is_Record_Type (Etype (Ent)) |
| 8416 |
then |
| 8417 |
declare |
| 8418 |
Comp : Entity_Id; |
| 8419 |
begin |
| 8420 |
Comp := First_Component (Ent); |
| 8421 |
while Present (Comp) loop |
| 8422 |
Mark_Component_Or_Object (Comp); |
| 8423 |
|
| 8424 |
Next_Component (Comp); |
| 8425 |
end loop; |
| 8426 |
end; |
| 8427 |
end if; |
| 8428 |
end Mark_Type; |
| 8429 |
|
| 8430 |
-------------------- |
| 8431 |
-- Set_Atomic_VFA -- |
| 8432 |
-------------------- |
| 8433 |
|
| 8434 |
procedure Set_Atomic_VFA (Ent : Entity_Id) is |
| 8435 |
begin |
| 8436 |
if Prag_Id = Pragma_Volatile_Full_Access then |
| 8437 |
Set_Is_Volatile_Full_Access (Ent); |
| 8438 |
else |
| 8439 |
Set_Is_Atomic (Ent); |
| 8440 |
end if; |
| 8441 |
|
| 8442 |
if not Has_Alignment_Clause (Ent) then |
| 8443 |
Reinit_Alignment (Ent); |
| 8444 |
end if; |
| 8445 |
end Set_Atomic_VFA; |
| 8446 |
|
| 8447 |
-- Local variables |
| 8448 |
|
| 8449 |
Decl : Node_Id; |
| 8450 |
E : Entity_Id; |
| 8451 |
E_Arg : Node_Id; |
| 8452 |
|
| 8453 |
-- Start of processing for Process_Atomic_Independent_Shared_Volatile |
| 8454 |
|
| 8455 |
begin |
| 8456 |
Check_Ada_83_Warning; |
| 8457 |
Check_No_Identifiers; |
| 8458 |
Check_Arg_Count (1); |
| 8459 |
Check_Arg_Is_Local_Name (Arg1); |
| 8460 |
E_Arg := Get_Pragma_Arg (Arg1); |
| 8461 |
|
| 8462 |
if Etype (E_Arg) = Any_Type then |
| 8463 |
return; |
| 8464 |
end if; |
| 8465 |
|
| 8466 |
E := Entity (E_Arg); |
| 8467 |
Decl := Declaration_Node (E); |
| 8468 |
|
| 8469 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 8470 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 8471 |
|
| 8472 |
Mark_Ghost_Pragma (N, E); |
| 8473 |
|
| 8474 |
-- Check duplicate before we chain ourselves |
| 8475 |
|
| 8476 |
Check_Duplicate_Pragma (E); |
| 8477 |
|
| 8478 |
-- Check the constraints of Full_Access_Only in Ada 2022. Note that |
| 8479 |
-- they do not apply to GNAT's Volatile_Full_Access because 1) this |
| 8480 |
-- aspect subsumes the Volatile aspect and 2) nesting is supported |
| 8481 |
-- for this aspect and the outermost enclosing VFA object prevails. |
| 8482 |
|
| 8483 |
-- Note also that we used to forbid specifying both Atomic and VFA on |
| 8484 |
-- the same type or object, but the restriction has been lifted in |
| 8485 |
-- light of the semantics of Full_Access_Only and Atomic in Ada 2022. |
| 8486 |
|
| 8487 |
if Prag_Id = Pragma_Volatile_Full_Access |
| 8488 |
and then From_Aspect_Specification (N) |
| 8489 |
and then |
| 8490 |
Get_Aspect_Id (Corresponding_Aspect (N)) = Aspect_Full_Access_Only |
| 8491 |
then |
| 8492 |
Check_Full_Access_Only (E); |
| 8493 |
end if; |
| 8494 |
|
| 8495 |
-- Deal with the case where the pragma/attribute is applied to a type |
| 8496 |
|
| 8497 |
if Is_Type (E) then |
| 8498 |
if Rep_Item_Too_Early (E, N) |
| 8499 |
or else Rep_Item_Too_Late (E, N) |
| 8500 |
then |
| 8501 |
return; |
| 8502 |
else |
| 8503 |
Check_First_Subtype (Arg1); |
| 8504 |
end if; |
| 8505 |
|
| 8506 |
Mark_Type (E); |
| 8507 |
|
| 8508 |
-- Deal with the case where the pragma/attribute applies to a |
| 8509 |
-- component or object declaration. |
| 8510 |
|
| 8511 |
elsif Nkind (Decl) = N_Object_Declaration |
| 8512 |
or else (Nkind (Decl) = N_Component_Declaration |
| 8513 |
and then Original_Record_Component (E) = E) |
| 8514 |
then |
| 8515 |
if Rep_Item_Too_Late (E, N) then |
| 8516 |
return; |
| 8517 |
end if; |
| 8518 |
|
| 8519 |
Mark_Component_Or_Object (E); |
| 8520 |
|
| 8521 |
-- In other cases give an error |
| 8522 |
|
| 8523 |
else |
| 8524 |
Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1); |
| 8525 |
end if; |
| 8526 |
end Process_Atomic_Independent_Shared_Volatile; |
| 8527 |
|
| 8528 |
------------------------------------------- |
| 8529 |
-- Process_Compile_Time_Warning_Or_Error -- |
| 8530 |
------------------------------------------- |
| 8531 |
|
| 8532 |
procedure Process_Compile_Time_Warning_Or_Error is |
| 8533 |
P : Node_Id := Parent (N); |
| 8534 |
Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 8535 |
|
| 8536 |
begin |
| 8537 |
Check_Arg_Count (2); |
| 8538 |
Check_No_Identifiers; |
| 8539 |
Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String); |
| 8540 |
Analyze_And_Resolve (Arg1x, Standard_Boolean); |
| 8541 |
|
| 8542 |
if CodePeer_Mode then |
| 8543 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 8544 |
return; |
| 8545 |
end if; |
| 8546 |
|
| 8547 |
-- In GNATprove mode, pragma Compile_Time_Error is translated as |
| 8548 |
-- a Check pragma in GNATprove mode, handled as an assumption in |
| 8549 |
-- GNATprove. This is correct as the compiler will issue an error |
| 8550 |
-- if the condition cannot be statically evaluated to False. |
| 8551 |
-- Compile_Time_Warning are ignored, as the analyzer may not have the |
| 8552 |
-- same information as the compiler (in particular regarding size of |
| 8553 |
-- objects decided in gigi) so it makes no sense to issue a warning |
| 8554 |
-- in GNATprove. |
| 8555 |
|
| 8556 |
if GNATprove_Mode then |
| 8557 |
if Prag_Id = Pragma_Compile_Time_Error then |
| 8558 |
declare |
| 8559 |
New_Args : List_Id; |
| 8560 |
begin |
| 8561 |
-- Implement Compile_Time_Error by generating |
| 8562 |
-- a corresponding Check pragma: |
| 8563 |
|
| 8564 |
-- pragma Check (name, condition); |
| 8565 |
|
| 8566 |
-- where name is the identifier matching the pragma name. So |
| 8567 |
-- rewrite pragma in this manner and analyze the result. |
| 8568 |
|
| 8569 |
New_Args := New_List |
| 8570 |
(Make_Pragma_Argument_Association |
| 8571 |
(Loc, |
| 8572 |
Expression => Make_Identifier (Loc, Pname)), |
| 8573 |
Make_Pragma_Argument_Association |
| 8574 |
(Sloc (Arg1x), |
| 8575 |
Expression => Arg1x)); |
| 8576 |
|
| 8577 |
-- Rewrite as Check pragma |
| 8578 |
|
| 8579 |
Rewrite (N, |
| 8580 |
Make_Pragma (Loc, |
| 8581 |
Chars => Name_Check, |
| 8582 |
Pragma_Argument_Associations => New_Args)); |
| 8583 |
|
| 8584 |
Analyze (N); |
| 8585 |
end; |
| 8586 |
|
| 8587 |
else |
| 8588 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 8589 |
end if; |
| 8590 |
|
| 8591 |
return; |
| 8592 |
end if; |
| 8593 |
|
| 8594 |
-- If the condition is known at compile time (now), validate it now. |
| 8595 |
-- Otherwise, register the expression for validation after the back |
| 8596 |
-- end has been called, because it might be known at compile time |
| 8597 |
-- then. For example, if the expression is "Record_Type'Size /= 32" |
| 8598 |
-- it might be known after the back end has determined the size of |
| 8599 |
-- Record_Type. We do not defer validation if we're inside a generic |
| 8600 |
-- unit, because we will have more information in the instances, and |
| 8601 |
-- this ultimately applies to the main unit itself, because it is not |
| 8602 |
-- compiled by the back end when it is generic. |
| 8603 |
|
| 8604 |
if Compile_Time_Known_Value (Arg1x) then |
| 8605 |
Validate_Compile_Time_Warning_Or_Error (N, Sloc (Arg1)); |
| 8606 |
|
| 8607 |
else |
| 8608 |
while Present (P) and then Nkind (P) not in N_Generic_Declaration |
| 8609 |
loop |
| 8610 |
if (Nkind (P) = N_Subprogram_Body and then not Acts_As_Spec (P)) |
| 8611 |
or else Nkind (P) = N_Package_Body |
| 8612 |
then |
| 8613 |
P := Parent (Corresponding_Spec (P)); |
| 8614 |
|
| 8615 |
else |
| 8616 |
P := Parent (P); |
| 8617 |
end if; |
| 8618 |
end loop; |
| 8619 |
|
| 8620 |
if No (P) |
| 8621 |
and then |
| 8622 |
Nkind (Unit (Cunit (Main_Unit))) not in N_Generic_Declaration |
| 8623 |
then |
| 8624 |
Defer_Compile_Time_Warning_Error_To_BE (N); |
| 8625 |
end if; |
| 8626 |
end if; |
| 8627 |
end Process_Compile_Time_Warning_Or_Error; |
| 8628 |
|
| 8629 |
------------------------ |
| 8630 |
-- Process_Convention -- |
| 8631 |
------------------------ |
| 8632 |
|
| 8633 |
procedure Process_Convention |
| 8634 |
(C : out Convention_Id; |
| 8635 |
Ent : out Entity_Id) |
| 8636 |
is |
| 8637 |
Cname : Name_Id; |
| 8638 |
|
| 8639 |
procedure Diagnose_Multiple_Pragmas (S : Entity_Id); |
| 8640 |
-- Called if we have more than one Export/Import/Convention pragma. |
| 8641 |
-- This is generally illegal, but we have a special case of allowing |
| 8642 |
-- Import and Interface to coexist if they specify the convention in |
| 8643 |
-- a consistent manner. We are allowed to do this, since Interface is |
| 8644 |
-- an implementation defined pragma, and we choose to do it since we |
| 8645 |
-- know Rational allows this combination. S is the entity id of the |
| 8646 |
-- subprogram in question. This procedure also sets the special flag |
| 8647 |
-- Import_Interface_Present in both pragmas in the case where we do |
| 8648 |
-- have matching Import and Interface pragmas. |
| 8649 |
|
| 8650 |
procedure Set_Convention_From_Pragma (E : Entity_Id); |
| 8651 |
-- Set convention in entity E, and also flag that the entity has a |
| 8652 |
-- convention pragma. If entity is for a private or incomplete type, |
| 8653 |
-- also set convention and flag on underlying type. This procedure |
| 8654 |
-- also deals with the special case of C_Pass_By_Copy convention, |
| 8655 |
-- and error checks for inappropriate convention specification. |
| 8656 |
|
| 8657 |
------------------------------- |
| 8658 |
-- Diagnose_Multiple_Pragmas -- |
| 8659 |
------------------------------- |
| 8660 |
|
| 8661 |
procedure Diagnose_Multiple_Pragmas (S : Entity_Id) is |
| 8662 |
Pdec : constant Node_Id := Declaration_Node (S); |
| 8663 |
Decl : Node_Id; |
| 8664 |
Err : Boolean; |
| 8665 |
|
| 8666 |
function Matching_Convention (Decl : Node_Id) return Boolean; |
| 8667 |
-- Decl is a pragma node. This function returns True if this |
| 8668 |
-- pragma has a first argument that is an identifier with a |
| 8669 |
-- Chars field corresponding to the Convention_Id C. |
| 8670 |
|
| 8671 |
function Matching_Name (Decl : Node_Id) return Boolean; |
| 8672 |
-- Decl is a pragma node. This function returns True if this |
| 8673 |
-- pragma has a second argument that is an identifier with a |
| 8674 |
-- Chars field that matches the Chars of the current subprogram. |
| 8675 |
|
| 8676 |
------------------------- |
| 8677 |
-- Matching_Convention -- |
| 8678 |
------------------------- |
| 8679 |
|
| 8680 |
function Matching_Convention (Decl : Node_Id) return Boolean is |
| 8681 |
Arg1 : constant Node_Id := |
| 8682 |
First (Pragma_Argument_Associations (Decl)); |
| 8683 |
|
| 8684 |
begin |
| 8685 |
if Present (Arg1) then |
| 8686 |
declare |
| 8687 |
Arg : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 8688 |
begin |
| 8689 |
if Nkind (Arg) = N_Identifier |
| 8690 |
and then Is_Convention_Name (Chars (Arg)) |
| 8691 |
and then Get_Convention_Id (Chars (Arg)) = C |
| 8692 |
then |
| 8693 |
return True; |
| 8694 |
end if; |
| 8695 |
end; |
| 8696 |
end if; |
| 8697 |
|
| 8698 |
return False; |
| 8699 |
end Matching_Convention; |
| 8700 |
|
| 8701 |
------------------- |
| 8702 |
-- Matching_Name -- |
| 8703 |
------------------- |
| 8704 |
|
| 8705 |
function Matching_Name (Decl : Node_Id) return Boolean is |
| 8706 |
Arg1 : constant Node_Id := |
| 8707 |
First (Pragma_Argument_Associations (Decl)); |
| 8708 |
Arg2 : Node_Id; |
| 8709 |
|
| 8710 |
begin |
| 8711 |
if No (Arg1) then |
| 8712 |
return False; |
| 8713 |
end if; |
| 8714 |
|
| 8715 |
Arg2 := Next (Arg1); |
| 8716 |
|
| 8717 |
if No (Arg2) then |
| 8718 |
return False; |
| 8719 |
end if; |
| 8720 |
|
| 8721 |
declare |
| 8722 |
Arg : constant Node_Id := Get_Pragma_Arg (Arg2); |
| 8723 |
begin |
| 8724 |
if Nkind (Arg) = N_Identifier |
| 8725 |
and then Chars (Arg) = Chars (S) |
| 8726 |
then |
| 8727 |
return True; |
| 8728 |
end if; |
| 8729 |
end; |
| 8730 |
|
| 8731 |
return False; |
| 8732 |
end Matching_Name; |
| 8733 |
|
| 8734 |
-- Start of processing for Diagnose_Multiple_Pragmas |
| 8735 |
|
| 8736 |
begin |
| 8737 |
Err := True; |
| 8738 |
|
| 8739 |
-- Definitely give message if we have Convention/Export here |
| 8740 |
|
| 8741 |
if Prag_Id = Pragma_Convention or else Prag_Id = Pragma_Export then |
| 8742 |
null; |
| 8743 |
|
| 8744 |
-- If we have an Import or Export, scan back from pragma to |
| 8745 |
-- find any previous pragma applying to the same procedure. |
| 8746 |
-- The scan will be terminated by the start of the list, or |
| 8747 |
-- hitting the subprogram declaration. This won't allow one |
| 8748 |
-- pragma to appear in the public part and one in the private |
| 8749 |
-- part, but that seems very unlikely in practice. |
| 8750 |
|
| 8751 |
else |
| 8752 |
Decl := Prev (N); |
| 8753 |
while Present (Decl) and then Decl /= Pdec loop |
| 8754 |
|
| 8755 |
-- Look for pragma with same name as us |
| 8756 |
|
| 8757 |
if Nkind (Decl) = N_Pragma |
| 8758 |
and then Matching_Name (Decl) |
| 8759 |
then |
| 8760 |
-- Give error if same as our pragma or Export/Convention |
| 8761 |
|
| 8762 |
if Pragma_Name_Unmapped (Decl) |
| 8763 |
in Name_Export |
| 8764 |
| Name_Convention |
| 8765 |
| Pragma_Name_Unmapped (N) |
| 8766 |
then |
| 8767 |
exit; |
| 8768 |
|
| 8769 |
-- Case of Import/Interface or the other way round |
| 8770 |
|
| 8771 |
elsif Pragma_Name_Unmapped (Decl) |
| 8772 |
in Name_Interface | Name_Import |
| 8773 |
then |
| 8774 |
-- Here we know that we have Import and Interface. It |
| 8775 |
-- doesn't matter which way round they are. See if |
| 8776 |
-- they specify the same convention. If so, all OK, |
| 8777 |
-- and set special flags to stop other messages |
| 8778 |
|
| 8779 |
if Matching_Convention (Decl) then |
| 8780 |
Set_Import_Interface_Present (N); |
| 8781 |
Set_Import_Interface_Present (Decl); |
| 8782 |
Err := False; |
| 8783 |
|
| 8784 |
-- If different conventions, special message |
| 8785 |
|
| 8786 |
else |
| 8787 |
Error_Msg_Sloc := Sloc (Decl); |
| 8788 |
Error_Pragma_Arg |
| 8789 |
("convention differs from that given#", Arg1); |
| 8790 |
end if; |
| 8791 |
end if; |
| 8792 |
end if; |
| 8793 |
|
| 8794 |
Next (Decl); |
| 8795 |
end loop; |
| 8796 |
end if; |
| 8797 |
|
| 8798 |
-- Give message if needed if we fall through those tests |
| 8799 |
-- except on Relaxed_RM_Semantics where we let go: either this |
| 8800 |
-- is a case accepted/ignored by other Ada compilers (e.g. |
| 8801 |
-- a mix of Convention and Import), or another error will be |
| 8802 |
-- generated later (e.g. using both Import and Export). |
| 8803 |
|
| 8804 |
if Err and not Relaxed_RM_Semantics then |
| 8805 |
Error_Pragma_Arg |
| 8806 |
("at most one Convention/Export/Import pragma is allowed", |
| 8807 |
Arg2); |
| 8808 |
end if; |
| 8809 |
end Diagnose_Multiple_Pragmas; |
| 8810 |
|
| 8811 |
-------------------------------- |
| 8812 |
-- Set_Convention_From_Pragma -- |
| 8813 |
-------------------------------- |
| 8814 |
|
| 8815 |
procedure Set_Convention_From_Pragma (E : Entity_Id) is |
| 8816 |
begin |
| 8817 |
-- Ada 2005 (AI-430): Check invalid attempt to change convention |
| 8818 |
-- for an overridden dispatching operation. Technically this is |
| 8819 |
-- an amendment and should only be done in Ada 2005 mode. However, |
| 8820 |
-- this is clearly a mistake, since the problem that is addressed |
| 8821 |
-- by this AI is that there is a clear gap in the RM. |
| 8822 |
|
| 8823 |
if Is_Dispatching_Operation (E) |
| 8824 |
and then Present (Overridden_Operation (E)) |
| 8825 |
and then C /= Convention (Overridden_Operation (E)) |
| 8826 |
then |
| 8827 |
Error_Pragma_Arg |
| 8828 |
("cannot change convention for overridden dispatching " |
| 8829 |
& "operation", Arg1); |
| 8830 |
|
| 8831 |
-- Special check for convention Stdcall: a dispatching call is not |
| 8832 |
-- allowed. A dispatching subprogram cannot be used to interface |
| 8833 |
-- to the Win32 API, so this check actually does not impose any |
| 8834 |
-- effective restriction. |
| 8835 |
|
| 8836 |
elsif Is_Dispatching_Operation (E) |
| 8837 |
and then C = Convention_Stdcall |
| 8838 |
then |
| 8839 |
-- Note: make this unconditional so that if there is more |
| 8840 |
-- than one call to which the pragma applies, we get a |
| 8841 |
-- message for each call. Also don't use Error_Pragma, |
| 8842 |
-- so that we get multiple messages. |
| 8843 |
|
| 8844 |
Error_Msg_Sloc := Sloc (E); |
| 8845 |
Error_Msg_N |
| 8846 |
("dispatching subprogram# cannot use Stdcall convention!", |
| 8847 |
Get_Pragma_Arg (Arg1)); |
| 8848 |
end if; |
| 8849 |
|
| 8850 |
-- Set the convention |
| 8851 |
|
| 8852 |
Set_Convention (E, C); |
| 8853 |
Set_Has_Convention_Pragma (E); |
| 8854 |
|
| 8855 |
-- For the case of a record base type, also set the convention of |
| 8856 |
-- any anonymous access types declared in the record which do not |
| 8857 |
-- currently have a specified convention. |
| 8858 |
-- Similarly for an array base type and anonymous access types |
| 8859 |
-- components. |
| 8860 |
|
| 8861 |
if Is_Base_Type (E) then |
| 8862 |
if Is_Record_Type (E) then |
| 8863 |
declare |
| 8864 |
Comp : Node_Id; |
| 8865 |
|
| 8866 |
begin |
| 8867 |
Comp := First_Component (E); |
| 8868 |
while Present (Comp) loop |
| 8869 |
if Present (Etype (Comp)) |
| 8870 |
and then |
| 8871 |
Ekind (Etype (Comp)) in |
| 8872 |
E_Anonymous_Access_Type | |
| 8873 |
E_Anonymous_Access_Subprogram_Type |
| 8874 |
and then not Has_Convention_Pragma (Comp) |
| 8875 |
then |
| 8876 |
Set_Convention (Comp, C); |
| 8877 |
end if; |
| 8878 |
|
| 8879 |
Next_Component (Comp); |
| 8880 |
end loop; |
| 8881 |
end; |
| 8882 |
|
| 8883 |
elsif Is_Array_Type (E) |
| 8884 |
and then Ekind (Component_Type (E)) in |
| 8885 |
E_Anonymous_Access_Type | |
| 8886 |
E_Anonymous_Access_Subprogram_Type |
| 8887 |
then |
| 8888 |
Set_Convention (Designated_Type (Component_Type (E)), C); |
| 8889 |
end if; |
| 8890 |
end if; |
| 8891 |
|
| 8892 |
-- Deal with incomplete/private type case, where underlying type |
| 8893 |
-- is available, so set convention of that underlying type. |
| 8894 |
|
| 8895 |
if Is_Incomplete_Or_Private_Type (E) |
| 8896 |
and then Present (Underlying_Type (E)) |
| 8897 |
then |
| 8898 |
Set_Convention (Underlying_Type (E), C); |
| 8899 |
Set_Has_Convention_Pragma (Underlying_Type (E), True); |
| 8900 |
end if; |
| 8901 |
|
| 8902 |
-- A class-wide type should inherit the convention of the specific |
| 8903 |
-- root type (although this isn't specified clearly by the RM). |
| 8904 |
|
| 8905 |
if Is_Type (E) and then Present (Class_Wide_Type (E)) then |
| 8906 |
Set_Convention (Class_Wide_Type (E), C); |
| 8907 |
end if; |
| 8908 |
|
| 8909 |
-- If the entity is a record type, then check for special case of |
| 8910 |
-- C_Pass_By_Copy, which is treated the same as C except that the |
| 8911 |
-- special record flag is set. This convention is only permitted |
| 8912 |
-- on record types (see AI95-00131). |
| 8913 |
|
| 8914 |
if Cname = Name_C_Pass_By_Copy then |
| 8915 |
if Is_Record_Type (E) then |
| 8916 |
Set_C_Pass_By_Copy (Base_Type (E)); |
| 8917 |
elsif Is_Incomplete_Or_Private_Type (E) |
| 8918 |
and then Is_Record_Type (Underlying_Type (E)) |
| 8919 |
then |
| 8920 |
Set_C_Pass_By_Copy (Base_Type (Underlying_Type (E))); |
| 8921 |
else |
| 8922 |
Error_Pragma_Arg |
| 8923 |
("C_Pass_By_Copy convention allowed only for record type", |
| 8924 |
Arg2); |
| 8925 |
end if; |
| 8926 |
end if; |
| 8927 |
|
| 8928 |
-- If the convention of a record type is changed (such as to C), |
| 8929 |
-- this must override C_Pass_By_Copy if that flag was inherited |
| 8930 |
-- from a parent type where the latter convention was specified, |
| 8931 |
-- so we force the flag to False. |
| 8932 |
|
| 8933 |
if Cname /= Name_C_Pass_By_Copy and then Is_Record_Type (E) then |
| 8934 |
Set_C_Pass_By_Copy (Base_Type (E), False); |
| 8935 |
end if; |
| 8936 |
|
| 8937 |
-- If the entity is a derived boolean type, check for the special |
| 8938 |
-- case of convention C, C++, or Fortran, where we consider any |
| 8939 |
-- nonzero value to represent true. |
| 8940 |
|
| 8941 |
if Is_Discrete_Type (E) |
| 8942 |
and then Root_Type (Etype (E)) = Standard_Boolean |
| 8943 |
and then |
| 8944 |
(C = Convention_C |
| 8945 |
or else |
| 8946 |
C = Convention_CPP |
| 8947 |
or else |
| 8948 |
C = Convention_Fortran) |
| 8949 |
then |
| 8950 |
Set_Nonzero_Is_True (Base_Type (E)); |
| 8951 |
end if; |
| 8952 |
end Set_Convention_From_Pragma; |
| 8953 |
|
| 8954 |
-- Local variables |
| 8955 |
|
| 8956 |
Comp_Unit : Unit_Number_Type; |
| 8957 |
E : Entity_Id; |
| 8958 |
E1 : Entity_Id; |
| 8959 |
Id : Node_Id; |
| 8960 |
Subp : Entity_Id; |
| 8961 |
|
| 8962 |
-- Start of processing for Process_Convention |
| 8963 |
|
| 8964 |
begin |
| 8965 |
Check_At_Least_N_Arguments (2); |
| 8966 |
Check_Optional_Identifier (Arg1, Name_Convention); |
| 8967 |
Check_Arg_Is_Identifier (Arg1); |
| 8968 |
Cname := Chars (Get_Pragma_Arg (Arg1)); |
| 8969 |
|
| 8970 |
-- C_Pass_By_Copy is treated as a synonym for convention C (this is |
| 8971 |
-- tested again below to set the critical flag). |
| 8972 |
|
| 8973 |
if Cname = Name_C_Pass_By_Copy then |
| 8974 |
C := Convention_C; |
| 8975 |
|
| 8976 |
-- Otherwise we must have something in the standard convention list |
| 8977 |
|
| 8978 |
elsif Is_Convention_Name (Cname) then |
| 8979 |
C := Get_Convention_Id (Chars (Get_Pragma_Arg (Arg1))); |
| 8980 |
|
| 8981 |
-- Otherwise warn on unrecognized convention |
| 8982 |
|
| 8983 |
else |
| 8984 |
if Warn_On_Export_Import then |
| 8985 |
Error_Msg_N |
| 8986 |
("??unrecognized convention name, C assumed", |
| 8987 |
Get_Pragma_Arg (Arg1)); |
| 8988 |
end if; |
| 8989 |
|
| 8990 |
C := Convention_C; |
| 8991 |
end if; |
| 8992 |
|
| 8993 |
Check_Optional_Identifier (Arg2, Name_Entity); |
| 8994 |
Check_Arg_Is_Local_Name (Arg2); |
| 8995 |
|
| 8996 |
Id := Get_Pragma_Arg (Arg2); |
| 8997 |
Analyze (Id); |
| 8998 |
|
| 8999 |
if not Is_Entity_Name (Id) then |
| 9000 |
Error_Pragma_Arg ("entity name required", Arg2); |
| 9001 |
end if; |
| 9002 |
|
| 9003 |
E := Entity (Id); |
| 9004 |
|
| 9005 |
-- Set entity to return |
| 9006 |
|
| 9007 |
Ent := E; |
| 9008 |
|
| 9009 |
-- Ada_Pass_By_Copy special checking |
| 9010 |
|
| 9011 |
if C = Convention_Ada_Pass_By_Copy then |
| 9012 |
if not Is_First_Subtype (E) then |
| 9013 |
Error_Pragma_Arg |
| 9014 |
("convention `Ada_Pass_By_Copy` only allowed for types", |
| 9015 |
Arg2); |
| 9016 |
end if; |
| 9017 |
|
| 9018 |
if Is_By_Reference_Type (E) then |
| 9019 |
Error_Pragma_Arg |
| 9020 |
("convention `Ada_Pass_By_Copy` not allowed for by-reference " |
| 9021 |
& "type", Arg1); |
| 9022 |
end if; |
| 9023 |
|
| 9024 |
-- Ada_Pass_By_Reference special checking |
| 9025 |
|
| 9026 |
elsif C = Convention_Ada_Pass_By_Reference then |
| 9027 |
if not Is_First_Subtype (E) then |
| 9028 |
Error_Pragma_Arg |
| 9029 |
("convention `Ada_Pass_By_Reference` only allowed for types", |
| 9030 |
Arg2); |
| 9031 |
end if; |
| 9032 |
|
| 9033 |
if Is_By_Copy_Type (E) then |
| 9034 |
Error_Pragma_Arg |
| 9035 |
("convention `Ada_Pass_By_Reference` not allowed for by-copy " |
| 9036 |
& "type", Arg1); |
| 9037 |
end if; |
| 9038 |
end if; |
| 9039 |
|
| 9040 |
-- Go to renamed subprogram if present, since convention applies to |
| 9041 |
-- the actual renamed entity, not to the renaming entity. If the |
| 9042 |
-- subprogram is inherited, go to parent subprogram. |
| 9043 |
|
| 9044 |
if Is_Subprogram (E) |
| 9045 |
and then Present (Alias (E)) |
| 9046 |
then |
| 9047 |
if Nkind (Parent (Declaration_Node (E))) = |
| 9048 |
N_Subprogram_Renaming_Declaration |
| 9049 |
then |
| 9050 |
if Scope (E) /= Scope (Alias (E)) then |
| 9051 |
Error_Pragma_Ref |
| 9052 |
("cannot apply pragma% to non-local entity&#", E); |
| 9053 |
end if; |
| 9054 |
|
| 9055 |
E := Alias (E); |
| 9056 |
|
| 9057 |
elsif Nkind (Parent (E)) in |
| 9058 |
N_Full_Type_Declaration | N_Private_Extension_Declaration |
| 9059 |
and then Scope (E) = Scope (Alias (E)) |
| 9060 |
then |
| 9061 |
E := Alias (E); |
| 9062 |
|
| 9063 |
-- Return the parent subprogram the entity was inherited from |
| 9064 |
|
| 9065 |
Ent := E; |
| 9066 |
end if; |
| 9067 |
end if; |
| 9068 |
|
| 9069 |
-- Check that we are not applying this to a specless body. Relax this |
| 9070 |
-- check if Relaxed_RM_Semantics to accommodate other Ada compilers. |
| 9071 |
|
| 9072 |
if Is_Subprogram (E) |
| 9073 |
and then Nkind (Parent (Declaration_Node (E))) = N_Subprogram_Body |
| 9074 |
and then not Relaxed_RM_Semantics |
| 9075 |
then |
| 9076 |
Error_Pragma |
| 9077 |
("pragma% requires separate spec and must come before body"); |
| 9078 |
end if; |
| 9079 |
|
| 9080 |
-- Check that we are not applying this to a named constant |
| 9081 |
|
| 9082 |
if Is_Named_Number (E) then |
| 9083 |
Error_Msg_Name_1 := Pname; |
| 9084 |
Error_Msg_N |
| 9085 |
("cannot apply pragma% to named constant!", |
| 9086 |
Get_Pragma_Arg (Arg2)); |
| 9087 |
Error_Pragma_Arg |
| 9088 |
("\supply appropriate type for&!", Arg2); |
| 9089 |
end if; |
| 9090 |
|
| 9091 |
if Ekind (E) = E_Enumeration_Literal then |
| 9092 |
Error_Pragma ("enumeration literal not allowed for pragma%"); |
| 9093 |
end if; |
| 9094 |
|
| 9095 |
-- Check for rep item appearing too early or too late |
| 9096 |
|
| 9097 |
if Etype (E) = Any_Type |
| 9098 |
or else Rep_Item_Too_Early (E, N) |
| 9099 |
then |
| 9100 |
raise Pragma_Exit; |
| 9101 |
|
| 9102 |
elsif Present (Underlying_Type (E)) then |
| 9103 |
E := Underlying_Type (E); |
| 9104 |
end if; |
| 9105 |
|
| 9106 |
if Rep_Item_Too_Late (E, N) then |
| 9107 |
raise Pragma_Exit; |
| 9108 |
end if; |
| 9109 |
|
| 9110 |
if Has_Convention_Pragma (E) then |
| 9111 |
Diagnose_Multiple_Pragmas (E); |
| 9112 |
|
| 9113 |
elsif Convention (E) = Convention_Protected |
| 9114 |
or else Ekind (Scope (E)) = E_Protected_Type |
| 9115 |
then |
| 9116 |
Error_Pragma_Arg |
| 9117 |
("a protected operation cannot be given a different convention", |
| 9118 |
Arg2); |
| 9119 |
end if; |
| 9120 |
|
| 9121 |
-- For Intrinsic, a subprogram is required |
| 9122 |
|
| 9123 |
if C = Convention_Intrinsic |
| 9124 |
and then not Is_Subprogram_Or_Generic_Subprogram (E) |
| 9125 |
then |
| 9126 |
-- Accept Intrinsic Export on types if Relaxed_RM_Semantics |
| 9127 |
|
| 9128 |
if not (Is_Type (E) and then Relaxed_RM_Semantics) then |
| 9129 |
if From_Aspect_Specification (N) then |
| 9130 |
Error_Pragma_Arg |
| 9131 |
("entity for aspect% must be a subprogram", Arg2); |
| 9132 |
else |
| 9133 |
Error_Pragma_Arg |
| 9134 |
("second argument of pragma% must be a subprogram", Arg2); |
| 9135 |
end if; |
| 9136 |
end if; |
| 9137 |
|
| 9138 |
-- Special checks for C_Variadic_n |
| 9139 |
|
| 9140 |
elsif C in Convention_C_Variadic then |
| 9141 |
|
| 9142 |
-- Several allowed cases |
| 9143 |
|
| 9144 |
if Is_Subprogram_Or_Generic_Subprogram (E) then |
| 9145 |
Subp := E; |
| 9146 |
|
| 9147 |
-- An access to subprogram is also allowed |
| 9148 |
|
| 9149 |
elsif Is_Access_Type (E) |
| 9150 |
and then Ekind (Designated_Type (E)) = E_Subprogram_Type |
| 9151 |
then |
| 9152 |
Subp := Designated_Type (E); |
| 9153 |
|
| 9154 |
-- Allow internal call to set convention of subprogram type |
| 9155 |
|
| 9156 |
elsif Ekind (E) = E_Subprogram_Type then |
| 9157 |
Subp := E; |
| 9158 |
|
| 9159 |
else |
| 9160 |
Error_Pragma_Arg |
| 9161 |
("argument of pragma% must be subprogram or access type", |
| 9162 |
Arg2); |
| 9163 |
end if; |
| 9164 |
|
| 9165 |
-- ISO C requires a named parameter before the ellipsis, so a |
| 9166 |
-- variadic C function taking 0 fixed parameter cannot exist. |
| 9167 |
|
| 9168 |
if C = Convention_C_Variadic_0 then |
| 9169 |
|
| 9170 |
Error_Msg_N |
| 9171 |
("??C_Variadic_0 cannot be used for an 'I'S'O C function", |
| 9172 |
Get_Pragma_Arg (Arg2)); |
| 9173 |
|
| 9174 |
-- Now check the number of parameters of the subprogram and give |
| 9175 |
-- an error if it is lower than n. |
| 9176 |
|
| 9177 |
elsif Present (Subp) then |
| 9178 |
declare |
| 9179 |
Minimum : constant Nat := |
| 9180 |
Convention_Id'Pos (C) - |
| 9181 |
Convention_Id'Pos (Convention_C_Variadic_0); |
| 9182 |
begin |
| 9183 |
if Number_Formals (Subp) < Minimum then |
| 9184 |
Error_Msg_Uint_1 := UI_From_Int (Minimum); |
| 9185 |
Error_Pragma_Arg |
| 9186 |
("argument of pragma% must have at least" |
| 9187 |
& "^ parameters", Arg2); |
| 9188 |
end if; |
| 9189 |
end; |
| 9190 |
end if; |
| 9191 |
|
| 9192 |
-- Special checks for Stdcall |
| 9193 |
|
| 9194 |
elsif C = Convention_Stdcall then |
| 9195 |
|
| 9196 |
-- Several allowed cases |
| 9197 |
|
| 9198 |
if Is_Subprogram_Or_Generic_Subprogram (E) |
| 9199 |
|
| 9200 |
-- A variable is OK |
| 9201 |
|
| 9202 |
or else Ekind (E) = E_Variable |
| 9203 |
|
| 9204 |
-- A component as well. The entity does not have its Ekind |
| 9205 |
-- set until the enclosing record declaration is fully |
| 9206 |
-- analyzed. |
| 9207 |
|
| 9208 |
or else Nkind (Parent (E)) = N_Component_Declaration |
| 9209 |
|
| 9210 |
-- An access to subprogram is also allowed |
| 9211 |
|
| 9212 |
or else |
| 9213 |
(Is_Access_Type (E) |
| 9214 |
and then Ekind (Designated_Type (E)) = E_Subprogram_Type) |
| 9215 |
|
| 9216 |
-- Allow internal call to set convention of subprogram type |
| 9217 |
|
| 9218 |
or else Ekind (E) = E_Subprogram_Type |
| 9219 |
then |
| 9220 |
null; |
| 9221 |
|
| 9222 |
else |
| 9223 |
Error_Pragma_Arg |
| 9224 |
("argument of pragma% must be subprogram or access type", |
| 9225 |
Arg2); |
| 9226 |
end if; |
| 9227 |
end if; |
| 9228 |
|
| 9229 |
Set_Convention_From_Pragma (E); |
| 9230 |
|
| 9231 |
-- Deal with non-subprogram cases |
| 9232 |
|
| 9233 |
if not Is_Subprogram_Or_Generic_Subprogram (E) then |
| 9234 |
if Is_Type (E) then |
| 9235 |
|
| 9236 |
-- The pragma must apply to a first subtype, but it can also |
| 9237 |
-- apply to a generic type in a generic formal part, in which |
| 9238 |
-- case it will also appear in the corresponding instance. |
| 9239 |
|
| 9240 |
if Is_Generic_Type (E) or else In_Instance then |
| 9241 |
null; |
| 9242 |
else |
| 9243 |
Check_First_Subtype (Arg2); |
| 9244 |
end if; |
| 9245 |
|
| 9246 |
Set_Convention_From_Pragma (Base_Type (E)); |
| 9247 |
|
| 9248 |
-- For access subprograms, we must set the convention on the |
| 9249 |
-- internally generated directly designated type as well. |
| 9250 |
|
| 9251 |
if Ekind (E) = E_Access_Subprogram_Type then |
| 9252 |
Set_Convention_From_Pragma (Directly_Designated_Type (E)); |
| 9253 |
end if; |
| 9254 |
end if; |
| 9255 |
|
| 9256 |
-- For the subprogram case, set proper convention for all homonyms |
| 9257 |
-- in same scope and the same declarative part, i.e. the same |
| 9258 |
-- compilation unit. |
| 9259 |
|
| 9260 |
else |
| 9261 |
-- Treat a pragma Import as an implicit body, and pragma import |
| 9262 |
-- as implicit reference (for navigation in GNAT Studio). |
| 9263 |
|
| 9264 |
if Prag_Id = Pragma_Import then |
| 9265 |
Generate_Reference (E, Id, 'b'); |
| 9266 |
|
| 9267 |
-- For exported entities we restrict the generation of references |
| 9268 |
-- to entities exported to foreign languages since entities |
| 9269 |
-- exported to Ada do not provide further information to |
| 9270 |
-- GNAT Studio and add undesired references to the output of the |
| 9271 |
-- gnatxref tool. |
| 9272 |
|
| 9273 |
elsif Prag_Id = Pragma_Export |
| 9274 |
and then Convention (E) /= Convention_Ada |
| 9275 |
then |
| 9276 |
Generate_Reference (E, Id, 'i'); |
| 9277 |
end if; |
| 9278 |
|
| 9279 |
-- If the pragma comes from an aspect, it only applies to the |
| 9280 |
-- given entity, not its homonyms. |
| 9281 |
|
| 9282 |
if From_Aspect_Specification (N) then |
| 9283 |
if C = Convention_Intrinsic |
| 9284 |
and then Nkind (Ent) = N_Defining_Operator_Symbol |
| 9285 |
then |
| 9286 |
if Is_Fixed_Point_Type (Etype (Ent)) |
| 9287 |
or else Is_Fixed_Point_Type (Etype (First_Entity (Ent))) |
| 9288 |
or else Is_Fixed_Point_Type (Etype (Last_Entity (Ent))) |
| 9289 |
then |
| 9290 |
Error_Msg_N |
| 9291 |
("no intrinsic operator available for this fixed-point " |
| 9292 |
& "operation", N); |
| 9293 |
Error_Msg_N |
| 9294 |
("\use expression functions with the desired " |
| 9295 |
& "conversions made explicit", N); |
| 9296 |
end if; |
| 9297 |
end if; |
| 9298 |
|
| 9299 |
return; |
| 9300 |
end if; |
| 9301 |
|
| 9302 |
-- Otherwise Loop through the homonyms of the pragma argument's |
| 9303 |
-- entity, an apply convention to those in the current scope. |
| 9304 |
|
| 9305 |
Comp_Unit := Get_Source_Unit (E); |
| 9306 |
E1 := Ent; |
| 9307 |
|
| 9308 |
loop |
| 9309 |
E1 := Homonym (E1); |
| 9310 |
exit when No (E1) or else Scope (E1) /= Current_Scope; |
| 9311 |
|
| 9312 |
-- Ignore entry for which convention is already set |
| 9313 |
|
| 9314 |
if Has_Convention_Pragma (E1) then |
| 9315 |
goto Continue; |
| 9316 |
end if; |
| 9317 |
|
| 9318 |
if Is_Subprogram (E1) |
| 9319 |
and then Nkind (Parent (Declaration_Node (E1))) = |
| 9320 |
N_Subprogram_Body |
| 9321 |
and then not Relaxed_RM_Semantics |
| 9322 |
then |
| 9323 |
Set_Has_Completion (E); -- to prevent cascaded error |
| 9324 |
Error_Pragma_Ref |
| 9325 |
("pragma% requires separate spec and must come before " |
| 9326 |
& "body#", E1); |
| 9327 |
end if; |
| 9328 |
|
| 9329 |
-- Do not set the pragma on inherited operations or on formal |
| 9330 |
-- subprograms. |
| 9331 |
|
| 9332 |
if Comes_From_Source (E1) |
| 9333 |
and then Comp_Unit = Get_Source_Unit (E1) |
| 9334 |
and then not Is_Formal_Subprogram (E1) |
| 9335 |
and then Nkind (Original_Node (Parent (E1))) /= |
| 9336 |
N_Full_Type_Declaration |
| 9337 |
then |
| 9338 |
if Present (Alias (E1)) |
| 9339 |
and then Scope (E1) /= Scope (Alias (E1)) |
| 9340 |
then |
| 9341 |
Error_Pragma_Ref |
| 9342 |
("cannot apply pragma% to non-local entity& declared#", |
| 9343 |
E1); |
| 9344 |
end if; |
| 9345 |
|
| 9346 |
Set_Convention_From_Pragma (E1); |
| 9347 |
|
| 9348 |
if Prag_Id = Pragma_Import then |
| 9349 |
Generate_Reference (E1, Id, 'b'); |
| 9350 |
end if; |
| 9351 |
end if; |
| 9352 |
|
| 9353 |
<<Continue>> |
| 9354 |
null; |
| 9355 |
end loop; |
| 9356 |
end if; |
| 9357 |
end Process_Convention; |
| 9358 |
|
| 9359 |
---------------------------------------- |
| 9360 |
-- Process_Disable_Enable_Atomic_Sync -- |
| 9361 |
---------------------------------------- |
| 9362 |
|
| 9363 |
procedure Process_Disable_Enable_Atomic_Sync (Nam : Name_Id) is |
| 9364 |
begin |
| 9365 |
Check_No_Identifiers; |
| 9366 |
Check_At_Most_N_Arguments (1); |
| 9367 |
|
| 9368 |
-- Implemented internally as |
| 9369 |
-- pragma Suppress/Unsuppress (_Atomic_Synchronization [,Entity]) |
| 9370 |
|
| 9371 |
Rewrite (N, |
| 9372 |
Make_Pragma (Loc, |
| 9373 |
Chars => Nam, |
| 9374 |
Pragma_Argument_Associations => New_List ( |
| 9375 |
Make_Pragma_Argument_Association (Loc, |
| 9376 |
Expression => |
| 9377 |
Make_Identifier (Loc, Name_uAtomic_Synchronization))))); |
| 9378 |
|
| 9379 |
if Present (Arg1) then |
| 9380 |
Append_To (Pragma_Argument_Associations (N), New_Copy (Arg1)); |
| 9381 |
end if; |
| 9382 |
|
| 9383 |
Analyze (N); |
| 9384 |
end Process_Disable_Enable_Atomic_Sync; |
| 9385 |
|
| 9386 |
------------------------------------------------- |
| 9387 |
-- Process_Extended_Import_Export_Internal_Arg -- |
| 9388 |
------------------------------------------------- |
| 9389 |
|
| 9390 |
procedure Process_Extended_Import_Export_Internal_Arg |
| 9391 |
(Arg_Internal : Node_Id := Empty) |
| 9392 |
is |
| 9393 |
begin |
| 9394 |
if No (Arg_Internal) then |
| 9395 |
Error_Pragma ("Internal parameter required for pragma%"); |
| 9396 |
end if; |
| 9397 |
|
| 9398 |
if Nkind (Arg_Internal) = N_Identifier then |
| 9399 |
null; |
| 9400 |
|
| 9401 |
elsif Nkind (Arg_Internal) = N_Operator_Symbol |
| 9402 |
and then (Prag_Id = Pragma_Import_Function |
| 9403 |
or else |
| 9404 |
Prag_Id = Pragma_Export_Function) |
| 9405 |
then |
| 9406 |
null; |
| 9407 |
|
| 9408 |
else |
| 9409 |
Error_Pragma_Arg |
| 9410 |
("wrong form for Internal parameter for pragma%", Arg_Internal); |
| 9411 |
end if; |
| 9412 |
|
| 9413 |
Check_Arg_Is_Local_Name (Arg_Internal); |
| 9414 |
end Process_Extended_Import_Export_Internal_Arg; |
| 9415 |
|
| 9416 |
-------------------------------------------------- |
| 9417 |
-- Process_Extended_Import_Export_Object_Pragma -- |
| 9418 |
-------------------------------------------------- |
| 9419 |
|
| 9420 |
procedure Process_Extended_Import_Export_Object_Pragma |
| 9421 |
(Arg_Internal : Node_Id; |
| 9422 |
Arg_External : Node_Id; |
| 9423 |
Arg_Size : Node_Id) |
| 9424 |
is |
| 9425 |
Def_Id : Entity_Id; |
| 9426 |
|
| 9427 |
begin |
| 9428 |
Process_Extended_Import_Export_Internal_Arg (Arg_Internal); |
| 9429 |
Def_Id := Entity (Arg_Internal); |
| 9430 |
|
| 9431 |
if Ekind (Def_Id) not in E_Constant | E_Variable then |
| 9432 |
Error_Pragma_Arg |
| 9433 |
("pragma% must designate an object", Arg_Internal); |
| 9434 |
end if; |
| 9435 |
|
| 9436 |
if Has_Rep_Pragma (Def_Id, Name_Common_Object) |
| 9437 |
or else |
| 9438 |
Has_Rep_Pragma (Def_Id, Name_Psect_Object) |
| 9439 |
then |
| 9440 |
Error_Pragma_Arg |
| 9441 |
("previous Common/Psect_Object applies, pragma % not permitted", |
| 9442 |
Arg_Internal); |
| 9443 |
end if; |
| 9444 |
|
| 9445 |
if Rep_Item_Too_Late (Def_Id, N) then |
| 9446 |
raise Pragma_Exit; |
| 9447 |
end if; |
| 9448 |
|
| 9449 |
Set_Extended_Import_Export_External_Name (Def_Id, Arg_External); |
| 9450 |
|
| 9451 |
if Present (Arg_Size) then |
| 9452 |
Check_Arg_Is_External_Name (Arg_Size); |
| 9453 |
end if; |
| 9454 |
|
| 9455 |
-- Export_Object case |
| 9456 |
|
| 9457 |
if Prag_Id = Pragma_Export_Object then |
| 9458 |
if not Is_Library_Level_Entity (Def_Id) then |
| 9459 |
Error_Pragma_Arg |
| 9460 |
("argument for pragma% must be library level entity", |
| 9461 |
Arg_Internal); |
| 9462 |
end if; |
| 9463 |
|
| 9464 |
if Ekind (Current_Scope) = E_Generic_Package then |
| 9465 |
Error_Pragma ("pragma& cannot appear in a generic unit"); |
| 9466 |
end if; |
| 9467 |
|
| 9468 |
if not Size_Known_At_Compile_Time (Etype (Def_Id)) then |
| 9469 |
Error_Pragma_Arg |
| 9470 |
("exported object must have compile time known size", |
| 9471 |
Arg_Internal); |
| 9472 |
end if; |
| 9473 |
|
| 9474 |
if Warn_On_Export_Import and then Is_Exported (Def_Id) then |
| 9475 |
Error_Msg_N ("??duplicate Export_Object pragma", N); |
| 9476 |
else |
| 9477 |
Set_Exported (Def_Id, Arg_Internal); |
| 9478 |
end if; |
| 9479 |
|
| 9480 |
-- Import_Object case |
| 9481 |
|
| 9482 |
else |
| 9483 |
if Is_Concurrent_Type (Etype (Def_Id)) then |
| 9484 |
Error_Pragma_Arg |
| 9485 |
("cannot use pragma% for task/protected object", |
| 9486 |
Arg_Internal); |
| 9487 |
end if; |
| 9488 |
|
| 9489 |
if Ekind (Def_Id) = E_Constant then |
| 9490 |
Error_Pragma_Arg |
| 9491 |
("cannot import a constant", Arg_Internal); |
| 9492 |
end if; |
| 9493 |
|
| 9494 |
if Warn_On_Export_Import |
| 9495 |
and then Has_Discriminants (Etype (Def_Id)) |
| 9496 |
then |
| 9497 |
Error_Msg_N |
| 9498 |
("imported value must be initialized??", Arg_Internal); |
| 9499 |
end if; |
| 9500 |
|
| 9501 |
if Warn_On_Export_Import |
| 9502 |
and then Is_Access_Type (Etype (Def_Id)) |
| 9503 |
then |
| 9504 |
Error_Pragma_Arg |
| 9505 |
("cannot import object of an access type??", Arg_Internal); |
| 9506 |
end if; |
| 9507 |
|
| 9508 |
if Warn_On_Export_Import |
| 9509 |
and then Is_Imported (Def_Id) |
| 9510 |
then |
| 9511 |
Error_Msg_N ("??duplicate Import_Object pragma", N); |
| 9512 |
|
| 9513 |
-- Check for explicit initialization present. Note that an |
| 9514 |
-- initialization generated by the code generator, e.g. for an |
| 9515 |
-- access type, does not count here. |
| 9516 |
|
| 9517 |
elsif (Present (Expression (Parent (Def_Id))) |
| 9518 |
and then |
| 9519 |
Comes_From_Source |
| 9520 |
(Original_Node (Expression (Parent (Def_Id))))) |
| 9521 |
or else Has_Init_Expression (Parent (Def_Id)) |
| 9522 |
then |
| 9523 |
Error_Msg_Sloc := Sloc (Def_Id); |
| 9524 |
Error_Pragma_Arg |
| 9525 |
("no initialization allowed for declaration of& #", |
| 9526 |
"\imported entities cannot be initialized (RM B.1(24))", |
| 9527 |
Arg1); |
| 9528 |
else |
| 9529 |
Set_Imported (Def_Id); |
| 9530 |
Note_Possible_Modification (Arg_Internal, Sure => False); |
| 9531 |
end if; |
| 9532 |
end if; |
| 9533 |
end Process_Extended_Import_Export_Object_Pragma; |
| 9534 |
|
| 9535 |
------------------------------------------------------ |
| 9536 |
-- Process_Extended_Import_Export_Subprogram_Pragma -- |
| 9537 |
------------------------------------------------------ |
| 9538 |
|
| 9539 |
procedure Process_Extended_Import_Export_Subprogram_Pragma |
| 9540 |
(Arg_Internal : Node_Id; |
| 9541 |
Arg_External : Node_Id; |
| 9542 |
Arg_Parameter_Types : Node_Id; |
| 9543 |
Arg_Result_Type : Node_Id := Empty; |
| 9544 |
Arg_Mechanism : Node_Id; |
| 9545 |
Arg_Result_Mechanism : Node_Id := Empty) |
| 9546 |
is |
| 9547 |
Ent : Entity_Id; |
| 9548 |
Def_Id : Entity_Id; |
| 9549 |
Hom_Id : Entity_Id; |
| 9550 |
Formal : Entity_Id; |
| 9551 |
Ambiguous : Boolean; |
| 9552 |
Match : Boolean; |
| 9553 |
|
| 9554 |
function Same_Base_Type |
| 9555 |
(Ptype : Node_Id; |
| 9556 |
Formal : Entity_Id) return Boolean; |
| 9557 |
-- Determines if Ptype references the type of Formal. Note that only |
| 9558 |
-- the base types need to match according to the spec. Ptype here is |
| 9559 |
-- the argument from the pragma, which is either a type name, or an |
| 9560 |
-- access attribute. |
| 9561 |
|
| 9562 |
-------------------- |
| 9563 |
-- Same_Base_Type -- |
| 9564 |
-------------------- |
| 9565 |
|
| 9566 |
function Same_Base_Type |
| 9567 |
(Ptype : Node_Id; |
| 9568 |
Formal : Entity_Id) return Boolean |
| 9569 |
is |
| 9570 |
Ftyp : constant Entity_Id := Base_Type (Etype (Formal)); |
| 9571 |
Pref : Node_Id; |
| 9572 |
|
| 9573 |
begin |
| 9574 |
-- Case where pragma argument is typ'Access |
| 9575 |
|
| 9576 |
if Nkind (Ptype) = N_Attribute_Reference |
| 9577 |
and then Attribute_Name (Ptype) = Name_Access |
| 9578 |
then |
| 9579 |
Pref := Prefix (Ptype); |
| 9580 |
Find_Type (Pref); |
| 9581 |
|
| 9582 |
if not Is_Entity_Name (Pref) |
| 9583 |
or else Entity (Pref) = Any_Type |
| 9584 |
then |
| 9585 |
raise Pragma_Exit; |
| 9586 |
end if; |
| 9587 |
|
| 9588 |
-- We have a match if the corresponding argument is of an |
| 9589 |
-- anonymous access type, and its designated type matches the |
| 9590 |
-- type of the prefix of the access attribute |
| 9591 |
|
| 9592 |
return Ekind (Ftyp) = E_Anonymous_Access_Type |
| 9593 |
and then Base_Type (Entity (Pref)) = |
| 9594 |
Base_Type (Etype (Designated_Type (Ftyp))); |
| 9595 |
|
| 9596 |
-- Case where pragma argument is a type name |
| 9597 |
|
| 9598 |
else |
| 9599 |
Find_Type (Ptype); |
| 9600 |
|
| 9601 |
if not Is_Entity_Name (Ptype) |
| 9602 |
or else Entity (Ptype) = Any_Type |
| 9603 |
then |
| 9604 |
raise Pragma_Exit; |
| 9605 |
end if; |
| 9606 |
|
| 9607 |
-- We have a match if the corresponding argument is of the type |
| 9608 |
-- given in the pragma (comparing base types) |
| 9609 |
|
| 9610 |
return Base_Type (Entity (Ptype)) = Ftyp; |
| 9611 |
end if; |
| 9612 |
end Same_Base_Type; |
| 9613 |
|
| 9614 |
-- Start of processing for |
| 9615 |
-- Process_Extended_Import_Export_Subprogram_Pragma |
| 9616 |
|
| 9617 |
begin |
| 9618 |
Process_Extended_Import_Export_Internal_Arg (Arg_Internal); |
| 9619 |
Ent := Empty; |
| 9620 |
Ambiguous := False; |
| 9621 |
|
| 9622 |
-- Loop through homonyms (overloadings) of the entity |
| 9623 |
|
| 9624 |
Hom_Id := Entity (Arg_Internal); |
| 9625 |
while Present (Hom_Id) loop |
| 9626 |
Def_Id := Get_Base_Subprogram (Hom_Id); |
| 9627 |
|
| 9628 |
-- We need a subprogram in the current scope |
| 9629 |
|
| 9630 |
if not Is_Subprogram (Def_Id) |
| 9631 |
or else Scope (Def_Id) /= Current_Scope |
| 9632 |
then |
| 9633 |
null; |
| 9634 |
|
| 9635 |
else |
| 9636 |
Match := True; |
| 9637 |
|
| 9638 |
-- Pragma cannot apply to subprogram body |
| 9639 |
|
| 9640 |
if Is_Subprogram (Def_Id) |
| 9641 |
and then Nkind (Parent (Declaration_Node (Def_Id))) = |
| 9642 |
N_Subprogram_Body |
| 9643 |
then |
| 9644 |
Error_Pragma |
| 9645 |
("pragma% requires separate spec and must come before " |
| 9646 |
& "body"); |
| 9647 |
end if; |
| 9648 |
|
| 9649 |
-- Test result type if given, note that the result type |
| 9650 |
-- parameter can only be present for the function cases. |
| 9651 |
|
| 9652 |
if Present (Arg_Result_Type) |
| 9653 |
and then not Same_Base_Type (Arg_Result_Type, Def_Id) |
| 9654 |
then |
| 9655 |
Match := False; |
| 9656 |
|
| 9657 |
elsif Etype (Def_Id) /= Standard_Void_Type |
| 9658 |
and then |
| 9659 |
Pname in Name_Export_Procedure | Name_Import_Procedure |
| 9660 |
then |
| 9661 |
Match := False; |
| 9662 |
|
| 9663 |
-- Test parameter types if given. Note that this parameter has |
| 9664 |
-- not been analyzed (and must not be, since it is semantic |
| 9665 |
-- nonsense), so we get it as the parser left it. |
| 9666 |
|
| 9667 |
elsif Present (Arg_Parameter_Types) then |
| 9668 |
Check_Matching_Types : declare |
| 9669 |
Formal : Entity_Id; |
| 9670 |
Ptype : Node_Id; |
| 9671 |
|
| 9672 |
begin |
| 9673 |
Formal := First_Formal (Def_Id); |
| 9674 |
|
| 9675 |
if Nkind (Arg_Parameter_Types) = N_Null then |
| 9676 |
if Present (Formal) then |
| 9677 |
Match := False; |
| 9678 |
end if; |
| 9679 |
|
| 9680 |
-- A list of one type, e.g. (List) is parsed as a |
| 9681 |
-- parenthesized expression. |
| 9682 |
|
| 9683 |
elsif Nkind (Arg_Parameter_Types) /= N_Aggregate |
| 9684 |
and then Paren_Count (Arg_Parameter_Types) = 1 |
| 9685 |
then |
| 9686 |
if No (Formal) |
| 9687 |
or else Present (Next_Formal (Formal)) |
| 9688 |
then |
| 9689 |
Match := False; |
| 9690 |
else |
| 9691 |
Match := |
| 9692 |
Same_Base_Type (Arg_Parameter_Types, Formal); |
| 9693 |
end if; |
| 9694 |
|
| 9695 |
-- A list of more than one type is parsed as a aggregate |
| 9696 |
|
| 9697 |
elsif Nkind (Arg_Parameter_Types) = N_Aggregate |
| 9698 |
and then Paren_Count (Arg_Parameter_Types) = 0 |
| 9699 |
then |
| 9700 |
Ptype := First (Expressions (Arg_Parameter_Types)); |
| 9701 |
while Present (Ptype) or else Present (Formal) loop |
| 9702 |
if No (Ptype) |
| 9703 |
or else No (Formal) |
| 9704 |
or else not Same_Base_Type (Ptype, Formal) |
| 9705 |
then |
| 9706 |
Match := False; |
| 9707 |
exit; |
| 9708 |
else |
| 9709 |
Next_Formal (Formal); |
| 9710 |
Next (Ptype); |
| 9711 |
end if; |
| 9712 |
end loop; |
| 9713 |
|
| 9714 |
-- Anything else is of the wrong form |
| 9715 |
|
| 9716 |
else |
| 9717 |
Error_Pragma_Arg |
| 9718 |
("wrong form for Parameter_Types parameter", |
| 9719 |
Arg_Parameter_Types); |
| 9720 |
end if; |
| 9721 |
end Check_Matching_Types; |
| 9722 |
end if; |
| 9723 |
|
| 9724 |
-- Match is now False if the entry we found did not match |
| 9725 |
-- either a supplied Parameter_Types or Result_Types argument |
| 9726 |
|
| 9727 |
if Match then |
| 9728 |
if No (Ent) then |
| 9729 |
Ent := Def_Id; |
| 9730 |
|
| 9731 |
-- Ambiguous case, the flag Ambiguous shows if we already |
| 9732 |
-- detected this and output the initial messages. |
| 9733 |
|
| 9734 |
else |
| 9735 |
if not Ambiguous then |
| 9736 |
Ambiguous := True; |
| 9737 |
Error_Msg_Name_1 := Pname; |
| 9738 |
Error_Msg_N |
| 9739 |
("pragma% does not uniquely identify subprogram!", |
| 9740 |
N); |
| 9741 |
Error_Msg_Sloc := Sloc (Ent); |
| 9742 |
Error_Msg_N ("matching subprogram #!", N); |
| 9743 |
Ent := Empty; |
| 9744 |
end if; |
| 9745 |
|
| 9746 |
Error_Msg_Sloc := Sloc (Def_Id); |
| 9747 |
Error_Msg_N ("matching subprogram #!", N); |
| 9748 |
end if; |
| 9749 |
end if; |
| 9750 |
end if; |
| 9751 |
|
| 9752 |
Hom_Id := Homonym (Hom_Id); |
| 9753 |
end loop; |
| 9754 |
|
| 9755 |
-- See if we found an entry |
| 9756 |
|
| 9757 |
if No (Ent) then |
| 9758 |
if not Ambiguous then |
| 9759 |
if Is_Generic_Subprogram (Entity (Arg_Internal)) then |
| 9760 |
Error_Pragma |
| 9761 |
("pragma% cannot be given for generic subprogram"); |
| 9762 |
else |
| 9763 |
Error_Pragma |
| 9764 |
("pragma% does not identify local subprogram"); |
| 9765 |
end if; |
| 9766 |
end if; |
| 9767 |
|
| 9768 |
return; |
| 9769 |
end if; |
| 9770 |
|
| 9771 |
-- Import pragmas must be for imported entities |
| 9772 |
|
| 9773 |
if Prag_Id = Pragma_Import_Function |
| 9774 |
or else |
| 9775 |
Prag_Id = Pragma_Import_Procedure |
| 9776 |
or else |
| 9777 |
Prag_Id = Pragma_Import_Valued_Procedure |
| 9778 |
then |
| 9779 |
if not Is_Imported (Ent) then |
| 9780 |
Error_Pragma |
| 9781 |
("pragma Import or Interface must precede pragma%"); |
| 9782 |
end if; |
| 9783 |
|
| 9784 |
-- Here we have the Export case which can set the entity as exported |
| 9785 |
|
| 9786 |
-- But does not do so if the specified external name is null, since |
| 9787 |
-- that is taken as a signal in DEC Ada 83 (with which we want to be |
| 9788 |
-- compatible) to request no external name. |
| 9789 |
|
| 9790 |
elsif Nkind (Arg_External) = N_String_Literal |
| 9791 |
and then String_Length (Strval (Arg_External)) = 0 |
| 9792 |
then |
| 9793 |
null; |
| 9794 |
|
| 9795 |
-- In all other cases, set entity as exported |
| 9796 |
|
| 9797 |
else |
| 9798 |
Set_Exported (Ent, Arg_Internal); |
| 9799 |
end if; |
| 9800 |
|
| 9801 |
-- Special processing for Valued_Procedure cases |
| 9802 |
|
| 9803 |
if Prag_Id = Pragma_Import_Valued_Procedure |
| 9804 |
or else |
| 9805 |
Prag_Id = Pragma_Export_Valued_Procedure |
| 9806 |
then |
| 9807 |
Formal := First_Formal (Ent); |
| 9808 |
|
| 9809 |
if No (Formal) then |
| 9810 |
Error_Pragma ("at least one parameter required for pragma%"); |
| 9811 |
|
| 9812 |
elsif Ekind (Formal) /= E_Out_Parameter then |
| 9813 |
Error_Pragma ("first parameter must have mode OUT for pragma%"); |
| 9814 |
|
| 9815 |
else |
| 9816 |
Set_Is_Valued_Procedure (Ent); |
| 9817 |
end if; |
| 9818 |
end if; |
| 9819 |
|
| 9820 |
Set_Extended_Import_Export_External_Name (Ent, Arg_External); |
| 9821 |
|
| 9822 |
-- Process Result_Mechanism argument if present. We have already |
| 9823 |
-- checked that this is only allowed for the function case. |
| 9824 |
|
| 9825 |
if Present (Arg_Result_Mechanism) then |
| 9826 |
Set_Mechanism_Value (Ent, Arg_Result_Mechanism); |
| 9827 |
end if; |
| 9828 |
|
| 9829 |
-- Process Mechanism parameter if present. Note that this parameter |
| 9830 |
-- is not analyzed, and must not be analyzed since it is semantic |
| 9831 |
-- nonsense, so we get it in exactly as the parser left it. |
| 9832 |
|
| 9833 |
if Present (Arg_Mechanism) then |
| 9834 |
declare |
| 9835 |
Formal : Entity_Id; |
| 9836 |
Massoc : Node_Id; |
| 9837 |
Mname : Node_Id; |
| 9838 |
Choice : Node_Id; |
| 9839 |
|
| 9840 |
begin |
| 9841 |
-- A single mechanism association without a formal parameter |
| 9842 |
-- name is parsed as a parenthesized expression. All other |
| 9843 |
-- cases are parsed as aggregates, so we rewrite the single |
| 9844 |
-- parameter case as an aggregate for consistency. |
| 9845 |
|
| 9846 |
if Nkind (Arg_Mechanism) /= N_Aggregate |
| 9847 |
and then Paren_Count (Arg_Mechanism) = 1 |
| 9848 |
then |
| 9849 |
Rewrite (Arg_Mechanism, |
| 9850 |
Make_Aggregate (Sloc (Arg_Mechanism), |
| 9851 |
Expressions => New_List ( |
| 9852 |
Relocate_Node (Arg_Mechanism)))); |
| 9853 |
end if; |
| 9854 |
|
| 9855 |
-- Case of only mechanism name given, applies to all formals |
| 9856 |
|
| 9857 |
if Nkind (Arg_Mechanism) /= N_Aggregate then |
| 9858 |
Formal := First_Formal (Ent); |
| 9859 |
while Present (Formal) loop |
| 9860 |
Set_Mechanism_Value (Formal, Arg_Mechanism); |
| 9861 |
Next_Formal (Formal); |
| 9862 |
end loop; |
| 9863 |
|
| 9864 |
-- Case of list of mechanism associations given |
| 9865 |
|
| 9866 |
else |
| 9867 |
if Null_Record_Present (Arg_Mechanism) then |
| 9868 |
Error_Pragma_Arg |
| 9869 |
("inappropriate form for Mechanism parameter", |
| 9870 |
Arg_Mechanism); |
| 9871 |
end if; |
| 9872 |
|
| 9873 |
-- Deal with positional ones first |
| 9874 |
|
| 9875 |
Formal := First_Formal (Ent); |
| 9876 |
|
| 9877 |
if Present (Expressions (Arg_Mechanism)) then |
| 9878 |
Mname := First (Expressions (Arg_Mechanism)); |
| 9879 |
while Present (Mname) loop |
| 9880 |
if No (Formal) then |
| 9881 |
Error_Pragma_Arg |
| 9882 |
("too many mechanism associations", Mname); |
| 9883 |
end if; |
| 9884 |
|
| 9885 |
Set_Mechanism_Value (Formal, Mname); |
| 9886 |
Next_Formal (Formal); |
| 9887 |
Next (Mname); |
| 9888 |
end loop; |
| 9889 |
end if; |
| 9890 |
|
| 9891 |
-- Deal with named entries |
| 9892 |
|
| 9893 |
if Present (Component_Associations (Arg_Mechanism)) then |
| 9894 |
Massoc := First (Component_Associations (Arg_Mechanism)); |
| 9895 |
while Present (Massoc) loop |
| 9896 |
Choice := First (Choices (Massoc)); |
| 9897 |
|
| 9898 |
if Nkind (Choice) /= N_Identifier |
| 9899 |
or else Present (Next (Choice)) |
| 9900 |
then |
| 9901 |
Error_Pragma_Arg |
| 9902 |
("incorrect form for mechanism association", |
| 9903 |
Massoc); |
| 9904 |
end if; |
| 9905 |
|
| 9906 |
Formal := First_Formal (Ent); |
| 9907 |
loop |
| 9908 |
if No (Formal) then |
| 9909 |
Error_Pragma_Arg |
| 9910 |
("parameter name & not present", Choice); |
| 9911 |
end if; |
| 9912 |
|
| 9913 |
if Chars (Choice) = Chars (Formal) then |
| 9914 |
Set_Mechanism_Value |
| 9915 |
(Formal, Expression (Massoc)); |
| 9916 |
|
| 9917 |
-- Set entity on identifier for proper tree |
| 9918 |
-- structure. |
| 9919 |
|
| 9920 |
Set_Entity (Choice, Formal); |
| 9921 |
|
| 9922 |
exit; |
| 9923 |
end if; |
| 9924 |
|
| 9925 |
Next_Formal (Formal); |
| 9926 |
end loop; |
| 9927 |
|
| 9928 |
Next (Massoc); |
| 9929 |
end loop; |
| 9930 |
end if; |
| 9931 |
end if; |
| 9932 |
end; |
| 9933 |
end if; |
| 9934 |
end Process_Extended_Import_Export_Subprogram_Pragma; |
| 9935 |
|
| 9936 |
-------------------------- |
| 9937 |
-- Process_Generic_List -- |
| 9938 |
-------------------------- |
| 9939 |
|
| 9940 |
procedure Process_Generic_List is |
| 9941 |
Arg : Node_Id; |
| 9942 |
Exp : Node_Id; |
| 9943 |
|
| 9944 |
begin |
| 9945 |
Check_No_Identifiers; |
| 9946 |
Check_At_Least_N_Arguments (1); |
| 9947 |
|
| 9948 |
-- Check all arguments are names of generic units or instances |
| 9949 |
|
| 9950 |
Arg := Arg1; |
| 9951 |
while Present (Arg) loop |
| 9952 |
Exp := Get_Pragma_Arg (Arg); |
| 9953 |
Analyze (Exp); |
| 9954 |
|
| 9955 |
if not Is_Entity_Name (Exp) |
| 9956 |
or else |
| 9957 |
(not Is_Generic_Instance (Entity (Exp)) |
| 9958 |
and then |
| 9959 |
not Is_Generic_Unit (Entity (Exp))) |
| 9960 |
then |
| 9961 |
Error_Pragma_Arg |
| 9962 |
("pragma% argument must be name of generic unit/instance", |
| 9963 |
Arg); |
| 9964 |
end if; |
| 9965 |
|
| 9966 |
Next (Arg); |
| 9967 |
end loop; |
| 9968 |
end Process_Generic_List; |
| 9969 |
|
| 9970 |
------------------------------------ |
| 9971 |
-- Process_Import_Predefined_Type -- |
| 9972 |
------------------------------------ |
| 9973 |
|
| 9974 |
procedure Process_Import_Predefined_Type is |
| 9975 |
Loc : constant Source_Ptr := Sloc (N); |
| 9976 |
Elmt : Elmt_Id; |
| 9977 |
Ftyp : Node_Id := Empty; |
| 9978 |
Decl : Node_Id; |
| 9979 |
Def : Node_Id; |
| 9980 |
Nam : Name_Id; |
| 9981 |
|
| 9982 |
begin |
| 9983 |
Nam := String_To_Name (Strval (Expression (Arg3))); |
| 9984 |
|
| 9985 |
Elmt := First_Elmt (Predefined_Float_Types); |
| 9986 |
while Present (Elmt) and then Chars (Node (Elmt)) /= Nam loop |
| 9987 |
Next_Elmt (Elmt); |
| 9988 |
end loop; |
| 9989 |
|
| 9990 |
Ftyp := Node (Elmt); |
| 9991 |
|
| 9992 |
if Present (Ftyp) then |
| 9993 |
|
| 9994 |
-- Don't build a derived type declaration, because predefined C |
| 9995 |
-- types have no declaration anywhere, so cannot really be named. |
| 9996 |
-- Instead build a full type declaration, starting with an |
| 9997 |
-- appropriate type definition is built |
| 9998 |
|
| 9999 |
if Is_Floating_Point_Type (Ftyp) then |
| 10000 |
Def := Make_Floating_Point_Definition (Loc, |
| 10001 |
Make_Integer_Literal (Loc, Digits_Value (Ftyp)), |
| 10002 |
Make_Real_Range_Specification (Loc, |
| 10003 |
Make_Real_Literal (Loc, Realval (Type_Low_Bound (Ftyp))), |
| 10004 |
Make_Real_Literal (Loc, Realval (Type_High_Bound (Ftyp))))); |
| 10005 |
|
| 10006 |
-- Should never have a predefined type we cannot handle |
| 10007 |
|
| 10008 |
else |
| 10009 |
raise Program_Error; |
| 10010 |
end if; |
| 10011 |
|
| 10012 |
-- Build and insert a Full_Type_Declaration, which will be |
| 10013 |
-- analyzed as soon as this list entry has been analyzed. |
| 10014 |
|
| 10015 |
Decl := Make_Full_Type_Declaration (Loc, |
| 10016 |
Make_Defining_Identifier (Loc, Chars (Expression (Arg2))), |
| 10017 |
Type_Definition => Def); |
| 10018 |
|
| 10019 |
Insert_After (N, Decl); |
| 10020 |
Mark_Rewrite_Insertion (Decl); |
| 10021 |
|
| 10022 |
else |
| 10023 |
Error_Pragma_Arg ("no matching type found for pragma%", Arg2); |
| 10024 |
end if; |
| 10025 |
end Process_Import_Predefined_Type; |
| 10026 |
|
| 10027 |
--------------------------------- |
| 10028 |
-- Process_Import_Or_Interface -- |
| 10029 |
--------------------------------- |
| 10030 |
|
| 10031 |
procedure Process_Import_Or_Interface is |
| 10032 |
C : Convention_Id; |
| 10033 |
Def_Id : Entity_Id; |
| 10034 |
Hom_Id : Entity_Id; |
| 10035 |
|
| 10036 |
begin |
| 10037 |
-- In Relaxed_RM_Semantics, support old Ada 83 style: |
| 10038 |
-- pragma Import (Entity, "external name"); |
| 10039 |
|
| 10040 |
if Relaxed_RM_Semantics |
| 10041 |
and then Arg_Count = 2 |
| 10042 |
and then Prag_Id = Pragma_Import |
| 10043 |
and then Nkind (Expression (Arg2)) = N_String_Literal |
| 10044 |
then |
| 10045 |
C := Convention_C; |
| 10046 |
Def_Id := Get_Pragma_Arg (Arg1); |
| 10047 |
Analyze (Def_Id); |
| 10048 |
|
| 10049 |
if not Is_Entity_Name (Def_Id) then |
| 10050 |
Error_Pragma_Arg ("entity name required", Arg1); |
| 10051 |
end if; |
| 10052 |
|
| 10053 |
Def_Id := Entity (Def_Id); |
| 10054 |
Kill_Size_Check_Code (Def_Id); |
| 10055 |
if Ekind (Def_Id) /= E_Constant then |
| 10056 |
Note_Possible_Modification |
| 10057 |
(Get_Pragma_Arg (Arg1), Sure => False); |
| 10058 |
end if; |
| 10059 |
|
| 10060 |
else |
| 10061 |
Process_Convention (C, Def_Id); |
| 10062 |
|
| 10063 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 10064 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 10065 |
|
| 10066 |
Mark_Ghost_Pragma (N, Def_Id); |
| 10067 |
Kill_Size_Check_Code (Def_Id); |
| 10068 |
if Ekind (Def_Id) /= E_Constant then |
| 10069 |
Note_Possible_Modification |
| 10070 |
(Get_Pragma_Arg (Arg2), Sure => False); |
| 10071 |
end if; |
| 10072 |
end if; |
| 10073 |
|
| 10074 |
-- Various error checks |
| 10075 |
|
| 10076 |
if Ekind (Def_Id) in E_Variable | E_Constant then |
| 10077 |
|
| 10078 |
-- We do not permit Import to apply to a renaming declaration |
| 10079 |
|
| 10080 |
if Present (Renamed_Object (Def_Id)) then |
| 10081 |
Error_Pragma_Arg |
| 10082 |
("pragma% not allowed for object renaming", Arg2); |
| 10083 |
|
| 10084 |
-- User initialization is not allowed for imported object, but |
| 10085 |
-- the object declaration may contain a default initialization, |
| 10086 |
-- that will be discarded. Note that an explicit initialization |
| 10087 |
-- only counts if it comes from source, otherwise it is simply |
| 10088 |
-- the code generator making an implicit initialization explicit. |
| 10089 |
|
| 10090 |
elsif (Present (Expression (Parent (Def_Id))) |
| 10091 |
and then Comes_From_Source |
| 10092 |
(Original_Node (Expression (Parent (Def_Id))))) |
| 10093 |
or else Has_Init_Expression (Parent (Def_Id)) |
| 10094 |
then |
| 10095 |
-- Set imported flag to prevent cascaded errors |
| 10096 |
|
| 10097 |
Set_Is_Imported (Def_Id); |
| 10098 |
|
| 10099 |
Error_Msg_Sloc := Sloc (Def_Id); |
| 10100 |
Error_Pragma_Arg |
| 10101 |
("no initialization allowed for declaration of& #", |
| 10102 |
"\imported entities cannot be initialized (RM B.1(24))", |
| 10103 |
Arg2); |
| 10104 |
|
| 10105 |
else |
| 10106 |
-- If the pragma comes from an aspect specification the |
| 10107 |
-- Is_Imported flag has already been set. |
| 10108 |
|
| 10109 |
if not From_Aspect_Specification (N) then |
| 10110 |
Set_Imported (Def_Id); |
| 10111 |
end if; |
| 10112 |
|
| 10113 |
Process_Interface_Name (Def_Id, Arg3, Arg4, N); |
| 10114 |
|
| 10115 |
-- Note that we do not set Is_Public here. That's because we |
| 10116 |
-- only want to set it if there is no address clause, and we |
| 10117 |
-- don't know that yet, so we delay that processing till |
| 10118 |
-- freeze time. |
| 10119 |
|
| 10120 |
-- pragma Import completes deferred constants |
| 10121 |
|
| 10122 |
if Ekind (Def_Id) = E_Constant then |
| 10123 |
Set_Has_Completion (Def_Id); |
| 10124 |
end if; |
| 10125 |
|
| 10126 |
-- It is not possible to import a constant of an unconstrained |
| 10127 |
-- array type (e.g. string) because there is no simple way to |
| 10128 |
-- write a meaningful subtype for it. |
| 10129 |
|
| 10130 |
if Is_Array_Type (Etype (Def_Id)) |
| 10131 |
and then not Is_Constrained (Etype (Def_Id)) |
| 10132 |
then |
| 10133 |
Error_Msg_NE |
| 10134 |
("imported constant& must have a constrained subtype", |
| 10135 |
N, Def_Id); |
| 10136 |
end if; |
| 10137 |
end if; |
| 10138 |
|
| 10139 |
elsif Is_Subprogram_Or_Generic_Subprogram (Def_Id) then |
| 10140 |
|
| 10141 |
-- If the name is overloaded, pragma applies to all of the denoted |
| 10142 |
-- entities in the same declarative part, unless the pragma comes |
| 10143 |
-- from an aspect specification or was generated by the compiler |
| 10144 |
-- (such as for pragma Provide_Shift_Operators). |
| 10145 |
|
| 10146 |
Hom_Id := Def_Id; |
| 10147 |
while Present (Hom_Id) loop |
| 10148 |
|
| 10149 |
Def_Id := Get_Base_Subprogram (Hom_Id); |
| 10150 |
|
| 10151 |
-- Ignore inherited subprograms because the pragma will apply |
| 10152 |
-- to the parent operation, which is the one called. |
| 10153 |
|
| 10154 |
if Is_Overloadable (Def_Id) |
| 10155 |
and then Present (Alias (Def_Id)) |
| 10156 |
then |
| 10157 |
null; |
| 10158 |
|
| 10159 |
-- If it is not a subprogram, it must be in an outer scope and |
| 10160 |
-- pragma does not apply. |
| 10161 |
|
| 10162 |
elsif not Is_Subprogram_Or_Generic_Subprogram (Def_Id) then |
| 10163 |
null; |
| 10164 |
|
| 10165 |
-- The pragma does not apply to primitives of interfaces |
| 10166 |
|
| 10167 |
elsif Is_Dispatching_Operation (Def_Id) |
| 10168 |
and then Present (Find_Dispatching_Type (Def_Id)) |
| 10169 |
and then Is_Interface (Find_Dispatching_Type (Def_Id)) |
| 10170 |
then |
| 10171 |
null; |
| 10172 |
|
| 10173 |
-- Verify that the homonym is in the same declarative part (not |
| 10174 |
-- just the same scope). If the pragma comes from an aspect |
| 10175 |
-- specification we know that it is part of the declaration. |
| 10176 |
|
| 10177 |
elsif (No (Unit_Declaration_Node (Def_Id)) |
| 10178 |
or else Parent (Unit_Declaration_Node (Def_Id)) /= |
| 10179 |
Parent (N)) |
| 10180 |
and then Nkind (Parent (N)) /= N_Compilation_Unit_Aux |
| 10181 |
and then not From_Aspect_Specification (N) |
| 10182 |
then |
| 10183 |
exit; |
| 10184 |
|
| 10185 |
else |
| 10186 |
-- If the pragma comes from an aspect specification the |
| 10187 |
-- Is_Imported flag has already been set. |
| 10188 |
|
| 10189 |
if not From_Aspect_Specification (N) then |
| 10190 |
Set_Imported (Def_Id); |
| 10191 |
end if; |
| 10192 |
|
| 10193 |
-- Reject an Import applied to an abstract subprogram |
| 10194 |
|
| 10195 |
if Is_Subprogram (Def_Id) |
| 10196 |
and then Is_Abstract_Subprogram (Def_Id) |
| 10197 |
then |
| 10198 |
Error_Msg_Sloc := Sloc (Def_Id); |
| 10199 |
Error_Msg_NE |
| 10200 |
("cannot import abstract subprogram& declared#", |
| 10201 |
Arg2, Def_Id); |
| 10202 |
end if; |
| 10203 |
|
| 10204 |
-- Special processing for Convention_Intrinsic |
| 10205 |
|
| 10206 |
if C = Convention_Intrinsic then |
| 10207 |
|
| 10208 |
-- Link_Name argument not allowed for intrinsic |
| 10209 |
|
| 10210 |
Check_No_Link_Name; |
| 10211 |
|
| 10212 |
Set_Is_Intrinsic_Subprogram (Def_Id); |
| 10213 |
|
| 10214 |
-- If no external name is present, then check that this |
| 10215 |
-- is a valid intrinsic subprogram. If an external name |
| 10216 |
-- is present, then this is handled by the back end. |
| 10217 |
|
| 10218 |
if No (Arg3) then |
| 10219 |
Check_Intrinsic_Subprogram |
| 10220 |
(Def_Id, Get_Pragma_Arg (Arg2)); |
| 10221 |
end if; |
| 10222 |
end if; |
| 10223 |
|
| 10224 |
-- Verify that the subprogram does not have a completion |
| 10225 |
-- through a renaming declaration. For other completions the |
| 10226 |
-- pragma appears as a too late representation. |
| 10227 |
|
| 10228 |
declare |
| 10229 |
Decl : constant Node_Id := Unit_Declaration_Node (Def_Id); |
| 10230 |
|
| 10231 |
begin |
| 10232 |
if Present (Decl) |
| 10233 |
and then Nkind (Decl) = N_Subprogram_Declaration |
| 10234 |
and then Present (Corresponding_Body (Decl)) |
| 10235 |
and then Nkind (Unit_Declaration_Node |
| 10236 |
(Corresponding_Body (Decl))) = |
| 10237 |
N_Subprogram_Renaming_Declaration |
| 10238 |
then |
| 10239 |
Error_Msg_Sloc := Sloc (Def_Id); |
| 10240 |
Error_Msg_NE |
| 10241 |
("cannot import&, renaming already provided for " |
| 10242 |
& "declaration #", N, Def_Id); |
| 10243 |
end if; |
| 10244 |
end; |
| 10245 |
|
| 10246 |
-- If the pragma comes from an aspect specification, there |
| 10247 |
-- must be an Import aspect specified as well. In the rare |
| 10248 |
-- case where Import is set to False, the subprogram needs |
| 10249 |
-- to have a local completion. |
| 10250 |
|
| 10251 |
declare |
| 10252 |
Imp_Aspect : constant Node_Id := |
| 10253 |
Find_Aspect (Def_Id, Aspect_Import); |
| 10254 |
Expr : Node_Id; |
| 10255 |
|
| 10256 |
begin |
| 10257 |
if Present (Imp_Aspect) |
| 10258 |
and then Present (Expression (Imp_Aspect)) |
| 10259 |
then |
| 10260 |
Expr := Expression (Imp_Aspect); |
| 10261 |
Analyze_And_Resolve (Expr, Standard_Boolean); |
| 10262 |
|
| 10263 |
if Is_Entity_Name (Expr) |
| 10264 |
and then Entity (Expr) = Standard_True |
| 10265 |
then |
| 10266 |
Set_Has_Completion (Def_Id); |
| 10267 |
end if; |
| 10268 |
|
| 10269 |
-- If there is no expression, the default is True, as for |
| 10270 |
-- all boolean aspects. Same for the older pragma. |
| 10271 |
|
| 10272 |
else |
| 10273 |
Set_Has_Completion (Def_Id); |
| 10274 |
end if; |
| 10275 |
end; |
| 10276 |
|
| 10277 |
Process_Interface_Name (Def_Id, Arg3, Arg4, N); |
| 10278 |
end if; |
| 10279 |
|
| 10280 |
if Is_Compilation_Unit (Hom_Id) then |
| 10281 |
|
| 10282 |
-- Its possible homonyms are not affected by the pragma. |
| 10283 |
-- Such homonyms might be present in the context of other |
| 10284 |
-- units being compiled. |
| 10285 |
|
| 10286 |
exit; |
| 10287 |
|
| 10288 |
elsif From_Aspect_Specification (N) then |
| 10289 |
exit; |
| 10290 |
|
| 10291 |
-- If the pragma was created by the compiler, then we don't |
| 10292 |
-- want it to apply to other homonyms. This kind of case can |
| 10293 |
-- occur when using pragma Provide_Shift_Operators, which |
| 10294 |
-- generates implicit shift and rotate operators with Import |
| 10295 |
-- pragmas that might apply to earlier explicit or implicit |
| 10296 |
-- declarations marked with Import (for example, coming from |
| 10297 |
-- an earlier pragma Provide_Shift_Operators for another type), |
| 10298 |
-- and we don't generally want other homonyms being treated |
| 10299 |
-- as imported or the pragma flagged as an illegal duplicate. |
| 10300 |
|
| 10301 |
elsif not Comes_From_Source (N) then |
| 10302 |
exit; |
| 10303 |
|
| 10304 |
else |
| 10305 |
Hom_Id := Homonym (Hom_Id); |
| 10306 |
end if; |
| 10307 |
end loop; |
| 10308 |
|
| 10309 |
-- Import a CPP class |
| 10310 |
|
| 10311 |
elsif C = Convention_CPP |
| 10312 |
and then (Is_Record_Type (Def_Id) |
| 10313 |
or else Ekind (Def_Id) = E_Incomplete_Type) |
| 10314 |
then |
| 10315 |
if Ekind (Def_Id) = E_Incomplete_Type then |
| 10316 |
if Present (Full_View (Def_Id)) then |
| 10317 |
Def_Id := Full_View (Def_Id); |
| 10318 |
|
| 10319 |
else |
| 10320 |
Error_Msg_N |
| 10321 |
("cannot import 'C'P'P type before full declaration seen", |
| 10322 |
Get_Pragma_Arg (Arg2)); |
| 10323 |
|
| 10324 |
-- Although we have reported the error we decorate it as |
| 10325 |
-- CPP_Class to avoid reporting spurious errors |
| 10326 |
|
| 10327 |
Set_Is_CPP_Class (Def_Id); |
| 10328 |
return; |
| 10329 |
end if; |
| 10330 |
end if; |
| 10331 |
|
| 10332 |
-- Types treated as CPP classes must be declared limited (note: |
| 10333 |
-- this used to be a warning but there is no real benefit to it |
| 10334 |
-- since we did effectively intend to treat the type as limited |
| 10335 |
-- anyway). |
| 10336 |
|
| 10337 |
if not Is_Limited_Type (Def_Id) then |
| 10338 |
Error_Msg_N |
| 10339 |
("imported 'C'P'P type must be limited", |
| 10340 |
Get_Pragma_Arg (Arg2)); |
| 10341 |
end if; |
| 10342 |
|
| 10343 |
if Etype (Def_Id) /= Def_Id |
| 10344 |
and then not Is_CPP_Class (Root_Type (Def_Id)) |
| 10345 |
then |
| 10346 |
Error_Msg_N ("root type must be a 'C'P'P type", Arg1); |
| 10347 |
end if; |
| 10348 |
|
| 10349 |
Set_Is_CPP_Class (Def_Id); |
| 10350 |
|
| 10351 |
-- Imported CPP types must not have discriminants (because C++ |
| 10352 |
-- classes do not have discriminants). |
| 10353 |
|
| 10354 |
if Has_Discriminants (Def_Id) then |
| 10355 |
Error_Msg_N |
| 10356 |
("imported 'C'P'P type cannot have discriminants", |
| 10357 |
First (Discriminant_Specifications |
| 10358 |
(Declaration_Node (Def_Id)))); |
| 10359 |
end if; |
| 10360 |
|
| 10361 |
-- Check that components of imported CPP types do not have default |
| 10362 |
-- expressions. For private types this check is performed when the |
| 10363 |
-- full view is analyzed (see Process_Full_View). |
| 10364 |
|
| 10365 |
if not Is_Private_Type (Def_Id) then |
| 10366 |
Check_CPP_Type_Has_No_Defaults (Def_Id); |
| 10367 |
end if; |
| 10368 |
|
| 10369 |
-- Import a CPP exception |
| 10370 |
|
| 10371 |
elsif C = Convention_CPP |
| 10372 |
and then Ekind (Def_Id) = E_Exception |
| 10373 |
then |
| 10374 |
if No (Arg3) then |
| 10375 |
Error_Pragma_Arg |
| 10376 |
("'External_'Name arguments is required for 'Cpp exception", |
| 10377 |
Arg3); |
| 10378 |
else |
| 10379 |
-- As only a string is allowed, Check_Arg_Is_External_Name |
| 10380 |
-- isn't called. |
| 10381 |
|
| 10382 |
Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String); |
| 10383 |
end if; |
| 10384 |
|
| 10385 |
if Present (Arg4) then |
| 10386 |
Error_Pragma_Arg |
| 10387 |
("Link_Name argument not allowed for imported Cpp exception", |
| 10388 |
Arg4); |
| 10389 |
end if; |
| 10390 |
|
| 10391 |
-- Do not call Set_Interface_Name as the name of the exception |
| 10392 |
-- shouldn't be modified (and in particular it shouldn't be |
| 10393 |
-- the External_Name). For exceptions, the External_Name is the |
| 10394 |
-- name of the RTTI structure. |
| 10395 |
|
| 10396 |
-- ??? Emit an error if pragma Import/Export_Exception is present |
| 10397 |
|
| 10398 |
elsif Nkind (Parent (Def_Id)) = N_Incomplete_Type_Declaration then |
| 10399 |
Check_No_Link_Name; |
| 10400 |
Check_Arg_Count (3); |
| 10401 |
Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String); |
| 10402 |
|
| 10403 |
Process_Import_Predefined_Type; |
| 10404 |
|
| 10405 |
-- Emit an error unless Relaxed_RM_Semantics since some legacy Ada |
| 10406 |
-- compilers may accept more cases, e.g. JGNAT allowed importing |
| 10407 |
-- a Java package. |
| 10408 |
|
| 10409 |
elsif not Relaxed_RM_Semantics then |
| 10410 |
if From_Aspect_Specification (N) then |
| 10411 |
Error_Pragma_Arg |
| 10412 |
("entity for aspect% must be object, subprogram " |
| 10413 |
& "or incomplete type", |
| 10414 |
Arg2); |
| 10415 |
else |
| 10416 |
Error_Pragma_Arg |
| 10417 |
("second argument of pragma% must be object, subprogram " |
| 10418 |
& "or incomplete type", |
| 10419 |
Arg2); |
| 10420 |
end if; |
| 10421 |
end if; |
| 10422 |
|
| 10423 |
-- If this pragma applies to a compilation unit, then the unit, which |
| 10424 |
-- is a subprogram, does not require (or allow) a body. We also do |
| 10425 |
-- not need to elaborate imported procedures. |
| 10426 |
|
| 10427 |
if Nkind (Parent (N)) = N_Compilation_Unit_Aux then |
| 10428 |
declare |
| 10429 |
Cunit : constant Node_Id := Parent (Parent (N)); |
| 10430 |
begin |
| 10431 |
Set_Body_Required (Cunit, False); |
| 10432 |
end; |
| 10433 |
end if; |
| 10434 |
end Process_Import_Or_Interface; |
| 10435 |
|
| 10436 |
-------------------- |
| 10437 |
-- Process_Inline -- |
| 10438 |
-------------------- |
| 10439 |
|
| 10440 |
procedure Process_Inline (Status : Inline_Status) is |
| 10441 |
Applies : Boolean; |
| 10442 |
Assoc : Node_Id; |
| 10443 |
Decl : Node_Id; |
| 10444 |
Subp : Entity_Id; |
| 10445 |
Subp_Id : Node_Id; |
| 10446 |
|
| 10447 |
Ghost_Error_Posted : Boolean := False; |
| 10448 |
-- Flag set when an error concerning the illegal mix of Ghost and |
| 10449 |
-- non-Ghost subprograms is emitted. |
| 10450 |
|
| 10451 |
Ghost_Id : Entity_Id := Empty; |
| 10452 |
-- The entity of the first Ghost subprogram encountered while |
| 10453 |
-- processing the arguments of the pragma. |
| 10454 |
|
| 10455 |
procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id); |
| 10456 |
-- Verify the placement of pragma Inline_Always with respect to the |
| 10457 |
-- initial declaration of subprogram Spec_Id. |
| 10458 |
|
| 10459 |
function Inlining_Not_Possible (Subp : Entity_Id) return Boolean; |
| 10460 |
-- Returns True if it can be determined at this stage that inlining |
| 10461 |
-- is not possible, for example if the body is available and contains |
| 10462 |
-- exception handlers, we prevent inlining, since otherwise we can |
| 10463 |
-- get undefined symbols at link time. This function also emits a |
| 10464 |
-- warning if the pragma appears too late. |
| 10465 |
-- |
| 10466 |
-- ??? is business with link symbols still valid, or does it relate |
| 10467 |
-- to front end ZCX which is being phased out ??? |
| 10468 |
|
| 10469 |
procedure Make_Inline (Subp : Entity_Id); |
| 10470 |
-- Subp is the defining unit name of the subprogram declaration. If |
| 10471 |
-- the pragma is valid, call Set_Inline_Flags on Subp, as well as on |
| 10472 |
-- the corresponding body, if there is one present. |
| 10473 |
|
| 10474 |
procedure Set_Inline_Flags (Subp : Entity_Id); |
| 10475 |
-- Set Has_Pragma_{No_Inline,Inline,Inline_Always} flag on Subp. |
| 10476 |
-- Also set or clear Is_Inlined flag on Subp depending on Status. |
| 10477 |
|
| 10478 |
----------------------------------- |
| 10479 |
-- Check_Inline_Always_Placement -- |
| 10480 |
----------------------------------- |
| 10481 |
|
| 10482 |
procedure Check_Inline_Always_Placement (Spec_Id : Entity_Id) is |
| 10483 |
Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id); |
| 10484 |
|
| 10485 |
function Compilation_Unit_OK return Boolean; |
| 10486 |
pragma Inline (Compilation_Unit_OK); |
| 10487 |
-- Determine whether pragma Inline_Always applies to a compatible |
| 10488 |
-- compilation unit denoted by Spec_Id. |
| 10489 |
|
| 10490 |
function Declarative_List_OK return Boolean; |
| 10491 |
pragma Inline (Declarative_List_OK); |
| 10492 |
-- Determine whether the initial declaration of subprogram Spec_Id |
| 10493 |
-- and the pragma appear in compatible declarative lists. |
| 10494 |
|
| 10495 |
function Subprogram_Body_OK return Boolean; |
| 10496 |
pragma Inline (Subprogram_Body_OK); |
| 10497 |
-- Determine whether pragma Inline_Always applies to a compatible |
| 10498 |
-- subprogram body denoted by Spec_Id. |
| 10499 |
|
| 10500 |
------------------------- |
| 10501 |
-- Compilation_Unit_OK -- |
| 10502 |
------------------------- |
| 10503 |
|
| 10504 |
function Compilation_Unit_OK return Boolean is |
| 10505 |
Comp_Unit : constant Node_Id := Parent (Spec_Decl); |
| 10506 |
|
| 10507 |
begin |
| 10508 |
-- The pragma appears after the initial declaration of a |
| 10509 |
-- compilation unit. |
| 10510 |
|
| 10511 |
-- procedure Comp_Unit; |
| 10512 |
-- pragma Inline_Always (Comp_Unit); |
| 10513 |
|
| 10514 |
-- Note that for compatibility reasons, the following case is |
| 10515 |
-- also accepted. |
| 10516 |
|
| 10517 |
-- procedure Stand_Alone_Body_Comp_Unit is |
| 10518 |
-- ... |
| 10519 |
-- end Stand_Alone_Body_Comp_Unit; |
| 10520 |
-- pragma Inline_Always (Stand_Alone_Body_Comp_Unit); |
| 10521 |
|
| 10522 |
return |
| 10523 |
Nkind (Comp_Unit) = N_Compilation_Unit |
| 10524 |
and then Present (Aux_Decls_Node (Comp_Unit)) |
| 10525 |
and then Is_List_Member (N) |
| 10526 |
and then List_Containing (N) = |
| 10527 |
Pragmas_After (Aux_Decls_Node (Comp_Unit)); |
| 10528 |
end Compilation_Unit_OK; |
| 10529 |
|
| 10530 |
------------------------- |
| 10531 |
-- Declarative_List_OK -- |
| 10532 |
------------------------- |
| 10533 |
|
| 10534 |
function Declarative_List_OK return Boolean is |
| 10535 |
Context : constant Node_Id := Parent (Spec_Decl); |
| 10536 |
|
| 10537 |
Init_Decl : Node_Id; |
| 10538 |
Init_List : List_Id; |
| 10539 |
Prag_List : List_Id; |
| 10540 |
|
| 10541 |
begin |
| 10542 |
-- Determine the proper initial declaration. In general this is |
| 10543 |
-- the declaration node of the subprogram except when the input |
| 10544 |
-- denotes a generic instantiation. |
| 10545 |
|
| 10546 |
-- procedure Inst is new Gen; |
| 10547 |
-- pragma Inline_Always (Inst); |
| 10548 |
|
| 10549 |
-- In this case the original subprogram is moved inside an |
| 10550 |
-- anonymous package while pragma Inline_Always remains at the |
| 10551 |
-- level of the anonymous package. Use the declaration of the |
| 10552 |
-- package because it reflects the placement of the original |
| 10553 |
-- instantiation. |
| 10554 |
|
| 10555 |
-- package Anon_Pack is |
| 10556 |
-- procedure Inst is ... end Inst; -- original |
| 10557 |
-- end Anon_Pack; |
| 10558 |
|
| 10559 |
-- procedure Inst renames Anon_Pack.Inst; |
| 10560 |
-- pragma Inline_Always (Inst); |
| 10561 |
|
| 10562 |
if Is_Generic_Instance (Spec_Id) then |
| 10563 |
Init_Decl := Parent (Parent (Spec_Decl)); |
| 10564 |
pragma Assert (Nkind (Init_Decl) = N_Package_Declaration); |
| 10565 |
else |
| 10566 |
Init_Decl := Spec_Decl; |
| 10567 |
end if; |
| 10568 |
|
| 10569 |
if Is_List_Member (Init_Decl) and then Is_List_Member (N) then |
| 10570 |
Init_List := List_Containing (Init_Decl); |
| 10571 |
Prag_List := List_Containing (N); |
| 10572 |
|
| 10573 |
-- The pragma and then initial declaration appear within the |
| 10574 |
-- same declarative list. |
| 10575 |
|
| 10576 |
if Init_List = Prag_List then |
| 10577 |
return True; |
| 10578 |
|
| 10579 |
-- A special case of the above is when both the pragma and |
| 10580 |
-- the initial declaration appear in different lists of a |
| 10581 |
-- package spec, protected definition, or a task definition. |
| 10582 |
|
| 10583 |
-- package Pack is |
| 10584 |
-- procedure Proc; |
| 10585 |
-- private |
| 10586 |
-- pragma Inline_Always (Proc); |
| 10587 |
-- end Pack; |
| 10588 |
|
| 10589 |
elsif Nkind (Context) in N_Package_Specification |
| 10590 |
| N_Protected_Definition |
| 10591 |
| N_Task_Definition |
| 10592 |
and then Init_List = Visible_Declarations (Context) |
| 10593 |
and then Prag_List = Private_Declarations (Context) |
| 10594 |
then |
| 10595 |
return True; |
| 10596 |
end if; |
| 10597 |
end if; |
| 10598 |
|
| 10599 |
return False; |
| 10600 |
end Declarative_List_OK; |
| 10601 |
|
| 10602 |
------------------------ |
| 10603 |
-- Subprogram_Body_OK -- |
| 10604 |
------------------------ |
| 10605 |
|
| 10606 |
function Subprogram_Body_OK return Boolean is |
| 10607 |
Body_Decl : Node_Id; |
| 10608 |
|
| 10609 |
begin |
| 10610 |
-- The pragma appears within the declarative list of a stand- |
| 10611 |
-- alone subprogram body. |
| 10612 |
|
| 10613 |
-- procedure Stand_Alone_Body is |
| 10614 |
-- pragma Inline_Always (Stand_Alone_Body); |
| 10615 |
-- begin |
| 10616 |
-- ... |
| 10617 |
-- end Stand_Alone_Body; |
| 10618 |
|
| 10619 |
-- The compiler creates a dummy spec in this case, however the |
| 10620 |
-- pragma remains within the declarative list of the body. |
| 10621 |
|
| 10622 |
if Nkind (Spec_Decl) = N_Subprogram_Declaration |
| 10623 |
and then not Comes_From_Source (Spec_Decl) |
| 10624 |
and then Present (Corresponding_Body (Spec_Decl)) |
| 10625 |
then |
| 10626 |
Body_Decl := |
| 10627 |
Unit_Declaration_Node (Corresponding_Body (Spec_Decl)); |
| 10628 |
|
| 10629 |
if Present (Declarations (Body_Decl)) |
| 10630 |
and then Is_List_Member (N) |
| 10631 |
and then List_Containing (N) = Declarations (Body_Decl) |
| 10632 |
then |
| 10633 |
return True; |
| 10634 |
end if; |
| 10635 |
end if; |
| 10636 |
|
| 10637 |
return False; |
| 10638 |
end Subprogram_Body_OK; |
| 10639 |
|
| 10640 |
-- Start of processing for Check_Inline_Always_Placement |
| 10641 |
|
| 10642 |
begin |
| 10643 |
-- This check is relevant only for pragma Inline_Always |
| 10644 |
|
| 10645 |
if Pname /= Name_Inline_Always then |
| 10646 |
return; |
| 10647 |
|
| 10648 |
-- Nothing to do when the pragma is internally generated on the |
| 10649 |
-- assumption that it is properly placed. |
| 10650 |
|
| 10651 |
elsif not Comes_From_Source (N) then |
| 10652 |
return; |
| 10653 |
|
| 10654 |
-- Nothing to do for internally generated subprograms that act |
| 10655 |
-- as accidental homonyms of a source subprogram being inlined. |
| 10656 |
|
| 10657 |
elsif not Comes_From_Source (Spec_Id) then |
| 10658 |
return; |
| 10659 |
|
| 10660 |
-- Nothing to do for generic formal subprograms that act as |
| 10661 |
-- homonyms of another source subprogram being inlined. |
| 10662 |
|
| 10663 |
elsif Is_Formal_Subprogram (Spec_Id) then |
| 10664 |
return; |
| 10665 |
|
| 10666 |
elsif Compilation_Unit_OK |
| 10667 |
or else Declarative_List_OK |
| 10668 |
or else Subprogram_Body_OK |
| 10669 |
then |
| 10670 |
return; |
| 10671 |
end if; |
| 10672 |
|
| 10673 |
-- At this point it is known that the pragma applies to or appears |
| 10674 |
-- within a completing body, a completing stub, or a subunit. |
| 10675 |
|
| 10676 |
Error_Msg_Name_1 := Pname; |
| 10677 |
Error_Msg_Name_2 := Chars (Spec_Id); |
| 10678 |
Error_Msg_Sloc := Sloc (Spec_Id); |
| 10679 |
|
| 10680 |
Error_Msg_N |
| 10681 |
("pragma % must appear on initial declaration of subprogram " |
| 10682 |
& "% defined #", N); |
| 10683 |
end Check_Inline_Always_Placement; |
| 10684 |
|
| 10685 |
--------------------------- |
| 10686 |
-- Inlining_Not_Possible -- |
| 10687 |
--------------------------- |
| 10688 |
|
| 10689 |
function Inlining_Not_Possible (Subp : Entity_Id) return Boolean is |
| 10690 |
Decl : constant Node_Id := Unit_Declaration_Node (Subp); |
| 10691 |
Stats : Node_Id; |
| 10692 |
|
| 10693 |
begin |
| 10694 |
if Nkind (Decl) = N_Subprogram_Body then |
| 10695 |
Stats := Handled_Statement_Sequence (Decl); |
| 10696 |
return Present (Exception_Handlers (Stats)) |
| 10697 |
or else Present (At_End_Proc (Stats)); |
| 10698 |
|
| 10699 |
elsif Nkind (Decl) = N_Subprogram_Declaration |
| 10700 |
and then Present (Corresponding_Body (Decl)) |
| 10701 |
then |
| 10702 |
if Analyzed (Corresponding_Body (Decl)) then |
| 10703 |
Error_Msg_N ("pragma appears too late, ignored??", N); |
| 10704 |
return True; |
| 10705 |
|
| 10706 |
-- If the subprogram is a renaming as body, the body is just a |
| 10707 |
-- call to the renamed subprogram, and inlining is trivially |
| 10708 |
-- possible. |
| 10709 |
|
| 10710 |
elsif |
| 10711 |
Nkind (Unit_Declaration_Node (Corresponding_Body (Decl))) = |
| 10712 |
N_Subprogram_Renaming_Declaration |
| 10713 |
then |
| 10714 |
return False; |
| 10715 |
|
| 10716 |
else |
| 10717 |
Stats := |
| 10718 |
Handled_Statement_Sequence |
| 10719 |
(Unit_Declaration_Node (Corresponding_Body (Decl))); |
| 10720 |
|
| 10721 |
return |
| 10722 |
Present (Exception_Handlers (Stats)) |
| 10723 |
or else Present (At_End_Proc (Stats)); |
| 10724 |
end if; |
| 10725 |
|
| 10726 |
else |
| 10727 |
-- If body is not available, assume the best, the check is |
| 10728 |
-- performed again when compiling enclosing package bodies. |
| 10729 |
|
| 10730 |
return False; |
| 10731 |
end if; |
| 10732 |
end Inlining_Not_Possible; |
| 10733 |
|
| 10734 |
----------------- |
| 10735 |
-- Make_Inline -- |
| 10736 |
----------------- |
| 10737 |
|
| 10738 |
procedure Make_Inline (Subp : Entity_Id) is |
| 10739 |
Kind : constant Entity_Kind := Ekind (Subp); |
| 10740 |
Inner_Subp : Entity_Id := Subp; |
| 10741 |
|
| 10742 |
begin |
| 10743 |
-- Ignore if bad type, avoid cascaded error |
| 10744 |
|
| 10745 |
if Etype (Subp) = Any_Type then |
| 10746 |
Applies := True; |
| 10747 |
return; |
| 10748 |
|
| 10749 |
-- If inlining is not possible, for now do not treat as an error |
| 10750 |
|
| 10751 |
elsif Status /= Suppressed |
| 10752 |
and then Front_End_Inlining |
| 10753 |
and then Inlining_Not_Possible (Subp) |
| 10754 |
then |
| 10755 |
Applies := True; |
| 10756 |
return; |
| 10757 |
|
| 10758 |
-- Here we have a candidate for inlining, but we must exclude |
| 10759 |
-- derived operations. Otherwise we would end up trying to inline |
| 10760 |
-- a phantom declaration, and the result would be to drag in a |
| 10761 |
-- body which has no direct inlining associated with it. That |
| 10762 |
-- would not only be inefficient but would also result in the |
| 10763 |
-- backend doing cross-unit inlining in cases where it was |
| 10764 |
-- definitely inappropriate to do so. |
| 10765 |
|
| 10766 |
-- However, a simple Comes_From_Source test is insufficient, since |
| 10767 |
-- we do want to allow inlining of generic instances which also do |
| 10768 |
-- not come from source. We also need to recognize specs generated |
| 10769 |
-- by the front-end for bodies that carry the pragma. Finally, |
| 10770 |
-- predefined operators do not come from source but are not |
| 10771 |
-- inlineable either. |
| 10772 |
|
| 10773 |
elsif Is_Generic_Instance (Subp) |
| 10774 |
or else Parent_Kind (Parent (Subp)) = N_Subprogram_Declaration |
| 10775 |
then |
| 10776 |
null; |
| 10777 |
|
| 10778 |
elsif not Comes_From_Source (Subp) |
| 10779 |
and then Scope (Subp) /= Standard_Standard |
| 10780 |
then |
| 10781 |
Applies := True; |
| 10782 |
return; |
| 10783 |
end if; |
| 10784 |
|
| 10785 |
-- The referenced entity must either be the enclosing entity, or |
| 10786 |
-- an entity declared within the current open scope. |
| 10787 |
|
| 10788 |
if Present (Scope (Subp)) |
| 10789 |
and then Scope (Subp) /= Current_Scope |
| 10790 |
and then Subp /= Current_Scope |
| 10791 |
then |
| 10792 |
Error_Pragma_Arg |
| 10793 |
("argument of% must be entity in current scope", Assoc); |
| 10794 |
end if; |
| 10795 |
|
| 10796 |
-- Processing for procedure, operator or function. If subprogram |
| 10797 |
-- is aliased (as for an instance) indicate that the renamed |
| 10798 |
-- entity (if declared in the same unit) is inlined. |
| 10799 |
-- If this is the anonymous subprogram created for a subprogram |
| 10800 |
-- instance, the inlining applies to it directly. Otherwise we |
| 10801 |
-- retrieve it as the alias of the visible subprogram instance. |
| 10802 |
|
| 10803 |
if Is_Subprogram (Subp) then |
| 10804 |
|
| 10805 |
-- Ensure that pragma Inline_Always is associated with the |
| 10806 |
-- initial declaration of the subprogram. |
| 10807 |
|
| 10808 |
Check_Inline_Always_Placement (Subp); |
| 10809 |
|
| 10810 |
if Is_Wrapper_Package (Scope (Subp)) then |
| 10811 |
Inner_Subp := Subp; |
| 10812 |
else |
| 10813 |
Inner_Subp := Ultimate_Alias (Inner_Subp); |
| 10814 |
end if; |
| 10815 |
|
| 10816 |
if In_Same_Source_Unit (Subp, Inner_Subp) then |
| 10817 |
Set_Inline_Flags (Inner_Subp); |
| 10818 |
|
| 10819 |
if Present (Parent (Inner_Subp)) then |
| 10820 |
Decl := Parent (Parent (Inner_Subp)); |
| 10821 |
else |
| 10822 |
Decl := Empty; |
| 10823 |
end if; |
| 10824 |
|
| 10825 |
if Nkind (Decl) = N_Subprogram_Declaration |
| 10826 |
and then Present (Corresponding_Body (Decl)) |
| 10827 |
then |
| 10828 |
Set_Inline_Flags (Corresponding_Body (Decl)); |
| 10829 |
|
| 10830 |
elsif Is_Generic_Instance (Subp) |
| 10831 |
and then Comes_From_Source (Subp) |
| 10832 |
then |
| 10833 |
-- Indicate that the body needs to be created for |
| 10834 |
-- inlining subsequent calls. The instantiation node |
| 10835 |
-- follows the declaration of the wrapper package |
| 10836 |
-- created for it. The subprogram that requires the |
| 10837 |
-- body is the anonymous one in the wrapper package. |
| 10838 |
|
| 10839 |
if Scope (Subp) /= Standard_Standard |
| 10840 |
and then |
| 10841 |
Need_Subprogram_Instance_Body |
| 10842 |
(Next (Unit_Declaration_Node |
| 10843 |
(Scope (Alias (Subp)))), Subp) |
| 10844 |
then |
| 10845 |
null; |
| 10846 |
end if; |
| 10847 |
|
| 10848 |
-- Inline is a program unit pragma (RM 10.1.5) and cannot |
| 10849 |
-- appear in a formal part to apply to a formal subprogram. |
| 10850 |
-- Do not apply check within an instance or a formal package |
| 10851 |
-- the test will have been applied to the original generic. |
| 10852 |
|
| 10853 |
elsif Nkind (Decl) in N_Formal_Subprogram_Declaration |
| 10854 |
and then In_Same_List (Decl, N) |
| 10855 |
and then not In_Instance |
| 10856 |
then |
| 10857 |
Error_Msg_N |
| 10858 |
("Inline cannot apply to a formal subprogram", N); |
| 10859 |
end if; |
| 10860 |
end if; |
| 10861 |
|
| 10862 |
Applies := True; |
| 10863 |
|
| 10864 |
-- For a generic subprogram set flag as well, for use at the point |
| 10865 |
-- of instantiation, to determine whether the body should be |
| 10866 |
-- generated. |
| 10867 |
|
| 10868 |
elsif Is_Generic_Subprogram (Subp) then |
| 10869 |
Set_Inline_Flags (Subp); |
| 10870 |
Applies := True; |
| 10871 |
|
| 10872 |
-- Literals are by definition inlined |
| 10873 |
|
| 10874 |
elsif Kind = E_Enumeration_Literal then |
| 10875 |
null; |
| 10876 |
|
| 10877 |
-- Anything else is an error |
| 10878 |
|
| 10879 |
else |
| 10880 |
Error_Pragma_Arg |
| 10881 |
("expect subprogram name for pragma%", Assoc); |
| 10882 |
end if; |
| 10883 |
end Make_Inline; |
| 10884 |
|
| 10885 |
---------------------- |
| 10886 |
-- Set_Inline_Flags -- |
| 10887 |
---------------------- |
| 10888 |
|
| 10889 |
procedure Set_Inline_Flags (Subp : Entity_Id) is |
| 10890 |
begin |
| 10891 |
-- First set the Has_Pragma_XXX flags and issue the appropriate |
| 10892 |
-- errors and warnings for suspicious combinations. |
| 10893 |
|
| 10894 |
if Prag_Id = Pragma_No_Inline then |
| 10895 |
if Has_Pragma_Inline_Always (Subp) then |
| 10896 |
Error_Msg_N |
| 10897 |
("Inline_Always and No_Inline are mutually exclusive", N); |
| 10898 |
elsif Has_Pragma_Inline (Subp) then |
| 10899 |
Error_Msg_NE |
| 10900 |
("Inline and No_Inline both specified for& ??", |
| 10901 |
N, Entity (Subp_Id)); |
| 10902 |
end if; |
| 10903 |
|
| 10904 |
Set_Has_Pragma_No_Inline (Subp); |
| 10905 |
else |
| 10906 |
if Prag_Id = Pragma_Inline_Always then |
| 10907 |
if Has_Pragma_No_Inline (Subp) then |
| 10908 |
Error_Msg_N |
| 10909 |
("Inline_Always and No_Inline are mutually exclusive", |
| 10910 |
N); |
| 10911 |
end if; |
| 10912 |
|
| 10913 |
Set_Has_Pragma_Inline_Always (Subp); |
| 10914 |
else |
| 10915 |
if Has_Pragma_No_Inline (Subp) then |
| 10916 |
Error_Msg_NE |
| 10917 |
("Inline and No_Inline both specified for& ??", |
| 10918 |
N, Entity (Subp_Id)); |
| 10919 |
end if; |
| 10920 |
end if; |
| 10921 |
|
| 10922 |
Set_Has_Pragma_Inline (Subp); |
| 10923 |
end if; |
| 10924 |
|
| 10925 |
-- Then adjust the Is_Inlined flag. It can never be set if the |
| 10926 |
-- subprogram is subject to pragma No_Inline. |
| 10927 |
|
| 10928 |
case Status is |
| 10929 |
when Suppressed => |
| 10930 |
Set_Is_Inlined (Subp, False); |
| 10931 |
|
| 10932 |
when Disabled => |
| 10933 |
null; |
| 10934 |
|
| 10935 |
when Enabled => |
| 10936 |
if not Has_Pragma_No_Inline (Subp) then |
| 10937 |
Set_Is_Inlined (Subp, True); |
| 10938 |
end if; |
| 10939 |
end case; |
| 10940 |
|
| 10941 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 10942 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 10943 |
|
| 10944 |
Mark_Ghost_Pragma (N, Subp); |
| 10945 |
|
| 10946 |
-- Capture the entity of the first Ghost subprogram being |
| 10947 |
-- processed for error detection purposes. |
| 10948 |
|
| 10949 |
if Is_Ghost_Entity (Subp) then |
| 10950 |
if No (Ghost_Id) then |
| 10951 |
Ghost_Id := Subp; |
| 10952 |
end if; |
| 10953 |
|
| 10954 |
-- Otherwise the subprogram is non-Ghost. It is illegal to mix |
| 10955 |
-- references to Ghost and non-Ghost entities (SPARK RM 6.9). |
| 10956 |
|
| 10957 |
elsif Present (Ghost_Id) and then not Ghost_Error_Posted then |
| 10958 |
Ghost_Error_Posted := True; |
| 10959 |
|
| 10960 |
Error_Msg_Name_1 := Pname; |
| 10961 |
Error_Msg_N |
| 10962 |
("pragma % cannot mention ghost and non-ghost subprograms", |
| 10963 |
N); |
| 10964 |
|
| 10965 |
Error_Msg_Sloc := Sloc (Ghost_Id); |
| 10966 |
Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id); |
| 10967 |
|
| 10968 |
Error_Msg_Sloc := Sloc (Subp); |
| 10969 |
Error_Msg_NE ("\& # declared as non-ghost", N, Subp); |
| 10970 |
end if; |
| 10971 |
end Set_Inline_Flags; |
| 10972 |
|
| 10973 |
-- Start of processing for Process_Inline |
| 10974 |
|
| 10975 |
begin |
| 10976 |
-- An inlined subprogram may grant access to its private enclosing |
| 10977 |
-- context depending on the placement of its body. From elaboration |
| 10978 |
-- point of view, the flow of execution may enter this private |
| 10979 |
-- context, and then reach an external unit, thus producing a |
| 10980 |
-- dependency on that external unit. For such a path to be properly |
| 10981 |
-- discovered and encoded in the ALI file of the main unit, let the |
| 10982 |
-- ABE mechanism process the body of the main unit, and encode all |
| 10983 |
-- relevant invocation constructs and the relations between them. |
| 10984 |
|
| 10985 |
Mark_Save_Invocation_Graph_Of_Body; |
| 10986 |
|
| 10987 |
Check_No_Identifiers; |
| 10988 |
Check_At_Least_N_Arguments (1); |
| 10989 |
|
| 10990 |
if Status = Enabled then |
| 10991 |
Inline_Processing_Required := True; |
| 10992 |
end if; |
| 10993 |
|
| 10994 |
Assoc := Arg1; |
| 10995 |
while Present (Assoc) loop |
| 10996 |
Subp_Id := Get_Pragma_Arg (Assoc); |
| 10997 |
Analyze (Subp_Id); |
| 10998 |
Applies := False; |
| 10999 |
|
| 11000 |
if Is_Entity_Name (Subp_Id) then |
| 11001 |
Subp := Entity (Subp_Id); |
| 11002 |
|
| 11003 |
if Subp = Any_Id then |
| 11004 |
|
| 11005 |
-- If previous error, avoid cascaded errors |
| 11006 |
|
| 11007 |
Check_Error_Detected; |
| 11008 |
Applies := True; |
| 11009 |
|
| 11010 |
else |
| 11011 |
-- Check for RM 13.1(9.2/4): If a [...] aspect_specification |
| 11012 |
-- is given that directly specifies an aspect of an entity, |
| 11013 |
-- then it is illegal to give another [...] |
| 11014 |
-- aspect_specification that directly specifies the same |
| 11015 |
-- aspect of the entity. |
| 11016 |
-- We only check Subp directly as per "directly specifies" |
| 11017 |
-- above and because the case of pragma Inline is really |
| 11018 |
-- special given its pre aspect usage. |
| 11019 |
|
| 11020 |
Check_Duplicate_Pragma (Subp); |
| 11021 |
Record_Rep_Item (Subp, N); |
| 11022 |
|
| 11023 |
Make_Inline (Subp); |
| 11024 |
|
| 11025 |
-- For the pragma case, climb homonym chain. This is |
| 11026 |
-- what implements allowing the pragma in the renaming |
| 11027 |
-- case, with the result applying to the ancestors, and |
| 11028 |
-- also allows Inline to apply to all previous homonyms. |
| 11029 |
|
| 11030 |
if not From_Aspect_Specification (N) then |
| 11031 |
while Present (Homonym (Subp)) |
| 11032 |
and then Scope (Homonym (Subp)) = Current_Scope |
| 11033 |
loop |
| 11034 |
Subp := Homonym (Subp); |
| 11035 |
Make_Inline (Subp); |
| 11036 |
end loop; |
| 11037 |
end if; |
| 11038 |
end if; |
| 11039 |
end if; |
| 11040 |
|
| 11041 |
if not Applies then |
| 11042 |
Error_Pragma_Arg ("inappropriate argument for pragma%", Assoc); |
| 11043 |
end if; |
| 11044 |
|
| 11045 |
Next (Assoc); |
| 11046 |
end loop; |
| 11047 |
|
| 11048 |
-- If the context is a package declaration, the pragma indicates |
| 11049 |
-- that inlining will require the presence of the corresponding |
| 11050 |
-- body. (this may be further refined). |
| 11051 |
|
| 11052 |
if not In_Instance |
| 11053 |
and then Nkind (Unit (Cunit (Current_Sem_Unit))) = |
| 11054 |
N_Package_Declaration |
| 11055 |
then |
| 11056 |
Set_Body_Needed_For_Inlining (Cunit_Entity (Current_Sem_Unit)); |
| 11057 |
end if; |
| 11058 |
end Process_Inline; |
| 11059 |
|
| 11060 |
---------------------------- |
| 11061 |
-- Process_Interface_Name -- |
| 11062 |
---------------------------- |
| 11063 |
|
| 11064 |
procedure Process_Interface_Name |
| 11065 |
(Subprogram_Def : Entity_Id; |
| 11066 |
Ext_Arg : Node_Id; |
| 11067 |
Link_Arg : Node_Id; |
| 11068 |
Prag : Node_Id) |
| 11069 |
is |
| 11070 |
Ext_Nam : Node_Id; |
| 11071 |
Link_Nam : Node_Id; |
| 11072 |
String_Val : String_Id; |
| 11073 |
|
| 11074 |
procedure Check_Form_Of_Interface_Name (SN : Node_Id); |
| 11075 |
-- SN is a string literal node for an interface name. This routine |
| 11076 |
-- performs some minimal checks that the name is reasonable. In |
| 11077 |
-- particular that no spaces or other obviously incorrect characters |
| 11078 |
-- appear. This is only a warning, since any characters are allowed. |
| 11079 |
|
| 11080 |
---------------------------------- |
| 11081 |
-- Check_Form_Of_Interface_Name -- |
| 11082 |
---------------------------------- |
| 11083 |
|
| 11084 |
procedure Check_Form_Of_Interface_Name (SN : Node_Id) is |
| 11085 |
S : constant String_Id := Strval (Expr_Value_S (SN)); |
| 11086 |
SL : constant Nat := String_Length (S); |
| 11087 |
C : Char_Code; |
| 11088 |
|
| 11089 |
begin |
| 11090 |
if SL = 0 then |
| 11091 |
Error_Msg_N ("interface name cannot be null string", SN); |
| 11092 |
end if; |
| 11093 |
|
| 11094 |
for J in 1 .. SL loop |
| 11095 |
C := Get_String_Char (S, J); |
| 11096 |
|
| 11097 |
-- Look for dubious character and issue unconditional warning. |
| 11098 |
-- Definitely dubious if not in character range. |
| 11099 |
|
| 11100 |
if not In_Character_Range (C) |
| 11101 |
|
| 11102 |
-- Commas, spaces and (back)slashes are dubious |
| 11103 |
|
| 11104 |
or else Get_Character (C) = ',' |
| 11105 |
or else Get_Character (C) = '\' |
| 11106 |
or else Get_Character (C) = ' ' |
| 11107 |
or else Get_Character (C) = '/' |
| 11108 |
then |
| 11109 |
Error_Msg |
| 11110 |
("??interface name contains illegal character", |
| 11111 |
Sloc (SN) + Source_Ptr (J)); |
| 11112 |
end if; |
| 11113 |
end loop; |
| 11114 |
end Check_Form_Of_Interface_Name; |
| 11115 |
|
| 11116 |
-- Start of processing for Process_Interface_Name |
| 11117 |
|
| 11118 |
begin |
| 11119 |
-- If we are looking at a pragma that comes from an aspect then it |
| 11120 |
-- needs to have its corresponding aspect argument expressions |
| 11121 |
-- analyzed in addition to the generated pragma so that aspects |
| 11122 |
-- within generic units get properly resolved. |
| 11123 |
|
| 11124 |
if Present (Prag) and then From_Aspect_Specification (Prag) then |
| 11125 |
declare |
| 11126 |
Asp : constant Node_Id := Corresponding_Aspect (Prag); |
| 11127 |
Dummy_1 : Node_Id; |
| 11128 |
Dummy_2 : Node_Id; |
| 11129 |
Dummy_3 : Node_Id; |
| 11130 |
EN : Node_Id; |
| 11131 |
LN : Node_Id; |
| 11132 |
|
| 11133 |
begin |
| 11134 |
-- Obtain all interfacing aspects used to construct the pragma |
| 11135 |
|
| 11136 |
Get_Interfacing_Aspects |
| 11137 |
(Asp, Dummy_1, EN, Dummy_2, Dummy_3, LN); |
| 11138 |
|
| 11139 |
-- Analyze the expression of aspect External_Name |
| 11140 |
|
| 11141 |
if Present (EN) then |
| 11142 |
Analyze (Expression (EN)); |
| 11143 |
end if; |
| 11144 |
|
| 11145 |
-- Analyze the expressio of aspect Link_Name |
| 11146 |
|
| 11147 |
if Present (LN) then |
| 11148 |
Analyze (Expression (LN)); |
| 11149 |
end if; |
| 11150 |
end; |
| 11151 |
end if; |
| 11152 |
|
| 11153 |
if No (Link_Arg) then |
| 11154 |
if No (Ext_Arg) then |
| 11155 |
return; |
| 11156 |
|
| 11157 |
elsif Chars (Ext_Arg) = Name_Link_Name then |
| 11158 |
Ext_Nam := Empty; |
| 11159 |
Link_Nam := Expression (Ext_Arg); |
| 11160 |
|
| 11161 |
else |
| 11162 |
Check_Optional_Identifier (Ext_Arg, Name_External_Name); |
| 11163 |
Ext_Nam := Expression (Ext_Arg); |
| 11164 |
Link_Nam := Empty; |
| 11165 |
end if; |
| 11166 |
|
| 11167 |
else |
| 11168 |
Check_Optional_Identifier (Ext_Arg, Name_External_Name); |
| 11169 |
Check_Optional_Identifier (Link_Arg, Name_Link_Name); |
| 11170 |
Ext_Nam := Expression (Ext_Arg); |
| 11171 |
Link_Nam := Expression (Link_Arg); |
| 11172 |
end if; |
| 11173 |
|
| 11174 |
-- Check expressions for external name and link name are static |
| 11175 |
|
| 11176 |
if Present (Ext_Nam) then |
| 11177 |
Check_Arg_Is_OK_Static_Expression (Ext_Nam, Standard_String); |
| 11178 |
Check_Form_Of_Interface_Name (Ext_Nam); |
| 11179 |
|
| 11180 |
-- Verify that external name is not the name of a local entity, |
| 11181 |
-- which would hide the imported one and could lead to run-time |
| 11182 |
-- surprises. The problem can only arise for entities declared in |
| 11183 |
-- a package body (otherwise the external name is fully qualified |
| 11184 |
-- and will not conflict). |
| 11185 |
|
| 11186 |
declare |
| 11187 |
Nam : Name_Id; |
| 11188 |
E : Entity_Id; |
| 11189 |
Par : Node_Id; |
| 11190 |
|
| 11191 |
begin |
| 11192 |
if Prag_Id = Pragma_Import then |
| 11193 |
Nam := String_To_Name (Strval (Expr_Value_S (Ext_Nam))); |
| 11194 |
E := Entity_Id (Get_Name_Table_Int (Nam)); |
| 11195 |
|
| 11196 |
if Nam /= Chars (Subprogram_Def) |
| 11197 |
and then Present (E) |
| 11198 |
and then not Is_Overloadable (E) |
| 11199 |
and then Is_Immediately_Visible (E) |
| 11200 |
and then not Is_Imported (E) |
| 11201 |
and then Ekind (Scope (E)) = E_Package |
| 11202 |
then |
| 11203 |
Par := Parent (E); |
| 11204 |
while Present (Par) loop |
| 11205 |
if Nkind (Par) = N_Package_Body then |
| 11206 |
Error_Msg_Sloc := Sloc (E); |
| 11207 |
Error_Msg_NE |
| 11208 |
("imported entity is hidden by & declared#", |
| 11209 |
Ext_Arg, E); |
| 11210 |
exit; |
| 11211 |
end if; |
| 11212 |
|
| 11213 |
Par := Parent (Par); |
| 11214 |
end loop; |
| 11215 |
end if; |
| 11216 |
end if; |
| 11217 |
end; |
| 11218 |
end if; |
| 11219 |
|
| 11220 |
if Present (Link_Nam) then |
| 11221 |
Check_Arg_Is_OK_Static_Expression (Link_Nam, Standard_String); |
| 11222 |
Check_Form_Of_Interface_Name (Link_Nam); |
| 11223 |
end if; |
| 11224 |
|
| 11225 |
-- If there is no link name, just set the external name |
| 11226 |
|
| 11227 |
if No (Link_Nam) then |
| 11228 |
Link_Nam := Adjust_External_Name_Case (Expr_Value_S (Ext_Nam)); |
| 11229 |
|
| 11230 |
-- For the Link_Name case, the given literal is preceded by an |
| 11231 |
-- asterisk, which indicates to GCC that the given name should be |
| 11232 |
-- taken literally, and in particular that no prepending of |
| 11233 |
-- underlines should occur, even in systems where this is the |
| 11234 |
-- normal default. |
| 11235 |
|
| 11236 |
else |
| 11237 |
Start_String; |
| 11238 |
Store_String_Char (Get_Char_Code ('*')); |
| 11239 |
String_Val := Strval (Expr_Value_S (Link_Nam)); |
| 11240 |
Store_String_Chars (String_Val); |
| 11241 |
Link_Nam := |
| 11242 |
Make_String_Literal (Sloc (Link_Nam), |
| 11243 |
Strval => End_String); |
| 11244 |
end if; |
| 11245 |
|
| 11246 |
-- Set the interface name. If the entity is a generic instance, use |
| 11247 |
-- its alias, which is the callable entity. |
| 11248 |
|
| 11249 |
if Is_Generic_Instance (Subprogram_Def) then |
| 11250 |
Set_Encoded_Interface_Name |
| 11251 |
(Alias (Get_Base_Subprogram (Subprogram_Def)), Link_Nam); |
| 11252 |
else |
| 11253 |
Set_Encoded_Interface_Name |
| 11254 |
(Get_Base_Subprogram (Subprogram_Def), Link_Nam); |
| 11255 |
end if; |
| 11256 |
|
| 11257 |
Check_Duplicated_Export_Name (Link_Nam); |
| 11258 |
end Process_Interface_Name; |
| 11259 |
|
| 11260 |
----------------------------------------- |
| 11261 |
-- Process_Interrupt_Or_Attach_Handler -- |
| 11262 |
----------------------------------------- |
| 11263 |
|
| 11264 |
procedure Process_Interrupt_Or_Attach_Handler is |
| 11265 |
Handler : constant Entity_Id := Entity (Get_Pragma_Arg (Arg1)); |
| 11266 |
Prot_Typ : constant Entity_Id := Scope (Handler); |
| 11267 |
|
| 11268 |
begin |
| 11269 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 11270 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 11271 |
|
| 11272 |
Mark_Ghost_Pragma (N, Handler); |
| 11273 |
Set_Is_Interrupt_Handler (Handler); |
| 11274 |
|
| 11275 |
pragma Assert (Ekind (Prot_Typ) = E_Protected_Type); |
| 11276 |
|
| 11277 |
Record_Rep_Item (Prot_Typ, N); |
| 11278 |
|
| 11279 |
-- Chain the pragma on the contract for completeness |
| 11280 |
|
| 11281 |
Add_Contract_Item (N, Handler); |
| 11282 |
end Process_Interrupt_Or_Attach_Handler; |
| 11283 |
|
| 11284 |
-------------------------------------------------- |
| 11285 |
-- Process_Restrictions_Or_Restriction_Warnings -- |
| 11286 |
-------------------------------------------------- |
| 11287 |
|
| 11288 |
-- Note: some of the simple identifier cases were handled in par-prag, |
| 11289 |
-- but it is harmless (and more straightforward) to simply handle all |
| 11290 |
-- cases here, even if it means we repeat a bit of work in some cases. |
| 11291 |
|
| 11292 |
procedure Process_Restrictions_Or_Restriction_Warnings |
| 11293 |
(Warn : Boolean) |
| 11294 |
is |
| 11295 |
Arg : Node_Id; |
| 11296 |
R_Id : Restriction_Id; |
| 11297 |
Id : Name_Id; |
| 11298 |
Expr : Node_Id; |
| 11299 |
Val : Uint; |
| 11300 |
|
| 11301 |
procedure Process_No_Specification_of_Aspect; |
| 11302 |
-- Process the No_Specification_of_Aspect restriction |
| 11303 |
|
| 11304 |
procedure Process_No_Use_Of_Attribute; |
| 11305 |
-- Process the No_Use_Of_Attribute restriction |
| 11306 |
|
| 11307 |
---------------------------------------- |
| 11308 |
-- Process_No_Specification_of_Aspect -- |
| 11309 |
---------------------------------------- |
| 11310 |
|
| 11311 |
procedure Process_No_Specification_of_Aspect is |
| 11312 |
Name : constant Name_Id := Chars (Expr); |
| 11313 |
begin |
| 11314 |
if Nkind (Expr) = N_Identifier |
| 11315 |
and then Is_Aspect_Id (Name) |
| 11316 |
then |
| 11317 |
Set_Restriction_No_Specification_Of_Aspect (Expr, Warn); |
| 11318 |
else |
| 11319 |
Bad_Aspect (Expr, Name, Warn => True); |
| 11320 |
|
| 11321 |
raise Pragma_Exit; |
| 11322 |
end if; |
| 11323 |
end Process_No_Specification_of_Aspect; |
| 11324 |
|
| 11325 |
--------------------------------- |
| 11326 |
-- Process_No_Use_Of_Attribute -- |
| 11327 |
--------------------------------- |
| 11328 |
|
| 11329 |
procedure Process_No_Use_Of_Attribute is |
| 11330 |
Name : constant Name_Id := Chars (Expr); |
| 11331 |
begin |
| 11332 |
if Nkind (Expr) = N_Identifier |
| 11333 |
and then Is_Attribute_Name (Name) |
| 11334 |
then |
| 11335 |
Set_Restriction_No_Use_Of_Attribute (Expr, Warn); |
| 11336 |
else |
| 11337 |
Bad_Attribute (Expr, Name, Warn => True); |
| 11338 |
end if; |
| 11339 |
|
| 11340 |
end Process_No_Use_Of_Attribute; |
| 11341 |
|
| 11342 |
-- Start of processing for Process_Restrictions_Or_Restriction_Warnings |
| 11343 |
|
| 11344 |
begin |
| 11345 |
-- Ignore all Restrictions pragmas in CodePeer mode |
| 11346 |
|
| 11347 |
if CodePeer_Mode then |
| 11348 |
return; |
| 11349 |
end if; |
| 11350 |
|
| 11351 |
Check_Ada_83_Warning; |
| 11352 |
Check_At_Least_N_Arguments (1); |
| 11353 |
Check_Valid_Configuration_Pragma; |
| 11354 |
|
| 11355 |
Arg := Arg1; |
| 11356 |
while Present (Arg) loop |
| 11357 |
Id := Chars (Arg); |
| 11358 |
Expr := Get_Pragma_Arg (Arg); |
| 11359 |
|
| 11360 |
-- Case of no restriction identifier present |
| 11361 |
|
| 11362 |
if Id = No_Name then |
| 11363 |
if Nkind (Expr) /= N_Identifier then |
| 11364 |
Error_Pragma_Arg |
| 11365 |
("invalid form for restriction", Arg); |
| 11366 |
end if; |
| 11367 |
|
| 11368 |
R_Id := |
| 11369 |
Get_Restriction_Id |
| 11370 |
(Process_Restriction_Synonyms (Expr)); |
| 11371 |
|
| 11372 |
if R_Id not in All_Boolean_Restrictions then |
| 11373 |
Error_Msg_Name_1 := Pname; |
| 11374 |
Error_Msg_N |
| 11375 |
("invalid restriction identifier&", Get_Pragma_Arg (Arg)); |
| 11376 |
|
| 11377 |
-- Check for possible misspelling |
| 11378 |
|
| 11379 |
for J in All_Restrictions loop |
| 11380 |
declare |
| 11381 |
Rnm : constant String := Restriction_Id'Image (J); |
| 11382 |
|
| 11383 |
begin |
| 11384 |
Name_Buffer (1 .. Rnm'Length) := Rnm; |
| 11385 |
Name_Len := Rnm'Length; |
| 11386 |
Set_Casing (All_Lower_Case); |
| 11387 |
|
| 11388 |
if Is_Bad_Spelling_Of (Chars (Expr), Name_Enter) then |
| 11389 |
Set_Casing |
| 11390 |
(Identifier_Casing |
| 11391 |
(Source_Index (Current_Sem_Unit))); |
| 11392 |
Error_Msg_String (1 .. Rnm'Length) := |
| 11393 |
Name_Buffer (1 .. Name_Len); |
| 11394 |
Error_Msg_Strlen := Rnm'Length; |
| 11395 |
Error_Msg_N -- CODEFIX |
| 11396 |
("\possible misspelling of ""~""", |
| 11397 |
Get_Pragma_Arg (Arg)); |
| 11398 |
exit; |
| 11399 |
end if; |
| 11400 |
end; |
| 11401 |
end loop; |
| 11402 |
|
| 11403 |
raise Pragma_Exit; |
| 11404 |
end if; |
| 11405 |
|
| 11406 |
if Implementation_Restriction (R_Id) then |
| 11407 |
Check_Restriction (No_Implementation_Restrictions, Arg); |
| 11408 |
end if; |
| 11409 |
|
| 11410 |
-- Special processing for No_Elaboration_Code restriction |
| 11411 |
|
| 11412 |
if R_Id = No_Elaboration_Code then |
| 11413 |
|
| 11414 |
-- Restriction is only recognized within a configuration |
| 11415 |
-- pragma file, or within a unit of the main extended |
| 11416 |
-- program. Note: the test for Main_Unit is needed to |
| 11417 |
-- properly include the case of configuration pragma files. |
| 11418 |
|
| 11419 |
if not (Current_Sem_Unit = Main_Unit |
| 11420 |
or else In_Extended_Main_Source_Unit (N)) |
| 11421 |
then |
| 11422 |
return; |
| 11423 |
|
| 11424 |
-- Don't allow in a subunit unless already specified in |
| 11425 |
-- body or spec. |
| 11426 |
|
| 11427 |
elsif Nkind (Parent (N)) = N_Compilation_Unit |
| 11428 |
and then Nkind (Unit (Parent (N))) = N_Subunit |
| 11429 |
and then not Restriction_Active (No_Elaboration_Code) |
| 11430 |
then |
| 11431 |
Error_Msg_N |
| 11432 |
("invalid specification of ""No_Elaboration_Code""", |
| 11433 |
N); |
| 11434 |
Error_Msg_N |
| 11435 |
("\restriction cannot be specified in a subunit", N); |
| 11436 |
Error_Msg_N |
| 11437 |
("\unless also specified in body or spec", N); |
| 11438 |
return; |
| 11439 |
|
| 11440 |
-- If we accept a No_Elaboration_Code restriction, then it |
| 11441 |
-- needs to be added to the configuration restriction set so |
| 11442 |
-- that we get proper application to other units in the main |
| 11443 |
-- extended source as required. |
| 11444 |
|
| 11445 |
else |
| 11446 |
Add_To_Config_Boolean_Restrictions (No_Elaboration_Code); |
| 11447 |
end if; |
| 11448 |
|
| 11449 |
-- Special processing for No_Dynamic_Accessibility_Checks to |
| 11450 |
-- disallow exclusive specification in a body or subunit. |
| 11451 |
|
| 11452 |
elsif R_Id = No_Dynamic_Accessibility_Checks |
| 11453 |
-- Check if the restriction is within configuration pragma |
| 11454 |
-- in a similar way to No_Elaboration_Code. |
| 11455 |
|
| 11456 |
and then not (Current_Sem_Unit = Main_Unit |
| 11457 |
or else In_Extended_Main_Source_Unit (N)) |
| 11458 |
|
| 11459 |
and then Nkind (Unit (Parent (N))) = N_Compilation_Unit |
| 11460 |
|
| 11461 |
and then (Nkind (Unit (Parent (N))) = N_Package_Body |
| 11462 |
or else Nkind (Unit (Parent (N))) = N_Subunit) |
| 11463 |
|
| 11464 |
and then not Restriction_Active |
| 11465 |
(No_Dynamic_Accessibility_Checks) |
| 11466 |
then |
| 11467 |
Error_Msg_N |
| 11468 |
("invalid specification of " & |
| 11469 |
"""No_Dynamic_Accessibility_Checks""", N); |
| 11470 |
|
| 11471 |
if Nkind (Unit (Parent (N))) = N_Package_Body then |
| 11472 |
Error_Msg_N |
| 11473 |
("\restriction cannot be specified in a package " & |
| 11474 |
"body", N); |
| 11475 |
|
| 11476 |
elsif Nkind (Unit (Parent (N))) = N_Subunit then |
| 11477 |
Error_Msg_N |
| 11478 |
("\restriction cannot be specified in a subunit", N); |
| 11479 |
end if; |
| 11480 |
|
| 11481 |
Error_Msg_N |
| 11482 |
("\unless also specified in spec", N); |
| 11483 |
|
| 11484 |
-- Special processing for No_Tasking restriction (not just a |
| 11485 |
-- warning) when it appears as a configuration pragma. |
| 11486 |
|
| 11487 |
elsif R_Id = No_Tasking |
| 11488 |
and then No (Cunit (Main_Unit)) |
| 11489 |
and then not Warn |
| 11490 |
then |
| 11491 |
Set_Global_No_Tasking; |
| 11492 |
end if; |
| 11493 |
|
| 11494 |
Set_Restriction (R_Id, N, Warn); |
| 11495 |
|
| 11496 |
if R_Id = No_Dynamic_CPU_Assignment |
| 11497 |
or else R_Id = No_Tasks_Unassigned_To_CPU |
| 11498 |
then |
| 11499 |
-- These imply No_Dependence => |
| 11500 |
-- "System.Multiprocessors.Dispatching_Domains". |
| 11501 |
-- This is not strictly what the AI says, but it eliminates |
| 11502 |
-- the need for run-time checks, which are undesirable in |
| 11503 |
-- this context. |
| 11504 |
|
| 11505 |
Set_Restriction_No_Dependence |
| 11506 |
(Sel_Comp |
| 11507 |
(Sel_Comp ("system", "multiprocessors", Loc), |
| 11508 |
"dispatching_domains"), |
| 11509 |
Warn); |
| 11510 |
end if; |
| 11511 |
|
| 11512 |
if R_Id = No_Tasks_Unassigned_To_CPU then |
| 11513 |
-- Likewise, imply No_Dynamic_CPU_Assignment |
| 11514 |
|
| 11515 |
Set_Restriction (No_Dynamic_CPU_Assignment, N, Warn); |
| 11516 |
end if; |
| 11517 |
|
| 11518 |
-- Check for obsolescent restrictions in Ada 2005 mode |
| 11519 |
|
| 11520 |
if not Warn |
| 11521 |
and then Ada_Version >= Ada_2005 |
| 11522 |
and then (R_Id = No_Asynchronous_Control |
| 11523 |
or else |
| 11524 |
R_Id = No_Unchecked_Deallocation |
| 11525 |
or else |
| 11526 |
R_Id = No_Unchecked_Conversion) |
| 11527 |
then |
| 11528 |
Check_Restriction (No_Obsolescent_Features, N); |
| 11529 |
end if; |
| 11530 |
|
| 11531 |
-- A very special case that must be processed here: pragma |
| 11532 |
-- Restrictions (No_Exceptions) turns off all run-time |
| 11533 |
-- checking. This is a bit dubious in terms of the formal |
| 11534 |
-- language definition, but it is what is intended by RM |
| 11535 |
-- H.4(12). Restriction_Warnings never affects generated code |
| 11536 |
-- so this is done only in the real restriction case. |
| 11537 |
|
| 11538 |
-- Atomic_Synchronization is not a real check, so it is not |
| 11539 |
-- affected by this processing). |
| 11540 |
|
| 11541 |
-- Ignore the effect of pragma Restrictions (No_Exceptions) on |
| 11542 |
-- run-time checks in CodePeer and GNATprove modes: we want to |
| 11543 |
-- generate checks for analysis purposes, as set respectively |
| 11544 |
-- by -gnatC and -gnatd.F |
| 11545 |
|
| 11546 |
if not Warn |
| 11547 |
and then not (CodePeer_Mode or GNATprove_Mode) |
| 11548 |
and then R_Id = No_Exceptions |
| 11549 |
then |
| 11550 |
for J in Scope_Suppress.Suppress'Range loop |
| 11551 |
if J /= Atomic_Synchronization then |
| 11552 |
Scope_Suppress.Suppress (J) := True; |
| 11553 |
end if; |
| 11554 |
end loop; |
| 11555 |
end if; |
| 11556 |
|
| 11557 |
-- Case of No_Dependence => unit-name. Note that the parser |
| 11558 |
-- already made the necessary entry in the No_Dependence table. |
| 11559 |
|
| 11560 |
elsif Id = Name_No_Dependence then |
| 11561 |
if not OK_No_Dependence_Unit_Name (Expr) then |
| 11562 |
raise Pragma_Exit; |
| 11563 |
end if; |
| 11564 |
|
| 11565 |
-- Case of No_Specification_Of_Aspect => aspect-identifier |
| 11566 |
|
| 11567 |
elsif Id = Name_No_Specification_Of_Aspect then |
| 11568 |
Process_No_Specification_of_Aspect; |
| 11569 |
|
| 11570 |
-- Case of No_Use_Of_Attribute => attribute-identifier |
| 11571 |
|
| 11572 |
elsif Id = Name_No_Use_Of_Attribute then |
| 11573 |
Process_No_Use_Of_Attribute; |
| 11574 |
|
| 11575 |
-- Case of No_Use_Of_Entity => fully-qualified-name |
| 11576 |
|
| 11577 |
elsif Id = Name_No_Use_Of_Entity then |
| 11578 |
|
| 11579 |
-- Restriction is only recognized within a configuration |
| 11580 |
-- pragma file, or within a unit of the main extended |
| 11581 |
-- program. Note: the test for Main_Unit is needed to |
| 11582 |
-- properly include the case of configuration pragma files. |
| 11583 |
|
| 11584 |
if Current_Sem_Unit = Main_Unit |
| 11585 |
or else In_Extended_Main_Source_Unit (N) |
| 11586 |
then |
| 11587 |
if not OK_No_Dependence_Unit_Name (Expr) then |
| 11588 |
Error_Msg_N ("wrong form for entity name", Expr); |
| 11589 |
else |
| 11590 |
Set_Restriction_No_Use_Of_Entity |
| 11591 |
(Expr, Warn, No_Profile); |
| 11592 |
end if; |
| 11593 |
end if; |
| 11594 |
|
| 11595 |
-- Case of No_Use_Of_Pragma => pragma-identifier |
| 11596 |
|
| 11597 |
elsif Id = Name_No_Use_Of_Pragma then |
| 11598 |
if Nkind (Expr) /= N_Identifier |
| 11599 |
or else not Is_Pragma_Name (Chars (Expr)) |
| 11600 |
then |
| 11601 |
Error_Msg_N ("unknown pragma name??", Expr); |
| 11602 |
else |
| 11603 |
Set_Restriction_No_Use_Of_Pragma (Expr, Warn); |
| 11604 |
end if; |
| 11605 |
|
| 11606 |
-- All other cases of restriction identifier present |
| 11607 |
|
| 11608 |
else |
| 11609 |
R_Id := Get_Restriction_Id (Process_Restriction_Synonyms (Arg)); |
| 11610 |
|
| 11611 |
if R_Id not in All_Parameter_Restrictions then |
| 11612 |
Error_Pragma_Arg |
| 11613 |
("invalid restriction parameter identifier", Arg); |
| 11614 |
end if; |
| 11615 |
|
| 11616 |
Analyze_And_Resolve (Expr, Any_Integer); |
| 11617 |
|
| 11618 |
if not Is_OK_Static_Expression (Expr) then |
| 11619 |
Flag_Non_Static_Expr |
| 11620 |
("value must be static expression!", Expr); |
| 11621 |
raise Pragma_Exit; |
| 11622 |
|
| 11623 |
elsif not Is_Integer_Type (Etype (Expr)) |
| 11624 |
or else Expr_Value (Expr) < 0 |
| 11625 |
then |
| 11626 |
Error_Pragma_Arg |
| 11627 |
("value must be non-negative integer", Arg); |
| 11628 |
end if; |
| 11629 |
|
| 11630 |
-- Restriction pragma is active |
| 11631 |
|
| 11632 |
Val := Expr_Value (Expr); |
| 11633 |
|
| 11634 |
if not UI_Is_In_Int_Range (Val) then |
| 11635 |
Error_Pragma_Arg |
| 11636 |
("pragma ignored, value too large??", Arg); |
| 11637 |
end if; |
| 11638 |
|
| 11639 |
Set_Restriction (R_Id, N, Warn, Integer (UI_To_Int (Val))); |
| 11640 |
end if; |
| 11641 |
|
| 11642 |
Next (Arg); |
| 11643 |
end loop; |
| 11644 |
end Process_Restrictions_Or_Restriction_Warnings; |
| 11645 |
|
| 11646 |
--------------------------------- |
| 11647 |
-- Process_Suppress_Unsuppress -- |
| 11648 |
--------------------------------- |
| 11649 |
|
| 11650 |
-- Note: this procedure makes entries in the check suppress data |
| 11651 |
-- structures managed by Sem. See spec of package Sem for full |
| 11652 |
-- details on how we handle recording of check suppression. |
| 11653 |
|
| 11654 |
procedure Process_Suppress_Unsuppress (Suppress_Case : Boolean) is |
| 11655 |
C : Check_Id; |
| 11656 |
E : Entity_Id; |
| 11657 |
E_Id : Node_Id; |
| 11658 |
|
| 11659 |
In_Package_Spec : constant Boolean := |
| 11660 |
Is_Package_Or_Generic_Package (Current_Scope) |
| 11661 |
and then not In_Package_Body (Current_Scope); |
| 11662 |
|
| 11663 |
procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id); |
| 11664 |
-- Used to suppress a single check on the given entity |
| 11665 |
|
| 11666 |
-------------------------------- |
| 11667 |
-- Suppress_Unsuppress_Echeck -- |
| 11668 |
-------------------------------- |
| 11669 |
|
| 11670 |
procedure Suppress_Unsuppress_Echeck (E : Entity_Id; C : Check_Id) is |
| 11671 |
begin |
| 11672 |
-- Check for error of trying to set atomic synchronization for |
| 11673 |
-- a non-atomic variable. |
| 11674 |
|
| 11675 |
if C = Atomic_Synchronization |
| 11676 |
and then not (Is_Atomic (E) or else Has_Atomic_Components (E)) |
| 11677 |
then |
| 11678 |
Error_Msg_N |
| 11679 |
("pragma & requires atomic type or variable", |
| 11680 |
Pragma_Identifier (Original_Node (N))); |
| 11681 |
end if; |
| 11682 |
|
| 11683 |
Set_Checks_May_Be_Suppressed (E); |
| 11684 |
|
| 11685 |
if In_Package_Spec then |
| 11686 |
Push_Global_Suppress_Stack_Entry |
| 11687 |
(Entity => E, |
| 11688 |
Check => C, |
| 11689 |
Suppress => Suppress_Case); |
| 11690 |
else |
| 11691 |
Push_Local_Suppress_Stack_Entry |
| 11692 |
(Entity => E, |
| 11693 |
Check => C, |
| 11694 |
Suppress => Suppress_Case); |
| 11695 |
end if; |
| 11696 |
|
| 11697 |
-- If this is a first subtype, and the base type is distinct, |
| 11698 |
-- then also set the suppress flags on the base type. |
| 11699 |
|
| 11700 |
if Is_First_Subtype (E) and then Etype (E) /= E then |
| 11701 |
Suppress_Unsuppress_Echeck (Etype (E), C); |
| 11702 |
end if; |
| 11703 |
end Suppress_Unsuppress_Echeck; |
| 11704 |
|
| 11705 |
-- Start of processing for Process_Suppress_Unsuppress |
| 11706 |
|
| 11707 |
begin |
| 11708 |
-- Ignore pragma Suppress/Unsuppress in CodePeer and GNATprove modes |
| 11709 |
-- on user code: we want to generate checks for analysis purposes, as |
| 11710 |
-- set respectively by -gnatC and -gnatd.F |
| 11711 |
|
| 11712 |
if Comes_From_Source (N) |
| 11713 |
and then (CodePeer_Mode or GNATprove_Mode) |
| 11714 |
then |
| 11715 |
return; |
| 11716 |
end if; |
| 11717 |
|
| 11718 |
-- Suppress/Unsuppress can appear as a configuration pragma, or in a |
| 11719 |
-- declarative part or a package spec (RM 11.5(5)). |
| 11720 |
|
| 11721 |
if not Is_Configuration_Pragma then |
| 11722 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 11723 |
end if; |
| 11724 |
|
| 11725 |
Check_At_Least_N_Arguments (1); |
| 11726 |
Check_At_Most_N_Arguments (2); |
| 11727 |
Check_No_Identifier (Arg1); |
| 11728 |
Check_Arg_Is_Identifier (Arg1); |
| 11729 |
|
| 11730 |
C := Get_Check_Id (Chars (Get_Pragma_Arg (Arg1))); |
| 11731 |
|
| 11732 |
if C = No_Check_Id then |
| 11733 |
Error_Pragma_Arg |
| 11734 |
("argument of pragma% is not valid check name", Arg1); |
| 11735 |
end if; |
| 11736 |
|
| 11737 |
-- Warn that suppress of Elaboration_Check has no effect in SPARK |
| 11738 |
|
| 11739 |
if C = Elaboration_Check |
| 11740 |
and then Suppress_Case |
| 11741 |
and then SPARK_Mode = On |
| 11742 |
then |
| 11743 |
Error_Pragma_Arg |
| 11744 |
("Suppress of Elaboration_Check ignored in SPARK??", |
| 11745 |
"\elaboration checking rules are statically enforced " |
| 11746 |
& "(SPARK RM 7.7)", Arg1); |
| 11747 |
end if; |
| 11748 |
|
| 11749 |
-- One-argument case |
| 11750 |
|
| 11751 |
if Arg_Count = 1 then |
| 11752 |
|
| 11753 |
-- Make an entry in the local scope suppress table. This is the |
| 11754 |
-- table that directly shows the current value of the scope |
| 11755 |
-- suppress check for any check id value. |
| 11756 |
|
| 11757 |
if C = All_Checks then |
| 11758 |
|
| 11759 |
-- For All_Checks, we set all specific predefined checks with |
| 11760 |
-- the exception of Elaboration_Check, which is handled |
| 11761 |
-- specially because of not wanting All_Checks to have the |
| 11762 |
-- effect of deactivating static elaboration order processing. |
| 11763 |
-- Atomic_Synchronization is also not affected, since this is |
| 11764 |
-- not a real check. |
| 11765 |
|
| 11766 |
for J in Scope_Suppress.Suppress'Range loop |
| 11767 |
if J not in Elaboration_Check | Atomic_Synchronization then |
| 11768 |
Scope_Suppress.Suppress (J) := Suppress_Case; |
| 11769 |
end if; |
| 11770 |
end loop; |
| 11771 |
|
| 11772 |
-- If not All_Checks, and predefined check, then set appropriate |
| 11773 |
-- scope entry. Note that we will set Elaboration_Check if this |
| 11774 |
-- is explicitly specified. |
| 11775 |
|
| 11776 |
elsif C in Predefined_Check_Id then |
| 11777 |
Scope_Suppress.Suppress (C) := Suppress_Case; |
| 11778 |
end if; |
| 11779 |
|
| 11780 |
-- Also push an entry in the local suppress stack |
| 11781 |
|
| 11782 |
Push_Local_Suppress_Stack_Entry |
| 11783 |
(Entity => Empty, |
| 11784 |
Check => C, |
| 11785 |
Suppress => Suppress_Case); |
| 11786 |
|
| 11787 |
-- Case of two arguments present, where the check is suppressed for |
| 11788 |
-- a specified entity (given as the second argument of the pragma) |
| 11789 |
|
| 11790 |
else |
| 11791 |
-- This is obsolescent in Ada 2005 mode |
| 11792 |
|
| 11793 |
if Ada_Version >= Ada_2005 then |
| 11794 |
Check_Restriction (No_Obsolescent_Features, Arg2); |
| 11795 |
end if; |
| 11796 |
|
| 11797 |
Check_Optional_Identifier (Arg2, Name_On); |
| 11798 |
E_Id := Get_Pragma_Arg (Arg2); |
| 11799 |
Analyze (E_Id); |
| 11800 |
|
| 11801 |
if not Is_Entity_Name (E_Id) then |
| 11802 |
Error_Pragma_Arg |
| 11803 |
("second argument of pragma% must be entity name", Arg2); |
| 11804 |
end if; |
| 11805 |
|
| 11806 |
E := Entity (E_Id); |
| 11807 |
|
| 11808 |
if E = Any_Id then |
| 11809 |
return; |
| 11810 |
end if; |
| 11811 |
|
| 11812 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 11813 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 11814 |
|
| 11815 |
Mark_Ghost_Pragma (N, E); |
| 11816 |
|
| 11817 |
-- Enforce RM 11.5(7) which requires that for a pragma that |
| 11818 |
-- appears within a package spec, the named entity must be |
| 11819 |
-- within the package spec. We allow the package name itself |
| 11820 |
-- to be mentioned since that makes sense, although it is not |
| 11821 |
-- strictly allowed by 11.5(7). |
| 11822 |
|
| 11823 |
if In_Package_Spec |
| 11824 |
and then E /= Current_Scope |
| 11825 |
and then Scope (E) /= Current_Scope |
| 11826 |
then |
| 11827 |
Error_Pragma_Arg |
| 11828 |
("entity in pragma% is not in package spec (RM 11.5(7))", |
| 11829 |
Arg2); |
| 11830 |
end if; |
| 11831 |
|
| 11832 |
-- Loop through homonyms. As noted below, in the case of a package |
| 11833 |
-- spec, only homonyms within the package spec are considered. |
| 11834 |
|
| 11835 |
loop |
| 11836 |
Suppress_Unsuppress_Echeck (E, C); |
| 11837 |
|
| 11838 |
if Is_Generic_Instance (E) |
| 11839 |
and then Is_Subprogram (E) |
| 11840 |
and then Present (Alias (E)) |
| 11841 |
then |
| 11842 |
Suppress_Unsuppress_Echeck (Alias (E), C); |
| 11843 |
end if; |
| 11844 |
|
| 11845 |
-- Move to next homonym if not aspect spec case |
| 11846 |
|
| 11847 |
exit when From_Aspect_Specification (N); |
| 11848 |
E := Homonym (E); |
| 11849 |
exit when No (E); |
| 11850 |
|
| 11851 |
-- If we are within a package specification, the pragma only |
| 11852 |
-- applies to homonyms in the same scope. |
| 11853 |
|
| 11854 |
exit when In_Package_Spec |
| 11855 |
and then Scope (E) /= Current_Scope; |
| 11856 |
end loop; |
| 11857 |
end if; |
| 11858 |
end Process_Suppress_Unsuppress; |
| 11859 |
|
| 11860 |
------------------------------- |
| 11861 |
-- Record_Independence_Check -- |
| 11862 |
------------------------------- |
| 11863 |
|
| 11864 |
procedure Record_Independence_Check (N : Node_Id; E : Entity_Id) is |
| 11865 |
pragma Unreferenced (N, E); |
| 11866 |
begin |
| 11867 |
-- For GCC back ends the validation is done a priori. This code is |
| 11868 |
-- dead, but might be useful in the future. |
| 11869 |
|
| 11870 |
-- if not AAMP_On_Target then |
| 11871 |
-- return; |
| 11872 |
-- end if; |
| 11873 |
|
| 11874 |
-- Independence_Checks.Append ((N, E)); |
| 11875 |
|
| 11876 |
return; |
| 11877 |
end Record_Independence_Check; |
| 11878 |
|
| 11879 |
------------------ |
| 11880 |
-- Set_Exported -- |
| 11881 |
------------------ |
| 11882 |
|
| 11883 |
procedure Set_Exported (E : Entity_Id; Arg : Node_Id) is |
| 11884 |
begin |
| 11885 |
if Is_Imported (E) then |
| 11886 |
Error_Pragma_Arg |
| 11887 |
("cannot export entity& that was previously imported", Arg); |
| 11888 |
|
| 11889 |
elsif Present (Address_Clause (E)) |
| 11890 |
and then not Relaxed_RM_Semantics |
| 11891 |
then |
| 11892 |
Error_Pragma_Arg |
| 11893 |
("cannot export entity& that has an address clause", Arg); |
| 11894 |
end if; |
| 11895 |
|
| 11896 |
Set_Is_Exported (E); |
| 11897 |
|
| 11898 |
-- Generate a reference for entity explicitly, because the |
| 11899 |
-- identifier may be overloaded and name resolution will not |
| 11900 |
-- generate one. |
| 11901 |
|
| 11902 |
Generate_Reference (E, Arg); |
| 11903 |
|
| 11904 |
-- Deal with exporting non-library level entity |
| 11905 |
|
| 11906 |
if not Is_Library_Level_Entity (E) then |
| 11907 |
|
| 11908 |
-- Not allowed at all for subprograms |
| 11909 |
|
| 11910 |
if Is_Subprogram (E) then |
| 11911 |
Error_Pragma_Arg ("local subprogram& cannot be exported", Arg); |
| 11912 |
|
| 11913 |
-- Otherwise set public and statically allocated |
| 11914 |
|
| 11915 |
else |
| 11916 |
Set_Is_Public (E); |
| 11917 |
Set_Is_Statically_Allocated (E); |
| 11918 |
|
| 11919 |
-- Warn if the corresponding W flag is set |
| 11920 |
|
| 11921 |
if Warn_On_Export_Import |
| 11922 |
|
| 11923 |
-- Only do this for something that was in the source. Not |
| 11924 |
-- clear if this can be False now (there used for sure to be |
| 11925 |
-- cases on some systems where it was False), but anyway the |
| 11926 |
-- test is harmless if not needed, so it is retained. |
| 11927 |
|
| 11928 |
and then Comes_From_Source (Arg) |
| 11929 |
then |
| 11930 |
Error_Msg_NE |
| 11931 |
("?x?& has been made static as a result of Export", |
| 11932 |
Arg, E); |
| 11933 |
Error_Msg_N |
| 11934 |
("\?x?this usage is non-standard and non-portable", |
| 11935 |
Arg); |
| 11936 |
end if; |
| 11937 |
end if; |
| 11938 |
end if; |
| 11939 |
|
| 11940 |
if Warn_On_Export_Import and Inside_A_Generic then |
| 11941 |
Error_Msg_NE |
| 11942 |
("all instances of& will have the same external name?x?", |
| 11943 |
Arg, E); |
| 11944 |
end if; |
| 11945 |
end Set_Exported; |
| 11946 |
|
| 11947 |
---------------------------------------------- |
| 11948 |
-- Set_Extended_Import_Export_External_Name -- |
| 11949 |
---------------------------------------------- |
| 11950 |
|
| 11951 |
procedure Set_Extended_Import_Export_External_Name |
| 11952 |
(Internal_Ent : Entity_Id; |
| 11953 |
Arg_External : Node_Id) |
| 11954 |
is |
| 11955 |
Old_Name : constant Node_Id := Interface_Name (Internal_Ent); |
| 11956 |
New_Name : Node_Id; |
| 11957 |
|
| 11958 |
begin |
| 11959 |
if No (Arg_External) then |
| 11960 |
return; |
| 11961 |
end if; |
| 11962 |
|
| 11963 |
Check_Arg_Is_External_Name (Arg_External); |
| 11964 |
|
| 11965 |
if Nkind (Arg_External) = N_String_Literal then |
| 11966 |
if String_Length (Strval (Arg_External)) = 0 then |
| 11967 |
return; |
| 11968 |
else |
| 11969 |
New_Name := Adjust_External_Name_Case (Arg_External); |
| 11970 |
end if; |
| 11971 |
|
| 11972 |
elsif Nkind (Arg_External) = N_Identifier then |
| 11973 |
New_Name := Get_Default_External_Name (Arg_External); |
| 11974 |
|
| 11975 |
-- Check_Arg_Is_External_Name should let through only identifiers and |
| 11976 |
-- string literals or static string expressions (which are folded to |
| 11977 |
-- string literals). |
| 11978 |
|
| 11979 |
else |
| 11980 |
raise Program_Error; |
| 11981 |
end if; |
| 11982 |
|
| 11983 |
-- If we already have an external name set (by a prior normal Import |
| 11984 |
-- or Export pragma), then the external names must match |
| 11985 |
|
| 11986 |
if Present (Interface_Name (Internal_Ent)) then |
| 11987 |
|
| 11988 |
-- Ignore mismatching names in CodePeer mode, to support some |
| 11989 |
-- old compilers which would export the same procedure under |
| 11990 |
-- different names, e.g: |
| 11991 |
-- procedure P; |
| 11992 |
-- pragma Export_Procedure (P, "a"); |
| 11993 |
-- pragma Export_Procedure (P, "b"); |
| 11994 |
|
| 11995 |
if CodePeer_Mode then |
| 11996 |
return; |
| 11997 |
end if; |
| 11998 |
|
| 11999 |
Check_Matching_Internal_Names : declare |
| 12000 |
S1 : constant String_Id := Strval (Old_Name); |
| 12001 |
S2 : constant String_Id := Strval (New_Name); |
| 12002 |
|
| 12003 |
procedure Mismatch; |
| 12004 |
pragma No_Return (Mismatch); |
| 12005 |
-- Called if names do not match |
| 12006 |
|
| 12007 |
-------------- |
| 12008 |
-- Mismatch -- |
| 12009 |
-------------- |
| 12010 |
|
| 12011 |
procedure Mismatch is |
| 12012 |
begin |
| 12013 |
Error_Msg_Sloc := Sloc (Old_Name); |
| 12014 |
Error_Pragma_Arg |
| 12015 |
("external name does not match that given #", |
| 12016 |
Arg_External); |
| 12017 |
end Mismatch; |
| 12018 |
|
| 12019 |
-- Start of processing for Check_Matching_Internal_Names |
| 12020 |
|
| 12021 |
begin |
| 12022 |
if String_Length (S1) /= String_Length (S2) then |
| 12023 |
Mismatch; |
| 12024 |
|
| 12025 |
else |
| 12026 |
for J in 1 .. String_Length (S1) loop |
| 12027 |
if Get_String_Char (S1, J) /= Get_String_Char (S2, J) then |
| 12028 |
Mismatch; |
| 12029 |
end if; |
| 12030 |
end loop; |
| 12031 |
end if; |
| 12032 |
end Check_Matching_Internal_Names; |
| 12033 |
|
| 12034 |
-- Otherwise set the given name |
| 12035 |
|
| 12036 |
else |
| 12037 |
Set_Encoded_Interface_Name (Internal_Ent, New_Name); |
| 12038 |
Check_Duplicated_Export_Name (New_Name); |
| 12039 |
end if; |
| 12040 |
end Set_Extended_Import_Export_External_Name; |
| 12041 |
|
| 12042 |
------------------ |
| 12043 |
-- Set_Imported -- |
| 12044 |
------------------ |
| 12045 |
|
| 12046 |
procedure Set_Imported (E : Entity_Id) is |
| 12047 |
begin |
| 12048 |
-- Error message if already imported or exported |
| 12049 |
|
| 12050 |
if Is_Exported (E) or else Is_Imported (E) then |
| 12051 |
|
| 12052 |
-- Error if being set Exported twice |
| 12053 |
|
| 12054 |
if Is_Exported (E) then |
| 12055 |
Error_Msg_NE ("entity& was previously exported", N, E); |
| 12056 |
|
| 12057 |
-- Ignore error in CodePeer mode where we treat all imported |
| 12058 |
-- subprograms as unknown. |
| 12059 |
|
| 12060 |
elsif CodePeer_Mode then |
| 12061 |
goto OK; |
| 12062 |
|
| 12063 |
-- OK if Import/Interface case |
| 12064 |
|
| 12065 |
elsif Import_Interface_Present (N) then |
| 12066 |
goto OK; |
| 12067 |
|
| 12068 |
-- Error if being set Imported twice |
| 12069 |
|
| 12070 |
else |
| 12071 |
Error_Msg_NE ("entity& was previously imported", N, E); |
| 12072 |
end if; |
| 12073 |
|
| 12074 |
Error_Msg_Name_1 := Pname; |
| 12075 |
Error_Msg_N |
| 12076 |
("\(pragma% applies to all previous entities)", N); |
| 12077 |
|
| 12078 |
Error_Msg_Sloc := Sloc (E); |
| 12079 |
Error_Msg_NE ("\import not allowed for& declared#", N, E); |
| 12080 |
|
| 12081 |
-- Here if not previously imported or exported, OK to import |
| 12082 |
|
| 12083 |
else |
| 12084 |
Set_Is_Imported (E); |
| 12085 |
|
| 12086 |
-- For subprogram, set Import_Pragma field |
| 12087 |
|
| 12088 |
if Is_Subprogram (E) then |
| 12089 |
Set_Import_Pragma (E, N); |
| 12090 |
end if; |
| 12091 |
|
| 12092 |
-- If the entity is an object that is not at the library level, |
| 12093 |
-- then it is statically allocated. We do not worry about objects |
| 12094 |
-- with address clauses in this context since they are not really |
| 12095 |
-- imported in the linker sense. |
| 12096 |
|
| 12097 |
if Is_Object (E) |
| 12098 |
and then not Is_Library_Level_Entity (E) |
| 12099 |
and then No (Address_Clause (E)) |
| 12100 |
then |
| 12101 |
Set_Is_Statically_Allocated (E); |
| 12102 |
end if; |
| 12103 |
end if; |
| 12104 |
|
| 12105 |
<<OK>> null; |
| 12106 |
end Set_Imported; |
| 12107 |
|
| 12108 |
------------------------- |
| 12109 |
-- Set_Mechanism_Value -- |
| 12110 |
------------------------- |
| 12111 |
|
| 12112 |
-- Note: the mechanism name has not been analyzed (and cannot indeed be |
| 12113 |
-- analyzed, since it is semantic nonsense), so we get it in the exact |
| 12114 |
-- form created by the parser. |
| 12115 |
|
| 12116 |
procedure Set_Mechanism_Value (Ent : Entity_Id; Mech_Name : Node_Id) is |
| 12117 |
procedure Bad_Mechanism; |
| 12118 |
pragma No_Return (Bad_Mechanism); |
| 12119 |
-- Signal bad mechanism name |
| 12120 |
|
| 12121 |
------------------- |
| 12122 |
-- Bad_Mechanism -- |
| 12123 |
------------------- |
| 12124 |
|
| 12125 |
procedure Bad_Mechanism is |
| 12126 |
begin |
| 12127 |
Error_Pragma_Arg ("unrecognized mechanism name", Mech_Name); |
| 12128 |
end Bad_Mechanism; |
| 12129 |
|
| 12130 |
-- Start of processing for Set_Mechanism_Value |
| 12131 |
|
| 12132 |
begin |
| 12133 |
if Mechanism (Ent) /= Default_Mechanism then |
| 12134 |
Error_Msg_NE |
| 12135 |
("mechanism for & has already been set", Mech_Name, Ent); |
| 12136 |
end if; |
| 12137 |
|
| 12138 |
-- MECHANISM_NAME ::= value | reference |
| 12139 |
|
| 12140 |
if Nkind (Mech_Name) = N_Identifier then |
| 12141 |
if Chars (Mech_Name) = Name_Value then |
| 12142 |
Set_Mechanism (Ent, By_Copy); |
| 12143 |
return; |
| 12144 |
|
| 12145 |
elsif Chars (Mech_Name) = Name_Reference then |
| 12146 |
Set_Mechanism (Ent, By_Reference); |
| 12147 |
return; |
| 12148 |
|
| 12149 |
elsif Chars (Mech_Name) = Name_Copy then |
| 12150 |
Error_Pragma_Arg |
| 12151 |
("bad mechanism name, Value assumed", Mech_Name); |
| 12152 |
|
| 12153 |
else |
| 12154 |
Bad_Mechanism; |
| 12155 |
end if; |
| 12156 |
|
| 12157 |
else |
| 12158 |
Bad_Mechanism; |
| 12159 |
end if; |
| 12160 |
end Set_Mechanism_Value; |
| 12161 |
|
| 12162 |
-------------------------- |
| 12163 |
-- Set_Rational_Profile -- |
| 12164 |
-------------------------- |
| 12165 |
|
| 12166 |
-- The Rational profile includes Implicit_Packing, Use_Vads_Size, and |
| 12167 |
-- extension to the semantics of renaming declarations. |
| 12168 |
|
| 12169 |
procedure Set_Rational_Profile is |
| 12170 |
begin |
| 12171 |
Implicit_Packing := True; |
| 12172 |
Overriding_Renamings := True; |
| 12173 |
Use_VADS_Size := True; |
| 12174 |
end Set_Rational_Profile; |
| 12175 |
|
| 12176 |
--------------------------- |
| 12177 |
-- Set_Ravenscar_Profile -- |
| 12178 |
--------------------------- |
| 12179 |
|
| 12180 |
-- The tasks to be done here are |
| 12181 |
|
| 12182 |
-- Set required policies |
| 12183 |
|
| 12184 |
-- pragma Task_Dispatching_Policy (FIFO_Within_Priorities) |
| 12185 |
-- (For Ravenscar, Jorvik, and GNAT_Extended_Ravenscar profiles) |
| 12186 |
-- pragma Task_Dispatching_Policy (EDF_Across_Priorities) |
| 12187 |
-- (For GNAT_Ravenscar_EDF profile) |
| 12188 |
-- pragma Locking_Policy (Ceiling_Locking) |
| 12189 |
|
| 12190 |
-- Set Detect_Blocking mode |
| 12191 |
|
| 12192 |
-- Set required restrictions (see System.Rident for detailed list) |
| 12193 |
|
| 12194 |
-- Set the No_Dependence rules |
| 12195 |
-- No_Dependence => Ada.Asynchronous_Task_Control |
| 12196 |
-- No_Dependence => Ada.Calendar |
| 12197 |
-- No_Dependence => Ada.Execution_Time.Group_Budget |
| 12198 |
-- No_Dependence => Ada.Execution_Time.Timers |
| 12199 |
-- No_Dependence => Ada.Task_Attributes |
| 12200 |
-- No_Dependence => System.Multiprocessors.Dispatching_Domains |
| 12201 |
|
| 12202 |
procedure Set_Ravenscar_Profile (Profile : Profile_Name; N : Node_Id) is |
| 12203 |
procedure Set_Error_Msg_To_Profile_Name; |
| 12204 |
-- Set Error_Msg_String and Error_Msg_Strlen to the name of the |
| 12205 |
-- profile. |
| 12206 |
|
| 12207 |
----------------------------------- |
| 12208 |
-- Set_Error_Msg_To_Profile_Name -- |
| 12209 |
----------------------------------- |
| 12210 |
|
| 12211 |
procedure Set_Error_Msg_To_Profile_Name is |
| 12212 |
Prof_Nam : constant Node_Id := |
| 12213 |
Get_Pragma_Arg |
| 12214 |
(First (Pragma_Argument_Associations (N))); |
| 12215 |
|
| 12216 |
begin |
| 12217 |
Get_Name_String (Chars (Prof_Nam)); |
| 12218 |
Adjust_Name_Case (Global_Name_Buffer, Sloc (Prof_Nam)); |
| 12219 |
Error_Msg_Strlen := Name_Len; |
| 12220 |
Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len); |
| 12221 |
end Set_Error_Msg_To_Profile_Name; |
| 12222 |
|
| 12223 |
Profile_Dispatching_Policy : Character; |
| 12224 |
|
| 12225 |
-- Start of processing for Set_Ravenscar_Profile |
| 12226 |
|
| 12227 |
begin |
| 12228 |
-- pragma Task_Dispatching_Policy (EDF_Across_Priorities) |
| 12229 |
|
| 12230 |
if Profile = GNAT_Ravenscar_EDF then |
| 12231 |
Profile_Dispatching_Policy := 'E'; |
| 12232 |
|
| 12233 |
-- pragma Task_Dispatching_Policy (FIFO_Within_Priorities) |
| 12234 |
|
| 12235 |
else |
| 12236 |
Profile_Dispatching_Policy := 'F'; |
| 12237 |
end if; |
| 12238 |
|
| 12239 |
if Task_Dispatching_Policy /= ' ' |
| 12240 |
and then Task_Dispatching_Policy /= Profile_Dispatching_Policy |
| 12241 |
then |
| 12242 |
Error_Msg_Sloc := Task_Dispatching_Policy_Sloc; |
| 12243 |
Set_Error_Msg_To_Profile_Name; |
| 12244 |
Error_Pragma ("Profile (~) incompatible with policy#"); |
| 12245 |
|
| 12246 |
-- Set the FIFO_Within_Priorities policy, but always preserve |
| 12247 |
-- System_Location since we like the error message with the run time |
| 12248 |
-- name. |
| 12249 |
|
| 12250 |
else |
| 12251 |
Task_Dispatching_Policy := Profile_Dispatching_Policy; |
| 12252 |
|
| 12253 |
if Task_Dispatching_Policy_Sloc /= System_Location then |
| 12254 |
Task_Dispatching_Policy_Sloc := Loc; |
| 12255 |
end if; |
| 12256 |
end if; |
| 12257 |
|
| 12258 |
-- pragma Locking_Policy (Ceiling_Locking) |
| 12259 |
|
| 12260 |
if Locking_Policy /= ' ' |
| 12261 |
and then Locking_Policy /= 'C' |
| 12262 |
then |
| 12263 |
Error_Msg_Sloc := Locking_Policy_Sloc; |
| 12264 |
Set_Error_Msg_To_Profile_Name; |
| 12265 |
Error_Pragma ("Profile (~) incompatible with policy#"); |
| 12266 |
|
| 12267 |
-- Set the Ceiling_Locking policy, but preserve System_Location since |
| 12268 |
-- we like the error message with the run time name. |
| 12269 |
|
| 12270 |
else |
| 12271 |
Locking_Policy := 'C'; |
| 12272 |
|
| 12273 |
if Locking_Policy_Sloc /= System_Location then |
| 12274 |
Locking_Policy_Sloc := Loc; |
| 12275 |
end if; |
| 12276 |
end if; |
| 12277 |
|
| 12278 |
-- pragma Detect_Blocking |
| 12279 |
|
| 12280 |
Detect_Blocking := True; |
| 12281 |
|
| 12282 |
-- Set the corresponding restrictions |
| 12283 |
|
| 12284 |
Set_Profile_Restrictions |
| 12285 |
(Profile, N, Warn => Treat_Restrictions_As_Warnings); |
| 12286 |
|
| 12287 |
-- Set the No_Dependence restrictions |
| 12288 |
|
| 12289 |
-- The following No_Dependence restrictions: |
| 12290 |
-- No_Dependence => Ada.Asynchronous_Task_Control |
| 12291 |
-- No_Dependence => Ada.Calendar |
| 12292 |
-- No_Dependence => Ada.Task_Attributes |
| 12293 |
-- are already set by previous call to Set_Profile_Restrictions. |
| 12294 |
-- Really??? |
| 12295 |
|
| 12296 |
-- Set the following restrictions which were added to Ada 2005: |
| 12297 |
-- No_Dependence => Ada.Execution_Time.Group_Budget |
| 12298 |
-- No_Dependence => Ada.Execution_Time.Timers |
| 12299 |
|
| 12300 |
if Ada_Version >= Ada_2005 then |
| 12301 |
declare |
| 12302 |
Execution_Time : constant Node_Id := |
| 12303 |
Sel_Comp ("ada", "execution_time", Loc); |
| 12304 |
Group_Budgets : constant Node_Id := |
| 12305 |
Sel_Comp (Execution_Time, "group_budgets"); |
| 12306 |
Timers : constant Node_Id := |
| 12307 |
Sel_Comp (Execution_Time, "timers"); |
| 12308 |
begin |
| 12309 |
Set_Restriction_No_Dependence |
| 12310 |
(Unit => Group_Budgets, |
| 12311 |
Warn => Treat_Restrictions_As_Warnings, |
| 12312 |
Profile => Ravenscar); |
| 12313 |
Set_Restriction_No_Dependence |
| 12314 |
(Unit => Timers, |
| 12315 |
Warn => Treat_Restrictions_As_Warnings, |
| 12316 |
Profile => Ravenscar); |
| 12317 |
end; |
| 12318 |
end if; |
| 12319 |
|
| 12320 |
-- Set the following restriction which was added to Ada 2012 (see |
| 12321 |
-- AI05-0171): |
| 12322 |
-- No_Dependence => System.Multiprocessors.Dispatching_Domains |
| 12323 |
|
| 12324 |
if Ada_Version >= Ada_2012 then |
| 12325 |
Set_Restriction_No_Dependence |
| 12326 |
(Sel_Comp |
| 12327 |
(Sel_Comp ("system", "multiprocessors", Loc), |
| 12328 |
"dispatching_domains"), |
| 12329 |
Warn => Treat_Restrictions_As_Warnings, |
| 12330 |
Profile => Ravenscar); |
| 12331 |
|
| 12332 |
-- Set the following restriction which was added to Ada 2022, |
| 12333 |
-- but as a binding interpretation: |
| 12334 |
-- No_Dependence => Ada.Synchronous_Barriers |
| 12335 |
-- for Ravenscar (and therefore for Ravenscar variants) but not |
| 12336 |
-- for Jorvik. The unit Ada.Synchronous_Barriers was introduced |
| 12337 |
-- in Ada2012 (AI05-0174). |
| 12338 |
|
| 12339 |
if Profile /= Jorvik then |
| 12340 |
Set_Restriction_No_Dependence |
| 12341 |
(Sel_Comp ("ada", "synchronous_barriers", Loc), |
| 12342 |
Warn => Treat_Restrictions_As_Warnings, |
| 12343 |
Profile => Ravenscar); |
| 12344 |
end if; |
| 12345 |
end if; |
| 12346 |
|
| 12347 |
end Set_Ravenscar_Profile; |
| 12348 |
|
| 12349 |
-- Start of processing for Analyze_Pragma |
| 12350 |
|
| 12351 |
begin |
| 12352 |
-- The following code is a defense against recursion. Not clear that |
| 12353 |
-- this can happen legitimately, but perhaps some error situations can |
| 12354 |
-- cause it, and we did see this recursion during testing. |
| 12355 |
|
| 12356 |
if Analyzed (N) then |
| 12357 |
return; |
| 12358 |
else |
| 12359 |
Set_Analyzed (N); |
| 12360 |
end if; |
| 12361 |
|
| 12362 |
Check_Restriction_No_Use_Of_Pragma (N); |
| 12363 |
|
| 12364 |
if Is_Aspect_Id (Chars (Pragma_Identifier (N))) then |
| 12365 |
-- 6.1/3 No_Specification_of_Aspect: Identifies an aspect for which |
| 12366 |
-- no aspect_specification, attribute_definition_clause, or pragma |
| 12367 |
-- is given. |
| 12368 |
Check_Restriction_No_Specification_Of_Aspect (N); |
| 12369 |
end if; |
| 12370 |
|
| 12371 |
-- Ignore pragma if Ignore_Pragma applies. Also ignore pragma |
| 12372 |
-- Default_Scalar_Storage_Order if the -gnatI switch was given. |
| 12373 |
|
| 12374 |
if Should_Ignore_Pragma_Sem (N) |
| 12375 |
or else (Prag_Id = Pragma_Default_Scalar_Storage_Order |
| 12376 |
and then Ignore_Rep_Clauses) |
| 12377 |
then |
| 12378 |
return; |
| 12379 |
end if; |
| 12380 |
|
| 12381 |
-- Deal with unrecognized pragma |
| 12382 |
|
| 12383 |
if not Is_Pragma_Name (Pname) then |
| 12384 |
declare |
| 12385 |
Msg_Issued : Boolean := False; |
| 12386 |
begin |
| 12387 |
Check_Restriction |
| 12388 |
(Msg_Issued, No_Unrecognized_Pragmas, Pragma_Identifier (N)); |
| 12389 |
if not Msg_Issued and then Warn_On_Unrecognized_Pragma then |
| 12390 |
Error_Msg_Name_1 := Pname; |
| 12391 |
Error_Msg_N ("?g?unrecognized pragma%!", Pragma_Identifier (N)); |
| 12392 |
|
| 12393 |
for PN in First_Pragma_Name .. Last_Pragma_Name loop |
| 12394 |
if Is_Bad_Spelling_Of (Pname, PN) then |
| 12395 |
Error_Msg_Name_1 := PN; |
| 12396 |
Error_Msg_N -- CODEFIX |
| 12397 |
("\?g?possible misspelling of %!", |
| 12398 |
Pragma_Identifier (N)); |
| 12399 |
exit; |
| 12400 |
end if; |
| 12401 |
end loop; |
| 12402 |
end if; |
| 12403 |
end; |
| 12404 |
|
| 12405 |
return; |
| 12406 |
end if; |
| 12407 |
|
| 12408 |
-- Here to start processing for recognized pragma |
| 12409 |
|
| 12410 |
Pname := Original_Aspect_Pragma_Name (N); |
| 12411 |
|
| 12412 |
-- Capture setting of Opt.Uneval_Old |
| 12413 |
|
| 12414 |
case Opt.Uneval_Old is |
| 12415 |
when 'A' => |
| 12416 |
Set_Uneval_Old_Accept (N); |
| 12417 |
|
| 12418 |
when 'E' => |
| 12419 |
null; |
| 12420 |
|
| 12421 |
when 'W' => |
| 12422 |
Set_Uneval_Old_Warn (N); |
| 12423 |
|
| 12424 |
when others => |
| 12425 |
raise Program_Error; |
| 12426 |
end case; |
| 12427 |
|
| 12428 |
-- Check applicable policy. We skip this if Is_Checked or Is_Ignored |
| 12429 |
-- is already set, indicating that we have already checked the policy |
| 12430 |
-- at the right point. This happens for example in the case of a pragma |
| 12431 |
-- that is derived from an Aspect. |
| 12432 |
|
| 12433 |
if Is_Ignored (N) or else Is_Checked (N) then |
| 12434 |
null; |
| 12435 |
|
| 12436 |
-- For a pragma that is a rewriting of another pragma, copy the |
| 12437 |
-- Is_Checked/Is_Ignored status from the rewritten pragma. |
| 12438 |
|
| 12439 |
elsif Is_Rewrite_Substitution (N) |
| 12440 |
and then Nkind (Original_Node (N)) = N_Pragma |
| 12441 |
then |
| 12442 |
Set_Is_Ignored (N, Is_Ignored (Original_Node (N))); |
| 12443 |
Set_Is_Checked (N, Is_Checked (Original_Node (N))); |
| 12444 |
|
| 12445 |
-- Skip querying the applicable policy at this point for dynamic |
| 12446 |
-- predicate checks since they rely on the policy applicable in |
| 12447 |
-- the context of their associated type declaration (and this |
| 12448 |
-- pragma check has been internally added by the frontend at the |
| 12449 |
-- point where the runtime check must be performed). |
| 12450 |
|
| 12451 |
elsif not Comes_From_Source (N) |
| 12452 |
and then Chars (Pragma_Identifier (N)) = Name_Check |
| 12453 |
and then Pname = Name_Dynamic_Predicate |
| 12454 |
then |
| 12455 |
null; |
| 12456 |
|
| 12457 |
-- Otherwise query the applicable policy at this point |
| 12458 |
|
| 12459 |
else |
| 12460 |
Check_Applicable_Policy (N); |
| 12461 |
|
| 12462 |
-- If pragma is disabled, rewrite as NULL and skip analysis |
| 12463 |
|
| 12464 |
if Is_Disabled (N) then |
| 12465 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 12466 |
Analyze (N); |
| 12467 |
raise Pragma_Exit; |
| 12468 |
end if; |
| 12469 |
end if; |
| 12470 |
|
| 12471 |
-- Mark assertion pragmas as Ghost depending on their enclosing context |
| 12472 |
|
| 12473 |
if Assertion_Expression_Pragma (Prag_Id) then |
| 12474 |
Mark_Ghost_Pragma (N, Current_Scope); |
| 12475 |
end if; |
| 12476 |
|
| 12477 |
-- Preset arguments |
| 12478 |
|
| 12479 |
Arg_Count := List_Length (Pragma_Argument_Associations (N)); |
| 12480 |
Arg1 := First (Pragma_Argument_Associations (N)); |
| 12481 |
Arg2 := Empty; |
| 12482 |
Arg3 := Empty; |
| 12483 |
Arg4 := Empty; |
| 12484 |
Arg5 := Empty; |
| 12485 |
|
| 12486 |
if Present (Arg1) then |
| 12487 |
Arg2 := Next (Arg1); |
| 12488 |
|
| 12489 |
if Present (Arg2) then |
| 12490 |
Arg3 := Next (Arg2); |
| 12491 |
|
| 12492 |
if Present (Arg3) then |
| 12493 |
Arg4 := Next (Arg3); |
| 12494 |
|
| 12495 |
if Present (Arg4) then |
| 12496 |
Arg5 := Next (Arg4); |
| 12497 |
end if; |
| 12498 |
end if; |
| 12499 |
end if; |
| 12500 |
end if; |
| 12501 |
|
| 12502 |
-- An enumeration type defines the pragmas that are supported by the |
| 12503 |
-- implementation. Get_Pragma_Id (in package Prag) transforms a name |
| 12504 |
-- into the corresponding enumeration value for the following case. |
| 12505 |
|
| 12506 |
case Prag_Id is |
| 12507 |
|
| 12508 |
----------------- |
| 12509 |
-- Abort_Defer -- |
| 12510 |
----------------- |
| 12511 |
|
| 12512 |
-- pragma Abort_Defer; |
| 12513 |
|
| 12514 |
when Pragma_Abort_Defer => |
| 12515 |
GNAT_Pragma; |
| 12516 |
Check_Arg_Count (0); |
| 12517 |
|
| 12518 |
-- The only required semantic processing is to check the |
| 12519 |
-- placement. This pragma must appear at the start of the |
| 12520 |
-- statement sequence of a handled sequence of statements. |
| 12521 |
|
| 12522 |
if Nkind (Parent (N)) /= N_Handled_Sequence_Of_Statements |
| 12523 |
or else N /= First (Statements (Parent (N))) |
| 12524 |
then |
| 12525 |
Pragma_Misplaced; |
| 12526 |
end if; |
| 12527 |
|
| 12528 |
-------------------- |
| 12529 |
-- Abstract_State -- |
| 12530 |
-------------------- |
| 12531 |
|
| 12532 |
-- pragma Abstract_State (ABSTRACT_STATE_LIST); |
| 12533 |
|
| 12534 |
-- ABSTRACT_STATE_LIST ::= |
| 12535 |
-- null |
| 12536 |
-- | STATE_NAME_WITH_OPTIONS |
| 12537 |
-- | (STATE_NAME_WITH_OPTIONS {, STATE_NAME_WITH_OPTIONS}) |
| 12538 |
|
| 12539 |
-- STATE_NAME_WITH_OPTIONS ::= |
| 12540 |
-- STATE_NAME |
| 12541 |
-- | (STATE_NAME with OPTION_LIST) |
| 12542 |
|
| 12543 |
-- OPTION_LIST ::= OPTION {, OPTION} |
| 12544 |
|
| 12545 |
-- OPTION ::= |
| 12546 |
-- SIMPLE_OPTION |
| 12547 |
-- | NAME_VALUE_OPTION |
| 12548 |
|
| 12549 |
-- SIMPLE_OPTION ::= Ghost | Relaxed_Initialization | Synchronous |
| 12550 |
|
| 12551 |
-- NAME_VALUE_OPTION ::= |
| 12552 |
-- Part_Of => ABSTRACT_STATE |
| 12553 |
-- | External [=> EXTERNAL_PROPERTY_LIST] |
| 12554 |
|
| 12555 |
-- EXTERNAL_PROPERTY_LIST ::= |
| 12556 |
-- EXTERNAL_PROPERTY |
| 12557 |
-- | (EXTERNAL_PROPERTY {, EXTERNAL_PROPERTY}) |
| 12558 |
|
| 12559 |
-- EXTERNAL_PROPERTY ::= |
| 12560 |
-- Async_Readers [=> boolean_EXPRESSION] |
| 12561 |
-- | Async_Writers [=> boolean_EXPRESSION] |
| 12562 |
-- | Effective_Reads [=> boolean_EXPRESSION] |
| 12563 |
-- | Effective_Writes [=> boolean_EXPRESSION] |
| 12564 |
-- others => boolean_EXPRESSION |
| 12565 |
|
| 12566 |
-- STATE_NAME ::= defining_identifier |
| 12567 |
|
| 12568 |
-- ABSTRACT_STATE ::= name |
| 12569 |
|
| 12570 |
-- Characteristics: |
| 12571 |
|
| 12572 |
-- * Analysis - The annotation is fully analyzed immediately upon |
| 12573 |
-- elaboration as it cannot forward reference entities. |
| 12574 |
|
| 12575 |
-- * Expansion - None. |
| 12576 |
|
| 12577 |
-- * Template - The annotation utilizes the generic template of the |
| 12578 |
-- related package declaration. |
| 12579 |
|
| 12580 |
-- * Globals - The annotation cannot reference global entities. |
| 12581 |
|
| 12582 |
-- * Instance - The annotation is instantiated automatically when |
| 12583 |
-- the related generic package is instantiated. |
| 12584 |
|
| 12585 |
when Pragma_Abstract_State => Abstract_State : declare |
| 12586 |
Missing_Parentheses : Boolean := False; |
| 12587 |
-- Flag set when a state declaration with options is not properly |
| 12588 |
-- parenthesized. |
| 12589 |
|
| 12590 |
-- Flags used to verify the consistency of states |
| 12591 |
|
| 12592 |
Non_Null_Seen : Boolean := False; |
| 12593 |
Null_Seen : Boolean := False; |
| 12594 |
|
| 12595 |
procedure Analyze_Abstract_State |
| 12596 |
(State : Node_Id; |
| 12597 |
Pack_Id : Entity_Id); |
| 12598 |
-- Verify the legality of a single state declaration. Create and |
| 12599 |
-- decorate a state abstraction entity and introduce it into the |
| 12600 |
-- visibility chain. Pack_Id denotes the entity or the related |
| 12601 |
-- package where pragma Abstract_State appears. |
| 12602 |
|
| 12603 |
procedure Malformed_State_Error (State : Node_Id); |
| 12604 |
-- Emit an error concerning the illegal declaration of abstract |
| 12605 |
-- state State. This routine diagnoses syntax errors that lead to |
| 12606 |
-- a different parse tree. The error is issued regardless of the |
| 12607 |
-- SPARK mode in effect. |
| 12608 |
|
| 12609 |
---------------------------- |
| 12610 |
-- Analyze_Abstract_State -- |
| 12611 |
---------------------------- |
| 12612 |
|
| 12613 |
procedure Analyze_Abstract_State |
| 12614 |
(State : Node_Id; |
| 12615 |
Pack_Id : Entity_Id) |
| 12616 |
is |
| 12617 |
-- Flags used to verify the consistency of options |
| 12618 |
|
| 12619 |
AR_Seen : Boolean := False; |
| 12620 |
AW_Seen : Boolean := False; |
| 12621 |
ER_Seen : Boolean := False; |
| 12622 |
EW_Seen : Boolean := False; |
| 12623 |
External_Seen : Boolean := False; |
| 12624 |
Ghost_Seen : Boolean := False; |
| 12625 |
Others_Seen : Boolean := False; |
| 12626 |
Part_Of_Seen : Boolean := False; |
| 12627 |
Synchronous_Seen : Boolean := False; |
| 12628 |
|
| 12629 |
-- Flags used to store the static value of all external states' |
| 12630 |
-- expressions. |
| 12631 |
|
| 12632 |
AR_Val : Boolean := False; |
| 12633 |
AW_Val : Boolean := False; |
| 12634 |
ER_Val : Boolean := False; |
| 12635 |
EW_Val : Boolean := False; |
| 12636 |
|
| 12637 |
State_Id : Entity_Id := Empty; |
| 12638 |
-- The entity to be generated for the current state declaration |
| 12639 |
|
| 12640 |
procedure Analyze_External_Option (Opt : Node_Id); |
| 12641 |
-- Verify the legality of option External |
| 12642 |
|
| 12643 |
procedure Analyze_External_Property |
| 12644 |
(Prop : Node_Id; |
| 12645 |
Expr : Node_Id := Empty); |
| 12646 |
-- Verify the legailty of a single external property. Prop |
| 12647 |
-- denotes the external property. Expr is the expression used |
| 12648 |
-- to set the property. |
| 12649 |
|
| 12650 |
procedure Analyze_Part_Of_Option (Opt : Node_Id); |
| 12651 |
-- Verify the legality of option Part_Of |
| 12652 |
|
| 12653 |
procedure Check_Duplicate_Option |
| 12654 |
(Opt : Node_Id; |
| 12655 |
Status : in out Boolean); |
| 12656 |
-- Flag Status denotes whether a particular option has been |
| 12657 |
-- seen while processing a state. This routine verifies that |
| 12658 |
-- Opt is not a duplicate option and sets the flag Status |
| 12659 |
-- (SPARK RM 7.1.4(1)). |
| 12660 |
|
| 12661 |
procedure Check_Duplicate_Property |
| 12662 |
(Prop : Node_Id; |
| 12663 |
Status : in out Boolean); |
| 12664 |
-- Flag Status denotes whether a particular property has been |
| 12665 |
-- seen while processing option External. This routine verifies |
| 12666 |
-- that Prop is not a duplicate property and sets flag Status. |
| 12667 |
-- Opt is not a duplicate property and sets the flag Status. |
| 12668 |
-- (SPARK RM 7.1.4(2)) |
| 12669 |
|
| 12670 |
procedure Check_Ghost_Synchronous; |
| 12671 |
-- Ensure that the abstract state is not subject to both Ghost |
| 12672 |
-- and Synchronous simple options. Emit an error if this is the |
| 12673 |
-- case. |
| 12674 |
|
| 12675 |
procedure Create_Abstract_State |
| 12676 |
(Nam : Name_Id; |
| 12677 |
Decl : Node_Id; |
| 12678 |
Loc : Source_Ptr; |
| 12679 |
Is_Null : Boolean); |
| 12680 |
-- Generate an abstract state entity with name Nam and enter it |
| 12681 |
-- into visibility. Decl is the "declaration" of the state as |
| 12682 |
-- it appears in pragma Abstract_State. Loc is the location of |
| 12683 |
-- the related state "declaration". Flag Is_Null should be set |
| 12684 |
-- when the associated Abstract_State pragma defines a null |
| 12685 |
-- state. |
| 12686 |
|
| 12687 |
----------------------------- |
| 12688 |
-- Analyze_External_Option -- |
| 12689 |
----------------------------- |
| 12690 |
|
| 12691 |
procedure Analyze_External_Option (Opt : Node_Id) is |
| 12692 |
Errors : constant Nat := Serious_Errors_Detected; |
| 12693 |
Prop : Node_Id; |
| 12694 |
Props : Node_Id := Empty; |
| 12695 |
|
| 12696 |
begin |
| 12697 |
if Nkind (Opt) = N_Component_Association then |
| 12698 |
Props := Expression (Opt); |
| 12699 |
end if; |
| 12700 |
|
| 12701 |
-- External state with properties |
| 12702 |
|
| 12703 |
if Present (Props) then |
| 12704 |
|
| 12705 |
-- Multiple properties appear as an aggregate |
| 12706 |
|
| 12707 |
if Nkind (Props) = N_Aggregate then |
| 12708 |
|
| 12709 |
-- Simple property form |
| 12710 |
|
| 12711 |
Prop := First (Expressions (Props)); |
| 12712 |
while Present (Prop) loop |
| 12713 |
Analyze_External_Property (Prop); |
| 12714 |
Next (Prop); |
| 12715 |
end loop; |
| 12716 |
|
| 12717 |
-- Property with expression form |
| 12718 |
|
| 12719 |
Prop := First (Component_Associations (Props)); |
| 12720 |
while Present (Prop) loop |
| 12721 |
Analyze_External_Property |
| 12722 |
(Prop => First (Choices (Prop)), |
| 12723 |
Expr => Expression (Prop)); |
| 12724 |
|
| 12725 |
Next (Prop); |
| 12726 |
end loop; |
| 12727 |
|
| 12728 |
-- Single property |
| 12729 |
|
| 12730 |
else |
| 12731 |
Analyze_External_Property (Props); |
| 12732 |
end if; |
| 12733 |
|
| 12734 |
-- An external state defined without any properties defaults |
| 12735 |
-- all properties to True. |
| 12736 |
|
| 12737 |
else |
| 12738 |
AR_Val := True; |
| 12739 |
AW_Val := True; |
| 12740 |
ER_Val := True; |
| 12741 |
EW_Val := True; |
| 12742 |
end if; |
| 12743 |
|
| 12744 |
-- Once all external properties have been processed, verify |
| 12745 |
-- their mutual interaction. Do not perform the check when |
| 12746 |
-- at least one of the properties is illegal as this will |
| 12747 |
-- produce a bogus error. |
| 12748 |
|
| 12749 |
if Errors = Serious_Errors_Detected then |
| 12750 |
Check_External_Properties |
| 12751 |
(State, AR_Val, AW_Val, ER_Val, EW_Val); |
| 12752 |
end if; |
| 12753 |
end Analyze_External_Option; |
| 12754 |
|
| 12755 |
------------------------------- |
| 12756 |
-- Analyze_External_Property -- |
| 12757 |
------------------------------- |
| 12758 |
|
| 12759 |
procedure Analyze_External_Property |
| 12760 |
(Prop : Node_Id; |
| 12761 |
Expr : Node_Id := Empty) |
| 12762 |
is |
| 12763 |
Expr_Val : Boolean; |
| 12764 |
|
| 12765 |
begin |
| 12766 |
-- Check the placement of "others" (if available) |
| 12767 |
|
| 12768 |
if Nkind (Prop) = N_Others_Choice then |
| 12769 |
if Others_Seen then |
| 12770 |
SPARK_Msg_N |
| 12771 |
("only one OTHERS choice allowed in option External", |
| 12772 |
Prop); |
| 12773 |
else |
| 12774 |
Others_Seen := True; |
| 12775 |
end if; |
| 12776 |
|
| 12777 |
elsif Others_Seen then |
| 12778 |
SPARK_Msg_N |
| 12779 |
("OTHERS must be the last property in option External", |
| 12780 |
Prop); |
| 12781 |
|
| 12782 |
-- The only remaining legal options are the four predefined |
| 12783 |
-- external properties. |
| 12784 |
|
| 12785 |
elsif Nkind (Prop) = N_Identifier |
| 12786 |
and then Chars (Prop) in Name_Async_Readers |
| 12787 |
| Name_Async_Writers |
| 12788 |
| Name_Effective_Reads |
| 12789 |
| Name_Effective_Writes |
| 12790 |
then |
| 12791 |
null; |
| 12792 |
|
| 12793 |
-- Otherwise the construct is not a valid property |
| 12794 |
|
| 12795 |
else |
| 12796 |
SPARK_Msg_N ("invalid external state property", Prop); |
| 12797 |
return; |
| 12798 |
end if; |
| 12799 |
|
| 12800 |
-- Ensure that the expression of the external state property |
| 12801 |
-- is static Boolean (if applicable) (SPARK RM 7.1.2(5)). |
| 12802 |
|
| 12803 |
if Present (Expr) then |
| 12804 |
Analyze_And_Resolve (Expr, Standard_Boolean); |
| 12805 |
|
| 12806 |
if Is_OK_Static_Expression (Expr) then |
| 12807 |
Expr_Val := Is_True (Expr_Value (Expr)); |
| 12808 |
else |
| 12809 |
SPARK_Msg_N |
| 12810 |
("expression of external state property must be " |
| 12811 |
& "static", Expr); |
| 12812 |
return; |
| 12813 |
end if; |
| 12814 |
|
| 12815 |
-- The lack of expression defaults the property to True |
| 12816 |
|
| 12817 |
else |
| 12818 |
Expr_Val := True; |
| 12819 |
end if; |
| 12820 |
|
| 12821 |
-- Named properties |
| 12822 |
|
| 12823 |
if Nkind (Prop) = N_Identifier then |
| 12824 |
if Chars (Prop) = Name_Async_Readers then |
| 12825 |
Check_Duplicate_Property (Prop, AR_Seen); |
| 12826 |
AR_Val := Expr_Val; |
| 12827 |
|
| 12828 |
elsif Chars (Prop) = Name_Async_Writers then |
| 12829 |
Check_Duplicate_Property (Prop, AW_Seen); |
| 12830 |
AW_Val := Expr_Val; |
| 12831 |
|
| 12832 |
elsif Chars (Prop) = Name_Effective_Reads then |
| 12833 |
Check_Duplicate_Property (Prop, ER_Seen); |
| 12834 |
ER_Val := Expr_Val; |
| 12835 |
|
| 12836 |
else |
| 12837 |
Check_Duplicate_Property (Prop, EW_Seen); |
| 12838 |
EW_Val := Expr_Val; |
| 12839 |
end if; |
| 12840 |
|
| 12841 |
-- The handling of property "others" must take into account |
| 12842 |
-- all other named properties that have been encountered so |
| 12843 |
-- far. Only those that have not been seen are affected by |
| 12844 |
-- "others". |
| 12845 |
|
| 12846 |
else |
| 12847 |
if not AR_Seen then |
| 12848 |
AR_Val := Expr_Val; |
| 12849 |
end if; |
| 12850 |
|
| 12851 |
if not AW_Seen then |
| 12852 |
AW_Val := Expr_Val; |
| 12853 |
end if; |
| 12854 |
|
| 12855 |
if not ER_Seen then |
| 12856 |
ER_Val := Expr_Val; |
| 12857 |
end if; |
| 12858 |
|
| 12859 |
if not EW_Seen then |
| 12860 |
EW_Val := Expr_Val; |
| 12861 |
end if; |
| 12862 |
end if; |
| 12863 |
end Analyze_External_Property; |
| 12864 |
|
| 12865 |
---------------------------- |
| 12866 |
-- Analyze_Part_Of_Option -- |
| 12867 |
---------------------------- |
| 12868 |
|
| 12869 |
procedure Analyze_Part_Of_Option (Opt : Node_Id) is |
| 12870 |
Encap : constant Node_Id := Expression (Opt); |
| 12871 |
Constits : Elist_Id; |
| 12872 |
Encap_Id : Entity_Id; |
| 12873 |
Legal : Boolean; |
| 12874 |
|
| 12875 |
begin |
| 12876 |
Check_Duplicate_Option (Opt, Part_Of_Seen); |
| 12877 |
|
| 12878 |
Analyze_Part_Of |
| 12879 |
(Indic => First (Choices (Opt)), |
| 12880 |
Item_Id => State_Id, |
| 12881 |
Encap => Encap, |
| 12882 |
Encap_Id => Encap_Id, |
| 12883 |
Legal => Legal); |
| 12884 |
|
| 12885 |
-- The Part_Of indicator transforms the abstract state into |
| 12886 |
-- a constituent of the encapsulating state or single |
| 12887 |
-- concurrent type. |
| 12888 |
|
| 12889 |
if Legal then |
| 12890 |
pragma Assert (Present (Encap_Id)); |
| 12891 |
Constits := Part_Of_Constituents (Encap_Id); |
| 12892 |
|
| 12893 |
if No (Constits) then |
| 12894 |
Constits := New_Elmt_List; |
| 12895 |
Set_Part_Of_Constituents (Encap_Id, Constits); |
| 12896 |
end if; |
| 12897 |
|
| 12898 |
Append_Elmt (State_Id, Constits); |
| 12899 |
Set_Encapsulating_State (State_Id, Encap_Id); |
| 12900 |
end if; |
| 12901 |
end Analyze_Part_Of_Option; |
| 12902 |
|
| 12903 |
---------------------------- |
| 12904 |
-- Check_Duplicate_Option -- |
| 12905 |
---------------------------- |
| 12906 |
|
| 12907 |
procedure Check_Duplicate_Option |
| 12908 |
(Opt : Node_Id; |
| 12909 |
Status : in out Boolean) |
| 12910 |
is |
| 12911 |
begin |
| 12912 |
if Status then |
| 12913 |
SPARK_Msg_N ("duplicate state option", Opt); |
| 12914 |
end if; |
| 12915 |
|
| 12916 |
Status := True; |
| 12917 |
end Check_Duplicate_Option; |
| 12918 |
|
| 12919 |
------------------------------ |
| 12920 |
-- Check_Duplicate_Property -- |
| 12921 |
------------------------------ |
| 12922 |
|
| 12923 |
procedure Check_Duplicate_Property |
| 12924 |
(Prop : Node_Id; |
| 12925 |
Status : in out Boolean) |
| 12926 |
is |
| 12927 |
begin |
| 12928 |
if Status then |
| 12929 |
SPARK_Msg_N ("duplicate external property", Prop); |
| 12930 |
end if; |
| 12931 |
|
| 12932 |
Status := True; |
| 12933 |
end Check_Duplicate_Property; |
| 12934 |
|
| 12935 |
----------------------------- |
| 12936 |
-- Check_Ghost_Synchronous -- |
| 12937 |
----------------------------- |
| 12938 |
|
| 12939 |
procedure Check_Ghost_Synchronous is |
| 12940 |
begin |
| 12941 |
-- A synchronized abstract state cannot be Ghost and vice |
| 12942 |
-- versa (SPARK RM 6.9(21)). |
| 12943 |
|
| 12944 |
if Ghost_Seen and Synchronous_Seen then |
| 12945 |
SPARK_Msg_N ("synchronized state cannot be ghost", State); |
| 12946 |
end if; |
| 12947 |
end Check_Ghost_Synchronous; |
| 12948 |
|
| 12949 |
--------------------------- |
| 12950 |
-- Create_Abstract_State -- |
| 12951 |
--------------------------- |
| 12952 |
|
| 12953 |
procedure Create_Abstract_State |
| 12954 |
(Nam : Name_Id; |
| 12955 |
Decl : Node_Id; |
| 12956 |
Loc : Source_Ptr; |
| 12957 |
Is_Null : Boolean) |
| 12958 |
is |
| 12959 |
begin |
| 12960 |
-- The abstract state may be semi-declared when the related |
| 12961 |
-- package was withed through a limited with clause. In that |
| 12962 |
-- case reuse the entity to fully declare the state. |
| 12963 |
|
| 12964 |
if Present (Decl) and then Present (Entity (Decl)) then |
| 12965 |
State_Id := Entity (Decl); |
| 12966 |
|
| 12967 |
-- Otherwise the elaboration of pragma Abstract_State |
| 12968 |
-- declares the state. |
| 12969 |
|
| 12970 |
else |
| 12971 |
State_Id := Make_Defining_Identifier (Loc, Nam); |
| 12972 |
|
| 12973 |
if Present (Decl) then |
| 12974 |
Set_Entity (Decl, State_Id); |
| 12975 |
end if; |
| 12976 |
end if; |
| 12977 |
|
| 12978 |
-- Null states never come from source |
| 12979 |
|
| 12980 |
Set_Comes_From_Source (State_Id, not Is_Null); |
| 12981 |
Set_Parent (State_Id, State); |
| 12982 |
Mutate_Ekind (State_Id, E_Abstract_State); |
| 12983 |
Set_Is_Not_Self_Hidden (State_Id); |
| 12984 |
Set_Etype (State_Id, Standard_Void_Type); |
| 12985 |
Set_Encapsulating_State (State_Id, Empty); |
| 12986 |
|
| 12987 |
-- Set the SPARK mode from the current context |
| 12988 |
|
| 12989 |
Set_SPARK_Pragma (State_Id, SPARK_Mode_Pragma); |
| 12990 |
Set_SPARK_Pragma_Inherited (State_Id); |
| 12991 |
|
| 12992 |
-- An abstract state declared within a Ghost region becomes |
| 12993 |
-- Ghost (SPARK RM 6.9(2)). |
| 12994 |
|
| 12995 |
if Ghost_Mode > None or else Is_Ghost_Entity (Pack_Id) then |
| 12996 |
Set_Is_Ghost_Entity (State_Id); |
| 12997 |
end if; |
| 12998 |
|
| 12999 |
-- Establish a link between the state declaration and the |
| 13000 |
-- abstract state entity. Note that a null state remains as |
| 13001 |
-- N_Null and does not carry any linkages. |
| 13002 |
|
| 13003 |
if not Is_Null then |
| 13004 |
if Present (Decl) then |
| 13005 |
Set_Entity (Decl, State_Id); |
| 13006 |
Set_Etype (Decl, Standard_Void_Type); |
| 13007 |
end if; |
| 13008 |
|
| 13009 |
-- Every non-null state must be defined, nameable and |
| 13010 |
-- resolvable. |
| 13011 |
|
| 13012 |
Push_Scope (Pack_Id); |
| 13013 |
Generate_Definition (State_Id); |
| 13014 |
Enter_Name (State_Id); |
| 13015 |
Pop_Scope; |
| 13016 |
end if; |
| 13017 |
end Create_Abstract_State; |
| 13018 |
|
| 13019 |
-- Local variables |
| 13020 |
|
| 13021 |
Opt : Node_Id; |
| 13022 |
Opt_Nam : Node_Id; |
| 13023 |
|
| 13024 |
-- Start of processing for Analyze_Abstract_State |
| 13025 |
|
| 13026 |
begin |
| 13027 |
-- A package with a null abstract state is not allowed to |
| 13028 |
-- declare additional states. |
| 13029 |
|
| 13030 |
if Null_Seen then |
| 13031 |
SPARK_Msg_NE |
| 13032 |
("package & has null abstract state", State, Pack_Id); |
| 13033 |
|
| 13034 |
-- Null states appear as internally generated entities |
| 13035 |
|
| 13036 |
elsif Nkind (State) = N_Null then |
| 13037 |
Create_Abstract_State |
| 13038 |
(Nam => New_Internal_Name ('S'), |
| 13039 |
Decl => Empty, |
| 13040 |
Loc => Sloc (State), |
| 13041 |
Is_Null => True); |
| 13042 |
Null_Seen := True; |
| 13043 |
|
| 13044 |
-- Catch a case where a null state appears in a list of |
| 13045 |
-- non-null states. |
| 13046 |
|
| 13047 |
if Non_Null_Seen then |
| 13048 |
SPARK_Msg_NE |
| 13049 |
("package & has non-null abstract state", |
| 13050 |
State, Pack_Id); |
| 13051 |
end if; |
| 13052 |
|
| 13053 |
-- Simple state declaration |
| 13054 |
|
| 13055 |
elsif Nkind (State) = N_Identifier then |
| 13056 |
Create_Abstract_State |
| 13057 |
(Nam => Chars (State), |
| 13058 |
Decl => State, |
| 13059 |
Loc => Sloc (State), |
| 13060 |
Is_Null => False); |
| 13061 |
Non_Null_Seen := True; |
| 13062 |
|
| 13063 |
-- State declaration with various options. This construct |
| 13064 |
-- appears as an extension aggregate in the tree. |
| 13065 |
|
| 13066 |
elsif Nkind (State) = N_Extension_Aggregate then |
| 13067 |
if Nkind (Ancestor_Part (State)) = N_Identifier then |
| 13068 |
Create_Abstract_State |
| 13069 |
(Nam => Chars (Ancestor_Part (State)), |
| 13070 |
Decl => Ancestor_Part (State), |
| 13071 |
Loc => Sloc (Ancestor_Part (State)), |
| 13072 |
Is_Null => False); |
| 13073 |
Non_Null_Seen := True; |
| 13074 |
else |
| 13075 |
SPARK_Msg_N |
| 13076 |
("state name must be an identifier", |
| 13077 |
Ancestor_Part (State)); |
| 13078 |
end if; |
| 13079 |
|
| 13080 |
-- Options External, Ghost and Synchronous appear as |
| 13081 |
-- expressions. |
| 13082 |
|
| 13083 |
Opt := First (Expressions (State)); |
| 13084 |
while Present (Opt) loop |
| 13085 |
if Nkind (Opt) = N_Identifier then |
| 13086 |
|
| 13087 |
-- External |
| 13088 |
|
| 13089 |
if Chars (Opt) = Name_External then |
| 13090 |
Check_Duplicate_Option (Opt, External_Seen); |
| 13091 |
Analyze_External_Option (Opt); |
| 13092 |
|
| 13093 |
-- Ghost |
| 13094 |
|
| 13095 |
elsif Chars (Opt) = Name_Ghost then |
| 13096 |
Check_Duplicate_Option (Opt, Ghost_Seen); |
| 13097 |
Check_Ghost_Synchronous; |
| 13098 |
|
| 13099 |
if Present (State_Id) then |
| 13100 |
Set_Is_Ghost_Entity (State_Id); |
| 13101 |
end if; |
| 13102 |
|
| 13103 |
-- Synchronous |
| 13104 |
|
| 13105 |
elsif Chars (Opt) = Name_Synchronous then |
| 13106 |
Check_Duplicate_Option (Opt, Synchronous_Seen); |
| 13107 |
Check_Ghost_Synchronous; |
| 13108 |
|
| 13109 |
-- Option Part_Of without an encapsulating state is |
| 13110 |
-- illegal (SPARK RM 7.1.4(8)). |
| 13111 |
|
| 13112 |
elsif Chars (Opt) = Name_Part_Of then |
| 13113 |
SPARK_Msg_N |
| 13114 |
("indicator Part_Of must denote abstract state, " |
| 13115 |
& "single protected type or single task type", |
| 13116 |
Opt); |
| 13117 |
|
| 13118 |
-- Do not emit an error message when a previous state |
| 13119 |
-- declaration with options was not parenthesized as |
| 13120 |
-- the option is actually another state declaration. |
| 13121 |
-- |
| 13122 |
-- with Abstract_State |
| 13123 |
-- (State_1 with ..., -- missing parentheses |
| 13124 |
-- (State_2 with ...), |
| 13125 |
-- State_3) -- ok state declaration |
| 13126 |
|
| 13127 |
elsif Missing_Parentheses then |
| 13128 |
null; |
| 13129 |
|
| 13130 |
-- Otherwise the option is not allowed. Note that it |
| 13131 |
-- is not possible to distinguish between an option |
| 13132 |
-- and a state declaration when a previous state with |
| 13133 |
-- options not properly parentheses. |
| 13134 |
-- |
| 13135 |
-- with Abstract_State |
| 13136 |
-- (State_1 with ..., -- missing parentheses |
| 13137 |
-- State_2); -- could be an option |
| 13138 |
|
| 13139 |
else |
| 13140 |
SPARK_Msg_N |
| 13141 |
("simple option not allowed in state declaration", |
| 13142 |
Opt); |
| 13143 |
end if; |
| 13144 |
|
| 13145 |
-- Catch a case where missing parentheses around a state |
| 13146 |
-- declaration with options cause a subsequent state |
| 13147 |
-- declaration with options to be treated as an option. |
| 13148 |
-- |
| 13149 |
-- with Abstract_State |
| 13150 |
-- (State_1 with ..., -- missing parentheses |
| 13151 |
-- (State_2 with ...)) |
| 13152 |
|
| 13153 |
elsif Nkind (Opt) = N_Extension_Aggregate then |
| 13154 |
Missing_Parentheses := True; |
| 13155 |
SPARK_Msg_N |
| 13156 |
("state declaration must be parenthesized", |
| 13157 |
Ancestor_Part (State)); |
| 13158 |
|
| 13159 |
-- Otherwise the option is malformed |
| 13160 |
|
| 13161 |
else |
| 13162 |
SPARK_Msg_N ("malformed option", Opt); |
| 13163 |
end if; |
| 13164 |
|
| 13165 |
Next (Opt); |
| 13166 |
end loop; |
| 13167 |
|
| 13168 |
-- Options External and Part_Of appear as component |
| 13169 |
-- associations. |
| 13170 |
|
| 13171 |
Opt := First (Component_Associations (State)); |
| 13172 |
while Present (Opt) loop |
| 13173 |
Opt_Nam := First (Choices (Opt)); |
| 13174 |
|
| 13175 |
if Nkind (Opt_Nam) = N_Identifier then |
| 13176 |
if Chars (Opt_Nam) = Name_External then |
| 13177 |
Analyze_External_Option (Opt); |
| 13178 |
|
| 13179 |
elsif Chars (Opt_Nam) = Name_Part_Of then |
| 13180 |
Analyze_Part_Of_Option (Opt); |
| 13181 |
|
| 13182 |
else |
| 13183 |
SPARK_Msg_N ("invalid state option", Opt); |
| 13184 |
end if; |
| 13185 |
else |
| 13186 |
SPARK_Msg_N ("invalid state option", Opt); |
| 13187 |
end if; |
| 13188 |
|
| 13189 |
Next (Opt); |
| 13190 |
end loop; |
| 13191 |
|
| 13192 |
-- Any other attempt to declare a state is illegal |
| 13193 |
|
| 13194 |
else |
| 13195 |
Malformed_State_Error (State); |
| 13196 |
return; |
| 13197 |
end if; |
| 13198 |
|
| 13199 |
-- Guard against a junk state. In such cases no entity is |
| 13200 |
-- generated and the subsequent checks cannot be applied. |
| 13201 |
|
| 13202 |
if Present (State_Id) then |
| 13203 |
|
| 13204 |
-- Verify whether the state does not introduce an illegal |
| 13205 |
-- hidden state within a package subject to a null abstract |
| 13206 |
-- state. |
| 13207 |
|
| 13208 |
Check_No_Hidden_State (State_Id); |
| 13209 |
|
| 13210 |
-- Check whether the lack of option Part_Of agrees with the |
| 13211 |
-- placement of the abstract state with respect to the state |
| 13212 |
-- space. |
| 13213 |
|
| 13214 |
if not Part_Of_Seen then |
| 13215 |
Check_Missing_Part_Of (State_Id); |
| 13216 |
end if; |
| 13217 |
|
| 13218 |
-- Associate the state with its related package |
| 13219 |
|
| 13220 |
if No (Abstract_States (Pack_Id)) then |
| 13221 |
Set_Abstract_States (Pack_Id, New_Elmt_List); |
| 13222 |
end if; |
| 13223 |
|
| 13224 |
Append_Elmt (State_Id, Abstract_States (Pack_Id)); |
| 13225 |
end if; |
| 13226 |
end Analyze_Abstract_State; |
| 13227 |
|
| 13228 |
--------------------------- |
| 13229 |
-- Malformed_State_Error -- |
| 13230 |
--------------------------- |
| 13231 |
|
| 13232 |
procedure Malformed_State_Error (State : Node_Id) is |
| 13233 |
begin |
| 13234 |
Error_Msg_N ("malformed abstract state declaration", State); |
| 13235 |
|
| 13236 |
-- An abstract state with a simple option is being declared |
| 13237 |
-- with "=>" rather than the legal "with". The state appears |
| 13238 |
-- as a component association. |
| 13239 |
|
| 13240 |
if Nkind (State) = N_Component_Association then |
| 13241 |
Error_Msg_N ("\use WITH to specify simple option", State); |
| 13242 |
end if; |
| 13243 |
end Malformed_State_Error; |
| 13244 |
|
| 13245 |
-- Local variables |
| 13246 |
|
| 13247 |
Pack_Decl : Node_Id; |
| 13248 |
Pack_Id : Entity_Id; |
| 13249 |
State : Node_Id; |
| 13250 |
States : Node_Id; |
| 13251 |
|
| 13252 |
-- Start of processing for Abstract_State |
| 13253 |
|
| 13254 |
begin |
| 13255 |
GNAT_Pragma; |
| 13256 |
Check_No_Identifiers; |
| 13257 |
Check_Arg_Count (1); |
| 13258 |
|
| 13259 |
Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
| 13260 |
|
| 13261 |
if Nkind (Pack_Decl) not in |
| 13262 |
N_Generic_Package_Declaration | N_Package_Declaration |
| 13263 |
then |
| 13264 |
Pragma_Misplaced; |
| 13265 |
end if; |
| 13266 |
|
| 13267 |
Pack_Id := Defining_Entity (Pack_Decl); |
| 13268 |
|
| 13269 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 13270 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 13271 |
|
| 13272 |
Mark_Ghost_Pragma (N, Pack_Id); |
| 13273 |
Ensure_Aggregate_Form (Get_Argument (N, Pack_Id)); |
| 13274 |
|
| 13275 |
-- Chain the pragma on the contract for completeness |
| 13276 |
|
| 13277 |
Add_Contract_Item (N, Pack_Id); |
| 13278 |
|
| 13279 |
-- The legality checks of pragmas Abstract_State, Initializes, and |
| 13280 |
-- Initial_Condition are affected by the SPARK mode in effect. In |
| 13281 |
-- addition, these three pragmas are subject to an inherent order: |
| 13282 |
|
| 13283 |
-- 1) Abstract_State |
| 13284 |
-- 2) Initializes |
| 13285 |
-- 3) Initial_Condition |
| 13286 |
|
| 13287 |
-- Analyze all these pragmas in the order outlined above |
| 13288 |
|
| 13289 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 13290 |
States := Expression (Get_Argument (N, Pack_Id)); |
| 13291 |
|
| 13292 |
-- Multiple non-null abstract states appear as an aggregate |
| 13293 |
|
| 13294 |
if Nkind (States) = N_Aggregate then |
| 13295 |
State := First (Expressions (States)); |
| 13296 |
while Present (State) loop |
| 13297 |
Analyze_Abstract_State (State, Pack_Id); |
| 13298 |
Next (State); |
| 13299 |
end loop; |
| 13300 |
|
| 13301 |
-- An abstract state with a simple option is being illegaly |
| 13302 |
-- declared with "=>" rather than "with". In this case the |
| 13303 |
-- state declaration appears as a component association. |
| 13304 |
|
| 13305 |
if Present (Component_Associations (States)) then |
| 13306 |
State := First (Component_Associations (States)); |
| 13307 |
while Present (State) loop |
| 13308 |
Malformed_State_Error (State); |
| 13309 |
Next (State); |
| 13310 |
end loop; |
| 13311 |
end if; |
| 13312 |
|
| 13313 |
-- Various forms of a single abstract state. Note that these may |
| 13314 |
-- include malformed state declarations. |
| 13315 |
|
| 13316 |
else |
| 13317 |
Analyze_Abstract_State (States, Pack_Id); |
| 13318 |
end if; |
| 13319 |
|
| 13320 |
Analyze_If_Present (Pragma_Initializes); |
| 13321 |
Analyze_If_Present (Pragma_Initial_Condition); |
| 13322 |
end Abstract_State; |
| 13323 |
|
| 13324 |
------------ |
| 13325 |
-- Ada_83 -- |
| 13326 |
------------ |
| 13327 |
|
| 13328 |
-- pragma Ada_83; |
| 13329 |
|
| 13330 |
-- Note: this pragma also has some specific processing in Par.Prag |
| 13331 |
-- because we want to set the Ada version mode during parsing. |
| 13332 |
|
| 13333 |
when Pragma_Ada_83 => |
| 13334 |
GNAT_Pragma; |
| 13335 |
Check_Arg_Count (0); |
| 13336 |
|
| 13337 |
-- We really should check unconditionally for proper configuration |
| 13338 |
-- pragma placement, since we really don't want mixed Ada modes |
| 13339 |
-- within a single unit, and the GNAT reference manual has always |
| 13340 |
-- said this was a configuration pragma, but we did not check and |
| 13341 |
-- are hesitant to add the check now. |
| 13342 |
|
| 13343 |
-- However, we really cannot tolerate mixing Ada 2005 or Ada 2012 |
| 13344 |
-- with Ada 83 or Ada 95, so we must check if we are in Ada 2005 |
| 13345 |
-- or Ada 2012 mode. |
| 13346 |
|
| 13347 |
if Ada_Version >= Ada_2005 then |
| 13348 |
Check_Valid_Configuration_Pragma; |
| 13349 |
end if; |
| 13350 |
|
| 13351 |
-- Now set Ada 83 mode |
| 13352 |
|
| 13353 |
if Latest_Ada_Only then |
| 13354 |
Error_Pragma ("??pragma% ignored"); |
| 13355 |
else |
| 13356 |
Ada_Version := Ada_83; |
| 13357 |
Ada_Version_Explicit := Ada_83; |
| 13358 |
Ada_Version_Pragma := N; |
| 13359 |
end if; |
| 13360 |
|
| 13361 |
------------ |
| 13362 |
-- Ada_95 -- |
| 13363 |
------------ |
| 13364 |
|
| 13365 |
-- pragma Ada_95; |
| 13366 |
|
| 13367 |
-- Note: this pragma also has some specific processing in Par.Prag |
| 13368 |
-- because we want to set the Ada 83 version mode during parsing. |
| 13369 |
|
| 13370 |
when Pragma_Ada_95 => |
| 13371 |
GNAT_Pragma; |
| 13372 |
Check_Arg_Count (0); |
| 13373 |
|
| 13374 |
-- We really should check unconditionally for proper configuration |
| 13375 |
-- pragma placement, since we really don't want mixed Ada modes |
| 13376 |
-- within a single unit, and the GNAT reference manual has always |
| 13377 |
-- said this was a configuration pragma, but we did not check and |
| 13378 |
-- are hesitant to add the check now. |
| 13379 |
|
| 13380 |
-- However, we really cannot tolerate mixing Ada 2005 with Ada 83 |
| 13381 |
-- or Ada 95, so we must check if we are in Ada 2005 mode. |
| 13382 |
|
| 13383 |
if Ada_Version >= Ada_2005 then |
| 13384 |
Check_Valid_Configuration_Pragma; |
| 13385 |
end if; |
| 13386 |
|
| 13387 |
-- Now set Ada 95 mode |
| 13388 |
|
| 13389 |
if Latest_Ada_Only then |
| 13390 |
Error_Pragma ("??pragma% ignored"); |
| 13391 |
else |
| 13392 |
Ada_Version := Ada_95; |
| 13393 |
Ada_Version_Explicit := Ada_95; |
| 13394 |
Ada_Version_Pragma := N; |
| 13395 |
end if; |
| 13396 |
|
| 13397 |
--------------------- |
| 13398 |
-- Ada_05/Ada_2005 -- |
| 13399 |
--------------------- |
| 13400 |
|
| 13401 |
-- pragma Ada_05; |
| 13402 |
-- pragma Ada_05 (LOCAL_NAME); |
| 13403 |
|
| 13404 |
-- pragma Ada_2005; |
| 13405 |
-- pragma Ada_2005 (LOCAL_NAME): |
| 13406 |
|
| 13407 |
-- Note: these pragmas also have some specific processing in Par.Prag |
| 13408 |
-- because we want to set the Ada 2005 version mode during parsing. |
| 13409 |
|
| 13410 |
-- The one argument form is used for managing the transition from |
| 13411 |
-- Ada 95 to Ada 2005 in the run-time library. If an entity is marked |
| 13412 |
-- as Ada_2005 only, then referencing the entity in Ada_83 or Ada_95 |
| 13413 |
-- mode will generate a warning. In addition, in Ada_83 or Ada_95 |
| 13414 |
-- mode, a preference rule is established which does not choose |
| 13415 |
-- such an entity unless it is unambiguously specified. This avoids |
| 13416 |
-- extra subprograms marked this way from generating ambiguities in |
| 13417 |
-- otherwise legal pre-Ada_2005 programs. The one argument form is |
| 13418 |
-- intended for exclusive use in the GNAT run-time library. |
| 13419 |
|
| 13420 |
when Pragma_Ada_05 |
| 13421 |
| Pragma_Ada_2005 |
| 13422 |
=> |
| 13423 |
declare |
| 13424 |
E_Id : Node_Id; |
| 13425 |
|
| 13426 |
begin |
| 13427 |
GNAT_Pragma; |
| 13428 |
|
| 13429 |
if Arg_Count = 1 then |
| 13430 |
Check_Arg_Is_Local_Name (Arg1); |
| 13431 |
E_Id := Get_Pragma_Arg (Arg1); |
| 13432 |
|
| 13433 |
if Etype (E_Id) = Any_Type then |
| 13434 |
return; |
| 13435 |
end if; |
| 13436 |
|
| 13437 |
Set_Is_Ada_2005_Only (Entity (E_Id)); |
| 13438 |
Record_Rep_Item (Entity (E_Id), N); |
| 13439 |
|
| 13440 |
else |
| 13441 |
Check_Arg_Count (0); |
| 13442 |
|
| 13443 |
-- For Ada_2005 we unconditionally enforce the documented |
| 13444 |
-- configuration pragma placement, since we do not want to |
| 13445 |
-- tolerate mixed modes in a unit involving Ada 2005. That |
| 13446 |
-- would cause real difficulties for those cases where there |
| 13447 |
-- are incompatibilities between Ada 95 and Ada 2005. |
| 13448 |
|
| 13449 |
Check_Valid_Configuration_Pragma; |
| 13450 |
|
| 13451 |
-- Now set appropriate Ada mode |
| 13452 |
|
| 13453 |
if Latest_Ada_Only then |
| 13454 |
Error_Pragma ("??pragma% ignored"); |
| 13455 |
else |
| 13456 |
Ada_Version := Ada_2005; |
| 13457 |
Ada_Version_Explicit := Ada_2005; |
| 13458 |
Ada_Version_Pragma := N; |
| 13459 |
end if; |
| 13460 |
end if; |
| 13461 |
end; |
| 13462 |
|
| 13463 |
--------------------- |
| 13464 |
-- Ada_12/Ada_2012 -- |
| 13465 |
--------------------- |
| 13466 |
|
| 13467 |
-- pragma Ada_12; |
| 13468 |
-- pragma Ada_12 (LOCAL_NAME); |
| 13469 |
|
| 13470 |
-- pragma Ada_2012; |
| 13471 |
-- pragma Ada_2012 (LOCAL_NAME): |
| 13472 |
|
| 13473 |
-- Note: these pragmas also have some specific processing in Par.Prag |
| 13474 |
-- because we want to set the Ada 2012 version mode during parsing. |
| 13475 |
|
| 13476 |
-- The one argument form is used for managing the transition from Ada |
| 13477 |
-- 2005 to Ada 2012 in the run-time library. If an entity is marked |
| 13478 |
-- as Ada_2012 only, then referencing the entity in any pre-Ada_2012 |
| 13479 |
-- mode will generate a warning. In addition, in any pre-Ada_2012 |
| 13480 |
-- mode, a preference rule is established which does not choose |
| 13481 |
-- such an entity unless it is unambiguously specified. This avoids |
| 13482 |
-- extra subprograms marked this way from generating ambiguities in |
| 13483 |
-- otherwise legal pre-Ada_2012 programs. The one argument form is |
| 13484 |
-- intended for exclusive use in the GNAT run-time library. |
| 13485 |
|
| 13486 |
when Pragma_Ada_12 |
| 13487 |
| Pragma_Ada_2012 |
| 13488 |
=> |
| 13489 |
declare |
| 13490 |
E_Id : Node_Id; |
| 13491 |
|
| 13492 |
begin |
| 13493 |
GNAT_Pragma; |
| 13494 |
|
| 13495 |
if Arg_Count = 1 then |
| 13496 |
Check_Arg_Is_Local_Name (Arg1); |
| 13497 |
E_Id := Get_Pragma_Arg (Arg1); |
| 13498 |
|
| 13499 |
if Etype (E_Id) = Any_Type then |
| 13500 |
return; |
| 13501 |
end if; |
| 13502 |
|
| 13503 |
Set_Is_Ada_2012_Only (Entity (E_Id)); |
| 13504 |
Record_Rep_Item (Entity (E_Id), N); |
| 13505 |
|
| 13506 |
else |
| 13507 |
Check_Arg_Count (0); |
| 13508 |
|
| 13509 |
-- For Ada_2012 we unconditionally enforce the documented |
| 13510 |
-- configuration pragma placement, since we do not want to |
| 13511 |
-- tolerate mixed modes in a unit involving Ada 2012. That |
| 13512 |
-- would cause real difficulties for those cases where there |
| 13513 |
-- are incompatibilities between Ada 95 and Ada 2012. We could |
| 13514 |
-- allow mixing of Ada 2005 and Ada 2012 but it's not worth it. |
| 13515 |
|
| 13516 |
Check_Valid_Configuration_Pragma; |
| 13517 |
|
| 13518 |
-- Now set appropriate Ada mode |
| 13519 |
|
| 13520 |
Ada_Version := Ada_2012; |
| 13521 |
Ada_Version_Explicit := Ada_2012; |
| 13522 |
Ada_Version_Pragma := N; |
| 13523 |
end if; |
| 13524 |
end; |
| 13525 |
|
| 13526 |
-------------- |
| 13527 |
-- Ada_2022 -- |
| 13528 |
-------------- |
| 13529 |
|
| 13530 |
-- pragma Ada_2022; |
| 13531 |
-- pragma Ada_2022 (LOCAL_NAME): |
| 13532 |
|
| 13533 |
-- Note: this pragma also has some specific processing in Par.Prag |
| 13534 |
-- because we want to set the Ada 2022 version mode during parsing. |
| 13535 |
|
| 13536 |
-- The one argument form is used for managing the transition from Ada |
| 13537 |
-- 2012 to Ada 2022 in the run-time library. If an entity is marked |
| 13538 |
-- as Ada_2022 only, then referencing the entity in any pre-Ada_2022 |
| 13539 |
-- mode will generate a warning;for calls to Ada_2022 only primitives |
| 13540 |
-- that require overriding an error will be reported. In addition, in |
| 13541 |
-- any pre-Ada_2022 mode, a preference rule is established which does |
| 13542 |
-- not choose such an entity unless it is unambiguously specified. |
| 13543 |
-- This avoids extra subprograms marked this way from generating |
| 13544 |
-- ambiguities in otherwise legal pre-Ada 2022 programs. The one |
| 13545 |
-- argument form is intended for exclusive use in the GNAT run-time |
| 13546 |
-- library. |
| 13547 |
|
| 13548 |
when Pragma_Ada_2022 => |
| 13549 |
declare |
| 13550 |
E_Id : Node_Id; |
| 13551 |
|
| 13552 |
begin |
| 13553 |
GNAT_Pragma; |
| 13554 |
|
| 13555 |
if Arg_Count = 1 then |
| 13556 |
Check_Arg_Is_Local_Name (Arg1); |
| 13557 |
E_Id := Get_Pragma_Arg (Arg1); |
| 13558 |
|
| 13559 |
if Etype (E_Id) = Any_Type then |
| 13560 |
return; |
| 13561 |
end if; |
| 13562 |
|
| 13563 |
Set_Is_Ada_2022_Only (Entity (E_Id)); |
| 13564 |
Record_Rep_Item (Entity (E_Id), N); |
| 13565 |
|
| 13566 |
else |
| 13567 |
Check_Arg_Count (0); |
| 13568 |
|
| 13569 |
-- For Ada_2022 we unconditionally enforce the documented |
| 13570 |
-- configuration pragma placement, since we do not want to |
| 13571 |
-- tolerate mixed modes in a unit involving Ada 2022. That |
| 13572 |
-- would cause real difficulties for those cases where there |
| 13573 |
-- are incompatibilities between Ada 2012 and Ada 2022. We |
| 13574 |
-- could allow mixing of Ada 2012 and Ada 2022 but it's not |
| 13575 |
-- worth it. |
| 13576 |
|
| 13577 |
Check_Valid_Configuration_Pragma; |
| 13578 |
|
| 13579 |
-- Now set appropriate Ada mode |
| 13580 |
|
| 13581 |
Ada_Version := Ada_2022; |
| 13582 |
Ada_Version_Explicit := Ada_2022; |
| 13583 |
Ada_Version_Pragma := N; |
| 13584 |
end if; |
| 13585 |
end; |
| 13586 |
|
| 13587 |
------------------------------------- |
| 13588 |
-- Aggregate_Individually_Assign -- |
| 13589 |
------------------------------------- |
| 13590 |
|
| 13591 |
-- pragma Aggregate_Individually_Assign; |
| 13592 |
|
| 13593 |
when Pragma_Aggregate_Individually_Assign => |
| 13594 |
GNAT_Pragma; |
| 13595 |
Check_Arg_Count (0); |
| 13596 |
Check_Valid_Configuration_Pragma; |
| 13597 |
Aggregate_Individually_Assign := True; |
| 13598 |
|
| 13599 |
---------------------- |
| 13600 |
-- All_Calls_Remote -- |
| 13601 |
---------------------- |
| 13602 |
|
| 13603 |
-- pragma All_Calls_Remote [(library_package_NAME)]; |
| 13604 |
|
| 13605 |
when Pragma_All_Calls_Remote => All_Calls_Remote : declare |
| 13606 |
Lib_Entity : Entity_Id; |
| 13607 |
|
| 13608 |
begin |
| 13609 |
Check_Ada_83_Warning; |
| 13610 |
Check_Valid_Library_Unit_Pragma; |
| 13611 |
|
| 13612 |
-- If N was rewritten as a null statement there is nothing more |
| 13613 |
-- to do. |
| 13614 |
|
| 13615 |
if Nkind (N) = N_Null_Statement then |
| 13616 |
return; |
| 13617 |
end if; |
| 13618 |
|
| 13619 |
Lib_Entity := Find_Lib_Unit_Name; |
| 13620 |
|
| 13621 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 13622 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 13623 |
|
| 13624 |
Mark_Ghost_Pragma (N, Lib_Entity); |
| 13625 |
|
| 13626 |
-- This pragma should only apply to a RCI unit (RM E.2.3(23)) |
| 13627 |
|
| 13628 |
if Present (Lib_Entity) and then not Debug_Flag_U then |
| 13629 |
if not Is_Remote_Call_Interface (Lib_Entity) then |
| 13630 |
Error_Pragma ("pragma% only apply to rci unit"); |
| 13631 |
|
| 13632 |
-- Set flag for entity of the library unit |
| 13633 |
|
| 13634 |
else |
| 13635 |
Set_Has_All_Calls_Remote (Lib_Entity); |
| 13636 |
end if; |
| 13637 |
end if; |
| 13638 |
end All_Calls_Remote; |
| 13639 |
|
| 13640 |
--------------------------- |
| 13641 |
-- Allow_Integer_Address -- |
| 13642 |
--------------------------- |
| 13643 |
|
| 13644 |
-- pragma Allow_Integer_Address; |
| 13645 |
|
| 13646 |
when Pragma_Allow_Integer_Address => |
| 13647 |
GNAT_Pragma; |
| 13648 |
Check_Valid_Configuration_Pragma; |
| 13649 |
Check_Arg_Count (0); |
| 13650 |
|
| 13651 |
-- If Address is a private type, then set the flag to allow |
| 13652 |
-- integer address values. If Address is not private, then this |
| 13653 |
-- pragma has no purpose, so it is simply ignored. Not clear if |
| 13654 |
-- there are any such targets now. |
| 13655 |
|
| 13656 |
if Opt.Address_Is_Private then |
| 13657 |
Opt.Allow_Integer_Address := True; |
| 13658 |
end if; |
| 13659 |
|
| 13660 |
----------------------- |
| 13661 |
-- Always_Terminates -- |
| 13662 |
----------------------- |
| 13663 |
|
| 13664 |
-- pragma Always_Terminates [ (boolean_EXPRESSION) ]; |
| 13665 |
|
| 13666 |
-- Characteristics: |
| 13667 |
|
| 13668 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 13669 |
-- the legal placement and context. Secondary checks preanalyze the |
| 13670 |
-- expressions in: |
| 13671 |
|
| 13672 |
-- Analyze_Always_Terminates_Cases_In_Decl_Part |
| 13673 |
|
| 13674 |
-- * Expansion - The annotation is expanded during the expansion of |
| 13675 |
-- the related subprogram [body] contract as performed in: |
| 13676 |
|
| 13677 |
-- Expand_Subprogram_Contract |
| 13678 |
|
| 13679 |
-- * Template - The annotation utilizes the generic template of the |
| 13680 |
-- related subprogram [body] when it is: |
| 13681 |
|
| 13682 |
-- aspect on subprogram declaration |
| 13683 |
-- aspect on stand-alone subprogram body |
| 13684 |
-- pragma on stand-alone subprogram body |
| 13685 |
|
| 13686 |
-- The annotation must prepare its own template when it is: |
| 13687 |
|
| 13688 |
-- pragma on subprogram declaration |
| 13689 |
|
| 13690 |
-- * Globals - Capture of global references must occur after full |
| 13691 |
-- analysis. |
| 13692 |
|
| 13693 |
-- * Instance - The annotation is instantiated automatically when |
| 13694 |
-- the related generic subprogram [body] is instantiated except for |
| 13695 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 13696 |
-- the annotation must instantiate itself. |
| 13697 |
|
| 13698 |
when Pragma_Always_Terminates => Always_Terminates : declare |
| 13699 |
Spec_Id : Entity_Id; |
| 13700 |
Subp_Decl : Node_Id; |
| 13701 |
Subp_Spec : Node_Id; |
| 13702 |
|
| 13703 |
begin |
| 13704 |
GNAT_Pragma; |
| 13705 |
Check_No_Identifiers; |
| 13706 |
Check_At_Most_N_Arguments (1); |
| 13707 |
|
| 13708 |
-- Ensure the proper placement of the pragma. Always_Terminates |
| 13709 |
-- must be associated with a subprogram declaration or a body that |
| 13710 |
-- acts as a spec. |
| 13711 |
|
| 13712 |
Subp_Decl := |
| 13713 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 13714 |
|
| 13715 |
-- Generic subprogram and package declaration |
| 13716 |
|
| 13717 |
if Nkind (Subp_Decl) in N_Generic_Declaration then |
| 13718 |
null; |
| 13719 |
|
| 13720 |
-- Package declaration |
| 13721 |
|
| 13722 |
elsif Nkind (Subp_Decl) = N_Package_Declaration then |
| 13723 |
null; |
| 13724 |
|
| 13725 |
-- Body acts as spec |
| 13726 |
|
| 13727 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 13728 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 13729 |
then |
| 13730 |
null; |
| 13731 |
|
| 13732 |
-- Body stub acts as spec |
| 13733 |
|
| 13734 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 13735 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 13736 |
then |
| 13737 |
null; |
| 13738 |
|
| 13739 |
-- Subprogram |
| 13740 |
|
| 13741 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 13742 |
Subp_Spec := Specification (Subp_Decl); |
| 13743 |
|
| 13744 |
-- Pragma Always_Terminates is forbidden on null procedures, |
| 13745 |
-- as this may lead to potential ambiguities in behavior |
| 13746 |
-- when interface null procedures are involved. Also, it |
| 13747 |
-- just wouldn't make sense, because null procedures always |
| 13748 |
-- terminate anyway. |
| 13749 |
|
| 13750 |
if Nkind (Subp_Spec) = N_Procedure_Specification |
| 13751 |
and then Null_Present (Subp_Spec) |
| 13752 |
then |
| 13753 |
Error_Msg_N (Fix_Error |
| 13754 |
("pragma % cannot apply to null procedure"), N); |
| 13755 |
return; |
| 13756 |
end if; |
| 13757 |
|
| 13758 |
-- Entry |
| 13759 |
|
| 13760 |
elsif Nkind (Subp_Decl) = N_Entry_Declaration then |
| 13761 |
null; |
| 13762 |
|
| 13763 |
else |
| 13764 |
Pragma_Misplaced; |
| 13765 |
end if; |
| 13766 |
|
| 13767 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 13768 |
|
| 13769 |
-- In order to call Is_Function_With_Side_Effects, analyze pragma |
| 13770 |
-- Side_Effects if present. |
| 13771 |
|
| 13772 |
Analyze_If_Present (Pragma_Side_Effects); |
| 13773 |
|
| 13774 |
-- Pragma Always_Terminates is not allowed on functions without |
| 13775 |
-- side effects. |
| 13776 |
|
| 13777 |
if Ekind (Spec_Id) in E_Function | E_Generic_Function |
| 13778 |
and then not Is_Function_With_Side_Effects (Spec_Id) |
| 13779 |
then |
| 13780 |
Error_Msg_Code := GEC_Always_Terminates_On_Function; |
| 13781 |
|
| 13782 |
if Ekind (Spec_Id) = E_Function then |
| 13783 |
Error_Msg_N (Fix_Error |
| 13784 |
("pragma % cannot apply to function '[[]']"), N); |
| 13785 |
return; |
| 13786 |
|
| 13787 |
elsif Ekind (Spec_Id) = E_Generic_Function then |
| 13788 |
Error_Msg_N (Fix_Error |
| 13789 |
("pragma % cannot apply to generic function '[[]']"), N); |
| 13790 |
return; |
| 13791 |
end if; |
| 13792 |
end if; |
| 13793 |
|
| 13794 |
-- Pragma Always_Terminates applied to packages doesn't allow any |
| 13795 |
-- expression. |
| 13796 |
|
| 13797 |
if Is_Package_Or_Generic_Package (Spec_Id) |
| 13798 |
and then Arg_Count /= 0 |
| 13799 |
then |
| 13800 |
Error_Msg_N (Fix_Error |
| 13801 |
("pragma % applied to package cannot have arguments"), N); |
| 13802 |
return; |
| 13803 |
end if; |
| 13804 |
|
| 13805 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 13806 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 13807 |
|
| 13808 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 13809 |
|
| 13810 |
-- Chain the pragma on the contract for further processing by |
| 13811 |
-- Analyze_Always_Terminates_In_Decl_Part. |
| 13812 |
|
| 13813 |
Add_Contract_Item (N, Defining_Entity (Subp_Decl)); |
| 13814 |
|
| 13815 |
-- Fully analyze the pragma when it appears inside a subprogram |
| 13816 |
-- body because it cannot benefit from forward references. |
| 13817 |
|
| 13818 |
if Nkind (Subp_Decl) in N_Subprogram_Body |
| 13819 |
| N_Subprogram_Body_Stub |
| 13820 |
then |
| 13821 |
-- The legality checks of pragma Always_Terminates are affected |
| 13822 |
-- by the SPARK mode in effect and the volatility of the |
| 13823 |
-- context. Analyze all pragmas in a specific order. |
| 13824 |
|
| 13825 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 13826 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 13827 |
Analyze_Always_Terminates_In_Decl_Part (N); |
| 13828 |
end if; |
| 13829 |
end Always_Terminates; |
| 13830 |
|
| 13831 |
-------------- |
| 13832 |
-- Annotate -- |
| 13833 |
-------------- |
| 13834 |
|
| 13835 |
-- pragma Annotate |
| 13836 |
-- (IDENTIFIER [, IDENTIFIER {, ARG}] [,Entity => local_NAME]); |
| 13837 |
-- ARG ::= NAME | EXPRESSION |
| 13838 |
|
| 13839 |
-- The first two arguments are by convention intended to refer to an |
| 13840 |
-- external tool and a tool-specific function. These arguments are |
| 13841 |
-- not analyzed. |
| 13842 |
|
| 13843 |
when Pragma_Annotate | Pragma_GNAT_Annotate => Annotate : declare |
| 13844 |
Arg : Node_Id; |
| 13845 |
Expr : Node_Id; |
| 13846 |
Nam_Arg : Node_Id; |
| 13847 |
|
| 13848 |
-------------------------- |
| 13849 |
-- Inferred_String_Type -- |
| 13850 |
-------------------------- |
| 13851 |
|
| 13852 |
function Preferred_String_Type (Expr : Node_Id) return Entity_Id; |
| 13853 |
-- Infer the type to use for a string literal or a concatentation |
| 13854 |
-- of operands whose types can be inferred. For such expressions, |
| 13855 |
-- returns the "narrowest" of the three predefined string types |
| 13856 |
-- that can represent the characters occurring in the expression. |
| 13857 |
-- For other expressions, returns Empty. |
| 13858 |
|
| 13859 |
function Preferred_String_Type (Expr : Node_Id) return Entity_Id is |
| 13860 |
begin |
| 13861 |
case Nkind (Expr) is |
| 13862 |
when N_String_Literal => |
| 13863 |
if Has_Wide_Wide_Character (Expr) then |
| 13864 |
return Standard_Wide_Wide_String; |
| 13865 |
elsif Has_Wide_Character (Expr) then |
| 13866 |
return Standard_Wide_String; |
| 13867 |
else |
| 13868 |
return Standard_String; |
| 13869 |
end if; |
| 13870 |
|
| 13871 |
when N_Op_Concat => |
| 13872 |
declare |
| 13873 |
L_Type : constant Entity_Id := |
| 13874 |
Preferred_String_Type (Left_Opnd (Expr)); |
| 13875 |
R_Type : constant Entity_Id := |
| 13876 |
Preferred_String_Type (Right_Opnd (Expr)); |
| 13877 |
|
| 13878 |
Type_Table : constant array (1 .. 4) of Entity_Id := |
| 13879 |
(Empty, |
| 13880 |
Standard_Wide_Wide_String, |
| 13881 |
Standard_Wide_String, |
| 13882 |
Standard_String); |
| 13883 |
begin |
| 13884 |
for Idx in Type_Table'Range loop |
| 13885 |
if L_Type = Type_Table (Idx) or |
| 13886 |
R_Type = Type_Table (Idx) |
| 13887 |
then |
| 13888 |
return Type_Table (Idx); |
| 13889 |
end if; |
| 13890 |
end loop; |
| 13891 |
raise Program_Error; |
| 13892 |
end; |
| 13893 |
|
| 13894 |
when others => |
| 13895 |
return Empty; |
| 13896 |
end case; |
| 13897 |
end Preferred_String_Type; |
| 13898 |
begin |
| 13899 |
GNAT_Pragma; |
| 13900 |
Check_At_Least_N_Arguments (1); |
| 13901 |
|
| 13902 |
Nam_Arg := Last (Pragma_Argument_Associations (N)); |
| 13903 |
|
| 13904 |
-- Determine whether the last argument is "Entity => local_NAME" |
| 13905 |
-- and if it is, perform the required semantic checks. Remove the |
| 13906 |
-- argument from further processing. |
| 13907 |
|
| 13908 |
if Nkind (Nam_Arg) = N_Pragma_Argument_Association |
| 13909 |
and then Chars (Nam_Arg) = Name_Entity |
| 13910 |
then |
| 13911 |
Check_Arg_Is_Local_Name (Nam_Arg); |
| 13912 |
Arg_Count := Arg_Count - 1; |
| 13913 |
|
| 13914 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 13915 |
-- the purposes of legality checks and removal of ignored Ghost |
| 13916 |
-- code. |
| 13917 |
|
| 13918 |
if Is_Entity_Name (Get_Pragma_Arg (Nam_Arg)) |
| 13919 |
and then Present (Entity (Get_Pragma_Arg (Nam_Arg))) |
| 13920 |
then |
| 13921 |
Mark_Ghost_Pragma (N, Entity (Get_Pragma_Arg (Nam_Arg))); |
| 13922 |
end if; |
| 13923 |
end if; |
| 13924 |
|
| 13925 |
-- Continue the processing with last argument removed for now |
| 13926 |
|
| 13927 |
Check_Arg_Is_Identifier (Arg1); |
| 13928 |
Check_No_Identifiers; |
| 13929 |
Store_Note (N); |
| 13930 |
|
| 13931 |
-- The second parameter is optional, it is never analyzed |
| 13932 |
|
| 13933 |
if No (Arg2) then |
| 13934 |
null; |
| 13935 |
|
| 13936 |
-- Otherwise there is a second parameter |
| 13937 |
|
| 13938 |
else |
| 13939 |
-- The second parameter must be an identifier |
| 13940 |
|
| 13941 |
Check_Arg_Is_Identifier (Arg2); |
| 13942 |
|
| 13943 |
-- Process the remaining parameters (if any) |
| 13944 |
|
| 13945 |
Arg := Next (Arg2); |
| 13946 |
while Present (Arg) loop |
| 13947 |
Expr := Get_Pragma_Arg (Arg); |
| 13948 |
Analyze (Expr); |
| 13949 |
|
| 13950 |
if Is_Entity_Name (Expr) then |
| 13951 |
null; |
| 13952 |
|
| 13953 |
-- For string literals and concatenations of string literals |
| 13954 |
-- we assume Standard_String as the type, unless the string |
| 13955 |
-- contains wide or wide_wide characters. |
| 13956 |
|
| 13957 |
elsif Present (Preferred_String_Type (Expr)) then |
| 13958 |
Resolve (Expr, Preferred_String_Type (Expr)); |
| 13959 |
|
| 13960 |
elsif Is_Overloaded (Expr) then |
| 13961 |
Error_Pragma_Arg ("ambiguous argument for pragma%", Expr); |
| 13962 |
|
| 13963 |
else |
| 13964 |
Resolve (Expr); |
| 13965 |
end if; |
| 13966 |
|
| 13967 |
Next (Arg); |
| 13968 |
end loop; |
| 13969 |
end if; |
| 13970 |
end Annotate; |
| 13971 |
|
| 13972 |
------------------------------------------------- |
| 13973 |
-- Assert/Assert_And_Cut/Assume/Loop_Invariant -- |
| 13974 |
------------------------------------------------- |
| 13975 |
|
| 13976 |
-- pragma Assert |
| 13977 |
-- ( [Check => ] Boolean_EXPRESSION |
| 13978 |
-- [, [Message =>] Static_String_EXPRESSION]); |
| 13979 |
|
| 13980 |
-- pragma Assert_And_Cut |
| 13981 |
-- ( [Check => ] Boolean_EXPRESSION |
| 13982 |
-- [, [Message =>] Static_String_EXPRESSION]); |
| 13983 |
|
| 13984 |
-- pragma Assume |
| 13985 |
-- ( [Check => ] Boolean_EXPRESSION |
| 13986 |
-- [, [Message =>] Static_String_EXPRESSION]); |
| 13987 |
|
| 13988 |
-- pragma Loop_Invariant |
| 13989 |
-- ( [Check => ] Boolean_EXPRESSION |
| 13990 |
-- [, [Message =>] Static_String_EXPRESSION]); |
| 13991 |
|
| 13992 |
when Pragma_Assert |
| 13993 |
| Pragma_Assert_And_Cut |
| 13994 |
| Pragma_Assume |
| 13995 |
| Pragma_Loop_Invariant |
| 13996 |
=> |
| 13997 |
Assert : declare |
| 13998 |
function Contains_Loop_Entry (Expr : Node_Id) return Boolean; |
| 13999 |
-- Determine whether expression Expr contains a Loop_Entry |
| 14000 |
-- attribute reference. |
| 14001 |
|
| 14002 |
------------------------- |
| 14003 |
-- Contains_Loop_Entry -- |
| 14004 |
------------------------- |
| 14005 |
|
| 14006 |
function Contains_Loop_Entry (Expr : Node_Id) return Boolean is |
| 14007 |
function Process (N : Node_Id) return Traverse_Result; |
| 14008 |
-- Process function for traversal to look for Loop_Entry |
| 14009 |
|
| 14010 |
------------- |
| 14011 |
-- Process -- |
| 14012 |
------------- |
| 14013 |
|
| 14014 |
function Process (N : Node_Id) return Traverse_Result is |
| 14015 |
begin |
| 14016 |
if Is_Attribute_Loop_Entry (N) then |
| 14017 |
return Abandon; |
| 14018 |
else |
| 14019 |
return OK; |
| 14020 |
end if; |
| 14021 |
end Process; |
| 14022 |
|
| 14023 |
function Traverse is new Traverse_Func (Process); |
| 14024 |
|
| 14025 |
-- Start of processing for Contains_Loop_Entry |
| 14026 |
|
| 14027 |
begin |
| 14028 |
return Traverse (Expr) = Abandon; |
| 14029 |
end Contains_Loop_Entry; |
| 14030 |
|
| 14031 |
-- Local variables |
| 14032 |
|
| 14033 |
Expr : Node_Id; |
| 14034 |
New_Args : List_Id; |
| 14035 |
|
| 14036 |
-- Start of processing for Assert |
| 14037 |
|
| 14038 |
begin |
| 14039 |
-- Assert is an Ada 2005 RM-defined pragma |
| 14040 |
|
| 14041 |
if Prag_Id = Pragma_Assert then |
| 14042 |
Ada_2005_Pragma; |
| 14043 |
|
| 14044 |
-- The remaining ones are GNAT pragmas |
| 14045 |
|
| 14046 |
else |
| 14047 |
GNAT_Pragma; |
| 14048 |
end if; |
| 14049 |
|
| 14050 |
Check_At_Least_N_Arguments (1); |
| 14051 |
Check_At_Most_N_Arguments (2); |
| 14052 |
Check_Arg_Order ((Name_Check, Name_Message)); |
| 14053 |
Check_Optional_Identifier (Arg1, Name_Check); |
| 14054 |
Expr := Get_Pragma_Arg (Arg1); |
| 14055 |
|
| 14056 |
-- Special processing for Loop_Invariant, Loop_Variant or for |
| 14057 |
-- other cases where a Loop_Entry attribute is present. If the |
| 14058 |
-- assertion pragma contains attribute Loop_Entry, ensure that |
| 14059 |
-- the related pragma is within a loop. |
| 14060 |
|
| 14061 |
if Prag_Id = Pragma_Loop_Invariant |
| 14062 |
or else Prag_Id = Pragma_Loop_Variant |
| 14063 |
or else Contains_Loop_Entry (Expr) |
| 14064 |
then |
| 14065 |
Check_Loop_Pragma_Placement; |
| 14066 |
|
| 14067 |
-- Perform preanalysis to deal with embedded Loop_Entry |
| 14068 |
-- attributes. |
| 14069 |
|
| 14070 |
Preanalyze_Assert_Expression (Expr, Any_Boolean); |
| 14071 |
end if; |
| 14072 |
|
| 14073 |
-- Implement Assert[_And_Cut]/Assume/Loop_Invariant by generating |
| 14074 |
-- a corresponding Check pragma: |
| 14075 |
|
| 14076 |
-- pragma Check (name, condition [, msg]); |
| 14077 |
|
| 14078 |
-- Where name is the identifier matching the pragma name. So |
| 14079 |
-- rewrite pragma in this manner, transfer the message argument |
| 14080 |
-- if present, and analyze the result |
| 14081 |
|
| 14082 |
-- Note: When dealing with a semantically analyzed tree, the |
| 14083 |
-- information that a Check node N corresponds to a source Assert, |
| 14084 |
-- Assume, or Assert_And_Cut pragma can be retrieved from the |
| 14085 |
-- pragma kind of Original_Node(N). |
| 14086 |
|
| 14087 |
New_Args := New_List ( |
| 14088 |
Make_Pragma_Argument_Association (Loc, |
| 14089 |
Expression => Make_Identifier (Loc, Pname)), |
| 14090 |
Make_Pragma_Argument_Association (Sloc (Expr), |
| 14091 |
Expression => Expr)); |
| 14092 |
|
| 14093 |
if Arg_Count > 1 then |
| 14094 |
Check_Optional_Identifier (Arg2, Name_Message); |
| 14095 |
|
| 14096 |
-- Provide semantic annotations for optional argument, for |
| 14097 |
-- ASIS use, before rewriting. |
| 14098 |
-- Is this still needed??? |
| 14099 |
|
| 14100 |
Preanalyze_And_Resolve (Expression (Arg2), Standard_String); |
| 14101 |
Append_To (New_Args, New_Copy_Tree (Arg2)); |
| 14102 |
end if; |
| 14103 |
|
| 14104 |
-- Rewrite as Check pragma |
| 14105 |
|
| 14106 |
Rewrite (N, |
| 14107 |
Make_Pragma (Loc, |
| 14108 |
Chars => Name_Check, |
| 14109 |
Pragma_Argument_Associations => New_Args)); |
| 14110 |
|
| 14111 |
Analyze (N); |
| 14112 |
end Assert; |
| 14113 |
|
| 14114 |
---------------------- |
| 14115 |
-- Assertion_Policy -- |
| 14116 |
---------------------- |
| 14117 |
|
| 14118 |
-- pragma Assertion_Policy (POLICY_IDENTIFIER); |
| 14119 |
|
| 14120 |
-- The following form is Ada 2012 only, but we allow it in all modes |
| 14121 |
|
| 14122 |
-- Pragma Assertion_Policy ( |
| 14123 |
-- ASSERTION_KIND => POLICY_IDENTIFIER |
| 14124 |
-- {, ASSERTION_KIND => POLICY_IDENTIFIER}); |
| 14125 |
|
| 14126 |
-- ASSERTION_KIND ::= RM_ASSERTION_KIND | ID_ASSERTION_KIND |
| 14127 |
|
| 14128 |
-- RM_ASSERTION_KIND ::= Assert | |
| 14129 |
-- Static_Predicate | |
| 14130 |
-- Dynamic_Predicate | |
| 14131 |
-- Pre | |
| 14132 |
-- Pre'Class | |
| 14133 |
-- Post | |
| 14134 |
-- Post'Class | |
| 14135 |
-- Type_Invariant | |
| 14136 |
-- Type_Invariant'Class | |
| 14137 |
-- Default_Initial_Condition |
| 14138 |
|
| 14139 |
-- ID_ASSERTION_KIND ::= Assert_And_Cut | |
| 14140 |
-- Assume | |
| 14141 |
-- Contract_Cases | |
| 14142 |
-- Debug | |
| 14143 |
-- Ghost | |
| 14144 |
-- Initial_Condition | |
| 14145 |
-- Loop_Invariant | |
| 14146 |
-- Loop_Variant | |
| 14147 |
-- Postcondition | |
| 14148 |
-- Precondition | |
| 14149 |
-- Predicate | |
| 14150 |
-- Refined_Post | |
| 14151 |
-- Statement_Assertions | |
| 14152 |
-- Subprogram_Variant |
| 14153 |
|
| 14154 |
-- Note: The RM_ASSERTION_KIND list is language-defined, and the |
| 14155 |
-- ID_ASSERTION_KIND list contains implementation-defined additions |
| 14156 |
-- recognized by GNAT. The effect is to control the behavior of |
| 14157 |
-- identically named aspects and pragmas, depending on the specified |
| 14158 |
-- policy identifier: |
| 14159 |
|
| 14160 |
-- POLICY_IDENTIFIER ::= Check | Disable | Ignore | Suppressible |
| 14161 |
|
| 14162 |
-- Note: Check and Ignore are language-defined. Disable is a GNAT |
| 14163 |
-- implementation-defined addition that results in totally ignoring |
| 14164 |
-- the corresponding assertion. If Disable is specified, then the |
| 14165 |
-- argument of the assertion is not even analyzed. This is useful |
| 14166 |
-- when the aspect/pragma argument references entities in a with'ed |
| 14167 |
-- package that is replaced by a dummy package in the final build. |
| 14168 |
|
| 14169 |
-- Note: the attribute forms Pre'Class, Post'Class, Invariant'Class, |
| 14170 |
-- and Type_Invariant'Class were recognized by the parser and |
| 14171 |
-- transformed into references to the special internal identifiers |
| 14172 |
-- _Pre, _Post, _Invariant, and _Type_Invariant, so no special |
| 14173 |
-- processing is required here. |
| 14174 |
|
| 14175 |
when Pragma_Assertion_Policy => Assertion_Policy : declare |
| 14176 |
procedure Resolve_Suppressible (Policy : Node_Id); |
| 14177 |
-- Converts the assertion policy 'Suppressible' to either Check or |
| 14178 |
-- Ignore based on whether checks are suppressed via -gnatp. |
| 14179 |
|
| 14180 |
-------------------------- |
| 14181 |
-- Resolve_Suppressible -- |
| 14182 |
-------------------------- |
| 14183 |
|
| 14184 |
procedure Resolve_Suppressible (Policy : Node_Id) is |
| 14185 |
Arg : constant Node_Id := Get_Pragma_Arg (Policy); |
| 14186 |
Nam : Name_Id; |
| 14187 |
|
| 14188 |
begin |
| 14189 |
-- Transform policy argument Suppressible into either Ignore or |
| 14190 |
-- Check depending on whether checks are enabled or suppressed. |
| 14191 |
|
| 14192 |
if Chars (Arg) = Name_Suppressible then |
| 14193 |
if Suppress_Checks then |
| 14194 |
Nam := Name_Ignore; |
| 14195 |
else |
| 14196 |
Nam := Name_Check; |
| 14197 |
end if; |
| 14198 |
|
| 14199 |
Rewrite (Arg, Make_Identifier (Sloc (Arg), Nam)); |
| 14200 |
end if; |
| 14201 |
end Resolve_Suppressible; |
| 14202 |
|
| 14203 |
-- Local variables |
| 14204 |
|
| 14205 |
Arg : Node_Id; |
| 14206 |
Kind : Name_Id; |
| 14207 |
LocP : Source_Ptr; |
| 14208 |
Policy : Node_Id; |
| 14209 |
|
| 14210 |
begin |
| 14211 |
Ada_2005_Pragma; |
| 14212 |
|
| 14213 |
-- This can always appear as a configuration pragma |
| 14214 |
|
| 14215 |
if Is_Configuration_Pragma then |
| 14216 |
null; |
| 14217 |
|
| 14218 |
-- It can also appear in a declarative part or package spec in Ada |
| 14219 |
-- 2012 mode. We allow this in other modes, but in that case we |
| 14220 |
-- consider that we have an Ada 2012 pragma on our hands. |
| 14221 |
|
| 14222 |
else |
| 14223 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 14224 |
Ada_2012_Pragma; |
| 14225 |
end if; |
| 14226 |
|
| 14227 |
-- One argument case with no identifier (first form above) |
| 14228 |
|
| 14229 |
if Arg_Count = 1 |
| 14230 |
and then (Nkind (Arg1) /= N_Pragma_Argument_Association |
| 14231 |
or else Chars (Arg1) = No_Name) |
| 14232 |
then |
| 14233 |
Check_Arg_Is_One_Of (Arg1, |
| 14234 |
Name_Check, Name_Disable, Name_Ignore, Name_Suppressible); |
| 14235 |
|
| 14236 |
Resolve_Suppressible (Arg1); |
| 14237 |
|
| 14238 |
-- Treat one argument Assertion_Policy as equivalent to: |
| 14239 |
|
| 14240 |
-- pragma Check_Policy (Assertion, policy) |
| 14241 |
|
| 14242 |
-- So rewrite pragma in that manner and link on to the chain |
| 14243 |
-- of Check_Policy pragmas, marking the pragma as analyzed. |
| 14244 |
|
| 14245 |
Policy := Get_Pragma_Arg (Arg1); |
| 14246 |
|
| 14247 |
Rewrite (N, |
| 14248 |
Make_Pragma (Loc, |
| 14249 |
Chars => Name_Check_Policy, |
| 14250 |
Pragma_Argument_Associations => New_List ( |
| 14251 |
Make_Pragma_Argument_Association (Loc, |
| 14252 |
Expression => Make_Identifier (Loc, Name_Assertion)), |
| 14253 |
|
| 14254 |
Make_Pragma_Argument_Association (Loc, |
| 14255 |
Expression => |
| 14256 |
Make_Identifier (Sloc (Policy), Chars (Policy)))))); |
| 14257 |
Analyze (N); |
| 14258 |
|
| 14259 |
-- Here if we have two or more arguments |
| 14260 |
|
| 14261 |
else |
| 14262 |
Check_At_Least_N_Arguments (1); |
| 14263 |
Ada_2012_Pragma; |
| 14264 |
|
| 14265 |
-- Loop through arguments |
| 14266 |
|
| 14267 |
Arg := Arg1; |
| 14268 |
while Present (Arg) loop |
| 14269 |
LocP := Sloc (Arg); |
| 14270 |
|
| 14271 |
-- Kind must be specified |
| 14272 |
|
| 14273 |
if Nkind (Arg) /= N_Pragma_Argument_Association |
| 14274 |
or else Chars (Arg) = No_Name |
| 14275 |
then |
| 14276 |
Error_Pragma_Arg |
| 14277 |
("missing assertion kind for pragma%", Arg); |
| 14278 |
end if; |
| 14279 |
|
| 14280 |
-- Check Kind and Policy have allowed forms |
| 14281 |
|
| 14282 |
Kind := Chars (Arg); |
| 14283 |
Policy := Get_Pragma_Arg (Arg); |
| 14284 |
|
| 14285 |
if not Is_Valid_Assertion_Kind (Kind) then |
| 14286 |
Error_Pragma_Arg |
| 14287 |
("invalid assertion kind for pragma%", Arg); |
| 14288 |
end if; |
| 14289 |
|
| 14290 |
Check_Arg_Is_One_Of (Arg, |
| 14291 |
Name_Check, Name_Disable, Name_Ignore, Name_Suppressible); |
| 14292 |
|
| 14293 |
Resolve_Suppressible (Arg); |
| 14294 |
|
| 14295 |
if Kind = Name_Ghost then |
| 14296 |
|
| 14297 |
-- The Ghost policy must be either Check or Ignore |
| 14298 |
-- (SPARK RM 6.9(6)). |
| 14299 |
|
| 14300 |
if Chars (Policy) not in Name_Check | Name_Ignore then |
| 14301 |
Error_Pragma_Arg |
| 14302 |
("argument of pragma % Ghost must be Check or " |
| 14303 |
& "Ignore", Policy); |
| 14304 |
end if; |
| 14305 |
|
| 14306 |
-- Pragma Assertion_Policy specifying a Ghost policy |
| 14307 |
-- cannot occur within a Ghost subprogram or package |
| 14308 |
-- (SPARK RM 6.9(16)). |
| 14309 |
|
| 14310 |
if Ghost_Mode > None then |
| 14311 |
Error_Pragma |
| 14312 |
("pragma % cannot appear within ghost subprogram or " |
| 14313 |
& "package"); |
| 14314 |
end if; |
| 14315 |
end if; |
| 14316 |
|
| 14317 |
-- Rewrite the Assertion_Policy pragma as a series of |
| 14318 |
-- Check_Policy pragmas of the form: |
| 14319 |
|
| 14320 |
-- Check_Policy (Kind, Policy); |
| 14321 |
|
| 14322 |
-- Note: the insertion of the pragmas cannot be done with |
| 14323 |
-- Insert_Action because in the configuration case, there |
| 14324 |
-- are no scopes on the scope stack and the mechanism will |
| 14325 |
-- fail. |
| 14326 |
|
| 14327 |
Insert_Before_And_Analyze (N, |
| 14328 |
Make_Pragma (LocP, |
| 14329 |
Chars => Name_Check_Policy, |
| 14330 |
Pragma_Argument_Associations => New_List ( |
| 14331 |
Make_Pragma_Argument_Association (LocP, |
| 14332 |
Expression => Make_Identifier (LocP, Kind)), |
| 14333 |
Make_Pragma_Argument_Association (LocP, |
| 14334 |
Expression => Policy)))); |
| 14335 |
|
| 14336 |
Arg := Next (Arg); |
| 14337 |
end loop; |
| 14338 |
|
| 14339 |
-- Rewrite the Assertion_Policy pragma as null since we have |
| 14340 |
-- now inserted all the equivalent Check pragmas. |
| 14341 |
|
| 14342 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 14343 |
Analyze (N); |
| 14344 |
end if; |
| 14345 |
end Assertion_Policy; |
| 14346 |
|
| 14347 |
------------------------------ |
| 14348 |
-- Assume_No_Invalid_Values -- |
| 14349 |
------------------------------ |
| 14350 |
|
| 14351 |
-- pragma Assume_No_Invalid_Values (On | Off); |
| 14352 |
|
| 14353 |
when Pragma_Assume_No_Invalid_Values => |
| 14354 |
GNAT_Pragma; |
| 14355 |
Check_Valid_Configuration_Pragma; |
| 14356 |
Check_Arg_Count (1); |
| 14357 |
Check_No_Identifiers; |
| 14358 |
Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off); |
| 14359 |
|
| 14360 |
if Chars (Get_Pragma_Arg (Arg1)) = Name_On then |
| 14361 |
Assume_No_Invalid_Values := True; |
| 14362 |
else |
| 14363 |
Assume_No_Invalid_Values := False; |
| 14364 |
end if; |
| 14365 |
|
| 14366 |
-------------------------- |
| 14367 |
-- Attribute_Definition -- |
| 14368 |
-------------------------- |
| 14369 |
|
| 14370 |
-- pragma Attribute_Definition |
| 14371 |
-- ([Attribute =>] ATTRIBUTE_DESIGNATOR, |
| 14372 |
-- [Entity =>] LOCAL_NAME, |
| 14373 |
-- [Expression =>] EXPRESSION | NAME); |
| 14374 |
|
| 14375 |
when Pragma_Attribute_Definition => Attribute_Definition : declare |
| 14376 |
Attribute_Designator : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 14377 |
Aname : Name_Id; |
| 14378 |
|
| 14379 |
begin |
| 14380 |
GNAT_Pragma; |
| 14381 |
Check_Arg_Count (3); |
| 14382 |
Check_Optional_Identifier (Arg1, "attribute"); |
| 14383 |
Check_Optional_Identifier (Arg2, "entity"); |
| 14384 |
Check_Optional_Identifier (Arg3, "expression"); |
| 14385 |
|
| 14386 |
if Nkind (Attribute_Designator) /= N_Identifier then |
| 14387 |
Error_Msg_N ("attribute name expected", Attribute_Designator); |
| 14388 |
return; |
| 14389 |
end if; |
| 14390 |
|
| 14391 |
Check_Arg_Is_Local_Name (Arg2); |
| 14392 |
|
| 14393 |
-- If the attribute is not recognized, then issue a warning (not |
| 14394 |
-- an error), and ignore the pragma. |
| 14395 |
|
| 14396 |
Aname := Chars (Attribute_Designator); |
| 14397 |
|
| 14398 |
if not Is_Attribute_Name (Aname) then |
| 14399 |
Bad_Attribute (Attribute_Designator, Aname, Warn => True); |
| 14400 |
return; |
| 14401 |
end if; |
| 14402 |
|
| 14403 |
-- Otherwise, rewrite the pragma as an attribute definition clause |
| 14404 |
|
| 14405 |
Rewrite (N, |
| 14406 |
Make_Attribute_Definition_Clause (Loc, |
| 14407 |
Name => Get_Pragma_Arg (Arg2), |
| 14408 |
Chars => Aname, |
| 14409 |
Expression => Get_Pragma_Arg (Arg3))); |
| 14410 |
Analyze (N); |
| 14411 |
end Attribute_Definition; |
| 14412 |
|
| 14413 |
------------------------------------------------------------------ |
| 14414 |
-- Async_Readers/Async_Writers/Effective_Reads/Effective_Writes -- |
| 14415 |
-- No_Caching -- |
| 14416 |
------------------------------------------------------------------ |
| 14417 |
|
| 14418 |
-- pragma Async_Readers [ (static_boolean_EXPRESSION) ]; |
| 14419 |
-- pragma Async_Writers [ (static_boolean_EXPRESSION) ]; |
| 14420 |
-- pragma Effective_Reads [ (static_boolean_EXPRESSION) ]; |
| 14421 |
-- pragma Effective_Writes [ (static_boolean_EXPRESSION) ]; |
| 14422 |
-- pragma No_Caching [ (static_boolean_EXPRESSION) ]; |
| 14423 |
|
| 14424 |
when Pragma_Async_Readers |
| 14425 |
| Pragma_Async_Writers |
| 14426 |
| Pragma_Effective_Reads |
| 14427 |
| Pragma_Effective_Writes |
| 14428 |
| Pragma_No_Caching |
| 14429 |
=> |
| 14430 |
Async_Effective : declare |
| 14431 |
Obj_Or_Type_Decl : Node_Id; |
| 14432 |
Obj_Or_Type_Id : Entity_Id; |
| 14433 |
begin |
| 14434 |
GNAT_Pragma; |
| 14435 |
Check_No_Identifiers; |
| 14436 |
Check_At_Most_N_Arguments (1); |
| 14437 |
|
| 14438 |
Obj_Or_Type_Decl := Find_Related_Context (N, Do_Checks => True); |
| 14439 |
|
| 14440 |
-- Pragma must apply to a object declaration or to a type |
| 14441 |
-- declaration. Original_Node is necessary to account for |
| 14442 |
-- untagged derived types that are rewritten as subtypes of |
| 14443 |
-- their respective root types. |
| 14444 |
|
| 14445 |
if Nkind (Obj_Or_Type_Decl) /= N_Object_Declaration |
| 14446 |
and then Nkind (Original_Node (Obj_Or_Type_Decl)) not in |
| 14447 |
N_Full_Type_Declaration | |
| 14448 |
N_Private_Type_Declaration | |
| 14449 |
N_Formal_Type_Declaration | |
| 14450 |
N_Task_Type_Declaration | |
| 14451 |
N_Protected_Type_Declaration |
| 14452 |
then |
| 14453 |
Pragma_Misplaced; |
| 14454 |
end if; |
| 14455 |
|
| 14456 |
Obj_Or_Type_Id := Defining_Entity (Obj_Or_Type_Decl); |
| 14457 |
|
| 14458 |
-- Perform minimal verification to ensure that the argument is at |
| 14459 |
-- least an object or a type. Subsequent finer grained checks will |
| 14460 |
-- be done at the end of the declarative region that contains the |
| 14461 |
-- pragma. |
| 14462 |
|
| 14463 |
if Ekind (Obj_Or_Type_Id) in E_Constant | E_Variable |
| 14464 |
or else Is_Type (Obj_Or_Type_Id) |
| 14465 |
then |
| 14466 |
|
| 14467 |
-- In the case of a type, pragma is a type-related |
| 14468 |
-- representation item and so requires checks common to |
| 14469 |
-- all type-related representation items. |
| 14470 |
|
| 14471 |
if Is_Type (Obj_Or_Type_Id) |
| 14472 |
and then Rep_Item_Too_Late (Obj_Or_Type_Id, N) |
| 14473 |
then |
| 14474 |
return; |
| 14475 |
end if; |
| 14476 |
|
| 14477 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 14478 |
-- the purposes of legality checks and removal of ignored Ghost |
| 14479 |
-- code. |
| 14480 |
|
| 14481 |
Mark_Ghost_Pragma (N, Obj_Or_Type_Id); |
| 14482 |
|
| 14483 |
-- Chain the pragma on the contract for further processing by |
| 14484 |
-- Analyze_External_Property_In_Decl_Part. |
| 14485 |
|
| 14486 |
Add_Contract_Item (N, Obj_Or_Type_Id); |
| 14487 |
|
| 14488 |
-- Analyze the Boolean expression (if any) |
| 14489 |
|
| 14490 |
if Present (Arg1) then |
| 14491 |
Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1)); |
| 14492 |
end if; |
| 14493 |
|
| 14494 |
-- Otherwise the external property applies to a constant |
| 14495 |
|
| 14496 |
else |
| 14497 |
Error_Pragma |
| 14498 |
("pragma % must apply to a volatile type or object"); |
| 14499 |
end if; |
| 14500 |
end Async_Effective; |
| 14501 |
|
| 14502 |
------------------ |
| 14503 |
-- Asynchronous -- |
| 14504 |
------------------ |
| 14505 |
|
| 14506 |
-- pragma Asynchronous (LOCAL_NAME); |
| 14507 |
|
| 14508 |
when Pragma_Asynchronous => Asynchronous : declare |
| 14509 |
C_Ent : Entity_Id; |
| 14510 |
Decl : Node_Id; |
| 14511 |
Formal : Entity_Id; |
| 14512 |
L : List_Id; |
| 14513 |
Nm : Entity_Id; |
| 14514 |
S : Node_Id; |
| 14515 |
|
| 14516 |
procedure Process_Async_Pragma; |
| 14517 |
-- Common processing for procedure and access-to-procedure case |
| 14518 |
|
| 14519 |
-------------------------- |
| 14520 |
-- Process_Async_Pragma -- |
| 14521 |
-------------------------- |
| 14522 |
|
| 14523 |
procedure Process_Async_Pragma is |
| 14524 |
begin |
| 14525 |
if No (L) then |
| 14526 |
Set_Is_Asynchronous (Nm); |
| 14527 |
return; |
| 14528 |
end if; |
| 14529 |
|
| 14530 |
-- The formals should be of mode IN (RM E.4.1(6)) |
| 14531 |
|
| 14532 |
S := First (L); |
| 14533 |
while Present (S) loop |
| 14534 |
Formal := Defining_Identifier (S); |
| 14535 |
|
| 14536 |
if Nkind (Formal) = N_Defining_Identifier |
| 14537 |
and then Ekind (Formal) /= E_In_Parameter |
| 14538 |
then |
| 14539 |
Error_Pragma_Arg |
| 14540 |
("pragma% procedure can only have IN parameter", |
| 14541 |
Arg1); |
| 14542 |
end if; |
| 14543 |
|
| 14544 |
Next (S); |
| 14545 |
end loop; |
| 14546 |
|
| 14547 |
Set_Is_Asynchronous (Nm); |
| 14548 |
end Process_Async_Pragma; |
| 14549 |
|
| 14550 |
-- Start of processing for pragma Asynchronous |
| 14551 |
|
| 14552 |
begin |
| 14553 |
Check_Ada_83_Warning; |
| 14554 |
Check_No_Identifiers; |
| 14555 |
Check_Arg_Count (1); |
| 14556 |
Check_Arg_Is_Local_Name (Arg1); |
| 14557 |
|
| 14558 |
if Debug_Flag_U then |
| 14559 |
return; |
| 14560 |
end if; |
| 14561 |
|
| 14562 |
C_Ent := Cunit_Entity (Current_Sem_Unit); |
| 14563 |
Analyze (Get_Pragma_Arg (Arg1)); |
| 14564 |
Nm := Entity (Get_Pragma_Arg (Arg1)); |
| 14565 |
|
| 14566 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 14567 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 14568 |
|
| 14569 |
Mark_Ghost_Pragma (N, Nm); |
| 14570 |
|
| 14571 |
if not Is_Remote_Call_Interface (C_Ent) |
| 14572 |
and then not Is_Remote_Types (C_Ent) |
| 14573 |
then |
| 14574 |
-- This pragma should only appear in an RCI or Remote Types |
| 14575 |
-- unit (RM E.4.1(4)). |
| 14576 |
|
| 14577 |
Error_Pragma |
| 14578 |
("pragma% not in Remote_Call_Interface or Remote_Types unit"); |
| 14579 |
end if; |
| 14580 |
|
| 14581 |
if Ekind (Nm) = E_Procedure |
| 14582 |
and then Nkind (Parent (Nm)) = N_Procedure_Specification |
| 14583 |
then |
| 14584 |
if not Is_Remote_Call_Interface (Nm) then |
| 14585 |
Error_Pragma_Arg |
| 14586 |
("pragma% cannot be applied on non-remote procedure", |
| 14587 |
Arg1); |
| 14588 |
end if; |
| 14589 |
|
| 14590 |
L := Parameter_Specifications (Parent (Nm)); |
| 14591 |
Process_Async_Pragma; |
| 14592 |
return; |
| 14593 |
|
| 14594 |
elsif Ekind (Nm) = E_Function then |
| 14595 |
Error_Pragma_Arg |
| 14596 |
("pragma% cannot be applied to function", Arg1); |
| 14597 |
|
| 14598 |
elsif Is_Remote_Access_To_Subprogram_Type (Nm) then |
| 14599 |
if Is_Record_Type (Nm) then |
| 14600 |
|
| 14601 |
-- A record type that is the Equivalent_Type for a remote |
| 14602 |
-- access-to-subprogram type. |
| 14603 |
|
| 14604 |
Decl := Declaration_Node (Corresponding_Remote_Type (Nm)); |
| 14605 |
|
| 14606 |
else |
| 14607 |
-- A non-expanded RAS type (distribution is not enabled) |
| 14608 |
|
| 14609 |
Decl := Declaration_Node (Nm); |
| 14610 |
end if; |
| 14611 |
|
| 14612 |
if Nkind (Decl) = N_Full_Type_Declaration |
| 14613 |
and then Nkind (Type_Definition (Decl)) = |
| 14614 |
N_Access_Procedure_Definition |
| 14615 |
then |
| 14616 |
L := Parameter_Specifications (Type_Definition (Decl)); |
| 14617 |
Process_Async_Pragma; |
| 14618 |
|
| 14619 |
if Is_Asynchronous (Nm) |
| 14620 |
and then Expander_Active |
| 14621 |
and then Get_PCS_Name /= Name_No_DSA |
| 14622 |
then |
| 14623 |
RACW_Type_Is_Asynchronous (Underlying_RACW_Type (Nm)); |
| 14624 |
end if; |
| 14625 |
|
| 14626 |
else |
| 14627 |
Error_Pragma_Arg |
| 14628 |
("pragma% cannot reference access-to-function type", |
| 14629 |
Arg1); |
| 14630 |
end if; |
| 14631 |
|
| 14632 |
-- Only other possibility is access-to-class-wide type |
| 14633 |
|
| 14634 |
elsif Is_Access_Type (Nm) |
| 14635 |
and then Is_Class_Wide_Type (Designated_Type (Nm)) |
| 14636 |
then |
| 14637 |
Check_First_Subtype (Arg1); |
| 14638 |
Set_Is_Asynchronous (Nm); |
| 14639 |
if Expander_Active then |
| 14640 |
RACW_Type_Is_Asynchronous (Nm); |
| 14641 |
end if; |
| 14642 |
|
| 14643 |
else |
| 14644 |
Error_Pragma_Arg ("inappropriate argument for pragma%", Arg1); |
| 14645 |
end if; |
| 14646 |
end Asynchronous; |
| 14647 |
|
| 14648 |
------------ |
| 14649 |
-- Atomic -- |
| 14650 |
------------ |
| 14651 |
|
| 14652 |
-- pragma Atomic (LOCAL_NAME); |
| 14653 |
|
| 14654 |
when Pragma_Atomic => |
| 14655 |
Process_Atomic_Independent_Shared_Volatile; |
| 14656 |
|
| 14657 |
----------------------- |
| 14658 |
-- Atomic_Components -- |
| 14659 |
----------------------- |
| 14660 |
|
| 14661 |
-- pragma Atomic_Components (array_LOCAL_NAME); |
| 14662 |
|
| 14663 |
-- This processing is shared by Volatile_Components |
| 14664 |
|
| 14665 |
when Pragma_Atomic_Components |
| 14666 |
| Pragma_Volatile_Components |
| 14667 |
=> |
| 14668 |
Atomic_Components : declare |
| 14669 |
D : Node_Id; |
| 14670 |
E : Entity_Id; |
| 14671 |
E_Id : Node_Id; |
| 14672 |
|
| 14673 |
begin |
| 14674 |
Check_Ada_83_Warning; |
| 14675 |
Check_No_Identifiers; |
| 14676 |
Check_Arg_Count (1); |
| 14677 |
Check_Arg_Is_Local_Name (Arg1); |
| 14678 |
E_Id := Get_Pragma_Arg (Arg1); |
| 14679 |
|
| 14680 |
if Etype (E_Id) = Any_Type then |
| 14681 |
return; |
| 14682 |
end if; |
| 14683 |
|
| 14684 |
E := Entity (E_Id); |
| 14685 |
|
| 14686 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 14687 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 14688 |
|
| 14689 |
Mark_Ghost_Pragma (N, E); |
| 14690 |
Check_Duplicate_Pragma (E); |
| 14691 |
|
| 14692 |
if Rep_Item_Too_Early (E, N) |
| 14693 |
or else |
| 14694 |
Rep_Item_Too_Late (E, N) |
| 14695 |
then |
| 14696 |
return; |
| 14697 |
end if; |
| 14698 |
|
| 14699 |
D := Declaration_Node (E); |
| 14700 |
|
| 14701 |
if (Nkind (D) in N_Full_Type_Declaration |
| 14702 |
| N_Formal_Type_Declaration |
| 14703 |
and then Is_Array_Type (E)) |
| 14704 |
or else |
| 14705 |
(Nkind (D) = N_Object_Declaration |
| 14706 |
and then Ekind (E) in E_Constant | E_Variable |
| 14707 |
and then Nkind (Object_Definition (D)) = |
| 14708 |
N_Constrained_Array_Definition) |
| 14709 |
then |
| 14710 |
-- The flag is set on the base type, or on the object |
| 14711 |
|
| 14712 |
if Is_Array_Type (E) then |
| 14713 |
E := Base_Type (E); |
| 14714 |
end if; |
| 14715 |
|
| 14716 |
-- Atomic implies both Independent and Volatile |
| 14717 |
|
| 14718 |
if Prag_Id = Pragma_Atomic_Components then |
| 14719 |
Set_Has_Atomic_Components (E); |
| 14720 |
Set_Has_Independent_Components (E); |
| 14721 |
end if; |
| 14722 |
|
| 14723 |
Set_Has_Volatile_Components (E); |
| 14724 |
|
| 14725 |
else |
| 14726 |
Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1); |
| 14727 |
end if; |
| 14728 |
end Atomic_Components; |
| 14729 |
|
| 14730 |
-------------------- |
| 14731 |
-- Attach_Handler -- |
| 14732 |
-------------------- |
| 14733 |
|
| 14734 |
-- pragma Attach_Handler (handler_NAME, EXPRESSION); |
| 14735 |
|
| 14736 |
when Pragma_Attach_Handler => |
| 14737 |
Check_Ada_83_Warning; |
| 14738 |
Check_No_Identifiers; |
| 14739 |
Check_Arg_Count (2); |
| 14740 |
|
| 14741 |
if No_Run_Time_Mode then |
| 14742 |
Error_Msg_CRT ("Attach_Handler pragma", N); |
| 14743 |
else |
| 14744 |
Check_Interrupt_Or_Attach_Handler; |
| 14745 |
|
| 14746 |
-- The expression that designates the attribute may depend on a |
| 14747 |
-- discriminant, and is therefore a per-object expression, to |
| 14748 |
-- be expanded in the init proc. If expansion is enabled, then |
| 14749 |
-- perform semantic checks on a copy only. |
| 14750 |
|
| 14751 |
declare |
| 14752 |
Temp : Node_Id; |
| 14753 |
Typ : Node_Id; |
| 14754 |
Parg2 : constant Node_Id := Get_Pragma_Arg (Arg2); |
| 14755 |
|
| 14756 |
begin |
| 14757 |
-- In Relaxed_RM_Semantics mode, we allow any static |
| 14758 |
-- integer value, for compatibility with other compilers. |
| 14759 |
|
| 14760 |
if Relaxed_RM_Semantics |
| 14761 |
and then Nkind (Parg2) = N_Integer_Literal |
| 14762 |
then |
| 14763 |
Typ := Standard_Integer; |
| 14764 |
else |
| 14765 |
Typ := RTE (RE_Interrupt_ID); |
| 14766 |
end if; |
| 14767 |
|
| 14768 |
if Expander_Active then |
| 14769 |
Temp := New_Copy_Tree (Parg2); |
| 14770 |
Set_Parent (Temp, N); |
| 14771 |
Preanalyze_And_Resolve (Temp, Typ); |
| 14772 |
else |
| 14773 |
Analyze (Parg2); |
| 14774 |
Resolve (Parg2, Typ); |
| 14775 |
end if; |
| 14776 |
end; |
| 14777 |
|
| 14778 |
Process_Interrupt_Or_Attach_Handler; |
| 14779 |
end if; |
| 14780 |
|
| 14781 |
-------------------- |
| 14782 |
-- C_Pass_By_Copy -- |
| 14783 |
-------------------- |
| 14784 |
|
| 14785 |
-- pragma C_Pass_By_Copy ([Max_Size =>] static_integer_EXPRESSION); |
| 14786 |
|
| 14787 |
when Pragma_C_Pass_By_Copy => C_Pass_By_Copy : declare |
| 14788 |
Arg : Node_Id; |
| 14789 |
Val : Uint; |
| 14790 |
|
| 14791 |
begin |
| 14792 |
GNAT_Pragma; |
| 14793 |
Check_Valid_Configuration_Pragma; |
| 14794 |
Check_Arg_Count (1); |
| 14795 |
Check_Optional_Identifier (Arg1, Name_Max_Size); |
| 14796 |
|
| 14797 |
Arg := Get_Pragma_Arg (Arg1); |
| 14798 |
Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer); |
| 14799 |
|
| 14800 |
Val := Expr_Value (Arg); |
| 14801 |
|
| 14802 |
if Val <= 0 then |
| 14803 |
Error_Pragma_Arg |
| 14804 |
("maximum size for pragma% must be positive", Arg1); |
| 14805 |
|
| 14806 |
elsif UI_Is_In_Int_Range (Val) then |
| 14807 |
Default_C_Record_Mechanism := UI_To_Int (Val); |
| 14808 |
|
| 14809 |
-- If a giant value is given, Int'Last will do well enough. |
| 14810 |
-- If sometime someone complains that a record larger than |
| 14811 |
-- two gigabytes is not copied, we will worry about it then. |
| 14812 |
|
| 14813 |
else |
| 14814 |
Default_C_Record_Mechanism := Mechanism_Type'Last; |
| 14815 |
end if; |
| 14816 |
end C_Pass_By_Copy; |
| 14817 |
|
| 14818 |
----------- |
| 14819 |
-- Check -- |
| 14820 |
----------- |
| 14821 |
|
| 14822 |
-- pragma Check ([Name =>] CHECK_KIND, |
| 14823 |
-- [Check =>] Boolean_EXPRESSION |
| 14824 |
-- [,[Message =>] String_EXPRESSION]); |
| 14825 |
|
| 14826 |
-- CHECK_KIND ::= IDENTIFIER | |
| 14827 |
-- Pre'Class | |
| 14828 |
-- Post'Class | |
| 14829 |
-- Invariant'Class | |
| 14830 |
-- Type_Invariant'Class |
| 14831 |
|
| 14832 |
-- The identifiers Assertions and Statement_Assertions are not |
| 14833 |
-- allowed, since they have special meaning for Check_Policy. |
| 14834 |
|
| 14835 |
-- WARNING: The code below manages Ghost regions. Return statements |
| 14836 |
-- must be replaced by gotos which jump to the end of the code and |
| 14837 |
-- restore the Ghost mode. |
| 14838 |
|
| 14839 |
when Pragma_Check => Check : declare |
| 14840 |
|
| 14841 |
procedure Handle_Dynamic_Predicate_Check; |
| 14842 |
-- Enable or ignore the pragma depending on whether dynamic |
| 14843 |
-- checks are enabled in the context where the associated |
| 14844 |
-- type declaration is defined. |
| 14845 |
|
| 14846 |
------------------------------------ |
| 14847 |
-- Handle_Dynamic_Predicate_Check -- |
| 14848 |
------------------------------------ |
| 14849 |
|
| 14850 |
procedure Handle_Dynamic_Predicate_Check is |
| 14851 |
Func_Call : constant Node_Id := Expression (Arg2); |
| 14852 |
Func_Id : constant Entity_Id := Entity (Name (Func_Call)); |
| 14853 |
Typ : Entity_Id; |
| 14854 |
|
| 14855 |
begin |
| 14856 |
-- Locate the type declaration associated with this runtime |
| 14857 |
-- check. The 2nd parameter of this pragma is a call to an |
| 14858 |
-- internally built function that has a single parameter; |
| 14859 |
-- the type of that formal parameter is the type we are |
| 14860 |
-- searching for. |
| 14861 |
|
| 14862 |
pragma Assert (Is_Predicate_Function (Func_Id)); |
| 14863 |
Typ := Etype (First_Entity (Func_Id)); |
| 14864 |
|
| 14865 |
if not Has_Dynamic_Predicate_Aspect (Typ) |
| 14866 |
and then Is_Private_Type (Typ) |
| 14867 |
and then Present (Full_View (Typ)) |
| 14868 |
then |
| 14869 |
Typ := Full_View (Typ); |
| 14870 |
end if; |
| 14871 |
|
| 14872 |
pragma Assert (Has_Dynamic_Predicate_Aspect (Typ)); |
| 14873 |
|
| 14874 |
if not Predicates_Ignored (Typ) then |
| 14875 |
Set_Is_Checked (N, True); |
| 14876 |
Set_Is_Ignored (N, False); |
| 14877 |
|
| 14878 |
else |
| 14879 |
-- In CodePeer mode and GNATprove mode, we need to |
| 14880 |
-- consider all assertions, unless they are disabled, |
| 14881 |
-- because transformations of the AST may depend on |
| 14882 |
-- assertions being checked. |
| 14883 |
|
| 14884 |
if CodePeer_Mode or GNATprove_Mode then |
| 14885 |
Set_Is_Checked (N, True); |
| 14886 |
Set_Is_Ignored (N, False); |
| 14887 |
else |
| 14888 |
Set_Is_Checked (N, False); |
| 14889 |
Set_Is_Ignored (N, True); |
| 14890 |
end if; |
| 14891 |
end if; |
| 14892 |
end Handle_Dynamic_Predicate_Check; |
| 14893 |
|
| 14894 |
-- Local variables |
| 14895 |
|
| 14896 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 14897 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 14898 |
-- Save the Ghost-related attributes to restore on exit |
| 14899 |
|
| 14900 |
Cname : Name_Id; |
| 14901 |
Eloc : Source_Ptr; |
| 14902 |
Expr : Node_Id; |
| 14903 |
Str : Node_Id; |
| 14904 |
pragma Warnings (Off, Str); |
| 14905 |
|
| 14906 |
-- Start of processing for Pragma_Check |
| 14907 |
|
| 14908 |
begin |
| 14909 |
-- Pragma Check is Ghost when it applies to a Ghost entity. Set |
| 14910 |
-- the mode now to ensure that any nodes generated during analysis |
| 14911 |
-- and expansion are marked as Ghost. |
| 14912 |
|
| 14913 |
Set_Ghost_Mode (N); |
| 14914 |
|
| 14915 |
GNAT_Pragma; |
| 14916 |
Check_At_Least_N_Arguments (2); |
| 14917 |
Check_At_Most_N_Arguments (3); |
| 14918 |
Check_Optional_Identifier (Arg1, Name_Name); |
| 14919 |
Check_Optional_Identifier (Arg2, Name_Check); |
| 14920 |
|
| 14921 |
if Arg_Count = 3 then |
| 14922 |
Check_Optional_Identifier (Arg3, Name_Message); |
| 14923 |
Str := Get_Pragma_Arg (Arg3); |
| 14924 |
end if; |
| 14925 |
|
| 14926 |
Rewrite_Assertion_Kind (Get_Pragma_Arg (Arg1)); |
| 14927 |
Check_Arg_Is_Identifier (Arg1); |
| 14928 |
Cname := Chars (Get_Pragma_Arg (Arg1)); |
| 14929 |
|
| 14930 |
-- Check forbidden name Assertions or Statement_Assertions |
| 14931 |
|
| 14932 |
case Cname is |
| 14933 |
when Name_Assertions => |
| 14934 |
Error_Pragma_Arg |
| 14935 |
("""Assertions"" is not allowed as a check kind for " |
| 14936 |
& "pragma%", Arg1); |
| 14937 |
|
| 14938 |
when Name_Statement_Assertions => |
| 14939 |
Error_Pragma_Arg |
| 14940 |
("""Statement_Assertions"" is not allowed as a check kind " |
| 14941 |
& "for pragma%", Arg1); |
| 14942 |
|
| 14943 |
when others => |
| 14944 |
null; |
| 14945 |
end case; |
| 14946 |
|
| 14947 |
-- Check applicable policy. We skip this if Checked/Ignored status |
| 14948 |
-- is already set (e.g. in the case of a pragma from an aspect). |
| 14949 |
|
| 14950 |
if Is_Checked (N) or else Is_Ignored (N) then |
| 14951 |
null; |
| 14952 |
|
| 14953 |
-- For a non-source pragma that is a rewriting of another pragma, |
| 14954 |
-- copy the Is_Checked/Ignored status from the rewritten pragma. |
| 14955 |
|
| 14956 |
elsif Is_Rewrite_Substitution (N) |
| 14957 |
and then Nkind (Original_Node (N)) = N_Pragma |
| 14958 |
then |
| 14959 |
Set_Is_Ignored (N, Is_Ignored (Original_Node (N))); |
| 14960 |
Set_Is_Checked (N, Is_Checked (Original_Node (N))); |
| 14961 |
|
| 14962 |
-- Internally added dynamic predicate checks require checking the |
| 14963 |
-- applicable policy at the point of the type declaration of their |
| 14964 |
-- corresponding entity. |
| 14965 |
|
| 14966 |
elsif not Comes_From_Source (N) |
| 14967 |
and then Chars (Pragma_Identifier (N)) = Name_Check |
| 14968 |
and then Pname = Name_Dynamic_Predicate |
| 14969 |
then |
| 14970 |
Handle_Dynamic_Predicate_Check; |
| 14971 |
|
| 14972 |
-- Otherwise query the applicable policy at this point |
| 14973 |
|
| 14974 |
else |
| 14975 |
case Check_Kind (Cname) is |
| 14976 |
when Name_Ignore => |
| 14977 |
Set_Is_Ignored (N, True); |
| 14978 |
Set_Is_Checked (N, False); |
| 14979 |
|
| 14980 |
when Name_Check => |
| 14981 |
Set_Is_Ignored (N, False); |
| 14982 |
Set_Is_Checked (N, True); |
| 14983 |
|
| 14984 |
-- For disable, rewrite pragma as null statement and skip |
| 14985 |
-- rest of the analysis of the pragma. |
| 14986 |
|
| 14987 |
when Name_Disable => |
| 14988 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 14989 |
Analyze (N); |
| 14990 |
raise Pragma_Exit; |
| 14991 |
|
| 14992 |
-- No other possibilities |
| 14993 |
|
| 14994 |
when others => |
| 14995 |
raise Program_Error; |
| 14996 |
end case; |
| 14997 |
end if; |
| 14998 |
|
| 14999 |
-- If check kind was not Disable, then continue pragma analysis |
| 15000 |
|
| 15001 |
Expr := Get_Pragma_Arg (Arg2); |
| 15002 |
|
| 15003 |
-- Mark the pragma (or, if rewritten from an aspect, the original |
| 15004 |
-- aspect) as enabled. Nothing to do for an internally generated |
| 15005 |
-- check for a dynamic predicate. |
| 15006 |
|
| 15007 |
if Is_Checked (N) |
| 15008 |
and then Cname /= Name_Dynamic_Predicate |
| 15009 |
then |
| 15010 |
Set_SCO_Pragma_Enabled (Loc); |
| 15011 |
end if; |
| 15012 |
|
| 15013 |
-- Deal with analyzing the string argument. If checks are not |
| 15014 |
-- on we don't want any expansion (since such expansion would |
| 15015 |
-- not get properly deleted) but we do want to analyze (to get |
| 15016 |
-- proper references). The Preanalyze_And_Resolve routine does |
| 15017 |
-- just what we want. Ditto if pragma is active, because it will |
| 15018 |
-- be rewritten as an if-statement whose analysis will complete |
| 15019 |
-- analysis and expansion of the string message. This makes a |
| 15020 |
-- difference in the unusual case where the expression for the |
| 15021 |
-- string may have a side effect, such as raising an exception. |
| 15022 |
-- This is mandated by RM 11.4.2, which specifies that the string |
| 15023 |
-- expression is only evaluated if the check fails and |
| 15024 |
-- Assertion_Error is to be raised. |
| 15025 |
|
| 15026 |
if Arg_Count = 3 then |
| 15027 |
Preanalyze_And_Resolve (Str, Standard_String); |
| 15028 |
end if; |
| 15029 |
|
| 15030 |
-- Now you might think we could just do the same with the Boolean |
| 15031 |
-- expression if checks are off (and expansion is on) and then |
| 15032 |
-- rewrite the check as a null statement. This would work but we |
| 15033 |
-- would lose the useful warnings about an assertion being bound |
| 15034 |
-- to fail even if assertions are turned off. |
| 15035 |
|
| 15036 |
-- So instead we wrap the boolean expression in an if statement |
| 15037 |
-- that looks like: |
| 15038 |
|
| 15039 |
-- if False and then condition then |
| 15040 |
-- null; |
| 15041 |
-- end if; |
| 15042 |
|
| 15043 |
-- The reason we do this rewriting during semantic analysis rather |
| 15044 |
-- than as part of normal expansion is that we cannot analyze and |
| 15045 |
-- expand the code for the boolean expression directly, or it may |
| 15046 |
-- cause insertion of actions that would escape the attempt to |
| 15047 |
-- suppress the check code. |
| 15048 |
|
| 15049 |
-- Note that the Sloc for the if statement corresponds to the |
| 15050 |
-- argument condition, not the pragma itself. The reason for |
| 15051 |
-- this is that we may generate a warning if the condition is |
| 15052 |
-- False at compile time, and we do not want to delete this |
| 15053 |
-- warning when we delete the if statement. |
| 15054 |
|
| 15055 |
if Expander_Active and Is_Ignored (N) then |
| 15056 |
Eloc := Sloc (Expr); |
| 15057 |
|
| 15058 |
Rewrite (N, |
| 15059 |
Make_If_Statement (Eloc, |
| 15060 |
Condition => |
| 15061 |
Make_And_Then (Eloc, |
| 15062 |
Left_Opnd => Make_Identifier (Eloc, Name_False), |
| 15063 |
Right_Opnd => Expr), |
| 15064 |
Then_Statements => New_List ( |
| 15065 |
Make_Null_Statement (Eloc)))); |
| 15066 |
|
| 15067 |
-- Now go ahead and analyze the if statement |
| 15068 |
|
| 15069 |
In_Assertion_Expr := In_Assertion_Expr + 1; |
| 15070 |
|
| 15071 |
-- One rather special treatment. If we are now in Eliminated |
| 15072 |
-- overflow mode, then suppress overflow checking since we do |
| 15073 |
-- not want to drag in the bignum stuff if we are in Ignore |
| 15074 |
-- mode anyway. This is particularly important if we are using |
| 15075 |
-- a configurable run time that does not support bignum ops. |
| 15076 |
|
| 15077 |
if Scope_Suppress.Overflow_Mode_Assertions = Eliminated then |
| 15078 |
declare |
| 15079 |
Svo : constant Boolean := |
| 15080 |
Scope_Suppress.Suppress (Overflow_Check); |
| 15081 |
begin |
| 15082 |
Scope_Suppress.Overflow_Mode_Assertions := Strict; |
| 15083 |
Scope_Suppress.Suppress (Overflow_Check) := True; |
| 15084 |
Analyze (N); |
| 15085 |
Scope_Suppress.Suppress (Overflow_Check) := Svo; |
| 15086 |
Scope_Suppress.Overflow_Mode_Assertions := Eliminated; |
| 15087 |
end; |
| 15088 |
|
| 15089 |
-- Not that special case |
| 15090 |
|
| 15091 |
else |
| 15092 |
Analyze (N); |
| 15093 |
end if; |
| 15094 |
|
| 15095 |
-- All done with this check |
| 15096 |
|
| 15097 |
In_Assertion_Expr := In_Assertion_Expr - 1; |
| 15098 |
|
| 15099 |
-- Check is active or expansion not active. In these cases we can |
| 15100 |
-- just go ahead and analyze the boolean with no worries. |
| 15101 |
|
| 15102 |
else |
| 15103 |
In_Assertion_Expr := In_Assertion_Expr + 1; |
| 15104 |
Analyze_And_Resolve (Expr, Any_Boolean); |
| 15105 |
In_Assertion_Expr := In_Assertion_Expr - 1; |
| 15106 |
end if; |
| 15107 |
|
| 15108 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 15109 |
end Check; |
| 15110 |
|
| 15111 |
-------------------------- |
| 15112 |
-- Check_Float_Overflow -- |
| 15113 |
-------------------------- |
| 15114 |
|
| 15115 |
-- pragma Check_Float_Overflow; |
| 15116 |
|
| 15117 |
when Pragma_Check_Float_Overflow => |
| 15118 |
GNAT_Pragma; |
| 15119 |
Check_Valid_Configuration_Pragma; |
| 15120 |
Check_Arg_Count (0); |
| 15121 |
Check_Float_Overflow := not Machine_Overflows_On_Target; |
| 15122 |
|
| 15123 |
---------------- |
| 15124 |
-- Check_Name -- |
| 15125 |
---------------- |
| 15126 |
|
| 15127 |
-- pragma Check_Name (check_IDENTIFIER); |
| 15128 |
|
| 15129 |
when Pragma_Check_Name => |
| 15130 |
GNAT_Pragma; |
| 15131 |
Check_No_Identifiers; |
| 15132 |
Check_Valid_Configuration_Pragma; |
| 15133 |
Check_Arg_Count (1); |
| 15134 |
Check_Arg_Is_Identifier (Arg1); |
| 15135 |
|
| 15136 |
declare |
| 15137 |
Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1)); |
| 15138 |
|
| 15139 |
begin |
| 15140 |
for J in Check_Names.First .. Check_Names.Last loop |
| 15141 |
if Check_Names.Table (J) = Nam then |
| 15142 |
return; |
| 15143 |
end if; |
| 15144 |
end loop; |
| 15145 |
|
| 15146 |
Check_Names.Append (Nam); |
| 15147 |
end; |
| 15148 |
|
| 15149 |
------------------ |
| 15150 |
-- Check_Policy -- |
| 15151 |
------------------ |
| 15152 |
|
| 15153 |
-- This is the old style syntax, which is still allowed in all modes: |
| 15154 |
|
| 15155 |
-- pragma Check_Policy ([Name =>] CHECK_KIND |
| 15156 |
-- [Policy =>] POLICY_IDENTIFIER); |
| 15157 |
|
| 15158 |
-- POLICY_IDENTIFIER ::= On | Off | Check | Disable | Ignore |
| 15159 |
|
| 15160 |
-- CHECK_KIND ::= IDENTIFIER | |
| 15161 |
-- Pre'Class | |
| 15162 |
-- Post'Class | |
| 15163 |
-- Type_Invariant'Class | |
| 15164 |
-- Invariant'Class |
| 15165 |
|
| 15166 |
-- This is the new style syntax, compatible with Assertion_Policy |
| 15167 |
-- and also allowed in all modes. |
| 15168 |
|
| 15169 |
-- Pragma Check_Policy ( |
| 15170 |
-- CHECK_KIND => POLICY_IDENTIFIER |
| 15171 |
-- {, CHECK_KIND => POLICY_IDENTIFIER}); |
| 15172 |
|
| 15173 |
-- Note: the identifiers Name and Policy are not allowed as |
| 15174 |
-- Check_Kind values. This avoids ambiguities between the old and |
| 15175 |
-- new form syntax. |
| 15176 |
|
| 15177 |
when Pragma_Check_Policy => Check_Policy : declare |
| 15178 |
Kind : Node_Id; |
| 15179 |
|
| 15180 |
begin |
| 15181 |
GNAT_Pragma; |
| 15182 |
Check_At_Least_N_Arguments (1); |
| 15183 |
|
| 15184 |
-- A Check_Policy pragma can appear either as a configuration |
| 15185 |
-- pragma, or in a declarative part or a package spec (see RM |
| 15186 |
-- 11.5(5) for rules for Suppress/Unsuppress which are also |
| 15187 |
-- followed for Check_Policy). |
| 15188 |
|
| 15189 |
if not Is_Configuration_Pragma then |
| 15190 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 15191 |
end if; |
| 15192 |
|
| 15193 |
-- Figure out if we have the old or new syntax. We have the |
| 15194 |
-- old syntax if the first argument has no identifier, or the |
| 15195 |
-- identifier is Name. |
| 15196 |
|
| 15197 |
if Nkind (Arg1) /= N_Pragma_Argument_Association |
| 15198 |
or else Chars (Arg1) in No_Name | Name_Name |
| 15199 |
then |
| 15200 |
-- Old syntax |
| 15201 |
|
| 15202 |
Check_Arg_Count (2); |
| 15203 |
Check_Optional_Identifier (Arg1, Name_Name); |
| 15204 |
Kind := Get_Pragma_Arg (Arg1); |
| 15205 |
Rewrite_Assertion_Kind (Kind, |
| 15206 |
From_Policy => Comes_From_Source (N)); |
| 15207 |
Check_Arg_Is_Identifier (Arg1); |
| 15208 |
|
| 15209 |
-- Check forbidden check kind |
| 15210 |
|
| 15211 |
if Chars (Kind) in Name_Name | Name_Policy then |
| 15212 |
Error_Msg_Name_2 := Chars (Kind); |
| 15213 |
Error_Pragma_Arg |
| 15214 |
("pragma% does not allow% as check name", Arg1); |
| 15215 |
end if; |
| 15216 |
|
| 15217 |
-- Check policy |
| 15218 |
|
| 15219 |
Check_Optional_Identifier (Arg2, Name_Policy); |
| 15220 |
Check_Arg_Is_One_Of |
| 15221 |
(Arg2, |
| 15222 |
Name_On, Name_Off, Name_Check, Name_Disable, Name_Ignore); |
| 15223 |
|
| 15224 |
-- And chain pragma on the Check_Policy_List for search |
| 15225 |
|
| 15226 |
Set_Next_Pragma (N, Opt.Check_Policy_List); |
| 15227 |
Opt.Check_Policy_List := N; |
| 15228 |
|
| 15229 |
-- For the new syntax, what we do is to convert each argument to |
| 15230 |
-- an old syntax equivalent. We do that because we want to chain |
| 15231 |
-- old style Check_Policy pragmas for the search (we don't want |
| 15232 |
-- to have to deal with multiple arguments in the search). |
| 15233 |
|
| 15234 |
else |
| 15235 |
declare |
| 15236 |
Arg : Node_Id; |
| 15237 |
Argx : Node_Id; |
| 15238 |
LocP : Source_Ptr; |
| 15239 |
New_P : Node_Id; |
| 15240 |
|
| 15241 |
begin |
| 15242 |
Arg := Arg1; |
| 15243 |
while Present (Arg) loop |
| 15244 |
LocP := Sloc (Arg); |
| 15245 |
Argx := Get_Pragma_Arg (Arg); |
| 15246 |
|
| 15247 |
-- Kind must be specified |
| 15248 |
|
| 15249 |
if Nkind (Arg) /= N_Pragma_Argument_Association |
| 15250 |
or else Chars (Arg) = No_Name |
| 15251 |
then |
| 15252 |
Error_Pragma_Arg |
| 15253 |
("missing assertion kind for pragma%", Arg); |
| 15254 |
end if; |
| 15255 |
|
| 15256 |
-- Construct equivalent old form syntax Check_Policy |
| 15257 |
-- pragma and insert it to get remaining checks. |
| 15258 |
|
| 15259 |
New_P := |
| 15260 |
Make_Pragma (LocP, |
| 15261 |
Chars => Name_Check_Policy, |
| 15262 |
Pragma_Argument_Associations => New_List ( |
| 15263 |
Make_Pragma_Argument_Association (LocP, |
| 15264 |
Expression => |
| 15265 |
Make_Identifier (LocP, Chars (Arg))), |
| 15266 |
Make_Pragma_Argument_Association (Sloc (Argx), |
| 15267 |
Expression => Argx))); |
| 15268 |
|
| 15269 |
Arg := Next (Arg); |
| 15270 |
|
| 15271 |
-- For a configuration pragma, insert old form in |
| 15272 |
-- the corresponding file. |
| 15273 |
|
| 15274 |
if Is_Configuration_Pragma then |
| 15275 |
Insert_After (N, New_P); |
| 15276 |
Analyze (New_P); |
| 15277 |
|
| 15278 |
else |
| 15279 |
Insert_Action (N, New_P); |
| 15280 |
end if; |
| 15281 |
end loop; |
| 15282 |
|
| 15283 |
-- Rewrite original Check_Policy pragma to null, since we |
| 15284 |
-- have converted it into a series of old syntax pragmas. |
| 15285 |
|
| 15286 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 15287 |
Analyze (N); |
| 15288 |
end; |
| 15289 |
end if; |
| 15290 |
end Check_Policy; |
| 15291 |
|
| 15292 |
------------- |
| 15293 |
-- Comment -- |
| 15294 |
------------- |
| 15295 |
|
| 15296 |
-- pragma Comment (static_string_EXPRESSION) |
| 15297 |
|
| 15298 |
-- Processing for pragma Comment shares the circuitry for pragma |
| 15299 |
-- Ident. The only differences are that Ident enforces a limit of 31 |
| 15300 |
-- characters on its argument, and also enforces limitations on |
| 15301 |
-- placement for DEC compatibility. Pragma Comment shares neither of |
| 15302 |
-- these restrictions. |
| 15303 |
|
| 15304 |
------------------- |
| 15305 |
-- Common_Object -- |
| 15306 |
------------------- |
| 15307 |
|
| 15308 |
-- pragma Common_Object ( |
| 15309 |
-- [Internal =>] LOCAL_NAME |
| 15310 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 15311 |
-- [, [Size =>] EXTERNAL_SYMBOL]); |
| 15312 |
|
| 15313 |
-- Processing for this pragma is shared with Psect_Object |
| 15314 |
|
| 15315 |
---------------------------------------------- |
| 15316 |
-- Compile_Time_Error, Compile_Time_Warning -- |
| 15317 |
---------------------------------------------- |
| 15318 |
|
| 15319 |
-- pragma Compile_Time_Error |
| 15320 |
-- (boolean_EXPRESSION, static_string_EXPRESSION); |
| 15321 |
|
| 15322 |
-- pragma Compile_Time_Warning |
| 15323 |
-- (boolean_EXPRESSION, static_string_EXPRESSION); |
| 15324 |
|
| 15325 |
when Pragma_Compile_Time_Error | Pragma_Compile_Time_Warning => |
| 15326 |
GNAT_Pragma; |
| 15327 |
|
| 15328 |
Process_Compile_Time_Warning_Or_Error; |
| 15329 |
|
| 15330 |
----------------------------- |
| 15331 |
-- Complete_Representation -- |
| 15332 |
----------------------------- |
| 15333 |
|
| 15334 |
-- pragma Complete_Representation; |
| 15335 |
|
| 15336 |
when Pragma_Complete_Representation => |
| 15337 |
GNAT_Pragma; |
| 15338 |
Check_Arg_Count (0); |
| 15339 |
|
| 15340 |
if Nkind (Parent (N)) /= N_Record_Representation_Clause then |
| 15341 |
Error_Pragma |
| 15342 |
("pragma & must appear within record representation clause"); |
| 15343 |
end if; |
| 15344 |
|
| 15345 |
---------------------------- |
| 15346 |
-- Complex_Representation -- |
| 15347 |
---------------------------- |
| 15348 |
|
| 15349 |
-- pragma Complex_Representation ([Entity =>] LOCAL_NAME); |
| 15350 |
|
| 15351 |
when Pragma_Complex_Representation => Complex_Representation : declare |
| 15352 |
E_Id : Node_Id; |
| 15353 |
E : Entity_Id; |
| 15354 |
Ent : Entity_Id; |
| 15355 |
|
| 15356 |
begin |
| 15357 |
GNAT_Pragma; |
| 15358 |
Check_Arg_Count (1); |
| 15359 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 15360 |
Check_Arg_Is_Local_Name (Arg1); |
| 15361 |
E_Id := Get_Pragma_Arg (Arg1); |
| 15362 |
|
| 15363 |
if Etype (E_Id) = Any_Type then |
| 15364 |
return; |
| 15365 |
end if; |
| 15366 |
|
| 15367 |
E := Entity (E_Id); |
| 15368 |
|
| 15369 |
if not Is_Record_Type (E) then |
| 15370 |
Error_Pragma_Arg |
| 15371 |
("argument for pragma% must be record type", Arg1); |
| 15372 |
end if; |
| 15373 |
|
| 15374 |
Ent := First_Entity (E); |
| 15375 |
|
| 15376 |
if No (Ent) |
| 15377 |
or else No (Next_Entity (Ent)) |
| 15378 |
or else Present (Next_Entity (Next_Entity (Ent))) |
| 15379 |
or else not Is_Floating_Point_Type (Etype (Ent)) |
| 15380 |
or else Etype (Ent) /= Etype (Next_Entity (Ent)) |
| 15381 |
then |
| 15382 |
Error_Pragma_Arg |
| 15383 |
("record for pragma% must have two fields of the same " |
| 15384 |
& "floating-point type", Arg1); |
| 15385 |
|
| 15386 |
else |
| 15387 |
Set_Has_Complex_Representation (Base_Type (E)); |
| 15388 |
|
| 15389 |
-- We need to treat the type has having a non-standard |
| 15390 |
-- representation, for back-end purposes, even though in |
| 15391 |
-- general a complex will have the default representation |
| 15392 |
-- of a record with two real components. |
| 15393 |
|
| 15394 |
Set_Has_Non_Standard_Rep (Base_Type (E)); |
| 15395 |
end if; |
| 15396 |
end Complex_Representation; |
| 15397 |
|
| 15398 |
------------------------- |
| 15399 |
-- Component_Alignment -- |
| 15400 |
------------------------- |
| 15401 |
|
| 15402 |
-- pragma Component_Alignment ( |
| 15403 |
-- [Form =>] ALIGNMENT_CHOICE |
| 15404 |
-- [, [Name =>] type_LOCAL_NAME]); |
| 15405 |
-- |
| 15406 |
-- ALIGNMENT_CHOICE ::= |
| 15407 |
-- Component_Size |
| 15408 |
-- | Component_Size_4 |
| 15409 |
-- | Storage_Unit |
| 15410 |
-- | Default |
| 15411 |
|
| 15412 |
when Pragma_Component_Alignment => Component_AlignmentP : declare |
| 15413 |
Args : Args_List (1 .. 2); |
| 15414 |
Names : constant Name_List (1 .. 2) := ( |
| 15415 |
Name_Form, |
| 15416 |
Name_Name); |
| 15417 |
|
| 15418 |
Form : Node_Id renames Args (1); |
| 15419 |
Name : Node_Id renames Args (2); |
| 15420 |
|
| 15421 |
Atype : Component_Alignment_Kind; |
| 15422 |
Typ : Entity_Id; |
| 15423 |
|
| 15424 |
begin |
| 15425 |
GNAT_Pragma; |
| 15426 |
Gather_Associations (Names, Args); |
| 15427 |
|
| 15428 |
if No (Form) then |
| 15429 |
Error_Pragma ("missing Form argument for pragma%"); |
| 15430 |
end if; |
| 15431 |
|
| 15432 |
Check_Arg_Is_Identifier (Form); |
| 15433 |
|
| 15434 |
-- Get proper alignment, note that Default = Component_Size on all |
| 15435 |
-- machines we have so far, and we want to set this value rather |
| 15436 |
-- than the default value to indicate that it has been explicitly |
| 15437 |
-- set (and thus will not get overridden by the default component |
| 15438 |
-- alignment for the current scope) |
| 15439 |
|
| 15440 |
if Chars (Form) = Name_Component_Size then |
| 15441 |
Atype := Calign_Component_Size; |
| 15442 |
|
| 15443 |
elsif Chars (Form) = Name_Component_Size_4 then |
| 15444 |
Atype := Calign_Component_Size_4; |
| 15445 |
|
| 15446 |
elsif Chars (Form) = Name_Default then |
| 15447 |
Atype := Calign_Component_Size; |
| 15448 |
|
| 15449 |
elsif Chars (Form) = Name_Storage_Unit then |
| 15450 |
Atype := Calign_Storage_Unit; |
| 15451 |
|
| 15452 |
else |
| 15453 |
Error_Pragma_Arg |
| 15454 |
("invalid Form parameter for pragma%", Form); |
| 15455 |
end if; |
| 15456 |
|
| 15457 |
-- The pragma appears in a configuration file |
| 15458 |
|
| 15459 |
if No (Parent (N)) then |
| 15460 |
Check_Valid_Configuration_Pragma; |
| 15461 |
|
| 15462 |
-- Capture the component alignment in a global variable when |
| 15463 |
-- the pragma appears in a configuration file. Note that the |
| 15464 |
-- scope stack is empty at this point and cannot be used to |
| 15465 |
-- store the alignment value. |
| 15466 |
|
| 15467 |
Configuration_Component_Alignment := Atype; |
| 15468 |
|
| 15469 |
-- Case with no name, supplied, affects scope table entry |
| 15470 |
|
| 15471 |
elsif No (Name) then |
| 15472 |
Scope_Stack.Table |
| 15473 |
(Scope_Stack.Last).Component_Alignment_Default := Atype; |
| 15474 |
|
| 15475 |
-- Case of name supplied |
| 15476 |
|
| 15477 |
else |
| 15478 |
Check_Arg_Is_Local_Name (Name); |
| 15479 |
Find_Type (Name); |
| 15480 |
Typ := Entity (Name); |
| 15481 |
|
| 15482 |
if Typ = Any_Type |
| 15483 |
or else Rep_Item_Too_Early (Typ, N) |
| 15484 |
then |
| 15485 |
return; |
| 15486 |
else |
| 15487 |
Typ := Underlying_Type (Typ); |
| 15488 |
end if; |
| 15489 |
|
| 15490 |
if not Is_Record_Type (Typ) |
| 15491 |
and then not Is_Array_Type (Typ) |
| 15492 |
then |
| 15493 |
Error_Pragma_Arg |
| 15494 |
("Name parameter of pragma% must identify record or " |
| 15495 |
& "array type", Name); |
| 15496 |
end if; |
| 15497 |
|
| 15498 |
-- An explicit Component_Alignment pragma overrides an |
| 15499 |
-- implicit pragma Pack, but not an explicit one. |
| 15500 |
|
| 15501 |
if not Has_Pragma_Pack (Base_Type (Typ)) then |
| 15502 |
Set_Is_Packed (Base_Type (Typ), False); |
| 15503 |
Set_Component_Alignment (Base_Type (Typ), Atype); |
| 15504 |
end if; |
| 15505 |
end if; |
| 15506 |
end Component_AlignmentP; |
| 15507 |
|
| 15508 |
-------------------------------- |
| 15509 |
-- Constant_After_Elaboration -- |
| 15510 |
-------------------------------- |
| 15511 |
|
| 15512 |
-- pragma Constant_After_Elaboration [ (boolean_EXPRESSION) ]; |
| 15513 |
|
| 15514 |
when Pragma_Constant_After_Elaboration => Constant_After_Elaboration : |
| 15515 |
declare |
| 15516 |
Obj_Decl : Node_Id; |
| 15517 |
Obj_Id : Entity_Id; |
| 15518 |
|
| 15519 |
begin |
| 15520 |
GNAT_Pragma; |
| 15521 |
Check_No_Identifiers; |
| 15522 |
Check_At_Most_N_Arguments (1); |
| 15523 |
|
| 15524 |
Obj_Decl := Find_Related_Context (N, Do_Checks => True); |
| 15525 |
|
| 15526 |
if Nkind (Obj_Decl) /= N_Object_Declaration then |
| 15527 |
Pragma_Misplaced; |
| 15528 |
end if; |
| 15529 |
|
| 15530 |
Obj_Id := Defining_Entity (Obj_Decl); |
| 15531 |
|
| 15532 |
-- The object declaration must be a library-level variable which |
| 15533 |
-- is either explicitly initialized or obtains a value during the |
| 15534 |
-- elaboration of a package body (SPARK RM 3.3.1). |
| 15535 |
|
| 15536 |
if Ekind (Obj_Id) = E_Variable then |
| 15537 |
if not Is_Library_Level_Entity (Obj_Id) then |
| 15538 |
Error_Pragma |
| 15539 |
("pragma % must apply to a library level variable"); |
| 15540 |
end if; |
| 15541 |
|
| 15542 |
-- Otherwise the pragma applies to a constant, which is illegal |
| 15543 |
|
| 15544 |
else |
| 15545 |
Error_Pragma ("pragma % must apply to a variable declaration"); |
| 15546 |
end if; |
| 15547 |
|
| 15548 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 15549 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 15550 |
|
| 15551 |
Mark_Ghost_Pragma (N, Obj_Id); |
| 15552 |
|
| 15553 |
-- Chain the pragma on the contract for completeness |
| 15554 |
|
| 15555 |
Add_Contract_Item (N, Obj_Id); |
| 15556 |
|
| 15557 |
-- Analyze the Boolean expression (if any) |
| 15558 |
|
| 15559 |
if Present (Arg1) then |
| 15560 |
Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1)); |
| 15561 |
end if; |
| 15562 |
end Constant_After_Elaboration; |
| 15563 |
|
| 15564 |
-------------------- |
| 15565 |
-- Contract_Cases -- |
| 15566 |
-------------------- |
| 15567 |
|
| 15568 |
-- pragma Contract_Cases ((CONTRACT_CASE {, CONTRACT_CASE)); |
| 15569 |
|
| 15570 |
-- CONTRACT_CASE ::= CASE_GUARD => CONSEQUENCE |
| 15571 |
|
| 15572 |
-- CASE_GUARD ::= boolean_EXPRESSION | others |
| 15573 |
|
| 15574 |
-- CONSEQUENCE ::= boolean_EXPRESSION |
| 15575 |
|
| 15576 |
-- Characteristics: |
| 15577 |
|
| 15578 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 15579 |
-- the legal placement and context. Secondary checks preanalyze the |
| 15580 |
-- expressions in: |
| 15581 |
|
| 15582 |
-- Analyze_Contract_Cases_In_Decl_Part |
| 15583 |
|
| 15584 |
-- * Expansion - The annotation is expanded during the expansion of |
| 15585 |
-- the related subprogram [body] contract as performed in: |
| 15586 |
|
| 15587 |
-- Expand_Subprogram_Contract |
| 15588 |
|
| 15589 |
-- * Template - The annotation utilizes the generic template of the |
| 15590 |
-- related subprogram [body] when it is: |
| 15591 |
|
| 15592 |
-- aspect on subprogram declaration |
| 15593 |
-- aspect on stand-alone subprogram body |
| 15594 |
-- pragma on stand-alone subprogram body |
| 15595 |
|
| 15596 |
-- The annotation must prepare its own template when it is: |
| 15597 |
|
| 15598 |
-- pragma on subprogram declaration |
| 15599 |
|
| 15600 |
-- * Globals - Capture of global references must occur after full |
| 15601 |
-- analysis. |
| 15602 |
|
| 15603 |
-- * Instance - The annotation is instantiated automatically when |
| 15604 |
-- the related generic subprogram [body] is instantiated except for |
| 15605 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 15606 |
-- the annotation must instantiate itself. |
| 15607 |
|
| 15608 |
when Pragma_Contract_Cases => Contract_Cases : declare |
| 15609 |
Spec_Id : Entity_Id; |
| 15610 |
Subp_Decl : Node_Id; |
| 15611 |
Subp_Spec : Node_Id; |
| 15612 |
|
| 15613 |
begin |
| 15614 |
GNAT_Pragma; |
| 15615 |
Check_No_Identifiers; |
| 15616 |
Check_Arg_Count (1); |
| 15617 |
|
| 15618 |
-- Ensure the proper placement of the pragma. Contract_Cases must |
| 15619 |
-- be associated with a subprogram declaration or a body that acts |
| 15620 |
-- as a spec. |
| 15621 |
|
| 15622 |
Subp_Decl := |
| 15623 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 15624 |
|
| 15625 |
-- Entry |
| 15626 |
|
| 15627 |
if Nkind (Subp_Decl) = N_Entry_Declaration then |
| 15628 |
null; |
| 15629 |
|
| 15630 |
-- Generic subprogram |
| 15631 |
|
| 15632 |
elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 15633 |
null; |
| 15634 |
|
| 15635 |
-- Body acts as spec |
| 15636 |
|
| 15637 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 15638 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 15639 |
then |
| 15640 |
null; |
| 15641 |
|
| 15642 |
-- Body stub acts as spec |
| 15643 |
|
| 15644 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 15645 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 15646 |
then |
| 15647 |
null; |
| 15648 |
|
| 15649 |
-- Subprogram |
| 15650 |
|
| 15651 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 15652 |
Subp_Spec := Specification (Subp_Decl); |
| 15653 |
|
| 15654 |
-- Pragma Contract_Cases is forbidden on null procedures, as |
| 15655 |
-- this may lead to potential ambiguities in behavior when |
| 15656 |
-- interface null procedures are involved. |
| 15657 |
|
| 15658 |
if Nkind (Subp_Spec) = N_Procedure_Specification |
| 15659 |
and then Null_Present (Subp_Spec) |
| 15660 |
then |
| 15661 |
Error_Msg_N (Fix_Error |
| 15662 |
("pragma % cannot apply to null procedure"), N); |
| 15663 |
return; |
| 15664 |
end if; |
| 15665 |
|
| 15666 |
else |
| 15667 |
Pragma_Misplaced; |
| 15668 |
end if; |
| 15669 |
|
| 15670 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 15671 |
|
| 15672 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 15673 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 15674 |
|
| 15675 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 15676 |
Ensure_Aggregate_Form (Get_Argument (N, Spec_Id)); |
| 15677 |
|
| 15678 |
-- Chain the pragma on the contract for further processing by |
| 15679 |
-- Analyze_Contract_Cases_In_Decl_Part. |
| 15680 |
|
| 15681 |
Add_Contract_Item (N, Defining_Entity (Subp_Decl)); |
| 15682 |
|
| 15683 |
-- Fully analyze the pragma when it appears inside an entry |
| 15684 |
-- or subprogram body because it cannot benefit from forward |
| 15685 |
-- references. |
| 15686 |
|
| 15687 |
if Nkind (Subp_Decl) in N_Entry_Body |
| 15688 |
| N_Subprogram_Body |
| 15689 |
| N_Subprogram_Body_Stub |
| 15690 |
then |
| 15691 |
-- The legality checks of pragma Contract_Cases are affected by |
| 15692 |
-- the SPARK mode in effect and the volatility of the context. |
| 15693 |
-- Analyze all pragmas in a specific order. |
| 15694 |
|
| 15695 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 15696 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 15697 |
Analyze_Contract_Cases_In_Decl_Part (N); |
| 15698 |
end if; |
| 15699 |
end Contract_Cases; |
| 15700 |
|
| 15701 |
---------------- |
| 15702 |
-- Controlled -- |
| 15703 |
---------------- |
| 15704 |
|
| 15705 |
-- pragma Controlled (first_subtype_LOCAL_NAME); |
| 15706 |
|
| 15707 |
when Pragma_Controlled => Controlled : declare |
| 15708 |
Arg : Node_Id; |
| 15709 |
|
| 15710 |
begin |
| 15711 |
Check_No_Identifiers; |
| 15712 |
Check_Arg_Count (1); |
| 15713 |
Check_Arg_Is_Local_Name (Arg1); |
| 15714 |
Arg := Get_Pragma_Arg (Arg1); |
| 15715 |
|
| 15716 |
if not Is_Entity_Name (Arg) |
| 15717 |
or else not Is_Access_Type (Entity (Arg)) |
| 15718 |
then |
| 15719 |
Error_Pragma_Arg ("pragma% requires access type", Arg1); |
| 15720 |
else |
| 15721 |
Set_Has_Pragma_Controlled (Base_Type (Entity (Arg))); |
| 15722 |
end if; |
| 15723 |
end Controlled; |
| 15724 |
|
| 15725 |
---------------- |
| 15726 |
-- Convention -- |
| 15727 |
---------------- |
| 15728 |
|
| 15729 |
-- pragma Convention ([Convention =>] convention_IDENTIFIER, |
| 15730 |
-- [Entity =>] LOCAL_NAME); |
| 15731 |
|
| 15732 |
when Pragma_Convention => Convention : declare |
| 15733 |
C : Convention_Id; |
| 15734 |
E : Entity_Id; |
| 15735 |
pragma Warnings (Off, C); |
| 15736 |
pragma Warnings (Off, E); |
| 15737 |
|
| 15738 |
begin |
| 15739 |
Check_Arg_Order ((Name_Convention, Name_Entity)); |
| 15740 |
Check_Ada_83_Warning; |
| 15741 |
Check_Arg_Count (2); |
| 15742 |
Process_Convention (C, E); |
| 15743 |
|
| 15744 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 15745 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 15746 |
|
| 15747 |
Mark_Ghost_Pragma (N, E); |
| 15748 |
end Convention; |
| 15749 |
|
| 15750 |
--------------------------- |
| 15751 |
-- Convention_Identifier -- |
| 15752 |
--------------------------- |
| 15753 |
|
| 15754 |
-- pragma Convention_Identifier ([Name =>] IDENTIFIER, |
| 15755 |
-- [Convention =>] convention_IDENTIFIER); |
| 15756 |
|
| 15757 |
when Pragma_Convention_Identifier => Convention_Identifier : declare |
| 15758 |
Idnam : Name_Id; |
| 15759 |
Cname : Name_Id; |
| 15760 |
|
| 15761 |
begin |
| 15762 |
GNAT_Pragma; |
| 15763 |
Check_Arg_Order ((Name_Name, Name_Convention)); |
| 15764 |
Check_Arg_Count (2); |
| 15765 |
Check_Optional_Identifier (Arg1, Name_Name); |
| 15766 |
Check_Optional_Identifier (Arg2, Name_Convention); |
| 15767 |
Check_Arg_Is_Identifier (Arg1); |
| 15768 |
Check_Arg_Is_Identifier (Arg2); |
| 15769 |
Idnam := Chars (Get_Pragma_Arg (Arg1)); |
| 15770 |
Cname := Chars (Get_Pragma_Arg (Arg2)); |
| 15771 |
|
| 15772 |
if Is_Convention_Name (Cname) then |
| 15773 |
Record_Convention_Identifier |
| 15774 |
(Idnam, Get_Convention_Id (Cname)); |
| 15775 |
else |
| 15776 |
Error_Pragma_Arg |
| 15777 |
("second arg for % pragma must be convention", Arg2); |
| 15778 |
end if; |
| 15779 |
end Convention_Identifier; |
| 15780 |
|
| 15781 |
--------------- |
| 15782 |
-- CPP_Class -- |
| 15783 |
--------------- |
| 15784 |
|
| 15785 |
-- pragma CPP_Class ([Entity =>] LOCAL_NAME) |
| 15786 |
|
| 15787 |
when Pragma_CPP_Class => |
| 15788 |
GNAT_Pragma; |
| 15789 |
|
| 15790 |
if Warn_On_Obsolescent_Feature then |
| 15791 |
Error_Msg_N |
| 15792 |
("'G'N'A'T pragma cpp'_class is now obsolete and has no " |
| 15793 |
& "effect; replace it by pragma import?j?", N); |
| 15794 |
end if; |
| 15795 |
|
| 15796 |
Check_Arg_Count (1); |
| 15797 |
|
| 15798 |
Rewrite (N, |
| 15799 |
Make_Pragma (Loc, |
| 15800 |
Chars => Name_Import, |
| 15801 |
Pragma_Argument_Associations => New_List ( |
| 15802 |
Make_Pragma_Argument_Association (Loc, |
| 15803 |
Expression => Make_Identifier (Loc, Name_CPP)), |
| 15804 |
New_Copy (First (Pragma_Argument_Associations (N)))))); |
| 15805 |
Analyze (N); |
| 15806 |
|
| 15807 |
--------------------- |
| 15808 |
-- CPP_Constructor -- |
| 15809 |
--------------------- |
| 15810 |
|
| 15811 |
-- pragma CPP_Constructor ([Entity =>] LOCAL_NAME |
| 15812 |
-- [, [External_Name =>] static_string_EXPRESSION ] |
| 15813 |
-- [, [Link_Name =>] static_string_EXPRESSION ]); |
| 15814 |
|
| 15815 |
when Pragma_CPP_Constructor => CPP_Constructor : declare |
| 15816 |
Id : Entity_Id; |
| 15817 |
Def_Id : Entity_Id; |
| 15818 |
Tag_Typ : Entity_Id; |
| 15819 |
|
| 15820 |
begin |
| 15821 |
GNAT_Pragma; |
| 15822 |
Check_At_Least_N_Arguments (1); |
| 15823 |
Check_At_Most_N_Arguments (3); |
| 15824 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 15825 |
Check_Arg_Is_Local_Name (Arg1); |
| 15826 |
|
| 15827 |
Id := Get_Pragma_Arg (Arg1); |
| 15828 |
Find_Program_Unit_Name (Id); |
| 15829 |
|
| 15830 |
-- If we did not find the name, we are done |
| 15831 |
|
| 15832 |
if Etype (Id) = Any_Type then |
| 15833 |
return; |
| 15834 |
end if; |
| 15835 |
|
| 15836 |
Def_Id := Entity (Id); |
| 15837 |
|
| 15838 |
-- Check if already defined as constructor |
| 15839 |
|
| 15840 |
if Is_Constructor (Def_Id) then |
| 15841 |
Error_Msg_N |
| 15842 |
("??duplicate argument for pragma 'C'P'P_Constructor", Arg1); |
| 15843 |
return; |
| 15844 |
end if; |
| 15845 |
|
| 15846 |
if Ekind (Def_Id) = E_Function |
| 15847 |
and then (Is_CPP_Class (Etype (Def_Id)) |
| 15848 |
or else (Is_Class_Wide_Type (Etype (Def_Id)) |
| 15849 |
and then |
| 15850 |
Is_CPP_Class (Root_Type (Etype (Def_Id))))) |
| 15851 |
then |
| 15852 |
if Scope (Def_Id) /= Scope (Etype (Def_Id)) then |
| 15853 |
Error_Msg_N |
| 15854 |
("'C'P'P constructor must be defined in the scope of " |
| 15855 |
& "its returned type", Arg1); |
| 15856 |
end if; |
| 15857 |
|
| 15858 |
if Arg_Count >= 2 then |
| 15859 |
Set_Imported (Def_Id); |
| 15860 |
Set_Is_Public (Def_Id); |
| 15861 |
Process_Interface_Name (Def_Id, Arg2, Arg3, N); |
| 15862 |
end if; |
| 15863 |
|
| 15864 |
Set_Has_Completion (Def_Id); |
| 15865 |
Set_Is_Constructor (Def_Id); |
| 15866 |
Set_Convention (Def_Id, Convention_CPP); |
| 15867 |
|
| 15868 |
-- Imported C++ constructors are not dispatching primitives |
| 15869 |
-- because in C++ they don't have a dispatch table slot. |
| 15870 |
-- However, in Ada the constructor has the profile of a |
| 15871 |
-- function that returns a tagged type and therefore it has |
| 15872 |
-- been treated as a primitive operation during semantic |
| 15873 |
-- analysis. We now remove it from the list of primitive |
| 15874 |
-- operations of the type. |
| 15875 |
|
| 15876 |
if Is_Tagged_Type (Etype (Def_Id)) |
| 15877 |
and then not Is_Class_Wide_Type (Etype (Def_Id)) |
| 15878 |
and then Is_Dispatching_Operation (Def_Id) |
| 15879 |
then |
| 15880 |
Tag_Typ := Etype (Def_Id); |
| 15881 |
|
| 15882 |
Remove (Primitive_Operations (Tag_Typ), Def_Id); |
| 15883 |
Set_Is_Dispatching_Operation (Def_Id, False); |
| 15884 |
end if; |
| 15885 |
|
| 15886 |
-- For backward compatibility, if the constructor returns a |
| 15887 |
-- class wide type, and we internally change the return type to |
| 15888 |
-- the corresponding root type. |
| 15889 |
|
| 15890 |
if Is_Class_Wide_Type (Etype (Def_Id)) then |
| 15891 |
Set_Etype (Def_Id, Root_Type (Etype (Def_Id))); |
| 15892 |
end if; |
| 15893 |
else |
| 15894 |
Error_Pragma_Arg |
| 15895 |
("pragma% requires function returning a 'C'P'P_Class type", |
| 15896 |
Arg1); |
| 15897 |
end if; |
| 15898 |
end CPP_Constructor; |
| 15899 |
|
| 15900 |
----------------- |
| 15901 |
-- CPP_Virtual -- |
| 15902 |
----------------- |
| 15903 |
|
| 15904 |
when Pragma_CPP_Virtual => |
| 15905 |
GNAT_Pragma; |
| 15906 |
|
| 15907 |
if Warn_On_Obsolescent_Feature then |
| 15908 |
Error_Msg_N |
| 15909 |
("'G'N'A'T pragma Cpp'_Virtual is now obsolete and has no " |
| 15910 |
& "effect?j?", N); |
| 15911 |
end if; |
| 15912 |
|
| 15913 |
----------------- |
| 15914 |
-- CUDA_Device -- |
| 15915 |
----------------- |
| 15916 |
|
| 15917 |
-- pragma CUDA_Device (LOCAL_NAME); |
| 15918 |
|
| 15919 |
when Pragma_CUDA_Device => CUDA_Device : declare |
| 15920 |
Arg_Node : Node_Id; |
| 15921 |
Device_Entity : Entity_Id; |
| 15922 |
begin |
| 15923 |
GNAT_Pragma; |
| 15924 |
Check_Arg_Count (1); |
| 15925 |
Check_Arg_Is_Library_Level_Local_Name (Arg1); |
| 15926 |
|
| 15927 |
Arg_Node := Get_Pragma_Arg (Arg1); |
| 15928 |
Device_Entity := Entity (Arg_Node); |
| 15929 |
|
| 15930 |
if Ekind (Device_Entity) in E_Variable |
| 15931 |
| E_Constant |
| 15932 |
| E_Procedure |
| 15933 |
| E_Function |
| 15934 |
then |
| 15935 |
Add_CUDA_Device_Entity |
| 15936 |
(Package_Specification_Of_Scope (Scope (Device_Entity)), |
| 15937 |
Device_Entity); |
| 15938 |
|
| 15939 |
else |
| 15940 |
Error_Msg_NE ("& must be constant, variable or subprogram", |
| 15941 |
N, |
| 15942 |
Device_Entity); |
| 15943 |
end if; |
| 15944 |
|
| 15945 |
end CUDA_Device; |
| 15946 |
|
| 15947 |
------------------ |
| 15948 |
-- CUDA_Execute -- |
| 15949 |
------------------ |
| 15950 |
|
| 15951 |
-- pragma CUDA_Execute (PROCEDURE_CALL_STATEMENT, |
| 15952 |
-- EXPRESSION, |
| 15953 |
-- EXPRESSION, |
| 15954 |
-- [, EXPRESSION |
| 15955 |
-- [, EXPRESSION]]); |
| 15956 |
|
| 15957 |
when Pragma_CUDA_Execute => CUDA_Execute : declare |
| 15958 |
|
| 15959 |
function Is_Acceptable_Dim3 (N : Node_Id) return Boolean; |
| 15960 |
-- Returns True if N is an acceptable argument for CUDA_Execute, |
| 15961 |
-- False otherwise. |
| 15962 |
|
| 15963 |
------------------------ |
| 15964 |
-- Is_Acceptable_Dim3 -- |
| 15965 |
------------------------ |
| 15966 |
|
| 15967 |
function Is_Acceptable_Dim3 (N : Node_Id) return Boolean is |
| 15968 |
Expr : Node_Id; |
| 15969 |
begin |
| 15970 |
if Is_RTE (Etype (N), RE_Dim3) |
| 15971 |
or else Is_Integer_Type (Etype (N)) |
| 15972 |
then |
| 15973 |
return True; |
| 15974 |
end if; |
| 15975 |
|
| 15976 |
if Nkind (N) = N_Aggregate |
| 15977 |
and then not Null_Record_Present (N) |
| 15978 |
and then No (Component_Associations (N)) |
| 15979 |
and then List_Length (Expressions (N)) = 3 |
| 15980 |
then |
| 15981 |
Expr := First (Expressions (N)); |
| 15982 |
while Present (Expr) loop |
| 15983 |
Analyze_And_Resolve (Expr, Any_Integer); |
| 15984 |
Next (Expr); |
| 15985 |
end loop; |
| 15986 |
return True; |
| 15987 |
end if; |
| 15988 |
|
| 15989 |
return False; |
| 15990 |
end Is_Acceptable_Dim3; |
| 15991 |
|
| 15992 |
-- Local variables |
| 15993 |
|
| 15994 |
Block_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg3); |
| 15995 |
Grid_Dimensions : constant Node_Id := Get_Pragma_Arg (Arg2); |
| 15996 |
Kernel_Call : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 15997 |
Shared_Memory : Node_Id; |
| 15998 |
Stream : Node_Id; |
| 15999 |
|
| 16000 |
-- Start of processing for CUDA_Execute |
| 16001 |
|
| 16002 |
begin |
| 16003 |
GNAT_Pragma; |
| 16004 |
Check_At_Least_N_Arguments (3); |
| 16005 |
Check_At_Most_N_Arguments (5); |
| 16006 |
|
| 16007 |
Analyze_And_Resolve (Kernel_Call); |
| 16008 |
if Nkind (Kernel_Call) /= N_Function_Call |
| 16009 |
or else Etype (Kernel_Call) /= Standard_Void_Type |
| 16010 |
then |
| 16011 |
-- In `pragma CUDA_Execute (Kernel_Call (...), ...)`, |
| 16012 |
-- GNAT sees Kernel_Call as an N_Function_Call since |
| 16013 |
-- Kernel_Call "looks" like an expression. However, only |
| 16014 |
-- procedures can be kernels, so to make things easier for the |
| 16015 |
-- user the error message complains about Kernel_Call not being |
| 16016 |
-- a procedure call. |
| 16017 |
|
| 16018 |
Error_Msg_N ("first argument of & must be a procedure call", N); |
| 16019 |
end if; |
| 16020 |
|
| 16021 |
Analyze (Grid_Dimensions); |
| 16022 |
if not Is_Acceptable_Dim3 (Grid_Dimensions) then |
| 16023 |
Error_Msg_N |
| 16024 |
("second argument of & must be an Integer, Dim3 or aggregate " |
| 16025 |
& "containing 3 Integers", N); |
| 16026 |
end if; |
| 16027 |
|
| 16028 |
Analyze (Block_Dimensions); |
| 16029 |
if not Is_Acceptable_Dim3 (Block_Dimensions) then |
| 16030 |
Error_Msg_N |
| 16031 |
("third argument of & must be an Integer, Dim3 or aggregate " |
| 16032 |
& "containing 3 Integers", N); |
| 16033 |
end if; |
| 16034 |
|
| 16035 |
if Present (Arg4) then |
| 16036 |
Shared_Memory := Get_Pragma_Arg (Arg4); |
| 16037 |
Analyze_And_Resolve (Shared_Memory, Any_Integer); |
| 16038 |
|
| 16039 |
if Present (Arg5) then |
| 16040 |
Stream := Get_Pragma_Arg (Arg5); |
| 16041 |
Analyze_And_Resolve (Stream, RTE (RE_Stream_T)); |
| 16042 |
end if; |
| 16043 |
end if; |
| 16044 |
end CUDA_Execute; |
| 16045 |
|
| 16046 |
----------------- |
| 16047 |
-- CUDA_Global -- |
| 16048 |
----------------- |
| 16049 |
|
| 16050 |
-- pragma CUDA_Global ([Entity =>] procedure_LOCAL_NAME); |
| 16051 |
|
| 16052 |
when Pragma_CUDA_Global => CUDA_Global : declare |
| 16053 |
Arg_Node : Node_Id; |
| 16054 |
Kernel_Proc : Entity_Id; |
| 16055 |
Pack_Id : Entity_Id; |
| 16056 |
begin |
| 16057 |
GNAT_Pragma; |
| 16058 |
Check_Arg_Count (1); |
| 16059 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 16060 |
Check_Arg_Is_Local_Name (Arg1); |
| 16061 |
|
| 16062 |
Arg_Node := Get_Pragma_Arg (Arg1); |
| 16063 |
Analyze (Arg_Node); |
| 16064 |
|
| 16065 |
Kernel_Proc := Entity (Arg_Node); |
| 16066 |
Pack_Id := Scope (Kernel_Proc); |
| 16067 |
|
| 16068 |
if Ekind (Kernel_Proc) /= E_Procedure then |
| 16069 |
Error_Msg_NE ("& must be a procedure", N, Kernel_Proc); |
| 16070 |
|
| 16071 |
elsif Ekind (Pack_Id) /= E_Package |
| 16072 |
or else not Is_Library_Level_Entity (Pack_Id) |
| 16073 |
then |
| 16074 |
Error_Msg_NE |
| 16075 |
("& must reside in a library-level package", N, Kernel_Proc); |
| 16076 |
|
| 16077 |
else |
| 16078 |
Set_Is_CUDA_Kernel (Kernel_Proc); |
| 16079 |
Add_CUDA_Kernel (Pack_Id, Kernel_Proc); |
| 16080 |
end if; |
| 16081 |
end CUDA_Global; |
| 16082 |
|
| 16083 |
---------------- |
| 16084 |
-- CPP_Vtable -- |
| 16085 |
---------------- |
| 16086 |
|
| 16087 |
when Pragma_CPP_Vtable => |
| 16088 |
GNAT_Pragma; |
| 16089 |
|
| 16090 |
if Warn_On_Obsolescent_Feature then |
| 16091 |
Error_Msg_N |
| 16092 |
("'G'N'A'T pragma Cpp'_Vtable is now obsolete and has no " |
| 16093 |
& "effect?j?", N); |
| 16094 |
end if; |
| 16095 |
|
| 16096 |
--------- |
| 16097 |
-- CPU -- |
| 16098 |
--------- |
| 16099 |
|
| 16100 |
-- pragma CPU (EXPRESSION); |
| 16101 |
|
| 16102 |
when Pragma_CPU => CPU : declare |
| 16103 |
P : constant Node_Id := Parent (N); |
| 16104 |
Arg : Node_Id; |
| 16105 |
Ent : Entity_Id; |
| 16106 |
|
| 16107 |
begin |
| 16108 |
Ada_2012_Pragma; |
| 16109 |
Check_No_Identifiers; |
| 16110 |
Check_Arg_Count (1); |
| 16111 |
Arg := Get_Pragma_Arg (Arg1); |
| 16112 |
|
| 16113 |
-- Subprogram case |
| 16114 |
|
| 16115 |
if Nkind (P) = N_Subprogram_Body then |
| 16116 |
Check_In_Main_Program; |
| 16117 |
|
| 16118 |
Analyze_And_Resolve (Arg, Any_Integer); |
| 16119 |
|
| 16120 |
Ent := Defining_Unit_Name (Specification (P)); |
| 16121 |
|
| 16122 |
if Nkind (Ent) = N_Defining_Program_Unit_Name then |
| 16123 |
Ent := Defining_Identifier (Ent); |
| 16124 |
end if; |
| 16125 |
|
| 16126 |
-- Must be static |
| 16127 |
|
| 16128 |
if not Is_OK_Static_Expression (Arg) then |
| 16129 |
Flag_Non_Static_Expr |
| 16130 |
("main subprogram affinity is not static!", Arg); |
| 16131 |
raise Pragma_Exit; |
| 16132 |
|
| 16133 |
-- If constraint error, then we already signalled an error |
| 16134 |
|
| 16135 |
elsif Raises_Constraint_Error (Arg) then |
| 16136 |
null; |
| 16137 |
|
| 16138 |
-- Otherwise check in range |
| 16139 |
|
| 16140 |
else |
| 16141 |
declare |
| 16142 |
CPU_Id : constant Entity_Id := RTE (RE_CPU_Range); |
| 16143 |
-- This is the entity System.Multiprocessors.CPU_Range; |
| 16144 |
|
| 16145 |
Val : constant Uint := Expr_Value (Arg); |
| 16146 |
|
| 16147 |
begin |
| 16148 |
if Val < Expr_Value (Type_Low_Bound (CPU_Id)) |
| 16149 |
or else |
| 16150 |
Val > Expr_Value (Type_High_Bound (CPU_Id)) |
| 16151 |
then |
| 16152 |
Error_Pragma_Arg |
| 16153 |
("main subprogram CPU is out of range", Arg1); |
| 16154 |
end if; |
| 16155 |
end; |
| 16156 |
end if; |
| 16157 |
|
| 16158 |
Set_Main_CPU |
| 16159 |
(Current_Sem_Unit, UI_To_Int (Expr_Value (Arg))); |
| 16160 |
|
| 16161 |
-- Task case |
| 16162 |
|
| 16163 |
elsif Nkind (P) = N_Task_Definition then |
| 16164 |
Ent := Defining_Identifier (Parent (P)); |
| 16165 |
|
| 16166 |
-- The expression must be analyzed in the special manner |
| 16167 |
-- described in "Handling of Default and Per-Object |
| 16168 |
-- Expressions" in sem.ads. |
| 16169 |
|
| 16170 |
Preanalyze_Spec_Expression (Arg, RTE (RE_CPU_Range)); |
| 16171 |
|
| 16172 |
-- See comment in Sem_Ch13 about the following restrictions |
| 16173 |
|
| 16174 |
if Is_OK_Static_Expression (Arg) then |
| 16175 |
if Expr_Value (Arg) = Uint_0 then |
| 16176 |
Check_Restriction (No_Tasks_Unassigned_To_CPU, N); |
| 16177 |
end if; |
| 16178 |
else |
| 16179 |
Check_Restriction (No_Dynamic_CPU_Assignment, N); |
| 16180 |
end if; |
| 16181 |
|
| 16182 |
-- Anything else is incorrect |
| 16183 |
|
| 16184 |
else |
| 16185 |
Pragma_Misplaced; |
| 16186 |
end if; |
| 16187 |
|
| 16188 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 16189 |
-- Item chain of Ent. |
| 16190 |
|
| 16191 |
Check_Duplicate_Pragma (Ent); |
| 16192 |
Record_Rep_Item (Ent, N); |
| 16193 |
end CPU; |
| 16194 |
|
| 16195 |
-------------------- |
| 16196 |
-- Deadline_Floor -- |
| 16197 |
-------------------- |
| 16198 |
|
| 16199 |
-- pragma Deadline_Floor (time_span_EXPRESSION); |
| 16200 |
|
| 16201 |
when Pragma_Deadline_Floor => Deadline_Floor : declare |
| 16202 |
P : constant Node_Id := Parent (N); |
| 16203 |
Arg : Node_Id; |
| 16204 |
Ent : Entity_Id; |
| 16205 |
|
| 16206 |
begin |
| 16207 |
GNAT_Pragma; |
| 16208 |
Check_No_Identifiers; |
| 16209 |
Check_Arg_Count (1); |
| 16210 |
|
| 16211 |
Arg := Get_Pragma_Arg (Arg1); |
| 16212 |
|
| 16213 |
-- The expression must be analyzed in the special manner described |
| 16214 |
-- in "Handling of Default and Per-Object Expressions" in sem.ads. |
| 16215 |
|
| 16216 |
Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span)); |
| 16217 |
|
| 16218 |
-- Only protected types allowed |
| 16219 |
|
| 16220 |
if Nkind (P) /= N_Protected_Definition then |
| 16221 |
Pragma_Misplaced; |
| 16222 |
|
| 16223 |
else |
| 16224 |
Ent := Defining_Identifier (Parent (P)); |
| 16225 |
|
| 16226 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 16227 |
-- Item chain of Ent. |
| 16228 |
|
| 16229 |
Check_Duplicate_Pragma (Ent); |
| 16230 |
Record_Rep_Item (Ent, N); |
| 16231 |
end if; |
| 16232 |
end Deadline_Floor; |
| 16233 |
|
| 16234 |
----------- |
| 16235 |
-- Debug -- |
| 16236 |
----------- |
| 16237 |
|
| 16238 |
-- pragma Debug ([boolean_EXPRESSION,] PROCEDURE_CALL_STATEMENT); |
| 16239 |
|
| 16240 |
when Pragma_Debug => Debug : declare |
| 16241 |
Cond : Node_Id; |
| 16242 |
Call : Node_Id; |
| 16243 |
|
| 16244 |
begin |
| 16245 |
GNAT_Pragma; |
| 16246 |
|
| 16247 |
-- The condition for executing the call is that the expander |
| 16248 |
-- is active and that we are not ignoring this debug pragma. |
| 16249 |
|
| 16250 |
Cond := |
| 16251 |
New_Occurrence_Of |
| 16252 |
(Boolean_Literals |
| 16253 |
(Expander_Active and then not Is_Ignored (N)), |
| 16254 |
Loc); |
| 16255 |
|
| 16256 |
if not Is_Ignored (N) then |
| 16257 |
Set_SCO_Pragma_Enabled (Loc); |
| 16258 |
end if; |
| 16259 |
|
| 16260 |
if Arg_Count = 2 then |
| 16261 |
Cond := |
| 16262 |
Make_And_Then (Loc, |
| 16263 |
Left_Opnd => Relocate_Node (Cond), |
| 16264 |
Right_Opnd => Get_Pragma_Arg (Arg1)); |
| 16265 |
Call := Get_Pragma_Arg (Arg2); |
| 16266 |
else |
| 16267 |
Call := Get_Pragma_Arg (Arg1); |
| 16268 |
end if; |
| 16269 |
|
| 16270 |
if Nkind (Call) in N_Expanded_Name |
| 16271 |
| N_Function_Call |
| 16272 |
| N_Identifier |
| 16273 |
| N_Indexed_Component |
| 16274 |
| N_Selected_Component |
| 16275 |
then |
| 16276 |
-- If this pragma Debug comes from source, its argument was |
| 16277 |
-- parsed as a name form (which is syntactically identical). |
| 16278 |
-- In a generic context a parameterless call will be left as |
| 16279 |
-- an expanded name (if global) or selected_component if local. |
| 16280 |
-- Change it to a procedure call statement now. |
| 16281 |
|
| 16282 |
Change_Name_To_Procedure_Call_Statement (Call); |
| 16283 |
|
| 16284 |
elsif Nkind (Call) = N_Procedure_Call_Statement then |
| 16285 |
|
| 16286 |
-- Already in the form of a procedure call statement: nothing |
| 16287 |
-- to do (could happen in case of an internally generated |
| 16288 |
-- pragma Debug). |
| 16289 |
|
| 16290 |
null; |
| 16291 |
|
| 16292 |
else |
| 16293 |
-- All other cases: diagnose error |
| 16294 |
|
| 16295 |
Error_Msg_N |
| 16296 |
("argument of pragma ""Debug"" is not procedure call", Call); |
| 16297 |
return; |
| 16298 |
end if; |
| 16299 |
|
| 16300 |
-- Rewrite into a conditional with an appropriate condition. We |
| 16301 |
-- wrap the procedure call in a block so that overhead from e.g. |
| 16302 |
-- use of the secondary stack does not generate execution overhead |
| 16303 |
-- for suppressed conditions. |
| 16304 |
|
| 16305 |
-- Normally the analysis that follows will freeze the subprogram |
| 16306 |
-- being called. However, if the call is to a null procedure, |
| 16307 |
-- we want to freeze it before creating the block, because the |
| 16308 |
-- analysis that follows may be done with expansion disabled, in |
| 16309 |
-- which case the body will not be generated, leading to spurious |
| 16310 |
-- errors. |
| 16311 |
|
| 16312 |
if Nkind (Call) = N_Procedure_Call_Statement |
| 16313 |
and then Is_Entity_Name (Name (Call)) |
| 16314 |
then |
| 16315 |
Analyze (Name (Call)); |
| 16316 |
Freeze_Before (N, Entity (Name (Call))); |
| 16317 |
end if; |
| 16318 |
|
| 16319 |
Rewrite (N, |
| 16320 |
Make_Implicit_If_Statement (N, |
| 16321 |
Condition => Cond, |
| 16322 |
Then_Statements => New_List ( |
| 16323 |
Make_Block_Statement (Loc, |
| 16324 |
Handled_Statement_Sequence => |
| 16325 |
Make_Handled_Sequence_Of_Statements (Loc, |
| 16326 |
Statements => New_List (Relocate_Node (Call))))))); |
| 16327 |
Analyze (N); |
| 16328 |
|
| 16329 |
-- Ignore pragma Debug in GNATprove mode. Do this rewriting |
| 16330 |
-- after analysis of the normally rewritten node, to capture all |
| 16331 |
-- references to entities, which avoids issuing wrong warnings |
| 16332 |
-- about unused entities. |
| 16333 |
|
| 16334 |
if GNATprove_Mode then |
| 16335 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 16336 |
end if; |
| 16337 |
end Debug; |
| 16338 |
|
| 16339 |
------------------ |
| 16340 |
-- Debug_Policy -- |
| 16341 |
------------------ |
| 16342 |
|
| 16343 |
-- pragma Debug_Policy (On | Off | Check | Disable | Ignore) |
| 16344 |
|
| 16345 |
when Pragma_Debug_Policy => |
| 16346 |
GNAT_Pragma; |
| 16347 |
Check_Arg_Count (1); |
| 16348 |
Check_No_Identifiers; |
| 16349 |
Check_Arg_Is_Identifier (Arg1); |
| 16350 |
|
| 16351 |
-- Exactly equivalent to pragma Check_Policy (Debug, arg), so |
| 16352 |
-- rewrite it that way, and let the rest of the checking come |
| 16353 |
-- from analyzing the rewritten pragma. |
| 16354 |
|
| 16355 |
Rewrite (N, |
| 16356 |
Make_Pragma (Loc, |
| 16357 |
Chars => Name_Check_Policy, |
| 16358 |
Pragma_Argument_Associations => New_List ( |
| 16359 |
Make_Pragma_Argument_Association (Loc, |
| 16360 |
Expression => Make_Identifier (Loc, Name_Debug)), |
| 16361 |
|
| 16362 |
Make_Pragma_Argument_Association (Loc, |
| 16363 |
Expression => Get_Pragma_Arg (Arg1))))); |
| 16364 |
Analyze (N); |
| 16365 |
|
| 16366 |
------------------------------- |
| 16367 |
-- Default_Initial_Condition -- |
| 16368 |
------------------------------- |
| 16369 |
|
| 16370 |
-- pragma Default_Initial_Condition [ (null | boolean_EXPRESSION) ]; |
| 16371 |
|
| 16372 |
when Pragma_Default_Initial_Condition => DIC : declare |
| 16373 |
Discard : Boolean; |
| 16374 |
Stmt : Node_Id; |
| 16375 |
Typ : Entity_Id; |
| 16376 |
|
| 16377 |
begin |
| 16378 |
GNAT_Pragma; |
| 16379 |
Check_No_Identifiers; |
| 16380 |
Check_At_Most_N_Arguments (2); -- Accounts for implicit type arg |
| 16381 |
|
| 16382 |
Typ := Empty; |
| 16383 |
Stmt := Prev (N); |
| 16384 |
while Present (Stmt) loop |
| 16385 |
|
| 16386 |
-- Skip prior pragmas, but check for duplicates |
| 16387 |
|
| 16388 |
if Nkind (Stmt) = N_Pragma then |
| 16389 |
if Pragma_Name (Stmt) = Pname then |
| 16390 |
Duplication_Error |
| 16391 |
(Prag => N, |
| 16392 |
Prev => Stmt); |
| 16393 |
raise Pragma_Exit; |
| 16394 |
end if; |
| 16395 |
|
| 16396 |
-- Skip internally generated code. Note that derived type |
| 16397 |
-- declarations of untagged types with discriminants are |
| 16398 |
-- rewritten as private type declarations. |
| 16399 |
|
| 16400 |
elsif not Comes_From_Source (Stmt) |
| 16401 |
and then Nkind (Stmt) /= N_Private_Type_Declaration |
| 16402 |
then |
| 16403 |
null; |
| 16404 |
|
| 16405 |
-- The associated private type [extension] has been found, stop |
| 16406 |
-- the search. |
| 16407 |
|
| 16408 |
elsif Nkind (Stmt) in N_Private_Extension_Declaration |
| 16409 |
| N_Private_Type_Declaration |
| 16410 |
then |
| 16411 |
Typ := Defining_Entity (Stmt); |
| 16412 |
exit; |
| 16413 |
|
| 16414 |
-- The pragma does not apply to a legal construct, issue an |
| 16415 |
-- error and stop the analysis. |
| 16416 |
|
| 16417 |
else |
| 16418 |
Pragma_Misplaced; |
| 16419 |
end if; |
| 16420 |
|
| 16421 |
Stmt := Prev (Stmt); |
| 16422 |
end loop; |
| 16423 |
|
| 16424 |
-- The pragma does not apply to a legal construct, issue an error |
| 16425 |
-- and stop the analysis. |
| 16426 |
|
| 16427 |
if No (Typ) then |
| 16428 |
Pragma_Misplaced; |
| 16429 |
end if; |
| 16430 |
|
| 16431 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 16432 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 16433 |
|
| 16434 |
Mark_Ghost_Pragma (N, Typ); |
| 16435 |
|
| 16436 |
-- The pragma signals that the type defines its own DIC assertion |
| 16437 |
-- expression. |
| 16438 |
|
| 16439 |
Set_Has_Own_DIC (Typ); |
| 16440 |
|
| 16441 |
-- A type entity argument is appended to facilitate inheriting the |
| 16442 |
-- aspect/pragma from parent types (see Build_DIC_Procedure_Body), |
| 16443 |
-- though that extra argument isn't documented for the pragma. |
| 16444 |
|
| 16445 |
if No (Arg2) then |
| 16446 |
-- When the pragma has no arguments, create an argument with |
| 16447 |
-- the value Empty, so the type name argument can be appended |
| 16448 |
-- following it (since it's expected as the second argument). |
| 16449 |
|
| 16450 |
if No (Arg1) then |
| 16451 |
Set_Pragma_Argument_Associations (N, New_List ( |
| 16452 |
Make_Pragma_Argument_Association (Sloc (Typ), |
| 16453 |
Expression => Empty))); |
| 16454 |
end if; |
| 16455 |
|
| 16456 |
Append_To |
| 16457 |
(Pragma_Argument_Associations (N), |
| 16458 |
Make_Pragma_Argument_Association (Sloc (Typ), |
| 16459 |
Expression => New_Occurrence_Of (Typ, Sloc (Typ)))); |
| 16460 |
end if; |
| 16461 |
|
| 16462 |
-- Chain the pragma on the rep item chain for further processing |
| 16463 |
|
| 16464 |
Discard := Rep_Item_Too_Late (Typ, N, FOnly => True); |
| 16465 |
|
| 16466 |
-- Create the declaration of the procedure which verifies the |
| 16467 |
-- assertion expression of pragma DIC at runtime. |
| 16468 |
|
| 16469 |
Build_DIC_Procedure_Declaration (Typ); |
| 16470 |
end DIC; |
| 16471 |
|
| 16472 |
---------------------------------- |
| 16473 |
-- Default_Scalar_Storage_Order -- |
| 16474 |
---------------------------------- |
| 16475 |
|
| 16476 |
-- pragma Default_Scalar_Storage_Order |
| 16477 |
-- (High_Order_First | Low_Order_First); |
| 16478 |
|
| 16479 |
when Pragma_Default_Scalar_Storage_Order => DSSO : declare |
| 16480 |
Default : Character; |
| 16481 |
|
| 16482 |
begin |
| 16483 |
GNAT_Pragma; |
| 16484 |
Check_Arg_Count (1); |
| 16485 |
|
| 16486 |
-- Default_Scalar_Storage_Order can appear as a configuration |
| 16487 |
-- pragma, or in a declarative part of a package spec. |
| 16488 |
|
| 16489 |
if not Is_Configuration_Pragma then |
| 16490 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 16491 |
end if; |
| 16492 |
|
| 16493 |
Check_No_Identifiers; |
| 16494 |
Check_Arg_Is_One_Of |
| 16495 |
(Arg1, Name_High_Order_First, Name_Low_Order_First); |
| 16496 |
Get_Name_String (Chars (Get_Pragma_Arg (Arg1))); |
| 16497 |
Default := Fold_Upper (Name_Buffer (1)); |
| 16498 |
|
| 16499 |
if not Support_Nondefault_SSO_On_Target |
| 16500 |
and then Ttypes.Bytes_Big_Endian /= (Default = 'H') |
| 16501 |
then |
| 16502 |
if Warn_On_Unrecognized_Pragma then |
| 16503 |
Error_Msg_N |
| 16504 |
("non-default Scalar_Storage_Order not supported " |
| 16505 |
& "on target?g?", N); |
| 16506 |
Error_Msg_N |
| 16507 |
("\pragma Default_Scalar_Storage_Order ignored?g?", N); |
| 16508 |
end if; |
| 16509 |
|
| 16510 |
-- Here set the specified default |
| 16511 |
|
| 16512 |
else |
| 16513 |
Opt.Default_SSO := Default; |
| 16514 |
end if; |
| 16515 |
end DSSO; |
| 16516 |
|
| 16517 |
-------------------------- |
| 16518 |
-- Default_Storage_Pool -- |
| 16519 |
-------------------------- |
| 16520 |
|
| 16521 |
-- pragma Default_Storage_Pool (storage_pool_NAME | null | Standard); |
| 16522 |
|
| 16523 |
when Pragma_Default_Storage_Pool => Default_Storage_Pool : declare |
| 16524 |
Pool : Node_Id; |
| 16525 |
|
| 16526 |
begin |
| 16527 |
Ada_2012_Pragma; |
| 16528 |
Check_Arg_Count (1); |
| 16529 |
|
| 16530 |
-- Default_Storage_Pool can appear as a configuration pragma, or |
| 16531 |
-- in a declarative part of a package spec. |
| 16532 |
|
| 16533 |
if not Is_Configuration_Pragma then |
| 16534 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 16535 |
end if; |
| 16536 |
|
| 16537 |
if From_Aspect_Specification (N) then |
| 16538 |
declare |
| 16539 |
E : constant Entity_Id := Entity (Corresponding_Aspect (N)); |
| 16540 |
begin |
| 16541 |
if not In_Open_Scopes (E) then |
| 16542 |
Error_Msg_N |
| 16543 |
("aspect must apply to package or subprogram", N); |
| 16544 |
end if; |
| 16545 |
end; |
| 16546 |
end if; |
| 16547 |
|
| 16548 |
if Present (Arg1) then |
| 16549 |
Pool := Get_Pragma_Arg (Arg1); |
| 16550 |
|
| 16551 |
-- Case of Default_Storage_Pool (null); |
| 16552 |
|
| 16553 |
if Nkind (Pool) = N_Null then |
| 16554 |
Analyze (Pool); |
| 16555 |
|
| 16556 |
-- This is an odd case, this is not really an expression, |
| 16557 |
-- so we don't have a type for it. So just set the type to |
| 16558 |
-- Empty. |
| 16559 |
|
| 16560 |
Set_Etype (Pool, Empty); |
| 16561 |
|
| 16562 |
-- Case of Default_Storage_Pool (Standard); |
| 16563 |
|
| 16564 |
elsif Nkind (Pool) = N_Identifier |
| 16565 |
and then Chars (Pool) = Name_Standard |
| 16566 |
then |
| 16567 |
Analyze (Pool); |
| 16568 |
|
| 16569 |
if Entity (Pool) /= Standard_Standard then |
| 16570 |
Error_Pragma_Arg |
| 16571 |
("package Standard is not directly visible", Arg1); |
| 16572 |
end if; |
| 16573 |
|
| 16574 |
-- Case of Default_Storage_Pool (storage_pool_NAME); |
| 16575 |
|
| 16576 |
else |
| 16577 |
-- If it's a configuration pragma, then the only allowed |
| 16578 |
-- argument is "null". |
| 16579 |
|
| 16580 |
if Is_Configuration_Pragma then |
| 16581 |
Error_Pragma_Arg ("NULL or Standard expected", Arg1); |
| 16582 |
end if; |
| 16583 |
|
| 16584 |
-- The expected type for a non-"null" argument is |
| 16585 |
-- Root_Storage_Pool'Class, and the pool must be a variable. |
| 16586 |
|
| 16587 |
Analyze_And_Resolve |
| 16588 |
(Pool, Class_Wide_Type (RTE (RE_Root_Storage_Pool))); |
| 16589 |
|
| 16590 |
if Is_Variable (Pool) then |
| 16591 |
|
| 16592 |
-- A pragma that applies to a Ghost entity becomes Ghost |
| 16593 |
-- for the purposes of legality checks and removal of |
| 16594 |
-- ignored Ghost code. |
| 16595 |
|
| 16596 |
Mark_Ghost_Pragma (N, Entity (Pool)); |
| 16597 |
|
| 16598 |
else |
| 16599 |
Error_Pragma_Arg |
| 16600 |
("default storage pool must be a variable", Arg1); |
| 16601 |
end if; |
| 16602 |
end if; |
| 16603 |
|
| 16604 |
-- Record the pool name (or null). Freeze.Freeze_Entity for an |
| 16605 |
-- access type will use this information to set the appropriate |
| 16606 |
-- attributes of the access type. If the pragma appears in a |
| 16607 |
-- generic unit it is ignored, given that it may refer to a |
| 16608 |
-- local entity. |
| 16609 |
|
| 16610 |
if not Inside_A_Generic then |
| 16611 |
Default_Pool := Pool; |
| 16612 |
end if; |
| 16613 |
end if; |
| 16614 |
end Default_Storage_Pool; |
| 16615 |
|
| 16616 |
------------- |
| 16617 |
-- Depends -- |
| 16618 |
------------- |
| 16619 |
|
| 16620 |
-- pragma Depends (DEPENDENCY_RELATION); |
| 16621 |
|
| 16622 |
-- DEPENDENCY_RELATION ::= |
| 16623 |
-- null |
| 16624 |
-- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}) |
| 16625 |
|
| 16626 |
-- DEPENDENCY_CLAUSE ::= |
| 16627 |
-- OUTPUT_LIST =>[+] INPUT_LIST |
| 16628 |
-- | NULL_DEPENDENCY_CLAUSE |
| 16629 |
|
| 16630 |
-- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST |
| 16631 |
|
| 16632 |
-- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT}) |
| 16633 |
|
| 16634 |
-- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT}) |
| 16635 |
|
| 16636 |
-- OUTPUT ::= NAME | FUNCTION_RESULT |
| 16637 |
-- INPUT ::= NAME |
| 16638 |
|
| 16639 |
-- where FUNCTION_RESULT is a function Result attribute_reference |
| 16640 |
|
| 16641 |
-- Characteristics: |
| 16642 |
|
| 16643 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 16644 |
-- the legal placement and context. Secondary checks fully analyze |
| 16645 |
-- the dependency clauses in: |
| 16646 |
|
| 16647 |
-- Analyze_Depends_In_Decl_Part |
| 16648 |
|
| 16649 |
-- * Expansion - None. |
| 16650 |
|
| 16651 |
-- * Template - The annotation utilizes the generic template of the |
| 16652 |
-- related subprogram [body] when it is: |
| 16653 |
|
| 16654 |
-- aspect on subprogram declaration |
| 16655 |
-- aspect on stand-alone subprogram body |
| 16656 |
-- pragma on stand-alone subprogram body |
| 16657 |
|
| 16658 |
-- The annotation must prepare its own template when it is: |
| 16659 |
|
| 16660 |
-- pragma on subprogram declaration |
| 16661 |
|
| 16662 |
-- * Globals - Capture of global references must occur after full |
| 16663 |
-- analysis. |
| 16664 |
|
| 16665 |
-- * Instance - The annotation is instantiated automatically when |
| 16666 |
-- the related generic subprogram [body] is instantiated except for |
| 16667 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 16668 |
-- the annotation must instantiate itself. |
| 16669 |
|
| 16670 |
when Pragma_Depends => Depends : declare |
| 16671 |
Legal : Boolean; |
| 16672 |
Spec_Id : Entity_Id; |
| 16673 |
Subp_Decl : Node_Id; |
| 16674 |
|
| 16675 |
begin |
| 16676 |
Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal); |
| 16677 |
|
| 16678 |
if Legal then |
| 16679 |
|
| 16680 |
-- Chain the pragma on the contract for further processing by |
| 16681 |
-- Analyze_Depends_In_Decl_Part. |
| 16682 |
|
| 16683 |
Add_Contract_Item (N, Spec_Id); |
| 16684 |
|
| 16685 |
-- Fully analyze the pragma when it appears inside an entry |
| 16686 |
-- or subprogram body because it cannot benefit from forward |
| 16687 |
-- references. |
| 16688 |
|
| 16689 |
if Nkind (Subp_Decl) in N_Entry_Body |
| 16690 |
| N_Subprogram_Body |
| 16691 |
| N_Subprogram_Body_Stub |
| 16692 |
then |
| 16693 |
-- The legality checks of pragmas Depends and Global are |
| 16694 |
-- affected by the SPARK mode in effect and the volatility |
| 16695 |
-- of the context. In addition these two pragmas are subject |
| 16696 |
-- to an inherent order: |
| 16697 |
|
| 16698 |
-- 1) Global |
| 16699 |
-- 2) Depends |
| 16700 |
|
| 16701 |
-- Analyze all these pragmas in the order outlined above |
| 16702 |
|
| 16703 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 16704 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 16705 |
Analyze_If_Present (Pragma_Side_Effects); |
| 16706 |
Analyze_If_Present (Pragma_Global); |
| 16707 |
Analyze_Depends_In_Decl_Part (N); |
| 16708 |
end if; |
| 16709 |
end if; |
| 16710 |
end Depends; |
| 16711 |
|
| 16712 |
--------------------- |
| 16713 |
-- Detect_Blocking -- |
| 16714 |
--------------------- |
| 16715 |
|
| 16716 |
-- pragma Detect_Blocking; |
| 16717 |
|
| 16718 |
when Pragma_Detect_Blocking => |
| 16719 |
Ada_2005_Pragma; |
| 16720 |
Check_Arg_Count (0); |
| 16721 |
Check_Valid_Configuration_Pragma; |
| 16722 |
Detect_Blocking := True; |
| 16723 |
|
| 16724 |
------------------------------------ |
| 16725 |
-- Disable_Atomic_Synchronization -- |
| 16726 |
------------------------------------ |
| 16727 |
|
| 16728 |
-- pragma Disable_Atomic_Synchronization [(Entity)]; |
| 16729 |
|
| 16730 |
when Pragma_Disable_Atomic_Synchronization => |
| 16731 |
GNAT_Pragma; |
| 16732 |
Process_Disable_Enable_Atomic_Sync (Name_Suppress); |
| 16733 |
|
| 16734 |
------------------- |
| 16735 |
-- Discard_Names -- |
| 16736 |
------------------- |
| 16737 |
|
| 16738 |
-- pragma Discard_Names [([On =>] LOCAL_NAME)]; |
| 16739 |
|
| 16740 |
when Pragma_Discard_Names => Discard_Names : declare |
| 16741 |
E : Entity_Id; |
| 16742 |
E_Id : Node_Id; |
| 16743 |
|
| 16744 |
begin |
| 16745 |
Check_Ada_83_Warning; |
| 16746 |
|
| 16747 |
-- Deal with configuration pragma case |
| 16748 |
|
| 16749 |
if Is_Configuration_Pragma then |
| 16750 |
if Arg_Count /= 0 then |
| 16751 |
Error_Pragma |
| 16752 |
("nonzero number of arguments for configuration pragma%"); |
| 16753 |
else |
| 16754 |
Global_Discard_Names := True; |
| 16755 |
end if; |
| 16756 |
return; |
| 16757 |
|
| 16758 |
-- Otherwise, check correct appropriate context |
| 16759 |
|
| 16760 |
else |
| 16761 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 16762 |
|
| 16763 |
if Arg_Count = 0 then |
| 16764 |
|
| 16765 |
-- If there is no parameter, then from now on this pragma |
| 16766 |
-- applies to any enumeration, exception or tagged type |
| 16767 |
-- defined in the current declarative part, and recursively |
| 16768 |
-- to any nested scope. |
| 16769 |
|
| 16770 |
Set_Discard_Names (Current_Scope); |
| 16771 |
return; |
| 16772 |
|
| 16773 |
else |
| 16774 |
Check_Arg_Count (1); |
| 16775 |
Check_Optional_Identifier (Arg1, Name_On); |
| 16776 |
Check_Arg_Is_Local_Name (Arg1); |
| 16777 |
|
| 16778 |
E_Id := Get_Pragma_Arg (Arg1); |
| 16779 |
|
| 16780 |
if Etype (E_Id) = Any_Type then |
| 16781 |
return; |
| 16782 |
end if; |
| 16783 |
|
| 16784 |
E := Entity (E_Id); |
| 16785 |
|
| 16786 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 16787 |
-- the purposes of legality checks and removal of ignored |
| 16788 |
-- Ghost code. |
| 16789 |
|
| 16790 |
Mark_Ghost_Pragma (N, E); |
| 16791 |
|
| 16792 |
if (Is_First_Subtype (E) |
| 16793 |
and then |
| 16794 |
(Is_Enumeration_Type (E) or else Is_Tagged_Type (E))) |
| 16795 |
or else Ekind (E) = E_Exception |
| 16796 |
then |
| 16797 |
Set_Discard_Names (E); |
| 16798 |
Record_Rep_Item (E, N); |
| 16799 |
|
| 16800 |
else |
| 16801 |
Error_Pragma_Arg |
| 16802 |
("inappropriate entity for pragma%", Arg1); |
| 16803 |
end if; |
| 16804 |
end if; |
| 16805 |
end if; |
| 16806 |
end Discard_Names; |
| 16807 |
|
| 16808 |
------------------------ |
| 16809 |
-- Dispatching_Domain -- |
| 16810 |
------------------------ |
| 16811 |
|
| 16812 |
-- pragma Dispatching_Domain (EXPRESSION); |
| 16813 |
|
| 16814 |
when Pragma_Dispatching_Domain => Dispatching_Domain : declare |
| 16815 |
P : constant Node_Id := Parent (N); |
| 16816 |
Arg : Node_Id; |
| 16817 |
Ent : Entity_Id; |
| 16818 |
|
| 16819 |
begin |
| 16820 |
Ada_2012_Pragma; |
| 16821 |
Check_No_Identifiers; |
| 16822 |
Check_Arg_Count (1); |
| 16823 |
|
| 16824 |
-- This pragma is born obsolete, but not the aspect |
| 16825 |
|
| 16826 |
if not From_Aspect_Specification (N) then |
| 16827 |
Check_Restriction |
| 16828 |
(No_Obsolescent_Features, Pragma_Identifier (N)); |
| 16829 |
end if; |
| 16830 |
|
| 16831 |
if Nkind (P) = N_Task_Definition then |
| 16832 |
Arg := Get_Pragma_Arg (Arg1); |
| 16833 |
Ent := Defining_Identifier (Parent (P)); |
| 16834 |
|
| 16835 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 16836 |
-- the purposes of legality checks and removal of ignored Ghost |
| 16837 |
-- code. |
| 16838 |
|
| 16839 |
Mark_Ghost_Pragma (N, Ent); |
| 16840 |
|
| 16841 |
-- The expression must be analyzed in the special manner |
| 16842 |
-- described in "Handling of Default and Per-Object |
| 16843 |
-- Expressions" in sem.ads. |
| 16844 |
|
| 16845 |
Preanalyze_Spec_Expression (Arg, RTE (RE_Dispatching_Domain)); |
| 16846 |
|
| 16847 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 16848 |
-- Item chain of Ent. |
| 16849 |
|
| 16850 |
Check_Duplicate_Pragma (Ent); |
| 16851 |
Record_Rep_Item (Ent, N); |
| 16852 |
|
| 16853 |
-- Anything else is incorrect |
| 16854 |
|
| 16855 |
else |
| 16856 |
Pragma_Misplaced; |
| 16857 |
end if; |
| 16858 |
end Dispatching_Domain; |
| 16859 |
|
| 16860 |
--------------- |
| 16861 |
-- Elaborate -- |
| 16862 |
--------------- |
| 16863 |
|
| 16864 |
-- pragma Elaborate (library_unit_NAME {, library_unit_NAME}); |
| 16865 |
|
| 16866 |
when Pragma_Elaborate => Elaborate : declare |
| 16867 |
Arg : Node_Id; |
| 16868 |
Citem : Node_Id; |
| 16869 |
|
| 16870 |
begin |
| 16871 |
-- Pragma must be in context items list of a compilation unit |
| 16872 |
|
| 16873 |
if not Is_In_Context_Clause then |
| 16874 |
Pragma_Misplaced; |
| 16875 |
end if; |
| 16876 |
|
| 16877 |
-- Must be at least one argument |
| 16878 |
|
| 16879 |
if Arg_Count = 0 then |
| 16880 |
Error_Pragma ("pragma% requires at least one argument"); |
| 16881 |
end if; |
| 16882 |
|
| 16883 |
-- In Ada 83 mode, there can be no items following it in the |
| 16884 |
-- context list except other pragmas and implicit with clauses |
| 16885 |
-- (e.g. those added by Rtsfind). In Ada 95 mode, this placement |
| 16886 |
-- rule does not apply. |
| 16887 |
|
| 16888 |
if Ada_Version = Ada_83 and then Comes_From_Source (N) then |
| 16889 |
Citem := Next (N); |
| 16890 |
while Present (Citem) loop |
| 16891 |
if Nkind (Citem) = N_Pragma |
| 16892 |
or else (Nkind (Citem) = N_With_Clause |
| 16893 |
and then Is_Implicit_With (Citem)) |
| 16894 |
then |
| 16895 |
null; |
| 16896 |
else |
| 16897 |
Error_Pragma |
| 16898 |
("(Ada 83) pragma% must be at end of context clause"); |
| 16899 |
end if; |
| 16900 |
|
| 16901 |
Next (Citem); |
| 16902 |
end loop; |
| 16903 |
end if; |
| 16904 |
|
| 16905 |
-- Finally, the arguments must all be units mentioned in a with |
| 16906 |
-- clause in the same context clause. Note we already checked (in |
| 16907 |
-- Par.Prag) that the arguments are all identifiers or selected |
| 16908 |
-- components. |
| 16909 |
|
| 16910 |
Arg := Arg1; |
| 16911 |
Outer : while Present (Arg) loop |
| 16912 |
Citem := First (List_Containing (N)); |
| 16913 |
Inner : while Citem /= N loop |
| 16914 |
if Nkind (Citem) = N_With_Clause |
| 16915 |
and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg)) |
| 16916 |
then |
| 16917 |
Set_Elaborate_Present (Citem, True); |
| 16918 |
Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem)); |
| 16919 |
|
| 16920 |
-- With the pragma present, elaboration calls on |
| 16921 |
-- subprograms from the named unit need no further |
| 16922 |
-- checks, as long as the pragma appears in the current |
| 16923 |
-- compilation unit. If the pragma appears in some unit |
| 16924 |
-- in the context, there might still be a need for an |
| 16925 |
-- Elaborate_All_Desirable from the current compilation |
| 16926 |
-- to the named unit, so we keep the check enabled. This |
| 16927 |
-- does not apply in SPARK mode, where we allow pragma |
| 16928 |
-- Elaborate, but we don't trust it to be right so we |
| 16929 |
-- will still insist on the Elaborate_All. |
| 16930 |
|
| 16931 |
if Legacy_Elaboration_Checks |
| 16932 |
and then In_Extended_Main_Source_Unit (N) |
| 16933 |
and then SPARK_Mode /= On |
| 16934 |
then |
| 16935 |
Set_Suppress_Elaboration_Warnings |
| 16936 |
(Entity (Name (Citem))); |
| 16937 |
end if; |
| 16938 |
|
| 16939 |
exit Inner; |
| 16940 |
end if; |
| 16941 |
|
| 16942 |
Next (Citem); |
| 16943 |
end loop Inner; |
| 16944 |
|
| 16945 |
if Citem = N then |
| 16946 |
Error_Pragma_Arg |
| 16947 |
("argument of pragma% is not withed unit", Arg); |
| 16948 |
end if; |
| 16949 |
|
| 16950 |
Next (Arg); |
| 16951 |
end loop Outer; |
| 16952 |
end Elaborate; |
| 16953 |
|
| 16954 |
------------------- |
| 16955 |
-- Elaborate_All -- |
| 16956 |
------------------- |
| 16957 |
|
| 16958 |
-- pragma Elaborate_All (library_unit_NAME {, library_unit_NAME}); |
| 16959 |
|
| 16960 |
when Pragma_Elaborate_All => Elaborate_All : declare |
| 16961 |
Arg : Node_Id; |
| 16962 |
Citem : Node_Id; |
| 16963 |
|
| 16964 |
begin |
| 16965 |
Check_Ada_83_Warning; |
| 16966 |
|
| 16967 |
-- Pragma must be in context items list of a compilation unit |
| 16968 |
|
| 16969 |
if not Is_In_Context_Clause then |
| 16970 |
Pragma_Misplaced; |
| 16971 |
end if; |
| 16972 |
|
| 16973 |
-- Must be at least one argument |
| 16974 |
|
| 16975 |
if Arg_Count = 0 then |
| 16976 |
Error_Pragma ("pragma% requires at least one argument"); |
| 16977 |
end if; |
| 16978 |
|
| 16979 |
-- Note: unlike pragma Elaborate, pragma Elaborate_All does not |
| 16980 |
-- have to appear at the end of the context clause, but may |
| 16981 |
-- appear mixed in with other items, even in Ada 83 mode. |
| 16982 |
|
| 16983 |
-- Final check: the arguments must all be units mentioned in |
| 16984 |
-- a with clause in the same context clause. Note that we |
| 16985 |
-- already checked (in Par.Prag) that all the arguments are |
| 16986 |
-- either identifiers or selected components. |
| 16987 |
|
| 16988 |
Arg := Arg1; |
| 16989 |
Outr : while Present (Arg) loop |
| 16990 |
Citem := First (List_Containing (N)); |
| 16991 |
Innr : while Citem /= N loop |
| 16992 |
if Nkind (Citem) = N_With_Clause |
| 16993 |
and then Same_Name (Name (Citem), Get_Pragma_Arg (Arg)) |
| 16994 |
then |
| 16995 |
Set_Elaborate_All_Present (Citem, True); |
| 16996 |
Set_Elab_Unit_Name (Get_Pragma_Arg (Arg), Name (Citem)); |
| 16997 |
|
| 16998 |
-- Suppress warnings and elaboration checks on the named |
| 16999 |
-- unit if the pragma is in the current compilation, as |
| 17000 |
-- for pragma Elaborate. |
| 17001 |
|
| 17002 |
if Legacy_Elaboration_Checks |
| 17003 |
and then In_Extended_Main_Source_Unit (N) |
| 17004 |
then |
| 17005 |
Set_Suppress_Elaboration_Warnings |
| 17006 |
(Entity (Name (Citem))); |
| 17007 |
end if; |
| 17008 |
|
| 17009 |
exit Innr; |
| 17010 |
end if; |
| 17011 |
|
| 17012 |
Next (Citem); |
| 17013 |
end loop Innr; |
| 17014 |
|
| 17015 |
if Citem = N then |
| 17016 |
Error_Pragma_Arg |
| 17017 |
("argument of pragma% is not withed unit", Arg); |
| 17018 |
end if; |
| 17019 |
|
| 17020 |
Next (Arg); |
| 17021 |
end loop Outr; |
| 17022 |
end Elaborate_All; |
| 17023 |
|
| 17024 |
-------------------- |
| 17025 |
-- Elaborate_Body -- |
| 17026 |
-------------------- |
| 17027 |
|
| 17028 |
-- pragma Elaborate_Body [( library_unit_NAME )]; |
| 17029 |
|
| 17030 |
when Pragma_Elaborate_Body => Elaborate_Body : declare |
| 17031 |
Cunit_Node : Node_Id; |
| 17032 |
Cunit_Ent : Entity_Id; |
| 17033 |
|
| 17034 |
begin |
| 17035 |
Check_Ada_83_Warning; |
| 17036 |
Check_Valid_Library_Unit_Pragma; |
| 17037 |
|
| 17038 |
-- If N was rewritten as a null statement there is nothing more |
| 17039 |
-- to do. |
| 17040 |
|
| 17041 |
if Nkind (N) = N_Null_Statement then |
| 17042 |
return; |
| 17043 |
end if; |
| 17044 |
|
| 17045 |
Cunit_Node := Cunit (Current_Sem_Unit); |
| 17046 |
Cunit_Ent := Cunit_Entity (Current_Sem_Unit); |
| 17047 |
|
| 17048 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 17049 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 17050 |
|
| 17051 |
Mark_Ghost_Pragma (N, Cunit_Ent); |
| 17052 |
|
| 17053 |
if Nkind (Unit (Cunit_Node)) in |
| 17054 |
N_Package_Body | N_Subprogram_Body |
| 17055 |
then |
| 17056 |
Error_Pragma ("pragma% must refer to a spec, not a body"); |
| 17057 |
else |
| 17058 |
Set_Body_Required (Cunit_Node); |
| 17059 |
Set_Has_Pragma_Elaborate_Body (Cunit_Ent); |
| 17060 |
|
| 17061 |
-- If we are in dynamic elaboration mode, then we suppress |
| 17062 |
-- elaboration warnings for the unit, since it is definitely |
| 17063 |
-- fine NOT to do dynamic checks at the first level (and such |
| 17064 |
-- checks will be suppressed because no elaboration boolean |
| 17065 |
-- is created for Elaborate_Body packages). |
| 17066 |
-- |
| 17067 |
-- But in the static model of elaboration, Elaborate_Body is |
| 17068 |
-- definitely NOT good enough to ensure elaboration safety on |
| 17069 |
-- its own, since the body may WITH other units that are not |
| 17070 |
-- safe from an elaboration point of view, so a client must |
| 17071 |
-- still do an Elaborate_All on such units. |
| 17072 |
-- |
| 17073 |
-- Debug flag -gnatdD restores the old behavior of 3.13, where |
| 17074 |
-- Elaborate_Body always suppressed elab warnings. |
| 17075 |
|
| 17076 |
if Legacy_Elaboration_Checks |
| 17077 |
and then (Dynamic_Elaboration_Checks or Debug_Flag_DD) |
| 17078 |
then |
| 17079 |
Set_Suppress_Elaboration_Warnings (Cunit_Ent); |
| 17080 |
end if; |
| 17081 |
end if; |
| 17082 |
end Elaborate_Body; |
| 17083 |
|
| 17084 |
------------------------ |
| 17085 |
-- Elaboration_Checks -- |
| 17086 |
------------------------ |
| 17087 |
|
| 17088 |
-- pragma Elaboration_Checks (Static | Dynamic); |
| 17089 |
|
| 17090 |
when Pragma_Elaboration_Checks => Elaboration_Checks : declare |
| 17091 |
procedure Check_Duplicate_Elaboration_Checks_Pragma; |
| 17092 |
-- Emit an error if the current context list already contains |
| 17093 |
-- a previous Elaboration_Checks pragma. This routine raises |
| 17094 |
-- Pragma_Exit if a duplicate is found. |
| 17095 |
|
| 17096 |
procedure Ignore_Elaboration_Checks_Pragma; |
| 17097 |
-- Warn that the effects of the pragma are ignored. This routine |
| 17098 |
-- raises Pragma_Exit. |
| 17099 |
|
| 17100 |
----------------------------------------------- |
| 17101 |
-- Check_Duplicate_Elaboration_Checks_Pragma -- |
| 17102 |
----------------------------------------------- |
| 17103 |
|
| 17104 |
procedure Check_Duplicate_Elaboration_Checks_Pragma is |
| 17105 |
Item : Node_Id; |
| 17106 |
|
| 17107 |
begin |
| 17108 |
Item := Prev (N); |
| 17109 |
while Present (Item) loop |
| 17110 |
if Nkind (Item) = N_Pragma |
| 17111 |
and then Pragma_Name (Item) = Name_Elaboration_Checks |
| 17112 |
then |
| 17113 |
Duplication_Error |
| 17114 |
(Prag => N, |
| 17115 |
Prev => Item); |
| 17116 |
raise Pragma_Exit; |
| 17117 |
end if; |
| 17118 |
|
| 17119 |
Prev (Item); |
| 17120 |
end loop; |
| 17121 |
end Check_Duplicate_Elaboration_Checks_Pragma; |
| 17122 |
|
| 17123 |
-------------------------------------- |
| 17124 |
-- Ignore_Elaboration_Checks_Pragma -- |
| 17125 |
-------------------------------------- |
| 17126 |
|
| 17127 |
procedure Ignore_Elaboration_Checks_Pragma is |
| 17128 |
begin |
| 17129 |
Error_Msg_Name_1 := Pname; |
| 17130 |
Error_Msg_N ("??effects of pragma % are ignored", N); |
| 17131 |
Error_Msg_N |
| 17132 |
("\place pragma on initial declaration of library unit", N); |
| 17133 |
|
| 17134 |
raise Pragma_Exit; |
| 17135 |
end Ignore_Elaboration_Checks_Pragma; |
| 17136 |
|
| 17137 |
-- Local variables |
| 17138 |
|
| 17139 |
Context : constant Node_Id := Parent (N); |
| 17140 |
Unt : Node_Id; |
| 17141 |
|
| 17142 |
-- Start of processing for Elaboration_Checks |
| 17143 |
|
| 17144 |
begin |
| 17145 |
GNAT_Pragma; |
| 17146 |
Check_Arg_Count (1); |
| 17147 |
Check_Arg_Is_One_Of (Arg1, Name_Static, Name_Dynamic); |
| 17148 |
|
| 17149 |
-- The pragma appears in a configuration file |
| 17150 |
|
| 17151 |
if No (Context) then |
| 17152 |
Check_Valid_Configuration_Pragma; |
| 17153 |
Check_Duplicate_Elaboration_Checks_Pragma; |
| 17154 |
|
| 17155 |
-- The pragma acts as a configuration pragma in a compilation unit |
| 17156 |
|
| 17157 |
-- pragma Elaboration_Checks (...); |
| 17158 |
-- package Pack is ...; |
| 17159 |
|
| 17160 |
elsif Nkind (Context) = N_Compilation_Unit |
| 17161 |
and then List_Containing (N) = Context_Items (Context) |
| 17162 |
then |
| 17163 |
Check_Valid_Configuration_Pragma; |
| 17164 |
Check_Duplicate_Elaboration_Checks_Pragma; |
| 17165 |
|
| 17166 |
Unt := Unit (Context); |
| 17167 |
|
| 17168 |
-- The pragma must appear on the initial declaration of a unit. |
| 17169 |
-- If this is not the case, warn that the effects of the pragma |
| 17170 |
-- are ignored. |
| 17171 |
|
| 17172 |
if Nkind (Unt) = N_Package_Body then |
| 17173 |
Ignore_Elaboration_Checks_Pragma; |
| 17174 |
|
| 17175 |
-- Check the Acts_As_Spec flag of the compilation units itself |
| 17176 |
-- to determine whether the subprogram body completes since it |
| 17177 |
-- has not been analyzed yet. This is safe because compilation |
| 17178 |
-- units are not overloadable. |
| 17179 |
|
| 17180 |
elsif Nkind (Unt) = N_Subprogram_Body |
| 17181 |
and then not Acts_As_Spec (Context) |
| 17182 |
then |
| 17183 |
Ignore_Elaboration_Checks_Pragma; |
| 17184 |
|
| 17185 |
elsif Nkind (Unt) = N_Subunit then |
| 17186 |
Ignore_Elaboration_Checks_Pragma; |
| 17187 |
end if; |
| 17188 |
|
| 17189 |
-- Otherwise the pragma does not appear at the configuration level |
| 17190 |
-- and is illegal. |
| 17191 |
|
| 17192 |
else |
| 17193 |
Pragma_Misplaced; |
| 17194 |
end if; |
| 17195 |
|
| 17196 |
-- At this point the pragma is not a duplicate, and appears in the |
| 17197 |
-- proper context. Set the elaboration model in effect. |
| 17198 |
|
| 17199 |
Dynamic_Elaboration_Checks := |
| 17200 |
Chars (Get_Pragma_Arg (Arg1)) = Name_Dynamic; |
| 17201 |
end Elaboration_Checks; |
| 17202 |
|
| 17203 |
--------------- |
| 17204 |
-- Eliminate -- |
| 17205 |
--------------- |
| 17206 |
|
| 17207 |
-- pragma Eliminate ( |
| 17208 |
-- [Unit_Name =>] IDENTIFIER | SELECTED_COMPONENT, |
| 17209 |
-- [Entity =>] IDENTIFIER | |
| 17210 |
-- SELECTED_COMPONENT | |
| 17211 |
-- STRING_LITERAL] |
| 17212 |
-- [, Source_Location => SOURCE_TRACE]); |
| 17213 |
|
| 17214 |
-- SOURCE_LOCATION ::= Source_Location => SOURCE_TRACE |
| 17215 |
-- SOURCE_TRACE ::= STRING_LITERAL |
| 17216 |
|
| 17217 |
when Pragma_Eliminate => Eliminate : declare |
| 17218 |
Args : Args_List (1 .. 5); |
| 17219 |
Names : constant Name_List (1 .. 5) := ( |
| 17220 |
Name_Unit_Name, |
| 17221 |
Name_Entity, |
| 17222 |
Name_Parameter_Types, |
| 17223 |
Name_Result_Type, |
| 17224 |
Name_Source_Location); |
| 17225 |
|
| 17226 |
-- Note : Parameter_Types and Result_Type are leftovers from |
| 17227 |
-- prior implementations of the pragma. They are not generated |
| 17228 |
-- by the gnatelim tool, and play no role in selecting which |
| 17229 |
-- of a set of overloaded names is chosen for elimination. |
| 17230 |
|
| 17231 |
Unit_Name : Node_Id renames Args (1); |
| 17232 |
Entity : Node_Id renames Args (2); |
| 17233 |
Parameter_Types : Node_Id renames Args (3); |
| 17234 |
Result_Type : Node_Id renames Args (4); |
| 17235 |
Source_Location : Node_Id renames Args (5); |
| 17236 |
|
| 17237 |
begin |
| 17238 |
GNAT_Pragma; |
| 17239 |
Check_Valid_Configuration_Pragma; |
| 17240 |
Gather_Associations (Names, Args); |
| 17241 |
|
| 17242 |
if No (Unit_Name) then |
| 17243 |
Error_Pragma ("missing Unit_Name argument for pragma%"); |
| 17244 |
end if; |
| 17245 |
|
| 17246 |
if No (Entity) |
| 17247 |
and then (Present (Parameter_Types) |
| 17248 |
or else |
| 17249 |
Present (Result_Type) |
| 17250 |
or else |
| 17251 |
Present (Source_Location)) |
| 17252 |
then |
| 17253 |
Error_Pragma ("missing Entity argument for pragma%"); |
| 17254 |
end if; |
| 17255 |
|
| 17256 |
if (Present (Parameter_Types) |
| 17257 |
or else |
| 17258 |
Present (Result_Type)) |
| 17259 |
and then |
| 17260 |
Present (Source_Location) |
| 17261 |
then |
| 17262 |
Error_Pragma |
| 17263 |
("parameter profile and source location cannot be used " |
| 17264 |
& "together in pragma%"); |
| 17265 |
end if; |
| 17266 |
|
| 17267 |
Process_Eliminate_Pragma |
| 17268 |
(N, |
| 17269 |
Unit_Name, |
| 17270 |
Entity, |
| 17271 |
Parameter_Types, |
| 17272 |
Result_Type, |
| 17273 |
Source_Location); |
| 17274 |
end Eliminate; |
| 17275 |
|
| 17276 |
----------------------------------- |
| 17277 |
-- Enable_Atomic_Synchronization -- |
| 17278 |
----------------------------------- |
| 17279 |
|
| 17280 |
-- pragma Enable_Atomic_Synchronization [(Entity)]; |
| 17281 |
|
| 17282 |
when Pragma_Enable_Atomic_Synchronization => |
| 17283 |
GNAT_Pragma; |
| 17284 |
Process_Disable_Enable_Atomic_Sync (Name_Unsuppress); |
| 17285 |
|
| 17286 |
----------------------- |
| 17287 |
-- Exceptional_Cases -- |
| 17288 |
----------------------- |
| 17289 |
|
| 17290 |
-- pragma Exceptional_Cases ( EXCEPTIONAL_CONTRACT_LIST ); |
| 17291 |
|
| 17292 |
-- EXCEPTIONAL_CONTRACT_LIST ::= |
| 17293 |
-- ( EXCEPTIONAL_CONTRACT {, EXCEPTIONAL_CONTRACT }) |
| 17294 |
|
| 17295 |
-- EXCEPTIONAL_CONTRACT ::= |
| 17296 |
-- EXCEPTION_CHOICE {'|' EXCEPTION_CHOICE} => CONSEQUENCE |
| 17297 |
-- |
| 17298 |
-- where |
| 17299 |
-- |
| 17300 |
-- CONSEQUENCE ::= boolean_EXPRESSION |
| 17301 |
|
| 17302 |
-- Characteristics: |
| 17303 |
|
| 17304 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 17305 |
-- the legal placement and context. Secondary checks preanalyze the |
| 17306 |
-- expressions in: |
| 17307 |
|
| 17308 |
-- Analyze_Exceptional_Cases_In_Decl_Part |
| 17309 |
|
| 17310 |
-- * Expansion - The annotation is expanded during the expansion of |
| 17311 |
-- the related subprogram [body] contract as performed in: |
| 17312 |
|
| 17313 |
-- Expand_Subprogram_Contract |
| 17314 |
|
| 17315 |
-- * Template - The annotation utilizes the generic template of the |
| 17316 |
-- related subprogram [body] when it is: |
| 17317 |
|
| 17318 |
-- aspect on subprogram declaration |
| 17319 |
-- aspect on stand-alone subprogram body |
| 17320 |
-- pragma on stand-alone subprogram body |
| 17321 |
|
| 17322 |
-- The annotation must prepare its own template when it is: |
| 17323 |
|
| 17324 |
-- pragma on subprogram declaration |
| 17325 |
|
| 17326 |
-- * Globals - Capture of global references must occur after full |
| 17327 |
-- analysis. |
| 17328 |
|
| 17329 |
-- * Instance - The annotation is instantiated automatically when |
| 17330 |
-- the related generic subprogram [body] is instantiated except for |
| 17331 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 17332 |
-- the annotation must instantiate itself. |
| 17333 |
|
| 17334 |
when Pragma_Exceptional_Cases => Exceptional_Cases : declare |
| 17335 |
Spec_Id : Entity_Id; |
| 17336 |
Subp_Decl : Node_Id; |
| 17337 |
Subp_Spec : Node_Id; |
| 17338 |
|
| 17339 |
begin |
| 17340 |
GNAT_Pragma; |
| 17341 |
Check_No_Identifiers; |
| 17342 |
Check_Arg_Count (1); |
| 17343 |
|
| 17344 |
-- Ensure the proper placement of the pragma. Exceptional_Cases |
| 17345 |
-- must be associated with a subprogram declaration or a body that |
| 17346 |
-- acts as a spec. |
| 17347 |
|
| 17348 |
Subp_Decl := |
| 17349 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 17350 |
|
| 17351 |
-- Generic subprogram |
| 17352 |
|
| 17353 |
if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 17354 |
null; |
| 17355 |
|
| 17356 |
-- Body acts as spec |
| 17357 |
|
| 17358 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 17359 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 17360 |
then |
| 17361 |
null; |
| 17362 |
|
| 17363 |
-- Body stub acts as spec |
| 17364 |
|
| 17365 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 17366 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 17367 |
then |
| 17368 |
null; |
| 17369 |
|
| 17370 |
-- Subprogram |
| 17371 |
|
| 17372 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 17373 |
Subp_Spec := Specification (Subp_Decl); |
| 17374 |
|
| 17375 |
-- Pragma Exceptional_Cases is forbidden on null procedures, |
| 17376 |
-- as this may lead to potential ambiguities in behavior when |
| 17377 |
-- interface null procedures are involved. Also, it just |
| 17378 |
-- wouldn't make sense, because null procedures do not raise |
| 17379 |
-- exceptions. |
| 17380 |
|
| 17381 |
if Nkind (Subp_Spec) = N_Procedure_Specification |
| 17382 |
and then Null_Present (Subp_Spec) |
| 17383 |
then |
| 17384 |
Error_Msg_N (Fix_Error |
| 17385 |
("pragma % cannot apply to null procedure"), N); |
| 17386 |
return; |
| 17387 |
end if; |
| 17388 |
|
| 17389 |
else |
| 17390 |
Pragma_Misplaced; |
| 17391 |
end if; |
| 17392 |
|
| 17393 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 17394 |
|
| 17395 |
-- In order to call Is_Function_With_Side_Effects, analyze pragma |
| 17396 |
-- Side_Effects if present. |
| 17397 |
|
| 17398 |
Analyze_If_Present (Pragma_Side_Effects); |
| 17399 |
|
| 17400 |
-- Pragma Exceptional_Cases is not allowed on functions without |
| 17401 |
-- side effects. |
| 17402 |
|
| 17403 |
if Ekind (Spec_Id) in E_Function | E_Generic_Function |
| 17404 |
and then not Is_Function_With_Side_Effects (Spec_Id) |
| 17405 |
then |
| 17406 |
Error_Msg_Sloc := GEC_Exceptional_Cases_On_Function; |
| 17407 |
|
| 17408 |
if Ekind (Spec_Id) = E_Function then |
| 17409 |
Error_Msg_N (Fix_Error |
| 17410 |
("pragma % cannot apply to function '[[]']"), N); |
| 17411 |
return; |
| 17412 |
|
| 17413 |
elsif Ekind (Spec_Id) = E_Generic_Function then |
| 17414 |
Error_Msg_N (Fix_Error |
| 17415 |
("pragma % cannot apply to generic function '[[]']"), N); |
| 17416 |
return; |
| 17417 |
end if; |
| 17418 |
end if; |
| 17419 |
|
| 17420 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 17421 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 17422 |
|
| 17423 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 17424 |
Ensure_Aggregate_Form (Get_Argument (N, Spec_Id)); |
| 17425 |
|
| 17426 |
-- Chain the pragma on the contract for further processing by |
| 17427 |
-- Analyze_Exceptional_Cases_In_Decl_Part. |
| 17428 |
|
| 17429 |
Add_Contract_Item (N, Defining_Entity (Subp_Decl)); |
| 17430 |
|
| 17431 |
-- Fully analyze the pragma when it appears inside a subprogram |
| 17432 |
-- body because it cannot benefit from forward references. |
| 17433 |
|
| 17434 |
if Nkind (Subp_Decl) in N_Subprogram_Body |
| 17435 |
| N_Subprogram_Body_Stub |
| 17436 |
then |
| 17437 |
-- The legality checks of pragma Exceptional_Cases are |
| 17438 |
-- affected by the SPARK mode in effect and the volatility |
| 17439 |
-- of the context. Analyze all pragmas in a specific order. |
| 17440 |
|
| 17441 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 17442 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 17443 |
Analyze_Exceptional_Cases_In_Decl_Part (N); |
| 17444 |
end if; |
| 17445 |
end Exceptional_Cases; |
| 17446 |
|
| 17447 |
---------------- |
| 17448 |
-- Exit_Cases -- |
| 17449 |
---------------- |
| 17450 |
|
| 17451 |
-- pragma Exit_Cases ( EXIT_CONTRACT_LIST ); |
| 17452 |
|
| 17453 |
-- EXIT_CONTRACT_LIST ::= |
| 17454 |
-- ( EXIT_CONTRACT {, EXIT_CONTRACT }) |
| 17455 |
|
| 17456 |
-- EXIT_CONTRACT ::= |
| 17457 |
-- CASE_GUARD => EXIT_KIND |
| 17458 |
-- |
| 17459 |
-- EXIT_KIND ::= |
| 17460 |
-- Normal_Return |
| 17461 |
-- | Exception_Raised |
| 17462 |
-- | (Exception_Raised => exception_name) |
| 17463 |
-- |
| 17464 |
-- where |
| 17465 |
-- |
| 17466 |
-- CASE_GUARD ::= boolean_EXPRESSION |
| 17467 |
|
| 17468 |
-- Characteristics: |
| 17469 |
|
| 17470 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 17471 |
-- the legal placement and context. Secondary checks preanalyze the |
| 17472 |
-- expressions in: |
| 17473 |
|
| 17474 |
-- Analyze_Exit_Cases_In_Decl_Part |
| 17475 |
|
| 17476 |
-- * Expansion - The annotation is expanded during the expansion of |
| 17477 |
-- the related subprogram [body] contract as performed in: |
| 17478 |
|
| 17479 |
-- Expand_Subprogram_Contract |
| 17480 |
|
| 17481 |
-- * Template - The annotation utilizes the generic template of the |
| 17482 |
-- related subprogram [body] when it is: |
| 17483 |
|
| 17484 |
-- aspect on subprogram declaration |
| 17485 |
-- aspect on stand-alone subprogram body |
| 17486 |
-- pragma on stand-alone subprogram body |
| 17487 |
|
| 17488 |
-- The annotation must prepare its own template when it is: |
| 17489 |
|
| 17490 |
-- pragma on subprogram declaration |
| 17491 |
|
| 17492 |
-- * Globals - Capture of global references must occur after full |
| 17493 |
-- analysis. |
| 17494 |
|
| 17495 |
-- * Instance - The annotation is instantiated automatically when |
| 17496 |
-- the related generic subprogram [body] is instantiated except for |
| 17497 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 17498 |
-- the annotation must instantiate itself. |
| 17499 |
|
| 17500 |
when Pragma_Exit_Cases => Exit_Cases : declare |
| 17501 |
Spec_Id : Entity_Id; |
| 17502 |
Subp_Decl : Node_Id; |
| 17503 |
Subp_Spec : Node_Id; |
| 17504 |
|
| 17505 |
begin |
| 17506 |
GNAT_Pragma; |
| 17507 |
Check_No_Identifiers; |
| 17508 |
Check_Arg_Count (1); |
| 17509 |
|
| 17510 |
-- Ensure the proper placement of the pragma. Exit_Cases must be |
| 17511 |
-- associated with a subprogram declaration or a body that acts as |
| 17512 |
-- a spec. |
| 17513 |
|
| 17514 |
Subp_Decl := |
| 17515 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 17516 |
|
| 17517 |
-- Generic subprogram |
| 17518 |
|
| 17519 |
if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 17520 |
null; |
| 17521 |
|
| 17522 |
-- Body acts as spec |
| 17523 |
|
| 17524 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 17525 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 17526 |
then |
| 17527 |
null; |
| 17528 |
|
| 17529 |
-- Body stub acts as spec |
| 17530 |
|
| 17531 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 17532 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 17533 |
then |
| 17534 |
null; |
| 17535 |
|
| 17536 |
-- Subprogram |
| 17537 |
|
| 17538 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 17539 |
Subp_Spec := Specification (Subp_Decl); |
| 17540 |
|
| 17541 |
-- Pragma Exit_Cases is forbidden on null procedures, as this |
| 17542 |
-- may lead to potential ambiguities in behavior when interface |
| 17543 |
-- null procedures are involved. |
| 17544 |
|
| 17545 |
if Nkind (Subp_Spec) = N_Procedure_Specification |
| 17546 |
and then Null_Present (Subp_Spec) |
| 17547 |
then |
| 17548 |
Error_Msg_N (Fix_Error |
| 17549 |
("pragma % cannot apply to null procedure"), N); |
| 17550 |
return; |
| 17551 |
end if; |
| 17552 |
|
| 17553 |
else |
| 17554 |
Pragma_Misplaced; |
| 17555 |
end if; |
| 17556 |
|
| 17557 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 17558 |
|
| 17559 |
-- In order to call Is_Function_With_Side_Effects, analyze pragma |
| 17560 |
-- Side_Effects if present. |
| 17561 |
|
| 17562 |
Analyze_If_Present (Pragma_Side_Effects); |
| 17563 |
|
| 17564 |
-- Pragma Exit_Cases is not allowed on functions without side |
| 17565 |
-- effects. |
| 17566 |
|
| 17567 |
if Ekind (Spec_Id) in E_Function | E_Generic_Function |
| 17568 |
and then not Is_Function_With_Side_Effects (Spec_Id) |
| 17569 |
then |
| 17570 |
if Ekind (Spec_Id) = E_Function then |
| 17571 |
Error_Msg_N (Fix_Error |
| 17572 |
("pragma % cannot apply to function"), N); |
| 17573 |
return; |
| 17574 |
|
| 17575 |
elsif Ekind (Spec_Id) = E_Generic_Function then |
| 17576 |
Error_Msg_N (Fix_Error |
| 17577 |
("pragma % cannot apply to generic function"), N); |
| 17578 |
return; |
| 17579 |
end if; |
| 17580 |
end if; |
| 17581 |
|
| 17582 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 17583 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 17584 |
|
| 17585 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 17586 |
Ensure_Aggregate_Form (Get_Argument (N, Spec_Id)); |
| 17587 |
|
| 17588 |
-- Chain the pragma on the contract for further processing by |
| 17589 |
-- Analyze_Exit_Cases_In_Decl_Part. |
| 17590 |
|
| 17591 |
Add_Contract_Item (N, Defining_Entity (Subp_Decl)); |
| 17592 |
|
| 17593 |
-- Fully analyze the pragma when it appears inside a subprogram |
| 17594 |
-- body because it cannot benefit from forward references. |
| 17595 |
|
| 17596 |
if Nkind (Subp_Decl) in N_Subprogram_Body |
| 17597 |
| N_Subprogram_Body_Stub |
| 17598 |
then |
| 17599 |
-- The legality checks of pragma Exit_Cases are affected by the |
| 17600 |
-- SPARK mode in effect and the volatility of the context. |
| 17601 |
-- Analyze all pragmas in a specific order. |
| 17602 |
|
| 17603 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 17604 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 17605 |
Analyze_Exit_Cases_In_Decl_Part (N); |
| 17606 |
end if; |
| 17607 |
end Exit_Cases; |
| 17608 |
|
| 17609 |
------------ |
| 17610 |
-- Export -- |
| 17611 |
------------ |
| 17612 |
|
| 17613 |
-- pragma Export ( |
| 17614 |
-- [ Convention =>] convention_IDENTIFIER, |
| 17615 |
-- [ Entity =>] LOCAL_NAME |
| 17616 |
-- [, [External_Name =>] static_string_EXPRESSION ] |
| 17617 |
-- [, [Link_Name =>] static_string_EXPRESSION ]); |
| 17618 |
|
| 17619 |
when Pragma_Export => Export : declare |
| 17620 |
C : Convention_Id; |
| 17621 |
Def_Id : Entity_Id; |
| 17622 |
|
| 17623 |
pragma Warnings (Off, C); |
| 17624 |
|
| 17625 |
begin |
| 17626 |
Check_Ada_83_Warning; |
| 17627 |
Check_Arg_Order |
| 17628 |
((Name_Convention, |
| 17629 |
Name_Entity, |
| 17630 |
Name_External_Name, |
| 17631 |
Name_Link_Name)); |
| 17632 |
|
| 17633 |
Check_At_Least_N_Arguments (2); |
| 17634 |
Check_At_Most_N_Arguments (4); |
| 17635 |
|
| 17636 |
-- In Relaxed_RM_Semantics, support old Ada 83 style: |
| 17637 |
-- pragma Export (Entity, "external name"); |
| 17638 |
|
| 17639 |
if Relaxed_RM_Semantics |
| 17640 |
and then Arg_Count = 2 |
| 17641 |
and then Nkind (Expression (Arg2)) = N_String_Literal |
| 17642 |
then |
| 17643 |
C := Convention_C; |
| 17644 |
Def_Id := Get_Pragma_Arg (Arg1); |
| 17645 |
Analyze (Def_Id); |
| 17646 |
|
| 17647 |
if not Is_Entity_Name (Def_Id) then |
| 17648 |
Error_Pragma_Arg ("entity name required", Arg1); |
| 17649 |
end if; |
| 17650 |
|
| 17651 |
Def_Id := Entity (Def_Id); |
| 17652 |
Set_Exported (Def_Id, Arg1); |
| 17653 |
|
| 17654 |
else |
| 17655 |
Process_Convention (C, Def_Id); |
| 17656 |
|
| 17657 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 17658 |
-- the purposes of legality checks and removal of ignored Ghost |
| 17659 |
-- code. |
| 17660 |
|
| 17661 |
Mark_Ghost_Pragma (N, Def_Id); |
| 17662 |
|
| 17663 |
if Ekind (Def_Id) /= E_Constant then |
| 17664 |
Note_Possible_Modification |
| 17665 |
(Get_Pragma_Arg (Arg2), Sure => False); |
| 17666 |
end if; |
| 17667 |
|
| 17668 |
Process_Interface_Name (Def_Id, Arg3, Arg4, N); |
| 17669 |
Set_Exported (Def_Id, Arg2); |
| 17670 |
end if; |
| 17671 |
|
| 17672 |
-- If the entity is a deferred constant, propagate the information |
| 17673 |
-- to the full view, because gigi elaborates the full view only. |
| 17674 |
|
| 17675 |
if Ekind (Def_Id) = E_Constant |
| 17676 |
and then Present (Full_View (Def_Id)) |
| 17677 |
then |
| 17678 |
declare |
| 17679 |
Id2 : constant Entity_Id := Full_View (Def_Id); |
| 17680 |
begin |
| 17681 |
Set_Is_Exported (Id2, Is_Exported (Def_Id)); |
| 17682 |
Set_First_Rep_Item (Id2, First_Rep_Item (Def_Id)); |
| 17683 |
Set_Interface_Name |
| 17684 |
(Id2, Einfo.Entities.Interface_Name (Def_Id)); |
| 17685 |
end; |
| 17686 |
end if; |
| 17687 |
end Export; |
| 17688 |
|
| 17689 |
--------------------- |
| 17690 |
-- Export_Function -- |
| 17691 |
--------------------- |
| 17692 |
|
| 17693 |
-- pragma Export_Function ( |
| 17694 |
-- [Internal =>] LOCAL_NAME |
| 17695 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 17696 |
-- [, [Parameter_Types =>] (PARAMETER_TYPES)] |
| 17697 |
-- [, [Result_Type =>] TYPE_DESIGNATOR] |
| 17698 |
-- [, [Mechanism =>] MECHANISM] |
| 17699 |
-- [, [Result_Mechanism =>] MECHANISM_NAME]); |
| 17700 |
|
| 17701 |
-- EXTERNAL_SYMBOL ::= |
| 17702 |
-- IDENTIFIER |
| 17703 |
-- | static_string_EXPRESSION |
| 17704 |
|
| 17705 |
-- PARAMETER_TYPES ::= |
| 17706 |
-- null |
| 17707 |
-- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} |
| 17708 |
|
| 17709 |
-- TYPE_DESIGNATOR ::= |
| 17710 |
-- subtype_NAME |
| 17711 |
-- | subtype_Name ' Access |
| 17712 |
|
| 17713 |
-- MECHANISM ::= |
| 17714 |
-- MECHANISM_NAME |
| 17715 |
-- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) |
| 17716 |
|
| 17717 |
-- MECHANISM_ASSOCIATION ::= |
| 17718 |
-- [formal_parameter_NAME =>] MECHANISM_NAME |
| 17719 |
|
| 17720 |
-- MECHANISM_NAME ::= |
| 17721 |
-- Value |
| 17722 |
-- | Reference |
| 17723 |
|
| 17724 |
when Pragma_Export_Function => Export_Function : declare |
| 17725 |
Args : Args_List (1 .. 6); |
| 17726 |
Names : constant Name_List (1 .. 6) := ( |
| 17727 |
Name_Internal, |
| 17728 |
Name_External, |
| 17729 |
Name_Parameter_Types, |
| 17730 |
Name_Result_Type, |
| 17731 |
Name_Mechanism, |
| 17732 |
Name_Result_Mechanism); |
| 17733 |
|
| 17734 |
Internal : Node_Id renames Args (1); |
| 17735 |
External : Node_Id renames Args (2); |
| 17736 |
Parameter_Types : Node_Id renames Args (3); |
| 17737 |
Result_Type : Node_Id renames Args (4); |
| 17738 |
Mechanism : Node_Id renames Args (5); |
| 17739 |
Result_Mechanism : Node_Id renames Args (6); |
| 17740 |
|
| 17741 |
begin |
| 17742 |
GNAT_Pragma; |
| 17743 |
Gather_Associations (Names, Args); |
| 17744 |
Process_Extended_Import_Export_Subprogram_Pragma ( |
| 17745 |
Arg_Internal => Internal, |
| 17746 |
Arg_External => External, |
| 17747 |
Arg_Parameter_Types => Parameter_Types, |
| 17748 |
Arg_Result_Type => Result_Type, |
| 17749 |
Arg_Mechanism => Mechanism, |
| 17750 |
Arg_Result_Mechanism => Result_Mechanism); |
| 17751 |
end Export_Function; |
| 17752 |
|
| 17753 |
------------------- |
| 17754 |
-- Export_Object -- |
| 17755 |
------------------- |
| 17756 |
|
| 17757 |
-- pragma Export_Object ( |
| 17758 |
-- [Internal =>] LOCAL_NAME |
| 17759 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 17760 |
-- [, [Size =>] EXTERNAL_SYMBOL]); |
| 17761 |
|
| 17762 |
-- EXTERNAL_SYMBOL ::= |
| 17763 |
-- IDENTIFIER |
| 17764 |
-- | static_string_EXPRESSION |
| 17765 |
|
| 17766 |
-- PARAMETER_TYPES ::= |
| 17767 |
-- null |
| 17768 |
-- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} |
| 17769 |
|
| 17770 |
-- TYPE_DESIGNATOR ::= |
| 17771 |
-- subtype_NAME |
| 17772 |
-- | subtype_Name ' Access |
| 17773 |
|
| 17774 |
-- MECHANISM ::= |
| 17775 |
-- MECHANISM_NAME |
| 17776 |
-- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) |
| 17777 |
|
| 17778 |
-- MECHANISM_ASSOCIATION ::= |
| 17779 |
-- [formal_parameter_NAME =>] MECHANISM_NAME |
| 17780 |
|
| 17781 |
-- MECHANISM_NAME ::= |
| 17782 |
-- Value |
| 17783 |
-- | Reference |
| 17784 |
|
| 17785 |
when Pragma_Export_Object => Export_Object : declare |
| 17786 |
Args : Args_List (1 .. 3); |
| 17787 |
Names : constant Name_List (1 .. 3) := ( |
| 17788 |
Name_Internal, |
| 17789 |
Name_External, |
| 17790 |
Name_Size); |
| 17791 |
|
| 17792 |
Internal : Node_Id renames Args (1); |
| 17793 |
External : Node_Id renames Args (2); |
| 17794 |
Size : Node_Id renames Args (3); |
| 17795 |
|
| 17796 |
begin |
| 17797 |
GNAT_Pragma; |
| 17798 |
Gather_Associations (Names, Args); |
| 17799 |
Process_Extended_Import_Export_Object_Pragma ( |
| 17800 |
Arg_Internal => Internal, |
| 17801 |
Arg_External => External, |
| 17802 |
Arg_Size => Size); |
| 17803 |
end Export_Object; |
| 17804 |
|
| 17805 |
---------------------- |
| 17806 |
-- Export_Procedure -- |
| 17807 |
---------------------- |
| 17808 |
|
| 17809 |
-- pragma Export_Procedure ( |
| 17810 |
-- [Internal =>] LOCAL_NAME |
| 17811 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 17812 |
-- [, [Parameter_Types =>] (PARAMETER_TYPES)] |
| 17813 |
-- [, [Mechanism =>] MECHANISM]); |
| 17814 |
|
| 17815 |
-- EXTERNAL_SYMBOL ::= |
| 17816 |
-- IDENTIFIER |
| 17817 |
-- | static_string_EXPRESSION |
| 17818 |
|
| 17819 |
-- PARAMETER_TYPES ::= |
| 17820 |
-- null |
| 17821 |
-- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} |
| 17822 |
|
| 17823 |
-- TYPE_DESIGNATOR ::= |
| 17824 |
-- subtype_NAME |
| 17825 |
-- | subtype_Name ' Access |
| 17826 |
|
| 17827 |
-- MECHANISM ::= |
| 17828 |
-- MECHANISM_NAME |
| 17829 |
-- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) |
| 17830 |
|
| 17831 |
-- MECHANISM_ASSOCIATION ::= |
| 17832 |
-- [formal_parameter_NAME =>] MECHANISM_NAME |
| 17833 |
|
| 17834 |
-- MECHANISM_NAME ::= |
| 17835 |
-- Value |
| 17836 |
-- | Reference |
| 17837 |
|
| 17838 |
when Pragma_Export_Procedure => Export_Procedure : declare |
| 17839 |
Args : Args_List (1 .. 4); |
| 17840 |
Names : constant Name_List (1 .. 4) := ( |
| 17841 |
Name_Internal, |
| 17842 |
Name_External, |
| 17843 |
Name_Parameter_Types, |
| 17844 |
Name_Mechanism); |
| 17845 |
|
| 17846 |
Internal : Node_Id renames Args (1); |
| 17847 |
External : Node_Id renames Args (2); |
| 17848 |
Parameter_Types : Node_Id renames Args (3); |
| 17849 |
Mechanism : Node_Id renames Args (4); |
| 17850 |
|
| 17851 |
begin |
| 17852 |
GNAT_Pragma; |
| 17853 |
Gather_Associations (Names, Args); |
| 17854 |
Process_Extended_Import_Export_Subprogram_Pragma ( |
| 17855 |
Arg_Internal => Internal, |
| 17856 |
Arg_External => External, |
| 17857 |
Arg_Parameter_Types => Parameter_Types, |
| 17858 |
Arg_Mechanism => Mechanism); |
| 17859 |
end Export_Procedure; |
| 17860 |
|
| 17861 |
----------------------------- |
| 17862 |
-- Export_Valued_Procedure -- |
| 17863 |
----------------------------- |
| 17864 |
|
| 17865 |
-- pragma Export_Valued_Procedure ( |
| 17866 |
-- [Internal =>] LOCAL_NAME |
| 17867 |
-- [, [External =>] EXTERNAL_SYMBOL,] |
| 17868 |
-- [, [Parameter_Types =>] (PARAMETER_TYPES)] |
| 17869 |
-- [, [Mechanism =>] MECHANISM]); |
| 17870 |
|
| 17871 |
-- EXTERNAL_SYMBOL ::= |
| 17872 |
-- IDENTIFIER |
| 17873 |
-- | static_string_EXPRESSION |
| 17874 |
|
| 17875 |
-- PARAMETER_TYPES ::= |
| 17876 |
-- null |
| 17877 |
-- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} |
| 17878 |
|
| 17879 |
-- TYPE_DESIGNATOR ::= |
| 17880 |
-- subtype_NAME |
| 17881 |
-- | subtype_Name ' Access |
| 17882 |
|
| 17883 |
-- MECHANISM ::= |
| 17884 |
-- MECHANISM_NAME |
| 17885 |
-- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) |
| 17886 |
|
| 17887 |
-- MECHANISM_ASSOCIATION ::= |
| 17888 |
-- [formal_parameter_NAME =>] MECHANISM_NAME |
| 17889 |
|
| 17890 |
-- MECHANISM_NAME ::= |
| 17891 |
-- Value |
| 17892 |
-- | Reference |
| 17893 |
|
| 17894 |
when Pragma_Export_Valued_Procedure => |
| 17895 |
Export_Valued_Procedure : declare |
| 17896 |
Args : Args_List (1 .. 4); |
| 17897 |
Names : constant Name_List (1 .. 4) := ( |
| 17898 |
Name_Internal, |
| 17899 |
Name_External, |
| 17900 |
Name_Parameter_Types, |
| 17901 |
Name_Mechanism); |
| 17902 |
|
| 17903 |
Internal : Node_Id renames Args (1); |
| 17904 |
External : Node_Id renames Args (2); |
| 17905 |
Parameter_Types : Node_Id renames Args (3); |
| 17906 |
Mechanism : Node_Id renames Args (4); |
| 17907 |
|
| 17908 |
begin |
| 17909 |
GNAT_Pragma; |
| 17910 |
Gather_Associations (Names, Args); |
| 17911 |
Process_Extended_Import_Export_Subprogram_Pragma ( |
| 17912 |
Arg_Internal => Internal, |
| 17913 |
Arg_External => External, |
| 17914 |
Arg_Parameter_Types => Parameter_Types, |
| 17915 |
Arg_Mechanism => Mechanism); |
| 17916 |
end Export_Valued_Procedure; |
| 17917 |
|
| 17918 |
------------------- |
| 17919 |
-- Extend_System -- |
| 17920 |
------------------- |
| 17921 |
|
| 17922 |
-- pragma Extend_System ([Name =>] Identifier); |
| 17923 |
|
| 17924 |
when Pragma_Extend_System => |
| 17925 |
GNAT_Pragma; |
| 17926 |
Check_Valid_Configuration_Pragma; |
| 17927 |
Check_Arg_Count (1); |
| 17928 |
Check_Optional_Identifier (Arg1, Name_Name); |
| 17929 |
Check_Arg_Is_Identifier (Arg1); |
| 17930 |
|
| 17931 |
Get_Name_String (Chars (Get_Pragma_Arg (Arg1))); |
| 17932 |
|
| 17933 |
if Name_Len > 4 |
| 17934 |
and then Name_Buffer (1 .. 4) = "aux_" |
| 17935 |
then |
| 17936 |
if Present (System_Extend_Pragma_Arg) then |
| 17937 |
if Chars (Get_Pragma_Arg (Arg1)) = |
| 17938 |
Chars (Expression (System_Extend_Pragma_Arg)) |
| 17939 |
then |
| 17940 |
null; |
| 17941 |
else |
| 17942 |
Error_Msg_Sloc := Sloc (System_Extend_Pragma_Arg); |
| 17943 |
Error_Pragma ("pragma% conflicts with that #"); |
| 17944 |
end if; |
| 17945 |
|
| 17946 |
else |
| 17947 |
System_Extend_Pragma_Arg := Arg1; |
| 17948 |
|
| 17949 |
if not GNAT_Mode then |
| 17950 |
System_Extend_Unit := Arg1; |
| 17951 |
end if; |
| 17952 |
end if; |
| 17953 |
else |
| 17954 |
Error_Pragma ("incorrect name for pragma%, must be Aux_xxx"); |
| 17955 |
end if; |
| 17956 |
|
| 17957 |
--------------------- |
| 17958 |
-- Extended_Access -- |
| 17959 |
--------------------- |
| 17960 |
|
| 17961 |
-- pragma Extended_Access (first_subtype_LOCAL_NAME); |
| 17962 |
|
| 17963 |
when Pragma_Extended_Access => Extended_Access : declare |
| 17964 |
Assoc : constant Node_Id := Arg1; |
| 17965 |
Typ : Entity_Id; |
| 17966 |
Type_Id : Node_Id; |
| 17967 |
|
| 17968 |
begin |
| 17969 |
Check_No_Identifiers; |
| 17970 |
Check_Arg_Count (1); |
| 17971 |
Check_Arg_Is_Local_Name (Arg1); |
| 17972 |
Type_Id := Get_Pragma_Arg (Assoc); |
| 17973 |
|
| 17974 |
if not Is_Entity_Name (Type_Id) |
| 17975 |
or else not Is_Type (Entity (Type_Id)) |
| 17976 |
then |
| 17977 |
Error_Pragma_Arg |
| 17978 |
("argument for pragma% must be type or subtype", Arg1); |
| 17979 |
end if; |
| 17980 |
|
| 17981 |
Find_Type (Type_Id); |
| 17982 |
Typ := Entity (Type_Id); |
| 17983 |
|
| 17984 |
if Typ = Any_Type |
| 17985 |
or else Rep_Item_Too_Early (Typ, N) |
| 17986 |
then |
| 17987 |
return; |
| 17988 |
else |
| 17989 |
Typ := Underlying_Type (Typ); |
| 17990 |
end if; |
| 17991 |
|
| 17992 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 17993 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 17994 |
|
| 17995 |
Mark_Ghost_Pragma (N, Typ); |
| 17996 |
|
| 17997 |
if Ekind (Typ) = E_Access_Subtype then |
| 17998 |
Error_Pragma |
| 17999 |
("pragma% not specifiable for subtype"); |
| 18000 |
elsif Ekind (Typ) /= E_General_Access_Type then |
| 18001 |
Error_Pragma |
| 18002 |
("pragma% only specifiable for general access type"); |
| 18003 |
elsif Is_Derived_Type (Typ) then |
| 18004 |
Error_Pragma |
| 18005 |
("pragma% not specifiable for derived type"); |
| 18006 |
else |
| 18007 |
declare |
| 18008 |
Designated : constant Entity_Id := Designated_Type (Typ); |
| 18009 |
begin |
| 18010 |
if not Is_Array_Type (Designated) |
| 18011 |
or else Is_Constrained (Designated) |
| 18012 |
then |
| 18013 |
Error_Pragma |
| 18014 |
("pragma% only specifiable for access type" & |
| 18015 |
" having unconstrained array designated subtype"); |
| 18016 |
end if; |
| 18017 |
end; |
| 18018 |
end if; |
| 18019 |
|
| 18020 |
Check_First_Subtype (Arg1); |
| 18021 |
Check_Duplicate_Pragma (Typ); |
| 18022 |
|
| 18023 |
if Rep_Item_Too_Late (Typ, N) then |
| 18024 |
return; |
| 18025 |
end if; |
| 18026 |
end Extended_Access; |
| 18027 |
|
| 18028 |
------------------------ |
| 18029 |
-- Extensions_Allowed -- |
| 18030 |
------------------------ |
| 18031 |
|
| 18032 |
-- pragma Extensions_Allowed (ON | OFF | ALL_EXTENSIONS); |
| 18033 |
|
| 18034 |
when Pragma_Extensions_Allowed => |
| 18035 |
GNAT_Pragma; |
| 18036 |
Check_Arg_Count (1); |
| 18037 |
Check_No_Identifiers; |
| 18038 |
Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off, Name_All_Extensions); |
| 18039 |
|
| 18040 |
if Chars (Get_Pragma_Arg (Arg1)) = Name_On then |
| 18041 |
Ada_Version := Ada_With_Core_Extensions; |
| 18042 |
elsif Chars (Get_Pragma_Arg (Arg1)) = Name_All_Extensions then |
| 18043 |
Ada_Version := Ada_With_All_Extensions; |
| 18044 |
else |
| 18045 |
Ada_Version := Ada_Version_Explicit; |
| 18046 |
Ada_Version_Pragma := Empty; |
| 18047 |
end if; |
| 18048 |
|
| 18049 |
------------------------ |
| 18050 |
-- Extensions_Visible -- |
| 18051 |
------------------------ |
| 18052 |
|
| 18053 |
-- pragma Extensions_Visible [ (static_boolean_EXPRESSION) ]; |
| 18054 |
|
| 18055 |
-- Characteristics: |
| 18056 |
|
| 18057 |
-- * Analysis - The annotation is fully analyzed immediately upon |
| 18058 |
-- elaboration as its expression must be static. |
| 18059 |
|
| 18060 |
-- * Expansion - None. |
| 18061 |
|
| 18062 |
-- * Template - The annotation utilizes the generic template of the |
| 18063 |
-- related subprogram [body] when it is: |
| 18064 |
|
| 18065 |
-- aspect on subprogram declaration |
| 18066 |
-- aspect on stand-alone subprogram body |
| 18067 |
-- pragma on stand-alone subprogram body |
| 18068 |
|
| 18069 |
-- The annotation must prepare its own template when it is: |
| 18070 |
|
| 18071 |
-- pragma on subprogram declaration |
| 18072 |
|
| 18073 |
-- * Globals - Capture of global references must occur after full |
| 18074 |
-- analysis. |
| 18075 |
|
| 18076 |
-- * Instance - The annotation is instantiated automatically when |
| 18077 |
-- the related generic subprogram [body] is instantiated except for |
| 18078 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 18079 |
-- the annotation must instantiate itself. |
| 18080 |
|
| 18081 |
when Pragma_Extensions_Visible => Extensions_Visible : declare |
| 18082 |
Formal : Entity_Id; |
| 18083 |
Has_OK_Formal : Boolean := False; |
| 18084 |
Spec_Id : Entity_Id; |
| 18085 |
Subp_Decl : Node_Id; |
| 18086 |
|
| 18087 |
begin |
| 18088 |
GNAT_Pragma; |
| 18089 |
Check_No_Identifiers; |
| 18090 |
Check_At_Most_N_Arguments (1); |
| 18091 |
|
| 18092 |
Subp_Decl := |
| 18093 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 18094 |
|
| 18095 |
-- Abstract subprogram declaration |
| 18096 |
|
| 18097 |
if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then |
| 18098 |
null; |
| 18099 |
|
| 18100 |
-- Generic subprogram declaration |
| 18101 |
|
| 18102 |
elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 18103 |
null; |
| 18104 |
|
| 18105 |
-- Body acts as spec |
| 18106 |
|
| 18107 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 18108 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 18109 |
then |
| 18110 |
null; |
| 18111 |
|
| 18112 |
-- Body stub acts as spec |
| 18113 |
|
| 18114 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 18115 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 18116 |
then |
| 18117 |
null; |
| 18118 |
|
| 18119 |
-- Subprogram declaration |
| 18120 |
|
| 18121 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 18122 |
null; |
| 18123 |
|
| 18124 |
-- Otherwise the pragma is associated with an illegal construct |
| 18125 |
|
| 18126 |
else |
| 18127 |
Error_Pragma ("pragma % must apply to a subprogram"); |
| 18128 |
end if; |
| 18129 |
|
| 18130 |
-- Mark the pragma as Ghost if the related subprogram is also |
| 18131 |
-- Ghost. This also ensures that any expansion performed further |
| 18132 |
-- below will produce Ghost nodes. |
| 18133 |
|
| 18134 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 18135 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 18136 |
|
| 18137 |
-- Chain the pragma on the contract for completeness |
| 18138 |
|
| 18139 |
Add_Contract_Item (N, Defining_Entity (Subp_Decl)); |
| 18140 |
|
| 18141 |
-- The legality checks of pragma Extension_Visible are affected |
| 18142 |
-- by the SPARK mode in effect. Analyze all pragmas in specific |
| 18143 |
-- order. |
| 18144 |
|
| 18145 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 18146 |
|
| 18147 |
-- Examine the formals of the related subprogram |
| 18148 |
|
| 18149 |
Formal := First_Formal (Spec_Id); |
| 18150 |
while Present (Formal) loop |
| 18151 |
|
| 18152 |
-- At least one of the formals is of a specific tagged type, |
| 18153 |
-- the pragma is legal. |
| 18154 |
|
| 18155 |
if Is_Specific_Tagged_Type (Etype (Formal)) then |
| 18156 |
Has_OK_Formal := True; |
| 18157 |
exit; |
| 18158 |
|
| 18159 |
-- A generic subprogram with at least one formal of a private |
| 18160 |
-- type ensures the legality of the pragma because the actual |
| 18161 |
-- may be specifically tagged. Note that this is verified by |
| 18162 |
-- the check above at instantiation time. |
| 18163 |
|
| 18164 |
elsif Is_Private_Type (Etype (Formal)) |
| 18165 |
and then Is_Generic_Type (Etype (Formal)) |
| 18166 |
then |
| 18167 |
Has_OK_Formal := True; |
| 18168 |
exit; |
| 18169 |
end if; |
| 18170 |
|
| 18171 |
Next_Formal (Formal); |
| 18172 |
end loop; |
| 18173 |
|
| 18174 |
if not Has_OK_Formal then |
| 18175 |
Error_Msg_Name_1 := Pname; |
| 18176 |
Error_Msg_N (Fix_Error ("incorrect placement of pragma %"), N); |
| 18177 |
Error_Msg_NE |
| 18178 |
("\subprogram & lacks parameter of specific tagged or " |
| 18179 |
& "generic private type", N, Spec_Id); |
| 18180 |
|
| 18181 |
return; |
| 18182 |
end if; |
| 18183 |
|
| 18184 |
-- Analyze the Boolean expression (if any) |
| 18185 |
|
| 18186 |
if Present (Arg1) then |
| 18187 |
Check_Static_Boolean_Expression |
| 18188 |
(Expression (Get_Argument (N, Spec_Id))); |
| 18189 |
end if; |
| 18190 |
end Extensions_Visible; |
| 18191 |
|
| 18192 |
-------------- |
| 18193 |
-- External -- |
| 18194 |
-------------- |
| 18195 |
|
| 18196 |
-- pragma External ( |
| 18197 |
-- [ Convention =>] convention_IDENTIFIER, |
| 18198 |
-- [ Entity =>] LOCAL_NAME |
| 18199 |
-- [, [External_Name =>] static_string_EXPRESSION ] |
| 18200 |
-- [, [Link_Name =>] static_string_EXPRESSION ]); |
| 18201 |
|
| 18202 |
when Pragma_External => External : declare |
| 18203 |
C : Convention_Id; |
| 18204 |
E : Entity_Id; |
| 18205 |
pragma Warnings (Off, C); |
| 18206 |
|
| 18207 |
begin |
| 18208 |
GNAT_Pragma; |
| 18209 |
Check_Arg_Order |
| 18210 |
((Name_Convention, |
| 18211 |
Name_Entity, |
| 18212 |
Name_External_Name, |
| 18213 |
Name_Link_Name)); |
| 18214 |
Check_At_Least_N_Arguments (2); |
| 18215 |
Check_At_Most_N_Arguments (4); |
| 18216 |
Process_Convention (C, E); |
| 18217 |
|
| 18218 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 18219 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 18220 |
|
| 18221 |
Mark_Ghost_Pragma (N, E); |
| 18222 |
|
| 18223 |
Note_Possible_Modification |
| 18224 |
(Get_Pragma_Arg (Arg2), Sure => False); |
| 18225 |
Process_Interface_Name (E, Arg3, Arg4, N); |
| 18226 |
Set_Exported (E, Arg2); |
| 18227 |
end External; |
| 18228 |
|
| 18229 |
-------------------------- |
| 18230 |
-- External_Name_Casing -- |
| 18231 |
-------------------------- |
| 18232 |
|
| 18233 |
-- pragma External_Name_Casing ( |
| 18234 |
-- UPPERCASE | LOWERCASE |
| 18235 |
-- [, AS_IS | UPPERCASE | LOWERCASE]); |
| 18236 |
|
| 18237 |
when Pragma_External_Name_Casing => |
| 18238 |
GNAT_Pragma; |
| 18239 |
Check_No_Identifiers; |
| 18240 |
|
| 18241 |
if Arg_Count = 2 then |
| 18242 |
Check_Arg_Is_One_Of |
| 18243 |
(Arg2, Name_As_Is, Name_Uppercase, Name_Lowercase); |
| 18244 |
|
| 18245 |
case Chars (Get_Pragma_Arg (Arg2)) is |
| 18246 |
when Name_As_Is => |
| 18247 |
Opt.External_Name_Exp_Casing := As_Is; |
| 18248 |
|
| 18249 |
when Name_Uppercase => |
| 18250 |
Opt.External_Name_Exp_Casing := Uppercase; |
| 18251 |
|
| 18252 |
when Name_Lowercase => |
| 18253 |
Opt.External_Name_Exp_Casing := Lowercase; |
| 18254 |
|
| 18255 |
when others => |
| 18256 |
null; |
| 18257 |
end case; |
| 18258 |
|
| 18259 |
else |
| 18260 |
Check_Arg_Count (1); |
| 18261 |
end if; |
| 18262 |
|
| 18263 |
Check_Arg_Is_One_Of (Arg1, Name_Uppercase, Name_Lowercase); |
| 18264 |
|
| 18265 |
case Chars (Get_Pragma_Arg (Arg1)) is |
| 18266 |
when Name_Uppercase => |
| 18267 |
Opt.External_Name_Imp_Casing := Uppercase; |
| 18268 |
|
| 18269 |
when Name_Lowercase => |
| 18270 |
Opt.External_Name_Imp_Casing := Lowercase; |
| 18271 |
|
| 18272 |
when others => |
| 18273 |
null; |
| 18274 |
end case; |
| 18275 |
|
| 18276 |
--------------- |
| 18277 |
-- Fast_Math -- |
| 18278 |
--------------- |
| 18279 |
|
| 18280 |
-- pragma Fast_Math; |
| 18281 |
|
| 18282 |
when Pragma_Fast_Math => |
| 18283 |
GNAT_Pragma; |
| 18284 |
Check_No_Identifiers; |
| 18285 |
Check_Valid_Configuration_Pragma; |
| 18286 |
Fast_Math := True; |
| 18287 |
|
| 18288 |
-------------------------- |
| 18289 |
-- Favor_Top_Level -- |
| 18290 |
-------------------------- |
| 18291 |
|
| 18292 |
-- pragma Favor_Top_Level (type_LOCAL_NAME); |
| 18293 |
|
| 18294 |
when Pragma_Favor_Top_Level => Favor_Top_Level : declare |
| 18295 |
Typ : Entity_Id; |
| 18296 |
|
| 18297 |
begin |
| 18298 |
GNAT_Pragma; |
| 18299 |
Check_No_Identifiers; |
| 18300 |
Check_Arg_Count (1); |
| 18301 |
Check_Arg_Is_Local_Name (Arg1); |
| 18302 |
Typ := Entity (Get_Pragma_Arg (Arg1)); |
| 18303 |
|
| 18304 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 18305 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 18306 |
|
| 18307 |
Mark_Ghost_Pragma (N, Typ); |
| 18308 |
|
| 18309 |
-- If it's an access-to-subprogram type (in particular, not a |
| 18310 |
-- subtype), set the flag on that type. |
| 18311 |
|
| 18312 |
if Is_Access_Subprogram_Type (Typ) then |
| 18313 |
Set_Can_Use_Internal_Rep (Typ, False); |
| 18314 |
|
| 18315 |
-- Otherwise it's an error (name denotes the wrong sort of entity) |
| 18316 |
|
| 18317 |
else |
| 18318 |
Error_Pragma_Arg |
| 18319 |
("access-to-subprogram type expected", |
| 18320 |
Get_Pragma_Arg (Arg1)); |
| 18321 |
end if; |
| 18322 |
end Favor_Top_Level; |
| 18323 |
|
| 18324 |
--------------------------- |
| 18325 |
-- Finalize_Storage_Only -- |
| 18326 |
--------------------------- |
| 18327 |
|
| 18328 |
-- pragma Finalize_Storage_Only (first_subtype_LOCAL_NAME); |
| 18329 |
|
| 18330 |
when Pragma_Finalize_Storage_Only => Finalize_Storage : declare |
| 18331 |
Assoc : constant Node_Id := Arg1; |
| 18332 |
Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc); |
| 18333 |
Typ : Entity_Id; |
| 18334 |
|
| 18335 |
begin |
| 18336 |
GNAT_Pragma; |
| 18337 |
Check_No_Identifiers; |
| 18338 |
Check_Arg_Count (1); |
| 18339 |
Check_Arg_Is_Local_Name (Arg1); |
| 18340 |
|
| 18341 |
Find_Type (Type_Id); |
| 18342 |
Typ := Entity (Type_Id); |
| 18343 |
|
| 18344 |
if Typ = Any_Type |
| 18345 |
or else Rep_Item_Too_Early (Typ, N) |
| 18346 |
then |
| 18347 |
return; |
| 18348 |
else |
| 18349 |
Typ := Underlying_Type (Typ); |
| 18350 |
end if; |
| 18351 |
|
| 18352 |
if not Is_Controlled (Typ) then |
| 18353 |
Error_Pragma ("pragma% must specify controlled type"); |
| 18354 |
end if; |
| 18355 |
|
| 18356 |
Check_First_Subtype (Arg1); |
| 18357 |
|
| 18358 |
if Finalize_Storage_Only (Typ) then |
| 18359 |
Error_Pragma ("duplicate pragma%, only one allowed"); |
| 18360 |
|
| 18361 |
elsif not Rep_Item_Too_Late (Typ, N) then |
| 18362 |
Set_Finalize_Storage_Only (Base_Type (Typ), True); |
| 18363 |
end if; |
| 18364 |
end Finalize_Storage; |
| 18365 |
|
| 18366 |
---------------------------------------- |
| 18367 |
-- Pragma_First_Controlling_Parameter -- |
| 18368 |
---------------------------------------- |
| 18369 |
|
| 18370 |
when Pragma_First_Controlling_Parameter => First_Ctrl_Param : declare |
| 18371 |
Arg : Node_Id; |
| 18372 |
E : Entity_Id := Empty; |
| 18373 |
Expr : Node_Id := Empty; |
| 18374 |
|
| 18375 |
begin |
| 18376 |
GNAT_Pragma; |
| 18377 |
Check_At_Least_N_Arguments (1); |
| 18378 |
Check_At_Most_N_Arguments (2); |
| 18379 |
|
| 18380 |
Arg := Get_Pragma_Arg (Arg1); |
| 18381 |
Check_Arg_Is_Identifier (Arg); |
| 18382 |
|
| 18383 |
Analyze (Arg); |
| 18384 |
E := Entity (Arg); |
| 18385 |
|
| 18386 |
if Present (Arg2) then |
| 18387 |
Check_Arg_Is_OK_Static_Expression (Arg2, Standard_Boolean); |
| 18388 |
Expr := Get_Pragma_Arg (Arg2); |
| 18389 |
Analyze_And_Resolve (Expr, Standard_Boolean); |
| 18390 |
end if; |
| 18391 |
|
| 18392 |
if not Core_Extensions_Allowed then |
| 18393 |
if No (Expr) |
| 18394 |
or else |
| 18395 |
(Present (Expr) |
| 18396 |
and then Is_Entity_Name (Expr) |
| 18397 |
and then Entity (Expr) = Standard_True) |
| 18398 |
then |
| 18399 |
Error_Msg_GNAT_Extension |
| 18400 |
("'First_'Controlling_'Parameter", Sloc (N), |
| 18401 |
Is_Core_Extension => True); |
| 18402 |
end if; |
| 18403 |
|
| 18404 |
return; |
| 18405 |
|
| 18406 |
elsif Present (Expr) |
| 18407 |
and then Is_Entity_Name (Expr) |
| 18408 |
and then Entity (Expr) = Standard_False |
| 18409 |
then |
| 18410 |
if Is_Derived_Type (E) |
| 18411 |
and then Has_First_Controlling_Parameter_Aspect (Etype (E)) |
| 18412 |
then |
| 18413 |
Error_Msg_Name_1 := Name_First_Controlling_Parameter; |
| 18414 |
Error_Msg_N |
| 18415 |
("specification of inherited True value for aspect% can " |
| 18416 |
& "only confirm parent value", Pragma_Identifier (N)); |
| 18417 |
end if; |
| 18418 |
|
| 18419 |
return; |
| 18420 |
end if; |
| 18421 |
|
| 18422 |
if No (E) |
| 18423 |
or else not Is_Type (E) |
| 18424 |
or else not (Is_Tagged_Type (E) |
| 18425 |
or else Is_Concurrent_Type (E)) |
| 18426 |
then |
| 18427 |
Error_Pragma |
| 18428 |
("pragma% must specify tagged type or concurrent type"); |
| 18429 |
end if; |
| 18430 |
|
| 18431 |
-- Check use of the pragma on private types |
| 18432 |
|
| 18433 |
if Has_Private_Declaration (E) then |
| 18434 |
declare |
| 18435 |
Prev_Id : constant Entity_Id := |
| 18436 |
Incomplete_Or_Partial_View (E); |
| 18437 |
begin |
| 18438 |
if Is_Tagged_Type (Prev_Id) then |
| 18439 |
if Has_First_Controlling_Parameter_Aspect (Prev_Id) then |
| 18440 |
Error_Pragma |
| 18441 |
("pragma already specified in private declaration"); |
| 18442 |
else |
| 18443 |
Error_Msg_N |
| 18444 |
("hidden 'First_'Controlling_'Parameter tagged type" |
| 18445 |
& " not allowed", N); |
| 18446 |
end if; |
| 18447 |
|
| 18448 |
-- No action needed if the partial view is not tagged. For |
| 18449 |
-- example: |
| 18450 |
|
| 18451 |
-- package Example is |
| 18452 |
-- type Private_Type is private; |
| 18453 |
-- private |
| 18454 |
-- type Private_Type is new ... with null record |
| 18455 |
-- with First_Controlling_Parameter; -- Legal |
| 18456 |
-- end; |
| 18457 |
|
| 18458 |
else |
| 18459 |
null; |
| 18460 |
end if; |
| 18461 |
end; |
| 18462 |
end if; |
| 18463 |
|
| 18464 |
-- The corresponding record type of concurrent types will not be |
| 18465 |
-- a tagged type when it does not implement some interface type. |
| 18466 |
|
| 18467 |
if Is_Concurrent_Type (E) |
| 18468 |
and then Present (Parent (E)) |
| 18469 |
and then No (Interface_List (Parent (E))) |
| 18470 |
then |
| 18471 |
if Warn_On_Non_Dispatching_Primitives then |
| 18472 |
Error_Msg_N |
| 18473 |
("?_j?'First_'Controlling_'Parameter has no effect", N); |
| 18474 |
Error_Msg_NE |
| 18475 |
("\?_j?because & does not implement interface types", |
| 18476 |
N, E); |
| 18477 |
end if; |
| 18478 |
|
| 18479 |
else |
| 18480 |
Set_Has_First_Controlling_Parameter_Aspect (E); |
| 18481 |
end if; |
| 18482 |
end First_Ctrl_Param; |
| 18483 |
|
| 18484 |
----------- |
| 18485 |
-- Ghost -- |
| 18486 |
----------- |
| 18487 |
|
| 18488 |
-- pragma Ghost [ (static_boolean_EXPRESSION) ]; |
| 18489 |
|
| 18490 |
when Pragma_Ghost => Ghost : declare |
| 18491 |
Context : Node_Id; |
| 18492 |
Expr : Node_Id; |
| 18493 |
Id : Entity_Id; |
| 18494 |
Orig_Stmt : Node_Id; |
| 18495 |
Prev_Id : Entity_Id; |
| 18496 |
Stmt : Node_Id; |
| 18497 |
|
| 18498 |
begin |
| 18499 |
GNAT_Pragma; |
| 18500 |
Check_No_Identifiers; |
| 18501 |
Check_At_Most_N_Arguments (1); |
| 18502 |
|
| 18503 |
Id := Empty; |
| 18504 |
Stmt := Prev (N); |
| 18505 |
while Present (Stmt) loop |
| 18506 |
|
| 18507 |
-- Skip prior pragmas, but check for duplicates |
| 18508 |
|
| 18509 |
if Nkind (Stmt) = N_Pragma then |
| 18510 |
if Pragma_Name (Stmt) = Pname then |
| 18511 |
Duplication_Error |
| 18512 |
(Prag => N, |
| 18513 |
Prev => Stmt); |
| 18514 |
raise Pragma_Exit; |
| 18515 |
end if; |
| 18516 |
|
| 18517 |
-- Task unit declared without a definition cannot be subject to |
| 18518 |
-- pragma Ghost (SPARK RM 6.9(21)). |
| 18519 |
|
| 18520 |
elsif Nkind (Stmt) in |
| 18521 |
N_Single_Task_Declaration | N_Task_Type_Declaration |
| 18522 |
then |
| 18523 |
Error_Pragma ("pragma % cannot apply to a task type"); |
| 18524 |
|
| 18525 |
-- Skip internally generated code |
| 18526 |
|
| 18527 |
elsif not Comes_From_Source (Stmt) then |
| 18528 |
Orig_Stmt := Original_Node (Stmt); |
| 18529 |
|
| 18530 |
-- When pragma Ghost applies to an untagged derivation, the |
| 18531 |
-- derivation is transformed into a [sub]type declaration. |
| 18532 |
|
| 18533 |
if Nkind (Stmt) in |
| 18534 |
N_Full_Type_Declaration | N_Subtype_Declaration |
| 18535 |
and then Comes_From_Source (Orig_Stmt) |
| 18536 |
and then Nkind (Orig_Stmt) = N_Full_Type_Declaration |
| 18537 |
and then Nkind (Type_Definition (Orig_Stmt)) = |
| 18538 |
N_Derived_Type_Definition |
| 18539 |
then |
| 18540 |
Id := Defining_Entity (Stmt); |
| 18541 |
exit; |
| 18542 |
|
| 18543 |
-- When pragma Ghost applies to an object declaration which |
| 18544 |
-- is initialized by means of a function call that returns |
| 18545 |
-- on the secondary stack, the object declaration becomes a |
| 18546 |
-- renaming. |
| 18547 |
|
| 18548 |
elsif Nkind (Stmt) = N_Object_Renaming_Declaration |
| 18549 |
and then Comes_From_Source (Orig_Stmt) |
| 18550 |
and then Nkind (Orig_Stmt) = N_Object_Declaration |
| 18551 |
then |
| 18552 |
Id := Defining_Entity (Stmt); |
| 18553 |
exit; |
| 18554 |
|
| 18555 |
-- When pragma Ghost applies to an expression function, the |
| 18556 |
-- expression function is transformed into a subprogram. |
| 18557 |
|
| 18558 |
elsif Nkind (Stmt) = N_Subprogram_Declaration |
| 18559 |
and then Comes_From_Source (Orig_Stmt) |
| 18560 |
and then Nkind (Orig_Stmt) = N_Expression_Function |
| 18561 |
then |
| 18562 |
Id := Defining_Entity (Stmt); |
| 18563 |
exit; |
| 18564 |
|
| 18565 |
-- When pragma Ghost applies to a generic formal type, the |
| 18566 |
-- type declaration in the instantiation is a generated |
| 18567 |
-- subtype declaration. |
| 18568 |
|
| 18569 |
elsif Nkind (Stmt) = N_Subtype_Declaration |
| 18570 |
and then Present (Generic_Parent_Type (Stmt)) |
| 18571 |
then |
| 18572 |
Id := Defining_Entity (Stmt); |
| 18573 |
exit; |
| 18574 |
end if; |
| 18575 |
|
| 18576 |
-- The pragma applies to a legal construct, stop the traversal |
| 18577 |
|
| 18578 |
elsif Nkind (Stmt) in N_Abstract_Subprogram_Declaration |
| 18579 |
| N_Formal_Object_Declaration |
| 18580 |
| N_Formal_Subprogram_Declaration |
| 18581 |
| N_Formal_Type_Declaration |
| 18582 |
| N_Full_Type_Declaration |
| 18583 |
| N_Generic_Subprogram_Declaration |
| 18584 |
| N_Object_Declaration |
| 18585 |
| N_Private_Extension_Declaration |
| 18586 |
| N_Private_Type_Declaration |
| 18587 |
| N_Subprogram_Declaration |
| 18588 |
| N_Subtype_Declaration |
| 18589 |
then |
| 18590 |
Id := Defining_Entity (Stmt); |
| 18591 |
exit; |
| 18592 |
|
| 18593 |
-- The pragma does not apply to a legal construct, issue an |
| 18594 |
-- error and stop the analysis. |
| 18595 |
|
| 18596 |
else |
| 18597 |
Error_Pragma |
| 18598 |
("pragma % must apply to an object, package, subprogram " |
| 18599 |
& "or type"); |
| 18600 |
end if; |
| 18601 |
|
| 18602 |
Stmt := Prev (Stmt); |
| 18603 |
end loop; |
| 18604 |
|
| 18605 |
Context := Parent (N); |
| 18606 |
|
| 18607 |
-- Handle compilation units |
| 18608 |
|
| 18609 |
if Nkind (Context) = N_Compilation_Unit_Aux then |
| 18610 |
Context := Unit (Parent (Context)); |
| 18611 |
end if; |
| 18612 |
|
| 18613 |
-- Protected and task types cannot be subject to pragma Ghost |
| 18614 |
-- (SPARK RM 6.9(21)). |
| 18615 |
|
| 18616 |
if Nkind (Context) in N_Protected_Body | N_Protected_Definition |
| 18617 |
then |
| 18618 |
Error_Pragma ("pragma % cannot apply to a protected type"); |
| 18619 |
|
| 18620 |
elsif Nkind (Context) in N_Task_Body | N_Task_Definition then |
| 18621 |
Error_Pragma ("pragma % cannot apply to a task type"); |
| 18622 |
end if; |
| 18623 |
|
| 18624 |
if No (Id) then |
| 18625 |
|
| 18626 |
-- When pragma Ghost is associated with a [generic] package, it |
| 18627 |
-- appears in the visible declarations. |
| 18628 |
|
| 18629 |
if Nkind (Context) = N_Package_Specification |
| 18630 |
and then Present (Visible_Declarations (Context)) |
| 18631 |
and then List_Containing (N) = Visible_Declarations (Context) |
| 18632 |
then |
| 18633 |
Id := Defining_Entity (Context); |
| 18634 |
|
| 18635 |
-- Pragma Ghost applies to a stand-alone subprogram body |
| 18636 |
|
| 18637 |
elsif Nkind (Context) = N_Subprogram_Body |
| 18638 |
and then No (Corresponding_Spec (Context)) |
| 18639 |
then |
| 18640 |
Id := Defining_Entity (Context); |
| 18641 |
|
| 18642 |
-- Pragma Ghost applies to a subprogram declaration that acts |
| 18643 |
-- as a compilation unit. |
| 18644 |
|
| 18645 |
elsif Nkind (Context) = N_Subprogram_Declaration then |
| 18646 |
Id := Defining_Entity (Context); |
| 18647 |
|
| 18648 |
-- Pragma Ghost applies to a generic subprogram |
| 18649 |
|
| 18650 |
elsif Nkind (Context) = N_Generic_Subprogram_Declaration then |
| 18651 |
Id := Defining_Entity (Specification (Context)); |
| 18652 |
end if; |
| 18653 |
end if; |
| 18654 |
|
| 18655 |
if No (Id) then |
| 18656 |
Error_Pragma |
| 18657 |
("pragma % must apply to an object, package, subprogram or " |
| 18658 |
& "type"); |
| 18659 |
end if; |
| 18660 |
|
| 18661 |
-- Handle completions of types and constants that are subject to |
| 18662 |
-- pragma Ghost. |
| 18663 |
|
| 18664 |
if Is_Record_Type (Id) or else Ekind (Id) = E_Constant then |
| 18665 |
Prev_Id := Incomplete_Or_Partial_View (Id); |
| 18666 |
|
| 18667 |
if Present (Prev_Id) and then not Is_Ghost_Entity (Prev_Id) then |
| 18668 |
Error_Msg_Name_1 := Pname; |
| 18669 |
|
| 18670 |
-- The full declaration of a deferred constant cannot be |
| 18671 |
-- subject to pragma Ghost unless the deferred declaration |
| 18672 |
-- is also Ghost (SPARK RM 6.9(9)). |
| 18673 |
|
| 18674 |
if Ekind (Prev_Id) = E_Constant then |
| 18675 |
Error_Msg_Name_1 := Pname; |
| 18676 |
Error_Msg_NE (Fix_Error |
| 18677 |
("pragma % must apply to declaration of deferred " |
| 18678 |
& "constant &"), N, Id); |
| 18679 |
return; |
| 18680 |
|
| 18681 |
-- Pragma Ghost may appear on the full view of an incomplete |
| 18682 |
-- type because the incomplete declaration lacks aspects and |
| 18683 |
-- cannot be subject to pragma Ghost. |
| 18684 |
|
| 18685 |
elsif Ekind (Prev_Id) = E_Incomplete_Type then |
| 18686 |
null; |
| 18687 |
|
| 18688 |
-- The full declaration of a type cannot be subject to |
| 18689 |
-- pragma Ghost unless the partial view is also Ghost |
| 18690 |
-- (SPARK RM 6.9(9)). |
| 18691 |
|
| 18692 |
else |
| 18693 |
Error_Msg_NE (Fix_Error |
| 18694 |
("pragma % must apply to partial view of type &"), |
| 18695 |
N, Id); |
| 18696 |
return; |
| 18697 |
end if; |
| 18698 |
end if; |
| 18699 |
|
| 18700 |
-- A synchronized object cannot be subject to pragma Ghost |
| 18701 |
-- (SPARK RM 6.9(21)). |
| 18702 |
|
| 18703 |
elsif Ekind (Id) = E_Variable then |
| 18704 |
if Is_Protected_Type (Etype (Id)) then |
| 18705 |
Error_Pragma ("pragma % cannot apply to a protected object"); |
| 18706 |
|
| 18707 |
elsif Is_Task_Type (Etype (Id)) then |
| 18708 |
Error_Pragma ("pragma % cannot apply to a task object"); |
| 18709 |
end if; |
| 18710 |
end if; |
| 18711 |
|
| 18712 |
-- Analyze the Boolean expression (if any) |
| 18713 |
|
| 18714 |
if Present (Arg1) then |
| 18715 |
Expr := Get_Pragma_Arg (Arg1); |
| 18716 |
|
| 18717 |
Analyze_And_Resolve (Expr, Standard_Boolean); |
| 18718 |
|
| 18719 |
if Is_OK_Static_Expression (Expr) then |
| 18720 |
|
| 18721 |
-- "Ghostness" cannot be turned off once enabled within a |
| 18722 |
-- region (SPARK RM 6.9(6)). |
| 18723 |
|
| 18724 |
if Is_False (Expr_Value (Expr)) |
| 18725 |
and then Ghost_Mode > None |
| 18726 |
then |
| 18727 |
Error_Pragma |
| 18728 |
("pragma % with value False cannot appear in enabled " |
| 18729 |
& "ghost region"); |
| 18730 |
end if; |
| 18731 |
|
| 18732 |
-- Otherwise the expression is not static |
| 18733 |
|
| 18734 |
else |
| 18735 |
Error_Pragma_Arg |
| 18736 |
("expression of pragma % must be static", Expr); |
| 18737 |
end if; |
| 18738 |
end if; |
| 18739 |
|
| 18740 |
Set_Is_Ghost_Entity (Id); |
| 18741 |
end Ghost; |
| 18742 |
|
| 18743 |
------------ |
| 18744 |
-- Global -- |
| 18745 |
------------ |
| 18746 |
|
| 18747 |
-- pragma Global (GLOBAL_SPECIFICATION); |
| 18748 |
|
| 18749 |
-- GLOBAL_SPECIFICATION ::= |
| 18750 |
-- null |
| 18751 |
-- | (GLOBAL_LIST) |
| 18752 |
-- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}) |
| 18753 |
|
| 18754 |
-- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST |
| 18755 |
|
| 18756 |
-- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In |
| 18757 |
-- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM}) |
| 18758 |
-- GLOBAL_ITEM ::= NAME |
| 18759 |
|
| 18760 |
-- Characteristics: |
| 18761 |
|
| 18762 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 18763 |
-- the legal placement and context. Secondary checks fully analyze |
| 18764 |
-- the dependency clauses in: |
| 18765 |
|
| 18766 |
-- Analyze_Global_In_Decl_Part |
| 18767 |
|
| 18768 |
-- * Expansion - None. |
| 18769 |
|
| 18770 |
-- * Template - The annotation utilizes the generic template of the |
| 18771 |
-- related subprogram [body] when it is: |
| 18772 |
|
| 18773 |
-- aspect on subprogram declaration |
| 18774 |
-- aspect on stand-alone subprogram body |
| 18775 |
-- pragma on stand-alone subprogram body |
| 18776 |
|
| 18777 |
-- The annotation must prepare its own template when it is: |
| 18778 |
|
| 18779 |
-- pragma on subprogram declaration |
| 18780 |
|
| 18781 |
-- * Globals - Capture of global references must occur after full |
| 18782 |
-- analysis. |
| 18783 |
|
| 18784 |
-- * Instance - The annotation is instantiated automatically when |
| 18785 |
-- the related generic subprogram [body] is instantiated except for |
| 18786 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 18787 |
-- the annotation must instantiate itself. |
| 18788 |
|
| 18789 |
when Pragma_Global => Global : declare |
| 18790 |
Legal : Boolean; |
| 18791 |
Spec_Id : Entity_Id; |
| 18792 |
Subp_Decl : Node_Id; |
| 18793 |
|
| 18794 |
begin |
| 18795 |
Analyze_Depends_Global (Spec_Id, Subp_Decl, Legal); |
| 18796 |
|
| 18797 |
if Legal then |
| 18798 |
|
| 18799 |
-- Chain the pragma on the contract for further processing by |
| 18800 |
-- Analyze_Global_In_Decl_Part. |
| 18801 |
|
| 18802 |
Add_Contract_Item (N, Spec_Id); |
| 18803 |
|
| 18804 |
-- Fully analyze the pragma when it appears inside an entry |
| 18805 |
-- or subprogram body because it cannot benefit from forward |
| 18806 |
-- references. |
| 18807 |
|
| 18808 |
if Nkind (Subp_Decl) in N_Entry_Body |
| 18809 |
| N_Subprogram_Body |
| 18810 |
| N_Subprogram_Body_Stub |
| 18811 |
then |
| 18812 |
-- The legality checks of pragmas Depends and Global are |
| 18813 |
-- affected by the SPARK mode in effect and the volatility |
| 18814 |
-- of the context. In addition these two pragmas are subject |
| 18815 |
-- to an inherent order: |
| 18816 |
|
| 18817 |
-- 1) Global |
| 18818 |
-- 2) Depends |
| 18819 |
|
| 18820 |
-- Analyze all these pragmas in the order outlined above |
| 18821 |
|
| 18822 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 18823 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 18824 |
Analyze_If_Present (Pragma_Side_Effects); |
| 18825 |
Analyze_Global_In_Decl_Part (N); |
| 18826 |
Analyze_If_Present (Pragma_Depends); |
| 18827 |
end if; |
| 18828 |
end if; |
| 18829 |
end Global; |
| 18830 |
|
| 18831 |
----------- |
| 18832 |
-- Ident -- |
| 18833 |
----------- |
| 18834 |
|
| 18835 |
-- pragma Ident (static_string_EXPRESSION) |
| 18836 |
|
| 18837 |
-- Note: pragma Comment shares this processing. Pragma Ident is |
| 18838 |
-- identical in effect to pragma Commment. |
| 18839 |
|
| 18840 |
when Pragma_Comment |
| 18841 |
| Pragma_Ident |
| 18842 |
=> |
| 18843 |
Ident : declare |
| 18844 |
Str : Node_Id; |
| 18845 |
|
| 18846 |
begin |
| 18847 |
GNAT_Pragma; |
| 18848 |
Check_Arg_Count (1); |
| 18849 |
Check_No_Identifiers; |
| 18850 |
Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String); |
| 18851 |
Store_Note (N); |
| 18852 |
|
| 18853 |
Str := Expr_Value_S (Get_Pragma_Arg (Arg1)); |
| 18854 |
|
| 18855 |
declare |
| 18856 |
CS : Node_Id; |
| 18857 |
GP : Node_Id; |
| 18858 |
|
| 18859 |
begin |
| 18860 |
GP := Parent (Parent (N)); |
| 18861 |
|
| 18862 |
if Nkind (GP) in |
| 18863 |
N_Package_Declaration | N_Generic_Package_Declaration |
| 18864 |
then |
| 18865 |
GP := Parent (GP); |
| 18866 |
end if; |
| 18867 |
|
| 18868 |
-- If we have a compilation unit, then record the ident value, |
| 18869 |
-- checking for improper duplication. |
| 18870 |
|
| 18871 |
if Nkind (GP) = N_Compilation_Unit then |
| 18872 |
CS := Ident_String (Current_Sem_Unit); |
| 18873 |
|
| 18874 |
if Present (CS) then |
| 18875 |
|
| 18876 |
-- If we have multiple instances, concatenate them. |
| 18877 |
|
| 18878 |
Start_String (Strval (CS)); |
| 18879 |
Store_String_Char (' '); |
| 18880 |
Store_String_Chars (Strval (Str)); |
| 18881 |
Set_Strval (CS, End_String); |
| 18882 |
|
| 18883 |
else |
| 18884 |
Set_Ident_String (Current_Sem_Unit, Str); |
| 18885 |
end if; |
| 18886 |
|
| 18887 |
-- For subunits, we just ignore the Ident, since in GNAT these |
| 18888 |
-- are not separate object files, and hence not separate units |
| 18889 |
-- in the unit table. |
| 18890 |
|
| 18891 |
elsif Nkind (GP) = N_Subunit then |
| 18892 |
null; |
| 18893 |
end if; |
| 18894 |
end; |
| 18895 |
end Ident; |
| 18896 |
|
| 18897 |
------------------- |
| 18898 |
-- Ignore_Pragma -- |
| 18899 |
------------------- |
| 18900 |
|
| 18901 |
-- pragma Ignore_Pragma (pragma_IDENTIFIER); |
| 18902 |
|
| 18903 |
-- Entirely handled in the parser, nothing to do here |
| 18904 |
|
| 18905 |
when Pragma_Ignore_Pragma => |
| 18906 |
null; |
| 18907 |
|
| 18908 |
---------------------------- |
| 18909 |
-- Implementation_Defined -- |
| 18910 |
---------------------------- |
| 18911 |
|
| 18912 |
-- pragma Implementation_Defined (LOCAL_NAME); |
| 18913 |
|
| 18914 |
-- Marks previously declared entity as implementation defined. For |
| 18915 |
-- an overloaded entity, applies to the most recent homonym. |
| 18916 |
|
| 18917 |
-- pragma Implementation_Defined; |
| 18918 |
|
| 18919 |
-- The form with no arguments appears anywhere within a scope, most |
| 18920 |
-- typically a package spec, and indicates that all entities that are |
| 18921 |
-- defined within the package spec are Implementation_Defined. |
| 18922 |
|
| 18923 |
when Pragma_Implementation_Defined => Implementation_Defined : declare |
| 18924 |
Ent : Entity_Id; |
| 18925 |
|
| 18926 |
begin |
| 18927 |
GNAT_Pragma; |
| 18928 |
Check_No_Identifiers; |
| 18929 |
|
| 18930 |
-- Form with no arguments |
| 18931 |
|
| 18932 |
if Arg_Count = 0 then |
| 18933 |
Set_Is_Implementation_Defined (Current_Scope); |
| 18934 |
|
| 18935 |
-- Form with one argument |
| 18936 |
|
| 18937 |
else |
| 18938 |
Check_Arg_Count (1); |
| 18939 |
Check_Arg_Is_Local_Name (Arg1); |
| 18940 |
Ent := Entity (Get_Pragma_Arg (Arg1)); |
| 18941 |
Set_Is_Implementation_Defined (Ent); |
| 18942 |
end if; |
| 18943 |
end Implementation_Defined; |
| 18944 |
|
| 18945 |
----------------- |
| 18946 |
-- Implemented -- |
| 18947 |
----------------- |
| 18948 |
|
| 18949 |
-- pragma Implemented (procedure_LOCAL_NAME, IMPLEMENTATION_KIND); |
| 18950 |
|
| 18951 |
-- IMPLEMENTATION_KIND ::= |
| 18952 |
-- By_Entry | By_Protected_Procedure | By_Any | Optional |
| 18953 |
|
| 18954 |
-- "By_Any" and "Optional" are treated as synonyms in order to |
| 18955 |
-- support Ada 2012 aspect Synchronization. |
| 18956 |
|
| 18957 |
when Pragma_Implemented => Implemented : declare |
| 18958 |
Proc_Id : Entity_Id; |
| 18959 |
Typ : Entity_Id; |
| 18960 |
|
| 18961 |
begin |
| 18962 |
Ada_2012_Pragma; |
| 18963 |
Check_Arg_Count (2); |
| 18964 |
Check_No_Identifiers; |
| 18965 |
Check_Arg_Is_Identifier (Arg1); |
| 18966 |
Check_Arg_Is_Local_Name (Arg1); |
| 18967 |
Check_Arg_Is_One_Of (Arg2, |
| 18968 |
Name_By_Any, |
| 18969 |
Name_By_Entry, |
| 18970 |
Name_By_Protected_Procedure, |
| 18971 |
Name_Optional); |
| 18972 |
|
| 18973 |
-- Extract the name of the local procedure |
| 18974 |
|
| 18975 |
Proc_Id := Entity (Get_Pragma_Arg (Arg1)); |
| 18976 |
|
| 18977 |
-- Ada 2012 (AI05-0030): The procedure_LOCAL_NAME must denote a |
| 18978 |
-- primitive procedure of a synchronized tagged type. |
| 18979 |
|
| 18980 |
if Ekind (Proc_Id) = E_Procedure |
| 18981 |
and then Is_Primitive (Proc_Id) |
| 18982 |
and then Present (First_Formal (Proc_Id)) |
| 18983 |
then |
| 18984 |
Typ := Etype (First_Formal (Proc_Id)); |
| 18985 |
|
| 18986 |
if Is_Tagged_Type (Typ) |
| 18987 |
and then |
| 18988 |
|
| 18989 |
-- Check for a protected, a synchronized or a task interface |
| 18990 |
|
| 18991 |
((Is_Interface (Typ) |
| 18992 |
and then Is_Synchronized_Interface (Typ)) |
| 18993 |
|
| 18994 |
-- Check for a protected type or a task type that implements |
| 18995 |
-- an interface. |
| 18996 |
|
| 18997 |
or else |
| 18998 |
(Is_Concurrent_Record_Type (Typ) |
| 18999 |
and then Present (Interfaces (Typ))) |
| 19000 |
|
| 19001 |
-- In analysis-only mode, examine original protected type |
| 19002 |
|
| 19003 |
or else |
| 19004 |
(Nkind (Parent (Typ)) = N_Protected_Type_Declaration |
| 19005 |
and then Present (Interface_List (Parent (Typ)))) |
| 19006 |
|
| 19007 |
-- Check for a private record extension with keyword |
| 19008 |
-- "synchronized". |
| 19009 |
|
| 19010 |
or else |
| 19011 |
(Ekind (Typ) in E_Record_Type_With_Private |
| 19012 |
| E_Record_Subtype_With_Private |
| 19013 |
and then Synchronized_Present (Parent (Typ)))) |
| 19014 |
then |
| 19015 |
null; |
| 19016 |
else |
| 19017 |
Error_Pragma_Arg |
| 19018 |
("controlling formal must be of synchronized tagged type", |
| 19019 |
Arg1); |
| 19020 |
end if; |
| 19021 |
|
| 19022 |
-- Ada 2012 (AI05-0030): Cannot apply the implementation_kind |
| 19023 |
-- By_Protected_Procedure to the primitive procedure of a task |
| 19024 |
-- interface. |
| 19025 |
|
| 19026 |
if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure |
| 19027 |
and then Is_Interface (Typ) |
| 19028 |
and then Is_Task_Interface (Typ) |
| 19029 |
then |
| 19030 |
Error_Pragma_Arg |
| 19031 |
("implementation kind By_Protected_Procedure cannot be " |
| 19032 |
& "applied to a task interface primitive", Arg2); |
| 19033 |
end if; |
| 19034 |
|
| 19035 |
-- Procedures declared inside a protected type must be accepted |
| 19036 |
|
| 19037 |
elsif Ekind (Proc_Id) = E_Procedure |
| 19038 |
and then Is_Protected_Type (Scope (Proc_Id)) |
| 19039 |
then |
| 19040 |
null; |
| 19041 |
|
| 19042 |
-- The first argument is not a primitive procedure |
| 19043 |
|
| 19044 |
else |
| 19045 |
Error_Pragma_Arg |
| 19046 |
("pragma % must be applied to a primitive procedure", Arg1); |
| 19047 |
end if; |
| 19048 |
|
| 19049 |
-- Ada 2012 (AI12-0279): Cannot apply the implementation_kind |
| 19050 |
-- By_Protected_Procedure to a procedure that has aspect Yield |
| 19051 |
|
| 19052 |
if Chars (Get_Pragma_Arg (Arg2)) = Name_By_Protected_Procedure |
| 19053 |
and then Has_Yield_Aspect (Proc_Id) |
| 19054 |
then |
| 19055 |
Error_Pragma_Arg |
| 19056 |
("implementation kind By_Protected_Procedure cannot be " |
| 19057 |
& "applied to entities with aspect 'Yield", Arg2); |
| 19058 |
end if; |
| 19059 |
|
| 19060 |
Record_Rep_Item (Proc_Id, N); |
| 19061 |
end Implemented; |
| 19062 |
|
| 19063 |
---------------------- |
| 19064 |
-- Implicit_Packing -- |
| 19065 |
---------------------- |
| 19066 |
|
| 19067 |
-- pragma Implicit_Packing; |
| 19068 |
|
| 19069 |
when Pragma_Implicit_Packing => |
| 19070 |
GNAT_Pragma; |
| 19071 |
Check_Arg_Count (0); |
| 19072 |
Implicit_Packing := True; |
| 19073 |
|
| 19074 |
------------ |
| 19075 |
-- Import -- |
| 19076 |
------------ |
| 19077 |
|
| 19078 |
-- pragma Import ( |
| 19079 |
-- [Convention =>] convention_IDENTIFIER, |
| 19080 |
-- [Entity =>] LOCAL_NAME |
| 19081 |
-- [, [External_Name =>] static_string_EXPRESSION ] |
| 19082 |
-- [, [Link_Name =>] static_string_EXPRESSION ]); |
| 19083 |
|
| 19084 |
when Pragma_Import => |
| 19085 |
Check_Ada_83_Warning; |
| 19086 |
Check_Arg_Order |
| 19087 |
((Name_Convention, |
| 19088 |
Name_Entity, |
| 19089 |
Name_External_Name, |
| 19090 |
Name_Link_Name)); |
| 19091 |
|
| 19092 |
Check_At_Least_N_Arguments (2); |
| 19093 |
Check_At_Most_N_Arguments (4); |
| 19094 |
Process_Import_Or_Interface; |
| 19095 |
|
| 19096 |
--------------------- |
| 19097 |
-- Import_Function -- |
| 19098 |
--------------------- |
| 19099 |
|
| 19100 |
-- pragma Import_Function ( |
| 19101 |
-- [Internal =>] LOCAL_NAME, |
| 19102 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 19103 |
-- [, [Parameter_Types =>] (PARAMETER_TYPES)] |
| 19104 |
-- [, [Result_Type =>] SUBTYPE_MARK] |
| 19105 |
-- [, [Mechanism =>] MECHANISM] |
| 19106 |
-- [, [Result_Mechanism =>] MECHANISM_NAME]); |
| 19107 |
|
| 19108 |
-- EXTERNAL_SYMBOL ::= |
| 19109 |
-- IDENTIFIER |
| 19110 |
-- | static_string_EXPRESSION |
| 19111 |
|
| 19112 |
-- PARAMETER_TYPES ::= |
| 19113 |
-- null |
| 19114 |
-- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} |
| 19115 |
|
| 19116 |
-- TYPE_DESIGNATOR ::= |
| 19117 |
-- subtype_NAME |
| 19118 |
-- | subtype_Name ' Access |
| 19119 |
|
| 19120 |
-- MECHANISM ::= |
| 19121 |
-- MECHANISM_NAME |
| 19122 |
-- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) |
| 19123 |
|
| 19124 |
-- MECHANISM_ASSOCIATION ::= |
| 19125 |
-- [formal_parameter_NAME =>] MECHANISM_NAME |
| 19126 |
|
| 19127 |
-- MECHANISM_NAME ::= |
| 19128 |
-- Value |
| 19129 |
-- | Reference |
| 19130 |
|
| 19131 |
when Pragma_Import_Function => Import_Function : declare |
| 19132 |
Args : Args_List (1 .. 6); |
| 19133 |
Names : constant Name_List (1 .. 6) := ( |
| 19134 |
Name_Internal, |
| 19135 |
Name_External, |
| 19136 |
Name_Parameter_Types, |
| 19137 |
Name_Result_Type, |
| 19138 |
Name_Mechanism, |
| 19139 |
Name_Result_Mechanism); |
| 19140 |
|
| 19141 |
Internal : Node_Id renames Args (1); |
| 19142 |
External : Node_Id renames Args (2); |
| 19143 |
Parameter_Types : Node_Id renames Args (3); |
| 19144 |
Result_Type : Node_Id renames Args (4); |
| 19145 |
Mechanism : Node_Id renames Args (5); |
| 19146 |
Result_Mechanism : Node_Id renames Args (6); |
| 19147 |
|
| 19148 |
begin |
| 19149 |
GNAT_Pragma; |
| 19150 |
Gather_Associations (Names, Args); |
| 19151 |
Process_Extended_Import_Export_Subprogram_Pragma ( |
| 19152 |
Arg_Internal => Internal, |
| 19153 |
Arg_External => External, |
| 19154 |
Arg_Parameter_Types => Parameter_Types, |
| 19155 |
Arg_Result_Type => Result_Type, |
| 19156 |
Arg_Mechanism => Mechanism, |
| 19157 |
Arg_Result_Mechanism => Result_Mechanism); |
| 19158 |
end Import_Function; |
| 19159 |
|
| 19160 |
------------------- |
| 19161 |
-- Import_Object -- |
| 19162 |
------------------- |
| 19163 |
|
| 19164 |
-- pragma Import_Object ( |
| 19165 |
-- [Internal =>] LOCAL_NAME |
| 19166 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 19167 |
-- [, [Size =>] EXTERNAL_SYMBOL]); |
| 19168 |
|
| 19169 |
-- EXTERNAL_SYMBOL ::= |
| 19170 |
-- IDENTIFIER |
| 19171 |
-- | static_string_EXPRESSION |
| 19172 |
|
| 19173 |
when Pragma_Import_Object => Import_Object : declare |
| 19174 |
Args : Args_List (1 .. 3); |
| 19175 |
Names : constant Name_List (1 .. 3) := ( |
| 19176 |
Name_Internal, |
| 19177 |
Name_External, |
| 19178 |
Name_Size); |
| 19179 |
|
| 19180 |
Internal : Node_Id renames Args (1); |
| 19181 |
External : Node_Id renames Args (2); |
| 19182 |
Size : Node_Id renames Args (3); |
| 19183 |
|
| 19184 |
begin |
| 19185 |
GNAT_Pragma; |
| 19186 |
Gather_Associations (Names, Args); |
| 19187 |
Process_Extended_Import_Export_Object_Pragma ( |
| 19188 |
Arg_Internal => Internal, |
| 19189 |
Arg_External => External, |
| 19190 |
Arg_Size => Size); |
| 19191 |
end Import_Object; |
| 19192 |
|
| 19193 |
---------------------- |
| 19194 |
-- Import_Procedure -- |
| 19195 |
---------------------- |
| 19196 |
|
| 19197 |
-- pragma Import_Procedure ( |
| 19198 |
-- [Internal =>] LOCAL_NAME |
| 19199 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 19200 |
-- [, [Parameter_Types =>] (PARAMETER_TYPES)] |
| 19201 |
-- [, [Mechanism =>] MECHANISM]); |
| 19202 |
|
| 19203 |
-- EXTERNAL_SYMBOL ::= |
| 19204 |
-- IDENTIFIER |
| 19205 |
-- | static_string_EXPRESSION |
| 19206 |
|
| 19207 |
-- PARAMETER_TYPES ::= |
| 19208 |
-- null |
| 19209 |
-- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} |
| 19210 |
|
| 19211 |
-- TYPE_DESIGNATOR ::= |
| 19212 |
-- subtype_NAME |
| 19213 |
-- | subtype_Name ' Access |
| 19214 |
|
| 19215 |
-- MECHANISM ::= |
| 19216 |
-- MECHANISM_NAME |
| 19217 |
-- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) |
| 19218 |
|
| 19219 |
-- MECHANISM_ASSOCIATION ::= |
| 19220 |
-- [formal_parameter_NAME =>] MECHANISM_NAME |
| 19221 |
|
| 19222 |
-- MECHANISM_NAME ::= |
| 19223 |
-- Value |
| 19224 |
-- | Reference |
| 19225 |
|
| 19226 |
when Pragma_Import_Procedure => Import_Procedure : declare |
| 19227 |
Args : Args_List (1 .. 4); |
| 19228 |
Names : constant Name_List (1 .. 4) := ( |
| 19229 |
Name_Internal, |
| 19230 |
Name_External, |
| 19231 |
Name_Parameter_Types, |
| 19232 |
Name_Mechanism); |
| 19233 |
|
| 19234 |
Internal : Node_Id renames Args (1); |
| 19235 |
External : Node_Id renames Args (2); |
| 19236 |
Parameter_Types : Node_Id renames Args (3); |
| 19237 |
Mechanism : Node_Id renames Args (4); |
| 19238 |
|
| 19239 |
begin |
| 19240 |
GNAT_Pragma; |
| 19241 |
Gather_Associations (Names, Args); |
| 19242 |
Process_Extended_Import_Export_Subprogram_Pragma ( |
| 19243 |
Arg_Internal => Internal, |
| 19244 |
Arg_External => External, |
| 19245 |
Arg_Parameter_Types => Parameter_Types, |
| 19246 |
Arg_Mechanism => Mechanism); |
| 19247 |
end Import_Procedure; |
| 19248 |
|
| 19249 |
----------------------------- |
| 19250 |
-- Import_Valued_Procedure -- |
| 19251 |
----------------------------- |
| 19252 |
|
| 19253 |
-- pragma Import_Valued_Procedure ( |
| 19254 |
-- [Internal =>] LOCAL_NAME |
| 19255 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 19256 |
-- [, [Parameter_Types =>] (PARAMETER_TYPES)] |
| 19257 |
-- [, [Mechanism =>] MECHANISM]); |
| 19258 |
|
| 19259 |
-- EXTERNAL_SYMBOL ::= |
| 19260 |
-- IDENTIFIER |
| 19261 |
-- | static_string_EXPRESSION |
| 19262 |
|
| 19263 |
-- PARAMETER_TYPES ::= |
| 19264 |
-- null |
| 19265 |
-- | TYPE_DESIGNATOR @{, TYPE_DESIGNATOR@} |
| 19266 |
|
| 19267 |
-- TYPE_DESIGNATOR ::= |
| 19268 |
-- subtype_NAME |
| 19269 |
-- | subtype_Name ' Access |
| 19270 |
|
| 19271 |
-- MECHANISM ::= |
| 19272 |
-- MECHANISM_NAME |
| 19273 |
-- | (MECHANISM_ASSOCIATION @{, MECHANISM_ASSOCIATION@}) |
| 19274 |
|
| 19275 |
-- MECHANISM_ASSOCIATION ::= |
| 19276 |
-- [formal_parameter_NAME =>] MECHANISM_NAME |
| 19277 |
|
| 19278 |
-- MECHANISM_NAME ::= |
| 19279 |
-- Value |
| 19280 |
-- | Reference |
| 19281 |
|
| 19282 |
when Pragma_Import_Valued_Procedure => |
| 19283 |
Import_Valued_Procedure : declare |
| 19284 |
Args : Args_List (1 .. 4); |
| 19285 |
Names : constant Name_List (1 .. 4) := ( |
| 19286 |
Name_Internal, |
| 19287 |
Name_External, |
| 19288 |
Name_Parameter_Types, |
| 19289 |
Name_Mechanism); |
| 19290 |
|
| 19291 |
Internal : Node_Id renames Args (1); |
| 19292 |
External : Node_Id renames Args (2); |
| 19293 |
Parameter_Types : Node_Id renames Args (3); |
| 19294 |
Mechanism : Node_Id renames Args (4); |
| 19295 |
|
| 19296 |
begin |
| 19297 |
GNAT_Pragma; |
| 19298 |
Gather_Associations (Names, Args); |
| 19299 |
Process_Extended_Import_Export_Subprogram_Pragma ( |
| 19300 |
Arg_Internal => Internal, |
| 19301 |
Arg_External => External, |
| 19302 |
Arg_Parameter_Types => Parameter_Types, |
| 19303 |
Arg_Mechanism => Mechanism); |
| 19304 |
end Import_Valued_Procedure; |
| 19305 |
|
| 19306 |
----------------- |
| 19307 |
-- Independent -- |
| 19308 |
----------------- |
| 19309 |
|
| 19310 |
-- pragma Independent (LOCAL_NAME); |
| 19311 |
|
| 19312 |
when Pragma_Independent => |
| 19313 |
Process_Atomic_Independent_Shared_Volatile; |
| 19314 |
|
| 19315 |
---------------------------- |
| 19316 |
-- Independent_Components -- |
| 19317 |
---------------------------- |
| 19318 |
|
| 19319 |
-- pragma Independent_Components (array_or_record_LOCAL_NAME); |
| 19320 |
|
| 19321 |
when Pragma_Independent_Components => Independent_Components : declare |
| 19322 |
C : Node_Id; |
| 19323 |
D : Node_Id; |
| 19324 |
E_Id : Node_Id; |
| 19325 |
E : Entity_Id; |
| 19326 |
|
| 19327 |
begin |
| 19328 |
Check_Ada_83_Warning; |
| 19329 |
Ada_2012_Pragma; |
| 19330 |
Check_No_Identifiers; |
| 19331 |
Check_Arg_Count (1); |
| 19332 |
Check_Arg_Is_Local_Name (Arg1); |
| 19333 |
E_Id := Get_Pragma_Arg (Arg1); |
| 19334 |
|
| 19335 |
if Etype (E_Id) = Any_Type then |
| 19336 |
return; |
| 19337 |
end if; |
| 19338 |
|
| 19339 |
E := Entity (E_Id); |
| 19340 |
|
| 19341 |
-- A record type with a self-referential component of anonymous |
| 19342 |
-- access type is given an incomplete view in order to handle the |
| 19343 |
-- self reference: |
| 19344 |
-- |
| 19345 |
-- type Rec is record |
| 19346 |
-- Self : access Rec; |
| 19347 |
-- end record; |
| 19348 |
-- |
| 19349 |
-- becomes |
| 19350 |
-- |
| 19351 |
-- type Rec; |
| 19352 |
-- type Ptr is access Rec; |
| 19353 |
-- type Rec is record |
| 19354 |
-- Self : Ptr; |
| 19355 |
-- end record; |
| 19356 |
-- |
| 19357 |
-- Since the incomplete view is now the initial view of the type, |
| 19358 |
-- the argument of the pragma will reference the incomplete view, |
| 19359 |
-- but this view is illegal according to the semantics of the |
| 19360 |
-- pragma. |
| 19361 |
-- |
| 19362 |
-- Obtain the full view of an internally-generated incomplete type |
| 19363 |
-- only. This way an attempt to associate the pragma with a source |
| 19364 |
-- incomplete type is still caught. |
| 19365 |
|
| 19366 |
if Ekind (E) = E_Incomplete_Type |
| 19367 |
and then not Comes_From_Source (E) |
| 19368 |
and then Present (Full_View (E)) |
| 19369 |
then |
| 19370 |
E := Full_View (E); |
| 19371 |
end if; |
| 19372 |
|
| 19373 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 19374 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 19375 |
|
| 19376 |
Mark_Ghost_Pragma (N, E); |
| 19377 |
|
| 19378 |
-- Check duplicate before we chain ourselves |
| 19379 |
|
| 19380 |
Check_Duplicate_Pragma (E); |
| 19381 |
|
| 19382 |
-- Check appropriate entity |
| 19383 |
|
| 19384 |
if Rep_Item_Too_Early (E, N) |
| 19385 |
or else |
| 19386 |
Rep_Item_Too_Late (E, N) |
| 19387 |
then |
| 19388 |
return; |
| 19389 |
end if; |
| 19390 |
|
| 19391 |
D := Declaration_Node (E); |
| 19392 |
|
| 19393 |
-- The flag is set on the base type, or on the object |
| 19394 |
|
| 19395 |
if Nkind (D) = N_Full_Type_Declaration |
| 19396 |
and then (Is_Array_Type (E) or else Is_Record_Type (E)) |
| 19397 |
then |
| 19398 |
Set_Has_Independent_Components (Base_Type (E)); |
| 19399 |
Record_Independence_Check (N, Base_Type (E)); |
| 19400 |
|
| 19401 |
-- For record type, set all components independent |
| 19402 |
|
| 19403 |
if Is_Record_Type (E) then |
| 19404 |
C := First_Component (E); |
| 19405 |
while Present (C) loop |
| 19406 |
Set_Is_Independent (C); |
| 19407 |
Next_Component (C); |
| 19408 |
end loop; |
| 19409 |
end if; |
| 19410 |
|
| 19411 |
elsif (Ekind (E) = E_Constant or else Ekind (E) = E_Variable) |
| 19412 |
and then Nkind (D) = N_Object_Declaration |
| 19413 |
and then Nkind (Object_Definition (D)) = |
| 19414 |
N_Constrained_Array_Definition |
| 19415 |
then |
| 19416 |
Set_Has_Independent_Components (E); |
| 19417 |
Record_Independence_Check (N, E); |
| 19418 |
|
| 19419 |
else |
| 19420 |
Error_Pragma_Arg ("inappropriate entity for pragma%", Arg1); |
| 19421 |
end if; |
| 19422 |
end Independent_Components; |
| 19423 |
|
| 19424 |
----------------------- |
| 19425 |
-- Initial_Condition -- |
| 19426 |
----------------------- |
| 19427 |
|
| 19428 |
-- pragma Initial_Condition (boolean_EXPRESSION); |
| 19429 |
|
| 19430 |
-- Characteristics: |
| 19431 |
|
| 19432 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 19433 |
-- the legal placement and context. Secondary checks preanalyze the |
| 19434 |
-- expression in: |
| 19435 |
|
| 19436 |
-- Analyze_Initial_Condition_In_Decl_Part |
| 19437 |
|
| 19438 |
-- * Expansion - The annotation is expanded during the expansion of |
| 19439 |
-- the package body whose declaration is subject to the annotation |
| 19440 |
-- as done in: |
| 19441 |
|
| 19442 |
-- Expand_Pragma_Initial_Condition |
| 19443 |
|
| 19444 |
-- * Template - The annotation utilizes the generic template of the |
| 19445 |
-- related package declaration. |
| 19446 |
|
| 19447 |
-- * Globals - Capture of global references must occur after full |
| 19448 |
-- analysis. |
| 19449 |
|
| 19450 |
-- * Instance - The annotation is instantiated automatically when |
| 19451 |
-- the related generic package is instantiated. |
| 19452 |
|
| 19453 |
when Pragma_Initial_Condition => Initial_Condition : declare |
| 19454 |
Pack_Decl : Node_Id; |
| 19455 |
Pack_Id : Entity_Id; |
| 19456 |
|
| 19457 |
begin |
| 19458 |
GNAT_Pragma; |
| 19459 |
Check_No_Identifiers; |
| 19460 |
Check_Arg_Count (1); |
| 19461 |
|
| 19462 |
Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
| 19463 |
|
| 19464 |
if Nkind (Pack_Decl) not in |
| 19465 |
N_Generic_Package_Declaration | N_Package_Declaration |
| 19466 |
then |
| 19467 |
Pragma_Misplaced; |
| 19468 |
end if; |
| 19469 |
|
| 19470 |
Pack_Id := Defining_Entity (Pack_Decl); |
| 19471 |
|
| 19472 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 19473 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 19474 |
|
| 19475 |
Mark_Ghost_Pragma (N, Pack_Id); |
| 19476 |
|
| 19477 |
-- Chain the pragma on the contract for further processing by |
| 19478 |
-- Analyze_Initial_Condition_In_Decl_Part. |
| 19479 |
|
| 19480 |
Add_Contract_Item (N, Pack_Id); |
| 19481 |
|
| 19482 |
-- The legality checks of pragmas Abstract_State, Initializes, and |
| 19483 |
-- Initial_Condition are affected by the SPARK mode in effect. In |
| 19484 |
-- addition, these three pragmas are subject to an inherent order: |
| 19485 |
|
| 19486 |
-- 1) Abstract_State |
| 19487 |
-- 2) Initializes |
| 19488 |
-- 3) Initial_Condition |
| 19489 |
|
| 19490 |
-- Analyze all these pragmas in the order outlined above |
| 19491 |
|
| 19492 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 19493 |
Analyze_If_Present (Pragma_Abstract_State); |
| 19494 |
Analyze_If_Present (Pragma_Initializes); |
| 19495 |
end Initial_Condition; |
| 19496 |
|
| 19497 |
------------------------ |
| 19498 |
-- Initialize_Scalars -- |
| 19499 |
------------------------ |
| 19500 |
|
| 19501 |
-- pragma Initialize_Scalars |
| 19502 |
-- [ ( TYPE_VALUE_PAIR {, TYPE_VALUE_PAIR} ) ]; |
| 19503 |
|
| 19504 |
-- TYPE_VALUE_PAIR ::= |
| 19505 |
-- SCALAR_TYPE => static_EXPRESSION |
| 19506 |
|
| 19507 |
-- SCALAR_TYPE := |
| 19508 |
-- Short_Float |
| 19509 |
-- | Float |
| 19510 |
-- | Long_Float |
| 19511 |
-- | Long_Long_Float |
| 19512 |
-- | Signed_8 |
| 19513 |
-- | Signed_16 |
| 19514 |
-- | Signed_32 |
| 19515 |
-- | Signed_64 |
| 19516 |
-- | Signed_128 |
| 19517 |
-- | Unsigned_8 |
| 19518 |
-- | Unsigned_16 |
| 19519 |
-- | Unsigned_32 |
| 19520 |
-- | Unsigned_64 |
| 19521 |
-- | Unsigned_128 |
| 19522 |
|
| 19523 |
when Pragma_Initialize_Scalars => Do_Initialize_Scalars : declare |
| 19524 |
Seen : array (Scalar_Id) of Node_Id := (others => Empty); |
| 19525 |
-- This collection holds the individual pairs which specify the |
| 19526 |
-- invalid values of their respective scalar types. |
| 19527 |
|
| 19528 |
procedure Analyze_Float_Value |
| 19529 |
(Scal_Typ : Float_Scalar_Id; |
| 19530 |
Val_Expr : Node_Id); |
| 19531 |
-- Analyze a type value pair associated with float type Scal_Typ |
| 19532 |
-- and expression Val_Expr. |
| 19533 |
|
| 19534 |
procedure Analyze_Integer_Value |
| 19535 |
(Scal_Typ : Integer_Scalar_Id; |
| 19536 |
Val_Expr : Node_Id); |
| 19537 |
-- Analyze a type value pair associated with integer type Scal_Typ |
| 19538 |
-- and expression Val_Expr. |
| 19539 |
|
| 19540 |
procedure Analyze_Type_Value_Pair (Pair : Node_Id); |
| 19541 |
-- Analyze type value pair Pair |
| 19542 |
|
| 19543 |
------------------------- |
| 19544 |
-- Analyze_Float_Value -- |
| 19545 |
------------------------- |
| 19546 |
|
| 19547 |
procedure Analyze_Float_Value |
| 19548 |
(Scal_Typ : Float_Scalar_Id; |
| 19549 |
Val_Expr : Node_Id) |
| 19550 |
is |
| 19551 |
begin |
| 19552 |
Analyze_And_Resolve (Val_Expr, Any_Real); |
| 19553 |
|
| 19554 |
if Is_OK_Static_Expression (Val_Expr) then |
| 19555 |
Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value_R (Val_Expr)); |
| 19556 |
|
| 19557 |
else |
| 19558 |
Error_Msg_Name_1 := Scal_Typ; |
| 19559 |
Error_Msg_N ("value for type % must be static", Val_Expr); |
| 19560 |
end if; |
| 19561 |
end Analyze_Float_Value; |
| 19562 |
|
| 19563 |
--------------------------- |
| 19564 |
-- Analyze_Integer_Value -- |
| 19565 |
--------------------------- |
| 19566 |
|
| 19567 |
procedure Analyze_Integer_Value |
| 19568 |
(Scal_Typ : Integer_Scalar_Id; |
| 19569 |
Val_Expr : Node_Id) |
| 19570 |
is |
| 19571 |
begin |
| 19572 |
Analyze_And_Resolve (Val_Expr, Any_Integer); |
| 19573 |
|
| 19574 |
if (Scal_Typ = Name_Signed_128 |
| 19575 |
or else Scal_Typ = Name_Unsigned_128) |
| 19576 |
and then Ttypes.System_Max_Integer_Size < 128 |
| 19577 |
then |
| 19578 |
Error_Msg_Name_1 := Scal_Typ; |
| 19579 |
Error_Msg_N ("value cannot be set for type %", Val_Expr); |
| 19580 |
|
| 19581 |
elsif Is_OK_Static_Expression (Val_Expr) then |
| 19582 |
Set_Invalid_Scalar_Value (Scal_Typ, Expr_Value (Val_Expr)); |
| 19583 |
|
| 19584 |
else |
| 19585 |
Error_Msg_Name_1 := Scal_Typ; |
| 19586 |
Error_Msg_N ("value for type % must be static", Val_Expr); |
| 19587 |
end if; |
| 19588 |
end Analyze_Integer_Value; |
| 19589 |
|
| 19590 |
----------------------------- |
| 19591 |
-- Analyze_Type_Value_Pair -- |
| 19592 |
----------------------------- |
| 19593 |
|
| 19594 |
procedure Analyze_Type_Value_Pair (Pair : Node_Id) is |
| 19595 |
Scal_Typ : constant Name_Id := Chars (Pair); |
| 19596 |
Val_Expr : constant Node_Id := Expression (Pair); |
| 19597 |
Prev_Pair : Node_Id; |
| 19598 |
|
| 19599 |
begin |
| 19600 |
if Scal_Typ in Scalar_Id then |
| 19601 |
Prev_Pair := Seen (Scal_Typ); |
| 19602 |
|
| 19603 |
-- Prevent multiple attempts to set a value for a scalar |
| 19604 |
-- type. |
| 19605 |
|
| 19606 |
if Present (Prev_Pair) then |
| 19607 |
Error_Msg_Name_1 := Scal_Typ; |
| 19608 |
Error_Msg_N |
| 19609 |
("cannot specify multiple invalid values for type %", |
| 19610 |
Pair); |
| 19611 |
|
| 19612 |
Error_Msg_Sloc := Sloc (Prev_Pair); |
| 19613 |
Error_Msg_N ("previous value set #", Pair); |
| 19614 |
|
| 19615 |
-- Ignore the effects of the pair, but do not halt the |
| 19616 |
-- analysis of the pragma altogether. |
| 19617 |
|
| 19618 |
return; |
| 19619 |
|
| 19620 |
-- Otherwise capture the first pair for this scalar type |
| 19621 |
|
| 19622 |
else |
| 19623 |
Seen (Scal_Typ) := Pair; |
| 19624 |
end if; |
| 19625 |
|
| 19626 |
if Scal_Typ in Float_Scalar_Id then |
| 19627 |
Analyze_Float_Value (Scal_Typ, Val_Expr); |
| 19628 |
|
| 19629 |
else pragma Assert (Scal_Typ in Integer_Scalar_Id); |
| 19630 |
Analyze_Integer_Value (Scal_Typ, Val_Expr); |
| 19631 |
end if; |
| 19632 |
|
| 19633 |
-- Otherwise the scalar family is illegal |
| 19634 |
|
| 19635 |
else |
| 19636 |
Error_Msg_Name_1 := Pname; |
| 19637 |
Error_Msg_N |
| 19638 |
("argument of pragma % must denote valid scalar family", |
| 19639 |
Pair); |
| 19640 |
end if; |
| 19641 |
end Analyze_Type_Value_Pair; |
| 19642 |
|
| 19643 |
-- Local variables |
| 19644 |
|
| 19645 |
Pairs : constant List_Id := Pragma_Argument_Associations (N); |
| 19646 |
Pair : Node_Id; |
| 19647 |
|
| 19648 |
-- Start of processing for Do_Initialize_Scalars |
| 19649 |
|
| 19650 |
begin |
| 19651 |
GNAT_Pragma; |
| 19652 |
Check_Valid_Configuration_Pragma; |
| 19653 |
Check_Restriction (No_Initialize_Scalars, N); |
| 19654 |
|
| 19655 |
-- Ignore the effects of the pragma when No_Initialize_Scalars is |
| 19656 |
-- in effect. |
| 19657 |
|
| 19658 |
if Restriction_Active (No_Initialize_Scalars) then |
| 19659 |
null; |
| 19660 |
|
| 19661 |
-- Initialize_Scalars creates false positives in CodePeer, and |
| 19662 |
-- incorrect negative results in GNATprove mode, so ignore this |
| 19663 |
-- pragma in these modes. |
| 19664 |
|
| 19665 |
elsif CodePeer_Mode or GNATprove_Mode then |
| 19666 |
null; |
| 19667 |
|
| 19668 |
-- Otherwise analyze the pragma |
| 19669 |
|
| 19670 |
else |
| 19671 |
if Present (Pairs) then |
| 19672 |
|
| 19673 |
-- Install Standard in order to provide access to primitive |
| 19674 |
-- types in case the expressions contain attributes such as |
| 19675 |
-- Integer'Last. |
| 19676 |
|
| 19677 |
Push_Scope (Standard_Standard); |
| 19678 |
|
| 19679 |
Pair := First (Pairs); |
| 19680 |
while Present (Pair) loop |
| 19681 |
Analyze_Type_Value_Pair (Pair); |
| 19682 |
Next (Pair); |
| 19683 |
end loop; |
| 19684 |
|
| 19685 |
-- Remove Standard |
| 19686 |
|
| 19687 |
Pop_Scope; |
| 19688 |
end if; |
| 19689 |
|
| 19690 |
Init_Or_Norm_Scalars := True; |
| 19691 |
Initialize_Scalars := True; |
| 19692 |
end if; |
| 19693 |
end Do_Initialize_Scalars; |
| 19694 |
|
| 19695 |
----------------- |
| 19696 |
-- Initializes -- |
| 19697 |
----------------- |
| 19698 |
|
| 19699 |
-- pragma Initializes (INITIALIZATION_LIST); |
| 19700 |
|
| 19701 |
-- INITIALIZATION_LIST ::= |
| 19702 |
-- null |
| 19703 |
-- | (INITIALIZATION_ITEM {, INITIALIZATION_ITEM}) |
| 19704 |
|
| 19705 |
-- INITIALIZATION_ITEM ::= name [=> INPUT_LIST] |
| 19706 |
|
| 19707 |
-- INPUT_LIST ::= |
| 19708 |
-- null |
| 19709 |
-- | INPUT |
| 19710 |
-- | (INPUT {, INPUT}) |
| 19711 |
|
| 19712 |
-- INPUT ::= name |
| 19713 |
|
| 19714 |
-- Characteristics: |
| 19715 |
|
| 19716 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 19717 |
-- the legal placement and context. Secondary checks preanalyze the |
| 19718 |
-- expression in: |
| 19719 |
|
| 19720 |
-- Analyze_Initializes_In_Decl_Part |
| 19721 |
|
| 19722 |
-- * Expansion - None. |
| 19723 |
|
| 19724 |
-- * Template - The annotation utilizes the generic template of the |
| 19725 |
-- related package declaration. |
| 19726 |
|
| 19727 |
-- * Globals - Capture of global references must occur after full |
| 19728 |
-- analysis. |
| 19729 |
|
| 19730 |
-- * Instance - The annotation is instantiated automatically when |
| 19731 |
-- the related generic package is instantiated. |
| 19732 |
|
| 19733 |
when Pragma_Initializes => Initializes : declare |
| 19734 |
Pack_Decl : Node_Id; |
| 19735 |
Pack_Id : Entity_Id; |
| 19736 |
|
| 19737 |
begin |
| 19738 |
GNAT_Pragma; |
| 19739 |
Check_No_Identifiers; |
| 19740 |
Check_Arg_Count (1); |
| 19741 |
|
| 19742 |
Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
| 19743 |
|
| 19744 |
if Nkind (Pack_Decl) not in |
| 19745 |
N_Generic_Package_Declaration | N_Package_Declaration |
| 19746 |
then |
| 19747 |
Pragma_Misplaced; |
| 19748 |
end if; |
| 19749 |
|
| 19750 |
Pack_Id := Defining_Entity (Pack_Decl); |
| 19751 |
|
| 19752 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 19753 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 19754 |
|
| 19755 |
Mark_Ghost_Pragma (N, Pack_Id); |
| 19756 |
Ensure_Aggregate_Form (Get_Argument (N, Pack_Id)); |
| 19757 |
|
| 19758 |
-- Chain the pragma on the contract for further processing by |
| 19759 |
-- Analyze_Initializes_In_Decl_Part. |
| 19760 |
|
| 19761 |
Add_Contract_Item (N, Pack_Id); |
| 19762 |
|
| 19763 |
-- The legality checks of pragmas Abstract_State, Initializes, and |
| 19764 |
-- Initial_Condition are affected by the SPARK mode in effect. In |
| 19765 |
-- addition, these three pragmas are subject to an inherent order: |
| 19766 |
|
| 19767 |
-- 1) Abstract_State |
| 19768 |
-- 2) Initializes |
| 19769 |
-- 3) Initial_Condition |
| 19770 |
|
| 19771 |
-- Analyze all these pragmas in the order outlined above |
| 19772 |
|
| 19773 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 19774 |
Analyze_If_Present (Pragma_Abstract_State); |
| 19775 |
Analyze_If_Present (Pragma_Initial_Condition); |
| 19776 |
end Initializes; |
| 19777 |
|
| 19778 |
------------ |
| 19779 |
-- Inline -- |
| 19780 |
------------ |
| 19781 |
|
| 19782 |
-- pragma Inline ( NAME {, NAME} ); |
| 19783 |
|
| 19784 |
when Pragma_Inline => |
| 19785 |
|
| 19786 |
-- Pragma always active unless in GNATprove mode. It is disabled |
| 19787 |
-- in GNATprove mode because frontend inlining is applied |
| 19788 |
-- independently of pragmas Inline and Inline_Always for |
| 19789 |
-- formal verification, see Can_Be_Inlined_In_GNATprove_Mode |
| 19790 |
-- in inline.ads. |
| 19791 |
|
| 19792 |
if not GNATprove_Mode then |
| 19793 |
|
| 19794 |
-- Inline status is Enabled if option -gnatn is specified. |
| 19795 |
-- However this status determines only the value of the |
| 19796 |
-- Is_Inlined flag on the subprogram and does not prevent |
| 19797 |
-- the pragma itself from being recorded for later use, |
| 19798 |
-- in particular for a later modification of Is_Inlined |
| 19799 |
-- independently of the -gnatn option. |
| 19800 |
|
| 19801 |
-- In other words, if -gnatn is specified for a unit, then |
| 19802 |
-- all Inline pragmas processed for the compilation of this |
| 19803 |
-- unit, including those in the spec of other units, are |
| 19804 |
-- activated, so subprograms will be inlined across units. |
| 19805 |
|
| 19806 |
-- If -gnatn is not specified, no Inline pragma is activated |
| 19807 |
-- here, which means that subprograms will not be inlined |
| 19808 |
-- across units. The Is_Inlined flag will nevertheless be |
| 19809 |
-- set later when bodies are analyzed, so subprograms will |
| 19810 |
-- be inlined within the unit. |
| 19811 |
|
| 19812 |
if Inline_Active then |
| 19813 |
Process_Inline (Enabled); |
| 19814 |
else |
| 19815 |
Process_Inline (Disabled); |
| 19816 |
end if; |
| 19817 |
end if; |
| 19818 |
|
| 19819 |
------------------- |
| 19820 |
-- Inline_Always -- |
| 19821 |
------------------- |
| 19822 |
|
| 19823 |
-- pragma Inline_Always ( NAME {, NAME} ); |
| 19824 |
|
| 19825 |
when Pragma_Inline_Always => |
| 19826 |
GNAT_Pragma; |
| 19827 |
|
| 19828 |
-- Pragma always active unless in CodePeer mode or GNATprove |
| 19829 |
-- mode. It is disabled in CodePeer mode because inlining is |
| 19830 |
-- not helpful, and enabling it caused walk order issues. It |
| 19831 |
-- is disabled in GNATprove mode because frontend inlining is |
| 19832 |
-- applied independently of pragmas Inline and Inline_Always for |
| 19833 |
-- formal verification, see Can_Be_Inlined_In_GNATprove_Mode in |
| 19834 |
-- inline.ads. |
| 19835 |
|
| 19836 |
if not CodePeer_Mode and not GNATprove_Mode then |
| 19837 |
Process_Inline (Enabled); |
| 19838 |
end if; |
| 19839 |
|
| 19840 |
-------------------- |
| 19841 |
-- Inline_Generic -- |
| 19842 |
-------------------- |
| 19843 |
|
| 19844 |
-- pragma Inline_Generic (NAME {, NAME}); |
| 19845 |
|
| 19846 |
when Pragma_Inline_Generic => |
| 19847 |
GNAT_Pragma; |
| 19848 |
Process_Generic_List; |
| 19849 |
|
| 19850 |
---------------------- |
| 19851 |
-- Inspection_Point -- |
| 19852 |
---------------------- |
| 19853 |
|
| 19854 |
-- pragma Inspection_Point [(object_NAME {, object_NAME})]; |
| 19855 |
|
| 19856 |
when Pragma_Inspection_Point => Inspection_Point : declare |
| 19857 |
Arg : Node_Id; |
| 19858 |
Exp : Node_Id; |
| 19859 |
|
| 19860 |
begin |
| 19861 |
ip; |
| 19862 |
|
| 19863 |
if Arg_Count > 0 then |
| 19864 |
Arg := Arg1; |
| 19865 |
loop |
| 19866 |
Exp := Get_Pragma_Arg (Arg); |
| 19867 |
Analyze (Exp); |
| 19868 |
|
| 19869 |
if not Is_Entity_Name (Exp) |
| 19870 |
or else not Is_Object (Entity (Exp)) |
| 19871 |
then |
| 19872 |
Error_Pragma_Arg ("object name required", Arg); |
| 19873 |
end if; |
| 19874 |
|
| 19875 |
Next (Arg); |
| 19876 |
exit when No (Arg); |
| 19877 |
end loop; |
| 19878 |
end if; |
| 19879 |
end Inspection_Point; |
| 19880 |
|
| 19881 |
--------------- |
| 19882 |
-- Interface -- |
| 19883 |
--------------- |
| 19884 |
|
| 19885 |
-- pragma Interface ( |
| 19886 |
-- [ Convention =>] convention_IDENTIFIER, |
| 19887 |
-- [ Entity =>] LOCAL_NAME |
| 19888 |
-- [, [External_Name =>] static_string_EXPRESSION ] |
| 19889 |
-- [, [Link_Name =>] static_string_EXPRESSION ]); |
| 19890 |
|
| 19891 |
when Pragma_Interface => |
| 19892 |
GNAT_Pragma; |
| 19893 |
Check_Arg_Order |
| 19894 |
((Name_Convention, |
| 19895 |
Name_Entity, |
| 19896 |
Name_External_Name, |
| 19897 |
Name_Link_Name)); |
| 19898 |
Check_At_Least_N_Arguments (2); |
| 19899 |
Check_At_Most_N_Arguments (4); |
| 19900 |
Process_Import_Or_Interface; |
| 19901 |
|
| 19902 |
-- In Ada 2005, the permission to use Interface (a reserved word) |
| 19903 |
-- as a pragma name is considered an obsolescent feature, and this |
| 19904 |
-- pragma was already obsolescent in Ada 95. |
| 19905 |
|
| 19906 |
if Ada_Version >= Ada_95 then |
| 19907 |
Check_Restriction |
| 19908 |
(No_Obsolescent_Features, Pragma_Identifier (N)); |
| 19909 |
|
| 19910 |
if Warn_On_Obsolescent_Feature then |
| 19911 |
Error_Msg_N |
| 19912 |
("pragma Interface is an obsolescent feature?j?", N); |
| 19913 |
Error_Msg_N |
| 19914 |
("|use pragma Import instead?j?", N); |
| 19915 |
end if; |
| 19916 |
end if; |
| 19917 |
|
| 19918 |
-------------------- |
| 19919 |
-- Interface_Name -- |
| 19920 |
-------------------- |
| 19921 |
|
| 19922 |
-- pragma Interface_Name ( |
| 19923 |
-- [ Entity =>] LOCAL_NAME |
| 19924 |
-- [,[External_Name =>] static_string_EXPRESSION ] |
| 19925 |
-- [,[Link_Name =>] static_string_EXPRESSION ]); |
| 19926 |
|
| 19927 |
when Pragma_Interface_Name => Interface_Name : declare |
| 19928 |
Id : Node_Id; |
| 19929 |
Def_Id : Entity_Id; |
| 19930 |
Hom_Id : Entity_Id; |
| 19931 |
Found : Boolean; |
| 19932 |
|
| 19933 |
begin |
| 19934 |
GNAT_Pragma; |
| 19935 |
Check_Arg_Order |
| 19936 |
((Name_Entity, Name_External_Name, Name_Link_Name)); |
| 19937 |
Check_At_Least_N_Arguments (2); |
| 19938 |
Check_At_Most_N_Arguments (3); |
| 19939 |
Id := Get_Pragma_Arg (Arg1); |
| 19940 |
Analyze (Id); |
| 19941 |
|
| 19942 |
-- This is obsolete from Ada 95 on, but it is an implementation |
| 19943 |
-- defined pragma, so we do not consider that it violates the |
| 19944 |
-- restriction (No_Obsolescent_Features). |
| 19945 |
|
| 19946 |
if Ada_Version >= Ada_95 then |
| 19947 |
if Warn_On_Obsolescent_Feature then |
| 19948 |
Error_Msg_N |
| 19949 |
("pragma Interface_Name is an obsolescent feature?j?", N); |
| 19950 |
Error_Msg_N |
| 19951 |
("|use pragma Import instead?j?", N); |
| 19952 |
end if; |
| 19953 |
end if; |
| 19954 |
|
| 19955 |
if not Is_Entity_Name (Id) then |
| 19956 |
Error_Pragma_Arg |
| 19957 |
("first argument for pragma% must be entity name", Arg1); |
| 19958 |
elsif Etype (Id) = Any_Type then |
| 19959 |
return; |
| 19960 |
else |
| 19961 |
Def_Id := Entity (Id); |
| 19962 |
end if; |
| 19963 |
|
| 19964 |
-- Special DEC-compatible processing for the object case, forces |
| 19965 |
-- object to be imported. |
| 19966 |
|
| 19967 |
if Ekind (Def_Id) = E_Variable then |
| 19968 |
Kill_Size_Check_Code (Def_Id); |
| 19969 |
Note_Possible_Modification (Id, Sure => False); |
| 19970 |
|
| 19971 |
-- Initialization is not allowed for imported variable |
| 19972 |
|
| 19973 |
if Present (Expression (Parent (Def_Id))) |
| 19974 |
and then Comes_From_Source (Expression (Parent (Def_Id))) |
| 19975 |
then |
| 19976 |
Error_Msg_Sloc := Sloc (Def_Id); |
| 19977 |
Error_Pragma_Arg |
| 19978 |
("no initialization allowed for declaration of& #", |
| 19979 |
Arg2); |
| 19980 |
|
| 19981 |
else |
| 19982 |
-- For compatibility, support VADS usage of providing both |
| 19983 |
-- pragmas Interface and Interface_Name to obtain the effect |
| 19984 |
-- of a single Import pragma. |
| 19985 |
|
| 19986 |
if Is_Imported (Def_Id) |
| 19987 |
and then Present (First_Rep_Item (Def_Id)) |
| 19988 |
and then Nkind (First_Rep_Item (Def_Id)) = N_Pragma |
| 19989 |
and then Pragma_Name (First_Rep_Item (Def_Id)) = |
| 19990 |
Name_Interface |
| 19991 |
then |
| 19992 |
null; |
| 19993 |
else |
| 19994 |
Set_Imported (Def_Id); |
| 19995 |
end if; |
| 19996 |
|
| 19997 |
Set_Is_Public (Def_Id); |
| 19998 |
Process_Interface_Name (Def_Id, Arg2, Arg3, N); |
| 19999 |
end if; |
| 20000 |
|
| 20001 |
-- Otherwise must be subprogram |
| 20002 |
|
| 20003 |
elsif not Is_Subprogram (Def_Id) then |
| 20004 |
Error_Pragma_Arg |
| 20005 |
("argument of pragma% is not subprogram", Arg1); |
| 20006 |
|
| 20007 |
else |
| 20008 |
Check_At_Most_N_Arguments (3); |
| 20009 |
Hom_Id := Def_Id; |
| 20010 |
Found := False; |
| 20011 |
|
| 20012 |
-- Loop through homonyms |
| 20013 |
|
| 20014 |
loop |
| 20015 |
Def_Id := Get_Base_Subprogram (Hom_Id); |
| 20016 |
|
| 20017 |
if Is_Imported (Def_Id) then |
| 20018 |
Process_Interface_Name (Def_Id, Arg2, Arg3, N); |
| 20019 |
Found := True; |
| 20020 |
end if; |
| 20021 |
|
| 20022 |
exit when From_Aspect_Specification (N); |
| 20023 |
Hom_Id := Homonym (Hom_Id); |
| 20024 |
|
| 20025 |
exit when No (Hom_Id) |
| 20026 |
or else Scope (Hom_Id) /= Current_Scope; |
| 20027 |
end loop; |
| 20028 |
|
| 20029 |
if not Found then |
| 20030 |
Error_Pragma_Arg |
| 20031 |
("argument of pragma% is not imported subprogram", |
| 20032 |
Arg1); |
| 20033 |
end if; |
| 20034 |
end if; |
| 20035 |
end Interface_Name; |
| 20036 |
|
| 20037 |
----------------------- |
| 20038 |
-- Interrupt_Handler -- |
| 20039 |
----------------------- |
| 20040 |
|
| 20041 |
-- pragma Interrupt_Handler (handler_NAME); |
| 20042 |
|
| 20043 |
when Pragma_Interrupt_Handler => |
| 20044 |
Check_Ada_83_Warning; |
| 20045 |
Check_Arg_Count (1); |
| 20046 |
Check_No_Identifiers; |
| 20047 |
|
| 20048 |
if No_Run_Time_Mode then |
| 20049 |
Error_Msg_CRT ("Interrupt_Handler pragma", N); |
| 20050 |
else |
| 20051 |
Check_Interrupt_Or_Attach_Handler; |
| 20052 |
Process_Interrupt_Or_Attach_Handler; |
| 20053 |
end if; |
| 20054 |
|
| 20055 |
------------------------ |
| 20056 |
-- Interrupt_Priority -- |
| 20057 |
------------------------ |
| 20058 |
|
| 20059 |
-- pragma Interrupt_Priority [(EXPRESSION)]; |
| 20060 |
|
| 20061 |
when Pragma_Interrupt_Priority => Interrupt_Priority : declare |
| 20062 |
P : constant Node_Id := Parent (N); |
| 20063 |
Arg : Node_Id; |
| 20064 |
Ent : Entity_Id; |
| 20065 |
|
| 20066 |
begin |
| 20067 |
Check_Ada_83_Warning; |
| 20068 |
|
| 20069 |
if Arg_Count /= 0 then |
| 20070 |
Arg := Get_Pragma_Arg (Arg1); |
| 20071 |
Check_Arg_Count (1); |
| 20072 |
Check_No_Identifiers; |
| 20073 |
|
| 20074 |
-- The expression must be analyzed in the special manner |
| 20075 |
-- described in "Handling of Default and Per-Object |
| 20076 |
-- Expressions" in sem.ads. |
| 20077 |
|
| 20078 |
Preanalyze_Spec_Expression (Arg, RTE (RE_Interrupt_Priority)); |
| 20079 |
end if; |
| 20080 |
|
| 20081 |
if Nkind (P) not in N_Task_Definition | N_Protected_Definition then |
| 20082 |
Pragma_Misplaced; |
| 20083 |
|
| 20084 |
else |
| 20085 |
Ent := Defining_Identifier (Parent (P)); |
| 20086 |
|
| 20087 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 20088 |
-- Item chain of Ent. |
| 20089 |
|
| 20090 |
Check_Duplicate_Pragma (Ent); |
| 20091 |
Record_Rep_Item (Ent, N); |
| 20092 |
|
| 20093 |
-- Check the No_Task_At_Interrupt_Priority restriction |
| 20094 |
|
| 20095 |
if Nkind (P) = N_Task_Definition then |
| 20096 |
Check_Restriction (No_Task_At_Interrupt_Priority, N); |
| 20097 |
end if; |
| 20098 |
end if; |
| 20099 |
end Interrupt_Priority; |
| 20100 |
|
| 20101 |
--------------------- |
| 20102 |
-- Interrupt_State -- |
| 20103 |
--------------------- |
| 20104 |
|
| 20105 |
-- pragma Interrupt_State ( |
| 20106 |
-- [Name =>] INTERRUPT_ID, |
| 20107 |
-- [State =>] INTERRUPT_STATE); |
| 20108 |
|
| 20109 |
-- INTERRUPT_ID => IDENTIFIER | static_integer_EXPRESSION |
| 20110 |
-- INTERRUPT_STATE => System | Runtime | User |
| 20111 |
|
| 20112 |
-- Note: if the interrupt id is given as an identifier, then it must |
| 20113 |
-- be one of the identifiers in Ada.Interrupts.Names. Otherwise it is |
| 20114 |
-- given as a static integer expression which must be in the range of |
| 20115 |
-- Ada.Interrupts.Interrupt_ID. |
| 20116 |
|
| 20117 |
when Pragma_Interrupt_State => Interrupt_State : declare |
| 20118 |
Int_Id : constant Entity_Id := RTE (RE_Interrupt_ID); |
| 20119 |
-- This is the entity Ada.Interrupts.Interrupt_ID; |
| 20120 |
|
| 20121 |
State_Type : Character; |
| 20122 |
-- Set to 's'/'r'/'u' for System/Runtime/User |
| 20123 |
|
| 20124 |
IST_Num : Pos; |
| 20125 |
-- Index to entry in Interrupt_States table |
| 20126 |
|
| 20127 |
Int_Val : Uint; |
| 20128 |
-- Value of interrupt |
| 20129 |
|
| 20130 |
Arg1X : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 20131 |
-- The first argument to the pragma |
| 20132 |
|
| 20133 |
Int_Ent : Entity_Id; |
| 20134 |
-- Interrupt entity in Ada.Interrupts.Names |
| 20135 |
|
| 20136 |
begin |
| 20137 |
GNAT_Pragma; |
| 20138 |
Check_Arg_Order ((Name_Name, Name_State)); |
| 20139 |
Check_Arg_Count (2); |
| 20140 |
|
| 20141 |
Check_Optional_Identifier (Arg1, Name_Name); |
| 20142 |
Check_Optional_Identifier (Arg2, Name_State); |
| 20143 |
Check_Arg_Is_Identifier (Arg2); |
| 20144 |
|
| 20145 |
-- First argument is identifier |
| 20146 |
|
| 20147 |
if Nkind (Arg1X) = N_Identifier then |
| 20148 |
|
| 20149 |
-- Search list of names in Ada.Interrupts.Names |
| 20150 |
|
| 20151 |
Int_Ent := First_Entity (RTE (RE_Names)); |
| 20152 |
loop |
| 20153 |
if No (Int_Ent) then |
| 20154 |
Error_Pragma_Arg ("invalid interrupt name", Arg1); |
| 20155 |
|
| 20156 |
elsif Chars (Int_Ent) = Chars (Arg1X) then |
| 20157 |
Int_Val := Expr_Value (Constant_Value (Int_Ent)); |
| 20158 |
exit; |
| 20159 |
end if; |
| 20160 |
|
| 20161 |
Next_Entity (Int_Ent); |
| 20162 |
end loop; |
| 20163 |
|
| 20164 |
-- First argument is not an identifier, so it must be a static |
| 20165 |
-- expression of type Ada.Interrupts.Interrupt_ID. |
| 20166 |
|
| 20167 |
else |
| 20168 |
Check_Arg_Is_OK_Static_Expression (Arg1, Any_Integer); |
| 20169 |
Int_Val := Expr_Value (Arg1X); |
| 20170 |
|
| 20171 |
if Int_Val < Expr_Value (Type_Low_Bound (Int_Id)) |
| 20172 |
or else |
| 20173 |
Int_Val > Expr_Value (Type_High_Bound (Int_Id)) |
| 20174 |
then |
| 20175 |
Error_Pragma_Arg |
| 20176 |
("value not in range of type " |
| 20177 |
& """Ada.Interrupts.Interrupt_'I'D""", Arg1); |
| 20178 |
end if; |
| 20179 |
end if; |
| 20180 |
|
| 20181 |
-- Check OK state |
| 20182 |
|
| 20183 |
case Chars (Get_Pragma_Arg (Arg2)) is |
| 20184 |
when Name_Runtime => State_Type := 'r'; |
| 20185 |
when Name_System => State_Type := 's'; |
| 20186 |
when Name_User => State_Type := 'u'; |
| 20187 |
|
| 20188 |
when others => |
| 20189 |
Error_Pragma_Arg ("invalid interrupt state", Arg2); |
| 20190 |
end case; |
| 20191 |
|
| 20192 |
-- Check if entry is already stored |
| 20193 |
|
| 20194 |
IST_Num := Interrupt_States.First; |
| 20195 |
loop |
| 20196 |
-- If entry not found, add it |
| 20197 |
|
| 20198 |
if IST_Num > Interrupt_States.Last then |
| 20199 |
Interrupt_States.Append |
| 20200 |
((Interrupt_Number => UI_To_Int (Int_Val), |
| 20201 |
Interrupt_State => State_Type, |
| 20202 |
Pragma_Loc => Loc)); |
| 20203 |
exit; |
| 20204 |
|
| 20205 |
-- Case of entry for the same entry |
| 20206 |
|
| 20207 |
elsif Int_Val = Interrupt_States.Table (IST_Num). |
| 20208 |
Interrupt_Number |
| 20209 |
then |
| 20210 |
-- If state matches, done, no need to make redundant entry |
| 20211 |
|
| 20212 |
exit when |
| 20213 |
State_Type = Interrupt_States.Table (IST_Num). |
| 20214 |
Interrupt_State; |
| 20215 |
|
| 20216 |
-- Otherwise if state does not match, error |
| 20217 |
|
| 20218 |
Error_Msg_Sloc := |
| 20219 |
Interrupt_States.Table (IST_Num).Pragma_Loc; |
| 20220 |
Error_Pragma_Arg |
| 20221 |
("state conflicts with that given #", Arg2); |
| 20222 |
end if; |
| 20223 |
|
| 20224 |
IST_Num := IST_Num + 1; |
| 20225 |
end loop; |
| 20226 |
end Interrupt_State; |
| 20227 |
|
| 20228 |
--------------- |
| 20229 |
-- Invariant -- |
| 20230 |
--------------- |
| 20231 |
|
| 20232 |
-- pragma Invariant |
| 20233 |
-- ([Entity =>] type_LOCAL_NAME, |
| 20234 |
-- [Check =>] EXPRESSION |
| 20235 |
-- [,[Message =>] String_Expression]); |
| 20236 |
|
| 20237 |
when Pragma_Invariant => Invariant : declare |
| 20238 |
Discard : Boolean; |
| 20239 |
Typ : Entity_Id; |
| 20240 |
Typ_Arg : Node_Id; |
| 20241 |
|
| 20242 |
begin |
| 20243 |
GNAT_Pragma; |
| 20244 |
Check_At_Least_N_Arguments (2); |
| 20245 |
Check_At_Most_N_Arguments (3); |
| 20246 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 20247 |
Check_Optional_Identifier (Arg2, Name_Check); |
| 20248 |
|
| 20249 |
if Arg_Count = 3 then |
| 20250 |
Check_Optional_Identifier (Arg3, Name_Message); |
| 20251 |
Check_Arg_Is_OK_Static_Expression (Arg3, Standard_String); |
| 20252 |
end if; |
| 20253 |
|
| 20254 |
Check_Arg_Is_Local_Name (Arg1); |
| 20255 |
|
| 20256 |
Typ_Arg := Get_Pragma_Arg (Arg1); |
| 20257 |
Find_Type (Typ_Arg); |
| 20258 |
Typ := Entity (Typ_Arg); |
| 20259 |
|
| 20260 |
-- Nothing to do of the related type is erroneous in some way |
| 20261 |
|
| 20262 |
if Typ = Any_Type then |
| 20263 |
return; |
| 20264 |
|
| 20265 |
-- AI12-0041: Invariants are allowed in interface types |
| 20266 |
|
| 20267 |
elsif Is_Interface (Typ) then |
| 20268 |
null; |
| 20269 |
|
| 20270 |
-- An invariant must apply to a private type, or appear in the |
| 20271 |
-- private part of a package spec and apply to a completion. |
| 20272 |
-- A class-wide invariant can only appear on a private declaration |
| 20273 |
-- or private extension, not a completion. |
| 20274 |
|
| 20275 |
-- A [class-wide] invariant may be associated with a [limited] |
| 20276 |
-- private type. We need to explicitly exclude types that are |
| 20277 |
-- derived from formal private types here. |
| 20278 |
|
| 20279 |
elsif Ekind (Typ) in E_Limited_Private_Type |
| 20280 |
| E_Private_Type |
| 20281 |
and then not (Is_Derived_Type (Typ) |
| 20282 |
and then Is_Generic_Type (Etype (Typ))) |
| 20283 |
then |
| 20284 |
null; |
| 20285 |
|
| 20286 |
-- A [class-wide] invariant may be associated with a private |
| 20287 |
-- extension. |
| 20288 |
|
| 20289 |
elsif Ekind (Typ) = E_Record_Type_With_Private then |
| 20290 |
null; |
| 20291 |
|
| 20292 |
-- A non-class-wide invariant may be associated with the full view |
| 20293 |
-- of a [limited] private type or a private extension. |
| 20294 |
|
| 20295 |
elsif Has_Private_Declaration (Typ) |
| 20296 |
and then not Class_Present (N) |
| 20297 |
then |
| 20298 |
null; |
| 20299 |
|
| 20300 |
-- A class-wide invariant may appear on the partial view only |
| 20301 |
|
| 20302 |
elsif Class_Present (N) then |
| 20303 |
Error_Pragma_Arg |
| 20304 |
("pragma % only allowed for private type", Arg1); |
| 20305 |
|
| 20306 |
-- A regular invariant may appear on both views |
| 20307 |
|
| 20308 |
else |
| 20309 |
Error_Pragma_Arg |
| 20310 |
("pragma % only allowed for private type or corresponding " |
| 20311 |
& "full view", Arg1); |
| 20312 |
end if; |
| 20313 |
|
| 20314 |
-- An invariant associated with an abstract type (this includes |
| 20315 |
-- interfaces) must be class-wide. |
| 20316 |
|
| 20317 |
if Is_Abstract_Type (Typ) and then not Class_Present (N) then |
| 20318 |
Error_Pragma_Arg |
| 20319 |
("pragma % not allowed for abstract type", Arg1); |
| 20320 |
end if; |
| 20321 |
|
| 20322 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 20323 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 20324 |
|
| 20325 |
Mark_Ghost_Pragma (N, Typ); |
| 20326 |
|
| 20327 |
-- The pragma defines a type-specific invariant, the type is said |
| 20328 |
-- to have invariants of its "own". |
| 20329 |
|
| 20330 |
Set_Has_Own_Invariants (Base_Type (Typ)); |
| 20331 |
|
| 20332 |
-- If the invariant is class-wide, then it can be inherited by |
| 20333 |
-- derived or interface implementing types. The type is said to |
| 20334 |
-- have "inheritable" invariants. |
| 20335 |
|
| 20336 |
if Class_Present (N) then |
| 20337 |
Set_Has_Inheritable_Invariants (Typ); |
| 20338 |
end if; |
| 20339 |
|
| 20340 |
-- Chain the pragma on to the rep item chain, for processing when |
| 20341 |
-- the type is frozen. |
| 20342 |
|
| 20343 |
Discard := Rep_Item_Too_Late (Typ, N, FOnly => True); |
| 20344 |
|
| 20345 |
-- Create the declaration of the invariant procedure that will |
| 20346 |
-- verify the invariant at run time. Interfaces are treated as the |
| 20347 |
-- partial view of a private type in order to achieve uniformity |
| 20348 |
-- with the general case. As a result, an interface receives only |
| 20349 |
-- a "partial" invariant procedure, which is never called. |
| 20350 |
|
| 20351 |
Build_Invariant_Procedure_Declaration |
| 20352 |
(Typ => Typ, |
| 20353 |
Partial_Invariant => Is_Interface (Typ)); |
| 20354 |
end Invariant; |
| 20355 |
|
| 20356 |
---------------- |
| 20357 |
-- Keep_Names -- |
| 20358 |
---------------- |
| 20359 |
|
| 20360 |
-- pragma Keep_Names ([On => ] LOCAL_NAME); |
| 20361 |
|
| 20362 |
when Pragma_Keep_Names => Keep_Names : declare |
| 20363 |
Arg : Node_Id; |
| 20364 |
|
| 20365 |
begin |
| 20366 |
GNAT_Pragma; |
| 20367 |
Check_Arg_Count (1); |
| 20368 |
Check_Optional_Identifier (Arg1, Name_On); |
| 20369 |
Check_Arg_Is_Local_Name (Arg1); |
| 20370 |
|
| 20371 |
Arg := Get_Pragma_Arg (Arg1); |
| 20372 |
Analyze (Arg); |
| 20373 |
|
| 20374 |
if Etype (Arg) = Any_Type then |
| 20375 |
return; |
| 20376 |
end if; |
| 20377 |
|
| 20378 |
if not Is_Entity_Name (Arg) |
| 20379 |
or else Ekind (Entity (Arg)) /= E_Enumeration_Type |
| 20380 |
then |
| 20381 |
Error_Pragma_Arg |
| 20382 |
("pragma% requires a local enumeration type", Arg1); |
| 20383 |
end if; |
| 20384 |
|
| 20385 |
Set_Discard_Names (Entity (Arg), False); |
| 20386 |
end Keep_Names; |
| 20387 |
|
| 20388 |
------------- |
| 20389 |
-- License -- |
| 20390 |
------------- |
| 20391 |
|
| 20392 |
-- pragma License (RESTRICTED | UNRESTRICTED | GPL | MODIFIED_GPL); |
| 20393 |
|
| 20394 |
when Pragma_License => |
| 20395 |
GNAT_Pragma; |
| 20396 |
|
| 20397 |
-- Do not analyze pragma any further in CodePeer mode, to avoid |
| 20398 |
-- extraneous errors in this implementation-dependent pragma, |
| 20399 |
-- which has a different profile on other compilers. |
| 20400 |
|
| 20401 |
if CodePeer_Mode then |
| 20402 |
return; |
| 20403 |
end if; |
| 20404 |
|
| 20405 |
Check_Arg_Count (1); |
| 20406 |
Check_No_Identifiers; |
| 20407 |
Check_Valid_Configuration_Pragma; |
| 20408 |
Check_Arg_Is_Identifier (Arg1); |
| 20409 |
|
| 20410 |
declare |
| 20411 |
Sind : constant Source_File_Index := |
| 20412 |
Source_Index (Current_Sem_Unit); |
| 20413 |
|
| 20414 |
begin |
| 20415 |
case Chars (Get_Pragma_Arg (Arg1)) is |
| 20416 |
when Name_GPL => |
| 20417 |
Set_License (Sind, GPL); |
| 20418 |
|
| 20419 |
when Name_Modified_GPL => |
| 20420 |
Set_License (Sind, Modified_GPL); |
| 20421 |
|
| 20422 |
when Name_Restricted => |
| 20423 |
Set_License (Sind, Restricted); |
| 20424 |
|
| 20425 |
when Name_Unrestricted => |
| 20426 |
Set_License (Sind, Unrestricted); |
| 20427 |
|
| 20428 |
when others => |
| 20429 |
Error_Pragma_Arg ("invalid license name", Arg1); |
| 20430 |
end case; |
| 20431 |
end; |
| 20432 |
|
| 20433 |
--------------- |
| 20434 |
-- Link_With -- |
| 20435 |
--------------- |
| 20436 |
|
| 20437 |
-- pragma Link_With (string_EXPRESSION {, string_EXPRESSION}); |
| 20438 |
|
| 20439 |
when Pragma_Link_With => Link_With : declare |
| 20440 |
Arg : Node_Id; |
| 20441 |
|
| 20442 |
begin |
| 20443 |
GNAT_Pragma; |
| 20444 |
|
| 20445 |
if Operating_Mode = Generate_Code |
| 20446 |
and then In_Extended_Main_Source_Unit (N) |
| 20447 |
then |
| 20448 |
Check_At_Least_N_Arguments (1); |
| 20449 |
Check_No_Identifiers; |
| 20450 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 20451 |
Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String); |
| 20452 |
Start_String; |
| 20453 |
|
| 20454 |
Arg := Arg1; |
| 20455 |
while Present (Arg) loop |
| 20456 |
Check_Arg_Is_OK_Static_Expression (Arg, Standard_String); |
| 20457 |
|
| 20458 |
-- Store argument, converting sequences of spaces to a |
| 20459 |
-- single null character (this is one of the differences |
| 20460 |
-- in processing between Link_With and Linker_Options). |
| 20461 |
|
| 20462 |
Arg_Store : declare |
| 20463 |
C : constant Char_Code := Get_Char_Code (' '); |
| 20464 |
S : constant String_Id := |
| 20465 |
Strval (Expr_Value_S (Get_Pragma_Arg (Arg))); |
| 20466 |
L : constant Nat := String_Length (S); |
| 20467 |
F : Nat := 1; |
| 20468 |
|
| 20469 |
procedure Skip_Spaces; |
| 20470 |
-- Advance F past any spaces |
| 20471 |
|
| 20472 |
----------------- |
| 20473 |
-- Skip_Spaces -- |
| 20474 |
----------------- |
| 20475 |
|
| 20476 |
procedure Skip_Spaces is |
| 20477 |
begin |
| 20478 |
while F <= L and then Get_String_Char (S, F) = C loop |
| 20479 |
F := F + 1; |
| 20480 |
end loop; |
| 20481 |
end Skip_Spaces; |
| 20482 |
|
| 20483 |
-- Start of processing for Arg_Store |
| 20484 |
|
| 20485 |
begin |
| 20486 |
Skip_Spaces; -- skip leading spaces |
| 20487 |
|
| 20488 |
-- Loop through characters, changing any embedded |
| 20489 |
-- sequence of spaces to a single null character (this |
| 20490 |
-- is how Link_With/Linker_Options differ) |
| 20491 |
|
| 20492 |
while F <= L loop |
| 20493 |
if Get_String_Char (S, F) = C then |
| 20494 |
Skip_Spaces; |
| 20495 |
exit when F > L; |
| 20496 |
Store_String_Char (ASCII.NUL); |
| 20497 |
|
| 20498 |
else |
| 20499 |
Store_String_Char (Get_String_Char (S, F)); |
| 20500 |
F := F + 1; |
| 20501 |
end if; |
| 20502 |
end loop; |
| 20503 |
end Arg_Store; |
| 20504 |
|
| 20505 |
Arg := Next (Arg); |
| 20506 |
|
| 20507 |
if Present (Arg) then |
| 20508 |
Store_String_Char (ASCII.NUL); |
| 20509 |
end if; |
| 20510 |
end loop; |
| 20511 |
|
| 20512 |
Store_Linker_Option_String (End_String); |
| 20513 |
end if; |
| 20514 |
end Link_With; |
| 20515 |
|
| 20516 |
------------------ |
| 20517 |
-- Linker_Alias -- |
| 20518 |
------------------ |
| 20519 |
|
| 20520 |
-- pragma Linker_Alias ( |
| 20521 |
-- [Entity =>] LOCAL_NAME |
| 20522 |
-- [Target =>] static_string_EXPRESSION); |
| 20523 |
|
| 20524 |
when Pragma_Linker_Alias => |
| 20525 |
GNAT_Pragma; |
| 20526 |
Check_Arg_Order ((Name_Entity, Name_Target)); |
| 20527 |
Check_Arg_Count (2); |
| 20528 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 20529 |
Check_Optional_Identifier (Arg2, Name_Target); |
| 20530 |
Check_Arg_Is_Library_Level_Local_Name (Arg1); |
| 20531 |
Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String); |
| 20532 |
|
| 20533 |
-- The only processing required is to link this item on to the |
| 20534 |
-- list of rep items for the given entity. This is accomplished |
| 20535 |
-- by the call to Rep_Item_Too_Late (when no error is detected |
| 20536 |
-- and False is returned). |
| 20537 |
|
| 20538 |
if Rep_Item_Too_Late (Entity (Get_Pragma_Arg (Arg1)), N) then |
| 20539 |
return; |
| 20540 |
else |
| 20541 |
Set_Has_Gigi_Rep_Item (Entity (Get_Pragma_Arg (Arg1))); |
| 20542 |
end if; |
| 20543 |
|
| 20544 |
------------------------ |
| 20545 |
-- Linker_Constructor -- |
| 20546 |
------------------------ |
| 20547 |
|
| 20548 |
-- pragma Linker_Constructor (procedure_LOCAL_NAME); |
| 20549 |
|
| 20550 |
-- Code is shared with Linker_Destructor |
| 20551 |
|
| 20552 |
----------------------- |
| 20553 |
-- Linker_Destructor -- |
| 20554 |
----------------------- |
| 20555 |
|
| 20556 |
-- pragma Linker_Destructor (procedure_LOCAL_NAME); |
| 20557 |
|
| 20558 |
when Pragma_Linker_Constructor |
| 20559 |
| Pragma_Linker_Destructor |
| 20560 |
=> |
| 20561 |
Linker_Constructor : declare |
| 20562 |
Arg1_X : Node_Id; |
| 20563 |
Proc : Entity_Id; |
| 20564 |
|
| 20565 |
begin |
| 20566 |
GNAT_Pragma; |
| 20567 |
Check_Arg_Count (1); |
| 20568 |
Check_No_Identifiers; |
| 20569 |
Check_Arg_Is_Local_Name (Arg1); |
| 20570 |
Arg1_X := Get_Pragma_Arg (Arg1); |
| 20571 |
Analyze (Arg1_X); |
| 20572 |
Proc := Find_Unique_Parameterless_Procedure (Arg1_X, Arg1); |
| 20573 |
|
| 20574 |
if not Is_Library_Level_Entity (Proc) then |
| 20575 |
Error_Pragma_Arg |
| 20576 |
("argument for pragma% must be library level entity", Arg1); |
| 20577 |
end if; |
| 20578 |
|
| 20579 |
-- The only processing required is to link this item on to the |
| 20580 |
-- list of rep items for the given entity. This is accomplished |
| 20581 |
-- by the call to Rep_Item_Too_Late (when no error is detected |
| 20582 |
-- and False is returned). |
| 20583 |
|
| 20584 |
if Rep_Item_Too_Late (Proc, N) then |
| 20585 |
return; |
| 20586 |
else |
| 20587 |
Set_Has_Gigi_Rep_Item (Proc); |
| 20588 |
end if; |
| 20589 |
end Linker_Constructor; |
| 20590 |
|
| 20591 |
-------------------- |
| 20592 |
-- Linker_Options -- |
| 20593 |
-------------------- |
| 20594 |
|
| 20595 |
-- pragma Linker_Options (string_EXPRESSION {, string_EXPRESSION}); |
| 20596 |
|
| 20597 |
when Pragma_Linker_Options => Linker_Options : declare |
| 20598 |
Arg : Node_Id; |
| 20599 |
|
| 20600 |
begin |
| 20601 |
Check_Ada_83_Warning; |
| 20602 |
Check_No_Identifiers; |
| 20603 |
Check_Arg_Count (1); |
| 20604 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 20605 |
Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String); |
| 20606 |
Start_String (Strval (Expr_Value_S (Get_Pragma_Arg (Arg1)))); |
| 20607 |
|
| 20608 |
Arg := Arg2; |
| 20609 |
while Present (Arg) loop |
| 20610 |
Check_Arg_Is_OK_Static_Expression (Arg, Standard_String); |
| 20611 |
Store_String_Char (ASCII.NUL); |
| 20612 |
Store_String_Chars |
| 20613 |
(Strval (Expr_Value_S (Get_Pragma_Arg (Arg)))); |
| 20614 |
Arg := Next (Arg); |
| 20615 |
end loop; |
| 20616 |
|
| 20617 |
if Operating_Mode = Generate_Code |
| 20618 |
and then In_Extended_Main_Source_Unit (N) |
| 20619 |
then |
| 20620 |
Store_Linker_Option_String (End_String); |
| 20621 |
end if; |
| 20622 |
end Linker_Options; |
| 20623 |
|
| 20624 |
-------------------- |
| 20625 |
-- Linker_Section -- |
| 20626 |
-------------------- |
| 20627 |
|
| 20628 |
-- pragma Linker_Section ( |
| 20629 |
-- [Entity =>] LOCAL_NAME |
| 20630 |
-- [Section =>] static_string_EXPRESSION); |
| 20631 |
|
| 20632 |
when Pragma_Linker_Section => Linker_Section : declare |
| 20633 |
Arg : Node_Id; |
| 20634 |
Ent : Entity_Id; |
| 20635 |
LPE : Node_Id; |
| 20636 |
|
| 20637 |
Ghost_Error_Posted : Boolean := False; |
| 20638 |
-- Flag set when an error concerning the illegal mix of Ghost and |
| 20639 |
-- non-Ghost subprograms is emitted. |
| 20640 |
|
| 20641 |
Ghost_Id : Entity_Id := Empty; |
| 20642 |
-- The entity of the first Ghost subprogram encountered while |
| 20643 |
-- processing the arguments of the pragma. |
| 20644 |
|
| 20645 |
begin |
| 20646 |
GNAT_Pragma; |
| 20647 |
Check_Arg_Order ((Name_Entity, Name_Section)); |
| 20648 |
Check_Arg_Count (2); |
| 20649 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 20650 |
Check_Optional_Identifier (Arg2, Name_Section); |
| 20651 |
Check_Arg_Is_Library_Level_Local_Name (Arg1); |
| 20652 |
Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String); |
| 20653 |
|
| 20654 |
-- Check kind of entity |
| 20655 |
|
| 20656 |
Arg := Get_Pragma_Arg (Arg1); |
| 20657 |
Ent := Entity (Arg); |
| 20658 |
|
| 20659 |
case Ekind (Ent) is |
| 20660 |
|
| 20661 |
-- Objects (constants and variables) and types. For these cases |
| 20662 |
-- all we need to do is to set the Linker_Section_pragma field, |
| 20663 |
-- checking that we do not have a duplicate. |
| 20664 |
|
| 20665 |
when Type_Kind |
| 20666 |
| E_Constant |
| 20667 |
| E_Variable |
| 20668 |
=> |
| 20669 |
LPE := Linker_Section_Pragma (Ent); |
| 20670 |
|
| 20671 |
if Present (LPE) then |
| 20672 |
Error_Msg_Sloc := Sloc (LPE); |
| 20673 |
Error_Msg_NE |
| 20674 |
("Linker_Section already specified for &#", Arg1, Ent); |
| 20675 |
end if; |
| 20676 |
|
| 20677 |
Set_Linker_Section_Pragma (Ent, N); |
| 20678 |
|
| 20679 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 20680 |
-- the purposes of legality checks and removal of ignored |
| 20681 |
-- Ghost code. |
| 20682 |
|
| 20683 |
Mark_Ghost_Pragma (N, Ent); |
| 20684 |
|
| 20685 |
-- Subprograms |
| 20686 |
|
| 20687 |
when Subprogram_Kind => |
| 20688 |
|
| 20689 |
-- Aspect case, entity already set |
| 20690 |
|
| 20691 |
if From_Aspect_Specification (N) then |
| 20692 |
Set_Linker_Section_Pragma |
| 20693 |
(Entity (Corresponding_Aspect (N)), N); |
| 20694 |
|
| 20695 |
-- Propagate it to its ultimate aliased entity to |
| 20696 |
-- facilitate the backend processing this attribute |
| 20697 |
-- in instantiations of generic subprograms. |
| 20698 |
|
| 20699 |
if Present (Alias (Entity (Corresponding_Aspect (N)))) |
| 20700 |
then |
| 20701 |
Set_Linker_Section_Pragma |
| 20702 |
(Ultimate_Alias |
| 20703 |
(Entity (Corresponding_Aspect (N))), N); |
| 20704 |
end if; |
| 20705 |
|
| 20706 |
-- Pragma case, we must climb the homonym chain, but skip |
| 20707 |
-- any for which the linker section is already set. |
| 20708 |
|
| 20709 |
else |
| 20710 |
loop |
| 20711 |
if No (Linker_Section_Pragma (Ent)) then |
| 20712 |
Set_Linker_Section_Pragma (Ent, N); |
| 20713 |
|
| 20714 |
-- Propagate it to its ultimate aliased entity to |
| 20715 |
-- facilitate the backend processing this attribute |
| 20716 |
-- in instantiations of generic subprograms. |
| 20717 |
|
| 20718 |
if Present (Alias (Ent)) then |
| 20719 |
Set_Linker_Section_Pragma |
| 20720 |
(Ultimate_Alias (Ent), N); |
| 20721 |
end if; |
| 20722 |
|
| 20723 |
-- A pragma that applies to a Ghost entity becomes |
| 20724 |
-- Ghost for the purposes of legality checks and |
| 20725 |
-- removal of ignored Ghost code. |
| 20726 |
|
| 20727 |
Mark_Ghost_Pragma (N, Ent); |
| 20728 |
|
| 20729 |
-- Capture the entity of the first Ghost subprogram |
| 20730 |
-- being processed for error detection purposes. |
| 20731 |
|
| 20732 |
if Is_Ghost_Entity (Ent) then |
| 20733 |
if No (Ghost_Id) then |
| 20734 |
Ghost_Id := Ent; |
| 20735 |
end if; |
| 20736 |
|
| 20737 |
-- Otherwise the subprogram is non-Ghost. It is |
| 20738 |
-- illegal to mix references to Ghost and non-Ghost |
| 20739 |
-- entities (SPARK RM 6.9). |
| 20740 |
|
| 20741 |
elsif Present (Ghost_Id) |
| 20742 |
and then not Ghost_Error_Posted |
| 20743 |
then |
| 20744 |
Ghost_Error_Posted := True; |
| 20745 |
|
| 20746 |
Error_Msg_Name_1 := Pname; |
| 20747 |
Error_Msg_N |
| 20748 |
("pragma % cannot mention ghost and " |
| 20749 |
& "non-ghost subprograms", N); |
| 20750 |
|
| 20751 |
Error_Msg_Sloc := Sloc (Ghost_Id); |
| 20752 |
Error_Msg_NE |
| 20753 |
("\& # declared as ghost", N, Ghost_Id); |
| 20754 |
|
| 20755 |
Error_Msg_Sloc := Sloc (Ent); |
| 20756 |
Error_Msg_NE |
| 20757 |
("\& # declared as non-ghost", N, Ent); |
| 20758 |
end if; |
| 20759 |
end if; |
| 20760 |
|
| 20761 |
Ent := Homonym (Ent); |
| 20762 |
exit when No (Ent) |
| 20763 |
or else Scope (Ent) /= Current_Scope; |
| 20764 |
end loop; |
| 20765 |
end if; |
| 20766 |
|
| 20767 |
-- All other cases are illegal |
| 20768 |
|
| 20769 |
when others => |
| 20770 |
Error_Pragma_Arg |
| 20771 |
("pragma% applies only to objects, subprograms, and types", |
| 20772 |
Arg1); |
| 20773 |
end case; |
| 20774 |
end Linker_Section; |
| 20775 |
|
| 20776 |
---------- |
| 20777 |
-- List -- |
| 20778 |
---------- |
| 20779 |
|
| 20780 |
-- pragma List (On | Off) |
| 20781 |
|
| 20782 |
-- There is nothing to do here, since we did all the processing for |
| 20783 |
-- this pragma in Par.Prag (so that it works properly even in syntax |
| 20784 |
-- only mode). |
| 20785 |
|
| 20786 |
when Pragma_List => |
| 20787 |
null; |
| 20788 |
|
| 20789 |
--------------- |
| 20790 |
-- Lock_Free -- |
| 20791 |
--------------- |
| 20792 |
|
| 20793 |
-- pragma Lock_Free [(static_boolean_EXPRESSION)]; |
| 20794 |
|
| 20795 |
when Pragma_Lock_Free => Lock_Free : declare |
| 20796 |
P : constant Node_Id := Parent (N); |
| 20797 |
Arg : Node_Id; |
| 20798 |
Ent : Entity_Id; |
| 20799 |
Val : Boolean; |
| 20800 |
|
| 20801 |
begin |
| 20802 |
GNAT_Pragma; |
| 20803 |
Check_No_Identifiers; |
| 20804 |
Check_At_Most_N_Arguments (1); |
| 20805 |
|
| 20806 |
-- Protected definition case |
| 20807 |
|
| 20808 |
if Nkind (P) = N_Protected_Definition then |
| 20809 |
Ent := Defining_Identifier (Parent (P)); |
| 20810 |
|
| 20811 |
-- One argument |
| 20812 |
|
| 20813 |
if Arg_Count = 1 then |
| 20814 |
Arg := Get_Pragma_Arg (Arg1); |
| 20815 |
Val := Is_True (Static_Boolean (Arg)); |
| 20816 |
|
| 20817 |
-- No arguments (expression is considered to be True) |
| 20818 |
|
| 20819 |
else |
| 20820 |
Val := True; |
| 20821 |
end if; |
| 20822 |
|
| 20823 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 20824 |
-- Item chain of Ent. |
| 20825 |
|
| 20826 |
Check_Duplicate_Pragma (Ent); |
| 20827 |
Record_Rep_Item (Ent, N); |
| 20828 |
Set_Uses_Lock_Free (Ent, Val); |
| 20829 |
|
| 20830 |
-- Anything else is incorrect placement |
| 20831 |
|
| 20832 |
else |
| 20833 |
Pragma_Misplaced; |
| 20834 |
end if; |
| 20835 |
end Lock_Free; |
| 20836 |
|
| 20837 |
-------------------- |
| 20838 |
-- Locking_Policy -- |
| 20839 |
-------------------- |
| 20840 |
|
| 20841 |
-- pragma Locking_Policy (policy_IDENTIFIER); |
| 20842 |
|
| 20843 |
when Pragma_Locking_Policy => declare |
| 20844 |
subtype LP_Range is Name_Id |
| 20845 |
range First_Locking_Policy_Name .. Last_Locking_Policy_Name; |
| 20846 |
LP_Val : LP_Range; |
| 20847 |
LP : Character; |
| 20848 |
|
| 20849 |
begin |
| 20850 |
Check_Ada_83_Warning; |
| 20851 |
Check_Arg_Count (1); |
| 20852 |
Check_No_Identifiers; |
| 20853 |
Check_Arg_Is_Locking_Policy (Arg1); |
| 20854 |
Check_Valid_Configuration_Pragma; |
| 20855 |
LP_Val := Chars (Get_Pragma_Arg (Arg1)); |
| 20856 |
|
| 20857 |
case LP_Val is |
| 20858 |
when Name_Ceiling_Locking => LP := 'C'; |
| 20859 |
when Name_Concurrent_Readers_Locking => LP := 'R'; |
| 20860 |
when Name_Inheritance_Locking => LP := 'I'; |
| 20861 |
end case; |
| 20862 |
|
| 20863 |
if Locking_Policy /= ' ' |
| 20864 |
and then Locking_Policy /= LP |
| 20865 |
then |
| 20866 |
Error_Msg_Sloc := Locking_Policy_Sloc; |
| 20867 |
Error_Pragma ("locking policy incompatible with policy#"); |
| 20868 |
|
| 20869 |
-- Set new policy, but always preserve System_Location since we |
| 20870 |
-- like the error message with the run time name. |
| 20871 |
|
| 20872 |
else |
| 20873 |
Locking_Policy := LP; |
| 20874 |
|
| 20875 |
if Locking_Policy_Sloc /= System_Location then |
| 20876 |
Locking_Policy_Sloc := Loc; |
| 20877 |
end if; |
| 20878 |
end if; |
| 20879 |
end; |
| 20880 |
|
| 20881 |
------------------- |
| 20882 |
-- Loop_Optimize -- |
| 20883 |
------------------- |
| 20884 |
|
| 20885 |
-- pragma Loop_Optimize ( OPTIMIZATION_HINT {, OPTIMIZATION_HINT } ); |
| 20886 |
|
| 20887 |
-- OPTIMIZATION_HINT ::= |
| 20888 |
-- Ivdep | No_Unroll | Unroll | No_Vector | Vector |
| 20889 |
|
| 20890 |
when Pragma_Loop_Optimize => Loop_Optimize : declare |
| 20891 |
Hint : Node_Id; |
| 20892 |
|
| 20893 |
begin |
| 20894 |
GNAT_Pragma; |
| 20895 |
Check_At_Least_N_Arguments (1); |
| 20896 |
Check_No_Identifiers; |
| 20897 |
|
| 20898 |
Hint := First (Pragma_Argument_Associations (N)); |
| 20899 |
while Present (Hint) loop |
| 20900 |
Check_Arg_Is_One_Of (Hint, Name_Ivdep, |
| 20901 |
Name_No_Unroll, |
| 20902 |
Name_Unroll, |
| 20903 |
Name_No_Vector, |
| 20904 |
Name_Vector); |
| 20905 |
Next (Hint); |
| 20906 |
end loop; |
| 20907 |
|
| 20908 |
Check_Loop_Pragma_Placement; |
| 20909 |
end Loop_Optimize; |
| 20910 |
|
| 20911 |
------------------ |
| 20912 |
-- Loop_Variant -- |
| 20913 |
------------------ |
| 20914 |
|
| 20915 |
-- pragma Loop_Variant |
| 20916 |
-- ( LOOP_VARIANT_ITEM {, LOOP_VARIANT_ITEM } ); |
| 20917 |
|
| 20918 |
-- LOOP_VARIANT_ITEM ::= CHANGE_DIRECTION => discrete_EXPRESSION |
| 20919 |
|
| 20920 |
-- CHANGE_DIRECTION ::= Increases | Decreases |
| 20921 |
|
| 20922 |
when Pragma_Loop_Variant => Loop_Variant : declare |
| 20923 |
Variant : Node_Id; |
| 20924 |
|
| 20925 |
begin |
| 20926 |
GNAT_Pragma; |
| 20927 |
Check_At_Least_N_Arguments (1); |
| 20928 |
Check_Loop_Pragma_Placement; |
| 20929 |
|
| 20930 |
-- Process all increasing / decreasing expressions |
| 20931 |
|
| 20932 |
Variant := First (Pragma_Argument_Associations (N)); |
| 20933 |
while Present (Variant) loop |
| 20934 |
if Chars (Variant) = No_Name then |
| 20935 |
Error_Pragma_Arg_Ident ("expect name `Increases`", Variant); |
| 20936 |
|
| 20937 |
elsif Chars (Variant) not in |
| 20938 |
Name_Decreases | Name_Increases | Name_Structural |
| 20939 |
then |
| 20940 |
declare |
| 20941 |
Name : String := Get_Name_String (Chars (Variant)); |
| 20942 |
|
| 20943 |
begin |
| 20944 |
-- It is a common mistake to write "Increasing" for |
| 20945 |
-- "Increases" or "Decreasing" for "Decreases". Recognize |
| 20946 |
-- specially names starting with "incr" or "decr" to |
| 20947 |
-- suggest the corresponding name. |
| 20948 |
|
| 20949 |
System.Case_Util.To_Lower (Name); |
| 20950 |
|
| 20951 |
if Name'Length >= 4 |
| 20952 |
and then Name (1 .. 4) = "incr" |
| 20953 |
then |
| 20954 |
Error_Pragma_Arg_Ident |
| 20955 |
("expect name `Increases`", Variant); |
| 20956 |
|
| 20957 |
elsif Name'Length >= 4 |
| 20958 |
and then Name (1 .. 4) = "decr" |
| 20959 |
then |
| 20960 |
Error_Pragma_Arg_Ident |
| 20961 |
("expect name `Decreases`", Variant); |
| 20962 |
|
| 20963 |
elsif Name'Length >= 4 |
| 20964 |
and then Name (1 .. 4) = "stru" |
| 20965 |
then |
| 20966 |
Error_Pragma_Arg_Ident |
| 20967 |
("expect name `Structural`", Variant); |
| 20968 |
|
| 20969 |
else |
| 20970 |
Error_Pragma_Arg_Ident |
| 20971 |
("expect name `Increases`, `Decreases`," |
| 20972 |
& " or `Structural`", Variant); |
| 20973 |
end if; |
| 20974 |
end; |
| 20975 |
|
| 20976 |
elsif Chars (Variant) = Name_Structural |
| 20977 |
and then List_Length (Pragma_Argument_Associations (N)) > 1 |
| 20978 |
then |
| 20979 |
Error_Pragma_Arg_Ident |
| 20980 |
("Structural variant shall be the only variant", Variant); |
| 20981 |
end if; |
| 20982 |
|
| 20983 |
-- Preanalyze_Assert_Expression, but without enforcing any of |
| 20984 |
-- the two acceptable types. |
| 20985 |
|
| 20986 |
Preanalyze_Assert_Expression (Expression (Variant)); |
| 20987 |
|
| 20988 |
-- Expression of a discrete type is allowed. Nothing to |
| 20989 |
-- check for structural variants. |
| 20990 |
|
| 20991 |
if Chars (Variant) = Name_Structural |
| 20992 |
or else Is_Discrete_Type (Etype (Expression (Variant))) |
| 20993 |
then |
| 20994 |
null; |
| 20995 |
|
| 20996 |
-- Expression of a Big_Integer type (or its ghost variant) is |
| 20997 |
-- only allowed in Decreases clause. |
| 20998 |
|
| 20999 |
elsif |
| 21000 |
Is_RTE (Base_Type (Etype (Expression (Variant))), |
| 21001 |
RE_Big_Integer) |
| 21002 |
or else |
| 21003 |
Is_RTE (Base_Type (Etype (Expression (Variant))), |
| 21004 |
RO_GH_Big_Integer) |
| 21005 |
or else |
| 21006 |
Is_RTE (Base_Type (Etype (Expression (Variant))), |
| 21007 |
RO_SP_Big_Integer) |
| 21008 |
then |
| 21009 |
if Chars (Variant) = Name_Increases then |
| 21010 |
Error_Msg_N |
| 21011 |
("Loop_Variant with Big_Integer can only decrease", |
| 21012 |
Expression (Variant)); |
| 21013 |
end if; |
| 21014 |
|
| 21015 |
-- Expression of other types is not allowed |
| 21016 |
|
| 21017 |
else |
| 21018 |
Error_Msg_N |
| 21019 |
("expected a discrete or Big_Integer type", |
| 21020 |
Expression (Variant)); |
| 21021 |
end if; |
| 21022 |
|
| 21023 |
Next (Variant); |
| 21024 |
end loop; |
| 21025 |
end Loop_Variant; |
| 21026 |
|
| 21027 |
----------------------- |
| 21028 |
-- Machine_Attribute -- |
| 21029 |
----------------------- |
| 21030 |
|
| 21031 |
-- pragma Machine_Attribute ( |
| 21032 |
-- [Entity =>] LOCAL_NAME, |
| 21033 |
-- [Attribute_Name =>] static_string_EXPRESSION |
| 21034 |
-- [, [Info =>] static_EXPRESSION {, static_EXPRESSION}] ); |
| 21035 |
|
| 21036 |
when Pragma_Machine_Attribute => Machine_Attribute : declare |
| 21037 |
Arg : Node_Id; |
| 21038 |
Def_Id : Entity_Id; |
| 21039 |
|
| 21040 |
begin |
| 21041 |
GNAT_Pragma; |
| 21042 |
Check_Arg_Order ((Name_Entity, Name_Attribute_Name, Name_Info)); |
| 21043 |
|
| 21044 |
if Arg_Count >= 3 then |
| 21045 |
Check_Optional_Identifier (Arg3, Name_Info); |
| 21046 |
Arg := Arg3; |
| 21047 |
while Present (Arg) loop |
| 21048 |
Check_Arg_Is_OK_Static_Expression (Arg); |
| 21049 |
Arg := Next (Arg); |
| 21050 |
end loop; |
| 21051 |
else |
| 21052 |
Check_Arg_Count (2); |
| 21053 |
end if; |
| 21054 |
|
| 21055 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 21056 |
Check_Optional_Identifier (Arg2, Name_Attribute_Name); |
| 21057 |
Check_Arg_Is_Local_Name (Arg1); |
| 21058 |
Check_Arg_Is_OK_Static_Expression (Arg2, Standard_String); |
| 21059 |
Def_Id := Entity (Get_Pragma_Arg (Arg1)); |
| 21060 |
|
| 21061 |
-- Apply the pragma to the designated type, rather than to the |
| 21062 |
-- access type, unless it's a strub annotation. We wish to enable |
| 21063 |
-- objects of access type, as well as access types themselves, to |
| 21064 |
-- be annotated, so that reading the access objects (as oposed to |
| 21065 |
-- the designated data) automatically enables stack |
| 21066 |
-- scrubbing. That said, as in the attribute handler that |
| 21067 |
-- processes the pragma turned into a compiler attribute, a strub |
| 21068 |
-- annotation that must be associated with a subprogram type (for |
| 21069 |
-- holding an explicit strub mode), when applied to an |
| 21070 |
-- access-to-subprogram, gets promoted to the subprogram type. We |
| 21071 |
-- might be tempted to leave it alone here, since the C attribute |
| 21072 |
-- handler will adjust it, but then GNAT would convert the |
| 21073 |
-- annotated subprogram types to naked ones before using them, |
| 21074 |
-- cancelling out their intended effects. |
| 21075 |
|
| 21076 |
if Is_Access_Type (Def_Id) |
| 21077 |
and then (not Strub_Pragma_P (N) |
| 21078 |
or else |
| 21079 |
(Present (Arg3) |
| 21080 |
and then |
| 21081 |
Ekind (Designated_Type |
| 21082 |
(Def_Id)) = E_Subprogram_Type)) |
| 21083 |
then |
| 21084 |
Def_Id := Designated_Type (Def_Id); |
| 21085 |
end if; |
| 21086 |
|
| 21087 |
if Rep_Item_Too_Early (Def_Id, N) then |
| 21088 |
return; |
| 21089 |
end if; |
| 21090 |
|
| 21091 |
Def_Id := Underlying_Type (Def_Id); |
| 21092 |
|
| 21093 |
-- The only processing required is to link this item on to the |
| 21094 |
-- list of rep items for the given entity. This is accomplished |
| 21095 |
-- by the call to Rep_Item_Too_Late (when no error is detected |
| 21096 |
-- and False is returned). |
| 21097 |
|
| 21098 |
if Rep_Item_Too_Late (Def_Id, N) then |
| 21099 |
return; |
| 21100 |
else |
| 21101 |
Set_Has_Gigi_Rep_Item (Def_Id); |
| 21102 |
end if; |
| 21103 |
end Machine_Attribute; |
| 21104 |
|
| 21105 |
---------- |
| 21106 |
-- Main -- |
| 21107 |
---------- |
| 21108 |
|
| 21109 |
-- pragma Main |
| 21110 |
-- (MAIN_OPTION [, MAIN_OPTION]); |
| 21111 |
|
| 21112 |
-- MAIN_OPTION ::= |
| 21113 |
-- [STACK_SIZE =>] static_integer_EXPRESSION |
| 21114 |
-- | [TASK_STACK_SIZE_DEFAULT =>] static_integer_EXPRESSION |
| 21115 |
-- | [TIME_SLICING_ENABLED =>] static_boolean_EXPRESSION |
| 21116 |
|
| 21117 |
when Pragma_Main => Main : declare |
| 21118 |
Args : Args_List (1 .. 3); |
| 21119 |
Names : constant Name_List (1 .. 3) := ( |
| 21120 |
Name_Stack_Size, |
| 21121 |
Name_Task_Stack_Size_Default, |
| 21122 |
Name_Time_Slicing_Enabled); |
| 21123 |
|
| 21124 |
Nod : Node_Id; |
| 21125 |
|
| 21126 |
begin |
| 21127 |
GNAT_Pragma; |
| 21128 |
Gather_Associations (Names, Args); |
| 21129 |
|
| 21130 |
for J in 1 .. 2 loop |
| 21131 |
if Present (Args (J)) then |
| 21132 |
Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer); |
| 21133 |
end if; |
| 21134 |
end loop; |
| 21135 |
|
| 21136 |
if Present (Args (3)) then |
| 21137 |
Check_Arg_Is_OK_Static_Expression (Args (3), Standard_Boolean); |
| 21138 |
end if; |
| 21139 |
|
| 21140 |
Nod := Next (N); |
| 21141 |
while Present (Nod) loop |
| 21142 |
if Nkind (Nod) = N_Pragma |
| 21143 |
and then Pragma_Name (Nod) = Name_Main |
| 21144 |
then |
| 21145 |
Error_Msg_Name_1 := Pname; |
| 21146 |
Error_Msg_N ("duplicate pragma% not permitted", Nod); |
| 21147 |
end if; |
| 21148 |
|
| 21149 |
Next (Nod); |
| 21150 |
end loop; |
| 21151 |
end Main; |
| 21152 |
|
| 21153 |
------------------ |
| 21154 |
-- Main_Storage -- |
| 21155 |
------------------ |
| 21156 |
|
| 21157 |
-- pragma Main_Storage |
| 21158 |
-- (MAIN_STORAGE_OPTION [, MAIN_STORAGE_OPTION]); |
| 21159 |
|
| 21160 |
-- MAIN_STORAGE_OPTION ::= |
| 21161 |
-- [WORKING_STORAGE =>] static_SIMPLE_EXPRESSION |
| 21162 |
-- | [TOP_GUARD =>] static_SIMPLE_EXPRESSION |
| 21163 |
|
| 21164 |
when Pragma_Main_Storage => Main_Storage : declare |
| 21165 |
Args : Args_List (1 .. 2); |
| 21166 |
Names : constant Name_List (1 .. 2) := ( |
| 21167 |
Name_Working_Storage, |
| 21168 |
Name_Top_Guard); |
| 21169 |
|
| 21170 |
Nod : Node_Id; |
| 21171 |
|
| 21172 |
begin |
| 21173 |
GNAT_Pragma; |
| 21174 |
Gather_Associations (Names, Args); |
| 21175 |
|
| 21176 |
for J in 1 .. 2 loop |
| 21177 |
if Present (Args (J)) then |
| 21178 |
Check_Arg_Is_OK_Static_Expression (Args (J), Any_Integer); |
| 21179 |
end if; |
| 21180 |
end loop; |
| 21181 |
|
| 21182 |
Check_In_Main_Program; |
| 21183 |
|
| 21184 |
Nod := Next (N); |
| 21185 |
while Present (Nod) loop |
| 21186 |
if Nkind (Nod) = N_Pragma |
| 21187 |
and then Pragma_Name (Nod) = Name_Main_Storage |
| 21188 |
then |
| 21189 |
Error_Msg_Name_1 := Pname; |
| 21190 |
Error_Msg_N ("duplicate pragma% not permitted", Nod); |
| 21191 |
end if; |
| 21192 |
|
| 21193 |
Next (Nod); |
| 21194 |
end loop; |
| 21195 |
end Main_Storage; |
| 21196 |
|
| 21197 |
---------------------------- |
| 21198 |
-- Max_Entry_Queue_Length -- |
| 21199 |
---------------------------- |
| 21200 |
|
| 21201 |
-- pragma Max_Entry_Queue_Length (static_integer_EXPRESSION); |
| 21202 |
|
| 21203 |
when Pragma_Max_Entry_Queue_Length |
| 21204 |
| Pragma_Max_Queue_Length |
| 21205 |
=> |
| 21206 |
Max_Entry_Queue_Length : declare |
| 21207 |
Arg : Node_Id; |
| 21208 |
Entry_Decl : Node_Id; |
| 21209 |
Entry_Id : Entity_Id; |
| 21210 |
Val : Uint; |
| 21211 |
|
| 21212 |
begin |
| 21213 |
if Prag_Id = Pragma_Max_Queue_Length then |
| 21214 |
GNAT_Pragma; |
| 21215 |
end if; |
| 21216 |
|
| 21217 |
Check_Arg_Count (1); |
| 21218 |
|
| 21219 |
Entry_Decl := |
| 21220 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 21221 |
|
| 21222 |
-- Entry declaration |
| 21223 |
|
| 21224 |
if Nkind (Entry_Decl) = N_Entry_Declaration then |
| 21225 |
|
| 21226 |
-- Entry illegally within a task |
| 21227 |
|
| 21228 |
if Nkind (Parent (N)) = N_Task_Definition then |
| 21229 |
Error_Pragma ("pragma % cannot apply to task entries"); |
| 21230 |
end if; |
| 21231 |
|
| 21232 |
Entry_Id := Defining_Entity (Entry_Decl); |
| 21233 |
|
| 21234 |
-- Otherwise the pragma is associated with an illegal construct |
| 21235 |
|
| 21236 |
else |
| 21237 |
Error_Pragma |
| 21238 |
("pragma % must apply to a protected entry declaration"); |
| 21239 |
end if; |
| 21240 |
|
| 21241 |
-- Check for conflicting use of synonyms. Note that we exclude |
| 21242 |
-- the detection of duplicates here because they are detected |
| 21243 |
-- elsewhere. |
| 21244 |
|
| 21245 |
if (Has_Rep_Pragma (Entry_Id, Name_Max_Entry_Queue_Length) |
| 21246 |
and then |
| 21247 |
Prag_Id /= Pragma_Max_Entry_Queue_Length) |
| 21248 |
or else |
| 21249 |
(Has_Rep_Pragma (Entry_Id, Name_Max_Queue_Length) |
| 21250 |
and then |
| 21251 |
Prag_Id /= Pragma_Max_Queue_Length) |
| 21252 |
then |
| 21253 |
Error_Msg_N ("??maximum entry queue length already set", N); |
| 21254 |
end if; |
| 21255 |
|
| 21256 |
-- Mark the pragma as Ghost if the related subprogram is also |
| 21257 |
-- Ghost. This also ensures that any expansion performed further |
| 21258 |
-- below will produce Ghost nodes. |
| 21259 |
|
| 21260 |
Mark_Ghost_Pragma (N, Entry_Id); |
| 21261 |
|
| 21262 |
-- Analyze the Integer expression |
| 21263 |
|
| 21264 |
Arg := Get_Pragma_Arg (Arg1); |
| 21265 |
Check_Arg_Is_OK_Static_Expression (Arg, Any_Integer); |
| 21266 |
|
| 21267 |
Val := Expr_Value (Arg); |
| 21268 |
|
| 21269 |
if Val < -1 then |
| 21270 |
Error_Pragma_Arg |
| 21271 |
("argument for pragma% cannot be less than -1", Arg1); |
| 21272 |
|
| 21273 |
elsif not UI_Is_In_Int_Range (Val) then |
| 21274 |
Error_Pragma_Arg |
| 21275 |
("argument for pragma% out of range of Integer", Arg1); |
| 21276 |
|
| 21277 |
end if; |
| 21278 |
|
| 21279 |
Record_Rep_Item (Entry_Id, N); |
| 21280 |
end Max_Entry_Queue_Length; |
| 21281 |
|
| 21282 |
----------------- |
| 21283 |
-- Memory_Size -- |
| 21284 |
----------------- |
| 21285 |
|
| 21286 |
-- pragma Memory_Size (NUMERIC_LITERAL) |
| 21287 |
|
| 21288 |
when Pragma_Memory_Size => |
| 21289 |
GNAT_Pragma; |
| 21290 |
|
| 21291 |
-- Memory size is simply ignored |
| 21292 |
|
| 21293 |
Check_No_Identifiers; |
| 21294 |
Check_Arg_Count (1); |
| 21295 |
Check_Arg_Is_Integer_Literal (Arg1); |
| 21296 |
|
| 21297 |
------------- |
| 21298 |
-- No_Body -- |
| 21299 |
------------- |
| 21300 |
|
| 21301 |
-- pragma No_Body; |
| 21302 |
|
| 21303 |
-- The only correct use of this pragma is on its own in a file, in |
| 21304 |
-- which case it is specially processed (see Gnat1drv.Check_Bad_Body |
| 21305 |
-- and Frontend, which use Sinput.L.Source_File_Is_Pragma_No_Body to |
| 21306 |
-- check for a file containing nothing but a No_Body pragma). If we |
| 21307 |
-- attempt to process it during normal semantics processing, it means |
| 21308 |
-- it was misplaced. |
| 21309 |
|
| 21310 |
when Pragma_No_Body => |
| 21311 |
GNAT_Pragma; |
| 21312 |
Pragma_Misplaced; |
| 21313 |
|
| 21314 |
----------------------------- |
| 21315 |
-- No_Elaboration_Code_All -- |
| 21316 |
----------------------------- |
| 21317 |
|
| 21318 |
-- pragma No_Elaboration_Code_All; |
| 21319 |
|
| 21320 |
when Pragma_No_Elaboration_Code_All => |
| 21321 |
GNAT_Pragma; |
| 21322 |
Check_Valid_Library_Unit_Pragma; |
| 21323 |
|
| 21324 |
-- If N was rewritten as a null statement there is nothing more |
| 21325 |
-- to do. |
| 21326 |
|
| 21327 |
if Nkind (N) = N_Null_Statement then |
| 21328 |
return; |
| 21329 |
end if; |
| 21330 |
|
| 21331 |
-- Must appear for a spec or generic spec |
| 21332 |
|
| 21333 |
if Nkind (Unit (Cunit (Current_Sem_Unit))) not in |
| 21334 |
N_Generic_Package_Declaration | |
| 21335 |
N_Generic_Subprogram_Declaration | |
| 21336 |
N_Package_Declaration | |
| 21337 |
N_Subprogram_Declaration |
| 21338 |
then |
| 21339 |
Error_Pragma |
| 21340 |
(Fix_Error |
| 21341 |
("pragma% can only occur for package " |
| 21342 |
& "or subprogram spec")); |
| 21343 |
end if; |
| 21344 |
|
| 21345 |
-- Set flag in unit table |
| 21346 |
|
| 21347 |
Set_No_Elab_Code_All (Current_Sem_Unit); |
| 21348 |
|
| 21349 |
-- Set restriction No_Elaboration_Code if this is the main unit |
| 21350 |
|
| 21351 |
if Current_Sem_Unit = Main_Unit then |
| 21352 |
Set_Restriction (No_Elaboration_Code, N); |
| 21353 |
end if; |
| 21354 |
|
| 21355 |
-- If we are in the main unit or in an extended main source unit, |
| 21356 |
-- then we also add it to the configuration restrictions so that |
| 21357 |
-- it will apply to all units in the extended main source. |
| 21358 |
|
| 21359 |
if Current_Sem_Unit = Main_Unit |
| 21360 |
or else In_Extended_Main_Source_Unit (N) |
| 21361 |
then |
| 21362 |
Add_To_Config_Boolean_Restrictions (No_Elaboration_Code); |
| 21363 |
end if; |
| 21364 |
|
| 21365 |
-- If in main extended unit, activate transitive with test |
| 21366 |
|
| 21367 |
if In_Extended_Main_Source_Unit (N) then |
| 21368 |
Opt.No_Elab_Code_All_Pragma := N; |
| 21369 |
end if; |
| 21370 |
|
| 21371 |
----------------------------- |
| 21372 |
-- No_Component_Reordering -- |
| 21373 |
----------------------------- |
| 21374 |
|
| 21375 |
-- pragma No_Component_Reordering [([Entity =>] type_LOCAL_NAME)]; |
| 21376 |
|
| 21377 |
when Pragma_No_Component_Reordering => No_Comp_Reordering : declare |
| 21378 |
Typ : Entity_Id; |
| 21379 |
Type_Id : Node_Id; |
| 21380 |
|
| 21381 |
begin |
| 21382 |
GNAT_Pragma; |
| 21383 |
Check_At_Most_N_Arguments (1); |
| 21384 |
|
| 21385 |
if Arg_Count = 0 then |
| 21386 |
Check_Valid_Configuration_Pragma; |
| 21387 |
Opt.No_Component_Reordering := True; |
| 21388 |
|
| 21389 |
else |
| 21390 |
Check_Optional_Identifier (Arg2, Name_Entity); |
| 21391 |
Check_Arg_Is_Local_Name (Arg1); |
| 21392 |
Type_Id := Get_Pragma_Arg (Arg1); |
| 21393 |
|
| 21394 |
Find_Type (Type_Id); |
| 21395 |
Typ := Entity (Type_Id); |
| 21396 |
|
| 21397 |
if Typ = Any_Type then |
| 21398 |
return; |
| 21399 |
end if; |
| 21400 |
|
| 21401 |
if not Is_Record_Type (Typ) then |
| 21402 |
Error_Pragma_Arg ("pragma% requires record type", Arg1); |
| 21403 |
end if; |
| 21404 |
|
| 21405 |
Set_No_Reordering (Base_Type (Typ)); |
| 21406 |
end if; |
| 21407 |
end No_Comp_Reordering; |
| 21408 |
|
| 21409 |
-------------------------- |
| 21410 |
-- No_Heap_Finalization -- |
| 21411 |
-------------------------- |
| 21412 |
|
| 21413 |
-- pragma No_Heap_Finalization [ (first_subtype_LOCAL_NAME) ]; |
| 21414 |
|
| 21415 |
when Pragma_No_Heap_Finalization => No_Heap_Finalization : declare |
| 21416 |
Context : constant Node_Id := Parent (N); |
| 21417 |
Typ_Arg : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 21418 |
Prev : Node_Id; |
| 21419 |
Typ : Entity_Id; |
| 21420 |
|
| 21421 |
begin |
| 21422 |
GNAT_Pragma; |
| 21423 |
Check_No_Identifiers; |
| 21424 |
|
| 21425 |
-- The pragma appears in a configuration file |
| 21426 |
|
| 21427 |
if No (Context) then |
| 21428 |
Check_Arg_Count (0); |
| 21429 |
Check_Valid_Configuration_Pragma; |
| 21430 |
|
| 21431 |
-- Detect a duplicate pragma |
| 21432 |
|
| 21433 |
if Present (No_Heap_Finalization_Pragma) then |
| 21434 |
Duplication_Error |
| 21435 |
(Prag => N, |
| 21436 |
Prev => No_Heap_Finalization_Pragma); |
| 21437 |
raise Pragma_Exit; |
| 21438 |
end if; |
| 21439 |
|
| 21440 |
No_Heap_Finalization_Pragma := N; |
| 21441 |
|
| 21442 |
-- Otherwise the pragma should be associated with a library-level |
| 21443 |
-- named access-to-object type. |
| 21444 |
|
| 21445 |
else |
| 21446 |
Check_Arg_Count (1); |
| 21447 |
Check_Arg_Is_Local_Name (Arg1); |
| 21448 |
|
| 21449 |
Find_Type (Typ_Arg); |
| 21450 |
Typ := Entity (Typ_Arg); |
| 21451 |
|
| 21452 |
-- The type being subjected to the pragma is erroneous |
| 21453 |
|
| 21454 |
if Typ = Any_Type then |
| 21455 |
Error_Pragma ("cannot find type referenced by pragma %"); |
| 21456 |
|
| 21457 |
-- The pragma is applied to an incomplete or generic formal |
| 21458 |
-- type way too early. |
| 21459 |
|
| 21460 |
elsif Rep_Item_Too_Early (Typ, N) then |
| 21461 |
return; |
| 21462 |
|
| 21463 |
else |
| 21464 |
Typ := Underlying_Type (Typ); |
| 21465 |
end if; |
| 21466 |
|
| 21467 |
-- The pragma must apply to an access-to-object type |
| 21468 |
|
| 21469 |
if Ekind (Typ) in E_Access_Type | E_General_Access_Type then |
| 21470 |
null; |
| 21471 |
|
| 21472 |
-- Give a detailed error message on all other access type kinds |
| 21473 |
|
| 21474 |
elsif Ekind (Typ) = E_Access_Protected_Subprogram_Type then |
| 21475 |
Error_Pragma |
| 21476 |
("pragma % cannot apply to access protected subprogram " |
| 21477 |
& "type"); |
| 21478 |
|
| 21479 |
elsif Ekind (Typ) = E_Access_Subprogram_Type then |
| 21480 |
Error_Pragma |
| 21481 |
("pragma % cannot apply to access subprogram type"); |
| 21482 |
|
| 21483 |
elsif Is_Anonymous_Access_Type (Typ) then |
| 21484 |
Error_Pragma |
| 21485 |
("pragma % cannot apply to anonymous access type"); |
| 21486 |
|
| 21487 |
-- Give a general error message in case the pragma applies to a |
| 21488 |
-- non-access type. |
| 21489 |
|
| 21490 |
else |
| 21491 |
Error_Pragma |
| 21492 |
("pragma % must apply to library level access type"); |
| 21493 |
end if; |
| 21494 |
|
| 21495 |
-- At this point the argument denotes an access-to-object type. |
| 21496 |
-- Ensure that the type is declared at the library level. |
| 21497 |
|
| 21498 |
if Is_Library_Level_Entity (Typ) then |
| 21499 |
null; |
| 21500 |
|
| 21501 |
-- Quietly ignore an access-to-object type originally declared |
| 21502 |
-- at the library level within a generic, but instantiated at |
| 21503 |
-- a non-library level. As a result the access-to-object type |
| 21504 |
-- "loses" its No_Heap_Finalization property. |
| 21505 |
|
| 21506 |
elsif In_Instance then |
| 21507 |
raise Pragma_Exit; |
| 21508 |
|
| 21509 |
else |
| 21510 |
Error_Pragma |
| 21511 |
("pragma % must apply to library level access type"); |
| 21512 |
end if; |
| 21513 |
|
| 21514 |
-- Detect a duplicate pragma |
| 21515 |
|
| 21516 |
if Present (No_Heap_Finalization_Pragma) then |
| 21517 |
Duplication_Error |
| 21518 |
(Prag => N, |
| 21519 |
Prev => No_Heap_Finalization_Pragma); |
| 21520 |
raise Pragma_Exit; |
| 21521 |
|
| 21522 |
else |
| 21523 |
Prev := Get_Pragma (Typ, Pragma_No_Heap_Finalization); |
| 21524 |
|
| 21525 |
if Present (Prev) then |
| 21526 |
Duplication_Error |
| 21527 |
(Prag => N, |
| 21528 |
Prev => Prev); |
| 21529 |
raise Pragma_Exit; |
| 21530 |
end if; |
| 21531 |
end if; |
| 21532 |
|
| 21533 |
Record_Rep_Item (Typ, N); |
| 21534 |
end if; |
| 21535 |
end No_Heap_Finalization; |
| 21536 |
|
| 21537 |
--------------- |
| 21538 |
-- No_Inline -- |
| 21539 |
--------------- |
| 21540 |
|
| 21541 |
-- pragma No_Inline ( NAME {, NAME} ); |
| 21542 |
|
| 21543 |
when Pragma_No_Inline => |
| 21544 |
GNAT_Pragma; |
| 21545 |
Process_Inline (Suppressed); |
| 21546 |
|
| 21547 |
-------------- |
| 21548 |
-- No_Raise -- |
| 21549 |
-------------- |
| 21550 |
|
| 21551 |
-- pragma No_Raise (procedure_LOCAL_NAME {, procedure_LOCAL_NAME}); |
| 21552 |
|
| 21553 |
when Pragma_No_Raise => Prag_No_Raise : declare |
| 21554 |
Arg : Node_Id; |
| 21555 |
Assoc : Node_Id; |
| 21556 |
Subp : Entity_Id; |
| 21557 |
|
| 21558 |
begin |
| 21559 |
GNAT_Pragma; |
| 21560 |
Check_No_Identifiers; |
| 21561 |
Check_At_Least_N_Arguments (1); |
| 21562 |
|
| 21563 |
Assoc := Arg1; |
| 21564 |
while Present (Assoc) loop |
| 21565 |
Arg := Get_Pragma_Arg (Assoc); |
| 21566 |
Analyze (Arg); |
| 21567 |
|
| 21568 |
if Is_Entity_Name (Arg) then |
| 21569 |
Subp := Entity (Arg); |
| 21570 |
|
| 21571 |
-- If previous error, avoid cascaded errors |
| 21572 |
|
| 21573 |
if Subp = Any_Id then |
| 21574 |
Check_Error_Detected; |
| 21575 |
|
| 21576 |
-- The argument must be a [generic] subprogram |
| 21577 |
|
| 21578 |
elsif not Is_Subprogram_Or_Generic_Subprogram (Subp) then |
| 21579 |
Error_Pragma_Arg |
| 21580 |
("argument for pragma% must be a subprogram", Assoc); |
| 21581 |
|
| 21582 |
-- The argument must be in current scope |
| 21583 |
|
| 21584 |
elsif Scope (Subp) = Current_Scope then |
| 21585 |
Check_Duplicate_Pragma (Subp); |
| 21586 |
Record_Rep_Item (Subp, N); |
| 21587 |
|
| 21588 |
Set_No_Raise (Subp); |
| 21589 |
|
| 21590 |
-- For the pragma case, climb homonym chain. This is |
| 21591 |
-- what implements allowing the pragma in the renaming |
| 21592 |
-- case, with the result applying to the ancestors, and |
| 21593 |
-- allows No_Raise to apply to all previous homonyms. |
| 21594 |
|
| 21595 |
if not From_Aspect_Specification (N) then |
| 21596 |
while Present (Homonym (Subp)) |
| 21597 |
and then Scope (Homonym (Subp)) = Current_Scope |
| 21598 |
loop |
| 21599 |
Subp := Homonym (Subp); |
| 21600 |
Set_No_Raise (Subp); |
| 21601 |
end loop; |
| 21602 |
end if; |
| 21603 |
|
| 21604 |
-- If entity in not in current scope it may be the enclosing |
| 21605 |
-- subprogram body to which the aspect applies. |
| 21606 |
|
| 21607 |
elsif Subp = Current_Scope |
| 21608 |
and then From_Aspect_Specification (N) |
| 21609 |
then |
| 21610 |
Set_No_Raise (Subp); |
| 21611 |
|
| 21612 |
else |
| 21613 |
Error_Pragma_Arg |
| 21614 |
("expect local subprogram name for pragma%", Assoc); |
| 21615 |
end if; |
| 21616 |
end if; |
| 21617 |
|
| 21618 |
Next (Assoc); |
| 21619 |
end loop; |
| 21620 |
end Prag_No_Raise; |
| 21621 |
|
| 21622 |
--------------- |
| 21623 |
-- No_Return -- |
| 21624 |
--------------- |
| 21625 |
|
| 21626 |
-- pragma No_Return (procedure_LOCAL_NAME {, procedure_LOCAL_NAME}); |
| 21627 |
|
| 21628 |
when Pragma_No_Return => Prag_No_Return : declare |
| 21629 |
|
| 21630 |
function Check_No_Return |
| 21631 |
(E : Entity_Id; |
| 21632 |
N : Node_Id) return Boolean; |
| 21633 |
-- Check rule 6.5.1(4/3) of the Ada RM. If the rule is violated, |
| 21634 |
-- emit an error message and return False, otherwise return True. |
| 21635 |
-- 6.5.1 Nonreturning procedures: |
| 21636 |
-- 4/3 "Aspect No_Return shall not be specified for a null |
| 21637 |
-- procedure nor an instance of a generic unit." |
| 21638 |
|
| 21639 |
--------------------- |
| 21640 |
-- Check_No_Return -- |
| 21641 |
--------------------- |
| 21642 |
|
| 21643 |
function Check_No_Return |
| 21644 |
(E : Entity_Id; |
| 21645 |
N : Node_Id) return Boolean |
| 21646 |
is |
| 21647 |
begin |
| 21648 |
if Ekind (E) in E_Function | E_Generic_Function then |
| 21649 |
Error_Msg_Ada_2022_Feature ("No_Return function", Sloc (N)); |
| 21650 |
return Ada_Version >= Ada_2022; |
| 21651 |
|
| 21652 |
elsif Ekind (E) = E_Procedure then |
| 21653 |
|
| 21654 |
-- If E is a generic instance, marking it with No_Return |
| 21655 |
-- is forbidden, but having it inherit the No_Return of |
| 21656 |
-- the generic is allowed. We check if E is inheriting its |
| 21657 |
-- No_Return flag from the generic by checking if No_Return |
| 21658 |
-- is already set. |
| 21659 |
|
| 21660 |
if Is_Generic_Instance (E) and then not No_Return (E) then |
| 21661 |
Error_Msg_NE |
| 21662 |
("generic instance & is marked as No_Return", N, E); |
| 21663 |
Error_Msg_NE |
| 21664 |
("\generic procedure & must be marked No_Return", |
| 21665 |
N, |
| 21666 |
Generic_Parent (Parent (E))); |
| 21667 |
return False; |
| 21668 |
|
| 21669 |
elsif Null_Present (Subprogram_Specification (E)) then |
| 21670 |
Error_Msg_NE |
| 21671 |
("null procedure & cannot be marked No_Return", N, E); |
| 21672 |
return False; |
| 21673 |
end if; |
| 21674 |
end if; |
| 21675 |
|
| 21676 |
return True; |
| 21677 |
end Check_No_Return; |
| 21678 |
|
| 21679 |
Arg : Node_Id; |
| 21680 |
E : Entity_Id; |
| 21681 |
Found : Boolean; |
| 21682 |
Id : Node_Id; |
| 21683 |
|
| 21684 |
Ghost_Error_Posted : Boolean := False; |
| 21685 |
-- Flag set when an error concerning the illegal mix of Ghost and |
| 21686 |
-- non-Ghost subprograms is emitted. |
| 21687 |
|
| 21688 |
Ghost_Id : Entity_Id := Empty; |
| 21689 |
-- The entity of the first Ghost procedure encountered while |
| 21690 |
-- processing the arguments of the pragma. |
| 21691 |
|
| 21692 |
begin |
| 21693 |
Ada_2005_Pragma; |
| 21694 |
Check_At_Least_N_Arguments (1); |
| 21695 |
|
| 21696 |
-- Loop through arguments of pragma |
| 21697 |
|
| 21698 |
Arg := Arg1; |
| 21699 |
while Present (Arg) loop |
| 21700 |
Check_Arg_Is_Local_Name (Arg); |
| 21701 |
Id := Get_Pragma_Arg (Arg); |
| 21702 |
Analyze (Id); |
| 21703 |
|
| 21704 |
if not Is_Entity_Name (Id) then |
| 21705 |
Error_Pragma_Arg ("entity name required", Arg); |
| 21706 |
end if; |
| 21707 |
|
| 21708 |
if Etype (Id) = Any_Type then |
| 21709 |
raise Pragma_Exit; |
| 21710 |
end if; |
| 21711 |
|
| 21712 |
Found := False; |
| 21713 |
-- Loop to find matching procedures or functions (Ada 2022) |
| 21714 |
|
| 21715 |
Outer_Loop : |
| 21716 |
for Process_Functions in Boolean loop |
| 21717 |
|
| 21718 |
-- We make two passes over the Homonym list, first looking |
| 21719 |
-- at procedures and then at functions. This is done |
| 21720 |
-- in order to get the desired behavior in the pre-Ada2022 |
| 21721 |
-- case. There are two subcases of the pre-Ada2022 case - |
| 21722 |
-- either we found a non-function candidate in the first |
| 21723 |
-- pass or we didn't. If we found one, then exit early |
| 21724 |
-- (i.e., skip the second pass); we want to silently ignore |
| 21725 |
-- any functions. But if we didn't find one then we do not |
| 21726 |
-- want to exit early because looking at functions will |
| 21727 |
-- allow us (if we find one) to generate a more useful |
| 21728 |
-- error message ("this is an Ada 2022 construct" instead of |
| 21729 |
-- "name could not be resolved"). |
| 21730 |
|
| 21731 |
exit Outer_Loop when Found and Ada_Version < Ada_2022; |
| 21732 |
|
| 21733 |
E := Entity (Id); |
| 21734 |
|
| 21735 |
while Present (E) |
| 21736 |
and then Scope (E) = Current_Scope |
| 21737 |
loop |
| 21738 |
-- Ada 2022 (AI12-0269): A function can be No_Return |
| 21739 |
|
| 21740 |
if (if Process_Functions |
| 21741 |
then Ekind (E) in E_Generic_Function | E_Function |
| 21742 |
else Ekind (E) in E_Generic_Procedure | E_Procedure) |
| 21743 |
|
| 21744 |
-- if From_Aspect_Specification, then only one |
| 21745 |
-- candidate should be considered. |
| 21746 |
|
| 21747 |
and then (not From_Aspect_Specification (N) |
| 21748 |
or else E = Entity (Id) |
| 21749 |
or else No (Entity (Id))) |
| 21750 |
|
| 21751 |
then |
| 21752 |
-- Check that the pragma is not applied to a body. |
| 21753 |
-- First check the specless body case, to give a |
| 21754 |
-- different error message. These checks do not apply |
| 21755 |
-- if Relaxed_RM_Semantics, to accommodate other Ada |
| 21756 |
-- compilers. Disable these checks under -gnatd.J. |
| 21757 |
|
| 21758 |
if not Debug_Flag_Dot_JJ then |
| 21759 |
if Nkind (Parent (Declaration_Node (E))) = |
| 21760 |
N_Subprogram_Body |
| 21761 |
and then not Relaxed_RM_Semantics |
| 21762 |
then |
| 21763 |
Error_Pragma |
| 21764 |
("pragma% requires separate spec and must " |
| 21765 |
& "come before body"); |
| 21766 |
end if; |
| 21767 |
|
| 21768 |
-- Now the "specful" body case |
| 21769 |
|
| 21770 |
if Rep_Item_Too_Late (E, N) then |
| 21771 |
raise Pragma_Exit; |
| 21772 |
end if; |
| 21773 |
end if; |
| 21774 |
|
| 21775 |
if Check_No_Return (E, N) then |
| 21776 |
Set_No_Return (E); |
| 21777 |
end if; |
| 21778 |
|
| 21779 |
-- A pragma that applies to a Ghost entity becomes |
| 21780 |
-- Ghost for the purposes of legality checks and |
| 21781 |
-- removal of ignored Ghost code. |
| 21782 |
|
| 21783 |
Mark_Ghost_Pragma (N, E); |
| 21784 |
|
| 21785 |
-- Capture the entity of the first Ghost procedure |
| 21786 |
-- being processed for error detection purposes. |
| 21787 |
|
| 21788 |
if Is_Ghost_Entity (E) then |
| 21789 |
if No (Ghost_Id) then |
| 21790 |
Ghost_Id := E; |
| 21791 |
end if; |
| 21792 |
|
| 21793 |
-- Otherwise the subprogram is non-Ghost. It is |
| 21794 |
-- illegal to mix references to Ghost and non-Ghost |
| 21795 |
-- entities (SPARK RM 6.9). |
| 21796 |
|
| 21797 |
elsif Present (Ghost_Id) |
| 21798 |
and then not Ghost_Error_Posted |
| 21799 |
then |
| 21800 |
Ghost_Error_Posted := True; |
| 21801 |
|
| 21802 |
Error_Msg_Name_1 := Pname; |
| 21803 |
Error_Msg_N |
| 21804 |
("pragma % cannot mention ghost and non-ghost " |
| 21805 |
& "procedures", N); |
| 21806 |
|
| 21807 |
Error_Msg_Sloc := Sloc (Ghost_Id); |
| 21808 |
Error_Msg_NE |
| 21809 |
("\& # declared as ghost", N, Ghost_Id); |
| 21810 |
|
| 21811 |
Error_Msg_Sloc := Sloc (E); |
| 21812 |
Error_Msg_NE ("\& # declared as non-ghost", N, E); |
| 21813 |
end if; |
| 21814 |
|
| 21815 |
-- Set flag on any alias as well |
| 21816 |
|
| 21817 |
if Is_Overloadable (E) |
| 21818 |
and then Present (Alias (E)) |
| 21819 |
and then Check_No_Return (Alias (E), N) |
| 21820 |
then |
| 21821 |
Set_No_Return (Alias (E)); |
| 21822 |
end if; |
| 21823 |
|
| 21824 |
Found := True; |
| 21825 |
end if; |
| 21826 |
|
| 21827 |
E := Homonym (E); |
| 21828 |
end loop; |
| 21829 |
end loop Outer_Loop; |
| 21830 |
|
| 21831 |
-- If entity in not in current scope it may be the enclosing |
| 21832 |
-- subprogram body to which the aspect applies. |
| 21833 |
|
| 21834 |
if not Found then |
| 21835 |
if Entity (Id) = Current_Scope |
| 21836 |
and then From_Aspect_Specification (N) |
| 21837 |
and then Check_No_Return (Entity (Id), N) |
| 21838 |
then |
| 21839 |
Set_No_Return (Entity (Id)); |
| 21840 |
|
| 21841 |
elsif Ada_Version >= Ada_2022 then |
| 21842 |
Error_Pragma_Arg |
| 21843 |
("no subprogram& found for pragma%", Arg); |
| 21844 |
|
| 21845 |
else |
| 21846 |
Error_Pragma_Arg ("no procedure& found for pragma%", Arg); |
| 21847 |
end if; |
| 21848 |
end if; |
| 21849 |
|
| 21850 |
Next (Arg); |
| 21851 |
end loop; |
| 21852 |
end Prag_No_Return; |
| 21853 |
|
| 21854 |
----------------- |
| 21855 |
-- No_Run_Time -- |
| 21856 |
----------------- |
| 21857 |
|
| 21858 |
-- pragma No_Run_Time; |
| 21859 |
|
| 21860 |
-- Note: this pragma is retained for backwards compatibility. See |
| 21861 |
-- body of Rtsfind for full details on its handling. |
| 21862 |
|
| 21863 |
when Pragma_No_Run_Time => |
| 21864 |
GNAT_Pragma; |
| 21865 |
Check_Valid_Configuration_Pragma; |
| 21866 |
Check_Arg_Count (0); |
| 21867 |
|
| 21868 |
-- Remove backward compatibility if Build_Type is FSF or GPL and |
| 21869 |
-- generate a warning. |
| 21870 |
|
| 21871 |
declare |
| 21872 |
Ignore : constant Boolean := Build_Type in FSF .. GPL; |
| 21873 |
begin |
| 21874 |
if Ignore then |
| 21875 |
Error_Pragma ("pragma% is ignored, has no effect??"); |
| 21876 |
else |
| 21877 |
No_Run_Time_Mode := True; |
| 21878 |
Configurable_Run_Time_Mode := True; |
| 21879 |
|
| 21880 |
-- Set Duration to 32 bits if word size is 32 |
| 21881 |
|
| 21882 |
if Ttypes.System_Word_Size = 32 then |
| 21883 |
Duration_32_Bits_On_Target := True; |
| 21884 |
end if; |
| 21885 |
|
| 21886 |
-- Set appropriate restrictions |
| 21887 |
|
| 21888 |
Set_Restriction (No_Finalization, N); |
| 21889 |
Set_Restriction (No_Exception_Handlers, N); |
| 21890 |
Set_Restriction (Max_Tasks, N, 0); |
| 21891 |
Set_Restriction (No_Tasking, N); |
| 21892 |
end if; |
| 21893 |
end; |
| 21894 |
|
| 21895 |
---------------------------------- |
| 21896 |
-- Interrupts_System_By_Default -- |
| 21897 |
---------------------------------- |
| 21898 |
|
| 21899 |
-- pragma Interrupts_System_By_Default; |
| 21900 |
|
| 21901 |
when Pragma_Interrupts_System_By_Default => |
| 21902 |
GNAT_Pragma; |
| 21903 |
Check_Arg_Count (0); |
| 21904 |
Check_Valid_Configuration_Pragma; |
| 21905 |
Interrupts_System_By_Default := True; |
| 21906 |
|
| 21907 |
----------------------- |
| 21908 |
-- No_Tagged_Streams -- |
| 21909 |
----------------------- |
| 21910 |
|
| 21911 |
-- pragma No_Tagged_Streams [([Entity => ]tagged_type_local_NAME)]; |
| 21912 |
|
| 21913 |
when Pragma_No_Tagged_Streams => No_Tagged_Strms : declare |
| 21914 |
E : Entity_Id; |
| 21915 |
E_Id : Node_Id; |
| 21916 |
|
| 21917 |
begin |
| 21918 |
GNAT_Pragma; |
| 21919 |
Check_At_Most_N_Arguments (1); |
| 21920 |
|
| 21921 |
-- One argument case |
| 21922 |
|
| 21923 |
if Arg_Count = 1 then |
| 21924 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 21925 |
Check_Arg_Is_Local_Name (Arg1); |
| 21926 |
E_Id := Get_Pragma_Arg (Arg1); |
| 21927 |
|
| 21928 |
if Etype (E_Id) = Any_Type then |
| 21929 |
return; |
| 21930 |
end if; |
| 21931 |
|
| 21932 |
E := Entity (E_Id); |
| 21933 |
|
| 21934 |
Check_Duplicate_Pragma (E); |
| 21935 |
|
| 21936 |
if not Is_Tagged_Type (E) or else Is_Derived_Type (E) then |
| 21937 |
Error_Pragma_Arg |
| 21938 |
("argument for pragma% must be root tagged type", Arg1); |
| 21939 |
end if; |
| 21940 |
|
| 21941 |
if Rep_Item_Too_Early (E, N) |
| 21942 |
or else |
| 21943 |
Rep_Item_Too_Late (E, N) |
| 21944 |
then |
| 21945 |
return; |
| 21946 |
else |
| 21947 |
Set_No_Tagged_Streams_Pragma (E, N); |
| 21948 |
end if; |
| 21949 |
|
| 21950 |
-- Zero argument case |
| 21951 |
|
| 21952 |
else |
| 21953 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 21954 |
No_Tagged_Streams := N; |
| 21955 |
end if; |
| 21956 |
end No_Tagged_Strms; |
| 21957 |
|
| 21958 |
------------------------ |
| 21959 |
-- No_Strict_Aliasing -- |
| 21960 |
------------------------ |
| 21961 |
|
| 21962 |
-- pragma No_Strict_Aliasing [([Entity =>] type_LOCAL_NAME)]; |
| 21963 |
|
| 21964 |
when Pragma_No_Strict_Aliasing => No_Strict_Aliasing : declare |
| 21965 |
E : Entity_Id; |
| 21966 |
E_Id : Node_Id; |
| 21967 |
|
| 21968 |
begin |
| 21969 |
GNAT_Pragma; |
| 21970 |
Check_At_Most_N_Arguments (1); |
| 21971 |
|
| 21972 |
if Arg_Count = 0 then |
| 21973 |
Check_Valid_Configuration_Pragma; |
| 21974 |
Opt.No_Strict_Aliasing := True; |
| 21975 |
|
| 21976 |
else |
| 21977 |
Check_Optional_Identifier (Arg2, Name_Entity); |
| 21978 |
Check_Arg_Is_Local_Name (Arg1); |
| 21979 |
E_Id := Get_Pragma_Arg (Arg1); |
| 21980 |
|
| 21981 |
if Etype (E_Id) = Any_Type then |
| 21982 |
return; |
| 21983 |
end if; |
| 21984 |
|
| 21985 |
E := Entity (E_Id); |
| 21986 |
|
| 21987 |
if not Is_Access_Type (E) then |
| 21988 |
Error_Pragma_Arg ("pragma% requires access type", Arg1); |
| 21989 |
end if; |
| 21990 |
|
| 21991 |
Set_No_Strict_Aliasing (Base_Type (E)); |
| 21992 |
end if; |
| 21993 |
end No_Strict_Aliasing; |
| 21994 |
|
| 21995 |
----------------------- |
| 21996 |
-- Normalize_Scalars -- |
| 21997 |
----------------------- |
| 21998 |
|
| 21999 |
-- pragma Normalize_Scalars; |
| 22000 |
|
| 22001 |
when Pragma_Normalize_Scalars => |
| 22002 |
Check_Ada_83_Warning; |
| 22003 |
Check_Arg_Count (0); |
| 22004 |
Check_Valid_Configuration_Pragma; |
| 22005 |
|
| 22006 |
-- Normalize_Scalars creates false positives in CodePeer, and |
| 22007 |
-- incorrect negative results in GNATprove mode, so ignore this |
| 22008 |
-- pragma in these modes. |
| 22009 |
|
| 22010 |
if not (CodePeer_Mode or GNATprove_Mode) then |
| 22011 |
Normalize_Scalars := True; |
| 22012 |
Init_Or_Norm_Scalars := True; |
| 22013 |
end if; |
| 22014 |
|
| 22015 |
----------------- |
| 22016 |
-- Obsolescent -- |
| 22017 |
----------------- |
| 22018 |
|
| 22019 |
-- pragma Obsolescent; |
| 22020 |
|
| 22021 |
-- pragma Obsolescent ( |
| 22022 |
-- [Message =>] static_string_EXPRESSION |
| 22023 |
-- [,[Version =>] Ada_05]); |
| 22024 |
|
| 22025 |
-- pragma Obsolescent ( |
| 22026 |
-- [Entity =>] NAME |
| 22027 |
-- [,[Message =>] static_string_EXPRESSION |
| 22028 |
-- [,[Version =>] Ada_05]]); |
| 22029 |
|
| 22030 |
when Pragma_Obsolescent => Obsolescent : declare |
| 22031 |
Decl : Node_Id; |
| 22032 |
Ename : Node_Id; |
| 22033 |
|
| 22034 |
procedure Set_Obsolescent (E : Entity_Id); |
| 22035 |
-- Given an entity Ent, mark it as obsolescent if appropriate |
| 22036 |
|
| 22037 |
--------------------- |
| 22038 |
-- Set_Obsolescent -- |
| 22039 |
--------------------- |
| 22040 |
|
| 22041 |
procedure Set_Obsolescent (E : Entity_Id) is |
| 22042 |
Active : Boolean; |
| 22043 |
Ent : Entity_Id; |
| 22044 |
S : String_Id; |
| 22045 |
|
| 22046 |
begin |
| 22047 |
Active := True; |
| 22048 |
Ent := E; |
| 22049 |
|
| 22050 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 22051 |
-- the purposes of legality checks and removal of ignored Ghost |
| 22052 |
-- code. |
| 22053 |
|
| 22054 |
Mark_Ghost_Pragma (N, E); |
| 22055 |
|
| 22056 |
-- Entity name was given |
| 22057 |
|
| 22058 |
if Present (Ename) then |
| 22059 |
|
| 22060 |
-- If entity name matches, we are fine. |
| 22061 |
|
| 22062 |
if Chars (Ename) = Chars (Ent) then |
| 22063 |
Set_Entity (Ename, Ent); |
| 22064 |
Generate_Reference (Ent, Ename); |
| 22065 |
|
| 22066 |
-- If entity name does not match, only possibility is an |
| 22067 |
-- enumeration literal from an enumeration type declaration. |
| 22068 |
|
| 22069 |
elsif Ekind (Ent) /= E_Enumeration_Type then |
| 22070 |
Error_Pragma |
| 22071 |
("pragma % entity name does not match declaration"); |
| 22072 |
|
| 22073 |
else |
| 22074 |
Ent := First_Literal (E); |
| 22075 |
loop |
| 22076 |
if No (Ent) then |
| 22077 |
Error_Pragma |
| 22078 |
("pragma % entity name does not match any " |
| 22079 |
& "enumeration literal"); |
| 22080 |
|
| 22081 |
elsif Chars (Ent) = Chars (Ename) then |
| 22082 |
Set_Entity (Ename, Ent); |
| 22083 |
Generate_Reference (Ent, Ename); |
| 22084 |
exit; |
| 22085 |
|
| 22086 |
else |
| 22087 |
Next_Literal (Ent); |
| 22088 |
end if; |
| 22089 |
end loop; |
| 22090 |
end if; |
| 22091 |
end if; |
| 22092 |
|
| 22093 |
-- Ent points to entity to be marked |
| 22094 |
|
| 22095 |
if Arg_Count >= 1 then |
| 22096 |
|
| 22097 |
-- Deal with static string argument |
| 22098 |
|
| 22099 |
Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String); |
| 22100 |
S := Strval (Get_Pragma_Arg (Arg1)); |
| 22101 |
|
| 22102 |
for J in 1 .. String_Length (S) loop |
| 22103 |
if not In_Character_Range (Get_String_Char (S, J)) then |
| 22104 |
Error_Pragma_Arg |
| 22105 |
("pragma% argument does not allow wide characters", |
| 22106 |
Arg1); |
| 22107 |
end if; |
| 22108 |
end loop; |
| 22109 |
|
| 22110 |
Obsolescent_Warnings.Append |
| 22111 |
((Ent => Ent, Msg => Strval (Get_Pragma_Arg (Arg1)))); |
| 22112 |
|
| 22113 |
-- Check for Ada_05 parameter |
| 22114 |
|
| 22115 |
if Arg_Count /= 1 then |
| 22116 |
Check_Arg_Count (2); |
| 22117 |
|
| 22118 |
declare |
| 22119 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg2); |
| 22120 |
|
| 22121 |
begin |
| 22122 |
Check_Arg_Is_Identifier (Argx); |
| 22123 |
|
| 22124 |
if Chars (Argx) /= Name_Ada_05 then |
| 22125 |
Error_Msg_Name_2 := Name_Ada_05; |
| 22126 |
Error_Pragma_Arg |
| 22127 |
("only allowed argument for pragma% is %", Argx); |
| 22128 |
end if; |
| 22129 |
|
| 22130 |
if Ada_Version_Explicit < Ada_2005 |
| 22131 |
or else not Warn_On_Ada_2005_Compatibility |
| 22132 |
then |
| 22133 |
Active := False; |
| 22134 |
end if; |
| 22135 |
end; |
| 22136 |
end if; |
| 22137 |
end if; |
| 22138 |
|
| 22139 |
-- Set flag if pragma active |
| 22140 |
|
| 22141 |
if Active then |
| 22142 |
Set_Is_Obsolescent (Ent); |
| 22143 |
end if; |
| 22144 |
|
| 22145 |
return; |
| 22146 |
end Set_Obsolescent; |
| 22147 |
|
| 22148 |
-- Start of processing for pragma Obsolescent |
| 22149 |
|
| 22150 |
begin |
| 22151 |
GNAT_Pragma; |
| 22152 |
|
| 22153 |
Check_At_Most_N_Arguments (3); |
| 22154 |
|
| 22155 |
-- See if first argument specifies an entity name |
| 22156 |
|
| 22157 |
if Arg_Count >= 1 |
| 22158 |
and then |
| 22159 |
(Chars (Arg1) = Name_Entity |
| 22160 |
or else |
| 22161 |
Nkind (Get_Pragma_Arg (Arg1)) in |
| 22162 |
N_Character_Literal | N_Identifier | N_Operator_Symbol) |
| 22163 |
then |
| 22164 |
Ename := Get_Pragma_Arg (Arg1); |
| 22165 |
|
| 22166 |
-- Eliminate first argument, so we can share processing |
| 22167 |
|
| 22168 |
Arg1 := Arg2; |
| 22169 |
Arg2 := Arg3; |
| 22170 |
Arg_Count := Arg_Count - 1; |
| 22171 |
|
| 22172 |
-- No Entity name argument given |
| 22173 |
|
| 22174 |
else |
| 22175 |
Ename := Empty; |
| 22176 |
end if; |
| 22177 |
|
| 22178 |
if Arg_Count >= 1 then |
| 22179 |
Check_Optional_Identifier (Arg1, Name_Message); |
| 22180 |
|
| 22181 |
if Arg_Count = 2 then |
| 22182 |
Check_Optional_Identifier (Arg2, Name_Version); |
| 22183 |
end if; |
| 22184 |
end if; |
| 22185 |
|
| 22186 |
-- Get immediately preceding declaration |
| 22187 |
|
| 22188 |
Decl := Prev (N); |
| 22189 |
while Present (Decl) and then Nkind (Decl) = N_Pragma loop |
| 22190 |
Prev (Decl); |
| 22191 |
end loop; |
| 22192 |
|
| 22193 |
-- Cases where we do not follow anything other than another pragma |
| 22194 |
|
| 22195 |
if No (Decl) then |
| 22196 |
|
| 22197 |
-- Case 0: library level compilation unit declaration with |
| 22198 |
-- the pragma preceding the declaration. |
| 22199 |
|
| 22200 |
if Nkind (Parent (N)) = N_Compilation_Unit then |
| 22201 |
Pragma_Misplaced; |
| 22202 |
|
| 22203 |
-- Case 1: library level compilation unit declaration with |
| 22204 |
-- the pragma immediately following the declaration. |
| 22205 |
|
| 22206 |
elsif Nkind (Parent (N)) = N_Compilation_Unit_Aux then |
| 22207 |
Set_Obsolescent |
| 22208 |
(Defining_Entity (Unit (Parent (Parent (N))))); |
| 22209 |
return; |
| 22210 |
|
| 22211 |
-- Case 2: library unit placement for package |
| 22212 |
|
| 22213 |
else |
| 22214 |
declare |
| 22215 |
Ent : constant Entity_Id := Find_Lib_Unit_Name; |
| 22216 |
begin |
| 22217 |
if Is_Package_Or_Generic_Package (Ent) then |
| 22218 |
Set_Obsolescent (Ent); |
| 22219 |
return; |
| 22220 |
end if; |
| 22221 |
end; |
| 22222 |
end if; |
| 22223 |
|
| 22224 |
-- Cases where we must follow a declaration, including an |
| 22225 |
-- abstract subprogram declaration, which is not in the |
| 22226 |
-- other node subtypes. |
| 22227 |
|
| 22228 |
else |
| 22229 |
if Nkind (Decl) not in N_Declaration |
| 22230 |
and then Nkind (Decl) not in N_Later_Decl_Item |
| 22231 |
and then Nkind (Decl) not in N_Generic_Declaration |
| 22232 |
and then Nkind (Decl) not in N_Renaming_Declaration |
| 22233 |
and then Nkind (Decl) /= N_Abstract_Subprogram_Declaration |
| 22234 |
then |
| 22235 |
Error_Pragma |
| 22236 |
("pragma% misplaced, " |
| 22237 |
& "must immediately follow a declaration"); |
| 22238 |
|
| 22239 |
else |
| 22240 |
Set_Obsolescent (Defining_Entity (Decl)); |
| 22241 |
return; |
| 22242 |
end if; |
| 22243 |
end if; |
| 22244 |
end Obsolescent; |
| 22245 |
|
| 22246 |
-------------- |
| 22247 |
-- Optimize -- |
| 22248 |
-------------- |
| 22249 |
|
| 22250 |
-- pragma Optimize (Time | Space | Off); |
| 22251 |
|
| 22252 |
-- The actual check for optimize is done in Gigi. Note that this |
| 22253 |
-- pragma does not actually change the optimization setting, it |
| 22254 |
-- simply checks that it is consistent with the pragma. |
| 22255 |
|
| 22256 |
when Pragma_Optimize => |
| 22257 |
Check_No_Identifiers; |
| 22258 |
Check_Arg_Count (1); |
| 22259 |
Check_Arg_Is_One_Of (Arg1, Name_Time, Name_Space, Name_Off); |
| 22260 |
|
| 22261 |
------------------------ |
| 22262 |
-- Optimize_Alignment -- |
| 22263 |
------------------------ |
| 22264 |
|
| 22265 |
-- pragma Optimize_Alignment (Time | Space | Off); |
| 22266 |
|
| 22267 |
when Pragma_Optimize_Alignment => Optimize_Alignment : begin |
| 22268 |
GNAT_Pragma; |
| 22269 |
Check_No_Identifiers; |
| 22270 |
Check_Arg_Count (1); |
| 22271 |
Check_Valid_Configuration_Pragma; |
| 22272 |
|
| 22273 |
declare |
| 22274 |
Nam : constant Name_Id := Chars (Get_Pragma_Arg (Arg1)); |
| 22275 |
begin |
| 22276 |
case Nam is |
| 22277 |
when Name_Off => Opt.Optimize_Alignment := 'O'; |
| 22278 |
when Name_Space => Opt.Optimize_Alignment := 'S'; |
| 22279 |
when Name_Time => Opt.Optimize_Alignment := 'T'; |
| 22280 |
|
| 22281 |
when others => |
| 22282 |
Error_Pragma_Arg ("invalid argument for pragma%", Arg1); |
| 22283 |
end case; |
| 22284 |
end; |
| 22285 |
|
| 22286 |
-- Set indication that mode is set locally. If we are in fact in a |
| 22287 |
-- configuration pragma file, this setting is harmless since the |
| 22288 |
-- switch will get reset anyway at the start of each unit. |
| 22289 |
|
| 22290 |
Optimize_Alignment_Local := True; |
| 22291 |
end Optimize_Alignment; |
| 22292 |
|
| 22293 |
------------- |
| 22294 |
-- Ordered -- |
| 22295 |
------------- |
| 22296 |
|
| 22297 |
-- pragma Ordered (first_enumeration_subtype_LOCAL_NAME); |
| 22298 |
|
| 22299 |
when Pragma_Ordered => Ordered : declare |
| 22300 |
Assoc : constant Node_Id := Arg1; |
| 22301 |
Type_Id : Node_Id; |
| 22302 |
Typ : Entity_Id; |
| 22303 |
|
| 22304 |
begin |
| 22305 |
GNAT_Pragma; |
| 22306 |
Check_No_Identifiers; |
| 22307 |
Check_Arg_Count (1); |
| 22308 |
Check_Arg_Is_Local_Name (Arg1); |
| 22309 |
|
| 22310 |
Type_Id := Get_Pragma_Arg (Assoc); |
| 22311 |
Find_Type (Type_Id); |
| 22312 |
Typ := Entity (Type_Id); |
| 22313 |
|
| 22314 |
if Typ = Any_Type then |
| 22315 |
return; |
| 22316 |
else |
| 22317 |
Typ := Underlying_Type (Typ); |
| 22318 |
end if; |
| 22319 |
|
| 22320 |
if not Is_Enumeration_Type (Typ) then |
| 22321 |
Error_Pragma ("pragma% must specify enumeration type"); |
| 22322 |
end if; |
| 22323 |
|
| 22324 |
Check_First_Subtype (Arg1); |
| 22325 |
Set_Has_Pragma_Ordered (Base_Type (Typ)); |
| 22326 |
end Ordered; |
| 22327 |
|
| 22328 |
------------------- |
| 22329 |
-- Overflow_Mode -- |
| 22330 |
------------------- |
| 22331 |
|
| 22332 |
-- pragma Overflow_Mode |
| 22333 |
-- ([General => ] MODE [, [Assertions => ] MODE]); |
| 22334 |
|
| 22335 |
-- MODE := STRICT | MINIMIZED | ELIMINATED |
| 22336 |
|
| 22337 |
-- Note: ELIMINATED is allowed only if Long_Long_Integer'Size is 64 |
| 22338 |
-- since System.Bignums makes this assumption. This is true of nearly |
| 22339 |
-- all (all?) targets. |
| 22340 |
|
| 22341 |
when Pragma_Overflow_Mode => Overflow_Mode : declare |
| 22342 |
function Get_Overflow_Mode |
| 22343 |
(Name : Name_Id; |
| 22344 |
Arg : Node_Id) return Overflow_Mode_Type; |
| 22345 |
-- Function to process one pragma argument, Arg. If an identifier |
| 22346 |
-- is present, it must be Name. Mode type is returned if a valid |
| 22347 |
-- argument exists, otherwise an error is signalled. |
| 22348 |
|
| 22349 |
----------------------- |
| 22350 |
-- Get_Overflow_Mode -- |
| 22351 |
----------------------- |
| 22352 |
|
| 22353 |
function Get_Overflow_Mode |
| 22354 |
(Name : Name_Id; |
| 22355 |
Arg : Node_Id) return Overflow_Mode_Type |
| 22356 |
is |
| 22357 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 22358 |
|
| 22359 |
begin |
| 22360 |
Check_Optional_Identifier (Arg, Name); |
| 22361 |
Check_Arg_Is_Identifier (Argx); |
| 22362 |
|
| 22363 |
if Chars (Argx) = Name_Strict then |
| 22364 |
return Strict; |
| 22365 |
|
| 22366 |
elsif Chars (Argx) = Name_Minimized then |
| 22367 |
return Minimized; |
| 22368 |
|
| 22369 |
elsif Chars (Argx) = Name_Eliminated then |
| 22370 |
if Ttypes.Standard_Long_Long_Integer_Size /= 64 then |
| 22371 |
Error_Pragma_Arg |
| 22372 |
("Eliminated requires Long_Long_Integer'Size = 64", |
| 22373 |
Argx); |
| 22374 |
else |
| 22375 |
return Eliminated; |
| 22376 |
end if; |
| 22377 |
|
| 22378 |
else |
| 22379 |
Error_Pragma_Arg ("invalid argument for pragma%", Argx); |
| 22380 |
end if; |
| 22381 |
end Get_Overflow_Mode; |
| 22382 |
|
| 22383 |
-- Start of processing for Overflow_Mode |
| 22384 |
|
| 22385 |
begin |
| 22386 |
GNAT_Pragma; |
| 22387 |
Check_At_Least_N_Arguments (1); |
| 22388 |
Check_At_Most_N_Arguments (2); |
| 22389 |
|
| 22390 |
-- Process first argument |
| 22391 |
|
| 22392 |
Scope_Suppress.Overflow_Mode_General := |
| 22393 |
Get_Overflow_Mode (Name_General, Arg1); |
| 22394 |
|
| 22395 |
-- Case of only one argument |
| 22396 |
|
| 22397 |
if Arg_Count = 1 then |
| 22398 |
Scope_Suppress.Overflow_Mode_Assertions := |
| 22399 |
Scope_Suppress.Overflow_Mode_General; |
| 22400 |
|
| 22401 |
-- Case of two arguments present |
| 22402 |
|
| 22403 |
else |
| 22404 |
Scope_Suppress.Overflow_Mode_Assertions := |
| 22405 |
Get_Overflow_Mode (Name_Assertions, Arg2); |
| 22406 |
end if; |
| 22407 |
end Overflow_Mode; |
| 22408 |
|
| 22409 |
-------------------------- |
| 22410 |
-- Overriding Renamings -- |
| 22411 |
-------------------------- |
| 22412 |
|
| 22413 |
-- pragma Overriding_Renamings; |
| 22414 |
|
| 22415 |
when Pragma_Overriding_Renamings => |
| 22416 |
GNAT_Pragma; |
| 22417 |
Check_Arg_Count (0); |
| 22418 |
Check_Valid_Configuration_Pragma; |
| 22419 |
Overriding_Renamings := True; |
| 22420 |
|
| 22421 |
---------- |
| 22422 |
-- Pack -- |
| 22423 |
---------- |
| 22424 |
|
| 22425 |
-- pragma Pack (first_subtype_LOCAL_NAME); |
| 22426 |
|
| 22427 |
when Pragma_Pack => Pack : declare |
| 22428 |
Assoc : constant Node_Id := Arg1; |
| 22429 |
Ctyp : Entity_Id; |
| 22430 |
Ignore : Boolean := False; |
| 22431 |
Typ : Entity_Id; |
| 22432 |
Type_Id : Node_Id; |
| 22433 |
|
| 22434 |
begin |
| 22435 |
Check_No_Identifiers; |
| 22436 |
Check_Arg_Count (1); |
| 22437 |
Check_Arg_Is_Local_Name (Arg1); |
| 22438 |
Type_Id := Get_Pragma_Arg (Assoc); |
| 22439 |
|
| 22440 |
if not Is_Entity_Name (Type_Id) |
| 22441 |
or else not Is_Type (Entity (Type_Id)) |
| 22442 |
then |
| 22443 |
Error_Pragma_Arg |
| 22444 |
("argument for pragma% must be type or subtype", Arg1); |
| 22445 |
end if; |
| 22446 |
|
| 22447 |
Find_Type (Type_Id); |
| 22448 |
Typ := Entity (Type_Id); |
| 22449 |
|
| 22450 |
if Typ = Any_Type |
| 22451 |
or else Rep_Item_Too_Early (Typ, N) |
| 22452 |
then |
| 22453 |
return; |
| 22454 |
else |
| 22455 |
Typ := Underlying_Type (Typ); |
| 22456 |
end if; |
| 22457 |
|
| 22458 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 22459 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 22460 |
|
| 22461 |
Mark_Ghost_Pragma (N, Typ); |
| 22462 |
|
| 22463 |
if not Is_Array_Type (Typ) and then not Is_Record_Type (Typ) then |
| 22464 |
Error_Pragma ("pragma% must specify array or record type"); |
| 22465 |
end if; |
| 22466 |
|
| 22467 |
Check_First_Subtype (Arg1); |
| 22468 |
Check_Duplicate_Pragma (Typ); |
| 22469 |
|
| 22470 |
-- Array type |
| 22471 |
|
| 22472 |
if Is_Array_Type (Typ) then |
| 22473 |
Ctyp := Component_Type (Typ); |
| 22474 |
|
| 22475 |
-- Ignore pack that does nothing |
| 22476 |
|
| 22477 |
if Known_Static_Esize (Ctyp) |
| 22478 |
and then Known_Static_RM_Size (Ctyp) |
| 22479 |
and then Esize (Ctyp) = RM_Size (Ctyp) |
| 22480 |
and then Addressable (Esize (Ctyp)) |
| 22481 |
then |
| 22482 |
Ignore := True; |
| 22483 |
end if; |
| 22484 |
|
| 22485 |
-- Process OK pragma Pack. Note that if there is a separate |
| 22486 |
-- component clause present, the Pack will be cancelled. This |
| 22487 |
-- processing is in Freeze. |
| 22488 |
|
| 22489 |
if not Rep_Item_Too_Late (Typ, N) then |
| 22490 |
|
| 22491 |
-- In CodePeer mode, we do not need complex front-end |
| 22492 |
-- expansions related to pragma Pack, so disable handling |
| 22493 |
-- of pragma Pack. |
| 22494 |
|
| 22495 |
if CodePeer_Mode then |
| 22496 |
null; |
| 22497 |
|
| 22498 |
-- Normal case where we do the pack action |
| 22499 |
|
| 22500 |
else |
| 22501 |
if not Ignore then |
| 22502 |
Set_Is_Packed (Base_Type (Typ)); |
| 22503 |
Set_Has_Non_Standard_Rep (Base_Type (Typ)); |
| 22504 |
end if; |
| 22505 |
|
| 22506 |
Set_Has_Pragma_Pack (Base_Type (Typ)); |
| 22507 |
end if; |
| 22508 |
end if; |
| 22509 |
|
| 22510 |
-- For record types, the pack is always effective |
| 22511 |
|
| 22512 |
else pragma Assert (Is_Record_Type (Typ)); |
| 22513 |
if not Rep_Item_Too_Late (Typ, N) then |
| 22514 |
Set_Is_Packed (Base_Type (Typ)); |
| 22515 |
Set_Has_Pragma_Pack (Base_Type (Typ)); |
| 22516 |
Set_Has_Non_Standard_Rep (Base_Type (Typ)); |
| 22517 |
end if; |
| 22518 |
end if; |
| 22519 |
end Pack; |
| 22520 |
|
| 22521 |
---------- |
| 22522 |
-- Page -- |
| 22523 |
---------- |
| 22524 |
|
| 22525 |
-- pragma Page; |
| 22526 |
|
| 22527 |
-- There is nothing to do here, since we did all the processing for |
| 22528 |
-- this pragma in Par.Prag (so that it works properly even in syntax |
| 22529 |
-- only mode). |
| 22530 |
|
| 22531 |
when Pragma_Page => |
| 22532 |
null; |
| 22533 |
|
| 22534 |
------------- |
| 22535 |
-- Part_Of -- |
| 22536 |
------------- |
| 22537 |
|
| 22538 |
-- pragma Part_Of (ABSTRACT_STATE); |
| 22539 |
|
| 22540 |
-- ABSTRACT_STATE ::= NAME |
| 22541 |
|
| 22542 |
when Pragma_Part_Of => Part_Of : declare |
| 22543 |
procedure Propagate_Part_Of |
| 22544 |
(Pack_Id : Entity_Id; |
| 22545 |
State_Id : Entity_Id; |
| 22546 |
Instance : Node_Id); |
| 22547 |
-- Propagate the Part_Of indicator to all abstract states and |
| 22548 |
-- objects declared in the visible state space of a package |
| 22549 |
-- denoted by Pack_Id. State_Id is the encapsulating state. |
| 22550 |
-- Instance is the package instantiation node. |
| 22551 |
|
| 22552 |
----------------------- |
| 22553 |
-- Propagate_Part_Of -- |
| 22554 |
----------------------- |
| 22555 |
|
| 22556 |
procedure Propagate_Part_Of |
| 22557 |
(Pack_Id : Entity_Id; |
| 22558 |
State_Id : Entity_Id; |
| 22559 |
Instance : Node_Id) |
| 22560 |
is |
| 22561 |
Has_Item : Boolean := False; |
| 22562 |
-- Flag set when the visible state space contains at least one |
| 22563 |
-- abstract state or variable. |
| 22564 |
|
| 22565 |
procedure Propagate_Part_Of (Pack_Id : Entity_Id); |
| 22566 |
-- Propagate the Part_Of indicator to all abstract states and |
| 22567 |
-- objects declared in the visible state space of a package |
| 22568 |
-- denoted by Pack_Id. |
| 22569 |
|
| 22570 |
----------------------- |
| 22571 |
-- Propagate_Part_Of -- |
| 22572 |
----------------------- |
| 22573 |
|
| 22574 |
procedure Propagate_Part_Of (Pack_Id : Entity_Id) is |
| 22575 |
Constits : Elist_Id; |
| 22576 |
Item_Id : Entity_Id; |
| 22577 |
|
| 22578 |
begin |
| 22579 |
-- Traverse the entity chain of the package and set relevant |
| 22580 |
-- attributes of abstract states and objects declared in the |
| 22581 |
-- visible state space of the package. |
| 22582 |
|
| 22583 |
Item_Id := First_Entity (Pack_Id); |
| 22584 |
while Present (Item_Id) |
| 22585 |
and then not In_Private_Part (Item_Id) |
| 22586 |
loop |
| 22587 |
-- Do not consider internally generated items |
| 22588 |
|
| 22589 |
if not Comes_From_Source (Item_Id) then |
| 22590 |
null; |
| 22591 |
|
| 22592 |
-- Do not consider generic formals or their corresponding |
| 22593 |
-- actuals because they are not part of a visible state. |
| 22594 |
-- Note that both entities are marked as hidden. |
| 22595 |
|
| 22596 |
elsif Is_Hidden (Item_Id) then |
| 22597 |
null; |
| 22598 |
|
| 22599 |
-- The Part_Of indicator turns an abstract state or an |
| 22600 |
-- object into a constituent of the encapsulating state. |
| 22601 |
-- Note that constants are considered here even though |
| 22602 |
-- they may not depend on variable input. This check is |
| 22603 |
-- left to the SPARK prover. |
| 22604 |
|
| 22605 |
elsif Ekind (Item_Id) in |
| 22606 |
E_Abstract_State | E_Constant | E_Variable |
| 22607 |
then |
| 22608 |
Has_Item := True; |
| 22609 |
Constits := Part_Of_Constituents (State_Id); |
| 22610 |
|
| 22611 |
if No (Constits) then |
| 22612 |
Constits := New_Elmt_List; |
| 22613 |
Set_Part_Of_Constituents (State_Id, Constits); |
| 22614 |
end if; |
| 22615 |
|
| 22616 |
Append_Elmt (Item_Id, Constits); |
| 22617 |
Set_Encapsulating_State (Item_Id, State_Id); |
| 22618 |
|
| 22619 |
-- Recursively handle nested packages and instantiations |
| 22620 |
|
| 22621 |
elsif Ekind (Item_Id) = E_Package then |
| 22622 |
Propagate_Part_Of (Item_Id); |
| 22623 |
end if; |
| 22624 |
|
| 22625 |
Next_Entity (Item_Id); |
| 22626 |
end loop; |
| 22627 |
end Propagate_Part_Of; |
| 22628 |
|
| 22629 |
-- Start of processing for Propagate_Part_Of |
| 22630 |
|
| 22631 |
begin |
| 22632 |
Propagate_Part_Of (Pack_Id); |
| 22633 |
|
| 22634 |
-- Detect a package instantiation that is subject to a Part_Of |
| 22635 |
-- indicator, but has no visible state. |
| 22636 |
|
| 22637 |
if not Has_Item then |
| 22638 |
SPARK_Msg_NE |
| 22639 |
("package instantiation & has Part_Of indicator but " |
| 22640 |
& "lacks visible state", Instance, Pack_Id); |
| 22641 |
end if; |
| 22642 |
end Propagate_Part_Of; |
| 22643 |
|
| 22644 |
-- Local variables |
| 22645 |
|
| 22646 |
Constits : Elist_Id; |
| 22647 |
Encap : Node_Id; |
| 22648 |
Encap_Id : Entity_Id; |
| 22649 |
Item_Id : Entity_Id; |
| 22650 |
Legal : Boolean; |
| 22651 |
Stmt : Node_Id; |
| 22652 |
|
| 22653 |
-- Start of processing for Part_Of |
| 22654 |
|
| 22655 |
begin |
| 22656 |
GNAT_Pragma; |
| 22657 |
Check_No_Identifiers; |
| 22658 |
Check_Arg_Count (1); |
| 22659 |
|
| 22660 |
Stmt := Find_Related_Context (N, Do_Checks => True); |
| 22661 |
|
| 22662 |
-- Object declaration |
| 22663 |
|
| 22664 |
if Nkind (Stmt) = N_Object_Declaration then |
| 22665 |
null; |
| 22666 |
|
| 22667 |
-- Package instantiation |
| 22668 |
|
| 22669 |
elsif Nkind (Stmt) = N_Package_Instantiation then |
| 22670 |
null; |
| 22671 |
|
| 22672 |
-- Single concurrent type declaration |
| 22673 |
|
| 22674 |
elsif Is_Single_Concurrent_Type_Declaration (Stmt) then |
| 22675 |
null; |
| 22676 |
|
| 22677 |
-- Otherwise the pragma is associated with an illegal construct |
| 22678 |
|
| 22679 |
else |
| 22680 |
Pragma_Misplaced; |
| 22681 |
end if; |
| 22682 |
|
| 22683 |
-- Extract the entity of the related object declaration or package |
| 22684 |
-- instantiation. In the case of the instantiation, use the entity |
| 22685 |
-- of the instance spec. |
| 22686 |
|
| 22687 |
if Nkind (Stmt) = N_Package_Instantiation then |
| 22688 |
Stmt := Instance_Spec (Stmt); |
| 22689 |
end if; |
| 22690 |
|
| 22691 |
Item_Id := Defining_Entity (Stmt); |
| 22692 |
|
| 22693 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 22694 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 22695 |
|
| 22696 |
Mark_Ghost_Pragma (N, Item_Id); |
| 22697 |
|
| 22698 |
-- Chain the pragma on the contract for further processing by |
| 22699 |
-- Analyze_Part_Of_In_Decl_Part or for completeness. |
| 22700 |
|
| 22701 |
Add_Contract_Item (N, Item_Id); |
| 22702 |
|
| 22703 |
-- A variable may act as constituent of a single concurrent type |
| 22704 |
-- which in turn could be declared after the variable. Due to this |
| 22705 |
-- discrepancy, the full analysis of indicator Part_Of is delayed |
| 22706 |
-- until the end of the enclosing declarative region (see routine |
| 22707 |
-- Analyze_Part_Of_In_Decl_Part). |
| 22708 |
|
| 22709 |
if Ekind (Item_Id) = E_Variable then |
| 22710 |
null; |
| 22711 |
|
| 22712 |
-- Otherwise indicator Part_Of applies to a constant or a package |
| 22713 |
-- instantiation. |
| 22714 |
|
| 22715 |
else |
| 22716 |
Encap := Get_Pragma_Arg (Arg1); |
| 22717 |
|
| 22718 |
-- Detect any discrepancies between the placement of the |
| 22719 |
-- constant or package instantiation with respect to state |
| 22720 |
-- space and the encapsulating state. |
| 22721 |
|
| 22722 |
Analyze_Part_Of |
| 22723 |
(Indic => N, |
| 22724 |
Item_Id => Item_Id, |
| 22725 |
Encap => Encap, |
| 22726 |
Encap_Id => Encap_Id, |
| 22727 |
Legal => Legal); |
| 22728 |
|
| 22729 |
if Legal then |
| 22730 |
pragma Assert (Present (Encap_Id)); |
| 22731 |
|
| 22732 |
if Ekind (Item_Id) = E_Constant then |
| 22733 |
Constits := Part_Of_Constituents (Encap_Id); |
| 22734 |
|
| 22735 |
if No (Constits) then |
| 22736 |
Constits := New_Elmt_List; |
| 22737 |
Set_Part_Of_Constituents (Encap_Id, Constits); |
| 22738 |
end if; |
| 22739 |
|
| 22740 |
Append_Elmt (Item_Id, Constits); |
| 22741 |
Set_Encapsulating_State (Item_Id, Encap_Id); |
| 22742 |
|
| 22743 |
-- Propagate the Part_Of indicator to the visible state |
| 22744 |
-- space of the package instantiation. |
| 22745 |
|
| 22746 |
else |
| 22747 |
Propagate_Part_Of |
| 22748 |
(Pack_Id => Item_Id, |
| 22749 |
State_Id => Encap_Id, |
| 22750 |
Instance => Stmt); |
| 22751 |
end if; |
| 22752 |
end if; |
| 22753 |
end if; |
| 22754 |
end Part_Of; |
| 22755 |
|
| 22756 |
---------------------------------- |
| 22757 |
-- Partition_Elaboration_Policy -- |
| 22758 |
---------------------------------- |
| 22759 |
|
| 22760 |
-- pragma Partition_Elaboration_Policy (policy_IDENTIFIER); |
| 22761 |
|
| 22762 |
when Pragma_Partition_Elaboration_Policy => PEP : declare |
| 22763 |
subtype PEP_Range is Name_Id |
| 22764 |
range First_Partition_Elaboration_Policy_Name |
| 22765 |
.. Last_Partition_Elaboration_Policy_Name; |
| 22766 |
PEP_Val : PEP_Range; |
| 22767 |
PEP : Character; |
| 22768 |
|
| 22769 |
begin |
| 22770 |
Ada_2005_Pragma; |
| 22771 |
Check_Arg_Count (1); |
| 22772 |
Check_No_Identifiers; |
| 22773 |
Check_Arg_Is_Partition_Elaboration_Policy (Arg1); |
| 22774 |
Check_Valid_Configuration_Pragma; |
| 22775 |
PEP_Val := Chars (Get_Pragma_Arg (Arg1)); |
| 22776 |
|
| 22777 |
case PEP_Val is |
| 22778 |
when Name_Concurrent => PEP := 'C'; |
| 22779 |
when Name_Sequential => PEP := 'S'; |
| 22780 |
end case; |
| 22781 |
|
| 22782 |
if Partition_Elaboration_Policy /= ' ' |
| 22783 |
and then Partition_Elaboration_Policy /= PEP |
| 22784 |
then |
| 22785 |
Error_Msg_Sloc := Partition_Elaboration_Policy_Sloc; |
| 22786 |
Error_Pragma |
| 22787 |
("partition elaboration policy incompatible with policy#"); |
| 22788 |
|
| 22789 |
-- Set new policy, but always preserve System_Location since we |
| 22790 |
-- like the error message with the run time name. |
| 22791 |
|
| 22792 |
else |
| 22793 |
Partition_Elaboration_Policy := PEP; |
| 22794 |
|
| 22795 |
if Partition_Elaboration_Policy_Sloc /= System_Location then |
| 22796 |
Partition_Elaboration_Policy_Sloc := Loc; |
| 22797 |
end if; |
| 22798 |
|
| 22799 |
if PEP_Val = Name_Sequential |
| 22800 |
and then not Restriction_Active (No_Task_Hierarchy) |
| 22801 |
then |
| 22802 |
-- RM H.6(6) guarantees that No_Task_Hierarchy will be |
| 22803 |
-- set eventually, so take advantage of that knowledge now. |
| 22804 |
-- But we have to do this in a tricky way. If we simply |
| 22805 |
-- set the No_Task_Hierarchy restriction here, then the |
| 22806 |
-- assumption that the restriction will be set eventually |
| 22807 |
-- becomes a self-fulfilling prophecy; the binder can |
| 22808 |
-- then mistakenly conclude that the H.6(6) rule is |
| 22809 |
-- satisified in cases where the post-compilation check |
| 22810 |
-- should fail. So we invent a new restriction, |
| 22811 |
-- No_Task_Hierarchy_Implicit, which is treated specially |
| 22812 |
-- in the function Restriction_Active. |
| 22813 |
|
| 22814 |
Set_Restriction (No_Task_Hierarchy_Implicit, N); |
| 22815 |
pragma Assert (Restriction_Active (No_Task_Hierarchy)); |
| 22816 |
end if; |
| 22817 |
end if; |
| 22818 |
end PEP; |
| 22819 |
|
| 22820 |
------------- |
| 22821 |
-- Passive -- |
| 22822 |
------------- |
| 22823 |
|
| 22824 |
-- pragma Passive [(PASSIVE_FORM)]; |
| 22825 |
|
| 22826 |
-- PASSIVE_FORM ::= Semaphore | No |
| 22827 |
|
| 22828 |
when Pragma_Passive => |
| 22829 |
GNAT_Pragma; |
| 22830 |
|
| 22831 |
if Nkind (Parent (N)) /= N_Task_Definition then |
| 22832 |
Error_Pragma ("pragma% must be within task definition"); |
| 22833 |
end if; |
| 22834 |
|
| 22835 |
if Arg_Count /= 0 then |
| 22836 |
Check_Arg_Count (1); |
| 22837 |
Check_Arg_Is_One_Of (Arg1, Name_Semaphore, Name_No); |
| 22838 |
end if; |
| 22839 |
|
| 22840 |
-------------------- |
| 22841 |
-- Persistent_BSS -- |
| 22842 |
-------------------- |
| 22843 |
|
| 22844 |
-- pragma Persistent_BSS [(object_LOCAL_NAME)]; |
| 22845 |
|
| 22846 |
when Pragma_Persistent_BSS => Persistent_BSS : declare |
| 22847 |
Decl : Node_Id; |
| 22848 |
Ent : Entity_Id; |
| 22849 |
Prag : Node_Id; |
| 22850 |
|
| 22851 |
begin |
| 22852 |
GNAT_Pragma; |
| 22853 |
Check_At_Most_N_Arguments (1); |
| 22854 |
|
| 22855 |
-- Case of application to specific object (one argument) |
| 22856 |
|
| 22857 |
if Arg_Count = 1 then |
| 22858 |
Check_Arg_Is_Library_Level_Local_Name (Arg1); |
| 22859 |
|
| 22860 |
if not Is_Entity_Name (Get_Pragma_Arg (Arg1)) |
| 22861 |
or else |
| 22862 |
Ekind (Entity (Get_Pragma_Arg (Arg1))) not in |
| 22863 |
E_Variable | E_Constant |
| 22864 |
then |
| 22865 |
Error_Pragma_Arg ("pragma% only applies to objects", Arg1); |
| 22866 |
end if; |
| 22867 |
|
| 22868 |
Ent := Entity (Get_Pragma_Arg (Arg1)); |
| 22869 |
|
| 22870 |
-- A pragma that applies to a Ghost entity becomes Ghost for |
| 22871 |
-- the purposes of legality checks and removal of ignored Ghost |
| 22872 |
-- code. |
| 22873 |
|
| 22874 |
Mark_Ghost_Pragma (N, Ent); |
| 22875 |
|
| 22876 |
-- Check for duplication before inserting in list of |
| 22877 |
-- representation items. |
| 22878 |
|
| 22879 |
Check_Duplicate_Pragma (Ent); |
| 22880 |
|
| 22881 |
if Rep_Item_Too_Late (Ent, N) then |
| 22882 |
return; |
| 22883 |
end if; |
| 22884 |
|
| 22885 |
Decl := Parent (Ent); |
| 22886 |
|
| 22887 |
if Present (Expression (Decl)) then |
| 22888 |
-- Variables in Persistent_BSS cannot be initialized, so |
| 22889 |
-- turn off any initialization that might be caused by |
| 22890 |
-- pragmas Initialize_Scalars or Normalize_Scalars. |
| 22891 |
|
| 22892 |
if Kill_Range_Check (Expression (Decl)) then |
| 22893 |
Prag := |
| 22894 |
Make_Pragma (Loc, |
| 22895 |
Name_Suppress_Initialization, |
| 22896 |
Pragma_Argument_Associations => New_List ( |
| 22897 |
Make_Pragma_Argument_Association (Loc, |
| 22898 |
Expression => New_Occurrence_Of (Ent, Loc)))); |
| 22899 |
Insert_Before (N, Prag); |
| 22900 |
Analyze (Prag); |
| 22901 |
|
| 22902 |
else |
| 22903 |
Error_Pragma_Arg |
| 22904 |
("object for pragma% cannot have initialization", Arg1); |
| 22905 |
end if; |
| 22906 |
end if; |
| 22907 |
|
| 22908 |
if not Is_Potentially_Persistent_Type (Etype (Ent)) then |
| 22909 |
Error_Pragma_Arg |
| 22910 |
("object type for pragma% is not potentially persistent", |
| 22911 |
Arg1); |
| 22912 |
end if; |
| 22913 |
|
| 22914 |
Prag := |
| 22915 |
Make_Linker_Section_Pragma |
| 22916 |
(Ent, Loc, ".persistent.bss"); |
| 22917 |
Insert_After (N, Prag); |
| 22918 |
Analyze (Prag); |
| 22919 |
|
| 22920 |
-- Case of use as configuration pragma with no arguments |
| 22921 |
|
| 22922 |
else |
| 22923 |
Check_Valid_Configuration_Pragma; |
| 22924 |
Persistent_BSS_Mode := True; |
| 22925 |
end if; |
| 22926 |
end Persistent_BSS; |
| 22927 |
|
| 22928 |
---------------------------------- |
| 22929 |
-- Preelaborable_Initialization -- |
| 22930 |
---------------------------------- |
| 22931 |
|
| 22932 |
-- pragma Preelaborable_Initialization (DIRECT_NAME); |
| 22933 |
|
| 22934 |
when Pragma_Preelaborable_Initialization => Preelab_Init : declare |
| 22935 |
Ent : Entity_Id; |
| 22936 |
|
| 22937 |
begin |
| 22938 |
Ada_2005_Pragma; |
| 22939 |
Check_Arg_Count (1); |
| 22940 |
Check_No_Identifiers; |
| 22941 |
Check_Arg_Is_Identifier (Arg1); |
| 22942 |
Check_Arg_Is_Local_Name (Arg1); |
| 22943 |
Check_First_Subtype (Arg1); |
| 22944 |
Ent := Entity (Get_Pragma_Arg (Arg1)); |
| 22945 |
|
| 22946 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 22947 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 22948 |
|
| 22949 |
Mark_Ghost_Pragma (N, Ent); |
| 22950 |
|
| 22951 |
-- The pragma may come from an aspect on a private declaration, |
| 22952 |
-- even if the freeze point at which this is analyzed in the |
| 22953 |
-- private part after the full view. |
| 22954 |
|
| 22955 |
if Has_Private_Declaration (Ent) |
| 22956 |
and then From_Aspect_Specification (N) |
| 22957 |
then |
| 22958 |
null; |
| 22959 |
|
| 22960 |
-- Check appropriate type argument |
| 22961 |
|
| 22962 |
elsif Is_Private_Type (Ent) |
| 22963 |
or else Is_Protected_Type (Ent) |
| 22964 |
or else (Is_Generic_Type (Ent) and then Is_Derived_Type (Ent)) |
| 22965 |
|
| 22966 |
-- AI05-0028: The pragma applies to all composite types. Note |
| 22967 |
-- that we apply this binding interpretation to earlier versions |
| 22968 |
-- of Ada, so there is no Ada 2012 guard. Seems a reasonable |
| 22969 |
-- choice since there are other compilers that do the same. |
| 22970 |
|
| 22971 |
or else Is_Composite_Type (Ent) |
| 22972 |
then |
| 22973 |
null; |
| 22974 |
|
| 22975 |
else |
| 22976 |
Error_Pragma_Arg |
| 22977 |
("pragma % can only be applied to private, formal derived, " |
| 22978 |
& "protected, or composite type", Arg1); |
| 22979 |
end if; |
| 22980 |
|
| 22981 |
-- Give an error if the pragma is applied to a protected type that |
| 22982 |
-- does not qualify (due to having entries, or due to components |
| 22983 |
-- that do not qualify). |
| 22984 |
|
| 22985 |
if Is_Protected_Type (Ent) |
| 22986 |
and then not Has_Preelaborable_Initialization (Ent) |
| 22987 |
then |
| 22988 |
Error_Msg_N |
| 22989 |
("protected type & does not have preelaborable " |
| 22990 |
& "initialization", Ent); |
| 22991 |
|
| 22992 |
-- Otherwise mark the type as definitely having preelaborable |
| 22993 |
-- initialization. |
| 22994 |
|
| 22995 |
else |
| 22996 |
Set_Known_To_Have_Preelab_Init (Ent); |
| 22997 |
end if; |
| 22998 |
|
| 22999 |
if Has_Pragma_Preelab_Init (Ent) |
| 23000 |
and then Warn_On_Redundant_Constructs |
| 23001 |
then |
| 23002 |
Error_Pragma ("?r?duplicate pragma%!"); |
| 23003 |
else |
| 23004 |
Set_Has_Pragma_Preelab_Init (Ent); |
| 23005 |
end if; |
| 23006 |
end Preelab_Init; |
| 23007 |
|
| 23008 |
-------------------- |
| 23009 |
-- Rename_Pragma -- |
| 23010 |
-------------------- |
| 23011 |
|
| 23012 |
-- pragma Rename_Pragma ( |
| 23013 |
-- [New_Name =>] IDENTIFIER, |
| 23014 |
-- [Renamed =>] pragma_IDENTIFIER); |
| 23015 |
|
| 23016 |
when Pragma_Rename_Pragma => Rename_Pragma : declare |
| 23017 |
New_Name : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 23018 |
Old_Name : constant Node_Id := Get_Pragma_Arg (Arg2); |
| 23019 |
|
| 23020 |
begin |
| 23021 |
GNAT_Pragma; |
| 23022 |
Check_Valid_Configuration_Pragma; |
| 23023 |
Check_Arg_Count (2); |
| 23024 |
Check_Optional_Identifier (Arg1, Name_New_Name); |
| 23025 |
Check_Optional_Identifier (Arg2, Name_Renamed); |
| 23026 |
|
| 23027 |
if Nkind (New_Name) /= N_Identifier then |
| 23028 |
Error_Pragma_Arg ("identifier expected", Arg1); |
| 23029 |
end if; |
| 23030 |
|
| 23031 |
if Nkind (Old_Name) /= N_Identifier then |
| 23032 |
Error_Pragma_Arg ("identifier expected", Arg2); |
| 23033 |
end if; |
| 23034 |
|
| 23035 |
-- The New_Name arg should not be an existing pragma (but we allow |
| 23036 |
-- it; it's just a warning). The Old_Name arg must be an existing |
| 23037 |
-- pragma. |
| 23038 |
|
| 23039 |
if Is_Pragma_Name (Chars (New_Name)) then |
| 23040 |
Error_Pragma_Arg ("??pragma is already defined", Arg1); |
| 23041 |
end if; |
| 23042 |
|
| 23043 |
if not Is_Pragma_Name (Chars (Old_Name)) then |
| 23044 |
Error_Pragma_Arg ("existing pragma name expected", Arg1); |
| 23045 |
end if; |
| 23046 |
|
| 23047 |
Map_Pragma_Name (From => Chars (New_Name), To => Chars (Old_Name)); |
| 23048 |
end Rename_Pragma; |
| 23049 |
|
| 23050 |
----------------------------------- |
| 23051 |
-- Post/Post_Class/Postcondition -- |
| 23052 |
----------------------------------- |
| 23053 |
|
| 23054 |
-- pragma Post (Boolean_EXPRESSION); |
| 23055 |
-- pragma Post_Class (Boolean_EXPRESSION); |
| 23056 |
-- pragma Postcondition ([Check =>] Boolean_EXPRESSION |
| 23057 |
-- [,[Message =>] String_EXPRESSION]); |
| 23058 |
|
| 23059 |
-- Characteristics: |
| 23060 |
|
| 23061 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 23062 |
-- the legal placement and context. Secondary checks preanalyze the |
| 23063 |
-- expression in: |
| 23064 |
|
| 23065 |
-- Analyze_Pre_Post_Condition_In_Decl_Part |
| 23066 |
|
| 23067 |
-- * Expansion - The annotation is expanded during the expansion of |
| 23068 |
-- the related subprogram [body] contract as performed in: |
| 23069 |
|
| 23070 |
-- Expand_Subprogram_Contract |
| 23071 |
|
| 23072 |
-- * Template - The annotation utilizes the generic template of the |
| 23073 |
-- related subprogram [body] when it is: |
| 23074 |
|
| 23075 |
-- aspect on subprogram declaration |
| 23076 |
-- aspect on stand-alone subprogram body |
| 23077 |
-- pragma on stand-alone subprogram body |
| 23078 |
|
| 23079 |
-- The annotation must prepare its own template when it is: |
| 23080 |
|
| 23081 |
-- pragma on subprogram declaration |
| 23082 |
|
| 23083 |
-- * Globals - Capture of global references must occur after full |
| 23084 |
-- analysis. |
| 23085 |
|
| 23086 |
-- * Instance - The annotation is instantiated automatically when |
| 23087 |
-- the related generic subprogram [body] is instantiated except for |
| 23088 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 23089 |
-- the annotation must instantiate itself. |
| 23090 |
|
| 23091 |
when Pragma_Post |
| 23092 |
| Pragma_Post_Class |
| 23093 |
| Pragma_Postcondition |
| 23094 |
=> |
| 23095 |
Analyze_Pre_Post_Condition; |
| 23096 |
|
| 23097 |
-------------------------------- |
| 23098 |
-- Pre/Pre_Class/Precondition -- |
| 23099 |
-------------------------------- |
| 23100 |
|
| 23101 |
-- pragma Pre (Boolean_EXPRESSION); |
| 23102 |
-- pragma Pre_Class (Boolean_EXPRESSION); |
| 23103 |
-- pragma Precondition ([Check =>] Boolean_EXPRESSION |
| 23104 |
-- [,[Message =>] String_EXPRESSION]); |
| 23105 |
|
| 23106 |
-- Characteristics: |
| 23107 |
|
| 23108 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 23109 |
-- the legal placement and context. Secondary checks preanalyze the |
| 23110 |
-- expression in: |
| 23111 |
|
| 23112 |
-- Analyze_Pre_Post_Condition_In_Decl_Part |
| 23113 |
|
| 23114 |
-- * Expansion - The annotation is expanded during the expansion of |
| 23115 |
-- the related subprogram [body] contract as performed in: |
| 23116 |
|
| 23117 |
-- Expand_Subprogram_Contract |
| 23118 |
|
| 23119 |
-- * Template - The annotation utilizes the generic template of the |
| 23120 |
-- related subprogram [body] when it is: |
| 23121 |
|
| 23122 |
-- aspect on subprogram declaration |
| 23123 |
-- aspect on stand-alone subprogram body |
| 23124 |
-- pragma on stand-alone subprogram body |
| 23125 |
|
| 23126 |
-- The annotation must prepare its own template when it is: |
| 23127 |
|
| 23128 |
-- pragma on subprogram declaration |
| 23129 |
|
| 23130 |
-- * Globals - Capture of global references must occur after full |
| 23131 |
-- analysis. |
| 23132 |
|
| 23133 |
-- * Instance - The annotation is instantiated automatically when |
| 23134 |
-- the related generic subprogram [body] is instantiated except for |
| 23135 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 23136 |
-- the annotation must instantiate itself. |
| 23137 |
|
| 23138 |
when Pragma_Pre |
| 23139 |
| Pragma_Pre_Class |
| 23140 |
| Pragma_Precondition |
| 23141 |
=> |
| 23142 |
Analyze_Pre_Post_Condition; |
| 23143 |
|
| 23144 |
--------------- |
| 23145 |
-- Predicate -- |
| 23146 |
--------------- |
| 23147 |
|
| 23148 |
-- pragma Predicate |
| 23149 |
-- ([Entity =>] type_LOCAL_NAME, |
| 23150 |
-- [Check =>] boolean_EXPRESSION); |
| 23151 |
|
| 23152 |
when Pragma_Predicate => Predicate : declare |
| 23153 |
Discard : Boolean; |
| 23154 |
Typ : Entity_Id; |
| 23155 |
Type_Id : Node_Id; |
| 23156 |
|
| 23157 |
begin |
| 23158 |
GNAT_Pragma; |
| 23159 |
Check_Arg_Count (2); |
| 23160 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 23161 |
Check_Optional_Identifier (Arg2, Name_Check); |
| 23162 |
|
| 23163 |
Check_Arg_Is_Local_Name (Arg1); |
| 23164 |
|
| 23165 |
Type_Id := Get_Pragma_Arg (Arg1); |
| 23166 |
Find_Type (Type_Id); |
| 23167 |
Typ := Entity (Type_Id); |
| 23168 |
|
| 23169 |
if Typ = Any_Type then |
| 23170 |
return; |
| 23171 |
end if; |
| 23172 |
|
| 23173 |
-- A Ghost_Predicate aspect is always Ghost with a mode inherited |
| 23174 |
-- from the context. A Predicate pragma that applies to a Ghost |
| 23175 |
-- entity becomes Ghost for the purposes of legality checks and |
| 23176 |
-- removal of ignored Ghost code. |
| 23177 |
|
| 23178 |
if From_Aspect_Specification (N) |
| 23179 |
and then Get_Aspect_Id |
| 23180 |
(Chars (Identifier (Corresponding_Aspect (N)))) |
| 23181 |
= Aspect_Ghost_Predicate |
| 23182 |
then |
| 23183 |
Mark_Ghost_Pragma |
| 23184 |
(N, Name_To_Ghost_Mode (Policy_In_Effect (Name_Ghost))); |
| 23185 |
else |
| 23186 |
Mark_Ghost_Pragma (N, Typ); |
| 23187 |
end if; |
| 23188 |
|
| 23189 |
-- The remaining processing is simply to link the pragma on to |
| 23190 |
-- the rep item chain, for processing when the type is frozen. |
| 23191 |
-- This is accomplished by a call to Rep_Item_Too_Late. We also |
| 23192 |
-- mark the type as having predicates. |
| 23193 |
|
| 23194 |
-- If the current policy for predicate checking is Ignore mark the |
| 23195 |
-- subtype accordingly. In the case of predicates we consider them |
| 23196 |
-- enabled unless Ignore is specified (either directly or with a |
| 23197 |
-- general Assertion_Policy pragma) to preserve existing warnings. |
| 23198 |
|
| 23199 |
Set_Has_Predicates (Typ); |
| 23200 |
|
| 23201 |
-- Indicate that the pragma must be processed at the point the |
| 23202 |
-- type is frozen, as is done for the corresponding aspect. |
| 23203 |
|
| 23204 |
Set_Has_Delayed_Aspects (Typ); |
| 23205 |
Set_Has_Delayed_Freeze (Typ); |
| 23206 |
|
| 23207 |
-- Mark this aspect as ignored if the policy in effect is Ignore. |
| 23208 |
|
| 23209 |
-- It is not done for the internally built pragma created as part |
| 23210 |
-- of processing aspect dynamic predicate because, in such case, |
| 23211 |
-- this was done when the aspect was processed (see subprogram |
| 23212 |
-- Analyze_One_Aspect). |
| 23213 |
|
| 23214 |
if From_Aspect_Specification (N) |
| 23215 |
and then Pname = Name_Dynamic_Predicate |
| 23216 |
then |
| 23217 |
null; |
| 23218 |
else |
| 23219 |
Set_Predicates_Ignored (Typ, |
| 23220 |
Policy_In_Effect (Name_Dynamic_Predicate) = Name_Ignore); |
| 23221 |
end if; |
| 23222 |
|
| 23223 |
Discard := Rep_Item_Too_Late (Typ, N, FOnly => True); |
| 23224 |
end Predicate; |
| 23225 |
|
| 23226 |
----------------------- |
| 23227 |
-- Predicate_Failure -- |
| 23228 |
----------------------- |
| 23229 |
|
| 23230 |
-- pragma Predicate_Failure |
| 23231 |
-- ([Entity =>] type_LOCAL_NAME, |
| 23232 |
-- [Message =>] string_EXPRESSION); |
| 23233 |
|
| 23234 |
when Pragma_Predicate_Failure => Predicate_Failure : declare |
| 23235 |
Discard : Boolean; |
| 23236 |
Typ : Entity_Id; |
| 23237 |
Type_Id : Node_Id; |
| 23238 |
|
| 23239 |
begin |
| 23240 |
GNAT_Pragma; |
| 23241 |
Check_Arg_Count (2); |
| 23242 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 23243 |
Check_Optional_Identifier (Arg2, Name_Message); |
| 23244 |
|
| 23245 |
Check_Arg_Is_Local_Name (Arg1); |
| 23246 |
|
| 23247 |
Type_Id := Get_Pragma_Arg (Arg1); |
| 23248 |
Find_Type (Type_Id); |
| 23249 |
Typ := Entity (Type_Id); |
| 23250 |
|
| 23251 |
if Typ = Any_Type then |
| 23252 |
return; |
| 23253 |
end if; |
| 23254 |
|
| 23255 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 23256 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 23257 |
|
| 23258 |
Mark_Ghost_Pragma (N, Typ); |
| 23259 |
|
| 23260 |
-- The remaining processing is simply to link the pragma on to |
| 23261 |
-- the rep item chain, for processing when the type is frozen. |
| 23262 |
-- This is accomplished by a call to Rep_Item_Too_Late. |
| 23263 |
|
| 23264 |
Discard := Rep_Item_Too_Late (Typ, N, FOnly => True); |
| 23265 |
end Predicate_Failure; |
| 23266 |
|
| 23267 |
------------------ |
| 23268 |
-- Preelaborate -- |
| 23269 |
------------------ |
| 23270 |
|
| 23271 |
-- pragma Preelaborate [(library_unit_NAME)]; |
| 23272 |
|
| 23273 |
-- Set the flag Is_Preelaborated of program unit name entity |
| 23274 |
|
| 23275 |
when Pragma_Preelaborate => Preelaborate : declare |
| 23276 |
Pa : constant Node_Id := Parent (N); |
| 23277 |
Pk : constant Node_Kind := Nkind (Pa); |
| 23278 |
Ent : Entity_Id; |
| 23279 |
|
| 23280 |
begin |
| 23281 |
Check_Ada_83_Warning; |
| 23282 |
Check_Valid_Library_Unit_Pragma; |
| 23283 |
|
| 23284 |
-- If N was rewritten as a null statement there is nothing more |
| 23285 |
-- to do. |
| 23286 |
|
| 23287 |
if Nkind (N) = N_Null_Statement then |
| 23288 |
return; |
| 23289 |
end if; |
| 23290 |
|
| 23291 |
Ent := Find_Lib_Unit_Name; |
| 23292 |
|
| 23293 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 23294 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 23295 |
|
| 23296 |
Mark_Ghost_Pragma (N, Ent); |
| 23297 |
Check_Duplicate_Pragma (Ent); |
| 23298 |
|
| 23299 |
-- This filters out pragmas inside generic parents that show up |
| 23300 |
-- inside instantiations. Pragmas that come from aspects in the |
| 23301 |
-- unit are not ignored. |
| 23302 |
|
| 23303 |
if Present (Ent) then |
| 23304 |
if Pk = N_Package_Specification |
| 23305 |
and then Present (Generic_Parent (Pa)) |
| 23306 |
and then not From_Aspect_Specification (N) |
| 23307 |
then |
| 23308 |
null; |
| 23309 |
|
| 23310 |
else |
| 23311 |
if not Debug_Flag_U then |
| 23312 |
Set_Is_Preelaborated (Ent); |
| 23313 |
|
| 23314 |
if Legacy_Elaboration_Checks then |
| 23315 |
Set_Suppress_Elaboration_Warnings (Ent); |
| 23316 |
end if; |
| 23317 |
end if; |
| 23318 |
end if; |
| 23319 |
end if; |
| 23320 |
end Preelaborate; |
| 23321 |
|
| 23322 |
------------------------------- |
| 23323 |
-- Prefix_Exception_Messages -- |
| 23324 |
------------------------------- |
| 23325 |
|
| 23326 |
-- pragma Prefix_Exception_Messages; |
| 23327 |
|
| 23328 |
when Pragma_Prefix_Exception_Messages => |
| 23329 |
GNAT_Pragma; |
| 23330 |
Check_Valid_Configuration_Pragma; |
| 23331 |
Check_Arg_Count (0); |
| 23332 |
Prefix_Exception_Messages := True; |
| 23333 |
|
| 23334 |
-------------- |
| 23335 |
-- Priority -- |
| 23336 |
-------------- |
| 23337 |
|
| 23338 |
-- pragma Priority (EXPRESSION); |
| 23339 |
|
| 23340 |
when Pragma_Priority => Priority : declare |
| 23341 |
P : constant Node_Id := Parent (N); |
| 23342 |
Arg : Node_Id; |
| 23343 |
Ent : Entity_Id; |
| 23344 |
|
| 23345 |
begin |
| 23346 |
Check_No_Identifiers; |
| 23347 |
Check_Arg_Count (1); |
| 23348 |
|
| 23349 |
-- Subprogram case |
| 23350 |
|
| 23351 |
if Nkind (P) = N_Subprogram_Body then |
| 23352 |
Check_In_Main_Program; |
| 23353 |
|
| 23354 |
Ent := Defining_Unit_Name (Specification (P)); |
| 23355 |
|
| 23356 |
if Nkind (Ent) = N_Defining_Program_Unit_Name then |
| 23357 |
Ent := Defining_Identifier (Ent); |
| 23358 |
end if; |
| 23359 |
|
| 23360 |
Arg := Get_Pragma_Arg (Arg1); |
| 23361 |
Analyze_And_Resolve (Arg, Standard_Integer); |
| 23362 |
|
| 23363 |
-- Must be static |
| 23364 |
|
| 23365 |
if not Is_OK_Static_Expression (Arg) then |
| 23366 |
Flag_Non_Static_Expr |
| 23367 |
("main subprogram priority is not static!", Arg); |
| 23368 |
raise Pragma_Exit; |
| 23369 |
|
| 23370 |
-- If constraint error, then we already signalled an error |
| 23371 |
|
| 23372 |
elsif Raises_Constraint_Error (Arg) then |
| 23373 |
null; |
| 23374 |
|
| 23375 |
-- Otherwise check in range except if Relaxed_RM_Semantics |
| 23376 |
-- where we ignore the value if out of range. |
| 23377 |
|
| 23378 |
else |
| 23379 |
if not Relaxed_RM_Semantics |
| 23380 |
and then not Is_In_Range (Arg, RTE (RE_Priority)) |
| 23381 |
then |
| 23382 |
Error_Pragma_Arg |
| 23383 |
("main subprogram priority is out of range", Arg1); |
| 23384 |
else |
| 23385 |
Set_Main_Priority |
| 23386 |
(Current_Sem_Unit, UI_To_Int (Expr_Value (Arg))); |
| 23387 |
end if; |
| 23388 |
end if; |
| 23389 |
|
| 23390 |
-- Load an arbitrary entity from System.Tasking.Stages or |
| 23391 |
-- System.Tasking.Restricted.Stages (depending on the |
| 23392 |
-- supported profile) to make sure that one of these packages |
| 23393 |
-- is implicitly with'ed, since we need to have the tasking |
| 23394 |
-- run time active for the pragma Priority to have any effect. |
| 23395 |
-- Previously we with'ed the package System.Tasking, but this |
| 23396 |
-- package does not trigger the required initialization of the |
| 23397 |
-- run-time library. |
| 23398 |
|
| 23399 |
if Restricted_Profile then |
| 23400 |
Discard_Node (RTE (RE_Activate_Restricted_Tasks)); |
| 23401 |
else |
| 23402 |
Discard_Node (RTE (RE_Activate_Tasks)); |
| 23403 |
end if; |
| 23404 |
|
| 23405 |
-- Task or Protected, must be of type Integer |
| 23406 |
|
| 23407 |
elsif Nkind (P) in N_Protected_Definition | N_Task_Definition then |
| 23408 |
Arg := Get_Pragma_Arg (Arg1); |
| 23409 |
Ent := Defining_Identifier (Parent (P)); |
| 23410 |
|
| 23411 |
-- The expression must be analyzed in the special manner |
| 23412 |
-- described in "Handling of Default and Per-Object |
| 23413 |
-- Expressions" in sem.ads. |
| 23414 |
|
| 23415 |
Preanalyze_Spec_Expression (Arg, RTE (RE_Any_Priority)); |
| 23416 |
|
| 23417 |
if not Is_OK_Static_Expression (Arg) then |
| 23418 |
Check_Restriction (Static_Priorities, Arg); |
| 23419 |
end if; |
| 23420 |
|
| 23421 |
-- Anything else is incorrect |
| 23422 |
|
| 23423 |
else |
| 23424 |
Pragma_Misplaced; |
| 23425 |
end if; |
| 23426 |
|
| 23427 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 23428 |
-- Item chain of Ent. |
| 23429 |
|
| 23430 |
Check_Duplicate_Pragma (Ent); |
| 23431 |
Record_Rep_Item (Ent, N); |
| 23432 |
end Priority; |
| 23433 |
|
| 23434 |
----------------------------------- |
| 23435 |
-- Priority_Specific_Dispatching -- |
| 23436 |
----------------------------------- |
| 23437 |
|
| 23438 |
-- pragma Priority_Specific_Dispatching ( |
| 23439 |
-- policy_IDENTIFIER, |
| 23440 |
-- first_priority_EXPRESSION, |
| 23441 |
-- last_priority_EXPRESSION); |
| 23442 |
|
| 23443 |
when Pragma_Priority_Specific_Dispatching => |
| 23444 |
Priority_Specific_Dispatching : declare |
| 23445 |
Prio_Id : constant Entity_Id := RTE (RE_Any_Priority); |
| 23446 |
-- This is the entity System.Any_Priority; |
| 23447 |
|
| 23448 |
DP : Character; |
| 23449 |
Lower_Bound : Node_Id; |
| 23450 |
Upper_Bound : Node_Id; |
| 23451 |
Lower_Val : Uint; |
| 23452 |
Upper_Val : Uint; |
| 23453 |
|
| 23454 |
begin |
| 23455 |
Ada_2005_Pragma; |
| 23456 |
Check_Arg_Count (3); |
| 23457 |
Check_No_Identifiers; |
| 23458 |
Check_Arg_Is_Task_Dispatching_Policy (Arg1); |
| 23459 |
Check_Valid_Configuration_Pragma; |
| 23460 |
Get_Name_String (Chars (Get_Pragma_Arg (Arg1))); |
| 23461 |
DP := Fold_Upper (Name_Buffer (1)); |
| 23462 |
|
| 23463 |
Lower_Bound := Get_Pragma_Arg (Arg2); |
| 23464 |
Check_Arg_Is_OK_Static_Expression (Lower_Bound, Standard_Integer); |
| 23465 |
Lower_Val := Expr_Value (Lower_Bound); |
| 23466 |
|
| 23467 |
Upper_Bound := Get_Pragma_Arg (Arg3); |
| 23468 |
Check_Arg_Is_OK_Static_Expression (Upper_Bound, Standard_Integer); |
| 23469 |
Upper_Val := Expr_Value (Upper_Bound); |
| 23470 |
|
| 23471 |
-- It is not allowed to use Task_Dispatching_Policy and |
| 23472 |
-- Priority_Specific_Dispatching in the same partition. |
| 23473 |
|
| 23474 |
if Task_Dispatching_Policy /= ' ' then |
| 23475 |
Error_Msg_Sloc := Task_Dispatching_Policy_Sloc; |
| 23476 |
Error_Pragma |
| 23477 |
("pragma% incompatible with Task_Dispatching_Policy#"); |
| 23478 |
|
| 23479 |
-- Check lower bound in range |
| 23480 |
|
| 23481 |
elsif Lower_Val < Expr_Value (Type_Low_Bound (Prio_Id)) |
| 23482 |
or else |
| 23483 |
Lower_Val > Expr_Value (Type_High_Bound (Prio_Id)) |
| 23484 |
then |
| 23485 |
Error_Pragma_Arg |
| 23486 |
("first_priority is out of range", Arg2); |
| 23487 |
|
| 23488 |
-- Check upper bound in range |
| 23489 |
|
| 23490 |
elsif Upper_Val < Expr_Value (Type_Low_Bound (Prio_Id)) |
| 23491 |
or else |
| 23492 |
Upper_Val > Expr_Value (Type_High_Bound (Prio_Id)) |
| 23493 |
then |
| 23494 |
Error_Pragma_Arg |
| 23495 |
("last_priority is out of range", Arg3); |
| 23496 |
|
| 23497 |
-- Check that the priority range is valid |
| 23498 |
|
| 23499 |
elsif Lower_Val > Upper_Val then |
| 23500 |
Error_Pragma |
| 23501 |
("last_priority_expression must be greater than or equal to " |
| 23502 |
& "first_priority_expression"); |
| 23503 |
|
| 23504 |
-- Store the new policy, but always preserve System_Location since |
| 23505 |
-- we like the error message with the run-time name. |
| 23506 |
|
| 23507 |
else |
| 23508 |
-- Check overlapping in the priority ranges specified in other |
| 23509 |
-- Priority_Specific_Dispatching pragmas within the same |
| 23510 |
-- partition. We can only check those we know about. |
| 23511 |
|
| 23512 |
for J in |
| 23513 |
Specific_Dispatching.First .. Specific_Dispatching.Last |
| 23514 |
loop |
| 23515 |
if Specific_Dispatching.Table (J).First_Priority in |
| 23516 |
UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val) |
| 23517 |
or else Specific_Dispatching.Table (J).Last_Priority in |
| 23518 |
UI_To_Int (Lower_Val) .. UI_To_Int (Upper_Val) |
| 23519 |
then |
| 23520 |
Error_Msg_Sloc := |
| 23521 |
Specific_Dispatching.Table (J).Pragma_Loc; |
| 23522 |
Error_Pragma |
| 23523 |
("priority range overlaps with " |
| 23524 |
& "Priority_Specific_Dispatching#"); |
| 23525 |
end if; |
| 23526 |
end loop; |
| 23527 |
|
| 23528 |
-- The use of Priority_Specific_Dispatching is incompatible |
| 23529 |
-- with Task_Dispatching_Policy. |
| 23530 |
|
| 23531 |
if Task_Dispatching_Policy /= ' ' then |
| 23532 |
Error_Msg_Sloc := Task_Dispatching_Policy_Sloc; |
| 23533 |
Error_Pragma |
| 23534 |
("Priority_Specific_Dispatching incompatible " |
| 23535 |
& "with Task_Dispatching_Policy#"); |
| 23536 |
end if; |
| 23537 |
|
| 23538 |
-- The use of Priority_Specific_Dispatching forces ceiling |
| 23539 |
-- locking policy. |
| 23540 |
|
| 23541 |
if Locking_Policy /= ' ' and then Locking_Policy /= 'C' then |
| 23542 |
Error_Msg_Sloc := Locking_Policy_Sloc; |
| 23543 |
Error_Pragma |
| 23544 |
("Priority_Specific_Dispatching incompatible " |
| 23545 |
& "with Locking_Policy#"); |
| 23546 |
|
| 23547 |
-- Set the Ceiling_Locking policy, but preserve System_Location |
| 23548 |
-- since we like the error message with the run time name. |
| 23549 |
|
| 23550 |
else |
| 23551 |
Locking_Policy := 'C'; |
| 23552 |
|
| 23553 |
if Locking_Policy_Sloc /= System_Location then |
| 23554 |
Locking_Policy_Sloc := Loc; |
| 23555 |
end if; |
| 23556 |
end if; |
| 23557 |
|
| 23558 |
-- Add entry in the table |
| 23559 |
|
| 23560 |
Specific_Dispatching.Append |
| 23561 |
((Dispatching_Policy => DP, |
| 23562 |
First_Priority => UI_To_Int (Lower_Val), |
| 23563 |
Last_Priority => UI_To_Int (Upper_Val), |
| 23564 |
Pragma_Loc => Loc)); |
| 23565 |
end if; |
| 23566 |
end Priority_Specific_Dispatching; |
| 23567 |
|
| 23568 |
------------- |
| 23569 |
-- Profile -- |
| 23570 |
------------- |
| 23571 |
|
| 23572 |
-- pragma Profile (profile_IDENTIFIER); |
| 23573 |
|
| 23574 |
-- profile_IDENTIFIER => Restricted | Ravenscar | Rational |
| 23575 |
|
| 23576 |
when Pragma_Profile => |
| 23577 |
Ada_2005_Pragma; |
| 23578 |
Check_Arg_Count (1); |
| 23579 |
Check_Valid_Configuration_Pragma; |
| 23580 |
Check_No_Identifiers; |
| 23581 |
|
| 23582 |
declare |
| 23583 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 23584 |
|
| 23585 |
begin |
| 23586 |
if Nkind (Argx) /= N_Identifier then |
| 23587 |
Error_Msg_N |
| 23588 |
("argument of pragma Profile must be an identifier", N); |
| 23589 |
|
| 23590 |
elsif Chars (Argx) = Name_Ravenscar then |
| 23591 |
Set_Ravenscar_Profile (Ravenscar, N); |
| 23592 |
|
| 23593 |
elsif Chars (Argx) = Name_Jorvik then |
| 23594 |
Set_Ravenscar_Profile (Jorvik, N); |
| 23595 |
|
| 23596 |
elsif Chars (Argx) = Name_Gnat_Extended_Ravenscar then |
| 23597 |
Set_Ravenscar_Profile (GNAT_Extended_Ravenscar, N); |
| 23598 |
|
| 23599 |
elsif Chars (Argx) = Name_Gnat_Ravenscar_EDF then |
| 23600 |
Set_Ravenscar_Profile (GNAT_Ravenscar_EDF, N); |
| 23601 |
|
| 23602 |
elsif Chars (Argx) = Name_Restricted then |
| 23603 |
Set_Profile_Restrictions |
| 23604 |
(Restricted, |
| 23605 |
N, Warn => Treat_Restrictions_As_Warnings); |
| 23606 |
|
| 23607 |
elsif Chars (Argx) = Name_Rational then |
| 23608 |
Set_Rational_Profile; |
| 23609 |
|
| 23610 |
elsif Chars (Argx) = Name_No_Implementation_Extensions then |
| 23611 |
Set_Profile_Restrictions |
| 23612 |
(No_Implementation_Extensions, |
| 23613 |
N, Warn => Treat_Restrictions_As_Warnings); |
| 23614 |
|
| 23615 |
else |
| 23616 |
Error_Pragma_Arg ("& is not a valid profile", Argx); |
| 23617 |
end if; |
| 23618 |
end; |
| 23619 |
|
| 23620 |
---------------------- |
| 23621 |
-- Profile_Warnings -- |
| 23622 |
---------------------- |
| 23623 |
|
| 23624 |
-- pragma Profile_Warnings (profile_IDENTIFIER); |
| 23625 |
|
| 23626 |
-- profile_IDENTIFIER => Restricted | Ravenscar |
| 23627 |
|
| 23628 |
when Pragma_Profile_Warnings => |
| 23629 |
GNAT_Pragma; |
| 23630 |
Check_Arg_Count (1); |
| 23631 |
Check_Valid_Configuration_Pragma; |
| 23632 |
Check_No_Identifiers; |
| 23633 |
|
| 23634 |
declare |
| 23635 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 23636 |
|
| 23637 |
begin |
| 23638 |
if Chars (Argx) = Name_Ravenscar then |
| 23639 |
Set_Profile_Restrictions (Ravenscar, N, Warn => True); |
| 23640 |
|
| 23641 |
elsif Chars (Argx) = Name_Restricted then |
| 23642 |
Set_Profile_Restrictions (Restricted, N, Warn => True); |
| 23643 |
|
| 23644 |
elsif Chars (Argx) = Name_No_Implementation_Extensions then |
| 23645 |
Set_Profile_Restrictions |
| 23646 |
(No_Implementation_Extensions, N, Warn => True); |
| 23647 |
|
| 23648 |
else |
| 23649 |
Error_Pragma_Arg ("& is not a valid profile", Argx); |
| 23650 |
end if; |
| 23651 |
end; |
| 23652 |
|
| 23653 |
-------------------------- |
| 23654 |
-- Propagate_Exceptions -- |
| 23655 |
-------------------------- |
| 23656 |
|
| 23657 |
-- pragma Propagate_Exceptions; |
| 23658 |
|
| 23659 |
-- Note: this pragma is obsolete and has no effect |
| 23660 |
|
| 23661 |
when Pragma_Propagate_Exceptions => |
| 23662 |
GNAT_Pragma; |
| 23663 |
Check_Arg_Count (0); |
| 23664 |
|
| 23665 |
if Warn_On_Obsolescent_Feature then |
| 23666 |
Error_Msg_N |
| 23667 |
("'G'N'A'T pragma Propagate'_Exceptions is now obsolete " & |
| 23668 |
"and has no effect?j?", N); |
| 23669 |
end if; |
| 23670 |
|
| 23671 |
----------------------------- |
| 23672 |
-- Provide_Shift_Operators -- |
| 23673 |
----------------------------- |
| 23674 |
|
| 23675 |
-- pragma Provide_Shift_Operators (integer_subtype_LOCAL_NAME); |
| 23676 |
|
| 23677 |
when Pragma_Provide_Shift_Operators => |
| 23678 |
Provide_Shift_Operators : declare |
| 23679 |
Ent : Entity_Id; |
| 23680 |
|
| 23681 |
procedure Declare_Shift_Operator (Nam : Name_Id); |
| 23682 |
-- Insert declaration and pragma Instrinsic for named shift op |
| 23683 |
|
| 23684 |
---------------------------- |
| 23685 |
-- Declare_Shift_Operator -- |
| 23686 |
---------------------------- |
| 23687 |
|
| 23688 |
procedure Declare_Shift_Operator (Nam : Name_Id) is |
| 23689 |
Func : Node_Id; |
| 23690 |
Import : Node_Id; |
| 23691 |
|
| 23692 |
begin |
| 23693 |
Func := |
| 23694 |
Make_Subprogram_Declaration (Loc, |
| 23695 |
Make_Function_Specification (Loc, |
| 23696 |
Defining_Unit_Name => |
| 23697 |
Make_Defining_Identifier (Loc, Chars => Nam), |
| 23698 |
|
| 23699 |
Result_Definition => |
| 23700 |
Make_Identifier (Loc, Chars => Chars (Ent)), |
| 23701 |
|
| 23702 |
Parameter_Specifications => New_List ( |
| 23703 |
Make_Parameter_Specification (Loc, |
| 23704 |
Defining_Identifier => |
| 23705 |
Make_Defining_Identifier (Loc, Name_Value), |
| 23706 |
Parameter_Type => |
| 23707 |
Make_Identifier (Loc, Chars => Chars (Ent))), |
| 23708 |
|
| 23709 |
Make_Parameter_Specification (Loc, |
| 23710 |
Defining_Identifier => |
| 23711 |
Make_Defining_Identifier (Loc, Name_Amount), |
| 23712 |
Parameter_Type => |
| 23713 |
New_Occurrence_Of (Standard_Natural, Loc))))); |
| 23714 |
|
| 23715 |
Import := |
| 23716 |
Make_Pragma (Loc, |
| 23717 |
Chars => Name_Import, |
| 23718 |
Pragma_Argument_Associations => New_List ( |
| 23719 |
Make_Pragma_Argument_Association (Loc, |
| 23720 |
Expression => Make_Identifier (Loc, Name_Intrinsic)), |
| 23721 |
Make_Pragma_Argument_Association (Loc, |
| 23722 |
Expression => Make_Identifier (Loc, Nam)))); |
| 23723 |
|
| 23724 |
Insert_After (N, Import); |
| 23725 |
Insert_After (N, Func); |
| 23726 |
end Declare_Shift_Operator; |
| 23727 |
|
| 23728 |
-- Start of processing for Provide_Shift_Operators |
| 23729 |
|
| 23730 |
begin |
| 23731 |
GNAT_Pragma; |
| 23732 |
Check_Arg_Count (1); |
| 23733 |
Check_Arg_Is_Local_Name (Arg1); |
| 23734 |
|
| 23735 |
Arg1 := Get_Pragma_Arg (Arg1); |
| 23736 |
|
| 23737 |
-- We must have an entity name |
| 23738 |
|
| 23739 |
if not Is_Entity_Name (Arg1) then |
| 23740 |
Error_Pragma_Arg |
| 23741 |
("pragma % must apply to integer first subtype", Arg1); |
| 23742 |
end if; |
| 23743 |
|
| 23744 |
-- If no Entity, means there was a prior error so ignore |
| 23745 |
|
| 23746 |
if Present (Entity (Arg1)) then |
| 23747 |
Ent := Entity (Arg1); |
| 23748 |
|
| 23749 |
-- Apply error checks |
| 23750 |
|
| 23751 |
if not Is_First_Subtype (Ent) then |
| 23752 |
Error_Pragma_Arg |
| 23753 |
("cannot apply pragma %", |
| 23754 |
"\& is not a first subtype", |
| 23755 |
Arg1); |
| 23756 |
|
| 23757 |
elsif not Is_Integer_Type (Ent) then |
| 23758 |
Error_Pragma_Arg |
| 23759 |
("cannot apply pragma %", |
| 23760 |
"\& is not an integer type", |
| 23761 |
Arg1); |
| 23762 |
|
| 23763 |
elsif Has_Shift_Operator (Ent) then |
| 23764 |
Error_Pragma_Arg |
| 23765 |
("cannot apply pragma %", |
| 23766 |
"\& already has declared shift operators", |
| 23767 |
Arg1); |
| 23768 |
|
| 23769 |
elsif Is_Frozen (Ent) then |
| 23770 |
Error_Pragma_Arg |
| 23771 |
("pragma % appears too late", |
| 23772 |
"\& is already frozen", |
| 23773 |
Arg1); |
| 23774 |
end if; |
| 23775 |
|
| 23776 |
-- Now declare the operators. We do this during analysis rather |
| 23777 |
-- than expansion, since we want the operators available if we |
| 23778 |
-- are operating in -gnatc mode. |
| 23779 |
|
| 23780 |
Declare_Shift_Operator (Name_Rotate_Left); |
| 23781 |
Declare_Shift_Operator (Name_Rotate_Right); |
| 23782 |
Declare_Shift_Operator (Name_Shift_Left); |
| 23783 |
Declare_Shift_Operator (Name_Shift_Right); |
| 23784 |
Declare_Shift_Operator (Name_Shift_Right_Arithmetic); |
| 23785 |
end if; |
| 23786 |
end Provide_Shift_Operators; |
| 23787 |
|
| 23788 |
------------------ |
| 23789 |
-- Psect_Object -- |
| 23790 |
------------------ |
| 23791 |
|
| 23792 |
-- pragma Psect_Object ( |
| 23793 |
-- [Internal =>] LOCAL_NAME, |
| 23794 |
-- [, [External =>] EXTERNAL_SYMBOL] |
| 23795 |
-- [, [Size =>] EXTERNAL_SYMBOL]); |
| 23796 |
|
| 23797 |
when Pragma_Common_Object |
| 23798 |
| Pragma_Psect_Object |
| 23799 |
=> |
| 23800 |
Psect_Object : declare |
| 23801 |
Args : Args_List (1 .. 3); |
| 23802 |
Names : constant Name_List (1 .. 3) := ( |
| 23803 |
Name_Internal, |
| 23804 |
Name_External, |
| 23805 |
Name_Size); |
| 23806 |
|
| 23807 |
Internal : Node_Id renames Args (1); |
| 23808 |
External : Node_Id renames Args (2); |
| 23809 |
Size : Node_Id renames Args (3); |
| 23810 |
|
| 23811 |
Def_Id : Entity_Id; |
| 23812 |
|
| 23813 |
procedure Check_Arg (Arg : Node_Id); |
| 23814 |
-- Checks that argument is either a string literal or an |
| 23815 |
-- identifier, and posts error message if not. |
| 23816 |
|
| 23817 |
--------------- |
| 23818 |
-- Check_Arg -- |
| 23819 |
--------------- |
| 23820 |
|
| 23821 |
procedure Check_Arg (Arg : Node_Id) is |
| 23822 |
begin |
| 23823 |
if Nkind (Original_Node (Arg)) not in |
| 23824 |
N_String_Literal | N_Identifier |
| 23825 |
then |
| 23826 |
Error_Pragma_Arg |
| 23827 |
("inappropriate argument for pragma %", Arg); |
| 23828 |
end if; |
| 23829 |
end Check_Arg; |
| 23830 |
|
| 23831 |
-- Start of processing for Common_Object/Psect_Object |
| 23832 |
|
| 23833 |
begin |
| 23834 |
GNAT_Pragma; |
| 23835 |
Gather_Associations (Names, Args); |
| 23836 |
Process_Extended_Import_Export_Internal_Arg (Internal); |
| 23837 |
|
| 23838 |
Def_Id := Entity (Internal); |
| 23839 |
|
| 23840 |
if Ekind (Def_Id) not in E_Constant | E_Variable then |
| 23841 |
Error_Pragma_Arg |
| 23842 |
("pragma% must designate an object", Internal); |
| 23843 |
end if; |
| 23844 |
|
| 23845 |
Check_Arg (Internal); |
| 23846 |
|
| 23847 |
if Is_Imported (Def_Id) or else Is_Exported (Def_Id) then |
| 23848 |
Error_Pragma_Arg |
| 23849 |
("cannot use pragma% for imported/exported object", |
| 23850 |
Internal); |
| 23851 |
end if; |
| 23852 |
|
| 23853 |
if Is_Concurrent_Type (Etype (Internal)) then |
| 23854 |
Error_Pragma_Arg |
| 23855 |
("cannot specify pragma % for task/protected object", |
| 23856 |
Internal); |
| 23857 |
end if; |
| 23858 |
|
| 23859 |
if Has_Rep_Pragma (Def_Id, Name_Common_Object) |
| 23860 |
or else |
| 23861 |
Has_Rep_Pragma (Def_Id, Name_Psect_Object) |
| 23862 |
then |
| 23863 |
Error_Msg_N ("??duplicate Common/Psect_Object pragma", N); |
| 23864 |
end if; |
| 23865 |
|
| 23866 |
if Ekind (Def_Id) = E_Constant then |
| 23867 |
Error_Pragma_Arg |
| 23868 |
("cannot specify pragma % for a constant", Internal); |
| 23869 |
end if; |
| 23870 |
|
| 23871 |
if Is_Record_Type (Etype (Internal)) then |
| 23872 |
declare |
| 23873 |
Ent : Entity_Id; |
| 23874 |
Decl : Entity_Id; |
| 23875 |
|
| 23876 |
begin |
| 23877 |
Ent := First_Entity (Etype (Internal)); |
| 23878 |
while Present (Ent) loop |
| 23879 |
Decl := Declaration_Node (Ent); |
| 23880 |
|
| 23881 |
if Ekind (Ent) = E_Component |
| 23882 |
and then Nkind (Decl) = N_Component_Declaration |
| 23883 |
and then Present (Expression (Decl)) |
| 23884 |
and then Warn_On_Export_Import |
| 23885 |
then |
| 23886 |
Error_Msg_N |
| 23887 |
("?x?object for pragma % has defaults", Internal); |
| 23888 |
exit; |
| 23889 |
|
| 23890 |
else |
| 23891 |
Next_Entity (Ent); |
| 23892 |
end if; |
| 23893 |
end loop; |
| 23894 |
end; |
| 23895 |
end if; |
| 23896 |
|
| 23897 |
if Present (Size) then |
| 23898 |
Check_Arg (Size); |
| 23899 |
end if; |
| 23900 |
|
| 23901 |
if Present (External) then |
| 23902 |
Check_Arg_Is_External_Name (External); |
| 23903 |
end if; |
| 23904 |
|
| 23905 |
-- If all error tests pass, link pragma on to the rep item chain |
| 23906 |
|
| 23907 |
Record_Rep_Item (Def_Id, N); |
| 23908 |
end Psect_Object; |
| 23909 |
|
| 23910 |
---------- |
| 23911 |
-- Pure -- |
| 23912 |
---------- |
| 23913 |
|
| 23914 |
-- pragma Pure [(library_unit_NAME)]; |
| 23915 |
|
| 23916 |
when Pragma_Pure => Pure : declare |
| 23917 |
Ent : Entity_Id; |
| 23918 |
|
| 23919 |
begin |
| 23920 |
Check_Ada_83_Warning; |
| 23921 |
|
| 23922 |
-- If the pragma comes from a subprogram instantiation, nothing to |
| 23923 |
-- check, this can happen at any level of nesting. |
| 23924 |
|
| 23925 |
if Is_Wrapper_Package (Current_Scope) then |
| 23926 |
return; |
| 23927 |
end if; |
| 23928 |
|
| 23929 |
Check_Valid_Library_Unit_Pragma; |
| 23930 |
|
| 23931 |
-- If N was rewritten as a null statement there is nothing more |
| 23932 |
-- to do. |
| 23933 |
|
| 23934 |
if Nkind (N) = N_Null_Statement then |
| 23935 |
return; |
| 23936 |
end if; |
| 23937 |
|
| 23938 |
Ent := Find_Lib_Unit_Name; |
| 23939 |
|
| 23940 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 23941 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 23942 |
|
| 23943 |
Mark_Ghost_Pragma (N, Ent); |
| 23944 |
|
| 23945 |
if not Debug_Flag_U then |
| 23946 |
Set_Is_Pure (Ent); |
| 23947 |
Set_Has_Pragma_Pure (Ent); |
| 23948 |
|
| 23949 |
if Legacy_Elaboration_Checks then |
| 23950 |
Set_Suppress_Elaboration_Warnings (Ent); |
| 23951 |
end if; |
| 23952 |
end if; |
| 23953 |
end Pure; |
| 23954 |
|
| 23955 |
------------------- |
| 23956 |
-- Pure_Function -- |
| 23957 |
------------------- |
| 23958 |
|
| 23959 |
-- pragma Pure_Function ([Entity =>] function_LOCAL_NAME); |
| 23960 |
|
| 23961 |
when Pragma_Pure_Function => Pure_Function : declare |
| 23962 |
Def_Id : Entity_Id; |
| 23963 |
E : Entity_Id; |
| 23964 |
E_Id : Node_Id; |
| 23965 |
Effective : Boolean := False; |
| 23966 |
Orig_Def : Entity_Id; |
| 23967 |
Same_Decl : Boolean := False; |
| 23968 |
|
| 23969 |
begin |
| 23970 |
GNAT_Pragma; |
| 23971 |
Check_Arg_Count (1); |
| 23972 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 23973 |
Check_Arg_Is_Local_Name (Arg1); |
| 23974 |
E_Id := Get_Pragma_Arg (Arg1); |
| 23975 |
|
| 23976 |
if Etype (E_Id) = Any_Type then |
| 23977 |
return; |
| 23978 |
end if; |
| 23979 |
|
| 23980 |
-- Loop through homonyms (overloadings) of referenced entity |
| 23981 |
|
| 23982 |
E := Entity (E_Id); |
| 23983 |
|
| 23984 |
Analyze_If_Present (Pragma_Side_Effects); |
| 23985 |
|
| 23986 |
-- A function with side effects shall not have a Pure_Function |
| 23987 |
-- aspect or pragma (SPARK RM 6.1.11(5)). |
| 23988 |
|
| 23989 |
if Is_Function_With_Side_Effects (E) then |
| 23990 |
Error_Pragma |
| 23991 |
("pragma % incompatible with ""Side_Effects"""); |
| 23992 |
end if; |
| 23993 |
|
| 23994 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 23995 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 23996 |
|
| 23997 |
Mark_Ghost_Pragma (N, E); |
| 23998 |
|
| 23999 |
if Present (E) then |
| 24000 |
loop |
| 24001 |
Def_Id := Get_Base_Subprogram (E); |
| 24002 |
|
| 24003 |
if Ekind (Def_Id) not in |
| 24004 |
E_Function | E_Generic_Function | E_Operator |
| 24005 |
then |
| 24006 |
Error_Pragma_Arg |
| 24007 |
("pragma% requires a function name", Arg1); |
| 24008 |
end if; |
| 24009 |
|
| 24010 |
-- When we have a generic function we must jump up a level |
| 24011 |
-- to the declaration of the wrapper package itself. |
| 24012 |
|
| 24013 |
Orig_Def := Def_Id; |
| 24014 |
|
| 24015 |
if Is_Generic_Instance (Def_Id) then |
| 24016 |
while Nkind (Orig_Def) /= N_Package_Declaration loop |
| 24017 |
Orig_Def := Parent (Orig_Def); |
| 24018 |
end loop; |
| 24019 |
end if; |
| 24020 |
|
| 24021 |
if In_Same_Declarative_Part (Parent (N), Orig_Def) then |
| 24022 |
Same_Decl := True; |
| 24023 |
Set_Is_Pure (Def_Id); |
| 24024 |
|
| 24025 |
if not Has_Pragma_Pure_Function (Def_Id) then |
| 24026 |
Set_Has_Pragma_Pure_Function (Def_Id); |
| 24027 |
Effective := True; |
| 24028 |
end if; |
| 24029 |
end if; |
| 24030 |
|
| 24031 |
exit when From_Aspect_Specification (N); |
| 24032 |
E := Homonym (E); |
| 24033 |
exit when No (E) or else Scope (E) /= Current_Scope; |
| 24034 |
end loop; |
| 24035 |
|
| 24036 |
if not Effective |
| 24037 |
and then Warn_On_Redundant_Constructs |
| 24038 |
then |
| 24039 |
Error_Msg_NE |
| 24040 |
("pragma Pure_Function on& is redundant?r?", |
| 24041 |
N, Entity (E_Id)); |
| 24042 |
|
| 24043 |
elsif not Same_Decl then |
| 24044 |
Error_Pragma_Arg |
| 24045 |
("pragma% argument must be in same declarative part", |
| 24046 |
Arg1); |
| 24047 |
end if; |
| 24048 |
end if; |
| 24049 |
end Pure_Function; |
| 24050 |
|
| 24051 |
-------------------- |
| 24052 |
-- Queuing_Policy -- |
| 24053 |
-------------------- |
| 24054 |
|
| 24055 |
-- pragma Queuing_Policy (policy_IDENTIFIER); |
| 24056 |
|
| 24057 |
when Pragma_Queuing_Policy => declare |
| 24058 |
QP : Character; |
| 24059 |
|
| 24060 |
begin |
| 24061 |
Check_Ada_83_Warning; |
| 24062 |
Check_Arg_Count (1); |
| 24063 |
Check_No_Identifiers; |
| 24064 |
Check_Arg_Is_Queuing_Policy (Arg1); |
| 24065 |
Check_Valid_Configuration_Pragma; |
| 24066 |
Get_Name_String (Chars (Get_Pragma_Arg (Arg1))); |
| 24067 |
QP := Fold_Upper (Name_Buffer (1)); |
| 24068 |
|
| 24069 |
if Queuing_Policy /= ' ' |
| 24070 |
and then Queuing_Policy /= QP |
| 24071 |
then |
| 24072 |
Error_Msg_Sloc := Queuing_Policy_Sloc; |
| 24073 |
Error_Pragma ("queuing policy incompatible with policy#"); |
| 24074 |
|
| 24075 |
-- Set new policy, but always preserve System_Location since we |
| 24076 |
-- like the error message with the run time name. |
| 24077 |
|
| 24078 |
else |
| 24079 |
Queuing_Policy := QP; |
| 24080 |
|
| 24081 |
if Queuing_Policy_Sloc /= System_Location then |
| 24082 |
Queuing_Policy_Sloc := Loc; |
| 24083 |
end if; |
| 24084 |
end if; |
| 24085 |
end; |
| 24086 |
|
| 24087 |
-------------- |
| 24088 |
-- Rational -- |
| 24089 |
-------------- |
| 24090 |
|
| 24091 |
-- pragma Rational, for compatibility with foreign compiler |
| 24092 |
|
| 24093 |
when Pragma_Rational => |
| 24094 |
Set_Rational_Profile; |
| 24095 |
|
| 24096 |
--------------------- |
| 24097 |
-- Refined_Depends -- |
| 24098 |
--------------------- |
| 24099 |
|
| 24100 |
-- pragma Refined_Depends (DEPENDENCY_RELATION); |
| 24101 |
|
| 24102 |
-- DEPENDENCY_RELATION ::= |
| 24103 |
-- null |
| 24104 |
-- | (DEPENDENCY_CLAUSE {, DEPENDENCY_CLAUSE}) |
| 24105 |
|
| 24106 |
-- DEPENDENCY_CLAUSE ::= |
| 24107 |
-- OUTPUT_LIST =>[+] INPUT_LIST |
| 24108 |
-- | NULL_DEPENDENCY_CLAUSE |
| 24109 |
|
| 24110 |
-- NULL_DEPENDENCY_CLAUSE ::= null => INPUT_LIST |
| 24111 |
|
| 24112 |
-- OUTPUT_LIST ::= OUTPUT | (OUTPUT {, OUTPUT}) |
| 24113 |
|
| 24114 |
-- INPUT_LIST ::= null | INPUT | (INPUT {, INPUT}) |
| 24115 |
|
| 24116 |
-- OUTPUT ::= NAME | FUNCTION_RESULT |
| 24117 |
-- INPUT ::= NAME |
| 24118 |
|
| 24119 |
-- where FUNCTION_RESULT is a function Result attribute_reference |
| 24120 |
|
| 24121 |
-- Characteristics: |
| 24122 |
|
| 24123 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 24124 |
-- the legal placement and context. Secondary checks fully analyze |
| 24125 |
-- the dependency clauses/global list in: |
| 24126 |
|
| 24127 |
-- Analyze_Refined_Depends_In_Decl_Part |
| 24128 |
|
| 24129 |
-- * Expansion - None. |
| 24130 |
|
| 24131 |
-- * Template - The annotation utilizes the generic template of the |
| 24132 |
-- related subprogram body. |
| 24133 |
|
| 24134 |
-- * Globals - Capture of global references must occur after full |
| 24135 |
-- analysis. |
| 24136 |
|
| 24137 |
-- * Instance - The annotation is instantiated automatically when |
| 24138 |
-- the related generic subprogram body is instantiated. |
| 24139 |
|
| 24140 |
when Pragma_Refined_Depends => Refined_Depends : declare |
| 24141 |
Body_Id : Entity_Id; |
| 24142 |
Legal : Boolean; |
| 24143 |
Spec_Id : Entity_Id; |
| 24144 |
|
| 24145 |
begin |
| 24146 |
Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal); |
| 24147 |
|
| 24148 |
if Legal then |
| 24149 |
|
| 24150 |
-- Chain the pragma on the contract for further processing by |
| 24151 |
-- Analyze_Refined_Depends_In_Decl_Part. |
| 24152 |
|
| 24153 |
Add_Contract_Item (N, Body_Id); |
| 24154 |
|
| 24155 |
-- The legality checks of pragmas Refined_Depends and |
| 24156 |
-- Refined_Global are affected by the SPARK mode in effect and |
| 24157 |
-- the volatility of the context. In addition these two pragmas |
| 24158 |
-- are subject to an inherent order: |
| 24159 |
|
| 24160 |
-- 1) Refined_Global |
| 24161 |
-- 2) Refined_Depends |
| 24162 |
|
| 24163 |
-- Analyze all these pragmas in the order outlined above |
| 24164 |
|
| 24165 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 24166 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 24167 |
Analyze_If_Present (Pragma_Side_Effects); |
| 24168 |
Analyze_If_Present (Pragma_Refined_Global); |
| 24169 |
Analyze_Refined_Depends_In_Decl_Part (N); |
| 24170 |
end if; |
| 24171 |
end Refined_Depends; |
| 24172 |
|
| 24173 |
-------------------- |
| 24174 |
-- Refined_Global -- |
| 24175 |
-------------------- |
| 24176 |
|
| 24177 |
-- pragma Refined_Global (GLOBAL_SPECIFICATION); |
| 24178 |
|
| 24179 |
-- GLOBAL_SPECIFICATION ::= |
| 24180 |
-- null |
| 24181 |
-- | (GLOBAL_LIST) |
| 24182 |
-- | (MODED_GLOBAL_LIST {, MODED_GLOBAL_LIST}) |
| 24183 |
|
| 24184 |
-- MODED_GLOBAL_LIST ::= MODE_SELECTOR => GLOBAL_LIST |
| 24185 |
|
| 24186 |
-- MODE_SELECTOR ::= In_Out | Input | Output | Proof_In |
| 24187 |
-- GLOBAL_LIST ::= GLOBAL_ITEM | (GLOBAL_ITEM {, GLOBAL_ITEM}) |
| 24188 |
-- GLOBAL_ITEM ::= NAME |
| 24189 |
|
| 24190 |
-- Characteristics: |
| 24191 |
|
| 24192 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 24193 |
-- the legal placement and context. Secondary checks fully analyze |
| 24194 |
-- the dependency clauses/global list in: |
| 24195 |
|
| 24196 |
-- Analyze_Refined_Global_In_Decl_Part |
| 24197 |
|
| 24198 |
-- * Expansion - None. |
| 24199 |
|
| 24200 |
-- * Template - The annotation utilizes the generic template of the |
| 24201 |
-- related subprogram body. |
| 24202 |
|
| 24203 |
-- * Globals - Capture of global references must occur after full |
| 24204 |
-- analysis. |
| 24205 |
|
| 24206 |
-- * Instance - The annotation is instantiated automatically when |
| 24207 |
-- the related generic subprogram body is instantiated. |
| 24208 |
|
| 24209 |
when Pragma_Refined_Global => Refined_Global : declare |
| 24210 |
Body_Id : Entity_Id; |
| 24211 |
Legal : Boolean; |
| 24212 |
Spec_Id : Entity_Id; |
| 24213 |
|
| 24214 |
begin |
| 24215 |
Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal); |
| 24216 |
|
| 24217 |
if Legal then |
| 24218 |
|
| 24219 |
-- Chain the pragma on the contract for further processing by |
| 24220 |
-- Analyze_Refined_Global_In_Decl_Part. |
| 24221 |
|
| 24222 |
Add_Contract_Item (N, Body_Id); |
| 24223 |
|
| 24224 |
-- The legality checks of pragmas Refined_Depends and |
| 24225 |
-- Refined_Global are affected by the SPARK mode in effect and |
| 24226 |
-- the volatility of the context. In addition these two pragmas |
| 24227 |
-- are subject to an inherent order: |
| 24228 |
|
| 24229 |
-- 1) Refined_Global |
| 24230 |
-- 2) Refined_Depends |
| 24231 |
|
| 24232 |
-- Analyze all these pragmas in the order outlined above |
| 24233 |
|
| 24234 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 24235 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 24236 |
Analyze_If_Present (Pragma_Side_Effects); |
| 24237 |
Analyze_Refined_Global_In_Decl_Part (N); |
| 24238 |
Analyze_If_Present (Pragma_Refined_Depends); |
| 24239 |
end if; |
| 24240 |
end Refined_Global; |
| 24241 |
|
| 24242 |
------------------ |
| 24243 |
-- Refined_Post -- |
| 24244 |
------------------ |
| 24245 |
|
| 24246 |
-- pragma Refined_Post (boolean_EXPRESSION); |
| 24247 |
|
| 24248 |
-- Characteristics: |
| 24249 |
|
| 24250 |
-- * Analysis - The annotation is fully analyzed immediately upon |
| 24251 |
-- elaboration as it cannot forward reference entities. |
| 24252 |
|
| 24253 |
-- * Expansion - The annotation is expanded during the expansion of |
| 24254 |
-- the related subprogram body contract as performed in: |
| 24255 |
|
| 24256 |
-- Expand_Subprogram_Contract |
| 24257 |
|
| 24258 |
-- * Template - The annotation utilizes the generic template of the |
| 24259 |
-- related subprogram body. |
| 24260 |
|
| 24261 |
-- * Globals - Capture of global references must occur after full |
| 24262 |
-- analysis. |
| 24263 |
|
| 24264 |
-- * Instance - The annotation is instantiated automatically when |
| 24265 |
-- the related generic subprogram body is instantiated. |
| 24266 |
|
| 24267 |
when Pragma_Refined_Post => Refined_Post : declare |
| 24268 |
Body_Id : Entity_Id; |
| 24269 |
Legal : Boolean; |
| 24270 |
Spec_Id : Entity_Id; |
| 24271 |
|
| 24272 |
begin |
| 24273 |
Analyze_Refined_Depends_Global_Post (Spec_Id, Body_Id, Legal); |
| 24274 |
|
| 24275 |
-- Fully analyze the pragma when it appears inside a subprogram |
| 24276 |
-- body because it cannot benefit from forward references. |
| 24277 |
|
| 24278 |
if Legal then |
| 24279 |
|
| 24280 |
-- Chain the pragma on the contract for completeness |
| 24281 |
|
| 24282 |
Add_Contract_Item (N, Body_Id); |
| 24283 |
|
| 24284 |
-- The legality checks of pragma Refined_Post are affected by |
| 24285 |
-- the SPARK mode in effect and the volatility of the context. |
| 24286 |
-- Analyze all pragmas in a specific order. |
| 24287 |
|
| 24288 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 24289 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 24290 |
Analyze_Pre_Post_Condition_In_Decl_Part (N); |
| 24291 |
|
| 24292 |
-- Currently it is not possible to inline pre/postconditions on |
| 24293 |
-- a subprogram subject to pragma Inline_Always. |
| 24294 |
|
| 24295 |
Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); |
| 24296 |
end if; |
| 24297 |
end Refined_Post; |
| 24298 |
|
| 24299 |
------------------- |
| 24300 |
-- Refined_State -- |
| 24301 |
------------------- |
| 24302 |
|
| 24303 |
-- pragma Refined_State (REFINEMENT_LIST); |
| 24304 |
|
| 24305 |
-- REFINEMENT_LIST ::= |
| 24306 |
-- (REFINEMENT_CLAUSE {, REFINEMENT_CLAUSE}) |
| 24307 |
|
| 24308 |
-- REFINEMENT_CLAUSE ::= state_NAME => CONSTITUENT_LIST |
| 24309 |
|
| 24310 |
-- CONSTITUENT_LIST ::= |
| 24311 |
-- null |
| 24312 |
-- | CONSTITUENT |
| 24313 |
-- | (CONSTITUENT {, CONSTITUENT}) |
| 24314 |
|
| 24315 |
-- CONSTITUENT ::= object_NAME | state_NAME |
| 24316 |
|
| 24317 |
-- Characteristics: |
| 24318 |
|
| 24319 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 24320 |
-- the legal placement and context. Secondary checks preanalyze the |
| 24321 |
-- refinement clauses in: |
| 24322 |
|
| 24323 |
-- Analyze_Refined_State_In_Decl_Part |
| 24324 |
|
| 24325 |
-- * Expansion - None. |
| 24326 |
|
| 24327 |
-- * Template - The annotation utilizes the template of the related |
| 24328 |
-- package body. |
| 24329 |
|
| 24330 |
-- * Globals - Capture of global references must occur after full |
| 24331 |
-- analysis. |
| 24332 |
|
| 24333 |
-- * Instance - The annotation is instantiated automatically when |
| 24334 |
-- the related generic package body is instantiated. |
| 24335 |
|
| 24336 |
when Pragma_Refined_State => Refined_State : declare |
| 24337 |
Pack_Decl : Node_Id; |
| 24338 |
Spec_Id : Entity_Id; |
| 24339 |
|
| 24340 |
begin |
| 24341 |
GNAT_Pragma; |
| 24342 |
Check_No_Identifiers; |
| 24343 |
Check_Arg_Count (1); |
| 24344 |
|
| 24345 |
Pack_Decl := Find_Related_Package_Or_Body (N, Do_Checks => True); |
| 24346 |
|
| 24347 |
if Nkind (Pack_Decl) /= N_Package_Body then |
| 24348 |
Pragma_Misplaced; |
| 24349 |
end if; |
| 24350 |
|
| 24351 |
Spec_Id := Corresponding_Spec (Pack_Decl); |
| 24352 |
|
| 24353 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 24354 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 24355 |
|
| 24356 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 24357 |
|
| 24358 |
-- Chain the pragma on the contract for further processing by |
| 24359 |
-- Analyze_Refined_State_In_Decl_Part. |
| 24360 |
|
| 24361 |
Add_Contract_Item (N, Defining_Entity (Pack_Decl)); |
| 24362 |
|
| 24363 |
-- The legality checks of pragma Refined_State are affected by the |
| 24364 |
-- SPARK mode in effect. Analyze all pragmas in a specific order. |
| 24365 |
|
| 24366 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 24367 |
|
| 24368 |
-- State refinement is allowed only when the corresponding package |
| 24369 |
-- declaration has non-null pragma Abstract_State (SPARK RM |
| 24370 |
-- 7.2.2(3)). |
| 24371 |
|
| 24372 |
if No (Abstract_States (Spec_Id)) |
| 24373 |
or else Has_Null_Abstract_State (Spec_Id) |
| 24374 |
then |
| 24375 |
SPARK_Msg_NE |
| 24376 |
("useless refinement, package & does not define abstract " |
| 24377 |
& "states", N, Spec_Id); |
| 24378 |
return; |
| 24379 |
end if; |
| 24380 |
end Refined_State; |
| 24381 |
|
| 24382 |
----------------------- |
| 24383 |
-- Relative_Deadline -- |
| 24384 |
----------------------- |
| 24385 |
|
| 24386 |
-- pragma Relative_Deadline (time_span_EXPRESSION); |
| 24387 |
|
| 24388 |
when Pragma_Relative_Deadline => Relative_Deadline : declare |
| 24389 |
P : constant Node_Id := Parent (N); |
| 24390 |
Arg : Node_Id; |
| 24391 |
|
| 24392 |
begin |
| 24393 |
Ada_2005_Pragma; |
| 24394 |
Check_No_Identifiers; |
| 24395 |
Check_Arg_Count (1); |
| 24396 |
|
| 24397 |
Arg := Get_Pragma_Arg (Arg1); |
| 24398 |
|
| 24399 |
-- The expression must be analyzed in the special manner described |
| 24400 |
-- in "Handling of Default and Per-Object Expressions" in sem.ads. |
| 24401 |
|
| 24402 |
Preanalyze_Spec_Expression (Arg, RTE (RE_Time_Span)); |
| 24403 |
|
| 24404 |
-- Subprogram case |
| 24405 |
|
| 24406 |
if Nkind (P) = N_Subprogram_Body then |
| 24407 |
Check_In_Main_Program; |
| 24408 |
|
| 24409 |
-- Only Task and subprogram cases allowed |
| 24410 |
|
| 24411 |
elsif Nkind (P) /= N_Task_Definition then |
| 24412 |
Pragma_Misplaced; |
| 24413 |
end if; |
| 24414 |
|
| 24415 |
-- Check duplicate pragma before we set the corresponding flag |
| 24416 |
|
| 24417 |
if Has_Relative_Deadline_Pragma (P) then |
| 24418 |
Error_Pragma ("duplicate pragma% not allowed"); |
| 24419 |
end if; |
| 24420 |
|
| 24421 |
-- Set Has_Relative_Deadline_Pragma only for tasks. Note that |
| 24422 |
-- Relative_Deadline pragma node cannot be inserted in the Rep |
| 24423 |
-- Item chain of Ent since it is rewritten by the expander as a |
| 24424 |
-- procedure call statement that will break the chain. |
| 24425 |
|
| 24426 |
Set_Has_Relative_Deadline_Pragma (P); |
| 24427 |
end Relative_Deadline; |
| 24428 |
|
| 24429 |
------------------------ |
| 24430 |
-- Remote_Access_Type -- |
| 24431 |
------------------------ |
| 24432 |
|
| 24433 |
-- pragma Remote_Access_Type ([Entity =>] formal_type_LOCAL_NAME); |
| 24434 |
|
| 24435 |
when Pragma_Remote_Access_Type => Remote_Access_Type : declare |
| 24436 |
E : Entity_Id; |
| 24437 |
|
| 24438 |
begin |
| 24439 |
GNAT_Pragma; |
| 24440 |
Check_Arg_Count (1); |
| 24441 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 24442 |
Check_Arg_Is_Local_Name (Arg1); |
| 24443 |
|
| 24444 |
E := Entity (Get_Pragma_Arg (Arg1)); |
| 24445 |
|
| 24446 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 24447 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 24448 |
|
| 24449 |
Mark_Ghost_Pragma (N, E); |
| 24450 |
|
| 24451 |
if Nkind (Parent (E)) = N_Formal_Type_Declaration |
| 24452 |
and then Ekind (E) = E_General_Access_Type |
| 24453 |
and then Is_Class_Wide_Type (Directly_Designated_Type (E)) |
| 24454 |
and then Scope (Root_Type (Directly_Designated_Type (E))) |
| 24455 |
= Scope (E) |
| 24456 |
and then Is_Valid_Remote_Object_Type |
| 24457 |
(Root_Type (Directly_Designated_Type (E))) |
| 24458 |
then |
| 24459 |
Set_Is_Remote_Types (E); |
| 24460 |
|
| 24461 |
else |
| 24462 |
Error_Pragma_Arg |
| 24463 |
("pragma% applies only to formal access-to-class-wide types", |
| 24464 |
Arg1); |
| 24465 |
end if; |
| 24466 |
end Remote_Access_Type; |
| 24467 |
|
| 24468 |
--------------------------- |
| 24469 |
-- Remote_Call_Interface -- |
| 24470 |
--------------------------- |
| 24471 |
|
| 24472 |
-- pragma Remote_Call_Interface [(library_unit_NAME)]; |
| 24473 |
|
| 24474 |
when Pragma_Remote_Call_Interface => Remote_Call_Interface : declare |
| 24475 |
Cunit_Node : Node_Id; |
| 24476 |
Cunit_Ent : Entity_Id; |
| 24477 |
K : Node_Kind; |
| 24478 |
|
| 24479 |
begin |
| 24480 |
Check_Ada_83_Warning; |
| 24481 |
Check_Valid_Library_Unit_Pragma; |
| 24482 |
|
| 24483 |
-- If N was rewritten as a null statement there is nothing more |
| 24484 |
-- to do. |
| 24485 |
|
| 24486 |
if Nkind (N) = N_Null_Statement then |
| 24487 |
return; |
| 24488 |
end if; |
| 24489 |
|
| 24490 |
Cunit_Node := Cunit (Current_Sem_Unit); |
| 24491 |
K := Nkind (Unit (Cunit_Node)); |
| 24492 |
Cunit_Ent := Cunit_Entity (Current_Sem_Unit); |
| 24493 |
|
| 24494 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 24495 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 24496 |
|
| 24497 |
Mark_Ghost_Pragma (N, Cunit_Ent); |
| 24498 |
|
| 24499 |
if K = N_Package_Declaration |
| 24500 |
or else K = N_Generic_Package_Declaration |
| 24501 |
or else K = N_Subprogram_Declaration |
| 24502 |
or else K = N_Generic_Subprogram_Declaration |
| 24503 |
or else (K = N_Subprogram_Body |
| 24504 |
and then Acts_As_Spec (Unit (Cunit_Node))) |
| 24505 |
then |
| 24506 |
null; |
| 24507 |
else |
| 24508 |
Error_Pragma ( |
| 24509 |
"pragma% must apply to package or subprogram declaration"); |
| 24510 |
end if; |
| 24511 |
|
| 24512 |
Set_Is_Remote_Call_Interface (Cunit_Ent); |
| 24513 |
end Remote_Call_Interface; |
| 24514 |
|
| 24515 |
------------------ |
| 24516 |
-- Remote_Types -- |
| 24517 |
------------------ |
| 24518 |
|
| 24519 |
-- pragma Remote_Types [(library_unit_NAME)]; |
| 24520 |
|
| 24521 |
when Pragma_Remote_Types => Remote_Types : declare |
| 24522 |
Cunit_Node : Node_Id; |
| 24523 |
Cunit_Ent : Entity_Id; |
| 24524 |
|
| 24525 |
begin |
| 24526 |
Check_Ada_83_Warning; |
| 24527 |
Check_Valid_Library_Unit_Pragma; |
| 24528 |
|
| 24529 |
-- If N was rewritten as a null statement there is nothing more |
| 24530 |
-- to do. |
| 24531 |
|
| 24532 |
if Nkind (N) = N_Null_Statement then |
| 24533 |
return; |
| 24534 |
end if; |
| 24535 |
|
| 24536 |
Cunit_Node := Cunit (Current_Sem_Unit); |
| 24537 |
Cunit_Ent := Cunit_Entity (Current_Sem_Unit); |
| 24538 |
|
| 24539 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 24540 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 24541 |
|
| 24542 |
Mark_Ghost_Pragma (N, Cunit_Ent); |
| 24543 |
|
| 24544 |
if Nkind (Unit (Cunit_Node)) not in |
| 24545 |
N_Package_Declaration | N_Generic_Package_Declaration |
| 24546 |
then |
| 24547 |
Error_Pragma |
| 24548 |
("pragma% can only apply to a package declaration"); |
| 24549 |
end if; |
| 24550 |
|
| 24551 |
Set_Is_Remote_Types (Cunit_Ent); |
| 24552 |
end Remote_Types; |
| 24553 |
|
| 24554 |
--------------- |
| 24555 |
-- Ravenscar -- |
| 24556 |
--------------- |
| 24557 |
|
| 24558 |
-- pragma Ravenscar; |
| 24559 |
|
| 24560 |
when Pragma_Ravenscar => |
| 24561 |
GNAT_Pragma; |
| 24562 |
Check_Arg_Count (0); |
| 24563 |
Check_Valid_Configuration_Pragma; |
| 24564 |
Set_Ravenscar_Profile (Ravenscar, N); |
| 24565 |
|
| 24566 |
if Warn_On_Obsolescent_Feature then |
| 24567 |
Error_Msg_N |
| 24568 |
("pragma Ravenscar is an obsolescent feature?j?", N); |
| 24569 |
Error_Msg_N |
| 24570 |
("|use pragma Profile (Ravenscar) instead?j?", N); |
| 24571 |
end if; |
| 24572 |
|
| 24573 |
------------------------- |
| 24574 |
-- Restricted_Run_Time -- |
| 24575 |
------------------------- |
| 24576 |
|
| 24577 |
-- pragma Restricted_Run_Time; |
| 24578 |
|
| 24579 |
when Pragma_Restricted_Run_Time => |
| 24580 |
GNAT_Pragma; |
| 24581 |
Check_Arg_Count (0); |
| 24582 |
Check_Valid_Configuration_Pragma; |
| 24583 |
Set_Profile_Restrictions |
| 24584 |
(Restricted, N, Warn => Treat_Restrictions_As_Warnings); |
| 24585 |
|
| 24586 |
if Warn_On_Obsolescent_Feature then |
| 24587 |
Error_Msg_N |
| 24588 |
("pragma Restricted_Run_Time is an obsolescent feature?j?", |
| 24589 |
N); |
| 24590 |
Error_Msg_N |
| 24591 |
("|use pragma Profile (Restricted) instead?j?", N); |
| 24592 |
end if; |
| 24593 |
|
| 24594 |
------------------ |
| 24595 |
-- Restrictions -- |
| 24596 |
------------------ |
| 24597 |
|
| 24598 |
-- pragma Restrictions (RESTRICTION {, RESTRICTION}); |
| 24599 |
|
| 24600 |
-- RESTRICTION ::= |
| 24601 |
-- restriction_IDENTIFIER |
| 24602 |
-- | restriction_parameter_IDENTIFIER => EXPRESSION |
| 24603 |
|
| 24604 |
when Pragma_Restrictions => |
| 24605 |
Process_Restrictions_Or_Restriction_Warnings |
| 24606 |
(Warn => Treat_Restrictions_As_Warnings); |
| 24607 |
|
| 24608 |
-------------------------- |
| 24609 |
-- Restriction_Warnings -- |
| 24610 |
-------------------------- |
| 24611 |
|
| 24612 |
-- pragma Restriction_Warnings (RESTRICTION {, RESTRICTION}); |
| 24613 |
|
| 24614 |
-- RESTRICTION ::= |
| 24615 |
-- restriction_IDENTIFIER |
| 24616 |
-- | restriction_parameter_IDENTIFIER => EXPRESSION |
| 24617 |
|
| 24618 |
when Pragma_Restriction_Warnings => |
| 24619 |
GNAT_Pragma; |
| 24620 |
Process_Restrictions_Or_Restriction_Warnings (Warn => True); |
| 24621 |
|
| 24622 |
---------------- |
| 24623 |
-- Reviewable -- |
| 24624 |
---------------- |
| 24625 |
|
| 24626 |
-- pragma Reviewable; |
| 24627 |
|
| 24628 |
when Pragma_Reviewable => |
| 24629 |
Check_Ada_83_Warning; |
| 24630 |
Check_Arg_Count (0); |
| 24631 |
|
| 24632 |
-- Call dummy debugging function rv. This is done to assist front |
| 24633 |
-- end debugging. By placing a Reviewable pragma in the source |
| 24634 |
-- program, a breakpoint on rv catches this place in the source, |
| 24635 |
-- allowing convenient stepping to the point of interest. |
| 24636 |
|
| 24637 |
rv; |
| 24638 |
|
| 24639 |
-------------------------- |
| 24640 |
-- Secondary_Stack_Size -- |
| 24641 |
-------------------------- |
| 24642 |
|
| 24643 |
-- pragma Secondary_Stack_Size (EXPRESSION); |
| 24644 |
|
| 24645 |
when Pragma_Secondary_Stack_Size => Secondary_Stack_Size : declare |
| 24646 |
P : constant Node_Id := Parent (N); |
| 24647 |
Arg : Node_Id; |
| 24648 |
Ent : Entity_Id; |
| 24649 |
|
| 24650 |
begin |
| 24651 |
GNAT_Pragma; |
| 24652 |
Check_No_Identifiers; |
| 24653 |
Check_Arg_Count (1); |
| 24654 |
|
| 24655 |
if Nkind (P) = N_Task_Definition then |
| 24656 |
Arg := Get_Pragma_Arg (Arg1); |
| 24657 |
Ent := Defining_Identifier (Parent (P)); |
| 24658 |
|
| 24659 |
-- The expression must be analyzed in the special manner |
| 24660 |
-- described in "Handling of Default Expressions" in sem.ads. |
| 24661 |
|
| 24662 |
Preanalyze_Spec_Expression (Arg, Any_Integer); |
| 24663 |
|
| 24664 |
-- The pragma cannot appear if the No_Secondary_Stack |
| 24665 |
-- restriction is in effect. |
| 24666 |
|
| 24667 |
Check_Restriction (No_Secondary_Stack, Arg); |
| 24668 |
|
| 24669 |
-- Anything else is incorrect |
| 24670 |
|
| 24671 |
else |
| 24672 |
Pragma_Misplaced; |
| 24673 |
end if; |
| 24674 |
|
| 24675 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 24676 |
-- Item chain of Ent. |
| 24677 |
|
| 24678 |
Check_Duplicate_Pragma (Ent); |
| 24679 |
Record_Rep_Item (Ent, N); |
| 24680 |
end Secondary_Stack_Size; |
| 24681 |
|
| 24682 |
-------------------------- |
| 24683 |
-- Short_Circuit_And_Or -- |
| 24684 |
-------------------------- |
| 24685 |
|
| 24686 |
-- pragma Short_Circuit_And_Or; |
| 24687 |
|
| 24688 |
when Pragma_Short_Circuit_And_Or => |
| 24689 |
GNAT_Pragma; |
| 24690 |
Check_Arg_Count (0); |
| 24691 |
Check_Valid_Configuration_Pragma; |
| 24692 |
Short_Circuit_And_Or := True; |
| 24693 |
|
| 24694 |
------------------- |
| 24695 |
-- Share_Generic -- |
| 24696 |
------------------- |
| 24697 |
|
| 24698 |
-- pragma Share_Generic (GNAME {, GNAME}); |
| 24699 |
|
| 24700 |
-- GNAME ::= generic_unit_NAME | generic_instance_NAME |
| 24701 |
|
| 24702 |
when Pragma_Share_Generic => |
| 24703 |
GNAT_Pragma; |
| 24704 |
Process_Generic_List; |
| 24705 |
|
| 24706 |
------------ |
| 24707 |
-- Shared -- |
| 24708 |
------------ |
| 24709 |
|
| 24710 |
-- pragma Shared (LOCAL_NAME); |
| 24711 |
|
| 24712 |
when Pragma_Shared => |
| 24713 |
GNAT_Pragma; |
| 24714 |
Process_Atomic_Independent_Shared_Volatile; |
| 24715 |
|
| 24716 |
-------------------- |
| 24717 |
-- Shared_Passive -- |
| 24718 |
-------------------- |
| 24719 |
|
| 24720 |
-- pragma Shared_Passive [(library_unit_NAME)]; |
| 24721 |
|
| 24722 |
-- Set the flag Is_Shared_Passive of program unit name entity |
| 24723 |
|
| 24724 |
when Pragma_Shared_Passive => Shared_Passive : declare |
| 24725 |
Cunit_Node : Node_Id; |
| 24726 |
Cunit_Ent : Entity_Id; |
| 24727 |
|
| 24728 |
begin |
| 24729 |
Check_Ada_83_Warning; |
| 24730 |
Check_Valid_Library_Unit_Pragma; |
| 24731 |
|
| 24732 |
-- If N was rewritten as a null statement there is nothing more |
| 24733 |
-- to do. |
| 24734 |
|
| 24735 |
if Nkind (N) = N_Null_Statement then |
| 24736 |
return; |
| 24737 |
end if; |
| 24738 |
|
| 24739 |
Cunit_Node := Cunit (Current_Sem_Unit); |
| 24740 |
Cunit_Ent := Cunit_Entity (Current_Sem_Unit); |
| 24741 |
|
| 24742 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 24743 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 24744 |
|
| 24745 |
Mark_Ghost_Pragma (N, Cunit_Ent); |
| 24746 |
|
| 24747 |
if Nkind (Unit (Cunit_Node)) not in |
| 24748 |
N_Package_Declaration | N_Generic_Package_Declaration |
| 24749 |
then |
| 24750 |
Error_Pragma |
| 24751 |
("pragma% can only apply to a package declaration"); |
| 24752 |
end if; |
| 24753 |
|
| 24754 |
Set_Is_Shared_Passive (Cunit_Ent); |
| 24755 |
end Shared_Passive; |
| 24756 |
|
| 24757 |
----------------------- |
| 24758 |
-- Short_Descriptors -- |
| 24759 |
----------------------- |
| 24760 |
|
| 24761 |
-- pragma Short_Descriptors; |
| 24762 |
|
| 24763 |
-- Recognize and validate, but otherwise ignore |
| 24764 |
|
| 24765 |
when Pragma_Short_Descriptors => |
| 24766 |
GNAT_Pragma; |
| 24767 |
Check_Arg_Count (0); |
| 24768 |
Check_Valid_Configuration_Pragma; |
| 24769 |
|
| 24770 |
------------------ |
| 24771 |
-- Side_Effects -- |
| 24772 |
------------------ |
| 24773 |
|
| 24774 |
-- pragma Side_Effects [ (boolean_EXPRESSION) ]; |
| 24775 |
|
| 24776 |
-- Characteristics: |
| 24777 |
|
| 24778 |
-- * Analysis - The annotation is fully analyzed immediately upon |
| 24779 |
-- elaboration as its expression must be static. |
| 24780 |
|
| 24781 |
-- * Expansion - None. |
| 24782 |
|
| 24783 |
-- * Template - The annotation utilizes the generic template of the |
| 24784 |
-- related subprogram [body] when it is: |
| 24785 |
|
| 24786 |
-- aspect on subprogram declaration |
| 24787 |
-- aspect on stand-alone subprogram body |
| 24788 |
-- pragma on stand-alone subprogram body |
| 24789 |
|
| 24790 |
-- The annotation must prepare its own template when it is: |
| 24791 |
|
| 24792 |
-- pragma on subprogram declaration |
| 24793 |
|
| 24794 |
-- * Globals - Capture of global references must occur after full |
| 24795 |
-- analysis. |
| 24796 |
|
| 24797 |
-- * Instance - The annotation is instantiated automatically when |
| 24798 |
-- the related generic subprogram [body] is instantiated except for |
| 24799 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 24800 |
-- the annotation must instantiate itself. |
| 24801 |
|
| 24802 |
when Pragma_Side_Effects => Side_Effects : declare |
| 24803 |
Subp_Decl : Node_Id; |
| 24804 |
Spec_Id : Entity_Id; |
| 24805 |
Over_Id : Entity_Id; |
| 24806 |
|
| 24807 |
begin |
| 24808 |
GNAT_Pragma; |
| 24809 |
Check_No_Identifiers; |
| 24810 |
Check_At_Most_N_Arguments (1); |
| 24811 |
|
| 24812 |
Subp_Decl := |
| 24813 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 24814 |
|
| 24815 |
-- Abstract subprogram declaration |
| 24816 |
|
| 24817 |
if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then |
| 24818 |
null; |
| 24819 |
|
| 24820 |
-- Generic subprogram declaration |
| 24821 |
|
| 24822 |
elsif Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 24823 |
null; |
| 24824 |
|
| 24825 |
-- Body acts as spec |
| 24826 |
|
| 24827 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 24828 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 24829 |
then |
| 24830 |
null; |
| 24831 |
|
| 24832 |
-- Body stub acts as spec |
| 24833 |
|
| 24834 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 24835 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 24836 |
then |
| 24837 |
null; |
| 24838 |
|
| 24839 |
-- Subprogram declaration |
| 24840 |
|
| 24841 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 24842 |
null; |
| 24843 |
|
| 24844 |
-- Otherwise the pragma is associated with an illegal construct |
| 24845 |
|
| 24846 |
else |
| 24847 |
Error_Pragma ("pragma % must apply to a subprogram"); |
| 24848 |
end if; |
| 24849 |
|
| 24850 |
if Nkind (Specification (Subp_Decl)) /= N_Function_Specification |
| 24851 |
then |
| 24852 |
Error_Pragma ("pragma % must apply to a function"); |
| 24853 |
end if; |
| 24854 |
|
| 24855 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 24856 |
|
| 24857 |
-- Chain the pragma on the contract for completeness |
| 24858 |
|
| 24859 |
Add_Contract_Item (N, Spec_Id); |
| 24860 |
|
| 24861 |
-- A function with side effects cannot override a function without |
| 24862 |
-- side effects (SPARK RM 7.1.2(16)). Overriding checks are |
| 24863 |
-- usually performed in New_Overloaded_Entity, however at |
| 24864 |
-- that point the pragma has not been processed yet. |
| 24865 |
|
| 24866 |
Over_Id := Overridden_Operation (Spec_Id); |
| 24867 |
|
| 24868 |
if Present (Over_Id) |
| 24869 |
and then not Is_Function_With_Side_Effects (Over_Id) |
| 24870 |
then |
| 24871 |
Error_Msg_N |
| 24872 |
("incompatible declaration of side effects for function", |
| 24873 |
Spec_Id); |
| 24874 |
|
| 24875 |
Error_Msg_Sloc := Sloc (Over_Id); |
| 24876 |
Error_Msg_N |
| 24877 |
("\& declared # with Side_Effects value False", |
| 24878 |
Spec_Id); |
| 24879 |
|
| 24880 |
Error_Msg_Sloc := Sloc (Spec_Id); |
| 24881 |
Error_Msg_N |
| 24882 |
("\overridden # with Side_Effects value True", |
| 24883 |
Spec_Id); |
| 24884 |
end if; |
| 24885 |
|
| 24886 |
-- Analyze the Boolean expression (if any) |
| 24887 |
|
| 24888 |
if Present (Arg1) then |
| 24889 |
Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1)); |
| 24890 |
end if; |
| 24891 |
end Side_Effects; |
| 24892 |
|
| 24893 |
------------------------------------ |
| 24894 |
-- Pragma_Simulate_Internal_Error -- |
| 24895 |
------------------------------------ |
| 24896 |
|
| 24897 |
-- pragma Simulate_Internal_Error; |
| 24898 |
|
| 24899 |
-- Since the only purpose of this pragma is to write tests for the |
| 24900 |
-- compiler, it is not documented in the GNAT reference manual. The |
| 24901 |
-- effect of the pragma is to cause the compiler to raise an |
| 24902 |
-- exception when it analyzes the pragma. |
| 24903 |
|
| 24904 |
when Pragma_Simulate_Internal_Error => |
| 24905 |
Simulate_Internal_Error : declare |
| 24906 |
Simulated_Internal_Error : exception; |
| 24907 |
begin |
| 24908 |
GNAT_Pragma; |
| 24909 |
Check_Arg_Count (0); |
| 24910 |
|
| 24911 |
raise Simulated_Internal_Error; |
| 24912 |
end Simulate_Internal_Error; |
| 24913 |
|
| 24914 |
------------------------------ |
| 24915 |
-- Simple_Storage_Pool_Type -- |
| 24916 |
------------------------------ |
| 24917 |
|
| 24918 |
-- pragma Simple_Storage_Pool_Type (type_LOCAL_NAME); |
| 24919 |
|
| 24920 |
when Pragma_Simple_Storage_Pool_Type => |
| 24921 |
Simple_Storage_Pool_Type : declare |
| 24922 |
Typ : Entity_Id; |
| 24923 |
Type_Id : Node_Id; |
| 24924 |
|
| 24925 |
begin |
| 24926 |
GNAT_Pragma; |
| 24927 |
Check_Arg_Count (1); |
| 24928 |
Check_Arg_Is_Library_Level_Local_Name (Arg1); |
| 24929 |
|
| 24930 |
Type_Id := Get_Pragma_Arg (Arg1); |
| 24931 |
Find_Type (Type_Id); |
| 24932 |
Typ := Entity (Type_Id); |
| 24933 |
|
| 24934 |
if Typ = Any_Type then |
| 24935 |
return; |
| 24936 |
end if; |
| 24937 |
|
| 24938 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 24939 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 24940 |
|
| 24941 |
Mark_Ghost_Pragma (N, Typ); |
| 24942 |
|
| 24943 |
-- We require the pragma to apply to a type declared in a package |
| 24944 |
-- declaration, but not (immediately) within a package body. |
| 24945 |
|
| 24946 |
if Ekind (Current_Scope) /= E_Package |
| 24947 |
or else In_Package_Body (Current_Scope) |
| 24948 |
then |
| 24949 |
Error_Pragma |
| 24950 |
("pragma% can only apply to type declared immediately " |
| 24951 |
& "within a package declaration"); |
| 24952 |
end if; |
| 24953 |
|
| 24954 |
-- A simple storage pool type must be an immutably limited record |
| 24955 |
-- or private type. If the pragma is given for a private type, |
| 24956 |
-- the full type is similarly restricted (which is checked later |
| 24957 |
-- in Freeze_Entity). |
| 24958 |
|
| 24959 |
if Is_Record_Type (Typ) |
| 24960 |
and then not Is_Inherently_Limited_Type (Typ) |
| 24961 |
then |
| 24962 |
Error_Pragma |
| 24963 |
("pragma% can only apply to explicitly limited record type"); |
| 24964 |
|
| 24965 |
elsif Is_Private_Type (Typ) and then not Is_Limited_Type (Typ) then |
| 24966 |
Error_Pragma |
| 24967 |
("pragma% can only apply to a private type that is limited"); |
| 24968 |
|
| 24969 |
elsif not Is_Record_Type (Typ) |
| 24970 |
and then not Is_Private_Type (Typ) |
| 24971 |
then |
| 24972 |
Error_Pragma |
| 24973 |
("pragma% can only apply to limited record or private type"); |
| 24974 |
end if; |
| 24975 |
|
| 24976 |
Record_Rep_Item (Typ, N); |
| 24977 |
end Simple_Storage_Pool_Type; |
| 24978 |
|
| 24979 |
---------------------- |
| 24980 |
-- Source_File_Name -- |
| 24981 |
---------------------- |
| 24982 |
|
| 24983 |
-- There are five forms for this pragma: |
| 24984 |
|
| 24985 |
-- pragma Source_File_Name ( |
| 24986 |
-- [UNIT_NAME =>] unit_NAME, |
| 24987 |
-- BODY_FILE_NAME => STRING_LITERAL |
| 24988 |
-- [, [INDEX =>] INTEGER_LITERAL]); |
| 24989 |
|
| 24990 |
-- pragma Source_File_Name ( |
| 24991 |
-- [UNIT_NAME =>] unit_NAME, |
| 24992 |
-- SPEC_FILE_NAME => STRING_LITERAL |
| 24993 |
-- [, [INDEX =>] INTEGER_LITERAL]); |
| 24994 |
|
| 24995 |
-- pragma Source_File_Name ( |
| 24996 |
-- BODY_FILE_NAME => STRING_LITERAL |
| 24997 |
-- [, DOT_REPLACEMENT => STRING_LITERAL] |
| 24998 |
-- [, CASING => CASING_SPEC]); |
| 24999 |
|
| 25000 |
-- pragma Source_File_Name ( |
| 25001 |
-- SPEC_FILE_NAME => STRING_LITERAL |
| 25002 |
-- [, DOT_REPLACEMENT => STRING_LITERAL] |
| 25003 |
-- [, CASING => CASING_SPEC]); |
| 25004 |
|
| 25005 |
-- pragma Source_File_Name ( |
| 25006 |
-- SUBUNIT_FILE_NAME => STRING_LITERAL |
| 25007 |
-- [, DOT_REPLACEMENT => STRING_LITERAL] |
| 25008 |
-- [, CASING => CASING_SPEC]); |
| 25009 |
|
| 25010 |
-- CASING_SPEC ::= Uppercase | Lowercase | Mixedcase |
| 25011 |
|
| 25012 |
-- Pragma Source_File_Name_Project (SFNP) is equivalent to pragma |
| 25013 |
-- Source_File_Name (SFN), however their usage is exclusive: SFN can |
| 25014 |
-- only be used when no project file is used, while SFNP can only be |
| 25015 |
-- used when a project file is used. |
| 25016 |
|
| 25017 |
-- No processing here. Processing was completed during parsing, since |
| 25018 |
-- we need to have file names set as early as possible. Units are |
| 25019 |
-- loaded well before semantic processing starts. |
| 25020 |
|
| 25021 |
-- The only processing we defer to this point is the check for |
| 25022 |
-- correct placement. |
| 25023 |
|
| 25024 |
when Pragma_Source_File_Name => |
| 25025 |
GNAT_Pragma; |
| 25026 |
Check_Valid_Configuration_Pragma; |
| 25027 |
|
| 25028 |
------------------------------ |
| 25029 |
-- Source_File_Name_Project -- |
| 25030 |
------------------------------ |
| 25031 |
|
| 25032 |
-- See Source_File_Name for syntax |
| 25033 |
|
| 25034 |
-- No processing here. Processing was completed during parsing, since |
| 25035 |
-- we need to have file names set as early as possible. Units are |
| 25036 |
-- loaded well before semantic processing starts. |
| 25037 |
|
| 25038 |
-- The only processing we defer to this point is the check for |
| 25039 |
-- correct placement. |
| 25040 |
|
| 25041 |
when Pragma_Source_File_Name_Project => |
| 25042 |
GNAT_Pragma; |
| 25043 |
Check_Valid_Configuration_Pragma; |
| 25044 |
|
| 25045 |
-- Check that a pragma Source_File_Name_Project is used only in a |
| 25046 |
-- configuration pragmas file. |
| 25047 |
|
| 25048 |
-- Pragmas Source_File_Name_Project should only be generated by |
| 25049 |
-- the Project Manager in configuration pragmas files. |
| 25050 |
|
| 25051 |
-- This is really an ugly test. It seems to depend on some |
| 25052 |
-- accidental and undocumented property. At the very least it |
| 25053 |
-- needs to be documented, but it would be better to have a |
| 25054 |
-- clean way of testing if we are in a configuration file??? |
| 25055 |
|
| 25056 |
if Present (Parent (N)) then |
| 25057 |
Error_Pragma |
| 25058 |
("pragma% can only appear in a configuration pragmas file"); |
| 25059 |
end if; |
| 25060 |
|
| 25061 |
---------------------- |
| 25062 |
-- Source_Reference -- |
| 25063 |
---------------------- |
| 25064 |
|
| 25065 |
-- pragma Source_Reference (INTEGER_LITERAL [, STRING_LITERAL]); |
| 25066 |
|
| 25067 |
-- Nothing to do, all processing completed in Par.Prag, since we need |
| 25068 |
-- the information for possible parser messages that are output. |
| 25069 |
|
| 25070 |
when Pragma_Source_Reference => |
| 25071 |
GNAT_Pragma; |
| 25072 |
|
| 25073 |
---------------- |
| 25074 |
-- SPARK_Mode -- |
| 25075 |
---------------- |
| 25076 |
|
| 25077 |
-- pragma SPARK_Mode [(Auto | On | Off)]; |
| 25078 |
|
| 25079 |
when Pragma_SPARK_Mode => Do_SPARK_Mode : declare |
| 25080 |
Mode_Id : SPARK_Mode_Type; |
| 25081 |
|
| 25082 |
procedure Check_Pragma_Conformance |
| 25083 |
(Context_Pragma : Node_Id; |
| 25084 |
Entity : Entity_Id; |
| 25085 |
Entity_Pragma : Node_Id); |
| 25086 |
-- Subsidiary to routines Process_xxx. Verify the SPARK_Mode |
| 25087 |
-- conformance of pragma N depending the following scenarios: |
| 25088 |
-- |
| 25089 |
-- If pragma Context_Pragma is not Empty, verify that pragma N is |
| 25090 |
-- compatible with the pragma Context_Pragma that was inherited |
| 25091 |
-- from the context: |
| 25092 |
-- * If the mode of Context_Pragma is ON, then the new mode can |
| 25093 |
-- be anything. |
| 25094 |
-- * If the mode of Context_Pragma is OFF, then the only allowed |
| 25095 |
-- new mode is also OFF. Emit error if this is not the case. |
| 25096 |
-- |
| 25097 |
-- If Entity is not Empty, verify that pragma N is compatible with |
| 25098 |
-- pragma Entity_Pragma that belongs to Entity. |
| 25099 |
-- * If Entity_Pragma is Empty, always issue an error as this |
| 25100 |
-- corresponds to the case where a previous section of Entity |
| 25101 |
-- has no SPARK_Mode set. |
| 25102 |
-- * If the mode of Entity_Pragma is ON, then the new mode can |
| 25103 |
-- be anything. |
| 25104 |
-- * If the mode of Entity_Pragma is OFF, then the only allowed |
| 25105 |
-- new mode is also OFF. Emit error if this is not the case. |
| 25106 |
|
| 25107 |
procedure Check_Library_Level_Entity (E : Entity_Id); |
| 25108 |
-- Subsidiary to routines Process_xxx. Verify that the related |
| 25109 |
-- entity E subject to pragma SPARK_Mode is library-level. |
| 25110 |
|
| 25111 |
procedure Process_Body (Decl : Node_Id); |
| 25112 |
-- Verify the legality of pragma SPARK_Mode when it appears as the |
| 25113 |
-- top of the body declarations of entry, package, protected unit, |
| 25114 |
-- subprogram or task unit body denoted by Decl. |
| 25115 |
|
| 25116 |
procedure Process_Overloadable (Decl : Node_Id); |
| 25117 |
-- Verify the legality of pragma SPARK_Mode when it applies to an |
| 25118 |
-- entry or [generic] subprogram declaration denoted by Decl. |
| 25119 |
|
| 25120 |
procedure Process_Private_Part (Decl : Node_Id); |
| 25121 |
-- Verify the legality of pragma SPARK_Mode when it appears at the |
| 25122 |
-- top of the private declarations of a package spec, protected or |
| 25123 |
-- task unit declaration denoted by Decl. |
| 25124 |
|
| 25125 |
procedure Process_Statement_Part (Decl : Node_Id); |
| 25126 |
-- Verify the legality of pragma SPARK_Mode when it appears at the |
| 25127 |
-- top of the statement sequence of a package body denoted by node |
| 25128 |
-- Decl. |
| 25129 |
|
| 25130 |
procedure Process_Visible_Part (Decl : Node_Id); |
| 25131 |
-- Verify the legality of pragma SPARK_Mode when it appears at the |
| 25132 |
-- top of the visible declarations of a package spec, protected or |
| 25133 |
-- task unit declaration denoted by Decl. The routine is also used |
| 25134 |
-- on protected or task units declared without a definition. |
| 25135 |
|
| 25136 |
procedure Set_SPARK_Context; |
| 25137 |
-- Subsidiary to routines Process_xxx. Set the global variables |
| 25138 |
-- which represent the mode of the context from pragma N. Ensure |
| 25139 |
-- that Dynamic_Elaboration_Checks are off if the new mode is On. |
| 25140 |
|
| 25141 |
------------------------------ |
| 25142 |
-- Check_Pragma_Conformance -- |
| 25143 |
------------------------------ |
| 25144 |
|
| 25145 |
procedure Check_Pragma_Conformance |
| 25146 |
(Context_Pragma : Node_Id; |
| 25147 |
Entity : Entity_Id; |
| 25148 |
Entity_Pragma : Node_Id) |
| 25149 |
is |
| 25150 |
Err_Id : Entity_Id; |
| 25151 |
Err_N : Node_Id; |
| 25152 |
|
| 25153 |
begin |
| 25154 |
-- The current pragma may appear without an argument. If this |
| 25155 |
-- is the case, associate all error messages with the pragma |
| 25156 |
-- itself. |
| 25157 |
|
| 25158 |
if Present (Arg1) then |
| 25159 |
Err_N := Arg1; |
| 25160 |
else |
| 25161 |
Err_N := N; |
| 25162 |
end if; |
| 25163 |
|
| 25164 |
-- The mode of the current pragma is compared against that of |
| 25165 |
-- an enclosing context. |
| 25166 |
|
| 25167 |
if Present (Context_Pragma) then |
| 25168 |
pragma Assert (Nkind (Context_Pragma) = N_Pragma); |
| 25169 |
|
| 25170 |
-- Issue an error if the new mode is less restrictive than |
| 25171 |
-- that of the context. |
| 25172 |
|
| 25173 |
if Get_SPARK_Mode_From_Annotation (Context_Pragma) = Off |
| 25174 |
and then Get_SPARK_Mode_From_Annotation (N) = On |
| 25175 |
then |
| 25176 |
Error_Msg_N |
| 25177 |
("cannot change SPARK_Mode from Off to On", Err_N); |
| 25178 |
Error_Msg_Sloc := Sloc (SPARK_Mode_Pragma); |
| 25179 |
Error_Msg_N ("\SPARK_Mode was set to Off#", Err_N); |
| 25180 |
raise Pragma_Exit; |
| 25181 |
end if; |
| 25182 |
end if; |
| 25183 |
|
| 25184 |
-- The mode of the current pragma is compared against that of |
| 25185 |
-- an initial package, protected type, subprogram or task type |
| 25186 |
-- declaration. |
| 25187 |
|
| 25188 |
if Present (Entity) then |
| 25189 |
|
| 25190 |
-- A simple protected or task type is transformed into an |
| 25191 |
-- anonymous type whose name cannot be used to issue error |
| 25192 |
-- messages. Recover the original entity of the type. |
| 25193 |
|
| 25194 |
if Ekind (Entity) in E_Protected_Type | E_Task_Type then |
| 25195 |
Err_Id := |
| 25196 |
Defining_Entity |
| 25197 |
(Original_Node (Unit_Declaration_Node (Entity))); |
| 25198 |
else |
| 25199 |
Err_Id := Entity; |
| 25200 |
end if; |
| 25201 |
|
| 25202 |
-- Both the initial declaration and the completion carry |
| 25203 |
-- SPARK_Mode pragmas. |
| 25204 |
|
| 25205 |
if Present (Entity_Pragma) then |
| 25206 |
pragma Assert (Nkind (Entity_Pragma) = N_Pragma); |
| 25207 |
|
| 25208 |
-- Issue an error if the new mode is less restrictive |
| 25209 |
-- than that of the initial declaration. |
| 25210 |
|
| 25211 |
if Get_SPARK_Mode_From_Annotation (Entity_Pragma) = Off |
| 25212 |
and then Get_SPARK_Mode_From_Annotation (N) = On |
| 25213 |
then |
| 25214 |
Error_Msg_N ("incorrect use of SPARK_Mode", Err_N); |
| 25215 |
Error_Msg_Sloc := Sloc (Entity_Pragma); |
| 25216 |
Error_Msg_NE |
| 25217 |
("\value Off was set for SPARK_Mode on&#", |
| 25218 |
Err_N, Err_Id); |
| 25219 |
raise Pragma_Exit; |
| 25220 |
end if; |
| 25221 |
|
| 25222 |
-- Otherwise the initial declaration lacks a SPARK_Mode |
| 25223 |
-- pragma in which case the current pragma is illegal as |
| 25224 |
-- it cannot "complete". |
| 25225 |
|
| 25226 |
elsif Get_SPARK_Mode_From_Annotation (N) = Off |
| 25227 |
and then (Is_Generic_Unit (Entity) or else In_Instance) |
| 25228 |
then |
| 25229 |
null; |
| 25230 |
|
| 25231 |
else |
| 25232 |
Error_Msg_N ("incorrect use of SPARK_Mode", Err_N); |
| 25233 |
Error_Msg_Sloc := Sloc (Err_Id); |
| 25234 |
Error_Msg_NE |
| 25235 |
("\no value was set for SPARK_Mode on&#", |
| 25236 |
Err_N, Err_Id); |
| 25237 |
raise Pragma_Exit; |
| 25238 |
end if; |
| 25239 |
end if; |
| 25240 |
end Check_Pragma_Conformance; |
| 25241 |
|
| 25242 |
-------------------------------- |
| 25243 |
-- Check_Library_Level_Entity -- |
| 25244 |
-------------------------------- |
| 25245 |
|
| 25246 |
procedure Check_Library_Level_Entity (E : Entity_Id) is |
| 25247 |
procedure Add_Entity_To_Name_Buffer; |
| 25248 |
-- Add the E_Kind of entity E to the name buffer |
| 25249 |
|
| 25250 |
------------------------------- |
| 25251 |
-- Add_Entity_To_Name_Buffer -- |
| 25252 |
------------------------------- |
| 25253 |
|
| 25254 |
procedure Add_Entity_To_Name_Buffer is |
| 25255 |
begin |
| 25256 |
if Ekind (E) in E_Entry | E_Entry_Family then |
| 25257 |
Add_Str_To_Name_Buffer ("entry"); |
| 25258 |
|
| 25259 |
elsif Ekind (E) in E_Generic_Package |
| 25260 |
| E_Package |
| 25261 |
| E_Package_Body |
| 25262 |
then |
| 25263 |
Add_Str_To_Name_Buffer ("package"); |
| 25264 |
|
| 25265 |
elsif Ekind (E) in E_Protected_Body | E_Protected_Type then |
| 25266 |
Add_Str_To_Name_Buffer ("protected type"); |
| 25267 |
|
| 25268 |
elsif Ekind (E) in E_Function |
| 25269 |
| E_Generic_Function |
| 25270 |
| E_Generic_Procedure |
| 25271 |
| E_Procedure |
| 25272 |
| E_Subprogram_Body |
| 25273 |
then |
| 25274 |
Add_Str_To_Name_Buffer ("subprogram"); |
| 25275 |
|
| 25276 |
else |
| 25277 |
pragma Assert (Ekind (E) in E_Task_Body | E_Task_Type); |
| 25278 |
Add_Str_To_Name_Buffer ("task type"); |
| 25279 |
end if; |
| 25280 |
end Add_Entity_To_Name_Buffer; |
| 25281 |
|
| 25282 |
-- Local variables |
| 25283 |
|
| 25284 |
Msg_1 : constant String := |
| 25285 |
"incorrect placement of pragma% with value ""On"" '[[]']"; |
| 25286 |
Msg_2 : Name_Id; |
| 25287 |
|
| 25288 |
-- Start of processing for Check_Library_Level_Entity |
| 25289 |
|
| 25290 |
begin |
| 25291 |
-- A SPARK_Mode of On shall only apply to library-level |
| 25292 |
-- entities, except for those in generic instances, which are |
| 25293 |
-- ignored (even if the entity gets SPARK_Mode pragma attached |
| 25294 |
-- in the AST, its effect is not taken into account unless the |
| 25295 |
-- context already provides SPARK_Mode of On in GNATprove). |
| 25296 |
|
| 25297 |
if Get_SPARK_Mode_From_Annotation (N) = On |
| 25298 |
and then not Is_Library_Level_Entity (E) |
| 25299 |
and then Instantiation_Location (Sloc (N)) = No_Location |
| 25300 |
then |
| 25301 |
Error_Msg_Name_1 := Pname; |
| 25302 |
Error_Msg_Code := GEC_SPARK_Mode_On_Not_Library_Level; |
| 25303 |
Error_Msg_N (Fix_Error (Msg_1), N); |
| 25304 |
|
| 25305 |
Name_Len := 0; |
| 25306 |
Add_Str_To_Name_Buffer ("\& is not a library-level "); |
| 25307 |
Add_Entity_To_Name_Buffer; |
| 25308 |
|
| 25309 |
Msg_2 := Name_Find; |
| 25310 |
Error_Msg_NE (Get_Name_String (Msg_2), N, E); |
| 25311 |
|
| 25312 |
raise Pragma_Exit; |
| 25313 |
end if; |
| 25314 |
end Check_Library_Level_Entity; |
| 25315 |
|
| 25316 |
------------------ |
| 25317 |
-- Process_Body -- |
| 25318 |
------------------ |
| 25319 |
|
| 25320 |
procedure Process_Body (Decl : Node_Id) is |
| 25321 |
Body_Id : constant Entity_Id := Defining_Entity (Decl); |
| 25322 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Decl); |
| 25323 |
|
| 25324 |
begin |
| 25325 |
-- Ignore pragma when applied to the special body created |
| 25326 |
-- for inlining, recognized by its internal name _Parent; or |
| 25327 |
-- when applied to the special body created for contracts, |
| 25328 |
-- recognized by its internal name _Wrapped_Statements. |
| 25329 |
|
| 25330 |
if Chars (Body_Id) in Name_uParent |
| 25331 |
| Name_uWrapped_Statements |
| 25332 |
then |
| 25333 |
return; |
| 25334 |
end if; |
| 25335 |
|
| 25336 |
Check_Library_Level_Entity (Body_Id); |
| 25337 |
|
| 25338 |
-- For entry bodies, verify the legality against: |
| 25339 |
-- * The mode of the context |
| 25340 |
-- * The mode of the spec (if any) |
| 25341 |
|
| 25342 |
if Nkind (Decl) in N_Entry_Body | N_Subprogram_Body then |
| 25343 |
|
| 25344 |
-- A stand-alone subprogram body |
| 25345 |
|
| 25346 |
if Body_Id = Spec_Id then |
| 25347 |
Check_Pragma_Conformance |
| 25348 |
(Context_Pragma => SPARK_Pragma (Body_Id), |
| 25349 |
Entity => Empty, |
| 25350 |
Entity_Pragma => Empty); |
| 25351 |
|
| 25352 |
-- An entry or subprogram body that completes a previous |
| 25353 |
-- declaration. |
| 25354 |
|
| 25355 |
else |
| 25356 |
Check_Pragma_Conformance |
| 25357 |
(Context_Pragma => SPARK_Pragma (Body_Id), |
| 25358 |
Entity => Spec_Id, |
| 25359 |
Entity_Pragma => SPARK_Pragma (Spec_Id)); |
| 25360 |
end if; |
| 25361 |
|
| 25362 |
Set_SPARK_Context; |
| 25363 |
Set_SPARK_Pragma (Body_Id, N); |
| 25364 |
Set_SPARK_Pragma_Inherited (Body_Id, False); |
| 25365 |
|
| 25366 |
-- For package bodies, verify the legality against: |
| 25367 |
-- * The mode of the context |
| 25368 |
-- * The mode of the private part |
| 25369 |
|
| 25370 |
-- This case is separated from protected and task bodies |
| 25371 |
-- because the statement part of the package body inherits |
| 25372 |
-- the mode of the body declarations. |
| 25373 |
|
| 25374 |
elsif Nkind (Decl) = N_Package_Body then |
| 25375 |
Check_Pragma_Conformance |
| 25376 |
(Context_Pragma => SPARK_Pragma (Body_Id), |
| 25377 |
Entity => Spec_Id, |
| 25378 |
Entity_Pragma => SPARK_Aux_Pragma (Spec_Id)); |
| 25379 |
|
| 25380 |
Set_SPARK_Context; |
| 25381 |
Set_SPARK_Pragma (Body_Id, N); |
| 25382 |
Set_SPARK_Pragma_Inherited (Body_Id, False); |
| 25383 |
Set_SPARK_Aux_Pragma (Body_Id, N); |
| 25384 |
Set_SPARK_Aux_Pragma_Inherited (Body_Id, True); |
| 25385 |
|
| 25386 |
-- For protected and task bodies, verify the legality against: |
| 25387 |
-- * The mode of the context |
| 25388 |
-- * The mode of the private part |
| 25389 |
|
| 25390 |
else |
| 25391 |
pragma Assert |
| 25392 |
(Nkind (Decl) in N_Protected_Body | N_Task_Body); |
| 25393 |
|
| 25394 |
Check_Pragma_Conformance |
| 25395 |
(Context_Pragma => SPARK_Pragma (Body_Id), |
| 25396 |
Entity => Spec_Id, |
| 25397 |
Entity_Pragma => SPARK_Aux_Pragma (Spec_Id)); |
| 25398 |
|
| 25399 |
Set_SPARK_Context; |
| 25400 |
Set_SPARK_Pragma (Body_Id, N); |
| 25401 |
Set_SPARK_Pragma_Inherited (Body_Id, False); |
| 25402 |
end if; |
| 25403 |
end Process_Body; |
| 25404 |
|
| 25405 |
-------------------------- |
| 25406 |
-- Process_Overloadable -- |
| 25407 |
-------------------------- |
| 25408 |
|
| 25409 |
procedure Process_Overloadable (Decl : Node_Id) is |
| 25410 |
Spec_Id : constant Entity_Id := Defining_Entity (Decl); |
| 25411 |
Spec_Typ : constant Entity_Id := Etype (Spec_Id); |
| 25412 |
|
| 25413 |
begin |
| 25414 |
Check_Library_Level_Entity (Spec_Id); |
| 25415 |
|
| 25416 |
-- Verify the legality against: |
| 25417 |
-- * The mode of the context |
| 25418 |
|
| 25419 |
Check_Pragma_Conformance |
| 25420 |
(Context_Pragma => SPARK_Pragma (Spec_Id), |
| 25421 |
Entity => Empty, |
| 25422 |
Entity_Pragma => Empty); |
| 25423 |
|
| 25424 |
Set_SPARK_Pragma (Spec_Id, N); |
| 25425 |
Set_SPARK_Pragma_Inherited (Spec_Id, False); |
| 25426 |
|
| 25427 |
-- When the pragma applies to the anonymous object created for |
| 25428 |
-- a single task type, decorate the type as well. This scenario |
| 25429 |
-- arises when the single task type lacks a task definition, |
| 25430 |
-- therefore there is no issue with respect to a potential |
| 25431 |
-- pragma SPARK_Mode in the private part. |
| 25432 |
|
| 25433 |
-- task type Anon_Task_Typ; |
| 25434 |
-- Obj : Anon_Task_Typ; |
| 25435 |
-- pragma SPARK_Mode ...; |
| 25436 |
|
| 25437 |
if Is_Single_Task_Object (Spec_Id) then |
| 25438 |
Set_SPARK_Pragma (Spec_Typ, N); |
| 25439 |
Set_SPARK_Pragma_Inherited (Spec_Typ, False); |
| 25440 |
Set_SPARK_Aux_Pragma (Spec_Typ, N); |
| 25441 |
Set_SPARK_Aux_Pragma_Inherited (Spec_Typ, True); |
| 25442 |
end if; |
| 25443 |
end Process_Overloadable; |
| 25444 |
|
| 25445 |
-------------------------- |
| 25446 |
-- Process_Private_Part -- |
| 25447 |
-------------------------- |
| 25448 |
|
| 25449 |
procedure Process_Private_Part (Decl : Node_Id) is |
| 25450 |
Spec_Id : constant Entity_Id := Defining_Entity (Decl); |
| 25451 |
|
| 25452 |
begin |
| 25453 |
Check_Library_Level_Entity (Spec_Id); |
| 25454 |
|
| 25455 |
-- Verify the legality against: |
| 25456 |
-- * The mode of the visible declarations |
| 25457 |
|
| 25458 |
Check_Pragma_Conformance |
| 25459 |
(Context_Pragma => Empty, |
| 25460 |
Entity => Spec_Id, |
| 25461 |
Entity_Pragma => SPARK_Pragma (Spec_Id)); |
| 25462 |
|
| 25463 |
Set_SPARK_Context; |
| 25464 |
Set_SPARK_Aux_Pragma (Spec_Id, N); |
| 25465 |
Set_SPARK_Aux_Pragma_Inherited (Spec_Id, False); |
| 25466 |
end Process_Private_Part; |
| 25467 |
|
| 25468 |
---------------------------- |
| 25469 |
-- Process_Statement_Part -- |
| 25470 |
---------------------------- |
| 25471 |
|
| 25472 |
procedure Process_Statement_Part (Decl : Node_Id) is |
| 25473 |
Body_Id : constant Entity_Id := Defining_Entity (Decl); |
| 25474 |
|
| 25475 |
begin |
| 25476 |
Check_Library_Level_Entity (Body_Id); |
| 25477 |
|
| 25478 |
-- Verify the legality against: |
| 25479 |
-- * The mode of the body declarations |
| 25480 |
|
| 25481 |
Check_Pragma_Conformance |
| 25482 |
(Context_Pragma => Empty, |
| 25483 |
Entity => Body_Id, |
| 25484 |
Entity_Pragma => SPARK_Pragma (Body_Id)); |
| 25485 |
|
| 25486 |
Set_SPARK_Context; |
| 25487 |
Set_SPARK_Aux_Pragma (Body_Id, N); |
| 25488 |
Set_SPARK_Aux_Pragma_Inherited (Body_Id, False); |
| 25489 |
end Process_Statement_Part; |
| 25490 |
|
| 25491 |
-------------------------- |
| 25492 |
-- Process_Visible_Part -- |
| 25493 |
-------------------------- |
| 25494 |
|
| 25495 |
procedure Process_Visible_Part (Decl : Node_Id) is |
| 25496 |
Spec_Id : constant Entity_Id := Defining_Entity (Decl); |
| 25497 |
Obj_Id : Entity_Id; |
| 25498 |
|
| 25499 |
begin |
| 25500 |
Check_Library_Level_Entity (Spec_Id); |
| 25501 |
|
| 25502 |
-- Verify the legality against: |
| 25503 |
-- * The mode of the context |
| 25504 |
|
| 25505 |
Check_Pragma_Conformance |
| 25506 |
(Context_Pragma => SPARK_Pragma (Spec_Id), |
| 25507 |
Entity => Empty, |
| 25508 |
Entity_Pragma => Empty); |
| 25509 |
|
| 25510 |
-- A task unit declared without a definition does not set the |
| 25511 |
-- SPARK_Mode of the context because the task does not have any |
| 25512 |
-- entries that could inherit the mode. |
| 25513 |
|
| 25514 |
if Nkind (Decl) not in |
| 25515 |
N_Single_Task_Declaration | N_Task_Type_Declaration |
| 25516 |
then |
| 25517 |
Set_SPARK_Context; |
| 25518 |
end if; |
| 25519 |
|
| 25520 |
Set_SPARK_Pragma (Spec_Id, N); |
| 25521 |
Set_SPARK_Pragma_Inherited (Spec_Id, False); |
| 25522 |
Set_SPARK_Aux_Pragma (Spec_Id, N); |
| 25523 |
Set_SPARK_Aux_Pragma_Inherited (Spec_Id, True); |
| 25524 |
|
| 25525 |
-- When the pragma applies to a single protected or task type, |
| 25526 |
-- decorate the corresponding anonymous object as well. |
| 25527 |
|
| 25528 |
-- protected Anon_Prot_Typ is |
| 25529 |
-- pragma SPARK_Mode ...; |
| 25530 |
-- ... |
| 25531 |
-- end Anon_Prot_Typ; |
| 25532 |
|
| 25533 |
-- Obj : Anon_Prot_Typ; |
| 25534 |
|
| 25535 |
if Is_Single_Concurrent_Type (Spec_Id) then |
| 25536 |
Obj_Id := Anonymous_Object (Spec_Id); |
| 25537 |
|
| 25538 |
Set_SPARK_Pragma (Obj_Id, N); |
| 25539 |
Set_SPARK_Pragma_Inherited (Obj_Id, False); |
| 25540 |
end if; |
| 25541 |
end Process_Visible_Part; |
| 25542 |
|
| 25543 |
----------------------- |
| 25544 |
-- Set_SPARK_Context -- |
| 25545 |
----------------------- |
| 25546 |
|
| 25547 |
procedure Set_SPARK_Context is |
| 25548 |
begin |
| 25549 |
SPARK_Mode := Mode_Id; |
| 25550 |
SPARK_Mode_Pragma := N; |
| 25551 |
end Set_SPARK_Context; |
| 25552 |
|
| 25553 |
-- Local variables |
| 25554 |
|
| 25555 |
Context : Node_Id; |
| 25556 |
Mode : Name_Id; |
| 25557 |
Stmt : Node_Id; |
| 25558 |
|
| 25559 |
-- Start of processing for Do_SPARK_Mode |
| 25560 |
|
| 25561 |
begin |
| 25562 |
GNAT_Pragma; |
| 25563 |
Check_No_Identifiers; |
| 25564 |
Check_At_Most_N_Arguments (1); |
| 25565 |
|
| 25566 |
-- Check the legality of the mode (no argument = ON) |
| 25567 |
|
| 25568 |
if Arg_Count = 1 then |
| 25569 |
Check_Arg_Is_One_Of (Arg1, Name_Auto, Name_On, Name_Off); |
| 25570 |
Mode := Chars (Get_Pragma_Arg (Arg1)); |
| 25571 |
else |
| 25572 |
Mode := Name_On; |
| 25573 |
end if; |
| 25574 |
|
| 25575 |
Mode_Id := Get_SPARK_Mode_Type (Mode); |
| 25576 |
Context := Parent (N); |
| 25577 |
|
| 25578 |
-- When a SPARK_Mode pragma appears inside an instantiation whose |
| 25579 |
-- enclosing context has SPARK_Mode set to "off", the pragma has |
| 25580 |
-- no semantic effect. |
| 25581 |
|
| 25582 |
if Ignore_SPARK_Mode_Pragmas_In_Instance |
| 25583 |
and then Mode_Id /= Off |
| 25584 |
then |
| 25585 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 25586 |
Analyze (N); |
| 25587 |
return; |
| 25588 |
end if; |
| 25589 |
|
| 25590 |
-- The pragma appears in a configuration file |
| 25591 |
|
| 25592 |
if No (Context) then |
| 25593 |
Check_Valid_Configuration_Pragma; |
| 25594 |
Set_SPARK_Context; |
| 25595 |
|
| 25596 |
-- The pragma acts as a configuration pragma in a compilation unit |
| 25597 |
|
| 25598 |
-- pragma SPARK_Mode ...; |
| 25599 |
-- package Pack is ...; |
| 25600 |
|
| 25601 |
elsif Nkind (Context) = N_Compilation_Unit |
| 25602 |
and then List_Containing (N) = Context_Items (Context) |
| 25603 |
then |
| 25604 |
Check_Valid_Configuration_Pragma; |
| 25605 |
Set_SPARK_Context; |
| 25606 |
|
| 25607 |
-- Otherwise the placement of the pragma within the tree dictates |
| 25608 |
-- its associated construct. Inspect the declarative list where |
| 25609 |
-- the pragma resides to find a potential construct. |
| 25610 |
|
| 25611 |
else |
| 25612 |
-- An explicit mode of Auto is only allowed as a configuration |
| 25613 |
-- pragma. Escape "pragma" to avoid replacement with "aspect". |
| 25614 |
|
| 25615 |
if Mode_Id = None then |
| 25616 |
Error_Pragma_Arg |
| 25617 |
("only configuration 'p'r'a'g'm'a% can have value &", |
| 25618 |
Arg1); |
| 25619 |
end if; |
| 25620 |
|
| 25621 |
Stmt := Prev (N); |
| 25622 |
while Present (Stmt) loop |
| 25623 |
|
| 25624 |
-- Skip prior pragmas, but check for duplicates. Note that |
| 25625 |
-- this also takes care of pragmas generated for aspects. |
| 25626 |
|
| 25627 |
if Nkind (Stmt) = N_Pragma then |
| 25628 |
if Pragma_Name (Stmt) = Pname then |
| 25629 |
Duplication_Error |
| 25630 |
(Prag => N, |
| 25631 |
Prev => Stmt); |
| 25632 |
raise Pragma_Exit; |
| 25633 |
end if; |
| 25634 |
|
| 25635 |
-- The pragma applies to an expression function that has |
| 25636 |
-- already been rewritten into a subprogram declaration. |
| 25637 |
|
| 25638 |
-- function Expr_Func return ... is (...); |
| 25639 |
-- pragma SPARK_Mode ...; |
| 25640 |
|
| 25641 |
elsif Nkind (Stmt) = N_Subprogram_Declaration |
| 25642 |
and then Nkind (Original_Node (Stmt)) = |
| 25643 |
N_Expression_Function |
| 25644 |
then |
| 25645 |
Process_Overloadable (Stmt); |
| 25646 |
return; |
| 25647 |
|
| 25648 |
-- The pragma applies to the anonymous object created for a |
| 25649 |
-- single concurrent type. |
| 25650 |
|
| 25651 |
-- protected type Anon_Prot_Typ ...; |
| 25652 |
-- Obj : Anon_Prot_Typ; |
| 25653 |
-- pragma SPARK_Mode ...; |
| 25654 |
|
| 25655 |
elsif Nkind (Stmt) = N_Object_Declaration |
| 25656 |
and then Is_Single_Concurrent_Object |
| 25657 |
(Defining_Entity (Stmt)) |
| 25658 |
then |
| 25659 |
Process_Overloadable (Stmt); |
| 25660 |
return; |
| 25661 |
|
| 25662 |
-- Skip internally generated code |
| 25663 |
|
| 25664 |
elsif not Comes_From_Source (Stmt) then |
| 25665 |
null; |
| 25666 |
|
| 25667 |
-- The pragma applies to an entry or [generic] subprogram |
| 25668 |
-- declaration. |
| 25669 |
|
| 25670 |
-- entry Ent ...; |
| 25671 |
-- pragma SPARK_Mode ...; |
| 25672 |
|
| 25673 |
-- [generic] |
| 25674 |
-- procedure Proc ...; |
| 25675 |
-- pragma SPARK_Mode ...; |
| 25676 |
|
| 25677 |
elsif Nkind (Stmt) in N_Generic_Subprogram_Declaration |
| 25678 |
| N_Subprogram_Declaration |
| 25679 |
or else (Nkind (Stmt) = N_Entry_Declaration |
| 25680 |
and then Is_Protected_Type |
| 25681 |
(Scope (Defining_Entity (Stmt)))) |
| 25682 |
then |
| 25683 |
Process_Overloadable (Stmt); |
| 25684 |
return; |
| 25685 |
|
| 25686 |
-- Otherwise the pragma does not apply to a legal construct |
| 25687 |
-- or it does not appear at the top of a declarative or a |
| 25688 |
-- statement list. Issue an error and stop the analysis. |
| 25689 |
|
| 25690 |
else |
| 25691 |
Pragma_Misplaced; |
| 25692 |
end if; |
| 25693 |
|
| 25694 |
Prev (Stmt); |
| 25695 |
end loop; |
| 25696 |
|
| 25697 |
-- The pragma applies to a package or a subprogram that acts as |
| 25698 |
-- a compilation unit. |
| 25699 |
|
| 25700 |
-- procedure Proc ...; |
| 25701 |
-- pragma SPARK_Mode ...; |
| 25702 |
|
| 25703 |
if Nkind (Context) = N_Compilation_Unit_Aux then |
| 25704 |
Context := Unit (Parent (Context)); |
| 25705 |
end if; |
| 25706 |
|
| 25707 |
-- The pragma appears at the top of entry, package, protected |
| 25708 |
-- unit, subprogram or task unit body declarations. |
| 25709 |
|
| 25710 |
-- entry Ent when ... is |
| 25711 |
-- pragma SPARK_Mode ...; |
| 25712 |
|
| 25713 |
-- package body Pack is |
| 25714 |
-- pragma SPARK_Mode ...; |
| 25715 |
|
| 25716 |
-- procedure Proc ... is |
| 25717 |
-- pragma SPARK_Mode; |
| 25718 |
|
| 25719 |
-- protected body Prot is |
| 25720 |
-- pragma SPARK_Mode ...; |
| 25721 |
|
| 25722 |
if Nkind (Context) in N_Entry_Body |
| 25723 |
| N_Package_Body |
| 25724 |
| N_Protected_Body |
| 25725 |
| N_Subprogram_Body |
| 25726 |
| N_Task_Body |
| 25727 |
then |
| 25728 |
Process_Body (Context); |
| 25729 |
|
| 25730 |
-- The pragma appears at the top of the visible or private |
| 25731 |
-- declaration of a package spec, protected or task unit. |
| 25732 |
|
| 25733 |
-- package Pack is |
| 25734 |
-- pragma SPARK_Mode ...; |
| 25735 |
-- private |
| 25736 |
-- pragma SPARK_Mode ...; |
| 25737 |
|
| 25738 |
-- protected [type] Prot is |
| 25739 |
-- pragma SPARK_Mode ...; |
| 25740 |
-- private |
| 25741 |
-- pragma SPARK_Mode ...; |
| 25742 |
|
| 25743 |
elsif Nkind (Context) in N_Package_Specification |
| 25744 |
| N_Protected_Definition |
| 25745 |
| N_Task_Definition |
| 25746 |
then |
| 25747 |
if List_Containing (N) = Visible_Declarations (Context) then |
| 25748 |
Process_Visible_Part (Parent (Context)); |
| 25749 |
else |
| 25750 |
Process_Private_Part (Parent (Context)); |
| 25751 |
end if; |
| 25752 |
|
| 25753 |
-- The pragma appears at the top of package body statements |
| 25754 |
|
| 25755 |
-- package body Pack is |
| 25756 |
-- begin |
| 25757 |
-- pragma SPARK_Mode; |
| 25758 |
|
| 25759 |
elsif Nkind (Context) = N_Handled_Sequence_Of_Statements |
| 25760 |
and then Nkind (Parent (Context)) = N_Package_Body |
| 25761 |
then |
| 25762 |
Process_Statement_Part (Parent (Context)); |
| 25763 |
|
| 25764 |
-- The pragma appeared as an aspect of a [generic] subprogram |
| 25765 |
-- declaration that acts as a compilation unit. |
| 25766 |
|
| 25767 |
-- [generic] |
| 25768 |
-- procedure Proc ...; |
| 25769 |
-- pragma SPARK_Mode ...; |
| 25770 |
|
| 25771 |
elsif Nkind (Context) in N_Generic_Subprogram_Declaration |
| 25772 |
| N_Subprogram_Declaration |
| 25773 |
then |
| 25774 |
Process_Overloadable (Context); |
| 25775 |
|
| 25776 |
-- The pragma does not apply to a legal construct, issue error |
| 25777 |
|
| 25778 |
else |
| 25779 |
Pragma_Misplaced; |
| 25780 |
end if; |
| 25781 |
end if; |
| 25782 |
end Do_SPARK_Mode; |
| 25783 |
|
| 25784 |
-------------------------------- |
| 25785 |
-- Static_Elaboration_Desired -- |
| 25786 |
-------------------------------- |
| 25787 |
|
| 25788 |
-- pragma Static_Elaboration_Desired (DIRECT_NAME); |
| 25789 |
|
| 25790 |
when Pragma_Static_Elaboration_Desired => |
| 25791 |
GNAT_Pragma; |
| 25792 |
Check_At_Most_N_Arguments (1); |
| 25793 |
|
| 25794 |
if Is_Compilation_Unit (Current_Scope) |
| 25795 |
and then Ekind (Current_Scope) = E_Package |
| 25796 |
then |
| 25797 |
Set_Static_Elaboration_Desired (Current_Scope, True); |
| 25798 |
else |
| 25799 |
Error_Pragma ("pragma% must apply to a library-level package"); |
| 25800 |
end if; |
| 25801 |
|
| 25802 |
------------------ |
| 25803 |
-- Storage_Size -- |
| 25804 |
------------------ |
| 25805 |
|
| 25806 |
-- pragma Storage_Size (EXPRESSION); |
| 25807 |
|
| 25808 |
when Pragma_Storage_Size => Storage_Size : declare |
| 25809 |
P : constant Node_Id := Parent (N); |
| 25810 |
Arg : Node_Id; |
| 25811 |
|
| 25812 |
begin |
| 25813 |
Check_No_Identifiers; |
| 25814 |
Check_Arg_Count (1); |
| 25815 |
|
| 25816 |
-- The expression must be analyzed in the special manner described |
| 25817 |
-- in "Handling of Default Expressions" in sem.ads. |
| 25818 |
|
| 25819 |
Arg := Get_Pragma_Arg (Arg1); |
| 25820 |
Preanalyze_Spec_Expression (Arg, Any_Integer); |
| 25821 |
|
| 25822 |
if not Is_OK_Static_Expression (Arg) then |
| 25823 |
Check_Restriction (Static_Storage_Size, Arg); |
| 25824 |
end if; |
| 25825 |
|
| 25826 |
if Nkind (P) /= N_Task_Definition then |
| 25827 |
Pragma_Misplaced; |
| 25828 |
|
| 25829 |
else |
| 25830 |
if Has_Storage_Size_Pragma (P) then |
| 25831 |
Error_Pragma ("duplicate pragma% not allowed"); |
| 25832 |
else |
| 25833 |
Set_Has_Storage_Size_Pragma (P, True); |
| 25834 |
end if; |
| 25835 |
|
| 25836 |
Record_Rep_Item (Defining_Identifier (Parent (P)), N); |
| 25837 |
end if; |
| 25838 |
end Storage_Size; |
| 25839 |
|
| 25840 |
------------------ |
| 25841 |
-- Storage_Unit -- |
| 25842 |
------------------ |
| 25843 |
|
| 25844 |
-- pragma Storage_Unit (NUMERIC_LITERAL); |
| 25845 |
|
| 25846 |
-- Only permitted argument is System'Storage_Unit value |
| 25847 |
|
| 25848 |
when Pragma_Storage_Unit => |
| 25849 |
Check_No_Identifiers; |
| 25850 |
Check_Arg_Count (1); |
| 25851 |
Check_Arg_Is_Integer_Literal (Arg1); |
| 25852 |
|
| 25853 |
if Intval (Get_Pragma_Arg (Arg1)) /= |
| 25854 |
UI_From_Int (Ttypes.System_Storage_Unit) |
| 25855 |
then |
| 25856 |
Error_Msg_Uint_1 := UI_From_Int (Ttypes.System_Storage_Unit); |
| 25857 |
Error_Pragma_Arg |
| 25858 |
("the only allowed argument for pragma% is ^", Arg1); |
| 25859 |
end if; |
| 25860 |
|
| 25861 |
-------------------- |
| 25862 |
-- Stream_Convert -- |
| 25863 |
-------------------- |
| 25864 |
|
| 25865 |
-- pragma Stream_Convert ( |
| 25866 |
-- [Entity =>] type_LOCAL_NAME, |
| 25867 |
-- [Read =>] function_NAME, |
| 25868 |
-- [Write =>] function NAME); |
| 25869 |
|
| 25870 |
when Pragma_Stream_Convert => Stream_Convert : declare |
| 25871 |
procedure Check_OK_Stream_Convert_Function (Arg : Node_Id); |
| 25872 |
-- Check that the given argument is the name of a local function |
| 25873 |
-- of one argument that is not overloaded earlier in the current |
| 25874 |
-- local scope. A check is also made that the argument is a |
| 25875 |
-- function with one parameter. |
| 25876 |
|
| 25877 |
-------------------------------------- |
| 25878 |
-- Check_OK_Stream_Convert_Function -- |
| 25879 |
-------------------------------------- |
| 25880 |
|
| 25881 |
procedure Check_OK_Stream_Convert_Function (Arg : Node_Id) is |
| 25882 |
Ent : Entity_Id; |
| 25883 |
|
| 25884 |
begin |
| 25885 |
Check_Arg_Is_Local_Name (Arg); |
| 25886 |
Ent := Entity (Get_Pragma_Arg (Arg)); |
| 25887 |
|
| 25888 |
if Has_Homonym (Ent) then |
| 25889 |
Error_Pragma_Arg |
| 25890 |
("argument for pragma% may not be overloaded", Arg); |
| 25891 |
end if; |
| 25892 |
|
| 25893 |
if Ekind (Ent) /= E_Function |
| 25894 |
or else No (First_Formal (Ent)) |
| 25895 |
or else Present (Next_Formal (First_Formal (Ent))) |
| 25896 |
then |
| 25897 |
Error_Pragma_Arg |
| 25898 |
("argument for pragma% must be function of one argument", |
| 25899 |
Arg); |
| 25900 |
elsif Is_Abstract_Subprogram (Ent) then |
| 25901 |
Error_Pragma_Arg |
| 25902 |
("argument for pragma% cannot be abstract", Arg); |
| 25903 |
end if; |
| 25904 |
end Check_OK_Stream_Convert_Function; |
| 25905 |
|
| 25906 |
-- Start of processing for Stream_Convert |
| 25907 |
|
| 25908 |
begin |
| 25909 |
GNAT_Pragma; |
| 25910 |
Check_Arg_Order ((Name_Entity, Name_Read, Name_Write)); |
| 25911 |
Check_Arg_Count (3); |
| 25912 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 25913 |
Check_Optional_Identifier (Arg2, Name_Read); |
| 25914 |
Check_Optional_Identifier (Arg3, Name_Write); |
| 25915 |
Check_Arg_Is_Local_Name (Arg1); |
| 25916 |
Check_OK_Stream_Convert_Function (Arg2); |
| 25917 |
Check_OK_Stream_Convert_Function (Arg3); |
| 25918 |
|
| 25919 |
declare |
| 25920 |
Typ : constant Entity_Id := |
| 25921 |
Underlying_Type (Entity (Get_Pragma_Arg (Arg1))); |
| 25922 |
Read : constant Entity_Id := Entity (Get_Pragma_Arg (Arg2)); |
| 25923 |
Write : constant Entity_Id := Entity (Get_Pragma_Arg (Arg3)); |
| 25924 |
|
| 25925 |
begin |
| 25926 |
Check_First_Subtype (Arg1); |
| 25927 |
|
| 25928 |
-- Check for too early or too late. Note that we don't enforce |
| 25929 |
-- the rule about primitive operations in this case, since, as |
| 25930 |
-- is the case for explicit stream attributes themselves, these |
| 25931 |
-- restrictions are not appropriate. Note that the chaining of |
| 25932 |
-- the pragma by Rep_Item_Too_Late is actually the critical |
| 25933 |
-- processing done for this pragma. |
| 25934 |
|
| 25935 |
if Rep_Item_Too_Early (Typ, N) |
| 25936 |
or else |
| 25937 |
Rep_Item_Too_Late (Typ, N, FOnly => True) |
| 25938 |
then |
| 25939 |
return; |
| 25940 |
end if; |
| 25941 |
|
| 25942 |
-- Return if previous error |
| 25943 |
|
| 25944 |
if Etype (Typ) = Any_Type |
| 25945 |
or else |
| 25946 |
Etype (Read) = Any_Type |
| 25947 |
or else |
| 25948 |
Etype (Write) = Any_Type |
| 25949 |
then |
| 25950 |
return; |
| 25951 |
end if; |
| 25952 |
|
| 25953 |
-- Error checks |
| 25954 |
|
| 25955 |
if Underlying_Type (Etype (Read)) /= Typ then |
| 25956 |
Error_Pragma_Arg |
| 25957 |
("incorrect return type for function&", Arg2); |
| 25958 |
end if; |
| 25959 |
|
| 25960 |
if Underlying_Type (Etype (First_Formal (Write))) /= Typ then |
| 25961 |
Error_Pragma_Arg |
| 25962 |
("incorrect parameter type for function&", Arg3); |
| 25963 |
end if; |
| 25964 |
|
| 25965 |
if Underlying_Type (Etype (First_Formal (Read))) /= |
| 25966 |
Underlying_Type (Etype (Write)) |
| 25967 |
then |
| 25968 |
Error_Pragma_Arg |
| 25969 |
("result type of & does not match Read parameter type", |
| 25970 |
Arg3); |
| 25971 |
end if; |
| 25972 |
end; |
| 25973 |
end Stream_Convert; |
| 25974 |
|
| 25975 |
------------------ |
| 25976 |
-- Style_Checks -- |
| 25977 |
------------------ |
| 25978 |
|
| 25979 |
-- pragma Style_Checks (On | Off | ALL_CHECKS | STRING_LITERAL); |
| 25980 |
|
| 25981 |
-- This is processed by the parser since some of the style checks |
| 25982 |
-- take place during source scanning and parsing. This means that |
| 25983 |
-- we don't need to issue error messages here. |
| 25984 |
|
| 25985 |
when Pragma_Style_Checks => Style_Checks : declare |
| 25986 |
A : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 25987 |
S : String_Id; |
| 25988 |
C : Char_Code; |
| 25989 |
|
| 25990 |
begin |
| 25991 |
GNAT_Pragma; |
| 25992 |
Check_No_Identifiers; |
| 25993 |
|
| 25994 |
-- Two argument form |
| 25995 |
|
| 25996 |
if Arg_Count = 2 then |
| 25997 |
Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off); |
| 25998 |
|
| 25999 |
declare |
| 26000 |
E_Id : Node_Id; |
| 26001 |
E : Entity_Id; |
| 26002 |
|
| 26003 |
begin |
| 26004 |
E_Id := Get_Pragma_Arg (Arg2); |
| 26005 |
Analyze (E_Id); |
| 26006 |
|
| 26007 |
if not Is_Entity_Name (E_Id) then |
| 26008 |
Error_Pragma_Arg |
| 26009 |
("second argument of pragma% must be entity name", |
| 26010 |
Arg2); |
| 26011 |
end if; |
| 26012 |
|
| 26013 |
E := Entity (E_Id); |
| 26014 |
|
| 26015 |
if not Ignore_Style_Checks_Pragmas then |
| 26016 |
if E = Any_Id then |
| 26017 |
return; |
| 26018 |
else |
| 26019 |
loop |
| 26020 |
Set_Suppress_Style_Checks |
| 26021 |
(E, Chars (Get_Pragma_Arg (Arg1)) = Name_Off); |
| 26022 |
exit when No (Homonym (E)); |
| 26023 |
E := Homonym (E); |
| 26024 |
end loop; |
| 26025 |
end if; |
| 26026 |
end if; |
| 26027 |
end; |
| 26028 |
|
| 26029 |
-- One argument form |
| 26030 |
|
| 26031 |
else |
| 26032 |
Check_Arg_Count (1); |
| 26033 |
|
| 26034 |
if Ignore_Style_Checks_Pragmas then |
| 26035 |
return; |
| 26036 |
end if; |
| 26037 |
|
| 26038 |
if Nkind (A) = N_String_Literal then |
| 26039 |
S := Strval (A); |
| 26040 |
|
| 26041 |
declare |
| 26042 |
Slen : constant Natural := Natural (String_Length (S)); |
| 26043 |
Options : String (1 .. Slen); |
| 26044 |
J : Positive; |
| 26045 |
|
| 26046 |
begin |
| 26047 |
J := 1; |
| 26048 |
loop |
| 26049 |
C := Get_String_Char (S, Pos (J)); |
| 26050 |
exit when not In_Character_Range (C); |
| 26051 |
Options (J) := Get_Character (C); |
| 26052 |
|
| 26053 |
-- If at end of string, set options. As per discussion |
| 26054 |
-- above, no need to check for errors, since we issued |
| 26055 |
-- them in the parser. |
| 26056 |
|
| 26057 |
if J = Slen then |
| 26058 |
Set_Style_Check_Options (Options); |
| 26059 |
|
| 26060 |
exit; |
| 26061 |
end if; |
| 26062 |
|
| 26063 |
J := J + 1; |
| 26064 |
end loop; |
| 26065 |
end; |
| 26066 |
|
| 26067 |
elsif Nkind (A) = N_Identifier then |
| 26068 |
if Chars (A) = Name_All_Checks then |
| 26069 |
if GNAT_Mode then |
| 26070 |
Set_GNAT_Style_Check_Options; |
| 26071 |
else |
| 26072 |
Set_Default_Style_Check_Options; |
| 26073 |
end if; |
| 26074 |
|
| 26075 |
elsif Chars (A) = Name_On then |
| 26076 |
Style_Check := True; |
| 26077 |
|
| 26078 |
elsif Chars (A) = Name_Off then |
| 26079 |
Style_Check := False; |
| 26080 |
end if; |
| 26081 |
end if; |
| 26082 |
end if; |
| 26083 |
end Style_Checks; |
| 26084 |
|
| 26085 |
------------------------ |
| 26086 |
-- Subprogram_Variant -- |
| 26087 |
------------------------ |
| 26088 |
|
| 26089 |
-- pragma Subprogram_Variant ( SUBPROGRAM_VARIANT_LIST ); |
| 26090 |
|
| 26091 |
-- SUBPROGRAM_VARIANT_LIST ::= STRUCTURAL_SUBPROGRAM_VARIANT_ITEM |
| 26092 |
-- | NUMERIC_SUBPROGRAM_VARIANT_ITEMS |
| 26093 |
-- NUMERIC_SUBPROGRAM_VARIANT_ITEMS ::= |
| 26094 |
-- NUMERIC_SUBPROGRAM_VARIANT_ITEM |
| 26095 |
-- {, NUMERIC_SUBPROGRAM_VARIANT_ITEM} |
| 26096 |
-- NUMERIC_SUBPROGRAM_VARIANT_ITEM ::= CHANGE_DIRECTION => EXPRESSION |
| 26097 |
-- STRUCTURAL_SUBPROGRAM_VARIANT_ITEM ::= Structural => EXPRESSION |
| 26098 |
-- CHANGE_DIRECTION ::= Increases | Decreases |
| 26099 |
|
| 26100 |
-- Characteristics: |
| 26101 |
|
| 26102 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 26103 |
-- the legal placement and context. Secondary checks preanalyze the |
| 26104 |
-- expressions in: |
| 26105 |
|
| 26106 |
-- Analyze_Subprogram_Variant_In_Decl_Part |
| 26107 |
|
| 26108 |
-- * Expansion - The annotation is expanded during the expansion of |
| 26109 |
-- the related subprogram [body] contract as performed in: |
| 26110 |
|
| 26111 |
-- Expand_Subprogram_Contract |
| 26112 |
|
| 26113 |
-- * Template - The annotation utilizes the generic template of the |
| 26114 |
-- related subprogram [body] when it is: |
| 26115 |
|
| 26116 |
-- aspect on subprogram declaration |
| 26117 |
-- aspect on stand-alone subprogram body |
| 26118 |
-- pragma on stand-alone subprogram body |
| 26119 |
|
| 26120 |
-- The annotation must prepare its own template when it is: |
| 26121 |
|
| 26122 |
-- pragma on subprogram declaration |
| 26123 |
|
| 26124 |
-- * Globals - Capture of global references must occur after full |
| 26125 |
-- analysis. |
| 26126 |
|
| 26127 |
-- * Instance - The annotation is instantiated automatically when |
| 26128 |
-- the related generic subprogram [body] is instantiated except for |
| 26129 |
-- the "pragma on subprogram declaration" case. In that scenario |
| 26130 |
-- the annotation must instantiate itself. |
| 26131 |
|
| 26132 |
when Pragma_Subprogram_Variant => Subprogram_Variant : declare |
| 26133 |
Spec_Id : Entity_Id; |
| 26134 |
Subp_Decl : Node_Id; |
| 26135 |
Subp_Spec : Node_Id; |
| 26136 |
|
| 26137 |
begin |
| 26138 |
GNAT_Pragma; |
| 26139 |
Check_No_Identifiers; |
| 26140 |
Check_Arg_Count (1); |
| 26141 |
|
| 26142 |
-- Ensure the proper placement of the pragma. Subprogram_Variant |
| 26143 |
-- must be associated with a subprogram declaration or a body that |
| 26144 |
-- acts as a spec. |
| 26145 |
|
| 26146 |
Subp_Decl := |
| 26147 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 26148 |
|
| 26149 |
-- Generic subprogram |
| 26150 |
|
| 26151 |
if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 26152 |
null; |
| 26153 |
|
| 26154 |
-- Body acts as spec |
| 26155 |
|
| 26156 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 26157 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 26158 |
then |
| 26159 |
null; |
| 26160 |
|
| 26161 |
-- Body stub acts as spec |
| 26162 |
|
| 26163 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 26164 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 26165 |
then |
| 26166 |
null; |
| 26167 |
|
| 26168 |
-- Subprogram |
| 26169 |
|
| 26170 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 26171 |
Subp_Spec := Specification (Subp_Decl); |
| 26172 |
|
| 26173 |
-- Pragma Subprogram_Variant is forbidden on null procedures, |
| 26174 |
-- as this may lead to potential ambiguities in behavior when |
| 26175 |
-- interface null procedures are involved. Also, it just |
| 26176 |
-- wouldn't make sense, because null procedure is not |
| 26177 |
-- recursive. |
| 26178 |
|
| 26179 |
if Nkind (Subp_Spec) = N_Procedure_Specification |
| 26180 |
and then Null_Present (Subp_Spec) |
| 26181 |
then |
| 26182 |
Error_Msg_N (Fix_Error |
| 26183 |
("pragma % cannot apply to null procedure"), N); |
| 26184 |
return; |
| 26185 |
end if; |
| 26186 |
|
| 26187 |
else |
| 26188 |
Pragma_Misplaced; |
| 26189 |
end if; |
| 26190 |
|
| 26191 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 26192 |
|
| 26193 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 26194 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 26195 |
|
| 26196 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 26197 |
Ensure_Aggregate_Form (Get_Argument (N, Spec_Id)); |
| 26198 |
|
| 26199 |
-- Chain the pragma on the contract for further processing by |
| 26200 |
-- Analyze_Subprogram_Variant_In_Decl_Part. |
| 26201 |
|
| 26202 |
Add_Contract_Item (N, Defining_Entity (Subp_Decl)); |
| 26203 |
|
| 26204 |
-- Fully analyze the pragma when it appears inside a subprogram |
| 26205 |
-- body because it cannot benefit from forward references. |
| 26206 |
|
| 26207 |
if Nkind (Subp_Decl) in N_Subprogram_Body |
| 26208 |
| N_Subprogram_Body_Stub |
| 26209 |
then |
| 26210 |
-- The legality checks of pragma Subprogram_Variant are |
| 26211 |
-- affected by the SPARK mode in effect and the volatility |
| 26212 |
-- of the context. Analyze all pragmas in a specific order. |
| 26213 |
|
| 26214 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 26215 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 26216 |
Analyze_Subprogram_Variant_In_Decl_Part (N); |
| 26217 |
end if; |
| 26218 |
end Subprogram_Variant; |
| 26219 |
|
| 26220 |
-------------- |
| 26221 |
-- Subtitle -- |
| 26222 |
-------------- |
| 26223 |
|
| 26224 |
-- pragma Subtitle ([Subtitle =>] STRING_LITERAL); |
| 26225 |
|
| 26226 |
when Pragma_Subtitle => |
| 26227 |
GNAT_Pragma; |
| 26228 |
Check_Arg_Count (1); |
| 26229 |
Check_Optional_Identifier (Arg1, Name_Subtitle); |
| 26230 |
Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String); |
| 26231 |
Store_Note (N); |
| 26232 |
|
| 26233 |
-------------- |
| 26234 |
-- Suppress -- |
| 26235 |
-------------- |
| 26236 |
|
| 26237 |
-- pragma Suppress (IDENTIFIER [, [On =>] NAME]); |
| 26238 |
|
| 26239 |
when Pragma_Suppress => |
| 26240 |
Process_Suppress_Unsuppress (Suppress_Case => True); |
| 26241 |
|
| 26242 |
------------------ |
| 26243 |
-- Suppress_All -- |
| 26244 |
------------------ |
| 26245 |
|
| 26246 |
-- pragma Suppress_All; |
| 26247 |
|
| 26248 |
-- The only check made here is that the pragma has no arguments. |
| 26249 |
-- There are no placement rules, and the processing required (setting |
| 26250 |
-- the Has_Pragma_Suppress_All flag in the compilation unit node was |
| 26251 |
-- taken care of by the parser). Process_Compilation_Unit_Pragmas |
| 26252 |
-- then creates and inserts a pragma Suppress (All_Checks). |
| 26253 |
|
| 26254 |
when Pragma_Suppress_All => |
| 26255 |
GNAT_Pragma; |
| 26256 |
Check_Arg_Count (0); |
| 26257 |
|
| 26258 |
------------------------- |
| 26259 |
-- Suppress_Debug_Info -- |
| 26260 |
------------------------- |
| 26261 |
|
| 26262 |
-- pragma Suppress_Debug_Info ([Entity =>] LOCAL_NAME); |
| 26263 |
|
| 26264 |
when Pragma_Suppress_Debug_Info => Suppress_Debug_Info : declare |
| 26265 |
Nam_Id : Entity_Id; |
| 26266 |
|
| 26267 |
begin |
| 26268 |
GNAT_Pragma; |
| 26269 |
Check_Arg_Count (1); |
| 26270 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 26271 |
Check_Arg_Is_Local_Name (Arg1); |
| 26272 |
|
| 26273 |
Nam_Id := Entity (Get_Pragma_Arg (Arg1)); |
| 26274 |
|
| 26275 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 26276 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 26277 |
|
| 26278 |
Mark_Ghost_Pragma (N, Nam_Id); |
| 26279 |
Set_Debug_Info_Off (Nam_Id); |
| 26280 |
end Suppress_Debug_Info; |
| 26281 |
|
| 26282 |
---------------------------------- |
| 26283 |
-- Suppress_Exception_Locations -- |
| 26284 |
---------------------------------- |
| 26285 |
|
| 26286 |
-- pragma Suppress_Exception_Locations; |
| 26287 |
|
| 26288 |
when Pragma_Suppress_Exception_Locations => |
| 26289 |
GNAT_Pragma; |
| 26290 |
Check_Arg_Count (0); |
| 26291 |
Check_Valid_Configuration_Pragma; |
| 26292 |
Exception_Locations_Suppressed := True; |
| 26293 |
|
| 26294 |
----------------------------- |
| 26295 |
-- Suppress_Initialization -- |
| 26296 |
----------------------------- |
| 26297 |
|
| 26298 |
-- pragma Suppress_Initialization ([Entity =>] type_LOCAL_NAME); |
| 26299 |
|
| 26300 |
when Pragma_Suppress_Initialization => Suppress_Init : declare |
| 26301 |
E : Entity_Id; |
| 26302 |
E_Id : Node_Id; |
| 26303 |
|
| 26304 |
begin |
| 26305 |
GNAT_Pragma; |
| 26306 |
Check_Arg_Count (1); |
| 26307 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 26308 |
Check_Arg_Is_Local_Name (Arg1); |
| 26309 |
|
| 26310 |
E_Id := Get_Pragma_Arg (Arg1); |
| 26311 |
|
| 26312 |
if Etype (E_Id) = Any_Type then |
| 26313 |
return; |
| 26314 |
end if; |
| 26315 |
|
| 26316 |
E := Entity (E_Id); |
| 26317 |
|
| 26318 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 26319 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 26320 |
|
| 26321 |
Mark_Ghost_Pragma (N, E); |
| 26322 |
|
| 26323 |
if not Is_Type (E) and then Ekind (E) /= E_Variable then |
| 26324 |
Error_Pragma_Arg |
| 26325 |
("pragma% requires variable, type or subtype", Arg1); |
| 26326 |
end if; |
| 26327 |
|
| 26328 |
if Rep_Item_Too_Early (E, N) |
| 26329 |
or else |
| 26330 |
Rep_Item_Too_Late (E, N, FOnly => True) |
| 26331 |
then |
| 26332 |
return; |
| 26333 |
end if; |
| 26334 |
|
| 26335 |
-- For incomplete/private type, set flag on full view |
| 26336 |
|
| 26337 |
if Is_Incomplete_Or_Private_Type (E) then |
| 26338 |
if No (Full_View (Base_Type (E))) then |
| 26339 |
Error_Pragma_Arg |
| 26340 |
("argument of pragma% cannot be an incomplete type", Arg1); |
| 26341 |
else |
| 26342 |
Set_Suppress_Initialization (Full_View (E)); |
| 26343 |
end if; |
| 26344 |
|
| 26345 |
-- For first subtype, set flag on base type |
| 26346 |
|
| 26347 |
elsif Is_First_Subtype (E) then |
| 26348 |
Set_Suppress_Initialization (Base_Type (E)); |
| 26349 |
|
| 26350 |
-- For other than first subtype, set flag on subtype or variable |
| 26351 |
|
| 26352 |
else |
| 26353 |
Set_Suppress_Initialization (E); |
| 26354 |
end if; |
| 26355 |
end Suppress_Init; |
| 26356 |
|
| 26357 |
----------------- |
| 26358 |
-- System_Name -- |
| 26359 |
----------------- |
| 26360 |
|
| 26361 |
-- pragma System_Name (DIRECT_NAME); |
| 26362 |
|
| 26363 |
-- Syntax check: one argument, which must be the identifier GNAT or |
| 26364 |
-- the identifier GCC, no other identifiers are acceptable. |
| 26365 |
|
| 26366 |
when Pragma_System_Name => |
| 26367 |
GNAT_Pragma; |
| 26368 |
Check_No_Identifiers; |
| 26369 |
Check_Arg_Count (1); |
| 26370 |
Check_Arg_Is_One_Of (Arg1, Name_Gcc, Name_Gnat); |
| 26371 |
|
| 26372 |
----------------------------- |
| 26373 |
-- Task_Dispatching_Policy -- |
| 26374 |
----------------------------- |
| 26375 |
|
| 26376 |
-- pragma Task_Dispatching_Policy (policy_IDENTIFIER); |
| 26377 |
|
| 26378 |
when Pragma_Task_Dispatching_Policy => declare |
| 26379 |
DP : Character; |
| 26380 |
|
| 26381 |
begin |
| 26382 |
Check_Ada_83_Warning; |
| 26383 |
Check_Arg_Count (1); |
| 26384 |
Check_No_Identifiers; |
| 26385 |
Check_Arg_Is_Task_Dispatching_Policy (Arg1); |
| 26386 |
Check_Valid_Configuration_Pragma; |
| 26387 |
Get_Name_String (Chars (Get_Pragma_Arg (Arg1))); |
| 26388 |
DP := Fold_Upper (Name_Buffer (1)); |
| 26389 |
|
| 26390 |
if Task_Dispatching_Policy /= ' ' |
| 26391 |
and then Task_Dispatching_Policy /= DP |
| 26392 |
then |
| 26393 |
Error_Msg_Sloc := Task_Dispatching_Policy_Sloc; |
| 26394 |
Error_Pragma |
| 26395 |
("task dispatching policy incompatible with policy#"); |
| 26396 |
|
| 26397 |
-- Set new policy, but always preserve System_Location since we |
| 26398 |
-- like the error message with the run time name. |
| 26399 |
|
| 26400 |
else |
| 26401 |
Task_Dispatching_Policy := DP; |
| 26402 |
|
| 26403 |
if Task_Dispatching_Policy_Sloc /= System_Location then |
| 26404 |
Task_Dispatching_Policy_Sloc := Loc; |
| 26405 |
end if; |
| 26406 |
end if; |
| 26407 |
end; |
| 26408 |
|
| 26409 |
--------------- |
| 26410 |
-- Task_Info -- |
| 26411 |
--------------- |
| 26412 |
|
| 26413 |
-- pragma Task_Info (EXPRESSION); |
| 26414 |
|
| 26415 |
when Pragma_Task_Info => Task_Info : declare |
| 26416 |
P : constant Node_Id := Parent (N); |
| 26417 |
Ent : Entity_Id; |
| 26418 |
|
| 26419 |
begin |
| 26420 |
GNAT_Pragma; |
| 26421 |
|
| 26422 |
if Warn_On_Obsolescent_Feature then |
| 26423 |
Error_Msg_N |
| 26424 |
("'G'N'A'T pragma Task_Info is now obsolete, use 'C'P'U " |
| 26425 |
& "instead?j?", N); |
| 26426 |
end if; |
| 26427 |
|
| 26428 |
if Nkind (P) /= N_Task_Definition then |
| 26429 |
Error_Pragma ("pragma% must appear in task definition"); |
| 26430 |
end if; |
| 26431 |
|
| 26432 |
Check_No_Identifiers; |
| 26433 |
Check_Arg_Count (1); |
| 26434 |
|
| 26435 |
Analyze_And_Resolve |
| 26436 |
(Get_Pragma_Arg (Arg1), RTE (RE_Task_Info_Type)); |
| 26437 |
|
| 26438 |
if Etype (Get_Pragma_Arg (Arg1)) = Any_Type then |
| 26439 |
return; |
| 26440 |
end if; |
| 26441 |
|
| 26442 |
Ent := Defining_Identifier (Parent (P)); |
| 26443 |
|
| 26444 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 26445 |
-- Item chain of Ent. |
| 26446 |
|
| 26447 |
if Has_Rep_Pragma |
| 26448 |
(Ent, Name_Task_Info, Check_Parents => False) |
| 26449 |
then |
| 26450 |
Error_Pragma ("duplicate pragma% not allowed"); |
| 26451 |
end if; |
| 26452 |
|
| 26453 |
Record_Rep_Item (Ent, N); |
| 26454 |
end Task_Info; |
| 26455 |
|
| 26456 |
--------------- |
| 26457 |
-- Task_Name -- |
| 26458 |
--------------- |
| 26459 |
|
| 26460 |
-- pragma Task_Name (string_EXPRESSION); |
| 26461 |
|
| 26462 |
when Pragma_Task_Name => Task_Name : declare |
| 26463 |
P : constant Node_Id := Parent (N); |
| 26464 |
Arg : Node_Id; |
| 26465 |
Ent : Entity_Id; |
| 26466 |
|
| 26467 |
begin |
| 26468 |
Check_No_Identifiers; |
| 26469 |
Check_Arg_Count (1); |
| 26470 |
|
| 26471 |
Arg := Get_Pragma_Arg (Arg1); |
| 26472 |
|
| 26473 |
-- The expression is used in the call to Create_Task, and must be |
| 26474 |
-- expanded there, not in the context of the current spec. It must |
| 26475 |
-- however be analyzed to capture global references, in case it |
| 26476 |
-- appears in a generic context. |
| 26477 |
|
| 26478 |
Preanalyze_And_Resolve (Arg, Standard_String); |
| 26479 |
|
| 26480 |
if Nkind (P) /= N_Task_Definition then |
| 26481 |
Pragma_Misplaced; |
| 26482 |
end if; |
| 26483 |
|
| 26484 |
Ent := Defining_Identifier (Parent (P)); |
| 26485 |
|
| 26486 |
-- Check duplicate pragma before we chain the pragma in the Rep |
| 26487 |
-- Item chain of Ent. |
| 26488 |
|
| 26489 |
if Has_Rep_Pragma |
| 26490 |
(Ent, Name_Task_Name, Check_Parents => False) |
| 26491 |
then |
| 26492 |
Error_Pragma ("duplicate pragma% not allowed"); |
| 26493 |
end if; |
| 26494 |
|
| 26495 |
Record_Rep_Item (Ent, N); |
| 26496 |
end Task_Name; |
| 26497 |
|
| 26498 |
------------------ |
| 26499 |
-- Task_Storage -- |
| 26500 |
------------------ |
| 26501 |
|
| 26502 |
-- pragma Task_Storage ( |
| 26503 |
-- [Task_Type =>] LOCAL_NAME, |
| 26504 |
-- [Top_Guard =>] static_integer_EXPRESSION); |
| 26505 |
|
| 26506 |
when Pragma_Task_Storage => Task_Storage : declare |
| 26507 |
Args : Args_List (1 .. 2); |
| 26508 |
Names : constant Name_List (1 .. 2) := ( |
| 26509 |
Name_Task_Type, |
| 26510 |
Name_Top_Guard); |
| 26511 |
|
| 26512 |
Task_Type : Node_Id renames Args (1); |
| 26513 |
Top_Guard : Node_Id renames Args (2); |
| 26514 |
|
| 26515 |
Ent : Entity_Id; |
| 26516 |
|
| 26517 |
begin |
| 26518 |
GNAT_Pragma; |
| 26519 |
Gather_Associations (Names, Args); |
| 26520 |
|
| 26521 |
if No (Task_Type) then |
| 26522 |
Error_Pragma |
| 26523 |
("missing task_type argument for pragma%"); |
| 26524 |
end if; |
| 26525 |
|
| 26526 |
Check_Arg_Is_Local_Name (Task_Type); |
| 26527 |
|
| 26528 |
Ent := Entity (Task_Type); |
| 26529 |
|
| 26530 |
if not Is_Task_Type (Ent) then |
| 26531 |
Error_Pragma_Arg |
| 26532 |
("argument for pragma% must be task type", Task_Type); |
| 26533 |
end if; |
| 26534 |
|
| 26535 |
if No (Top_Guard) then |
| 26536 |
Error_Pragma_Arg |
| 26537 |
("pragma% takes two arguments", Task_Type); |
| 26538 |
else |
| 26539 |
Check_Arg_Is_OK_Static_Expression (Top_Guard, Any_Integer); |
| 26540 |
end if; |
| 26541 |
|
| 26542 |
Check_First_Subtype (Task_Type); |
| 26543 |
|
| 26544 |
if Rep_Item_Too_Late (Ent, N) then |
| 26545 |
return; |
| 26546 |
end if; |
| 26547 |
end Task_Storage; |
| 26548 |
|
| 26549 |
--------------- |
| 26550 |
-- Test_Case -- |
| 26551 |
--------------- |
| 26552 |
|
| 26553 |
-- pragma Test_Case |
| 26554 |
-- ([Name =>] Static_String_EXPRESSION |
| 26555 |
-- ,[Mode =>] MODE_TYPE |
| 26556 |
-- [, Requires => Boolean_EXPRESSION] |
| 26557 |
-- [, Ensures => Boolean_EXPRESSION]); |
| 26558 |
|
| 26559 |
-- MODE_TYPE ::= Nominal | Robustness |
| 26560 |
|
| 26561 |
-- Characteristics: |
| 26562 |
|
| 26563 |
-- * Analysis - The annotation undergoes initial checks to verify |
| 26564 |
-- the legal placement and context. Secondary checks preanalyze the |
| 26565 |
-- expressions in: |
| 26566 |
|
| 26567 |
-- Analyze_Test_Case_In_Decl_Part |
| 26568 |
|
| 26569 |
-- * Expansion - None. |
| 26570 |
|
| 26571 |
-- * Template - The annotation utilizes the generic template of the |
| 26572 |
-- related subprogram when it is: |
| 26573 |
|
| 26574 |
-- aspect on subprogram declaration |
| 26575 |
|
| 26576 |
-- The annotation must prepare its own template when it is: |
| 26577 |
|
| 26578 |
-- pragma on subprogram declaration |
| 26579 |
|
| 26580 |
-- * Globals - Capture of global references must occur after full |
| 26581 |
-- analysis. |
| 26582 |
|
| 26583 |
-- * Instance - The annotation is instantiated automatically when |
| 26584 |
-- the related generic subprogram is instantiated except for the |
| 26585 |
-- "pragma on subprogram declaration" case. In that scenario the |
| 26586 |
-- annotation must instantiate itself. |
| 26587 |
|
| 26588 |
when Pragma_Test_Case => Test_Case : declare |
| 26589 |
procedure Check_Distinct_Name (Subp_Id : Entity_Id); |
| 26590 |
-- Ensure that the contract of subprogram Subp_Id does not contain |
| 26591 |
-- another Test_Case pragma with the same Name as the current one. |
| 26592 |
|
| 26593 |
------------------------- |
| 26594 |
-- Check_Distinct_Name -- |
| 26595 |
------------------------- |
| 26596 |
|
| 26597 |
procedure Check_Distinct_Name (Subp_Id : Entity_Id) is |
| 26598 |
Items : constant Node_Id := Contract (Subp_Id); |
| 26599 |
Name : constant String_Id := Get_Name_From_CTC_Pragma (N); |
| 26600 |
Prag : Node_Id; |
| 26601 |
|
| 26602 |
begin |
| 26603 |
-- Inspect all Test_Case pragma of the related subprogram |
| 26604 |
-- looking for one with a duplicate "Name" argument. |
| 26605 |
|
| 26606 |
if Present (Items) then |
| 26607 |
Prag := Contract_Test_Cases (Items); |
| 26608 |
while Present (Prag) loop |
| 26609 |
if Pragma_Name (Prag) = Name_Test_Case |
| 26610 |
and then Prag /= N |
| 26611 |
and then String_Equal |
| 26612 |
(Name, Get_Name_From_CTC_Pragma (Prag)) |
| 26613 |
then |
| 26614 |
Error_Msg_Sloc := Sloc (Prag); |
| 26615 |
Error_Pragma ("name for pragma % is already used #"); |
| 26616 |
end if; |
| 26617 |
|
| 26618 |
Prag := Next_Pragma (Prag); |
| 26619 |
end loop; |
| 26620 |
end if; |
| 26621 |
end Check_Distinct_Name; |
| 26622 |
|
| 26623 |
-- Local variables |
| 26624 |
|
| 26625 |
Pack_Decl : constant Node_Id := Unit (Cunit (Current_Sem_Unit)); |
| 26626 |
Asp_Arg : Node_Id; |
| 26627 |
Context : Node_Id; |
| 26628 |
Subp_Decl : Node_Id; |
| 26629 |
Subp_Id : Entity_Id; |
| 26630 |
|
| 26631 |
-- Start of processing for Test_Case |
| 26632 |
|
| 26633 |
begin |
| 26634 |
GNAT_Pragma; |
| 26635 |
Check_At_Least_N_Arguments (2); |
| 26636 |
Check_At_Most_N_Arguments (4); |
| 26637 |
Check_Arg_Order |
| 26638 |
((Name_Name, Name_Mode, Name_Requires, Name_Ensures)); |
| 26639 |
|
| 26640 |
-- Argument "Name" |
| 26641 |
|
| 26642 |
Check_Optional_Identifier (Arg1, Name_Name); |
| 26643 |
Check_Arg_Is_OK_Static_Expression (Arg1, Standard_String); |
| 26644 |
|
| 26645 |
-- Argument "Mode" |
| 26646 |
|
| 26647 |
Check_Optional_Identifier (Arg2, Name_Mode); |
| 26648 |
Check_Arg_Is_One_Of (Arg2, Name_Nominal, Name_Robustness); |
| 26649 |
|
| 26650 |
-- Arguments "Requires" and "Ensures" |
| 26651 |
|
| 26652 |
if Present (Arg3) then |
| 26653 |
if Present (Arg4) then |
| 26654 |
Check_Identifier (Arg3, Name_Requires); |
| 26655 |
Check_Identifier (Arg4, Name_Ensures); |
| 26656 |
else |
| 26657 |
Check_Identifier_Is_One_Of |
| 26658 |
(Arg3, Name_Requires, Name_Ensures); |
| 26659 |
end if; |
| 26660 |
end if; |
| 26661 |
|
| 26662 |
-- Pragma Test_Case must be associated with a subprogram declared |
| 26663 |
-- in a library-level package. First determine whether the current |
| 26664 |
-- compilation unit is a legal context. |
| 26665 |
|
| 26666 |
if Nkind (Pack_Decl) in N_Package_Declaration |
| 26667 |
| N_Generic_Package_Declaration |
| 26668 |
then |
| 26669 |
null; |
| 26670 |
|
| 26671 |
-- Otherwise the placement is illegal |
| 26672 |
|
| 26673 |
else |
| 26674 |
Error_Pragma |
| 26675 |
("pragma % must be specified within a package declaration"); |
| 26676 |
end if; |
| 26677 |
|
| 26678 |
Subp_Decl := Find_Related_Declaration_Or_Body (N); |
| 26679 |
|
| 26680 |
-- Find the enclosing context |
| 26681 |
|
| 26682 |
Context := Parent (Subp_Decl); |
| 26683 |
|
| 26684 |
if Present (Context) then |
| 26685 |
Context := Parent (Context); |
| 26686 |
end if; |
| 26687 |
|
| 26688 |
-- Verify the placement of the pragma |
| 26689 |
|
| 26690 |
if Nkind (Subp_Decl) = N_Abstract_Subprogram_Declaration then |
| 26691 |
Error_Pragma |
| 26692 |
("pragma % cannot be applied to abstract subprogram"); |
| 26693 |
|
| 26694 |
elsif Nkind (Subp_Decl) = N_Entry_Declaration then |
| 26695 |
Error_Pragma ("pragma % cannot be applied to entry"); |
| 26696 |
|
| 26697 |
-- The context is a [generic] subprogram declared at the top level |
| 26698 |
-- of the [generic] package unit. |
| 26699 |
|
| 26700 |
elsif Nkind (Subp_Decl) in N_Generic_Subprogram_Declaration |
| 26701 |
| N_Subprogram_Declaration |
| 26702 |
and then Present (Context) |
| 26703 |
and then Nkind (Context) in N_Generic_Package_Declaration |
| 26704 |
| N_Package_Declaration |
| 26705 |
then |
| 26706 |
null; |
| 26707 |
|
| 26708 |
-- Otherwise the placement is illegal |
| 26709 |
|
| 26710 |
else |
| 26711 |
Error_Pragma |
| 26712 |
("pragma % must be applied to a library-level subprogram " |
| 26713 |
& "declaration"); |
| 26714 |
end if; |
| 26715 |
|
| 26716 |
Subp_Id := Defining_Entity (Subp_Decl); |
| 26717 |
|
| 26718 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 26719 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 26720 |
|
| 26721 |
Mark_Ghost_Pragma (N, Subp_Id); |
| 26722 |
|
| 26723 |
-- Chain the pragma on the contract for further processing by |
| 26724 |
-- Analyze_Test_Case_In_Decl_Part. |
| 26725 |
|
| 26726 |
Add_Contract_Item (N, Subp_Id); |
| 26727 |
|
| 26728 |
-- Preanalyze the original aspect argument "Name" for a generic |
| 26729 |
-- subprogram to properly capture global references. |
| 26730 |
|
| 26731 |
if Is_Generic_Subprogram (Subp_Id) then |
| 26732 |
Asp_Arg := Test_Case_Arg (N, Name_Name, From_Aspect => True); |
| 26733 |
|
| 26734 |
if Present (Asp_Arg) then |
| 26735 |
|
| 26736 |
-- The argument appears with an identifier in association |
| 26737 |
-- form. |
| 26738 |
|
| 26739 |
if Nkind (Asp_Arg) = N_Component_Association then |
| 26740 |
Asp_Arg := Expression (Asp_Arg); |
| 26741 |
end if; |
| 26742 |
|
| 26743 |
Check_Expr_Is_OK_Static_Expression |
| 26744 |
(Asp_Arg, Standard_String); |
| 26745 |
end if; |
| 26746 |
end if; |
| 26747 |
|
| 26748 |
-- Ensure that the all Test_Case pragmas of the related subprogram |
| 26749 |
-- have distinct names. |
| 26750 |
|
| 26751 |
Check_Distinct_Name (Subp_Id); |
| 26752 |
|
| 26753 |
-- Fully analyze the pragma when it appears inside an entry |
| 26754 |
-- or subprogram body because it cannot benefit from forward |
| 26755 |
-- references. |
| 26756 |
|
| 26757 |
if Nkind (Subp_Decl) in N_Entry_Body |
| 26758 |
| N_Subprogram_Body |
| 26759 |
| N_Subprogram_Body_Stub |
| 26760 |
then |
| 26761 |
-- The legality checks of pragma Test_Case are affected by the |
| 26762 |
-- SPARK mode in effect and the volatility of the context. |
| 26763 |
-- Analyze all pragmas in a specific order. |
| 26764 |
|
| 26765 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 26766 |
Analyze_If_Present (Pragma_Volatile_Function); |
| 26767 |
Analyze_Test_Case_In_Decl_Part (N); |
| 26768 |
end if; |
| 26769 |
end Test_Case; |
| 26770 |
|
| 26771 |
-------------------------- |
| 26772 |
-- Thread_Local_Storage -- |
| 26773 |
-------------------------- |
| 26774 |
|
| 26775 |
-- pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME); |
| 26776 |
|
| 26777 |
when Pragma_Thread_Local_Storage => Thread_Local_Storage : declare |
| 26778 |
E : Entity_Id; |
| 26779 |
Id : Node_Id; |
| 26780 |
|
| 26781 |
begin |
| 26782 |
GNAT_Pragma; |
| 26783 |
Check_Arg_Count (1); |
| 26784 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 26785 |
Check_Arg_Is_Library_Level_Local_Name (Arg1); |
| 26786 |
|
| 26787 |
Id := Get_Pragma_Arg (Arg1); |
| 26788 |
|
| 26789 |
if not Is_Entity_Name (Id) |
| 26790 |
or else Ekind (Entity (Id)) /= E_Variable |
| 26791 |
then |
| 26792 |
Error_Pragma_Arg ("local variable name required", Arg1); |
| 26793 |
end if; |
| 26794 |
|
| 26795 |
E := Entity (Id); |
| 26796 |
|
| 26797 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 26798 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 26799 |
|
| 26800 |
Mark_Ghost_Pragma (N, E); |
| 26801 |
|
| 26802 |
if Rep_Item_Too_Early (E, N) |
| 26803 |
or else |
| 26804 |
Rep_Item_Too_Late (E, N) |
| 26805 |
then |
| 26806 |
return; |
| 26807 |
end if; |
| 26808 |
|
| 26809 |
Set_Has_Pragma_Thread_Local_Storage (E); |
| 26810 |
Set_Has_Gigi_Rep_Item (E); |
| 26811 |
end Thread_Local_Storage; |
| 26812 |
|
| 26813 |
---------------- |
| 26814 |
-- Time_Slice -- |
| 26815 |
---------------- |
| 26816 |
|
| 26817 |
-- pragma Time_Slice (static_duration_EXPRESSION); |
| 26818 |
|
| 26819 |
when Pragma_Time_Slice => Time_Slice : declare |
| 26820 |
Val : Ureal; |
| 26821 |
Nod : Node_Id; |
| 26822 |
|
| 26823 |
begin |
| 26824 |
GNAT_Pragma; |
| 26825 |
Check_Arg_Count (1); |
| 26826 |
Check_No_Identifiers; |
| 26827 |
Check_In_Main_Program; |
| 26828 |
Check_Arg_Is_OK_Static_Expression (Arg1, Standard_Duration); |
| 26829 |
|
| 26830 |
if not Error_Posted (Arg1) then |
| 26831 |
Nod := Next (N); |
| 26832 |
while Present (Nod) loop |
| 26833 |
if Nkind (Nod) = N_Pragma |
| 26834 |
and then Pragma_Name (Nod) = Name_Time_Slice |
| 26835 |
then |
| 26836 |
Error_Msg_Name_1 := Pname; |
| 26837 |
Error_Msg_N ("duplicate pragma% not permitted", Nod); |
| 26838 |
end if; |
| 26839 |
|
| 26840 |
Next (Nod); |
| 26841 |
end loop; |
| 26842 |
end if; |
| 26843 |
|
| 26844 |
-- Process only if in main unit |
| 26845 |
|
| 26846 |
if Get_Source_Unit (Loc) = Main_Unit then |
| 26847 |
Opt.Time_Slice_Set := True; |
| 26848 |
Val := Expr_Value_R (Get_Pragma_Arg (Arg1)); |
| 26849 |
|
| 26850 |
if Val <= Ureal_0 then |
| 26851 |
Opt.Time_Slice_Value := 0; |
| 26852 |
|
| 26853 |
elsif Val > UR_From_Uint (UI_From_Int (1000)) then |
| 26854 |
Opt.Time_Slice_Value := 1_000_000_000; |
| 26855 |
|
| 26856 |
else |
| 26857 |
Opt.Time_Slice_Value := |
| 26858 |
UI_To_Int (UR_To_Uint (Val * UI_From_Int (1_000_000))); |
| 26859 |
end if; |
| 26860 |
end if; |
| 26861 |
end Time_Slice; |
| 26862 |
|
| 26863 |
----------- |
| 26864 |
-- Title -- |
| 26865 |
----------- |
| 26866 |
|
| 26867 |
-- pragma Title (TITLING_OPTION [, TITLING OPTION]); |
| 26868 |
|
| 26869 |
-- TITLING_OPTION ::= |
| 26870 |
-- [Title =>] STRING_LITERAL |
| 26871 |
-- | [Subtitle =>] STRING_LITERAL |
| 26872 |
|
| 26873 |
when Pragma_Title => Title : declare |
| 26874 |
Args : Args_List (1 .. 2); |
| 26875 |
Names : constant Name_List (1 .. 2) := ( |
| 26876 |
Name_Title, |
| 26877 |
Name_Subtitle); |
| 26878 |
|
| 26879 |
begin |
| 26880 |
GNAT_Pragma; |
| 26881 |
Gather_Associations (Names, Args); |
| 26882 |
Store_Note (N); |
| 26883 |
|
| 26884 |
for J in 1 .. 2 loop |
| 26885 |
if Present (Args (J)) then |
| 26886 |
Check_Arg_Is_OK_Static_Expression |
| 26887 |
(Args (J), Standard_String); |
| 26888 |
end if; |
| 26889 |
end loop; |
| 26890 |
end Title; |
| 26891 |
|
| 26892 |
---------------------------- |
| 26893 |
-- Type_Invariant[_Class] -- |
| 26894 |
---------------------------- |
| 26895 |
|
| 26896 |
-- pragma Type_Invariant[_Class] |
| 26897 |
-- ([Entity =>] type_LOCAL_NAME, |
| 26898 |
-- [Check =>] EXPRESSION); |
| 26899 |
|
| 26900 |
when Pragma_Type_Invariant |
| 26901 |
| Pragma_Type_Invariant_Class |
| 26902 |
=> |
| 26903 |
Type_Invariant : declare |
| 26904 |
I_Pragma : Node_Id; |
| 26905 |
|
| 26906 |
begin |
| 26907 |
Check_Arg_Count (2); |
| 26908 |
|
| 26909 |
-- Rewrite Type_Invariant[_Class] pragma as an Invariant pragma, |
| 26910 |
-- setting Class_Present for the Type_Invariant_Class case. |
| 26911 |
|
| 26912 |
Set_Class_Present (N, Prag_Id = Pragma_Type_Invariant_Class); |
| 26913 |
I_Pragma := New_Copy (N); |
| 26914 |
Set_Pragma_Identifier |
| 26915 |
(I_Pragma, Make_Identifier (Loc, Name_Invariant)); |
| 26916 |
Rewrite (N, I_Pragma); |
| 26917 |
Set_Analyzed (N, False); |
| 26918 |
Analyze (N); |
| 26919 |
end Type_Invariant; |
| 26920 |
|
| 26921 |
--------------------- |
| 26922 |
-- Unchecked_Union -- |
| 26923 |
--------------------- |
| 26924 |
|
| 26925 |
-- pragma Unchecked_Union (first_subtype_LOCAL_NAME); |
| 26926 |
|
| 26927 |
when Pragma_Unchecked_Union => Unchecked_Union : declare |
| 26928 |
Assoc : constant Node_Id := Arg1; |
| 26929 |
Type_Id : constant Node_Id := Get_Pragma_Arg (Assoc); |
| 26930 |
Clist : Node_Id; |
| 26931 |
Comp : Node_Id; |
| 26932 |
Tdef : Node_Id; |
| 26933 |
Typ : Entity_Id; |
| 26934 |
Variant : Node_Id; |
| 26935 |
Vpart : Node_Id; |
| 26936 |
|
| 26937 |
begin |
| 26938 |
Ada_2005_Pragma; |
| 26939 |
Check_No_Identifiers; |
| 26940 |
Check_Arg_Count (1); |
| 26941 |
Check_Arg_Is_Local_Name (Arg1); |
| 26942 |
|
| 26943 |
Find_Type (Type_Id); |
| 26944 |
|
| 26945 |
Typ := Entity (Type_Id); |
| 26946 |
|
| 26947 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 26948 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 26949 |
|
| 26950 |
Mark_Ghost_Pragma (N, Typ); |
| 26951 |
|
| 26952 |
if Typ = Any_Type |
| 26953 |
or else Rep_Item_Too_Early (Typ, N) |
| 26954 |
then |
| 26955 |
return; |
| 26956 |
else |
| 26957 |
Typ := Underlying_Type (Typ); |
| 26958 |
end if; |
| 26959 |
|
| 26960 |
if Rep_Item_Too_Late (Typ, N) then |
| 26961 |
return; |
| 26962 |
end if; |
| 26963 |
|
| 26964 |
Check_First_Subtype (Arg1); |
| 26965 |
|
| 26966 |
-- Note remaining cases are references to a type in the current |
| 26967 |
-- declarative part. If we find an error, we post the error on |
| 26968 |
-- the relevant type declaration at an appropriate point. |
| 26969 |
|
| 26970 |
if not Is_Record_Type (Typ) then |
| 26971 |
Error_Msg_N ("unchecked union must be record type", Typ); |
| 26972 |
return; |
| 26973 |
|
| 26974 |
elsif Is_Tagged_Type (Typ) then |
| 26975 |
Error_Msg_N ("unchecked union must not be tagged", Typ); |
| 26976 |
return; |
| 26977 |
|
| 26978 |
elsif not Has_Discriminants (Typ) then |
| 26979 |
Error_Msg_N |
| 26980 |
("unchecked union must have one discriminant", Typ); |
| 26981 |
return; |
| 26982 |
|
| 26983 |
-- Note: in previous versions of GNAT we used to check for limited |
| 26984 |
-- types and give an error, but in fact the standard does allow |
| 26985 |
-- Unchecked_Union on limited types, so this check was removed. |
| 26986 |
|
| 26987 |
-- Similarly, GNAT used to require that all discriminants have |
| 26988 |
-- default values, but this is not mandated by the RM. |
| 26989 |
|
| 26990 |
-- Proceed with basic error checks completed |
| 26991 |
|
| 26992 |
else |
| 26993 |
Tdef := Type_Definition (Declaration_Node (Typ)); |
| 26994 |
Clist := Component_List (Tdef); |
| 26995 |
|
| 26996 |
-- Check presence of component list and variant part |
| 26997 |
|
| 26998 |
if No (Clist) or else No (Variant_Part (Clist)) then |
| 26999 |
Error_Msg_N |
| 27000 |
("unchecked union must have variant part", Tdef); |
| 27001 |
return; |
| 27002 |
end if; |
| 27003 |
|
| 27004 |
-- Check components |
| 27005 |
|
| 27006 |
Comp := First_Non_Pragma (Component_Items (Clist)); |
| 27007 |
while Present (Comp) loop |
| 27008 |
Check_Component (Comp, Typ); |
| 27009 |
Next_Non_Pragma (Comp); |
| 27010 |
end loop; |
| 27011 |
|
| 27012 |
-- Check variant part |
| 27013 |
|
| 27014 |
Vpart := Variant_Part (Clist); |
| 27015 |
|
| 27016 |
Variant := First_Non_Pragma (Variants (Vpart)); |
| 27017 |
while Present (Variant) loop |
| 27018 |
Check_Variant (Variant, Typ); |
| 27019 |
Next_Non_Pragma (Variant); |
| 27020 |
end loop; |
| 27021 |
end if; |
| 27022 |
|
| 27023 |
Set_Is_Unchecked_Union (Typ); |
| 27024 |
Set_Convention (Typ, Convention_C); |
| 27025 |
Set_Has_Unchecked_Union (Base_Type (Typ)); |
| 27026 |
Set_Is_Unchecked_Union (Base_Type (Typ)); |
| 27027 |
end Unchecked_Union; |
| 27028 |
|
| 27029 |
---------------------------- |
| 27030 |
-- Unevaluated_Use_Of_Old -- |
| 27031 |
---------------------------- |
| 27032 |
|
| 27033 |
-- pragma Unevaluated_Use_Of_Old (Error | Warn | Allow); |
| 27034 |
|
| 27035 |
when Pragma_Unevaluated_Use_Of_Old => |
| 27036 |
GNAT_Pragma; |
| 27037 |
Check_Arg_Count (1); |
| 27038 |
Check_No_Identifiers; |
| 27039 |
Check_Arg_Is_One_Of (Arg1, Name_Error, Name_Warn, Name_Allow); |
| 27040 |
|
| 27041 |
-- Suppress/Unsuppress can appear as a configuration pragma, or in |
| 27042 |
-- a declarative part or a package spec. |
| 27043 |
|
| 27044 |
if not Is_Configuration_Pragma then |
| 27045 |
Check_Is_In_Decl_Part_Or_Package_Spec; |
| 27046 |
end if; |
| 27047 |
|
| 27048 |
-- Store proper setting of Uneval_Old |
| 27049 |
|
| 27050 |
Get_Name_String (Chars (Get_Pragma_Arg (Arg1))); |
| 27051 |
Uneval_Old := Fold_Upper (Name_Buffer (1)); |
| 27052 |
|
| 27053 |
------------------------ |
| 27054 |
-- Unimplemented_Unit -- |
| 27055 |
------------------------ |
| 27056 |
|
| 27057 |
-- pragma Unimplemented_Unit; |
| 27058 |
|
| 27059 |
-- Note: this only gives an error if we are generating code, or if |
| 27060 |
-- we are in a generic library unit (where the pragma appears in the |
| 27061 |
-- body, not in the spec). |
| 27062 |
|
| 27063 |
when Pragma_Unimplemented_Unit => Unimplemented_Unit : declare |
| 27064 |
Cunitent : constant Entity_Id := |
| 27065 |
Cunit_Entity (Get_Source_Unit (Loc)); |
| 27066 |
|
| 27067 |
begin |
| 27068 |
GNAT_Pragma; |
| 27069 |
Check_Arg_Count (0); |
| 27070 |
|
| 27071 |
if Operating_Mode = Generate_Code |
| 27072 |
or else Is_Generic_Unit (Cunitent) |
| 27073 |
then |
| 27074 |
Get_Name_String (Chars (Cunitent)); |
| 27075 |
Set_Casing (Mixed_Case); |
| 27076 |
Write_Str (Name_Buffer (1 .. Name_Len)); |
| 27077 |
Write_Str (" is not supported in this configuration"); |
| 27078 |
Write_Eol; |
| 27079 |
raise Unrecoverable_Error; |
| 27080 |
end if; |
| 27081 |
end Unimplemented_Unit; |
| 27082 |
|
| 27083 |
------------------------ |
| 27084 |
-- Universal_Aliasing -- |
| 27085 |
------------------------ |
| 27086 |
|
| 27087 |
-- pragma Universal_Aliasing [([Entity =>] type_LOCAL_NAME)]; |
| 27088 |
|
| 27089 |
when Pragma_Universal_Aliasing => Universal_Alias : declare |
| 27090 |
E : Entity_Id; |
| 27091 |
E_Id : Node_Id; |
| 27092 |
|
| 27093 |
begin |
| 27094 |
GNAT_Pragma; |
| 27095 |
Check_Arg_Count (1); |
| 27096 |
Check_Optional_Identifier (Arg2, Name_Entity); |
| 27097 |
Check_Arg_Is_Local_Name (Arg1); |
| 27098 |
E_Id := Get_Pragma_Arg (Arg1); |
| 27099 |
|
| 27100 |
if Etype (E_Id) = Any_Type then |
| 27101 |
return; |
| 27102 |
end if; |
| 27103 |
|
| 27104 |
E := Entity (E_Id); |
| 27105 |
|
| 27106 |
if not Is_Type (E) then |
| 27107 |
Error_Pragma_Arg ("pragma% requires type", Arg1); |
| 27108 |
end if; |
| 27109 |
|
| 27110 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 27111 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 27112 |
|
| 27113 |
Mark_Ghost_Pragma (N, E); |
| 27114 |
Set_Universal_Aliasing (Base_Type (E)); |
| 27115 |
Record_Rep_Item (E, N); |
| 27116 |
end Universal_Alias; |
| 27117 |
|
| 27118 |
---------------- |
| 27119 |
-- Unmodified -- |
| 27120 |
---------------- |
| 27121 |
|
| 27122 |
-- pragma Unmodified (LOCAL_NAME {, LOCAL_NAME}); |
| 27123 |
|
| 27124 |
when Pragma_Unmodified => |
| 27125 |
Analyze_Unmodified_Or_Unused; |
| 27126 |
|
| 27127 |
------------------ |
| 27128 |
-- Unreferenced -- |
| 27129 |
------------------ |
| 27130 |
|
| 27131 |
-- pragma Unreferenced (LOCAL_NAME {, LOCAL_NAME}); |
| 27132 |
|
| 27133 |
-- or when used in a context clause: |
| 27134 |
|
| 27135 |
-- pragma Unreferenced (library_unit_NAME {, library_unit_NAME}); |
| 27136 |
|
| 27137 |
when Pragma_Unreferenced => |
| 27138 |
Analyze_Unreferenced_Or_Unused; |
| 27139 |
|
| 27140 |
-------------------------- |
| 27141 |
-- Unreferenced_Objects -- |
| 27142 |
-------------------------- |
| 27143 |
|
| 27144 |
-- pragma Unreferenced_Objects (LOCAL_NAME {, LOCAL_NAME}); |
| 27145 |
|
| 27146 |
when Pragma_Unreferenced_Objects => Unreferenced_Objects : declare |
| 27147 |
Arg : Node_Id; |
| 27148 |
Arg_Expr : Node_Id; |
| 27149 |
Arg_Id : Entity_Id; |
| 27150 |
|
| 27151 |
Ghost_Error_Posted : Boolean := False; |
| 27152 |
-- Flag set when an error concerning the illegal mix of Ghost and |
| 27153 |
-- non-Ghost types is emitted. |
| 27154 |
|
| 27155 |
Ghost_Id : Entity_Id := Empty; |
| 27156 |
-- The entity of the first Ghost type encountered while processing |
| 27157 |
-- the arguments of the pragma. |
| 27158 |
|
| 27159 |
begin |
| 27160 |
GNAT_Pragma; |
| 27161 |
Check_At_Least_N_Arguments (1); |
| 27162 |
|
| 27163 |
Arg := Arg1; |
| 27164 |
while Present (Arg) loop |
| 27165 |
Check_No_Identifier (Arg); |
| 27166 |
Check_Arg_Is_Local_Name (Arg); |
| 27167 |
Arg_Expr := Get_Pragma_Arg (Arg); |
| 27168 |
|
| 27169 |
if Is_Entity_Name (Arg_Expr) then |
| 27170 |
Arg_Id := Entity (Arg_Expr); |
| 27171 |
|
| 27172 |
if Is_Type (Arg_Id) then |
| 27173 |
Set_Has_Pragma_Unreferenced_Objects (Arg_Id); |
| 27174 |
|
| 27175 |
-- A pragma that applies to a Ghost entity becomes Ghost |
| 27176 |
-- for the purposes of legality checks and removal of |
| 27177 |
-- ignored Ghost code. |
| 27178 |
|
| 27179 |
Mark_Ghost_Pragma (N, Arg_Id); |
| 27180 |
|
| 27181 |
-- Capture the entity of the first Ghost type being |
| 27182 |
-- processed for error detection purposes. |
| 27183 |
|
| 27184 |
if Is_Ghost_Entity (Arg_Id) then |
| 27185 |
if No (Ghost_Id) then |
| 27186 |
Ghost_Id := Arg_Id; |
| 27187 |
end if; |
| 27188 |
|
| 27189 |
-- Otherwise the type is non-Ghost. It is illegal to mix |
| 27190 |
-- references to Ghost and non-Ghost entities |
| 27191 |
-- (SPARK RM 6.9). |
| 27192 |
|
| 27193 |
elsif Present (Ghost_Id) |
| 27194 |
and then not Ghost_Error_Posted |
| 27195 |
then |
| 27196 |
Ghost_Error_Posted := True; |
| 27197 |
|
| 27198 |
Error_Msg_Name_1 := Pname; |
| 27199 |
Error_Msg_N |
| 27200 |
("pragma % cannot mention ghost and non-ghost types", |
| 27201 |
N); |
| 27202 |
|
| 27203 |
Error_Msg_Sloc := Sloc (Ghost_Id); |
| 27204 |
Error_Msg_NE ("\& # declared as ghost", N, Ghost_Id); |
| 27205 |
|
| 27206 |
Error_Msg_Sloc := Sloc (Arg_Id); |
| 27207 |
Error_Msg_NE ("\& # declared as non-ghost", N, Arg_Id); |
| 27208 |
end if; |
| 27209 |
else |
| 27210 |
Error_Pragma_Arg |
| 27211 |
("argument for pragma% must be type or subtype", Arg); |
| 27212 |
end if; |
| 27213 |
else |
| 27214 |
Error_Pragma_Arg |
| 27215 |
("argument for pragma% must be type or subtype", Arg); |
| 27216 |
end if; |
| 27217 |
|
| 27218 |
Next (Arg); |
| 27219 |
end loop; |
| 27220 |
end Unreferenced_Objects; |
| 27221 |
|
| 27222 |
------------------------------ |
| 27223 |
-- Unreserve_All_Interrupts -- |
| 27224 |
------------------------------ |
| 27225 |
|
| 27226 |
-- pragma Unreserve_All_Interrupts; |
| 27227 |
|
| 27228 |
when Pragma_Unreserve_All_Interrupts => |
| 27229 |
GNAT_Pragma; |
| 27230 |
Check_Arg_Count (0); |
| 27231 |
|
| 27232 |
if In_Extended_Main_Code_Unit (Main_Unit_Entity) then |
| 27233 |
Unreserve_All_Interrupts := True; |
| 27234 |
end if; |
| 27235 |
|
| 27236 |
---------------- |
| 27237 |
-- Unsuppress -- |
| 27238 |
---------------- |
| 27239 |
|
| 27240 |
-- pragma Unsuppress (IDENTIFIER [, [On =>] NAME]); |
| 27241 |
|
| 27242 |
when Pragma_Unsuppress => |
| 27243 |
Ada_2005_Pragma; |
| 27244 |
Process_Suppress_Unsuppress (Suppress_Case => False); |
| 27245 |
|
| 27246 |
------------ |
| 27247 |
-- Unused -- |
| 27248 |
------------ |
| 27249 |
|
| 27250 |
-- pragma Unused (LOCAL_NAME {, LOCAL_NAME}); |
| 27251 |
|
| 27252 |
when Pragma_Unused => |
| 27253 |
Analyze_Unmodified_Or_Unused (Is_Unused => True); |
| 27254 |
Analyze_Unreferenced_Or_Unused (Is_Unused => True); |
| 27255 |
|
| 27256 |
------------------- |
| 27257 |
-- Use_VADS_Size -- |
| 27258 |
------------------- |
| 27259 |
|
| 27260 |
-- pragma Use_VADS_Size; |
| 27261 |
|
| 27262 |
when Pragma_Use_VADS_Size => |
| 27263 |
GNAT_Pragma; |
| 27264 |
Check_Arg_Count (0); |
| 27265 |
Check_Valid_Configuration_Pragma; |
| 27266 |
Use_VADS_Size := True; |
| 27267 |
|
| 27268 |
---------------------------- |
| 27269 |
-- User_Aspect_Definition -- |
| 27270 |
---------------------------- |
| 27271 |
|
| 27272 |
-- pragma User_Aspect_Definition |
| 27273 |
-- (Identifier, {, Identifier [(Identifier {, Identifier})]}); |
| 27274 |
|
| 27275 |
when Pragma_User_Aspect_Definition => |
| 27276 |
GNAT_Pragma; |
| 27277 |
Check_Valid_Configuration_Pragma; |
| 27278 |
declare |
| 27279 |
Arg : Node_Id := |
| 27280 |
First (Pragma_Argument_Associations (N)); |
| 27281 |
User_Aspect_Name : constant Name_Id := Chars (Expression (Arg)); |
| 27282 |
Expr : Node_Id; |
| 27283 |
Aspect : Aspect_Id; |
| 27284 |
begin |
| 27285 |
if Get_Aspect_Id (User_Aspect_Name) /= No_Aspect then |
| 27286 |
Error_Pragma_Arg |
| 27287 |
("User-defined aspect name for pragma% is the name " & |
| 27288 |
"of an existing aspect", Arg); |
| 27289 |
end if; |
| 27290 |
|
| 27291 |
Next (Arg); -- skip first argument, the name of the aspect |
| 27292 |
|
| 27293 |
while Present (Arg) loop |
| 27294 |
Expr := Expression (Arg); |
| 27295 |
case Nkind (Expr) is |
| 27296 |
when N_Identifier => |
| 27297 |
Aspect := Get_Aspect_Id (Chars (Expr)); |
| 27298 |
if Aspect in Boolean_Aspects |
| 27299 |
and not Is_Representation_Aspect (Aspect) |
| 27300 |
then |
| 27301 |
-- If we allowed representation aspects such as |
| 27302 |
-- Pack here, then User_Aspect itself would need |
| 27303 |
-- to be a representation aspect. |
| 27304 |
|
| 27305 |
null; |
| 27306 |
elsif Aspect = No_Aspect and then |
| 27307 |
Present (User_Aspect_Support.Registered_UAD_Pragma |
| 27308 |
(User_Aspect_Name)) |
| 27309 |
then |
| 27310 |
null; |
| 27311 |
else |
| 27312 |
Error_Pragma_Arg |
| 27313 |
("unparameterized argument for pragma% must be " & |
| 27314 |
"either a Boolean-valued non-representation " & |
| 27315 |
"aspect or user-defined", Arg); |
| 27316 |
end if; |
| 27317 |
when N_Indexed_Component => |
| 27318 |
Aspect := Get_Aspect_Id (Chars (Prefix (Expr))); |
| 27319 |
|
| 27320 |
-- Aspect should be an aspect that takes |
| 27321 |
-- identifier arguments that do not refer to |
| 27322 |
-- declarations, but rather to undeclared entities |
| 27323 |
-- such as GNATProve or No_Secondary_Stack for |
| 27324 |
-- which the notion of visibility does not apply. |
| 27325 |
|
| 27326 |
case Aspect is |
| 27327 |
when Aspect_Annotate => |
| 27328 |
if List_Length (Expressions (Expr)) /= 2 then |
| 27329 |
Error_Pragma_Arg |
| 27330 |
("Annotate argument for pragma% takes " & |
| 27331 |
"two parameters", Arg); |
| 27332 |
end if; |
| 27333 |
|
| 27334 |
when Aspect_Local_Restrictions => |
| 27335 |
null; |
| 27336 |
|
| 27337 |
when others => |
| 27338 |
Error_Pragma_Arg |
| 27339 |
("parameterized argument for pragma% must be " & |
| 27340 |
"Annotate or Local_Restrictions aspect", Arg); |
| 27341 |
end case; |
| 27342 |
when others => |
| 27343 |
raise Program_Error; -- parsing error |
| 27344 |
end case; |
| 27345 |
Next (Arg); |
| 27346 |
end loop; |
| 27347 |
|
| 27348 |
declare |
| 27349 |
Registered : constant Node_Id := |
| 27350 |
User_Aspect_Support.Registered_UAD_Pragma |
| 27351 |
(User_Aspect_Name); |
| 27352 |
|
| 27353 |
-- Given two User_Aspect_Definition pragmas with |
| 27354 |
-- matching names for the first argument, check that |
| 27355 |
-- subsequent arguments also match; complain if they differ. |
| 27356 |
procedure Check_UAD_Conformance |
| 27357 |
(New_Pragma, Old_Pragma : Node_Id); |
| 27358 |
|
| 27359 |
--------------------------- |
| 27360 |
-- Check_UAD_Conformance -- |
| 27361 |
--------------------------- |
| 27362 |
|
| 27363 |
procedure Check_UAD_Conformance |
| 27364 |
(New_Pragma, Old_Pragma : Node_Id) |
| 27365 |
is |
| 27366 |
Old_Arg : Node_Id := |
| 27367 |
First (Pragma_Argument_Associations (Old_Pragma)); |
| 27368 |
New_Arg : Node_Id := |
| 27369 |
First (Pragma_Argument_Associations (New_Pragma)); |
| 27370 |
OK : Boolean := True; |
| 27371 |
|
| 27372 |
function Same_Chars (Id1, Id2 : Node_Id) return Boolean |
| 27373 |
is (Chars (Id1) = Chars (Id2)); |
| 27374 |
|
| 27375 |
function Same_Identifier_List (Id1, Id2 : Node_Id) |
| 27376 |
return Boolean |
| 27377 |
is (if No (Id1) and No (Id2) then True |
| 27378 |
elsif No (Id1) or No (Id2) then False |
| 27379 |
else (Same_Chars (Id1, Id2) and then |
| 27380 |
Same_Identifier_List (Next (Id1), Next (Id2)))); |
| 27381 |
begin |
| 27382 |
-- We could skip the first argument pair since those |
| 27383 |
-- are already known to match (or we wouldn't be |
| 27384 |
-- calling this procedure). |
| 27385 |
|
| 27386 |
while Present (Old_Arg) or Present (New_Arg) loop |
| 27387 |
if Present (Old_Arg) /= Present (New_Arg) then |
| 27388 |
OK := False; |
| 27389 |
elsif Nkind (Expression (Old_Arg)) /= |
| 27390 |
Nkind (Expression (New_Arg)) |
| 27391 |
then |
| 27392 |
OK := False; |
| 27393 |
else |
| 27394 |
case Nkind (Expression (Old_Arg)) is |
| 27395 |
when N_Identifier => |
| 27396 |
OK := Same_Chars (Expression (Old_Arg), |
| 27397 |
Expression (New_Arg)); |
| 27398 |
|
| 27399 |
when N_Indexed_Component => |
| 27400 |
OK := Same_Chars |
| 27401 |
(Prefix (Expression (Old_Arg)), |
| 27402 |
Prefix (Expression (New_Arg))) |
| 27403 |
and then Same_Identifier_List |
| 27404 |
(First (Expressions |
| 27405 |
(Expression (Old_Arg))), |
| 27406 |
First (Expressions |
| 27407 |
(Expression (New_Arg)))); |
| 27408 |
|
| 27409 |
when others => |
| 27410 |
OK := False; |
| 27411 |
pragma Assert (False); |
| 27412 |
end case; |
| 27413 |
end if; |
| 27414 |
|
| 27415 |
if not OK then |
| 27416 |
Error_Msg_Sloc := Sloc (Old_Pragma); |
| 27417 |
Error_Msg_N |
| 27418 |
("Nonconforming definitions for user-defined " & |
| 27419 |
"aspect #", New_Pragma); |
| 27420 |
return; |
| 27421 |
end if; |
| 27422 |
|
| 27423 |
Next (Old_Arg); |
| 27424 |
Next (New_Arg); |
| 27425 |
end loop; |
| 27426 |
end Check_UAD_Conformance; |
| 27427 |
begin |
| 27428 |
if Present (Registered) then |
| 27429 |
-- If we have already seen a UAD pragma with this name, |
| 27430 |
-- then check that the two pragmas conform (which means |
| 27431 |
-- that the new pragma is redundant and can be ignored). |
| 27432 |
|
| 27433 |
-- ??? We could also perform a similar bind-time check, |
| 27434 |
-- since it is possible that an incompatible pair of |
| 27435 |
-- UAD pragmas might not be detected by this check. |
| 27436 |
-- This could arise if no unit's compilation closure |
| 27437 |
-- includes both of the two. The major downside of |
| 27438 |
-- failing to detect this case is possible confusion |
| 27439 |
-- for human readers. |
| 27440 |
|
| 27441 |
Check_UAD_Conformance (New_Pragma => N, |
| 27442 |
Old_Pragma => Registered); |
| 27443 |
else |
| 27444 |
User_Aspect_Support.Register_UAD_Pragma (N); |
| 27445 |
end if; |
| 27446 |
end; |
| 27447 |
end; |
| 27448 |
|
| 27449 |
--------------------- |
| 27450 |
-- Validity_Checks -- |
| 27451 |
--------------------- |
| 27452 |
|
| 27453 |
-- pragma Validity_Checks (On | Off | ALL_CHECKS | STRING_LITERAL); |
| 27454 |
|
| 27455 |
when Pragma_Validity_Checks => Validity_Checks : declare |
| 27456 |
A : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 27457 |
S : String_Id; |
| 27458 |
C : Char_Code; |
| 27459 |
|
| 27460 |
begin |
| 27461 |
GNAT_Pragma; |
| 27462 |
Check_Arg_Count (1); |
| 27463 |
Check_No_Identifiers; |
| 27464 |
|
| 27465 |
-- Pragma always active unless in CodePeer or GNATprove modes, |
| 27466 |
-- which use a fixed configuration of validity checks. |
| 27467 |
|
| 27468 |
if not (CodePeer_Mode or GNATprove_Mode) then |
| 27469 |
if Nkind (A) = N_String_Literal then |
| 27470 |
S := Strval (A); |
| 27471 |
|
| 27472 |
declare |
| 27473 |
Slen : constant Natural := Natural (String_Length (S)); |
| 27474 |
Options : String (1 .. Slen); |
| 27475 |
J : Positive; |
| 27476 |
|
| 27477 |
begin |
| 27478 |
-- Couldn't we use a for loop here over Options'Range??? |
| 27479 |
|
| 27480 |
J := 1; |
| 27481 |
loop |
| 27482 |
C := Get_String_Char (S, Pos (J)); |
| 27483 |
|
| 27484 |
-- This is a weird test, it skips setting validity |
| 27485 |
-- checks entirely if any element of S is out of |
| 27486 |
-- range of Character, what is that about ??? |
| 27487 |
|
| 27488 |
exit when not In_Character_Range (C); |
| 27489 |
Options (J) := Get_Character (C); |
| 27490 |
|
| 27491 |
if J = Slen then |
| 27492 |
Set_Validity_Check_Options (Options); |
| 27493 |
exit; |
| 27494 |
else |
| 27495 |
J := J + 1; |
| 27496 |
end if; |
| 27497 |
end loop; |
| 27498 |
end; |
| 27499 |
|
| 27500 |
elsif Nkind (A) = N_Identifier then |
| 27501 |
if Chars (A) = Name_All_Checks then |
| 27502 |
Set_Validity_Check_Options ("a"); |
| 27503 |
elsif Chars (A) = Name_On then |
| 27504 |
Validity_Checks_On := True; |
| 27505 |
elsif Chars (A) = Name_Off then |
| 27506 |
Validity_Checks_On := False; |
| 27507 |
end if; |
| 27508 |
end if; |
| 27509 |
end if; |
| 27510 |
end Validity_Checks; |
| 27511 |
|
| 27512 |
-------------- |
| 27513 |
-- Volatile -- |
| 27514 |
-------------- |
| 27515 |
|
| 27516 |
-- pragma Volatile (LOCAL_NAME); |
| 27517 |
|
| 27518 |
when Pragma_Volatile => |
| 27519 |
Process_Atomic_Independent_Shared_Volatile; |
| 27520 |
|
| 27521 |
------------------------- |
| 27522 |
-- Volatile_Components -- |
| 27523 |
------------------------- |
| 27524 |
|
| 27525 |
-- pragma Volatile_Components (array_LOCAL_NAME); |
| 27526 |
|
| 27527 |
-- Volatile is handled by the same circuit as Atomic_Components |
| 27528 |
|
| 27529 |
-------------------------- |
| 27530 |
-- Volatile_Full_Access -- |
| 27531 |
-------------------------- |
| 27532 |
|
| 27533 |
-- pragma Volatile_Full_Access (LOCAL_NAME); |
| 27534 |
|
| 27535 |
when Pragma_Volatile_Full_Access => |
| 27536 |
GNAT_Pragma; |
| 27537 |
Process_Atomic_Independent_Shared_Volatile; |
| 27538 |
|
| 27539 |
----------------------- |
| 27540 |
-- Volatile_Function -- |
| 27541 |
----------------------- |
| 27542 |
|
| 27543 |
-- pragma Volatile_Function [ (static_boolean_EXPRESSION) ]; |
| 27544 |
|
| 27545 |
when Pragma_Volatile_Function => Volatile_Function : declare |
| 27546 |
Over_Id : Entity_Id; |
| 27547 |
Spec_Id : Entity_Id; |
| 27548 |
Subp_Decl : Node_Id; |
| 27549 |
|
| 27550 |
begin |
| 27551 |
GNAT_Pragma; |
| 27552 |
Check_No_Identifiers; |
| 27553 |
Check_At_Most_N_Arguments (1); |
| 27554 |
|
| 27555 |
Subp_Decl := |
| 27556 |
Find_Related_Declaration_Or_Body (N, Do_Checks => True); |
| 27557 |
|
| 27558 |
-- Generic subprogram |
| 27559 |
|
| 27560 |
if Nkind (Subp_Decl) = N_Generic_Subprogram_Declaration then |
| 27561 |
null; |
| 27562 |
|
| 27563 |
-- Body acts as spec |
| 27564 |
|
| 27565 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body |
| 27566 |
and then No (Corresponding_Spec (Subp_Decl)) |
| 27567 |
then |
| 27568 |
null; |
| 27569 |
|
| 27570 |
-- Body stub acts as spec |
| 27571 |
|
| 27572 |
elsif Nkind (Subp_Decl) = N_Subprogram_Body_Stub |
| 27573 |
and then No (Corresponding_Spec_Of_Stub (Subp_Decl)) |
| 27574 |
then |
| 27575 |
null; |
| 27576 |
|
| 27577 |
-- Subprogram |
| 27578 |
|
| 27579 |
elsif Nkind (Subp_Decl) = N_Subprogram_Declaration then |
| 27580 |
null; |
| 27581 |
|
| 27582 |
else |
| 27583 |
Pragma_Misplaced; |
| 27584 |
end if; |
| 27585 |
|
| 27586 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 27587 |
|
| 27588 |
if Ekind (Spec_Id) not in E_Function | E_Generic_Function then |
| 27589 |
Pragma_Misplaced; |
| 27590 |
end if; |
| 27591 |
|
| 27592 |
-- A pragma that applies to a Ghost entity becomes Ghost for the |
| 27593 |
-- purposes of legality checks and removal of ignored Ghost code. |
| 27594 |
|
| 27595 |
Mark_Ghost_Pragma (N, Spec_Id); |
| 27596 |
|
| 27597 |
-- Chain the pragma on the contract for completeness |
| 27598 |
|
| 27599 |
Add_Contract_Item (N, Spec_Id); |
| 27600 |
|
| 27601 |
-- The legality checks of pragma Volatile_Function are affected by |
| 27602 |
-- the SPARK mode in effect. Analyze all pragmas in a specific |
| 27603 |
-- order. |
| 27604 |
|
| 27605 |
Analyze_If_Present (Pragma_SPARK_Mode); |
| 27606 |
|
| 27607 |
-- A volatile function cannot override a non-volatile function |
| 27608 |
-- (SPARK RM 7.1.2(15)). Overriding checks are usually performed |
| 27609 |
-- in New_Overloaded_Entity, however at that point the pragma has |
| 27610 |
-- not been processed yet. |
| 27611 |
|
| 27612 |
Over_Id := Overridden_Operation (Spec_Id); |
| 27613 |
|
| 27614 |
if Present (Over_Id) |
| 27615 |
and then not Is_Volatile_Function (Over_Id) |
| 27616 |
then |
| 27617 |
Error_Msg_N |
| 27618 |
("incompatible volatile function values in effect", Spec_Id); |
| 27619 |
|
| 27620 |
Error_Msg_Sloc := Sloc (Over_Id); |
| 27621 |
Error_Msg_N |
| 27622 |
("\& declared # with Volatile_Function value False", |
| 27623 |
Spec_Id); |
| 27624 |
|
| 27625 |
Error_Msg_Sloc := Sloc (Spec_Id); |
| 27626 |
Error_Msg_N |
| 27627 |
("\overridden # with Volatile_Function value True", |
| 27628 |
Spec_Id); |
| 27629 |
end if; |
| 27630 |
|
| 27631 |
-- Analyze the Boolean expression (if any) |
| 27632 |
|
| 27633 |
if Present (Arg1) then |
| 27634 |
Check_Static_Boolean_Expression (Get_Pragma_Arg (Arg1)); |
| 27635 |
end if; |
| 27636 |
end Volatile_Function; |
| 27637 |
|
| 27638 |
---------------------- |
| 27639 |
-- Warning_As_Error -- |
| 27640 |
---------------------- |
| 27641 |
|
| 27642 |
-- pragma Warning_As_Error (static_string_EXPRESSION); |
| 27643 |
|
| 27644 |
when Pragma_Warning_As_Error => |
| 27645 |
GNAT_Pragma; |
| 27646 |
Check_Arg_Count (1); |
| 27647 |
Check_No_Identifiers; |
| 27648 |
Check_Valid_Configuration_Pragma; |
| 27649 |
|
| 27650 |
if not Is_Static_String_Expression (Arg1) then |
| 27651 |
Error_Pragma_Arg |
| 27652 |
("argument of pragma% must be static string expression", |
| 27653 |
Arg1); |
| 27654 |
|
| 27655 |
-- OK static string expression |
| 27656 |
|
| 27657 |
else |
| 27658 |
Warnings_As_Errors_Count := Warnings_As_Errors_Count + 1; |
| 27659 |
Warnings_As_Errors (Warnings_As_Errors_Count) := |
| 27660 |
new String'(Acquire_Warning_Match_String |
| 27661 |
(Expr_Value_S (Get_Pragma_Arg (Arg1)))); |
| 27662 |
end if; |
| 27663 |
|
| 27664 |
-------------- |
| 27665 |
-- Warnings -- |
| 27666 |
-------------- |
| 27667 |
|
| 27668 |
-- pragma Warnings ([TOOL_NAME,] DETAILS [, REASON]); |
| 27669 |
|
| 27670 |
-- DETAILS ::= On | Off |
| 27671 |
-- DETAILS ::= On | Off, local_NAME |
| 27672 |
-- DETAILS ::= static_string_EXPRESSION |
| 27673 |
-- DETAILS ::= On | Off, static_string_EXPRESSION |
| 27674 |
|
| 27675 |
-- TOOL_NAME ::= GNAT | GNATprove |
| 27676 |
|
| 27677 |
-- REASON ::= Reason => STRING_LITERAL {& STRING_LITERAL} |
| 27678 |
|
| 27679 |
-- Note: If the first argument matches an allowed tool name, it is |
| 27680 |
-- always considered to be a tool name, even if there is a string |
| 27681 |
-- variable of that name. |
| 27682 |
|
| 27683 |
-- Note if the second argument of DETAILS is a local_NAME then the |
| 27684 |
-- second form is always understood. If the intention is to use |
| 27685 |
-- the fourth form, then you can write NAME & "" to force the |
| 27686 |
-- intepretation as a static_string_EXPRESSION. |
| 27687 |
|
| 27688 |
when Pragma_Warnings => Warnings : declare |
| 27689 |
Reason : String_Id; |
| 27690 |
|
| 27691 |
begin |
| 27692 |
GNAT_Pragma; |
| 27693 |
Check_At_Least_N_Arguments (1); |
| 27694 |
|
| 27695 |
-- See if last argument is labeled Reason. If so, make sure we |
| 27696 |
-- have a string literal or a concatenation of string literals, |
| 27697 |
-- and acquire the REASON string. Then remove the REASON argument |
| 27698 |
-- by decreasing Num_Args by one; Remaining processing looks only |
| 27699 |
-- at first Num_Args arguments). |
| 27700 |
|
| 27701 |
declare |
| 27702 |
Last_Arg : constant Node_Id := |
| 27703 |
Last (Pragma_Argument_Associations (N)); |
| 27704 |
|
| 27705 |
begin |
| 27706 |
if Nkind (Last_Arg) = N_Pragma_Argument_Association |
| 27707 |
and then Chars (Last_Arg) = Name_Reason |
| 27708 |
then |
| 27709 |
Start_String; |
| 27710 |
Get_Reason_String (Get_Pragma_Arg (Last_Arg)); |
| 27711 |
Reason := End_String; |
| 27712 |
Arg_Count := Arg_Count - 1; |
| 27713 |
|
| 27714 |
-- No REASON string, set null string as reason |
| 27715 |
|
| 27716 |
else |
| 27717 |
Reason := Null_String_Id; |
| 27718 |
end if; |
| 27719 |
end; |
| 27720 |
|
| 27721 |
-- Now proceed with REASON taken care of and eliminated |
| 27722 |
|
| 27723 |
Check_No_Identifiers; |
| 27724 |
|
| 27725 |
-- If debug flag -gnatd.i is set, pragma is ignored |
| 27726 |
|
| 27727 |
if Debug_Flag_Dot_I then |
| 27728 |
return; |
| 27729 |
end if; |
| 27730 |
|
| 27731 |
-- Process various forms of the pragma |
| 27732 |
|
| 27733 |
declare |
| 27734 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 27735 |
Shifted_Args : List_Id; |
| 27736 |
|
| 27737 |
begin |
| 27738 |
-- See if first argument is a tool name, currently either |
| 27739 |
-- GNAT or GNATprove. If so, either ignore the pragma if the |
| 27740 |
-- tool used does not match, or continue as if no tool name |
| 27741 |
-- was given otherwise, by shifting the arguments. |
| 27742 |
|
| 27743 |
if Nkind (Argx) = N_Identifier |
| 27744 |
and then Chars (Argx) in Name_Gnat | Name_Gnatprove |
| 27745 |
then |
| 27746 |
if Chars (Argx) = Name_Gnat then |
| 27747 |
if CodePeer_Mode or GNATprove_Mode then |
| 27748 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 27749 |
Analyze (N); |
| 27750 |
return; |
| 27751 |
end if; |
| 27752 |
|
| 27753 |
elsif Chars (Argx) = Name_Gnatprove then |
| 27754 |
if not GNATprove_Mode then |
| 27755 |
Rewrite (N, Make_Null_Statement (Loc)); |
| 27756 |
Analyze (N); |
| 27757 |
return; |
| 27758 |
end if; |
| 27759 |
else |
| 27760 |
raise Program_Error; |
| 27761 |
end if; |
| 27762 |
|
| 27763 |
-- At this point, the pragma Warnings applies to the tool, |
| 27764 |
-- so continue with shifted arguments. |
| 27765 |
|
| 27766 |
Arg_Count := Arg_Count - 1; |
| 27767 |
|
| 27768 |
if Arg_Count = 1 then |
| 27769 |
Shifted_Args := New_List (New_Copy (Arg2)); |
| 27770 |
elsif Arg_Count = 2 then |
| 27771 |
Shifted_Args := New_List (New_Copy (Arg2), |
| 27772 |
New_Copy (Arg3)); |
| 27773 |
elsif Arg_Count = 3 then |
| 27774 |
Shifted_Args := New_List (New_Copy (Arg2), |
| 27775 |
New_Copy (Arg3), |
| 27776 |
New_Copy (Arg4)); |
| 27777 |
else |
| 27778 |
raise Program_Error; |
| 27779 |
end if; |
| 27780 |
|
| 27781 |
Rewrite (N, |
| 27782 |
Make_Pragma (Loc, |
| 27783 |
Chars => Name_Warnings, |
| 27784 |
Pragma_Argument_Associations => Shifted_Args)); |
| 27785 |
Analyze (N); |
| 27786 |
return; |
| 27787 |
end if; |
| 27788 |
|
| 27789 |
-- One argument case |
| 27790 |
|
| 27791 |
if Arg_Count = 1 then |
| 27792 |
|
| 27793 |
-- On/Off one argument case was processed by parser |
| 27794 |
|
| 27795 |
if Nkind (Argx) = N_Identifier |
| 27796 |
and then Chars (Argx) in Name_On | Name_Off |
| 27797 |
then |
| 27798 |
null; |
| 27799 |
|
| 27800 |
-- One argument case must be ON/OFF or static string expr |
| 27801 |
|
| 27802 |
elsif not Is_Static_String_Expression (Arg1) then |
| 27803 |
Error_Pragma_Arg |
| 27804 |
("argument of pragma% must be On/Off or static string " |
| 27805 |
& "expression", Arg1); |
| 27806 |
|
| 27807 |
-- Use of pragma Warnings to set warning switches is |
| 27808 |
-- ignored in GNATprove mode, as these switches apply to |
| 27809 |
-- the compiler only. |
| 27810 |
|
| 27811 |
elsif GNATprove_Mode then |
| 27812 |
null; |
| 27813 |
|
| 27814 |
-- One argument string expression case |
| 27815 |
|
| 27816 |
else |
| 27817 |
declare |
| 27818 |
Lit : constant Node_Id := Expr_Value_S (Argx); |
| 27819 |
Str : constant String_Id := Strval (Lit); |
| 27820 |
Len : constant Nat := String_Length (Str); |
| 27821 |
C : Char_Code; |
| 27822 |
J : Nat; |
| 27823 |
OK : Boolean; |
| 27824 |
Chr : Character; |
| 27825 |
|
| 27826 |
begin |
| 27827 |
J := 1; |
| 27828 |
while J <= Len loop |
| 27829 |
C := Get_String_Char (Str, J); |
| 27830 |
OK := In_Character_Range (C); |
| 27831 |
|
| 27832 |
if OK then |
| 27833 |
Chr := Get_Character (C); |
| 27834 |
|
| 27835 |
-- Dash case: only -Wxxx is accepted |
| 27836 |
|
| 27837 |
if J = 1 |
| 27838 |
and then J < Len |
| 27839 |
and then Chr = '-' |
| 27840 |
then |
| 27841 |
J := J + 1; |
| 27842 |
C := Get_String_Char (Str, J); |
| 27843 |
Chr := Get_Character (C); |
| 27844 |
exit when Chr = 'W'; |
| 27845 |
OK := False; |
| 27846 |
|
| 27847 |
-- Dot case |
| 27848 |
|
| 27849 |
elsif J < Len and then Chr = '.' then |
| 27850 |
J := J + 1; |
| 27851 |
C := Get_String_Char (Str, J); |
| 27852 |
Chr := Get_Character (C); |
| 27853 |
|
| 27854 |
if not Set_Warning_Switch ('.', Chr) then |
| 27855 |
Error_Pragma_Arg |
| 27856 |
("invalid warning switch character " |
| 27857 |
& '.' & Chr, Arg1); |
| 27858 |
end if; |
| 27859 |
|
| 27860 |
-- Non-Dot case |
| 27861 |
|
| 27862 |
else |
| 27863 |
OK := Set_Warning_Switch (Plain, Chr); |
| 27864 |
end if; |
| 27865 |
|
| 27866 |
if not OK then |
| 27867 |
Error_Pragma_Arg |
| 27868 |
("invalid warning switch character " & Chr, |
| 27869 |
Arg1); |
| 27870 |
end if; |
| 27871 |
|
| 27872 |
else |
| 27873 |
Error_Pragma_Arg |
| 27874 |
("invalid wide character in warning switch ", |
| 27875 |
Arg1); |
| 27876 |
end if; |
| 27877 |
|
| 27878 |
J := J + 1; |
| 27879 |
end loop; |
| 27880 |
end; |
| 27881 |
end if; |
| 27882 |
|
| 27883 |
-- Two or more arguments (must be two) |
| 27884 |
|
| 27885 |
else |
| 27886 |
Check_Arg_Is_One_Of (Arg1, Name_On, Name_Off); |
| 27887 |
Check_Arg_Count (2); |
| 27888 |
|
| 27889 |
declare |
| 27890 |
E_Id : Node_Id; |
| 27891 |
E : Entity_Id; |
| 27892 |
Err : Boolean; |
| 27893 |
|
| 27894 |
begin |
| 27895 |
E_Id := Get_Pragma_Arg (Arg2); |
| 27896 |
Analyze (E_Id); |
| 27897 |
|
| 27898 |
-- In the expansion of an inlined body, a reference to |
| 27899 |
-- the formal may be wrapped in a conversion if the |
| 27900 |
-- actual is a conversion. Retrieve the real entity name. |
| 27901 |
|
| 27902 |
if (In_Instance_Body or In_Inlined_Body) |
| 27903 |
and then Nkind (E_Id) = N_Unchecked_Type_Conversion |
| 27904 |
then |
| 27905 |
E_Id := Expression (E_Id); |
| 27906 |
end if; |
| 27907 |
|
| 27908 |
-- Entity name case |
| 27909 |
|
| 27910 |
if Is_Entity_Name (E_Id) then |
| 27911 |
E := Entity (E_Id); |
| 27912 |
|
| 27913 |
if E = Any_Id then |
| 27914 |
return; |
| 27915 |
else |
| 27916 |
loop |
| 27917 |
Set_Warnings_Off |
| 27918 |
(E, (Chars (Get_Pragma_Arg (Arg1)) = |
| 27919 |
Name_Off)); |
| 27920 |
|
| 27921 |
-- Suppress elaboration warnings if the entity |
| 27922 |
-- denotes an elaboration target. |
| 27923 |
|
| 27924 |
if Is_Elaboration_Target (E) then |
| 27925 |
Set_Is_Elaboration_Warnings_OK_Id (E, False); |
| 27926 |
end if; |
| 27927 |
|
| 27928 |
-- For OFF case, make entry in warnings off |
| 27929 |
-- pragma table for later processing. But we do |
| 27930 |
-- not do that within an instance, since these |
| 27931 |
-- warnings are about what is needed in the |
| 27932 |
-- template, not an instance of it. |
| 27933 |
|
| 27934 |
if Chars (Get_Pragma_Arg (Arg1)) = Name_Off |
| 27935 |
and then Warn_On_Warnings_Off |
| 27936 |
and then not In_Instance |
| 27937 |
then |
| 27938 |
Warnings_Off_Pragmas.Append ((N, E, Reason)); |
| 27939 |
end if; |
| 27940 |
|
| 27941 |
if Is_Enumeration_Type (E) then |
| 27942 |
declare |
| 27943 |
Lit : Entity_Id; |
| 27944 |
begin |
| 27945 |
Lit := First_Literal (E); |
| 27946 |
while Present (Lit) loop |
| 27947 |
Set_Warnings_Off (Lit); |
| 27948 |
Next_Literal (Lit); |
| 27949 |
end loop; |
| 27950 |
end; |
| 27951 |
end if; |
| 27952 |
|
| 27953 |
exit when No (Homonym (E)); |
| 27954 |
E := Homonym (E); |
| 27955 |
end loop; |
| 27956 |
end if; |
| 27957 |
|
| 27958 |
-- Error if not entity or static string expression case |
| 27959 |
|
| 27960 |
elsif not Is_Static_String_Expression (Arg2) then |
| 27961 |
Error_Pragma_Arg |
| 27962 |
("second argument of pragma% must be entity name " |
| 27963 |
& "or static string expression", Arg2); |
| 27964 |
|
| 27965 |
-- Static string expression case |
| 27966 |
|
| 27967 |
else |
| 27968 |
-- Note on configuration pragma case: If this is a |
| 27969 |
-- configuration pragma, then for an OFF pragma, we |
| 27970 |
-- just set Config True in the call, which is all |
| 27971 |
-- that needs to be done. For the case of ON, this |
| 27972 |
-- is normally an error, unless it is canceling the |
| 27973 |
-- effect of a previous OFF pragma in the same file. |
| 27974 |
-- In any other case, an error will be signalled (ON |
| 27975 |
-- with no matching OFF). |
| 27976 |
|
| 27977 |
-- Note: We set Used if we are inside a generic to |
| 27978 |
-- disable the test that the non-config case actually |
| 27979 |
-- cancels a warning. That's because we can't be sure |
| 27980 |
-- there isn't an instantiation in some other unit |
| 27981 |
-- where a warning is suppressed. |
| 27982 |
|
| 27983 |
-- We could do a little better here by checking if the |
| 27984 |
-- generic unit we are inside is public, but for now |
| 27985 |
-- we don't bother with that refinement. |
| 27986 |
|
| 27987 |
declare |
| 27988 |
Message : constant String := |
| 27989 |
Acquire_Warning_Match_String |
| 27990 |
(Expr_Value_S (Get_Pragma_Arg (Arg2))); |
| 27991 |
begin |
| 27992 |
if Chars (Argx) = Name_Off then |
| 27993 |
Set_Specific_Warning_Off |
| 27994 |
(N, Message, Reason, |
| 27995 |
Config => Is_Configuration_Pragma, |
| 27996 |
Used => Inside_A_Generic or else In_Instance); |
| 27997 |
|
| 27998 |
elsif Chars (Argx) = Name_On then |
| 27999 |
Set_Specific_Warning_On (Loc, Message, Err); |
| 28000 |
|
| 28001 |
if Err then |
| 28002 |
Error_Msg_N |
| 28003 |
("??pragma Warnings On with no matching " |
| 28004 |
& "Warnings Off", N); |
| 28005 |
end if; |
| 28006 |
end if; |
| 28007 |
end; |
| 28008 |
end if; |
| 28009 |
end; |
| 28010 |
end if; |
| 28011 |
end; |
| 28012 |
end Warnings; |
| 28013 |
|
| 28014 |
------------------- |
| 28015 |
-- Weak_External -- |
| 28016 |
------------------- |
| 28017 |
|
| 28018 |
-- pragma Weak_External ([Entity =>] LOCAL_NAME); |
| 28019 |
|
| 28020 |
when Pragma_Weak_External => Weak_External : declare |
| 28021 |
Ent : Entity_Id; |
| 28022 |
|
| 28023 |
begin |
| 28024 |
GNAT_Pragma; |
| 28025 |
Check_Arg_Count (1); |
| 28026 |
Check_Optional_Identifier (Arg1, Name_Entity); |
| 28027 |
Check_Arg_Is_Library_Level_Local_Name (Arg1); |
| 28028 |
Ent := Entity (Get_Pragma_Arg (Arg1)); |
| 28029 |
|
| 28030 |
if Rep_Item_Too_Early (Ent, N) then |
| 28031 |
return; |
| 28032 |
else |
| 28033 |
Ent := Underlying_Type (Ent); |
| 28034 |
end if; |
| 28035 |
|
| 28036 |
-- The pragma applies to entities with addresses |
| 28037 |
|
| 28038 |
if Is_Type (Ent) then |
| 28039 |
Error_Pragma ("pragma applies to objects and subprograms"); |
| 28040 |
end if; |
| 28041 |
|
| 28042 |
-- The only processing required is to link this item on to the |
| 28043 |
-- list of rep items for the given entity. This is accomplished |
| 28044 |
-- by the call to Rep_Item_Too_Late (when no error is detected |
| 28045 |
-- and False is returned). |
| 28046 |
|
| 28047 |
if Rep_Item_Too_Late (Ent, N) then |
| 28048 |
return; |
| 28049 |
else |
| 28050 |
Set_Has_Gigi_Rep_Item (Ent); |
| 28051 |
end if; |
| 28052 |
end Weak_External; |
| 28053 |
|
| 28054 |
----------------------------- |
| 28055 |
-- Wide_Character_Encoding -- |
| 28056 |
----------------------------- |
| 28057 |
|
| 28058 |
-- pragma Wide_Character_Encoding (IDENTIFIER); |
| 28059 |
|
| 28060 |
when Pragma_Wide_Character_Encoding => |
| 28061 |
GNAT_Pragma; |
| 28062 |
|
| 28063 |
-- Nothing to do, handled in parser. Note that we do not enforce |
| 28064 |
-- configuration pragma placement, this pragma can appear at any |
| 28065 |
-- place in the source, allowing mixed encodings within a single |
| 28066 |
-- source program. |
| 28067 |
|
| 28068 |
null; |
| 28069 |
|
| 28070 |
-------------------- |
| 28071 |
-- Unknown_Pragma -- |
| 28072 |
-------------------- |
| 28073 |
|
| 28074 |
-- Should be impossible, since the case of an unknown pragma is |
| 28075 |
-- separately processed before the case statement is entered. |
| 28076 |
|
| 28077 |
when Unknown_Pragma => |
| 28078 |
raise Program_Error; |
| 28079 |
end case; |
| 28080 |
|
| 28081 |
-- AI05-0144: detect dangerous order dependence. Disabled for now, |
| 28082 |
-- until AI is formally approved. |
| 28083 |
|
| 28084 |
-- Check_Order_Dependence; |
| 28085 |
|
| 28086 |
exception |
| 28087 |
when Pragma_Exit => null; |
| 28088 |
end Analyze_Pragma; |
| 28089 |
|
| 28090 |
-------------------------------- |
| 28091 |
-- Analyze_Pragmas_If_Present -- |
| 28092 |
-------------------------------- |
| 28093 |
|
| 28094 |
procedure Analyze_Pragmas_If_Present (Decl : Node_Id; Id : Pragma_Id) is |
| 28095 |
Prag : Node_Id; |
| 28096 |
begin |
| 28097 |
if Nkind (Parent (Decl)) = N_Compilation_Unit then |
| 28098 |
Prag := First (Pragmas_After (Aux_Decls_Node (Parent (Decl)))); |
| 28099 |
else |
| 28100 |
pragma Assert (Is_List_Member (Decl)); |
| 28101 |
Prag := Next (Decl); |
| 28102 |
end if; |
| 28103 |
|
| 28104 |
if Present (Prag) then |
| 28105 |
Analyze_If_Present_Internal (Prag, Id, Included => True); |
| 28106 |
end if; |
| 28107 |
end Analyze_Pragmas_If_Present; |
| 28108 |
|
| 28109 |
--------------------------------------------- |
| 28110 |
-- Analyze_Pre_Post_Condition_In_Decl_Part -- |
| 28111 |
--------------------------------------------- |
| 28112 |
|
| 28113 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 28114 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 28115 |
-- Ghost mode. |
| 28116 |
|
| 28117 |
procedure Analyze_Pre_Post_Condition_In_Decl_Part |
| 28118 |
(N : Node_Id; |
| 28119 |
Freeze_Id : Entity_Id := Empty) |
| 28120 |
is |
| 28121 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 28122 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 28123 |
|
| 28124 |
Disp_Typ : Entity_Id; |
| 28125 |
-- The dispatching type of the subprogram subject to the pre- or |
| 28126 |
-- postcondition. |
| 28127 |
|
| 28128 |
function Check_References (Nod : Node_Id) return Traverse_Result; |
| 28129 |
-- Check that expression Nod does not mention non-primitives of the |
| 28130 |
-- type, global objects of the type, or other illegalities described |
| 28131 |
-- and implied by AI12-0113. |
| 28132 |
|
| 28133 |
---------------------- |
| 28134 |
-- Check_References -- |
| 28135 |
---------------------- |
| 28136 |
|
| 28137 |
function Check_References (Nod : Node_Id) return Traverse_Result is |
| 28138 |
begin |
| 28139 |
if Nkind (Nod) = N_Function_Call |
| 28140 |
and then Is_Entity_Name (Name (Nod)) |
| 28141 |
then |
| 28142 |
declare |
| 28143 |
Func : constant Entity_Id := Entity (Name (Nod)); |
| 28144 |
Form : Entity_Id; |
| 28145 |
|
| 28146 |
begin |
| 28147 |
-- An operation of the type must be a primitive |
| 28148 |
|
| 28149 |
if No (Find_Dispatching_Type (Func)) then |
| 28150 |
Form := First_Formal (Func); |
| 28151 |
while Present (Form) loop |
| 28152 |
if Etype (Form) = Disp_Typ then |
| 28153 |
Error_Msg_NE |
| 28154 |
("operation in class-wide condition must be " |
| 28155 |
& "primitive of &", Nod, Disp_Typ); |
| 28156 |
end if; |
| 28157 |
|
| 28158 |
Next_Formal (Form); |
| 28159 |
end loop; |
| 28160 |
|
| 28161 |
-- A return object of the type is illegal as well |
| 28162 |
|
| 28163 |
if Etype (Func) = Disp_Typ |
| 28164 |
or else Etype (Func) = Class_Wide_Type (Disp_Typ) |
| 28165 |
then |
| 28166 |
Error_Msg_NE |
| 28167 |
("operation in class-wide condition must be primitive " |
| 28168 |
& "of &", Nod, Disp_Typ); |
| 28169 |
end if; |
| 28170 |
end if; |
| 28171 |
end; |
| 28172 |
|
| 28173 |
elsif Is_Entity_Name (Nod) |
| 28174 |
and then |
| 28175 |
(Etype (Nod) = Disp_Typ |
| 28176 |
or else Etype (Nod) = Class_Wide_Type (Disp_Typ)) |
| 28177 |
and then Ekind (Entity (Nod)) in E_Constant | E_Variable |
| 28178 |
then |
| 28179 |
Error_Msg_NE |
| 28180 |
("object in class-wide condition must be formal of type &", |
| 28181 |
Nod, Disp_Typ); |
| 28182 |
|
| 28183 |
elsif Nkind (Nod) = N_Explicit_Dereference |
| 28184 |
and then (Etype (Nod) = Disp_Typ |
| 28185 |
or else Etype (Nod) = Class_Wide_Type (Disp_Typ)) |
| 28186 |
and then (not Is_Entity_Name (Prefix (Nod)) |
| 28187 |
or else not Is_Formal (Entity (Prefix (Nod)))) |
| 28188 |
then |
| 28189 |
Error_Msg_NE |
| 28190 |
("operation in class-wide condition must be primitive of &", |
| 28191 |
Nod, Disp_Typ); |
| 28192 |
end if; |
| 28193 |
|
| 28194 |
return OK; |
| 28195 |
end Check_References; |
| 28196 |
|
| 28197 |
procedure Check_Class_Wide_Condition is |
| 28198 |
new Traverse_Proc (Check_References); |
| 28199 |
|
| 28200 |
-- Local variables |
| 28201 |
|
| 28202 |
Expr : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
| 28203 |
|
| 28204 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 28205 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 28206 |
-- Save the Ghost-related attributes to restore on exit |
| 28207 |
|
| 28208 |
Errors : Nat; |
| 28209 |
Restore_Scope : Boolean := False; |
| 28210 |
|
| 28211 |
-- Start of processing for Analyze_Pre_Post_Condition_In_Decl_Part |
| 28212 |
|
| 28213 |
begin |
| 28214 |
-- Do not analyze the pragma multiple times |
| 28215 |
|
| 28216 |
if Is_Analyzed_Pragma (N) then |
| 28217 |
return; |
| 28218 |
end if; |
| 28219 |
|
| 28220 |
-- Set the Ghost mode in effect from the pragma. Due to the delayed |
| 28221 |
-- analysis of the pragma, the Ghost mode at point of declaration and |
| 28222 |
-- point of analysis may not necessarily be the same. Use the mode in |
| 28223 |
-- effect at the point of declaration. |
| 28224 |
|
| 28225 |
Set_Ghost_Mode (N); |
| 28226 |
|
| 28227 |
-- Ensure that the subprogram and its formals are visible when analyzing |
| 28228 |
-- the expression of the pragma. |
| 28229 |
|
| 28230 |
if not In_Open_Scopes (Spec_Id) then |
| 28231 |
Restore_Scope := True; |
| 28232 |
|
| 28233 |
if Is_Generic_Subprogram (Spec_Id) then |
| 28234 |
Push_Scope (Spec_Id); |
| 28235 |
Install_Generic_Formals (Spec_Id); |
| 28236 |
elsif Is_Access_Subprogram_Type (Spec_Id) then |
| 28237 |
Push_Scope (Designated_Type (Spec_Id)); |
| 28238 |
Install_Formals (Designated_Type (Spec_Id)); |
| 28239 |
else |
| 28240 |
Push_Scope (Spec_Id); |
| 28241 |
Install_Formals (Spec_Id); |
| 28242 |
end if; |
| 28243 |
end if; |
| 28244 |
|
| 28245 |
Errors := Serious_Errors_Detected; |
| 28246 |
Preanalyze_Assert_Expression (Expr, Standard_Boolean); |
| 28247 |
|
| 28248 |
-- Emit a clarification message when the expression contains at least |
| 28249 |
-- one undefined reference, possibly due to contract freezing. |
| 28250 |
|
| 28251 |
if Errors /= Serious_Errors_Detected |
| 28252 |
and then Present (Freeze_Id) |
| 28253 |
and then Has_Undefined_Reference (Expr) |
| 28254 |
then |
| 28255 |
Contract_Freeze_Error (Spec_Id, Freeze_Id); |
| 28256 |
end if; |
| 28257 |
|
| 28258 |
if Class_Present (N) then |
| 28259 |
|
| 28260 |
-- Verify that a class-wide condition is legal, i.e. the operation is |
| 28261 |
-- a primitive of a tagged type. |
| 28262 |
|
| 28263 |
if not Is_Dispatching_Operation (Spec_Id) then |
| 28264 |
Error_Msg_Name_1 := Original_Aspect_Pragma_Name (N); |
| 28265 |
|
| 28266 |
if From_Aspect_Specification (N) then |
| 28267 |
Error_Msg_N |
| 28268 |
("aspect % can only be specified for a primitive operation " |
| 28269 |
& "of a tagged type", Corresponding_Aspect (N)); |
| 28270 |
|
| 28271 |
-- The pragma is a source construct |
| 28272 |
|
| 28273 |
else |
| 28274 |
Error_Msg_N |
| 28275 |
("pragma % can only be specified for a primitive operation " |
| 28276 |
& "of a tagged type", N); |
| 28277 |
end if; |
| 28278 |
|
| 28279 |
-- Remaining semantic checks require a full tree traversal |
| 28280 |
|
| 28281 |
else |
| 28282 |
Disp_Typ := Find_Dispatching_Type (Spec_Id); |
| 28283 |
Check_Class_Wide_Condition (Expr); |
| 28284 |
end if; |
| 28285 |
|
| 28286 |
end if; |
| 28287 |
|
| 28288 |
if Restore_Scope then |
| 28289 |
End_Scope; |
| 28290 |
end if; |
| 28291 |
|
| 28292 |
-- Currently it is not possible to inline pre/postconditions on a |
| 28293 |
-- subprogram subject to pragma Inline_Always. |
| 28294 |
|
| 28295 |
Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); |
| 28296 |
Set_Is_Analyzed_Pragma (N); |
| 28297 |
|
| 28298 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 28299 |
end Analyze_Pre_Post_Condition_In_Decl_Part; |
| 28300 |
|
| 28301 |
------------------------------------------ |
| 28302 |
-- Analyze_Refined_Depends_In_Decl_Part -- |
| 28303 |
------------------------------------------ |
| 28304 |
|
| 28305 |
procedure Analyze_Refined_Depends_In_Decl_Part (N : Node_Id) is |
| 28306 |
procedure Check_Dependency_Clause |
| 28307 |
(Spec_Id : Entity_Id; |
| 28308 |
Dep_Clause : Node_Id; |
| 28309 |
Dep_States : Elist_Id; |
| 28310 |
Refinements : List_Id; |
| 28311 |
Matched_Items : in out Elist_Id); |
| 28312 |
-- Try to match a single dependency clause Dep_Clause against one or |
| 28313 |
-- more refinement clauses found in list Refinements. Each successful |
| 28314 |
-- match eliminates at least one refinement clause from Refinements. |
| 28315 |
-- Spec_Id denotes the entity of the related subprogram. Dep_States |
| 28316 |
-- denotes the entities of all abstract states which appear in pragma |
| 28317 |
-- Depends. Matched_Items contains the entities of all successfully |
| 28318 |
-- matched items found in pragma Depends. |
| 28319 |
|
| 28320 |
procedure Check_Output_States |
| 28321 |
(Spec_Inputs : Elist_Id; |
| 28322 |
Spec_Outputs : Elist_Id; |
| 28323 |
Body_Inputs : Elist_Id; |
| 28324 |
Body_Outputs : Elist_Id); |
| 28325 |
-- Determine whether pragma Depends contains an output state with a |
| 28326 |
-- visible refinement and if so, ensure that pragma Refined_Depends |
| 28327 |
-- mentions all its constituents as outputs. Spec_Inputs and |
| 28328 |
-- Spec_Outputs denote the inputs and outputs of the subprogram spec |
| 28329 |
-- synthesized from pragma Depends. Body_Inputs and Body_Outputs denote |
| 28330 |
-- the inputs and outputs of the subprogram body synthesized from pragma |
| 28331 |
-- Refined_Depends. |
| 28332 |
|
| 28333 |
function Collect_States (Clauses : List_Id) return Elist_Id; |
| 28334 |
-- Given a normalized list of dependencies obtained from calling |
| 28335 |
-- Normalize_Clauses, return a list containing the entities of all |
| 28336 |
-- states appearing in dependencies. It helps in checking refinements |
| 28337 |
-- involving a state and a corresponding constituent which is not a |
| 28338 |
-- direct constituent of the state. |
| 28339 |
|
| 28340 |
procedure Normalize_Clauses (Clauses : List_Id); |
| 28341 |
-- Given a list of dependence or refinement clauses Clauses, normalize |
| 28342 |
-- each clause by creating multiple dependencies with exactly one input |
| 28343 |
-- and one output. |
| 28344 |
|
| 28345 |
procedure Remove_Extra_Clauses |
| 28346 |
(Clauses : List_Id; |
| 28347 |
Matched_Items : Elist_Id); |
| 28348 |
-- Given a list of refinement clauses Clauses, remove all clauses whose |
| 28349 |
-- inputs and/or outputs have been previously matched. See the body for |
| 28350 |
-- all special cases. Matched_Items contains the entities of all matched |
| 28351 |
-- items found in pragma Depends. |
| 28352 |
|
| 28353 |
procedure Report_Extra_Clauses (Clauses : List_Id); |
| 28354 |
-- Emit an error for each extra clause found in list Clauses |
| 28355 |
|
| 28356 |
----------------------------- |
| 28357 |
-- Check_Dependency_Clause -- |
| 28358 |
----------------------------- |
| 28359 |
|
| 28360 |
procedure Check_Dependency_Clause |
| 28361 |
(Spec_Id : Entity_Id; |
| 28362 |
Dep_Clause : Node_Id; |
| 28363 |
Dep_States : Elist_Id; |
| 28364 |
Refinements : List_Id; |
| 28365 |
Matched_Items : in out Elist_Id) |
| 28366 |
is |
| 28367 |
Dep_Input : constant Node_Id := Expression (Dep_Clause); |
| 28368 |
Dep_Output : constant Node_Id := First (Choices (Dep_Clause)); |
| 28369 |
|
| 28370 |
function Is_Already_Matched (Dep_Item : Node_Id) return Boolean; |
| 28371 |
-- Determine whether dependency item Dep_Item has been matched in a |
| 28372 |
-- previous clause. |
| 28373 |
|
| 28374 |
function Is_In_Out_State_Clause return Boolean; |
| 28375 |
-- Determine whether dependence clause Dep_Clause denotes an abstract |
| 28376 |
-- state that depends on itself (State => State). |
| 28377 |
|
| 28378 |
function Is_Null_Refined_State (Item : Node_Id) return Boolean; |
| 28379 |
-- Determine whether item Item denotes an abstract state with visible |
| 28380 |
-- null refinement. |
| 28381 |
|
| 28382 |
procedure Match_Items |
| 28383 |
(Dep_Item : Node_Id; |
| 28384 |
Ref_Item : Node_Id; |
| 28385 |
Matched : out Boolean); |
| 28386 |
-- Try to match dependence item Dep_Item against refinement item |
| 28387 |
-- Ref_Item. To match against a possible null refinement (see 2, 9), |
| 28388 |
-- set Ref_Item to Empty. Flag Matched is set to True when one of |
| 28389 |
-- the following conformance scenarios is in effect: |
| 28390 |
-- 1) Both items denote null |
| 28391 |
-- 2) Dep_Item denotes null and Ref_Item is Empty (special case) |
| 28392 |
-- 3) Both items denote attribute 'Result |
| 28393 |
-- 4) Both items denote the same object |
| 28394 |
-- 5) Both items denote the same formal parameter |
| 28395 |
-- 6) Both items denote the same current instance of a type |
| 28396 |
-- 7) Both items denote the same discriminant |
| 28397 |
-- 8) Dep_Item is an abstract state with visible null refinement |
| 28398 |
-- and Ref_Item denotes null. |
| 28399 |
-- 9) Dep_Item is an abstract state with visible null refinement |
| 28400 |
-- and Ref_Item is Empty (special case). |
| 28401 |
-- 10) Dep_Item is an abstract state with full or partial visible |
| 28402 |
-- non-null refinement and Ref_Item denotes one of its |
| 28403 |
-- constituents. |
| 28404 |
-- 11) Dep_Item is an abstract state without a full visible |
| 28405 |
-- refinement and Ref_Item denotes the same state. |
| 28406 |
-- When scenario 10 is in effect, the entity of the abstract state |
| 28407 |
-- denoted by Dep_Item is added to list Refined_States. |
| 28408 |
|
| 28409 |
procedure Record_Item (Item_Id : Entity_Id); |
| 28410 |
-- Store the entity of an item denoted by Item_Id in Matched_Items |
| 28411 |
|
| 28412 |
------------------------ |
| 28413 |
-- Is_Already_Matched -- |
| 28414 |
------------------------ |
| 28415 |
|
| 28416 |
function Is_Already_Matched (Dep_Item : Node_Id) return Boolean is |
| 28417 |
Item_Id : Entity_Id := Empty; |
| 28418 |
|
| 28419 |
begin |
| 28420 |
-- When the dependency item denotes attribute 'Result, check for |
| 28421 |
-- the entity of the related subprogram. |
| 28422 |
|
| 28423 |
if Is_Attribute_Result (Dep_Item) then |
| 28424 |
Item_Id := Spec_Id; |
| 28425 |
|
| 28426 |
elsif Is_Entity_Name (Dep_Item) then |
| 28427 |
Item_Id := Available_View (Entity_Of (Dep_Item)); |
| 28428 |
end if; |
| 28429 |
|
| 28430 |
return |
| 28431 |
Present (Item_Id) and then Contains (Matched_Items, Item_Id); |
| 28432 |
end Is_Already_Matched; |
| 28433 |
|
| 28434 |
---------------------------- |
| 28435 |
-- Is_In_Out_State_Clause -- |
| 28436 |
---------------------------- |
| 28437 |
|
| 28438 |
function Is_In_Out_State_Clause return Boolean is |
| 28439 |
Dep_Input_Id : Entity_Id; |
| 28440 |
Dep_Output_Id : Entity_Id; |
| 28441 |
|
| 28442 |
begin |
| 28443 |
-- Detect the following clause: |
| 28444 |
-- State => State |
| 28445 |
|
| 28446 |
if Is_Entity_Name (Dep_Input) |
| 28447 |
and then Is_Entity_Name (Dep_Output) |
| 28448 |
then |
| 28449 |
-- Handle abstract views generated for limited with clauses |
| 28450 |
|
| 28451 |
Dep_Input_Id := Available_View (Entity_Of (Dep_Input)); |
| 28452 |
Dep_Output_Id := Available_View (Entity_Of (Dep_Output)); |
| 28453 |
|
| 28454 |
return |
| 28455 |
Ekind (Dep_Input_Id) = E_Abstract_State |
| 28456 |
and then Dep_Input_Id = Dep_Output_Id; |
| 28457 |
else |
| 28458 |
return False; |
| 28459 |
end if; |
| 28460 |
end Is_In_Out_State_Clause; |
| 28461 |
|
| 28462 |
--------------------------- |
| 28463 |
-- Is_Null_Refined_State -- |
| 28464 |
--------------------------- |
| 28465 |
|
| 28466 |
function Is_Null_Refined_State (Item : Node_Id) return Boolean is |
| 28467 |
Item_Id : Entity_Id; |
| 28468 |
|
| 28469 |
begin |
| 28470 |
if Is_Entity_Name (Item) then |
| 28471 |
|
| 28472 |
-- Handle abstract views generated for limited with clauses |
| 28473 |
|
| 28474 |
Item_Id := Available_View (Entity_Of (Item)); |
| 28475 |
|
| 28476 |
return |
| 28477 |
Ekind (Item_Id) = E_Abstract_State |
| 28478 |
and then Has_Null_Visible_Refinement (Item_Id); |
| 28479 |
else |
| 28480 |
return False; |
| 28481 |
end if; |
| 28482 |
end Is_Null_Refined_State; |
| 28483 |
|
| 28484 |
----------------- |
| 28485 |
-- Match_Items -- |
| 28486 |
----------------- |
| 28487 |
|
| 28488 |
procedure Match_Items |
| 28489 |
(Dep_Item : Node_Id; |
| 28490 |
Ref_Item : Node_Id; |
| 28491 |
Matched : out Boolean) |
| 28492 |
is |
| 28493 |
Dep_Item_Id : Entity_Id; |
| 28494 |
Ref_Item_Id : Entity_Id; |
| 28495 |
|
| 28496 |
begin |
| 28497 |
-- Assume that the two items do not match |
| 28498 |
|
| 28499 |
Matched := False; |
| 28500 |
|
| 28501 |
-- A null matches null or Empty (special case) |
| 28502 |
|
| 28503 |
if Nkind (Dep_Item) = N_Null |
| 28504 |
and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null) |
| 28505 |
then |
| 28506 |
Matched := True; |
| 28507 |
|
| 28508 |
-- Attribute 'Result matches attribute 'Result |
| 28509 |
|
| 28510 |
elsif Is_Attribute_Result (Dep_Item) |
| 28511 |
and then Is_Attribute_Result (Ref_Item) |
| 28512 |
then |
| 28513 |
-- Put the entity of the related function on the list of |
| 28514 |
-- matched items because attribute 'Result does not carry |
| 28515 |
-- an entity similar to states and constituents. |
| 28516 |
|
| 28517 |
Record_Item (Spec_Id); |
| 28518 |
Matched := True; |
| 28519 |
|
| 28520 |
-- Abstract states, current instances of concurrent types, |
| 28521 |
-- discriminants, formal parameters and objects. |
| 28522 |
|
| 28523 |
elsif Is_Entity_Name (Dep_Item) then |
| 28524 |
|
| 28525 |
-- Handle abstract views generated for limited with clauses |
| 28526 |
|
| 28527 |
Dep_Item_Id := Available_View (Entity_Of (Dep_Item)); |
| 28528 |
|
| 28529 |
if Ekind (Dep_Item_Id) = E_Abstract_State then |
| 28530 |
|
| 28531 |
-- An abstract state with visible null refinement matches |
| 28532 |
-- null or Empty (special case). |
| 28533 |
|
| 28534 |
if Has_Null_Visible_Refinement (Dep_Item_Id) |
| 28535 |
and then (No (Ref_Item) or else Nkind (Ref_Item) = N_Null) |
| 28536 |
then |
| 28537 |
Record_Item (Dep_Item_Id); |
| 28538 |
Matched := True; |
| 28539 |
|
| 28540 |
-- An abstract state with visible non-null refinement |
| 28541 |
-- matches one of its constituents, or itself for an |
| 28542 |
-- abstract state with partial visible refinement. |
| 28543 |
|
| 28544 |
elsif Has_Non_Null_Visible_Refinement (Dep_Item_Id) then |
| 28545 |
if Is_Entity_Name (Ref_Item) then |
| 28546 |
Ref_Item_Id := Entity_Of (Ref_Item); |
| 28547 |
|
| 28548 |
if Ekind (Ref_Item_Id) in |
| 28549 |
E_Abstract_State | E_Constant | E_Variable |
| 28550 |
and then Present (Encapsulating_State (Ref_Item_Id)) |
| 28551 |
and then Find_Encapsulating_State |
| 28552 |
(Dep_States, Ref_Item_Id) = Dep_Item_Id |
| 28553 |
then |
| 28554 |
Record_Item (Dep_Item_Id); |
| 28555 |
Matched := True; |
| 28556 |
|
| 28557 |
elsif not Has_Visible_Refinement (Dep_Item_Id) |
| 28558 |
and then Ref_Item_Id = Dep_Item_Id |
| 28559 |
then |
| 28560 |
Record_Item (Dep_Item_Id); |
| 28561 |
Matched := True; |
| 28562 |
end if; |
| 28563 |
end if; |
| 28564 |
|
| 28565 |
-- An abstract state without a visible refinement matches |
| 28566 |
-- itself. |
| 28567 |
|
| 28568 |
elsif Is_Entity_Name (Ref_Item) |
| 28569 |
and then Entity_Of (Ref_Item) = Dep_Item_Id |
| 28570 |
then |
| 28571 |
Record_Item (Dep_Item_Id); |
| 28572 |
Matched := True; |
| 28573 |
end if; |
| 28574 |
|
| 28575 |
-- A current instance of a concurrent type, discriminant, |
| 28576 |
-- formal parameter or an object matches itself. |
| 28577 |
|
| 28578 |
elsif Is_Entity_Name (Ref_Item) |
| 28579 |
and then Entity_Of (Ref_Item) = Dep_Item_Id |
| 28580 |
then |
| 28581 |
Record_Item (Dep_Item_Id); |
| 28582 |
Matched := True; |
| 28583 |
end if; |
| 28584 |
end if; |
| 28585 |
end Match_Items; |
| 28586 |
|
| 28587 |
----------------- |
| 28588 |
-- Record_Item -- |
| 28589 |
----------------- |
| 28590 |
|
| 28591 |
procedure Record_Item (Item_Id : Entity_Id) is |
| 28592 |
begin |
| 28593 |
if No (Matched_Items) then |
| 28594 |
Matched_Items := New_Elmt_List; |
| 28595 |
end if; |
| 28596 |
|
| 28597 |
Append_Unique_Elmt (Item_Id, Matched_Items); |
| 28598 |
end Record_Item; |
| 28599 |
|
| 28600 |
-- Local variables |
| 28601 |
|
| 28602 |
Clause_Matched : Boolean := False; |
| 28603 |
Dummy : Boolean := False; |
| 28604 |
Inputs_Match : Boolean; |
| 28605 |
Next_Ref_Clause : Node_Id; |
| 28606 |
Outputs_Match : Boolean; |
| 28607 |
Ref_Clause : Node_Id; |
| 28608 |
Ref_Input : Node_Id; |
| 28609 |
Ref_Output : Node_Id; |
| 28610 |
|
| 28611 |
-- Start of processing for Check_Dependency_Clause |
| 28612 |
|
| 28613 |
begin |
| 28614 |
-- Examine all refinement clauses and compare them against the |
| 28615 |
-- dependence clause. |
| 28616 |
|
| 28617 |
Ref_Clause := First (Refinements); |
| 28618 |
while Present (Ref_Clause) loop |
| 28619 |
Next_Ref_Clause := Next (Ref_Clause); |
| 28620 |
|
| 28621 |
-- Obtain the attributes of the current refinement clause |
| 28622 |
|
| 28623 |
Ref_Input := Expression (Ref_Clause); |
| 28624 |
Ref_Output := First (Choices (Ref_Clause)); |
| 28625 |
|
| 28626 |
-- The current refinement clause matches the dependence clause |
| 28627 |
-- when both outputs match and both inputs match. See routine |
| 28628 |
-- Match_Items for all possible conformance scenarios. |
| 28629 |
|
| 28630 |
-- Depends Dep_Output => Dep_Input |
| 28631 |
-- ^ ^ |
| 28632 |
-- match ? match ? |
| 28633 |
-- v v |
| 28634 |
-- Refined_Depends Ref_Output => Ref_Input |
| 28635 |
|
| 28636 |
Match_Items |
| 28637 |
(Dep_Item => Dep_Input, |
| 28638 |
Ref_Item => Ref_Input, |
| 28639 |
Matched => Inputs_Match); |
| 28640 |
|
| 28641 |
Match_Items |
| 28642 |
(Dep_Item => Dep_Output, |
| 28643 |
Ref_Item => Ref_Output, |
| 28644 |
Matched => Outputs_Match); |
| 28645 |
|
| 28646 |
-- An In_Out state clause may be matched against a refinement with |
| 28647 |
-- a null input or null output as long as the non-null side of the |
| 28648 |
-- relation contains a valid constituent of the In_Out_State. |
| 28649 |
|
| 28650 |
if Is_In_Out_State_Clause then |
| 28651 |
|
| 28652 |
-- Depends => (State => State) |
| 28653 |
-- Refined_Depends => (null => Constit) -- OK |
| 28654 |
|
| 28655 |
if Inputs_Match |
| 28656 |
and then not Outputs_Match |
| 28657 |
and then Nkind (Ref_Output) = N_Null |
| 28658 |
then |
| 28659 |
Outputs_Match := True; |
| 28660 |
end if; |
| 28661 |
|
| 28662 |
-- Depends => (State => State) |
| 28663 |
-- Refined_Depends => (Constit => null) -- OK |
| 28664 |
|
| 28665 |
if not Inputs_Match |
| 28666 |
and then Outputs_Match |
| 28667 |
and then Nkind (Ref_Input) = N_Null |
| 28668 |
then |
| 28669 |
Inputs_Match := True; |
| 28670 |
end if; |
| 28671 |
end if; |
| 28672 |
|
| 28673 |
-- The current refinement clause is legally constructed following |
| 28674 |
-- the rules in SPARK RM 7.2.5, therefore it can be removed from |
| 28675 |
-- the pool of candidates. The search continues because a single |
| 28676 |
-- dependence clause may have multiple matching refinements. |
| 28677 |
|
| 28678 |
if Inputs_Match and Outputs_Match then |
| 28679 |
Clause_Matched := True; |
| 28680 |
Remove (Ref_Clause); |
| 28681 |
end if; |
| 28682 |
|
| 28683 |
Ref_Clause := Next_Ref_Clause; |
| 28684 |
end loop; |
| 28685 |
|
| 28686 |
-- Depending on the order or composition of refinement clauses, an |
| 28687 |
-- In_Out state clause may not be directly refinable. |
| 28688 |
|
| 28689 |
-- Refined_State => (State => (Constit_1, Constit_2)) |
| 28690 |
-- Depends => ((Output, State) => (Input, State)) |
| 28691 |
-- Refined_Depends => (Constit_1 => Input, Output => Constit_2) |
| 28692 |
|
| 28693 |
-- Matching normalized clause (State => State) fails because there is |
| 28694 |
-- no direct refinement capable of satisfying this relation. Another |
| 28695 |
-- similar case arises when clauses (Constit_1 => Input) and (Output |
| 28696 |
-- => Constit_2) are matched first, leaving no candidates for clause |
| 28697 |
-- (State => State). Both scenarios are legal as long as one of the |
| 28698 |
-- previous clauses mentioned a valid constituent of State. |
| 28699 |
|
| 28700 |
if not Clause_Matched |
| 28701 |
and then Is_In_Out_State_Clause |
| 28702 |
and then Is_Already_Matched (Dep_Input) |
| 28703 |
then |
| 28704 |
Clause_Matched := True; |
| 28705 |
end if; |
| 28706 |
|
| 28707 |
-- A clause where the input is an abstract state with visible null |
| 28708 |
-- refinement or a 'Result attribute is implicitly matched when the |
| 28709 |
-- output has already been matched in a previous clause. |
| 28710 |
|
| 28711 |
-- Refined_State => (State => null) |
| 28712 |
-- Depends => (Output => State) -- implicitly OK |
| 28713 |
-- Refined_Depends => (Output => ...) |
| 28714 |
-- Depends => (...'Result => State) -- implicitly OK |
| 28715 |
-- Refined_Depends => (...'Result => ...) |
| 28716 |
|
| 28717 |
if not Clause_Matched |
| 28718 |
and then Is_Null_Refined_State (Dep_Input) |
| 28719 |
and then Is_Already_Matched (Dep_Output) |
| 28720 |
then |
| 28721 |
Clause_Matched := True; |
| 28722 |
end if; |
| 28723 |
|
| 28724 |
-- A clause where the output is an abstract state with visible null |
| 28725 |
-- refinement is implicitly matched when the input has already been |
| 28726 |
-- matched in a previous clause. |
| 28727 |
|
| 28728 |
-- Refined_State => (State => null) |
| 28729 |
-- Depends => (State => Input) -- implicitly OK |
| 28730 |
-- Refined_Depends => (... => Input) |
| 28731 |
|
| 28732 |
if not Clause_Matched |
| 28733 |
and then Is_Null_Refined_State (Dep_Output) |
| 28734 |
and then Is_Already_Matched (Dep_Input) |
| 28735 |
then |
| 28736 |
Clause_Matched := True; |
| 28737 |
end if; |
| 28738 |
|
| 28739 |
-- At this point either all refinement clauses have been examined or |
| 28740 |
-- pragma Refined_Depends contains a solitary null. Only an abstract |
| 28741 |
-- state with null refinement can possibly match these cases. |
| 28742 |
|
| 28743 |
-- Refined_State => (State => null) |
| 28744 |
-- Depends => (State => null) |
| 28745 |
-- Refined_Depends => null -- OK |
| 28746 |
|
| 28747 |
if not Clause_Matched then |
| 28748 |
Match_Items |
| 28749 |
(Dep_Item => Dep_Input, |
| 28750 |
Ref_Item => Empty, |
| 28751 |
Matched => Inputs_Match); |
| 28752 |
|
| 28753 |
Match_Items |
| 28754 |
(Dep_Item => Dep_Output, |
| 28755 |
Ref_Item => Empty, |
| 28756 |
Matched => Outputs_Match); |
| 28757 |
|
| 28758 |
Clause_Matched := Inputs_Match and Outputs_Match; |
| 28759 |
end if; |
| 28760 |
|
| 28761 |
-- If the contents of Refined_Depends are legal, then the current |
| 28762 |
-- dependence clause should be satisfied either by an explicit match |
| 28763 |
-- or by one of the special cases. |
| 28764 |
|
| 28765 |
if not Clause_Matched then |
| 28766 |
SPARK_Msg_NE |
| 28767 |
(Fix_Msg (Spec_Id, "dependence clause of subprogram & has no " |
| 28768 |
& "matching refinement in body"), Dep_Clause, Spec_Id); |
| 28769 |
end if; |
| 28770 |
end Check_Dependency_Clause; |
| 28771 |
|
| 28772 |
------------------------- |
| 28773 |
-- Check_Output_States -- |
| 28774 |
------------------------- |
| 28775 |
|
| 28776 |
procedure Check_Output_States |
| 28777 |
(Spec_Inputs : Elist_Id; |
| 28778 |
Spec_Outputs : Elist_Id; |
| 28779 |
Body_Inputs : Elist_Id; |
| 28780 |
Body_Outputs : Elist_Id) |
| 28781 |
is |
| 28782 |
procedure Check_Constituent_Usage (State_Id : Entity_Id); |
| 28783 |
-- Determine whether all constituents of state State_Id with full |
| 28784 |
-- visible refinement are used as outputs in pragma Refined_Depends. |
| 28785 |
-- Emit an error if this is not the case (SPARK RM 7.2.4(5)). |
| 28786 |
|
| 28787 |
----------------------------- |
| 28788 |
-- Check_Constituent_Usage -- |
| 28789 |
----------------------------- |
| 28790 |
|
| 28791 |
procedure Check_Constituent_Usage (State_Id : Entity_Id) is |
| 28792 |
Constits : constant Elist_Id := |
| 28793 |
Partial_Refinement_Constituents (State_Id); |
| 28794 |
Constit_Elmt : Elmt_Id; |
| 28795 |
Constit_Id : Entity_Id; |
| 28796 |
Only_Partial : constant Boolean := |
| 28797 |
not Has_Visible_Refinement (State_Id); |
| 28798 |
Posted : Boolean := False; |
| 28799 |
|
| 28800 |
begin |
| 28801 |
if Present (Constits) then |
| 28802 |
Constit_Elmt := First_Elmt (Constits); |
| 28803 |
while Present (Constit_Elmt) loop |
| 28804 |
Constit_Id := Node (Constit_Elmt); |
| 28805 |
|
| 28806 |
-- Issue an error when a constituent of State_Id is used, |
| 28807 |
-- and State_Id has only partial visible refinement |
| 28808 |
-- (SPARK RM 7.2.4(3d)). |
| 28809 |
|
| 28810 |
if Only_Partial then |
| 28811 |
if (Present (Body_Inputs) |
| 28812 |
and then Appears_In (Body_Inputs, Constit_Id)) |
| 28813 |
or else |
| 28814 |
(Present (Body_Outputs) |
| 28815 |
and then Appears_In (Body_Outputs, Constit_Id)) |
| 28816 |
then |
| 28817 |
Error_Msg_Name_1 := Chars (State_Id); |
| 28818 |
SPARK_Msg_NE |
| 28819 |
("constituent & of state % cannot be used in " |
| 28820 |
& "dependence refinement", N, Constit_Id); |
| 28821 |
Error_Msg_Name_1 := Chars (State_Id); |
| 28822 |
SPARK_Msg_N ("\use state % instead", N); |
| 28823 |
end if; |
| 28824 |
|
| 28825 |
-- The constituent acts as an input (SPARK RM 7.2.5(3)) |
| 28826 |
|
| 28827 |
elsif Present (Body_Inputs) |
| 28828 |
and then Appears_In (Body_Inputs, Constit_Id) |
| 28829 |
then |
| 28830 |
Error_Msg_Name_1 := Chars (State_Id); |
| 28831 |
SPARK_Msg_NE |
| 28832 |
("constituent & of state % must act as output in " |
| 28833 |
& "dependence refinement", N, Constit_Id); |
| 28834 |
|
| 28835 |
-- The constituent is altogether missing (SPARK RM 7.2.5(3)) |
| 28836 |
|
| 28837 |
elsif No (Body_Outputs) |
| 28838 |
or else not Appears_In (Body_Outputs, Constit_Id) |
| 28839 |
then |
| 28840 |
if not Posted then |
| 28841 |
Posted := True; |
| 28842 |
SPARK_Msg_NE |
| 28843 |
("output state & must be replaced by all its " |
| 28844 |
& "constituents in dependence refinement", |
| 28845 |
N, State_Id); |
| 28846 |
end if; |
| 28847 |
|
| 28848 |
SPARK_Msg_NE |
| 28849 |
("\constituent & is missing in output list", |
| 28850 |
N, Constit_Id); |
| 28851 |
end if; |
| 28852 |
|
| 28853 |
Next_Elmt (Constit_Elmt); |
| 28854 |
end loop; |
| 28855 |
end if; |
| 28856 |
end Check_Constituent_Usage; |
| 28857 |
|
| 28858 |
-- Local variables |
| 28859 |
|
| 28860 |
Item : Node_Id; |
| 28861 |
Item_Elmt : Elmt_Id; |
| 28862 |
Item_Id : Entity_Id; |
| 28863 |
|
| 28864 |
-- Start of processing for Check_Output_States |
| 28865 |
|
| 28866 |
begin |
| 28867 |
-- Inspect the outputs of pragma Depends looking for a state with a |
| 28868 |
-- visible refinement. |
| 28869 |
|
| 28870 |
if Present (Spec_Outputs) then |
| 28871 |
Item_Elmt := First_Elmt (Spec_Outputs); |
| 28872 |
while Present (Item_Elmt) loop |
| 28873 |
Item := Node (Item_Elmt); |
| 28874 |
|
| 28875 |
-- Deal with the mixed nature of the input and output lists |
| 28876 |
|
| 28877 |
if Nkind (Item) = N_Defining_Identifier then |
| 28878 |
Item_Id := Item; |
| 28879 |
else |
| 28880 |
Item_Id := Available_View (Entity_Of (Item)); |
| 28881 |
end if; |
| 28882 |
|
| 28883 |
if Ekind (Item_Id) = E_Abstract_State then |
| 28884 |
|
| 28885 |
-- The state acts as an input-output, skip it |
| 28886 |
|
| 28887 |
if Present (Spec_Inputs) |
| 28888 |
and then Appears_In (Spec_Inputs, Item_Id) |
| 28889 |
then |
| 28890 |
null; |
| 28891 |
|
| 28892 |
-- Ensure that all of the constituents are utilized as |
| 28893 |
-- outputs in pragma Refined_Depends. |
| 28894 |
|
| 28895 |
elsif Has_Non_Null_Visible_Refinement (Item_Id) then |
| 28896 |
Check_Constituent_Usage (Item_Id); |
| 28897 |
end if; |
| 28898 |
end if; |
| 28899 |
|
| 28900 |
Next_Elmt (Item_Elmt); |
| 28901 |
end loop; |
| 28902 |
end if; |
| 28903 |
end Check_Output_States; |
| 28904 |
|
| 28905 |
-------------------- |
| 28906 |
-- Collect_States -- |
| 28907 |
-------------------- |
| 28908 |
|
| 28909 |
function Collect_States (Clauses : List_Id) return Elist_Id is |
| 28910 |
procedure Collect_State |
| 28911 |
(Item : Node_Id; |
| 28912 |
States : in out Elist_Id); |
| 28913 |
-- Add the entity of Item to list States when it denotes to a state |
| 28914 |
|
| 28915 |
------------------- |
| 28916 |
-- Collect_State -- |
| 28917 |
------------------- |
| 28918 |
|
| 28919 |
procedure Collect_State |
| 28920 |
(Item : Node_Id; |
| 28921 |
States : in out Elist_Id) |
| 28922 |
is |
| 28923 |
Id : Entity_Id; |
| 28924 |
|
| 28925 |
begin |
| 28926 |
if Is_Entity_Name (Item) then |
| 28927 |
Id := Entity_Of (Item); |
| 28928 |
|
| 28929 |
if Ekind (Id) = E_Abstract_State then |
| 28930 |
if No (States) then |
| 28931 |
States := New_Elmt_List; |
| 28932 |
end if; |
| 28933 |
|
| 28934 |
Append_Unique_Elmt (Id, States); |
| 28935 |
end if; |
| 28936 |
end if; |
| 28937 |
end Collect_State; |
| 28938 |
|
| 28939 |
-- Local variables |
| 28940 |
|
| 28941 |
Clause : Node_Id; |
| 28942 |
Input : Node_Id; |
| 28943 |
Output : Node_Id; |
| 28944 |
States : Elist_Id := No_Elist; |
| 28945 |
|
| 28946 |
-- Start of processing for Collect_States |
| 28947 |
|
| 28948 |
begin |
| 28949 |
Clause := First (Clauses); |
| 28950 |
while Present (Clause) loop |
| 28951 |
Input := Expression (Clause); |
| 28952 |
Output := First (Choices (Clause)); |
| 28953 |
|
| 28954 |
Collect_State (Input, States); |
| 28955 |
Collect_State (Output, States); |
| 28956 |
|
| 28957 |
Next (Clause); |
| 28958 |
end loop; |
| 28959 |
|
| 28960 |
return States; |
| 28961 |
end Collect_States; |
| 28962 |
|
| 28963 |
----------------------- |
| 28964 |
-- Normalize_Clauses -- |
| 28965 |
----------------------- |
| 28966 |
|
| 28967 |
procedure Normalize_Clauses (Clauses : List_Id) is |
| 28968 |
procedure Normalize_Inputs (Clause : Node_Id); |
| 28969 |
-- Normalize clause Clause by creating multiple clauses for each |
| 28970 |
-- input item of Clause. It is assumed that Clause has exactly one |
| 28971 |
-- output. The transformation is as follows: |
| 28972 |
-- |
| 28973 |
-- Output => (Input_1, Input_2) -- original |
| 28974 |
-- |
| 28975 |
-- Output => Input_1 -- normalizations |
| 28976 |
-- Output => Input_2 |
| 28977 |
|
| 28978 |
procedure Normalize_Outputs (Clause : Node_Id); |
| 28979 |
-- Normalize clause Clause by creating multiple clause for each |
| 28980 |
-- output item of Clause. The transformation is as follows: |
| 28981 |
-- |
| 28982 |
-- (Output_1, Output_2) => Input -- original |
| 28983 |
-- |
| 28984 |
-- Output_1 => Input -- normalization |
| 28985 |
-- Output_2 => Input |
| 28986 |
|
| 28987 |
---------------------- |
| 28988 |
-- Normalize_Inputs -- |
| 28989 |
---------------------- |
| 28990 |
|
| 28991 |
procedure Normalize_Inputs (Clause : Node_Id) is |
| 28992 |
Inputs : constant Node_Id := Expression (Clause); |
| 28993 |
Loc : constant Source_Ptr := Sloc (Clause); |
| 28994 |
Output : constant List_Id := Choices (Clause); |
| 28995 |
Last_Input : Node_Id; |
| 28996 |
Input : Node_Id; |
| 28997 |
New_Clause : Node_Id; |
| 28998 |
Next_Input : Node_Id; |
| 28999 |
|
| 29000 |
begin |
| 29001 |
-- Normalization is performed only when the original clause has |
| 29002 |
-- more than one input. Multiple inputs appear as an aggregate. |
| 29003 |
|
| 29004 |
if Nkind (Inputs) = N_Aggregate then |
| 29005 |
Last_Input := Last (Expressions (Inputs)); |
| 29006 |
|
| 29007 |
-- Create a new clause for each input |
| 29008 |
|
| 29009 |
Input := First (Expressions (Inputs)); |
| 29010 |
while Present (Input) loop |
| 29011 |
Next_Input := Next (Input); |
| 29012 |
|
| 29013 |
-- Unhook the current input from the original input list |
| 29014 |
-- because it will be relocated to a new clause. |
| 29015 |
|
| 29016 |
Remove (Input); |
| 29017 |
|
| 29018 |
-- Special processing for the last input. At this point the |
| 29019 |
-- original aggregate has been stripped down to one element. |
| 29020 |
-- Replace the aggregate by the element itself. |
| 29021 |
|
| 29022 |
if Input = Last_Input then |
| 29023 |
Rewrite (Inputs, Input); |
| 29024 |
|
| 29025 |
-- Generate a clause of the form: |
| 29026 |
-- Output => Input |
| 29027 |
|
| 29028 |
else |
| 29029 |
New_Clause := |
| 29030 |
Make_Component_Association (Loc, |
| 29031 |
Choices => New_Copy_List_Tree (Output), |
| 29032 |
Expression => Input); |
| 29033 |
|
| 29034 |
-- The new clause contains replicated content that has |
| 29035 |
-- already been analyzed, mark the clause as analyzed. |
| 29036 |
|
| 29037 |
Set_Analyzed (New_Clause); |
| 29038 |
Insert_After (Clause, New_Clause); |
| 29039 |
end if; |
| 29040 |
|
| 29041 |
Input := Next_Input; |
| 29042 |
end loop; |
| 29043 |
end if; |
| 29044 |
end Normalize_Inputs; |
| 29045 |
|
| 29046 |
----------------------- |
| 29047 |
-- Normalize_Outputs -- |
| 29048 |
----------------------- |
| 29049 |
|
| 29050 |
procedure Normalize_Outputs (Clause : Node_Id) is |
| 29051 |
Inputs : constant Node_Id := Expression (Clause); |
| 29052 |
Loc : constant Source_Ptr := Sloc (Clause); |
| 29053 |
Outputs : constant Node_Id := First (Choices (Clause)); |
| 29054 |
Last_Output : Node_Id; |
| 29055 |
New_Clause : Node_Id; |
| 29056 |
Next_Output : Node_Id; |
| 29057 |
Output : Node_Id; |
| 29058 |
|
| 29059 |
begin |
| 29060 |
-- Multiple outputs appear as an aggregate. Nothing to do when |
| 29061 |
-- the clause has exactly one output. |
| 29062 |
|
| 29063 |
if Nkind (Outputs) = N_Aggregate then |
| 29064 |
Last_Output := Last (Expressions (Outputs)); |
| 29065 |
|
| 29066 |
-- Create a clause for each output. Note that each time a new |
| 29067 |
-- clause is created, the original output list slowly shrinks |
| 29068 |
-- until there is one item left. |
| 29069 |
|
| 29070 |
Output := First (Expressions (Outputs)); |
| 29071 |
while Present (Output) loop |
| 29072 |
Next_Output := Next (Output); |
| 29073 |
|
| 29074 |
-- Unhook the output from the original output list as it |
| 29075 |
-- will be relocated to a new clause. |
| 29076 |
|
| 29077 |
Remove (Output); |
| 29078 |
|
| 29079 |
-- Special processing for the last output. At this point |
| 29080 |
-- the original aggregate has been stripped down to one |
| 29081 |
-- element. Replace the aggregate by the element itself. |
| 29082 |
|
| 29083 |
if Output = Last_Output then |
| 29084 |
Rewrite (Outputs, Output); |
| 29085 |
|
| 29086 |
else |
| 29087 |
-- Generate a clause of the form: |
| 29088 |
-- (Output => Inputs) |
| 29089 |
|
| 29090 |
New_Clause := |
| 29091 |
Make_Component_Association (Loc, |
| 29092 |
Choices => New_List (Output), |
| 29093 |
Expression => New_Copy_Tree (Inputs)); |
| 29094 |
|
| 29095 |
-- The new clause contains replicated content that has |
| 29096 |
-- already been analyzed. There is not need to reanalyze |
| 29097 |
-- them. |
| 29098 |
|
| 29099 |
Set_Analyzed (New_Clause); |
| 29100 |
Insert_After (Clause, New_Clause); |
| 29101 |
end if; |
| 29102 |
|
| 29103 |
Output := Next_Output; |
| 29104 |
end loop; |
| 29105 |
end if; |
| 29106 |
end Normalize_Outputs; |
| 29107 |
|
| 29108 |
-- Local variables |
| 29109 |
|
| 29110 |
Clause : Node_Id; |
| 29111 |
|
| 29112 |
-- Start of processing for Normalize_Clauses |
| 29113 |
|
| 29114 |
begin |
| 29115 |
Clause := First (Clauses); |
| 29116 |
while Present (Clause) loop |
| 29117 |
Normalize_Outputs (Clause); |
| 29118 |
Next (Clause); |
| 29119 |
end loop; |
| 29120 |
|
| 29121 |
Clause := First (Clauses); |
| 29122 |
while Present (Clause) loop |
| 29123 |
Normalize_Inputs (Clause); |
| 29124 |
Next (Clause); |
| 29125 |
end loop; |
| 29126 |
end Normalize_Clauses; |
| 29127 |
|
| 29128 |
-------------------------- |
| 29129 |
-- Remove_Extra_Clauses -- |
| 29130 |
-------------------------- |
| 29131 |
|
| 29132 |
procedure Remove_Extra_Clauses |
| 29133 |
(Clauses : List_Id; |
| 29134 |
Matched_Items : Elist_Id) |
| 29135 |
is |
| 29136 |
Clause : Node_Id; |
| 29137 |
Input : Node_Id; |
| 29138 |
Input_Id : Entity_Id; |
| 29139 |
Next_Clause : Node_Id; |
| 29140 |
Output : Node_Id; |
| 29141 |
State_Id : Entity_Id; |
| 29142 |
|
| 29143 |
begin |
| 29144 |
Clause := First (Clauses); |
| 29145 |
while Present (Clause) loop |
| 29146 |
Next_Clause := Next (Clause); |
| 29147 |
|
| 29148 |
Input := Expression (Clause); |
| 29149 |
Output := First (Choices (Clause)); |
| 29150 |
|
| 29151 |
-- Recognize a clause of the form |
| 29152 |
|
| 29153 |
-- null => Input |
| 29154 |
|
| 29155 |
-- where Input is a constituent of a state which was already |
| 29156 |
-- successfully matched. This clause must be removed because it |
| 29157 |
-- simply indicates that some of the constituents of the state |
| 29158 |
-- are not used. |
| 29159 |
|
| 29160 |
-- Refined_State => (State => (Constit_1, Constit_2)) |
| 29161 |
-- Depends => (Output => State) |
| 29162 |
-- Refined_Depends => ((Output => Constit_1), -- State matched |
| 29163 |
-- (null => Constit_2)) -- OK |
| 29164 |
|
| 29165 |
if Nkind (Output) = N_Null and then Is_Entity_Name (Input) then |
| 29166 |
|
| 29167 |
-- Handle abstract views generated for limited with clauses |
| 29168 |
|
| 29169 |
Input_Id := Available_View (Entity_Of (Input)); |
| 29170 |
|
| 29171 |
-- The input must be a constituent of a state |
| 29172 |
|
| 29173 |
if Ekind (Input_Id) in |
| 29174 |
E_Abstract_State | E_Constant | E_Variable |
| 29175 |
and then Present (Encapsulating_State (Input_Id)) |
| 29176 |
then |
| 29177 |
State_Id := Encapsulating_State (Input_Id); |
| 29178 |
|
| 29179 |
-- The state must have a non-null visible refinement and be |
| 29180 |
-- matched in a previous clause. |
| 29181 |
|
| 29182 |
if Has_Non_Null_Visible_Refinement (State_Id) |
| 29183 |
and then Contains (Matched_Items, State_Id) |
| 29184 |
then |
| 29185 |
Remove (Clause); |
| 29186 |
end if; |
| 29187 |
end if; |
| 29188 |
|
| 29189 |
-- Recognize a clause of the form |
| 29190 |
|
| 29191 |
-- Output => null |
| 29192 |
|
| 29193 |
-- where Output is an arbitrary item. This clause must be removed |
| 29194 |
-- because a null input legitimately matches anything. |
| 29195 |
|
| 29196 |
elsif Nkind (Input) = N_Null then |
| 29197 |
Remove (Clause); |
| 29198 |
end if; |
| 29199 |
|
| 29200 |
Clause := Next_Clause; |
| 29201 |
end loop; |
| 29202 |
end Remove_Extra_Clauses; |
| 29203 |
|
| 29204 |
-------------------------- |
| 29205 |
-- Report_Extra_Clauses -- |
| 29206 |
-------------------------- |
| 29207 |
|
| 29208 |
procedure Report_Extra_Clauses (Clauses : List_Id) is |
| 29209 |
Clause : Node_Id; |
| 29210 |
|
| 29211 |
begin |
| 29212 |
Clause := First (Clauses); |
| 29213 |
while Present (Clause) loop |
| 29214 |
SPARK_Msg_N |
| 29215 |
("unmatched or extra clause in dependence refinement", Clause); |
| 29216 |
|
| 29217 |
Next (Clause); |
| 29218 |
end loop; |
| 29219 |
end Report_Extra_Clauses; |
| 29220 |
|
| 29221 |
-- Local variables |
| 29222 |
|
| 29223 |
Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 29224 |
Body_Id : constant Entity_Id := Defining_Entity (Body_Decl); |
| 29225 |
Errors : constant Nat := Serious_Errors_Detected; |
| 29226 |
|
| 29227 |
Clause : Node_Id; |
| 29228 |
Deps : Node_Id; |
| 29229 |
Dummy : Boolean; |
| 29230 |
Refs : Node_Id; |
| 29231 |
|
| 29232 |
Body_Inputs : Elist_Id := No_Elist; |
| 29233 |
Body_Outputs : Elist_Id := No_Elist; |
| 29234 |
-- The inputs and outputs of the subprogram body synthesized from pragma |
| 29235 |
-- Refined_Depends. |
| 29236 |
|
| 29237 |
Dependencies : List_Id := No_List; |
| 29238 |
Depends : Node_Id; |
| 29239 |
-- The corresponding Depends pragma along with its clauses |
| 29240 |
|
| 29241 |
Matched_Items : Elist_Id := No_Elist; |
| 29242 |
-- A list containing the entities of all successfully matched items |
| 29243 |
-- found in pragma Depends. |
| 29244 |
|
| 29245 |
Refinements : List_Id := No_List; |
| 29246 |
-- The clauses of pragma Refined_Depends |
| 29247 |
|
| 29248 |
Spec_Id : Entity_Id; |
| 29249 |
-- The entity of the subprogram subject to pragma Refined_Depends |
| 29250 |
|
| 29251 |
Spec_Inputs : Elist_Id := No_Elist; |
| 29252 |
Spec_Outputs : Elist_Id := No_Elist; |
| 29253 |
-- The inputs and outputs of the subprogram spec synthesized from pragma |
| 29254 |
-- Depends. |
| 29255 |
|
| 29256 |
States : Elist_Id := No_Elist; |
| 29257 |
-- A list containing the entities of all states whose constituents |
| 29258 |
-- appear in pragma Depends. |
| 29259 |
|
| 29260 |
-- Start of processing for Analyze_Refined_Depends_In_Decl_Part |
| 29261 |
|
| 29262 |
begin |
| 29263 |
-- Do not analyze the pragma multiple times |
| 29264 |
|
| 29265 |
if Is_Analyzed_Pragma (N) then |
| 29266 |
return; |
| 29267 |
end if; |
| 29268 |
|
| 29269 |
Spec_Id := Unique_Defining_Entity (Body_Decl); |
| 29270 |
|
| 29271 |
-- Use the anonymous object as the proper spec when Refined_Depends |
| 29272 |
-- applies to the body of a single task type. The object carries the |
| 29273 |
-- proper Chars as well as all non-refined versions of pragmas. |
| 29274 |
|
| 29275 |
if Is_Single_Concurrent_Type (Spec_Id) then |
| 29276 |
Spec_Id := Anonymous_Object (Spec_Id); |
| 29277 |
end if; |
| 29278 |
|
| 29279 |
Depends := Get_Pragma (Spec_Id, Pragma_Depends); |
| 29280 |
|
| 29281 |
-- Subprogram declarations lacks pragma Depends. Refined_Depends is |
| 29282 |
-- rendered useless as there is nothing to refine (SPARK RM 7.2.5(2)). |
| 29283 |
|
| 29284 |
if No (Depends) then |
| 29285 |
SPARK_Msg_NE |
| 29286 |
(Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram " |
| 29287 |
& "& lacks aspect or pragma Depends"), N, Spec_Id); |
| 29288 |
goto Leave; |
| 29289 |
end if; |
| 29290 |
|
| 29291 |
Deps := Expression (Get_Argument (Depends, Spec_Id)); |
| 29292 |
|
| 29293 |
-- A null dependency relation renders the refinement useless because it |
| 29294 |
-- cannot possibly mention abstract states with visible refinement. Note |
| 29295 |
-- that the inverse is not true as states may be refined to null |
| 29296 |
-- (SPARK RM 7.2.5(2)). |
| 29297 |
|
| 29298 |
if Nkind (Deps) = N_Null then |
| 29299 |
SPARK_Msg_NE |
| 29300 |
(Fix_Msg (Spec_Id, "useless refinement, subprogram & does not " |
| 29301 |
& "depend on abstract state with visible refinement"), N, Spec_Id); |
| 29302 |
goto Leave; |
| 29303 |
end if; |
| 29304 |
|
| 29305 |
-- Analyze Refined_Depends as if it behaved as a regular pragma Depends. |
| 29306 |
-- This ensures that the categorization of all refined dependency items |
| 29307 |
-- is consistent with their role. |
| 29308 |
|
| 29309 |
Analyze_Depends_In_Decl_Part (N); |
| 29310 |
|
| 29311 |
-- Do not perform these checks in an instance because they were already |
| 29312 |
-- performed successfully in the generic template. |
| 29313 |
|
| 29314 |
if In_Instance then |
| 29315 |
goto Leave; |
| 29316 |
end if; |
| 29317 |
|
| 29318 |
-- Do not match dependencies against refinements if Refined_Depends is |
| 29319 |
-- illegal to avoid emitting misleading error. |
| 29320 |
|
| 29321 |
if Serious_Errors_Detected = Errors then |
| 29322 |
|
| 29323 |
-- The related subprogram lacks pragma [Refined_]Global. Synthesize |
| 29324 |
-- the inputs and outputs of the subprogram spec and body to verify |
| 29325 |
-- the use of states with visible refinement and their constituents. |
| 29326 |
|
| 29327 |
if No (Get_Pragma (Spec_Id, Pragma_Global)) |
| 29328 |
or else No (Get_Pragma (Body_Id, Pragma_Refined_Global)) |
| 29329 |
then |
| 29330 |
Collect_Subprogram_Inputs_Outputs |
| 29331 |
(Subp_Id => Spec_Id, |
| 29332 |
Synthesize => True, |
| 29333 |
Subp_Inputs => Spec_Inputs, |
| 29334 |
Subp_Outputs => Spec_Outputs, |
| 29335 |
Global_Seen => Dummy); |
| 29336 |
|
| 29337 |
Collect_Subprogram_Inputs_Outputs |
| 29338 |
(Subp_Id => Body_Id, |
| 29339 |
Synthesize => True, |
| 29340 |
Subp_Inputs => Body_Inputs, |
| 29341 |
Subp_Outputs => Body_Outputs, |
| 29342 |
Global_Seen => Dummy); |
| 29343 |
|
| 29344 |
-- For an output state with a visible refinement, ensure that all |
| 29345 |
-- constituents appear as outputs in the dependency refinement. |
| 29346 |
|
| 29347 |
Check_Output_States |
| 29348 |
(Spec_Inputs => Spec_Inputs, |
| 29349 |
Spec_Outputs => Spec_Outputs, |
| 29350 |
Body_Inputs => Body_Inputs, |
| 29351 |
Body_Outputs => Body_Outputs); |
| 29352 |
end if; |
| 29353 |
|
| 29354 |
-- Multiple dependency clauses appear as component associations of an |
| 29355 |
-- aggregate. Note that the clauses are copied because the algorithm |
| 29356 |
-- modifies them and this should not be visible in Depends. |
| 29357 |
|
| 29358 |
pragma Assert (Nkind (Deps) = N_Aggregate); |
| 29359 |
Dependencies := New_Copy_List_Tree (Component_Associations (Deps)); |
| 29360 |
Normalize_Clauses (Dependencies); |
| 29361 |
|
| 29362 |
-- Gather all states which appear in Depends |
| 29363 |
|
| 29364 |
States := Collect_States (Dependencies); |
| 29365 |
|
| 29366 |
Refs := Expression (Get_Argument (N, Spec_Id)); |
| 29367 |
|
| 29368 |
if Nkind (Refs) = N_Null then |
| 29369 |
Refinements := No_List; |
| 29370 |
|
| 29371 |
-- Multiple dependency clauses appear as component associations of an |
| 29372 |
-- aggregate. Note that the clauses are copied because the algorithm |
| 29373 |
-- modifies them and this should not be visible in Refined_Depends. |
| 29374 |
|
| 29375 |
else pragma Assert (Nkind (Refs) = N_Aggregate); |
| 29376 |
Refinements := New_Copy_List_Tree (Component_Associations (Refs)); |
| 29377 |
Normalize_Clauses (Refinements); |
| 29378 |
end if; |
| 29379 |
|
| 29380 |
-- At this point the clauses of pragmas Depends and Refined_Depends |
| 29381 |
-- have been normalized into simple dependencies between one output |
| 29382 |
-- and one input. Examine all clauses of pragma Depends looking for |
| 29383 |
-- matching clauses in pragma Refined_Depends. |
| 29384 |
|
| 29385 |
Clause := First (Dependencies); |
| 29386 |
while Present (Clause) loop |
| 29387 |
Check_Dependency_Clause |
| 29388 |
(Spec_Id => Spec_Id, |
| 29389 |
Dep_Clause => Clause, |
| 29390 |
Dep_States => States, |
| 29391 |
Refinements => Refinements, |
| 29392 |
Matched_Items => Matched_Items); |
| 29393 |
|
| 29394 |
Next (Clause); |
| 29395 |
end loop; |
| 29396 |
|
| 29397 |
-- Pragma Refined_Depends may contain multiple clarification clauses |
| 29398 |
-- which indicate that certain constituents do not influence the data |
| 29399 |
-- flow in any way. Such clauses must be removed as long as the state |
| 29400 |
-- has been matched, otherwise they will be incorrectly flagged as |
| 29401 |
-- unmatched. |
| 29402 |
|
| 29403 |
-- Refined_State => (State => (Constit_1, Constit_2)) |
| 29404 |
-- Depends => (Output => State) |
| 29405 |
-- Refined_Depends => ((Output => Constit_1), -- State matched |
| 29406 |
-- (null => Constit_2)) -- must be removed |
| 29407 |
|
| 29408 |
Remove_Extra_Clauses (Refinements, Matched_Items); |
| 29409 |
|
| 29410 |
if Serious_Errors_Detected = Errors then |
| 29411 |
Report_Extra_Clauses (Refinements); |
| 29412 |
end if; |
| 29413 |
end if; |
| 29414 |
|
| 29415 |
<<Leave>> |
| 29416 |
Set_Is_Analyzed_Pragma (N); |
| 29417 |
end Analyze_Refined_Depends_In_Decl_Part; |
| 29418 |
|
| 29419 |
----------------------------------------- |
| 29420 |
-- Analyze_Refined_Global_In_Decl_Part -- |
| 29421 |
----------------------------------------- |
| 29422 |
|
| 29423 |
procedure Analyze_Refined_Global_In_Decl_Part (N : Node_Id) is |
| 29424 |
Global : Node_Id; |
| 29425 |
-- The corresponding Global pragma |
| 29426 |
|
| 29427 |
Has_In_State : Boolean := False; |
| 29428 |
Has_In_Out_State : Boolean := False; |
| 29429 |
Has_Out_State : Boolean := False; |
| 29430 |
Has_Proof_In_State : Boolean := False; |
| 29431 |
-- These flags are set when the corresponding Global pragma has a state |
| 29432 |
-- of mode Input, In_Out, Output or Proof_In respectively with a visible |
| 29433 |
-- refinement. |
| 29434 |
|
| 29435 |
Has_Null_State : Boolean := False; |
| 29436 |
-- This flag is set when the corresponding Global pragma has at least |
| 29437 |
-- one state with a null refinement. |
| 29438 |
|
| 29439 |
In_Constits : Elist_Id := No_Elist; |
| 29440 |
In_Out_Constits : Elist_Id := No_Elist; |
| 29441 |
Out_Constits : Elist_Id := No_Elist; |
| 29442 |
Proof_In_Constits : Elist_Id := No_Elist; |
| 29443 |
-- These lists contain the entities of all Input, In_Out, Output and |
| 29444 |
-- Proof_In constituents that appear in Refined_Global and participate |
| 29445 |
-- in state refinement. |
| 29446 |
|
| 29447 |
In_Items : Elist_Id := No_Elist; |
| 29448 |
In_Out_Items : Elist_Id := No_Elist; |
| 29449 |
Out_Items : Elist_Id := No_Elist; |
| 29450 |
Proof_In_Items : Elist_Id := No_Elist; |
| 29451 |
-- These lists contain the entities of all Input, In_Out, Output and |
| 29452 |
-- Proof_In items defined in the corresponding Global pragma. |
| 29453 |
|
| 29454 |
Repeat_Items : Elist_Id := No_Elist; |
| 29455 |
-- A list of all global items without full visible refinement found |
| 29456 |
-- in pragma Global. These states should be repeated in the global |
| 29457 |
-- refinement (SPARK RM 7.2.4(3c)) unless they have a partial visible |
| 29458 |
-- refinement, in which case they may be repeated (SPARK RM 7.2.4(3d)). |
| 29459 |
|
| 29460 |
Spec_Id : Entity_Id; |
| 29461 |
-- The entity of the subprogram subject to pragma Refined_Global |
| 29462 |
|
| 29463 |
States : Elist_Id := No_Elist; |
| 29464 |
-- A list of all states with full or partial visible refinement found in |
| 29465 |
-- pragma Global. |
| 29466 |
|
| 29467 |
procedure Check_In_Out_States; |
| 29468 |
-- Determine whether the corresponding Global pragma mentions In_Out |
| 29469 |
-- states with visible refinement and if so, ensure that one of the |
| 29470 |
-- following completions apply to the constituents of the state: |
| 29471 |
-- 1) there is at least one constituent of mode In_Out |
| 29472 |
-- 2) there is at least one Input and one Output constituent |
| 29473 |
-- 3) not all constituents are present and one of them is of mode |
| 29474 |
-- Output. |
| 29475 |
-- This routine may remove elements from In_Constits, In_Out_Constits, |
| 29476 |
-- Out_Constits and Proof_In_Constits. |
| 29477 |
|
| 29478 |
procedure Check_Input_States; |
| 29479 |
-- Determine whether the corresponding Global pragma mentions Input |
| 29480 |
-- states with visible refinement and if so, ensure that at least one of |
| 29481 |
-- its constituents appears as an Input item in Refined_Global. |
| 29482 |
-- This routine may remove elements from In_Constits, In_Out_Constits, |
| 29483 |
-- Out_Constits and Proof_In_Constits. |
| 29484 |
|
| 29485 |
procedure Check_Output_States; |
| 29486 |
-- Determine whether the corresponding Global pragma mentions Output |
| 29487 |
-- states with visible refinement and if so, ensure that all of its |
| 29488 |
-- constituents appear as Output items in Refined_Global. |
| 29489 |
-- This routine may remove elements from In_Constits, In_Out_Constits, |
| 29490 |
-- Out_Constits and Proof_In_Constits. |
| 29491 |
|
| 29492 |
procedure Check_Proof_In_States; |
| 29493 |
-- Determine whether the corresponding Global pragma mentions Proof_In |
| 29494 |
-- states with visible refinement and if so, ensure that at least one of |
| 29495 |
-- its constituents appears as a Proof_In item in Refined_Global. |
| 29496 |
-- This routine may remove elements from In_Constits, In_Out_Constits, |
| 29497 |
-- Out_Constits and Proof_In_Constits. |
| 29498 |
|
| 29499 |
procedure Check_Refined_Global_List |
| 29500 |
(List : Node_Id; |
| 29501 |
Global_Mode : Name_Id := Name_Input); |
| 29502 |
-- Verify the legality of a single global list declaration. Global_Mode |
| 29503 |
-- denotes the current mode in effect. |
| 29504 |
|
| 29505 |
procedure Collect_Global_Items |
| 29506 |
(List : Node_Id; |
| 29507 |
Mode : Name_Id := Name_Input); |
| 29508 |
-- Gather all Input, In_Out, Output and Proof_In items from node List |
| 29509 |
-- and separate them in lists In_Items, In_Out_Items, Out_Items and |
| 29510 |
-- Proof_In_Items. Flags Has_In_State, Has_In_Out_State, Has_Out_State |
| 29511 |
-- and Has_Proof_In_State are set when there is at least one abstract |
| 29512 |
-- state with full or partial visible refinement available in the |
| 29513 |
-- corresponding mode. Flag Has_Null_State is set when at least state |
| 29514 |
-- has a null refinement. Mode denotes the current global mode in |
| 29515 |
-- effect. |
| 29516 |
|
| 29517 |
function Present_Then_Remove |
| 29518 |
(List : Elist_Id; |
| 29519 |
Item : Entity_Id) return Boolean; |
| 29520 |
-- Search List for a particular entity Item. If Item has been found, |
| 29521 |
-- remove it from List. This routine is used to strip lists In_Constits, |
| 29522 |
-- In_Out_Constits and Out_Constits of valid constituents. |
| 29523 |
|
| 29524 |
procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id); |
| 29525 |
-- Same as function Present_Then_Remove, but do not report the presence |
| 29526 |
-- of Item in List. |
| 29527 |
|
| 29528 |
procedure Report_Extra_Constituents; |
| 29529 |
-- Emit an error for each constituent found in lists In_Constits, |
| 29530 |
-- In_Out_Constits and Out_Constits. |
| 29531 |
|
| 29532 |
procedure Report_Missing_Items; |
| 29533 |
-- Emit an error for each global item not repeated found in list |
| 29534 |
-- Repeat_Items. |
| 29535 |
|
| 29536 |
------------------------- |
| 29537 |
-- Check_In_Out_States -- |
| 29538 |
------------------------- |
| 29539 |
|
| 29540 |
procedure Check_In_Out_States is |
| 29541 |
procedure Check_Constituent_Usage (State_Id : Entity_Id); |
| 29542 |
-- Determine whether one of the following coverage scenarios is in |
| 29543 |
-- effect: |
| 29544 |
-- 1) there is at least one constituent of mode In_Out or Output |
| 29545 |
-- 2) there is at least one pair of constituents with modes Input |
| 29546 |
-- and Output, or Proof_In and Output. |
| 29547 |
-- 3) there is at least one constituent of mode Output and not all |
| 29548 |
-- constituents are present. |
| 29549 |
-- If this is not the case, emit an error (SPARK RM 7.2.4(5)). |
| 29550 |
|
| 29551 |
----------------------------- |
| 29552 |
-- Check_Constituent_Usage -- |
| 29553 |
----------------------------- |
| 29554 |
|
| 29555 |
procedure Check_Constituent_Usage (State_Id : Entity_Id) is |
| 29556 |
Constits : constant Elist_Id := |
| 29557 |
Partial_Refinement_Constituents (State_Id); |
| 29558 |
Constit_Elmt : Elmt_Id; |
| 29559 |
Constit_Id : Entity_Id; |
| 29560 |
Has_Missing : Boolean := False; |
| 29561 |
In_Out_Seen : Boolean := False; |
| 29562 |
Input_Seen : Boolean := False; |
| 29563 |
Output_Seen : Boolean := False; |
| 29564 |
Proof_In_Seen : Boolean := False; |
| 29565 |
|
| 29566 |
begin |
| 29567 |
-- Process all the constituents of the state and note their modes |
| 29568 |
-- within the global refinement. |
| 29569 |
|
| 29570 |
if Present (Constits) then |
| 29571 |
Constit_Elmt := First_Elmt (Constits); |
| 29572 |
while Present (Constit_Elmt) loop |
| 29573 |
Constit_Id := Node (Constit_Elmt); |
| 29574 |
|
| 29575 |
if Present_Then_Remove (In_Constits, Constit_Id) then |
| 29576 |
Input_Seen := True; |
| 29577 |
|
| 29578 |
elsif Present_Then_Remove (In_Out_Constits, Constit_Id) then |
| 29579 |
In_Out_Seen := True; |
| 29580 |
|
| 29581 |
elsif Present_Then_Remove (Out_Constits, Constit_Id) then |
| 29582 |
Output_Seen := True; |
| 29583 |
|
| 29584 |
elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) |
| 29585 |
then |
| 29586 |
Proof_In_Seen := True; |
| 29587 |
|
| 29588 |
else |
| 29589 |
Has_Missing := True; |
| 29590 |
end if; |
| 29591 |
|
| 29592 |
Next_Elmt (Constit_Elmt); |
| 29593 |
end loop; |
| 29594 |
end if; |
| 29595 |
|
| 29596 |
-- An In_Out constituent is a valid completion |
| 29597 |
|
| 29598 |
if In_Out_Seen then |
| 29599 |
null; |
| 29600 |
|
| 29601 |
-- A pair of one Input/Proof_In and one Output constituent is a |
| 29602 |
-- valid completion. |
| 29603 |
|
| 29604 |
elsif (Input_Seen or Proof_In_Seen) and Output_Seen then |
| 29605 |
null; |
| 29606 |
|
| 29607 |
elsif Output_Seen then |
| 29608 |
|
| 29609 |
-- A single Output constituent is a valid completion only when |
| 29610 |
-- some of the other constituents are missing. |
| 29611 |
|
| 29612 |
if Has_Missing then |
| 29613 |
null; |
| 29614 |
|
| 29615 |
-- Otherwise all constituents are of mode Output |
| 29616 |
|
| 29617 |
else |
| 29618 |
SPARK_Msg_NE |
| 29619 |
("global refinement of state & must include at least one " |
| 29620 |
& "constituent of mode `In_Out`, `Input`, or `Proof_In`", |
| 29621 |
N, State_Id); |
| 29622 |
end if; |
| 29623 |
|
| 29624 |
-- The state lacks a completion. When full refinement is visible, |
| 29625 |
-- always emit an error (SPARK RM 7.2.4(3a)). When only partial |
| 29626 |
-- refinement is visible, emit an error if the abstract state |
| 29627 |
-- itself is not utilized (SPARK RM 7.2.4(3d)). In the case where |
| 29628 |
-- both are utilized, Check_State_And_Constituent_Use. will issue |
| 29629 |
-- the error. |
| 29630 |
|
| 29631 |
elsif not Input_Seen |
| 29632 |
and then not In_Out_Seen |
| 29633 |
and then not Output_Seen |
| 29634 |
and then not Proof_In_Seen |
| 29635 |
then |
| 29636 |
if Has_Visible_Refinement (State_Id) |
| 29637 |
or else Contains (Repeat_Items, State_Id) |
| 29638 |
then |
| 29639 |
SPARK_Msg_NE |
| 29640 |
("missing global refinement of state &", N, State_Id); |
| 29641 |
end if; |
| 29642 |
|
| 29643 |
-- Otherwise the state has a malformed completion where at least |
| 29644 |
-- one of the constituents has a different mode. |
| 29645 |
|
| 29646 |
else |
| 29647 |
SPARK_Msg_NE |
| 29648 |
("global refinement of state & redefines the mode of its " |
| 29649 |
& "constituents", N, State_Id); |
| 29650 |
end if; |
| 29651 |
end Check_Constituent_Usage; |
| 29652 |
|
| 29653 |
-- Local variables |
| 29654 |
|
| 29655 |
Item_Elmt : Elmt_Id; |
| 29656 |
Item_Id : Entity_Id; |
| 29657 |
|
| 29658 |
-- Start of processing for Check_In_Out_States |
| 29659 |
|
| 29660 |
begin |
| 29661 |
-- Inspect the In_Out items of the corresponding Global pragma |
| 29662 |
-- looking for a state with a visible refinement. |
| 29663 |
|
| 29664 |
if Has_In_Out_State and then Present (In_Out_Items) then |
| 29665 |
Item_Elmt := First_Elmt (In_Out_Items); |
| 29666 |
while Present (Item_Elmt) loop |
| 29667 |
Item_Id := Node (Item_Elmt); |
| 29668 |
|
| 29669 |
-- Ensure that one of the three coverage variants is satisfied |
| 29670 |
|
| 29671 |
if Ekind (Item_Id) = E_Abstract_State |
| 29672 |
and then Has_Non_Null_Visible_Refinement (Item_Id) |
| 29673 |
then |
| 29674 |
Check_Constituent_Usage (Item_Id); |
| 29675 |
end if; |
| 29676 |
|
| 29677 |
Next_Elmt (Item_Elmt); |
| 29678 |
end loop; |
| 29679 |
end if; |
| 29680 |
end Check_In_Out_States; |
| 29681 |
|
| 29682 |
------------------------ |
| 29683 |
-- Check_Input_States -- |
| 29684 |
------------------------ |
| 29685 |
|
| 29686 |
procedure Check_Input_States is |
| 29687 |
procedure Check_Constituent_Usage (State_Id : Entity_Id); |
| 29688 |
-- Determine whether at least one constituent of state State_Id with |
| 29689 |
-- full or partial visible refinement is used and has mode Input. |
| 29690 |
-- Ensure that the remaining constituents do not have In_Out or |
| 29691 |
-- Output modes. Emit an error if this is not the case |
| 29692 |
-- (SPARK RM 7.2.4(5)). |
| 29693 |
|
| 29694 |
----------------------------- |
| 29695 |
-- Check_Constituent_Usage -- |
| 29696 |
----------------------------- |
| 29697 |
|
| 29698 |
procedure Check_Constituent_Usage (State_Id : Entity_Id) is |
| 29699 |
Constits : constant Elist_Id := |
| 29700 |
Partial_Refinement_Constituents (State_Id); |
| 29701 |
Constit_Elmt : Elmt_Id; |
| 29702 |
Constit_Id : Entity_Id; |
| 29703 |
In_Seen : Boolean := False; |
| 29704 |
|
| 29705 |
begin |
| 29706 |
if Present (Constits) then |
| 29707 |
Constit_Elmt := First_Elmt (Constits); |
| 29708 |
while Present (Constit_Elmt) loop |
| 29709 |
Constit_Id := Node (Constit_Elmt); |
| 29710 |
|
| 29711 |
-- At least one of the constituents appears as an Input |
| 29712 |
|
| 29713 |
if Present_Then_Remove (In_Constits, Constit_Id) then |
| 29714 |
In_Seen := True; |
| 29715 |
|
| 29716 |
-- A Proof_In constituent can refine an Input state as long |
| 29717 |
-- as there is at least one Input constituent present. |
| 29718 |
|
| 29719 |
elsif Present_Then_Remove (Proof_In_Constits, Constit_Id) |
| 29720 |
then |
| 29721 |
null; |
| 29722 |
|
| 29723 |
-- The constituent appears in the global refinement, but has |
| 29724 |
-- mode In_Out or Output (SPARK RM 7.2.4(5)). |
| 29725 |
|
| 29726 |
elsif Present_Then_Remove (In_Out_Constits, Constit_Id) |
| 29727 |
or else Present_Then_Remove (Out_Constits, Constit_Id) |
| 29728 |
then |
| 29729 |
Error_Msg_Name_1 := Chars (State_Id); |
| 29730 |
SPARK_Msg_NE |
| 29731 |
("constituent & of state % must have mode `Input` in " |
| 29732 |
& "global refinement", N, Constit_Id); |
| 29733 |
end if; |
| 29734 |
|
| 29735 |
Next_Elmt (Constit_Elmt); |
| 29736 |
end loop; |
| 29737 |
end if; |
| 29738 |
|
| 29739 |
-- Not one of the constituents appeared as Input. Always emit an |
| 29740 |
-- error when the full refinement is visible (SPARK RM 7.2.4(3a)). |
| 29741 |
-- When only partial refinement is visible, emit an error if the |
| 29742 |
-- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In |
| 29743 |
-- the case where both are utilized, an error will be issued in |
| 29744 |
-- Check_State_And_Constituent_Use. |
| 29745 |
|
| 29746 |
if not In_Seen |
| 29747 |
and then (Has_Visible_Refinement (State_Id) |
| 29748 |
or else Contains (Repeat_Items, State_Id)) |
| 29749 |
then |
| 29750 |
SPARK_Msg_NE |
| 29751 |
("global refinement of state & must include at least one " |
| 29752 |
& "constituent of mode `Input`", N, State_Id); |
| 29753 |
end if; |
| 29754 |
end Check_Constituent_Usage; |
| 29755 |
|
| 29756 |
-- Local variables |
| 29757 |
|
| 29758 |
Item_Elmt : Elmt_Id; |
| 29759 |
Item_Id : Entity_Id; |
| 29760 |
|
| 29761 |
-- Start of processing for Check_Input_States |
| 29762 |
|
| 29763 |
begin |
| 29764 |
-- Inspect the Input items of the corresponding Global pragma looking |
| 29765 |
-- for a state with a visible refinement. |
| 29766 |
|
| 29767 |
if Has_In_State and then Present (In_Items) then |
| 29768 |
Item_Elmt := First_Elmt (In_Items); |
| 29769 |
while Present (Item_Elmt) loop |
| 29770 |
Item_Id := Node (Item_Elmt); |
| 29771 |
|
| 29772 |
-- When full refinement is visible, ensure that at least one of |
| 29773 |
-- the constituents is utilized and is of mode Input. When only |
| 29774 |
-- partial refinement is visible, ensure that either one of |
| 29775 |
-- the constituents is utilized and is of mode Input, or the |
| 29776 |
-- abstract state is repeated and no constituent is utilized. |
| 29777 |
|
| 29778 |
if Ekind (Item_Id) = E_Abstract_State |
| 29779 |
and then Has_Non_Null_Visible_Refinement (Item_Id) |
| 29780 |
then |
| 29781 |
Check_Constituent_Usage (Item_Id); |
| 29782 |
end if; |
| 29783 |
|
| 29784 |
Next_Elmt (Item_Elmt); |
| 29785 |
end loop; |
| 29786 |
end if; |
| 29787 |
end Check_Input_States; |
| 29788 |
|
| 29789 |
------------------------- |
| 29790 |
-- Check_Output_States -- |
| 29791 |
------------------------- |
| 29792 |
|
| 29793 |
procedure Check_Output_States is |
| 29794 |
procedure Check_Constituent_Usage (State_Id : Entity_Id); |
| 29795 |
-- Determine whether all constituents of state State_Id with full |
| 29796 |
-- visible refinement are used and have mode Output. Emit an error |
| 29797 |
-- if this is not the case (SPARK RM 7.2.4(5)). |
| 29798 |
|
| 29799 |
----------------------------- |
| 29800 |
-- Check_Constituent_Usage -- |
| 29801 |
----------------------------- |
| 29802 |
|
| 29803 |
procedure Check_Constituent_Usage (State_Id : Entity_Id) is |
| 29804 |
Constits : constant Elist_Id := |
| 29805 |
Partial_Refinement_Constituents (State_Id); |
| 29806 |
Only_Partial : constant Boolean := |
| 29807 |
not Has_Visible_Refinement (State_Id); |
| 29808 |
Constit_Elmt : Elmt_Id; |
| 29809 |
Constit_Id : Entity_Id; |
| 29810 |
Posted : Boolean := False; |
| 29811 |
|
| 29812 |
begin |
| 29813 |
if Present (Constits) then |
| 29814 |
Constit_Elmt := First_Elmt (Constits); |
| 29815 |
while Present (Constit_Elmt) loop |
| 29816 |
Constit_Id := Node (Constit_Elmt); |
| 29817 |
|
| 29818 |
-- Issue an error when a constituent of State_Id is utilized |
| 29819 |
-- and State_Id has only partial visible refinement |
| 29820 |
-- (SPARK RM 7.2.4(3d)). |
| 29821 |
|
| 29822 |
if Only_Partial then |
| 29823 |
if Present_Then_Remove (Out_Constits, Constit_Id) |
| 29824 |
or else Present_Then_Remove (In_Constits, Constit_Id) |
| 29825 |
or else |
| 29826 |
Present_Then_Remove (In_Out_Constits, Constit_Id) |
| 29827 |
or else |
| 29828 |
Present_Then_Remove (Proof_In_Constits, Constit_Id) |
| 29829 |
then |
| 29830 |
Error_Msg_Name_1 := Chars (State_Id); |
| 29831 |
SPARK_Msg_NE |
| 29832 |
("constituent & of state % cannot be used in global " |
| 29833 |
& "refinement", N, Constit_Id); |
| 29834 |
Error_Msg_Name_1 := Chars (State_Id); |
| 29835 |
SPARK_Msg_N ("\use state % instead", N); |
| 29836 |
end if; |
| 29837 |
|
| 29838 |
elsif Present_Then_Remove (Out_Constits, Constit_Id) then |
| 29839 |
null; |
| 29840 |
|
| 29841 |
-- The constituent appears in the global refinement, but has |
| 29842 |
-- mode Input, In_Out or Proof_In (SPARK RM 7.2.4(5)). |
| 29843 |
|
| 29844 |
elsif Present_Then_Remove (In_Constits, Constit_Id) |
| 29845 |
or else Present_Then_Remove (In_Out_Constits, Constit_Id) |
| 29846 |
or else Present_Then_Remove (Proof_In_Constits, Constit_Id) |
| 29847 |
then |
| 29848 |
Error_Msg_Name_1 := Chars (State_Id); |
| 29849 |
SPARK_Msg_NE |
| 29850 |
("constituent & of state % must have mode `Output` in " |
| 29851 |
& "global refinement", N, Constit_Id); |
| 29852 |
|
| 29853 |
-- The constituent is altogether missing (SPARK RM 7.2.5(3)) |
| 29854 |
|
| 29855 |
else |
| 29856 |
if not Posted then |
| 29857 |
Posted := True; |
| 29858 |
SPARK_Msg_NE |
| 29859 |
("`Output` state & must be replaced by all its " |
| 29860 |
& "constituents in global refinement", N, State_Id); |
| 29861 |
end if; |
| 29862 |
|
| 29863 |
SPARK_Msg_NE |
| 29864 |
("\constituent & is missing in output list", |
| 29865 |
N, Constit_Id); |
| 29866 |
end if; |
| 29867 |
|
| 29868 |
Next_Elmt (Constit_Elmt); |
| 29869 |
end loop; |
| 29870 |
end if; |
| 29871 |
end Check_Constituent_Usage; |
| 29872 |
|
| 29873 |
-- Local variables |
| 29874 |
|
| 29875 |
Item_Elmt : Elmt_Id; |
| 29876 |
Item_Id : Entity_Id; |
| 29877 |
|
| 29878 |
-- Start of processing for Check_Output_States |
| 29879 |
|
| 29880 |
begin |
| 29881 |
-- Inspect the Output items of the corresponding Global pragma |
| 29882 |
-- looking for a state with a visible refinement. |
| 29883 |
|
| 29884 |
if Has_Out_State and then Present (Out_Items) then |
| 29885 |
Item_Elmt := First_Elmt (Out_Items); |
| 29886 |
while Present (Item_Elmt) loop |
| 29887 |
Item_Id := Node (Item_Elmt); |
| 29888 |
|
| 29889 |
-- When full refinement is visible, ensure that all of the |
| 29890 |
-- constituents are utilized and they have mode Output. When |
| 29891 |
-- only partial refinement is visible, ensure that no |
| 29892 |
-- constituent is utilized. |
| 29893 |
|
| 29894 |
if Ekind (Item_Id) = E_Abstract_State |
| 29895 |
and then Has_Non_Null_Visible_Refinement (Item_Id) |
| 29896 |
then |
| 29897 |
Check_Constituent_Usage (Item_Id); |
| 29898 |
end if; |
| 29899 |
|
| 29900 |
Next_Elmt (Item_Elmt); |
| 29901 |
end loop; |
| 29902 |
end if; |
| 29903 |
end Check_Output_States; |
| 29904 |
|
| 29905 |
--------------------------- |
| 29906 |
-- Check_Proof_In_States -- |
| 29907 |
--------------------------- |
| 29908 |
|
| 29909 |
procedure Check_Proof_In_States is |
| 29910 |
procedure Check_Constituent_Usage (State_Id : Entity_Id); |
| 29911 |
-- Determine whether at least one constituent of state State_Id with |
| 29912 |
-- full or partial visible refinement is used and has mode Proof_In. |
| 29913 |
-- Ensure that the remaining constituents do not have Input, In_Out, |
| 29914 |
-- or Output modes. Emit an error if this is not the case |
| 29915 |
-- (SPARK RM 7.2.4(5)). |
| 29916 |
|
| 29917 |
----------------------------- |
| 29918 |
-- Check_Constituent_Usage -- |
| 29919 |
----------------------------- |
| 29920 |
|
| 29921 |
procedure Check_Constituent_Usage (State_Id : Entity_Id) is |
| 29922 |
Constits : constant Elist_Id := |
| 29923 |
Partial_Refinement_Constituents (State_Id); |
| 29924 |
Constit_Elmt : Elmt_Id; |
| 29925 |
Constit_Id : Entity_Id; |
| 29926 |
Proof_In_Seen : Boolean := False; |
| 29927 |
|
| 29928 |
begin |
| 29929 |
if Present (Constits) then |
| 29930 |
Constit_Elmt := First_Elmt (Constits); |
| 29931 |
while Present (Constit_Elmt) loop |
| 29932 |
Constit_Id := Node (Constit_Elmt); |
| 29933 |
|
| 29934 |
-- At least one of the constituents appears as Proof_In |
| 29935 |
|
| 29936 |
if Present_Then_Remove (Proof_In_Constits, Constit_Id) then |
| 29937 |
Proof_In_Seen := True; |
| 29938 |
|
| 29939 |
-- The constituent appears in the global refinement, but has |
| 29940 |
-- mode Input, In_Out or Output (SPARK RM 7.2.4(5)). |
| 29941 |
|
| 29942 |
elsif Present_Then_Remove (In_Constits, Constit_Id) |
| 29943 |
or else Present_Then_Remove (In_Out_Constits, Constit_Id) |
| 29944 |
or else Present_Then_Remove (Out_Constits, Constit_Id) |
| 29945 |
then |
| 29946 |
Error_Msg_Name_1 := Chars (State_Id); |
| 29947 |
SPARK_Msg_NE |
| 29948 |
("constituent & of state % must have mode `Proof_In` " |
| 29949 |
& "in global refinement", N, Constit_Id); |
| 29950 |
end if; |
| 29951 |
|
| 29952 |
Next_Elmt (Constit_Elmt); |
| 29953 |
end loop; |
| 29954 |
end if; |
| 29955 |
|
| 29956 |
-- Not one of the constituents appeared as Proof_In. Always emit |
| 29957 |
-- an error when full refinement is visible (SPARK RM 7.2.4(3a)). |
| 29958 |
-- When only partial refinement is visible, emit an error if the |
| 29959 |
-- abstract state itself is not utilized (SPARK RM 7.2.4(3d)). In |
| 29960 |
-- the case where both are utilized, an error will be issued by |
| 29961 |
-- Check_State_And_Constituent_Use. |
| 29962 |
|
| 29963 |
if not Proof_In_Seen |
| 29964 |
and then (Has_Visible_Refinement (State_Id) |
| 29965 |
or else Contains (Repeat_Items, State_Id)) |
| 29966 |
then |
| 29967 |
SPARK_Msg_NE |
| 29968 |
("global refinement of state & must include at least one " |
| 29969 |
& "constituent of mode `Proof_In`", N, State_Id); |
| 29970 |
end if; |
| 29971 |
end Check_Constituent_Usage; |
| 29972 |
|
| 29973 |
-- Local variables |
| 29974 |
|
| 29975 |
Item_Elmt : Elmt_Id; |
| 29976 |
Item_Id : Entity_Id; |
| 29977 |
|
| 29978 |
-- Start of processing for Check_Proof_In_States |
| 29979 |
|
| 29980 |
begin |
| 29981 |
-- Inspect the Proof_In items of the corresponding Global pragma |
| 29982 |
-- looking for a state with a visible refinement. |
| 29983 |
|
| 29984 |
if Has_Proof_In_State and then Present (Proof_In_Items) then |
| 29985 |
Item_Elmt := First_Elmt (Proof_In_Items); |
| 29986 |
while Present (Item_Elmt) loop |
| 29987 |
Item_Id := Node (Item_Elmt); |
| 29988 |
|
| 29989 |
-- Ensure that at least one of the constituents is utilized |
| 29990 |
-- and is of mode Proof_In. When only partial refinement is |
| 29991 |
-- visible, ensure that either one of the constituents is |
| 29992 |
-- utilized and is of mode Proof_In, or the abstract state |
| 29993 |
-- is repeated and no constituent is utilized. |
| 29994 |
|
| 29995 |
if Ekind (Item_Id) = E_Abstract_State |
| 29996 |
and then Has_Non_Null_Visible_Refinement (Item_Id) |
| 29997 |
then |
| 29998 |
Check_Constituent_Usage (Item_Id); |
| 29999 |
end if; |
| 30000 |
|
| 30001 |
Next_Elmt (Item_Elmt); |
| 30002 |
end loop; |
| 30003 |
end if; |
| 30004 |
end Check_Proof_In_States; |
| 30005 |
|
| 30006 |
------------------------------- |
| 30007 |
-- Check_Refined_Global_List -- |
| 30008 |
------------------------------- |
| 30009 |
|
| 30010 |
procedure Check_Refined_Global_List |
| 30011 |
(List : Node_Id; |
| 30012 |
Global_Mode : Name_Id := Name_Input) |
| 30013 |
is |
| 30014 |
procedure Check_Refined_Global_Item |
| 30015 |
(Item : Node_Id; |
| 30016 |
Global_Mode : Name_Id); |
| 30017 |
-- Verify the legality of a single global item declaration. Parameter |
| 30018 |
-- Global_Mode denotes the current mode in effect. |
| 30019 |
|
| 30020 |
------------------------------- |
| 30021 |
-- Check_Refined_Global_Item -- |
| 30022 |
------------------------------- |
| 30023 |
|
| 30024 |
procedure Check_Refined_Global_Item |
| 30025 |
(Item : Node_Id; |
| 30026 |
Global_Mode : Name_Id) |
| 30027 |
is |
| 30028 |
Item_Id : constant Entity_Id := Entity_Of (Item); |
| 30029 |
|
| 30030 |
procedure Inconsistent_Mode_Error (Expect : Name_Id); |
| 30031 |
-- Issue a common error message for all mode mismatches. Expect |
| 30032 |
-- denotes the expected mode. |
| 30033 |
|
| 30034 |
----------------------------- |
| 30035 |
-- Inconsistent_Mode_Error -- |
| 30036 |
----------------------------- |
| 30037 |
|
| 30038 |
procedure Inconsistent_Mode_Error (Expect : Name_Id) is |
| 30039 |
begin |
| 30040 |
SPARK_Msg_NE |
| 30041 |
("global item & has inconsistent modes", Item, Item_Id); |
| 30042 |
|
| 30043 |
Error_Msg_Name_1 := Global_Mode; |
| 30044 |
Error_Msg_Name_2 := Expect; |
| 30045 |
SPARK_Msg_N ("\expected mode %, found mode %", Item); |
| 30046 |
end Inconsistent_Mode_Error; |
| 30047 |
|
| 30048 |
-- Local variables |
| 30049 |
|
| 30050 |
Enc_State : Entity_Id := Empty; |
| 30051 |
-- Encapsulating state for constituent, Empty otherwise |
| 30052 |
|
| 30053 |
-- Start of processing for Check_Refined_Global_Item |
| 30054 |
|
| 30055 |
begin |
| 30056 |
if Ekind (Item_Id) in E_Abstract_State | E_Constant | E_Variable |
| 30057 |
then |
| 30058 |
Enc_State := Find_Encapsulating_State (States, Item_Id); |
| 30059 |
end if; |
| 30060 |
|
| 30061 |
-- When the state or object acts as a constituent of another |
| 30062 |
-- state with a visible refinement, collect it for the state |
| 30063 |
-- completeness checks performed later on. Note that the item |
| 30064 |
-- acts as a constituent only when the encapsulating state is |
| 30065 |
-- present in pragma Global. |
| 30066 |
|
| 30067 |
if Present (Enc_State) |
| 30068 |
and then (Has_Visible_Refinement (Enc_State) |
| 30069 |
or else Has_Partial_Visible_Refinement (Enc_State)) |
| 30070 |
and then Contains (States, Enc_State) |
| 30071 |
then |
| 30072 |
-- If the state has only partial visible refinement, remove it |
| 30073 |
-- from the list of items that should be repeated from pragma |
| 30074 |
-- Global. |
| 30075 |
|
| 30076 |
if not Has_Visible_Refinement (Enc_State) then |
| 30077 |
Present_Then_Remove (Repeat_Items, Enc_State); |
| 30078 |
end if; |
| 30079 |
|
| 30080 |
if Global_Mode = Name_Input then |
| 30081 |
Append_New_Elmt (Item_Id, In_Constits); |
| 30082 |
|
| 30083 |
elsif Global_Mode = Name_In_Out then |
| 30084 |
Append_New_Elmt (Item_Id, In_Out_Constits); |
| 30085 |
|
| 30086 |
elsif Global_Mode = Name_Output then |
| 30087 |
Append_New_Elmt (Item_Id, Out_Constits); |
| 30088 |
|
| 30089 |
elsif Global_Mode = Name_Proof_In then |
| 30090 |
Append_New_Elmt (Item_Id, Proof_In_Constits); |
| 30091 |
end if; |
| 30092 |
|
| 30093 |
-- When not a constituent, ensure that both occurrences of the |
| 30094 |
-- item in pragmas Global and Refined_Global match. Also remove |
| 30095 |
-- it when present from the list of items that should be repeated |
| 30096 |
-- from pragma Global. |
| 30097 |
|
| 30098 |
else |
| 30099 |
Present_Then_Remove (Repeat_Items, Item_Id); |
| 30100 |
|
| 30101 |
if Contains (In_Items, Item_Id) then |
| 30102 |
if Global_Mode /= Name_Input then |
| 30103 |
Inconsistent_Mode_Error (Name_Input); |
| 30104 |
end if; |
| 30105 |
|
| 30106 |
elsif Contains (In_Out_Items, Item_Id) then |
| 30107 |
if Global_Mode /= Name_In_Out then |
| 30108 |
Inconsistent_Mode_Error (Name_In_Out); |
| 30109 |
end if; |
| 30110 |
|
| 30111 |
elsif Contains (Out_Items, Item_Id) then |
| 30112 |
if Global_Mode /= Name_Output then |
| 30113 |
Inconsistent_Mode_Error (Name_Output); |
| 30114 |
end if; |
| 30115 |
|
| 30116 |
elsif Contains (Proof_In_Items, Item_Id) then |
| 30117 |
null; |
| 30118 |
|
| 30119 |
-- The item does not appear in the corresponding Global pragma, |
| 30120 |
-- it must be an extra (SPARK RM 7.2.4(3)). |
| 30121 |
|
| 30122 |
else |
| 30123 |
pragma Assert (Present (Global)); |
| 30124 |
Error_Msg_Sloc := Sloc (Global); |
| 30125 |
SPARK_Msg_NE |
| 30126 |
("extra global item & does not refine or repeat any " |
| 30127 |
& "global item #", Item, Item_Id); |
| 30128 |
end if; |
| 30129 |
end if; |
| 30130 |
end Check_Refined_Global_Item; |
| 30131 |
|
| 30132 |
-- Local variables |
| 30133 |
|
| 30134 |
Item : Node_Id; |
| 30135 |
|
| 30136 |
-- Start of processing for Check_Refined_Global_List |
| 30137 |
|
| 30138 |
begin |
| 30139 |
if Nkind (List) = N_Null then |
| 30140 |
null; |
| 30141 |
|
| 30142 |
-- Single global item declaration |
| 30143 |
|
| 30144 |
elsif Nkind (List) in N_Expanded_Name |
| 30145 |
| N_Identifier |
| 30146 |
| N_Selected_Component |
| 30147 |
then |
| 30148 |
Check_Refined_Global_Item (List, Global_Mode); |
| 30149 |
|
| 30150 |
-- Simple global list or moded global list declaration |
| 30151 |
|
| 30152 |
elsif Nkind (List) = N_Aggregate then |
| 30153 |
|
| 30154 |
-- The declaration of a simple global list appear as a collection |
| 30155 |
-- of expressions. |
| 30156 |
|
| 30157 |
if Present (Expressions (List)) then |
| 30158 |
Item := First (Expressions (List)); |
| 30159 |
while Present (Item) loop |
| 30160 |
Check_Refined_Global_Item (Item, Global_Mode); |
| 30161 |
Next (Item); |
| 30162 |
end loop; |
| 30163 |
|
| 30164 |
-- The declaration of a moded global list appears as a collection |
| 30165 |
-- of component associations where individual choices denote |
| 30166 |
-- modes. |
| 30167 |
|
| 30168 |
elsif Present (Component_Associations (List)) then |
| 30169 |
Item := First (Component_Associations (List)); |
| 30170 |
while Present (Item) loop |
| 30171 |
Check_Refined_Global_List |
| 30172 |
(List => Expression (Item), |
| 30173 |
Global_Mode => Chars (First (Choices (Item)))); |
| 30174 |
|
| 30175 |
Next (Item); |
| 30176 |
end loop; |
| 30177 |
|
| 30178 |
-- Invalid tree |
| 30179 |
|
| 30180 |
else |
| 30181 |
raise Program_Error; |
| 30182 |
end if; |
| 30183 |
|
| 30184 |
-- Invalid list |
| 30185 |
|
| 30186 |
else |
| 30187 |
raise Program_Error; |
| 30188 |
end if; |
| 30189 |
end Check_Refined_Global_List; |
| 30190 |
|
| 30191 |
-------------------------- |
| 30192 |
-- Collect_Global_Items -- |
| 30193 |
-------------------------- |
| 30194 |
|
| 30195 |
procedure Collect_Global_Items |
| 30196 |
(List : Node_Id; |
| 30197 |
Mode : Name_Id := Name_Input) |
| 30198 |
is |
| 30199 |
procedure Collect_Global_Item |
| 30200 |
(Item : Node_Id; |
| 30201 |
Item_Mode : Name_Id); |
| 30202 |
-- Add a single item to the appropriate list. Item_Mode denotes the |
| 30203 |
-- current mode in effect. |
| 30204 |
|
| 30205 |
------------------------- |
| 30206 |
-- Collect_Global_Item -- |
| 30207 |
------------------------- |
| 30208 |
|
| 30209 |
procedure Collect_Global_Item |
| 30210 |
(Item : Node_Id; |
| 30211 |
Item_Mode : Name_Id) |
| 30212 |
is |
| 30213 |
Item_Id : constant Entity_Id := Available_View (Entity_Of (Item)); |
| 30214 |
-- The above handles abstract views of variables and states built |
| 30215 |
-- for limited with clauses. |
| 30216 |
|
| 30217 |
begin |
| 30218 |
-- Signal that the global list contains at least one abstract |
| 30219 |
-- state with a visible refinement. Note that the refinement may |
| 30220 |
-- be null in which case there are no constituents. |
| 30221 |
|
| 30222 |
if Ekind (Item_Id) = E_Abstract_State then |
| 30223 |
if Has_Null_Visible_Refinement (Item_Id) then |
| 30224 |
Has_Null_State := True; |
| 30225 |
|
| 30226 |
elsif Has_Non_Null_Visible_Refinement (Item_Id) then |
| 30227 |
Append_New_Elmt (Item_Id, States); |
| 30228 |
|
| 30229 |
if Item_Mode = Name_Input then |
| 30230 |
Has_In_State := True; |
| 30231 |
elsif Item_Mode = Name_In_Out then |
| 30232 |
Has_In_Out_State := True; |
| 30233 |
elsif Item_Mode = Name_Output then |
| 30234 |
Has_Out_State := True; |
| 30235 |
elsif Item_Mode = Name_Proof_In then |
| 30236 |
Has_Proof_In_State := True; |
| 30237 |
end if; |
| 30238 |
end if; |
| 30239 |
end if; |
| 30240 |
|
| 30241 |
-- Record global items without full visible refinement found in |
| 30242 |
-- pragma Global which should be repeated in the global refinement |
| 30243 |
-- (SPARK RM 7.2.4(3c), SPARK RM 7.2.4(3d)). |
| 30244 |
|
| 30245 |
if Ekind (Item_Id) /= E_Abstract_State |
| 30246 |
or else not Has_Visible_Refinement (Item_Id) |
| 30247 |
then |
| 30248 |
Append_New_Elmt (Item_Id, Repeat_Items); |
| 30249 |
end if; |
| 30250 |
|
| 30251 |
-- Add the item to the proper list |
| 30252 |
|
| 30253 |
if Item_Mode = Name_Input then |
| 30254 |
Append_New_Elmt (Item_Id, In_Items); |
| 30255 |
elsif Item_Mode = Name_In_Out then |
| 30256 |
Append_New_Elmt (Item_Id, In_Out_Items); |
| 30257 |
elsif Item_Mode = Name_Output then |
| 30258 |
Append_New_Elmt (Item_Id, Out_Items); |
| 30259 |
elsif Item_Mode = Name_Proof_In then |
| 30260 |
Append_New_Elmt (Item_Id, Proof_In_Items); |
| 30261 |
end if; |
| 30262 |
end Collect_Global_Item; |
| 30263 |
|
| 30264 |
-- Local variables |
| 30265 |
|
| 30266 |
Item : Node_Id; |
| 30267 |
|
| 30268 |
-- Start of processing for Collect_Global_Items |
| 30269 |
|
| 30270 |
begin |
| 30271 |
if Nkind (List) = N_Null then |
| 30272 |
null; |
| 30273 |
|
| 30274 |
-- Single global item declaration |
| 30275 |
|
| 30276 |
elsif Nkind (List) in N_Expanded_Name |
| 30277 |
| N_Identifier |
| 30278 |
| N_Selected_Component |
| 30279 |
then |
| 30280 |
Collect_Global_Item (List, Mode); |
| 30281 |
|
| 30282 |
-- Single global list or moded global list declaration |
| 30283 |
|
| 30284 |
elsif Nkind (List) = N_Aggregate then |
| 30285 |
|
| 30286 |
-- The declaration of a simple global list appear as a collection |
| 30287 |
-- of expressions. |
| 30288 |
|
| 30289 |
if Present (Expressions (List)) then |
| 30290 |
Item := First (Expressions (List)); |
| 30291 |
while Present (Item) loop |
| 30292 |
Collect_Global_Item (Item, Mode); |
| 30293 |
Next (Item); |
| 30294 |
end loop; |
| 30295 |
|
| 30296 |
-- The declaration of a moded global list appears as a collection |
| 30297 |
-- of component associations where individual choices denote mode. |
| 30298 |
|
| 30299 |
elsif Present (Component_Associations (List)) then |
| 30300 |
Item := First (Component_Associations (List)); |
| 30301 |
while Present (Item) loop |
| 30302 |
Collect_Global_Items |
| 30303 |
(List => Expression (Item), |
| 30304 |
Mode => Chars (First (Choices (Item)))); |
| 30305 |
|
| 30306 |
Next (Item); |
| 30307 |
end loop; |
| 30308 |
|
| 30309 |
-- Invalid tree |
| 30310 |
|
| 30311 |
else |
| 30312 |
raise Program_Error; |
| 30313 |
end if; |
| 30314 |
|
| 30315 |
-- To accommodate partial decoration of disabled SPARK features, this |
| 30316 |
-- routine may be called with illegal input. If this is the case, do |
| 30317 |
-- not raise Program_Error. |
| 30318 |
|
| 30319 |
else |
| 30320 |
null; |
| 30321 |
end if; |
| 30322 |
end Collect_Global_Items; |
| 30323 |
|
| 30324 |
------------------------- |
| 30325 |
-- Present_Then_Remove -- |
| 30326 |
------------------------- |
| 30327 |
|
| 30328 |
function Present_Then_Remove |
| 30329 |
(List : Elist_Id; |
| 30330 |
Item : Entity_Id) return Boolean |
| 30331 |
is |
| 30332 |
Elmt : Elmt_Id; |
| 30333 |
|
| 30334 |
begin |
| 30335 |
if Present (List) then |
| 30336 |
Elmt := First_Elmt (List); |
| 30337 |
while Present (Elmt) loop |
| 30338 |
if Node (Elmt) = Item then |
| 30339 |
Remove_Elmt (List, Elmt); |
| 30340 |
return True; |
| 30341 |
end if; |
| 30342 |
|
| 30343 |
Next_Elmt (Elmt); |
| 30344 |
end loop; |
| 30345 |
end if; |
| 30346 |
|
| 30347 |
return False; |
| 30348 |
end Present_Then_Remove; |
| 30349 |
|
| 30350 |
procedure Present_Then_Remove (List : Elist_Id; Item : Entity_Id) is |
| 30351 |
Ignore : Boolean; |
| 30352 |
begin |
| 30353 |
Ignore := Present_Then_Remove (List, Item); |
| 30354 |
end Present_Then_Remove; |
| 30355 |
|
| 30356 |
------------------------------- |
| 30357 |
-- Report_Extra_Constituents -- |
| 30358 |
------------------------------- |
| 30359 |
|
| 30360 |
procedure Report_Extra_Constituents is |
| 30361 |
procedure Report_Extra_Constituents_In_List (List : Elist_Id); |
| 30362 |
-- Emit an error for every element of List |
| 30363 |
|
| 30364 |
--------------------------------------- |
| 30365 |
-- Report_Extra_Constituents_In_List -- |
| 30366 |
--------------------------------------- |
| 30367 |
|
| 30368 |
procedure Report_Extra_Constituents_In_List (List : Elist_Id) is |
| 30369 |
Constit_Elmt : Elmt_Id; |
| 30370 |
|
| 30371 |
begin |
| 30372 |
if Present (List) then |
| 30373 |
Constit_Elmt := First_Elmt (List); |
| 30374 |
while Present (Constit_Elmt) loop |
| 30375 |
SPARK_Msg_NE ("extra constituent &", N, Node (Constit_Elmt)); |
| 30376 |
Next_Elmt (Constit_Elmt); |
| 30377 |
end loop; |
| 30378 |
end if; |
| 30379 |
end Report_Extra_Constituents_In_List; |
| 30380 |
|
| 30381 |
-- Start of processing for Report_Extra_Constituents |
| 30382 |
|
| 30383 |
begin |
| 30384 |
Report_Extra_Constituents_In_List (In_Constits); |
| 30385 |
Report_Extra_Constituents_In_List (In_Out_Constits); |
| 30386 |
Report_Extra_Constituents_In_List (Out_Constits); |
| 30387 |
Report_Extra_Constituents_In_List (Proof_In_Constits); |
| 30388 |
end Report_Extra_Constituents; |
| 30389 |
|
| 30390 |
-------------------------- |
| 30391 |
-- Report_Missing_Items -- |
| 30392 |
-------------------------- |
| 30393 |
|
| 30394 |
procedure Report_Missing_Items is |
| 30395 |
Item_Elmt : Elmt_Id; |
| 30396 |
Item_Id : Entity_Id; |
| 30397 |
|
| 30398 |
begin |
| 30399 |
if Present (Repeat_Items) then |
| 30400 |
Item_Elmt := First_Elmt (Repeat_Items); |
| 30401 |
while Present (Item_Elmt) loop |
| 30402 |
Item_Id := Node (Item_Elmt); |
| 30403 |
SPARK_Msg_NE ("missing global item &", N, Item_Id); |
| 30404 |
Next_Elmt (Item_Elmt); |
| 30405 |
end loop; |
| 30406 |
end if; |
| 30407 |
end Report_Missing_Items; |
| 30408 |
|
| 30409 |
-- Local variables |
| 30410 |
|
| 30411 |
Body_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 30412 |
Errors : constant Nat := Serious_Errors_Detected; |
| 30413 |
Items : Node_Id; |
| 30414 |
No_Constit : Boolean; |
| 30415 |
|
| 30416 |
-- Start of processing for Analyze_Refined_Global_In_Decl_Part |
| 30417 |
|
| 30418 |
begin |
| 30419 |
-- Do not analyze the pragma multiple times |
| 30420 |
|
| 30421 |
if Is_Analyzed_Pragma (N) then |
| 30422 |
return; |
| 30423 |
end if; |
| 30424 |
|
| 30425 |
Spec_Id := Unique_Defining_Entity (Body_Decl); |
| 30426 |
|
| 30427 |
-- Use the anonymous object as the proper spec when Refined_Global |
| 30428 |
-- applies to the body of a single task type. The object carries the |
| 30429 |
-- proper Chars as well as all non-refined versions of pragmas. |
| 30430 |
|
| 30431 |
if Is_Single_Concurrent_Type (Spec_Id) then |
| 30432 |
Spec_Id := Anonymous_Object (Spec_Id); |
| 30433 |
end if; |
| 30434 |
|
| 30435 |
Global := Get_Pragma (Spec_Id, Pragma_Global); |
| 30436 |
Items := Expression (Get_Argument (N, Spec_Id)); |
| 30437 |
|
| 30438 |
-- The subprogram declaration lacks pragma Global. This renders |
| 30439 |
-- Refined_Global useless as there is nothing to refine. |
| 30440 |
|
| 30441 |
if No (Global) then |
| 30442 |
SPARK_Msg_NE |
| 30443 |
(Fix_Msg (Spec_Id, "useless refinement, declaration of subprogram " |
| 30444 |
& "& lacks aspect or pragma Global"), N, Spec_Id); |
| 30445 |
goto Leave; |
| 30446 |
end if; |
| 30447 |
|
| 30448 |
-- Extract all relevant items from the corresponding Global pragma |
| 30449 |
|
| 30450 |
Collect_Global_Items (Expression (Get_Argument (Global, Spec_Id))); |
| 30451 |
|
| 30452 |
-- Package and subprogram bodies are instantiated individually in |
| 30453 |
-- a separate compiler pass. Due to this mode of instantiation, the |
| 30454 |
-- refinement of a state may no longer be visible when a subprogram |
| 30455 |
-- body contract is instantiated. Since the generic template is legal, |
| 30456 |
-- do not perform this check in the instance to circumvent this oddity. |
| 30457 |
|
| 30458 |
if In_Instance then |
| 30459 |
null; |
| 30460 |
|
| 30461 |
-- Non-instance case |
| 30462 |
|
| 30463 |
else |
| 30464 |
-- The corresponding Global pragma must mention at least one |
| 30465 |
-- state with a visible refinement at the point Refined_Global |
| 30466 |
-- is processed. States with null refinements need Refined_Global |
| 30467 |
-- pragma (SPARK RM 7.2.4(2)). |
| 30468 |
|
| 30469 |
if not Has_In_State |
| 30470 |
and then not Has_In_Out_State |
| 30471 |
and then not Has_Out_State |
| 30472 |
and then not Has_Proof_In_State |
| 30473 |
and then not Has_Null_State |
| 30474 |
then |
| 30475 |
SPARK_Msg_NE |
| 30476 |
(Fix_Msg (Spec_Id, "useless refinement, subprogram & does not " |
| 30477 |
& "depend on abstract state with visible refinement"), |
| 30478 |
N, Spec_Id); |
| 30479 |
goto Leave; |
| 30480 |
|
| 30481 |
-- The global refinement of inputs and outputs cannot be null when |
| 30482 |
-- the corresponding Global pragma contains at least one item except |
| 30483 |
-- in the case where we have states with null refinements. |
| 30484 |
|
| 30485 |
elsif Nkind (Items) = N_Null |
| 30486 |
and then |
| 30487 |
(Present (In_Items) |
| 30488 |
or else Present (In_Out_Items) |
| 30489 |
or else Present (Out_Items) |
| 30490 |
or else Present (Proof_In_Items)) |
| 30491 |
and then not Has_Null_State |
| 30492 |
then |
| 30493 |
SPARK_Msg_NE |
| 30494 |
(Fix_Msg (Spec_Id, "refinement cannot be null, subprogram & has " |
| 30495 |
& "global items"), N, Spec_Id); |
| 30496 |
goto Leave; |
| 30497 |
end if; |
| 30498 |
end if; |
| 30499 |
|
| 30500 |
-- Analyze Refined_Global as if it behaved as a regular pragma Global. |
| 30501 |
-- This ensures that the categorization of all refined global items is |
| 30502 |
-- consistent with their role. |
| 30503 |
|
| 30504 |
Analyze_Global_In_Decl_Part (N); |
| 30505 |
|
| 30506 |
-- Do not perform these checks in an instance because they were already |
| 30507 |
-- performed successfully in the generic template. |
| 30508 |
|
| 30509 |
if In_Instance then |
| 30510 |
goto Leave; |
| 30511 |
end if; |
| 30512 |
|
| 30513 |
-- Perform all refinement checks with respect to completeness and mode |
| 30514 |
-- matching. |
| 30515 |
|
| 30516 |
if Serious_Errors_Detected = Errors then |
| 30517 |
Check_Refined_Global_List (Items); |
| 30518 |
end if; |
| 30519 |
|
| 30520 |
-- Store the information that no constituent is used in the global |
| 30521 |
-- refinement, prior to calling checking procedures which remove items |
| 30522 |
-- from the list of constituents. |
| 30523 |
|
| 30524 |
No_Constit := |
| 30525 |
No (In_Constits) |
| 30526 |
and then No (In_Out_Constits) |
| 30527 |
and then No (Out_Constits) |
| 30528 |
and then No (Proof_In_Constits); |
| 30529 |
|
| 30530 |
-- For Input states with visible refinement, at least one constituent |
| 30531 |
-- must be used as an Input in the global refinement. |
| 30532 |
|
| 30533 |
if Serious_Errors_Detected = Errors then |
| 30534 |
Check_Input_States; |
| 30535 |
end if; |
| 30536 |
|
| 30537 |
-- Verify all possible completion variants for In_Out states with |
| 30538 |
-- visible refinement. |
| 30539 |
|
| 30540 |
if Serious_Errors_Detected = Errors then |
| 30541 |
Check_In_Out_States; |
| 30542 |
end if; |
| 30543 |
|
| 30544 |
-- For Output states with visible refinement, all constituents must be |
| 30545 |
-- used as Outputs in the global refinement. |
| 30546 |
|
| 30547 |
if Serious_Errors_Detected = Errors then |
| 30548 |
Check_Output_States; |
| 30549 |
end if; |
| 30550 |
|
| 30551 |
-- For Proof_In states with visible refinement, at least one constituent |
| 30552 |
-- must be used as Proof_In in the global refinement. |
| 30553 |
|
| 30554 |
if Serious_Errors_Detected = Errors then |
| 30555 |
Check_Proof_In_States; |
| 30556 |
end if; |
| 30557 |
|
| 30558 |
-- Emit errors for all constituents that belong to other states with |
| 30559 |
-- visible refinement that do not appear in Global. |
| 30560 |
|
| 30561 |
if Serious_Errors_Detected = Errors then |
| 30562 |
Report_Extra_Constituents; |
| 30563 |
end if; |
| 30564 |
|
| 30565 |
-- Emit errors for all items in Global that are not repeated in the |
| 30566 |
-- global refinement and for which there is no full visible refinement |
| 30567 |
-- and, in the case of states with partial visible refinement, no |
| 30568 |
-- constituent is mentioned in the global refinement. |
| 30569 |
|
| 30570 |
if Serious_Errors_Detected = Errors then |
| 30571 |
Report_Missing_Items; |
| 30572 |
end if; |
| 30573 |
|
| 30574 |
-- Emit an error if no constituent is used in the global refinement |
| 30575 |
-- (SPARK RM 7.2.4(3f)). Emit this error last, in case a more precise |
| 30576 |
-- one may be issued by the checking procedures. Do not perform this |
| 30577 |
-- check in an instance because it was already performed successfully |
| 30578 |
-- in the generic template. |
| 30579 |
|
| 30580 |
if Serious_Errors_Detected = Errors |
| 30581 |
and then not Has_Null_State |
| 30582 |
and then No_Constit |
| 30583 |
then |
| 30584 |
SPARK_Msg_N ("missing refinement", N); |
| 30585 |
end if; |
| 30586 |
|
| 30587 |
<<Leave>> |
| 30588 |
Set_Is_Analyzed_Pragma (N); |
| 30589 |
end Analyze_Refined_Global_In_Decl_Part; |
| 30590 |
|
| 30591 |
---------------------------------------- |
| 30592 |
-- Analyze_Refined_State_In_Decl_Part -- |
| 30593 |
---------------------------------------- |
| 30594 |
|
| 30595 |
procedure Analyze_Refined_State_In_Decl_Part |
| 30596 |
(N : Node_Id; |
| 30597 |
Freeze_Id : Entity_Id := Empty) |
| 30598 |
is |
| 30599 |
Body_Decl : constant Node_Id := Find_Related_Package_Or_Body (N); |
| 30600 |
Body_Id : constant Entity_Id := Defining_Entity (Body_Decl); |
| 30601 |
Spec_Id : constant Entity_Id := Corresponding_Spec (Body_Decl); |
| 30602 |
|
| 30603 |
Available_States : Elist_Id := No_Elist; |
| 30604 |
-- A list of all abstract states defined in the package declaration that |
| 30605 |
-- are available for refinement. The list is used to report unrefined |
| 30606 |
-- states. |
| 30607 |
|
| 30608 |
Body_States : Elist_Id := No_Elist; |
| 30609 |
-- A list of all hidden states that appear in the body of the related |
| 30610 |
-- package. The list is used to report unused hidden states. |
| 30611 |
|
| 30612 |
Constituents_Seen : Elist_Id := No_Elist; |
| 30613 |
-- A list that contains all constituents processed so far. The list is |
| 30614 |
-- used to detect multiple uses of the same constituent. |
| 30615 |
|
| 30616 |
Freeze_Posted : Boolean := False; |
| 30617 |
-- A flag that controls the output of a freezing-related error (see use |
| 30618 |
-- below). |
| 30619 |
|
| 30620 |
Refined_States_Seen : Elist_Id := No_Elist; |
| 30621 |
-- A list that contains all refined states processed so far. The list is |
| 30622 |
-- used to detect duplicate refinements. |
| 30623 |
|
| 30624 |
procedure Analyze_Refinement_Clause (Clause : Node_Id); |
| 30625 |
-- Perform full analysis of a single refinement clause |
| 30626 |
|
| 30627 |
procedure Report_Unrefined_States (States : Elist_Id); |
| 30628 |
-- Emit errors for all unrefined abstract states found in list States |
| 30629 |
|
| 30630 |
------------------------------- |
| 30631 |
-- Analyze_Refinement_Clause -- |
| 30632 |
------------------------------- |
| 30633 |
|
| 30634 |
procedure Analyze_Refinement_Clause (Clause : Node_Id) is |
| 30635 |
AR_Constit : Entity_Id := Empty; |
| 30636 |
AW_Constit : Entity_Id := Empty; |
| 30637 |
ER_Constit : Entity_Id := Empty; |
| 30638 |
EW_Constit : Entity_Id := Empty; |
| 30639 |
-- The entities of external constituents that contain one of the |
| 30640 |
-- following enabled properties: Async_Readers, Async_Writers, |
| 30641 |
-- Effective_Reads and Effective_Writes. |
| 30642 |
|
| 30643 |
External_Constit_Seen : Boolean := False; |
| 30644 |
-- Flag used to mark when at least one external constituent is part |
| 30645 |
-- of the state refinement. |
| 30646 |
|
| 30647 |
Non_Null_Seen : Boolean := False; |
| 30648 |
Null_Seen : Boolean := False; |
| 30649 |
-- Flags used to detect multiple uses of null in a single clause or a |
| 30650 |
-- mixture of null and non-null constituents. |
| 30651 |
|
| 30652 |
Part_Of_Constits : Elist_Id := No_Elist; |
| 30653 |
-- A list of all candidate constituents subject to indicator Part_Of |
| 30654 |
-- where the encapsulating state is the current state. |
| 30655 |
|
| 30656 |
State : Node_Id; |
| 30657 |
State_Id : Entity_Id; |
| 30658 |
-- The current state being refined |
| 30659 |
|
| 30660 |
procedure Analyze_Constituent (Constit : Node_Id); |
| 30661 |
-- Perform full analysis of a single constituent |
| 30662 |
|
| 30663 |
procedure Check_External_Property |
| 30664 |
(Prop_Nam : Name_Id; |
| 30665 |
Enabled : Boolean; |
| 30666 |
Constit : Entity_Id); |
| 30667 |
-- Determine whether a property denoted by name Prop_Nam is present |
| 30668 |
-- in the refined state. Emit an error if this is not the case. Flag |
| 30669 |
-- Enabled should be set when the property applies to the refined |
| 30670 |
-- state. Constit denotes the constituent (if any) which introduces |
| 30671 |
-- the property in the refinement. |
| 30672 |
|
| 30673 |
procedure Match_State; |
| 30674 |
-- Determine whether the state being refined appears in list |
| 30675 |
-- Available_States. Emit an error when attempting to re-refine the |
| 30676 |
-- state or when the state is not defined in the package declaration, |
| 30677 |
-- otherwise remove the state from Available_States. |
| 30678 |
|
| 30679 |
procedure Report_Unused_Constituents (Constits : Elist_Id); |
| 30680 |
-- Emit errors for all unused Part_Of constituents in list Constits |
| 30681 |
|
| 30682 |
------------------------- |
| 30683 |
-- Analyze_Constituent -- |
| 30684 |
------------------------- |
| 30685 |
|
| 30686 |
procedure Analyze_Constituent (Constit : Node_Id) is |
| 30687 |
procedure Match_Constituent (Constit_Id : Entity_Id); |
| 30688 |
-- Determine whether constituent Constit denoted by its entity |
| 30689 |
-- Constit_Id appears in Body_States. Emit an error when the |
| 30690 |
-- constituent is not a valid hidden state of the related package |
| 30691 |
-- or when it is used more than once. Otherwise remove the |
| 30692 |
-- constituent from Body_States. |
| 30693 |
|
| 30694 |
----------------------- |
| 30695 |
-- Match_Constituent -- |
| 30696 |
----------------------- |
| 30697 |
|
| 30698 |
procedure Match_Constituent (Constit_Id : Entity_Id) is |
| 30699 |
procedure Collect_Constituent; |
| 30700 |
-- Verify the legality of constituent Constit_Id and add it to |
| 30701 |
-- the refinements of State_Id. |
| 30702 |
|
| 30703 |
------------------------- |
| 30704 |
-- Collect_Constituent -- |
| 30705 |
------------------------- |
| 30706 |
|
| 30707 |
procedure Collect_Constituent is |
| 30708 |
Constits : Elist_Id; |
| 30709 |
|
| 30710 |
begin |
| 30711 |
-- The Ghost policy in effect at the point of abstract state |
| 30712 |
-- declaration and constituent must match (SPARK RM 6.9(17)) |
| 30713 |
|
| 30714 |
Check_Ghost_Refinement |
| 30715 |
(State, State_Id, Constit, Constit_Id); |
| 30716 |
|
| 30717 |
-- A synchronized state must be refined by a synchronized |
| 30718 |
-- object or another synchronized state (SPARK RM 9.6). |
| 30719 |
|
| 30720 |
if Is_Synchronized_State (State_Id) |
| 30721 |
and then not Is_Synchronized_Object (Constit_Id) |
| 30722 |
and then not Is_Synchronized_State (Constit_Id) |
| 30723 |
then |
| 30724 |
SPARK_Msg_NE |
| 30725 |
("constituent of synchronized state & must be " |
| 30726 |
& "synchronized", Constit, State_Id); |
| 30727 |
end if; |
| 30728 |
|
| 30729 |
-- Add the constituent to the list of processed items to aid |
| 30730 |
-- with the detection of duplicates. |
| 30731 |
|
| 30732 |
Append_New_Elmt (Constit_Id, Constituents_Seen); |
| 30733 |
|
| 30734 |
-- Collect the constituent in the list of refinement items |
| 30735 |
-- and establish a relation between the refined state and |
| 30736 |
-- the item. |
| 30737 |
|
| 30738 |
Constits := Refinement_Constituents (State_Id); |
| 30739 |
|
| 30740 |
if No (Constits) then |
| 30741 |
Constits := New_Elmt_List; |
| 30742 |
Set_Refinement_Constituents (State_Id, Constits); |
| 30743 |
end if; |
| 30744 |
|
| 30745 |
Append_Elmt (Constit_Id, Constits); |
| 30746 |
Set_Encapsulating_State (Constit_Id, State_Id); |
| 30747 |
|
| 30748 |
-- The state has at least one legal constituent, mark the |
| 30749 |
-- start of the refinement region. The region ends when the |
| 30750 |
-- body declarations end (see routine Analyze_Declarations). |
| 30751 |
|
| 30752 |
Set_Has_Visible_Refinement (State_Id); |
| 30753 |
|
| 30754 |
-- When the constituent is external, save its relevant |
| 30755 |
-- property for further checks. |
| 30756 |
|
| 30757 |
if Async_Readers_Enabled (Constit_Id) then |
| 30758 |
AR_Constit := Constit_Id; |
| 30759 |
External_Constit_Seen := True; |
| 30760 |
end if; |
| 30761 |
|
| 30762 |
if Async_Writers_Enabled (Constit_Id) then |
| 30763 |
AW_Constit := Constit_Id; |
| 30764 |
External_Constit_Seen := True; |
| 30765 |
end if; |
| 30766 |
|
| 30767 |
if Effective_Reads_Enabled (Constit_Id) then |
| 30768 |
ER_Constit := Constit_Id; |
| 30769 |
External_Constit_Seen := True; |
| 30770 |
end if; |
| 30771 |
|
| 30772 |
if Effective_Writes_Enabled (Constit_Id) then |
| 30773 |
EW_Constit := Constit_Id; |
| 30774 |
External_Constit_Seen := True; |
| 30775 |
end if; |
| 30776 |
end Collect_Constituent; |
| 30777 |
|
| 30778 |
-- Local variables |
| 30779 |
|
| 30780 |
State_Elmt : Elmt_Id; |
| 30781 |
|
| 30782 |
-- Start of processing for Match_Constituent |
| 30783 |
|
| 30784 |
begin |
| 30785 |
-- Detect a duplicate use of a constituent |
| 30786 |
|
| 30787 |
if Contains (Constituents_Seen, Constit_Id) then |
| 30788 |
SPARK_Msg_NE |
| 30789 |
("duplicate use of constituent &", Constit, Constit_Id); |
| 30790 |
return; |
| 30791 |
end if; |
| 30792 |
|
| 30793 |
-- The constituent is subject to a Part_Of indicator |
| 30794 |
|
| 30795 |
if Present (Encapsulating_State (Constit_Id)) then |
| 30796 |
if Encapsulating_State (Constit_Id) = State_Id then |
| 30797 |
Remove (Part_Of_Constits, Constit_Id); |
| 30798 |
Collect_Constituent; |
| 30799 |
|
| 30800 |
-- The constituent is part of another state and is used |
| 30801 |
-- incorrectly in the refinement of the current state. |
| 30802 |
|
| 30803 |
else |
| 30804 |
Error_Msg_Name_1 := Chars (State_Id); |
| 30805 |
SPARK_Msg_NE |
| 30806 |
("& cannot act as constituent of state %", |
| 30807 |
Constit, Constit_Id); |
| 30808 |
SPARK_Msg_NE |
| 30809 |
("\Part_Of indicator specifies encapsulator &", |
| 30810 |
Constit, Encapsulating_State (Constit_Id)); |
| 30811 |
end if; |
| 30812 |
|
| 30813 |
else |
| 30814 |
declare |
| 30815 |
Pack_Id : Entity_Id; |
| 30816 |
Placement : State_Space_Kind; |
| 30817 |
begin |
| 30818 |
-- Find where the constituent lives with respect to the |
| 30819 |
-- state space. |
| 30820 |
|
| 30821 |
Find_Placement_In_State_Space |
| 30822 |
(Item_Id => Constit_Id, |
| 30823 |
Placement => Placement, |
| 30824 |
Pack_Id => Pack_Id); |
| 30825 |
|
| 30826 |
-- The constituent is either part of the hidden state of |
| 30827 |
-- the package or part of the visible state of a private |
| 30828 |
-- child package, but lacks a Part_Of indicator. |
| 30829 |
|
| 30830 |
if (Placement = Private_State_Space |
| 30831 |
and then Pack_Id = Spec_Id) |
| 30832 |
or else |
| 30833 |
(Placement = Visible_State_Space |
| 30834 |
and then Is_Child_Unit (Pack_Id) |
| 30835 |
and then not Is_Generic_Unit (Pack_Id) |
| 30836 |
and then Is_Private_Descendant (Pack_Id)) |
| 30837 |
then |
| 30838 |
Error_Msg_Name_1 := Chars (State_Id); |
| 30839 |
SPARK_Msg_NE |
| 30840 |
("& cannot act as constituent of state %", |
| 30841 |
Constit, Constit_Id); |
| 30842 |
Error_Msg_Sloc := |
| 30843 |
Sloc (Enclosing_Declaration (Constit_Id)); |
| 30844 |
SPARK_Msg_NE |
| 30845 |
("\missing Part_Of indicator # should specify " |
| 30846 |
& "encapsulator &", |
| 30847 |
Constit, State_Id); |
| 30848 |
|
| 30849 |
-- The only other source of legal constituents is the |
| 30850 |
-- body state space of the related package. |
| 30851 |
|
| 30852 |
else |
| 30853 |
if Present (Body_States) then |
| 30854 |
State_Elmt := First_Elmt (Body_States); |
| 30855 |
while Present (State_Elmt) loop |
| 30856 |
|
| 30857 |
-- Consume a valid constituent to signal that it |
| 30858 |
-- has been encountered. |
| 30859 |
|
| 30860 |
if Node (State_Elmt) = Constit_Id then |
| 30861 |
Remove_Elmt (Body_States, State_Elmt); |
| 30862 |
Collect_Constituent; |
| 30863 |
return; |
| 30864 |
end if; |
| 30865 |
|
| 30866 |
Next_Elmt (State_Elmt); |
| 30867 |
end loop; |
| 30868 |
end if; |
| 30869 |
|
| 30870 |
-- At this point it is known that the constituent is |
| 30871 |
-- not part of the package hidden state and cannot be |
| 30872 |
-- used in a refinement (SPARK RM 7.2.2(9)). |
| 30873 |
|
| 30874 |
Error_Msg_Name_1 := Chars (Spec_Id); |
| 30875 |
SPARK_Msg_NE |
| 30876 |
("cannot use & in refinement, constituent is not a " |
| 30877 |
& "hidden state of package %", Constit, Constit_Id); |
| 30878 |
end if; |
| 30879 |
end; |
| 30880 |
end if; |
| 30881 |
end Match_Constituent; |
| 30882 |
|
| 30883 |
-- Local variables |
| 30884 |
|
| 30885 |
Constit_Id : Entity_Id; |
| 30886 |
Constits : Elist_Id; |
| 30887 |
|
| 30888 |
-- Start of processing for Analyze_Constituent |
| 30889 |
|
| 30890 |
begin |
| 30891 |
-- Detect multiple uses of null in a single refinement clause or a |
| 30892 |
-- mixture of null and non-null constituents. |
| 30893 |
|
| 30894 |
if Nkind (Constit) = N_Null then |
| 30895 |
if Null_Seen then |
| 30896 |
SPARK_Msg_N |
| 30897 |
("multiple null constituents not allowed", Constit); |
| 30898 |
|
| 30899 |
elsif Non_Null_Seen then |
| 30900 |
SPARK_Msg_N |
| 30901 |
("cannot mix null and non-null constituents", Constit); |
| 30902 |
|
| 30903 |
else |
| 30904 |
Null_Seen := True; |
| 30905 |
|
| 30906 |
-- Collect the constituent in the list of refinement items |
| 30907 |
|
| 30908 |
Constits := Refinement_Constituents (State_Id); |
| 30909 |
|
| 30910 |
if No (Constits) then |
| 30911 |
Constits := New_Elmt_List; |
| 30912 |
Set_Refinement_Constituents (State_Id, Constits); |
| 30913 |
end if; |
| 30914 |
|
| 30915 |
Append_Elmt (Constit, Constits); |
| 30916 |
|
| 30917 |
-- The state has at least one legal constituent, mark the |
| 30918 |
-- start of the refinement region. The region ends when the |
| 30919 |
-- body declarations end (see Analyze_Declarations). |
| 30920 |
|
| 30921 |
Set_Has_Visible_Refinement (State_Id); |
| 30922 |
end if; |
| 30923 |
|
| 30924 |
-- Non-null constituents |
| 30925 |
|
| 30926 |
else |
| 30927 |
Non_Null_Seen := True; |
| 30928 |
|
| 30929 |
if Null_Seen then |
| 30930 |
SPARK_Msg_N |
| 30931 |
("cannot mix null and non-null constituents", Constit); |
| 30932 |
end if; |
| 30933 |
|
| 30934 |
Analyze (Constit); |
| 30935 |
Resolve_State (Constit); |
| 30936 |
|
| 30937 |
-- Ensure that the constituent denotes a valid state or a |
| 30938 |
-- whole object (SPARK RM 7.2.2(5)). |
| 30939 |
|
| 30940 |
if Is_Entity_Name (Constit) then |
| 30941 |
Constit_Id := Entity_Of (Constit); |
| 30942 |
|
| 30943 |
-- When a constituent is declared after a subprogram body |
| 30944 |
-- that caused freezing of the related contract where |
| 30945 |
-- pragma Refined_State resides, the constituent appears |
| 30946 |
-- undefined and carries Any_Id as its entity. |
| 30947 |
|
| 30948 |
-- package body Pack |
| 30949 |
-- with Refined_State => (State => Constit) |
| 30950 |
-- is |
| 30951 |
-- procedure Proc |
| 30952 |
-- with Refined_Global => (Input => Constit) |
| 30953 |
-- is |
| 30954 |
-- ... |
| 30955 |
-- end Proc; |
| 30956 |
|
| 30957 |
-- Constit : ...; |
| 30958 |
-- end Pack; |
| 30959 |
|
| 30960 |
if Constit_Id = Any_Id then |
| 30961 |
SPARK_Msg_NE ("& is undefined", Constit, Constit_Id); |
| 30962 |
|
| 30963 |
-- Emit a specialized info message when the contract of |
| 30964 |
-- the related package body was "frozen" by another body. |
| 30965 |
-- Note that it is not possible to precisely identify why |
| 30966 |
-- the constituent is undefined because it is not visible |
| 30967 |
-- when pragma Refined_State is analyzed. This message is |
| 30968 |
-- a reasonable approximation. |
| 30969 |
|
| 30970 |
if Present (Freeze_Id) and then not Freeze_Posted then |
| 30971 |
Freeze_Posted := True; |
| 30972 |
|
| 30973 |
Error_Msg_Name_1 := Chars (Body_Id); |
| 30974 |
Error_Msg_Sloc := Sloc (Freeze_Id); |
| 30975 |
SPARK_Msg_NE |
| 30976 |
("body & declared # freezes the contract of %", |
| 30977 |
N, Freeze_Id); |
| 30978 |
SPARK_Msg_N |
| 30979 |
("\all constituents must be declared before body #", |
| 30980 |
N); |
| 30981 |
|
| 30982 |
-- A misplaced constituent is a critical error because |
| 30983 |
-- pragma Refined_Depends or Refined_Global depends on |
| 30984 |
-- the proper link between a state and a constituent. |
| 30985 |
-- Stop the compilation, as this leads to a multitude |
| 30986 |
-- of misleading cascaded errors. |
| 30987 |
|
| 30988 |
raise Unrecoverable_Error; |
| 30989 |
end if; |
| 30990 |
|
| 30991 |
-- The constituent is a valid state or object |
| 30992 |
|
| 30993 |
elsif Ekind (Constit_Id) in |
| 30994 |
E_Abstract_State | E_Constant | E_Variable |
| 30995 |
then |
| 30996 |
Match_Constituent (Constit_Id); |
| 30997 |
|
| 30998 |
-- The variable may eventually become a constituent of a |
| 30999 |
-- single protected/task type. Record the reference now |
| 31000 |
-- and verify its legality when analyzing the contract of |
| 31001 |
-- the variable (SPARK RM 9.3). |
| 31002 |
|
| 31003 |
if Ekind (Constit_Id) = E_Variable then |
| 31004 |
Record_Possible_Part_Of_Reference |
| 31005 |
(Var_Id => Constit_Id, |
| 31006 |
Ref => Constit); |
| 31007 |
end if; |
| 31008 |
|
| 31009 |
-- Otherwise the constituent is illegal |
| 31010 |
|
| 31011 |
else |
| 31012 |
SPARK_Msg_NE |
| 31013 |
("constituent & must denote object or state", |
| 31014 |
Constit, Constit_Id); |
| 31015 |
end if; |
| 31016 |
|
| 31017 |
-- The constituent is illegal |
| 31018 |
|
| 31019 |
else |
| 31020 |
SPARK_Msg_N ("malformed constituent", Constit); |
| 31021 |
end if; |
| 31022 |
end if; |
| 31023 |
end Analyze_Constituent; |
| 31024 |
|
| 31025 |
----------------------------- |
| 31026 |
-- Check_External_Property -- |
| 31027 |
----------------------------- |
| 31028 |
|
| 31029 |
procedure Check_External_Property |
| 31030 |
(Prop_Nam : Name_Id; |
| 31031 |
Enabled : Boolean; |
| 31032 |
Constit : Entity_Id) |
| 31033 |
is |
| 31034 |
begin |
| 31035 |
-- The property is missing in the declaration of the state, but |
| 31036 |
-- a constituent is introducing it in the state refinement |
| 31037 |
-- (SPARK RM 7.2.8(2)). |
| 31038 |
|
| 31039 |
if not Enabled and then Present (Constit) then |
| 31040 |
Error_Msg_Name_1 := Prop_Nam; |
| 31041 |
Error_Msg_Name_2 := Chars (State_Id); |
| 31042 |
SPARK_Msg_NE |
| 31043 |
("constituent & introduces external property % in refinement " |
| 31044 |
& "of state %", State, Constit); |
| 31045 |
|
| 31046 |
Error_Msg_Sloc := Sloc (State_Id); |
| 31047 |
SPARK_Msg_N |
| 31048 |
("\property is missing in abstract state declaration #", |
| 31049 |
State); |
| 31050 |
end if; |
| 31051 |
end Check_External_Property; |
| 31052 |
|
| 31053 |
----------------- |
| 31054 |
-- Match_State -- |
| 31055 |
----------------- |
| 31056 |
|
| 31057 |
procedure Match_State is |
| 31058 |
State_Elmt : Elmt_Id; |
| 31059 |
|
| 31060 |
begin |
| 31061 |
-- Detect a duplicate refinement of a state (SPARK RM 7.2.2(8)) |
| 31062 |
|
| 31063 |
if Contains (Refined_States_Seen, State_Id) then |
| 31064 |
SPARK_Msg_NE |
| 31065 |
("duplicate refinement of state &", State, State_Id); |
| 31066 |
return; |
| 31067 |
end if; |
| 31068 |
|
| 31069 |
-- Inspect the abstract states defined in the package declaration |
| 31070 |
-- looking for a match. |
| 31071 |
|
| 31072 |
State_Elmt := First_Elmt (Available_States); |
| 31073 |
while Present (State_Elmt) loop |
| 31074 |
|
| 31075 |
-- A valid abstract state is being refined in the body. Add |
| 31076 |
-- the state to the list of processed refined states to aid |
| 31077 |
-- with the detection of duplicate refinements. Remove the |
| 31078 |
-- state from Available_States to signal that it has already |
| 31079 |
-- been refined. |
| 31080 |
|
| 31081 |
if Node (State_Elmt) = State_Id then |
| 31082 |
Append_New_Elmt (State_Id, Refined_States_Seen); |
| 31083 |
Remove_Elmt (Available_States, State_Elmt); |
| 31084 |
return; |
| 31085 |
end if; |
| 31086 |
|
| 31087 |
Next_Elmt (State_Elmt); |
| 31088 |
end loop; |
| 31089 |
|
| 31090 |
-- If we get here, we are refining a state that is not defined in |
| 31091 |
-- the package declaration. |
| 31092 |
|
| 31093 |
Error_Msg_Name_1 := Chars (Spec_Id); |
| 31094 |
SPARK_Msg_NE |
| 31095 |
("cannot refine state, & is not defined in package %", |
| 31096 |
State, State_Id); |
| 31097 |
end Match_State; |
| 31098 |
|
| 31099 |
-------------------------------- |
| 31100 |
-- Report_Unused_Constituents -- |
| 31101 |
-------------------------------- |
| 31102 |
|
| 31103 |
procedure Report_Unused_Constituents (Constits : Elist_Id) is |
| 31104 |
Constit_Elmt : Elmt_Id; |
| 31105 |
Constit_Id : Entity_Id; |
| 31106 |
Posted : Boolean := False; |
| 31107 |
|
| 31108 |
begin |
| 31109 |
if Present (Constits) then |
| 31110 |
Constit_Elmt := First_Elmt (Constits); |
| 31111 |
while Present (Constit_Elmt) loop |
| 31112 |
Constit_Id := Node (Constit_Elmt); |
| 31113 |
|
| 31114 |
-- Generate an error message of the form: |
| 31115 |
|
| 31116 |
-- state ... has unused Part_Of constituents |
| 31117 |
-- abstract state ... defined at ... |
| 31118 |
-- constant ... defined at ... |
| 31119 |
-- variable ... defined at ... |
| 31120 |
|
| 31121 |
if not Posted then |
| 31122 |
Posted := True; |
| 31123 |
SPARK_Msg_NE |
| 31124 |
("state & has unused Part_Of constituents", |
| 31125 |
State, State_Id); |
| 31126 |
end if; |
| 31127 |
|
| 31128 |
Error_Msg_Sloc := Sloc (Constit_Id); |
| 31129 |
|
| 31130 |
if Ekind (Constit_Id) = E_Abstract_State then |
| 31131 |
SPARK_Msg_NE |
| 31132 |
("\abstract state & defined #", State, Constit_Id); |
| 31133 |
|
| 31134 |
elsif Ekind (Constit_Id) = E_Constant then |
| 31135 |
SPARK_Msg_NE |
| 31136 |
("\constant & defined #", State, Constit_Id); |
| 31137 |
|
| 31138 |
else |
| 31139 |
pragma Assert (Ekind (Constit_Id) = E_Variable); |
| 31140 |
SPARK_Msg_NE ("\variable & defined #", State, Constit_Id); |
| 31141 |
end if; |
| 31142 |
|
| 31143 |
Next_Elmt (Constit_Elmt); |
| 31144 |
end loop; |
| 31145 |
end if; |
| 31146 |
end Report_Unused_Constituents; |
| 31147 |
|
| 31148 |
-- Local declarations |
| 31149 |
|
| 31150 |
Body_Ref : Node_Id; |
| 31151 |
Body_Ref_Elmt : Elmt_Id; |
| 31152 |
Constit : Node_Id; |
| 31153 |
Extra_State : Node_Id; |
| 31154 |
|
| 31155 |
-- Start of processing for Analyze_Refinement_Clause |
| 31156 |
|
| 31157 |
begin |
| 31158 |
-- A refinement clause appears as a component association where the |
| 31159 |
-- sole choice is the state and the expressions are the constituents. |
| 31160 |
-- This is a syntax error, always report. |
| 31161 |
|
| 31162 |
if Nkind (Clause) /= N_Component_Association then |
| 31163 |
Error_Msg_N ("malformed state refinement clause", Clause); |
| 31164 |
return; |
| 31165 |
end if; |
| 31166 |
|
| 31167 |
-- Analyze the state name of a refinement clause |
| 31168 |
|
| 31169 |
State := First (Choices (Clause)); |
| 31170 |
|
| 31171 |
Analyze (State); |
| 31172 |
Resolve_State (State); |
| 31173 |
|
| 31174 |
-- Ensure that the state name denotes a valid abstract state that is |
| 31175 |
-- defined in the spec of the related package. |
| 31176 |
|
| 31177 |
if Is_Entity_Name (State) then |
| 31178 |
State_Id := Entity_Of (State); |
| 31179 |
|
| 31180 |
-- When the abstract state is undefined, it appears as Any_Id. Do |
| 31181 |
-- not continue with the analysis of the clause. |
| 31182 |
|
| 31183 |
if State_Id = Any_Id then |
| 31184 |
return; |
| 31185 |
|
| 31186 |
-- Catch any attempts to re-refine a state or refine a state that |
| 31187 |
-- is not defined in the package declaration. |
| 31188 |
|
| 31189 |
elsif Ekind (State_Id) = E_Abstract_State then |
| 31190 |
Match_State; |
| 31191 |
|
| 31192 |
else |
| 31193 |
SPARK_Msg_NE ("& must denote abstract state", State, State_Id); |
| 31194 |
return; |
| 31195 |
end if; |
| 31196 |
|
| 31197 |
-- References to a state with visible refinement are illegal. |
| 31198 |
-- When nested packages are involved, detecting such references is |
| 31199 |
-- tricky because pragma Refined_State is analyzed later than the |
| 31200 |
-- offending pragma Depends or Global. References that occur in |
| 31201 |
-- such nested context are stored in a list. Emit errors for all |
| 31202 |
-- references found in Body_References (SPARK RM 6.1.4(8)). |
| 31203 |
|
| 31204 |
if Present (Body_References (State_Id)) then |
| 31205 |
Body_Ref_Elmt := First_Elmt (Body_References (State_Id)); |
| 31206 |
while Present (Body_Ref_Elmt) loop |
| 31207 |
Body_Ref := Node (Body_Ref_Elmt); |
| 31208 |
|
| 31209 |
SPARK_Msg_N ("reference to & not allowed", Body_Ref); |
| 31210 |
Error_Msg_Sloc := Sloc (State); |
| 31211 |
SPARK_Msg_N ("\refinement of & is visible#", Body_Ref); |
| 31212 |
|
| 31213 |
Next_Elmt (Body_Ref_Elmt); |
| 31214 |
end loop; |
| 31215 |
end if; |
| 31216 |
|
| 31217 |
-- The state name is illegal. This is a syntax error, always report. |
| 31218 |
|
| 31219 |
else |
| 31220 |
Error_Msg_N ("malformed state name in refinement clause", State); |
| 31221 |
return; |
| 31222 |
end if; |
| 31223 |
|
| 31224 |
-- A refinement clause may only refine one state at a time |
| 31225 |
|
| 31226 |
Extra_State := Next (State); |
| 31227 |
|
| 31228 |
if Present (Extra_State) then |
| 31229 |
SPARK_Msg_N |
| 31230 |
("refinement clause cannot cover multiple states", Extra_State); |
| 31231 |
end if; |
| 31232 |
|
| 31233 |
-- Replicate the Part_Of constituents of the refined state because |
| 31234 |
-- the algorithm will consume items. |
| 31235 |
|
| 31236 |
Part_Of_Constits := New_Copy_Elist (Part_Of_Constituents (State_Id)); |
| 31237 |
|
| 31238 |
-- Analyze all constituents of the refinement. Multiple constituents |
| 31239 |
-- appear as an aggregate. |
| 31240 |
|
| 31241 |
Constit := Expression (Clause); |
| 31242 |
|
| 31243 |
if Nkind (Constit) = N_Aggregate then |
| 31244 |
if Present (Component_Associations (Constit)) then |
| 31245 |
SPARK_Msg_N |
| 31246 |
("constituents of refinement clause must appear in " |
| 31247 |
& "positional form", Constit); |
| 31248 |
|
| 31249 |
else pragma Assert (Present (Expressions (Constit))); |
| 31250 |
Constit := First (Expressions (Constit)); |
| 31251 |
while Present (Constit) loop |
| 31252 |
Analyze_Constituent (Constit); |
| 31253 |
Next (Constit); |
| 31254 |
end loop; |
| 31255 |
end if; |
| 31256 |
|
| 31257 |
-- Various forms of a single constituent. Note that these may include |
| 31258 |
-- malformed constituents. |
| 31259 |
|
| 31260 |
else |
| 31261 |
Analyze_Constituent (Constit); |
| 31262 |
end if; |
| 31263 |
|
| 31264 |
-- Verify that external constituents do not introduce new external |
| 31265 |
-- property in the state refinement (SPARK RM 7.2.8(2)). |
| 31266 |
|
| 31267 |
if Is_External_State (State_Id) then |
| 31268 |
Check_External_Property |
| 31269 |
(Prop_Nam => Name_Async_Readers, |
| 31270 |
Enabled => Async_Readers_Enabled (State_Id), |
| 31271 |
Constit => AR_Constit); |
| 31272 |
|
| 31273 |
Check_External_Property |
| 31274 |
(Prop_Nam => Name_Async_Writers, |
| 31275 |
Enabled => Async_Writers_Enabled (State_Id), |
| 31276 |
Constit => AW_Constit); |
| 31277 |
|
| 31278 |
Check_External_Property |
| 31279 |
(Prop_Nam => Name_Effective_Reads, |
| 31280 |
Enabled => Effective_Reads_Enabled (State_Id), |
| 31281 |
Constit => ER_Constit); |
| 31282 |
|
| 31283 |
Check_External_Property |
| 31284 |
(Prop_Nam => Name_Effective_Writes, |
| 31285 |
Enabled => Effective_Writes_Enabled (State_Id), |
| 31286 |
Constit => EW_Constit); |
| 31287 |
|
| 31288 |
-- When a refined state is not external, it should not have external |
| 31289 |
-- constituents (SPARK RM 7.2.8(1)). |
| 31290 |
|
| 31291 |
elsif External_Constit_Seen then |
| 31292 |
SPARK_Msg_NE |
| 31293 |
("non-external state & cannot contain external constituents in " |
| 31294 |
& "refinement", State, State_Id); |
| 31295 |
end if; |
| 31296 |
|
| 31297 |
-- Ensure that all Part_Of candidate constituents have been mentioned |
| 31298 |
-- in the refinement clause. |
| 31299 |
|
| 31300 |
Report_Unused_Constituents (Part_Of_Constits); |
| 31301 |
|
| 31302 |
-- Avoid a cascading error reporting a missing refinement by adding a |
| 31303 |
-- dummy constituent. |
| 31304 |
|
| 31305 |
if No (Refinement_Constituents (State_Id)) then |
| 31306 |
Set_Refinement_Constituents (State_Id, New_Elmt_List (Any_Id)); |
| 31307 |
end if; |
| 31308 |
|
| 31309 |
-- At this point the refinement might be dummy, but must be |
| 31310 |
-- well-formed, to prevent cascaded errors. |
| 31311 |
|
| 31312 |
pragma Assert (Has_Null_Refinement (State_Id) |
| 31313 |
xor |
| 31314 |
Has_Non_Null_Refinement (State_Id)); |
| 31315 |
end Analyze_Refinement_Clause; |
| 31316 |
|
| 31317 |
----------------------------- |
| 31318 |
-- Report_Unrefined_States -- |
| 31319 |
----------------------------- |
| 31320 |
|
| 31321 |
procedure Report_Unrefined_States (States : Elist_Id) is |
| 31322 |
State_Elmt : Elmt_Id; |
| 31323 |
|
| 31324 |
begin |
| 31325 |
if Present (States) then |
| 31326 |
State_Elmt := First_Elmt (States); |
| 31327 |
while Present (State_Elmt) loop |
| 31328 |
SPARK_Msg_N |
| 31329 |
("abstract state & must be refined", Node (State_Elmt)); |
| 31330 |
|
| 31331 |
Next_Elmt (State_Elmt); |
| 31332 |
end loop; |
| 31333 |
end if; |
| 31334 |
end Report_Unrefined_States; |
| 31335 |
|
| 31336 |
-- Local declarations |
| 31337 |
|
| 31338 |
Clauses : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
| 31339 |
Clause : Node_Id; |
| 31340 |
|
| 31341 |
-- Start of processing for Analyze_Refined_State_In_Decl_Part |
| 31342 |
|
| 31343 |
begin |
| 31344 |
-- Do not analyze the pragma multiple times |
| 31345 |
|
| 31346 |
if Is_Analyzed_Pragma (N) then |
| 31347 |
return; |
| 31348 |
end if; |
| 31349 |
|
| 31350 |
-- Save the scenario for examination by the ABE Processing phase |
| 31351 |
|
| 31352 |
Record_Elaboration_Scenario (N); |
| 31353 |
|
| 31354 |
-- Replicate the abstract states declared by the package because the |
| 31355 |
-- matching algorithm will consume states. |
| 31356 |
|
| 31357 |
Available_States := New_Copy_Elist (Abstract_States (Spec_Id)); |
| 31358 |
|
| 31359 |
-- Gather all abstract states and objects declared in the visible |
| 31360 |
-- state space of the package body. These items must be utilized as |
| 31361 |
-- constituents in a state refinement. |
| 31362 |
|
| 31363 |
Body_States := Collect_Body_States (Body_Id); |
| 31364 |
|
| 31365 |
-- Multiple non-null state refinements appear as an aggregate |
| 31366 |
|
| 31367 |
if Nkind (Clauses) = N_Aggregate then |
| 31368 |
if Present (Expressions (Clauses)) then |
| 31369 |
SPARK_Msg_N |
| 31370 |
("state refinements must appear as component associations", |
| 31371 |
Clauses); |
| 31372 |
|
| 31373 |
else pragma Assert (Present (Component_Associations (Clauses))); |
| 31374 |
Clause := First (Component_Associations (Clauses)); |
| 31375 |
while Present (Clause) loop |
| 31376 |
Analyze_Refinement_Clause (Clause); |
| 31377 |
Next (Clause); |
| 31378 |
end loop; |
| 31379 |
end if; |
| 31380 |
|
| 31381 |
-- Various forms of a single state refinement. Note that these may |
| 31382 |
-- include malformed refinements. |
| 31383 |
|
| 31384 |
else |
| 31385 |
Analyze_Refinement_Clause (Clauses); |
| 31386 |
end if; |
| 31387 |
|
| 31388 |
-- List all abstract states that were left unrefined |
| 31389 |
|
| 31390 |
Report_Unrefined_States (Available_States); |
| 31391 |
|
| 31392 |
Set_Is_Analyzed_Pragma (N); |
| 31393 |
end Analyze_Refined_State_In_Decl_Part; |
| 31394 |
|
| 31395 |
--------------------------------------------- |
| 31396 |
-- Analyze_Subprogram_Variant_In_Decl_Part -- |
| 31397 |
--------------------------------------------- |
| 31398 |
|
| 31399 |
-- WARNING: This routine manages Ghost regions. Return statements must be |
| 31400 |
-- replaced by gotos which jump to the end of the routine and restore the |
| 31401 |
-- Ghost mode. |
| 31402 |
|
| 31403 |
procedure Analyze_Subprogram_Variant_In_Decl_Part |
| 31404 |
(N : Node_Id; |
| 31405 |
Freeze_Id : Entity_Id := Empty) |
| 31406 |
is |
| 31407 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 31408 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 31409 |
|
| 31410 |
procedure Analyze_Variant (Variant : Node_Id); |
| 31411 |
-- Verify the legality of a single contract case |
| 31412 |
|
| 31413 |
--------------------- |
| 31414 |
-- Analyze_Variant -- |
| 31415 |
--------------------- |
| 31416 |
|
| 31417 |
procedure Analyze_Variant (Variant : Node_Id) is |
| 31418 |
Direction : Node_Id; |
| 31419 |
Expr : Node_Id; |
| 31420 |
Errors : Nat; |
| 31421 |
Extra_Direction : Node_Id; |
| 31422 |
|
| 31423 |
begin |
| 31424 |
if Nkind (Variant) /= N_Component_Association then |
| 31425 |
Error_Msg_N ("wrong syntax in subprogram variant", Variant); |
| 31426 |
return; |
| 31427 |
end if; |
| 31428 |
|
| 31429 |
Direction := First (Choices (Variant)); |
| 31430 |
Expr := Expression (Variant); |
| 31431 |
|
| 31432 |
-- Each variant must have exactly one direction |
| 31433 |
|
| 31434 |
Extra_Direction := Next (Direction); |
| 31435 |
|
| 31436 |
if Present (Extra_Direction) then |
| 31437 |
Error_Msg_N |
| 31438 |
("subprogram variant case must have exactly one direction", |
| 31439 |
Extra_Direction); |
| 31440 |
end if; |
| 31441 |
|
| 31442 |
-- Check placement of OTHERS if available (SPARK RM 6.1.3(1)) |
| 31443 |
|
| 31444 |
if Nkind (Direction) = N_Identifier then |
| 31445 |
if Chars (Direction) not in Name_Decreases |
| 31446 |
| Name_Increases |
| 31447 |
| Name_Structural |
| 31448 |
then |
| 31449 |
Error_Msg_N ("wrong direction", Direction); |
| 31450 |
end if; |
| 31451 |
else |
| 31452 |
Error_Msg_N ("wrong syntax", Direction); |
| 31453 |
end if; |
| 31454 |
|
| 31455 |
Errors := Serious_Errors_Detected; |
| 31456 |
|
| 31457 |
-- Preanalyze_Assert_Expression, but without enforcing any of the |
| 31458 |
-- acceptable types. |
| 31459 |
|
| 31460 |
Preanalyze_Assert_Expression (Expr); |
| 31461 |
|
| 31462 |
-- Expression of a discrete type is allowed. Nothing more to check |
| 31463 |
-- for structural variants. |
| 31464 |
|
| 31465 |
if Is_Discrete_Type (Etype (Expr)) |
| 31466 |
or else Chars (Direction) = Name_Structural |
| 31467 |
then |
| 31468 |
null; |
| 31469 |
|
| 31470 |
-- Expression of a Big_Integer type (or its ghost variant) is only |
| 31471 |
-- allowed in Decreases clause. |
| 31472 |
|
| 31473 |
elsif |
| 31474 |
Is_RTE (Base_Type (Etype (Expr)), RE_Big_Integer) |
| 31475 |
or else |
| 31476 |
Is_RTE (Base_Type (Etype (Expr)), RO_GH_Big_Integer) |
| 31477 |
or else |
| 31478 |
Is_RTE (Base_Type (Etype (Expr)), RO_SP_Big_Integer) |
| 31479 |
then |
| 31480 |
if Chars (Direction) = Name_Increases then |
| 31481 |
Error_Msg_N |
| 31482 |
("Subprogram_Variant with Big_Integer can only decrease", |
| 31483 |
Expr); |
| 31484 |
end if; |
| 31485 |
|
| 31486 |
-- Expression of other types is not allowed |
| 31487 |
|
| 31488 |
else |
| 31489 |
Error_Msg_N ("expected a discrete or Big_Integer type", Expr); |
| 31490 |
end if; |
| 31491 |
|
| 31492 |
-- Emit a clarification message when the variant expression |
| 31493 |
-- contains at least one undefined reference, possibly due |
| 31494 |
-- to contract freezing. |
| 31495 |
|
| 31496 |
if Errors /= Serious_Errors_Detected |
| 31497 |
and then Present (Freeze_Id) |
| 31498 |
and then Has_Undefined_Reference (Expr) |
| 31499 |
then |
| 31500 |
Contract_Freeze_Error (Spec_Id, Freeze_Id); |
| 31501 |
end if; |
| 31502 |
end Analyze_Variant; |
| 31503 |
|
| 31504 |
-- Local variables |
| 31505 |
|
| 31506 |
Variants : constant Node_Id := Expression (Get_Argument (N, Spec_Id)); |
| 31507 |
|
| 31508 |
Saved_GM : constant Ghost_Mode_Type := Ghost_Mode; |
| 31509 |
Saved_IGR : constant Node_Id := Ignored_Ghost_Region; |
| 31510 |
-- Save the Ghost-related attributes to restore on exit |
| 31511 |
|
| 31512 |
Variant : Node_Id; |
| 31513 |
Restore_Scope : Boolean := False; |
| 31514 |
|
| 31515 |
-- Start of processing for Analyze_Subprogram_Variant_In_Decl_Part |
| 31516 |
|
| 31517 |
begin |
| 31518 |
-- Do not analyze the pragma multiple times |
| 31519 |
|
| 31520 |
if Is_Analyzed_Pragma (N) then |
| 31521 |
return; |
| 31522 |
end if; |
| 31523 |
|
| 31524 |
-- Set the Ghost mode in effect from the pragma. Due to the delayed |
| 31525 |
-- analysis of the pragma, the Ghost mode at point of declaration and |
| 31526 |
-- point of analysis may not necessarily be the same. Use the mode in |
| 31527 |
-- effect at the point of declaration. |
| 31528 |
|
| 31529 |
Set_Ghost_Mode (N); |
| 31530 |
|
| 31531 |
-- Single and multiple contract cases must appear in aggregate form. If |
| 31532 |
-- this is not the case, then either the parser of the analysis of the |
| 31533 |
-- pragma failed to produce an aggregate, e.g. when the contract is |
| 31534 |
-- "null" or a "(null record)". |
| 31535 |
|
| 31536 |
pragma Assert |
| 31537 |
(if Nkind (Variants) = N_Aggregate |
| 31538 |
then Null_Record_Present (Variants) |
| 31539 |
xor (Present (Component_Associations (Variants)) |
| 31540 |
or |
| 31541 |
Present (Expressions (Variants))) |
| 31542 |
else Nkind (Variants) = N_Null); |
| 31543 |
|
| 31544 |
-- Only "change_direction => discrete_expression" clauses are allowed |
| 31545 |
|
| 31546 |
if Nkind (Variants) = N_Aggregate |
| 31547 |
and then Present (Component_Associations (Variants)) |
| 31548 |
and then No (Expressions (Variants)) |
| 31549 |
then |
| 31550 |
|
| 31551 |
-- Check that the expression is a proper aggregate (no parentheses) |
| 31552 |
|
| 31553 |
if Paren_Count (Variants) /= 0 then |
| 31554 |
Error_Msg_F -- CODEFIX |
| 31555 |
("redundant parentheses", Variants); |
| 31556 |
end if; |
| 31557 |
|
| 31558 |
-- Ensure that the formal parameters are visible when analyzing all |
| 31559 |
-- clauses. This falls out of the general rule of aspects pertaining |
| 31560 |
-- to subprogram declarations. |
| 31561 |
|
| 31562 |
if not In_Open_Scopes (Spec_Id) then |
| 31563 |
Restore_Scope := True; |
| 31564 |
Push_Scope (Spec_Id); |
| 31565 |
|
| 31566 |
if Is_Generic_Subprogram (Spec_Id) then |
| 31567 |
Install_Generic_Formals (Spec_Id); |
| 31568 |
else |
| 31569 |
Install_Formals (Spec_Id); |
| 31570 |
end if; |
| 31571 |
end if; |
| 31572 |
|
| 31573 |
Variant := First (Component_Associations (Variants)); |
| 31574 |
while Present (Variant) loop |
| 31575 |
Analyze_Variant (Variant); |
| 31576 |
|
| 31577 |
if Chars (First (Choices (Variant))) = Name_Structural |
| 31578 |
and then List_Length (Component_Associations (Variants)) > 1 |
| 31579 |
then |
| 31580 |
Error_Msg_N |
| 31581 |
("Structural variant shall be the only variant", Variant); |
| 31582 |
end if; |
| 31583 |
|
| 31584 |
Next (Variant); |
| 31585 |
end loop; |
| 31586 |
|
| 31587 |
if Restore_Scope then |
| 31588 |
End_Scope; |
| 31589 |
end if; |
| 31590 |
|
| 31591 |
-- Currently it is not possible to inline Subprogram_Variant on a |
| 31592 |
-- subprogram subject to pragma Inline_Always. |
| 31593 |
|
| 31594 |
Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); |
| 31595 |
|
| 31596 |
-- Otherwise the pragma is illegal |
| 31597 |
|
| 31598 |
else |
| 31599 |
Error_Msg_N ("wrong syntax for subprogram variant", N); |
| 31600 |
end if; |
| 31601 |
|
| 31602 |
Set_Is_Analyzed_Pragma (N); |
| 31603 |
|
| 31604 |
Restore_Ghost_Region (Saved_GM, Saved_IGR); |
| 31605 |
end Analyze_Subprogram_Variant_In_Decl_Part; |
| 31606 |
|
| 31607 |
------------------------------------ |
| 31608 |
-- Analyze_Test_Case_In_Decl_Part -- |
| 31609 |
------------------------------------ |
| 31610 |
|
| 31611 |
procedure Analyze_Test_Case_In_Decl_Part (N : Node_Id) is |
| 31612 |
Subp_Decl : constant Node_Id := Find_Related_Declaration_Or_Body (N); |
| 31613 |
Spec_Id : constant Entity_Id := Unique_Defining_Entity (Subp_Decl); |
| 31614 |
|
| 31615 |
procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id); |
| 31616 |
-- Preanalyze one of the optional arguments "Requires" or "Ensures" |
| 31617 |
-- denoted by Arg_Nam. |
| 31618 |
|
| 31619 |
------------------------------ |
| 31620 |
-- Preanalyze_Test_Case_Arg -- |
| 31621 |
------------------------------ |
| 31622 |
|
| 31623 |
procedure Preanalyze_Test_Case_Arg (Arg_Nam : Name_Id) is |
| 31624 |
Arg : Node_Id; |
| 31625 |
|
| 31626 |
begin |
| 31627 |
-- Preanalyze the original aspect argument for a generic subprogram |
| 31628 |
-- to properly capture global references. |
| 31629 |
|
| 31630 |
if Is_Generic_Subprogram (Spec_Id) then |
| 31631 |
Arg := |
| 31632 |
Test_Case_Arg |
| 31633 |
(Prag => N, |
| 31634 |
Arg_Nam => Arg_Nam, |
| 31635 |
From_Aspect => True); |
| 31636 |
|
| 31637 |
if Present (Arg) then |
| 31638 |
Preanalyze_Assert_Expression |
| 31639 |
(Expression (Arg), Standard_Boolean); |
| 31640 |
end if; |
| 31641 |
end if; |
| 31642 |
|
| 31643 |
Arg := Test_Case_Arg (N, Arg_Nam); |
| 31644 |
|
| 31645 |
if Present (Arg) then |
| 31646 |
Preanalyze_Assert_Expression (Expression (Arg), Standard_Boolean); |
| 31647 |
end if; |
| 31648 |
end Preanalyze_Test_Case_Arg; |
| 31649 |
|
| 31650 |
-- Local variables |
| 31651 |
|
| 31652 |
Restore_Scope : Boolean := False; |
| 31653 |
|
| 31654 |
-- Start of processing for Analyze_Test_Case_In_Decl_Part |
| 31655 |
|
| 31656 |
begin |
| 31657 |
-- Do not analyze the pragma multiple times |
| 31658 |
|
| 31659 |
if Is_Analyzed_Pragma (N) then |
| 31660 |
return; |
| 31661 |
end if; |
| 31662 |
|
| 31663 |
-- Ensure that the formal parameters are visible when analyzing all |
| 31664 |
-- clauses. This falls out of the general rule of aspects pertaining |
| 31665 |
-- to subprogram declarations. |
| 31666 |
|
| 31667 |
if not In_Open_Scopes (Spec_Id) then |
| 31668 |
Restore_Scope := True; |
| 31669 |
Push_Scope (Spec_Id); |
| 31670 |
|
| 31671 |
if Is_Generic_Subprogram (Spec_Id) then |
| 31672 |
Install_Generic_Formals (Spec_Id); |
| 31673 |
else |
| 31674 |
Install_Formals (Spec_Id); |
| 31675 |
end if; |
| 31676 |
end if; |
| 31677 |
|
| 31678 |
Preanalyze_Test_Case_Arg (Name_Requires); |
| 31679 |
Preanalyze_Test_Case_Arg (Name_Ensures); |
| 31680 |
|
| 31681 |
if Restore_Scope then |
| 31682 |
End_Scope; |
| 31683 |
end if; |
| 31684 |
|
| 31685 |
-- Currently it is not possible to inline pre/postconditions on a |
| 31686 |
-- subprogram subject to pragma Inline_Always. |
| 31687 |
|
| 31688 |
Check_Postcondition_Use_In_Inlined_Subprogram (N, Spec_Id); |
| 31689 |
|
| 31690 |
Set_Is_Analyzed_Pragma (N); |
| 31691 |
end Analyze_Test_Case_In_Decl_Part; |
| 31692 |
|
| 31693 |
---------------- |
| 31694 |
-- Appears_In -- |
| 31695 |
---------------- |
| 31696 |
|
| 31697 |
function Appears_In (List : Elist_Id; Item_Id : Entity_Id) return Boolean is |
| 31698 |
Elmt : Elmt_Id; |
| 31699 |
Id : Entity_Id; |
| 31700 |
|
| 31701 |
begin |
| 31702 |
if Present (List) then |
| 31703 |
Elmt := First_Elmt (List); |
| 31704 |
while Present (Elmt) loop |
| 31705 |
if Nkind (Node (Elmt)) = N_Defining_Identifier then |
| 31706 |
Id := Node (Elmt); |
| 31707 |
else |
| 31708 |
Id := Entity_Of (Node (Elmt)); |
| 31709 |
end if; |
| 31710 |
|
| 31711 |
if Id = Item_Id then |
| 31712 |
return True; |
| 31713 |
end if; |
| 31714 |
|
| 31715 |
Next_Elmt (Elmt); |
| 31716 |
end loop; |
| 31717 |
end if; |
| 31718 |
|
| 31719 |
return False; |
| 31720 |
end Appears_In; |
| 31721 |
|
| 31722 |
----------------------------------- |
| 31723 |
-- Build_Pragma_Check_Equivalent -- |
| 31724 |
----------------------------------- |
| 31725 |
|
| 31726 |
function Build_Pragma_Check_Equivalent |
| 31727 |
(Prag : Node_Id; |
| 31728 |
Subp_Id : Entity_Id := Empty; |
| 31729 |
Inher_Id : Entity_Id := Empty; |
| 31730 |
Keep_Pragma_Id : Boolean := False) return Node_Id |
| 31731 |
is |
| 31732 |
function Suppress_Reference (N : Node_Id) return Traverse_Result; |
| 31733 |
-- Detect whether node N references a formal parameter subject to |
| 31734 |
-- pragma Unreferenced. If this is the case, set Comes_From_Source |
| 31735 |
-- to False to suppress the generation of a reference when analyzing |
| 31736 |
-- N later on. |
| 31737 |
|
| 31738 |
------------------------ |
| 31739 |
-- Suppress_Reference -- |
| 31740 |
------------------------ |
| 31741 |
|
| 31742 |
function Suppress_Reference (N : Node_Id) return Traverse_Result is |
| 31743 |
Formal : Entity_Id; |
| 31744 |
|
| 31745 |
begin |
| 31746 |
if Is_Entity_Name (N) and then Present (Entity (N)) then |
| 31747 |
Formal := Entity (N); |
| 31748 |
|
| 31749 |
-- The formal parameter is subject to pragma Unreferenced. Prevent |
| 31750 |
-- the generation of references by resetting the Comes_From_Source |
| 31751 |
-- flag. |
| 31752 |
|
| 31753 |
if Is_Formal (Formal) |
| 31754 |
and then Has_Pragma_Unreferenced (Formal) |
| 31755 |
then |
| 31756 |
Set_Comes_From_Source (N, False); |
| 31757 |
end if; |
| 31758 |
end if; |
| 31759 |
|
| 31760 |
return OK; |
| 31761 |
end Suppress_Reference; |
| 31762 |
|
| 31763 |
procedure Suppress_References is |
| 31764 |
new Traverse_Proc (Suppress_Reference); |
| 31765 |
|
| 31766 |
-- Local variables |
| 31767 |
|
| 31768 |
Loc : constant Source_Ptr := Sloc (Prag); |
| 31769 |
Prag_Nam : constant Name_Id := Pragma_Name (Prag); |
| 31770 |
Check_Prag : Node_Id; |
| 31771 |
Nam : Name_Id; |
| 31772 |
|
| 31773 |
-- Start of processing for Build_Pragma_Check_Equivalent |
| 31774 |
|
| 31775 |
begin |
| 31776 |
-- When the pre- or postcondition is inherited, map the formals of the |
| 31777 |
-- inherited subprogram to those of the current subprogram. In addition, |
| 31778 |
-- map primitive operations of the parent type into the corresponding |
| 31779 |
-- primitive operations of the descendant. |
| 31780 |
|
| 31781 |
if Present (Inher_Id) then |
| 31782 |
pragma Assert (Present (Subp_Id)); |
| 31783 |
|
| 31784 |
Update_Primitives_Mapping (Inher_Id, Subp_Id); |
| 31785 |
|
| 31786 |
-- Use generic machinery to copy inherited pragma, as if it were an |
| 31787 |
-- instantiation, resetting source locations appropriately, so that |
| 31788 |
-- expressions inside the inherited pragma use chained locations. |
| 31789 |
-- This is used in particular in GNATprove to locate precisely |
| 31790 |
-- messages on a given inherited pragma. |
| 31791 |
|
| 31792 |
Set_Copied_Sloc_For_Inherited_Pragma |
| 31793 |
(Unit_Declaration_Node (Subp_Id), Inher_Id); |
| 31794 |
Check_Prag := New_Copy_Tree (Source => Prag); |
| 31795 |
|
| 31796 |
-- Build the inherited class-wide condition |
| 31797 |
|
| 31798 |
Build_Class_Wide_Expression |
| 31799 |
(Pragma_Or_Expr => Check_Prag, |
| 31800 |
Subp => Subp_Id, |
| 31801 |
Par_Subp => Inher_Id, |
| 31802 |
Adjust_Sloc => True); |
| 31803 |
|
| 31804 |
-- If not an inherited condition simply copy the original pragma |
| 31805 |
|
| 31806 |
else |
| 31807 |
Check_Prag := New_Copy_Tree (Source => Prag); |
| 31808 |
end if; |
| 31809 |
|
| 31810 |
-- Mark the pragma as being internally generated and reset the Analyzed |
| 31811 |
-- flag. |
| 31812 |
|
| 31813 |
Set_Analyzed (Check_Prag, False); |
| 31814 |
Set_Comes_From_Source (Check_Prag, False); |
| 31815 |
|
| 31816 |
-- The tree of the original pragma may contain references to the |
| 31817 |
-- formal parameters of the related subprogram. At the same time |
| 31818 |
-- the corresponding body may mark the formals as unreferenced: |
| 31819 |
|
| 31820 |
-- procedure Proc (Formal : ...) |
| 31821 |
-- with Pre => Formal ...; |
| 31822 |
|
| 31823 |
-- procedure Proc (Formal : ...) is |
| 31824 |
-- pragma Unreferenced (Formal); |
| 31825 |
-- ... |
| 31826 |
|
| 31827 |
-- This creates problems because all pragma Check equivalents are |
| 31828 |
-- analyzed at the end of the body declarations. Since all source |
| 31829 |
-- references have already been accounted for, reset any references |
| 31830 |
-- to such formals in the generated pragma Check equivalent. |
| 31831 |
|
| 31832 |
Suppress_References (Check_Prag); |
| 31833 |
|
| 31834 |
if Present (Corresponding_Aspect (Prag)) then |
| 31835 |
Nam := Chars (Identifier (Corresponding_Aspect (Prag))); |
| 31836 |
else |
| 31837 |
Nam := Prag_Nam; |
| 31838 |
end if; |
| 31839 |
|
| 31840 |
-- Unless Keep_Pragma_Id is True in order to keep the identifier of |
| 31841 |
-- the copied pragma in the newly created pragma, convert the copy into |
| 31842 |
-- pragma Check by correcting the name and adding a check_kind argument. |
| 31843 |
|
| 31844 |
if not Keep_Pragma_Id then |
| 31845 |
Set_Class_Present (Check_Prag, False); |
| 31846 |
|
| 31847 |
Set_Pragma_Identifier |
| 31848 |
(Check_Prag, Make_Identifier (Loc, Name_Check)); |
| 31849 |
|
| 31850 |
Prepend_To (Pragma_Argument_Associations (Check_Prag), |
| 31851 |
Make_Pragma_Argument_Association (Loc, |
| 31852 |
Expression => Make_Identifier (Loc, Nam))); |
| 31853 |
end if; |
| 31854 |
|
| 31855 |
return Check_Prag; |
| 31856 |
end Build_Pragma_Check_Equivalent; |
| 31857 |
|
| 31858 |
----------------------------- |
| 31859 |
-- Check_Applicable_Policy -- |
| 31860 |
----------------------------- |
| 31861 |
|
| 31862 |
procedure Check_Applicable_Policy (N : Node_Id) is |
| 31863 |
PP : Node_Id; |
| 31864 |
Policy : Name_Id; |
| 31865 |
|
| 31866 |
Ename : constant Name_Id := Original_Aspect_Pragma_Name (N); |
| 31867 |
|
| 31868 |
begin |
| 31869 |
-- No effect if not valid assertion kind name |
| 31870 |
|
| 31871 |
if not Is_Valid_Assertion_Kind (Ename) then |
| 31872 |
return; |
| 31873 |
end if; |
| 31874 |
|
| 31875 |
-- Loop through entries in check policy list |
| 31876 |
|
| 31877 |
PP := Opt.Check_Policy_List; |
| 31878 |
while Present (PP) loop |
| 31879 |
declare |
| 31880 |
PPA : constant List_Id := Pragma_Argument_Associations (PP); |
| 31881 |
Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA))); |
| 31882 |
|
| 31883 |
begin |
| 31884 |
if Ename = Pnm |
| 31885 |
or else Pnm = Name_Assertion |
| 31886 |
or else (Pnm = Name_Statement_Assertions |
| 31887 |
and then Ename in Name_Assert |
| 31888 |
| Name_Assert_And_Cut |
| 31889 |
| Name_Assume |
| 31890 |
| Name_Loop_Invariant |
| 31891 |
| Name_Loop_Variant) |
| 31892 |
then |
| 31893 |
Policy := Chars (Get_Pragma_Arg (Last (PPA))); |
| 31894 |
|
| 31895 |
case Policy is |
| 31896 |
when Name_Ignore |
| 31897 |
| Name_Off |
| 31898 |
=> |
| 31899 |
-- In CodePeer mode and GNATprove mode, we need to |
| 31900 |
-- consider all assertions, unless they are disabled. |
| 31901 |
-- Force Is_Checked on ignored assertions, in particular |
| 31902 |
-- because transformations of the AST may depend on |
| 31903 |
-- assertions being checked (e.g. the translation of |
| 31904 |
-- attribute 'Loop_Entry). |
| 31905 |
|
| 31906 |
if CodePeer_Mode or GNATprove_Mode then |
| 31907 |
Set_Is_Checked (N, True); |
| 31908 |
Set_Is_Ignored (N, False); |
| 31909 |
else |
| 31910 |
Set_Is_Checked (N, False); |
| 31911 |
Set_Is_Ignored (N, True); |
| 31912 |
end if; |
| 31913 |
|
| 31914 |
when Name_Check |
| 31915 |
| Name_On |
| 31916 |
=> |
| 31917 |
Set_Is_Checked (N, True); |
| 31918 |
Set_Is_Ignored (N, False); |
| 31919 |
|
| 31920 |
when Name_Disable => |
| 31921 |
Set_Is_Ignored (N, True); |
| 31922 |
Set_Is_Checked (N, False); |
| 31923 |
Set_Is_Disabled (N, True); |
| 31924 |
|
| 31925 |
-- That should be exhaustive, the null here is a defence |
| 31926 |
-- against a malformed tree from previous errors. |
| 31927 |
|
| 31928 |
when others => |
| 31929 |
null; |
| 31930 |
end case; |
| 31931 |
|
| 31932 |
return; |
| 31933 |
end if; |
| 31934 |
|
| 31935 |
PP := Next_Pragma (PP); |
| 31936 |
end; |
| 31937 |
end loop; |
| 31938 |
|
| 31939 |
-- If there are no specific entries that matched, then we let the |
| 31940 |
-- setting of assertions govern. Note that this provides the needed |
| 31941 |
-- compatibility with the RM for the cases of assertion, invariant, |
| 31942 |
-- precondition, predicate, and postcondition. Note also that |
| 31943 |
-- Assertions_Enabled is forced in CodePeer mode and GNATprove mode. |
| 31944 |
|
| 31945 |
if Assertions_Enabled then |
| 31946 |
Set_Is_Checked (N, True); |
| 31947 |
Set_Is_Ignored (N, False); |
| 31948 |
else |
| 31949 |
Set_Is_Checked (N, False); |
| 31950 |
Set_Is_Ignored (N, True); |
| 31951 |
end if; |
| 31952 |
end Check_Applicable_Policy; |
| 31953 |
|
| 31954 |
------------------------------- |
| 31955 |
-- Check_External_Properties -- |
| 31956 |
------------------------------- |
| 31957 |
|
| 31958 |
procedure Check_External_Properties |
| 31959 |
(Item : Node_Id; |
| 31960 |
AR : Boolean; |
| 31961 |
AW : Boolean; |
| 31962 |
ER : Boolean; |
| 31963 |
EW : Boolean) |
| 31964 |
is |
| 31965 |
type Properties is array (Positive range 1 .. 4) of Boolean; |
| 31966 |
type Combinations is array (Positive range <>) of Properties; |
| 31967 |
-- Arrays of Async_Readers, Async_Writers, Effective_Writes and |
| 31968 |
-- Effective_Reads properties and their combinations, respectively. |
| 31969 |
|
| 31970 |
Specified : constant Properties := (AR, AW, EW, ER); |
| 31971 |
-- External properties, as given by the Item pragma |
| 31972 |
|
| 31973 |
Allowed : constant Combinations := |
| 31974 |
(1 => (True, False, True, False), |
| 31975 |
2 => (False, True, False, True), |
| 31976 |
3 => (True, False, False, False), |
| 31977 |
4 => (False, True, False, False), |
| 31978 |
5 => (True, True, True, False), |
| 31979 |
6 => (True, True, False, True), |
| 31980 |
7 => (True, True, False, False), |
| 31981 |
8 => (True, True, True, True)); |
| 31982 |
-- Allowed combinations, as listed in the SPARK RM 7.1.2(6) table |
| 31983 |
|
| 31984 |
begin |
| 31985 |
-- Check if the specified properties match any of the allowed |
| 31986 |
-- combination; if not, then emit an error. |
| 31987 |
|
| 31988 |
for J in Allowed'Range loop |
| 31989 |
if Specified = Allowed (J) then |
| 31990 |
return; |
| 31991 |
end if; |
| 31992 |
end loop; |
| 31993 |
|
| 31994 |
SPARK_Msg_N |
| 31995 |
("illegal combination of external properties (SPARK RM 7.1.2(6))", |
| 31996 |
Item); |
| 31997 |
end Check_External_Properties; |
| 31998 |
|
| 31999 |
---------------- |
| 32000 |
-- Check_Kind -- |
| 32001 |
---------------- |
| 32002 |
|
| 32003 |
function Check_Kind (Nam : Name_Id) return Name_Id is |
| 32004 |
PP : Node_Id; |
| 32005 |
|
| 32006 |
begin |
| 32007 |
-- Loop through entries in check policy list |
| 32008 |
|
| 32009 |
PP := Opt.Check_Policy_List; |
| 32010 |
while Present (PP) loop |
| 32011 |
declare |
| 32012 |
PPA : constant List_Id := Pragma_Argument_Associations (PP); |
| 32013 |
Pnm : constant Name_Id := Chars (Get_Pragma_Arg (First (PPA))); |
| 32014 |
|
| 32015 |
begin |
| 32016 |
if Nam = Pnm |
| 32017 |
or else (Pnm = Name_Assertion |
| 32018 |
and then Is_Valid_Assertion_Kind (Nam)) |
| 32019 |
or else (Pnm = Name_Statement_Assertions |
| 32020 |
and then Nam in Name_Assert |
| 32021 |
| Name_Assert_And_Cut |
| 32022 |
| Name_Assume |
| 32023 |
| Name_Loop_Invariant |
| 32024 |
| Name_Loop_Variant) |
| 32025 |
then |
| 32026 |
case Chars (Get_Pragma_Arg (Last (PPA))) is |
| 32027 |
when Name_Check |
| 32028 |
| Name_On |
| 32029 |
=> |
| 32030 |
return Name_Check; |
| 32031 |
|
| 32032 |
when Name_Ignore |
| 32033 |
| Name_Off |
| 32034 |
=> |
| 32035 |
return Name_Ignore; |
| 32036 |
|
| 32037 |
when Name_Disable => |
| 32038 |
return Name_Disable; |
| 32039 |
|
| 32040 |
when others => |
| 32041 |
raise Program_Error; |
| 32042 |
end case; |
| 32043 |
|
| 32044 |
else |
| 32045 |
PP := Next_Pragma (PP); |
| 32046 |
end if; |
| 32047 |
end; |
| 32048 |
end loop; |
| 32049 |
|
| 32050 |
-- If there are no specific entries that matched, then we let the |
| 32051 |
-- setting of assertions govern. Note that this provides the needed |
| 32052 |
-- compatibility with the RM for the cases of assertion, invariant, |
| 32053 |
-- precondition, predicate, and postcondition. |
| 32054 |
|
| 32055 |
if Assertions_Enabled then |
| 32056 |
return Name_Check; |
| 32057 |
else |
| 32058 |
return Name_Ignore; |
| 32059 |
end if; |
| 32060 |
end Check_Kind; |
| 32061 |
|
| 32062 |
--------------------------- |
| 32063 |
-- Check_Missing_Part_Of -- |
| 32064 |
--------------------------- |
| 32065 |
|
| 32066 |
procedure Check_Missing_Part_Of (Item_Id : Entity_Id) is |
| 32067 |
function Has_Visible_State (Pack_Id : Entity_Id) return Boolean; |
| 32068 |
-- Determine whether a package denoted by Pack_Id declares at least one |
| 32069 |
-- visible state. |
| 32070 |
|
| 32071 |
----------------------- |
| 32072 |
-- Has_Visible_State -- |
| 32073 |
----------------------- |
| 32074 |
|
| 32075 |
function Has_Visible_State (Pack_Id : Entity_Id) return Boolean is |
| 32076 |
Item_Id : Entity_Id; |
| 32077 |
|
| 32078 |
begin |
| 32079 |
-- Traverse the entity chain of the package trying to find at least |
| 32080 |
-- one visible abstract state, variable or a package [instantiation] |
| 32081 |
-- that declares a visible state. |
| 32082 |
|
| 32083 |
Item_Id := First_Entity (Pack_Id); |
| 32084 |
while Present (Item_Id) |
| 32085 |
and then not In_Private_Part (Item_Id) |
| 32086 |
loop |
| 32087 |
-- Do not consider internally generated items |
| 32088 |
|
| 32089 |
if not Comes_From_Source (Item_Id) then |
| 32090 |
null; |
| 32091 |
|
| 32092 |
-- Do not consider generic formals or their corresponding actuals |
| 32093 |
-- because they are not part of a visible state. Note that both |
| 32094 |
-- entities are marked as hidden. |
| 32095 |
|
| 32096 |
elsif Is_Hidden (Item_Id) then |
| 32097 |
null; |
| 32098 |
|
| 32099 |
-- A visible state has been found. Note that constants are not |
| 32100 |
-- considered here because it is not possible to determine whether |
| 32101 |
-- they depend on variable input. This check is left to the SPARK |
| 32102 |
-- prover. |
| 32103 |
|
| 32104 |
elsif Ekind (Item_Id) in E_Abstract_State | E_Variable then |
| 32105 |
return True; |
| 32106 |
|
| 32107 |
-- Recursively peek into nested packages and instantiations |
| 32108 |
|
| 32109 |
elsif Ekind (Item_Id) = E_Package |
| 32110 |
and then Has_Visible_State (Item_Id) |
| 32111 |
then |
| 32112 |
return True; |
| 32113 |
end if; |
| 32114 |
|
| 32115 |
Next_Entity (Item_Id); |
| 32116 |
end loop; |
| 32117 |
|
| 32118 |
return False; |
| 32119 |
end Has_Visible_State; |
| 32120 |
|
| 32121 |
-- Local variables |
| 32122 |
|
| 32123 |
Pack_Id : Entity_Id; |
| 32124 |
Placement : State_Space_Kind; |
| 32125 |
|
| 32126 |
-- Start of processing for Check_Missing_Part_Of |
| 32127 |
|
| 32128 |
begin |
| 32129 |
-- Do not consider abstract states, variables or package instantiations |
| 32130 |
-- coming from an instance as those always inherit the Part_Of indicator |
| 32131 |
-- of the instance itself. |
| 32132 |
|
| 32133 |
if In_Instance then |
| 32134 |
return; |
| 32135 |
|
| 32136 |
-- Do not consider internally generated entities as these can never |
| 32137 |
-- have a Part_Of indicator. |
| 32138 |
|
| 32139 |
elsif not Comes_From_Source (Item_Id) then |
| 32140 |
return; |
| 32141 |
|
| 32142 |
-- Perform these checks only when SPARK_Mode is enabled as they will |
| 32143 |
-- interfere with standard Ada rules and produce false positives. |
| 32144 |
|
| 32145 |
elsif SPARK_Mode /= On then |
| 32146 |
return; |
| 32147 |
|
| 32148 |
-- Do not consider constants, because the compiler cannot accurately |
| 32149 |
-- determine whether they have variable input (SPARK RM 7.1.1(2)) and |
| 32150 |
-- act as a hidden state of a package. |
| 32151 |
|
| 32152 |
elsif Ekind (Item_Id) = E_Constant then |
| 32153 |
return; |
| 32154 |
end if; |
| 32155 |
|
| 32156 |
-- Find where the abstract state, variable or package instantiation |
| 32157 |
-- lives with respect to the state space. |
| 32158 |
|
| 32159 |
Find_Placement_In_State_Space |
| 32160 |
(Item_Id => Item_Id, |
| 32161 |
Placement => Placement, |
| 32162 |
Pack_Id => Pack_Id); |
| 32163 |
|
| 32164 |
-- Items that appear in a non-package construct (subprogram, block, etc) |
| 32165 |
-- do not require a Part_Of indicator because they can never act as a |
| 32166 |
-- hidden state. |
| 32167 |
|
| 32168 |
if Placement = Not_In_Package then |
| 32169 |
null; |
| 32170 |
|
| 32171 |
-- An item declared in the body state space of a package always act as a |
| 32172 |
-- constituent and does not need explicit Part_Of indicator. |
| 32173 |
|
| 32174 |
elsif Placement = Body_State_Space then |
| 32175 |
null; |
| 32176 |
|
| 32177 |
-- In general an item declared in the visible state space of a package |
| 32178 |
-- does not require a Part_Of indicator. The only exception is when the |
| 32179 |
-- related package is a nongeneric private child unit, in which case |
| 32180 |
-- Part_Of must denote a state in the parent unit or in one of its |
| 32181 |
-- descendants. |
| 32182 |
|
| 32183 |
elsif Placement = Visible_State_Space then |
| 32184 |
if Is_Child_Unit (Pack_Id) |
| 32185 |
and then not Is_Generic_Unit (Pack_Id) |
| 32186 |
and then Is_Private_Descendant (Pack_Id) |
| 32187 |
then |
| 32188 |
-- A package instantiation does not need a Part_Of indicator when |
| 32189 |
-- the related generic template has no visible state. |
| 32190 |
|
| 32191 |
if Ekind (Item_Id) = E_Package |
| 32192 |
and then Is_Generic_Instance (Item_Id) |
| 32193 |
and then not Has_Visible_State (Item_Id) |
| 32194 |
then |
| 32195 |
null; |
| 32196 |
|
| 32197 |
-- All other cases require Part_Of |
| 32198 |
|
| 32199 |
else |
| 32200 |
Error_Msg_N |
| 32201 |
("indicator Part_Of is required in this context " |
| 32202 |
& "(SPARK RM 7.2.6(3))", Item_Id); |
| 32203 |
Error_Msg_Name_1 := Chars (Pack_Id); |
| 32204 |
Error_Msg_N |
| 32205 |
("\& is declared in the visible part of private child " |
| 32206 |
& "unit %", Item_Id); |
| 32207 |
end if; |
| 32208 |
end if; |
| 32209 |
|
| 32210 |
-- When the item appears in the private state space of a package, it |
| 32211 |
-- must be a part of some state declared by the said package. |
| 32212 |
|
| 32213 |
else pragma Assert (Placement = Private_State_Space); |
| 32214 |
|
| 32215 |
-- The related package does not declare a state, the item cannot act |
| 32216 |
-- as a Part_Of constituent. |
| 32217 |
|
| 32218 |
if No (Get_Pragma (Pack_Id, Pragma_Abstract_State)) then |
| 32219 |
null; |
| 32220 |
|
| 32221 |
-- A package instantiation does not need a Part_Of indicator when the |
| 32222 |
-- related generic template has no visible state. |
| 32223 |
|
| 32224 |
elsif Ekind (Item_Id) = E_Package |
| 32225 |
and then Is_Generic_Instance (Item_Id) |
| 32226 |
and then not Has_Visible_State (Item_Id) |
| 32227 |
then |
| 32228 |
null; |
| 32229 |
|
| 32230 |
-- All other cases require Part_Of |
| 32231 |
|
| 32232 |
else |
| 32233 |
Error_Msg_Code := GEC_Required_Part_Of; |
| 32234 |
Error_Msg_N |
| 32235 |
("indicator Part_Of is required in this context '[[]']", |
| 32236 |
Item_Id); |
| 32237 |
Error_Msg_Name_1 := Chars (Pack_Id); |
| 32238 |
Error_Msg_N |
| 32239 |
("\& is declared in the private part of package %", Item_Id); |
| 32240 |
end if; |
| 32241 |
end if; |
| 32242 |
end Check_Missing_Part_Of; |
| 32243 |
|
| 32244 |
--------------------------------------------------- |
| 32245 |
-- Check_Postcondition_Use_In_Inlined_Subprogram -- |
| 32246 |
--------------------------------------------------- |
| 32247 |
|
| 32248 |
procedure Check_Postcondition_Use_In_Inlined_Subprogram |
| 32249 |
(Prag : Node_Id; |
| 32250 |
Spec_Id : Entity_Id) |
| 32251 |
is |
| 32252 |
begin |
| 32253 |
if Warn_On_Redundant_Constructs |
| 32254 |
and then Has_Pragma_Inline_Always (Spec_Id) |
| 32255 |
and then Assertions_Enabled |
| 32256 |
and then not Back_End_Inlining |
| 32257 |
then |
| 32258 |
Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag); |
| 32259 |
|
| 32260 |
if From_Aspect_Specification (Prag) then |
| 32261 |
Error_Msg_NE |
| 32262 |
("aspect % not enforced on inlined subprogram &?r?", |
| 32263 |
Corresponding_Aspect (Prag), Spec_Id); |
| 32264 |
else |
| 32265 |
Error_Msg_NE |
| 32266 |
("pragma % not enforced on inlined subprogram &?r?", |
| 32267 |
Prag, Spec_Id); |
| 32268 |
end if; |
| 32269 |
end if; |
| 32270 |
end Check_Postcondition_Use_In_Inlined_Subprogram; |
| 32271 |
|
| 32272 |
------------------------------------- |
| 32273 |
-- Check_State_And_Constituent_Use -- |
| 32274 |
------------------------------------- |
| 32275 |
|
| 32276 |
procedure Check_State_And_Constituent_Use |
| 32277 |
(States : Elist_Id; |
| 32278 |
Constits : Elist_Id; |
| 32279 |
Context : Node_Id) |
| 32280 |
is |
| 32281 |
Constit_Elmt : Elmt_Id; |
| 32282 |
Constit_Id : Entity_Id; |
| 32283 |
State_Id : Entity_Id; |
| 32284 |
|
| 32285 |
begin |
| 32286 |
-- Nothing to do if there are no states or constituents |
| 32287 |
|
| 32288 |
if No (States) or else No (Constits) then |
| 32289 |
return; |
| 32290 |
end if; |
| 32291 |
|
| 32292 |
-- Inspect the list of constituents and try to determine whether its |
| 32293 |
-- encapsulating state is in list States. |
| 32294 |
|
| 32295 |
Constit_Elmt := First_Elmt (Constits); |
| 32296 |
while Present (Constit_Elmt) loop |
| 32297 |
Constit_Id := Node (Constit_Elmt); |
| 32298 |
|
| 32299 |
-- Determine whether the constituent is part of an encapsulating |
| 32300 |
-- state that appears in the same context and if this is the case, |
| 32301 |
-- emit an error (SPARK RM 7.2.6(7)). |
| 32302 |
|
| 32303 |
State_Id := Find_Encapsulating_State (States, Constit_Id); |
| 32304 |
|
| 32305 |
if Present (State_Id) then |
| 32306 |
Error_Msg_Name_1 := Chars (Constit_Id); |
| 32307 |
SPARK_Msg_NE |
| 32308 |
("cannot mention state & and its constituent % in the same " |
| 32309 |
& "context", Context, State_Id); |
| 32310 |
exit; |
| 32311 |
end if; |
| 32312 |
|
| 32313 |
Next_Elmt (Constit_Elmt); |
| 32314 |
end loop; |
| 32315 |
end Check_State_And_Constituent_Use; |
| 32316 |
|
| 32317 |
--------------------------------------------- |
| 32318 |
-- Collect_Inherited_Class_Wide_Conditions -- |
| 32319 |
--------------------------------------------- |
| 32320 |
|
| 32321 |
procedure Collect_Inherited_Class_Wide_Conditions (Subp : Entity_Id) is |
| 32322 |
Parent_Subp : constant Entity_Id := |
| 32323 |
Ultimate_Alias (Overridden_Operation (Subp)); |
| 32324 |
-- The Overridden_Operation may itself be inherited and as such have no |
| 32325 |
-- explicit contract. |
| 32326 |
|
| 32327 |
Prags : constant Node_Id := Contract (Parent_Subp); |
| 32328 |
In_Spec_Expr : Boolean := In_Spec_Expression; |
| 32329 |
Installed : Boolean; |
| 32330 |
Prag : Node_Id; |
| 32331 |
New_Prag : Node_Id; |
| 32332 |
|
| 32333 |
begin |
| 32334 |
Installed := False; |
| 32335 |
|
| 32336 |
-- Iterate over the contract of the overridden subprogram to find all |
| 32337 |
-- inherited class-wide pre- and postconditions. |
| 32338 |
|
| 32339 |
if Present (Prags) then |
| 32340 |
Prag := Pre_Post_Conditions (Prags); |
| 32341 |
|
| 32342 |
while Present (Prag) loop |
| 32343 |
if Pragma_Name_Unmapped (Prag) |
| 32344 |
in Name_Precondition | Name_Postcondition |
| 32345 |
and then Class_Present (Prag) |
| 32346 |
then |
| 32347 |
-- The generated pragma must be analyzed in the context of |
| 32348 |
-- the subprogram, to make its formals visible. In addition, |
| 32349 |
-- we must inhibit freezing and full analysis because the |
| 32350 |
-- controlling type of the subprogram is not frozen yet, and |
| 32351 |
-- may have further primitives. |
| 32352 |
|
| 32353 |
if not Installed then |
| 32354 |
Installed := True; |
| 32355 |
Push_Scope (Subp); |
| 32356 |
Install_Formals (Subp); |
| 32357 |
In_Spec_Expr := In_Spec_Expression; |
| 32358 |
In_Spec_Expression := True; |
| 32359 |
end if; |
| 32360 |
|
| 32361 |
New_Prag := |
| 32362 |
Build_Pragma_Check_Equivalent |
| 32363 |
(Prag, Subp, Parent_Subp, Keep_Pragma_Id => True); |
| 32364 |
|
| 32365 |
Insert_After (Unit_Declaration_Node (Subp), New_Prag); |
| 32366 |
Preanalyze (New_Prag); |
| 32367 |
|
| 32368 |
-- Prevent further analysis in subsequent processing of the |
| 32369 |
-- current list of declarations |
| 32370 |
|
| 32371 |
Set_Analyzed (New_Prag); |
| 32372 |
end if; |
| 32373 |
|
| 32374 |
Prag := Next_Pragma (Prag); |
| 32375 |
end loop; |
| 32376 |
|
| 32377 |
if Installed then |
| 32378 |
In_Spec_Expression := In_Spec_Expr; |
| 32379 |
End_Scope; |
| 32380 |
end if; |
| 32381 |
end if; |
| 32382 |
end Collect_Inherited_Class_Wide_Conditions; |
| 32383 |
|
| 32384 |
--------------------------------------- |
| 32385 |
-- Collect_Subprogram_Inputs_Outputs -- |
| 32386 |
--------------------------------------- |
| 32387 |
|
| 32388 |
procedure Collect_Subprogram_Inputs_Outputs |
| 32389 |
(Subp_Id : Entity_Id; |
| 32390 |
Synthesize : Boolean := False; |
| 32391 |
Subp_Inputs : in out Elist_Id; |
| 32392 |
Subp_Outputs : in out Elist_Id; |
| 32393 |
Global_Seen : out Boolean) |
| 32394 |
is |
| 32395 |
procedure Collect_Dependency_Clause (Clause : Node_Id); |
| 32396 |
-- Collect all relevant items from a dependency clause |
| 32397 |
|
| 32398 |
procedure Collect_Global_List |
| 32399 |
(List : Node_Id; |
| 32400 |
Mode : Name_Id := Name_Input); |
| 32401 |
-- Collect all relevant items from a global list |
| 32402 |
|
| 32403 |
------------------------------- |
| 32404 |
-- Collect_Dependency_Clause -- |
| 32405 |
------------------------------- |
| 32406 |
|
| 32407 |
procedure Collect_Dependency_Clause (Clause : Node_Id) is |
| 32408 |
procedure Collect_Dependency_Item |
| 32409 |
(Item : Node_Id; |
| 32410 |
Is_Input : Boolean); |
| 32411 |
-- Add an item to the proper subprogram input or output collection |
| 32412 |
|
| 32413 |
----------------------------- |
| 32414 |
-- Collect_Dependency_Item -- |
| 32415 |
----------------------------- |
| 32416 |
|
| 32417 |
procedure Collect_Dependency_Item |
| 32418 |
(Item : Node_Id; |
| 32419 |
Is_Input : Boolean) |
| 32420 |
is |
| 32421 |
Extra : Node_Id; |
| 32422 |
|
| 32423 |
begin |
| 32424 |
-- Nothing to collect when the item is null |
| 32425 |
|
| 32426 |
if Nkind (Item) = N_Null then |
| 32427 |
null; |
| 32428 |
|
| 32429 |
-- Ditto for attribute 'Result |
| 32430 |
|
| 32431 |
elsif Is_Attribute_Result (Item) then |
| 32432 |
null; |
| 32433 |
|
| 32434 |
-- Multiple items appear as an aggregate |
| 32435 |
|
| 32436 |
elsif Nkind (Item) = N_Aggregate then |
| 32437 |
Extra := First (Expressions (Item)); |
| 32438 |
while Present (Extra) loop |
| 32439 |
Collect_Dependency_Item (Extra, Is_Input); |
| 32440 |
Next (Extra); |
| 32441 |
end loop; |
| 32442 |
|
| 32443 |
-- Otherwise this is a solitary item |
| 32444 |
|
| 32445 |
else |
| 32446 |
if Is_Input then |
| 32447 |
Append_New_Elmt (Item, Subp_Inputs); |
| 32448 |
else |
| 32449 |
Append_New_Elmt (Item, Subp_Outputs); |
| 32450 |
end if; |
| 32451 |
end if; |
| 32452 |
end Collect_Dependency_Item; |
| 32453 |
|
| 32454 |
-- Start of processing for Collect_Dependency_Clause |
| 32455 |
|
| 32456 |
begin |
| 32457 |
if Nkind (Clause) = N_Null then |
| 32458 |
null; |
| 32459 |
|
| 32460 |
-- A dependency clause appears as component association |
| 32461 |
|
| 32462 |
elsif Nkind (Clause) = N_Component_Association then |
| 32463 |
Collect_Dependency_Item |
| 32464 |
(Item => Expression (Clause), |
| 32465 |
Is_Input => True); |
| 32466 |
|
| 32467 |
Collect_Dependency_Item |
| 32468 |
(Item => First (Choices (Clause)), |
| 32469 |
Is_Input => False); |
| 32470 |
|
| 32471 |
-- To accommodate partial decoration of disabled SPARK features, this |
| 32472 |
-- routine may be called with illegal input. If this is the case, do |
| 32473 |
-- not raise Program_Error. |
| 32474 |
|
| 32475 |
else |
| 32476 |
null; |
| 32477 |
end if; |
| 32478 |
end Collect_Dependency_Clause; |
| 32479 |
|
| 32480 |
------------------------- |
| 32481 |
-- Collect_Global_List -- |
| 32482 |
------------------------- |
| 32483 |
|
| 32484 |
procedure Collect_Global_List |
| 32485 |
(List : Node_Id; |
| 32486 |
Mode : Name_Id := Name_Input) |
| 32487 |
is |
| 32488 |
procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id); |
| 32489 |
-- Add an item to the proper subprogram input or output collection |
| 32490 |
|
| 32491 |
------------------------- |
| 32492 |
-- Collect_Global_Item -- |
| 32493 |
------------------------- |
| 32494 |
|
| 32495 |
procedure Collect_Global_Item (Item : Node_Id; Mode : Name_Id) is |
| 32496 |
begin |
| 32497 |
if Mode in Name_In_Out | Name_Input then |
| 32498 |
Append_New_Elmt (Item, Subp_Inputs); |
| 32499 |
end if; |
| 32500 |
|
| 32501 |
if Mode in Name_In_Out | Name_Output then |
| 32502 |
Append_New_Elmt (Item, Subp_Outputs); |
| 32503 |
end if; |
| 32504 |
end Collect_Global_Item; |
| 32505 |
|
| 32506 |
-- Local variables |
| 32507 |
|
| 32508 |
Assoc : Node_Id; |
| 32509 |
Item : Node_Id; |
| 32510 |
|
| 32511 |
-- Start of processing for Collect_Global_List |
| 32512 |
|
| 32513 |
begin |
| 32514 |
if Nkind (List) = N_Null then |
| 32515 |
null; |
| 32516 |
|
| 32517 |
-- Single global item declaration |
| 32518 |
|
| 32519 |
elsif Nkind (List) in N_Expanded_Name |
| 32520 |
| N_Identifier |
| 32521 |
| N_Selected_Component |
| 32522 |
then |
| 32523 |
Collect_Global_Item (List, Mode); |
| 32524 |
|
| 32525 |
-- Simple global list or moded global list declaration |
| 32526 |
|
| 32527 |
elsif Nkind (List) = N_Aggregate then |
| 32528 |
if Present (Expressions (List)) then |
| 32529 |
Item := First (Expressions (List)); |
| 32530 |
while Present (Item) loop |
| 32531 |
Collect_Global_Item (Item, Mode); |
| 32532 |
Next (Item); |
| 32533 |
end loop; |
| 32534 |
|
| 32535 |
else |
| 32536 |
Assoc := First (Component_Associations (List)); |
| 32537 |
while Present (Assoc) loop |
| 32538 |
Collect_Global_List |
| 32539 |
(List => Expression (Assoc), |
| 32540 |
Mode => Chars (First (Choices (Assoc)))); |
| 32541 |
Next (Assoc); |
| 32542 |
end loop; |
| 32543 |
end if; |
| 32544 |
|
| 32545 |
-- To accommodate partial decoration of disabled SPARK features, this |
| 32546 |
-- routine may be called with illegal input. If this is the case, do |
| 32547 |
-- not raise Program_Error. |
| 32548 |
|
| 32549 |
else |
| 32550 |
null; |
| 32551 |
end if; |
| 32552 |
end Collect_Global_List; |
| 32553 |
|
| 32554 |
-- Local variables |
| 32555 |
|
| 32556 |
Clause : Node_Id; |
| 32557 |
Clauses : Node_Id; |
| 32558 |
Depends : Node_Id; |
| 32559 |
Formal : Entity_Id; |
| 32560 |
Global : Node_Id; |
| 32561 |
Spec_Id : Entity_Id := Empty; |
| 32562 |
Subp_Decl : Node_Id; |
| 32563 |
Typ : Entity_Id; |
| 32564 |
|
| 32565 |
-- Start of processing for Collect_Subprogram_Inputs_Outputs |
| 32566 |
|
| 32567 |
begin |
| 32568 |
Global_Seen := False; |
| 32569 |
|
| 32570 |
-- Process all formal parameters of entries, [generic] subprograms, and |
| 32571 |
-- their bodies. |
| 32572 |
|
| 32573 |
if Ekind (Subp_Id) in E_Entry |
| 32574 |
| E_Entry_Family |
| 32575 |
| E_Function |
| 32576 |
| E_Generic_Function |
| 32577 |
| E_Generic_Procedure |
| 32578 |
| E_Procedure |
| 32579 |
| E_Subprogram_Body |
| 32580 |
then |
| 32581 |
Subp_Decl := Unit_Declaration_Node (Subp_Id); |
| 32582 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 32583 |
|
| 32584 |
-- Process all formal parameters |
| 32585 |
|
| 32586 |
Formal := First_Formal (Spec_Id); |
| 32587 |
while Present (Formal) loop |
| 32588 |
if Ekind (Formal) in E_In_Out_Parameter | E_In_Parameter then |
| 32589 |
Append_New_Elmt (Formal, Subp_Inputs); |
| 32590 |
|
| 32591 |
-- IN parameters of procedures and protected entries can act as |
| 32592 |
-- outputs when the related type is access-to-variable. |
| 32593 |
|
| 32594 |
if Ekind (Formal) = E_In_Parameter |
| 32595 |
and then (Ekind (Spec_Id) not in E_Function |
| 32596 |
| E_Generic_Function |
| 32597 |
or else Is_Function_With_Side_Effects (Spec_Id)) |
| 32598 |
and then Is_Access_Variable (Etype (Formal)) |
| 32599 |
then |
| 32600 |
Append_New_Elmt (Formal, Subp_Outputs); |
| 32601 |
end if; |
| 32602 |
end if; |
| 32603 |
|
| 32604 |
if Ekind (Formal) in E_In_Out_Parameter | E_Out_Parameter then |
| 32605 |
Append_New_Elmt (Formal, Subp_Outputs); |
| 32606 |
|
| 32607 |
-- OUT parameters can act as inputs when the related type is |
| 32608 |
-- tagged, unconstrained array or unconstrained record. |
| 32609 |
|
| 32610 |
if Ekind (Formal) = E_Out_Parameter |
| 32611 |
and then Is_Unconstrained_Or_Tagged_Item (Formal) |
| 32612 |
then |
| 32613 |
Append_New_Elmt (Formal, Subp_Inputs); |
| 32614 |
end if; |
| 32615 |
end if; |
| 32616 |
|
| 32617 |
Next_Formal (Formal); |
| 32618 |
end loop; |
| 32619 |
|
| 32620 |
-- Otherwise the input denotes a task type, a task body, or the |
| 32621 |
-- anonymous object created for a single task type. |
| 32622 |
|
| 32623 |
elsif Ekind (Subp_Id) in E_Task_Type | E_Task_Body |
| 32624 |
or else Is_Single_Task_Object (Subp_Id) |
| 32625 |
then |
| 32626 |
Subp_Decl := Declaration_Node (Subp_Id); |
| 32627 |
Spec_Id := Unique_Defining_Entity (Subp_Decl); |
| 32628 |
end if; |
| 32629 |
|
| 32630 |
-- When processing an entry, subprogram or task body, look for pragmas |
| 32631 |
-- Refined_Depends and Refined_Global as they specify the inputs and |
| 32632 |
-- outputs. |
| 32633 |
|
| 32634 |
if Is_Entry_Body (Subp_Id) |
| 32635 |
or else Ekind (Subp_Id) in E_Subprogram_Body | E_Task_Body |
| 32636 |
then |
| 32637 |
Depends := Get_Pragma (Subp_Id, Pragma_Refined_Depends); |
| 32638 |
Global := Get_Pragma (Subp_Id, Pragma_Refined_Global); |
| 32639 |
|
| 32640 |
-- Subprogram declaration or stand-alone body case, look for pragmas |
| 32641 |
-- Depends and Global. |
| 32642 |
|
| 32643 |
else |
| 32644 |
Depends := Get_Pragma (Spec_Id, Pragma_Depends); |
| 32645 |
Global := Get_Pragma (Spec_Id, Pragma_Global); |
| 32646 |
end if; |
| 32647 |
|
| 32648 |
-- Pragma [Refined_]Global takes precedence over [Refined_]Depends |
| 32649 |
-- because it provides finer granularity of inputs and outputs. |
| 32650 |
|
| 32651 |
if Present (Global) then |
| 32652 |
Global_Seen := True; |
| 32653 |
Collect_Global_List (Expression (Get_Argument (Global, Spec_Id))); |
| 32654 |
|
| 32655 |
-- When the related subprogram lacks pragma [Refined_]Global, fall back |
| 32656 |
-- to [Refined_]Depends if the caller requests this behavior. Synthesize |
| 32657 |
-- the inputs and outputs from [Refined_]Depends. |
| 32658 |
|
| 32659 |
elsif Synthesize and then Present (Depends) then |
| 32660 |
Clauses := Expression (Get_Argument (Depends, Spec_Id)); |
| 32661 |
|
| 32662 |
-- Multiple dependency clauses appear as an aggregate |
| 32663 |
|
| 32664 |
if Nkind (Clauses) = N_Aggregate then |
| 32665 |
Clause := First (Component_Associations (Clauses)); |
| 32666 |
while Present (Clause) loop |
| 32667 |
Collect_Dependency_Clause (Clause); |
| 32668 |
Next (Clause); |
| 32669 |
end loop; |
| 32670 |
|
| 32671 |
-- Otherwise this is a single dependency clause |
| 32672 |
|
| 32673 |
else |
| 32674 |
Collect_Dependency_Clause (Clauses); |
| 32675 |
end if; |
| 32676 |
end if; |
| 32677 |
|
| 32678 |
-- The current instance of a protected type acts as a formal parameter |
| 32679 |
-- of mode IN for functions and IN OUT for entries and procedures |
| 32680 |
-- (SPARK RM 6.1.4). |
| 32681 |
|
| 32682 |
if Ekind (Scope (Spec_Id)) = E_Protected_Type then |
| 32683 |
Typ := Scope (Spec_Id); |
| 32684 |
|
| 32685 |
-- Use the anonymous object when the type is single protected |
| 32686 |
|
| 32687 |
if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then |
| 32688 |
Typ := Anonymous_Object (Typ); |
| 32689 |
end if; |
| 32690 |
|
| 32691 |
Append_New_Elmt (Typ, Subp_Inputs); |
| 32692 |
|
| 32693 |
if Ekind (Spec_Id) in E_Entry | E_Entry_Family | E_Procedure then |
| 32694 |
Append_New_Elmt (Typ, Subp_Outputs); |
| 32695 |
end if; |
| 32696 |
|
| 32697 |
-- The current instance of a task type acts as a formal parameter of |
| 32698 |
-- mode IN OUT (SPARK RM 6.1.4). |
| 32699 |
|
| 32700 |
elsif Ekind (Spec_Id) = E_Task_Type then |
| 32701 |
Typ := Spec_Id; |
| 32702 |
|
| 32703 |
-- Use the anonymous object when the type is single task |
| 32704 |
|
| 32705 |
if Is_Single_Concurrent_Type_Declaration (Declaration_Node (Typ)) then |
| 32706 |
Typ := Anonymous_Object (Typ); |
| 32707 |
end if; |
| 32708 |
|
| 32709 |
Append_New_Elmt (Typ, Subp_Inputs); |
| 32710 |
Append_New_Elmt (Typ, Subp_Outputs); |
| 32711 |
|
| 32712 |
elsif Is_Single_Task_Object (Spec_Id) then |
| 32713 |
Append_New_Elmt (Spec_Id, Subp_Inputs); |
| 32714 |
Append_New_Elmt (Spec_Id, Subp_Outputs); |
| 32715 |
end if; |
| 32716 |
end Collect_Subprogram_Inputs_Outputs; |
| 32717 |
|
| 32718 |
--------------------------- |
| 32719 |
-- Contract_Freeze_Error -- |
| 32720 |
--------------------------- |
| 32721 |
|
| 32722 |
procedure Contract_Freeze_Error |
| 32723 |
(Contract_Id : Entity_Id; |
| 32724 |
Freeze_Id : Entity_Id) |
| 32725 |
is |
| 32726 |
begin |
| 32727 |
Error_Msg_Name_1 := Chars (Contract_Id); |
| 32728 |
Error_Msg_Sloc := Sloc (Freeze_Id); |
| 32729 |
|
| 32730 |
SPARK_Msg_NE |
| 32731 |
("body & declared # freezes the contract of%", Contract_Id, Freeze_Id); |
| 32732 |
SPARK_Msg_N |
| 32733 |
("\all contractual items must be declared before body #", Contract_Id); |
| 32734 |
end Contract_Freeze_Error; |
| 32735 |
|
| 32736 |
--------------------------------- |
| 32737 |
-- Delay_Config_Pragma_Analyze -- |
| 32738 |
--------------------------------- |
| 32739 |
|
| 32740 |
function Delay_Config_Pragma_Analyze (N : Node_Id) return Boolean is |
| 32741 |
begin |
| 32742 |
return Pragma_Name_Unmapped (N) |
| 32743 |
in Name_Interrupt_State | Name_Priority_Specific_Dispatching; |
| 32744 |
end Delay_Config_Pragma_Analyze; |
| 32745 |
|
| 32746 |
----------------------- |
| 32747 |
-- Duplication_Error -- |
| 32748 |
----------------------- |
| 32749 |
|
| 32750 |
procedure Duplication_Error (Prag : Node_Id; Prev : Node_Id) is |
| 32751 |
Prag_From_Asp : constant Boolean := From_Aspect_Specification (Prag); |
| 32752 |
Prev_From_Asp : constant Boolean := From_Aspect_Specification (Prev); |
| 32753 |
|
| 32754 |
begin |
| 32755 |
Error_Msg_Sloc := Sloc (Prev); |
| 32756 |
Error_Msg_Name_1 := Original_Aspect_Pragma_Name (Prag); |
| 32757 |
|
| 32758 |
-- Emit a precise message to distinguish between source pragmas and |
| 32759 |
-- pragmas generated from aspects. The ordering of the two pragmas is |
| 32760 |
-- the following: |
| 32761 |
|
| 32762 |
-- Prev -- ok |
| 32763 |
-- Prag -- duplicate |
| 32764 |
|
| 32765 |
-- No error is emitted when both pragmas come from aspects because this |
| 32766 |
-- is already detected by the general aspect analysis mechanism. |
| 32767 |
|
| 32768 |
if Prag_From_Asp and Prev_From_Asp then |
| 32769 |
null; |
| 32770 |
elsif Prag_From_Asp then |
| 32771 |
Error_Msg_N ("aspect % duplicates pragma declared #", Prag); |
| 32772 |
elsif Prev_From_Asp then |
| 32773 |
Error_Msg_N ("pragma % duplicates aspect declared #", Prag); |
| 32774 |
else |
| 32775 |
Error_Msg_N ("pragma % duplicates pragma declared #", Prag); |
| 32776 |
end if; |
| 32777 |
end Duplication_Error; |
| 32778 |
|
| 32779 |
------------------------------ |
| 32780 |
-- Find_Encapsulating_State -- |
| 32781 |
------------------------------ |
| 32782 |
|
| 32783 |
function Find_Encapsulating_State |
| 32784 |
(States : Elist_Id; |
| 32785 |
Constit_Id : Entity_Id) return Entity_Id |
| 32786 |
is |
| 32787 |
State_Id : Entity_Id; |
| 32788 |
|
| 32789 |
begin |
| 32790 |
-- Since a constituent may be part of a larger constituent set, climb |
| 32791 |
-- the encapsulating state chain looking for a state that appears in |
| 32792 |
-- States. |
| 32793 |
|
| 32794 |
State_Id := Encapsulating_State (Constit_Id); |
| 32795 |
while Present (State_Id) loop |
| 32796 |
if Contains (States, State_Id) then |
| 32797 |
return State_Id; |
| 32798 |
end if; |
| 32799 |
|
| 32800 |
State_Id := Encapsulating_State (State_Id); |
| 32801 |
end loop; |
| 32802 |
|
| 32803 |
return Empty; |
| 32804 |
end Find_Encapsulating_State; |
| 32805 |
|
| 32806 |
-------------------------- |
| 32807 |
-- Find_Related_Context -- |
| 32808 |
-------------------------- |
| 32809 |
|
| 32810 |
function Find_Related_Context |
| 32811 |
(Prag : Node_Id; |
| 32812 |
Do_Checks : Boolean := False) return Node_Id |
| 32813 |
is |
| 32814 |
Stmt : Node_Id; |
| 32815 |
|
| 32816 |
begin |
| 32817 |
-- If the pragma comes from an aspect on a compilation unit that is a |
| 32818 |
-- package instance, then return the original package instantiation |
| 32819 |
-- node. |
| 32820 |
|
| 32821 |
if Nkind (Parent (Prag)) = N_Compilation_Unit_Aux then |
| 32822 |
return |
| 32823 |
Get_Unit_Instantiation_Node |
| 32824 |
(Defining_Entity (Unit (Enclosing_Comp_Unit_Node (Prag)))); |
| 32825 |
end if; |
| 32826 |
|
| 32827 |
Stmt := Prev (Prag); |
| 32828 |
while Present (Stmt) loop |
| 32829 |
|
| 32830 |
-- Skip prior pragmas, but check for duplicates |
| 32831 |
|
| 32832 |
if Nkind (Stmt) = N_Pragma then |
| 32833 |
if Do_Checks |
| 32834 |
and then Pragma_Name (Stmt) = Pragma_Name (Prag) |
| 32835 |
then |
| 32836 |
Duplication_Error |
| 32837 |
(Prag => Prag, |
| 32838 |
Prev => Stmt); |
| 32839 |
end if; |
| 32840 |
|
| 32841 |
-- Skip internally generated code |
| 32842 |
|
| 32843 |
elsif not Comes_From_Source (Stmt) |
| 32844 |
and then not Comes_From_Source (Original_Node (Stmt)) |
| 32845 |
then |
| 32846 |
|
| 32847 |
-- The anonymous object created for a single concurrent type is a |
| 32848 |
-- suitable context. |
| 32849 |
|
| 32850 |
if Nkind (Stmt) = N_Object_Declaration |
| 32851 |
and then Is_Single_Concurrent_Object (Defining_Entity (Stmt)) |
| 32852 |
then |
| 32853 |
return Stmt; |
| 32854 |
end if; |
| 32855 |
|
| 32856 |
-- Return the current source construct |
| 32857 |
|
| 32858 |
else |
| 32859 |
return Stmt; |
| 32860 |
end if; |
| 32861 |
|
| 32862 |
Prev (Stmt); |
| 32863 |
end loop; |
| 32864 |
|
| 32865 |
return Empty; |
| 32866 |
end Find_Related_Context; |
| 32867 |
|
| 32868 |
-------------------------------------- |
| 32869 |
-- Find_Related_Declaration_Or_Body -- |
| 32870 |
-------------------------------------- |
| 32871 |
|
| 32872 |
function Find_Related_Declaration_Or_Body |
| 32873 |
(Prag : Node_Id; |
| 32874 |
Do_Checks : Boolean := False) return Node_Id |
| 32875 |
is |
| 32876 |
Prag_Nam : constant Name_Id := Original_Aspect_Pragma_Name (Prag); |
| 32877 |
|
| 32878 |
procedure Expression_Function_Error; |
| 32879 |
-- Emit an error concerning pragma Prag that illegaly applies to an |
| 32880 |
-- expression function. |
| 32881 |
|
| 32882 |
------------------------------- |
| 32883 |
-- Expression_Function_Error -- |
| 32884 |
------------------------------- |
| 32885 |
|
| 32886 |
procedure Expression_Function_Error is |
| 32887 |
begin |
| 32888 |
Error_Msg_Name_1 := Prag_Nam; |
| 32889 |
|
| 32890 |
-- Emit a precise message to distinguish between source pragmas and |
| 32891 |
-- pragmas generated from aspects. |
| 32892 |
|
| 32893 |
if From_Aspect_Specification (Prag) then |
| 32894 |
Error_Msg_N |
| 32895 |
("aspect % cannot apply to a standalone expression function", |
| 32896 |
Prag); |
| 32897 |
else |
| 32898 |
Error_Msg_N |
| 32899 |
("pragma % cannot apply to a standalone expression function", |
| 32900 |
Prag); |
| 32901 |
end if; |
| 32902 |
end Expression_Function_Error; |
| 32903 |
|
| 32904 |
-- Local variables |
| 32905 |
|
| 32906 |
Context : constant Node_Id := Parent (Prag); |
| 32907 |
Stmt : Node_Id; |
| 32908 |
|
| 32909 |
Look_For_Body : constant Boolean := |
| 32910 |
Prag_Nam in Name_Refined_Depends |
| 32911 |
| Name_Refined_Global |
| 32912 |
| Name_Refined_Post |
| 32913 |
| Name_Refined_State; |
| 32914 |
-- Refinement pragmas must be associated with a subprogram body [stub] |
| 32915 |
|
| 32916 |
-- Start of processing for Find_Related_Declaration_Or_Body |
| 32917 |
|
| 32918 |
begin |
| 32919 |
Stmt := Prev (Prag); |
| 32920 |
while Present (Stmt) loop |
| 32921 |
|
| 32922 |
-- Skip prior pragmas, but check for duplicates |
| 32923 |
|
| 32924 |
if Nkind (Stmt) = N_Pragma then |
| 32925 |
if Do_Checks |
| 32926 |
and then Original_Aspect_Pragma_Name (Stmt) = Prag_Nam |
| 32927 |
then |
| 32928 |
Duplication_Error |
| 32929 |
(Prag => Prag, |
| 32930 |
Prev => Stmt); |
| 32931 |
end if; |
| 32932 |
|
| 32933 |
-- Emit an error when a refinement pragma appears on an expression |
| 32934 |
-- function without a completion. |
| 32935 |
|
| 32936 |
elsif Do_Checks |
| 32937 |
and then Look_For_Body |
| 32938 |
and then Nkind (Stmt) = N_Subprogram_Declaration |
| 32939 |
and then Nkind (Original_Node (Stmt)) = N_Expression_Function |
| 32940 |
and then not Has_Completion (Defining_Entity (Stmt)) |
| 32941 |
then |
| 32942 |
Expression_Function_Error; |
| 32943 |
return Empty; |
| 32944 |
|
| 32945 |
-- The refinement pragma applies to a subprogram body stub |
| 32946 |
|
| 32947 |
elsif Look_For_Body |
| 32948 |
and then Nkind (Stmt) = N_Subprogram_Body_Stub |
| 32949 |
then |
| 32950 |
return Stmt; |
| 32951 |
|
| 32952 |
-- Skip internally generated code |
| 32953 |
|
| 32954 |
elsif not Comes_From_Source (Stmt) then |
| 32955 |
|
| 32956 |
-- The anonymous object created for a single concurrent type is a |
| 32957 |
-- suitable context. |
| 32958 |
|
| 32959 |
if Nkind (Stmt) = N_Object_Declaration |
| 32960 |
and then Is_Single_Concurrent_Object (Defining_Entity (Stmt)) |
| 32961 |
then |
| 32962 |
return Stmt; |
| 32963 |
|
| 32964 |
elsif Nkind (Stmt) = N_Subprogram_Declaration then |
| 32965 |
|
| 32966 |
-- The subprogram declaration is an internally generated spec |
| 32967 |
-- for an expression function. |
| 32968 |
|
| 32969 |
if Nkind (Original_Node (Stmt)) = N_Expression_Function then |
| 32970 |
return Stmt; |
| 32971 |
|
| 32972 |
-- The subprogram declaration is an internally generated spec |
| 32973 |
-- for a stand-alone subprogram body declared inside a |
| 32974 |
-- protected body. |
| 32975 |
|
| 32976 |
elsif Present (Corresponding_Body (Stmt)) |
| 32977 |
and then Comes_From_Source (Corresponding_Body (Stmt)) |
| 32978 |
and then Is_Protected_Type (Current_Scope) |
| 32979 |
then |
| 32980 |
return Stmt; |
| 32981 |
|
| 32982 |
-- The subprogram is actually an instance housed within an |
| 32983 |
-- anonymous wrapper package. |
| 32984 |
|
| 32985 |
elsif Present (Generic_Parent (Specification (Stmt))) then |
| 32986 |
return Stmt; |
| 32987 |
|
| 32988 |
-- Ada 2022: contract on formal subprogram or on generated |
| 32989 |
-- Access_Subprogram_Wrapper, which appears after the related |
| 32990 |
-- Access_Subprogram declaration. |
| 32991 |
|
| 32992 |
elsif Is_Generic_Actual_Subprogram (Defining_Entity (Stmt)) |
| 32993 |
and then Ada_Version >= Ada_2022 |
| 32994 |
then |
| 32995 |
return Stmt; |
| 32996 |
|
| 32997 |
elsif Is_Access_Subprogram_Wrapper (Defining_Entity (Stmt)) |
| 32998 |
and then Ada_Version >= Ada_2022 |
| 32999 |
then |
| 33000 |
return Stmt; |
| 33001 |
end if; |
| 33002 |
end if; |
| 33003 |
|
| 33004 |
-- Return the current construct which is either a subprogram body, |
| 33005 |
-- a subprogram declaration or is illegal. |
| 33006 |
|
| 33007 |
else |
| 33008 |
return Stmt; |
| 33009 |
end if; |
| 33010 |
|
| 33011 |
Prev (Stmt); |
| 33012 |
end loop; |
| 33013 |
|
| 33014 |
-- If we fall through, then the pragma was either the first declaration |
| 33015 |
-- or it was preceded by other pragmas and no source constructs. |
| 33016 |
|
| 33017 |
-- The pragma is associated with a library-level subprogram |
| 33018 |
|
| 33019 |
if Nkind (Context) = N_Compilation_Unit_Aux then |
| 33020 |
return Unit (Parent (Context)); |
| 33021 |
|
| 33022 |
-- The pragma appears inside the declarations of an entry body |
| 33023 |
|
| 33024 |
elsif Nkind (Context) = N_Entry_Body then |
| 33025 |
return Context; |
| 33026 |
|
| 33027 |
-- The pragma appears inside the statements of a subprogram body at |
| 33028 |
-- some nested level. |
| 33029 |
|
| 33030 |
elsif Is_Statement (Context) |
| 33031 |
and then Present (Enclosing_HSS (Context)) |
| 33032 |
then |
| 33033 |
return Parent (Enclosing_HSS (Context)); |
| 33034 |
|
| 33035 |
-- The pragma appears directly in the statements of a subprogram body |
| 33036 |
|
| 33037 |
elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then |
| 33038 |
return Parent (Context); |
| 33039 |
|
| 33040 |
-- The pragma appears inside the declarative part of a package body |
| 33041 |
|
| 33042 |
elsif Nkind (Context) = N_Package_Body then |
| 33043 |
return Context; |
| 33044 |
|
| 33045 |
-- The pragma appears inside the declarative part of a subprogram body |
| 33046 |
|
| 33047 |
elsif Nkind (Context) = N_Subprogram_Body then |
| 33048 |
return Context; |
| 33049 |
|
| 33050 |
-- The pragma appears inside the declarative part of a task body |
| 33051 |
|
| 33052 |
elsif Nkind (Context) = N_Task_Body then |
| 33053 |
return Context; |
| 33054 |
|
| 33055 |
-- The pragma appears inside the visible part of a package specification |
| 33056 |
|
| 33057 |
elsif Nkind (Context) = N_Package_Specification then |
| 33058 |
return Parent (Context); |
| 33059 |
|
| 33060 |
-- The pragma is a byproduct of aspect expansion, return the related |
| 33061 |
-- context of the original aspect. This case has a lower priority as |
| 33062 |
-- the above circuitry pinpoints precisely the related context. |
| 33063 |
|
| 33064 |
elsif Present (Corresponding_Aspect (Prag)) then |
| 33065 |
return Parent (Corresponding_Aspect (Prag)); |
| 33066 |
|
| 33067 |
-- No candidate subprogram [body] found |
| 33068 |
|
| 33069 |
else |
| 33070 |
return Empty; |
| 33071 |
end if; |
| 33072 |
end Find_Related_Declaration_Or_Body; |
| 33073 |
|
| 33074 |
---------------------------------- |
| 33075 |
-- Find_Related_Package_Or_Body -- |
| 33076 |
---------------------------------- |
| 33077 |
|
| 33078 |
function Find_Related_Package_Or_Body |
| 33079 |
(Prag : Node_Id; |
| 33080 |
Do_Checks : Boolean := False) return Node_Id |
| 33081 |
is |
| 33082 |
Context : constant Node_Id := Parent (Prag); |
| 33083 |
Prag_Nam : constant Name_Id := Pragma_Name (Prag); |
| 33084 |
Stmt : Node_Id; |
| 33085 |
|
| 33086 |
begin |
| 33087 |
Stmt := Prev (Prag); |
| 33088 |
while Present (Stmt) loop |
| 33089 |
|
| 33090 |
-- Skip prior pragmas, but check for duplicates |
| 33091 |
|
| 33092 |
if Nkind (Stmt) = N_Pragma then |
| 33093 |
if Do_Checks and then Pragma_Name (Stmt) = Prag_Nam then |
| 33094 |
Duplication_Error |
| 33095 |
(Prag => Prag, |
| 33096 |
Prev => Stmt); |
| 33097 |
end if; |
| 33098 |
|
| 33099 |
-- Skip internally generated code |
| 33100 |
|
| 33101 |
elsif not Comes_From_Source (Stmt) then |
| 33102 |
if Nkind (Stmt) = N_Subprogram_Declaration then |
| 33103 |
|
| 33104 |
-- The subprogram declaration is an internally generated spec |
| 33105 |
-- for an expression function. |
| 33106 |
|
| 33107 |
if Nkind (Original_Node (Stmt)) = N_Expression_Function then |
| 33108 |
return Stmt; |
| 33109 |
|
| 33110 |
-- The subprogram is actually an instance housed within an |
| 33111 |
-- anonymous wrapper package. |
| 33112 |
|
| 33113 |
elsif Present (Generic_Parent (Specification (Stmt))) then |
| 33114 |
return Stmt; |
| 33115 |
end if; |
| 33116 |
end if; |
| 33117 |
|
| 33118 |
-- Return the current source construct which is illegal |
| 33119 |
|
| 33120 |
else |
| 33121 |
return Stmt; |
| 33122 |
end if; |
| 33123 |
|
| 33124 |
Prev (Stmt); |
| 33125 |
end loop; |
| 33126 |
|
| 33127 |
-- If we fall through, then the pragma was either the first declaration |
| 33128 |
-- or it was preceded by other pragmas and no source constructs. |
| 33129 |
|
| 33130 |
-- The pragma is associated with a package. The immediate context in |
| 33131 |
-- this case is the specification of the package. |
| 33132 |
|
| 33133 |
if Nkind (Context) = N_Package_Specification then |
| 33134 |
return Parent (Context); |
| 33135 |
|
| 33136 |
-- The pragma appears in the declarations of a package body |
| 33137 |
|
| 33138 |
elsif Nkind (Context) = N_Package_Body then |
| 33139 |
return Context; |
| 33140 |
|
| 33141 |
-- The pragma appears in the statements of a package body |
| 33142 |
|
| 33143 |
elsif Nkind (Context) = N_Handled_Sequence_Of_Statements |
| 33144 |
and then Nkind (Parent (Context)) = N_Package_Body |
| 33145 |
then |
| 33146 |
return Parent (Context); |
| 33147 |
|
| 33148 |
-- The pragma is a byproduct of aspect expansion, return the related |
| 33149 |
-- context of the original aspect. This case has a lower priority as |
| 33150 |
-- the above circuitry pinpoints precisely the related context. |
| 33151 |
|
| 33152 |
elsif Present (Corresponding_Aspect (Prag)) then |
| 33153 |
return Parent (Corresponding_Aspect (Prag)); |
| 33154 |
|
| 33155 |
-- No candidate package [body] found |
| 33156 |
|
| 33157 |
else |
| 33158 |
return Empty; |
| 33159 |
end if; |
| 33160 |
end Find_Related_Package_Or_Body; |
| 33161 |
|
| 33162 |
------------------ |
| 33163 |
-- Get_Argument -- |
| 33164 |
------------------ |
| 33165 |
|
| 33166 |
function Get_Argument |
| 33167 |
(Prag : Node_Id; |
| 33168 |
Context_Id : Entity_Id := Empty) return Node_Id |
| 33169 |
is |
| 33170 |
Args : constant List_Id := Pragma_Argument_Associations (Prag); |
| 33171 |
|
| 33172 |
begin |
| 33173 |
-- Use the expression of the original aspect when analyzing the template |
| 33174 |
-- of a generic unit. In both cases the aspect's tree must be decorated |
| 33175 |
-- to save the global references in the generic context. |
| 33176 |
|
| 33177 |
if From_Aspect_Specification (Prag) |
| 33178 |
and then Present (Context_Id) |
| 33179 |
and then |
| 33180 |
Is_Generic_Declaration_Or_Body (Unit_Declaration_Node (Context_Id)) |
| 33181 |
then |
| 33182 |
return Corresponding_Aspect (Prag); |
| 33183 |
|
| 33184 |
-- Otherwise use the expression of the pragma |
| 33185 |
|
| 33186 |
elsif Present (Args) then |
| 33187 |
return First (Args); |
| 33188 |
|
| 33189 |
else |
| 33190 |
return Empty; |
| 33191 |
end if; |
| 33192 |
end Get_Argument; |
| 33193 |
|
| 33194 |
------------------------- |
| 33195 |
-- Get_Base_Subprogram -- |
| 33196 |
------------------------- |
| 33197 |
|
| 33198 |
function Get_Base_Subprogram (Def_Id : Entity_Id) return Entity_Id is |
| 33199 |
begin |
| 33200 |
-- Follow subprogram renaming chain |
| 33201 |
|
| 33202 |
if Is_Subprogram (Def_Id) |
| 33203 |
and then Parent_Kind (Declaration_Node (Def_Id)) = |
| 33204 |
N_Subprogram_Renaming_Declaration |
| 33205 |
and then Present (Alias (Def_Id)) |
| 33206 |
then |
| 33207 |
return Alias (Def_Id); |
| 33208 |
else |
| 33209 |
return Def_Id; |
| 33210 |
end if; |
| 33211 |
end Get_Base_Subprogram; |
| 33212 |
|
| 33213 |
------------------------- |
| 33214 |
-- Get_SPARK_Mode_Type -- |
| 33215 |
------------------------- |
| 33216 |
|
| 33217 |
function Get_SPARK_Mode_Type (N : Name_Id) return SPARK_Mode_Type is |
| 33218 |
begin |
| 33219 |
case N is |
| 33220 |
when Name_Auto => |
| 33221 |
return None; |
| 33222 |
when Name_On => |
| 33223 |
return On; |
| 33224 |
when Name_Off => |
| 33225 |
return Off; |
| 33226 |
|
| 33227 |
-- Any other argument is illegal. Assume that no SPARK mode applies |
| 33228 |
-- to avoid potential cascaded errors. |
| 33229 |
|
| 33230 |
when others => |
| 33231 |
return None; |
| 33232 |
end case; |
| 33233 |
end Get_SPARK_Mode_Type; |
| 33234 |
|
| 33235 |
------------------------------------ |
| 33236 |
-- Get_SPARK_Mode_From_Annotation -- |
| 33237 |
------------------------------------ |
| 33238 |
|
| 33239 |
function Get_SPARK_Mode_From_Annotation |
| 33240 |
(N : Node_Id) return SPARK_Mode_Type |
| 33241 |
is |
| 33242 |
Mode : Node_Id; |
| 33243 |
|
| 33244 |
begin |
| 33245 |
if Nkind (N) = N_Aspect_Specification then |
| 33246 |
Mode := Expression (N); |
| 33247 |
|
| 33248 |
else pragma Assert (Nkind (N) = N_Pragma); |
| 33249 |
Mode := First (Pragma_Argument_Associations (N)); |
| 33250 |
|
| 33251 |
if Present (Mode) then |
| 33252 |
Mode := Get_Pragma_Arg (Mode); |
| 33253 |
end if; |
| 33254 |
end if; |
| 33255 |
|
| 33256 |
-- Aspect or pragma SPARK_Mode specifies an explicit mode |
| 33257 |
|
| 33258 |
if Present (Mode) then |
| 33259 |
if Nkind (Mode) = N_Identifier then |
| 33260 |
return Get_SPARK_Mode_Type (Chars (Mode)); |
| 33261 |
|
| 33262 |
-- In case of a malformed aspect or pragma, return the default None |
| 33263 |
|
| 33264 |
else |
| 33265 |
return None; |
| 33266 |
end if; |
| 33267 |
|
| 33268 |
-- Otherwise the lack of an expression defaults SPARK_Mode to On |
| 33269 |
|
| 33270 |
else |
| 33271 |
return On; |
| 33272 |
end if; |
| 33273 |
end Get_SPARK_Mode_From_Annotation; |
| 33274 |
|
| 33275 |
--------------------------- |
| 33276 |
-- Has_Extra_Parentheses -- |
| 33277 |
--------------------------- |
| 33278 |
|
| 33279 |
function Has_Extra_Parentheses (Clause : Node_Id) return Boolean is |
| 33280 |
Expr : Node_Id; |
| 33281 |
|
| 33282 |
begin |
| 33283 |
-- The aggregate should not have an expression list because a clause |
| 33284 |
-- is always interpreted as a component association. The only way an |
| 33285 |
-- expression list can sneak in is by adding extra parentheses around |
| 33286 |
-- the individual clauses: |
| 33287 |
|
| 33288 |
-- Depends (Output => Input) -- proper form |
| 33289 |
-- Depends ((Output => Input)) -- extra parentheses |
| 33290 |
|
| 33291 |
-- Since the extra parentheses are not allowed by the syntax of the |
| 33292 |
-- pragma, flag them now to avoid emitting misleading errors down the |
| 33293 |
-- line. |
| 33294 |
|
| 33295 |
if Nkind (Clause) = N_Aggregate |
| 33296 |
and then Present (Expressions (Clause)) |
| 33297 |
then |
| 33298 |
Expr := First (Expressions (Clause)); |
| 33299 |
while Present (Expr) loop |
| 33300 |
|
| 33301 |
-- A dependency clause surrounded by extra parentheses appears |
| 33302 |
-- as an aggregate of component associations with an optional |
| 33303 |
-- Paren_Count set. |
| 33304 |
|
| 33305 |
if Nkind (Expr) = N_Aggregate |
| 33306 |
and then Present (Component_Associations (Expr)) |
| 33307 |
then |
| 33308 |
SPARK_Msg_N |
| 33309 |
("dependency clause contains extra parentheses", Expr); |
| 33310 |
|
| 33311 |
-- Otherwise the expression is a malformed construct |
| 33312 |
|
| 33313 |
else |
| 33314 |
SPARK_Msg_N ("malformed dependency clause", Expr); |
| 33315 |
end if; |
| 33316 |
|
| 33317 |
Next (Expr); |
| 33318 |
end loop; |
| 33319 |
|
| 33320 |
return True; |
| 33321 |
end if; |
| 33322 |
|
| 33323 |
return False; |
| 33324 |
end Has_Extra_Parentheses; |
| 33325 |
|
| 33326 |
---------------- |
| 33327 |
-- Initialize -- |
| 33328 |
---------------- |
| 33329 |
|
| 33330 |
procedure Initialize is |
| 33331 |
begin |
| 33332 |
Externals.Init; |
| 33333 |
Compile_Time_Warnings_Errors.Init; |
| 33334 |
end Initialize; |
| 33335 |
|
| 33336 |
-------- |
| 33337 |
-- ip -- |
| 33338 |
-------- |
| 33339 |
|
| 33340 |
procedure ip is |
| 33341 |
begin |
| 33342 |
Dummy := Dummy + 1; |
| 33343 |
end ip; |
| 33344 |
|
| 33345 |
----------------------------- |
| 33346 |
-- Is_Config_Static_String -- |
| 33347 |
----------------------------- |
| 33348 |
|
| 33349 |
function Is_Config_Static_String (Arg : Node_Id) return Boolean is |
| 33350 |
|
| 33351 |
function Add_Config_Static_String (Arg : Node_Id) return Boolean; |
| 33352 |
-- This is an internal recursive function that is just like the outer |
| 33353 |
-- function except that it adds the string to the name buffer rather |
| 33354 |
-- than placing the string in the name buffer. |
| 33355 |
|
| 33356 |
------------------------------ |
| 33357 |
-- Add_Config_Static_String -- |
| 33358 |
------------------------------ |
| 33359 |
|
| 33360 |
function Add_Config_Static_String (Arg : Node_Id) return Boolean is |
| 33361 |
N : Node_Id; |
| 33362 |
C : Char_Code; |
| 33363 |
|
| 33364 |
begin |
| 33365 |
N := Arg; |
| 33366 |
|
| 33367 |
if Nkind (N) = N_Op_Concat then |
| 33368 |
if Add_Config_Static_String (Left_Opnd (N)) then |
| 33369 |
N := Right_Opnd (N); |
| 33370 |
else |
| 33371 |
return False; |
| 33372 |
end if; |
| 33373 |
end if; |
| 33374 |
|
| 33375 |
if Nkind (N) /= N_String_Literal then |
| 33376 |
Error_Msg_N ("string literal expected for pragma argument", N); |
| 33377 |
return False; |
| 33378 |
|
| 33379 |
else |
| 33380 |
for J in 1 .. String_Length (Strval (N)) loop |
| 33381 |
C := Get_String_Char (Strval (N), J); |
| 33382 |
|
| 33383 |
if not In_Character_Range (C) then |
| 33384 |
Error_Msg |
| 33385 |
("string literal contains invalid wide character", |
| 33386 |
Sloc (N) + 1 + Source_Ptr (J)); |
| 33387 |
return False; |
| 33388 |
end if; |
| 33389 |
|
| 33390 |
Add_Char_To_Name_Buffer (Get_Character (C)); |
| 33391 |
end loop; |
| 33392 |
end if; |
| 33393 |
|
| 33394 |
return True; |
| 33395 |
end Add_Config_Static_String; |
| 33396 |
|
| 33397 |
-- Start of processing for Is_Config_Static_String |
| 33398 |
|
| 33399 |
begin |
| 33400 |
Name_Len := 0; |
| 33401 |
|
| 33402 |
return Add_Config_Static_String (Arg); |
| 33403 |
end Is_Config_Static_String; |
| 33404 |
|
| 33405 |
------------------------------- |
| 33406 |
-- Is_Elaboration_SPARK_Mode -- |
| 33407 |
------------------------------- |
| 33408 |
|
| 33409 |
function Is_Elaboration_SPARK_Mode (N : Node_Id) return Boolean is |
| 33410 |
begin |
| 33411 |
pragma Assert |
| 33412 |
(Nkind (N) = N_Pragma |
| 33413 |
and then Pragma_Name (N) = Name_SPARK_Mode |
| 33414 |
and then Is_List_Member (N)); |
| 33415 |
|
| 33416 |
-- Pragma SPARK_Mode affects the elaboration of a package body when it |
| 33417 |
-- appears in the statement part of the body. |
| 33418 |
|
| 33419 |
return |
| 33420 |
Present (Parent (N)) |
| 33421 |
and then Nkind (Parent (N)) = N_Handled_Sequence_Of_Statements |
| 33422 |
and then List_Containing (N) = Statements (Parent (N)) |
| 33423 |
and then Present (Parent (Parent (N))) |
| 33424 |
and then Nkind (Parent (Parent (N))) = N_Package_Body; |
| 33425 |
end Is_Elaboration_SPARK_Mode; |
| 33426 |
|
| 33427 |
----------------------- |
| 33428 |
-- Is_Enabled_Pragma -- |
| 33429 |
----------------------- |
| 33430 |
|
| 33431 |
function Is_Enabled_Pragma (Prag : Node_Id) return Boolean is |
| 33432 |
Arg : Node_Id; |
| 33433 |
|
| 33434 |
begin |
| 33435 |
if Present (Prag) then |
| 33436 |
Arg := First (Pragma_Argument_Associations (Prag)); |
| 33437 |
|
| 33438 |
if Present (Arg) then |
| 33439 |
return Is_True (Expr_Value (Get_Pragma_Arg (Arg))); |
| 33440 |
|
| 33441 |
-- The lack of a Boolean argument automatically enables the pragma |
| 33442 |
|
| 33443 |
else |
| 33444 |
return True; |
| 33445 |
end if; |
| 33446 |
|
| 33447 |
-- The pragma is missing, therefore it is not enabled |
| 33448 |
|
| 33449 |
else |
| 33450 |
return False; |
| 33451 |
end if; |
| 33452 |
end Is_Enabled_Pragma; |
| 33453 |
|
| 33454 |
----------------------------------------- |
| 33455 |
-- Is_Non_Significant_Pragma_Reference -- |
| 33456 |
----------------------------------------- |
| 33457 |
|
| 33458 |
-- This function makes use of the following static table which indicates |
| 33459 |
-- whether appearance of some name in a given pragma is to be considered |
| 33460 |
-- as a reference for the purposes of warnings about unreferenced objects. |
| 33461 |
|
| 33462 |
-- -1 indicates that appearance in any argument is significant |
| 33463 |
-- 0 indicates that appearance in any argument is not significant |
| 33464 |
-- +n indicates that appearance as argument n is significant, but all |
| 33465 |
-- other arguments are not significant |
| 33466 |
-- 9n arguments from n on are significant, before n insignificant |
| 33467 |
|
| 33468 |
Sig_Flags : constant array (Pragma_Id) of Int := |
| 33469 |
(Pragma_Abort_Defer => -1, |
| 33470 |
Pragma_Abstract_State => -1, |
| 33471 |
Pragma_Ada_83 => -1, |
| 33472 |
Pragma_Ada_95 => -1, |
| 33473 |
Pragma_Ada_05 => -1, |
| 33474 |
Pragma_Ada_2005 => -1, |
| 33475 |
Pragma_Ada_12 => -1, |
| 33476 |
Pragma_Ada_2012 => -1, |
| 33477 |
Pragma_Ada_2022 => -1, |
| 33478 |
Pragma_Aggregate_Individually_Assign => 0, |
| 33479 |
Pragma_All_Calls_Remote => -1, |
| 33480 |
Pragma_Allow_Integer_Address => -1, |
| 33481 |
Pragma_Always_Terminates => -1, |
| 33482 |
Pragma_Annotate => 93, |
| 33483 |
Pragma_Assert => -1, |
| 33484 |
Pragma_Assert_And_Cut => -1, |
| 33485 |
Pragma_Assertion_Policy => 0, |
| 33486 |
Pragma_Assume => -1, |
| 33487 |
Pragma_Assume_No_Invalid_Values => 0, |
| 33488 |
Pragma_Async_Readers => 0, |
| 33489 |
Pragma_Async_Writers => 0, |
| 33490 |
Pragma_Asynchronous => 0, |
| 33491 |
Pragma_Atomic => 0, |
| 33492 |
Pragma_Atomic_Components => 0, |
| 33493 |
Pragma_Attach_Handler => -1, |
| 33494 |
Pragma_Attribute_Definition => 92, |
| 33495 |
Pragma_Check => -1, |
| 33496 |
Pragma_Check_Float_Overflow => 0, |
| 33497 |
Pragma_Check_Name => 0, |
| 33498 |
Pragma_Check_Policy => 0, |
| 33499 |
Pragma_CPP_Class => 0, |
| 33500 |
Pragma_CPP_Constructor => 0, |
| 33501 |
Pragma_CPP_Virtual => 0, |
| 33502 |
Pragma_CPP_Vtable => 0, |
| 33503 |
Pragma_CPU => -1, |
| 33504 |
Pragma_C_Pass_By_Copy => 0, |
| 33505 |
Pragma_Comment => -1, |
| 33506 |
Pragma_Common_Object => 0, |
| 33507 |
Pragma_CUDA_Device => -1, |
| 33508 |
Pragma_CUDA_Execute => -1, |
| 33509 |
Pragma_CUDA_Global => -1, |
| 33510 |
Pragma_Compile_Time_Error => -1, |
| 33511 |
Pragma_Compile_Time_Warning => -1, |
| 33512 |
Pragma_Complete_Representation => 0, |
| 33513 |
Pragma_Complex_Representation => 0, |
| 33514 |
Pragma_Component_Alignment => 0, |
| 33515 |
Pragma_Constant_After_Elaboration => 0, |
| 33516 |
Pragma_Contract_Cases => -1, |
| 33517 |
Pragma_Controlled => 0, |
| 33518 |
Pragma_Convention => 0, |
| 33519 |
Pragma_Convention_Identifier => 0, |
| 33520 |
Pragma_Deadline_Floor => -1, |
| 33521 |
Pragma_Debug => -1, |
| 33522 |
Pragma_Debug_Policy => 0, |
| 33523 |
Pragma_Default_Initial_Condition => -1, |
| 33524 |
Pragma_Default_Scalar_Storage_Order => 0, |
| 33525 |
Pragma_Default_Storage_Pool => 0, |
| 33526 |
Pragma_Depends => -1, |
| 33527 |
Pragma_Detect_Blocking => 0, |
| 33528 |
Pragma_Disable_Atomic_Synchronization => 0, |
| 33529 |
Pragma_Discard_Names => 0, |
| 33530 |
Pragma_Dispatching_Domain => -1, |
| 33531 |
Pragma_Effective_Reads => 0, |
| 33532 |
Pragma_Effective_Writes => 0, |
| 33533 |
Pragma_Elaborate => 0, |
| 33534 |
Pragma_Elaborate_All => 0, |
| 33535 |
Pragma_Elaborate_Body => 0, |
| 33536 |
Pragma_Elaboration_Checks => 0, |
| 33537 |
Pragma_Eliminate => 0, |
| 33538 |
Pragma_Enable_Atomic_Synchronization => 0, |
| 33539 |
Pragma_Exceptional_Cases => -1, |
| 33540 |
Pragma_Exit_Cases => -1, |
| 33541 |
Pragma_Export => -1, |
| 33542 |
Pragma_Export_Function => -1, |
| 33543 |
Pragma_Export_Object => -1, |
| 33544 |
Pragma_Export_Procedure => -1, |
| 33545 |
Pragma_Export_Valued_Procedure => -1, |
| 33546 |
Pragma_Extend_System => -1, |
| 33547 |
Pragma_Extended_Access => 0, |
| 33548 |
Pragma_Extensions_Allowed => 0, |
| 33549 |
Pragma_Extensions_Visible => 0, |
| 33550 |
Pragma_External => -1, |
| 33551 |
Pragma_External_Name_Casing => 0, |
| 33552 |
Pragma_Fast_Math => 0, |
| 33553 |
Pragma_Favor_Top_Level => 0, |
| 33554 |
Pragma_Finalize_Storage_Only => 0, |
| 33555 |
Pragma_First_Controlling_Parameter => 0, |
| 33556 |
Pragma_Ghost => 0, |
| 33557 |
Pragma_Global => -1, |
| 33558 |
Pragma_GNAT_Annotate => 93, |
| 33559 |
Pragma_Ident => -1, |
| 33560 |
Pragma_Ignore_Pragma => 0, |
| 33561 |
Pragma_Implementation_Defined => -1, |
| 33562 |
Pragma_Implemented => -1, |
| 33563 |
Pragma_Implicit_Packing => 0, |
| 33564 |
Pragma_Import => 93, |
| 33565 |
Pragma_Import_Function => 0, |
| 33566 |
Pragma_Import_Object => 0, |
| 33567 |
Pragma_Import_Procedure => 0, |
| 33568 |
Pragma_Import_Valued_Procedure => 0, |
| 33569 |
Pragma_Independent => 0, |
| 33570 |
Pragma_Independent_Components => 0, |
| 33571 |
Pragma_Initial_Condition => -1, |
| 33572 |
Pragma_Initialize_Scalars => 0, |
| 33573 |
Pragma_Initializes => -1, |
| 33574 |
Pragma_Inline => 0, |
| 33575 |
Pragma_Inline_Always => 0, |
| 33576 |
Pragma_Inline_Generic => 0, |
| 33577 |
Pragma_Inspection_Point => -1, |
| 33578 |
Pragma_Interface => 92, |
| 33579 |
Pragma_Interface_Name => 0, |
| 33580 |
Pragma_Interrupt_Handler => -1, |
| 33581 |
Pragma_Interrupt_Priority => -1, |
| 33582 |
Pragma_Interrupt_State => -1, |
| 33583 |
Pragma_Invariant => -1, |
| 33584 |
Pragma_Keep_Names => 0, |
| 33585 |
Pragma_License => 0, |
| 33586 |
Pragma_Link_With => -1, |
| 33587 |
Pragma_Linker_Alias => -1, |
| 33588 |
Pragma_Linker_Constructor => -1, |
| 33589 |
Pragma_Linker_Destructor => -1, |
| 33590 |
Pragma_Linker_Options => -1, |
| 33591 |
Pragma_Linker_Section => -1, |
| 33592 |
Pragma_List => 0, |
| 33593 |
Pragma_Lock_Free => 0, |
| 33594 |
Pragma_Locking_Policy => 0, |
| 33595 |
Pragma_Loop_Invariant => -1, |
| 33596 |
Pragma_Loop_Optimize => 0, |
| 33597 |
Pragma_Loop_Variant => -1, |
| 33598 |
Pragma_Machine_Attribute => -1, |
| 33599 |
Pragma_Main => -1, |
| 33600 |
Pragma_Main_Storage => -1, |
| 33601 |
Pragma_Max_Entry_Queue_Length => 0, |
| 33602 |
Pragma_Max_Queue_Length => 0, |
| 33603 |
Pragma_Memory_Size => 0, |
| 33604 |
Pragma_No_Body => 0, |
| 33605 |
Pragma_No_Caching => 0, |
| 33606 |
Pragma_No_Component_Reordering => -1, |
| 33607 |
Pragma_No_Elaboration_Code_All => 0, |
| 33608 |
Pragma_No_Heap_Finalization => 0, |
| 33609 |
Pragma_No_Inline => 0, |
| 33610 |
Pragma_No_Raise => 0, |
| 33611 |
Pragma_No_Return => 0, |
| 33612 |
Pragma_No_Run_Time => -1, |
| 33613 |
Pragma_Interrupts_System_By_Default => 0, |
| 33614 |
Pragma_No_Strict_Aliasing => -1, |
| 33615 |
Pragma_No_Tagged_Streams => 0, |
| 33616 |
Pragma_Normalize_Scalars => 0, |
| 33617 |
Pragma_Obsolescent => 0, |
| 33618 |
Pragma_Optimize => 0, |
| 33619 |
Pragma_Optimize_Alignment => 0, |
| 33620 |
Pragma_Ordered => 0, |
| 33621 |
Pragma_Overflow_Mode => 0, |
| 33622 |
Pragma_Overriding_Renamings => 0, |
| 33623 |
Pragma_Pack => 0, |
| 33624 |
Pragma_Page => 0, |
| 33625 |
Pragma_Part_Of => 0, |
| 33626 |
Pragma_Partition_Elaboration_Policy => 0, |
| 33627 |
Pragma_Passive => 0, |
| 33628 |
Pragma_Persistent_BSS => 0, |
| 33629 |
Pragma_Post => -1, |
| 33630 |
Pragma_Postcondition => -1, |
| 33631 |
Pragma_Post_Class => -1, |
| 33632 |
Pragma_Pre => -1, |
| 33633 |
Pragma_Precondition => -1, |
| 33634 |
Pragma_Predicate => -1, |
| 33635 |
Pragma_Predicate_Failure => -1, |
| 33636 |
Pragma_Preelaborable_Initialization => -1, |
| 33637 |
Pragma_Preelaborate => 0, |
| 33638 |
Pragma_Prefix_Exception_Messages => 0, |
| 33639 |
Pragma_Pre_Class => -1, |
| 33640 |
Pragma_Priority => -1, |
| 33641 |
Pragma_Priority_Specific_Dispatching => 0, |
| 33642 |
Pragma_Profile => 0, |
| 33643 |
Pragma_Profile_Warnings => 0, |
| 33644 |
Pragma_Propagate_Exceptions => 0, |
| 33645 |
Pragma_Provide_Shift_Operators => 0, |
| 33646 |
Pragma_Psect_Object => 0, |
| 33647 |
Pragma_Pure => 0, |
| 33648 |
Pragma_Pure_Function => 0, |
| 33649 |
Pragma_Queuing_Policy => 0, |
| 33650 |
Pragma_Rational => 0, |
| 33651 |
Pragma_Ravenscar => 0, |
| 33652 |
Pragma_Refined_Depends => -1, |
| 33653 |
Pragma_Refined_Global => -1, |
| 33654 |
Pragma_Refined_Post => -1, |
| 33655 |
Pragma_Refined_State => 0, |
| 33656 |
Pragma_Relative_Deadline => 0, |
| 33657 |
Pragma_Remote_Access_Type => -1, |
| 33658 |
Pragma_Remote_Call_Interface => -1, |
| 33659 |
Pragma_Remote_Types => -1, |
| 33660 |
Pragma_Rename_Pragma => 0, |
| 33661 |
Pragma_Restricted_Run_Time => 0, |
| 33662 |
Pragma_Restriction_Warnings => 0, |
| 33663 |
Pragma_Restrictions => 0, |
| 33664 |
Pragma_Reviewable => -1, |
| 33665 |
Pragma_Side_Effects => 0, |
| 33666 |
Pragma_Secondary_Stack_Size => -1, |
| 33667 |
Pragma_Share_Generic => 0, |
| 33668 |
Pragma_Shared => 0, |
| 33669 |
Pragma_Shared_Passive => 0, |
| 33670 |
Pragma_Short_Circuit_And_Or => 0, |
| 33671 |
Pragma_Short_Descriptors => 0, |
| 33672 |
Pragma_Simulate_Internal_Error => 0, |
| 33673 |
Pragma_Simple_Storage_Pool_Type => 0, |
| 33674 |
Pragma_Source_File_Name => 0, |
| 33675 |
Pragma_Source_File_Name_Project => 0, |
| 33676 |
Pragma_Source_Reference => 0, |
| 33677 |
Pragma_SPARK_Mode => 0, |
| 33678 |
Pragma_Static_Elaboration_Desired => 0, |
| 33679 |
Pragma_Storage_Size => -1, |
| 33680 |
Pragma_Storage_Unit => 0, |
| 33681 |
Pragma_Stream_Convert => 0, |
| 33682 |
Pragma_Style_Checks => 0, |
| 33683 |
Pragma_Subprogram_Variant => -1, |
| 33684 |
Pragma_Subtitle => 0, |
| 33685 |
Pragma_Suppress => 0, |
| 33686 |
Pragma_Suppress_All => 0, |
| 33687 |
Pragma_Suppress_Debug_Info => 0, |
| 33688 |
Pragma_Suppress_Exception_Locations => 0, |
| 33689 |
Pragma_Suppress_Initialization => 0, |
| 33690 |
Pragma_System_Name => 0, |
| 33691 |
Pragma_Task_Dispatching_Policy => 0, |
| 33692 |
Pragma_Task_Info => -1, |
| 33693 |
Pragma_Task_Name => -1, |
| 33694 |
Pragma_Task_Storage => -1, |
| 33695 |
Pragma_Test_Case => -1, |
| 33696 |
Pragma_Thread_Local_Storage => -1, |
| 33697 |
Pragma_Time_Slice => -1, |
| 33698 |
Pragma_Title => 0, |
| 33699 |
Pragma_Type_Invariant => -1, |
| 33700 |
Pragma_Type_Invariant_Class => -1, |
| 33701 |
Pragma_Unchecked_Union => 0, |
| 33702 |
Pragma_Unevaluated_Use_Of_Old => 0, |
| 33703 |
Pragma_Unimplemented_Unit => 0, |
| 33704 |
Pragma_Universal_Aliasing => 0, |
| 33705 |
Pragma_Unmodified => 0, |
| 33706 |
Pragma_Unreferenced => 0, |
| 33707 |
Pragma_Unreferenced_Objects => 0, |
| 33708 |
Pragma_Unreserve_All_Interrupts => 0, |
| 33709 |
Pragma_Unsuppress => 0, |
| 33710 |
Pragma_Unused => 0, |
| 33711 |
Pragma_Use_VADS_Size => 0, |
| 33712 |
Pragma_User_Aspect_Definition => 0, |
| 33713 |
Pragma_Validity_Checks => 0, |
| 33714 |
Pragma_Volatile => 0, |
| 33715 |
Pragma_Volatile_Components => 0, |
| 33716 |
Pragma_Volatile_Full_Access => 0, |
| 33717 |
Pragma_Volatile_Function => 0, |
| 33718 |
Pragma_Warning_As_Error => 0, |
| 33719 |
Pragma_Warnings => 0, |
| 33720 |
Pragma_Weak_External => 0, |
| 33721 |
Pragma_Wide_Character_Encoding => 0, |
| 33722 |
Unknown_Pragma => 0); |
| 33723 |
|
| 33724 |
function Is_Non_Significant_Pragma_Reference (N : Node_Id) return Boolean is |
| 33725 |
Id : Pragma_Id; |
| 33726 |
P : Node_Id; |
| 33727 |
C : Int; |
| 33728 |
AN : Nat; |
| 33729 |
|
| 33730 |
function Arg_No return Nat; |
| 33731 |
-- Returns an integer showing what argument we are in. A value of |
| 33732 |
-- zero means we are not in any of the arguments. |
| 33733 |
|
| 33734 |
------------ |
| 33735 |
-- Arg_No -- |
| 33736 |
------------ |
| 33737 |
|
| 33738 |
function Arg_No return Nat is |
| 33739 |
A : Node_Id; |
| 33740 |
N : Nat; |
| 33741 |
|
| 33742 |
begin |
| 33743 |
A := First (Pragma_Argument_Associations (Parent (P))); |
| 33744 |
N := 1; |
| 33745 |
loop |
| 33746 |
if No (A) then |
| 33747 |
return 0; |
| 33748 |
elsif A = P then |
| 33749 |
return N; |
| 33750 |
end if; |
| 33751 |
|
| 33752 |
Next (A); |
| 33753 |
N := N + 1; |
| 33754 |
end loop; |
| 33755 |
end Arg_No; |
| 33756 |
|
| 33757 |
-- Start of processing for Non_Significant_Pragma_Reference |
| 33758 |
|
| 33759 |
begin |
| 33760 |
-- Reference might appear either directly as expression of a pragma |
| 33761 |
-- argument association, e.g. pragma Export (...), or within an |
| 33762 |
-- aggregate with component associations, e.g. pragma Refined_State |
| 33763 |
-- ((... => ...)). |
| 33764 |
|
| 33765 |
P := Parent (N); |
| 33766 |
loop |
| 33767 |
case Nkind (P) is |
| 33768 |
when N_Pragma_Argument_Association => |
| 33769 |
exit; |
| 33770 |
when N_Aggregate | N_Component_Association => |
| 33771 |
P := Parent (P); |
| 33772 |
when others => |
| 33773 |
return False; |
| 33774 |
end case; |
| 33775 |
end loop; |
| 33776 |
|
| 33777 |
AN := Arg_No; |
| 33778 |
|
| 33779 |
if AN = 0 then |
| 33780 |
return False; |
| 33781 |
end if; |
| 33782 |
|
| 33783 |
Id := Get_Pragma_Id (Parent (P)); |
| 33784 |
C := Sig_Flags (Id); |
| 33785 |
|
| 33786 |
case C is |
| 33787 |
when -1 => |
| 33788 |
return False; |
| 33789 |
|
| 33790 |
when 0 => |
| 33791 |
return True; |
| 33792 |
|
| 33793 |
when 92 .. 99 => |
| 33794 |
return AN < (C - 90); |
| 33795 |
|
| 33796 |
when others => |
| 33797 |
return AN /= C; |
| 33798 |
end case; |
| 33799 |
end Is_Non_Significant_Pragma_Reference; |
| 33800 |
|
| 33801 |
------------------------------ |
| 33802 |
-- Is_Pragma_String_Literal -- |
| 33803 |
------------------------------ |
| 33804 |
|
| 33805 |
-- This function returns true if the corresponding pragma argument is a |
| 33806 |
-- static string expression. These are the only cases in which string |
| 33807 |
-- literals can appear as pragma arguments. We also allow a string literal |
| 33808 |
-- as the first argument to pragma Assert (although it will of course |
| 33809 |
-- always generate a type error). |
| 33810 |
|
| 33811 |
function Is_Pragma_String_Literal (Par : Node_Id) return Boolean is |
| 33812 |
Pragn : constant Node_Id := Parent (Par); |
| 33813 |
Assoc : constant List_Id := Pragma_Argument_Associations (Pragn); |
| 33814 |
Pname : constant Name_Id := Pragma_Name (Pragn); |
| 33815 |
Argn : Natural; |
| 33816 |
N : Node_Id; |
| 33817 |
|
| 33818 |
begin |
| 33819 |
Argn := 1; |
| 33820 |
N := First (Assoc); |
| 33821 |
loop |
| 33822 |
exit when N = Par; |
| 33823 |
Argn := Argn + 1; |
| 33824 |
Next (N); |
| 33825 |
end loop; |
| 33826 |
|
| 33827 |
if Pname = Name_Assert then |
| 33828 |
return True; |
| 33829 |
|
| 33830 |
elsif Pname = Name_Export then |
| 33831 |
return Argn > 2; |
| 33832 |
|
| 33833 |
elsif Pname = Name_Ident then |
| 33834 |
return Argn = 1; |
| 33835 |
|
| 33836 |
elsif Pname = Name_Import then |
| 33837 |
return Argn > 2; |
| 33838 |
|
| 33839 |
elsif Pname = Name_Interface_Name then |
| 33840 |
return Argn > 1; |
| 33841 |
|
| 33842 |
elsif Pname = Name_Linker_Alias then |
| 33843 |
return Argn = 2; |
| 33844 |
|
| 33845 |
elsif Pname = Name_Linker_Section then |
| 33846 |
return Argn = 2; |
| 33847 |
|
| 33848 |
elsif Pname = Name_Machine_Attribute then |
| 33849 |
return Argn = 2; |
| 33850 |
|
| 33851 |
elsif Pname = Name_Source_File_Name then |
| 33852 |
return True; |
| 33853 |
|
| 33854 |
elsif Pname = Name_Source_Reference then |
| 33855 |
return Argn = 2; |
| 33856 |
|
| 33857 |
elsif Pname = Name_Title then |
| 33858 |
return True; |
| 33859 |
|
| 33860 |
elsif Pname = Name_Subtitle then |
| 33861 |
return True; |
| 33862 |
|
| 33863 |
else |
| 33864 |
return False; |
| 33865 |
end if; |
| 33866 |
end Is_Pragma_String_Literal; |
| 33867 |
|
| 33868 |
--------------------------- |
| 33869 |
-- Is_Private_SPARK_Mode -- |
| 33870 |
--------------------------- |
| 33871 |
|
| 33872 |
function Is_Private_SPARK_Mode (N : Node_Id) return Boolean is |
| 33873 |
begin |
| 33874 |
pragma Assert |
| 33875 |
(Nkind (N) = N_Pragma |
| 33876 |
and then Pragma_Name (N) = Name_SPARK_Mode |
| 33877 |
and then Is_List_Member (N)); |
| 33878 |
|
| 33879 |
-- For pragma SPARK_Mode to be private, it has to appear in the private |
| 33880 |
-- declarations of a package. |
| 33881 |
|
| 33882 |
return |
| 33883 |
Present (Parent (N)) |
| 33884 |
and then Nkind (Parent (N)) = N_Package_Specification |
| 33885 |
and then List_Containing (N) = Private_Declarations (Parent (N)); |
| 33886 |
end Is_Private_SPARK_Mode; |
| 33887 |
|
| 33888 |
----------------------------- |
| 33889 |
-- Is_Valid_Assertion_Kind -- |
| 33890 |
----------------------------- |
| 33891 |
|
| 33892 |
function Is_Valid_Assertion_Kind (Nam : Name_Id) return Boolean is |
| 33893 |
begin |
| 33894 |
case Nam is |
| 33895 |
when |
| 33896 |
-- RM defined |
| 33897 |
|
| 33898 |
Name_Assert |
| 33899 |
| Name_Static_Predicate |
| 33900 |
| Name_Dynamic_Predicate |
| 33901 |
| Name_Pre |
| 33902 |
| Name_uPre |
| 33903 |
| Name_Post |
| 33904 |
| Name_uPost |
| 33905 |
| Name_Type_Invariant |
| 33906 |
| Name_uType_Invariant |
| 33907 |
|
| 33908 |
-- Impl defined |
| 33909 |
|
| 33910 |
| Name_Assert_And_Cut |
| 33911 |
| Name_Assume |
| 33912 |
| Name_Contract_Cases |
| 33913 |
| Name_Debug |
| 33914 |
| Name_Default_Initial_Condition |
| 33915 |
| Name_Ghost |
| 33916 |
| Name_Ghost_Predicate |
| 33917 |
| Name_Initial_Condition |
| 33918 |
| Name_Invariant |
| 33919 |
| Name_uInvariant |
| 33920 |
| Name_Loop_Invariant |
| 33921 |
| Name_Loop_Variant |
| 33922 |
| Name_Postcondition |
| 33923 |
| Name_Post_Class |
| 33924 |
| Name_Precondition |
| 33925 |
| Name_Pre_Class |
| 33926 |
| Name_Predicate |
| 33927 |
| Name_Refined_Post |
| 33928 |
| Name_Statement_Assertions |
| 33929 |
| Name_Subprogram_Variant |
| 33930 |
=> |
| 33931 |
return True; |
| 33932 |
|
| 33933 |
when others => |
| 33934 |
return False; |
| 33935 |
end case; |
| 33936 |
end Is_Valid_Assertion_Kind; |
| 33937 |
|
| 33938 |
-------------------------------------- |
| 33939 |
-- Process_Compilation_Unit_Pragmas -- |
| 33940 |
-------------------------------------- |
| 33941 |
|
| 33942 |
procedure Process_Compilation_Unit_Pragmas (N : Node_Id) is |
| 33943 |
begin |
| 33944 |
-- A special check for pragma Suppress_All, a very strange DEC pragma, |
| 33945 |
-- strange because it comes at the end of the unit. Rational has the |
| 33946 |
-- same name for a pragma, but treats it as a program unit pragma, In |
| 33947 |
-- GNAT we just decide to allow it anywhere at all. If it appeared then |
| 33948 |
-- the flag Has_Pragma_Suppress_All was set on the compilation unit |
| 33949 |
-- node, and we insert a pragma Suppress (All_Checks) at the start of |
| 33950 |
-- the context clause to ensure the correct processing. |
| 33951 |
|
| 33952 |
if Has_Pragma_Suppress_All (N) then |
| 33953 |
Prepend_To (Context_Items (N), |
| 33954 |
Make_Pragma (Sloc (N), |
| 33955 |
Chars => Name_Suppress, |
| 33956 |
Pragma_Argument_Associations => New_List ( |
| 33957 |
Make_Pragma_Argument_Association (Sloc (N), |
| 33958 |
Expression => Make_Identifier (Sloc (N), Name_All_Checks))))); |
| 33959 |
end if; |
| 33960 |
|
| 33961 |
-- Nothing else to do at the current time |
| 33962 |
|
| 33963 |
end Process_Compilation_Unit_Pragmas; |
| 33964 |
|
| 33965 |
-------------------------------------------- |
| 33966 |
-- Validate_Compile_Time_Warning_Or_Error -- |
| 33967 |
-------------------------------------------- |
| 33968 |
|
| 33969 |
procedure Validate_Compile_Time_Warning_Or_Error |
| 33970 |
(N : Node_Id; |
| 33971 |
Eloc : Source_Ptr) |
| 33972 |
is |
| 33973 |
Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N)); |
| 33974 |
Arg1x : constant Node_Id := Get_Pragma_Arg (Arg1); |
| 33975 |
Arg2 : constant Node_Id := Next (Arg1); |
| 33976 |
|
| 33977 |
Pname : constant Name_Id := Pragma_Name_Unmapped (N); |
| 33978 |
Prag_Id : constant Pragma_Id := Get_Pragma_Id (Pname); |
| 33979 |
|
| 33980 |
begin |
| 33981 |
Analyze_And_Resolve (Arg1x, Standard_Boolean); |
| 33982 |
|
| 33983 |
if Compile_Time_Known_Value (Arg1x) then |
| 33984 |
if Is_True (Expr_Value (Arg1x)) then |
| 33985 |
|
| 33986 |
-- We have already verified that the second argument is a static |
| 33987 |
-- string expression. Its string value must be retrieved |
| 33988 |
-- explicitly if it is a declared constant, otherwise it has |
| 33989 |
-- been constant-folded previously. |
| 33990 |
|
| 33991 |
declare |
| 33992 |
Cent : constant Entity_Id := Cunit_Entity (Current_Sem_Unit); |
| 33993 |
Str : constant String_Id := |
| 33994 |
Strval (Expr_Value_S (Get_Pragma_Arg (Arg2))); |
| 33995 |
Str_Len : constant Nat := String_Length (Str); |
| 33996 |
|
| 33997 |
Force : constant Boolean := |
| 33998 |
Prag_Id = Pragma_Compile_Time_Warning |
| 33999 |
and then Is_Spec_Name (Unit_Name (Current_Sem_Unit)) |
| 34000 |
and then (Ekind (Cent) /= E_Package |
| 34001 |
or else not In_Private_Part (Cent)); |
| 34002 |
-- Set True if this is the warning case, and we are in the |
| 34003 |
-- visible part of a package spec, or in a subprogram spec, |
| 34004 |
-- in which case we want to force the client to see the |
| 34005 |
-- warning, even though it is not in the main unit. |
| 34006 |
|
| 34007 |
C : Character; |
| 34008 |
CC : Char_Code; |
| 34009 |
Cont : Boolean; |
| 34010 |
Ptr : Nat; |
| 34011 |
|
| 34012 |
begin |
| 34013 |
-- Loop through segments of message separated by line feeds. |
| 34014 |
-- We output these segments as separate messages with |
| 34015 |
-- continuation marks for all but the first. |
| 34016 |
|
| 34017 |
Cont := False; |
| 34018 |
Ptr := 1; |
| 34019 |
loop |
| 34020 |
Error_Msg_Strlen := 0; |
| 34021 |
|
| 34022 |
-- Loop to copy characters from argument to error message |
| 34023 |
-- string buffer. |
| 34024 |
|
| 34025 |
loop |
| 34026 |
exit when Ptr > Str_Len; |
| 34027 |
CC := Get_String_Char (Str, Ptr); |
| 34028 |
Ptr := Ptr + 1; |
| 34029 |
|
| 34030 |
-- Ignore wide chars ??? else store character |
| 34031 |
|
| 34032 |
if In_Character_Range (CC) then |
| 34033 |
C := Get_Character (CC); |
| 34034 |
exit when C = ASCII.LF; |
| 34035 |
Error_Msg_Strlen := Error_Msg_Strlen + 1; |
| 34036 |
Error_Msg_String (Error_Msg_Strlen) := C; |
| 34037 |
end if; |
| 34038 |
end loop; |
| 34039 |
|
| 34040 |
-- Here with one line ready to go |
| 34041 |
|
| 34042 |
Error_Msg_Warn := Prag_Id = Pragma_Compile_Time_Warning; |
| 34043 |
|
| 34044 |
-- If this is a warning in a spec, then we want clients |
| 34045 |
-- to see the warning, so mark the message with the |
| 34046 |
-- special sequence !! to force the warning. In the case |
| 34047 |
-- of a package spec, we do not force this if we are in |
| 34048 |
-- the private part of the spec. |
| 34049 |
|
| 34050 |
if Force then |
| 34051 |
if Cont = False then |
| 34052 |
Error_Msg |
| 34053 |
("<<~!!", Eloc, N, Is_Compile_Time_Pragma => True); |
| 34054 |
Cont := True; |
| 34055 |
else |
| 34056 |
Error_Msg |
| 34057 |
("\<<~!!", Eloc, N, Is_Compile_Time_Pragma => True); |
| 34058 |
end if; |
| 34059 |
|
| 34060 |
-- Error, rather than warning, or in a body, so we do not |
| 34061 |
-- need to force visibility for client (error will be |
| 34062 |
-- output in any case, and this is the situation in which |
| 34063 |
-- we do not want a client to get a warning, since the |
| 34064 |
-- warning is in the body or the spec private part). |
| 34065 |
|
| 34066 |
else |
| 34067 |
if Cont = False then |
| 34068 |
Error_Msg |
| 34069 |
("<<~", Eloc, N, Is_Compile_Time_Pragma => True); |
| 34070 |
Cont := True; |
| 34071 |
else |
| 34072 |
Error_Msg |
| 34073 |
("\<<~", Eloc, N, Is_Compile_Time_Pragma => True); |
| 34074 |
end if; |
| 34075 |
end if; |
| 34076 |
|
| 34077 |
exit when Ptr > Str_Len; |
| 34078 |
end loop; |
| 34079 |
end; |
| 34080 |
end if; |
| 34081 |
|
| 34082 |
-- Arg1x is not known at compile time, so possibly issue an error |
| 34083 |
-- or warning. This can happen only if the pragma's processing |
| 34084 |
-- was deferred until after the back end is run (see |
| 34085 |
-- Process_Compile_Time_Warning_Or_Error). Note that the warning |
| 34086 |
-- control switch applies to only the warning case. |
| 34087 |
|
| 34088 |
elsif Prag_Id = Pragma_Compile_Time_Error then |
| 34089 |
Error_Msg_N ("condition is not known at compile time", Arg1x); |
| 34090 |
|
| 34091 |
elsif Warn_On_Unknown_Compile_Time_Warning then |
| 34092 |
Error_Msg_N ("?_c?condition is not known at compile time", Arg1x); |
| 34093 |
end if; |
| 34094 |
end Validate_Compile_Time_Warning_Or_Error; |
| 34095 |
|
| 34096 |
------------------------------------ |
| 34097 |
-- Record_Possible_Body_Reference -- |
| 34098 |
------------------------------------ |
| 34099 |
|
| 34100 |
procedure Record_Possible_Body_Reference |
| 34101 |
(State_Id : Entity_Id; |
| 34102 |
Ref : Node_Id) |
| 34103 |
is |
| 34104 |
Context : Node_Id; |
| 34105 |
Spec_Id : Entity_Id; |
| 34106 |
|
| 34107 |
begin |
| 34108 |
-- Ensure that we are dealing with a reference to a state |
| 34109 |
|
| 34110 |
pragma Assert (Ekind (State_Id) = E_Abstract_State); |
| 34111 |
|
| 34112 |
-- Climb the tree starting from the reference looking for a package body |
| 34113 |
-- whose spec declares the referenced state. This criteria automatically |
| 34114 |
-- excludes references in package specs which are legal. Note that it is |
| 34115 |
-- not wise to emit an error now as the package body may lack pragma |
| 34116 |
-- Refined_State or the referenced state may not be mentioned in the |
| 34117 |
-- refinement. This approach avoids the generation of misleading errors. |
| 34118 |
|
| 34119 |
Context := Ref; |
| 34120 |
while Present (Context) loop |
| 34121 |
if Nkind (Context) = N_Package_Body then |
| 34122 |
Spec_Id := Corresponding_Spec (Context); |
| 34123 |
|
| 34124 |
if Contains (Abstract_States (Spec_Id), State_Id) then |
| 34125 |
if No (Body_References (State_Id)) then |
| 34126 |
Set_Body_References (State_Id, New_Elmt_List); |
| 34127 |
end if; |
| 34128 |
|
| 34129 |
Append_Elmt (Ref, To => Body_References (State_Id)); |
| 34130 |
exit; |
| 34131 |
end if; |
| 34132 |
end if; |
| 34133 |
|
| 34134 |
Context := Parent (Context); |
| 34135 |
end loop; |
| 34136 |
end Record_Possible_Body_Reference; |
| 34137 |
|
| 34138 |
------------------------------------------ |
| 34139 |
-- Relocate_Pragmas_To_Anonymous_Object -- |
| 34140 |
------------------------------------------ |
| 34141 |
|
| 34142 |
procedure Relocate_Pragmas_To_Anonymous_Object |
| 34143 |
(Typ_Decl : Node_Id; |
| 34144 |
Obj_Decl : Node_Id) |
| 34145 |
is |
| 34146 |
Decl : Node_Id; |
| 34147 |
Def : Node_Id; |
| 34148 |
Next_Decl : Node_Id; |
| 34149 |
|
| 34150 |
begin |
| 34151 |
if Nkind (Typ_Decl) = N_Protected_Type_Declaration then |
| 34152 |
Def := Protected_Definition (Typ_Decl); |
| 34153 |
else |
| 34154 |
pragma Assert (Nkind (Typ_Decl) = N_Task_Type_Declaration); |
| 34155 |
Def := Task_Definition (Typ_Decl); |
| 34156 |
end if; |
| 34157 |
|
| 34158 |
-- The concurrent definition has a visible declaration list. Inspect it |
| 34159 |
-- and relocate all canidate pragmas. |
| 34160 |
|
| 34161 |
if Present (Def) and then Present (Visible_Declarations (Def)) then |
| 34162 |
Decl := First (Visible_Declarations (Def)); |
| 34163 |
while Present (Decl) loop |
| 34164 |
|
| 34165 |
-- Preserve the following declaration for iteration purposes due |
| 34166 |
-- to possible relocation of a pragma. |
| 34167 |
|
| 34168 |
Next_Decl := Next (Decl); |
| 34169 |
|
| 34170 |
if Nkind (Decl) = N_Pragma |
| 34171 |
and then Pragma_On_Anonymous_Object_OK (Get_Pragma_Id (Decl)) |
| 34172 |
then |
| 34173 |
Remove (Decl); |
| 34174 |
Insert_After (Obj_Decl, Decl); |
| 34175 |
|
| 34176 |
-- Skip internally generated code |
| 34177 |
|
| 34178 |
elsif not Comes_From_Source (Decl) then |
| 34179 |
null; |
| 34180 |
|
| 34181 |
-- No candidate pragmas are available for relocation |
| 34182 |
|
| 34183 |
else |
| 34184 |
exit; |
| 34185 |
end if; |
| 34186 |
|
| 34187 |
Decl := Next_Decl; |
| 34188 |
end loop; |
| 34189 |
end if; |
| 34190 |
end Relocate_Pragmas_To_Anonymous_Object; |
| 34191 |
|
| 34192 |
------------------------------ |
| 34193 |
-- Relocate_Pragmas_To_Body -- |
| 34194 |
------------------------------ |
| 34195 |
|
| 34196 |
procedure Relocate_Pragmas_To_Body |
| 34197 |
(Subp_Body : Node_Id; |
| 34198 |
Target_Body : Node_Id := Empty) |
| 34199 |
is |
| 34200 |
procedure Relocate_Pragma (Prag : Node_Id); |
| 34201 |
-- Remove a single pragma from its current list and add it to the |
| 34202 |
-- declarations of the proper body (either Subp_Body or Target_Body). |
| 34203 |
|
| 34204 |
--------------------- |
| 34205 |
-- Relocate_Pragma -- |
| 34206 |
--------------------- |
| 34207 |
|
| 34208 |
procedure Relocate_Pragma (Prag : Node_Id) is |
| 34209 |
Decls : List_Id; |
| 34210 |
Target : Node_Id; |
| 34211 |
|
| 34212 |
begin |
| 34213 |
-- When subprogram stubs or expression functions are involves, the |
| 34214 |
-- destination declaration list belongs to the proper body. |
| 34215 |
|
| 34216 |
if Present (Target_Body) then |
| 34217 |
Target := Target_Body; |
| 34218 |
else |
| 34219 |
Target := Subp_Body; |
| 34220 |
end if; |
| 34221 |
|
| 34222 |
Decls := Declarations (Target); |
| 34223 |
|
| 34224 |
if No (Decls) then |
| 34225 |
Decls := New_List; |
| 34226 |
Set_Declarations (Target, Decls); |
| 34227 |
end if; |
| 34228 |
|
| 34229 |
-- Unhook the pragma from its current list |
| 34230 |
|
| 34231 |
Remove (Prag); |
| 34232 |
Prepend (Prag, Decls); |
| 34233 |
end Relocate_Pragma; |
| 34234 |
|
| 34235 |
-- Local variables |
| 34236 |
|
| 34237 |
Body_Id : constant Entity_Id := |
| 34238 |
Defining_Unit_Name (Specification (Subp_Body)); |
| 34239 |
Next_Stmt : Node_Id; |
| 34240 |
Stmt : Node_Id; |
| 34241 |
|
| 34242 |
-- Start of processing for Relocate_Pragmas_To_Body |
| 34243 |
|
| 34244 |
begin |
| 34245 |
-- Do not process a body that comes from a separate unit as no construct |
| 34246 |
-- can possibly follow it. |
| 34247 |
|
| 34248 |
if not Is_List_Member (Subp_Body) then |
| 34249 |
return; |
| 34250 |
|
| 34251 |
-- Do not relocate pragmas that follow a stub if the stub does not have |
| 34252 |
-- a proper body. |
| 34253 |
|
| 34254 |
elsif Nkind (Subp_Body) = N_Subprogram_Body_Stub |
| 34255 |
and then No (Target_Body) |
| 34256 |
then |
| 34257 |
return; |
| 34258 |
|
| 34259 |
-- Do not process internally generated routine _Wrapped_Statements |
| 34260 |
|
| 34261 |
elsif Ekind (Body_Id) = E_Procedure |
| 34262 |
and then Chars (Body_Id) = Name_uWrapped_Statements |
| 34263 |
then |
| 34264 |
return; |
| 34265 |
end if; |
| 34266 |
|
| 34267 |
-- Look at what is following the body. We are interested in certain kind |
| 34268 |
-- of pragmas (either from source or byproducts of expansion) that can |
| 34269 |
-- apply to a body [stub]. |
| 34270 |
|
| 34271 |
Stmt := Next (Subp_Body); |
| 34272 |
while Present (Stmt) loop |
| 34273 |
|
| 34274 |
-- Preserve the following statement for iteration purposes due to a |
| 34275 |
-- possible relocation of a pragma. |
| 34276 |
|
| 34277 |
Next_Stmt := Next (Stmt); |
| 34278 |
|
| 34279 |
-- Move a candidate pragma following the body to the declarations of |
| 34280 |
-- the body. |
| 34281 |
|
| 34282 |
if Nkind (Stmt) = N_Pragma |
| 34283 |
and then Pragma_On_Body_Or_Stub_OK (Get_Pragma_Id (Stmt)) |
| 34284 |
then |
| 34285 |
|
| 34286 |
-- If a source pragma Warnings follows the body, it applies to |
| 34287 |
-- following statements and does not belong in the body. |
| 34288 |
|
| 34289 |
if Get_Pragma_Id (Stmt) = Pragma_Warnings |
| 34290 |
and then Comes_From_Source (Stmt) |
| 34291 |
then |
| 34292 |
null; |
| 34293 |
else |
| 34294 |
Relocate_Pragma (Stmt); |
| 34295 |
end if; |
| 34296 |
|
| 34297 |
-- Skip internally generated code |
| 34298 |
|
| 34299 |
elsif not Comes_From_Source (Stmt) then |
| 34300 |
null; |
| 34301 |
|
| 34302 |
-- No candidate pragmas are available for relocation |
| 34303 |
|
| 34304 |
else |
| 34305 |
exit; |
| 34306 |
end if; |
| 34307 |
|
| 34308 |
Stmt := Next_Stmt; |
| 34309 |
end loop; |
| 34310 |
end Relocate_Pragmas_To_Body; |
| 34311 |
|
| 34312 |
------------------- |
| 34313 |
-- Resolve_State -- |
| 34314 |
------------------- |
| 34315 |
|
| 34316 |
procedure Resolve_State (N : Node_Id) is |
| 34317 |
Func : Entity_Id; |
| 34318 |
State : Entity_Id; |
| 34319 |
|
| 34320 |
begin |
| 34321 |
if Is_Entity_Name (N) and then Present (Entity (N)) then |
| 34322 |
Func := Entity (N); |
| 34323 |
|
| 34324 |
-- Handle overloading of state names by functions. Traverse the |
| 34325 |
-- homonym chain looking for an abstract state. |
| 34326 |
|
| 34327 |
if Ekind (Func) = E_Function and then Has_Homonym (Func) then |
| 34328 |
pragma Assert (Is_Overloaded (N)); |
| 34329 |
|
| 34330 |
State := Homonym (Func); |
| 34331 |
while Present (State) loop |
| 34332 |
if Ekind (State) = E_Abstract_State then |
| 34333 |
|
| 34334 |
-- Resolve the overloading by setting the proper entity of |
| 34335 |
-- the reference to that of the state. |
| 34336 |
|
| 34337 |
Set_Etype (N, Standard_Void_Type); |
| 34338 |
Set_Entity (N, State); |
| 34339 |
Set_Is_Overloaded (N, False); |
| 34340 |
|
| 34341 |
Generate_Reference (State, N); |
| 34342 |
return; |
| 34343 |
end if; |
| 34344 |
|
| 34345 |
State := Homonym (State); |
| 34346 |
end loop; |
| 34347 |
|
| 34348 |
-- A function can never act as a state; it will be diagnosed later |
| 34349 |
end if; |
| 34350 |
end if; |
| 34351 |
end Resolve_State; |
| 34352 |
|
| 34353 |
---------------------------- |
| 34354 |
-- Rewrite_Assertion_Kind -- |
| 34355 |
---------------------------- |
| 34356 |
|
| 34357 |
procedure Rewrite_Assertion_Kind |
| 34358 |
(N : Node_Id; |
| 34359 |
From_Policy : Boolean := False) |
| 34360 |
is |
| 34361 |
Nam : Name_Id; |
| 34362 |
|
| 34363 |
begin |
| 34364 |
Nam := No_Name; |
| 34365 |
if Nkind (N) = N_Attribute_Reference |
| 34366 |
and then Attribute_Name (N) = Name_Class |
| 34367 |
and then Nkind (Prefix (N)) = N_Identifier |
| 34368 |
then |
| 34369 |
case Chars (Prefix (N)) is |
| 34370 |
when Name_Pre => |
| 34371 |
Nam := Name_uPre; |
| 34372 |
|
| 34373 |
when Name_Post => |
| 34374 |
Nam := Name_uPost; |
| 34375 |
|
| 34376 |
when Name_Type_Invariant => |
| 34377 |
Nam := Name_uType_Invariant; |
| 34378 |
|
| 34379 |
when Name_Invariant => |
| 34380 |
Nam := Name_uInvariant; |
| 34381 |
|
| 34382 |
when others => |
| 34383 |
return; |
| 34384 |
end case; |
| 34385 |
|
| 34386 |
-- Recommend standard use of aspect names Pre/Post |
| 34387 |
|
| 34388 |
elsif Nkind (N) = N_Identifier |
| 34389 |
and then From_Policy |
| 34390 |
and then Serious_Errors_Detected = 0 |
| 34391 |
then |
| 34392 |
if Chars (N) = Name_Precondition |
| 34393 |
or else Chars (N) = Name_Postcondition |
| 34394 |
then |
| 34395 |
Error_Msg_N ("Check_Policy is a non-standard pragma??", N); |
| 34396 |
Error_Msg_N |
| 34397 |
("\use Assertion_Policy and aspect names Pre/Post for " |
| 34398 |
& "Ada2012 conformance??", N); |
| 34399 |
end if; |
| 34400 |
|
| 34401 |
return; |
| 34402 |
end if; |
| 34403 |
|
| 34404 |
if Nam /= No_Name then |
| 34405 |
Rewrite (N, Make_Identifier (Sloc (N), Chars => Nam)); |
| 34406 |
end if; |
| 34407 |
end Rewrite_Assertion_Kind; |
| 34408 |
|
| 34409 |
-------- |
| 34410 |
-- rv -- |
| 34411 |
-------- |
| 34412 |
|
| 34413 |
procedure rv is |
| 34414 |
begin |
| 34415 |
Dummy := Dummy + 1; |
| 34416 |
end rv; |
| 34417 |
|
| 34418 |
-------------------------------- |
| 34419 |
-- Set_Encoded_Interface_Name -- |
| 34420 |
-------------------------------- |
| 34421 |
|
| 34422 |
procedure Set_Encoded_Interface_Name (E : Entity_Id; S : Node_Id) is |
| 34423 |
Str : constant String_Id := Strval (S); |
| 34424 |
Len : constant Nat := String_Length (Str); |
| 34425 |
CC : Char_Code; |
| 34426 |
C : Character; |
| 34427 |
J : Pos; |
| 34428 |
|
| 34429 |
Hex : constant array (0 .. 15) of Character := "0123456789abcdef"; |
| 34430 |
|
| 34431 |
procedure Encode; |
| 34432 |
-- Stores encoded value of character code CC. The encoding we use an |
| 34433 |
-- underscore followed by four lower case hex digits. |
| 34434 |
|
| 34435 |
------------ |
| 34436 |
-- Encode -- |
| 34437 |
------------ |
| 34438 |
|
| 34439 |
procedure Encode is |
| 34440 |
begin |
| 34441 |
Store_String_Char (Get_Char_Code ('_')); |
| 34442 |
Store_String_Char |
| 34443 |
(Get_Char_Code (Hex (Integer (CC / 2 ** 12)))); |
| 34444 |
Store_String_Char |
| 34445 |
(Get_Char_Code (Hex (Integer (CC / 2 ** 8 and 16#0F#)))); |
| 34446 |
Store_String_Char |
| 34447 |
(Get_Char_Code (Hex (Integer (CC / 2 ** 4 and 16#0F#)))); |
| 34448 |
Store_String_Char |
| 34449 |
(Get_Char_Code (Hex (Integer (CC and 16#0F#)))); |
| 34450 |
end Encode; |
| 34451 |
|
| 34452 |
-- Start of processing for Set_Encoded_Interface_Name |
| 34453 |
|
| 34454 |
begin |
| 34455 |
-- If first character is asterisk, this is a link name, and we leave it |
| 34456 |
-- completely unmodified. We also ignore null strings (the latter case |
| 34457 |
-- happens only in error cases). |
| 34458 |
|
| 34459 |
if Len = 0 |
| 34460 |
or else Get_String_Char (Str, 1) = Get_Char_Code ('*') |
| 34461 |
then |
| 34462 |
Set_Interface_Name (E, S); |
| 34463 |
|
| 34464 |
else |
| 34465 |
J := 1; |
| 34466 |
loop |
| 34467 |
CC := Get_String_Char (Str, J); |
| 34468 |
|
| 34469 |
exit when not In_Character_Range (CC); |
| 34470 |
|
| 34471 |
C := Get_Character (CC); |
| 34472 |
|
| 34473 |
exit when C /= '_' and then C /= '$' |
| 34474 |
and then C not in '0' .. '9' |
| 34475 |
and then C not in 'a' .. 'z' |
| 34476 |
and then C not in 'A' .. 'Z'; |
| 34477 |
|
| 34478 |
if J = Len then |
| 34479 |
Set_Interface_Name (E, S); |
| 34480 |
return; |
| 34481 |
|
| 34482 |
else |
| 34483 |
J := J + 1; |
| 34484 |
end if; |
| 34485 |
end loop; |
| 34486 |
|
| 34487 |
-- Here we need to encode. The encoding we use as follows: |
| 34488 |
-- three underscores + four hex digits (lower case) |
| 34489 |
|
| 34490 |
Start_String; |
| 34491 |
|
| 34492 |
for J in 1 .. String_Length (Str) loop |
| 34493 |
CC := Get_String_Char (Str, J); |
| 34494 |
|
| 34495 |
if not In_Character_Range (CC) then |
| 34496 |
Encode; |
| 34497 |
else |
| 34498 |
C := Get_Character (CC); |
| 34499 |
|
| 34500 |
if C = '_' or else C = '$' |
| 34501 |
or else C in '0' .. '9' |
| 34502 |
or else C in 'a' .. 'z' |
| 34503 |
or else C in 'A' .. 'Z' |
| 34504 |
then |
| 34505 |
Store_String_Char (CC); |
| 34506 |
else |
| 34507 |
Encode; |
| 34508 |
end if; |
| 34509 |
end if; |
| 34510 |
end loop; |
| 34511 |
|
| 34512 |
Set_Interface_Name (E, |
| 34513 |
Make_String_Literal (Sloc (S), |
| 34514 |
Strval => End_String)); |
| 34515 |
end if; |
| 34516 |
end Set_Encoded_Interface_Name; |
| 34517 |
|
| 34518 |
------------------------ |
| 34519 |
-- Set_Elab_Unit_Name -- |
| 34520 |
------------------------ |
| 34521 |
|
| 34522 |
procedure Set_Elab_Unit_Name (N : Node_Id; With_Item : Node_Id) is |
| 34523 |
Pref : Node_Id; |
| 34524 |
Scop : Entity_Id; |
| 34525 |
|
| 34526 |
begin |
| 34527 |
if Nkind (N) = N_Identifier |
| 34528 |
and then Nkind (With_Item) = N_Identifier |
| 34529 |
then |
| 34530 |
Set_Entity (N, Entity (With_Item)); |
| 34531 |
|
| 34532 |
elsif Nkind (N) = N_Selected_Component then |
| 34533 |
Change_Selected_Component_To_Expanded_Name (N); |
| 34534 |
Set_Entity (N, Entity (With_Item)); |
| 34535 |
Set_Entity (Selector_Name (N), Entity (N)); |
| 34536 |
|
| 34537 |
Pref := Prefix (N); |
| 34538 |
Scop := Scope (Entity (N)); |
| 34539 |
while Nkind (Pref) = N_Selected_Component loop |
| 34540 |
Change_Selected_Component_To_Expanded_Name (Pref); |
| 34541 |
Set_Entity (Selector_Name (Pref), Scop); |
| 34542 |
Set_Entity (Pref, Scop); |
| 34543 |
Pref := Prefix (Pref); |
| 34544 |
Scop := Scope (Scop); |
| 34545 |
end loop; |
| 34546 |
|
| 34547 |
Set_Entity (Pref, Scop); |
| 34548 |
end if; |
| 34549 |
|
| 34550 |
Generate_Reference (Entity (With_Item), N, Set_Ref => False); |
| 34551 |
end Set_Elab_Unit_Name; |
| 34552 |
|
| 34553 |
----------------------- |
| 34554 |
-- Set_Overflow_Mode -- |
| 34555 |
----------------------- |
| 34556 |
|
| 34557 |
procedure Set_Overflow_Mode (N : Node_Id) is |
| 34558 |
|
| 34559 |
function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type; |
| 34560 |
-- Function to process one pragma argument, Arg |
| 34561 |
|
| 34562 |
----------------------- |
| 34563 |
-- Get_Overflow_Mode -- |
| 34564 |
----------------------- |
| 34565 |
|
| 34566 |
function Get_Overflow_Mode (Arg : Node_Id) return Overflow_Mode_Type is |
| 34567 |
Argx : constant Node_Id := Get_Pragma_Arg (Arg); |
| 34568 |
|
| 34569 |
begin |
| 34570 |
if Chars (Argx) = Name_Strict then |
| 34571 |
return Strict; |
| 34572 |
|
| 34573 |
elsif Chars (Argx) = Name_Minimized then |
| 34574 |
return Minimized; |
| 34575 |
|
| 34576 |
elsif Chars (Argx) = Name_Eliminated then |
| 34577 |
return Eliminated; |
| 34578 |
|
| 34579 |
else |
| 34580 |
raise Program_Error; |
| 34581 |
end if; |
| 34582 |
end Get_Overflow_Mode; |
| 34583 |
|
| 34584 |
-- Local variables |
| 34585 |
|
| 34586 |
Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N)); |
| 34587 |
Arg2 : constant Node_Id := Next (Arg1); |
| 34588 |
|
| 34589 |
-- Start of processing for Set_Overflow_Mode |
| 34590 |
|
| 34591 |
begin |
| 34592 |
-- Process first argument |
| 34593 |
|
| 34594 |
Scope_Suppress.Overflow_Mode_General := |
| 34595 |
Get_Overflow_Mode (Arg1); |
| 34596 |
|
| 34597 |
-- Case of only one argument |
| 34598 |
|
| 34599 |
if No (Arg2) then |
| 34600 |
Scope_Suppress.Overflow_Mode_Assertions := |
| 34601 |
Scope_Suppress.Overflow_Mode_General; |
| 34602 |
|
| 34603 |
-- Case of two arguments present |
| 34604 |
|
| 34605 |
else |
| 34606 |
Scope_Suppress.Overflow_Mode_Assertions := |
| 34607 |
Get_Overflow_Mode (Arg2); |
| 34608 |
end if; |
| 34609 |
end Set_Overflow_Mode; |
| 34610 |
|
| 34611 |
------------------- |
| 34612 |
-- Test_Case_Arg -- |
| 34613 |
------------------- |
| 34614 |
|
| 34615 |
function Test_Case_Arg |
| 34616 |
(Prag : Node_Id; |
| 34617 |
Arg_Nam : Name_Id; |
| 34618 |
From_Aspect : Boolean := False) return Node_Id |
| 34619 |
is |
| 34620 |
Aspect : constant Node_Id := Corresponding_Aspect (Prag); |
| 34621 |
Arg : Node_Id; |
| 34622 |
Args : Node_Id; |
| 34623 |
|
| 34624 |
begin |
| 34625 |
pragma Assert |
| 34626 |
(Arg_Nam in Name_Ensures | Name_Mode | Name_Name | Name_Requires); |
| 34627 |
|
| 34628 |
-- The caller requests the aspect argument |
| 34629 |
|
| 34630 |
if From_Aspect then |
| 34631 |
if Present (Aspect) |
| 34632 |
and then Nkind (Expression (Aspect)) = N_Aggregate |
| 34633 |
then |
| 34634 |
Args := Expression (Aspect); |
| 34635 |
|
| 34636 |
-- "Name" and "Mode" may appear without an identifier as a |
| 34637 |
-- positional association. |
| 34638 |
|
| 34639 |
if Present (Expressions (Args)) then |
| 34640 |
Arg := First (Expressions (Args)); |
| 34641 |
|
| 34642 |
if Present (Arg) and then Arg_Nam = Name_Name then |
| 34643 |
return Arg; |
| 34644 |
end if; |
| 34645 |
|
| 34646 |
-- Skip "Name" |
| 34647 |
|
| 34648 |
Arg := Next (Arg); |
| 34649 |
|
| 34650 |
if Present (Arg) and then Arg_Nam = Name_Mode then |
| 34651 |
return Arg; |
| 34652 |
end if; |
| 34653 |
end if; |
| 34654 |
|
| 34655 |
-- Some or all arguments may appear as component associatons |
| 34656 |
|
| 34657 |
if Present (Component_Associations (Args)) then |
| 34658 |
Arg := First (Component_Associations (Args)); |
| 34659 |
while Present (Arg) loop |
| 34660 |
if Chars (First (Choices (Arg))) = Arg_Nam then |
| 34661 |
return Arg; |
| 34662 |
end if; |
| 34663 |
|
| 34664 |
Next (Arg); |
| 34665 |
end loop; |
| 34666 |
end if; |
| 34667 |
end if; |
| 34668 |
|
| 34669 |
-- Otherwise retrieve the argument directly from the pragma |
| 34670 |
|
| 34671 |
else |
| 34672 |
Arg := First (Pragma_Argument_Associations (Prag)); |
| 34673 |
|
| 34674 |
if Present (Arg) and then Arg_Nam = Name_Name then |
| 34675 |
return Arg; |
| 34676 |
end if; |
| 34677 |
|
| 34678 |
-- Skip argument "Name" |
| 34679 |
|
| 34680 |
Arg := Next (Arg); |
| 34681 |
|
| 34682 |
if Present (Arg) and then Arg_Nam = Name_Mode then |
| 34683 |
return Arg; |
| 34684 |
end if; |
| 34685 |
|
| 34686 |
-- Skip argument "Mode" |
| 34687 |
|
| 34688 |
Arg := Next (Arg); |
| 34689 |
|
| 34690 |
-- Arguments "Requires" and "Ensures" are optional and may not be |
| 34691 |
-- present at all. |
| 34692 |
|
| 34693 |
while Present (Arg) loop |
| 34694 |
if Chars (Arg) = Arg_Nam then |
| 34695 |
return Arg; |
| 34696 |
end if; |
| 34697 |
|
| 34698 |
Next (Arg); |
| 34699 |
end loop; |
| 34700 |
end if; |
| 34701 |
|
| 34702 |
return Empty; |
| 34703 |
end Test_Case_Arg; |
| 34704 |
|
| 34705 |
-------------------------------------------- |
| 34706 |
-- Defer_Compile_Time_Warning_Error_To_BE -- |
| 34707 |
-------------------------------------------- |
| 34708 |
|
| 34709 |
procedure Defer_Compile_Time_Warning_Error_To_BE (N : Node_Id) is |
| 34710 |
Arg1 : constant Node_Id := First (Pragma_Argument_Associations (N)); |
| 34711 |
begin |
| 34712 |
Compile_Time_Warnings_Errors.Append |
| 34713 |
(New_Val => CTWE_Entry'(Eloc => Sloc (Arg1), |
| 34714 |
Scope => Current_Scope, |
| 34715 |
Prag => N)); |
| 34716 |
|
| 34717 |
-- If the Boolean expression contains T'Size, and we're not in the main |
| 34718 |
-- unit being compiled, then we need to copy the pragma into the main |
| 34719 |
-- unit, because otherwise T'Size might never be computed, leaving it |
| 34720 |
-- as 0. |
| 34721 |
|
| 34722 |
if not In_Extended_Main_Code_Unit (N) then |
| 34723 |
-- We've created an Itype for the string in this pragma and |
| 34724 |
-- may have made other Itypes. When we copy the entire tree |
| 34725 |
-- of this pragma, we'll make a second copy of them in its |
| 34726 |
-- unit, which will mess up the numbering of the remaining |
| 34727 |
-- internal names. |
| 34728 |
|
| 34729 |
declare |
| 34730 |
Saved_Current_Sem_Unit : constant Unit_Number_Type := |
| 34731 |
Current_Sem_Unit; |
| 34732 |
New_N : Node_Id; |
| 34733 |
|
| 34734 |
begin |
| 34735 |
Current_Sem_Unit := Main_Unit; |
| 34736 |
New_N := New_Copy_Tree (N); |
| 34737 |
Current_Sem_Unit := Saved_Current_Sem_Unit; |
| 34738 |
Insert_Library_Level_Action (New_N); |
| 34739 |
end; |
| 34740 |
end if; |
| 34741 |
end Defer_Compile_Time_Warning_Error_To_BE; |
| 34742 |
|
| 34743 |
------------------------------------------ |
| 34744 |
-- Validate_Compile_Time_Warning_Errors -- |
| 34745 |
------------------------------------------ |
| 34746 |
|
| 34747 |
procedure Validate_Compile_Time_Warning_Errors is |
| 34748 |
procedure Set_Scope (S : Entity_Id); |
| 34749 |
-- Install all enclosing scopes of S along with S itself |
| 34750 |
|
| 34751 |
procedure Unset_Scope (S : Entity_Id); |
| 34752 |
-- Uninstall all enclosing scopes of S along with S itself |
| 34753 |
|
| 34754 |
--------------- |
| 34755 |
-- Set_Scope -- |
| 34756 |
--------------- |
| 34757 |
|
| 34758 |
procedure Set_Scope (S : Entity_Id) is |
| 34759 |
begin |
| 34760 |
if S /= Standard_Standard then |
| 34761 |
Set_Scope (Scope (S)); |
| 34762 |
end if; |
| 34763 |
|
| 34764 |
Push_Scope (S); |
| 34765 |
end Set_Scope; |
| 34766 |
|
| 34767 |
----------------- |
| 34768 |
-- Unset_Scope -- |
| 34769 |
----------------- |
| 34770 |
|
| 34771 |
procedure Unset_Scope (S : Entity_Id) is |
| 34772 |
begin |
| 34773 |
if S /= Standard_Standard then |
| 34774 |
Unset_Scope (Scope (S)); |
| 34775 |
end if; |
| 34776 |
|
| 34777 |
Pop_Scope; |
| 34778 |
end Unset_Scope; |
| 34779 |
|
| 34780 |
-- Start of processing for Validate_Compile_Time_Warning_Errors |
| 34781 |
|
| 34782 |
begin |
| 34783 |
-- These error/warning messages were deferred because they could not be |
| 34784 |
-- evaluated in the front-end and they needed additional information |
| 34785 |
-- from the back-end. There is no reason to run these checks again if |
| 34786 |
-- the back-end was not activated by this point. |
| 34787 |
|
| 34788 |
if not Generating_Code then |
| 34789 |
return; |
| 34790 |
end if; |
| 34791 |
|
| 34792 |
Expander_Mode_Save_And_Set (False); |
| 34793 |
In_Compile_Time_Warning_Or_Error := True; |
| 34794 |
|
| 34795 |
for N in Compile_Time_Warnings_Errors.First .. |
| 34796 |
Compile_Time_Warnings_Errors.Last |
| 34797 |
loop |
| 34798 |
declare |
| 34799 |
T : CTWE_Entry renames Compile_Time_Warnings_Errors.Table (N); |
| 34800 |
|
| 34801 |
begin |
| 34802 |
Set_Scope (T.Scope); |
| 34803 |
Reset_Analyzed_Flags (T.Prag); |
| 34804 |
Validate_Compile_Time_Warning_Or_Error (T.Prag, T.Eloc); |
| 34805 |
Unset_Scope (T.Scope); |
| 34806 |
end; |
| 34807 |
end loop; |
| 34808 |
|
| 34809 |
In_Compile_Time_Warning_Or_Error := False; |
| 34810 |
Expander_Mode_Restore; |
| 34811 |
end Validate_Compile_Time_Warning_Errors; |
| 34812 |
|
| 34813 |
end Sem_Prag; |